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();
}
}
}
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;
}
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;
}
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);
}
}
Aggregations