Search in sources :

Example 91 with Attributes

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

the class Parser method parseElement.

private void parseElement(Node parent) throws JasperException {
    Attributes attrs = parseAttributes();
    reader.skipSpaces();
    Node elementNode = new Node.JspElement(attrs, start, parent);
    parseOptionalBody(elementNode, "jsp:element", TagInfo.BODY_CONTENT_JSP);
}
Also used : Attributes(org.xml.sax.Attributes)

Example 92 with Attributes

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

the class Parser method parsePlugin.

/*
     * For Plugin: StdActionContent ::= Attributes PluginBody
     * 
     * PluginBody ::= EmptyBody | ( '>' S? ( '<jsp:attribute' NamedAttributes )? '<jsp:body' (
     * JspBodyPluginTags | <TRANSLATION_ERROR> ) S? ETag ) | ( '>' S? PluginTags
     * ETag )
     * 
     * EmptyBody ::= '/>' | ( '>' ETag ) | ( '>' S? '<jsp:attribute'
     * NamedAttributes ETag )
     * 
     */
private void parsePlugin(Node parent) throws JasperException {
    Attributes attrs = parseAttributes();
    reader.skipSpaces();
    Node pluginNode = new Node.PlugIn(attrs, start, parent);
    parseOptionalBody(pluginNode, "jsp:plugin", JAVAX_BODY_CONTENT_PLUGIN);
}
Also used : Attributes(org.xml.sax.Attributes)

Example 93 with Attributes

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

the class Parser method parseInvoke.

private void parseInvoke(Node parent) throws JasperException {
    Attributes attrs = parseAttributes();
    reader.skipSpaces();
    Node invokeNode = new Node.InvokeAction(attrs, start, parent);
    parseEmptyBody(invokeNode, "jsp:invoke");
}
Also used : Attributes(org.xml.sax.Attributes)

Example 94 with Attributes

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

the class JspUtil method checkAttributes.

/**
 * Checks if all mandatory attributes are present and if all attributes
 * present have valid names. Checks attributes specified as XML-style
 * attributes as well as attributes specified using the jsp:attribute
 * standard action.
 */
public static void checkAttributes(String typeOfTag, Node n, ValidAttribute[] validAttributes, ErrorDispatcher err) throws JasperException {
    Attributes attrs = n.getAttributes();
    Mark start = n.getStart();
    boolean valid = true;
    // AttributesImpl.removeAttribute is broken, so we do this...
    int tempLength = (attrs == null) ? 0 : attrs.getLength();
    Vector<String> temp = new Vector<String>(tempLength, 1);
    for (int i = 0; i < tempLength; i++) {
        // If attrs==null, tempLength == 0
        @SuppressWarnings("null") String qName = attrs.getQName(i);
        if ((!qName.equals("xmlns")) && (!qName.startsWith("xmlns:"))) {
            temp.addElement(qName);
        }
    }
    // Add names of attributes specified using jsp:attribute
    Node.Nodes tagBody = n.getBody();
    if (tagBody != null) {
        int numSubElements = tagBody.size();
        for (int i = 0; i < numSubElements; i++) {
            Node node = tagBody.getNode(i);
            if (node instanceof Node.NamedAttribute) {
                String attrName = node.getAttributeValue("name");
                temp.addElement(attrName);
                // Check if this value appear in the attribute of the node
                if (n.getAttributeValue(attrName) != null) {
                    err.jspError(n, "jsp.error.duplicate.name.jspattribute", attrName);
                }
            } else {
                // jsp:body can come after it.
                break;
            }
        }
    }
    /*
         * First check to see if all the mandatory attributes are present. If so
         * only then proceed to see if the other attributes are valid for the
         * particular tag.
         */
    String missingAttribute = null;
    for (int i = 0; i < validAttributes.length; i++) {
        int attrPos;
        if (validAttributes[i].mandatory) {
            attrPos = temp.indexOf(validAttributes[i].name);
            if (attrPos != -1) {
                temp.remove(attrPos);
                valid = true;
            } else {
                valid = false;
                missingAttribute = validAttributes[i].name;
                break;
            }
        }
    }
    // If mandatory attribute is missing then the exception is thrown
    if (!valid) {
        err.jspError(start, "jsp.error.mandatory.attribute", typeOfTag, missingAttribute);
    }
    // Check to see if there are any more attributes for the specified tag.
    int attrLeftLength = temp.size();
    if (attrLeftLength == 0) {
        return;
    }
    // Now check to see if the rest of the attributes are valid too.
    String attribute = null;
    for (int j = 0; j < attrLeftLength; j++) {
        valid = false;
        attribute = temp.elementAt(j);
        for (int i = 0; i < validAttributes.length; i++) {
            if (attribute.equals(validAttributes[i].name)) {
                valid = true;
                break;
            }
        }
        if (!valid) {
            err.jspError(start, "jsp.error.invalid.attribute", typeOfTag, attribute);
        }
    }
// XXX *could* move EL-syntax validation here... (sb)
}
Also used : Attributes(org.xml.sax.Attributes) Vector(java.util.Vector)

Example 95 with Attributes

use of org.xml.sax.Attributes in project webtools.sourceediting by eclipse.

the class XMLValidator method createXMLReader.

/**
 * Create an XML Reader.
 *
 * @return The newly created XML reader or null if unsuccessful.
 * @throws Exception
 */
protected XMLReader createXMLReader(final XMLValidationInfo valinfo, XMLEntityResolver entityResolver) throws Exception {
    XMLReader reader = null;
    // move to Xerces-2... add the contextClassLoader stuff
    ClassLoader prevClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
        MyStandardParserConfiguration configuration = new MyStandardParserConfiguration(valinfo);
        reader = new org.apache.xerces.parsers.SAXParser(configuration) {

            private XMLLocator locator = null;

            /* (non-Javadoc)
         * @see org.apache.xerces.parsers.AbstractSAXParser#startDocument(org.apache.xerces.xni.XMLLocator, java.lang.String, org.apache.xerces.xni.NamespaceContext, org.apache.xerces.xni.Augmentations)
         */
            public void startDocument(org.apache.xerces.xni.XMLLocator theLocator, java.lang.String encoding, NamespaceContext nscontext, org.apache.xerces.xni.Augmentations augs) {
                locator = theLocator;
                valinfo.setXMLLocator(theLocator);
                super.startDocument(theLocator, encoding, nscontext, augs);
            }

            /* (non-Javadoc)
         * @see org.apache.xerces.parsers.AbstractSAXParser#startElement(org.apache.xerces.xni.QName, org.apache.xerces.xni.XMLAttributes, org.apache.xerces.xni.Augmentations)
         */
            public void startElement(QName element, XMLAttributes attributes, Augmentations augs) throws XNIException {
                valinfo.getStartElementLocations().push(new LocationCoordinate(locator.getLineNumber(), locator.getColumnNumber()));
                super.startElement(element, attributes, augs);
            }

            /* (non-Javadoc)
		 * @see org.apache.xerces.parsers.AbstractSAXParser#endElement(org.apache.xerces.xni.QName, org.apache.xerces.xni.Augmentations)
		 */
            public void endElement(QName element, Augmentations augs) throws XNIException {
                super.endElement(element, augs);
                valinfo.getStartElementLocations().pop();
            }
        };
        // $NON-NLS-1$
        reader.setFeature("http://apache.org/xml/features/continue-after-fatal-error", false);
        // $NON-NLS-1$
        reader.setFeature("http://xml.org/sax/features/namespace-prefixes", valinfo.isNamespaceEncountered());
        // $NON-NLS-1$
        reader.setFeature("http://xml.org/sax/features/namespaces", valinfo.isNamespaceEncountered());
        reader.setContentHandler(new DefaultHandler() {

            public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
                valinfo.getErrorCustomizationManager().startElement(uri, localName);
            }

            public void endElement(String uri, String localName, String qName) throws SAXException {
                valinfo.getErrorCustomizationManager().endElement(uri, localName);
            }
        });
        // MH make sure validation works even when a customer entityResolver is note set (i.e. via setURIResolver())
        if (entityResolver != null) {
            // $NON-NLS-1$
            reader.setProperty("http://apache.org/xml/properties/internal/entity-resolver", entityResolver);
        }
        // $NON-NLS-1$
        reader.setProperty("http://xml.org/sax/properties/declaration-handler", new MyDeclHandler());
    } catch (Exception e) {
        Logger.logException(e);
    // e.printStackTrace();
    } finally {
        Thread.currentThread().setContextClassLoader(prevClassLoader);
    }
    return reader;
}
Also used : Augmentations(org.apache.xerces.xni.Augmentations) QName(org.apache.xerces.xni.QName) XMLLocator(org.apache.xerces.xni.XMLLocator) XMLAttributes(org.apache.xerces.xni.XMLAttributes) Attributes(org.xml.sax.Attributes) XMLLocator(org.apache.xerces.xni.XMLLocator) XNIException(org.apache.xerces.xni.XNIException) URISyntaxException(java.net.URISyntaxException) XNIException(org.apache.xerces.xni.XNIException) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) SAXParseException(org.xml.sax.SAXParseException) DefaultHandler(org.xml.sax.helpers.DefaultHandler) SAXException(org.xml.sax.SAXException) Augmentations(org.apache.xerces.xni.Augmentations) XMLAttributes(org.apache.xerces.xni.XMLAttributes) NamespaceContext(org.apache.xerces.xni.NamespaceContext) XMLReader(org.xml.sax.XMLReader)

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