Search in sources :

Example 1 with TagLibraryInfo

use of javax.servlet.jsp.tagext.TagLibraryInfo in project tomcat by apache.

the class JspDocumentParser method parseCustomAction.

/*
     * Checks if the XML element with the given tag name is a custom action,
     * and returns the corresponding Node object.
     */
private Node parseCustomAction(String qName, String localName, String uri, Attributes nonTaglibAttrs, Attributes nonTaglibXmlnsAttrs, Attributes taglibAttrs, Mark start, Node parent) throws SAXException {
    // Check if this is a user-defined (custom) tag
    TagLibraryInfo tagLibInfo = pageInfo.getTaglib(uri);
    if (tagLibInfo == null) {
        return null;
    }
    TagInfo tagInfo = tagLibInfo.getTag(localName);
    TagFileInfo tagFileInfo = tagLibInfo.getTagFile(localName);
    if (tagInfo == null && tagFileInfo == null) {
        throw new SAXParseException(Localizer.getMessage("jsp.error.xml.bad_tag", localName, uri), locator);
    }
    Class<?> tagHandlerClass = null;
    if (tagInfo != null) {
        String handlerClassName = tagInfo.getTagClassName();
        try {
            tagHandlerClass = ctxt.getClassLoader().loadClass(handlerClassName);
        } catch (Exception e) {
            throw new SAXParseException(Localizer.getMessage("jsp.error.loadclass.taghandler", handlerClassName, qName), locator, e);
        }
    }
    String prefix = getPrefix(qName);
    Node.CustomTag ret = null;
    if (tagInfo != null) {
        ret = new Node.CustomTag(qName, prefix, localName, uri, nonTaglibAttrs, nonTaglibXmlnsAttrs, taglibAttrs, start, parent, tagInfo, tagHandlerClass);
    } else {
        ret = new Node.CustomTag(qName, prefix, localName, uri, nonTaglibAttrs, nonTaglibXmlnsAttrs, taglibAttrs, start, parent, tagFileInfo);
    }
    return ret;
}
Also used : TagFileInfo(javax.servlet.jsp.tagext.TagFileInfo) SAXParseException(org.xml.sax.SAXParseException) TagInfo(javax.servlet.jsp.tagext.TagInfo) TagLibraryInfo(javax.servlet.jsp.tagext.TagLibraryInfo) JasperException(org.apache.jasper.JasperException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) SAXParseException(org.xml.sax.SAXParseException) SAXException(org.xml.sax.SAXException)

Example 2 with TagLibraryInfo

use of javax.servlet.jsp.tagext.TagLibraryInfo in project tomcat by apache.

the class JspDocumentParser method getTaglibInfo.

/*
     * Creates the tag library associated with the given uri namespace, and
     * returns it.
     *
     * @param prefix The prefix of the xmlns attribute
     * @param uri The uri namespace (value of the xmlns attribute)
     *
     * @return The tag library associated with the given uri namespace
     */
private TagLibraryInfo getTaglibInfo(String prefix, String uri) throws JasperException {
    TagLibraryInfo result = null;
    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, pageInfo, prefix, tagdir, err);
    } else {
        // uri references TLD file
        boolean isPlainUri = false;
        if (uri.startsWith(URN_JSPTLD)) {
            // uri is of the form "urn:jsptld:path"
            uri = uri.substring(URN_JSPTLD.length());
        } else {
            isPlainUri = true;
        }
        TldResourcePath tldResourcePath = ctxt.getTldResourcePath(uri);
        if (tldResourcePath != null || !isPlainUri) {
            if (ctxt.getOptions().isCaching()) {
                result = ctxt.getOptions().getCache().get(uri);
            }
            if (result == null) {
                /*
                     * If the uri value is a plain uri, a translation error must
                     * not be generated if the uri is not found in the taglib map.
                     * Instead, any actions in the namespace defined by the uri
                     * value must be treated as uninterpreted.
                     */
                result = new TagLibraryInfoImpl(ctxt, parserController, pageInfo, prefix, uri, tldResourcePath, err);
                if (ctxt.getOptions().isCaching()) {
                    ctxt.getOptions().getCache().put(uri, result);
                }
            }
        }
    }
    return result;
}
Also used : TldResourcePath(org.apache.tomcat.util.descriptor.tld.TldResourcePath) TagLibraryInfo(javax.servlet.jsp.tagext.TagLibraryInfo)

Example 3 with TagLibraryInfo

use of javax.servlet.jsp.tagext.TagLibraryInfo in project tomcat by apache.

the class Parser method parseCustomTag.

/*
     * # '<' CustomAction CustomActionBody
     *
     * CustomAction ::= TagPrefix ':' CustomActionName
     *
     * TagPrefix ::= Name
     *
     * CustomActionName ::= Name
     *
     * CustomActionBody ::= ( Attributes CustomActionEnd ) | <TRANSLATION_ERROR>
     *
     * Attributes ::= ( S Attribute )* S?
     *
     * CustomActionEnd ::= CustomActionTagDependent | CustomActionJSPContent |
     * CustomActionScriptlessContent
     *
     * CustomActionTagDependent ::= TagDependentOptionalBody
     *
     * CustomActionJSPContent ::= OptionalBody
     *
     * CustomActionScriptlessContent ::= ScriptlessOptionalBody
     */
// tagFileInfo can't be null after initial test
@SuppressWarnings("null")
private boolean parseCustomTag(Node parent) throws JasperException {
    if (reader.peekChar() != '<') {
        return false;
    }
    // Parse 'CustomAction' production (tag prefix and custom action name)
    // skip '<'
    reader.nextChar();
    String tagName = reader.parseToken(false);
    int i = tagName.indexOf(':');
    if (i == -1) {
        reader.reset(start);
        return false;
    }
    String prefix = tagName.substring(0, i);
    String shortTagName = tagName.substring(i + 1);
    // Check if this is a user-defined tag.
    String uri = pageInfo.getURI(prefix);
    if (uri == null) {
        if (pageInfo.isErrorOnUndeclaredNamespace()) {
            err.jspError(start, "jsp.error.undeclared_namespace", prefix);
        } else {
            reader.reset(start);
            // Remember the prefix for later error checking
            pageInfo.putNonCustomTagPrefix(prefix, reader.mark());
            return false;
        }
    }
    TagLibraryInfo tagLibInfo = pageInfo.getTaglib(uri);
    TagInfo tagInfo = tagLibInfo.getTag(shortTagName);
    TagFileInfo tagFileInfo = tagLibInfo.getTagFile(shortTagName);
    if (tagInfo == null && tagFileInfo == null) {
        err.jspError(start, "jsp.error.bad_tag", shortTagName, prefix);
    }
    Class<?> tagHandlerClass = null;
    if (tagInfo != null) {
        // Must be a classic tag, load it here.
        // tag files will be loaded later, in TagFileProcessor
        String handlerClassName = tagInfo.getTagClassName();
        try {
            tagHandlerClass = ctxt.getClassLoader().loadClass(handlerClassName);
        } catch (Exception e) {
            err.jspError(start, "jsp.error.loadclass.taghandler", handlerClassName, tagName);
        }
    }
    // Parse 'CustomActionBody' production:
    // At this point we are committed - if anything fails, we produce
    // a translation error.
    // Parse 'Attributes' production:
    Attributes attrs = parseAttributes();
    reader.skipSpaces();
    // Parse 'CustomActionEnd' production:
    if (reader.matches("/>")) {
        if (tagInfo != null) {
            @SuppressWarnings("unused") Node unused = new Node.CustomTag(tagName, prefix, shortTagName, uri, attrs, start, parent, tagInfo, tagHandlerClass);
        } else {
            @SuppressWarnings("unused") Node unused = new Node.CustomTag(tagName, prefix, shortTagName, uri, attrs, start, parent, tagFileInfo);
        }
        return true;
    }
    // Now we parse one of 'CustomActionTagDependent',
    // 'CustomActionJSPContent', or 'CustomActionScriptlessContent'.
    // depending on body-content in TLD.
    // 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 the TLD.
    String bc;
    if (tagInfo != null) {
        bc = tagInfo.getBodyContent();
    } else {
        bc = tagFileInfo.getTagInfo().getBodyContent();
    }
    Node tagNode = null;
    if (tagInfo != null) {
        tagNode = new Node.CustomTag(tagName, prefix, shortTagName, uri, attrs, start, parent, tagInfo, tagHandlerClass);
    } else {
        tagNode = new Node.CustomTag(tagName, prefix, shortTagName, uri, attrs, start, parent, tagFileInfo);
    }
    parseOptionalBody(tagNode, tagName, bc);
    return true;
}
Also used : TagFileInfo(javax.servlet.jsp.tagext.TagFileInfo) TagInfo(javax.servlet.jsp.tagext.TagInfo) Attributes(org.xml.sax.Attributes) TagLibraryInfo(javax.servlet.jsp.tagext.TagLibraryInfo) FileNotFoundException(java.io.FileNotFoundException) JasperException(org.apache.jasper.JasperException)

Example 4 with TagLibraryInfo

use of javax.servlet.jsp.tagext.TagLibraryInfo in project sling by apache.

the class JspDocumentParser method getTaglibInfo.

/*
     * Creates the tag library associated with the given uri namespace, and
     * returns it.
     *
     * @param prefix The prefix of the xmlns attribute
     * @param uri The uri namespace (value of the xmlns attribute)
     *
     * @return The tag library associated with the given uri namespace
     */
private TagLibraryInfo getTaglibInfo(String prefix, String uri) throws JasperException {
    TagLibraryInfo result = null;
    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, pageInfo, prefix, tagdir, err);
    } else {
        // uri references TLD file
        boolean isPlainUri = false;
        if (uri.startsWith(URN_JSPTLD)) {
            // uri is of the form "urn:jsptld:path"
            uri = uri.substring(URN_JSPTLD.length());
        } else {
            isPlainUri = true;
        }
        String[] location = ctxt.getTldLocation(uri);
        if (location != null || !isPlainUri) {
            /*
                 * If the uri value is a plain uri, a translation error must
                 * not be generated if the uri is not found in the taglib map.
                 * Instead, any actions in the namespace defined by the uri
                 * value must be treated as uninterpreted.
                 */
            result = new TagLibraryInfoImpl(ctxt, parserController, pageInfo, prefix, uri, location, err);
        }
    }
    return result;
}
Also used : TagLibraryInfo(javax.servlet.jsp.tagext.TagLibraryInfo)

Example 5 with TagLibraryInfo

use of javax.servlet.jsp.tagext.TagLibraryInfo in project sling by apache.

the class Parser method parseCustomTag.

/*
     * # '<' CustomAction CustomActionBody
     *
     * CustomAction ::= TagPrefix ':' CustomActionName
     *
     * TagPrefix ::= Name
     *
     * CustomActionName ::= Name
     *
     * CustomActionBody ::= ( Attributes CustomActionEnd ) | <TRANSLATION_ERROR>
     *
     * Attributes ::= ( S Attribute )* S?
     *
     * CustomActionEnd ::= CustomActionTagDependent | CustomActionJSPContent |
     * CustomActionScriptlessContent
     *
     * CustomActionTagDependent ::= TagDependentOptionalBody
     *
     * CustomActionJSPContent ::= OptionalBody
     *
     * CustomActionScriptlessContent ::= ScriptlessOptionalBody
     */
private boolean parseCustomTag(Node parent) throws JasperException {
    if (reader.peekChar() != '<') {
        return false;
    }
    // Parse 'CustomAction' production (tag prefix and custom action name)
    // skip '<'
    reader.nextChar();
    String tagName = reader.parseToken(false);
    int i = tagName.indexOf(':');
    if (i == -1) {
        reader.reset(start);
        return false;
    }
    String prefix = tagName.substring(0, i);
    String shortTagName = tagName.substring(i + 1);
    // Check if this is a user-defined tag.
    String uri = pageInfo.getURI(prefix);
    if (uri == null) {
        reader.reset(start);
        // Remember the prefix for later error checking
        pageInfo.putNonCustomTagPrefix(prefix, reader.mark());
        return false;
    }
    TagLibraryInfo tagLibInfo = pageInfo.getTaglib(uri);
    TagInfo tagInfo = tagLibInfo.getTag(shortTagName);
    TagFileInfo tagFileInfo = tagLibInfo.getTagFile(shortTagName);
    if (tagInfo == null && tagFileInfo == null) {
        err.jspError(start, "jsp.error.bad_tag", shortTagName, prefix);
    }
    Class tagHandlerClass = null;
    if (tagInfo != null) {
        // Must be a classic tag, load it here.
        // tag files will be loaded later, in TagFileProcessor
        String handlerClassName = tagInfo.getTagClassName();
        try {
            tagHandlerClass = ctxt.getClassLoader().loadClass(handlerClassName);
        } catch (Exception e) {
            err.jspError(start, "jsp.error.loadclass.taghandler", handlerClassName, tagName);
        }
    }
    // Parse 'CustomActionBody' production:
    // At this point we are committed - if anything fails, we produce
    // a translation error.
    // Parse 'Attributes' production:
    Attributes attrs = parseAttributes();
    reader.skipSpaces();
    // Parse 'CustomActionEnd' production:
    if (reader.matches("/>")) {
        if (tagInfo != null) {
            new Node.CustomTag(tagName, prefix, shortTagName, uri, attrs, start, parent, tagInfo, tagHandlerClass);
        } else {
            new Node.CustomTag(tagName, prefix, shortTagName, uri, attrs, start, parent, tagFileInfo);
        }
        return true;
    }
    // Now we parse one of 'CustomActionTagDependent',
    // 'CustomActionJSPContent', or 'CustomActionScriptlessContent'.
    // depending on body-content in TLD.
    // 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 the TLD.
    String bc;
    if (tagInfo != null) {
        bc = tagInfo.getBodyContent();
    } else {
        bc = tagFileInfo.getTagInfo().getBodyContent();
    }
    Node tagNode = null;
    if (tagInfo != null) {
        tagNode = new Node.CustomTag(tagName, prefix, shortTagName, uri, attrs, start, parent, tagInfo, tagHandlerClass);
    } else {
        tagNode = new Node.CustomTag(tagName, prefix, shortTagName, uri, attrs, start, parent, tagFileInfo);
    }
    parseOptionalBody(tagNode, tagName, bc);
    return true;
}
Also used : TagFileInfo(javax.servlet.jsp.tagext.TagFileInfo) TagInfo(javax.servlet.jsp.tagext.TagInfo) Attributes(org.xml.sax.Attributes) TagLibraryInfo(javax.servlet.jsp.tagext.TagLibraryInfo) FileNotFoundException(java.io.FileNotFoundException) JasperException(org.apache.sling.scripting.jsp.jasper.JasperException)

Aggregations

TagLibraryInfo (javax.servlet.jsp.tagext.TagLibraryInfo)6 FileNotFoundException (java.io.FileNotFoundException)4 TagFileInfo (javax.servlet.jsp.tagext.TagFileInfo)4 TagInfo (javax.servlet.jsp.tagext.TagInfo)4 IOException (java.io.IOException)2 JasperException (org.apache.jasper.JasperException)2 JasperException (org.apache.sling.scripting.jsp.jasper.JasperException)2 Attributes (org.xml.sax.Attributes)2 SAXException (org.xml.sax.SAXException)2 SAXParseException (org.xml.sax.SAXParseException)2 TldResourcePath (org.apache.tomcat.util.descriptor.tld.TldResourcePath)1