Search in sources :

Example 1 with Row

use of com.healthmarketscience.jackcess.Row in project tika by apache.

the class JackcessExtractor method parse.

public void parse(Database db, XHTMLContentHandler xhtml) throws IOException, SAXException, TikaException {
    String pw = db.getDatabasePassword();
    if (pw != null) {
        parentMetadata.set(JackcessParser.MDB_PW, pw);
    }
    PropertyMap dbp = db.getDatabaseProperties();
    for (PropertyMap.Property p : dbp) {
        parentMetadata.add(JackcessParser.MDB_PROPERTY_PREFIX + p.getName(), toString(p.getValue(), p.getType()));
    }
    PropertyMap up = db.getUserDefinedProperties();
    for (PropertyMap.Property p : up) {
        parentMetadata.add(JackcessParser.USER_DEFINED_PROPERTY_PREFIX + p.getName(), toString(p.getValue(), p.getType()));
    }
    Set<String> found = new HashSet<>();
    PropertyMap summaryProperties = db.getSummaryProperties();
    if (summaryProperties != null) {
        //try to get core properties
        PropertyMap.Property title = summaryProperties.get(TITLE_PROP_KEY);
        if (title != null) {
            parentMetadata.set(TikaCoreProperties.TITLE, toString(title.getValue(), title.getType()));
            found.add(title.getName());
        }
        PropertyMap.Property author = summaryProperties.get(AUTHOR_PROP_KEY);
        if (author != null && author.getValue() != null) {
            String authorString = toString(author.getValue(), author.getType());
            SummaryExtractor.addMulti(parentMetadata, TikaCoreProperties.CREATOR, authorString);
            found.add(author.getName());
        }
        PropertyMap.Property company = summaryProperties.get(COMPANY_PROP_KEY);
        if (company != null) {
            parentMetadata.set(OfficeOpenXMLExtended.COMPANY, toString(company.getValue(), company.getType()));
            found.add(company.getName());
        }
        for (PropertyMap.Property p : db.getSummaryProperties()) {
            if (!found.contains(p.getName())) {
                parentMetadata.add(JackcessParser.SUMMARY_PROPERTY_PREFIX + p.getName(), toString(p.getValue(), p.getType()));
            }
        }
    }
    Iterator<Table> it = db.newIterable().setIncludeLinkedTables(false).setIncludeSystemTables(false).iterator();
    while (it.hasNext()) {
        Table table = it.next();
        String tableName = table.getName();
        List<? extends Column> columns = table.getColumns();
        xhtml.startElement("table", "name", tableName);
        addHeaders(columns, xhtml);
        xhtml.startElement("tbody");
        Row r = table.getNextRow();
        while (r != null) {
            xhtml.startElement("tr");
            for (Column c : columns) {
                handleCell(r, c, xhtml);
            }
            xhtml.endElement("tr");
            r = table.getNextRow();
        }
        xhtml.endElement("tbody");
        xhtml.endElement("table");
    }
    for (Query q : db.getQueries()) {
        xhtml.startElement("div", "type", "sqlQuery");
        xhtml.characters(q.toSQLString());
        xhtml.endElement("div");
    }
}
Also used : PropertyMap(com.healthmarketscience.jackcess.PropertyMap) Table(com.healthmarketscience.jackcess.Table) Query(com.healthmarketscience.jackcess.query.Query) Column(com.healthmarketscience.jackcess.Column) Row(com.healthmarketscience.jackcess.Row) HashSet(java.util.HashSet)

Example 2 with Row

use of com.healthmarketscience.jackcess.Row in project timbuctoo by HuygensING.

the class MdbLoader method loadData.

@Override
public void loadData(List<Tuple<String, File>> files, Importer importer) throws InvalidFileException, IOException {
    Database database = DatabaseBuilder.open(files.get(0).getRight());
    for (String tableName : database.getTableNames()) {
        importer.startCollection(tableName);
        Table table = database.getTable(tableName);
        List<? extends Column> columns = table.getColumns();
        for (int i = 0; i < columns.size(); i++) {
            importer.registerPropertyName(i, columns.get(i).getName());
        }
        for (Row row : table) {
            importer.startEntity();
            for (int colNum = 0; colNum < columns.size(); colNum++) {
                Object cellValue = row.get(columns.get(colNum).getName());
                if (cellValue == null) {
                    cellValue = "";
                }
                importer.setValue(colNum, "" + cellValue);
            }
            importer.finishEntity();
        }
        importer.finishCollection();
    }
}
Also used : Table(com.healthmarketscience.jackcess.Table) Database(com.healthmarketscience.jackcess.Database) Row(com.healthmarketscience.jackcess.Row)

Aggregations

Row (com.healthmarketscience.jackcess.Row)2 Table (com.healthmarketscience.jackcess.Table)2 Column (com.healthmarketscience.jackcess.Column)1 Database (com.healthmarketscience.jackcess.Database)1 PropertyMap (com.healthmarketscience.jackcess.PropertyMap)1 Query (com.healthmarketscience.jackcess.query.Query)1 HashSet (java.util.HashSet)1