Main Page | Packages | Class Hierarchy | Class List | Directories | File List | Class Members | Related Pages

FileUploader Class Reference

List of all members.

Detailed Description

Utilities to do with uploading files.

Definition at line 36 of file FileUploader.java.


Public Member Functions

void init (ServletConfig config) throws ServletException
void upload (HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException

Protected Member Functions

void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException
void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException

Private Member Functions

String doPlotXMLUpload (FilePart filePart, HashMap< String, String > parameters) throws JetWebException, IOException
Generator doDefaultsXMLUpload (FilePart filePart, HashMap< String, String > parameters) throws JetWebException, IOException
Model doModelUpload (FilePart filePart, HttpServletRequest request) throws JetWebException, IOException

Private Attributes

String destinationDirName
File destinationDir
PrintWriter out
int paperId

Member Function Documentation

Generator doDefaultsXMLUpload FilePart  filePart,
HashMap< String, String >  parameters
throws JetWebException, IOException [private]
 

Definition at line 277 of file FileUploader.java.

References FileUploader.destinationDir, GeneratorWrapper.generator(), JetWebGeneratorReader.getGeneratorWrapper(), FileUploader.out, DBObjectManager.passDBConnection(), GeneratorWrapper.toString(), and DBObjectManager.writeObject().

Referenced by FileUploader.upload().

00279                                         {
00280 
00281     System.out.println("Called the xml defaults uploader");
00282 
00283     String fileName = filePart.getFileName();
00284 
00285     filePart.writeTo(destinationDir);
00286 
00287     GeneratorWrapper wrapper = null;
00288 
00289     System.out.println("opening xml file "+destinationDir+"/"+fileName);
00290 
00291     try{
00292         JetWebGeneratorReader reader = 
00293         new JetWebGeneratorReader(destinationDir+"/"+fileName);
00294         wrapper = reader.getGeneratorWrapper();
00295         
00296     }catch(Exception e){
00297         throw new JetWebException(e);
00298         }
00299 
00300     DBConnectionManager connManager = DBConfig.getDBConnectionManager();
00301     DBObjectManager objManager = new DBObjectManager();
00302     objManager.passDBConnection(connManager);
00303     String tableName =wrapper.toString()+"_defaults";
00304 
00305     Generator gen = wrapper.generator();
00306     String genName = gen.toString();
00307     int ii = genName.indexOf(".");
00308 
00309     while(ii>-1){
00310         genName = genName.substring(0,ii)+genName.substring(ii+1);
00311         ii = genName.indexOf(".");
00312     }
00313 
00314     ii = genName.indexOf("-");
00315     
00316     String genVersion = genName.substring(ii+1);
00317     genName = genName.substring(0, ii);
00318 
00319     Set<String> knownVersions = DBGeneratorManager.getVersions(genName);
00320 
00321     if(!knownVersions.contains(genVersion)){
00322 
00323 
00324         objManager.writeObject(wrapper, tableName, DBConfig.JETWEB);
00325                 
00326         // Now add the row to the generators table.
00327         System.out.println("using generator id = "+gen.getGeneratorId());
00328         DBGeneratorManager.add(wrapper.generator());
00329         
00330         System.out.println("used generator id = "+gen.getGeneratorId());
00331 
00332         HTMLGeneratorWriter.installedMessage(out,wrapper.generator());
00333         
00334 
00335     }else{
00336         HTMLGeneratorWriter.alreadyInstalledMessage
00337         (out, wrapper.generator());
00338     }
00339     return wrapper.generator();
00340     }

void doGet HttpServletRequest  request,
HttpServletResponse  response
throws ServletException, java.io.IOException [protected]
 

Handles the HTTP GET method.

Parameters:
request servlet request
response servlet response

Definition at line 64 of file FileUploader.java.

References FileUploader.upload().

00066                                                  {
00067         upload(request,response);
00068     }

Model doModelUpload FilePart  filePart,
HttpServletRequest  request
throws JetWebException, IOException [private]
 

Definition at line 342 of file FileUploader.java.

References FileUploader.destinationDir, JetWebLogReader.fillLog(), PlotSelection.fitIsEmpty(), LogFile.getRunSeries(), PlotSelection.setFitDefault(), PlotSelection.setSumDefault(), and PlotSelection.sumIsEmpty().

Referenced by FileUploader.upload().

00344                                        {
00345 
00346     String fileName = filePart.getFileName();
00347     filePart.writeTo(destinationDir);
00348 
00349     try{
00350         JetWebLogReader reader = 
00351         new JetWebLogReader(destinationDir+"/"+fileName);
00352         LogFile log = new LogFile(destinationDir+"/"+fileName);
00353         reader.fillLog(log);
00354         RunSeries rs = log.getRunSeries();
00355         PlotSelection selection = ServletUtils.makePlotSelection(request);
00356         // make this check only the sum plots!
00357         if (selection.fitIsEmpty()) { selection.setFitDefault(); }
00358         // make this check only the sum plots!
00359         if (selection.sumIsEmpty()) { selection.setSumDefault(); }
00360 
00361         ServletUtils.performResultSearch
00362         (rs, out, JetWebConfig.searchServletPath, selection, request);
00363 
00364     }catch(Exception e){
00365         throw new JetWebException(e);
00366     }
00367 
00368     return new Model();
00369     }

String doPlotXMLUpload FilePart  filePart,
HashMap< String, String >  parameters
throws JetWebException, IOException [private]
 

Definition at line 217 of file FileUploader.java.

References FileUploader.destinationDir, FileUploader.out, FileUploader.paperId, and HTMLWriter.write().

Referenced by FileUploader.upload().

00219                                         {
00220 
00221     String message   = "";
00222     String fileName = filePart.getFileName();
00223 
00224     String fileParm = filePart.getName();
00225     String plotNum  = fileParm.substring(fileParm.indexOf("-")+1);
00226 
00227     if (paperId != 0){
00228 
00229         System.out.println("Plot number "+plotNum);
00230         System.out.println("File name " + fileName );
00231         System.out.println("HZsteer plot id " + parameters.get("HZSTEERPLOTID"));
00232 
00233         System.out.println(parameters);
00234 
00235         if (fileName.equals("plot"+plotNum+".xml")) {
00236 
00237         long size = filePart.writeTo(destinationDir);
00238             
00239         System.out.println("replacing "+fileName);
00240         message = message+"<br>Successfully replaced file: "+fileName;
00241         parameters.put("UPDATED"+plotNum,"done");
00242         } else if(fileName.startsWith("n0") && fileName.endsWith(".aida") &&
00243               parameters.get("HZSTEERPLOTID")!=null &&
00244               !parameters.get("HZSTEERPLOTID").equals("")){
00245         //Then it's a file from hzsteer output.
00246 
00247         String plotDir = JetWebConfig.rootDirectory + "/" + 
00248             JetWebConfig.plotCacheDirName;
00249 
00250         System.out.println("found HZSteer output - writing to " +
00251                    plotDir);
00252 
00253         filePart.writeTo(new File(plotDir));
00254 
00255         //we save the file name in the parameters so that 
00256         //ServletUtils.addPlot can find it later.
00257 
00258         parameters.put("HZSTEERPLOT", 
00259                    plotDir + "/" + 
00260                    fileName.substring(fileName.lastIndexOf("/")+1));
00261 
00262         }else{
00263         System.out.println("Invalid file name");
00264         message = message+"XML file not replaced due to invalid name: "+fileName;
00265         }
00266 
00267     } else {
00268         JetWebException jwe = new 
00269         JetWebException("Paper ID is zero.","="+paperId);
00270         HTMLErrorWriter.write(out,jwe);
00271     }
00272 
00273     return message;
00274         
00275     }

void doPost HttpServletRequest  request,
HttpServletResponse  response
throws ServletException, java.io.IOException [protected]
 

Handles the HTTP POST method.

Parameters:
request servlet request
response servlet response

Definition at line 54 of file FileUploader.java.

References FileUploader.upload().

00056                                                  {
00057         upload(request,response);
00058     }

void init ServletConfig  config  )  throws ServletException
 

Definition at line 44 of file FileUploader.java.

00044                                                                    {
00045     super.init(config);
00046     // Set up configuration with servlet mode on. 
00047     JetWebConfig.init();
00048     }

void upload HttpServletRequest  request,
HttpServletResponse  response
throws ServletException, java.io.IOException
 

Handle file uploads for the text file of a paper or xml files of data.

Definition at line 74 of file FileUploader.java.

References HTMLWriter.close(), FileUploader.destinationDir, FileUploader.destinationDirName, FileUploader.doDefaultsXMLUpload(), FileUploader.doModelUpload(), FileUploader.doPlotXMLUpload(), FileUploader.out, FileUploader.paperId, HTMLWriter.write(), HTMLPaperWriter.writePaperForm(), and HTMLPaperWriter.writePlotsForm().

Referenced by FileUploader.doGet(), and FileUploader.doPost().

00075                                                  {
00076       
00077     System.out.println("Called upload");
00078     //PrintWriter out = response.getWriter();
00079 
00080     out = response.getWriter();
00081 
00082     boolean isXML       = false;
00083     boolean isPaperText = false;
00084     boolean isDefaults = false;
00085     boolean isModel = false;
00086     int maxPlotNum = 0;
00087     String message = "";
00088     response.setContentType("text/html");
00089 
00090     try {
00091         MultipartParser mp = 
00092         new MultipartParser(request, 10*1024*1024); // 10MB
00093         Part part;
00094 
00095         HashMap<String,String> parameters = new HashMap<String,String>();
00096         
00097         while ((part = mp.readNextPart()) != null) {
00098         String name = part.getName();
00099         String plotNum = "";
00100 
00101         // Handle parameter parts. Determine the directory the file
00102         // is to be written into, the paper ID, and whether this is an XML
00103         // upload or not.
00104         if (part.isParam()) {
00105             ParamPart paramPart = (ParamPart) part;
00106             String value        = paramPart.getStringValue();
00107             if(name.equals("MODELXML")){
00108             isModel = true;
00109             }else if (name.equals("DEFAULTSUPLOAD")){
00110             isDefaults = true;
00111             }else if (name.equals("PLOTUPLOAD")) {
00112             isXML = true;
00113             } else if (name.equals("PAPERTEXTUPLOAD")) {
00114             isPaperText = true;
00115             } else if (name.equals("DIRECTORY")) {
00116             destinationDirName = value;
00117             } else if (name.equals("PAPERID")) {
00118             try {
00119                 paperId= Integer.parseInt(value);       
00120             } catch (Exception e) {
00121                 HTMLErrorWriter.write(out,e);
00122             }
00123             } else {
00124             parameters.put(name,value);
00125             }
00126 
00127         }
00128 
00129         if(part.isFile()){
00130             FilePart filePart = (FilePart) part;
00131             
00132             destinationDir = new File(destinationDirName);
00133             if (filePart.getFileName()!=null){
00134             System.out.println
00135                 ("Directory is "+destinationDirName+". File is "
00136                  +filePart.getFileName());
00137             
00138             if (! destinationDir.exists() ) {
00139                 System.out.println("ERROR: Specified dir = "
00140                            +destinationDirName
00141                            +" DOES NOT EXIST.");
00142             }
00143             
00144             if (isXML){
00145                 
00146                 try {
00147                 message = doPlotXMLUpload(filePart,parameters);
00148                 } catch (JetWebException jwe){
00149                 HTMLErrorWriter.write(out,jwe);
00150                 return;
00151                 }
00152             } else if(isDefaults){
00153                 try{
00154                 Generator gen = 
00155                     doDefaultsXMLUpload(filePart, parameters);
00156                 //HTMLGeneratorWriter.installedMessage(out,gen);
00157                 }catch (JetWebException jwe){
00158                 HTMLErrorWriter.write(out,jwe);
00159                 }
00160                 return;
00161             }else if(isModel){
00162                 try{
00163                 doModelUpload(filePart, request);
00164                 }catch (JetWebException err){
00165                 HTMLErrorWriter.write(out, err);
00166                 }
00167                 return;
00168             }else {
00169                 
00170                 JetWebException jwe = new 
00171                 JetWebException("Unknown file upload request."," ");
00172                 HTMLErrorWriter.write(out,jwe);
00173                 return;
00174             }
00175             }
00176         
00177 
00178         }
00179         }
00180     
00181         System.out.println("Paper ID="+paperId);
00182         
00183         // When we get here, we have all the parameters 
00184         // and so can start altering the plots.
00185         try {
00186         
00187         Paper paper = new Paper(paperId);       
00188         ServletUtils.deletePlots(parameters,paper);
00189         ServletUtils.modifyPlots(parameters,paper);
00190         ServletUtils.addPlot(parameters,paper,"NEW");
00191         System.out.println("back from ServeletUtils.addPlot()");
00192         HTMLPaperWriter pm = new HTMLPaperWriter
00193             (out, JetWebConfig.mainServletPath);
00194         System.out.println("Created new HTMLPaperWriter");
00195 
00196         pm.writePaperForm(paper," ");
00197 
00198         System.out.println("written blank message");
00199 
00200         pm.writePlotsForm(paper,message);
00201         System.out.println("written message " + message);
00202 
00203         pm.close();
00204         System.out.println("closed HTMLPaperWriter");
00205 
00206         return;
00207         
00208         } catch (JetWebException jwe){
00209         HTMLErrorWriter.write(out,jwe);
00210         }
00211     }catch (IOException lEx) {
00212         //this.getServletContext().log("ERROR: reading or saving file"+lEx.toString());
00213     }
00214     }


Member Data Documentation

File destinationDir [private]
 

Definition at line 39 of file FileUploader.java.

Referenced by FileUploader.doDefaultsXMLUpload(), FileUploader.doModelUpload(), FileUploader.doPlotXMLUpload(), and FileUploader.upload().

String destinationDirName [private]
 

Definition at line 38 of file FileUploader.java.

Referenced by FileUploader.upload().

PrintWriter out [private]
 

Definition at line 41 of file FileUploader.java.

Referenced by FileUploader.doDefaultsXMLUpload(), FileUploader.doPlotXMLUpload(), and FileUploader.upload().

int paperId [private]
 

Definition at line 42 of file FileUploader.java.

Referenced by FileUploader.doPlotXMLUpload(), and FileUploader.upload().


The documentation for this class was generated from the following file:

Generated Wed Jan 17 09:14:27 GMT 2007