Search in sources :

Example 1 with PropertyMap

use of com.healthmarketscience.jackcess.PropertyMap 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 PropertyMap

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

the class JackcessExtractor method isRichText.

private boolean isRichText(Column c) throws IOException {
    if (c == null) {
        return false;
    }
    PropertyMap m = c.getProperties();
    if (m == null) {
        return false;
    }
    if (c.getType() == null || !c.getType().equals(DataType.MEMO)) {
        return false;
    }
    Object b = m.getValue(TEXT_FORMAT_KEY);
    if (b instanceof Byte) {
        if (((Byte) b).byteValue() == RICH_TEXT_FORMAT) {
            return true;
        }
    }
    return false;
}
Also used : PropertyMap(com.healthmarketscience.jackcess.PropertyMap)

Aggregations

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