final Object pValue = p.getValue(); final long pId = p.getID(); if (id != pId || (id != 0 && !typesAreEqual(type, p.getType()))) { return false; int len = unpaddedLength(thisVal); if (len != unpaddedLength(otherVal)) { return false;
/** * 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()); }
/** * @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); }
/** * Sets a property. * * @param p The property to be set. * * @see #setProperty(int, long, Object) * @see #getProperty * @see Variant */ public void setProperty(final Property p) { Property old = properties.get(p.getID()); if (old == null || !old.equals(p)) { properties.put(p.getID(), p); sectionBytes.reset(); } }
private static String getPropertiesText(PropertySet ps) { if (ps == null) { // Not defined, oh well return ""; } StringBuilder text = new StringBuilder(); PropertyIDMap idMap = ps.getPropertySetIDMap(); Property[] props = ps.getProperties(); for (Property prop : props) { String type = Long.toString(prop.getID()); Object typeObj = (idMap == null) ? null : idMap.get(prop.getID()); if (typeObj != null) { type = typeObj.toString(); } String val = getPropertyValueText(prop.getValue()); text.append(type).append(" = ").append(val).append("\n"); } return text.toString(); }
b.append(getType()); b.append(" ("); b.append(getVariantName()); b.append(") "); final Object value = getValue(); b.append(", value: "); if (value instanceof String) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); try { write(bos, codepage); } catch (Exception e) { LOG.log(POILogger.WARN, "can't serialize string", e); b.append(value); String decoded = decodeValueFromID(); if (decoded != null) { b.append(" (");
private String decodeValueFromID() { try { switch((int)getID()) { case PropertyIDMap.PID_CODEPAGE: return CodePageUtil.codepageToEncoding(((Number)value).intValue()); case PropertyIDMap.PID_LOCALE: return LocaleUtil.getLocaleFromLCID(((Number)value).intValue()); } } catch (Exception e) { LOG.log(POILogger.WARN, "Can't decode id "+getID()); } return null; }
/** * Returns the value of the property with the specified ID. If * the property is not available, {@code null} is returned * and a subsequent call to {@link #wasNull} will return * {@code true}. * * @param id The property's ID * * @return The property's value */ public Object getProperty(final long id) { wasNull = !properties.containsKey(id); return (wasNull) ? null : properties.get(id).getValue(); }
/** * Sets the value and the variant type of the property with the * specified ID. If a property with this ID is not yet present in * the section, it will be added. An already present property with * the specified ID will be overwritten. A default mapping will be * used to choose the property's type. * * @param id The property's ID. * @param variantType The property's variant type. * @param value The property's value. * * @see #setProperty(int, String) * @see #getProperty * @see Variant */ @SuppressWarnings("deprecation") public void setProperty(final int id, final long variantType, final Object value) { setProperty(new Property(id, variantType, value)); }
/** * @see Object#toString() */ @Override public String toString() { return toString(Property.DEFAULT_CODEPAGE, null); }
/** * 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; }