You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ki...@apache.org on 2016/11/27 20:19:19 UTC
svn commit: r1771640 [1/4] - in /poi: site/src/documentation/content/xdocs/
trunk/src/java/org/apache/poi/hpsf/
trunk/src/java/org/apache/poi/hpsf/extractor/
trunk/src/java/org/apache/poi/util/
trunk/src/testcases/org/apache/poi/hpsf/basic/
Author: kiwiwings
Date: Sun Nov 27 20:19:18 2016
New Revision: 1771640
URL: http://svn.apache.org/viewvc?rev=1771640&view=rev
Log:
#60331 - Remove deprecated classes - deprecate Mutable* property classes
sonarcube fix - make protected attributes private
Modified:
poi/site/src/documentation/content/xdocs/status.xml
poi/trunk/src/java/org/apache/poi/hpsf/CustomProperties.java
poi/trunk/src/java/org/apache/poi/hpsf/CustomProperty.java
poi/trunk/src/java/org/apache/poi/hpsf/DocumentSummaryInformation.java
poi/trunk/src/java/org/apache/poi/hpsf/MutableProperty.java
poi/trunk/src/java/org/apache/poi/hpsf/MutablePropertySet.java
poi/trunk/src/java/org/apache/poi/hpsf/MutableSection.java
poi/trunk/src/java/org/apache/poi/hpsf/NoFormatIDException.java
poi/trunk/src/java/org/apache/poi/hpsf/Property.java
poi/trunk/src/java/org/apache/poi/hpsf/PropertySet.java
poi/trunk/src/java/org/apache/poi/hpsf/PropertySetFactory.java
poi/trunk/src/java/org/apache/poi/hpsf/Section.java
poi/trunk/src/java/org/apache/poi/hpsf/SpecialPropertySet.java
poi/trunk/src/java/org/apache/poi/hpsf/SummaryInformation.java
poi/trunk/src/java/org/apache/poi/hpsf/Util.java
poi/trunk/src/java/org/apache/poi/hpsf/VariantSupport.java
poi/trunk/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java
poi/trunk/src/java/org/apache/poi/util/IOUtils.java
poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestBasic.java
poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java
Modified: poi/site/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/site/src/documentation/content/xdocs/status.xml?rev=1771640&r1=1771639&r2=1771640&view=diff
==============================================================================
--- poi/site/src/documentation/content/xdocs/status.xml (original)
+++ poi/site/src/documentation/content/xdocs/status.xml Sun Nov 27 20:19:18 2016
@@ -58,6 +58,7 @@
<release version="3.16-beta2" date="2017-02-??">
<actions>
+ <action dev="PD" type="fix" fixes-bug="60331" module="HPSF">Remove deprecated classes - deprecate Mutable* property classes</action>
<action dev="PD" type="fix" fixes-bug="59200" module="SS Common">Check for actual Excel limits on data validation title/text</action>
<action dev="PD" type="fix" fixes-bug="60373" module="XSLF">TableCell.getTextHeight() returns NullPointerException</action>
</actions>
Modified: poi/trunk/src/java/org/apache/poi/hpsf/CustomProperties.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hpsf/CustomProperties.java?rev=1771640&r1=1771639&r2=1771640&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hpsf/CustomProperties.java (original)
+++ poi/trunk/src/java/org/apache/poi/hpsf/CustomProperties.java Sun Nov 27 20:19:18 2016
@@ -19,132 +19,112 @@ package org.apache.poi.hpsf;
import java.util.Date;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.Map;
import java.util.Set;
+import org.apache.commons.collections4.bidimap.TreeBidiMap;
import org.apache.poi.hpsf.wellknown.PropertyIDMap;
/**
- * <p>Maintains the instances of {@link CustomProperty} that belong to a
+ * Maintains the instances of {@link CustomProperty} that belong to a
* {@link DocumentSummaryInformation}. The class maintains the names of the
* custom properties in a dictionary. It implements the {@link Map} interface
* and by this provides a simplified view on custom properties: A property's
* name is the key that maps to a typed value. This implementation hides
* property IDs from the developer and regards the property names as keys to
- * typed values.</p>
+ * typed values.<p>
*
- * <p>While this class provides a simple API to custom properties, it ignores
+ * While this class provides a simple API to custom properties, it ignores
* the fact that not names, but IDs are the real keys to properties. Under the
* hood this class maintains a 1:1 relationship between IDs and names. Therefore
* you should not use this class to process property sets with several IDs
* mapping to the same name or with properties without a name: the result will
* contain only a subset of the original properties. If you really need to deal
- * such property sets, use HPSF's low-level access methods.</p>
+ * such property sets, use HPSF's low-level access methods.<p>
*
- * <p>An application can call the {@link #isPure} method to check whether a
+ * An application can call the {@link #isPure} method to check whether a
* property set parsed by {@link CustomProperties} is still pure (i.e.
- * unmodified) or whether one or more properties have been dropped.</p>
+ * unmodified) or whether one or more properties have been dropped.<p>
*
- * <p>This class is not thread-safe; concurrent access to instances of this
- * class must be synchronized.</p>
+ * This class is not thread-safe; concurrent access to instances of this
+ * class must be synchronized.<p>
*
- * <p>While this class is roughly HashMap<Long,CustomProperty>, that's the
- * internal representation. To external calls, it should appear as
- * HashMap<String,Object> mapping between Names and Custom Property Values.</p>
+ * While this class is roughly HashMap<Long,CustomProperty>, that's the
+ * internal representation. To external calls, it should appear as
+ * HashMap<String,Object> mapping between Names and Custom Property Values.
*/
@SuppressWarnings("serial")
-public class CustomProperties extends HashMap<Object,CustomProperty>
-{
+public class CustomProperties extends HashMap<Long,CustomProperty> {
/**
- * <p>Maps property IDs to property names.</p>
+ * Maps property IDs to property names and vice versa.
*/
- private final Map<Long,String> dictionaryIDToName = new HashMap<Long,String>();
+ private final TreeBidiMap<Long,String> dictionary = new TreeBidiMap<Long,String>();
/**
- * <p>Maps property names to property IDs.</p>
- */
- private final Map<String,Long> dictionaryNameToID = new HashMap<String,Long>();
-
- /**
- * <p>Tells whether this object is pure or not.</p>
+ * Tells whether this object is pure or not.
*/
private boolean isPure = true;
/**
- * <p>Puts a {@link CustomProperty} into this map. It is assumed that the
+ * Puts a {@link CustomProperty} into this map. It is assumed that the
* {@link CustomProperty} already has a valid ID. Otherwise use
- * {@link #put(CustomProperty)}.</p>
+ * {@link #put(CustomProperty)}.
*
* @param name the property name
* @param cp the property
*
* @return the previous property stored under this name
*/
- public CustomProperty put(final String name, final CustomProperty cp)
- {
- if (name == null)
- {
+ public CustomProperty put(final String name, final CustomProperty cp) {
+ if (name == null) {
/* Ignoring a property without a name. */
isPure = false;
return null;
}
- if (!(name.equals(cp.getName())))
+
+ if (!name.equals(cp.getName())) {
throw new IllegalArgumentException("Parameter \"name\" (" + name +
") and custom property's name (" + cp.getName() +
") do not match.");
+ }
/* Register name and ID in the dictionary. Mapping in both directions is possible. If there is already a */
- final Long idKey = Long.valueOf(cp.getID());
- final Long oldID = dictionaryNameToID.get(name);
- dictionaryIDToName.remove(oldID);
- dictionaryNameToID.put(name, idKey);
- dictionaryIDToName.put(idKey, name);
+ super.remove(dictionary.getKey(name));
+ dictionary.put(cp.getID(), name);
/* Put the custom property into this map. */
- final CustomProperty oldCp = super.remove(oldID);
- super.put(idKey, cp);
- return oldCp;
+ return super.put(cp.getID(), cp);
}
/**
- * <p>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:</p>
+ * 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><p>If there is already a property with the same name, take the ID
- * of that property.</p></li>
- *
- * <li><p>Otherwise find the highest ID and use its value plus one.</p></li>
- *
+ * <li>Otherwise find the highest ID and use its value plus one.
* </ul>
*
* @param customProperty
- * @return If the was already a property with the same name, the
+ * @return If there was already a property with the same name, the old property
* @throws ClassCastException
*/
- private Object put(final CustomProperty customProperty) 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 = dictionaryNameToID.get(name);
- if (oldId != null)
- customProperty.setID(oldId.longValue());
- else
- {
- long max = 1;
- for (Long long1 : dictionaryIDToName.keySet()) {
- final long id = long1.longValue();
- if (id > max)
- max = id;
- }
- customProperty.setID(max + 1);
+ final Long oldId = (name == null) ? null : dictionary.getKey(name);
+ if (oldId != null) {
+ customProperty.setID(oldId);
+ } else {
+ long lastKey = (dictionary.isEmpty()) ? 0 : dictionary.lastKey();
+ customProperty.setID(Math.max(lastKey,PropertyIDMap.PID_MAX) + 1);
}
return this.put(name, customProperty);
}
@@ -152,123 +132,92 @@ public class CustomProperties extends Ha
/**
- * <p>Removes a custom property.</p>
+ * Removes a custom property.
* @param name The name of the custom property to remove
- * @return The removed property or <code>null</code> if the specified property was not found.
+ * @return The removed property or {@code null} if the specified property was not found.
*
* @see java.util.HashSet#remove(java.lang.Object)
*/
- public Object remove(final String name)
- {
- final Long id = dictionaryNameToID.get(name);
- if (id == null)
- return null;
- dictionaryIDToName.remove(id);
- dictionaryNameToID.remove(name);
+ public Object remove(final String name) {
+ final Long id = dictionary.removeValue(name);
return super.remove(id);
}
/**
- * <p>Adds a named string property.</p>
+ * Adds a named string property.
*
* @param name The property's name.
* @param value The property's value.
* @return the property that was stored under the specified name before, or
- * <code>null</code> if there was no such property before.
+ * {@code null} if there was no such property before.
*/
- public Object put(final String name, final String value)
- {
- final MutableProperty p = new MutableProperty();
- p.setID(-1);
- p.setType(Variant.VT_LPWSTR);
- p.setValue(value);
- final CustomProperty cp = new CustomProperty(p, name);
- return put(cp);
+ public Object put(final String name, final String value) {
+ final Property p = new Property(-1, Variant.VT_LPWSTR, value);
+ return put(new CustomProperty(p, name));
}
/**
- * <p>Adds a named long property.</p>
+ * Adds a named long property.
*
* @param name The property's name.
* @param value The property's value.
* @return the property that was stored under the specified name before, or
- * <code>null</code> if there was no such property before.
+ * {@code null} if there was no such property before.
*/
- public Object put(final String name, final Long value)
- {
- final MutableProperty p = new MutableProperty();
- p.setID(-1);
- p.setType(Variant.VT_I8);
- p.setValue(value);
- final CustomProperty cp = new CustomProperty(p, name);
- return put(cp);
+ public Object put(final String name, final Long value) {
+ final Property p = new Property(-1, Variant.VT_I8, value);
+ return put(new CustomProperty(p, name));
}
/**
- * <p>Adds a named double property.</p>
+ * Adds a named double property.
*
* @param name The property's name.
* @param value The property's value.
* @return the property that was stored under the specified name before, or
- * <code>null</code> if there was no such property before.
+ * {@code null} if there was no such property before.
*/
- public Object put(final String name, final Double value)
- {
- final MutableProperty p = new MutableProperty();
- p.setID(-1);
- p.setType(Variant.VT_R8);
- p.setValue(value);
- final CustomProperty cp = new CustomProperty(p, name);
- return put(cp);
+ public Object put(final String name, final Double value) {
+ final Property p = new Property(-1, Variant.VT_R8, value);
+ return put(new CustomProperty(p, name));
}
/**
- * <p>Adds a named integer property.</p>
+ * Adds a named integer property.
*
* @param name The property's name.
* @param value The property's value.
* @return the property that was stored under the specified name before, or
- * <code>null</code> if there was no such property before.
+ * {@code null} if there was no such property before.
*/
- public Object put(final String name, final Integer value)
- {
- final MutableProperty p = new MutableProperty();
- p.setID(-1);
- p.setType(Variant.VT_I4);
- p.setValue(value);
- final CustomProperty cp = new CustomProperty(p, name);
- return put(cp);
+ public Object put(final String name, final Integer value) {
+ final Property p = new Property(-1, Variant.VT_I4, value);
+ return put(new CustomProperty(p, name));
}
/**
- * <p>Adds a named boolean property.</p>
+ * Adds a named boolean property.
*
* @param name The property's name.
* @param value The property's value.
* @return the property that was stored under the specified name before, or
- * <code>null</code> if there was no such property before.
+ * {@code null} if there was no such property before.
*/
- public Object put(final String name, final Boolean value)
- {
- final MutableProperty p = new MutableProperty();
- p.setID(-1);
- p.setType(Variant.VT_BOOL);
- p.setValue(value);
- final CustomProperty cp = new CustomProperty(p, name);
- return put(cp);
+ public Object put(final String name, final Boolean value) {
+ final Property p = new Property(-1, Variant.VT_BOOL, value);
+ return put(new CustomProperty(p, name));
}
/**
- * <p>Gets a named value from the custom properties.</p>
+ * Gets a named value from the custom properties.
*
* @param name the name of the value to get
- * @return the value or <code>null</code> if a value with the specified
+ * @return the value or {@code null} if a value with the specified
* name is not found in the custom properties.
*/
- public Object get(final String name)
- {
- final Long id = dictionaryNameToID.get(name);
+ public Object get(final String name) {
+ final Long id = dictionary.getKey(name);
final CustomProperty cp = super.get(id);
return cp != null ? cp.getValue() : null;
}
@@ -276,21 +225,16 @@ public class CustomProperties extends Ha
/**
- * <p>Adds a named date property.</p>
+ * Adds a named date property.
*
* @param name The property's name.
* @param value The property's value.
* @return the property that was stored under the specified name before, or
- * <code>null</code> if there was no such property before.
+ * {@code null} if there was no such property before.
*/
- public Object put(final String name, final Date value)
- {
- final MutableProperty p = new MutableProperty();
- p.setID(-1);
- p.setType(Variant.VT_FILETIME);
- p.setValue(value);
- final CustomProperty cp = new CustomProperty(p, name);
- return put(cp);
+ public Object put(final String name, final Date value) {
+ final Property p = new Property(-1, Variant.VT_FILETIME, value);
+ return put(new CustomProperty(p, name));
}
/**
@@ -302,7 +246,7 @@ public class CustomProperties extends Ha
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public Set keySet() {
- return dictionaryNameToID.keySet();
+ return dictionary.values();
}
/**
@@ -311,7 +255,7 @@ public class CustomProperties extends Ha
* @return a set of all the names of our custom properties
*/
public Set<String> nameSet() {
- return dictionaryNameToID.keySet();
+ return dictionary.values();
}
/**
@@ -320,21 +264,17 @@ public class CustomProperties extends Ha
* @return a set of all the IDs of our custom properties
*/
public Set<String> idSet() {
- return dictionaryNameToID.keySet();
+ return dictionary.values();
}
/**
- * <p>Sets the codepage.</p>
+ * Sets the codepage.
*
* @param codepage the codepage
*/
- public void setCodepage(final int codepage)
- {
- final MutableProperty p = new MutableProperty();
- p.setID(PropertyIDMap.PID_CODEPAGE);
- p.setType(Variant.VT_I2);
- p.setValue(Integer.valueOf(codepage));
+ public void setCodepage(final int codepage) {
+ Property p = new Property(PropertyIDMap.PID_CODEPAGE, Variant.VT_I2, codepage);
put(new CustomProperty(p));
}
@@ -346,84 +286,65 @@ public class CustomProperties extends Ha
*
* @return the dictionary.
*/
- Map<Long,String> getDictionary()
- {
- return dictionaryIDToName;
+ Map<Long,String> getDictionary() {
+ return dictionary;
}
/**
* Checks against both String Name and Long ID
*/
- @Override
- public boolean containsKey(Object key) {
- if(key instanceof Long) {
- return super.containsKey(key);
- }
- if(key instanceof String) {
- return super.containsKey(dictionaryNameToID.get(key));
- }
- return false;
- }
-
- /**
- * Checks against both the property, and its values.
- */
- @Override
- public boolean containsValue(Object value) {
- if(value instanceof CustomProperty) {
- return super.containsValue(value);
- } else {
- for(CustomProperty cp : super.values()) {
+ @Override
+ public boolean containsKey(Object key) {
+ return ((key instanceof Long && dictionary.containsKey(key)) || dictionary.containsValue(key));
+ }
+
+ /**
+ * Checks against both the property, and its values.
+ */
+ @Override
+ public boolean containsValue(Object value) {
+ if(value instanceof CustomProperty) {
+ return super.containsValue(value);
+ }
+
+ for(CustomProperty cp : super.values()) {
if(cp.getValue() == value) {
- return true;
+ return true;
}
- }
- }
- return false;
- }
-
+ }
+ return false;
+ }
- /**
- * <p>Gets the codepage.</p>
+ /**
+ * Gets the codepage.
*
* @return the codepage or -1 if the codepage is undefined.
*/
- public int getCodepage()
- {
- int codepage = -1;
- for (final Iterator<CustomProperty> i = this.values().iterator(); codepage == -1 && i.hasNext();)
- {
- final CustomProperty cp = i.next();
- if (cp.getID() == PropertyIDMap.PID_CODEPAGE)
- codepage = ((Integer) cp.getValue()).intValue();
- }
- return codepage;
+ public int getCodepage() {
+ CustomProperty cp = get(PropertyIDMap.PID_CODEPAGE);
+ return (cp == null) ? -1 : (Integer)cp.getValue();
}
-
-
/**
- * <p>Tells whether this {@link CustomProperties} instance is pure or one or
+ * Tells whether this {@link CustomProperties} instance is pure or one or
* more properties of the underlying low-level property set has been
- * dropped.</p>
+ * dropped.
*
- * @return <code>true</code> if the {@link CustomProperties} is pure, else
- * <code>false</code>.
+ * @return {@code true} if the {@link CustomProperties} is pure, else
+ * {@code false}.
*/
- public boolean isPure()
- {
+ public boolean isPure() {
return isPure;
}
/**
- * <p>Sets the purity of the custom property set.</p>
+ * Sets the purity of the custom property set.
*
* @param isPure the purity
*/
- public void setPure(final boolean isPure)
- {
+ public void setPure(final boolean isPure) {
this.isPure = isPure;
}
}
Modified: poi/trunk/src/java/org/apache/poi/hpsf/CustomProperty.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hpsf/CustomProperty.java?rev=1771640&r1=1771639&r2=1771640&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hpsf/CustomProperty.java (original)
+++ poi/trunk/src/java/org/apache/poi/hpsf/CustomProperty.java Sun Nov 27 20:19:18 2016
@@ -18,10 +18,10 @@
package org.apache.poi.hpsf;
/**
- * <p>This class represents custom properties in the document summary
+ * This class represents custom properties in the document summary
* information stream. The difference to normal properties is that custom
- * properties have an optional name. If the name is not <code>null</code> it
- * will be maintained in the section's dictionary.</p>
+ * properties have an optional name. If the name is not {@code null} it
+ * will be maintained in the section's dictionary.
*/
public class CustomProperty extends MutableProperty
{
@@ -29,80 +29,75 @@ public class CustomProperty extends Muta
private String name;
/**
- * <p>Creates an empty {@link CustomProperty}. The set methods must be
- * called to make it usable.</p>
+ * Creates an empty {@link CustomProperty}. The set methods must be
+ * called to make it usable.
*/
- public CustomProperty()
- {
+ public CustomProperty() {
this.name = null;
}
/**
- * <p>Creates a {@link CustomProperty} without a name by copying the
- * underlying {@link Property}' attributes.</p>
+ * Creates a {@link CustomProperty} without a name by copying the
+ * underlying {@link Property}' attributes.
*
* @param property the property to copy
*/
- public CustomProperty(final Property property)
- {
+ public CustomProperty(final Property property) {
this(property, null);
}
/**
- * <p>Creates a {@link CustomProperty} with a name.</p>
+ * Creates a {@link CustomProperty} with a name.
*
* @param property This property's attributes are copied to the new custom
* property.
* @param name The new custom property's name.
*/
- public CustomProperty(final Property property, final String name)
- {
+ public CustomProperty(final Property property, final String name) {
super(property);
this.name = name;
}
/**
- * <p>Gets the property's name.</p>
+ * Gets the property's name.
*
* @return the property's name.
*/
- public String getName()
- {
+ public String getName() {
return name;
}
/**
- * <p>Sets the property's name.</p>
+ * Sets the property's name.
*
* @param name The name to set.
*/
- public void setName(final String name)
- {
+ public void setName(final String name) {
this.name = name;
}
/**
- * <p>Compares two custom properties for equality. The method returns
- * <code>true</code> if all attributes of the two custom properties are
- * equal.</p>
+ * Compares two custom properties for equality. The method returns
+ * {@code true} if all attributes of the two custom properties are
+ * equal.
*
* @param o The custom property to compare with.
- * @return <code>true</code> if both custom properties are equal, else
- * <code>false</code>.
+ * @return {@code true} if both custom properties are equal, else
+ * {@code false}.
*
* @see java.util.AbstractSet#equals(java.lang.Object)
*/
- public boolean equalsContents(final Object o)
- {
+ public boolean equalsContents(final Object o) {
final CustomProperty c = (CustomProperty) o;
final String name1 = c.getName();
final String name2 = this.getName();
boolean equalNames = true;
- if (name1 == null)
+ if (name1 == null) {
equalNames = name2 == null;
- else
+ } else {
equalNames = name1.equals(name2);
+ }
return equalNames && c.getID() == this.getID()
&& c.getType() == this.getType()
&& c.getValue().equals(this.getValue());
@@ -112,8 +107,7 @@ public class CustomProperty extends Muta
* @see java.util.AbstractSet#hashCode()
*/
@Override
- public int hashCode()
- {
+ public int hashCode() {
return (int) this.getID();
}
Modified: poi/trunk/src/java/org/apache/poi/hpsf/DocumentSummaryInformation.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hpsf/DocumentSummaryInformation.java?rev=1771640&r1=1771639&r2=1771640&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hpsf/DocumentSummaryInformation.java (original)
+++ poi/trunk/src/java/org/apache/poi/hpsf/DocumentSummaryInformation.java Sun Nov 27 20:19:18 2016
@@ -17,7 +17,8 @@
package org.apache.poi.hpsf;
-import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
import java.util.Map;
import org.apache.poi.hpsf.wellknown.PropertyIDMap;
@@ -25,16 +26,15 @@ import org.apache.poi.hpsf.wellknown.Sec
import org.apache.poi.util.CodePageUtil;
/**
- * <p>Convenience class representing a DocumentSummary Information stream in a
- * Microsoft Office document.</p>
+ * Convenience class representing a DocumentSummary Information stream in a
+ * Microsoft Office document.
*
* @see SummaryInformation
*/
-public class DocumentSummaryInformation extends SpecialPropertySet
-{
+public class DocumentSummaryInformation extends SpecialPropertySet {
/**
- * <p>The document name a document summary information stream
- * usually has in a POIFS filesystem.</p>
+ * The document name a document summary information stream
+ * usually has in a POIFS filesystem.
*/
public static final String DEFAULT_STREAM_NAME =
"\005DocumentSummaryInformation";
@@ -46,351 +46,308 @@ public class DocumentSummaryInformation
/**
- * <p>Creates a {@link DocumentSummaryInformation} from a given
- * {@link PropertySet}.</p>
+ * Creates an empty {@link DocumentSummaryInformation}.
+ */
+ public DocumentSummaryInformation() {
+ getFirstSection().setFormatID(SectionIDMap.DOCUMENT_SUMMARY_INFORMATION_ID[0]);
+ }
+
+
+ /**
+ * Creates a {@link DocumentSummaryInformation} from a given
+ * {@link PropertySet}.
*
* @param ps A property set which should be created from a
* document summary information stream.
- * @throws UnexpectedPropertySetTypeException if <var>ps</var>
+ * @throws UnexpectedPropertySetTypeException if {@code ps}
* does not contain a document summary information stream.
*/
public DocumentSummaryInformation(final PropertySet ps)
- throws UnexpectedPropertySetTypeException
- {
+ throws UnexpectedPropertySetTypeException {
super(ps);
- if (!isDocumentSummaryInformation())
- throw new UnexpectedPropertySetTypeException
- ("Not a " + getClass().getName());
+ if (!isDocumentSummaryInformation()) {
+ throw new UnexpectedPropertySetTypeException("Not a " + getClass().getName());
+ }
}
/**
- * <p>Returns the category (or {@code null}).</p>
+ * Returns the category (or {@code null}).
*
* @return The category value
*/
- public String getCategory()
- {
+ public String getCategory() {
return getPropertyStringValue(PropertyIDMap.PID_CATEGORY);
}
/**
- * <p>Sets the category.</p>
+ * Sets the category.
*
* @param category The category to set.
*/
- public void setCategory(final String category)
- {
- final MutableSection s = (MutableSection) getFirstSection();
- s.setProperty(PropertyIDMap.PID_CATEGORY, category);
+ public void setCategory(final String category) {
+ getFirstSection().setProperty(PropertyIDMap.PID_CATEGORY, category);
}
/**
- * <p>Removes the category.</p>
+ * Removes the category.
*/
- public void removeCategory()
- {
- final MutableSection s = (MutableSection) getFirstSection();
- s.removeProperty(PropertyIDMap.PID_CATEGORY);
+ public void removeCategory() {
+ remove1stProperty(PropertyIDMap.PID_CATEGORY);
}
/**
- * <p>Returns the presentation format (or
- * {@code null}).</p>
+ * Returns the presentation format (or
+ * {@code null}).
*
* @return The presentation format value
*/
- public String getPresentationFormat()
- {
+ public String getPresentationFormat() {
return getPropertyStringValue(PropertyIDMap.PID_PRESFORMAT);
}
/**
- * <p>Sets the presentation format.</p>
+ * Sets the presentation format.
*
* @param presentationFormat The presentation format to set.
*/
- public void setPresentationFormat(final String presentationFormat)
- {
- final MutableSection s = (MutableSection) getFirstSection();
- s.setProperty(PropertyIDMap.PID_PRESFORMAT, presentationFormat);
+ public void setPresentationFormat(final String presentationFormat) {
+ getFirstSection().setProperty(PropertyIDMap.PID_PRESFORMAT, presentationFormat);
}
/**
- * <p>Removes the presentation format.</p>
+ * Removes the presentation format.
*/
- public void removePresentationFormat()
- {
- final MutableSection s = (MutableSection) getFirstSection();
- s.removeProperty(PropertyIDMap.PID_PRESFORMAT);
+ public void removePresentationFormat() {
+ remove1stProperty(PropertyIDMap.PID_PRESFORMAT);
}
/**
- * <p>Returns the byte count or 0 if the {@link
- * DocumentSummaryInformation} does not contain a byte count.</p>
+ * Returns the byte count or 0 if the {@link
+ * DocumentSummaryInformation} does not contain a byte count.
*
* @return The byteCount value
*/
- public int getByteCount()
- {
+ public int getByteCount() {
return getPropertyIntValue(PropertyIDMap.PID_BYTECOUNT);
}
/**
- * <p>Sets the byte count.</p>
+ * Sets the byte count.
*
* @param byteCount The byte count to set.
*/
- public void setByteCount(final int byteCount)
- {
- final MutableSection s = (MutableSection) getFirstSection();
- s.setProperty(PropertyIDMap.PID_BYTECOUNT, byteCount);
+ public void setByteCount(final int byteCount) {
+ set1stProperty(PropertyIDMap.PID_BYTECOUNT, byteCount);
}
/**
- * <p>Removes the byte count.</p>
+ * Removes the byte count.
*/
- public void removeByteCount()
- {
- final MutableSection s = (MutableSection) getFirstSection();
- s.removeProperty(PropertyIDMap.PID_BYTECOUNT);
+ public void removeByteCount() {
+ remove1stProperty(PropertyIDMap.PID_BYTECOUNT);
}
/**
- * <p>Returns the line count or 0 if the {@link
- * DocumentSummaryInformation} does not contain a line count.</p>
+ * Returns the line count or 0 if the {@link
+ * DocumentSummaryInformation} does not contain a line count.
*
* @return The line count value
*/
- public int getLineCount()
- {
+ public int getLineCount() {
return getPropertyIntValue(PropertyIDMap.PID_LINECOUNT);
}
/**
- * <p>Sets the line count.</p>
+ * Sets the line count.
*
* @param lineCount The line count to set.
*/
- public void setLineCount(final int lineCount)
- {
- final MutableSection s = (MutableSection) getFirstSection();
- s.setProperty(PropertyIDMap.PID_LINECOUNT, lineCount);
+ public void setLineCount(final int lineCount) {
+ set1stProperty(PropertyIDMap.PID_LINECOUNT, lineCount);
}
/**
- * <p>Removes the line count.</p>
+ * Removes the line count.
*/
- public void removeLineCount()
- {
- final MutableSection s = (MutableSection) getFirstSection();
- s.removeProperty(PropertyIDMap.PID_LINECOUNT);
+ public void removeLineCount() {
+ remove1stProperty(PropertyIDMap.PID_LINECOUNT);
}
/**
- * <p>Returns the par count or 0 if the {@link
- * DocumentSummaryInformation} does not contain a par count.</p>
+ * Returns the par count or 0 if the {@link
+ * DocumentSummaryInformation} does not contain a par count.
*
* @return The par count value
*/
- public int getParCount()
- {
+ public int getParCount() {
return getPropertyIntValue(PropertyIDMap.PID_PARCOUNT);
}
/**
- * <p>Sets the par count.</p>
+ * Sets the par count.
*
* @param parCount The par count to set.
*/
- public void setParCount(final int parCount)
- {
- final MutableSection s = (MutableSection) getFirstSection();
- s.setProperty(PropertyIDMap.PID_PARCOUNT, parCount);
+ public void setParCount(final int parCount) {
+ set1stProperty(PropertyIDMap.PID_PARCOUNT, parCount);
}
/**
- * <p>Removes the par count.</p>
+ * Removes the par count.
*/
- public void removeParCount()
- {
- final MutableSection s = (MutableSection) getFirstSection();
- s.removeProperty(PropertyIDMap.PID_PARCOUNT);
+ public void removeParCount() {
+ remove1stProperty(PropertyIDMap.PID_PARCOUNT);
}
/**
- * <p>Returns the slide count or 0 if the {@link
- * DocumentSummaryInformation} does not contain a slide count.</p>
+ * Returns the slide count or 0 if the {@link
+ * DocumentSummaryInformation} does not contain a slide count.
*
* @return The slide count value
*/
- public int getSlideCount()
- {
+ public int getSlideCount() {
return getPropertyIntValue(PropertyIDMap.PID_SLIDECOUNT);
}
/**
- * <p>Sets the slideCount.</p>
+ * Sets the slideCount.
*
* @param slideCount The slide count to set.
*/
- public void setSlideCount(final int slideCount)
- {
- final MutableSection s = (MutableSection) getFirstSection();
- s.setProperty(PropertyIDMap.PID_SLIDECOUNT, slideCount);
+ public void setSlideCount(final int slideCount) {
+ set1stProperty(PropertyIDMap.PID_SLIDECOUNT, slideCount);
}
/**
- * <p>Removes the slide count.</p>
+ * Removes the slide count.
*/
- public void removeSlideCount()
- {
- final MutableSection s = (MutableSection) getFirstSection();
- s.removeProperty(PropertyIDMap.PID_SLIDECOUNT);
+ public void removeSlideCount() {
+ remove1stProperty(PropertyIDMap.PID_SLIDECOUNT);
}
/**
- * <p>Returns the note count or 0 if the {@link
- * DocumentSummaryInformation} does not contain a note count.</p>
+ * Returns the note count or 0 if the {@link
+ * DocumentSummaryInformation} does not contain a note count.
*
* @return The note count value
*/
- public int getNoteCount()
- {
+ public int getNoteCount() {
return getPropertyIntValue(PropertyIDMap.PID_NOTECOUNT);
}
/**
- * <p>Sets the note count.</p>
+ * Sets the note count.
*
* @param noteCount The note count to set.
*/
- public void setNoteCount(final int noteCount)
- {
- final MutableSection s = (MutableSection) getFirstSection();
- s.setProperty(PropertyIDMap.PID_NOTECOUNT, noteCount);
+ public void setNoteCount(final int noteCount) {
+ set1stProperty(PropertyIDMap.PID_NOTECOUNT, noteCount);
}
/**
- * <p>Removes the noteCount.</p>
+ * Removes the noteCount.
*/
- public void removeNoteCount()
- {
- final MutableSection s = (MutableSection) getFirstSection();
- s.removeProperty(PropertyIDMap.PID_NOTECOUNT);
+ public void removeNoteCount() {
+ remove1stProperty(PropertyIDMap.PID_NOTECOUNT);
}
/**
- * <p>Returns the hidden count or 0 if the {@link
+ * Returns the hidden count or 0 if the {@link
* DocumentSummaryInformation} does not contain a hidden
- * count.</p>
+ * count.
*
* @return The hidden count value
*/
- public int getHiddenCount()
- {
+ public int getHiddenCount() {
return getPropertyIntValue(PropertyIDMap.PID_HIDDENCOUNT);
}
/**
- * <p>Sets the hidden count.</p>
+ * Sets the hidden count.
*
* @param hiddenCount The hidden count to set.
*/
- public void setHiddenCount(final int hiddenCount)
- {
- final MutableSection s = (MutableSection) getSections().get(0);
- s.setProperty(PropertyIDMap.PID_HIDDENCOUNT, hiddenCount);
+ public void setHiddenCount(final int hiddenCount) {
+ set1stProperty(PropertyIDMap.PID_HIDDENCOUNT, hiddenCount);
}
/**
- * <p>Removes the hidden count.</p>
+ * Removes the hidden count.
*/
- public void removeHiddenCount()
- {
- final MutableSection s = (MutableSection) getFirstSection();
- s.removeProperty(PropertyIDMap.PID_HIDDENCOUNT);
+ public void removeHiddenCount() {
+ remove1stProperty(PropertyIDMap.PID_HIDDENCOUNT);
}
/**
- * <p>Returns the mmclip count or 0 if the {@link
+ * Returns the mmclip count or 0 if the {@link
* DocumentSummaryInformation} does not contain a mmclip
- * count.</p>
+ * count.
*
* @return The mmclip count value
*/
- public int getMMClipCount()
- {
+ public int getMMClipCount() {
return getPropertyIntValue(PropertyIDMap.PID_MMCLIPCOUNT);
}
/**
- * <p>Sets the mmclip count.</p>
+ * Sets the mmclip count.
*
* @param mmClipCount The mmclip count to set.
*/
- public void setMMClipCount(final int mmClipCount)
- {
- final MutableSection s = (MutableSection) getFirstSection();
- s.setProperty(PropertyIDMap.PID_MMCLIPCOUNT, mmClipCount);
+ public void setMMClipCount(final int mmClipCount) {
+ set1stProperty(PropertyIDMap.PID_MMCLIPCOUNT, mmClipCount);
}
/**
- * <p>Removes the mmclip count.</p>
+ * Removes the mmclip count.
*/
- public void removeMMClipCount()
- {
- final MutableSection s = (MutableSection) getFirstSection();
- s.removeProperty(PropertyIDMap.PID_MMCLIPCOUNT);
+ public void removeMMClipCount() {
+ remove1stProperty(PropertyIDMap.PID_MMCLIPCOUNT);
}
/**
- * <p>Returns <code>true</code> when scaling of the thumbnail is
- * desired, <code>false</code> if cropping is desired.</p>
+ * Returns {@code true} when scaling of the thumbnail is
+ * desired, {@code false} if cropping is desired.
*
* @return The scale value
*/
- public boolean getScale()
- {
+ public boolean getScale() {
return getPropertyBooleanValue(PropertyIDMap.PID_SCALE);
}
/**
- * <p>Sets the scale.</p>
+ * Sets the scale.
*
* @param scale The scale to set.
*/
- public void setScale(final boolean scale)
- {
- final MutableSection s = (MutableSection) getFirstSection();
- s.setProperty(PropertyIDMap.PID_SCALE, scale);
+ public void setScale(final boolean scale) {
+ set1stProperty(PropertyIDMap.PID_SCALE, scale);
}
/**
- * <p>Removes the scale.</p>
+ * Removes the scale.
*/
- public void removeScale()
- {
- final MutableSection s = (MutableSection) getFirstSection();
- s.removeProperty(PropertyIDMap.PID_SCALE);
+ public void removeScale() {
+ remove1stProperty(PropertyIDMap.PID_SCALE);
}
@@ -402,29 +359,25 @@ public class DocumentSummaryInformation
*
* @return The heading pair value
*/
- public byte[] getHeadingPair()
- {
+ public byte[] getHeadingPair() {
notYetImplemented("Reading byte arrays ");
return (byte[]) getProperty(PropertyIDMap.PID_HEADINGPAIR);
}
/**
- * <p>Sets the heading pair.</p>
+ * Sets the heading pair.
*
* @param headingPair The heading pair to set.
*/
- public void setHeadingPair(final byte[] headingPair)
- {
+ public void setHeadingPair(final byte[] headingPair) {
notYetImplemented("Writing byte arrays ");
}
/**
- * <p>Removes the heading pair.</p>
+ * Removes the heading pair.
*/
- public void removeHeadingPair()
- {
- final MutableSection s = (MutableSection) getFirstSection();
- s.removeProperty(PropertyIDMap.PID_HEADINGPAIR);
+ public void removeHeadingPair() {
+ remove1stProperty(PropertyIDMap.PID_HEADINGPAIR);
}
@@ -436,8 +389,7 @@ public class DocumentSummaryInformation
*
* @return The doc parts value
*/
- public byte[] getDocparts()
- {
+ public byte[] getDocparts() {
notYetImplemented("Reading byte arrays");
return (byte[]) getProperty(PropertyIDMap.PID_DOCPARTS);
}
@@ -445,129 +397,110 @@ public class DocumentSummaryInformation
/**
- * <p>Sets the doc parts.</p>
+ * Sets the doc parts.
*
* @param docparts The doc parts to set.
*/
- public void setDocparts(final byte[] docparts)
- {
+ public void setDocparts(final byte[] docparts) {
notYetImplemented("Writing byte arrays");
}
/**
- * <p>Removes the doc parts.</p>
+ * Removes the doc parts.
*/
- public void removeDocparts()
- {
- final MutableSection s = (MutableSection) getFirstSection();
- s.removeProperty(PropertyIDMap.PID_DOCPARTS);
+ public void removeDocparts() {
+ remove1stProperty(PropertyIDMap.PID_DOCPARTS);
}
/**
- * <p>Returns the manager (or {@code null}).</p>
+ * Returns the manager (or {@code null}).
*
* @return The manager value
*/
- public String getManager()
- {
+ public String getManager() {
return getPropertyStringValue(PropertyIDMap.PID_MANAGER);
}
/**
- * <p>Sets the manager.</p>
+ * Sets the manager.
*
* @param manager The manager to set.
*/
- public void setManager(final String manager)
- {
- final MutableSection s = (MutableSection) getFirstSection();
- s.setProperty(PropertyIDMap.PID_MANAGER, manager);
+ public void setManager(final String manager) {
+ set1stProperty(PropertyIDMap.PID_MANAGER, manager);
}
/**
- * <p>Removes the manager.</p>
+ * Removes the manager.
*/
- public void removeManager()
- {
- final MutableSection s = (MutableSection) getFirstSection();
- s.removeProperty(PropertyIDMap.PID_MANAGER);
+ public void removeManager() {
+ remove1stProperty(PropertyIDMap.PID_MANAGER);
}
/**
- * <p>Returns the company (or {@code null}).</p>
+ * Returns the company (or {@code null}).
*
* @return The company value
*/
- public String getCompany()
- {
+ public String getCompany() {
return getPropertyStringValue(PropertyIDMap.PID_COMPANY);
}
/**
- * <p>Sets the company.</p>
+ * Sets the company.
*
* @param company The company to set.
*/
- public void setCompany(final String company)
- {
- final MutableSection s = (MutableSection) getFirstSection();
- s.setProperty(PropertyIDMap.PID_COMPANY, company);
+ public void setCompany(final String company) {
+ set1stProperty(PropertyIDMap.PID_COMPANY, company);
}
/**
- * <p>Removes the company.</p>
+ * Removes the company.
*/
- public void removeCompany()
- {
- final MutableSection s = (MutableSection) getFirstSection();
- s.removeProperty(PropertyIDMap.PID_COMPANY);
+ public void removeCompany() {
+ remove1stProperty(PropertyIDMap.PID_COMPANY);
}
/**
- * <p>Returns <code>true</code> if the custom links are dirty.</p> <p>
+ * Returns {@code true} if the custom links are dirty. <p>
*
* @return The links dirty value
*/
- public boolean getLinksDirty()
- {
+ public boolean getLinksDirty() {
return getPropertyBooleanValue(PropertyIDMap.PID_LINKSDIRTY);
}
/**
- * <p>Sets the linksDirty.</p>
+ * Sets the linksDirty.
*
* @param linksDirty The links dirty value to set.
*/
- public void setLinksDirty(final boolean linksDirty)
- {
- final MutableSection s = (MutableSection) getFirstSection();
- s.setProperty(PropertyIDMap.PID_LINKSDIRTY, linksDirty);
+ public void setLinksDirty(final boolean linksDirty) {
+ set1stProperty(PropertyIDMap.PID_LINKSDIRTY, linksDirty);
}
/**
- * <p>Removes the links dirty.</p>
+ * Removes the links dirty.
*/
- public void removeLinksDirty()
- {
- final MutableSection s = (MutableSection) getFirstSection();
- s.removeProperty(PropertyIDMap.PID_LINKSDIRTY);
+ public void removeLinksDirty() {
+ remove1stProperty(PropertyIDMap.PID_LINKSDIRTY);
}
/**
- * <p>Returns the character count including whitespace, or 0 if the
- * {@link DocumentSummaryInformation} does not contain this char count.</p>
+ * Returns the character count including whitespace, or 0 if the
+ * {@link DocumentSummaryInformation} does not contain this char count.
* <p>This is the whitespace-including version of {@link SummaryInformation#getCharCount()}
*
* @return The character count or {@code null}
*/
- public int getCharCountWithSpaces()
- {
+ public int getCharCountWithSpaces() {
return getPropertyIntValue(PropertyIDMap.PID_CCHWITHSPACES);
}
@@ -576,19 +509,15 @@ public class DocumentSummaryInformation
*
* @param count The character count to set.
*/
- public void setCharCountWithSpaces(int count)
- {
- final MutableSection s = (MutableSection) getFirstSection();
- s.setProperty(PropertyIDMap.PID_CCHWITHSPACES, count);
+ public void setCharCountWithSpaces(int count) {
+ set1stProperty(PropertyIDMap.PID_CCHWITHSPACES, count);
}
/**
* Removes the character count
*/
- public void removeCharCountWithSpaces()
- {
- final MutableSection s = (MutableSection) getFirstSection();
- s.removeProperty(PropertyIDMap.PID_CCHWITHSPACES);
+ public void removeCharCountWithSpaces() {
+ remove1stProperty(PropertyIDMap.PID_CCHWITHSPACES);
}
@@ -599,8 +528,7 @@ public class DocumentSummaryInformation
*
* @return true, if the hyperlinks should be updated on document load
*/
- public boolean getHyperlinksChanged()
- {
+ public boolean getHyperlinksChanged() {
return getPropertyBooleanValue(PropertyIDMap.PID_HYPERLINKSCHANGED);
}
@@ -610,20 +538,16 @@ public class DocumentSummaryInformation
*
* @param changed true, if the User Defined Property Set has been updated
*/
- public void setHyperlinksChanged(boolean changed)
- {
- final MutableSection s = (MutableSection) getFirstSection();
- s.setProperty(PropertyIDMap.PID_HYPERLINKSCHANGED, changed);
+ public void setHyperlinksChanged(boolean changed) {
+ set1stProperty(PropertyIDMap.PID_HYPERLINKSCHANGED, changed);
}
/**
* Removes the flag for if the User Defined Property Set has been updated
* outside of the Application.
*/
- public void removeHyperlinksChanged()
- {
- final MutableSection s = (MutableSection) getFirstSection();
- s.removeProperty(PropertyIDMap.PID_HYPERLINKSCHANGED);
+ public void removeHyperlinksChanged() {
+ remove1stProperty(PropertyIDMap.PID_HYPERLINKSCHANGED);
}
@@ -635,8 +559,7 @@ public class DocumentSummaryInformation
*
* @return the Application version
*/
- public int getApplicationVersion()
- {
+ public int getApplicationVersion() {
return getPropertyIntValue(PropertyIDMap.PID_VERSION);
}
@@ -647,19 +570,15 @@ public class DocumentSummaryInformation
*
* @param version the Application version
*/
- public void setApplicationVersion(int version)
- {
- final MutableSection s = (MutableSection) getFirstSection();
- s.setProperty(PropertyIDMap.PID_VERSION, version);
+ public void setApplicationVersion(int version) {
+ set1stProperty(PropertyIDMap.PID_VERSION, version);
}
/**
* Removes the Application Version
*/
- public void removeApplicationVersion()
- {
- final MutableSection s = (MutableSection) getFirstSection();
- s.removeProperty(PropertyIDMap.PID_VERSION);
+ public void removeApplicationVersion() {
+ remove1stProperty(PropertyIDMap.PID_VERSION);
}
@@ -669,8 +588,7 @@ public class DocumentSummaryInformation
*
* @return the VBA digital signature
*/
- public byte[] getVBADigitalSignature()
- {
+ public byte[] getVBADigitalSignature() {
Object value = getProperty(PropertyIDMap.PID_DIGSIG);
if (value != null && value instanceof byte[]) {
return (byte[])value;
@@ -679,24 +597,20 @@ public class DocumentSummaryInformation
}
/**
- * <p>Sets the VBA digital signature for the VBA project
- * embedded in the document.</p>
+ * Sets the VBA digital signature for the VBA project
+ * embedded in the document.
*
* @param signature VBA Digital Signature for the project
*/
- public void setVBADigitalSignature(byte[] signature)
- {
- final MutableSection s = (MutableSection) getFirstSection();
- s.setProperty(PropertyIDMap.PID_DIGSIG, signature);
+ public void setVBADigitalSignature(byte[] signature) {
+ set1stProperty(PropertyIDMap.PID_DIGSIG, signature);
}
/**
* Removes the VBA Digital Signature
*/
- public void removeVBADigitalSignature()
- {
- final MutableSection s = (MutableSection) getFirstSection();
- s.removeProperty(PropertyIDMap.PID_DIGSIG);
+ public void removeVBADigitalSignature() {
+ remove1stProperty(PropertyIDMap.PID_DIGSIG);
}
@@ -705,8 +619,7 @@ public class DocumentSummaryInformation
*
* @return the content type of the file
*/
- public String getContentType()
- {
+ public String getContentType() {
return getPropertyStringValue(PropertyIDMap.PID_CONTENTTYPE);
}
@@ -715,19 +628,15 @@ public class DocumentSummaryInformation
*
* @param type the content type of the file
*/
- public void setContentType(String type)
- {
- final MutableSection s = (MutableSection) getFirstSection();
- s.setProperty(PropertyIDMap.PID_CONTENTTYPE, type);
+ public void setContentType(String type) {
+ set1stProperty(PropertyIDMap.PID_CONTENTTYPE, type);
}
/**
* Removes the content type of the file
*/
- public void removeContentType()
- {
- final MutableSection s = (MutableSection) getFirstSection();
- s.removeProperty(PropertyIDMap.PID_CONTENTTYPE);
+ public void removeContentType() {
+ remove1stProperty(PropertyIDMap.PID_CONTENTTYPE);
}
@@ -736,8 +645,7 @@ public class DocumentSummaryInformation
*
* @return the content status of the file
*/
- public String getContentStatus()
- {
+ public String getContentStatus() {
return getPropertyStringValue(PropertyIDMap.PID_CONTENTSTATUS);
}
@@ -746,19 +654,15 @@ public class DocumentSummaryInformation
*
* @param status the content status of the file
*/
- public void setContentStatus(String status)
- {
- final MutableSection s = (MutableSection) getFirstSection();
- s.setProperty(PropertyIDMap.PID_CONTENTSTATUS, status);
+ public void setContentStatus(String status) {
+ set1stProperty(PropertyIDMap.PID_CONTENTSTATUS, status);
}
/**
* Removes the content status of the file
*/
- public void removeContentStatus()
- {
- final MutableSection s = (MutableSection) getFirstSection();
- s.removeProperty(PropertyIDMap.PID_CONTENTSTATUS);
+ public void removeContentStatus() {
+ remove1stProperty(PropertyIDMap.PID_CONTENTSTATUS);
}
@@ -767,8 +671,7 @@ public class DocumentSummaryInformation
*
* @return the document language
*/
- public String getLanguage()
- {
+ public String getLanguage() {
return getPropertyStringValue(PropertyIDMap.PID_LANGUAGE);
}
@@ -777,30 +680,25 @@ public class DocumentSummaryInformation
*
* @param language the document language
*/
- public void setLanguage(String language)
- {
- final MutableSection s = (MutableSection) getFirstSection();
- s.setProperty(PropertyIDMap.PID_LANGUAGE, language);
+ public void setLanguage(String language) {
+ set1stProperty(PropertyIDMap.PID_LANGUAGE, language);
}
/**
* Removes the document language
*/
- public void removeLanguage()
- {
- final MutableSection s = (MutableSection) getFirstSection();
- s.removeProperty(PropertyIDMap.PID_LANGUAGE);
+ public void removeLanguage() {
+ remove1stProperty(PropertyIDMap.PID_LANGUAGE);
}
/**
- * <p>Gets the document version as a string, which is normally unset and empty
- * (or {@code null}).</p>
+ * Gets the document version as a string, which is normally unset and empty
+ * (or {@code null}).
*
* @return the document verion
*/
- public String getDocumentVersion()
- {
+ public String getDocumentVersion() {
return getPropertyStringValue(PropertyIDMap.PID_DOCVERSION);
}
@@ -809,64 +707,56 @@ public class DocumentSummaryInformation
*
* @param version the document version string
*/
- public void setDocumentVersion(String version)
- {
- final MutableSection s = (MutableSection) getFirstSection();
- s.setProperty(PropertyIDMap.PID_DOCVERSION, version);
+ public void setDocumentVersion(String version) {
+ set1stProperty(PropertyIDMap.PID_DOCVERSION, version);
}
/**
* Removes the document version string
*/
- public void removeDocumentVersion()
- {
- final MutableSection s = (MutableSection) getFirstSection();
- s.removeProperty(PropertyIDMap.PID_DOCVERSION);
+ public void removeDocumentVersion() {
+ remove1stProperty(PropertyIDMap.PID_DOCVERSION);
}
/**
- * <p>Gets the custom properties.</p>
+ * Gets the custom properties.
*
* @return The custom properties.
*/
- public CustomProperties getCustomProperties()
- {
+ public CustomProperties getCustomProperties() {
CustomProperties cps = null;
- if (getSectionCount() >= 2)
- {
+ 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 (int i = 0; i < properties.length; i++)
- {
+ for (int i = 0; i < properties.length; i++) {
final Property p = properties[i];
final long id = p.getID();
- if (id != 0 && id != 1)
- {
+ if (id != 0 && id != 1) {
propertyCount++;
final CustomProperty cp = new CustomProperty(p,
dictionary.get(Long.valueOf(id)));
cps.put(cp.getName(), cp);
}
}
- if (cps.size() != propertyCount)
+ if (cps.size() != propertyCount) {
cps.setPure(false);
+ }
}
return cps;
}
/**
- * <p>Sets the custom properties.</p>
+ * Sets the custom properties.
*
* @param customProperties The custom properties
*/
- public void setCustomProperties(final CustomProperties customProperties)
- {
+ public void setCustomProperties(final CustomProperties customProperties) {
ensureSection2();
- final MutableSection section = (MutableSection) getSections().get(1);
+ final Section section = getSections().get(1);
final Map<Long,String> dictionary = customProperties.getDictionary();
section.clear();
@@ -874,55 +764,57 @@ public class DocumentSummaryInformation
* 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)
+ if (cpCodepage < 0) {
cpCodepage = section.getCodepage();
- if (cpCodepage < 0)
+ }
+ if (cpCodepage < 0) {
cpCodepage = CodePageUtil.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();
+ for (CustomProperty p : customProperties.values()) {
section.setProperty(p);
}
}
/**
- * <p>Creates section 2 if it is not already present.</p>
- *
+ * Creates section 2 if it is not already present.
*/
- private void ensureSection2()
- {
- if (getSectionCount() < 2)
- {
- MutableSection s2 = new MutableSection();
+ private void ensureSection2() {
+ if (getSectionCount() < 2) {
+ Section s2 = new MutableSection();
s2.setFormatID(SectionIDMap.DOCUMENT_SUMMARY_INFORMATION_ID[1]);
addSection(s2);
}
}
/**
- * <p>Removes the custom properties.</p>
+ * Removes the custom properties.
*/
- public void removeCustomProperties()
- {
- if (getSectionCount() >= 2)
- getSections().remove(1);
- else
+ public void removeCustomProperties() {
+ if (getSectionCount() < 2) {
throw new HPSFRuntimeException("Illegal internal format of Document SummaryInformation stream: second section is missing.");
- }
-
+ }
+ List<Section> l = new LinkedList<Section>(getSections());
+ clearSections();
+ int idx = 0;
+ for (Section s : l) {
+ if (idx++ != 1) {
+ addSection(s);
+ }
+ }
+ }
+
/**
- * <p>Throws an {@link UnsupportedOperationException} with a message text
- * telling which functionality is not yet implemented.</p>
+ * Throws an {@link UnsupportedOperationException} with a message text
+ * telling which functionality is not yet implemented.
*
* @param msg text telling was leaves to be implemented, e.g.
* "Reading byte arrays".
*/
- private void notYetImplemented(final String msg)
- {
+ private void notYetImplemented(final String msg) {
throw new UnsupportedOperationException(msg + " is not yet implemented.");
}
}
Modified: poi/trunk/src/java/org/apache/poi/hpsf/MutableProperty.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hpsf/MutableProperty.java?rev=1771640&r1=1771639&r2=1771640&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hpsf/MutableProperty.java (original)
+++ poi/trunk/src/java/org/apache/poi/hpsf/MutableProperty.java Sun Nov 27 20:19:18 2016
@@ -17,103 +17,22 @@
package org.apache.poi.hpsf;
-import java.io.IOException;
-import java.io.OutputStream;
-
-import org.apache.poi.util.CodePageUtil;
+import org.apache.poi.util.Removal;
/**
* <p>Adds writing capability to the {@link Property} class.</p>
*
* <p>Please be aware that this class' functionality will be merged into the
* {@link Property} class at a later time, so the API will change.</p>
+ *
+ * @deprecated POI 3.16 - use Property as base class instead
*/
-public class MutableProperty extends Property
-{
-
- /**
- * <p>Creates an empty property. It must be filled using the set method to
- * be usable.</p>
- */
- public MutableProperty()
- { }
-
-
-
- /**
- * <p>Creates a <code>MutableProperty</code> as a copy of an existing
- * <code>Property</code>.</p>
- *
- * @param p The property to copy.
- */
- public MutableProperty(final Property p)
- {
- setID(p.getID());
- setType(p.getType());
- setValue(p.getValue());
- }
-
-
- /**
- * <p>Sets the property's ID.</p>
- *
- * @param id the ID
- */
- public void setID(final long id)
- {
- this.id = id;
- }
-
-
-
- /**
- * <p>Sets the property's type.</p>
- *
- * @param type the property's type
- */
- public void setType(final long type)
- {
- this.type = type;
- }
-
-
-
- /**
- * <p>Sets the property's value.</p>
- *
- * @param value the property's value
- */
- public void setValue(final Object value)
- {
- this.value = value;
- }
-
-
-
- /**
- * <p>Writes the property to an output stream.</p>
- *
- * @param out The output stream to write to.
- * @param codepage The codepage to use for writing non-wide strings
- * @return the number of bytes written to the stream
- *
- * @exception IOException if an I/O error occurs
- * @exception WritingNotSupportedException if a variant type is to be
- * written that is not yet supported
- */
- public int write(final OutputStream out, final int codepage)
- throws IOException, WritingNotSupportedException
- {
- int length = 0;
- long variantType = getType();
-
- /* Ensure that wide strings are written if the codepage is Unicode. */
- if (codepage == CodePageUtil.CP_UNICODE && variantType == Variant.VT_LPSTR)
- variantType = Variant.VT_LPWSTR;
+@Removal(version="3.18")
+public class MutableProperty extends Property {
+ public MutableProperty() {}
- length += TypeWriter.writeUIntToStream(out, variantType);
- length += VariantSupport.write(out, variantType, getValue(), codepage);
- return length;
+ public MutableProperty(final Property p) {
+ super(p);
}
}
Modified: poi/trunk/src/java/org/apache/poi/hpsf/MutablePropertySet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hpsf/MutablePropertySet.java?rev=1771640&r1=1771639&r2=1771640&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hpsf/MutablePropertySet.java (original)
+++ poi/trunk/src/java/org/apache/poi/hpsf/MutablePropertySet.java Sun Nov 27 20:19:18 2016
@@ -17,288 +17,21 @@
package org.apache.poi.hpsf;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.UnsupportedEncodingException;
-import java.util.LinkedList;
-
-import org.apache.poi.poifs.filesystem.DirectoryEntry;
-import org.apache.poi.poifs.filesystem.Entry;
-import org.apache.poi.util.LittleEndian;
-import org.apache.poi.util.LittleEndianConsts;
+import org.apache.poi.util.Removal;
/**
- * <p>Adds writing support to the {@link PropertySet} class.</p>
+ * dds writing support to the {@link PropertySet} class.<p>
+ *
+ * Please be aware that this class' functionality will be merged into the
+ * {@link PropertySet} class at a later time, so the API will change.
*
- * <p>Please be aware that this class' functionality will be merged into the
- * {@link PropertySet} class at a later time, so the API will change.</p>
+ * @deprecated POI 3.16 - use PropertySet as base class instead
*/
-public class MutablePropertySet extends PropertySet
-{
-
- /**
- * <p>Constructs a <code>MutablePropertySet</code> instance. Its
- * primary task is to initialize the immutable field with their proper
- * values. It also sets fields that might change to reasonable defaults.</p>
- */
- public MutablePropertySet()
- {
- /* Initialize the "byteOrder" field. */
- byteOrder = LittleEndian.getUShort(BYTE_ORDER_ASSERTION);
-
- /* Initialize the "format" field. */
- format = LittleEndian.getUShort(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;
-
- /* Initailize the "classID" field. */
- classID = new ClassID();
-
- /* Initialize the sections. Since property set must have at least
- * one section it is added right here. */
- sections = new LinkedList<Section>();
- sections.add(new MutableSection());
- }
-
-
-
- /**
- * <p>Constructs a <code>MutablePropertySet</code> by doing a deep copy of
- * an existing <code>PropertySet</code>. All nested elements, i.e.
- * <code>Section</code>s and <code>Property</code> instances, will be their
- * mutable counterparts in the new <code>MutablePropertySet</code>.</p>
- *
- * @param ps The property set to copy
- */
- public MutablePropertySet(final PropertySet ps)
- {
- byteOrder = ps.getByteOrder();
- format = ps.getFormat();
- osVersion = ps.getOSVersion();
- setClassID(ps.getClassID());
- clearSections();
- if (sections == null)
- sections = new LinkedList<Section>();
- for (final Section section : ps.getSections())
- {
- final MutableSection s = new MutableSection(section);
- addSection(s);
- }
- }
-
-
-
- /**
- * <p>The length of the property set stream header.</p>
- */
- private final static int OFFSET_HEADER =
- BYTE_ORDER_ASSERTION.length + /* Byte order */
- FORMAT_ASSERTION.length + /* Format */
- LittleEndianConsts.INT_SIZE + /* OS version */
- ClassID.LENGTH + /* Class ID */
- LittleEndianConsts.INT_SIZE; /* Section count */
-
-
-
- /**
- * <p>Sets the "byteOrder" property.</p>
- *
- * @param byteOrder the byteOrder value to set
- */
- public void setByteOrder(final int byteOrder)
- {
- this.byteOrder = byteOrder;
- }
-
-
-
- /**
- * <p>Sets the "format" property.</p>
- *
- * @param format the format value to set
- */
- public void setFormat(final int format)
- {
- this.format = format;
- }
-
-
-
- /**
- * <p>Sets the "osVersion" property.</p>
- *
- * @param osVersion the osVersion value to set
- */
- public void setOSVersion(final int osVersion)
- {
- this.osVersion = osVersion;
+@Removal(version="3.18")
+public class MutablePropertySet extends PropertySet {
+ public MutablePropertySet() {}
+
+ public MutablePropertySet(final PropertySet ps) {
+ super(ps);
}
-
-
-
- /**
- * <p>Sets the property set stream's low-level "class ID"
- * field.</p>
- *
- * @param classID The property set stream's low-level "class ID" field.
- *
- * @see PropertySet#getClassID()
- */
- public void setClassID(final ClassID classID)
- {
- this.classID = classID;
- }
-
-
-
- /**
- * <p>Removes all sections from this property set.</p>
- */
- public void clearSections()
- {
- sections = null;
- }
-
-
-
- /**
- * <p>Adds a section to this property set.</p>
- *
- * @param section The {@link Section} to add. It will be appended
- * after any sections that are already present in the property set
- * and thus become the last section.
- */
- public void addSection(final Section section)
- {
- if (sections == null)
- sections = new LinkedList<Section>();
- sections.add(section);
- }
-
-
-
- /**
- * <p>Writes the property set to an output stream.</p>
- *
- * @param out the output stream to write the section to
- * @exception IOException if an error when writing to the output stream
- * occurs
- * @exception WritingNotSupportedException if HPSF does not yet support
- * writing a property's variant type.
- */
- public void write(final OutputStream out)
- throws WritingNotSupportedException, IOException
- {
- /* Write the number of sections in this property set stream. */
- final int nrSections = sections.size();
-
- /* Write the property set's header. */
- TypeWriter.writeToStream(out, (short) getByteOrder());
- TypeWriter.writeToStream(out, (short) getFormat());
- TypeWriter.writeToStream(out, getOSVersion());
- TypeWriter.writeToStream(out, getClassID());
- TypeWriter.writeToStream(out, nrSections);
- int offset = OFFSET_HEADER;
-
- /* Write the section list, i.e. the references to the sections. Each
- * entry in the section list consist of the section's class ID and the
- * section's offset relative to the beginning of the stream. */
- offset += nrSections * (ClassID.LENGTH + LittleEndianConsts.INT_SIZE);
- final int sectionsBegin = offset;
- for (final Section section : sections)
- {
- final MutableSection s = (MutableSection)section;
- final ClassID formatID = s.getFormatID();
- if (formatID == null)
- throw new NoFormatIDException();
- TypeWriter.writeToStream(out, s.getFormatID());
- TypeWriter.writeUIntToStream(out, offset);
- try
- {
- offset += s.getSize();
- }
- catch (HPSFRuntimeException ex)
- {
- final Throwable cause = ex.getReason();
- if (cause instanceof UnsupportedEncodingException) {
- throw new IllegalPropertySetDataException(cause);
- }
- throw ex;
- }
- }
-
- /* Write the sections themselves. */
- offset = sectionsBegin;
- for (final Section section : sections)
- {
- final MutableSection s = (MutableSection)section;
- offset += s.write(out);
- }
-
- /* Indicate that we're done */
- out.close();
- }
-
-
-
- /**
- * <p>Returns the contents of this property set stream as an input stream.
- * The latter can be used for example to write the property set into a POIFS
- * document. The input stream represents a snapshot of the property set.
- * If the latter is modified while the input stream is still being
- * read, the modifications will not be reflected in the input stream but in
- * the {@link MutablePropertySet} only.</p>
- *
- * @return the contents of this property set stream
- *
- * @throws WritingNotSupportedException if HPSF does not yet support writing
- * of a property's variant type.
- * @throws IOException if an I/O exception occurs.
- */
- public InputStream toInputStream()
- throws IOException, WritingNotSupportedException
- {
- final ByteArrayOutputStream psStream = new ByteArrayOutputStream();
- try {
- write(psStream);
- } finally {
- psStream.close();
- }
- final byte[] streamData = psStream.toByteArray();
- return new ByteArrayInputStream(streamData);
- }
-
- /**
- * <p>Writes a property set to a document in a POI filesystem directory.</p>
- *
- * @param dir The directory in the POI filesystem to write the document to.
- * @param name The document's name. If there is already a document with the
- * same name in the directory the latter will be overwritten.
- *
- * @throws WritingNotSupportedException if the filesystem doesn't support writing
- * @throws IOException if the old entry can't be deleted or the new entry be written
- */
- public void write(final DirectoryEntry dir, final String name)
- throws WritingNotSupportedException, IOException
- {
- /* If there is already an entry with the same name, remove it. */
- try
- {
- final Entry e = dir.getEntry(name);
- e.delete();
- }
- catch (FileNotFoundException ex)
- {
- /* Entry not found, no need to remove it. */
- }
- /* Create the new entry. */
- dir.createDocument(name, toInputStream());
- }
-
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org