List of usage examples for org.apache.poi.hpsf CustomProperties get
@Override public Object get(final Object key)
From source file:edu.ku.brc.specify.tasks.subpane.wb.ConfigureXLS.java
License:Open Source License
/** * @param props/*from w w w .ja v a 2s . c om*/ * @param cols * @return */ protected boolean doReadMappings(CustomProperties props, List<ImportColumnInfo> cols) { boolean usesViewOrder = usesViewOrderKey(props); if (props != null && ((usesViewOrder && props.size() == cols.size()) || !usesViewOrder)) { if (usesViewOrder) { for (ImportColumnInfo col : cols) { String key = getKeyForCol(col, usesViewOrder); if (key != null) { String[] mapping = ((String) props.get(key)).split("\t"); if (!mapping[0].equals(col.getColTitle())) { return false; } } } } return true; } else { return false; } }
From source file:edu.ku.brc.specify.tasks.subpane.wb.ConfigureXLS.java
License:Open Source License
/** * @param poifs//from w w w . j ava 2 s . c om * * Reads workbench mappings from the XLS file. */ protected void readMappings(final POIFSFileSystem poifs) { DocumentSummaryInformation dsi = getDocSummary(poifs); if (dsi != null) { CustomProperties props = dsi.getCustomProperties(); List<ImportColumnInfo> sortedCols = new ArrayList<ImportColumnInfo>(colInfo); Collections.sort(sortedCols); if (doReadMappings(props, sortedCols)) { //Just in case colInfo is not sorted by column index... boolean usesViewOrder = usesViewOrderKey(props); int mapIdxOffset = usesViewOrder ? 1 : 0; Set<String> dupedCols = usesViewOrder ? new HashSet<String>() : getDuplicatedColTitles(sortedCols); for (ImportColumnInfo col : sortedCols) { if (!dupedCols.contains(col.getColTitle())) { String key = getKeyForCol(col, usesViewOrder); if (key != null && props.get(key) != null) { String[] mapping = ((String) props.get(key)).split("\t"); col.setMapToTbl(mapping[mapIdxOffset + 0]); col.setMapToFld(mapping[mapIdxOffset + 1]); if (mapping.length == 7 + mapIdxOffset) { col.setFormXCoord(Integer.valueOf(mapping[mapIdxOffset + 2])); col.setFormYCoord(Integer.valueOf(mapping[mapIdxOffset + 3])); if (StringUtils.isNotBlank(mapping[mapIdxOffset + 4])) { col.setCaption(mapping[mapIdxOffset + 4]); } col.setFrmFieldType(Integer.valueOf(mapping[mapIdxOffset + 5])); col.setFrmMetaData(mapping[mapIdxOffset + 6]); } } } } } } }
From source file:mj.ocraptor.extraction.tika.parser.microsoft.SummaryExtractor.java
License:Apache License
private String getLanguage(DocumentSummaryInformation summary) { CustomProperties customProperties = summary.getCustomProperties(); if (customProperties != null) { Object value = customProperties.get("Language"); if (value instanceof String) { return (String) value; }/*from w ww . jav a 2 s. c o m*/ } return null; }
From source file:mj.ocraptor.extraction.tika.parser.microsoft.SummaryExtractor.java
License:Apache License
/** * Attempt to parse custom document properties and add to the collection of metadata * @param customProperties/* www . j a va2 s. c om*/ */ private void parse(CustomProperties customProperties) { if (customProperties != null) { for (String name : customProperties.nameSet()) { // Apply the custom prefix String key = Metadata.USER_DEFINED_METADATA_NAME_PREFIX + name; // Get, convert and save property value Object value = customProperties.get(name); if (value instanceof String) { set(key, (String) value); } else if (value instanceof Date) { Property prop = Property.externalDate(key); metadata.set(prop, (Date) value); } else if (value instanceof Boolean) { Property prop = Property.externalBoolean(key); metadata.set(prop, ((Boolean) value).toString()); } else if (value instanceof Long) { Property prop = Property.externalInteger(key); metadata.set(prop, ((Long) value).intValue()); } else if (value instanceof Double) { Property prop = Property.externalReal(key); metadata.set(prop, ((Double) value).doubleValue()); } else if (value instanceof Integer) { Property prop = Property.externalInteger(key); metadata.set(prop, ((Integer) value).intValue()); } } } }
From source file:org.apache.tika.parser.microsoft.SummaryExtractor.java
License:Apache License
/** * Attempt to parse custom document properties and add to the collection of metadata * * @param customProperties// w ww . ja v a 2 s .co m */ private void parse(CustomProperties customProperties) { if (customProperties != null) { for (String name : customProperties.nameSet()) { // Apply the custom prefix String key = Metadata.USER_DEFINED_METADATA_NAME_PREFIX + name; // Get, convert and save property value Object value = customProperties.get(name); if (value instanceof String) { set(key, (String) value); } else if (value instanceof Date) { Property prop = Property.externalDate(key); metadata.set(prop, (Date) value); } else if (value instanceof Boolean) { Property prop = Property.externalBoolean(key); metadata.set(prop, value.toString()); } else if (value instanceof Long) { Property prop = Property.externalInteger(key); metadata.set(prop, ((Long) value).intValue()); } else if (value instanceof Double) { Property prop = Property.externalReal(key); metadata.set(prop, (Double) value); } else if (value instanceof Integer) { Property prop = Property.externalInteger(key); metadata.set(prop, ((Integer) value).intValue()); } } } }
From source file:poi.hpsf.examples.ModifyDocumentSummaryInformation.java
License:Apache License
/** * <p>Main method - see class description.</p> * * @param args The command-line parameters. * @throws java.io.IOException/*from w w w . j av a2s .c o m*/ * @throws MarkUnsupportedException * @throws NoPropertySetStreamException * @throws UnexpectedPropertySetTypeException * @throws WritingNotSupportedException */ public static void main(final String[] args) throws IOException, NoPropertySetStreamException, MarkUnsupportedException, UnexpectedPropertySetTypeException, WritingNotSupportedException { /* Read the name of the POI filesystem to modify from the command line. * For brevity to boundary check is performed on the command-line * arguments. */ File poiFilesystem = new File(args[0]); /* Open the POI filesystem. */ InputStream is = new FileInputStream(poiFilesystem); POIFSFileSystem poifs = new POIFSFileSystem(is); is.close(); /* Read the summary information. */ DirectoryEntry dir = poifs.getRoot(); SummaryInformation si; try { DocumentEntry siEntry = (DocumentEntry) dir.getEntry(SummaryInformation.DEFAULT_STREAM_NAME); DocumentInputStream dis = new DocumentInputStream(siEntry); PropertySet ps = new PropertySet(dis); dis.close(); si = new SummaryInformation(ps); } catch (FileNotFoundException ex) { /* There is no summary information yet. We have to create a new * one. */ si = PropertySetFactory.newSummaryInformation(); } /* Change the author to "Rainer Klute". Any former author value will * be lost. If there has been no author yet, it will be created. */ si.setAuthor("Rainer Klute"); System.out.println("Author changed to " + si.getAuthor() + "."); /* Handling the document summary information is analogous to handling * the summary information. An additional feature, however, are the * custom properties. */ /* Read the document summary information. */ DocumentSummaryInformation dsi; try { DocumentEntry dsiEntry = (DocumentEntry) dir.getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME); DocumentInputStream dis = new DocumentInputStream(dsiEntry); PropertySet ps = new PropertySet(dis); dis.close(); dsi = new DocumentSummaryInformation(ps); } catch (FileNotFoundException ex) { /* There is no document summary information yet. We have to create a * new one. */ dsi = PropertySetFactory.newDocumentSummaryInformation(); } /* Change the category to "POI example". Any former category value will * be lost. If there has been no category yet, it will be created. */ dsi.setCategory("POI example"); System.out.println("Category changed to " + dsi.getCategory() + "."); /* Read the custom properties. If there are no custom properties yet, * the application has to create a new CustomProperties object. It will * serve as a container for custom properties. */ CustomProperties customProperties = dsi.getCustomProperties(); if (customProperties == null) customProperties = new CustomProperties(); /* Insert some custom properties into the container. */ customProperties.put("Key 1", "Value 1"); customProperties.put("Schl\u00fcssel 2", "Wert 2"); customProperties.put("Sample Number", new Integer(12345)); customProperties.put("Sample Boolean", Boolean.TRUE); customProperties.put("Sample Date", new Date()); /* Read a custom property. */ Object value = customProperties.get("Sample Number"); /* Write the custom properties back to the document summary * information. */ dsi.setCustomProperties(customProperties); /* Write the summary information and the document summary information * to the POI filesystem. */ si.write(dir, SummaryInformation.DEFAULT_STREAM_NAME); dsi.write(dir, DocumentSummaryInformation.DEFAULT_STREAM_NAME); /* Write the POI filesystem back to the original file. Please note that * in production code you should never write directly to the origin * file! In case of a writing error everything would be lost. */ OutputStream out = new FileOutputStream(poiFilesystem); poifs.writeFilesystem(out); out.close(); }