public String getDocumentSummaryInformationText() { if(document == null) { // event based extractor does not have a document return ""; } DocumentSummaryInformation dsi = document.getDocumentSummaryInformation(); StringBuilder text = new StringBuilder(); // Normal properties text.append( getPropertiesText(dsi) ); // Now custom ones CustomProperties cps = dsi == null ? null : dsi.getCustomProperties(); if (cps != null) { for (String key : cps.nameSet()) { String val = getPropertyValueText(cps.get(key)); text.append(key).append(" = ").append(val).append("\n"); } } // All done return text.toString(); } public String getSummaryInformationText() {
/** * Gets the custom properties. * * @return The custom properties. */ public CustomProperties getCustomProperties() { CustomProperties cps = null; if (getSectionCount() >= 2) { cps = new CustomProperties(); final Section section = getSections().get(1); final Map<Long,String> dictionary = section.getDictionary(); final Property[] properties = section.getProperties(); int propertyCount = 0; for (Property p : properties) { final long id = p.getID(); if (id == PropertyIDMap.PID_CODEPAGE) { cps.setCodepage((Integer)p.getValue()); } else if (id > PropertyIDMap.PID_CODEPAGE) { propertyCount++; final CustomProperty cp = new CustomProperty(p, dictionary.get(id)); cps.put(cp.getName(), cp); } } if (cps.size() != propertyCount) { cps.setPure(false); } } return cps; }
/** * Sets the custom properties. * * @param customProperties The custom properties */ public void setCustomProperties(final CustomProperties customProperties) { ensureSection2(); final Section section = getSections().get(1); final Map<Long,String> dictionary = customProperties.getDictionary(); // section.clear(); /* Set the codepage. If both custom properties and section have a * codepage, the codepage from the custom properties wins, else take the * one that is defined. If none is defined, take ISO-8859-1. */ int cpCodepage = customProperties.getCodepage(); if (cpCodepage < 0) { cpCodepage = section.getCodepage(); } if (cpCodepage < 0) { cpCodepage = Property.DEFAULT_CODEPAGE; } customProperties.setCodepage(cpCodepage); section.setCodepage(cpCodepage); section.setDictionary(dictionary); for (CustomProperty p : customProperties.properties()) { section.setProperty(p); } }
private void checkCodePage(String value) { int cp = getCodepage(); if (cp == -1) { cp = Property.DEFAULT_CODEPAGE; } if (cp == CodePageUtil.CP_UNICODE) { return; } String cps = ""; try { cps = CodePageUtil.codepageToEncoding(cp, false); } catch (UnsupportedEncodingException e) { LOG.log(POILogger.ERROR, "Codepage '"+cp+"' can't be found."); } if (!cps.isEmpty() && Charset.forName(cps).newEncoder().canEncode(value)) { return; } LOG.log(POILogger.DEBUG, "Charset '"+cps+"' can't encode '"+value+"' - switching to unicode."); setCodepage(CodePageUtil.CP_UNICODE); } }
customProperties = new CustomProperties(); customProperties.put("Key 1", "Value 1"); customProperties.put("Schl\u00fcssel 2", "Wert 2"); customProperties.put("Sample Number", 12345); customProperties.put("Sample Boolean", Boolean.TRUE); customProperties.put("Sample Date", new Date()); Object value = customProperties.get("Sample Number"); System.out.println("Custom Sample Number is now " + value);
@Override public void putAll(Map<? extends String, ?> m) { for (Map.Entry<? extends String, ?> me : m.entrySet()) { put(me.getKey(), me.getValue()); } }
/** * <p>Sets the custom properties.</p> * * @param customProperties The custom properties */ public void setCustomProperties(final CustomProperties customProperties) { ensureSection2(); final MutableSection section = (MutableSection) getSections().get(1); final Map<Long,String> dictionary = customProperties.getDictionary(); section.clear(); /* Set the codepage. If both custom properties and section have a * codepage, the codepage from the custom properties wins, else take the * one that is defined. If none is defined, take Unicode. */ int cpCodepage = customProperties.getCodepage(); if (cpCodepage < 0) cpCodepage = section.getCodepage(); if (cpCodepage < 0) cpCodepage = Constants.CP_UNICODE; customProperties.setCodepage(cpCodepage); section.setCodepage(cpCodepage); section.setDictionary(dictionary); for (final Iterator<CustomProperty> i = customProperties.values().iterator(); i.hasNext();) { final Property p = i.next(); section.setProperty(p); } }
private String getLanguage(DocumentSummaryInformation summary) { CustomProperties customProperties = summary.getCustomProperties(); if (customProperties != null) { Object value = customProperties.get("Language"); if (value instanceof String) { return (String) value; } } return null; }
if (customProperties != null) for (CustomProperty property : customProperties.properties())
return put(new CustomProperty(p, key));
/** * <p>Sets the custom properties.</p> * * @param customProperties The custom properties */ public void setCustomProperties(final CustomProperties customProperties) { ensureSection2(); final MutableSection section = (MutableSection) getSections().get(1); final Map<Long,String> dictionary = customProperties.getDictionary(); section.clear(); /* Set the codepage. If both custom properties and section have a * codepage, the codepage from the custom properties wins, else take the * one that is defined. If none is defined, take Unicode. */ int cpCodepage = customProperties.getCodepage(); if (cpCodepage < 0) cpCodepage = section.getCodepage(); if (cpCodepage < 0) cpCodepage = Constants.CP_UNICODE; customProperties.setCodepage(cpCodepage); section.setCodepage(cpCodepage); section.setDictionary(dictionary); for (final Iterator<CustomProperty> i = customProperties.values().iterator(); i.hasNext();) { final Property p = i.next(); section.setProperty(p); } }
private String getLanguage(DocumentSummaryInformation summary) { CustomProperties customProperties = summary.getCustomProperties(); if (customProperties != null) { Object value = customProperties.get("Language"); if (value instanceof String) { return (String) value; } } return null; }
private void checkCodePage(String value) { int cp = getCodepage(); if (cp == -1) { cp = Property.DEFAULT_CODEPAGE; } if (cp == CodePageUtil.CP_UNICODE) { return; } String cps = ""; try { cps = CodePageUtil.codepageToEncoding(cp, false); } catch (UnsupportedEncodingException e) { LOG.log(POILogger.ERROR, "Codepage '"+cp+"' can't be found."); } if (!cps.isEmpty() && Charset.forName(cps).newEncoder().canEncode(value)) { return; } LOG.log(POILogger.DEBUG, "Charset '"+cps+"' can't encode '"+value+"' - switching to unicode."); setCodepage(CodePageUtil.CP_UNICODE); } }
if (customProperties != null) for (CustomProperty property : customProperties.properties())
/** * Gets the custom properties. * * @return The custom properties. */ public CustomProperties getCustomProperties() { CustomProperties cps = null; if (getSectionCount() >= 2) { cps = new CustomProperties(); final Section section = getSections().get(1); final Map<Long,String> dictionary = section.getDictionary(); final Property[] properties = section.getProperties(); int propertyCount = 0; for (Property p : properties) { final long id = p.getID(); if (id == PropertyIDMap.PID_CODEPAGE) { cps.setCodepage((Integer)p.getValue()); } else if (id > PropertyIDMap.PID_CODEPAGE) { propertyCount++; final CustomProperty cp = new CustomProperty(p, dictionary.get(id)); cps.put(cp.getName(), cp); } } if (cps.size() != propertyCount) { cps.setPure(false); } } return cps; }
/** * Puts a {@link CustomProperty} that has not yet a valid ID into this * map. The method will allocate a suitable ID for the custom property: * * <ul> * <li>If there is already a property with the same name, take the ID * of that property. * * <li>Otherwise find the highest ID and use its value plus one. * </ul> * * @param customProperty The {@link CustomProperty} to add. * @return If there was already a property with the same name, the old property * @throws ClassCastException */ private Object put(final CustomProperty customProperty) throws ClassCastException { final String name = customProperty.getName(); /* Check whether a property with this name is in the map already. */ final Long oldId = (name == null) ? null : dictionary.getKey(name); if (oldId != null) { customProperty.setID(oldId); } else { long lastKey = (dictionary.isEmpty()) ? 0 : dictionary.lastKey(); long nextKey = Math.max(lastKey,PropertyIDMap.PID_MAX)+1; customProperty.setID(nextKey); } return this.put(name, customProperty); }
/** * Sets the custom properties. * * @param customProperties The custom properties */ public void setCustomProperties(final CustomProperties customProperties) { ensureSection2(); final Section section = getSections().get(1); final Map<Long,String> dictionary = customProperties.getDictionary(); // section.clear(); /* Set the codepage. If both custom properties and section have a * codepage, the codepage from the custom properties wins, else take the * one that is defined. If none is defined, take ISO-8859-1. */ int cpCodepage = customProperties.getCodepage(); if (cpCodepage < 0) { cpCodepage = section.getCodepage(); } if (cpCodepage < 0) { cpCodepage = Property.DEFAULT_CODEPAGE; } customProperties.setCodepage(cpCodepage); section.setCodepage(cpCodepage); section.setDictionary(dictionary); for (CustomProperty p : customProperties.properties()) { section.setProperty(p); } }
private String getLanguage(DocumentSummaryInformation summary) { CustomProperties customProperties = summary.getCustomProperties(); if (customProperties != null) { Object value = customProperties.get("Language"); if (value instanceof String) { return (String) value; } } return null; }
if (getSectionCount() >= 2) cps = new CustomProperties(); final Section section = (Section) getSections().get(1); final Map<Long,String> dictionary = section.getDictionary(); final CustomProperty cp = new CustomProperty(p, dictionary.get(Long.valueOf(id))); cps.put(cp.getName(), cp); if (cps.size() != propertyCount) cps.setPure(false);