vgritsenko    2002/10/28 21:29:00

  Modified:    .        Tag: cocoon_2_0_3_branch changes.xml
               src/java/org/apache/cocoon/servlet Tag: cocoon_2_0_3_branch
                        CocoonServlet.java
  Log:
      CocoonServlet upload behavior now configurable from the web.xml.
      Configuration parameters are: autosave-uploads, overwrite-uploads,
      upload-max-size. See web.xml for description.
      Thanks to Geoff Howard.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.138.2.64 +6 -1      xml-cocoon2/changes.xml
  
  Index: changes.xml
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/changes.xml,v
  retrieving revision 1.138.2.63
  retrieving revision 1.138.2.64
  diff -u -r1.138.2.63 -r1.138.2.64
  --- changes.xml       29 Oct 2002 04:48:58 -0000      1.138.2.63
  +++ changes.xml       29 Oct 2002 05:28:59 -0000      1.138.2.64
  @@ -39,6 +39,11 @@
    </devs>
   
    <release version="@version@" date="@date@">
  +  <action dev="VG" type="fix" fixes-bug="13648" due-to="Geoff Howard" 
due-to-email="[EMAIL PROTECTED]">
  +    CocoonServlet upload behavior now configurable from the web.xml.
  +    Configuration parameters are: autosave-uploads, overwrite-uploads,
  +    upload-max-size. See web.xml for description.
  +  </action>
     <action dev="VG" type="fix" fixes-bug="13643" due-to="Leo Sutic" 
due-to-email="[EMAIL PROTECTED]">
       Remove the static factory variable in RequestFactory, and instead 
       pass it to the HttpRequest via the environment.
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.19.2.14 +47 -16    
xml-cocoon2/src/java/org/apache/cocoon/servlet/CocoonServlet.java
  
  Index: CocoonServlet.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/servlet/CocoonServlet.java,v
  retrieving revision 1.19.2.13
  retrieving revision 1.19.2.14
  diff -u -r1.19.2.13 -r1.19.2.14
  --- CocoonServlet.java        29 Oct 2002 04:48:59 -0000      1.19.2.13
  +++ CocoonServlet.java        29 Oct 2002 05:28:59 -0000      1.19.2.14
  @@ -148,11 +148,13 @@
       protected boolean showTime;
       protected boolean hiddenShowTime;
   
  -    private static final boolean ALLOW_OVERWRITE = false;
  -    private static final boolean SILENTLY_RENAME = true;
  -    private static final boolean SAVE_UPLOADED_FILES_TO_DISK = true;
  +    private static final boolean SAVE_UPLOADS_TO_DISK = true;
       private static final int MAX_UPLOAD_SIZE = 10000000; // 10Mb
  -    private int maxUploadSize = MAX_UPLOAD_SIZE; // 10Mb
  +
  +    private int maxUploadSize;
  +    private boolean autoSaveUploads;
  +    private boolean allowOverwrite;
  +    private boolean silentlyRename;
   
       private File uploadDir;
       private File workDir;
  @@ -167,7 +169,6 @@
       protected boolean initClassLoader = false;
   
       private String parentComponentManagerClass;
  -    private String requestFactoryClass;
   
       protected String forceLoadParameter;
       protected String forceSystemProperty;
  @@ -265,7 +266,7 @@
           }
           this.workDir.mkdirs();
   
  -        this.initLogger();
  +        initLogger();
           String path = this.servletContextPath;
           if (log.isDebugEnabled()) {
               log.debug("getRealPath for /: " + path);
  @@ -354,6 +355,36 @@
           this.uploadDir.mkdirs();
           this.appContext.put(Constants.CONTEXT_UPLOAD_DIR, this.uploadDir);
   
  +        value = conf.getInitParameter("autosave-uploads");
  +        if (value != null) {
  +            this.autoSaveUploads = ("yes".equalsIgnoreCase(value) || 
"true".equalsIgnoreCase(value));
  +        } else {
  +            this.autoSaveUploads = SAVE_UPLOADS_TO_DISK;
  +            if (log.isDebugEnabled()) {
  +               log.debug("autosave-uploads was not set - defaulting to " + 
this.autoSaveUploads);
  +            }
  +        }
  +
  +        String overwriteParam = conf.getInitParameter("overwrite-uploads");
  +        // accepted values are deny|allow|rename - rename is default.
  +        if (overwriteParam == null) {
  +            if (log.isDebugEnabled()) {
  +               log.debug("overwrite-uploads was not set - defaulting to rename");
  +            }
  +        }
  +        if ("deny".equalsIgnoreCase(overwriteParam)) {
  +            this.allowOverwrite = false;
  +            this.silentlyRename = false;
  +        } else if ("allow".equalsIgnoreCase(overwriteParam)) {
  +           this.allowOverwrite = true;
  +           this.silentlyRename = false; // ignored in this case
  +        } else {
  +           // either rename is specified or unsupported value - default to rename.
  +           this.allowOverwrite = false;
  +           this.silentlyRename = true;
  +        }
  +
  +        this.maxUploadSize = MAX_UPLOAD_SIZE;
           String maxSizeParam = conf.getInitParameter("upload-max-size");
           if ((maxSizeParam != null) && (!maxSizeParam.trim().equals(""))) {
               this.maxUploadSize = Integer.parseInt(maxSizeParam);
  @@ -387,7 +418,7 @@
           this.appContext.put(Constants.CONTEXT_CACHE_DIR, this.cacheDir);
   
           this.appContext.put(Constants.CONTEXT_CONFIG_URL,
  -                            
this.getConfigFile(conf.getInitParameter("configurations")));
  +                            getConfigFile(conf.getInitParameter("configurations")));
           if (conf.getInitParameter("configurations") == null) {
               if (log.isDebugEnabled()) {
                   log.debug("configurations was not set - defaulting to... ?");
  @@ -419,14 +450,14 @@
               }
           }
   
  -        this.requestFactoryClass = conf.getInitParameter("request-factory");
  -        if (requestFactoryClass == null) {
  -            requestFactoryClass = 
"org.apache.cocoon.components.request.MultipartRequestFactoryImpl";
  +        value = conf.getInitParameter("request-factory");
  +        if (value == null) {
  +            value = 
"org.apache.cocoon.components.request.MultipartRequestFactoryImpl";
               if (log.isDebugEnabled()) {
  -                log.debug("request-factory was not set - defaulting to " + 
requestFactoryClass);
  +                log.debug("request-factory was not set - defaulting to " + value);
               }
           }
  -        this.requestFactory = RequestFactory.getRequestFactory(requestFactoryClass);
  +        this.requestFactory = RequestFactory.getRequestFactory(value);
   
           this.containerEncoding = conf.getInitParameter("container-encoding");
           if (containerEncoding == null) {
  @@ -923,10 +954,10 @@
           long start = System.currentTimeMillis();
           res.addHeader("X-Cocoon-Version", Constants.VERSION);
           HttpServletRequest request = requestFactory.getServletRequest(req,
  -                                         CocoonServlet.SAVE_UPLOADED_FILES_TO_DISK,
  +                                         this.autoSaveUploads,
                                            this.uploadDir,
  -                                         CocoonServlet.ALLOW_OVERWRITE,
  -                                         CocoonServlet.SILENTLY_RENAME,
  +                                         this.allowOverwrite,
  +                                         this.silentlyRename,
                                            this.maxUploadSize);
   
           this.cocoon = getCocoon(request.getPathInfo(), 
request.getParameter(Constants.RELOAD_PARAM));
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     [EMAIL PROTECTED]
To unsubscribe, e-mail:          [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to