Changeset 1509
- Timestamp:
- 2008-02-13 23:08:27 (6 months ago)
- Location:
- FCKeditor.Java/branches/2.4/src
- Files:
-
- 1 removed
- 6 modified
- 2 moved
-
main/java/net/fckeditor/connector/ConnectorServlet.java (modified) (8 diffs)
-
main/java/net/fckeditor/FCKeditor.java (modified) (3 diffs)
-
main/java/net/fckeditor/handlers/ConfigurationHandler.java (modified) (6 diffs)
-
main/java/net/fckeditor/handlers/ExtensionsHandler.java (modified) (7 diffs)
-
main/java/net/fckeditor/handlers/FileTypeHandler.java (deleted)
-
main/java/net/fckeditor/ResourceType.java (moved) (moved from FCKeditor.Java/branches/2.4/src/main/java/net/fckeditor/FileType.java) (1 diff)
-
main/resources/net/fckeditor/handlers/default.properties (modified) (1 diff)
-
test/java/net/fckeditor/handlers/ExtensionsHandlerTest.java (modified) (3 diffs)
-
test/java/net/fckeditor/handlers/ResourceTypeTest.java (moved) (moved from FCKeditor.Java/branches/2.4/src/test/java/net/fckeditor/handlers/FileTypeHandlerTest.java) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
FCKeditor.Java/branches/2.4/src/main/java/net/fckeditor/connector/ConnectorServlet.java
r1478 r1509 45 45 import javax.xml.transform.stream.StreamResult; 46 46 47 import net.fckeditor. FileType;47 import net.fckeditor.ResourceType; 48 48 import net.fckeditor.handlers.ConfigurationHandler; 49 49 import net.fckeditor.handlers.ExtensionsHandler; 50 import net.fckeditor.handlers.FileTypeHandler;51 50 import net.fckeditor.tool.UploadResponse; 52 51 import net.fckeditor.tool.Utils; … … 96 95 // read the optional parameters 97 96 ConfigurationHandler.setForceSingleExtension(getInitParameter("ForceSingleExtension")); 98 if (getInitParameter(" baseDir") != null) // TODO should 'baseDir' contains '..' ??99 ConfigurationHandler.set BaseDir(getInitParameter("baseDir"));100 101 setExtension( FileType.FILE, getInitParameter("AllowedExtensionsFile"),97 if (getInitParameter("UserFilesPath") != null) // TODO should 'baseDir' contains '..' ?? 98 ConfigurationHandler.setUserFilesPath(getInitParameter("UserFilesPath")); 99 100 setExtension(ResourceType.File, getInitParameter("AllowedExtensionsFile"), 102 101 getInitParameter("DeniedExtensionsFile")); 103 setExtension( FileType.IMAGE, getInitParameter("AllowedExtensionsImage"),102 setExtension(ResourceType.Image, getInitParameter("AllowedExtensionsImage"), 104 103 getInitParameter("DeniedExtensionsImage")); 105 setExtension( FileType.FLASH, getInitParameter("AllowedExtensionsFlash"),104 setExtension(ResourceType.Flash, getInitParameter("AllowedExtensionsFlash"), 106 105 getInitParameter("DeniedExtensionsFlash")); 107 setExtension( FileType.MEDIA, getInitParameter("AllowedExtensionsMedia"),106 setExtension(ResourceType.Media, getInitParameter("AllowedExtensionsMedia"), 108 107 getInitParameter("DeniedExtensionsMedia")); 109 108 110 109 // check, if 'baseDir' exists 111 110 String realBaseDir = getServletContext().getRealPath( 112 ConfigurationHandler.getDefault BaseDir());111 ConfigurationHandler.getDefaultUserFilesPath()); 113 112 File baseFile = new File(realBaseDir); 114 113 if (!baseFile.exists()) { … … 140 139 String typeStr = request.getParameter("Type"); 141 140 String currentFolderStr = request.getParameter("CurrentFolder"); 142 FileType fileType = FileTypeHandler.getTypeDefault(typeStr);141 ResourceType fileType = ResourceType.getDefaultResourceType(typeStr); 143 142 144 143 logger.debug("Parameter Command: {}", commandStr); … … 239 238 String typeStr = request.getParameter("Type"); 240 239 String currentFolderStr = request.getParameter("CurrentFolder"); 241 if (! FileTypeHandler.isValid(typeStr))240 if (!ResourceType.isValid(typeStr)) 242 241 logger.warn("Unknown Type requested: {}", typeStr); 243 242 … … 251 250 } 252 251 253 FileType fileType = FileTypeHandler.getTypeDefault(typeStr);252 ResourceType fileType = ResourceType.getDefaultResourceType(typeStr); 254 253 255 254 UploadResponse ur = null; … … 283 282 String extension = FilenameUtils.getExtension(filename); 284 283 285 boolean validExtension = ExtensionsHandler.isAllowed(FileTypeHandler 286 .getType(typeStr), extension); 284 boolean validExtension = ExtensionsHandler.isAllowed(fileType, extension); 287 285 288 286 if (!validExtension) … … 378 376 } 379 377 380 private String constructTypeBasedFolderString(final FileType fileType,378 private String constructTypeBasedFolderString(final ResourceType fileType, 381 379 final String currentFolderString, final HttpServletRequest request) { 382 380 StringWriter retval = new StringWriter(); 383 retval.append(ConfigurationHandler.get BaseDir(request));384 retval.append( FileTypeHandler.getSubDirForType(fileType));381 retval.append(ConfigurationHandler.getUserFilesPath(request)); 382 retval.append(fileType.getPath()); 385 383 retval.append(currentFolderString); 386 384 return replaceAll(retval.toString(), "//", "/"); … … 397 395 * if allowed and denied extensions are set. 398 396 */ 399 private void setExtension(final FileType type, final String allowedList, final String deniedList) {397 private void setExtension(final ResourceType type, final String allowedList, final String deniedList) { 400 398 // if both lists are set, we have to throw an error, because only one list should be set 401 399 if (Utils.isNotEmpty(allowedList) && Utils.isNotEmpty(deniedList)) { -
FCKeditor.Java/branches/2.4/src/main/java/net/fckeditor/FCKeditor.java
r1507 r1509 41 41 private String instanceName; 42 42 private String value; 43 private String basePath = ConfigurationHandler.get FckEditorDir();43 private String basePath = ConfigurationHandler.getBasePath(); 44 44 private String toolbarSet = ConfigurationHandler.getFckEditorToolbarSet(); 45 45 private String width = ConfigurationHandler.getFckEditorWidth(); … … 51 51 * Initialize the object setting all basic configurations.<br> 52 52 * 53 * The basePath is context root + {@link ConfigurationHandler#get FckEditorDir()}.53 * The basePath is context root + {@link ConfigurationHandler#getBasePath()}. 54 54 * 55 55 * @param request … … 82 82 else 83 83 this.basePath = request.getContextPath() 84 + ConfigurationHandler.get FckEditorDir();84 + ConfigurationHandler.getBasePath(); 85 85 86 86 config = new FCKeditorConfig(); -
FCKeditor.Java/branches/2.4/src/main/java/net/fckeditor/handlers/ConfigurationHandler.java
r1492 r1509 48 48 * Something special is {@link ISessionData}. The implemented class provides some session based data. 49 49 * See {@link ISessionData} for additional informations. For example, to get a user based base dir, 50 * for each request {@link #get BaseDir(HttpServletRequest)} is calling. If 'sessionData' is set,50 * for each request {@link #getUserFilesPath(HttpServletRequest)} is calling. If 'sessionData' is set, 51 51 * {@link ISessionData#getBaseDir(HttpServletRequest)} will be returned, otherwise the default base 52 52 * dir. … … 58 58 59 59 private static Properties defaultProperties = new Properties(); 60 private static String baseDir;60 private static String userFilesPath; 61 61 private static ISessionData sessionData = null; 62 private static String fckEditorDir;62 private static String basePath; 63 63 private static String fckEditorHeight; 64 64 private static String fckEditorWidth; … … 82 82 throw new RuntimeException("Can't load default properties!", e); 83 83 } 84 baseDir = defaultProperties.getProperty("fckeditor.basedir");85 fckEditorDir = defaultProperties.getProperty("fckeditor.dir");84 userFilesPath = defaultProperties.getProperty("connector.userFilesPath"); 85 basePath = defaultProperties.getProperty("fckeditor.basePath"); 86 86 fckEditorWidth = defaultProperties.getProperty("fckeditor.width"); 87 87 fckEditorHeight = defaultProperties.getProperty("fckeditor.height"); 88 fckEditorToolbarSet = defaultProperties.getProperty("fckeditor.toolbar set");88 fckEditorToolbarSet = defaultProperties.getProperty("fckeditor.toolbarSet"); 89 89 forceSingleExtension = Boolean.valueOf(defaultProperties 90 .getProperty(" fckeditor.forcesingleextension"));90 .getProperty("connector.forceSingleExtension")); 91 91 92 92 logger.info("Default properties loaded and initialized successfully."); … … 99 99 * {@link ISessionData}} isn't set. 100 100 */ 101 public static String get BaseDir(final HttpServletRequest servletRequest) {101 public static String getUserFilesPath(final HttpServletRequest servletRequest) { 102 102 if (sessionData == null || sessionData.getBaseDir(servletRequest) == null) 103 return getDefault BaseDir();103 return getDefaultUserFilesPath(); 104 104 return sessionData.getBaseDir(servletRequest); 105 105 } 106 106 107 107 /** 108 * Getter for the default baseDir.108 * Getter for the default userFilesPath. 109 109 * 110 110 * @return 111 111 */ 112 public static String getDefault BaseDir() {113 return baseDir;114 } 115 116 /** 117 * Setter for the base dir (using for user files). If param ' baseDir' is empty, the property112 public static String getDefaultUserFilesPath() { 113 return userFilesPath; 114 } 115 116 /** 117 * Setter for the base dir (using for user files). If param 'userFilesPath' is empty, the property 118 118 * leaves untouched. 119 119 * 120 * @param baseDir120 * @param userFilesPath 121 121 * relative to the context root (no leading or ending /). 122 122 */ 123 public static void set BaseDir(final String baseDir) {124 if (Utils.isNotEmpty( baseDir))125 ConfigurationHandler. baseDir = baseDir;123 public static void setUserFilesPath(final String userFilesPath) { 124 if (Utils.isNotEmpty(userFilesPath)) 125 ConfigurationHandler.userFilesPath = userFilesPath; 126 126 } 127 127 … … 154 154 * @return Dir of the fckeditor relative to the context root. 155 155 */ 156 public static String get FckEditorDir() {157 return fckEditorDir;156 public static String getBasePath() { 157 return basePath; 158 158 } 159 159 … … 161 161 * Setter for the dir of the fckeditor. 162 162 * 163 * @param fckEditorDir163 * @param basePath 164 164 * relative to the context root (no leading or ending /). 165 165 */ 166 166 public static void setFckEditorDir(final String fckEditorDir) { 167 ConfigurationHandler. fckEditorDir= fckEditorDir;167 ConfigurationHandler.basePath = fckEditorDir; 168 168 } 169 169 -
FCKeditor.Java/branches/2.4/src/main/java/net/fckeditor/handlers/ExtensionsHandler.java
r1455 r1509 25 25 import java.util.Set; 26 26 27 import net.fckeditor. FileType;27 import net.fckeditor.ResourceType; 28 28 import net.fckeditor.tool.Utils; 29 29 … … 40 40 public class ExtensionsHandler { 41 41 42 private static Map< FileType, Set<String>> extensionsAllowed = new HashMap<FileType, Set<String>>();43 private static Map< FileType, Set<String>> extensionsDenied = new HashMap<FileType, Set<String>>();42 private static Map<ResourceType, Set<String>> extensionsAllowed = new HashMap<ResourceType, Set<String>>(); 43 private static Map<ResourceType, Set<String>> extensionsDenied = new HashMap<ResourceType, Set<String>>(); 44 44 45 45 static { 46 46 // load defaults 47 extensionsAllowed.put( FileType.FILE, Utils.getSet(ConfigurationHandler48 .getDefaultProperty(" fckeditor.file.extensions.allowed")));49 extensionsDenied.put( FileType.FILE, Utils.getSet(ConfigurationHandler50 .getDefaultProperty(" fckeditor.file.extensions.denied")));51 extensionsAllowed.put( FileType.MEDIA, Utils.getSet(ConfigurationHandler52 .getDefaultProperty(" fckeditor.media.extensions.allowed")));53 extensionsDenied.put( FileType.MEDIA, Utils.getSet(ConfigurationHandler54 .getDefaultProperty(" fckeditor.media.extensions.denied")));55 extensionsAllowed.put( FileType.IMAGE, Utils.getSet(ConfigurationHandler56 .getDefaultProperty(" fckeditor.image.extensions.allowed")));57 extensionsDenied.put( FileType.IMAGE, Utils.getSet(ConfigurationHandler58 .getDefaultProperty(" fckeditor.image.extensions.denied")));59 extensionsAllowed.put( FileType.FLASH, Utils.getSet(ConfigurationHandler60 .getDefaultProperty(" fckeditor.flash.extensions.allowed")));61 extensionsDenied.put( FileType.FLASH, Utils.getSet(ConfigurationHandler62 .getDefaultProperty(" fckeditor.flash.extensions.denied")));47 extensionsAllowed.put(ResourceType.File, Utils.getSet(ConfigurationHandler 48 .getDefaultProperty("connector.extensions.file.allowed"))); 49 extensionsDenied.put(ResourceType.File, Utils.getSet(ConfigurationHandler 50 .getDefaultProperty("connector.extensions.file.denied"))); 51 extensionsAllowed.put(ResourceType.Media, Utils.getSet(ConfigurationHandler 52 .getDefaultProperty("connector.extensions.media.allowed"))); 53 extensionsDenied.put(ResourceType.Media, Utils.getSet(ConfigurationHandler 54 .getDefaultProperty("connector.extensions.media.denied"))); 55 extensionsAllowed.put(ResourceType.Image, Utils.getSet(ConfigurationHandler 56 .getDefaultProperty("connector.extensions.image.allowed"))); 57 extensionsDenied.put(ResourceType.Image, Utils.getSet(ConfigurationHandler 58 .getDefaultProperty("connector.extensions.image.denied"))); 59 extensionsAllowed.put(ResourceType.Flash, Utils.getSet(ConfigurationHandler 60 .getDefaultProperty("connector.extensions.flash.allowed"))); 61 extensionsDenied.put(ResourceType.Flash, Utils.getSet(ConfigurationHandler 62 .getDefaultProperty("connector.extensions.flash.denied"))); 63 63 } 64 64 … … 70 70 * @return Set of allowed extensions or an empty set. 71 71 */ 72 public static Set<String> getExtensionsAllowed(final FileType type) {72 public static Set<String> getExtensionsAllowed(final ResourceType type) { 73 73 return extensionsAllowed.get(type); 74 74 } … … 83 83 * Required format: <code>ext1|ext2|ext3</code> 84 84 */ 85 public static void setExtensionsAllowed(final FileType type, final String extensionsList) {85 public static void setExtensionsAllowed(final ResourceType type, final String extensionsList) { 86 86 if (extensionsList != null) { 87 87 extensionsAllowed.put(type, Utils.getSet(extensionsList)); … … 97 97 * @return Set of denied extensions or an empty set. 98 98 */ 99 public static Set<String> getExtensionsDenied(final FileType type) {99 public static Set<String> getExtensionsDenied(final ResourceType type) { 100 100 return extensionsDenied.get(type); 101 101 } … … 110 110 * Required format: <code>ext1|ext2|ext3</code> 111 111 */ 112 public static void setExtensionsDenied(final FileType type, final String extensionsList) {112 public static void setExtensionsDenied(final ResourceType type, final String extensionsList) { 113 113 if (extensionsList != null) { 114 114 extensionsDenied.put(type, Utils.getSet(extensionsList)); … … 124 124 * @return True, false. False is returned too, if 'type' or 'extensions' is null. 125 125 */ 126 public static boolean isAllowed(final FileType type, final String extension) {126 public static boolean isAllowed(final ResourceType type, final String extension) { 127 127 if (type == null || extension == null) 128 128 return false; -
FCKeditor.Java/branches/2.4/src/main/java/net/fckeditor/ResourceType.java
r1455 r1509 21 21 package net.fckeditor; 22 22 23 24 23 /** 25 24 * The different types of files to work with. 26 * 25 * 27 26 * @version $Id$ 28 27 */ 29 public enum FileType { 30 FILE, // the defaults 31 IMAGE, 32 FLASH, 33 MEDIA 28 public enum ResourceType { 29 30 Image, File, Flash, Media; 31 32 public String getPath() { 33 return "/" + name().toLowerCase(); 34 } 35 36 public static ResourceType getDefaultResourceType(String name) { 37 38 ResourceType rt = getResourceType(name); 39 40 return rt == null ? File : rt; 41 42 } 43 44 public static ResourceType getResourceType(String name) { 45 46 try { 47 return ResourceType.valueOf(name); 48 } catch (IllegalArgumentException e) { 49 return null; 50 } catch (NullPointerException e) { 51 return null; 52 } 53 } 54 55 public static boolean isValid(final String name) { 56 return getResourceType(name) == null ? false : true; 57 } 58 34 59 } -
FCKeditor.Java/branches/2.4/src/main/resources/net/fckeditor/handlers/default.properties
r1500 r1509 4 4 ## @version $Id: default.properties 1184 2008-01-03 10:39:36Z th-schwarz $ 5 5 6 # default extensions settings 7 connector.extensions.file.denied = php|php3|php5|phtml|asp|aspx|ascx|jsp|cfm|cfc|pl|bat|exe|dll|reg|cgi 8 connector.extensions.flash.allowed = swf|fla 9 connector.extensions.image.allowed = jpg|gif|jpeg|png|bmp 10 connector.extensions.link.allowed = 7z|aiff|asf|avi|bmp|csv|doc|fla|flv|gif|gz|gzip|jpeg|jpg|mid|mov|mp3|mp4|mpc|mpeg|mpg|ods|odt|pdf|png|ppt|pxd|qt|ram|rar|rm|rmi|rmvb|rtf|sdc|sitd|swf|sxc|sxw|tar|tgz|tif|tiff|txt|vsd|wav|wma|wmv|xls|xml|zip 11 12 # Due to security issues with Apache modules, it is recommended to leave this setting enabled. 13 connector.forceSingleExtension = true 14 6 15 # base directory for the user files relative to the context root (starting / and no ending /) 7 fckeditor.basedir= /userfiles16 connector.userFilesPath = /userfiles 8 17 9 18 # directory of the editor relative to the context root according to fckeditor.js (trailing slashes!) 10 fckeditor.dir = /fckeditor/ 11 12 # default extensions settings 13 fckeditor.file.extensions.denied = php|php3|php5|phtml|asp|aspx|ascx|jsp|cfm|cfc|pl|bat|exe|dll|reg|cgi 14 fckeditor.flash.extensions.denied = swf|fla 15 fckeditor.image.extensions.allowed = jpg|gif|jpeg|png|bmp 16 17 # Due to security issues with Apache modules, it is recommended to leave this setting enabled. 18 fckeditor.forcesingleextension = true 19 fckeditor.basePath = /fckeditor/ 19 20 20 21 # default height of the editor 21 22 fckeditor.height = 200 22 23 23 # sub-directories for each file type24 fckeditor.subdir.media.file = /file25 fckeditor.subdir.media.flash = /flash26 fckeditor.subdir.media.image = /image27 fckeditor.subdir.media.media = /media28 29 24 # default toolbar set of the editor 30 fckeditor.toolbar set = Default25 fckeditor.toolbarSet = Default 31 26 32 27 # default width of the editor -
FCKeditor.Java/branches/2.4/src/test/java/net/fckeditor/handlers/ExtensionsHandlerTest.java
r1455 r1509 23 23 import static org.junit.Assert.assertFalse; 24 24 import static org.junit.Assert.assertTrue; 25 import net.fckeditor. FileType;25 import net.fckeditor.ResourceType; 26 26 27 27 import org.junit.Test; … … 36 36 @Test 37 37 public void testIsAllowed01() { 38 FileType type = FileType.FILE;38 ResourceType type = ResourceType.File; 39 39 ExtensionsHandler.setExtensionsAllowed(type, "a"); 40 40 ExtensionsHandler.setExtensionsDenied(type, "b"); … … 48 48 @Test 49 49 public void testIsAllowed02() { 50 FileType type = FileType.FILE;50 ResourceType type = ResourceType.File; 51 51 ExtensionsHandler.setExtensionsAllowed(type, "a|b|c"); 52 52 assertTrue(ExtensionsHandler.isAllowed(type, "a")); -
FCKeditor.Java/branches/2.4/src/test/java/net/fckeditor/handlers/ResourceTypeTest.java
r1455 r1509 22 22 23 23 import static org.junit.Assert.*; 24 25 import net.fckeditor.FileType; 24 import net.fckeditor.ResourceType; 26 25 27 26 import org.junit.Test; … … 29 28 /** 30 29 * Tests for {@link FileTypeHandler}. 31 * 30 * 32 31 * @version $Id$ 33 32 */ 34 public class FileTypeHandlerTest { 35 36 37 @Test 38 public void getType01() throws Exception { 39 assertTrue(FileTypeHandler.getType("xyz") == null); 40 } 33 public class ResourceTypeTest { 41 34 42 35 @Test 43 public void getType02() throws Exception {44 assertTrue(FileTypeHandler.getType("file") == FileType.FILE);45 }36 public void getType01() throws Exception { 37 assertNull(ResourceType.getResourceType("xyz")); 38 } 46 39 47 40 @Test 48 public void getType03() throws Exception { 49 assertTrue(FileTypeHandler.getType("FiLe") == FileType.FILE); 50 } 51 52 @Test 53 public void getType04() throws Exception { 54 assertTrue(FileTypeHandler.getType("IMAGE") == FileType.IMAGE); 55 } 56 57 @Test 58 public void isValid01() throws Exception { 59 assertFalse(FileTypeHandler.isValid("1234")); 60 } 61 62 @Test 63 public void isValid02() throws Exception { 64 assertTrue(FileTypeHandler.isValid("fLash")); 65 } 41 public void getType02() throws Exception { 42 assertEquals(ResourceType.File, ResourceType.getResourceType("File")); 43 } 66 44 67 45 @Test 68 public void isValid03() throws Exception { 69 assertTrue(FileTypeHandler.isValid("MeDiA")); 70 } 71 72 @Test 73 public void getTypeDefault01() throws Exception { 74 assertTrue(FileTypeHandler.getTypeDefault("wrong-type").equals(FileType.FILE)); 75 } 46 public void getType03() throws Exception { 47 assertEquals(ResourceType.Image, ResourceType.getResourceType("Image")); 48 } 76 49 77 50 @Test 78 public void getTypeDefault02() throws Exception { 79 assertTrue(FileTypeHandler.getTypeDefault("flAsh").equals(FileType.FLASH)); 80 } 81 82 @Test 83 public void getSubDirForType01() throws Exception { 84 assertTrue(FileTypeHandler.getSubDirForType(null).equals("/file")); 85 } 51 public void isValid01() throws Exception { 52 assertFalse(ResourceType.isValid("1234")); 53 } 86 54 87 55 @Test 88 public void getSubDirForType02() throws Exception { 89 assertTrue(FileTypeHandler.getSubDirForType(FileType.FILE).equals("/file")); 90 } 56 public void isValid02() throws Exception { 57 assertFalse(ResourceType.isValid("fLash")); 58 } 59 60 @Test 61 public void isValid03() throws Exception { 62 assertFalse(ResourceType.isValid("MeDiA")); 63 } 64 65 @Test 66 public void getTypeDefault01() throws Exception { 67