From 9ccba56e8e93dd2c07df5ef01ac22e22f7de1940 Mon Sep 17 00:00:00 2001 From: Rainer Klute Date: Sat, 22 Feb 2003 14:27:16 +0000 Subject: [PATCH] First preparations for HPSF writing functionality. git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353013 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/poi/hpsf/ClassID.java | 52 ++++++++++++++++++- .../poi/hpsf/DocumentSummaryInformation.java | 9 ++++ src/java/org/apache/poi/hpsf/PropertySet.java | 44 +++++++++++----- src/java/org/apache/poi/hpsf/Section.java | 18 +++++-- .../apache/poi/hpsf/SpecialPropertySet.java | 14 +++++ .../apache/poi/hpsf/SummaryInformation.java | 8 +++ 6 files changed, 124 insertions(+), 21 deletions(-) diff --git a/src/java/org/apache/poi/hpsf/ClassID.java b/src/java/org/apache/poi/hpsf/ClassID.java index 37cc49058..6d5676703 100644 --- a/src/java/org/apache/poi/hpsf/ClassID.java +++ b/src/java/org/apache/poi/hpsf/ClassID.java @@ -92,6 +92,18 @@ public class ClassID } + /** + *

Creates a {@link ClassID} and initializes its value with + * 0x00 bytes.

+ */ + public ClassID() + { + bytes = new byte[LENGTH]; + for (int i = 0; i < LENGTH; i++) + bytes[i] = 0x00; + } + + public final static int LENGTH = 16; @@ -114,8 +126,8 @@ public class ClassID /** - *

Reads a class ID from a byte array by turning little-endian - * into big-endian.

+ *

Reads the class ID's value from a byte array by turning + * little-endian into big-endian.

* * @param src The byte array to read from * @@ -148,4 +160,40 @@ public class ClassID return bytes; } + + + /** + *

Writes the class ID to a byte array in the + * little-endian.

+ * + * @param dst The byte array to write to. + * + * @param offset The offset within the dst byte array. + * + * @throws ArrayIndexOutOfBoundsException if there is not enough + * room for the class ID in the byte array. There must be at least + * 16 bytes in the byte array after the offset + * position. + */ + public void write(final byte[] dst, final int offset) + { + /* Write double word. */ + dst[0 + offset] = bytes[3]; + dst[1 + offset] = bytes[2]; + dst[2 + offset] = bytes[1]; + dst[3 + offset] = bytes[0]; + + /* Write first word. */ + dst[4 + offset] = bytes[5]; + dst[5 + offset] = bytes[4]; + + /* Write second word. */ + dst[6 + offset] = bytes[7]; + dst[7 + offset] = bytes[6]; + + /* Write 8 bytes. */ + for (int i = 8; i < 16; i++) + dst[i + offset] = bytes[i]; + } + } diff --git a/src/java/org/apache/poi/hpsf/DocumentSummaryInformation.java b/src/java/org/apache/poi/hpsf/DocumentSummaryInformation.java index aa5a84478..92005867a 100644 --- a/src/java/org/apache/poi/hpsf/DocumentSummaryInformation.java +++ b/src/java/org/apache/poi/hpsf/DocumentSummaryInformation.java @@ -71,6 +71,15 @@ import org.apache.poi.hpsf.wellknown.*; public class DocumentSummaryInformation extends SpecialPropertySet { + /** + *

The document name a document summary information stream + * usually has in a POIFS filesystem.

+ */ + public static final String DEFAULT_STREAM_NAME = + "\005DocumentSummaryInformation"; + + + /** *

Creates a {@link DocumentSummaryInformation} from a given * {@link PropertySet}.

diff --git a/src/java/org/apache/poi/hpsf/PropertySet.java b/src/java/org/apache/poi/hpsf/PropertySet.java index f98384206..17eda580a 100644 --- a/src/java/org/apache/poi/hpsf/PropertySet.java +++ b/src/java/org/apache/poi/hpsf/PropertySet.java @@ -102,17 +102,11 @@ public class PropertySet final static byte[] BYTE_ORDER_ASSERTION = new byte[]{(byte) 0xFE, (byte) 0xFF}; - /** - *

The "format" field must equal this value.

- */ - final static byte[] FORMAT_ASSERTION = - new byte[]{(byte) 0x00, (byte) 0x00}; - /** *

Specifies this {@link PropertySet}'s byte order. See the * HPFS documentation for details!

*/ - private int byteOrder; + protected int byteOrder; /** *

Returns the property set stream's low-level "byte order" @@ -127,11 +121,17 @@ public class PropertySet + /** + *

The "format" field must equal this value.

+ */ + final static byte[] FORMAT_ASSERTION = + new byte[]{(byte) 0x00, (byte) 0x00}; + /** *

Specifies this {@link PropertySet}'s format. See the HPFS * documentation for details!

*/ - private int format; + protected int format; /** *

Returns the property set stream's low-level "format" @@ -151,12 +151,21 @@ public class PropertySet * this {@link PropertySet}. See the HPFS documentation for * details!

*/ - private long osVersion; + protected int osVersion; + + + public final static int OS_WIN16 = 0x0000; + public final static int OS_MACINTOSH = 0x0001; + public final static int OS_WIN32 = 0x0002; /** *

Returns the property set stream's low-level "OS version" * field.

* + *

FIXME: Return an int instead + * of a long in the next major version, i.e. when + * incompatible changes are allowed.

+ * * @return The property set stream's low-level "OS version" field. */ public long getOSVersion() @@ -170,7 +179,7 @@ public class PropertySet *

Specifies this {@link PropertySet}'s "classID" field. See * the HPFS documentation for details!

*/ - private ClassID classID; + protected ClassID classID; /** *

Returns the property set stream's low-level "class ID" @@ -188,13 +197,17 @@ public class PropertySet /** *

The number of sections in this {@link PropertySet}.

*/ - private long sectionCount; + protected int sectionCount; /** *

Returns the number of {@link Section}s in the property * set.

* + *

FIXME: Return an int instead + * of a long in the next major version, i.e. when + * incompatible changes are allowed.

+ * * @return The number of {@link Section}s in the property set. */ public long getSectionCount() @@ -207,7 +220,7 @@ public class PropertySet /** *

The sections in this {@link PropertySet}.

*/ - private List sections; + protected List sections; /** @@ -420,12 +433,15 @@ public class PropertySet offset += LittleEndian.SHORT_SIZE; format = LittleEndian.getUShort(src, offset); offset += LittleEndian.SHORT_SIZE; - osVersion = LittleEndian.getUInt(src, offset); + osVersion = (int) LittleEndian.getUInt(src, offset); offset += LittleEndian.INT_SIZE; classID = new ClassID(src, offset); offset += ClassID.LENGTH; - sectionCount = LittleEndian.getUInt(src, offset); + sectionCount = LittleEndian.getInt(src, offset); offset += LittleEndian.INT_SIZE; + if (sectionCount <= 0) + throw new HPSFRuntimeException("Section count " + sectionCount + + " must be greater than 0."); /* * Read the sections, which are following the header. They diff --git a/src/java/org/apache/poi/hpsf/Section.java b/src/java/org/apache/poi/hpsf/Section.java index ccfee2799..ac75accda 100644 --- a/src/java/org/apache/poi/hpsf/Section.java +++ b/src/java/org/apache/poi/hpsf/Section.java @@ -75,7 +75,7 @@ public class Section */ protected Map dictionary; - private ClassID formatID; + protected ClassID formatID; /** @@ -95,7 +95,7 @@ public class Section - private long offset; + protected long offset; /** @@ -110,7 +110,7 @@ public class Section - private int size; + protected int size; /** @@ -125,7 +125,7 @@ public class Section - private int propertyCount; + protected int propertyCount; /** @@ -140,7 +140,7 @@ public class Section - private Property[] properties; + protected Property[] properties; /** @@ -155,6 +155,14 @@ public class Section + /** + *

Creates an empty and uninitialized {@link Section}. + */ + protected Section() + {} + + + /** *

Creates a {@link Section} instance from a byte array.

* diff --git a/src/java/org/apache/poi/hpsf/SpecialPropertySet.java b/src/java/org/apache/poi/hpsf/SpecialPropertySet.java index f9cddd819..286180e9d 100644 --- a/src/java/org/apache/poi/hpsf/SpecialPropertySet.java +++ b/src/java/org/apache/poi/hpsf/SpecialPropertySet.java @@ -115,6 +115,13 @@ public abstract class SpecialPropertySet extends PropertySet + /* + * This is intentionally no javadoc comment. + * + * FIXME: Return an int instead of a + * long in the next major version, i.e. when + * incompatible changes are allowed. + */ public long getOSVersion() { return delegate.getOSVersion(); @@ -129,6 +136,13 @@ public abstract class SpecialPropertySet extends PropertySet + /* + * This is intentionally no javadoc comment. + * + * FIXME: Return an int instead of a + * long in the next major version, i.e. when + * incompatible changes are allowed. + */ public long getSectionCount() { return delegate.getSectionCount(); diff --git a/src/java/org/apache/poi/hpsf/SummaryInformation.java b/src/java/org/apache/poi/hpsf/SummaryInformation.java index 1fc4ef168..c9a5e8ebb 100644 --- a/src/java/org/apache/poi/hpsf/SummaryInformation.java +++ b/src/java/org/apache/poi/hpsf/SummaryInformation.java @@ -78,6 +78,14 @@ import org.apache.poi.hpsf.wellknown.*; public class SummaryInformation extends SpecialPropertySet { + /** + *

The document name a summary information stream usually has + * in a POIFS filesystem.

+ */ + public static final String DEFAULT_STREAM_NAME = "\005SummaryInformation"; + + + /** *

Creates a {@link SummaryInformation} from a given {@link * PropertySet}.