Class MutableSection
-
Nested Class Summary
Nested classes/interfaces inherited from class org.docx4j.org.apache.poi.hpsf.Section
Section.PropertyListEntry -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanIf the "dirty" flag is true, the section's size must be (re-)calculated before the section is written.List to assemble the properties.private byte[]Contains the bytes making out the section.Fields inherited from class org.docx4j.org.apache.poi.hpsf.Section
dictionary, formatID, offset, properties, size -
Constructor Summary
ConstructorsConstructorDescriptionCreates an empty mutable section.Constructs aMutableSectionby doing a deep copy of an existingSection. -
Method Summary
Modifier and TypeMethodDescriptionprivate intcalcSize()Calculates the section's size.voidclear()Removes all properties from the section including 0 (dictionary) and 1 (codepage).Property[]Gets this section's properties.getProperty(long id) Gets a property.intOverwrites the super class' method to cope with a redundancy: the property count is maintained in a separate member variable, but shouldn't.intgetSize()Returns the section's size.voidremoveProperty(long id) Removes a property.voidsetCodepage(int codepage) Sets the codepage.voidsetDictionary(Map<Long, String> dictionary) Sets the section's dictionary.voidsetFormatID(byte[] formatID) Sets the section's format ID.voidsetFormatID(ClassID formatID) Sets the section's format ID.voidsetProperties(Property[] properties) Sets this section's properties.voidsetProperty(int id, boolean value) Sets the boolean value of the property with the specified ID.voidsetProperty(int id, int value) Sets the int value of the property with the specified ID.voidsetProperty(int id, long value) Sets the long value of the property with the specified ID.voidsetProperty(int id, long variantType, Object value) Sets the value and the variant type of the property with the specified ID.voidsetProperty(int id, Object value) Sets a property.voidsetProperty(int id, String value) Sets the string value of the property with the specified ID.voidSets a property.protected voidsetPropertyBooleanValue(int id, boolean value) Sets the value of the boolean property with the specified ID.intwrite(OutputStream out) Writes this section into an output stream.private static intwriteDictionary(OutputStream out, Map<Long, String> dictionary, int codepage) Writes the section's dictionary.Methods inherited from class org.docx4j.org.apache.poi.hpsf.Section
equals, getCodepage, getDictionary, getFormatID, getOffset, getPIDString, getPropertyBooleanValue, getPropertyIntValue, hashCode, toString, wasNull
-
Field Details
-
dirty
private boolean dirtyIf the "dirty" flag is true, the section's size must be (re-)calculated before the section is written.
-
preprops
List to assemble the properties. Unfortunately a wrong decision has been taken when specifying the "properties" field as an Property[]. It should have been a
List. -
sectionBytes
private byte[] sectionBytesContains the bytes making out the section. This byte array is established when the section's size is calculated and can be reused later. It is valid only if the "dirty" flag is false.
-
-
Constructor Details
-
MutableSection
public MutableSection()Creates an empty mutable section.
-
MutableSection
Constructs a
MutableSectionby doing a deep copy of an existingSection. All nestedPropertyinstances, will be their mutable counterparts in the newMutableSection.- Parameters:
s- The section set to copy
-
-
Method Details
-
setFormatID
Sets the section's format ID.
- Parameters:
formatID- The section's format ID- See Also:
-
setFormatID
public void setFormatID(byte[] formatID) Sets the section's format ID.
- Parameters:
formatID- The section's format ID as a byte array. It components are in big-endian format.- See Also:
-
setProperties
Sets this section's properties. Any former values are overwritten.
- Parameters:
properties- This section's new properties.
-
setProperty
Sets the string value of the property with the specified ID.
- Parameters:
id- The property's IDvalue- The property's value. It will be written as a Unicode string.- See Also:
-
setProperty
public void setProperty(int id, int value) Sets the int value of the property with the specified ID.
- Parameters:
id- The property's IDvalue- The property's value.- See Also:
-
setProperty
public void setProperty(int id, long value) Sets the long value of the property with the specified ID.
- Parameters:
id- The property's IDvalue- The property's value.- See Also:
-
setProperty
public void setProperty(int id, boolean value) Sets the boolean value of the property with the specified ID.
- Parameters:
id- The property's IDvalue- The property's value.- See Also:
-
setProperty
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.
- Parameters:
id- The property's ID.variantType- The property's variant type.value- The property's value.- See Also:
-
setProperty
Sets a property.
- Parameters:
p- The property to be set.- See Also:
-
removeProperty
public void removeProperty(long id) Removes a property.
- Parameters:
id- The ID of the property to be removed
-
setPropertyBooleanValue
protected void setPropertyBooleanValue(int id, boolean value) Sets the value of the boolean property with the specified ID.
- Parameters:
id- The property's IDvalue- The property's value- See Also:
-
getSize
public int getSize()Returns the section's size.
-
calcSize
Calculates the section's size. It is the sum of the lengths of the section's header (8), the properties list (16 times the number of properties) and the properties themselves.
- Returns:
- the section's length in bytes.
- Throws:
WritingNotSupportedExceptionIOException
-
write
Writes this section into an output stream.
Internally this is done by writing into three byte array output streams: one for the properties, one for the property list and one for the section as such. The two former are appended to the latter when they have received all their data.
- Parameters:
out- The stream to write into.- Returns:
- The number of bytes written, i.e. the section's size.
- Throws:
IOException- if an I/O error occursWritingNotSupportedException- if HPSF does not yet support writing a property's variant type.
-
writeDictionary
private static int writeDictionary(OutputStream out, Map<Long, String> dictionary, int codepage) throws IOExceptionWrites the section's dictionary.
- Parameters:
out- The output stream to write to.dictionary- The dictionary.codepage- The codepage to be used to write the dictionary items.- Returns:
- The number of bytes written
- Throws:
IOException- if an I/O exception occurs.
-
getPropertyCount
public int getPropertyCount()Overwrites the super class' method to cope with a redundancy: the property count is maintained in a separate member variable, but shouldn't.
- Overrides:
getPropertyCountin classSection- Returns:
- The number of properties in this section
-
getProperties
Gets this section's properties.
- Overrides:
getPropertiesin classSection- Returns:
- this section's properties.
-
getProperty
Gets a property.
- Overrides:
getPropertyin classSection- Parameters:
id- The ID of the property to get- Returns:
- The property or
nullif there is no such property
-
setDictionary
Sets the section's dictionary. All keys in the dictionary must be
Longinstances, all values must beStrings. This method overwrites the properties with IDs 0 and 1 since they are reserved for the dictionary and the dictionary's codepage. Setting these properties explicitly might have surprising effects. An application should never do this but always use this method.- Parameters:
dictionary- The dictionary- Throws:
IllegalPropertySetDataException- if the dictionary's key and value types are not correct.- See Also:
-
setProperty
Sets a property.
- Parameters:
id- The property ID.value- The property's value. The value's class must be one of those supported by HPSF.
-
clear
public void clear()Removes all properties from the section including 0 (dictionary) and 1 (codepage).
-
setCodepage
public void setCodepage(int codepage) Sets the codepage.
- Parameters:
codepage- the codepage
-