Changeset 2231 for FCKeditor.Java/trunk
- Timestamp:
- 2008-07-19 14:00:21 (5 months ago)
- Location:
- FCKeditor.Java/trunk/java-core/src/main/java/net/fckeditor
- Files:
-
- 10 modified
-
connector/ConnectorServlet.java (modified) (15 diffs)
-
FCKeditorConfig.java (modified) (2 diffs)
-
FCKeditor.java (modified) (12 diffs)
-
handlers/CommandHandler.java (modified) (2 diffs)
-
handlers/ResourceTypeHandler.java (modified) (1 diff)
-
response/UploadResponse.java (modified) (5 diffs)
-
response/XmlResponse.java (modified) (3 diffs)
-
tags/ConfigTag.java (modified) (1 diff)
-
tags/EditorTag.java (modified) (2 diffs)
-
tool/Utils.java (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
FCKeditor.Java/trunk/java-core/src/main/java/net/fckeditor/connector/ConnectorServlet.java
r2223 r2231 60 60 * <li><code>GetFolders</code>: Retrieves a list of folders in the current 61 61 * folder</li> 62 * <li><code>GetFoldersAndFiles</code>: Retri ves a list of files and folders63 * in the current folder</li>62 * <li><code>GetFoldersAndFiles</code>: Retrieves a list of files and 63 * folders in the current folder</li> 64 64 * <li><code>CreateFolder</code>: Creates a new folder in the current folder</li> 65 65 * <li><code>FileUpload</code>: Stores an uploaded file into the current … … 72 72 73 73 private static final long serialVersionUID = -5742008970929377161L; 74 private static final Logger logger = LoggerFactory.getLogger(ConnectorServlet.class); 74 private static final Logger logger = LoggerFactory 75 .getLogger(ConnectorServlet.class); 75 76 76 77 /** … … 79 80 public void init() throws ServletException, IllegalArgumentException { 80 81 String realDefaultUserFilesPath = getServletContext().getRealPath( 81 ConnectorHandler.getDefaultUserFilesPath());82 ConnectorHandler.getDefaultUserFilesPath()); 82 83 83 84 File defaultUserFilesDir = new File(realDefaultUserFilesPath); … … 99 100 */ 100 101 public void doGet(HttpServletRequest request, HttpServletResponse response) 101 throws ServletException, IOException {102 throws ServletException, IOException { 102 103 logger.debug("Entering ConnectorServlet#doGet"); 103 104 … … 119 120 120 121 if (!RequestCycleHandler.isEnabledForFileBrowsing(request)) 121 xr = new XmlResponse(XmlResponse.EN_ERROR, lrh.getString("message.connector.fileBrowsing.disabled")); 122 xr = new XmlResponse(XmlResponse.EN_ERROR, lrh 123 .getString("message.connector.fileBrowsing.disabled")); 122 124 else if (!CommandHandler.isValidForGet(commandStr)) 123 xr = new XmlResponse(XmlResponse.EN_ERROR, lrh.getString("message.connector.invalid_command_specified")); 125 xr = new XmlResponse(XmlResponse.EN_ERROR, lrh 126 .getString("message.connector.invalid_command_specified")); 124 127 else if (typeStr != null && !ResourceTypeHandler.isValid(typeStr)) 125 xr = new XmlResponse(XmlResponse.EN_ERROR, lrh.getString("message.connector.invalid_type_specified")); 128 xr = new XmlResponse(XmlResponse.EN_ERROR, lrh 129 .getString("message.connector.invalid_type_specified")); 126 130 else if (!UtilsFile.isValidPath(currentFolderStr)) 127 xr = new XmlResponse(XmlResponse.EN_ERROR, lrh.getString("message.connector.invalid_current_folder_speficied")); 131 xr = new XmlResponse( 132 XmlResponse.EN_ERROR, 133 lrh 134 .getString("message.connector.invalid_current_folder_speficied")); 128 135 else { 129 136 CommandHandler command = CommandHandler.getCommand(commandStr); 130 ResourceTypeHandler resourceType = ResourceTypeHandler.getDefaultResourceType(typeStr); 131 132 String typePath = UtilsFile.constructServerSidePath(request, resourceType); 137 ResourceTypeHandler resourceType = ResourceTypeHandler 138 .getDefaultResourceType(typeStr); 139 140 String typePath = UtilsFile.constructServerSidePath(request, 141 resourceType); 133 142 String typeDirPath = getServletContext().getRealPath(typePath); 134 143 … … 142 151 else { 143 152 144 xr = new XmlResponse(command, resourceType, currentFolderStr, UtilsResponse 145 .constructResponseUrl(request, resourceType, currentFolderStr, true, 146 ConnectorHandler.isFullUrl())); 153 xr = new XmlResponse(command, resourceType, currentFolderStr, 154 UtilsResponse.constructResponseUrl(request, 155 resourceType, currentFolderStr, true, 156 ConnectorHandler.isFullUrl())); 147 157 148 158 if (command.equals(CommandHandler.GET_FOLDERS)) … … 152 162 else if (command.equals(CommandHandler.CREATE_FOLDER)) { 153 163 String newFolderStr = UtilsFile.sanitizeFolderName(request 154 .getParameter("NewFolderName"));164 .getParameter("NewFolderName")); 155 165 logger.debug("Parameter NewFolderName: {}", newFolderStr); 156 166 … … 163 173 try { 164 174 errorNumber = (newFolder.mkdir()) ? XmlResponse.EN_OK 165 : XmlResponse.EN_INVALID_FOLDER_NAME;175 : XmlResponse.EN_INVALID_FOLDER_NAME; 166 176 } catch (SecurityException e) { 167 177 errorNumber = XmlResponse.EN_SECURITY_ERROR; … … 191 201 @SuppressWarnings("unchecked") 192 202 public void doPost(HttpServletRequest request, HttpServletResponse response) 193 throws ServletException, IOException {203 throws ServletException, IOException { 194 204 logger.debug("Entering Connector#doPost"); 195 205 … … 218 228 219 229 if (!RequestCycleHandler.isEnabledForFileUpload(request)) 220 ur = new UploadResponse(UploadResponse.SC_SECURITY_ERROR, null, null, 221 lrh.getString("message.connector.fileUpload.disabled")); 230 ur = new UploadResponse(UploadResponse.SC_SECURITY_ERROR, null, 231 null, lrh 232 .getString("message.connector.fileUpload.disabled")); 222 233 else if (!CommandHandler.isValidForPost(commandStr)) 223 ur = new UploadResponse(UploadResponse.SC_ERROR, null, null, lrh.getString("message.connector.invalid_command_specified")); 234 ur = new UploadResponse(UploadResponse.SC_ERROR, null, null, lrh 235 .getString("message.connector.invalid_command_specified")); 224 236 else if (typeStr != null && !ResourceTypeHandler.isValid(typeStr)) 225 ur = new UploadResponse(UploadResponse.SC_ERROR, null, null, lrh.getString("message.connector.invalid_type_specified")); 237 ur = new UploadResponse(UploadResponse.SC_ERROR, null, null, lrh 238 .getString("message.connector.invalid_type_specified")); 226 239 else if (!UtilsFile.isValidPath(currentFolderStr)) 227 ur = new UploadResponse(UploadResponse.SC_ERROR, null, null, 228 lrh.getString("message.connector.invalid_current_folder_speficied")); 240 ur = new UploadResponse( 241 UploadResponse.SC_ERROR, 242 null, 243 null, 244 lrh 245 .getString("message.connector.invalid_current_folder_speficied")); 229 246 else { 230 ResourceTypeHandler resourceType = ResourceTypeHandler.getDefaultResourceType(typeStr); 231 232 String typePath = UtilsFile.constructServerSidePath(request, resourceType); 247 ResourceTypeHandler resourceType = ResourceTypeHandler 248 .getDefaultResourceType(typeStr); 249 250 String typePath = UtilsFile.constructServerSidePath(request, 251 resourceType); 233 252 String typeDirPath = getServletContext().getRealPath(typePath); 234 253 … … 239 258 240 259 if (!currentDir.exists()) 241 ur = new UploadResponse(UploadResponse.SC_ERROR, null, null, 242 lrh.getString("message.connector.invalid_current_folder_speficied")); 260 ur = new UploadResponse( 261 UploadResponse.SC_ERROR, 262 null, 263 null, 264 lrh 265 .getString("message.connector.invalid_current_folder_speficied")); 243 266 else { 244 267 … … 253 276 // We upload only one file at the same time 254 277 FileItem uplFile = items.get(0); 255 String rawName = UtilsFile.sanitizeFileName(uplFile.getName()); 278 String rawName = UtilsFile.sanitizeFileName(uplFile 279 .getName()); 256 280 String filename = FilenameUtils.getName(rawName); 257 281 String baseName = FilenameUtils.removeExtension(filename); … … 259 283 260 284 if (!ExtensionsHandler.isAllowed(resourceType, extension)) 261 ur = new UploadResponse(UploadResponse.SC_INVALID_EXTENSION); 285 ur = new UploadResponse( 286 UploadResponse.SC_INVALID_EXTENSION); 262 287 else { 263 288 … … 266 291 int counter = 1; 267 292 while (pathToSave.exists()) { 268 newFilename = baseName.concat("(").concat(String.valueOf(counter)) 269 .concat(")").concat(".").concat(extension); 293 newFilename = baseName.concat("(").concat( 294 String.valueOf(counter)).concat(")") 295 .concat(".").concat(extension); 270 296 pathToSave = new File(currentDir, newFilename); 271 297 counter++; … … 273 299 274 300 if (Utils.isEmpty(newFilename)) 275 ur = new UploadResponse(UploadResponse.SC_OK, UtilsResponse 276 .constructResponseUrl(request, resourceType, currentFolderStr, 277 true, ConnectorHandler.isFullUrl()).concat(filename)); 301 ur = new UploadResponse(UploadResponse.SC_OK, 302 UtilsResponse.constructResponseUrl(request, 303 resourceType, currentFolderStr, 304 true, ConnectorHandler.isFullUrl()) 305 .concat(filename)); 278 306 else 279 307 ur = new UploadResponse(UploadResponse.SC_RENAMED, 280 UtilsResponse.constructResponseUrl(request, resourceType, 281 currentFolderStr, true, ConnectorHandler.isFullUrl()) 282 .concat(newFilename), newFilename); 308 UtilsResponse.constructResponseUrl(request, 309 resourceType, currentFolderStr, 310 true, ConnectorHandler.isFullUrl()) 311 .concat(newFilename), newFilename); 283 312 284 313 // secure image check 285 314 if (resourceType.equals(ResourceTypeHandler.IMAGE) 286 && ConnectorHandler.isSecureImageUploads()) {315 && ConnectorHandler.isSecureImageUploads()) { 287 316 if (UtilsFile.isImage(uplFile.getInputStream())) 288 317 uplFile.write(pathToSave); 289 318 else { 290 319 uplFile.delete(); 291 ur = new UploadResponse(UploadResponse.SC_INVALID_EXTENSION); 320 ur = new UploadResponse( 321 UploadResponse.SC_INVALID_EXTENSION); 292 322 } 293 323 } else -
FCKeditor.Java/trunk/java-core/src/main/java/net/fckeditor/FCKeditorConfig.java
r2224 r2231 42 42 43 43 private static final long serialVersionUID = -4831190504944866644L; 44 private final Logger logger = LoggerFactory.getLogger(FCKeditorConfig.class); 44 private final Logger logger = LoggerFactory 45 .getLogger(FCKeditorConfig.class); 45 46 46 47 /** 47 48 * Initialize the configuration collection 48 49 */ 49 public FCKeditorConfig( ) {50 public FCKeditorConfig() { 50 51 super(); 51 52 } 52 53 53 54 /** 54 * Generates the urlparameter sequence from this configuration which is55 * Generates the URL parameter sequence from this configuration which is 55 56 * passed to the editor. 56 57 * 57 * @return htmlencoded sequence of configuration parameters58 * @return HTML-encoded sequence of configuration parameters 58 59 */ 59 60 public String getUrlParams() { … … 63 64 if (Utils.isNotEmpty(entry.getValue())) { 64 65 osParams.append("&"); 65 osParams.append(URLEncoder.encode(entry.getKey(), "UTF-8"));66 osParams.append(URLEncoder.encode(entry.getKey(), "UTF-8")); 66 67 osParams.append("="); 67 osParams.append(URLEncoder.encode(entry.getValue(),"UTF-8")); 68 osParams.append(URLEncoder 69 .encode(entry.getValue(), "UTF-8")); 68 70 } 69 71 } 70 72 71 73 } catch (UnsupportedEncodingException e) { 72 74 logger.error("Configuration parameters could not be encoded", e); 73 75 } 74 76 75 77 if (osParams.length() > 0) 76 osParams.delete(0, 5);78 osParams.delete(0, 5); 77 79 return osParams.toString(); 78 80 } -
FCKeditor.Java/trunk/java-core/src/main/java/net/fckeditor/FCKeditor.java
r2227 r2231 30 30 31 31 /** 32 * Java repres antation of the FCKeditor. This class creates the htmlcode for32 * Java representation of the FCKeditor. This class creates the HTML code for 33 33 * the FCKeditor based on the following things: 34 34 * <ul> … … 48 48 49 49 // defaults 50 private String toolbarSet = PropertiesLoader.getProperty("fckeditor.toolbarSet"); 50 private String toolbarSet = PropertiesLoader 51 .getProperty("fckeditor.toolbarSet"); 51 52 private String width = PropertiesLoader.getProperty("fckeditor.width"); 52 53 private String height = PropertiesLoader.getProperty("fckeditor.height"); 53 private String basePath = PropertiesLoader.getProperty("fckeditor.basePath"); 54 private String basePath = PropertiesLoader 55 .getProperty("fckeditor.basePath"); 54 56 55 57 /** … … 72 74 * when instanceName is not valid HTML id 73 75 */ 74 public FCKeditor(final HttpServletRequest request, final String instanceName,75 final String width, final String height, final String toolbarSet, final String value,76 final String basePath) {76 public FCKeditor(final HttpServletRequest request, 77 final String instanceName, final String width, final String height, 78 final String toolbarSet, final String value, final String basePath) { 77 79 this.request = request; 78 80 if (Utils.isBlank(instanceName)) … … 90 92 if (Utils.isNotEmpty(value)) 91 93 this.value = value; 92 else93 this.value = new String();94 else 95 this.value = new String(); 94 96 if (Utils.isNotBlank(basePath)) 95 97 this.basePath = request.getContextPath().concat(basePath); … … 185 187 return config; 186 188 } 187 /** 188 * Set the advanced configuation set. 189 190 /** 191 * Set the advanced configuration set. 189 192 * 190 193 * @param config … … 206 209 if (Utils.isEmpty(str)) 207 210 return str; 208 211 209 212 /* 210 * TODO Strings are ineffic ent. It should be done like in Commons Lang213 * TODO Strings are inefficient. It should be done like in Commons Lang 211 214 * 2.4 StringUtils#replaceEach(String, String[], String[]) 212 215 */ … … 218 221 return str; 219 222 } 220 223 221 224 /* 222 225 * (non-Javadoc) … … 226 229 /** 227 230 * This method simply wraps to {@link #createHtml()}. 231 * 228 232 * @see #createHtml() 229 233 */ … … 239 243 * or a simple textarea otherwise. 240 244 * 241 * @return FCKeditor htmlcode245 * @return FCKeditor HTML code 242 246 */ 243 247 public String createHtml() { … … 248 252 249 253 if (Compatibility.check(request.getHeader("user-agent"))) { 250 strEditor.append(createInputForVariable(instanceName, instanceName, encodedValue)); 251 252 // create config html 254 strEditor.append(createInputForVariable(instanceName, instanceName, 255 encodedValue)); 256 257 // create config HTML 253 258 String configStr = config.getUrlParams(); 254 259 if (Utils.isNotEmpty(configStr)) 255 strEditor.append(createInputForVariable(null, instanceName .concat("___Config"),256 configStr));260 strEditor.append(createInputForVariable(null, instanceName 261 .concat("___Config"), configStr)); 257 262 258 263 // create IFrame 259 String sLink = basePath.concat("/editor/fckeditor.html?InstanceName=").concat( 260 instanceName); 264 String sLink = basePath.concat( 265 "/editor/fckeditor.html?InstanceName=") 266 .concat(instanceName); 261 267 if (Utils.isNotEmpty(toolbarSet)) 262 268 sLink += "&Toolbar=".concat(toolbarSet); 263 XHtmlTagTool iframeTag = new XHtmlTagTool("iframe", XHtmlTagTool.SPACE); 269 XHtmlTagTool iframeTag = new XHtmlTagTool("iframe", 270 XHtmlTagTool.SPACE); 264 271 iframeTag.addAttribute("id", instanceName.concat("___Frame")); 265 272 iframeTag.addAttribute("src", sLink); … … 271 278 272 279 } else { 273 XHtmlTagTool textareaTag = new XHtmlTagTool("textarea", encodedValue); 280 XHtmlTagTool textareaTag = new XHtmlTagTool("textarea", 281 encodedValue); 274 282 textareaTag.addAttribute("name", instanceName); 275 283 textareaTag.addAttribute("rows", "4"); 276 284 textareaTag.addAttribute("cols", "40"); 277 285 textareaTag.addAttribute("wrap", "virtual"); 278 textareaTag.addAttribute("style", "width: ".concat(width).concat( "; height: ").concat(279 height));286 textareaTag.addAttribute("style", "width: ".concat(width).concat( 287 "; height: ").concat(height)); 280 288 } 281 289 strEditor.append("</div>"); … … 283 291 } 284 292 285 private String createInputForVariable(final String name, final String id, final String value) { 293 private String createInputForVariable(final String name, final String id, 294 final String value) { 286 295 XHtmlTagTool tag = new XHtmlTagTool("input"); 287 296 if (Utils.isNotEmpty(id)) -
FCKeditor.Java/trunk/java-core/src/main/java/net/fckeditor/handlers/CommandHandler.java
r2151 r2231 89 89 90 90 /** 91 * Checks if a spec fied string represents a valid <code>GET</code>91 * Checks if a specified string represents a valid <code>GET</code> 92 92 * command. 93 93 * … … 102 102 103 103 /** 104 * Checks if a spec fied string represents a valid <code>POST</code>104 * Checks if a specified string represents a valid <code>POST</code> 105 105 * command. 106 106 * -
FCKeditor.Java/trunk/java-core/src/main/java/net/fckeditor/handlers/ResourceTypeHandler.java
r2151 r2231 101 101 /** 102 102 * 103 * Checks if a spec fied string represents a valid resource type.103 * Checks if a specified string represents a valid resource type. 104 104 * 105 105 * @param name -
FCKeditor.Java/trunk/java-core/src/main/java/net/fckeditor/response/UploadResponse.java