public String toString(PropertyIDMap idMap) { final StringBuilder b = new StringBuilder(); final Property[] pa = getProperties(); b.append("\n\n\n"); b.append(getClass().getName()); b.append('['); b.append("formatID: "); b.append(getFormatID()); b.append(", offset: "); b.append(getOffset()); b.append(", propertyCount: "); b.append(getPropertyCount()); b.append(", size: "); b.append(getSize()); b.append(", properties: [\n"); int codepage = getCodepage(); if (codepage == -1) { codepage = Property.DEFAULT_CODEPAGE; } for (Property p : pa) { b.append(p.toString(codepage, idMap)); b.append(",\n"); } b.append(']'); b.append(']'); return b.toString(); }
/** * Constructs a {@code PropertySet} instance. Its * primary task is to initialize the field with their proper values. * It also sets fields that might change to reasonable defaults. */ public PropertySet() { /* Initialize the "byteOrder" field. */ byteOrder = BYTE_ORDER_ASSERTION; /* Initialize the "format" field. */ format = FORMAT_ASSERTION; /* Initialize "osVersion" field as if the property has been created on * a Win32 platform, whether this is the case or not. */ osVersion = (OS_WIN32 << 16) | 0x0A04; /* Initialize the "classID" field. */ classID = new ClassID(); /* Initialize the sections. Since property set must have at least * one section it is added right here. */ addSection(new Section()); }
/** * Returns the value of the boolean property with the specified * ID. If the property is not available, {@code false} is * returned. A subsequent call to {@link #wasNull} will return * {@code true} to let the caller distinguish that case from * a real property value of {@code false}. * * @param id The property's ID * * @return The property's value */ boolean getPropertyBooleanValue(final int id) { final Boolean b = (Boolean) getProperty(id); return b != null && b; }
/** * Removes all properties from the section including 0 (dictionary) and 1 (codepage). */ public void clear() { for (Property p : getProperties()) { removeProperty(p.getID()); } }
/** * Constructs a {@code Section} by doing a deep copy of an * existing {@code Section}. All nested {@code Property} * instances, will be their mutable counterparts in the new * {@code MutableSection}. * * @param s The section set to copy */ public Section(final Section s) { this._offset = -1; setFormatID(s.getFormatID()); for (Property p : s.properties.values()) { properties.put(p.getID(), new Property(p)); } setDictionary(s.getDictionary()); }
/** * Creates section 2 if it is not already present. */ private void ensureSection2() { if (getSectionCount() < 2) { Section s2 = new Section(); s2.setFormatID(USER_DEFINED_PROPERTIES); addSection(s2); } }
System.out.println("ss# fid: "+s.getFormatID()); System.out.println("ss# codepage: "+s.getCodepage()); System.out.println("ss# # properties: "+s.getPropertyCount()); for( Property sp : s.getProperties() ) { System.out.println("ss# property: "+sp.getValue().getClass().getCanonicalName()+" "+sp.getValue());
/** * @see Object#hashCode() */ @Override public int hashCode() { long hashCode = 0; hashCode += getFormatID().hashCode(); final Property[] pa = getProperties(); for (Property aPa : pa) { hashCode += aPa.hashCode(); } return (int) (hashCode & 0x0ffffffffL); }
/** * <p>Constructs a <code>MutableSection</code> by doing a deep copy of an * existing <code>Section</code>. All nested <code>Property</code> * instances, will be their mutable counterparts in the new * <code>MutableSection</code>.</p> * * @param s The section set to copy */ public MutableSection(final Section s) { setFormatID(s.getFormatID()); final Property[] pa = s.getProperties(); final MutableProperty[] mpa = new MutableProperty[pa.length]; for (int i = 0; i < pa.length; i++) mpa[i] = new MutableProperty(pa[i]); setProperties(mpa); setDictionary(s.getDictionary()); }
/** * 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; }
String s = hex(sec.getFormatID().getBytes()); s = s.substring(0, s.length() - 1); out(" Format ID: " + s); int propertyCount = sec.getPropertyCount(); out(" No. of properties: " + propertyCount); Property[] properties = sec.getProperties(); for (Property p : properties) {
if (!s.getFormatID().equals(getFormatID())) { return false; Map<Long,String> d1 = getDictionary(); Map<Long,String> d2 = s.getDictionary();
/** * Checks whether this {@link PropertySet} is a Document Summary Information. * * @return {@code true} if this {@link PropertySet} * represents a Document Summary Information, else {@code false}. */ public boolean isDocumentSummaryInformation() { return !sections.isEmpty() && matchesSummary(getFirstSection().getFormatID(), DocumentSummaryInformation.FORMAT_ID); }
/** * Convenience method returning the {@link Property} array contained in this * property set. It is a shortcut for getting he {@link PropertySet}'s * {@link Section}s list and then getting the {@link Property} array from the * first {@link Section}. * * @return The properties of the only {@link Section} of this * {@link PropertySet}. * @throws NoSingleSectionException if the {@link PropertySet} has * more or less than one {@link Section}. */ public Property[] getProperties() throws NoSingleSectionException { return getFirstSection().getProperties(); }
for (int i=1; i<4; ++i) { Section aSection = new Section(); aSection.setName("Document " + i); aSection.setSection("Section " +i ); aSection.setText("Text " +i); }
/** * Sets the section's format ID. * * @param formatID The section's format ID as a byte array. It components * are in big-endian format. */ @SuppressWarnings("WeakerAccess") public void setFormatID(final byte[] formatID) { ClassID fid = getFormatID(); if (fid == null) { fid = new ClassID(); setFormatID(fid); } fid.setBytes(formatID); }
final ClassID formatID = section.getFormatID(); if (formatID == null) { throw new NoFormatIDException(); for (final Section section : getSections()) { offsets[secCnt++][1] = bos.size(); section.write(bos);
/** * Convenience method returning the value of a boolean property with the * specified ID. If the property is not available, {@code false} is returned. * A subsequent call to {@link #wasNull} will return {@code true} to let the * caller distinguish that case from a real property value of {@code false}. * * @param id The property ID * @return The property value * @throws NoSingleSectionException if the {@link PropertySet} has * more or less than one {@link Section}. */ boolean getPropertyBooleanValue(final int id) throws NoSingleSectionException { return getFirstSection().getPropertyBooleanValue(id); }
/** * Convenience method returning the value of the numeric * property with the specified ID. If the property is not * available, 0 is returned. A subsequent call to {@link #wasNull} * will return {@code true} to let the caller distinguish * that case from a real property value of 0. * * @param id The property ID * @return The propertyIntValue value * @throws NoSingleSectionException if the {@link PropertySet} has * more or less than one {@link Section}. */ int getPropertyIntValue(final int id) throws NoSingleSectionException { return getFirstSection().getPropertyIntValue(id); }
/** * Writes the section's dictionary. * * @param out The output stream to write to. * @param codepage The codepage to be used to write the dictionary items. * @exception IOException if an I/O exception occurs. */ private void writeDictionary(final OutputStream out, final int codepage) throws IOException { final byte padding[] = new byte[4]; final Map<Long,String> dic = getDictionary(); LittleEndian.putUInt(dic.size(), out); int length = LittleEndianConsts.INT_SIZE; for (Map.Entry<Long,String> ls : dic.entrySet()) { LittleEndian.putUInt(ls.getKey(), out); length += LittleEndianConsts.INT_SIZE; final String value = ls.getValue()+"\0"; final byte bytes[] = CodePageUtil.getBytesInCodePage(value, codepage); final int len = (codepage == CodePageUtil.CP_UNICODE) ? value.length() : bytes.length; LittleEndian.putUInt( len, out ); length += LittleEndianConsts.INT_SIZE; out.write(bytes); length += bytes.length; final int pad = (codepage == CodePageUtil.CP_UNICODE) ? ((4 - (length & 0x3)) & 0x3) : 0; out.write(padding, 0, pad); length += pad; } final int pad = (4 - (length & 0x3)) & 0x3; out.write(padding, 0, pad); }