Search in sources :

Example 31 with LexicalHandler

use of org.xml.sax.ext.LexicalHandler in project spring-framework by spring-projects.

the class AbstractStaxXMLReaderTestCase method lexicalHandler.

@Test
public void lexicalHandler() throws Exception {
    Resource testLexicalHandlerXml = new ClassPathResource("testLexicalHandler.xml", getClass());
    LexicalHandler expectedLexicalHandler = mockLexicalHandler();
    standardReader.setContentHandler(null);
    standardReader.setProperty("http://xml.org/sax/properties/lexical-handler", expectedLexicalHandler);
    standardReader.parse(new InputSource(testLexicalHandlerXml.getInputStream()));
    inputFactory.setProperty("javax.xml.stream.isCoalescing", Boolean.FALSE);
    inputFactory.setProperty("http://java.sun.com/xml/stream/properties/report-cdata-event", Boolean.TRUE);
    inputFactory.setProperty("javax.xml.stream.isReplacingEntityReferences", Boolean.FALSE);
    inputFactory.setProperty("javax.xml.stream.isSupportingExternalEntities", Boolean.FALSE);
    LexicalHandler actualLexicalHandler = mockLexicalHandler();
    willAnswer(invocation -> invocation.getArguments()[0] = "element").given(actualLexicalHandler).startDTD(anyString(), anyString(), anyString());
    AbstractStaxXMLReader staxXmlReader = createStaxXmlReader(testLexicalHandlerXml.getInputStream());
    staxXmlReader.setProperty("http://xml.org/sax/properties/lexical-handler", actualLexicalHandler);
    staxXmlReader.parse(new InputSource());
// TODO: broken comparison since Mockito 2.2 upgrade
// verifyIdenticalInvocations(expectedLexicalHandler, actualLexicalHandler);
}
Also used : InputSource(org.xml.sax.InputSource) LexicalHandler(org.xml.sax.ext.LexicalHandler) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 32 with LexicalHandler

use of org.xml.sax.ext.LexicalHandler in project j2objc by google.

the class DOM3TreeWalker method traverse.

/**
     * Perform a pre-order traversal non-recursive style.  
     *
     * Note that TreeWalker assumes that the subtree is intended to represent 
     * a complete (though not necessarily well-formed) document and, during a 
     * traversal, startDocument and endDocument will always be issued to the 
     * SAX listener.
     *  
     * @param pos Node in the tree where to start traversal
     *
     * @throws TransformerException
     */
public void traverse(Node pos) throws org.xml.sax.SAXException {
    this.fSerializer.startDocument();
    // Determine if the Node is a DOM Level 3 Core Node.
    if (pos.getNodeType() != Node.DOCUMENT_NODE) {
        Document ownerDoc = pos.getOwnerDocument();
        if (ownerDoc != null && ownerDoc.getImplementation().hasFeature("Core", "3.0")) {
            fIsLevel3DOM = true;
        }
    } else {
        if (((Document) pos).getImplementation().hasFeature("Core", "3.0")) {
            fIsLevel3DOM = true;
        }
    }
    if (fSerializer instanceof LexicalHandler) {
        fLexicalHandler = ((LexicalHandler) this.fSerializer);
    }
    if (fFilter != null)
        fWhatToShowFilter = fFilter.getWhatToShow();
    Node top = pos;
    while (null != pos) {
        startNode(pos);
        Node nextNode = null;
        nextNode = pos.getFirstChild();
        while (null == nextNode) {
            endNode(pos);
            if (top.equals(pos))
                break;
            nextNode = pos.getNextSibling();
            if (null == nextNode) {
                pos = pos.getParentNode();
                if ((null == pos) || (top.equals(pos))) {
                    if (null != pos)
                        endNode(pos);
                    nextNode = null;
                    break;
                }
            }
        }
        pos = nextNode;
    }
    this.fSerializer.endDocument();
}
Also used : LexicalHandler(org.xml.sax.ext.LexicalHandler) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document)

Example 33 with LexicalHandler

use of org.xml.sax.ext.LexicalHandler in project robovm by robovm.

the class DOM3TreeWalker method traverse.

/**
     * Perform a pre-order traversal non-recursive style.  
     *
     * Note that TreeWalker assumes that the subtree is intended to represent 
     * a complete (though not necessarily well-formed) document and, during a 
     * traversal, startDocument and endDocument will always be issued to the 
     * SAX listener.
     *  
     * @param pos Node in the tree where to start traversal
     *
     * @throws TransformerException
     */
public void traverse(Node pos) throws org.xml.sax.SAXException {
    this.fSerializer.startDocument();
    // Determine if the Node is a DOM Level 3 Core Node.
    if (pos.getNodeType() != Node.DOCUMENT_NODE) {
        Document ownerDoc = pos.getOwnerDocument();
        if (ownerDoc != null && ownerDoc.getImplementation().hasFeature("Core", "3.0")) {
            fIsLevel3DOM = true;
        }
    } else {
        if (((Document) pos).getImplementation().hasFeature("Core", "3.0")) {
            fIsLevel3DOM = true;
        }
    }
    if (fSerializer instanceof LexicalHandler) {
        fLexicalHandler = ((LexicalHandler) this.fSerializer);
    }
    if (fFilter != null)
        fWhatToShowFilter = fFilter.getWhatToShow();
    Node top = pos;
    while (null != pos) {
        startNode(pos);
        Node nextNode = null;
        nextNode = pos.getFirstChild();
        while (null == nextNode) {
            endNode(pos);
            if (top.equals(pos))
                break;
            nextNode = pos.getNextSibling();
            if (null == nextNode) {
                pos = pos.getParentNode();
                if ((null == pos) || (top.equals(pos))) {
                    if (null != pos)
                        endNode(pos);
                    nextNode = null;
                    break;
                }
            }
        }
        pos = nextNode;
    }
    this.fSerializer.endDocument();
}
Also used : LexicalHandler(org.xml.sax.ext.LexicalHandler) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document)

Example 34 with LexicalHandler

use of org.xml.sax.ext.LexicalHandler in project sling by apache.

the class HtmlParserImpl method parse.

/**
     * @see org.apache.sling.commons.html.HtmlParser#parse(java.io.InputStream, java.lang.String, org.xml.sax.ContentHandler)
     */
public void parse(InputStream stream, String encoding, ContentHandler ch) throws SAXException {
    final Parser parser = new Parser();
    if (ch instanceof LexicalHandler) {
        parser.setProperty("http://xml.org/sax/properties/lexical-handler", ch);
    }
    for (String feature : features.keySet()) {
        parser.setProperty(feature, features.get(feature));
    }
    parser.setContentHandler(ch);
    final InputSource source = new InputSource(stream);
    source.setEncoding(encoding);
    try {
        parser.parse(source);
    } catch (IOException ioe) {
        throw new SAXException(ioe);
    }
}
Also used : InputSource(org.xml.sax.InputSource) LexicalHandler(org.xml.sax.ext.LexicalHandler) IOException(java.io.IOException) HtmlParser(org.apache.sling.commons.html.HtmlParser) Parser(org.ccil.cowan.tagsoup.Parser) SAXException(org.xml.sax.SAXException)

Aggregations

LexicalHandler (org.xml.sax.ext.LexicalHandler)34 Node (org.w3c.dom.Node)14 IOException (java.io.IOException)11 TransformerException (javax.xml.transform.TransformerException)10 ContentHandler (org.xml.sax.ContentHandler)9 Element (org.w3c.dom.Element)8 EntityReference (org.w3c.dom.EntityReference)8 NamedNodeMap (org.w3c.dom.NamedNodeMap)8 SAXException (org.xml.sax.SAXException)8 DTDHandler (org.xml.sax.DTDHandler)6 SAXResult (javax.xml.transform.sax.SAXResult)5 DocumentBuilder (javax.xml.parsers.DocumentBuilder)4 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)4 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)4 DOMResult (javax.xml.transform.dom.DOMResult)4 StreamResult (javax.xml.transform.stream.StreamResult)4 SerializationHandler (org.apache.xml.serializer.SerializationHandler)4 Serializer (org.apache.xml.serializer.Serializer)4 ToXMLSAXHandler (org.apache.xml.serializer.ToXMLSAXHandler)4 DOMBuilder (org.apache.xml.utils.DOMBuilder)4