Index: /FCKeditor.Java/branches/2.4/src/main/java/net/fckeditor/connector/ConnectorServlet.java
===================================================================
--- /FCKeditor.Java/branches/2.4/src/main/java/net/fckeditor/connector/ConnectorServlet.java	(revision 1525)
+++ /FCKeditor.Java/branches/2.4/src/main/java/net/fckeditor/connector/ConnectorServlet.java	(revision 1526)
@@ -68,9 +68,10 @@
  * Servlet to upload and browse files.<br>
  * 
- * This servlet accepts 4 commands used to retrieve and create files and folders from a server
- * directory. The allowed commands are:
+ * This servlet accepts 4 commands used to retrieve and create files and folders
+ * from a server directory. The allowed commands are:
  * <ul>
  * <li>GetFolders: Retrive the list of directory under the current folder
- * <li>GetFoldersAndFiles: Retrive the list of files and directory under the current folder
+ * <li>GetFoldersAndFiles: Retrive the list of files and directory under the
+ * current folder
  * <li>CreateFolder: Create a new directory under the current folder
  * <li>FileUpload: Send a new file to the server (must be sent with a POST)
@@ -82,5 +83,6 @@
 
 	private static final long serialVersionUID = -5742008970929377161L;
-	private static final Logger logger = LoggerFactory.getLogger(ConnectorServlet.class);
+	private static final Logger logger = LoggerFactory
+			.getLogger(ConnectorServlet.class);
 
 	/**
@@ -95,6 +97,14 @@
 		// read the optional parameters
 		ConfigurationHandler.setForceSingleExtension(getInitParameter("ForceSingleExtension"));
-		if (getInitParameter("UserFilesPath") != null) // TODO should 'baseDir' contains '..' ??
-			ConfigurationHandler.setUserFilesPath(getInitParameter("UserFilesPath"));
+		if (getInitParameter("UserFilesPath") != null) {
+			if (!Utils.isValidPath(getInitParameter("UserFilesPath"))) {
+				logger
+						.warn("UserFilesPath is an illegal reference, using default path");
+				ConfigurationHandler.setUserFilesPath(ConfigurationHandler
+						.getDefaultUserFilesPath());
+			}
+		} else
+			ConfigurationHandler
+					.setUserFilesPath(getInitParameter("UserFilesPath"));
 
 		setExtension(ResourceType.FILE, getInitParameter("AllowedExtensionsFile"),
@@ -124,9 +134,10 @@
 	 * connector?Command=CommandName&Type=ResourceType&CurrentFolder=FolderPath<br>
 	 * <br>
-	 * It executes the command and then return the results to the client in XML format.
+	 * It executes the command and then return the results to the client in XML
+	 * format.
 	 * 
 	 */
 	public void doGet(HttpServletRequest request, HttpServletResponse response)
-	        throws ServletException, IOException {
+			throws ServletException, IOException {
 		logger.debug("Entering ConnectorServlet#doGet");
 
@@ -145,10 +156,11 @@
 		logger.debug("Parameter Type: {}", typeStr);
 
-		// TODO untersuchen wie es vom Res Browser kommt
-		String currentPath = constructTypeBasedFolderString(fileType, currentFolderStr, request);
+		String currentPath = constructTypeBasedFolderString(fileType,
+				currentFolderStr, request);
 		String currentDirPath = getServletContext().getRealPath(currentPath);
 
 		File currentDir = new File(currentDirPath);
-		if (!currentDir.exists() && ConfigurationHandler.isEnabledForFileBrowsing(request)) {
+		if (!currentDir.exists()
+				&& ConfigurationHandler.isEnabledForFileBrowsing(request)) {
 			currentDir.mkdirs();
 			logger.debug("Dir successfully created: {}", currentDirPath);
@@ -157,18 +169,20 @@
 		Document document = null;
 		try {
-			DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+			DocumentBuilderFactory factory = DocumentBuilderFactory
+					.newInstance();
 			DocumentBuilder builder = factory.newDocumentBuilder();
 			document = builder.newDocument();
 		} catch (ParserConfigurationException pce) {
 			logger.error("Error while building new XML document", pce);
-			// FIXME servlet cannot go on working if building fails 
-		}
-
-		Node root = createCommonXml(document, commandStr, typeStr, currentFolderStr, request
-		        .getContextPath().concat(currentPath));
+			// FIXME servlet cannot go on working if building fails
+		}
+
+		Node root = createCommonXml(document, commandStr, typeStr,
+				currentFolderStr, request.getContextPath().concat(currentPath));
 
 		if (!ConfigurationHandler.isEnabledForFileBrowsing(request)) {
-			createResponse("1", "The current user isn't authorized for file browsing!", root,
-			        document);
+			createResponse("1",
+					"The current user isn't authorized for file browsing!",
+					root, document);
 		} else if (commandStr.equals("GetFolders")) {
 			getFolders(currentDir, root, document);
@@ -208,6 +222,7 @@
 
 		} catch (Exception e) {
-			// FIXME servlet cannot go on working if transforming fails 
-			logger.error("Error while transforming DOM to HttpServletResponse", e);
+			// FIXME servlet cannot go on working if transforming fails
+			logger.error("Error while transforming DOM to HttpServletResponse",
+					e);
 		}
 
@@ -223,10 +238,10 @@
 	 * connector?Command=FileUpload&Type=ResourceType&CurrentFolder=FolderPath<br>
 	 * <br>
-	 * It store the file (renaming it in case a file with the same name exists) and then return an
-	 * HTML file with a javascript command in it.
+	 * It store the file (renaming it in case a file with the same name exists)
+	 * and then return an HTML file with a javascript command in it.
 	 * 
 	 */
 	public void doPost(HttpServletRequest request, HttpServletResponse response)
-	        throws ServletException, IOException {
+			throws ServletException, IOException {
 		logger.debug("Entering Connector#doPost");
 
@@ -239,9 +254,9 @@
 		String typeStr = request.getParameter("Type");
 		String currentFolderStr = request.getParameter("CurrentFolder");
-		
+
 		logger.debug("Parameter Command: {}", commandStr);
 		logger.debug("Parameter CurrentFolder: {}", currentFolderStr);
 		logger.debug("Parameter Type: {}", typeStr);
-		
+
 		if (!ResourceType.isValid(typeStr))
 			logger.warn("Unknown Type requested: {}", typeStr);
@@ -257,7 +272,9 @@
 
 		if (!ConfigurationHandler.isEnabledForFileUpload(request)) {
-			ur = new UploadResponse(UploadResponse.EN_SECURITY_ERROR, null, null,
-			        "The current user isn't authorized for uploading files!");
-		} else if (isEmpty(commandStr) || isEmpty(currentFolderStr) || isEmpty(typeStr))
+			ur = new UploadResponse(UploadResponse.EN_SECURITY_ERROR, null,
+					null,
+					"The current user isn't authorized for uploading files!");
+		} else if (isEmpty(commandStr) || isEmpty(currentFolderStr)
+				|| isEmpty(typeStr))
 			ur = UploadResponse.UR_BAD_REQUEST;
 		else if (!commandStr.matches("(File|Quick)Upload"))
@@ -265,8 +282,11 @@
 		else {
 
-			String currentPath = constructTypeBasedFolderString(fileType, currentFolderStr, request);
-			String currentDirPath = getServletContext().getRealPath(currentPath);
-
-			if (!isValidPath(currentFolderStr) || !(new File(currentDirPath).exists()))
+			String currentPath = constructTypeBasedFolderString(fileType,
+					currentFolderStr, request);
+			String currentDirPath = getServletContext()
+					.getRealPath(currentPath);
+
+			if (!isValidPath(currentFolderStr)
+					|| !(new File(currentDirPath).exists()))
 				ur = UploadResponse.UR_BAD_REQUEST;
 			else {
@@ -284,5 +304,6 @@
 					String extension = FilenameUtils.getExtension(filename);
 
-					boolean validExtension = ExtensionsHandler.isAllowed(fileType, extension);
+					boolean validExtension = ExtensionsHandler.isAllowed(
+							fileType, extension);
 
 					if (!validExtension)
@@ -298,5 +319,6 @@
 						int counter = 1;
 						while (pathToSave.exists()) {
-							newFilename = baseName + "(" + counter + ")" + "." + extension;
+							newFilename = baseName + "(" + counter + ")" + "."
+									+ extension;
 							pathToSave = new File(currentDirPath, newFilename);
 							counter++;
@@ -305,10 +327,11 @@
 						uplFile.write(pathToSave);
 						if (isEmpty(newFilename)) {
-							ur = new UploadResponse(UploadResponse.EN_OK, request.getContextPath()
-							        + currentPath + filename);
+							ur = new UploadResponse(UploadResponse.EN_OK,
+									request.getContextPath() + currentPath
+											+ filename);
 						} else {
-							ur = new UploadResponse(UploadResponse.EN_RENAMED, request
-							        .getContextPath()
-							        + currentPath + newFilename, newFilename);
+							ur = new UploadResponse(UploadResponse.EN_RENAMED,
+									request.getContextPath() + currentPath
+											+ newFilename, newFilename);
 						}
 					}
@@ -327,5 +350,6 @@
 	}
 
-	private void createResponse(String retValue, String msg, Node root, Document doc) {
+	private void createResponse(String retValue, String msg, Node root,
+			Document doc) {
 		Element myEl = doc.createElement("Error");
 		myEl.setAttribute("number", retValue);
@@ -342,5 +366,6 @@
 		Element folders = doc.createElement("Folders");
 		root.appendChild(folders);
-		File[] fileList = dir.listFiles((FileFilter) DirectoryFileFilter.DIRECTORY);
+		File[] fileList = dir
+				.listFiles((FileFilter) DirectoryFileFilter.DIRECTORY);
 		for (File file : fileList) {
 			Element folderElement = doc.createElement("Folder");
@@ -358,11 +383,12 @@
 			Element fileElement = doc.createElement("File");
 			fileElement.setAttribute("name", file.getName());
-			fileElement.setAttribute("size", String.valueOf(file.length() / 1024));
+			fileElement.setAttribute("size", String
+					.valueOf(file.length() / 1024));
 			files.appendChild(fileElement);
 		}
 	}
 
-	private Node createCommonXml(Document doc, String commandStr, String typeStr,
-	        String currentPath, String currentUrl) {
+	private Node createCommonXml(Document doc, String commandStr,
+			String typeStr, String currentPath, String currentUrl) {
 		Element root = doc.createElement("Connector");
 		doc.appendChild(root);
@@ -379,5 +405,5 @@
 
 	private String constructTypeBasedFolderString(final ResourceType fileType,
-	        final String currentFolderString, final HttpServletRequest request) {
+			final String currentFolderString, final HttpServletRequest request) {
 		StringWriter retval = new StringWriter();
 		retval.append(ConfigurationHandler.getUserFilesPath(request));
@@ -388,6 +414,6 @@
 
 	/**
-	 * Initializes the {@link ExtensionsHandler} with the allowed or denied extensions of a file
-	 * type.
+	 * Initializes the {@link ExtensionsHandler} with the allowed or denied
+	 * extensions of a file type.
 	 * 
 	 * @param type
@@ -397,9 +423,11 @@
 	 *             if allowed and denied extensions are set.
 	 */
-	private void setExtension(final ResourceType type, final String allowedList, final String deniedList) {
-		// if both lists are set, we have to throw an error, because only one list should be set
+	private void setExtension(final ResourceType type,
+			final String allowedList, final String deniedList) {
+		// if both lists are set, we have to throw an error, because only one
+		// list should be set
 		if (Utils.isNotEmpty(allowedList) && Utils.isNotEmpty(deniedList)) {
-			String errorMsg = "Allowed and denied extensions are set for [" + type
-			        + "]. Just one of them should be set!";
+			String errorMsg = "Allowed and denied extensions are set for ["
+					+ type + "]. Just one of them should be set!";
 			logger.error(errorMsg);
 			throw new IllegalArgumentException(errorMsg);
