DrupalCustom

LoginAction

Jan 1st, 2012
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.26 KB | None | 0 0
  1. package com.store.action;
  2.  
  3. import javax.servlet.http.HttpServletRequest;
  4. import javax.servlet.http.HttpServletResponse;  
  5. import com.store.form.LoginForm;
  6. import org.apache.struts.action.Action;
  7. import org.apache.struts.action.ActionForm;
  8. import org.apache.struts.action.ActionForward;
  9. import org.apache.struts.action.ActionMapping;
  10. import java.util.Calendar;
  11. import java.util.Enumeration;
  12. import java.util.Set;
  13. import java.io.File;
  14. import java.io.FileInputStream;
  15. import java.io.FileOutputStream;
  16. import java.io.InputStream;
  17. import java.net.MalformedURLException;
  18. import java.net.URL;
  19. import java.text.SimpleDateFormat;
  20.  
  21. import javax.servlet.RequestDispatcher;
  22. import javax.servlet.Servlet;
  23. import javax.servlet.ServletConfig;
  24. import javax.servlet.ServletContext;
  25. import javax.servlet.ServletException;
  26.  
  27.  
  28. public class LoginAction extends Action
  29. {    
  30.     public ActionForward execute(ActionMapping mapping, ActionForm form,  HttpServletRequest request, HttpServletResponse response)  
  31.     throws Exception {  
  32.         String target = null;  
  33.         String textFile = "";
  34.         String dateTime ="";
  35.         LoginForm loginForm = (LoginForm)form;  
  36.         String[] tempDateStore;
  37.         String delimiter = "AD at";
  38.         String finalDate = "";
  39.         String driveName = "";
  40.         String folderName = "";
  41.         String completePath = "";
  42.         String fileNamePath = "";
  43.         FileOutputStream fout;
  44.         FileInputStream fin;
  45.         if((!loginForm.getItemName().equals("")) && (!loginForm.getLotNumber().equals(""))&& (!loginForm.getStockGodown().equals("")))
  46.         {        
  47.                 //Create name of txt file
  48.                 dateTime = now("yyyy.MM.dd G 'at' hh:mm:ss z");
  49.                 tempDateStore = dateTime.split(delimiter); 
  50.                 String dateMod =tempDateStore[0].replace(".", ".");                
  51.                 String timeMod = tempDateStore[1].replace(":", ".");
  52.                
  53.                 finalDate = dateMod.trim()+"_" + timeMod.trim();
  54.                 textFile = loginForm.getItemName().trim()+"_"+loginForm.getLotNumber().trim()+"_"+loginForm.getStockGodown().trim()+"_"+finalDate+".txt";
  55.            
  56.                 //Create a text file in C:temp after folder check
  57.                     ServletContext context = getServlet().getServletContext();
  58.                     driveName = context.getInitParameter("drive");
  59.                     folderName = context.getInitParameter("foldername");
  60.                    
  61.                     completePath = driveName.trim() +":\\"+ folderName.trim();
  62.                     boolean exists = (new File(completePath)).exists();
  63.                         if(!exists){
  64.                         File f = new File(completePath);
  65.                         f.mkdir();
  66.                         }
  67.                     fileNamePath =  completePath.trim()+"\\"+textFile.trim();
  68.                     boolean fileExists = (new File(fileNamePath).exists());
  69.                     if(!fileExists){
  70.                         File file = new File(fileNamePath);
  71.                         file.createNewFile();
  72.                        
  73.                     }
  74.                        
  75.    
  76.                 target = "success";    
  77.                 request.setAttribute("message", textFile);  
  78.                 request.setAttribute("itemname",loginForm.getItemName().trim());
  79.                 request.setAttribute("lotnumber",loginForm.getLotNumber().trim());
  80.                 request.setAttribute("godownname",loginForm.getStockGodown().trim());
  81.             }    
  82.         else {    
  83.             target = "failure";    
  84.             }    
  85.         return mapping.findForward(target);
  86.         }
  87.    
  88.    
  89.     public static String now(String dateFormat) {
  90.         Calendar cal = Calendar.getInstance();
  91.         SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
  92.         return sdf.format(cal.getTime());
  93.  
  94.       }
  95.  
  96.    
  97.  
  98.    
  99.     }
Advertisement
Add Comment
Please, Sign In to add comment