|
|
@@ -59,23 +59,19 @@ import org.apache.poi.util.LittleEndian; |
|
|
|
import org.apache.poi.hpsf.wellknown.*; |
|
|
|
|
|
|
|
/** |
|
|
|
* <p> |
|
|
|
* <p>Represents a section in a {@link PropertySet}.</p> |
|
|
|
* |
|
|
|
* Represents a section in a {@link PropertySet}.</p> |
|
|
|
* |
|
|
|
*@author Rainer Klute (klute@rainer-klute.de) |
|
|
|
*@author Drew Varner (Drew.Varner allUpIn sc.edu) |
|
|
|
*@created May 10, 2002 |
|
|
|
*@version $Id$ |
|
|
|
*@since 2002-02-09 |
|
|
|
* @author Rainer Klute (klute@rainer-klute.de) |
|
|
|
* @author Drew Varner (Drew.Varner allUpIn sc.edu) |
|
|
|
* @version $Id$ |
|
|
|
* @since 2002-02-09 |
|
|
|
*/ |
|
|
|
public class Section { |
|
|
|
public class Section |
|
|
|
{ |
|
|
|
|
|
|
|
/** |
|
|
|
* <p> |
|
|
|
* |
|
|
|
* Maps property IDs to section-private PID strings. These strings can be |
|
|
|
* found in the property with ID 0.</p> |
|
|
|
* <p>Maps property IDs to section-private PID strings. These |
|
|
|
* strings can be found in the property with ID 0.</p> |
|
|
|
*/ |
|
|
|
protected Map dictionary; |
|
|
|
|
|
|
@@ -83,13 +79,13 @@ public class Section { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* <p> |
|
|
|
* |
|
|
|
* Returns the format ID. The format ID is the "type" of the section.</p> |
|
|
|
* <p>Returns the format ID. The format ID is the "type" of the |
|
|
|
* section.</p> |
|
|
|
* |
|
|
|
*@return The formatID value |
|
|
|
* @return The format ID |
|
|
|
*/ |
|
|
|
public ClassID getFormatID() { |
|
|
|
public ClassID getFormatID() |
|
|
|
{ |
|
|
|
return formatID; |
|
|
|
} |
|
|
|
|
|
|
@@ -99,13 +95,12 @@ public class Section { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* <p> |
|
|
|
* <p>Returns the offset of the section in the stream.</p> |
|
|
|
* |
|
|
|
* Returns the offset of the section in the stream.</p> |
|
|
|
* |
|
|
|
*@return The offset value |
|
|
|
* @return The offset of the section in the stream. |
|
|
|
*/ |
|
|
|
public long getOffset() { |
|
|
|
public long getOffset() |
|
|
|
{ |
|
|
|
return offset; |
|
|
|
} |
|
|
|
|
|
|
@@ -115,13 +110,12 @@ public class Section { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* <p> |
|
|
|
* |
|
|
|
* Returns the section's size in bytes.</p> |
|
|
|
* <p>Returns the section's size in bytes.</p> |
|
|
|
* |
|
|
|
*@return The size value |
|
|
|
* @return The section's size in bytes. |
|
|
|
*/ |
|
|
|
public int getSize() { |
|
|
|
public int getSize() |
|
|
|
{ |
|
|
|
return size; |
|
|
|
} |
|
|
|
|
|
|
@@ -131,13 +125,12 @@ public class Section { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* <p> |
|
|
|
* <p>Returns the number of properties in this section.</p> |
|
|
|
* |
|
|
|
* Returns the number of properties in this section.</p> |
|
|
|
* |
|
|
|
*@return The propertyCount value |
|
|
|
* @return The number of properties in this section. |
|
|
|
*/ |
|
|
|
public int getPropertyCount() { |
|
|
|
public int getPropertyCount() |
|
|
|
{ |
|
|
|
return propertyCount; |
|
|
|
} |
|
|
|
|
|
|
@@ -147,28 +140,26 @@ public class Section { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* <p> |
|
|
|
* |
|
|
|
* Returns this section's properties.</p> |
|
|
|
* <p>Returns this section's properties.</p> |
|
|
|
* |
|
|
|
*@return The properties value |
|
|
|
* @return This section's properties. |
|
|
|
*/ |
|
|
|
public Property[] getProperties() { |
|
|
|
public Property[] getProperties() |
|
|
|
{ |
|
|
|
return properties; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* <p> |
|
|
|
* <p>Creates a {@link Section} instance from a byte array.</p> |
|
|
|
* |
|
|
|
* Creates a {@link Section} instance from a byte array.</p> |
|
|
|
* |
|
|
|
*@param src Contains the complete property set stream. |
|
|
|
*@param offset The position in the stream that points to the section's |
|
|
|
* format ID. |
|
|
|
* @param src Contains the complete property set stream. |
|
|
|
* @param offset The position in the stream that points to the |
|
|
|
* section's format ID. |
|
|
|
*/ |
|
|
|
public Section(final byte[] src, int offset) { |
|
|
|
public Section(final byte[] src, int offset) |
|
|
|
{ |
|
|
|
/* |
|
|
|
* Read the format ID. |
|
|
|
*/ |
|
|
@@ -217,7 +208,8 @@ public class Section { |
|
|
|
length = (int)(src.length - this.offset - sOffset); |
|
|
|
} else { |
|
|
|
length = (int) |
|
|
|
LittleEndian.getUInt(src, offset + LittleEndian.INT_SIZE) - sOffset; |
|
|
|
LittleEndian.getUInt(src, offset + LittleEndian.INT_SIZE) - |
|
|
|
sOffset; |
|
|
|
} |
|
|
|
|
|
|
|
/* |
|
|
@@ -236,22 +228,21 @@ public class Section { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* <p> |
|
|
|
* <p>Returns the value of the property with the specified ID. If |
|
|
|
* the property is not available, <code>null</code> is returned |
|
|
|
* and a subsequent call to {@link #wasNull} will return |
|
|
|
* <code>true</code>.</p> |
|
|
|
* |
|
|
|
* Returns the value of the property with the specified ID. If the property |
|
|
|
* is not available, <code>null</code> is returned and a subsequent call to |
|
|
|
* {@link #wasNull} will return <code>true</code>.</p> |
|
|
|
* @param id The property's ID |
|
|
|
* |
|
|
|
*@param id Description of the Parameter |
|
|
|
*@return The property value |
|
|
|
* @return The property's value |
|
|
|
*/ |
|
|
|
protected Object getProperty(final int id) { |
|
|
|
protected Object getProperty(final int id) |
|
|
|
{ |
|
|
|
wasNull = false; |
|
|
|
for (int i = 0; i < properties.length; i++) { |
|
|
|
if (id == properties[i].getID()) { |
|
|
|
for (int i = 0; i < properties.length; i++) |
|
|
|
if (id == properties[i].getID()) |
|
|
|
return properties[i].getValue(); |
|
|
|
} |
|
|
|
} |
|
|
|
wasNull = true; |
|
|
|
return null; |
|
|
|
} |
|
|
@@ -259,47 +250,48 @@ public class Section { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* <p> |
|
|
|
* <p>Returns 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</code> to let the caller distinguish that case from |
|
|
|
* a real property value of 0.</p> |
|
|
|
* |
|
|
|
* Returns 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</code> to let the caller distinguish |
|
|
|
* that case from a real property value of 0.</p> |
|
|
|
* @param id The property's ID |
|
|
|
* |
|
|
|
*@param id Description of the Parameter |
|
|
|
*@return The propertyIntValue value |
|
|
|
* @return The property's value |
|
|
|
*/ |
|
|
|
protected int getPropertyIntValue(final int id) { |
|
|
|
final Integer i = (Integer) getProperty(id); |
|
|
|
if (i != null) { |
|
|
|
protected int getPropertyIntValue(final int id) |
|
|
|
{ |
|
|
|
/* FIXME: Find out why the following is a Long instead of an |
|
|
|
* Integer! */ |
|
|
|
final Long i = (Long) getProperty(id); |
|
|
|
if (i != null) |
|
|
|
return i.intValue(); |
|
|
|
} else { |
|
|
|
else |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* <p> |
|
|
|
* <p>Returns the value of the boolean property with the specified |
|
|
|
* ID. If the property is not available, <code>false</code> is |
|
|
|
* returned. A subsequent call to {@link #wasNull} will return |
|
|
|
* <code>true</code> to let the caller distinguish that case from |
|
|
|
* a real property value of <code>false</code>.</p> |
|
|
|
* |
|
|
|
* Returns the value of the boolean property with the specified ID. If the |
|
|
|
* property is not available, <code>false</code> is returned. A subsequent |
|
|
|
* call to {@link #wasNull} will return <code>true</code> to let the caller |
|
|
|
* distinguish that case from a real property value of <code>false</code>. |
|
|
|
* </p> |
|
|
|
* @param id The property's ID |
|
|
|
* |
|
|
|
*@param id Description of the Parameter |
|
|
|
*@return The propertyBooleanValue value |
|
|
|
* @return The property's value |
|
|
|
*/ |
|
|
|
protected boolean getPropertyBooleanValue(final int id) { |
|
|
|
protected boolean getPropertyBooleanValue(final int id) |
|
|
|
{ |
|
|
|
final Boolean b = (Boolean) getProperty(id); |
|
|
|
if (b != null) { |
|
|
|
if (b != null) |
|
|
|
return b.booleanValue(); |
|
|
|
} else { |
|
|
|
else |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -307,46 +299,44 @@ public class Section { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* <p> |
|
|
|
* <p>Checks whether the property which the last call to {@link |
|
|
|
* #getPropertyIntValue} or {@link #getProperty} tried to access |
|
|
|
* was available or not. This information might be important for |
|
|
|
* callers of {@link #getPropertyIntValue} since the latter |
|
|
|
* returns 0 if the property does not exist. Using {@link |
|
|
|
* #wasNull} the caller can distiguish this case from a property's |
|
|
|
* real value of 0.</p> |
|
|
|
* |
|
|
|
* Checks whether the property which the last call to {@link |
|
|
|
* #getPropertyIntValue} or {@link #getProperty} tried to access was |
|
|
|
* available or not. This information might be important for callers of |
|
|
|
* {@link #getPropertyIntValue} since the latter returns 0 if the property |
|
|
|
* does not exist. Using {@link #wasNull} the caller can distiguish this |
|
|
|
* case from a property's real value of 0.</p> |
|
|
|
* |
|
|
|
*@return <code>true</code> if the last call to {@link |
|
|
|
* #getPropertyIntValue} or {@link #getProperty} tried to access a |
|
|
|
* property that was not available, else <code>false</code>. |
|
|
|
* @return <code>true</code> if the last call to {@link |
|
|
|
* #getPropertyIntValue} or {@link #getProperty} tried to access a |
|
|
|
* property that was not available, else <code>false</code>. |
|
|
|
*/ |
|
|
|
public boolean wasNull() { |
|
|
|
public boolean wasNull() |
|
|
|
{ |
|
|
|
return wasNull; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* <p> |
|
|
|
* <p>Returns the PID string associated with a property ID. The ID |
|
|
|
* is first looked up in the {@link Section}'s private |
|
|
|
* dictionary. If it is not found there, the method calls {@link |
|
|
|
* SectionIDMap#getPIDString}.</p> |
|
|
|
* |
|
|
|
* Returns the PID string associated with a property ID. The ID is first |
|
|
|
* looked up in the {@link Section}'s private dictionary. If it is not |
|
|
|
* found there, the method calls {@link SectionIDMap#getPIDString}.</p> |
|
|
|
* @param pid The property ID |
|
|
|
* |
|
|
|
*@param pid Description of the Parameter |
|
|
|
*@return The pIDString value |
|
|
|
* @return The property ID's string value |
|
|
|
*/ |
|
|
|
public String getPIDString(final int pid) { |
|
|
|
public String getPIDString(final int pid) |
|
|
|
{ |
|
|
|
String s = null; |
|
|
|
if (dictionary != null) { |
|
|
|
if (dictionary != null) |
|
|
|
s = (String) dictionary.get(new Integer(pid)); |
|
|
|
} |
|
|
|
if (s == null) { |
|
|
|
if (s == null) |
|
|
|
s = SectionIDMap.getPIDString(getFormatID().getBytes(), pid); |
|
|
|
} |
|
|
|
if (s == null) { |
|
|
|
if (s == null) |
|
|
|
s = SectionIDMap.UNDEFINED; |
|
|
|
} |
|
|
|
return s; |
|
|
|
} |
|
|
|
|