Changeset 2227 for FCKeditor.Java/trunk

Show
Ignore:
Timestamp:
2008-07-16 23:55:32 (5 months ago)
Author:
mosipov
Message:

CLOSED - #2372: Empty/non-set FCK:editor value causes NullPointerException

Location:
FCKeditor.Java/trunk
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • FCKeditor.Java/trunk/java-core/src/main/java/net/fckeditor/FCKeditor.java

    r2224 r2227  
    4545        private String instanceName; 
    4646        private String value; 
    47         private String basePath; 
    4847        private HttpServletRequest request; 
    4948 
     
    5251        private String width = PropertiesLoader.getProperty("fckeditor.width"); 
    5352        private String height = PropertiesLoader.getProperty("fckeditor.height"); 
    54         private String defaultBasePath = PropertiesLoader.getProperty("fckeditor.basePath"); 
    55  
    56         /** 
    57          * Main constructor.<br> 
     53        private String basePath = PropertiesLoader.getProperty("fckeditor.basePath"); 
     54 
     55        /** 
     56         * Main constructor.<br /> 
    5857         * All important settings are done here and will be preset by the defaults 
    59          * taken from {@link PropertiesLoader}. 
     58         * taken from {@link PropertiesLoader}. Any parameter except instanceName 
     59         * failing {@link Utils#isNotBlank(String)} will be ignored. 
    6060         *  
    6161         * @param request 
     
    6969         * @param toolbarSet 
    7070         *            toolbarSet name 
     71         * @throws IllegalArgumentException 
     72         *             when instanceName is not valid HTML id 
    7173         */ 
    7274        public FCKeditor(final HttpServletRequest request, final String instanceName, 
     
    7476                final String basePath) { 
    7577                this.request = request; 
    76                 this.instanceName = instanceName; 
    77                 if (Utils.isNotEmpty(width)) 
     78                if (Utils.isBlank(instanceName)) 
     79                        throw new IllegalArgumentException( 
     80                                        "instanceName must be a valid HTML id"); 
     81                else 
     82                        this.instanceName = instanceName; 
     83                if (Utils.isNotBlank(width)) 
    7884                        this.width = width; 
    79                 if (Utils.isNotEmpty(height)) 
     85                if (Utils.isNotBlank(height)) 
    8086                        this.height = height; 
    81                 if (Utils.isNotEmpty(toolbarSet)) 
     87                if (Utils.isNotBlank(toolbarSet)) 
    8288                        this.toolbarSet = toolbarSet; 
     89                // TODO Should be check here for empty or blank? 
    8390                if (Utils.isNotEmpty(value)) 
    8491                        this.value = value; 
    85                 if (Utils.isNotEmpty(basePath)) 
     92                        else 
     93                                this.value = new String(); 
     94                if (Utils.isNotBlank(basePath)) 
    8695                        this.basePath = request.getContextPath().concat(basePath); 
    8796                else 
    88                         this.basePath = request.getContextPath().concat(defaultBasePath); 
     97                        this.basePath = request.getContextPath().concat(this.basePath); 
    8998 
    9099                config = new FCKeditorConfig(); 
  • FCKeditor.Java/trunk/java-core/src/main/java/net/fckeditor/tags/EditorTag.java

    r2151 r2227  
    123123         */ 
    124124        public int doStartTag() throws JspException { 
    125                 fckEditor = new FCKeditor( 
    126                                 (HttpServletRequest) pageContext.getRequest(), instanceName, 
    127                                 width, height, toolbarSet, value, basePath); 
     125 
     126                try { 
     127                        fckEditor = new FCKeditor((HttpServletRequest) pageContext 
     128                                        .getRequest(), instanceName, width, height, toolbarSet, 
     129                                        value, basePath); 
     130                } catch (IllegalArgumentException e) { 
     131                        throw new JspException(e); 
     132                } 
    128133 
    129134                return EVAL_BODY_INCLUDE; 
  • FCKeditor.Java/trunk/java-core/src/main/java/net/fckeditor/tool/Utils.java

    r2151 r2227  
    7474         * @param str 
    7575         *            to check 
    76          * @return <code>true</code> if the string is <code>null</code>. 
     76         * @return <code>true</code> if the string is <code>null</code> or 
     77         *         empty. 
    7778         */ 
    7879        public static boolean isEmpty(final String str) { 
     
    8485         *  
    8586         * @param str 
    86          * @return <code>true</code> if the String is not empty and not 
     87         *            to ckeck 
     88         * @return <code>true</code> if the String is not empty or not 
    8789         *         <code>null</code>. 
    8890         */ 
     
    9092                return !isEmpty(str); 
    9193        } 
     94 
     95        /** 
     96         * Checks if a String is whitespace, empty or null. 
     97         *  
     98         * @param str 
     99         *            to check 
     100         * @return <code>true</code> if the string is <code>null</code>, empty 
     101         *         or contains whitespace only. 
     102         */ 
     103        public static boolean isBlank(final String str) { 
     104 
     105                if (isEmpty(str)) 
     106                        return true; 
     107 
     108                for (char c : str.toCharArray()) { 
     109                        if (!Character.isWhitespace(c)) 
     110                                return false; 
     111                } 
     112 
     113                return true; 
     114        } 
     115 
     116        /** 
     117         * Just a wrapper to {@link #isBlank(String)}. 
     118         *  
     119         * @param str 
     120         *            to check 
     121         * @return <code>true</code> if the string is not <code>null</code>, 
     122         *         not empty or does not contain whitespace only. 
     123         */ 
     124        public static boolean isNotBlank(final String str) { 
     125                return !isBlank(str); 
     126        } 
    92127} 
  • FCKeditor.Java/trunk/java-core/src/main/resources/META-INF/FCKeditor.tld

    r2044 r2227  
    44        xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee  
    55        http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd" 
    6         version="2.0" 
    7 > 
     6        version="2.0"> 
    87        <description> 
    98                The FCKeditor Tag Library offers a very convenient way to create 
     
    1716        <tag> 
    1817                <description> 
    19                         Creates a FCKeditor instance with the given parameters. 
     18                        Creates a FCKeditor instance with the given parameters. Any 
     19                        parameter except instanceName which is empty or contains 
     20                        whitespaces only will be ignored. 
    2021                </description> 
    2122                <display-name>editor</display-name> 
  • FCKeditor.Java/trunk/java-core/src/test/java/net/fckeditor/tool/UtilsTest.java

    r2168 r2227  
    7474        } 
    7575 
     76        @Test 
     77        public void isBlank01() { 
     78                assertTrue(Utils.isBlank(null)); 
     79        } 
     80 
     81        @Test 
     82        public void isBlank02() { 
     83                assertTrue(Utils.isBlank("")); 
     84        } 
     85 
     86        @Test 
     87        public void isBlank03() { 
     88                assertTrue(Utils.isBlank("   ")); 
     89        } 
     90 
     91        @Test 
     92        public void isBlank04() { 
     93                assertTrue(Utils.isBlank("  \t  \n \r")); 
     94        } 
     95 
     96        @Test 
     97        public void isBlank05() { 
     98                assertFalse(Utils.isBlank(" h ")); 
     99        } 
     100 
     101        @Test 
     102        public void isBlank06() { 
     103                assertFalse(Utils.isBlank("\t n ")); 
     104        } 
     105 
     106        @Test 
     107        public void isNotBlank01() { 
     108                assertTrue(Utils.isNotBlank(" h ")); 
     109        } 
     110 
     111        @Test 
     112        public void isNotBlank02() { 
     113                assertTrue(Utils.isNotBlank(" h \t ")); 
     114        } 
     115 
     116        @Test 
     117        public void isNotBlank03() { 
     118                assertFalse(Utils.isNotBlank("  \t  \n \r")); 
     119        } 
     120 
     121        @Test 
     122        public void isNotBlank04() { 
     123                assertFalse(Utils.isNotBlank(null)); 
     124        } 
     125 
     126        @Test 
     127        public void isNotBlank05() { 
     128                assertFalse(Utils.isNotBlank("")); 
     129        } 
     130 
     131        @Test 
     132        public void isNotBlank06() { 
     133                assertFalse(Utils.isNotBlank("  ")); 
     134        } 
     135 
    76136} 
  • FCKeditor.Java/trunk/src/changes/changes.xml

    r2212 r2227  
    1010                        <action dev="mosipov" type="fix" issue="2355">FCK:editor output is not XHTML 1.0 compliant</action> 
    1111                        <action dev="mosipov" type="fix" issue="2359">fckeditor-java-demo fails in Glassfish</action> 
    12                          
     12                        <action dev="mosipov" type="fix" issue="2372">Empty/non-set FCK:editor value causes NullPointerException</action> 
    1313                </release> 
    1414        </body>