Search in sources :

Example 11 with IOExceptionWithCause

use of org.apache.commons.io.IOExceptionWithCause in project tika by apache.

the class AbstractDBParser method parse.

@Override
public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException {
    connection = getConnection(stream, metadata, context);
    XHTMLContentHandler xHandler = null;
    List<String> tableNames = null;
    try {
        tableNames = getTableNames(connection, metadata, context);
    } catch (SQLException e) {
        try {
            close();
        } catch (SQLException sqlE) {
        //swallow
        }
        throw new IOExceptionWithCause(e);
    }
    for (String tableName : tableNames) {
        //add table names to parent metadata
        metadata.add(Database.TABLE_NAME, tableName);
    }
    xHandler = new XHTMLContentHandler(handler, metadata);
    xHandler.startDocument();
    try {
        for (String tableName : tableNames) {
            JDBCTableReader tableReader = getTableReader(connection, tableName, context);
            xHandler.startElement("table", "name", tableReader.getTableName());
            xHandler.startElement("thead");
            xHandler.startElement("tr");
            for (String header : tableReader.getHeaders()) {
                xHandler.startElement("th");
                xHandler.characters(header);
                xHandler.endElement("th");
            }
            xHandler.endElement("tr");
            xHandler.endElement("thead");
            xHandler.startElement("tbody");
            while (tableReader.nextRow(xHandler, context)) {
            //no-op
            }
            xHandler.endElement("tbody");
            xHandler.endElement("table");
        }
    } finally {
        try {
            close();
        } catch (IOException | SQLException e) {
        //swallow
        }
        if (xHandler != null) {
            xHandler.endDocument();
        }
    }
}
Also used : IOExceptionWithCause(org.apache.commons.io.IOExceptionWithCause) SQLException(java.sql.SQLException) IOException(java.io.IOException) XHTMLContentHandler(org.apache.tika.sax.XHTMLContentHandler)

Example 12 with IOExceptionWithCause

use of org.apache.commons.io.IOExceptionWithCause in project tika by apache.

the class JDBCTableReader method reset.

void reset() throws IOException {
    if (results != null) {
        try {
            results.close();
        } catch (SQLException e) {
        //swallow
        }
    }
    String sql = "SELECT * from " + tableName;
    try {
        Statement st = connection.createStatement();
        results = st.executeQuery(sql);
    } catch (SQLException e) {
        throw new IOExceptionWithCause(e);
    }
    rows = 0;
}
Also used : IOExceptionWithCause(org.apache.commons.io.IOExceptionWithCause) SQLException(java.sql.SQLException) Statement(java.sql.Statement)

Example 13 with IOExceptionWithCause

use of org.apache.commons.io.IOExceptionWithCause in project tika by apache.

the class JDBCTableReader method nextRow.

public boolean nextRow(ContentHandler handler, ParseContext context) throws IOException, SAXException {
    //lazy initialization
    if (results == null) {
        reset();
    }
    try {
        if (!results.next()) {
            return false;
        }
    } catch (SQLException e) {
        throw new IOExceptionWithCause(e);
    }
    try {
        ResultSetMetaData meta = results.getMetaData();
        handler.startElement(XHTMLContentHandler.XHTML, "tr", "tr", EMPTY_ATTRIBUTES);
        for (int i = 1; i <= meta.getColumnCount(); i++) {
            handler.startElement(XHTMLContentHandler.XHTML, "td", "td", EMPTY_ATTRIBUTES);
            handleCell(meta, i, handler, context);
            handler.endElement(XHTMLContentHandler.XHTML, "td", "td");
        }
        handler.endElement(XHTMLContentHandler.XHTML, "tr", "tr");
    } catch (SQLException e) {
        throw new IOExceptionWithCause(e);
    }
    rows++;
    return true;
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) IOExceptionWithCause(org.apache.commons.io.IOExceptionWithCause) SQLException(java.sql.SQLException)

Example 14 with IOExceptionWithCause

use of org.apache.commons.io.IOExceptionWithCause in project tika by apache.

the class OCR2XHTML method processPage.

@Override
public void processPage(PDPage pdPage) throws IOException {
    try {
        startPage(pdPage);
        doOCROnCurrentPage();
        endPage(pdPage);
    } catch (TikaException | SAXException e) {
        throw new IOExceptionWithCause(e);
    } catch (IOException e) {
        handleCatchableIOE(e);
    }
}
Also used : IOExceptionWithCause(org.apache.commons.io.IOExceptionWithCause) TikaException(org.apache.tika.exception.TikaException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Aggregations

IOExceptionWithCause (org.apache.commons.io.IOExceptionWithCause)14 IOException (java.io.IOException)10 SQLException (java.sql.SQLException)5 TikaException (org.apache.tika.exception.TikaException)5 SAXException (org.xml.sax.SAXException)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 DataInputStream (java.io.DataInputStream)3 InputStream (java.io.InputStream)3 Connection (java.sql.Connection)2 RepositoryException (javax.jcr.RepositoryException)2 InternalValue (org.apache.jackrabbit.core.value.InternalValue)2 BufferedImage (java.awt.image.BufferedImage)1 BufferedInputStream (java.io.BufferedInputStream)1 DataInput (java.io.DataInput)1 OutputStream (java.io.OutputStream)1 Path (java.nio.file.Path)1 ResultSetMetaData (java.sql.ResultSetMetaData)1 Statement (java.sql.Statement)1 PDComplexFileSpecification (org.apache.pdfbox.pdmodel.common.filespecification.PDComplexFileSpecification)1 PDActionURI (org.apache.pdfbox.pdmodel.interactive.action.PDActionURI)1