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