Search in sources :

Example 11 with ContentHandler

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

the class AbstractStaxXMLReaderTestCase method mockContentHandler.

protected final ContentHandler mockContentHandler() throws Exception {
    ContentHandler contentHandler = mock(ContentHandler.class);
    willAnswer(new CopyCharsAnswer()).given(contentHandler).characters(any(char[].class), anyInt(), anyInt());
    willAnswer(new CopyCharsAnswer()).given(contentHandler).ignorableWhitespace(any(char[].class), anyInt(), anyInt());
    willAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            invocation.getArguments()[3] = new AttributesImpl((Attributes) invocation.getArguments()[3]);
            return null;
        }
    }).given(contentHandler).startElement(anyString(), anyString(), anyString(), any(Attributes.class));
    return contentHandler;
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Attributes(org.xml.sax.Attributes) ContentHandler(org.xml.sax.ContentHandler)

Example 12 with ContentHandler

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

the class AbstractStaxXMLReaderTestCase method contentHandlerNamespacesPrefixes.

@Test
public void contentHandlerNamespacesPrefixes() throws Exception {
    standardReader.setFeature("http://xml.org/sax/features/namespaces", true);
    standardReader.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
    standardReader.parse(new InputSource(createTestInputStream()));
    AbstractStaxXMLReader staxXmlReader = createStaxXmlReader(createTestInputStream());
    ContentHandler contentHandler = mockContentHandler();
    staxXmlReader.setFeature("http://xml.org/sax/features/namespaces", true);
    staxXmlReader.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
    staxXmlReader.setContentHandler(contentHandler);
    staxXmlReader.parse(new InputSource());
    verifyIdenticalInvocations(standardContentHandler, contentHandler);
}
Also used : InputSource(org.xml.sax.InputSource) ContentHandler(org.xml.sax.ContentHandler) Test(org.junit.Test)

Example 13 with ContentHandler

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

the class CastorMarshaller method marshalXmlStreamWriter.

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

Example 14 with ContentHandler

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

the class XStreamMarshaller 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 15 with ContentHandler

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

the class CastorMarshallerTests method marshalSaxResult.

@Test
public void marshalSaxResult() throws Exception {
    ContentHandler contentHandler = mock(ContentHandler.class);
    SAXResult result = new SAXResult(contentHandler);
    marshaller.marshal(flights, result);
    InOrder ordered = inOrder(contentHandler);
    ordered.verify(contentHandler).startDocument();
    ordered.verify(contentHandler).startPrefixMapping("tns", "http://samples.springframework.org/flight");
    ordered.verify(contentHandler).startElement(eq("http://samples.springframework.org/flight"), eq("flights"), eq("tns:flights"), isA(Attributes.class));
    ordered.verify(contentHandler).startElement(eq("http://samples.springframework.org/flight"), eq("flight"), eq("tns:flight"), isA(Attributes.class));
    ordered.verify(contentHandler).startElement(eq("http://samples.springframework.org/flight"), eq("number"), eq("tns:number"), isA(Attributes.class));
    ordered.verify(contentHandler).characters(eq(new char[] { '4', '2' }), eq(0), eq(2));
    ordered.verify(contentHandler).endElement("http://samples.springframework.org/flight", "number", "tns:number");
    ordered.verify(contentHandler).endElement("http://samples.springframework.org/flight", "flight", "tns:flight");
    ordered.verify(contentHandler).endElement("http://samples.springframework.org/flight", "flights", "tns:flights");
    ordered.verify(contentHandler).endPrefixMapping("tns");
    ordered.verify(contentHandler).endDocument();
}
Also used : InOrder(org.mockito.InOrder) SAXResult(javax.xml.transform.sax.SAXResult) Attributes(org.xml.sax.Attributes) ContentHandler(org.xml.sax.ContentHandler) Test(org.junit.Test)

Aggregations

ContentHandler (org.xml.sax.ContentHandler)351 BodyContentHandler (org.apache.tika.sax.BodyContentHandler)229 Metadata (org.apache.tika.metadata.Metadata)228 InputStream (java.io.InputStream)210 Test (org.junit.Test)208 ParseContext (org.apache.tika.parser.ParseContext)163 Parser (org.apache.tika.parser.Parser)105 TikaTest (org.apache.tika.TikaTest)103 AutoDetectParser (org.apache.tika.parser.AutoDetectParser)102 TikaInputStream (org.apache.tika.io.TikaInputStream)75 ByteArrayInputStream (java.io.ByteArrayInputStream)63 SAXException (org.xml.sax.SAXException)40 IOException (java.io.IOException)34 TeeContentHandler (org.apache.tika.sax.TeeContentHandler)27 TikaException (org.apache.tika.exception.TikaException)24 ExcelParserTest (org.apache.tika.parser.microsoft.ExcelParserTest)24 WordParserTest (org.apache.tika.parser.microsoft.WordParserTest)24 AttributesImpl (org.xml.sax.helpers.AttributesImpl)21 XHTMLContentHandler (org.apache.tika.sax.XHTMLContentHandler)20 InputSource (org.xml.sax.InputSource)20