Search in sources :

Example 1 with Table

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

use of com.healthmarketscience.jackcess.Table in project eol-globi-data by jhpoelen.

the class StudyImporterForADWTest method assertColumnNames.

private void assertColumnNames(List<String> expectedColumnNames, Table table) throws IOException {
    Table links = table;
    List<String> actualColumnNames = new ArrayList<String>();
    List<? extends Column> columns = links.getColumns();
    for (Column column : columns) {
        actualColumnNames.add(column.getName());
    }
    assertThat(actualColumnNames, is(expectedColumnNames));
}
Also used : Table(com.healthmarketscience.jackcess.Table) Column(com.healthmarketscience.jackcess.Column) ArrayList(java.util.ArrayList)

Example 3 with Table

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

Example 4 with Table

use of com.healthmarketscience.jackcess.Table in project pentaho-kettle by pentaho.

the class AccessOutputMeta method getRequiredFields.

public RowMetaInterface getRequiredFields(VariableSpace space) throws KettleException {
    String realFilename = space.environmentSubstitute(filename);
    File file = new File(realFilename);
    Database db = null;
    try {
        if (!file.exists() || !file.isFile()) {
            throw new KettleException(BaseMessages.getString(PKG, "AccessOutputMeta.Exception.FileDoesNotExist", realFilename));
        }
        // open the database and get the table
        db = Database.open(file);
        String realTablename = space.environmentSubstitute(tablename);
        Table table = db.getTable(realTablename);
        if (table == null) {
            throw new KettleException(BaseMessages.getString(PKG, "AccessOutputMeta.Exception.TableDoesNotExist", realTablename));
        }
        RowMetaInterface layout = getLayout(table);
        return layout;
    } catch (Exception e) {
        throw new KettleException(BaseMessages.getString(PKG, "AccessOutputMeta.Exception.ErrorGettingFields"), e);
    } finally {
        try {
            if (db != null) {
                db.close();
            }
        } catch (IOException e) {
            throw new KettleException(BaseMessages.getString(PKG, "AccessOutputMeta.Exception.ErrorClosingDatabase"), e);
        }
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) Table(com.healthmarketscience.jackcess.Table) Database(com.healthmarketscience.jackcess.Database) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) IOException(java.io.IOException) File(java.io.File) KettleException(org.pentaho.di.core.exception.KettleException) SQLException(java.sql.SQLException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) IOException(java.io.IOException) KettlePluginException(org.pentaho.di.core.exception.KettlePluginException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) KettleStepException(org.pentaho.di.core.exception.KettleStepException)

Example 5 with Table

use of com.healthmarketscience.jackcess.Table in project pentaho-kettle by pentaho.

the class AccessInputDialog method get.

private void get() {
    RowMetaInterface fields = new RowMeta();
    try {
        AccessInputMeta meta = new AccessInputMeta();
        getInfo(meta);
        // Check if a table name is specified
        if (!checkInputTableName(meta)) {
            return;
        }
        FileInputList inputList = meta.getFiles(transMeta);
        if (inputList.getFiles().size() > 0) {
            // Open the file (only first file)...
            Database d = Database.open(new File(AccessInputMeta.getFilename(inputList.getFile(0))), true);
            String realTableName = transMeta.environmentSubstitute(meta.getTableName());
            Table t = null;
            if (realTableName.startsWith(AccessInputMeta.PREFIX_SYSTEM)) {
                t = d.getSystemTable(realTableName);
            } else {
                t = d.getTable(realTableName);
            }
            // Get the list of columns
            List<Column> col = t.getColumns();
            int nr = col.size();
            for (int i = 0; i < nr; i++) {
                Column c = col.get(i);
                ValueMetaInterface field = AccessInputMeta.getValueMeta(c);
                if (field != null && fields.indexOfValue(field.getName()) < 0) {
                    fields.addValueMeta(field);
                }
            }
        }
    } catch (Exception e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "System.Dialog.Error.Title"), BaseMessages.getString(PKG, "AccessInputDialog.ErrorReadingFile.DialogMessage", e.toString()), e);
    }
    if (fields.size() > 0) {
        // Clear Fields Grid
        wFields.removeAll();
        for (int j = 0; j < fields.size(); j++) {
            ValueMetaInterface field = fields.getValueMeta(j);
            wFields.add(new String[] { field.getName(), field.getName(), field.getTypeDesc(), "", "-1", "", "", "", "", "none", "N" });
        }
        wFields.removeEmptyRows();
        wFields.setRowNums();
        wFields.optWidth(true);
    } else {
        MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_WARNING);
        mb.setMessage(BaseMessages.getString(PKG, "AccessInputDialog.UnableToFindFields.DialogTitle"));
        mb.setText(BaseMessages.getString(PKG, "AccessInputDialog.UnableToFindFields.DialogMessage"));
        mb.open();
    }
}
Also used : Table(com.healthmarketscience.jackcess.Table) RowMeta(org.pentaho.di.core.row.RowMeta) AccessInputMeta(org.pentaho.di.trans.steps.accessinput.AccessInputMeta) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) KettleException(org.pentaho.di.core.exception.KettleException) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) MessageBox(org.eclipse.swt.widgets.MessageBox) Column(com.healthmarketscience.jackcess.Column) Database(com.healthmarketscience.jackcess.Database) File(java.io.File) FileInputList(org.pentaho.di.core.fileinput.FileInputList)

Aggregations

Table (com.healthmarketscience.jackcess.Table)7 Database (com.healthmarketscience.jackcess.Database)5 File (java.io.File)4 Column (com.healthmarketscience.jackcess.Column)3 Row (com.healthmarketscience.jackcess.Row)2 HashSet (java.util.HashSet)2 KettleException (org.pentaho.di.core.exception.KettleException)2 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)2 DatabaseBuilder (com.healthmarketscience.jackcess.DatabaseBuilder)1 PropertyMap (com.healthmarketscience.jackcess.PropertyMap)1 Query (com.healthmarketscience.jackcess.query.Query)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 URI (java.net.URI)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HttpResponse (org.apache.http.HttpResponse)1 HttpGet (org.apache.http.client.methods.HttpGet)1 MessageBox (org.eclipse.swt.widgets.MessageBox)1