luehe 2003/02/28 18:07:53 Modified: jasper2/src/share/org/apache/jasper/compiler FunctionMapperImpl.java JspDocumentParser.java Node.java PageInfo.java Parser.java Validator.java Log: Use taglib URI instead of prefix as the key in taglib map Revision Changes Path 1.2 +7 -6 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/FunctionMapperImpl.java Index: FunctionMapperImpl.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/FunctionMapperImpl.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- FunctionMapperImpl.java 26 Feb 2003 00:11:38 -0000 1.1 +++ FunctionMapperImpl.java 1 Mar 2003 02:07:52 -0000 1.2 @@ -98,8 +98,8 @@ Iterator iter = taglibs.keySet().iterator(); ClassLoader loader = compiler.getCompilationContext().getClassLoader(); while (iter.hasNext()) { - String prefix = (String) iter.next(); - TagLibraryInfo tli = (TagLibraryInfo) taglibs.get(prefix); + String uri = (String) iter.next(); + TagLibraryInfo tli = (TagLibraryInfo) taglibs.get(uri); FunctionInfo[] fnInfos = tli.getFunctions(); for (int i = 0; fnInfos != null && i < fnInfos.length; i++) { FunctionSignature fnSig = @@ -114,7 +114,8 @@ err.jspError(e); } - String key = prefix + ":" + fnInfos[i].getName(); + String key = tli.getPrefixString() + ":" + + fnInfos[i].getName(); this.fnMap.put(key, method); this.fnSigMap.put(key, fnSig); this.fnInfoMap.put(key, fnInfos[i]); 1.46 +30 -34 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.45 retrieving revision 1.46 diff -u -r1.45 -r1.46 --- JspDocumentParser.java 26 Feb 2003 17:58:07 -0000 1.45 +++ JspDocumentParser.java 1 Mar 2003 02:07:52 -0000 1.46 @@ -637,14 +637,8 @@ Mark start, Node parent) throws SAXException { - String prefix = ""; - int colon = qName.indexOf(':'); - if (colon != -1) { - prefix = qName.substring(0, colon); - } - // Check if this is a user-defined (custom) tag - TagLibraryInfo tagLibInfo = (TagLibraryInfo) taglibs.get(prefix); + TagLibraryInfo tagLibInfo = (TagLibraryInfo) taglibs.get(uri); if (tagLibInfo == null) { return null; } @@ -668,10 +662,16 @@ } else { tagInfo = tagFileInfo.getTagInfo(); } + + String prefix = ""; + int colon = qName.indexOf(':'); + if (colon != -1) { + prefix = qName.substring(0, colon); + } - return new Node.CustomTag(qName, prefix, localName, attrs, xmlnsAttrs, - start, parent, tagInfo, tagFileInfo, - tagHandlerClass); + return new Node.CustomTag(qName, prefix, localName, uri, attrs, + xmlnsAttrs, start, parent, tagInfo, + tagFileInfo, tagHandlerClass); } /* @@ -726,39 +726,35 @@ continue; } - // Get the prefix - String prefix = ""; - int colon = qName.indexOf(':'); - if (colon != -1) { - prefix = qName.substring(colon + 1); - } - if (taglibs.containsKey(prefix)) { - // Prefix already in taglib map. - throw new JasperException( - Localizer.getMessage( - "jsp.error.xmlns.redefinition.notimplemented", - prefix)); + String uri = xmlnsAttrs.getValue(i); + if (!taglibs.containsKey(uri)) { + TagLibraryInfo tagLibInfo = getTaglibInfo(qName, uri); + taglibs.put(uri, tagLibInfo); } - - TagLibraryInfo tagLibInfo = getTaglibInfo(xmlnsAttrs.getValue(i), - prefix); - taglibs.put(prefix, tagLibInfo); } } /* - * Gets the tag library associated with the given uri namespace to which - * the given prefix is bound. + * Creates the tag library associated with the given uri namespace, and + * returns it. * - * @param uri The uri namespace - * @param prefix The prefix that is bound to the uri namespace + * @param qName The qualified name of the xmlns attribute + * (of the form 'xmlns:<prefix>') + * @param uri The uri namespace (value of the xmlns attribute) * * @return The tag library associated with the given uri namespace */ - private TagLibraryInfo getTaglibInfo(String uri, String prefix) + private TagLibraryInfo getTaglibInfo(String qName, String uri) throws JasperException { TagLibraryInfo result = null; + + // Get the prefix + String prefix = ""; + int colon = qName.indexOf(':'); + if (colon != -1) { + prefix = qName.substring(colon + 1); + } if (uri.startsWith(URN_JSPTAGDIR)) { // uri (of the form "urn:jsptagdir:path") references tag file dir 1.65 +19 -9 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Node.java Index: Node.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Node.java,v retrieving revision 1.64 retrieving revision 1.65 diff -u -r1.64 -r1.65 --- Node.java 26 Feb 2003 22:58:15 -0000 1.64 +++ Node.java 1 Mar 2003 02:07:52 -0000 1.65 @@ -1168,6 +1168,7 @@ */ public static class CustomTag extends Node { + private String uri; private String prefix; private JspAttribute[] jspAttrs; private TagData tagData; @@ -1202,19 +1203,21 @@ private Nodes atETag; public CustomTag(String qName, String prefix, String localName, - Attributes attrs, Mark start, Node parent, + String uri, Attributes attrs, Mark start, Node parent, TagInfo tagInfo, TagFileInfo tagFileInfo, Class tagHandlerClass) { - this(qName, prefix, localName, attrs, null, start, parent, tagInfo, - tagFileInfo, tagHandlerClass); + + this(qName, prefix, localName, uri, attrs, null, start, parent, + tagInfo, tagFileInfo, tagHandlerClass); } public CustomTag(String qName, String prefix, String localName, - Attributes attrs, Attributes xmlnsAttrs, Mark start, - Node parent, TagInfo tagInfo, TagFileInfo tagFileInfo, - Class tagHandlerClass) { + String uri, Attributes attrs, Attributes xmlnsAttrs, + Mark start, Node parent, TagInfo tagInfo, + TagFileInfo tagFileInfo, Class tagHandlerClass) { super(qName, localName, attrs, xmlnsAttrs, start, parent); + this.uri = uri; this.prefix = prefix; this.tagInfo = tagInfo; this.tagFileInfo = tagFileInfo; @@ -1246,6 +1249,13 @@ public void accept(Visitor v) throws JasperException { v.visit(this); + } + + /** + * @return The URI namespace that this custom action belongs to + */ + public String getURI() { + return this.uri; } /** 1.24 +12 -3 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/PageInfo.java Index: PageInfo.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/PageInfo.java,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- PageInfo.java 26 Feb 2003 22:58:16 -0000 1.23 +++ PageInfo.java 1 Mar 2003 02:07:52 -0000 1.24 @@ -77,6 +77,7 @@ private BeanRepository beanRepository; private Hashtable tagLibraries; + private Hashtable prefixMapper; private FunctionMapperImpl funcMap; private String language = "java"; @@ -126,6 +127,7 @@ PageInfo(BeanRepository beanRepository) { this.beanRepository = beanRepository; this.tagLibraries = new Hashtable(); + this.prefixMapper = new Hashtable(); this.imports = new Vector(); this.dependants = new Vector(); this.includePrelude = new Vector(); @@ -176,6 +178,13 @@ public Hashtable getTagLibraries() { return tagLibraries; + } + + /* + * Returns the prefix-to-URI mapper. + */ + public Hashtable getPrefixMapper() { + return prefixMapper; } public String getLanguage() { 1.68 +31 -27 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Parser.java Index: Parser.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Parser.java,v retrieving revision 1.67 retrieving revision 1.68 diff -u -r1.67 -r1.68 --- Parser.java 28 Feb 2003 20:12:26 -0000 1.67 +++ Parser.java 1 Mar 2003 02:07:52 -0000 1.68 @@ -95,6 +95,7 @@ private String currentFile; private Mark start; private Hashtable taglibs; + private Hashtable prefixMapper; private ErrorDispatcher err; private int scriptlessCount; private boolean isTagFile; @@ -118,6 +119,7 @@ this.parserController = pc; this.ctxt = pc.getJspCompilationContext(); this.taglibs = pc.getCompiler().getPageInfo().getTagLibraries(); + this.prefixMapper = pc.getCompiler().getPageInfo().getPrefixMapper(); this.err = pc.getCompiler().getErrorDispatcher(); this.reader = reader; this.currentFile = reader.mark().getFile(); @@ -218,12 +220,11 @@ int index = qName.indexOf(':'); if (index != -1) { String prefix = qName.substring(0, index); - TagLibraryInfo tagLibInfo = (TagLibraryInfo) taglibs.get(prefix); - if (tagLibInfo == null) { + uri = (String) prefixMapper.get(prefix); + if (uri == null) { err.jspError(reader.mark(), "jsp.error.attribute.invalidPrefix", prefix); } - uri = tagLibInfo.getURI(); localName = qName.substring(index+1); } @@ -441,26 +442,27 @@ String uri = attrs.getValue("uri"); String prefix = attrs.getValue("prefix"); if (prefix != null) { - TagLibraryInfo tagLibInfo = null; if (uri != null) { // Errors to be checked in Validator String[] location = ctxt.getTldLocation(uri); - tagLibInfo = new TagLibraryInfoImpl(ctxt, parserController, - prefix, uri, location, - err); + taglibs.put(uri, + new TagLibraryInfoImpl(ctxt, parserController, + prefix, uri, location, + err)); + prefixMapper.put(prefix, uri); } else { String tagdir = attrs.getValue("tagdir"); if (tagdir != null) { - tagLibInfo = new ImplicitTagLibraryInfo(ctxt, - parserController, - prefix, - tagdir, - err); + String urnTagdir = URN_JSPTAGDIR + tagdir; + taglibs.put(urnTagdir, + new ImplicitTagLibraryInfo(ctxt, + parserController, + prefix, + tagdir, + err)); + prefixMapper.put(prefix, urnTagdir); } } - if (tagLibInfo != null) { - taglibs.put(prefix, tagLibInfo); - } } new Node.TaglibDirective(attrs, start, parent); @@ -1314,11 +1316,13 @@ String shortTagName = tagName.substring(i+1); // Check if this is a user-defined tag. - TagLibraryInfo tagLibInfo = (TagLibraryInfo) taglibs.get(prefix); - if (tagLibInfo == null) { + String uri = (String) prefixMapper.get(prefix); + if (uri == null) { reader.reset(start); return false; } + + TagLibraryInfo tagLibInfo = (TagLibraryInfo) taglibs.get(uri); TagInfo tagInfo = tagLibInfo.getTag(shortTagName); TagFileInfo tagFileInfo = tagLibInfo.getTagFile(shortTagName); if (tagInfo == null && tagFileInfo == null) { @@ -1349,8 +1353,9 @@ // Parse 'CustomActionEnd' production: if (reader.matches("/>")) { - new Node.CustomTag(tagName, prefix, shortTagName, attrs, start, - parent, tagInfo, tagFileInfo, tagHandlerClass); + new Node.CustomTag(tagName, prefix, shortTagName, uri, attrs, + start, parent, tagInfo, tagFileInfo, + tagHandlerClass); return true; } @@ -1361,17 +1366,16 @@ // Looking for a body, it still can be empty; but if there is a // a tag body, its syntax would be dependent on the type of // body content declared in TLD. - TagLibraryInfo taglib = (TagLibraryInfo)taglibs.get(prefix); String bc; - if (taglib.getTag(shortTagName) != null) { - bc = taglib.getTag(shortTagName).getBodyContent(); - } else if (taglib.getTagFile(shortTagName) != null) { + if (tagInfo != null) { + bc = tagInfo.getBodyContent(); + } else if (tagFileInfo != null) { bc = TagInfo.BODY_CONTENT_SCRIPTLESS; } else { bc = TagInfo.BODY_CONTENT_EMPTY; } - Node tagNode = new Node.CustomTag(tagName, prefix, shortTagName, + Node tagNode = new Node.CustomTag(tagName, prefix, shortTagName, uri, attrs, start, parent, tagInfo, tagFileInfo, tagHandlerClass); parseOptionalBody( tagNode, tagName, bc ); 1.86 +16 -21 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Validator.java Index: Validator.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Validator.java,v retrieving revision 1.85 retrieving revision 1.86 diff -u -r1.85 -r1.86 --- Validator.java 26 Feb 2003 22:58:16 -0000 1.85 +++ Validator.java 1 Mar 2003 02:07:52 -0000 1.86 @@ -686,11 +686,6 @@ n.getQName()); } - // Get custom actions's namespace, which is used to validate the - // namespaces of any custom action attributes with qualified names - String customActionUri = - ((TagLibraryInfo) taglibs.get(n.getPrefix())).getURI(); - /* * Make sure all required attributes are present, either as * attributes or named attributes (<jsp:attribute>). @@ -698,6 +693,7 @@ * both attributes or named attributes. */ TagAttributeInfo[] tldAttrs = tagInfo.getAttributes(); + String customActionUri = n.getURI(); Attributes attrs = n.getAttributes(); for (int i=0; i<tldAttrs.length; i++) { String attr = attrs.getValue(tldAttrs[i].getName()); @@ -828,22 +824,21 @@ for (int i=0; i<namedAttributeNodes.size(); i++) { Node.NamedAttribute na = (Node.NamedAttribute)namedAttributeNodes.getNode( i ); - String uri = ""; - if (na.getPrefix() != null) { - TagLibraryInfo tagLibInfo = - (TagLibraryInfo) taglibs.get(na.getPrefix()); - if (tagLibInfo == null) { - err.jspError(n, "jsp.error.attribute.invalidPrefix", - na.getPrefix()); - } - uri = tagLibInfo.getURI(); - } boolean found = false; for (int j=0; j<tldAttrs.length; j++) { - // See above comment about namespace matches + /* + * See above comment about namespace matches. For named + * attributes, we use the prefix instead of URI as the + * match criterion, because in the case of a JSP document, + * we'd have to keep track of which namespaces are in scope + * when parsing a named attribute, in order to determine + * the URI that the prefix of the named attribute's name + * matches to. + */ + String attrPrefix = na.getPrefix(); if (na.getLocalName().equals(tldAttrs[j].getName()) - && (uri == null || uri.length() == 0 - || uri == customActionUri)) { + && (attrPrefix == null || attrPrefix.length() == 0 + || attrPrefix == n.getPrefix())) { jspAttrs[attrs.getLength() + i] = new Node.JspAttribute(na, false); NamedAttributeVisitor nav = null;
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]