Search in sources :

Example 26 with LexicalHandler

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

the class TransformerImpl method executeChildTemplates.

/**
      * Execute each of the children of a template element.
      *
      * @param elem The ElemTemplateElement that contains the children
      * that should execute.
      * @param handler The ContentHandler to where the result events
      * should be fed.
      *
      * @throws TransformerException
      * @xsl.usage advanced
      */
public void executeChildTemplates(ElemTemplateElement elem, ContentHandler handler) throws TransformerException {
    SerializationHandler xoh = this.getSerializationHandler();
    // These may well not be the same!  In this case when calling
    // the Redirect extension, it has already set the ContentHandler
    // in the Transformer.
    SerializationHandler savedHandler = xoh;
    try {
        xoh.flushPending();
        // %REVIEW% Make sure current node is being pushed.
        LexicalHandler lex = null;
        if (handler instanceof LexicalHandler) {
            lex = (LexicalHandler) handler;
        }
        m_serializationHandler = new ToXMLSAXHandler(handler, lex, savedHandler.getEncoding());
        m_serializationHandler.setTransformer(this);
        executeChildTemplates(elem, true);
    } catch (TransformerException e) {
        throw e;
    } catch (SAXException se) {
        throw new TransformerException(se);
    } finally {
        m_serializationHandler = savedHandler;
    }
}
Also used : LexicalHandler(org.xml.sax.ext.LexicalHandler) SerializationHandler(org.apache.xml.serializer.SerializationHandler) ToXMLSAXHandler(org.apache.xml.serializer.ToXMLSAXHandler) TransformerException(javax.xml.transform.TransformerException) SAXException(org.xml.sax.SAXException)

Example 27 with LexicalHandler

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

the class SAXParserTest method testSetGetProperty.

public void testSetGetProperty() {
    // Ordinary case
    String validName = "http://xml.org/sax/properties/lexical-handler";
    LexicalHandler validValue = new MockHandler(new MethodLogger());
    try {
        SAXParser parser = spf.newSAXParser();
        parser.setProperty(validName, validValue);
        assertEquals(validValue, parser.getProperty(validName));
        parser.setProperty(validName, null);
        assertEquals(null, parser.getProperty(validName));
    } catch (Exception e) {
        throw new RuntimeException("Unexpected exception", e);
    }
    // Unsupported property
    try {
        SAXParser parser = spf.newSAXParser();
        parser.setProperty("foo", "bar");
        fail("SAXNotRecognizedException expected");
    } catch (SAXNotRecognizedException e) {
    // Expected
    } catch (Exception e) {
        throw new RuntimeException("Unexpected exception", e);
    }
    try {
        SAXParser parser = spf.newSAXParser();
        parser.getProperty("foo");
        fail("SAXNotRecognizedException expected");
    } catch (SAXNotRecognizedException e) {
    // Expected
    } catch (Exception e) {
        throw new RuntimeException("Unexpected exception", e);
    }
    // No name case
    try {
        SAXParser parser = spf.newSAXParser();
        parser.setProperty(null, "bar");
        fail("NullPointerException expected");
    } catch (NullPointerException e) {
    // Expected
    } catch (Exception e) {
        throw new RuntimeException("Unexpected exception", e);
    }
    try {
        SAXParser parser = spf.newSAXParser();
        parser.getProperty(null);
        fail("NullPointerException expected");
    } catch (NullPointerException e) {
    // Expected
    } catch (Exception e) {
        throw new RuntimeException("Unexpected exception", e);
    }
}
Also used : LexicalHandler(org.xml.sax.ext.LexicalHandler) SAXParser(javax.xml.parsers.SAXParser) MockHandler(tests.api.org.xml.sax.support.MockHandler) SAXNotRecognizedException(org.xml.sax.SAXNotRecognizedException) MethodLogger(tests.api.org.xml.sax.support.MethodLogger) SAXNotSupportedException(org.xml.sax.SAXNotSupportedException) SAXNotRecognizedException(org.xml.sax.SAXNotRecognizedException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException)

Example 28 with LexicalHandler

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

the class CastorMarshaller method marshalXmlEventWriter.

@Override
protected void marshalXmlEventWriter(Object graph, XMLEventWriter eventWriter) throws XmlMappingException {
    ContentHandler contentHandler = StaxUtils.createContentHandler(eventWriter);
    LexicalHandler lexicalHandler = null;
    if (contentHandler instanceof LexicalHandler) {
        lexicalHandler = (LexicalHandler) contentHandler;
    }
    marshalSaxHandlers(graph, contentHandler, lexicalHandler);
}
Also used : LexicalHandler(org.xml.sax.ext.LexicalHandler) ContentHandler(org.xml.sax.ContentHandler)

Example 29 with LexicalHandler

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

the class AbstractMarshaller method marshalSaxResult.

/**
	 * Template method for handling {@code SAXResult}s.
	 * <p>This implementation delegates to {@code marshalSaxHandlers}.
	 * @param graph the root of the object graph to marshal
	 * @param saxResult the {@code SAXResult}
	 * @throws XmlMappingException if the given object cannot be marshalled to the result
	 * @see #marshalSaxHandlers(Object, org.xml.sax.ContentHandler, org.xml.sax.ext.LexicalHandler)
	 */
protected void marshalSaxResult(Object graph, SAXResult saxResult) throws XmlMappingException {
    ContentHandler contentHandler = saxResult.getHandler();
    Assert.notNull(contentHandler, "ContentHandler not set on SAXResult");
    LexicalHandler lexicalHandler = saxResult.getLexicalHandler();
    marshalSaxHandlers(graph, contentHandler, lexicalHandler);
}
Also used : LexicalHandler(org.xml.sax.ext.LexicalHandler) ContentHandler(org.xml.sax.ContentHandler)

Example 30 with LexicalHandler

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

the class AbstractStaxXMLReaderTestCase method mockLexicalHandler.

private LexicalHandler mockLexicalHandler() throws Exception {
    LexicalHandler lexicalHandler = mock(LexicalHandler.class);
    willAnswer(new CopyCharsAnswer()).given(lexicalHandler).comment(any(char[].class), anyInt(), anyInt());
    return lexicalHandler;
}
Also used : LexicalHandler(org.xml.sax.ext.LexicalHandler)

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