vgritsenko 2002/10/28 21:29:18 Modified: . changes.xml src/java/org/apache/cocoon/servlet 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 1.275 +6 -1 xml-cocoon2/changes.xml Index: changes.xml =================================================================== RCS file: /home/cvs/xml-cocoon2/changes.xml,v retrieving revision 1.274 retrieving revision 1.275 diff -u -r1.274 -r1.275 --- changes.xml 29 Oct 2002 04:49:52 -0000 1.274 +++ changes.xml 29 Oct 2002 05:29:18 -0000 1.275 @@ -40,6 +40,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. 1.43 +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.42 retrieving revision 1.43 diff -u -r1.42 -r1.43 --- CocoonServlet.java 29 Oct 2002 04:49:52 -0000 1.42 +++ CocoonServlet.java 29 Oct 2002 05:29:18 -0000 1.43 @@ -151,11 +151,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; @@ -170,7 +172,6 @@ protected boolean initClassLoader = false; private String parentComponentManagerClass; - private String requestFactoryClass; protected String forceLoadParameter; protected String forceSystemProperty; @@ -278,7 +279,7 @@ } this.workDir.mkdirs(); - this.initLogger(); + initLogger(); String path = this.servletContextPath; if (log.isDebugEnabled()) { log.debug("getRealPath for /: " + path); @@ -367,6 +368,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); @@ -400,7 +431,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... ?"); @@ -432,14 +463,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) { @@ -949,10 +980,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]