Ticket #3660: 3660_2.patch
File 3660_2.patch, 9.0 KB (added by , 14 years ago) |
---|
-
src/main/java/net/fckeditor/FCKeditor.java
33 33 * object-oriented way. It can be configured as any other JavaBean type class. 34 34 * The final output of this class is HTML code.<br /> 35 35 * <strong>Note:</strong> It's your responsibility to supply reasonable and 36 * valid values, only {@code request} and {@code instanceName} will be checked37 * for sanity.36 * valid values, only {@code request}, {@code instanceName} and {@code inputName} 37 * will be checked for sanity. 38 38 * 39 39 * @version $Id$ 40 40 */ … … 42 42 43 43 private FCKeditorConfig fckConfig = new FCKeditorConfig(); 44 44 private String instanceName; 45 private String inputName; 45 46 private HttpServletRequest request; 46 47 47 48 // defaults … … 52 53 private String basePath = PropertiesLoader.getEditorBasePath(); 53 54 54 55 /** 55 * Class constructor with all basicparameters.56 * Class constructor with all parameters. 56 57 * 57 * A constructors which handles basic FCKeditor initialization with a few58 * parameters. If you omit basic parameters, default ones will be taken from59 * the {@link PropertiesLoader properties file}.60 *61 58 * @param request 62 59 * current user request instance 63 60 * @param instanceName 64 61 * the unique name of this editor 62 * @param inputName 63 * the name for the underlying input element. See 64 * {@link #setInputName(String)} for details. 65 65 * @param width 66 66 * the desired editor width (CSS-style value) 67 67 * @param height … … 76 76 * @throws IllegalArgumentException 77 77 * if instanceName is empty or not a valid XHTML id 78 78 */ 79 public FCKeditor( final HttpServletRequest request,80 final String instanceName, final String width, final String height,81 final String toolbarSet, final String value, finalString basePath) {82 83 this(request, instanceName );79 public FCKeditor(HttpServletRequest request, String instanceName, 80 String inputName, String width, String height, String toolbarSet, 81 String value, String basePath) { 82 83 this(request, instanceName, inputName); 84 84 this.width = width; 85 85 this.height = height; 86 86 this.toolbarSet = toolbarSet; 87 87 this.value = value; 88 88 this.basePath = basePath; 89 90 } 89 91 92 /** 93 * Class constructor with a extended set of parameters. 94 * 95 * @param request 96 * current user request instance 97 * @param instanceName 98 * the unique name of this editor 99 * @param width 100 * the desired editor width (CSS-style value) 101 * @param height 102 * the desired editor height (CSS-style value) 103 * @param toolbarSet 104 * the desired toolbar set name 105 * @param value 106 * the HTML markup of this editor. Markup will be properly 107 * escaped. 108 * @param basePath 109 * the base path of this editor, absolute to the context 110 * @throws IllegalArgumentException 111 * if instanceName is empty or not a valid XHTML id 112 */ 113 public FCKeditor(final HttpServletRequest request, 114 final String instanceName, final String width, final String height, 115 final String toolbarSet, final String value, final String basePath) { 116 117 this(request, instanceName, null, width, height, toolbarSet, value, 118 basePath); 119 90 120 } 91 121 92 122 /** … … 112 142 } 113 143 114 144 /** 145 * Class constructor with a basic set of parameters. 146 * 147 * Omitted parameters will be set to default values. 148 * 149 * @param request 150 * current user request instance 151 * @param instanceName 152 * the unique name of this editor 153 * @param inputName 154 * the name for the underlying input element. See 155 * {@link #setInputName(String)} for details. 156 * @throws IllegalArgumentException 157 * if instanceName is empty or not a valid HTML id 158 */ 159 public FCKeditor(HttpServletRequest request, String instanceName, 160 String inputName) { 161 this(request, instanceName); 162 setInputName(inputName); 163 } 164 165 /** 115 166 * Sets the unique name of this editor. 116 167 * 117 168 * @param instanceName … … 127 178 "instanceName must be a valid XHTML id containing only \"\\p{Alpha}[\\p{Alnum}:_.-]*\""); 128 179 this.instanceName = instanceName; 129 180 } 181 182 /** 183 * Sets the name for the underlying input element. Empty strings will be 184 * ignored and field will be reset to {@code instanceName}. 185 * 186 * @param inputName 187 * the name for the underlying input element 188 */ 189 public void setInputName(final String inputName) { 190 if (Utils.isEmpty(inputName)) 191 this.inputName = instanceName; 192 else 193 this.inputName = inputName; 194 } 130 195 131 196 /** 132 197 * Sets the initial value to be edited as HTML markup. … … 271 336 272 337 strEditor.append("<div>"); 273 338 String encodedValue = escapeXml(value); 339 340 /* 341 * We have to reset inputName to make sure that a potentially reassigned 342 * instanceName has been propagated to empty field. 343 */ 344 setInputName(inputName); 274 345 275 346 if (Compatibility.isCompatibleBrowser(request)) { 276 strEditor.append(createInputForVariable(instanceName, in stanceName,347 strEditor.append(createInputForVariable(instanceName, inputName, 277 348 encodedValue)); 278 349 279 350 // create config HTML 280 351 String configStr = fckConfig.getUrlParams(); 281 352 if (Utils.isNotEmpty(configStr)) 282 strEditor.append(createInputForVariable( null,instanceName283 .concat("___Config"), configStr));353 strEditor.append(createInputForVariable(instanceName 354 .concat("___Config"), null, configStr)); 284 355 285 356 // create IFrame 286 357 StringBuffer editorLink = new StringBuffer(request.getContextPath()); … … 303 374 } else { 304 375 XHtmlTagTool textareaTag = new XHtmlTagTool("textarea", 305 376 encodedValue); 306 textareaTag.addAttribute("name", in stanceName);377 textareaTag.addAttribute("name", inputName); 307 378 textareaTag.addAttribute("rows", "4"); 308 379 textareaTag.addAttribute("cols", "40"); 309 380 textareaTag.addAttribute("wrap", "virtual"); … … 326 397 327 398 /** 328 399 * Creates a hidden input element for the given attributes. 329 * 400 * @param id 401 * id attribute of the input tag 330 402 * @param name 331 403 * name attribute of the input tag 332 * @param id333 * id attribute of the input tag334 404 * @param value 335 405 * value attribute of the input tag 406 * 336 407 * @return the produced XHTML tag 337 408 */ 338 private String createInputForVariable(final String name, final String id,409 private String createInputForVariable(final String id, final String name, 339 410 final String value) { 340 411 XHtmlTagTool tag = new XHtmlTagTool("input"); 341 if (Utils.isNotEmpty(id)) 342 tag.addAttribute("id", id); 343 if (Utils.isNotEmpty(name)) 344 tag.addAttribute("name", name); 412 tag.addAttribute("id", id); 413 tag.addAttribute("name", name); 345 414 tag.addAttribute("value", value); 346 415 tag.addAttribute("type", "hidden"); 347 416 return tag.toString(); -
src/main/java/net/fckeditor/tags/EditorTag.java
21 21 package net.fckeditor.tags; 22 22 23 23 import java.io.IOException; 24 import java.util.Map;25 24 26 25 import javax.servlet.http.HttpServletRequest; 27 26 import javax.servlet.jsp.JspException; … … 42 41 private static final long serialVersionUID = -173091731589866140L; 43 42 44 43 private String instanceName; 44 private String inputName; 45 45 private String width; 46 46 private String height; 47 47 private String toolbarSet; … … 57 57 public void setInstanceName(String instanceName) { 58 58 this.instanceName = instanceName; 59 59 } 60 61 /** 62 * @see FCKeditor#setInputName(String) 63 */ 64 public void setInputName(String inputName) { 65 this.inputName = inputName; 66 } 60 67 61 68 /** 62 69 * @see FCKeditor#setWidth(String) … … 105 112 106 113 try { 107 114 fckEditor = new FCKeditor((HttpServletRequest) pageContext 108 .getRequest(), instanceName );115 .getRequest(), instanceName, inputName); 109 116 110 117 if (Utils.isNotEmpty(width)) 111 118 fckEditor.setWidth(width); -
src/main/resources/META-INF/FCKeditor.tld
56 56 </attribute> 57 57 <attribute> 58 58 <description> 59 The name of the underlying input element. If not passed, field 60 will be reset to instanceName. 61 </description> 62 <name>inputName</name> 63 <rtexprvalue>true</rtexprvalue> 64 <type>java.lang.String</type> 65 </attribute> 66 <attribute> 67 <description> 59 68 Width of the FCKeditor instance in the browser window. 60 69 </description> 61 70 <name>width</name>