Search in sources :

Example 36 with ContentHandler

use of org.xml.sax.ContentHandler in project jackrabbit-oak by apache.

the class SessionImpl method exportSystemView.

@Override
public void exportSystemView(String absPath, OutputStream out, boolean skipBinary, boolean noRecurse) throws IOException, RepositoryException {
    try {
        ContentHandler handler = new ToXmlContentHandler(checkNotNull(out));
        export(checkNotNull(absPath), new SystemViewExporter(this, handler, !noRecurse, !skipBinary));
    } catch (SAXException e) {
        Exception exception = e.getException();
        if (exception instanceof RepositoryException) {
            throw (RepositoryException) exception;
        } else if (exception instanceof IOException) {
            throw (IOException) exception;
        } else {
            throw new RepositoryException("Error serializing system view XML", e);
        }
    }
}
Also used : SystemViewExporter(org.apache.jackrabbit.commons.xml.SystemViewExporter) ToXmlContentHandler(org.apache.jackrabbit.commons.xml.ToXmlContentHandler) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) ContentHandler(org.xml.sax.ContentHandler) ParsingContentHandler(org.apache.jackrabbit.commons.xml.ParsingContentHandler) ToXmlContentHandler(org.apache.jackrabbit.commons.xml.ToXmlContentHandler) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) InvalidSerializedDataException(javax.jcr.InvalidSerializedDataException) ItemNotFoundException(javax.jcr.ItemNotFoundException) SAXException(org.xml.sax.SAXException) AccessControlException(java.security.AccessControlException) AccessDeniedException(javax.jcr.AccessDeniedException) PathNotFoundException(javax.jcr.PathNotFoundException) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) SAXException(org.xml.sax.SAXException)

Example 37 with ContentHandler

use of org.xml.sax.ContentHandler in project jackrabbit-oak by apache.

the class SessionImpl method exportDocumentView.

@Override
public void exportDocumentView(String absPath, OutputStream out, boolean skipBinary, boolean noRecurse) throws IOException, RepositoryException {
    try {
        ContentHandler handler = new ToXmlContentHandler(checkNotNull(out));
        export(checkNotNull(absPath), new DocumentViewExporter(this, handler, !noRecurse, !skipBinary));
    } catch (SAXException e) {
        Exception exception = e.getException();
        if (exception instanceof RepositoryException) {
            throw (RepositoryException) exception;
        } else if (exception instanceof IOException) {
            throw (IOException) exception;
        } else {
            throw new RepositoryException("Error serializing document view XML", e);
        }
    }
}
Also used : DocumentViewExporter(org.apache.jackrabbit.commons.xml.DocumentViewExporter) ToXmlContentHandler(org.apache.jackrabbit.commons.xml.ToXmlContentHandler) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) ContentHandler(org.xml.sax.ContentHandler) ParsingContentHandler(org.apache.jackrabbit.commons.xml.ParsingContentHandler) ToXmlContentHandler(org.apache.jackrabbit.commons.xml.ToXmlContentHandler) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) InvalidSerializedDataException(javax.jcr.InvalidSerializedDataException) ItemNotFoundException(javax.jcr.ItemNotFoundException) SAXException(org.xml.sax.SAXException) AccessControlException(java.security.AccessControlException) AccessDeniedException(javax.jcr.AccessDeniedException) PathNotFoundException(javax.jcr.PathNotFoundException) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) SAXException(org.xml.sax.SAXException)

Example 38 with ContentHandler

use of org.xml.sax.ContentHandler in project robovm by robovm.

the class ExpatSaxParserTest method testExceptions.

public void testExceptions() {
    // From startElement().
    ContentHandler contentHandler = new DefaultHandler() {

        @Override
        public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
            throw new SAXException();
        }
    };
    try {
        parse(SNIPPET, contentHandler);
        fail();
    } catch (SAXException checked) {
    /* expected */
    }
    // From endElement().
    contentHandler = new DefaultHandler() {

        @Override
        public void endElement(String uri, String localName, String qName) throws SAXException {
            throw new SAXException();
        }
    };
    try {
        parse(SNIPPET, contentHandler);
        fail();
    } catch (SAXException checked) {
    /* expected */
    }
    // From characters().
    contentHandler = new DefaultHandler() {

        @Override
        public void characters(char[] ch, int start, int length) throws SAXException {
            throw new SAXException();
        }
    };
    try {
        parse(SNIPPET, contentHandler);
        fail();
    } catch (SAXException checked) {
    /* expected */
    }
}
Also used : Attributes(org.xml.sax.Attributes) ContentHandler(org.xml.sax.ContentHandler) DefaultHandler(org.xml.sax.helpers.DefaultHandler) SAXException(org.xml.sax.SAXException)

Example 39 with ContentHandler

use of org.xml.sax.ContentHandler in project nokogiri by sparklemotion.

the class DOM2DTMExt method dispatchToEvents.

/**
     * Directly create SAX parser events from a subtree.
     *
     * @param nodeHandle The node ID.
     * @param ch A non-null reference to a ContentHandler.
     *
     * @throws org.xml.sax.SAXException
     */
public void dispatchToEvents(int nodeHandle, org.xml.sax.ContentHandler ch) throws org.xml.sax.SAXException {
    TreeWalker treeWalker = m_walker;
    ContentHandler prevCH = treeWalker.getContentHandler();
    if (null != prevCH) {
        treeWalker = new TreeWalker(null);
    }
    treeWalker.setContentHandler(ch);
    try {
        Node node = getNode(nodeHandle);
        treeWalker.traverseFragment(node);
    } finally {
        treeWalker.setContentHandler(null);
    }
}
Also used : Node(org.w3c.dom.Node) TreeWalker(org.apache.xml.utils.TreeWalker) ContentHandler(org.xml.sax.ContentHandler)

Example 40 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)

Aggregations

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