luehe       2003/02/24 14:30:26

  Modified:    jasper2/src/share/org/apache/jasper/compiler
                        JspDocumentParser.java
               jasper2/src/share/org/apache/jasper/resources
                        messages.properties
  Log:
  Added support for default namespace in JSP documents.
  
  Revision  Changes    Path
  1.42      +63 -71    
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/JspDocumentParser.java
  
  Index: JspDocumentParser.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/JspDocumentParser.java,v
  retrieving revision 1.41
  retrieving revision 1.42
  diff -u -r1.41 -r1.42
  --- JspDocumentParser.java    23 Feb 2003 20:57:05 -0000      1.41
  +++ JspDocumentParser.java    24 Feb 2003 22:30:26 -0000      1.42
  @@ -83,7 +83,7 @@
   class JspDocumentParser extends DefaultHandler
               implements LexicalHandler, TagConstants {
   
  -    private static final String XMLNS = "xmlns:";
  +    private static final String XMLNS_ATTR = "xmlns";
       private static final String XMLNS_JSP = "xmlns:jsp";
       private static final String JSP_VERSION = "version";
       private static final String LEXICAL_HANDLER_PROPERTY
  @@ -249,8 +249,8 @@
            node = parseStandardAction(qName, localName, attrsCopy, xmlnsAttrs,
                                       start, current);
        } else {
  -         node = parseCustomAction(qName, attrsCopy, xmlnsAttrs, start,
  -                                  current);
  +         node = parseCustomAction(qName, localName, uri, attrsCopy,
  +                                  xmlnsAttrs, start, current);
            if (node == null) {
                node = new Node.UninterpretedTag(qName, localName, attrsCopy,
                                                 xmlnsAttrs, start, current);
  @@ -630,19 +630,17 @@
        * and returns the corresponding Node object.
        */
       private Node parseCustomAction(String qName,
  +                                String localName,
  +                                String uri,
                                   Attributes attrs,
                                   Attributes xmlnsAttrs,
                                   Mark start,
                                   Node parent) throws SAXException {
  -     int colon = qName.indexOf(':');
  -     if (colon == -1) {
  -         return null;
  -     }
   
  -     String prefix = qName.substring(0, colon);
  -     String shortName = qName.substring(colon + 1);
  -     if (shortName.length() == 0) {
  -         return null;
  +     String prefix = "";
  +     int colon = qName.indexOf(':');
  +     if (colon != -1) {
  +         prefix = qName.substring(0, colon);
        }
   
        // Check if this is a user-defined (custom) tag
  @@ -650,11 +648,12 @@
           if (tagLibInfo == null) {
               return null;
        }
  -     TagInfo tagInfo = tagLibInfo.getTag(shortName);
  -        TagFileInfo tagFileInfo = tagLibInfo.getTagFile(shortName);
  +
  +     TagInfo tagInfo = tagLibInfo.getTag(localName);
  +        TagFileInfo tagFileInfo = tagLibInfo.getTagFile(localName);
        if (tagInfo == null && tagFileInfo == null) {
  -         throw new SAXException(Localizer.getMessage("jsp.error.bad_tag",
  -                                                     shortName, prefix));
  +         throw new SAXException(Localizer.getMessage("jsp.error.xml.bad_tag",
  +                                                     localName, uri));
        }
        Class tagHandlerClass = null;
        if (tagFileInfo == null) {
  @@ -664,13 +663,13 @@
            } catch (Exception e) {
                throw new SAXException(
                        Localizer.getMessage("jsp.error.unable.loadclass",
  -                                          shortName, prefix));
  +                                          localName, prefix));
            }
        } else {
               tagInfo = tagFileInfo.getTagInfo();
           }
          
  -     return new Node.CustomTag(qName, prefix, shortName, attrs, xmlnsAttrs,
  +     return new Node.CustomTag(qName, prefix, localName, attrs, xmlnsAttrs,
                                  start, parent, tagInfo, tagFileInfo,
                                  tagHandlerClass);
       }
  @@ -694,7 +693,7 @@
        int len = attrs.getLength();
        for (int i=len-1; i>=0; i--) {
            String qName = attrs.getQName(i);
  -         if (qName.startsWith(XMLNS)) {
  +         if (qName.startsWith(XMLNS_ATTR)) {
                if (result == null) {
                    result = new AttributesImpl();
                }
  @@ -713,29 +712,27 @@
        * and adds the corresponding TagLibraryInfo objects to the set of custom
        * tag libraries.
        */
  -    private void addCustomTagLibraries(Attributes attrs)
  +    private void addCustomTagLibraries(Attributes xmlnsAttrs)
            throws JasperException 
       {
  -        if (attrs == null) {
  +        if (xmlnsAttrs == null) {
            return;
        }
   
  -     int len = attrs.getLength();
  +     int len = xmlnsAttrs.getLength();
           for (int i=len-1; i>=0; i--) {
  -         String qName = attrs.getQName(i);
  +         String qName = xmlnsAttrs.getQName(i);
            if (qName.startsWith(XMLNS_JSP)) {
                continue;
            }
   
  -         // get the prefix
  -         String prefix = null;
  -         try {
  -             prefix = qName.substring(XMLNS.length());
  -         } catch (StringIndexOutOfBoundsException e) {
  -             continue;
  +         // Get the prefix
  +         String prefix = "";
  +         int colon = qName.indexOf(':');
  +         if (colon != -1) {
  +             prefix = qName.substring(colon + 1);
            }
  -
  -         if( taglibs.containsKey( prefix ) ) {
  +         if (taglibs.containsKey(prefix)) {
                // Prefix already in taglib map.
                throw new JasperException(
                        Localizer.getMessage(
  @@ -743,48 +740,43 @@
                                prefix));
            }
   
  -         // get the uri
  -         String uri = attrs.getValue(i);
  +         TagLibraryInfo tagLibInfo = getTaglibInfo(xmlnsAttrs.getValue(i),
  +                                                   prefix);
  +         taglibs.put(prefix, tagLibInfo);
  +     }
  +    }
  +
  +    /*
  +     * XXX
  +     */
  +    private TagLibraryInfo getTaglibInfo(String uri, String prefix)
  +                throws JasperException {
   
  -         TagLibraryInfo tagLibInfo = null;
  -         if (uri.startsWith(URN_JSPTAGDIR)) {
  -             /*
  -              * uri references tag file directory
  -              * (is of the form "urn:jsptagdir:path")
  -              */
  -             String tagdir = uri.substring(URN_JSPTAGDIR.length());
  -             tagLibInfo = new ImplicitTagLibraryInfo(ctxt,
  -                                                     parserController,
  -                                                     prefix, 
  -                                                     tagdir,
  -                                                     err);
  -         } else {
  -             /*
  -              * uri references TLD file
  -              */
  -             if (uri.startsWith(URN_JSPTLD)) {
  -                 // uri is of the form "urn:jsptld:path"
  -                 uri = uri.substring(URN_JSPTLD.length());
  -             }
  +     TagLibraryInfo result = null;
   
  -             TldLocationsCache cache
  -                 = ctxt.getOptions().getTldLocationsCache();
  -             tagLibInfo = cache.getTagLibraryInfo(uri);
  -             if (tagLibInfo == null) {
  -                 // get the location
  -                 String[] location = ctxt.getTldLocation(uri);
  -                 
  -                 tagLibInfo = new TagLibraryInfoImpl(ctxt,
  -                                                     parserController,
  -                                                     prefix,
  -                                                     uri,
  -                                                     location,
  -                                                     err);
  -             }
  +     if (uri.startsWith(URN_JSPTAGDIR)) {
  +         // uri (of the form "urn:jsptagdir:path") references tag file dir
  +         String tagdir = uri.substring(URN_JSPTAGDIR.length());
  +         result = new ImplicitTagLibraryInfo(ctxt, parserController, prefix,
  +                                             tagdir, err);
  +     } else {
  +         // uri references TLD file
  +         if (uri.startsWith(URN_JSPTLD)) {
  +             // uri is of the form "urn:jsptld:path"
  +             uri = uri.substring(URN_JSPTLD.length());
  +         }
  +
  +         TldLocationsCache cache = ctxt.getOptions().getTldLocationsCache();
  +         result = cache.getTagLibraryInfo(uri);
  +         if (result == null) {
  +             // get the location
  +             String[] location = ctxt.getTldLocation(uri);
  +             result = new TagLibraryInfoImpl(ctxt, parserController, prefix,
  +                                             uri, location, err);
            }
  -                
  -         taglibs.put(prefix, tagLibInfo);
        }
  +
  +     return result;
       }
   
       /*
  
  
  
  1.97      +3 -2      
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/resources/messages.properties
  
  Index: messages.properties
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/resources/messages.properties,v
  retrieving revision 1.96
  retrieving revision 1.97
  diff -u -r1.96 -r1.97
  --- messages.properties       24 Feb 2003 19:39:39 -0000      1.96
  +++ messages.properties       24 Feb 2003 22:30:26 -0000      1.97
  @@ -177,7 +177,8 @@
   jsp.error.unable.to_find_method=Unable to find setter method for attribute: {0}
   jsp.error.unable.to_convert_string=Unable to convert a String to {0} for attribute 
{1}
   jsp.error.unable.to_introspect=Unable to introspect on tag handler class: {0} 
because of {1}
  -jsp.error.bad_tag=No such tag {0} in the tag library imported with prefix {1}
  +jsp.error.bad_tag=Tag \"{0}\" not defined in tag library imported with prefix 
\"{1}\"
  +jsp.error.xml.bad_tag=Tag \"{0}\" not defined in tag library associated with uri 
\"{1}\"
   jsp.error.bad_string_Character=Cannot extract a Character from a zero length array
   jsp.error.bad_string_char=Cannot extract a char from a zero length array
   jsp.warning.compiler.class.cantcreate=Can't create an instance of specified 
compiler plugin class {0} due to {1}. Will default to Sun Java Compiler.
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to