pierred     00/11/18 14:36:49

  Modified:    jasper/src/share/org/apache/jasper/compiler JspUtil.java
                        TagLibraryInfoImpl.java TldLocationsCache.java
  Log:
  Cleanup of all code where "element child text data"
  is read from the DOM when we parse a TLD.
  Trim all text data read, and properly handle
  null values.
  
  Revision  Changes    Path
  1.6       +45 -3     
jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/JspUtil.java
  
  Index: JspUtil.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/JspUtil.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- JspUtil.java      2000/10/11 19:35:15     1.5
  +++ JspUtil.java      2000/11/18 22:36:48     1.6
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/JspUtil.java,v
 1.5 2000/10/11 19:35:15 shemnon Exp $
  - * $Revision: 1.5 $
  - * $Date: 2000/10/11 19:35:15 $
  + * $Header: 
/home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/JspUtil.java,v
 1.6 2000/11/18 22:36:48 pierred Exp $
  + * $Revision: 1.6 $
  + * $Date: 2000/11/18 22:36:48 $
    *
    * ====================================================================
    * 
  @@ -345,6 +345,48 @@
           return table;
       }
   
  +    /**
  +     * Get the data for the first child associated with the
  +     * Element provided as argument. It is assumed that this
  +     * first child is of type Text.
  +     *
  +     * @param e the DOM Element to read from 
  +     * @return the data associated with the first child of the DOM
  +     *  element.
  +     */
  +    public static String getElementChildTextData(Element e) {
  +     String s = null;
  +     Text t = (Text)e.getFirstChild();
  +     if (t != null) {
  +         s = t.getData();
  +         if (s != null) {
  +             s = s.trim();
  +         }
  +     }
  +     return s;
  +    }
  +
  +    /**
  +     * Convert a String value to 'boolean'.
  +     * Besides the standard conversions done by
  +     * Boolean.valueOf(s).booleanValue(), the value "yes"
  +     * (ignore case) is also converted to 'true'. 
  +     * If 's' is null, then 'false' is returned.
  +     *
  +     * @param s the string to be converted
  +     * @return the boolean value associated with the string s
  +     */
  +    public static boolean booleanValue(String s) {
  +     boolean b = false;
  +     if (s != null) {
  +         if (s.equalsIgnoreCase("yes")) {
  +             b = true;
  +         } else {
  +             b = Boolean.valueOf(s).booleanValue();
  +         }
  +     }
  +     return b;
  +    }
   }
   
   class MyEntityResolver implements EntityResolver {
  
  
  
  1.15      +41 -87    
jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/TagLibraryInfoImpl.java
  
  Index: TagLibraryInfoImpl.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/TagLibraryInfoImpl.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- TagLibraryInfoImpl.java   2000/11/17 22:39:23     1.14
  +++ TagLibraryInfoImpl.java   2000/11/18 22:36:48     1.15
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/TagLibraryInfoImpl.java,v
 1.14 2000/11/17 22:39:23 pierred Exp $
  - * $Revision: 1.14 $
  - * $Date: 2000/11/17 22:39:23 $
  + * $Header: 
/home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/TagLibraryInfoImpl.java,v
 1.15 2000/11/18 22:36:48 pierred Exp $
  + * $Revision: 1.15 $
  + * $Date: 2000/11/18 22:36:48 $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -282,25 +282,15 @@
               Element e = (Element) tmp;
               String tname = e.getTagName();
               if (tname.equals("tlibversion") || tname.equals("tlib-version")) {
  -                Text t = (Text) e.getFirstChild();
  -                if (t != null)
  -                    this.tlibversion = t.getData().trim();
  +             this.tlibversion = JspUtil.getElementChildTextData(e);
               } else if (tname.equals("jspversion") || tname.equals("jsp-version")) {
  -                Text t = (Text) e.getFirstChild();
  -                if (t != null)
  -                    this.jspversion = t.getData().trim();
  +             this.jspversion = JspUtil.getElementChildTextData(e);
               } else if (tname.equals("shortname") || tname.equals("short-name")) {
  -                Text t = (Text) e.getFirstChild();
  -                if (t != null)
  -                    this.shortname = t.getData().trim();
  +             this.shortname = JspUtil.getElementChildTextData(e);
               } else if (tname.equals("uri")) {
  -                Text t = (Text) e.getFirstChild();
  -                if (t != null)
  -                    this.urn = t.getData().trim();
  +             this.urn = JspUtil.getElementChildTextData(e);
               } else if (tname.equals("info")) {
  -                Text t = (Text) e.getFirstChild();
  -                if (t != null)
  -                    this.info = t.getData().trim();
  +             this.info = JspUtil.getElementChildTextData(e);
               } else if (tname.equals("validator")) {
                this.tagLibraryValidator = createValidator(e);
               } else if (tname.equals("tag"))
  @@ -339,42 +329,26 @@
            Element e = (Element) tmp;
               String tname = e.getTagName();
               if (tname.equals("name")) {
  -                Text t = (Text) e.getFirstChild();
  -                if (t != null)
  -                    name = t.getData().trim();
  +             name = JspUtil.getElementChildTextData(e);
               } else if (tname.equals("tagclass") || tname.equals("tag-class")) {
  -                Text t = (Text) e.getFirstChild();
  -                if (t != null)
  -                    tagclass = t.getData().trim();
  +             tagclass = JspUtil.getElementChildTextData(e);
               } else if (tname.equals("teiclass") || tname.equals("tei-class")) {
  -                Text t = (Text) e.getFirstChild();
  -                if (t != null)
  -                    teiclass = t.getData().trim();
  +             teiclass = JspUtil.getElementChildTextData(e);
               } else if (tname.equals("bodycontent") || tname.equals("body-content")) 
{
  -                Text t = (Text) e.getFirstChild();
  -                if (t != null)
  -                    bodycontent = t.getData().trim();
  +             bodycontent = JspUtil.getElementChildTextData(e);
               } else if (tname.equals("info") || tname.equals("tlib-description")) {
  -                Text t = (Text) e.getFirstChild();
  -                if (t != null)
  -                    info = t.getData().trim();
  +             info = JspUtil.getElementChildTextData(e);
               } else if (tname.equals("attribute")) {
                   attributeVector.addElement(createAttribute(e));
   
            // JSP 1.2
   
            } else if (tname.equals("display-name")) {
  -                Text t = (Text) e.getFirstChild();
  -                if (t != null)
  -                    displayName = t.getData().trim();
  +             displayName = JspUtil.getElementChildTextData(e);
            } else if (tname.equals("small-icon")) {
  -                Text t = (Text) e.getFirstChild();
  -                if (t != null)
  -                    smallIcon = t.getData().trim();
  +             smallIcon = JspUtil.getElementChildTextData(e);
            } else if (tname.equals("large-icon")) {
  -                Text t = (Text) e.getFirstChild();
  -                if (t != null)
  -                    largeIcon = t.getData().trim();
  +             largeIcon = JspUtil.getElementChildTextData(e);
            } else if (tname.equals("variable")) {
                if (teiclass != null) {
                    // teiclass comes first in the tag element
  @@ -453,27 +427,19 @@
            Element e = (Element) tmp;
               String tname = e.getTagName();
               if (tname.equals("name"))  {
  -                Text t = (Text) e.getFirstChild();
  -                if (t != null)
  -                    name = t.getData().trim();
  +             name = JspUtil.getElementChildTextData(e);
               } else if (tname.equals("required"))  {
  -                Text t = (Text) e.getFirstChild();
  -                if (t != null) {
  -                    required = Boolean.valueOf(t.getData().trim()).booleanValue();
  -                 if( t.getData().trim().equalsIgnoreCase("yes") )
  -                     required = true;
  +                String s = JspUtil.getElementChildTextData(e);
  +                if (s != null) {
  +                 required = JspUtil.booleanValue(s);
                }
               } else if (tname.equals("rtexprvalue")) {
  -                Text t = (Text) e.getFirstChild();
  -                if (t != null) {
  -                    rtexprvalue = 
Boolean.valueOf(t.getData().trim()).booleanValue();
  -                    if( t.getData().trim().equalsIgnoreCase("yes") )
  -                        rtexprvalue = true;
  +             String s = JspUtil.getElementChildTextData(e);
  +                if (s != null) {
  +                 rtexprvalue = JspUtil.booleanValue(s);
                }
               } else if (tname.equals("type")) {
  -                Text t = (Text) e.getFirstChild();
  -                if (t != null)
  -                    type = t.getData().trim();
  +             type = JspUtil.getElementChildTextData(e);
               } else 
                   Constants.message("jsp.warning.unknown.element.in.attribute", 
                                     new Object[] {
  @@ -501,28 +467,19 @@
            Element e = (Element) tmp;
               String tname = e.getTagName();
               if (tname.equals("name-given"))  {
  -                Text t = (Text) e.getFirstChild();
  -                if (t != null)
  -                    nameGiven = t.getData().trim();
  +             nameGiven = JspUtil.getElementChildTextData(e);
               } else if (tname.equals("name-from-attribute"))  {
  -                Text t = (Text) e.getFirstChild();
  -                if (t != null)
  -                    nameFromAttribute = t.getData().trim();
  +             nameFromAttribute = JspUtil.getElementChildTextData(e);
               } else if (tname.equals("variable-class"))  {
  -                Text t = (Text) e.getFirstChild();
  -                if (t != null)
  -                    className = t.getData().trim();
  +             className = JspUtil.getElementChildTextData(e);
               } else if (tname.equals("declare"))  {
  -                Text t = (Text) e.getFirstChild();
  -                if (t != null) {
  -                    declare = Boolean.valueOf(t.getData().trim()).booleanValue();
  -                 if (t.getData().trim().equalsIgnoreCase("yes"))
  -                     declare = true;
  +                String s = JspUtil.getElementChildTextData(e);
  +                if (s != null) {
  +                 declare = JspUtil.booleanValue(s);
                }
               } else if (tname.equals("scope")) {
  -                Text t = (Text) e.getFirstChild();
  -                if (t != null) {
  -                 String s = t.getData().trim();
  +             String s = JspUtil.getElementChildTextData(e);
  +                if (s != null) {
                    if ("NESTED".equals(s)) {
                        scope = VariableInfo.NESTED;
                    } else if ("AT_BEGIN".equals(s)) {
  @@ -531,10 +488,11 @@
                        scope = VariableInfo.AT_END;
                    }
                }
  -            } else 
  +            } else {
                   Constants.message("jsp.warning.unknown.element.in.variable",
                                     new Object[] {e.getTagName()},
                                     Logger.WARNING);
  +         }
           }
           return new TagVariableInfo(nameGiven, nameFromAttribute,
                                   className, declare, scope);
  @@ -551,16 +509,15 @@
            Element e = (Element) tmp;
               String tname = e.getTagName();
               if (tname.equals("validator-class"))  {
  -                Text t = (Text) e.getFirstChild();
  -                if (t != null)
  -                    validatorClass = t.getData().trim();
  +             validatorClass = JspUtil.getElementChildTextData(e);
               } else if (tname.equals("init-param"))  {
                String[] initParam = createInitParam(e);
                initParams.put(initParam[0], initParam[1]);
  -            } else 
  +            } else {
                   Constants.message("jsp.warning.unknown.element.in.validator", //@@@ 
add in properties
                                     new Object[] {e.getTagName()},
                                     Logger.WARNING);
  +         }
           }
   
           TagLibraryValidator tlv = null;
  @@ -595,19 +552,16 @@
            Element e = (Element) tmp;
               String tname = e.getTagName();
               if (tname.equals("param-name"))  {
  -                Text t = (Text) e.getFirstChild();
  -                if (t != null)
  -                    initParam[0] = t.getData().trim();
  +             initParam[0] = JspUtil.getElementChildTextData(e);
               } else if (tname.equals("param-value"))  {
  -                Text t = (Text) e.getFirstChild();
  -                if (t != null)
  -                    initParam[1] = t.getData().trim();
  +             initParam[1] = JspUtil.getElementChildTextData(e);
               } else if (tname.equals("description"))  {
                // do nothing
  -            } else 
  +            } else {
                   Constants.message("jsp.warning.unknown.element.in.initParam", //@@@ 
properties
                                     new Object[] {e.getTagName()},
                                     Logger.WARNING);
  +         }
           }
        return initParam;
       }
  
  
  
  1.2       +4 -14     
jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/TldLocationsCache.java
  
  Index: TldLocationsCache.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/TldLocationsCache.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TldLocationsCache.java    2000/11/06 20:53:32     1.1
  +++ TldLocationsCache.java    2000/11/18 22:36:49     1.2
  @@ -161,23 +161,16 @@
                String tagUri = null;
                String tagLoc = null;
                Element e =  (Element)nList.item(i);
  +
                NodeList uriList = e.getElementsByTagName("taglib-uri");
                Element uriElem = (Element)uriList.item(0);
  -             Text t = (Text)uriElem.getFirstChild();
  -             if (t == null) continue;
  -
  -             tagUri = t.getData();
  +             tagUri = JspUtil.getElementChildTextData(uriElem);
                if (tagUri == null) continue;
   
  -             tagUri = tagUri.trim();
                NodeList locList = 
                    e.getElementsByTagName("taglib-location");
                Element locElem = (Element)locList.item(0);
  -             Text tl = (Text)locElem.getFirstChild();
  -             if (tl == null) continue;
  -
  -             tagLoc = tl.getData();
  -             if (tagLoc != null) tagLoc = tagLoc.trim();
  +             tagLoc = JspUtil.getElementChildTextData(locElem);
                if (tagLoc == null) continue;
   
                if (uriType(tagLoc) == NOROOT_REL_URI) {
  @@ -293,10 +286,7 @@
               Element e = (Element) tmp;
               String tname = e.getTagName();
               if (tname.equals("uri")) {
  -                Text t = (Text)e.getFirstChild();
  -                if (t != null) {
  -                 return t.getData();
  -             }
  +             return JspUtil.getElementChildTextData(e);
            }
        }
        //p("No URI defined for this tag library: " + resourcePath);
  
  
  

Reply via email to