Java Code Examples for javax.servlet.jsp.tagext.TagLibraryInfo#getTag()

The following examples show how to use javax.servlet.jsp.tagext.TagLibraryInfo#getTag() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JspDocumentParser.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
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;
}
 
Example 2
Source File: JspDocumentParser.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
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;
}
 
Example 3
Source File: Parser.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
private boolean parseCustomTag(Node parent) throws JasperException {

        if (reader.peekChar() != '<') {
            return false;
        }

        // Parse 'CustomAction' production (tag prefix and custom action name)
        reader.nextChar(); // skip '<'
        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) {
                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;
    }
 
Example 4
Source File: JspDocumentParser.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
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;
}
 
Example 5
Source File: Parser.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
private boolean parseCustomTag(Node parent) throws JasperException {

        if (reader.peekChar() != '<') {
            return false;
        }

        // Parse 'CustomAction' production (tag prefix and custom action name)
        reader.nextChar(); // skip '<'
        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) {
                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;
    }
 
Example 6
Source File: JspDocumentParser.java    From packagedrone with Eclipse Public License 1.0 4 votes vote down vote up
private Node parseCustomAction(
    String qName,
    String localName,
    String uri,
    Attributes nonTaglibAttrs,
    Attributes nonTaglibXmlnsAttrs,
    Attributes taglibAttrs,
    Mark start,
    Node parent)
    throws SAXException {

    if (uri.startsWith(TagConstants.URN_JSPTLD)) {
        uri = uri.substring(TagConstants.URN_JSPTLD.length());
    }

    // 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 SAXException(
            Localizer.getMessage("jsp.error.xml.bad_tag", localName, uri));
    }
    Class tagHandlerClass = null;
    if (tagInfo != null) {
        String handlerClassName = tagInfo.getTagClassName();
        try {
            tagHandlerClass =
                ctxt.getClassLoader().loadClass(handlerClassName);
        } catch (Exception e) {
            throw new SAXException(
                Localizer.getMessage("jsp.error.loadclass.taghandler",
                                     handlerClassName,
                                     qName),
                e);
        }
    }

    String prefix = "";
    int colon = qName.indexOf(':');
    if (colon != -1) {
        prefix = qName.substring(0, colon);
    }

    Node.CustomTag ret = null;
    if (tagInfo != null) {
        ret =
            new Node.CustomTag(
                tagLibInfo.getRequiredVersion(),
                qName,
                prefix,
                localName,
                uri,
                nonTaglibAttrs,
                nonTaglibXmlnsAttrs,
                taglibAttrs,
                start,
                parent,
                tagInfo,
                tagHandlerClass);
    } else {
        ret =
            new Node.CustomTag(
                tagLibInfo.getRequiredVersion(),
                qName,
                prefix,
                localName,
                uri,
                nonTaglibAttrs,
                nonTaglibXmlnsAttrs,
                taglibAttrs,
                start,
                parent,
                tagFileInfo);
    }

    return ret;
}