struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mschach...@locus.apache.org
Subject cvs commit: jakarta-struts/src/share/org/apache/struts/upload DiskMultipartRequestHandler.java
Date Fri, 10 Nov 2000 02:55:46 GMT
mschachter    00/11/09 18:55:45

  Modified:    src/share/org/apache/struts/upload
                        DiskMultipartRequestHandler.java
  Log:
  - If there is no temporary directory specified in web.xml as an
  init-param, the DiskMultipartRequestHandler first checks the servlet context value of
  javax.servlet.context.tmpdir for a directory value from the servlet
  container.  If that value is not specified, then it checks for the system
  property java.io.tmpdir.
  
  Revision  Changes    Path
  1.2       +22 -13    jakarta-struts/src/share/org/apache/struts/upload/DiskMultipartRequestHandler.java
  
  Index: DiskMultipartRequestHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/upload/DiskMultipartRequestHandler.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DiskMultipartRequestHandler.java	2000/11/09 20:08:56	1.1
  +++ DiskMultipartRequestHandler.java	2000/11/10 02:55:45	1.2
  @@ -7,6 +7,7 @@
   import java.io.UnsupportedEncodingException;
   import java.util.Hashtable;
   import java.util.Enumeration;
  +import javax.servlet.ServletContext;
   import javax.servlet.ServletException;
   import javax.servlet.http.HttpServletRequest;
   
  @@ -84,29 +85,37 @@
       }
       
       
  -    protected DiskFile writeFile(MultipartElement element) throws IOException {
  +    protected DiskFile writeFile(MultipartElement element) throws IOException,
  +                                                                     ServletException {
           DiskFile theFile = null;
   
           //get a handle to some temporary file and open
           //a stream to it
           String tempDir = servlet.getTempDir();
           if (tempDir == null) {
  -            tempDir = System.getProperty("java.io.tmpdir");
  +            //attempt to retrieve the servlet container's temporary directory
  +            ServletContext context = servlet.getServletConfig().getServletContext();
  +            tempDir = (String) context.getAttribute("javax.servlet.context.tempdir");
  +            
  +            if (tempDir == null) {
  +                //default to system-wide tempdir                
  +                tempDir = System.getProperty("java.io.tmpdir");
  +                
  +                if (servlet.getDebug() > 1) {
  +                    servlet.log("DiskMultipartRequestHandler.handleRequest(): " +
  +                    "defaulting to java.io.tmpdir directory \"" +
  +                    tempDir);
  +                }
  +            }
           }
           
           File tempDirectory = new File(tempDir);
  -        if ((!tempDirectory.exists()) && (!tempDirectory.isDirectory())) {
  -            tempDir = System.getProperty("java.io.tmpdir");
  -            tempDirectory = new File(tempDir);
  -
  -            if (servlet.getDebug() > 1) {
  -                servlet.log("DiskMultipartRequestHandler.handleRequest(): tempDir " +
  -                "\"" + tempDirectory + "\" doesn't exist or isn't a " +
  -                "directory, defaulting to java.io.tmpdir directory \"" +
  -                tempDir);
  -            }
  +        
  +        if ((!tempDirectory.exists()) || (!tempDirectory.isDirectory())) {
  +            throw new ServletException("DiskMultipartRequestHandler: no " +
  +                "temporary directory specified for disk write");
           }
  -
  +        
           File tempFile = File.createTempFile("strts", null, tempDirectory);
           FileOutputStream fos = new FileOutputStream(tempFile);
   
  
  
  

Mime
View raw message