Ticket #3660: 3660_2.patch

File 3660_2.patch, 9.0 KB (added by Michael Osipov, 14 years ago)

Modification of the first patch

  • src/main/java/net/fckeditor/FCKeditor.java

     
    3333 * object-oriented way. It can be configured as any other JavaBean type class.
    3434 * The final output of this class is HTML code.<br />
    3535 * <strong>Note:</strong> It's your responsibility to supply reasonable and
    36  * valid values, only {@code request} and {@code instanceName} will be checked
    37  * for sanity.
     36 * valid values, only {@code request}, {@code instanceName} and {@code inputName}
     37 * will be checked for sanity.
    3838 *
    3939 * @version $Id$
    4040 */
     
    4242
    4343        private FCKeditorConfig fckConfig = new FCKeditorConfig();
    4444        private String instanceName;
     45        private String inputName;
    4546        private HttpServletRequest request;
    4647
    4748        // defaults
     
    5253        private String basePath = PropertiesLoader.getEditorBasePath();
    5354
    5455        /**
    55          * Class constructor with all basic parameters.
     56         * Class constructor with all parameters.
    5657         *
    57          * A constructors which handles basic FCKeditor initialization with a few
    58          * parameters. If you omit basic parameters, default ones will be taken from
    59          * the {@link PropertiesLoader properties file}.
    60          *
    6158         * @param request
    6259         *            current user request instance
    6360         * @param instanceName
    6461         *            the unique name of this editor
     62         * @param inputName
     63         *            the name for the underlying input element. See
     64         *            {@link #setInputName(String)} for details.
    6565         * @param width
    6666         *            the desired editor width (CSS-style value)
    6767         * @param height
     
    7676         * @throws IllegalArgumentException
    7777         *             if instanceName is empty or not a valid XHTML id
    7878         */
    79         public FCKeditor(final HttpServletRequest request,
    80                         final String instanceName, final String width, final String height,
    81                         final String toolbarSet, final String value, final String 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);
    8484                this.width = width;
    8585                this.height = height;
    8686                this.toolbarSet = toolbarSet;
    8787                this.value = value;
    8888                this.basePath = basePath;
     89               
     90        }
    8991
     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
    90120        }
    91121
    92122        /**
     
    112142        }
    113143
    114144        /**
     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        /**
    115166         * Sets the unique name of this editor.
    116167         *
    117168         * @param instanceName
     
    127178                                        "instanceName must be a valid XHTML id containing only \"\\p{Alpha}[\\p{Alnum}:_.-]*\"");
    128179                this.instanceName = instanceName;
    129180        }
     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        }
    130195
    131196        /**
    132197         * Sets the initial value to be edited as HTML markup.
     
    271336
    272337                strEditor.append("<div>");
    273338                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);
    274345
    275346                if (Compatibility.isCompatibleBrowser(request)) {
    276                         strEditor.append(createInputForVariable(instanceName, instanceName,
     347                        strEditor.append(createInputForVariable(instanceName, inputName,
    277348                                        encodedValue));
    278349
    279350                        // create config HTML
    280351                        String configStr = fckConfig.getUrlParams();
    281352                        if (Utils.isNotEmpty(configStr))
    282                                 strEditor.append(createInputForVariable(null, instanceName
    283                                                 .concat("___Config"), configStr));
     353                                strEditor.append(createInputForVariable(instanceName
     354                                                .concat("___Config"), null, configStr));
    284355
    285356                        // create IFrame
    286357                        StringBuffer editorLink = new StringBuffer(request.getContextPath());
     
    303374                } else {
    304375                        XHtmlTagTool textareaTag = new XHtmlTagTool("textarea",
    305376                                        encodedValue);
    306                         textareaTag.addAttribute("name", instanceName);
     377                        textareaTag.addAttribute("name", inputName);
    307378                        textareaTag.addAttribute("rows", "4");
    308379                        textareaTag.addAttribute("cols", "40");
    309380                        textareaTag.addAttribute("wrap", "virtual");
     
    326397
    327398        /**
    328399         * Creates a hidden input element for the given attributes.
    329          *
     400         * @param id
     401         *            id attribute of the input tag
    330402         * @param name
    331403         *            name attribute of the input tag
    332          * @param id
    333          *            id attribute of the input tag
    334404         * @param value
    335405         *            value attribute of the input tag
     406         *
    336407         * @return the produced XHTML tag
    337408         */
    338         private String createInputForVariable(final String name, final String id,
     409        private String createInputForVariable(final String id, final String name,
    339410                        final String value) {
    340411                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);
    345414                tag.addAttribute("value", value);
    346415                tag.addAttribute("type", "hidden");
    347416                return tag.toString();
  • src/main/java/net/fckeditor/tags/EditorTag.java

     
    2121package net.fckeditor.tags;
    2222
    2323import java.io.IOException;
    24 import java.util.Map;
    2524
    2625import javax.servlet.http.HttpServletRequest;
    2726import javax.servlet.jsp.JspException;
     
    4241        private static final long serialVersionUID = -173091731589866140L;
    4342
    4443        private String instanceName;
     44        private String inputName;
    4545        private String width;
    4646        private String height;
    4747        private String toolbarSet;
     
    5757        public void setInstanceName(String instanceName) {
    5858                this.instanceName = instanceName;
    5959        }
     60       
     61        /**
     62         * @see FCKeditor#setInputName(String)
     63         */
     64        public void setInputName(String inputName) {
     65                this.inputName = inputName;
     66        }
    6067
    6168        /**
    6269         * @see FCKeditor#setWidth(String)
     
    105112
    106113                try {
    107114                        fckEditor = new FCKeditor((HttpServletRequest) pageContext
    108                                         .getRequest(), instanceName);
     115                                        .getRequest(), instanceName, inputName);
    109116
    110117                        if (Utils.isNotEmpty(width))
    111118                                fckEditor.setWidth(width);
  • src/main/resources/META-INF/FCKeditor.tld

     
    5656                </attribute>
    5757                <attribute>
    5858                        <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>
    5968                                Width of the FCKeditor instance in the browser window.
    6069                        </description>
    6170                        <name>width</name>
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy