Search in sources :

Example 86 with Attributes

use of org.xml.sax.Attributes in project tomcat70 by apache.

the class Parser method parseNamedAttributes.

/*
     * Parses named attributes.
     */
private void parseNamedAttributes(Node parent) throws JasperException {
    do {
        Mark start = reader.mark();
        Attributes attrs = parseAttributes();
        Node.NamedAttribute namedAttributeNode = new Node.NamedAttribute(attrs, start, parent);
        reader.skipSpaces();
        if (!reader.matches("/>")) {
            if (!reader.matches(">")) {
                err.jspError(start, "jsp.error.unterminated", "<jsp:attribute");
            }
            if (namedAttributeNode.isTrim()) {
                reader.skipSpaces();
            }
            parseBody(namedAttributeNode, "jsp:attribute", getAttributeBodyType(parent, attrs.getValue("name")));
            if (namedAttributeNode.isTrim()) {
                Node.Nodes subElems = namedAttributeNode.getBody();
                if (subElems != null) {
                    Node lastNode = subElems.getNode(subElems.size() - 1);
                    if (lastNode instanceof Node.TemplateText) {
                        ((Node.TemplateText) lastNode).rtrim();
                    }
                }
            }
        }
        reader.skipSpaces();
    } while (reader.matches("<jsp:attribute"));
}
Also used : Attributes(org.xml.sax.Attributes)

Example 87 with Attributes

use of org.xml.sax.Attributes in project tomcat70 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) {
        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;
}
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 88 with Attributes

use of org.xml.sax.Attributes in project tomcat70 by apache.

the class Parser method parseDoBody.

private void parseDoBody(Node parent) throws JasperException {
    Attributes attrs = parseAttributes();
    reader.skipSpaces();
    Node doBodyNode = new Node.DoBodyAction(attrs, start, parent);
    parseEmptyBody(doBodyNode, "jsp:doBody");
}
Also used : Attributes(org.xml.sax.Attributes)

Example 89 with Attributes

use of org.xml.sax.Attributes in project tomcat70 by apache.

the class Parser method parseForward.

/*
     * For Forward: StdActionContent ::= Attributes ParamBody
     */
private void parseForward(Node parent) throws JasperException {
    Attributes attrs = parseAttributes();
    reader.skipSpaces();
    Node forwardNode = new Node.ForwardAction(attrs, start, parent);
    parseOptionalBody(forwardNode, "jsp:forward", JAVAX_BODY_CONTENT_PARAM);
}
Also used : Attributes(org.xml.sax.Attributes)

Example 90 with Attributes

use of org.xml.sax.Attributes in project tomcat70 by apache.

the class Parser method parseSetProperty.

/*
     * For SetProperty: StdActionContent ::= Attributes EmptyBody
     */
private void parseSetProperty(Node parent) throws JasperException {
    Attributes attrs = parseAttributes();
    reader.skipSpaces();
    Node setPropertyNode = new Node.SetProperty(attrs, start, parent);
    parseOptionalBody(setPropertyNode, "jsp:setProperty", TagInfo.BODY_CONTENT_EMPTY);
}
Also used : Attributes(org.xml.sax.Attributes)

Aggregations

Attributes (org.xml.sax.Attributes)279 DefaultHandler (org.xml.sax.helpers.DefaultHandler)74 SAXException (org.xml.sax.SAXException)66 AttributesImpl (org.xml.sax.helpers.AttributesImpl)50 SAXParser (javax.xml.parsers.SAXParser)48 Test (org.junit.Test)46 POSaveFailedException (org.adempiere.pipo.exception.POSaveFailedException)37 InputSource (org.xml.sax.InputSource)33 SAXParserFactory (javax.xml.parsers.SAXParserFactory)30 IOException (java.io.IOException)29 File (java.io.File)22 ByteArrayInputStream (java.io.ByteArrayInputStream)19 InputStream (java.io.InputStream)17 ArrayList (java.util.ArrayList)17 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)17 Test (org.junit.jupiter.api.Test)17 XMLReader (org.xml.sax.XMLReader)17 ContentHandler (org.xml.sax.ContentHandler)15 StringReader (java.io.StringReader)12 Transformer (org.apache.sling.rewriter.Transformer)10