You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by cz...@apache.org on 2006/12/24 15:23:35 UTC
svn commit: r490021 - in /cocoon/trunk/core:
cocoon-common/src/main/java/org/apache/cocoon/
cocoon-configuration/cocoon-configuration-api/src/main/java/org/apache/cocoon/configuration/
cocoon-configuration/cocoon-configuration-impl/src/main/java/org/ap...
Author: cziegeler
Date: Sun Dec 24 06:23:34 2006
New Revision: 490021
URL: http://svn.apache.org/viewvc?view=rev&rev=490021
Log:
Remove upload-specific settings from general configuration
Added:
cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/multipart/MultipartConfigurationHelper.java (with props)
Modified:
cocoon/trunk/core/cocoon-common/src/main/java/org/apache/cocoon/Constants.java
cocoon/trunk/core/cocoon-configuration/cocoon-configuration-api/src/main/java/org/apache/cocoon/configuration/Settings.java
cocoon/trunk/core/cocoon-configuration/cocoon-configuration-impl/src/main/java/org/apache/cocoon/configuration/SettingsDefaults.java
cocoon/trunk/core/cocoon-configuration/cocoon-configuration-impl/src/main/java/org/apache/cocoon/configuration/impl/MutableSettings.java
cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/SettingsBeanFactoryPostProcessor.java
cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonContextFactoryBean.java
cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/generation/StatusGenerator.java
cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/multipart/MultipartFilter.java
Modified: cocoon/trunk/core/cocoon-common/src/main/java/org/apache/cocoon/Constants.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-common/src/main/java/org/apache/cocoon/Constants.java?view=diff&rev=490021&r1=490020&r2=490021
==============================================================================
--- cocoon/trunk/core/cocoon-common/src/main/java/org/apache/cocoon/Constants.java (original)
+++ cocoon/trunk/core/cocoon-common/src/main/java/org/apache/cocoon/Constants.java Sun Dec 24 06:23:34 2006
@@ -190,12 +190,6 @@
public static final String CONTEXT_WORK_DIR = "work-directory";
/**
- * Application <code>Context</code> Key for the upload directory path.
- * @deprecated Use {@link org.apache.cocoon.configuration.Settings#getUploadDirectory()} instead.
- */
- public static final String CONTEXT_UPLOAD_DIR = "upload-directory";
-
- /**
* Application <code>Context</code> Key for the cache directory path.
* @deprecated Use {@link org.apache.cocoon.configuration.Settings#getCacheDirectory()} instead.
*/
Modified: cocoon/trunk/core/cocoon-configuration/cocoon-configuration-api/src/main/java/org/apache/cocoon/configuration/Settings.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-configuration/cocoon-configuration-api/src/main/java/org/apache/cocoon/configuration/Settings.java?view=diff&rev=490021&r1=490020&r2=490021
==============================================================================
--- cocoon/trunk/core/cocoon-configuration/cocoon-configuration-api/src/main/java/org/apache/cocoon/configuration/Settings.java (original)
+++ cocoon/trunk/core/cocoon-configuration/cocoon-configuration-api/src/main/java/org/apache/cocoon/configuration/Settings.java Sun Dec 24 06:23:34 2006
@@ -41,14 +41,6 @@
String KEY_LOAD_CLASSES = "org.apache.cocoon.classloader.load.classes";
/**
- * This parameter allows to specify where Cocoon should put uploaded files.
- * The path specified can be either absolute or relative to the context
- * path of the servlet. On windows platform, absolute directory must start
- * with volume: C:\Path\To\Upload\Directory.
- */
- String KEY_UPLOADS_DIRECTORY = "org.apache.cocoon.uploads.directory";
-
- /**
* This parameter allows to specify where Cocoon should create its page
* and other objects cache. The path specified can be either absolute or
* relative to the context path of the servlet. On windows platform,
@@ -94,31 +86,6 @@
String KEY_RELOADING = "org.apache.cocoon.reloading";
/**
- * Causes all files in multipart requests to be processed.
- * Default is false for security reasons.
- */
- String KEY_UPLOADS_ENABLE = "org.apache.cocoon.uploads.enable";
-
- /**
- * Causes all files in multipart requests to be saved to upload-dir.
- * Default is true for security reasons.
- */
- String KEY_UPLOADS_AUTOSAVE = "org.apache.cocoon.uploads.autosave";
-
- /**
- * Specify handling of name conflicts when saving uploaded files to disk.
- * Acceptable values are deny, allow, rename (default). Files are renamed
- * x_filename where x is an integer value incremented to make the new
- * filename unique.
- */
- String KEY_UPLOADS_OVERWRITE = "org.apache.cocoon.uploads.overwrite";
-
- /**
- * Specify maximum allowed size of the upload. Defaults to 10 Mb.
- */
- String KEY_UPLOADS_MAXSIZE = "org.apache.cocoon.uploads.maxsize";
-
- /**
* Allow adding processing time to the response
*/
String KEY_SHOWTIME = "org.apache.cocoon.showtime";
@@ -175,12 +142,6 @@
List getLoadClasses();
/**
- * @return Returns the uploadDirectory.
- * @see #KEY_UPLOADS_DIRECTORY
- */
- String getUploadDirectory();
-
- /**
* @return Returns the workDirectory.
* @see #KEY_WORK_DIRECTORY
*/
@@ -246,38 +207,10 @@
long getReloadDelay(String type);
/**
- * @return Returns the autosaveUploads.
- * @see #KEY_UPLOADS_AUTOSAVE
- */
- boolean isAutosaveUploads();
-
- /**
- * @return Returns the enableUploads.
- * @see #KEY_UPLOADS_ENABLE
- */
- boolean isEnableUploads();
-
- /**
- * @return Returns the maxUploadSize.
- * @see #KEY_UPLOADS_MAXSIZE
- */
- int getMaxUploadSize();
-
- /**
- * @return Returns the overwriteUploads.
- * @see #KEY_UPLOADS_OVERWRITE
- */
- String getOverwriteUploads();
-
- /**
* @return Returns the showTime.
* @see #KEY_SHOWTIME
*/
boolean isShowTime();
-
- boolean isAllowOverwrite();
-
- boolean isSilentlyRename();
/**
* Return the current running mode.
Modified: cocoon/trunk/core/cocoon-configuration/cocoon-configuration-impl/src/main/java/org/apache/cocoon/configuration/SettingsDefaults.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-configuration/cocoon-configuration-impl/src/main/java/org/apache/cocoon/configuration/SettingsDefaults.java?view=diff&rev=490021&r1=490020&r2=490021
==============================================================================
--- cocoon/trunk/core/cocoon-configuration/cocoon-configuration-impl/src/main/java/org/apache/cocoon/configuration/SettingsDefaults.java (original)
+++ cocoon/trunk/core/cocoon-configuration/cocoon-configuration-impl/src/main/java/org/apache/cocoon/configuration/SettingsDefaults.java Sun Dec 24 06:23:34 2006
@@ -38,13 +38,6 @@
*/
public static final boolean RELOADING_ENABLED_DEFAULT = false;
- /**
- * Default value for {@link Settings#isEnableUploads()} parameter (false).
- */
- public static final boolean ENABLE_UPLOADS = false;
- public static final boolean SAVE_UPLOADS_TO_DISK = true;
- public static final int MAX_UPLOAD_SIZE = 10000000; // 10Mb
-
public static final boolean SHOW_TIME = false;
public static final boolean HIDE_SHOW_TIME = false;
Modified: cocoon/trunk/core/cocoon-configuration/cocoon-configuration-impl/src/main/java/org/apache/cocoon/configuration/impl/MutableSettings.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-configuration/cocoon-configuration-impl/src/main/java/org/apache/cocoon/configuration/impl/MutableSettings.java?view=diff&rev=490021&r1=490020&r2=490021
==============================================================================
--- cocoon/trunk/core/cocoon-configuration/cocoon-configuration-impl/src/main/java/org/apache/cocoon/configuration/impl/MutableSettings.java (original)
+++ cocoon/trunk/core/cocoon-configuration/cocoon-configuration-impl/src/main/java/org/apache/cocoon/configuration/impl/MutableSettings.java Sun Dec 24 06:23:34 2006
@@ -61,39 +61,6 @@
protected final List loadClasses = new ArrayList();
/**
- * Causes all files in multipart requests to be processed.
- * Default is false for security reasons.
- */
- protected boolean enableUploads;
-
- /**
- * This parameter allows to specify where Cocoon should put uploaded files.
- * The path specified can be either absolute or relative to the context
- * path of the servlet. On windows platform, absolute directory must start
- * with volume: C:\Path\To\Upload\Directory.
- */
- protected String uploadDirectory;
-
- /**
- * Causes all files in multipart requests to be saved to upload-dir.
- * Default is true for security reasons.
- */
- protected boolean autosaveUploads;
-
- /**
- * Specify handling of name conflicts when saving uploaded files to disk.
- * Acceptable values are deny, allow, rename (default). Files are renamed
- * x_filename where x is an integer value incremented to make the new
- * filename unique.
- */
- protected String overwriteUploads;
-
- /**
- * Specify maximum allowed size of the upload. Defaults to 10 Mb.
- */
- protected int maxUploadSize;
-
- /**
* This parameter allows to specify where Cocoon should create its page
* and other objects cache. The path specified can be either absolute or
* relative to the context path of the servlet. On windows platform,
@@ -161,9 +128,6 @@
public MutableSettings(String mode) {
// set default values
this.reloadingEnabled = SettingsDefaults.RELOADING_ENABLED_DEFAULT;
- this.enableUploads = SettingsDefaults.ENABLE_UPLOADS;
- this.autosaveUploads = SettingsDefaults.SAVE_UPLOADS_TO_DISK;
- this.maxUploadSize = SettingsDefaults.MAX_UPLOAD_SIZE;
this.showTime = SettingsDefaults.SHOW_TIME;
this.hideShowTime = SettingsDefaults.HIDE_SHOW_TIME;
this.showCocoonVersion = SettingsDefaults.SHOW_COCOON_VERSION;
@@ -195,16 +159,6 @@
this.setConfigurationReloadDelay(Long.valueOf(value).longValue());
} else if ( key.equals(KEY_RELOADING) ) {
this.setReloadingEnabled(BooleanUtils.toBoolean(value));
- } else if ( key.equals(KEY_UPLOADS_ENABLE) ) {
- this.setEnableUploads(BooleanUtils.toBoolean(value));
- } else if ( key.equals(KEY_UPLOADS_DIRECTORY) ) {
- this.setUploadDirectory(value);
- } else if ( key.equals(KEY_UPLOADS_AUTOSAVE) ) {
- this.setAutosaveUploads(BooleanUtils.toBoolean(value));
- } else if ( key.equals(KEY_UPLOADS_OVERWRITE) ) {
- this.setOverwriteUploads(value);
- } else if ( key.equals(KEY_UPLOADS_MAXSIZE) ) {
- this.setMaxUploadSize(Integer.valueOf(value).intValue());
} else if ( key.equals(KEY_CACHE_DIRECTORY) ) {
this.setCacheDirectory(value);
} else if ( key.equals(KEY_WORK_DIRECTORY) ) {
@@ -261,16 +215,6 @@
}
/**
- * @see org.apache.cocoon.core.DynamicSettings#isAutosaveUploads()
- */
- public boolean isAutosaveUploads() {
- if ( parent != null ) {
- return parent.isAutosaveUploads();
- }
- return this.autosaveUploads;
- }
-
- /**
* @see org.apache.cocoon.core.BaseSettings#getCacheDirectory()
*/
public String getCacheDirectory() {
@@ -281,16 +225,6 @@
}
/**
- * @see org.apache.cocoon.core.DynamicSettings#isEnableUploads()
- */
- public boolean isEnableUploads() {
- if ( parent != null ) {
- return parent.isEnableUploads();
- }
- return this.enableUploads;
- }
-
- /**
* @see org.apache.cocoon.core.BaseSettings#getFormEncoding()
*/
public String getFormEncoding() {
@@ -339,26 +273,6 @@
}
/**
- * @see org.apache.cocoon.core.DynamicSettings#getMaxUploadSize()
- */
- public int getMaxUploadSize() {
- if ( parent != null ) {
- return parent.getMaxUploadSize();
- }
- return this.maxUploadSize;
- }
-
- /**
- * @see org.apache.cocoon.core.DynamicSettings#getOverwriteUploads()
- */
- public String getOverwriteUploads() {
- if ( this.parent != null ) {
- return this.parent.getOverwriteUploads();
- }
- return this.overwriteUploads;
- }
-
- /**
* @see org.apache.cocoon.core.DynamicSettings#isShowTime()
*/
public boolean isShowTime() {
@@ -379,16 +293,6 @@
}
/**
- * @see org.apache.cocoon.core.BaseSettings#getUploadDirectory()
- */
- public String getUploadDirectory() {
- if ( this.parent != null ) {
- return this.parent.getUploadDirectory();
- }
- return this.uploadDirectory;
- }
-
- /**
* @see org.apache.cocoon.core.BaseSettings#getWorkDirectory()
*/
public String getWorkDirectory() {
@@ -399,36 +303,6 @@
}
/**
- * @see org.apache.cocoon.core.DynamicSettings#isAllowOverwrite()
- */
- public boolean isAllowOverwrite() {
- final String value = this.getOverwriteUploads();
- if ("deny".equalsIgnoreCase(value)) {
- return false;
- } else if ("allow".equalsIgnoreCase(value)) {
- return true;
- } else {
- // either rename is specified or unsupported value - default to rename.
- return false;
- }
- }
-
- /**
- * @see org.apache.cocoon.core.DynamicSettings#isSilentlyRename()
- */
- public boolean isSilentlyRename() {
- final String value = this.getOverwriteUploads();
- if ("deny".equalsIgnoreCase(value)) {
- return false;
- } else if ("allow".equalsIgnoreCase(value)) {
- return false; // ignored in this case
- } else {
- // either rename is specified or unsupported value - default to rename.
- return true;
- }
- }
-
- /**
* @see org.apache.cocoon.core.DynamicSettings#getReloadDelay(java.lang.String)
*/
public long getReloadDelay(String type) {
@@ -468,16 +342,6 @@
value = String.valueOf(this.getReloadDelay(null));
} else if ( key.equals(KEY_RELOADING) ) {
value = String.valueOf(this.isReloadingEnabled(null));
- } else if ( key.equals(KEY_UPLOADS_ENABLE) ) {
- value = String.valueOf(this.isEnableUploads());
- } else if ( key.equals(KEY_UPLOADS_DIRECTORY) ) {
- value = this.getUploadDirectory();
- } else if ( key.equals(KEY_UPLOADS_AUTOSAVE) ) {
- value = String.valueOf(this.isAutosaveUploads());
- } else if ( key.equals(KEY_UPLOADS_OVERWRITE) ) {
- value = this.getOverwriteUploads();
- } else if ( key.equals(KEY_UPLOADS_MAXSIZE) ) {
- value = String.valueOf(this.getMaxUploadSize());
} else if ( key.equals(KEY_CACHE_DIRECTORY) ) {
value = this.getCacheDirectory();
} else if ( key.equals(KEY_WORK_DIRECTORY) ) {
@@ -519,11 +383,6 @@
KEY_RELOADING + " : " + this.isReloadingEnabled(null) + '\n' +
KEY_LOAD_CLASSES + " : " + this.toString(this.getLoadClasses()) + '\n' +
KEY_MANAGE_EXCEPTIONS + " : " + this.isManageExceptions() + '\n' +
- KEY_UPLOADS_DIRECTORY + " : " + this.getUploadDirectory() + '\n' +
- KEY_UPLOADS_AUTOSAVE + " : " + this.isAutosaveUploads() + '\n' +
- KEY_UPLOADS_ENABLE + " : " + this.isEnableUploads() + '\n' +
- KEY_UPLOADS_MAXSIZE + " : " + this.getMaxUploadSize() + '\n' +
- KEY_UPLOADS_OVERWRITE + " : " + this.isAllowOverwrite() + '\n' +
KEY_CACHE_DIRECTORY + " : " + this.getCacheDirectory() + '\n' +
KEY_WORK_DIRECTORY + " : " + this.getWorkDirectory() + '\n' +
KEY_FORM_ENCODING + " : " + this.getFormEncoding() + '\n' +
@@ -570,15 +429,6 @@
}
/**
- * @param autosaveUploads The autosaveUploads to set.
- */
- public void setAutosaveUploads(boolean autosaveUploadsValue) {
- this.checkWriteable();
- this.checkSubSetting();
- this.autosaveUploads = autosaveUploadsValue;
- }
-
- /**
* @param cacheDirectory The cacheDirectory to set.
*/
public void setCacheDirectory(String cacheDirectory) {
@@ -588,15 +438,6 @@
}
/**
- * @param enableUploads The enableUploads to set.
- */
- public void setEnableUploads(boolean enableUploads) {
- this.checkWriteable();
- this.checkSubSetting();
- this.enableUploads = enableUploads;
- }
-
- /**
* @param formEncoding The formEncoding to set.
*/
public void setFormEncoding(String formEncoding) {
@@ -623,24 +464,6 @@
}
/**
- * @param maxUploadSize The maxUploadSize to set.
- */
- public void setMaxUploadSize(int maxUploadSize) {
- this.checkWriteable();
- this.checkSubSetting();
- this.maxUploadSize = maxUploadSize;
- }
-
- /**
- * @param overwriteUploads The overwriteUploads to set.
- */
- public void setOverwriteUploads(String overwriteUploads) {
- this.checkWriteable();
- this.checkSubSetting();
- this.overwriteUploads = overwriteUploads;
- }
-
- /**
* @param showTime The showTime to set.
*/
public void setShowTime(boolean showTime) {
@@ -656,15 +479,6 @@
this.checkWriteable();
this.checkSubSetting();
this.showCocoonVersion = showCocoonVersion;
- }
-
- /**
- * @param uploadDirectory The uploadDirectory to set.
- */
- public void setUploadDirectory(String uploadDirectory) {
- this.checkWriteable();
- this.checkSubSetting();
- this.uploadDirectory = uploadDirectory;
}
/**
Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/SettingsBeanFactoryPostProcessor.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/SettingsBeanFactoryPostProcessor.java?view=diff&rev=490021&r1=490020&r2=490021
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/SettingsBeanFactoryPostProcessor.java (original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/SettingsBeanFactoryPostProcessor.java Sun Dec 24 06:23:34 2006
@@ -102,22 +102,6 @@
}
}
- final String uploadDirParam = settings.getUploadDirectory();
- File uploadDir;
- if (uploadDirParam != null) {
- uploadDir = new File(uploadDirParam);
- if (this.logger.isDebugEnabled()) {
- this.logger.debug("Using upload-directory " + uploadDir);
- }
- } else {
- uploadDir = new File(workDir, "upload-dir" + File.separator);
- if (this.logger.isDebugEnabled()) {
- this.logger.debug("Using default upload-directory " + uploadDir);
- }
- }
- uploadDir.mkdirs();
- settings.setUploadDirectory(uploadDir.getAbsolutePath());
-
String cacheDirParam = settings.getCacheDirectory();
File cacheDir;
if (cacheDirParam != null) {
Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonContextFactoryBean.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonContextFactoryBean.java?view=diff&rev=490021&r1=490020&r2=490021
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonContextFactoryBean.java (original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/avalon/AvalonContextFactoryBean.java Sun Dec 24 06:23:34 2006
@@ -71,7 +71,6 @@
// add the Avalon context attributes that are contained in the settings
appContext.put(Constants.CONTEXT_WORK_DIR, new File(this.settings.getWorkDirectory()));
- appContext.put(Constants.CONTEXT_UPLOAD_DIR, new File(this.settings.getUploadDirectory()));
appContext.put(Constants.CONTEXT_CACHE_DIR, new File(this.settings.getCacheDirectory()));
appContext.put(Constants.CONTEXT_DEFAULT_ENCODING, this.settings.getFormEncoding());
Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/generation/StatusGenerator.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/generation/StatusGenerator.java?view=diff&rev=490021&r1=490020&r2=490021
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/generation/StatusGenerator.java (original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/generation/StatusGenerator.java Sun Dec 24 06:23:34 2006
@@ -462,7 +462,6 @@
this.addValue("Running mode", s.getRunningMode());
this.addMultilineValue(Settings.KEY_LOAD_CLASSES, s.getLoadClasses());
this.addValue(Settings.KEY_MANAGE_EXCEPTIONS, s.isManageExceptions());
- this.addValue(Settings.KEY_UPLOADS_DIRECTORY, s.getUploadDirectory());
this.addValue(Settings.KEY_CACHE_DIRECTORY, s.getCacheDirectory());
this.addValue(Settings.KEY_WORK_DIRECTORY, s.getWorkDirectory());
this.addValue(Settings.KEY_FORM_ENCODING, s.getFormEncoding());
@@ -486,10 +485,6 @@
final String value = s.getProperty(key);
this.addValue(key.substring(18), value);
}
- this.addValue(Settings.KEY_UPLOADS_AUTOSAVE, s.isAutosaveUploads());
- this.addValue(Settings.KEY_UPLOADS_ENABLE, s.isEnableUploads());
- this.addValue(Settings.KEY_UPLOADS_MAXSIZE, s.getMaxUploadSize());
- this.addValue(Settings.KEY_UPLOADS_OVERWRITE, s.isAllowOverwrite());
this.addValue(Settings.KEY_SHOWTIME, s.isShowTime());
this.addValue(Settings.KEY_HIDE_SHOWTIME, s.isHideShowTime());
this.addValue(Settings.KEY_SHOW_VERSION, s.isShowVersion());
Added: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/multipart/MultipartConfigurationHelper.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/multipart/MultipartConfigurationHelper.java?view=auto&rev=490021
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/multipart/MultipartConfigurationHelper.java (added)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/multipart/MultipartConfigurationHelper.java Sun Dec 24 06:23:34 2006
@@ -0,0 +1,234 @@
+package org.apache.cocoon.servlet.multipart;
+
+import java.io.File;
+
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.cocoon.configuration.Settings;
+import org.apache.commons.lang.BooleanUtils;
+
+public class MultipartConfigurationHelper {
+
+ public static final boolean ENABLE_UPLOADS = false;
+ public static final boolean SAVE_UPLOADS_TO_DISK = true;
+ public static final int MAX_UPLOAD_SIZE = 10000000; // 10Mb
+
+ /**
+ * This parameter allows to specify where Cocoon should put uploaded files.
+ * The path specified can be either absolute or relative to the context
+ * path of the servlet. On windows platform, absolute directory must start
+ * with volume: C:\Path\To\Upload\Directory.
+ */
+ String KEY_UPLOADS_DIRECTORY = "org.apache.cocoon.uploads.directory";
+
+ /**
+ * Causes all files in multipart requests to be processed.
+ * Default is false for security reasons.
+ */
+ String KEY_UPLOADS_ENABLE = "org.apache.cocoon.uploads.enable";
+
+ /**
+ * Causes all files in multipart requests to be saved to upload-dir.
+ * Default is true for security reasons.
+ */
+ String KEY_UPLOADS_AUTOSAVE = "org.apache.cocoon.uploads.autosave";
+
+ /**
+ * Specify handling of name conflicts when saving uploaded files to disk.
+ * Acceptable values are deny, allow, rename (default). Files are renamed
+ * x_filename where x is an integer value incremented to make the new
+ * filename unique.
+ */
+ String KEY_UPLOADS_OVERWRITE = "org.apache.cocoon.uploads.overwrite";
+
+ /**
+ * Specify maximum allowed size of the upload. Defaults to 10 Mb.
+ */
+ String KEY_UPLOADS_MAXSIZE = "org.apache.cocoon.uploads.maxsize";
+
+ /**
+ * Causes all files in multipart requests to be processed.
+ * Default is false for security reasons.
+ */
+ protected boolean enableUploads;
+
+ /**
+ * This parameter allows to specify where Cocoon should put uploaded files.
+ * The path specified can be either absolute or relative to the context
+ * path of the servlet. On windows platform, absolute directory must start
+ * with volume: C:\Path\To\Upload\Directory.
+ */
+ protected String uploadDirectory;
+
+ /**
+ * Causes all files in multipart requests to be saved to upload-dir.
+ * Default is true for security reasons.
+ */
+ protected boolean autosaveUploads;
+
+ /**
+ * Specify handling of name conflicts when saving uploaded files to disk.
+ * Acceptable values are deny, allow, rename (default). Files are renamed
+ * x_filename where x is an integer value incremented to make the new
+ * filename unique.
+ */
+ protected String overwriteUploads;
+
+ /**
+ * Specify maximum allowed size of the upload. Defaults to 10 Mb.
+ */
+ protected int maxUploadSize;
+
+ public MultipartConfigurationHelper() {
+ this.enableUploads = ENABLE_UPLOADS;
+ this.autosaveUploads = SAVE_UPLOADS_TO_DISK;
+ this.maxUploadSize = MAX_UPLOAD_SIZE;
+ }
+
+ /**
+ * Configure this from the settings object.
+ * @param settings
+ */
+ public void configure(Settings settings, Logger logger) {
+ String value;
+ value = settings.getProperty(KEY_UPLOADS_ENABLE);
+ if ( value != null ) {
+ this.setEnableUploads(BooleanUtils.toBoolean(value));
+ }
+ value = settings.getProperty(KEY_UPLOADS_DIRECTORY);
+ if ( value != null ) {
+ this.setUploadDirectory(value);
+ }
+ value = settings.getProperty(KEY_UPLOADS_AUTOSAVE);
+ if ( value != null ) {
+ this.setAutosaveUploads(BooleanUtils.toBoolean(value));
+ }
+ value = settings.getProperty(KEY_UPLOADS_OVERWRITE);
+ if ( value != null ) {
+ this.setOverwriteUploads(value);
+ }
+ value = settings.getProperty(KEY_UPLOADS_MAXSIZE);
+ if ( value != null ) {
+ this.setMaxUploadSize(Integer.valueOf(value).intValue());
+ }
+ final String uploadDirParam = this.getUploadDirectory();
+ File uploadDir;
+ if (uploadDirParam != null) {
+ uploadDir = new File(uploadDirParam);
+ if (logger.isDebugEnabled()) {
+ logger.debug("Using upload-directory " + uploadDir);
+ }
+ } else {
+ uploadDir = new File(settings.getWorkDirectory(), "upload-dir" + File.separator);
+ if (logger.isDebugEnabled()) {
+ logger.debug("Using default upload-directory " + uploadDir);
+ }
+ }
+ uploadDir.mkdirs();
+ this.setUploadDirectory(uploadDir.getAbsolutePath());
+ }
+
+ /**
+ * @return Returns the autosaveUploads.
+ * @see #KEY_UPLOADS_AUTOSAVE
+ */
+ public boolean isAutosaveUploads() {
+ return this.autosaveUploads;
+ }
+
+ /**
+ * @return Returns the enableUploads.
+ * @see #KEY_UPLOADS_ENABLE
+ */
+ public boolean isEnableUploads() {
+ return this.enableUploads;
+ }
+
+ /**
+ * @return Returns the maxUploadSize.
+ * @see #KEY_UPLOADS_MAXSIZE
+ */
+ public int getMaxUploadSize() {
+ return this.maxUploadSize;
+ }
+
+ /**
+ * @return Returns the overwriteUploads.
+ * @see #KEY_UPLOADS_OVERWRITE
+ */
+ public String getOverwriteUploads() {
+ return this.overwriteUploads;
+ }
+
+ /**
+ * @return Returns the uploadDirectory.
+ * @see #KEY_UPLOADS_DIRECTORY
+ */
+ public String getUploadDirectory() {
+ return this.uploadDirectory;
+ }
+
+ /**
+ * @see org.apache.cocoon.core.DynamicSettings#isAllowOverwrite()
+ */
+ public boolean isAllowOverwrite() {
+ final String value = this.getOverwriteUploads();
+ if ("deny".equalsIgnoreCase(value)) {
+ return false;
+ } else if ("allow".equalsIgnoreCase(value)) {
+ return true;
+ } else {
+ // either rename is specified or unsupported value - default to rename.
+ return false;
+ }
+ }
+
+ /**
+ * @see org.apache.cocoon.core.DynamicSettings#isSilentlyRename()
+ */
+ public boolean isSilentlyRename() {
+ final String value = this.getOverwriteUploads();
+ if ("deny".equalsIgnoreCase(value)) {
+ return false;
+ } else if ("allow".equalsIgnoreCase(value)) {
+ return false; // ignored in this case
+ } else {
+ // either rename is specified or unsupported value - default to rename.
+ return true;
+ }
+ }
+
+ /**
+ * @param autosaveUploads The autosaveUploads to set.
+ */
+ public void setAutosaveUploads(boolean autosaveUploadsValue) {
+ this.autosaveUploads = autosaveUploadsValue;
+ }
+
+ /**
+ * @param enableUploads The enableUploads to set.
+ */
+ public void setEnableUploads(boolean enableUploads) {
+ this.enableUploads = enableUploads;
+ }
+
+ /**
+ * @param maxUploadSize The maxUploadSize to set.
+ */
+ public void setMaxUploadSize(int maxUploadSize) {
+ this.maxUploadSize = maxUploadSize;
+ }
+
+ /**
+ * @param overwriteUploads The overwriteUploads to set.
+ */
+ public void setOverwriteUploads(String overwriteUploads) {
+ this.overwriteUploads = overwriteUploads;
+ }
+
+ /**
+ * @param uploadDirectory The uploadDirectory to set.
+ */
+ public void setUploadDirectory(String uploadDirectory) {
+ this.uploadDirectory = uploadDirectory;
+ }
+}
Propchange: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/multipart/MultipartConfigurationHelper.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/multipart/MultipartConfigurationHelper.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/multipart/MultipartFilter.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/multipart/MultipartFilter.java?view=diff&rev=490021&r1=490020&r2=490021
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/multipart/MultipartFilter.java (original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/multipart/MultipartFilter.java Sun Dec 24 06:23:34 2006
@@ -58,27 +58,14 @@
/** The root settings. */
protected Settings settings;
+ /** The servlet context. */
+ protected ServletContext servletContext;
+
/**
* @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
*/
public void init(FilterConfig config) throws ServletException {
- String containerEncoding;
- ServletContext servletContext = config.getServletContext();
- this.cocoonBeanFactory = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
- this.settings = (Settings) this.cocoonBeanFactory.getBean(Settings.ROLE);
- final String encoding = settings.getContainerEncoding();
- if ( encoding == null ) {
- containerEncoding = "ISO-8859-1";
- } else {
- containerEncoding = encoding;
- }
- this.requestFactory = new RequestFactory(this.settings.isAutosaveUploads(),
- new File(this.settings.getUploadDirectory()),
- this.settings.isAllowOverwrite(),
- this.settings.isSilentlyRename(),
- this.settings.getMaxUploadSize(),
- containerEncoding);
- this.log = (Logger) this.cocoonBeanFactory.getBean(AvalonUtils.LOGGER_ROLE);
+ this.servletContext = config.getServletContext();
}
/**
@@ -88,10 +75,37 @@
// nothing to do
}
+ protected synchronized void configure() {
+ if ( this.cocoonBeanFactory == null ) {
+ this.cocoonBeanFactory = WebApplicationContextUtils.getRequiredWebApplicationContext(this.servletContext);
+ this.log = (Logger) this.cocoonBeanFactory.getBean(AvalonUtils.LOGGER_ROLE);
+ this.settings = (Settings) this.cocoonBeanFactory.getBean(Settings.ROLE);
+ String containerEncoding;
+ final String encoding = settings.getContainerEncoding();
+ if ( encoding == null ) {
+ containerEncoding = "ISO-8859-1";
+ } else {
+ containerEncoding = encoding;
+ }
+ final MultipartConfigurationHelper config = new MultipartConfigurationHelper();
+ config.configure(this.settings, this.log);
+ this.requestFactory = new RequestFactory(config.isAutosaveUploads(),
+ new File(config.getUploadDirectory()),
+ config.isAllowOverwrite(),
+ config.isSilentlyRename(),
+ config.getMaxUploadSize(),
+ containerEncoding);
+ }
+ }
+
/**
* @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
*/
- public void doFilter(ServletRequest req, ServletResponse res, FilterChain filterChain) throws IOException, ServletException {
+ public void doFilter(ServletRequest req, ServletResponse res, FilterChain filterChain)
+ throws IOException, ServletException {
+ if ( this.cocoonBeanFactory == null ) {
+ this.configure();
+ }
// get the request (wrapped if contains multipart-form data)
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res;