aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/contrib/src/org/apache/poi/contrib/poibrowser/Codec.java225
-rw-r--r--src/contrib/src/org/apache/poi/contrib/poibrowser/DocumentDescriptor.java121
-rw-r--r--src/contrib/src/org/apache/poi/contrib/poibrowser/DocumentDescriptorRenderer.java120
-rw-r--r--src/contrib/src/org/apache/poi/contrib/poibrowser/ExtendableTreeCellRenderer.java187
-rw-r--r--src/contrib/src/org/apache/poi/contrib/poibrowser/POIBrowser.java156
-rw-r--r--src/contrib/src/org/apache/poi/contrib/poibrowser/PropertySetDescriptor.java113
-rw-r--r--src/contrib/src/org/apache/poi/contrib/poibrowser/PropertySetDescriptorRenderer.java193
-rw-r--r--src/contrib/src/org/apache/poi/contrib/poibrowser/TreeReaderListener.java277
-rw-r--r--src/contrib/src/org/apache/poi/contrib/poibrowser/Util.java89
-rw-r--r--src/contrib/src/org/apache/poi/contrib/poibrowser/package.html62
-rw-r--r--src/java/org/apache/poi/hpsf/DocumentSummaryInformation.java271
-rw-r--r--src/java/org/apache/poi/hpsf/HPSFException.java131
-rw-r--r--src/java/org/apache/poi/hpsf/HPSFRuntimeException.java131
-rw-r--r--src/java/org/apache/poi/hpsf/MarkUnsupportedException.java92
-rw-r--r--src/java/org/apache/poi/hpsf/NoPropertySetStreamException.java97
-rw-r--r--src/java/org/apache/poi/hpsf/NoSingleSectionException.java97
-rw-r--r--src/java/org/apache/poi/hpsf/Property.java274
-rw-r--r--src/java/org/apache/poi/hpsf/PropertySet.java528
-rw-r--r--src/java/org/apache/poi/hpsf/PropertySetFactory.java97
-rw-r--r--src/java/org/apache/poi/hpsf/Section.java278
-rw-r--r--src/java/org/apache/poi/hpsf/SpecialPropertySet.java169
-rw-r--r--src/java/org/apache/poi/hpsf/SummaryInformation.java290
-rw-r--r--src/java/org/apache/poi/hpsf/UnexpectedPropertySetTypeException.java97
-rw-r--r--src/java/org/apache/poi/hpsf/Util.java188
-rw-r--r--src/java/org/apache/poi/hpsf/Variant.java341
-rw-r--r--src/java/org/apache/poi/hpsf/littleendian/Byte.java93
-rw-r--r--src/java/org/apache/poi/hpsf/littleendian/ClassID.java130
-rw-r--r--src/java/org/apache/poi/hpsf/littleendian/DWord.java113
-rw-r--r--src/java/org/apache/poi/hpsf/littleendian/LittleEndian.java134
-rw-r--r--src/java/org/apache/poi/hpsf/littleendian/Word.java92
-rw-r--r--src/java/org/apache/poi/hpsf/littleendian/package.html43
-rw-r--r--src/java/org/apache/poi/hpsf/package.html133
-rw-r--r--src/java/org/apache/poi/hpsf/wellknown/PropertyIDMap.java234
-rw-r--r--src/java/org/apache/poi/hpsf/wellknown/SectionIDMap.java213
-rw-r--r--src/java/org/apache/poi/hpsf/wellknown/package.html44
35 files changed, 5853 insertions, 0 deletions
diff --git a/src/contrib/src/org/apache/poi/contrib/poibrowser/Codec.java b/src/contrib/src/org/apache/poi/contrib/poibrowser/Codec.java
new file mode 100644
index 0000000000..637eed256f
--- /dev/null
+++ b/src/contrib/src/org/apache/poi/contrib/poibrowser/Codec.java
@@ -0,0 +1,225 @@
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2000 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" must
+ * not be used to endorse or promote products derived from this
+ * software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * nor may "Apache" appear in their name, without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ * Portions of this software are based upon public domain software
+ * originally written at the National Center for Supercomputing Applications,
+ * University of Illinois, Urbana-Champaign.
+ */
+
+package org.apache.poi.contrib.poibrowser;
+
+import java.io.*;
+import java.util.*;
+
+
+
+/**
+ * <p>Provides utility methods for encoding and decoding hexadecimal
+ * data.</p>
+ *
+ * @author Rainer Klute (klute@rainer-klute.de) - with portions from Tomcat
+ * @version $Id$
+ * @since 2002-01-24
+ */
+public class Codec
+{
+
+ /**
+ * <p>The nibbles' hexadecimal values. A nibble is a half byte.</p>
+ */
+ protected static final byte hexval[] =
+ {(byte) '0', (byte) '1', (byte) '2', (byte) '3',
+ (byte) '4', (byte) '5', (byte) '6', (byte) '7',
+ (byte) '8', (byte) '9', (byte) 'A', (byte) 'B',
+ (byte) 'C', (byte) 'D', (byte) 'E', (byte) 'F'};
+
+
+
+ /**
+ * <p>Converts a string into its hexadecimal notation.</p>
+ *
+ * <p><strong>FIXME:</strong> If this method is called frequently,
+ * it should directly implement the algorithm in the called method
+ * in order to avoid creating a string instance.</p>
+ */
+ public static String hexEncode(final String s)
+ {
+ return hexEncode(s.getBytes());
+ }
+
+
+
+ /**
+ * <p>Converts a byte array into its hexadecimal notation.</p>
+ */
+ public static String hexEncode(final byte[] s)
+ {
+ return hexEncode(s, 0, s.length);
+ }
+
+
+
+ /**
+ * <p>Converts a part of a byte array into its hexadecimal
+ * notation.</p>
+ */
+ public static String hexEncode(final byte[] s, final int offset,
+ final int length)
+ {
+ StringBuffer b = new StringBuffer(length * 2);
+ for (int i = offset; i < offset + length; i++)
+ {
+ int c = s[i];
+ b.append((char) hexval[(c & 0xF0) >> 4]);
+ b.append((char) hexval[(c & 0x0F) >> 0]);
+ }
+ return b.toString();
+ }
+
+
+
+ /**
+ * <p>Converts a single byte into its hexadecimal notation.</p>
+ */
+ public static String hexEncode(final byte b)
+ {
+ StringBuffer sb = new StringBuffer(2);
+ sb.append((char) hexval[(b & 0xF0) >> 4]);
+ sb.append((char) hexval[(b & 0x0F) >> 0]);
+ return sb.toString();
+ }
+
+
+
+ /**
+ * <p>Decodes the hexadecimal representation of a sequence of
+ * bytes into a byte array. Each character in the string
+ * represents a nibble (half byte) and must be one of the
+ * characters '0'-'9', 'A'-'F' or 'a'-'f'.</p>
+ *
+ * @param s The string to be decoded
+ *
+ * @return The bytes
+ *
+ * @throw IllegalArgumentException if the string does not contain
+ * a valid representation of a byte sequence.
+ */
+ public static byte[] hexDecode(final String s)
+ {
+ final int length = s.length();
+
+ /* The string to be converted must have an even number of
+ characters. */
+ if (length % 2 == 1)
+ throw new IllegalArgumentException
+ ("String has odd length " + length);
+ byte[] b = new byte[length / 2];
+ char[] c = new char[length];
+ s.toUpperCase().getChars(0, length, c, 0);
+ for (int i = 0; i < length; i += 2)
+ b[i/2] = (byte) (decodeNibble(c[i]) << 4 & 0xF0 |
+ decodeNibble(c[i+1]) & 0x0F);
+ return b;
+ }
+
+
+
+ /**
+ * <p>Decodes a nibble.</p>
+ *
+ * @param c A character in the range '0'-'9' or 'A'-'F'. Lower
+ * case is not supported here.
+ *
+ * @return The decoded nibble in the range 0-15
+ *
+ * @throws IllegalArgumentException if <em>c</em> is not a
+ * permitted character
+ */
+ protected static byte decodeNibble(final char c)
+ {
+ for (byte i = 0; i < hexval.length; i++)
+ if ((byte) c == hexval[i])
+ return i;
+ throw new IllegalArgumentException("\"" + c + "\"" +
+ " does not represent a nibble.");
+ }
+
+
+
+ /**
+ * <p>For testing.</p>
+ */
+ public static void main(final String args[])
+ throws IOException
+ {
+ final BufferedReader in =
+ new BufferedReader(new InputStreamReader(System.in));
+ String s;
+ do
+ {
+ s = in.readLine();
+ if (s != null)
+ {
+ String bytes = hexEncode(s);
+ System.out.print("Hex encoded (String): ");
+ System.out.println(bytes);
+ System.out.print("Hex encoded (byte[]): ");
+ System.out.println(hexEncode(s.getBytes()));
+ System.out.print("Re-decoded (byte[]): ");
+ System.out.println(new String(hexDecode(bytes)));
+ }
+ }
+ while (s != null);
+ }
+
+}
diff --git a/src/contrib/src/org/apache/poi/contrib/poibrowser/DocumentDescriptor.java b/src/contrib/src/org/apache/poi/contrib/poibrowser/DocumentDescriptor.java
new file mode 100644
index 0000000000..6054d39c99
--- /dev/null
+++ b/src/contrib/src/org/apache/poi/contrib/poibrowser/DocumentDescriptor.java
@@ -0,0 +1,121 @@
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2000 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" must
+ * not be used to endorse or promote products derived from this
+ * software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * nor may "Apache" appear in their name, without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ * Portions of this software are based upon public domain software
+ * originally written at the National Center for Supercomputing Applications,
+ * University of Illinois, Urbana-Champaign.
+ */
+
+package org.apache.poi.contrib.poibrowser;
+
+import java.io.*;
+import org.apache.poi.poifs.filesystem.*;
+
+/**
+ * <p>Describes the most important (whatever that is) features of a
+ * {@link POIFSDocument}.</p>
+ *
+ * @author Rainer Klute (klute@rainer-klute.de)
+ * @version $Id$
+ * @since 2002-02-05
+ */
+public class DocumentDescriptor
+{
+ String name;
+ POIFSDocumentPath path;
+ DocumentInputStream stream;
+
+ int size;
+ byte[] bytes;
+
+
+ /**
+ * <p>Creates a {@link DocumentDescriptor}.</p>
+ *
+ * @param name The stream's name.
+ *
+ * @param path The stream's path in the POI filesystem hierarchy.
+ *
+ * @param stream The stream.
+ *
+ * @param nrOfBytes The maximum number of bytes to display in a
+ * dump starting at the beginning of the stream.
+ */
+ public DocumentDescriptor(final String name,
+ final POIFSDocumentPath path,
+ final DocumentInputStream stream,
+ final int nrOfBytes)
+ {
+ this.name = name;
+ this.path = path;
+ this.stream = stream;
+ try
+ {
+ size = stream.available();
+ if (stream.markSupported())
+ {
+ stream.mark(nrOfBytes);
+ final byte[] b = new byte[nrOfBytes];
+ final int read = stream.read(b, 0, Math.min(size, b.length));
+ bytes = new byte[read];
+ System.arraycopy(b, 0, bytes, 0, read);
+ stream.reset();
+ }
+ }
+ catch (IOException ex)
+ {
+ System.out.println(ex);
+ }
+ }
+
+}
diff --git a/src/contrib/src/org/apache/poi/contrib/poibrowser/DocumentDescriptorRenderer.java b/src/contrib/src/org/apache/poi/contrib/poibrowser/DocumentDescriptorRenderer.java
new file mode 100644
index 0000000000..bca744e6b2
--- /dev/null
+++ b/src/contrib/src/org/apache/poi/contrib/poibrowser/DocumentDescriptorRenderer.java
@@ -0,0 +1,120 @@
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2000 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" must
+ * not be used to endorse or promote products derived from this
+ * software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * nor may "Apache" appear in their name, without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ * Portions of this software are based upon public domain software
+ * originally written at the National Center for Supercomputing Applications,
+ * University of Illinois, Urbana-Champaign.
+ */
+
+package org.apache.poi.contrib.poibrowser;
+
+import java.awt.*;
+import javax.swing.*;
+import javax.swing.tree.*;
+
+/**
+ * <p>{@link TreeCellRenderer} for a {@link DocumentDescriptor}. The
+ * renderer is extremly rudimentary since displays only the document's
+ * name, its size and its fist few bytes.</p>
+ *
+ * @author Rainer Klute (klute@rainer-klute.de)
+ * @version $Id$
+ * @since 2002-02-05
+ */
+public class DocumentDescriptorRenderer extends DefaultTreeCellRenderer
+{
+
+ public Component getTreeCellRendererComponent(final JTree tree,
+ final Object value,
+ final boolean selected,
+ final boolean expanded,
+ final boolean leaf,
+ final int row,
+ final boolean hasFocus)
+ {
+ final DocumentDescriptor d = (DocumentDescriptor)
+ ((DefaultMutableTreeNode) value).getUserObject();
+ final JPanel p = new JPanel();
+ final JTextArea text = new JTextArea();
+ text.append(renderAsString(d));
+ text.setFont(new Font("Monospaced", Font.PLAIN, 10));
+ p.add(text);
+ if (selected)
+ Util.invert(text);
+ return p;
+ }
+
+
+ /**
+ * <p>Renders {@link DocumentDescriptor} as a string.</p>
+ */
+ protected String renderAsString(final DocumentDescriptor d)
+ {
+ final StringBuffer b = new StringBuffer();
+ b.append("Name: ");
+ b.append(d.name);
+ b.append(" (");
+ b.append(Codec.hexEncode(d.name));
+ b.append(") \n");
+
+ b.append("Size: ");
+ b.append(d.size);
+ b.append(" bytes\n");
+
+ b.append("First bytes: ");
+ b.append(Codec.hexEncode(d.bytes));
+
+ return b.toString();
+ }
+
+}
diff --git a/src/contrib/src/org/apache/poi/contrib/poibrowser/ExtendableTreeCellRenderer.java b/src/contrib/src/org/apache/poi/contrib/poibrowser/ExtendableTreeCellRenderer.java
new file mode 100644
index 0000000000..7c6a332db0
--- /dev/null
+++ b/src/contrib/src/org/apache/poi/contrib/poibrowser/ExtendableTreeCellRenderer.java
@@ -0,0 +1,187 @@
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2000 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" must
+ * not be used to endorse or promote products derived from this
+ * software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * nor may "Apache" appear in their name, without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ * Portions of this software are based upon public domain software
+ * originally written at the National Center for Supercomputing Applications,
+ * University of Illinois, Urbana-Champaign.
+ */
+
+package org.apache.poi.contrib.poibrowser;
+
+import java.awt.*;
+import javax.swing.*;
+import javax.swing.tree.*;
+import java.util.*;
+
+/**
+ * <p>This is a {@link TreeCellRenderer} implementation which is able
+ * to render arbitrary objects. The {@link ExtendableTreeCellRenderer}
+ * does not do the rendering itself but instead dispatches to
+ * class-specific renderers. A class/renderer pair must be registered
+ * using the {@link #register} method. If a class has no registered
+ * renderer, the renderer of its closest superclass is used. Since the
+ * {@link ExtendableTreeCellRenderer} always has a default renderer
+ * for the {@link Object} class, rendering is always possible. The
+ * default {@link Object} renderer can be replaced by another renderer
+ * but it cannot be unregistered.</p>
+ *
+ * @author Rainer Klute (klute@rainer-klute.de)
+ * @version $Id$
+ * @since 2002-01-22
+ */
+public class ExtendableTreeCellRenderer implements TreeCellRenderer
+{
+
+ /**
+ * <p>Maps classes to renderers.</p>
+ */
+ protected Map renderers;
+
+
+
+ public ExtendableTreeCellRenderer()
+ {
+ renderers = new HashMap();
+ register(Object.class, new DefaultTreeCellRenderer()
+ {
+ public Component getTreeCellRendererComponent
+ (JTree tree, Object value, boolean selected,
+ boolean expanded, boolean leaf, int row, boolean hasFocus)
+ {
+ final String s = value.toString();
+ final JLabel l = new JLabel(s + " ");
+ if (selected)
+ {
+ Util.invert(l);
+ l.setOpaque(true);
+ }
+ return l;
+ }
+ });
+ }
+
+
+
+ /**
+ * <p>Registers a renderer for a class.</p>
+ **/
+ public void register(final Class c, final TreeCellRenderer renderer)
+ {
+ renderers.put(c, renderer);
+ }
+
+
+
+ /**
+ * <p>Unregisters a renderer for a class. The renderer for the
+ * {@link Object} class cannot be unregistered.</p>
+ */
+ public void unregister(final Class c)
+ {
+ if (c == Object.class)
+ throw new IllegalArgumentException
+ ("Renderer for Object cannot be unregistered.");
+ renderers.put(c, null);
+ }
+
+
+
+ /**
+ * <p>Renders an object in a tree cell depending of the object's
+ * class.</p>
+ *
+ * @see TreeCellRenderer#getTreeCellRendererComponent
+ */
+ public Component getTreeCellRendererComponent
+ (final JTree tree, final Object value, final boolean selected,
+ final boolean expanded, final boolean leaf, final int row,
+ final boolean hasFocus)
+ {
+ final String NULL = "null";
+ TreeCellRenderer r;
+ Object userObject;
+ if (value == null)
+ userObject = NULL;
+ else
+ {
+ userObject = ((DefaultMutableTreeNode) value).getUserObject();
+ if (userObject == null)
+ userObject = NULL;
+ }
+ r = findRenderer(userObject.getClass());
+ return r.getTreeCellRendererComponent
+ (tree, value, selected, expanded, leaf, row,
+ hasFocus);
+ }
+
+
+
+ /**
+ * <p>Find the renderer for the specified class.</p>
+ */
+ protected TreeCellRenderer findRenderer(final Class c)
+ {
+ final TreeCellRenderer r = (TreeCellRenderer) renderers.get(c);
+ if (r != null)
+ /* The class has a renderer. */
+ return r;
+
+ /* The class has no renderer, try the superclass, if any. */
+ final Class superclass = c.getSuperclass();
+ if (superclass != null)
+ return findRenderer(superclass);
+ else
+ return null;
+ }
+
+}
diff --git a/src/contrib/src/org/apache/poi/contrib/poibrowser/POIBrowser.java b/src/contrib/src/org/apache/poi/contrib/poibrowser/POIBrowser.java
new file mode 100644
index 0000000000..5e78703923
--- /dev/null
+++ b/src/contrib/src/org/apache/poi/contrib/poibrowser/POIBrowser.java
@@ -0,0 +1,156 @@
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2000 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" must
+ * not be used to endorse or promote products derived from this
+ * software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * nor may "Apache" appear in their name, without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ * Portions of this software are based upon public domain software
+ * originally written at the National Center for Supercomputing Applications,
+ * University of Illinois, Urbana-Champaign.
+ */
+
+package org.apache.poi.contrib.poibrowser;
+
+import java.awt.event.*;
+import java.io.*;
+import javax.swing.*;
+import javax.swing.tree.*;
+import org.apache.poi.poifs.eventfilesystem.*;
+
+/**
+ * <p>The main class of the POI Browser. It shows the structure of POI
+ * filesystems (Microsoft Office documents) in a {@link
+ * JTree}. Specify their filenames on the command line!</p>
+ *
+ * @see POIFSReader
+ *
+ * @author Rainer Klute (klute@rainer-klute.de)
+ * @version $Id$
+ * @since 2002-01-19
+ */
+public class POIBrowser extends JFrame
+{
+
+ /**
+ * <p>The tree's root node must be visible to all methods.</p>
+ */
+ protected MutableTreeNode rootNode;
+
+
+
+ /**
+ * <p>Takes a bunch of file names as command line parameters,
+ * opens each of them as a POI filesystem and displays their
+ * internal structures in a {@link JTree}.</p>
+ */
+ public static void main(String[] args)
+ {
+ new POIBrowser().run(args);
+ }
+
+
+
+ protected void run(String[] args)
+ {
+ addWindowListener(new WindowAdapter()
+ {
+ public void windowClosing(WindowEvent e)
+ {
+ System.exit(0);
+ }
+ });
+
+ /* Create the tree model with a root node. The latter is
+ * invisible but it must be present because a tree model
+ * always needs a root. */
+ rootNode = new DefaultMutableTreeNode();
+ DefaultTreeModel treeModel = new DefaultTreeModel(rootNode);
+
+ /* Create the tree UI element. */
+ final JTree treeUI = new JTree(treeModel);
+ getContentPane().add(new JScrollPane(treeUI));
+
+ /* Add the POI filesystems to the tree. */
+ for (int i = 0; i < args.length; i++)
+ {
+ final String filename = args[i];
+ try
+ {
+ POIFSReader r = new POIFSReader();
+ r.registerListener(new TreeReaderListener(filename, rootNode));
+ r.read(new FileInputStream(filename));
+ }
+ catch (IOException ex)
+ {
+ System.err.println(filename + ": " + ex);
+ }
+ catch (Throwable t)
+ {
+ System.err.println("Unexpected exception while reading \"" +
+ filename + "\":");
+ t.printStackTrace(System.err);
+ }
+ }
+
+ /* Make the tree UI element visible. */
+ treeUI.setRootVisible(false);
+ treeUI.setShowsRootHandles(true);
+ ExtendableTreeCellRenderer etcr = new ExtendableTreeCellRenderer();
+ etcr.register(DocumentDescriptor.class,
+ new DocumentDescriptorRenderer());
+ etcr.register(PropertySetDescriptor.class,
+ new PropertySetDescriptorRenderer());
+ treeUI.setCellRenderer(etcr);
+ setSize(600, 450);
+ setTitle("POI Browser 0.10");
+ setVisible(true);
+ }
+
+}
diff --git a/src/contrib/src/org/apache/poi/contrib/poibrowser/PropertySetDescriptor.java b/src/contrib/src/org/apache/poi/contrib/poibrowser/PropertySetDescriptor.java
new file mode 100644
index 0000000000..2d38d4717c
--- /dev/null
+++ b/src/contrib/src/org/apache/poi/contrib/poibrowser/PropertySetDescriptor.java
@@ -0,0 +1,113 @@
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2000 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" must
+ * not be used to endorse or promote products derived from this
+ * software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * nor may "Apache" appear in their name, without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ * Portions of this software are based upon public domain software
+ * originally written at the National Center for Supercomputing Applications,
+ * University of Illinois, Urbana-Champaign.
+ */
+
+package org.apache.poi.contrib.poibrowser;
+
+import java.io.*;
+import org.apache.poi.hpsf.*;
+import org.apache.poi.poifs.filesystem.*;
+
+/**
+ * <p>Describes the most important (whatever that is) features of a
+ * stream containing a {@link PropertySet}.</p>
+ *
+ * @author Rainer Klute (klute@rainer-klute.de)
+ * @version $Id$
+ * @since 2002-02-05
+ */
+public class PropertySetDescriptor extends DocumentDescriptor
+{
+
+ protected PropertySet propertySet;
+
+ /**
+ * <p>Returns this {@link PropertySetDescriptor}'s {@link
+ * PropertySet}.</p>
+ */
+ public PropertySet getPropertySet()
+ {
+ return propertySet;
+ }
+
+
+
+ /**
+ * <p>Creates a {@link PropertySetDescriptor} by reading a {@link
+ * PropertySet} from a {@link DocumentInputStream}.</p>
+ *
+ * @param name The stream's name.
+ *
+ * @param path The stream's path in the POI filesystem hierarchy.
+ *
+ * @param stream The stream.
+ *
+ * @param nrOfBytes The maximum number of bytes to display in a
+ * dump starting at the beginning of the stream.
+ */
+ public PropertySetDescriptor(final String name,
+ final POIFSDocumentPath path,
+ final DocumentInputStream stream,
+ final int nrOfBytesToDump)
+ throws NoPropertySetStreamException, MarkUnsupportedException,
+ UnexpectedPropertySetTypeException, IOException
+ {
+ super(name, path, stream, nrOfBytesToDump);
+ propertySet = PropertySetFactory.create(stream);
+ }
+
+}
diff --git a/src/contrib/src/org/apache/poi/contrib/poibrowser/PropertySetDescriptorRenderer.java b/src/contrib/src/org/apache/poi/contrib/poibrowser/PropertySetDescriptorRenderer.java
new file mode 100644
index 0000000000..32541ed0ce
--- /dev/null
+++ b/src/contrib/src/org/apache/poi/contrib/poibrowser/PropertySetDescriptorRenderer.java
@@ -0,0 +1,193 @@
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2000 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" must
+ * not be used to endorse or promote products derived from this
+ * software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * nor may "Apache" appear in their name, without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ * Portions of this software are based upon public domain software
+ * originally written at the National Center for Supercomputing Applications,
+ * University of Illinois, Urbana-Champaign.
+ */
+
+package org.apache.poi.contrib.poibrowser;
+
+import java.awt.*;
+import java.util.Iterator;
+import java.util.List;
+import javax.swing.*;
+import javax.swing.tree.*;
+import org.apache.poi.hpsf.*;
+import org.apache.poi.hpsf.wellknown.*;
+
+/**
+ * <p>Renders a {@link PropertySetDescriptor} by more or less dumping
+ * the stuff into a {@link JTextArea}.</p>
+ *
+ * @author Rainer Klute (klute@rainer-klute.de)
+ * @version $Id$
+ * @since 2002-02-05
+ */
+public class PropertySetDescriptorRenderer extends DocumentDescriptorRenderer
+{
+
+ public Component getTreeCellRendererComponent(final JTree tree,
+ final Object value,
+ final boolean selected,
+ final boolean expanded,
+ final boolean leaf,
+ final int row,
+ final boolean hasFocus)
+ {
+ final PropertySetDescriptor d = (PropertySetDescriptor)
+ ((DefaultMutableTreeNode) value).getUserObject();
+ final PropertySet ps = d.getPropertySet();
+ final JPanel p = new JPanel();
+ final JTextArea text = new JTextArea();
+ text.setBackground(new Color(200, 255, 200));
+ text.setFont(new Font("Monospaced", Font.PLAIN, 10));
+ text.append(renderAsString(d));
+ text.append("\nByte order: " +
+ Codec.hexEncode(ps.getByteOrder().getBytes()));
+ text.append("\nFormat: " +
+ Codec.hexEncode(ps.getFormat().getBytes()));
+ text.append("\nOS version: " +
+ Codec.hexEncode(ps.getOSVersion().getBytes()));
+ text.append("\nClass ID: " +
+ Codec.hexEncode(ps.getClassID().getBytes()));
+ text.append("\nSection count: " + ps.getSectionCount());
+ text.append(sectionsToString(ps.getSections()));
+ p.add(text);
+
+ if (ps instanceof SummaryInformation)
+ {
+ /* Use the convenience methods. */
+ final SummaryInformation si = (SummaryInformation) ps;
+ text.append("\n");
+ text.append("\nTitle: " + si.getTitle());
+ text.append("\nSubject: " + si.getSubject());
+ text.append("\nAuthor: " + si.getAuthor());
+ text.append("\nKeywords: " + si.getKeywords());
+ text.append("\nComments: " + si.getComments());
+ text.append("\nTemplate: " + si.getTemplate());
+ text.append("\nLast Author: " + si.getLastAuthor());
+ text.append("\nRev. Number: " + si.getRevNumber());
+ text.append("\nEdit Time: " + si.getEditTime());
+ text.append("\nLast Printed: " + si.getLastPrinted());
+ text.append("\nCreate Date/Time: " + si.getCreateDateTime());
+ text.append("\nLast Save Date/Time: " + si.getLastSaveDateTime());
+ text.append("\nPage Count: " + si.getPageCount());
+ text.append("\nWord Count: " + si.getWordCount());
+ text.append("\nChar Count: " + si.getCharCount());
+ // text.append("\nThumbnail: " + si.getThumbnail());
+ text.append("\nApplication Name: " + si.getApplicationName());
+ text.append("\nSecurity: " + si.getSecurity());
+ }
+
+ if (selected)
+ Util.invert(text);
+ return p;
+ }
+
+
+
+ /**
+ * <p>Returns a string representation of a list of {@link
+ * Section}s.</p>
+ */
+ protected String sectionsToString(final List sections)
+ {
+ final StringBuffer b = new StringBuffer();
+ int count = 1;
+ for (Iterator i = sections.iterator(); i.hasNext();)
+ {
+ Section s = (Section) i.next();
+ b.append(toString(s, "Section " + count++));
+ }
+ return b.toString();
+ }
+
+
+
+ /**
+ * <p>Returns a string representation of a {@link Section}.</p>
+ */
+ protected String toString(final Section s, final String name)
+ {
+ final StringBuffer b = new StringBuffer();
+ b.append("\n" + name + " Format ID: ");
+ b.append(Codec.hexEncode(s.getFormatID().getBytes()));
+ b.append("\n" + name + " Offset: " + s.getOffset());
+ b.append("\n" + name + " Section size: " + s.getSize());
+ b.append("\n" + name + " Property count: " + s.getPropertyCount());
+
+ final Property[] properties = s.getProperties();
+ for (int i = 0; i < properties.length; i++)
+ {
+ final Property p = properties[i];
+ final Object value = p.getValue();
+ b.append("\n" + name + " ");
+ b.append("PID_");
+ b.append(p.getID());
+ b.append(' ');
+ b.append(s.getPIDString(p.getID()) + ": ");
+ if (value instanceof byte[])
+ {
+ byte[] b2 = (byte[]) value;
+ b.append("0x" + Codec.hexEncode(b2, 0, 4));
+ b.append(' ');
+ b.append("0x" + Codec.hexEncode(b2, 4, b2.length - 4));
+ }
+ else
+ b.append(value.toString());
+ }
+ return b.toString();
+ }
+
+}
diff --git a/src/contrib/src/org/apache/poi/contrib/poibrowser/TreeReaderListener.java b/src/contrib/src/org/apache/poi/contrib/poibrowser/TreeReaderListener.java
new file mode 100644
index 0000000000..124c595b60
--- /dev/null
+++ b/src/contrib/src/org/apache/poi/contrib/poibrowser/TreeReaderListener.java
@@ -0,0 +1,277 @@
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2000 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" must
+ * not be used to endorse or promote products derived from this
+ * software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * nor may "Apache" appear in their name, without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ * Portions of this software are based upon public domain software
+ * originally written at the National Center for Supercomputing Applications,
+ * University of Illinois, Urbana-Champaign.
+ */
+
+package org.apache.poi.contrib.poibrowser;
+
+import java.io.*;
+import java.util.*;
+import javax.swing.tree.*;
+import org.apache.poi.hpsf.*;
+import org.apache.poi.poifs.eventfilesystem.*;
+import org.apache.poi.poifs.filesystem.*;
+
+/**
+ * <p>Organizes document information in a tree model in order to be
+ * e.g. displayed in a Swing {@link JTree}. An instance of this class
+ * is created with a root tree node ({@link MutableTreeNode}) and
+ * registered as a {@link POIFSReaderListener} with a {@link
+ * POIFSReader}. While the latter processes a POI filesystem it calls
+ * this class' {@link #processPOIFSReaderEvent} for each document it
+ * has been registered for. This method appends the document it
+ * processes at the appropriate position into the tree rooted at the
+ * above mentioned root tree node.</p>
+ *
+ * <p>The root tree node should be the root tree node of a {@link
+ * TreeModel}.</p>
+ *
+ * <p>A top-level element in the tree model, i.e. an immediate child
+ * node of the root node, describes a POI filesystem as such. It is
+ * suggested to use the file's name (as seen by the operating system)
+ * but it could be any other string.</p>
+ *
+ * <p>The value of a tree node is a {@link DocumentDescriptor}. Unlike
+ * a {@link POIFSDocument} which may be as heavy as many megabytes, an
+ * instance of {@link DocumentDescriptor} is a light-weight object and
+ * contains only some meta-information about a document.</p>
+ *
+ * @author Rainer Klute (klute@rainer-klute.de)
+ * @version $Id$
+ * @since 2002-01-24
+ */
+public class TreeReaderListener implements POIFSReaderListener
+{
+
+ /**
+ * <p>The tree's root node. POI filesystems get attached to this
+ * node as children.</p>
+ */
+ protected MutableTreeNode rootNode;
+
+ /**
+ * <p>Maps filenames and POI document paths to their associated
+ * tree nodes.</p>
+ */
+ protected Map pathToNode;
+
+ /**
+ * <p>The name of the file this {@link TreeReaderListener}
+ * processes. It is used to identify a top-level element in the
+ * tree. Alternatively any other string can be used. It is just a
+ * label which should identify a POI filesystem.</p>
+ */
+ protected String filename;
+
+
+
+ /**
+ * <p>Creates a {@link TreeReaderListener} which should then be
+ * registered with a {@link POIFSReader}.</p>
+ *
+ * @param filename The name of the POI filesystem, i.e. the name
+ * of the file the POI filesystem resides in. Alternatively any
+ * other string can be used.
+ *
+ * @param rootNode All document information will be attached as
+ * descendands to this tree node.
+ */
+ public TreeReaderListener(final String filename,
+ final MutableTreeNode rootNode)
+ {
+ this.filename = filename;
+ this.rootNode = rootNode;
+ pathToNode = new HashMap(15);
+ }
+
+
+
+ /** <p>The number of bytes to dump.</p> */
+ private int nrOfBytes = 50;
+
+ public void setNrOfBytes(final int nrOfBytes)
+ {
+ this.nrOfBytes = nrOfBytes;
+ }
+
+ public int getNrOfBytes()
+ {
+ return nrOfBytes;
+ }
+
+
+
+ /**
+ * <p>A document in the POI filesystem has been opened for
+ * reading. This method retrieves properties of the document and
+ * adds them to a tree model.</p>
+ */
+ public void processPOIFSReaderEvent(final POIFSReaderEvent event)
+ {
+ DocumentDescriptor d;
+ final DocumentInputStream is = event.getStream();
+ if (!is.markSupported())
+ throw new UnsupportedOperationException(is.getClass().getName() +
+ " does not support mark().");
+
+ /* Try do handle this document as a property set. We receive
+ * an exception if is no property set and handle it as a
+ * document of some other format. We are not concerned about
+ * that document's details. */
+ try
+ {
+ d = new PropertySetDescriptor(event.getName(), event.getPath(),
+ is, nrOfBytes);
+ }
+ catch (HPSFException ex)
+ {
+ d = new DocumentDescriptor(event.getName(), event.getPath(),
+ is, nrOfBytes);
+ }
+ catch (Throwable t)
+ {
+ System.err.println
+ ("Unexpected exception while processing " +
+ event.getName() + " in " + event.getPath().toString());
+ t.printStackTrace(System.err);
+ throw new RuntimeException(t.getMessage());
+ }
+
+ try
+ {
+ is.close();
+ }
+ catch (IOException ex)
+ {
+ System.err.println
+ ("Unexpected exception while closing " +
+ event.getName() + " in " + event.getPath().toString());
+ ex.printStackTrace(System.err);
+ }
+
+ final MutableTreeNode parentNode = getNode(d.path, filename, rootNode);
+ final MutableTreeNode nameNode = new DefaultMutableTreeNode(d.name);
+ parentNode.insert(nameNode, 0);
+ final MutableTreeNode dNode = new DefaultMutableTreeNode(d);
+ nameNode.insert(dNode, 0);
+ }
+
+
+
+ /**
+ * <p>Locates the parent node for a document entry in the tree
+ * model. If the parent node does not yet exist it will be
+ * created, too. This is done recursively, if needed.</p>
+ *
+ * @param path The tree node for this path is located.
+ *
+ * @param fsName The name of the POI filesystem. This is just a
+ * string which is displayed in the tree at the top lovel.
+ *
+ * @param root The root node.
+ */
+ private MutableTreeNode getNode(final POIFSDocumentPath path,
+ final String fsName,
+ final MutableTreeNode root)
+ {
+ MutableTreeNode n = (MutableTreeNode) pathToNode.get(path);
+ if (n != null)
+ /* Node found in map, just return it. */
+ return n;
+ if (path.length() == 0)
+ {
+ /* This is the root path of the POI filesystem. Its tree
+ * node is resp. must be located below the tree node of
+ * the POI filesystem itself. This is a tree node with the
+ * POI filesystem's name (this the operating system file's
+ * name) as its key it the path-to-node map. */
+ n = (MutableTreeNode) pathToNode.get(fsName);
+ if (n == null)
+ {
+ /* A tree node for the POI filesystem does not yet
+ * exist. */
+ n = new DefaultMutableTreeNode(fsName);
+ pathToNode.put(fsName, n);
+ root.insert(n, 0);
+ }
+ return n;
+ }
+ else
+ {
+ /* The path is somewhere down in the POI filesystem's
+ * hierarchy. We need the tree node of this path's parent
+ * and attach our new node to it. */
+ final String name = path.getComponent(path.length() - 1);
+ final POIFSDocumentPath parentPath = path.getParent();
+ final MutableTreeNode parentNode =
+ getNode(parentPath, fsName, root);
+ n = new DefaultMutableTreeNode(name);
+ pathToNode.put(path, n);
+ parentNode.insert(n, 0);
+ return n;
+ }
+ }
+
+
+ private String s(final Object o)
+ {
+ if (o == null)
+ return "null";
+ else
+ return o.getClass().getName() + '@' + o.hashCode();
+ }
+
+}
diff --git a/src/contrib/src/org/apache/poi/contrib/poibrowser/Util.java b/src/contrib/src/org/apache/poi/contrib/poibrowser/Util.java
new file mode 100644
index 0000000000..07529948bb
--- /dev/null
+++ b/src/contrib/src/org/apache/poi/contrib/poibrowser/Util.java
@@ -0,0 +1,89 @@
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2000 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" must
+ * not be used to endorse or promote products derived from this
+ * software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * nor may "Apache" appear in their name, without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ * Portions of this software are based upon public domain software
+ * originally written at the National Center for Supercomputing Applications,
+ * University of Illinois, Urbana-Champaign.
+ */
+
+package org.apache.poi.contrib.poibrowser;
+
+import java.awt.*;
+import javax.swing.*;
+
+/**
+ * <p>Contains various (well, just one at the moment) static utility
+ * methods.</p>
+ *
+ * @author Rainer Klute (klute@rainer-klute.de)
+ * @version $Id$
+ * @since 2002-01-25
+ */
+public class Util
+{
+
+ /**
+ * <p>Makes a Swing component inverted by swapping its foreground
+ * and background colors. Hint: Depending on your needs it might
+ * also be a good idea to call <tt>c.setOpaque(true)</tt>.</p>
+ */
+ public static void invert(final JComponent c)
+ {
+ final Color invBackground = c.getForeground();
+ final Color invForeground = c.getBackground();
+ c.setBackground(invBackground);
+ c.setForeground(invForeground);
+ }
+
+}
+
diff --git a/src/contrib/src/org/apache/poi/contrib/poibrowser/package.html b/src/contrib/src/org/apache/poi/contrib/poibrowser/package.html
new file mode 100644
index 0000000000..ace98c0c2f
--- /dev/null
+++ b/src/contrib/src/org/apache/poi/contrib/poibrowser/package.html
@@ -0,0 +1,62 @@
+<!doctype html public "-//W3C//DTD HTML 4.0//EN//">
+
+<html>
+ <head>
+ <title></title>
+ </head>
+
+ <body>
+ <div>
+ <p>The <strong>POI Browser</strong> is a very simple Swing GUI tool that
+ displays the internal structure of a Microsoft Office file. It concentrates
+ on streams in the <em>Horrible Property Set Format (HPSF)</em>. In order to
+ access these streams the POI Browser uses the package
+ <tt>org.apache.poi.hpsf</tt>.</p>
+
+ <p>A file in Microsoft's Office format can be seen as a filesystem within a
+ file. For example, a Word document like <var>sample.doc</var> is just a
+ simple file from the operation system's point of view. However, internally
+ it is organized into various directories and files. For example,
+ <var>sample.doc</var> might consist of the three internal files (or
+ "streams", as Microsoft calls them) <tt>\001CompObj</tt>,
+ <tt>\005SummaryInformation</tt>, and <tt>WordDocument</tt>. (In these names
+ \001 and \005 denote the unprintable characters with the character codes 1
+ and 5, respectively.) A more complicated Word file typically contains a
+ directory named <tt>ObjectPool</tt> with more directories and files nested
+ within it.</p>
+
+ <p>The POI Browser makes these internal structures visible. It takes one or
+ more Microsoft files as input on the command line and shows directories and
+ files in a tree-like structure. On the top-level POI Browser displays the
+ (operating system) filenames. An internal file (i.e. a "stream" or a
+ "document") is shown with its name, its size and a hexadecimal dump of its
+ first bytes.</p>
+
+ <p>The POI Browser pays special attention to property set streams. For
+ example, the <tt>\005SummaryInformation</tt> stream contains information
+ like title and author of the document. The POI Browser opens every stream
+ in a POI filesystem. If it encounters a property set stream, it displays
+ not just its first bytes but analyses the whole stream and displays its
+ contents in a more or less readable manner.</p>
+ </div>
+ </body>
+</html>
+
+<!-- Keep this comment at the end of the file
+Local variables:
+sgml-default-dtd-file:"HTML_4.0_Strict.ced"
+mode: html
+sgml-omittag:t
+sgml-shorttag:nil
+sgml-namecase-general:t
+sgml-general-insert-case:lower
+sgml-minimize-attributes:nil
+sgml-always-quote-attributes:t
+sgml-indent-step:1
+sgml-indent-data:t
+sgml-parent-document:nil
+sgml-exposed-tags:nil
+sgml-local-catalogs:nil
+sgml-local-ecat-files:nil
+End:
+-->
diff --git a/src/java/org/apache/poi/hpsf/DocumentSummaryInformation.java b/src/java/org/apache/poi/hpsf/DocumentSummaryInformation.java
new file mode 100644
index 0000000000..6fc7799ea1
--- /dev/null
+++ b/src/java/org/apache/poi/hpsf/DocumentSummaryInformation.java
@@ -0,0 +1,271 @@
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2000 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" must
+ * not be used to endorse or promote products derived from this
+ * software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * nor may "Apache" appear in their name, without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ * Portions of this software are based upon public domain software
+ * originally written at the National Center for Supercomputing Applications,
+ * University of Illinois, Urbana-Champaign.
+ */
+
+package org.apache.poi.hpsf;
+
+import java.io.*;
+import java.util.*;
+import org.apache.poi.hpsf.wellknown.*;
+
+/**
+ * <p>Convenience class representing a DocumentSummary Information
+ * stream in a Microsoft Office document.</p>
+ *
+ * @see SummaryInformation
+ *
+ * @author Rainer Klute (klute@rainer-klute.de)
+ * @version $Id$
+ * @since 2002-02-09
+ */
+public class DocumentSummaryInformation extends SpecialPropertySet
+{
+
+ /**
+ * <p>Creates a {@link DocumentSummaryInformation} from a given
+ * {@link PropertySet}.</p>
+ *
+ * @param ps A property set which should be created from a
+ * document summary information stream.
+ *
+ * @throws UnexpectedPropertySetTypeException if <var>ps</var>
+ * does not contain a document summary information stream.
+ */
+ public DocumentSummaryInformation(final PropertySet ps)
+ throws UnexpectedPropertySetTypeException
+ {
+ super(ps);
+ if (!isDocumentSummaryInformation())
+ throw new UnexpectedPropertySetTypeException
+ ("Not a " + getClass().getName());
+ }
+
+
+
+ /**
+ * <p>Returns the stream's category (or <code>null</code>).</p>
+ */
+ public String getCategory()
+ {
+ return (String) getProperty(PropertyIDMap.PID_CATEGORY);
+ }
+
+
+
+ /**
+ * <p>Returns the stream's presentation format (or
+ * <code>null</code>).</p>
+ */
+ public String getPresentationFormat()
+ {
+ return (String) getProperty(PropertyIDMap.PID_PRESFORMAT);
+ }
+
+
+
+ /**
+ * <p>Returns the stream's byte count or 0 if the {@link
+ * DocumentSummaryInformation} does not contain a byte count.</p>
+ */
+ public int getByteCount()
+ {
+ return getPropertyIntValue(PropertyIDMap.PID_BYTECOUNT);
+ }
+
+
+
+ /**
+ * <p>Returns the stream's line count or 0 if the {@link
+ * DocumentSummaryInformation} does not contain a line count.</p>
+ */
+ public int getLineCount()
+ {
+ return getPropertyIntValue(PropertyIDMap.PID_LINECOUNT);
+ }
+
+
+
+ /**
+ * <p>Returns the stream's par count or 0 if the {@link
+ * DocumentSummaryInformation} does not contain a par count.</p>
+ */
+ public int getParCount()
+ {
+ return getPropertyIntValue(PropertyIDMap.PID_PARCOUNT);
+ }
+
+
+
+ /**
+ * <p>Returns the stream's slide count or 0 if the {@link
+ * DocumentSummaryInformation} does not contain a slide count.</p>
+ */
+ public int getSlideCount()
+ {
+ return getPropertyIntValue(PropertyIDMap.PID_SLIDECOUNT);
+ }
+
+
+
+ /**
+ * <p>Returns the stream's note count or 0 if the {@link
+ * DocumentSummaryInformation} does not contain a note count.</p>
+ */
+ public int getNoteCount()
+ {
+ return getPropertyIntValue(PropertyIDMap.PID_NOTECOUNT);
+ }
+
+
+
+ /**
+ * <p>Returns the stream's hidden count or 0 if the {@link
+ * DocumentSummaryInformation} does not contain a hidden count.</p>
+ */
+ public int getHiddenCount()
+ {
+ return getPropertyIntValue(PropertyIDMap.PID_HIDDENCOUNT);
+ }
+
+
+
+ /**
+ * <p>Returns the stream's mmclip count or 0 if the {@link
+ * DocumentSummaryInformation} does not contain a mmclip count.</p>
+ */
+ public int getMMClipCount()
+ {
+ return getPropertyIntValue(PropertyIDMap.PID_MMCLIPCOUNT);
+ }
+
+
+
+ /**
+ * <p>Returns the stream's scale (or <code>null</code>)
+ * <strong>when this method is implemented. Please note that the
+ * return type is likely to change!</strong>
+ */
+ public byte[] getScale()
+ {
+ if (true)
+ throw new UnsupportedOperationException("FIXME");
+ return (byte[]) getProperty(PropertyIDMap.PID_SCALE);
+ }
+
+
+
+ /**
+ * <p>Returns the stream's heading pair (or <code>null</code>)
+ * <strong>when this method is implemented. Please note that the
+ * return type is likely to change!</strong>
+ */
+ public byte[] getHeadingPair()
+ {
+ if (true)
+ throw new UnsupportedOperationException("FIXME");
+ return (byte[]) getProperty(PropertyIDMap.PID_HEADINGPAIR);
+ }
+
+
+
+ /**
+ * <p>Returns the stream's doc parts (or <code>null</code>)
+ * <strong>when this method is implemented. Please note that the
+ * return type is likely to change!</strong>
+ */
+ public byte[] getDocparts()
+ {
+ if (true)
+ throw new UnsupportedOperationException("FIXME");
+ return (byte[]) getProperty(PropertyIDMap.PID_DOCPARTS);
+ }
+
+
+
+ /**
+ * <p>Returns the stream's manager (or <code>null</code>).</p>
+ */
+ public String getManager()
+ {
+ return (String) getProperty(PropertyIDMap.PID_MANAGER);
+ }
+
+
+
+ /**
+ * <p>Returns the stream's company (or <code>null</code>).</p>
+ */
+ public String getCompany()
+ {
+ return (String) getProperty(PropertyIDMap.PID_COMPANY);
+ }
+
+
+
+ /**
+ * <p>Returns the stream's links dirty (or <code>null</code>)
+ * <strong>when this method is implemented. Please note that the
+ * return type is likely to change!</strong>
+ */
+ public byte[] getLinksDirty()
+ {
+ if (true)
+ throw new UnsupportedOperationException("FIXME");
+ return (byte[]) getProperty(PropertyIDMap.PID_LINKSDIRTY);
+ }
+
+}
diff --git a/src/java/org/apache/poi/hpsf/HPSFException.java b/src/java/org/apache/poi/hpsf/HPSFException.java
new file mode 100644
index 0000000000..def7fe902d
--- /dev/null
+++ b/src/java/org/apache/poi/hpsf/HPSFException.java
@@ -0,0 +1,131 @@
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2000 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" must
+ * not be used to endorse or promote products derived from this
+ * software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * nor may "Apache" appear in their name, without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ * Portions of this software are based upon public domain software
+ * originally written at the National Center for Supercomputing Applications,
+ * University of Illinois, Urbana-Champaign.
+ */
+
+package org.apache.poi.hpsf;
+
+/**
+ * <p>This exception is the superclass of all other checked exceptions
+ * thrown in this package. It supports a nested "reason" throwable,
+ * i.e. an exception that caused this one to be thrown.</p>
+ *
+ * @author Rainer Klute (klute@rainer-klute.de)
+ * @version $Id$
+ * @since 2002-02-09
+ */
+public class HPSFException extends Exception
+{
+
+ private Throwable reason;
+
+
+
+ /**
+ * <p>Creates a new {@link HPSFException}.</p>
+ */
+ public HPSFException()
+ {
+ super();
+ }
+
+
+
+ /**
+ * <p>Creates a new {@link HPSFException} with a message
+ * string.</p>
+ */
+ public HPSFException(final String msg)
+ {
+ super(msg);
+ }
+
+
+
+ /**
+ * <p>Creates a new {@link HPSFException} with a reason.</p>
+ */
+ public HPSFException(final Throwable reason)
+ {
+ super();
+ this.reason = reason;
+ }
+
+
+
+ /**
+ * <p>Creates a new {@link HPSFException} with a message string
+ * and a reason.</p>
+ */
+ public HPSFException(final String msg, final Throwable reason)
+ {
+ super(msg);
+ this.reason = reason;
+ }
+
+
+
+ /**
+ * <p>Returns the {@link Throwable} that caused this exception to
+ * be thrown or <code>null</code> if there was no such {@link
+ * Throwable}.</p>
+ */
+ public Throwable getReason()
+ {
+ return reason;
+ }
+
+}
diff --git a/src/java/org/apache/poi/hpsf/HPSFRuntimeException.java b/src/java/org/apache/poi/hpsf/HPSFRuntimeException.java
new file mode 100644
index 0000000000..cf11517da3
--- /dev/null
+++ b/src/java/org/apache/poi/hpsf/HPSFRuntimeException.java
@@ -0,0 +1,131 @@
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2000 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" must
+ * not be used to endorse or promote products derived from this
+ * software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * nor may "Apache" appear in their name, without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ * Portions of this software are based upon public domain software
+ * originally written at the National Center for Supercomputing Applications,
+ * University of Illinois, Urbana-Champaign.
+ */
+
+package org.apache.poi.hpsf;
+
+/**
+ * <p>This exception is the superclass of all other unchecked
+ * exceptions thrown in this package. It supports a nested "reason"
+ * throwable, i.e. an exception that caused this one to be thrown.</p>
+ *
+ * @author Rainer Klute (klute@rainer-klute.de)
+ * @version $Id$
+ * @since 2002-02-09
+ */
+public class HPSFRuntimeException extends RuntimeException
+{
+
+ private Throwable reason;
+
+
+
+ /**
+ * <p>Creates a new {@link HPSFRuntimeException}.</p>
+ */
+ public HPSFRuntimeException()
+ {
+ super();
+ }
+
+
+
+ /**
+ * <p>Creates a new {@link HPSFRuntimeException} with a message
+ * string.</p>
+ */
+ public HPSFRuntimeException(final String msg)
+ {
+ super(msg);
+ }
+
+
+
+ /**
+ * <p>Creates a new {@link HPSFRuntimeException} with a reason.</p>
+ */
+ public HPSFRuntimeException(final Throwable reason)
+ {
+ super();
+ this.reason = reason;
+ }
+
+
+
+ /**
+ * <p>Creates a new {@link HPSFRuntimeException} with a message string
+ * and a reason.</p>
+ */
+ public HPSFRuntimeException(final String msg, final Throwable reason)
+ {
+ super(msg);
+ this.reason = reason;
+ }
+
+
+
+ /**
+ * <p>Returns the {@link Throwable} that caused this exception to
+ * be thrown or <code>null</code> if there was no such {@link
+ * Throwable}.</p>
+ */
+ public Throwable getReason()
+ {
+ return reason;
+ }
+
+}
diff --git a/src/java/org/apache/poi/hpsf/MarkUnsupportedException.java b/src/java/org/apache/poi/hpsf/MarkUnsupportedException.java
new file mode 100644
index 0000000000..27cf0b8060
--- /dev/null
+++ b/src/java/org/apache/poi/hpsf/MarkUnsupportedException.java
@@ -0,0 +1,92 @@
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2000 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" must
+ * not be used to endorse or promote products derived from this
+ * software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * nor may "Apache" appear in their name, without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ * Portions of this software are based upon public domain software
+ * originally written at the National Center for Supercomputing Applications,
+ * University of Illinois, Urbana-Champaign.
+ */
+
+package org.apache.poi.hpsf;
+
+/**
+ * <p>This exception is thrown if an {@link java.io.InputStream} does
+ * not support the {@link java.io.InputStream#mark} operation.</p>
+ *
+ * @author Rainer Klute (klute@rainer-klute.de)
+ * @version $Id$
+ * @since 2002-02-09
+ */
+public class MarkUnsupportedException extends HPSFException
+{
+
+ public MarkUnsupportedException()
+ {
+ super();
+ }
+
+ public MarkUnsupportedException(final String msg)
+ {
+ super(msg);
+ }
+
+ public MarkUnsupportedException(final Throwable reason)
+ {
+ super(reason);
+ }
+
+ public MarkUnsupportedException(final String msg, final Throwable reason)
+ {
+ super(msg, reason);
+ }
+
+}
diff --git a/src/java/org/apache/poi/hpsf/NoPropertySetStreamException.java b/src/java/org/apache/poi/hpsf/NoPropertySetStreamException.java
new file mode 100644
index 0000000000..2a7d33138a
--- /dev/null
+++ b/src/java/org/apache/poi/hpsf/NoPropertySetStreamException.java
@@ -0,0 +1,97 @@
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2000 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" must
+ * not be used to endorse or promote products derived from this
+ * software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * nor may "Apache" appear in their name, without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ * Portions of this software are based upon public domain software
+ * originally written at the National Center for Supercomputing Applications,
+ * University of Illinois, Urbana-Champaign.
+ */
+
+package org.apache.poi.hpsf;
+
+/**
+ * <p>This exception is thrown if a format error in a property set
+ * stream is detected or when the input data do not constitute a
+ * property set stream.</p>
+ *
+ * <p>The constructors of this class are analogous to those of its
+ * superclass and documented there.</p>
+ *
+ * @author Rainer Klute (klute@rainer-klute.de)
+ * @version $Id$
+ * @since 2002-02-09
+ */
+public class NoPropertySetStreamException extends HPSFException
+{
+
+ public NoPropertySetStreamException()
+ {
+ super();
+ }
+
+ public NoPropertySetStreamException(final String msg)
+ {
+ super(msg);
+ }
+
+ public NoPropertySetStreamException(final Throwable reason)
+ {
+ super(reason);
+ }
+
+ public NoPropertySetStreamException(final String msg,
+ final Throwable reason)
+ {
+ super(msg, reason);
+ }
+
+}
diff --git a/src/java/org/apache/poi/hpsf/NoSingleSectionException.java b/src/java/org/apache/poi/hpsf/NoSingleSectionException.java
new file mode 100644
index 0000000000..78ba3f3706
--- /dev/null
+++ b/src/java/org/apache/poi/hpsf/NoSingleSectionException.java
@@ -0,0 +1,97 @@
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2000 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" must
+ * not be used to endorse or promote products derived from this
+ * software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * nor may "Apache" appear in their name, without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ * Portions of this software are based upon public domain software
+ * originally written at the National Center for Supercomputing Applications,
+ * University of Illinois, Urbana-Champaign.
+ */
+
+package org.apache.poi.hpsf;
+
+/**
+ * <p>This exception is thrown if one of the {@link PropertySet}'s
+ * convenience methods that require a single {@link Section} is called
+ * and the {@link PropertySet} does not contain exactly one {@link
+ * Section}.</p>
+ *
+ * <p>The constructors of this class are analogous to those of its
+ * superclass and documented there.</p>
+ *
+ * @author Rainer Klute (klute@rainer-klute.de)
+ * @version $Id$
+ * @since 2002-02-09
+ */
+public class NoSingleSectionException extends HPSFRuntimeException
+{
+
+ public NoSingleSectionException()
+ {
+ super();
+ }
+
+ public NoSingleSectionException(final String msg)
+ {
+ super(msg);
+ }
+
+ public NoSingleSectionException(final Throwable reason)
+ {
+ super(reason);
+ }
+
+ public NoSingleSectionException(final String msg, final Throwable reason)
+ {
+ super(msg, reason);
+ }
+
+}
diff --git a/src/java/org/apache/poi/hpsf/Property.java b/src/java/org/apache/poi/hpsf/Property.java
new file mode 100644
index 0000000000..c38b85eaae
--- /dev/null
+++ b/src/java/org/apache/poi/hpsf/Property.java
@@ -0,0 +1,274 @@
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2000 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" must
+ * not be used to endorse or promote products derived from this
+ * software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * nor may "Apache" appear in their name, without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ * Portions of this software are based upon public domain software
+ * originally written at the National Center for Supercomputing Applications,
+ * University of Illinois, Urbana-Champaign.
+ */
+
+package org.apache.poi.hpsf;
+
+import java.util.*;
+import org.apache.poi.hpsf.littleendian.*;
+
+/**
+ * <p>A property in a {@link Section} of a {@link PropertySet}.</p>
+ *
+ * <p>The property's <strong>ID</strong> gives the property a meaning
+ * in the context of its {@link Section}. Each {@link Section} spans
+ * its own name space of property IDs.</p>
+ *
+ * <p>The property's <strong>type</strong> determines how its
+ * <strong>value</strong> is interpreted. For example, if the type is
+ * {@link Variant#VT_LPSTR} (byte string), the value consists of a
+ * {@link DWord} telling how many bytes the string contains. The bytes
+ * follow immediately, including any null bytes that terminate the
+ * string. The type {@link Variant#VT_I4} denotes a four-byte integer
+ * value, {@link Variant#VT_FILETIME} some date and time (of a
+ * file).</p>
+ *
+ * <p><strong>FIXME:</strong> Reading of other types than those
+ * mentioned above and the dictionary property is not yet
+ * implemented.</p>
+ *
+ * @see Section
+ * @see Variant
+ *
+ * @author Rainer Klute (klute@rainer-klute.de)
+ * @version $Id$
+ * @since 2002-02-09
+ */
+public class Property
+{
+
+ private int id;
+
+ /**
+ * <p>Returns the property's ID.</p>
+ */
+ public int getID()
+ {
+ return id;
+ }
+
+
+
+ private int type;
+
+ /**
+ * <p>Returns the property's type.</p>
+ */
+ public int getType()
+ {
+ return type;
+ }
+
+
+
+ private Object value;
+
+ /**
+ * <p>Returns the property value's.</p>
+ */
+ public Object getValue()
+ {
+ return value;
+ }
+
+
+
+ /**
+ * <p>Creates a {@link Property} instance by reading its bytes
+ * from the property set stream.</p>
+ *
+ * @param id The property's ID.
+ *
+ * @param src The bytes the property set stream consists of.
+ *
+ * @param offset The property's type/value pair's offset in the
+ * section.
+ *
+ * @param length The property's type/value pair's length in bytes.
+ * list.
+ */
+ public Property(final int id, final byte[] src, final int offset,
+ final int length)
+ {
+ this.id = id;
+
+ /* ID 0 is a special case since it specifies a dictionary of
+ * property IDs and property names. */
+ if (id == 0)
+ {
+ value = readDictionary(src, offset, length);
+ return;
+ }
+
+ /* FIXME: Support this! */
+// /* ID 1 is another special case: It denotes the code page of
+// * byte strings in this section. */
+// if (id == 1)
+// {
+// value = readCodepage(src, offset);
+// return;
+// }
+
+ int o = offset;
+ type = new DWord(src, o).intValue();
+ o += DWord.LENGTH;
+
+ /* FIXME: Support reading more types! */
+ switch (type)
+ {
+ case Variant.VT_I4:
+ {
+ /* Read a word. In Java it is represented as an
+ Integer object. */
+ value = new Integer(new DWord(src, o).intValue());
+ break;
+ }
+ case Variant.VT_FILETIME:
+ {
+ /* Read a FILETIME object. In Java it is represented
+ as a Date. */
+ final int low = new DWord(src, o).intValue();
+ o += DWord.LENGTH;
+ final int high = new DWord(src, o).intValue();
+ value = Util.filetimeToDate(high, low);
+ break;
+ }
+ case Variant.VT_LPSTR:
+ {
+ /* Read a byte string. In Java it is represented as a
+ String. The null bytes at the end of the byte
+ strings must be stripped. */
+ final int first = o + DWord.LENGTH;
+ int last = first + new DWord(src, o).intValue() - 1;
+ o += DWord.LENGTH;
+ while (src[last] == 0 && first <= last)
+ last--;
+ value = new String(src, first, last - first + 1);
+ break;
+ }
+ default:
+ {
+ final byte[] v = new byte[length];
+ for (int i = 0; i < length; i++)
+ v[i] = src[offset + i];
+ value = v;
+ break;
+ }
+ }
+ }
+
+
+
+ /**
+ * <p>Reads a dictionary.</p>
+ *
+ * @param src The byte array containing the bytes making out the
+ * dictionary.
+ *
+ * @param offset At this offset within <var>src</var> the
+ * dictionary starts.
+ *
+ * @param length The dictionary contains at most this many bytes.
+ */
+ protected Map readDictionary(final byte[] src, final int offset,
+ final int length)
+ {
+ /* FIXME: Check the length! */
+ int o = offset;
+
+ /* Read the number of dictionary entries. */
+ final int nrEntries = new DWord(src, o).intValue();
+ o += DWord.LENGTH;
+
+ final Map m = new HashMap(nrEntries, (float) 1.0);
+ for (int i = 0; i < nrEntries; i++)
+ {
+ /* The key */
+ final Integer id = new Integer(new DWord(src, o).intValue());
+ o += DWord.LENGTH;
+
+ /* The value (a string) */
+ final int sLength = new DWord(src, o).intValue();
+ o += DWord.LENGTH;
+ /* Strip trailing 0x00 bytes. */
+ int l = sLength;
+ while (src[o + l - 1] == 0x00)
+ l--;
+ final String s = new String(src, o, l);
+ o += sLength;
+ m.put(id, s);
+ }
+ return m;
+ }
+
+
+
+ /**
+ * <p>Reads a code page.</p>
+ *
+ * @param src The byte array containing the bytes making out the
+ * code page.
+ *
+ * @param offset At this offset within <var>src</var> the code
+ * page starts.
+ */
+ protected int readCodePage(final byte[] src, final int offset)
+ {
+ throw new UnsupportedOperationException("FIXME");
+ }
+
+}
diff --git a/src/java/org/apache/poi/hpsf/PropertySet.java b/src/java/org/apache/poi/hpsf/PropertySet.java
new file mode 100644
index 0000000000..55e0102185
--- /dev/null
+++ b/src/java/org/apache/poi/hpsf/PropertySet.java
@@ -0,0 +1,528 @@
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2000 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" must
+ * not be used to endorse or promote products derived from this
+ * software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * nor may "Apache" appear in their name, without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ * Portions of this software are based upon public domain software
+ * originally written at the National Center for Supercomputing Applications,
+ * University of Illinois, Urbana-Champaign.
+ */
+
+package org.apache.poi.hpsf;
+
+import java.io.*;
+import java.util.*;
+import org.apache.poi.hpsf.littleendian.*;
+import org.apache.poi.hpsf.wellknown.*;
+import org.apache.poi.poifs.filesystem.*;
+
+/**
+ * <p>Represents a property set in the Horrible Property Set Format
+ * (HPSF). These are usually metadata of a Microsoft Office
+ * document.</p>
+ *
+ * <p>An application that wants to access these metadata should create
+ * an instance of this class or one of its subclasses by calling the
+ * factory method {@link PropertySetFactory#create} and then retrieve
+ * the information its needs by calling appropriate methods.</p>
+ *
+ * <p>{@link PropertySetFactory#create} does its work by calling one
+ * of the constructors {@link PropertySet#PropertySet(InputStream)} or
+ * {@link PropertySet#PropertySet(byte[])}. If the constructor's
+ * argument is not in the Horrible Property Set Format, i.e. not a
+ * property set stream, or if any other error occurs, an appropriate
+ * exception is thrown.</p>
+ *
+ * <p>A {@link PropertySet} has a list of {@link Section}s, and each
+ * {@link Section} has a {@link Property} array. Use {@link
+ * #getSections} to retrieve the {@link Section}s, then call {@link
+ * Section#getProperties} for each {@link Section} to get hold of the
+ * {@link Property} arrays.</p>
+ *
+ * Since the vast majority of {@link PropertySet}s contains only a
+ * single {@link Section}, the convenience method {@link
+ * #getProperties} returns the properties of a {@link PropertySet}'s
+ * {@link Section} (throwing a {@link NoSingleSectionException} if the
+ * {@link PropertySet} contains more (or less) than exactly one {@link
+ * Section}).
+ *
+ * @author Rainer Klute (klute@rainer-klute.de)
+ * @version $Id$
+ * @since 2002-02-09
+ */
+public class PropertySet
+{
+ static final byte[] BYTE_ORDER_ASSERTION =
+ new byte[] {(byte) 0xFF, (byte) 0xFE};
+ static final byte[] FORMAT_ASSERTION =
+ new byte[] {(byte) 0x00, (byte) 0x00};
+
+
+
+ private Word byteOrder; // Must equal BYTE_ORDER_ASSERTION
+
+ /**
+ * <p>Returns the property set stream's low-level "byte order"
+ * field. It is always <tt>0xFFFE</tt>.</p>
+ */
+ public Word getByteOrder()
+ {
+ return byteOrder;
+ }
+
+
+
+ private Word format; // Must equal FORMAT_ASSERTION
+
+ /**
+ * <p>Returns the property set stream's low-level "format"
+ * field. It is always <tt>0x0000</tt>.</p>
+ */
+ public Word getFormat()
+ {
+ return format;
+ }
+
+
+
+ private DWord osVersion;
+
+ /**
+ * <p>Returns the property set stream's low-level "OS version"
+ * field.</p>
+ */
+ public DWord getOSVersion()
+ {
+ return osVersion;
+ }
+
+
+
+ private ClassID classID;
+
+ /**
+ * <p>Returns the property set stream's low-level "class ID"
+ * field.</p>
+ */
+ public ClassID getClassID()
+ {
+ return classID;
+ }
+
+
+
+ private int sectionCount;
+
+ /**
+ * <p>Returns the number of {@link Section}s in the property
+ * set.</p>
+ */
+ public int getSectionCount()
+ {
+ return sectionCount;
+ }
+
+
+
+ private List sections;
+
+ /**
+ * <p>Returns the {@link Section}s in the property set.</p>
+ */
+ public List getSections()
+ {
+ return sections;
+ }
+
+
+
+ /**
+ * <p>Creates an empty (uninitialized) {@link PropertySet}.</p>
+ *
+ * <p><strong>Please note:</strong> For the time being this
+ * constructor is protected since it is used for internal purposes
+ * only, but expect it to become public once the property set
+ * writing functionality is implemented.</p>
+ */
+ protected PropertySet()
+ {}
+
+
+
+ /**
+ * <p>Creates a {@link PropertySet} instance from an {@link
+ * InputStream} in the Horrible Property Set Format.</p>
+ *
+ * <p>The constructor reads the first few bytes from the stream
+ * and determines whether it is really a property set stream. If
+ * it is, it parses the rest of the stream. If it is not, it
+ * resets the stream to its beginning in order to let other
+ * components mess around with the data and throws an
+ * exception.</p>
+ *
+ * @throws NoPropertySetStreamException if the stream is not a
+ * property set stream.
+ *
+ * @throws MarkUnsupportedException if the stream does not support
+ * the {@link InputStream#markSupported} method.
+ *
+ * @throws IOException if the {@link InputStream} cannot not be
+ * accessed as needed.
+ */
+ public PropertySet(final InputStream stream)
+ throws NoPropertySetStreamException, MarkUnsupportedException,
+ IOException
+ {
+ if (isPropertySetStream(stream))
+ {
+ final int avail = stream.available();
+ final byte[] buffer = new byte[avail];
+ stream.read(buffer, 0, buffer.length);
+ init(buffer, 0, buffer.length);
+ }
+ else
+ throw new NoPropertySetStreamException();
+ }
+
+
+
+ /**
+ * <p>Creates a {@link PropertySet} instance from a byte array
+ * that represents a stream in the Horrible Property Set
+ * Format.</p>
+ *
+ * @param stream The byte array holding the stream data.
+ *
+ * @param offset The offset in <var>stream</var> where the stream
+ * data begin. If the stream data begin with the first byte in the
+ * array, the <var>offset</var> is 0.
+ *
+ * @param length The length of the stream data.
+ *
+ * @throws NoPropertySetStreamException if the byte array is not a
+ * property set stream.
+ */
+ public PropertySet(final byte[] stream, final int offset, final int length)
+ throws NoPropertySetStreamException
+ {
+ if (isPropertySetStream(stream, offset, length))
+ init(stream, offset, length);
+ else
+ throw new NoPropertySetStreamException();
+ }
+
+
+
+ /**
+ * <p>Creates a {@link PropertySet} instance from a byte array
+ * that represents a stream in the Horrible Property Set
+ * Format.</p>
+ *
+ * @param stream The byte array holding the stream data. The
+ * complete byte array contents is the stream data.
+ *
+ * @throws NoPropertySetStreamException if the byte array is not a
+ * property set stream.
+ */
+ public PropertySet(final byte[] stream)
+ throws NoPropertySetStreamException
+ {
+ this(stream, 0, stream.length);
+ }
+
+
+
+ /**
+ * <p>Checks whether an {@link InputStream} is in the Horrible
+ * Property Set Format.</p>
+ *
+ * @param stream The {@link InputStream} to check. In order to
+ * perform the check, the method reads the first bytes from the
+ * stream. After reading, the stream is reset to the position it
+ * had before reading. The {@link InputStream} must support the
+ * {@link InputStream#mark} method.
+ *
+ * @return <code>true</code> if the stream is a property set
+ * stream, else <code>false</code>.
+ *
+ * @throws MarkUnsupportedException if the {@link InputStream}
+ * does not support the {@link InputStream#mark} method.
+ */
+ public static boolean isPropertySetStream(final InputStream stream)
+ throws MarkUnsupportedException, IOException
+ {
+ /* Read at most this many bytes. */
+ final int BUFFER_SIZE = 50;
+
+ /* Mark the current position in the stream so that we can
+ * reset to this position if the stream does not contain a
+ * property set. */
+ if (!stream.markSupported())
+ throw new MarkUnsupportedException(stream.getClass().getName());
+ stream.mark(BUFFER_SIZE);
+
+ /* Read a couple of bytes from the stream. */
+ final byte[] buffer = new byte[BUFFER_SIZE];
+ final int bytes =
+ stream.read(buffer, 0,
+ Math.min(buffer.length, stream.available()));
+ final boolean isPropertySetStream =
+ isPropertySetStream(buffer, 0, bytes);
+ stream.reset();
+ return isPropertySetStream;
+ }
+
+
+
+ /**
+ * <p>Checks whether a byte array is in the Horrible Property Set
+ * Format.</p>
+ *
+ * @param src The byte array to check.
+ *
+ * @param offset The offset in the byte array.
+ *
+ * @param length The significant number of bytes in the byte
+ * array. Only this number of bytes will be checked.
+ *
+ * @return <code>true</code> if the byte array is a property set
+ * stream, <code>false</code> if not.
+ */
+ public static boolean isPropertySetStream(final byte[] src, int offset,
+ final int length)
+ {
+ /* Read the header fields of the stream. They must always be
+ * there. */
+ final Word byteOrder = new Word(src, offset);
+ offset += Word.LENGTH;
+ if (!Util.equal(byteOrder.getBytes(), BYTE_ORDER_ASSERTION))
+ return false;
+ final Word format = new Word(src, offset);
+ offset += Word.LENGTH;
+ if (!Util.equal(format.getBytes(), FORMAT_ASSERTION))
+ return false;
+ final DWord osVersion = new DWord(src, offset);
+ offset += DWord.LENGTH;
+ final ClassID classID = new ClassID(src, offset);
+ offset += ClassID.LENGTH;
+ final DWord sectionCount = new DWord(src, offset);
+ offset += DWord.LENGTH;
+ if (sectionCount.intValue() < 1)
+ return false;
+ return true;
+ }
+
+
+
+ /**
+ * <p>Initializes this {@link PropertySet} instance from a byte
+ * array. The method assumes that it has been checked already that
+ * the byte array indeed represents a property set stream. It does
+ * no more checks on its own.</p>
+ */
+ private void init(final byte[] src, int offset, final int length)
+ {
+ /* Read the stream's header fields. */
+ byteOrder = new Word(src, offset);
+ offset += Word.LENGTH;
+ format = new Word(src, offset);
+ offset += Word.LENGTH;
+ osVersion = new DWord(src, offset);
+ offset += DWord.LENGTH;
+ classID = new ClassID(src, offset);
+ offset += ClassID.LENGTH;
+ sectionCount = new DWord(src, offset).intValue();
+ offset += DWord.LENGTH;
+
+ /* Read the sections, which are following the header. They
+ * start with an array of section descriptions. Each one
+ * consists of a format ID telling what the section contains
+ * and an offset telling how many bytes from the start of the
+ * stream the section begins. */
+ /* Most property sets have only one section. The Document
+ * Summary Information stream has 2. Everything else is a rare
+ * exception and is no longer fostered by Microsoft. */
+ sections = new ArrayList(2);
+
+ /* Loop over the section descriptor array. Each descriptor
+ * consists of a ClassID and a DWord, and we have to increment
+ * "offset" accordingly. */
+ for (int i = 0; i < sectionCount; i++)
+ {
+ final Section s = new Section(src, offset);
+ offset += ClassID.LENGTH + DWord.LENGTH;
+ sections.add(s);
+ }
+ }
+
+
+
+ /**
+ * <p>Checks whether this {@link PropertySet} represents a Summary
+ * Information.</p>
+ */
+ public boolean isSummaryInformation()
+ {
+ return Util.equal(((Section) sections.get(0)).getFormatID().getBytes(),
+ SectionIDMap.SUMMARY_INFORMATION_ID);
+ }
+
+
+
+ /**
+ * <p>Checks whether this {@link PropertySet} is a Document
+ * Summary Information.</p>
+ */
+ public boolean isDocumentSummaryInformation()
+ {
+ return Util.equal(((Section) sections.get(0)).getFormatID().getBytes(),
+ SectionIDMap.DOCUMENT_SUMMARY_INFORMATION_ID);
+ }
+
+
+
+ /**
+ * <p>Convenience method returning the {@link Property} array
+ * contained in this property set. It is a shortcut for getting
+ * the {@link PropertySet}'s {@link Section}s list and then
+ * getting the {@link Property} array from the first {@link
+ * Section}. However, it can only be used if the {@link
+ * PropertySet} contains exactly one {@link Section}, so check
+ * {@link #getSectionCount} first!</p>
+ *
+ * @return The properties of the only {@link Section} of this
+ * {@link PropertySet}.
+ *
+ * @throws NoSingleSectionException if the {@link PropertySet} has
+ * more or less than one {@link Section}.
+ */
+ public Property[] getProperties()
+ throws NoSingleSectionException
+ {
+ return getSingleSection().getProperties();
+ }
+
+
+
+ /**
+ * <p>Convenience method returning 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>
+ *
+ * @throws NoSingleSectionException if the {@link PropertySet} has
+ * more or less than one {@link Section}.
+ */
+ protected Object getProperty(final int id)
+ throws NoSingleSectionException
+ {
+ return getSingleSection().getProperty(id);
+ }
+
+
+
+ /**
+ * <p>Convenience method returning 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>
+ *
+ * @throws NoSingleSectionException if the {@link PropertySet} has
+ * more or less than one {@link Section}.
+ */
+ protected int getPropertyIntValue(final int id)
+ throws NoSingleSectionException
+ {
+ return getSingleSection().getPropertyIntValue(id);
+ }
+
+
+
+ /**
+ * <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>.
+ *
+ * @throws NoSingleSectionException if the {@link PropertySet} has
+ * more than one {@link Section}.
+ */
+ public boolean wasNull() throws NoSingleSectionException
+ {
+ return getSingleSection().wasNull();
+ }
+
+
+
+ /**
+ * <p>If the {@link PropertySet} has only a single section this
+ * method returns it.</p>
+ *
+ * @throws NoSingleSectionException if the {@link PropertySet} has
+ * more or less than exactly one {@link Section}.
+ */
+ public Section getSingleSection()
+ {
+ if (sectionCount != 1)
+ throw new NoSingleSectionException
+ ("Property set contains " + sectionCount + " sections.");
+ return ((Section) sections.get(0));
+ }
+
+}
diff --git a/src/java/org/apache/poi/hpsf/PropertySetFactory.java b/src/java/org/apache/poi/hpsf/PropertySetFactory.java
new file mode 100644
index 0000000000..fb36f2c9c9
--- /dev/null
+++ b/src/java/org/apache/poi/hpsf/PropertySetFactory.java
@@ -0,0 +1,97 @@
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2000 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" must
+ * not be used to endorse or promote products derived from this
+ * software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * nor may "Apache" appear in their name, without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ * Portions of this software are based upon public domain software
+ * originally written at the National Center for Supercomputing Applications,
+ * University of Illinois, Urbana-Champaign.
+ */
+
+package org.apache.poi.hpsf;
+
+import java.io.*;
+
+/**
+ * <p>Factory class to create instances of {@link SummaryInformation},
+ * {@link DocumentSummaryInformation} and {@link PropertySet}.</p>
+ *
+ * @author Rainer Klute (klute@rainer-klute.de)
+ * @version $Id$
+ * @since 2002-02-09
+ */
+public class PropertySetFactory
+{
+
+ /**
+ * <p>Creates the most specific {@link PropertySet} from an {@link
+ * InputStream}. This is preferrably a {@link
+ * DocumentSummaryInformation} or a {@link SummaryInformation}. If
+ * the specified {@link InputStream} does not contain a property
+ * set stream, an exception is thrown and the {@link InputStream}
+ * is repositioned at its beginning.</p>
+ *
+ * @param stream Contains the property set stream's data.
+ */
+ public static PropertySet create(final InputStream stream)
+ throws NoPropertySetStreamException, MarkUnsupportedException,
+ UnexpectedPropertySetTypeException, IOException
+ {
+ final PropertySet ps = new PropertySet(stream);
+ if (ps.isSummaryInformation())
+ return new SummaryInformation(ps);
+ else if (ps.isDocumentSummaryInformation())
+ return new DocumentSummaryInformation(ps);
+ else
+ return ps;
+ }
+
+}
diff --git a/src/java/org/apache/poi/hpsf/Section.java b/src/java/org/apache/poi/hpsf/Section.java
new file mode 100644
index 0000000000..63b6bb5bbd
--- /dev/null
+++ b/src/java/org/apache/poi/hpsf/Section.java
@@ -0,0 +1,278 @@
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2000 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" must
+ * not be used to endorse or promote products derived from this
+ * software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * nor may "Apache" appear in their name, without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ * Portions of this software are based upon public domain software
+ * originally written at the National Center for Supercomputing Applications,
+ * University of Illinois, Urbana-Champaign.
+ */
+
+package org.apache.poi.hpsf;
+
+import java.util.*;
+import org.apache.poi.hpsf.littleendian.*;
+import org.apache.poi.hpsf.wellknown.*;
+
+/**
+ * <p>Represents a section in a {@link PropertySet}.</p>
+ *
+ * @author Rainer Klute (klute@rainer-klute.de)
+ * @version $Id$
+ * @since 2002-02-09
+ */
+public class Section
+{
+
+ /**
+ * <p>Maps property IDs to section-private PID strings. These
+ * strings can be found in the property with ID 0.</p>
+ */
+ protected Map dictionary;
+
+
+
+ private ClassID formatID;
+
+ /**
+ * <p>Returns the format ID. The format ID is the "type" of the
+ * section.</p>
+ */
+ public ClassID getFormatID()
+ {
+ return formatID;
+ }
+
+
+
+ private int offset;
+
+ /**
+ * <p>Returns the offset of the section in the stream.</p>
+ */
+ public int getOffset()
+ {
+ return offset;
+ }
+
+
+
+ private int size;
+
+ /**
+ * <p>Returns the section's size in bytes.</p>
+ */
+ public int getSize()
+ {
+ return size;
+ }
+
+
+
+ private int propertyCount;
+
+ /**
+ * <p>Returns the number of properties in this section.</p>
+ */
+ public int getPropertyCount()
+ {
+ return propertyCount;
+ }
+
+
+
+ private Property[] properties;
+
+ /**
+ * <p>Returns this section's properties.</p>
+ */
+ public Property[] getProperties()
+ {
+ return properties;
+ }
+
+
+
+ /**
+ * <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.
+ */
+ public Section(final byte[] src, int offset)
+ {
+ /* Read the format ID. */
+ formatID = new ClassID(src, offset);
+ offset += ClassID.LENGTH;
+
+ /* Read the offset from the stream's start and positions to
+ * the section header. */
+ this.offset = new DWord(src, offset).intValue();
+ offset = this.offset;
+
+ /* Read the section length. */
+ size = new DWord(src, offset).intValue();
+ offset += DWord.LENGTH;
+
+ /* Read the number of properties. */
+ propertyCount = new DWord(src, offset).intValue();
+ offset += DWord.LENGTH;
+
+ /* Read the properties. The offset is positioned at the first
+ * entry of the property list. */
+ properties = new Property[propertyCount];
+ for (int i = 0; i < properties.length; i++)
+ {
+ final int id = new DWord(src, offset).intValue();
+ offset += DWord.LENGTH;
+
+ /* Offset from the section. */
+ final int sOffset = new DWord(src, offset).intValue();
+ offset += DWord.LENGTH;
+
+ /* Calculate the length of the property. */
+ int length;
+ if (i == properties.length - 1)
+ length = src.length - this.offset - sOffset;
+ else
+ length =
+ new DWord(src, offset + DWord.LENGTH).intValue() - sOffset;
+
+ /* Create it. */
+ properties[i] =
+ new Property(id, src, this.offset + sOffset, length);
+ }
+
+ /* Extract the dictionary (if available). */
+ dictionary = (Map) getProperty(0);
+ }
+
+
+
+ /**
+ * <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>
+ */
+ protected Object getProperty(final int id)
+ {
+ wasNull = false;
+ for (int i = 0; i < properties.length; i++)
+ if (id == properties[i].getID())
+ return properties[i].getValue();
+ wasNull = true;
+ return null;
+ }
+
+
+
+ /**
+ * <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>
+ */
+ protected int getPropertyIntValue(final int id)
+ {
+ final Integer i = (Integer) getProperty(id);
+ if (i != null)
+ return i.intValue();
+ else
+ return 0;
+ }
+
+
+
+ private boolean wasNull;
+
+ /**
+ * <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>.
+ */
+ public boolean wasNull()
+ {
+ return wasNull;
+ }
+
+
+
+ /**
+ * <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>
+ */
+ public String getPIDString(final int pid)
+ {
+ String s = null;
+ if (dictionary != null)
+ s = (String) dictionary.get(new Integer(pid));
+ if (s == null)
+ s = SectionIDMap.getPIDString(getFormatID().getBytes(), pid);
+ if (s == null)
+ s = SectionIDMap.UNDEFINED;
+ return s;
+ }
+
+}
diff --git a/src/java/org/apache/poi/hpsf/SpecialPropertySet.java b/src/java/org/apache/poi/hpsf/SpecialPropertySet.java
new file mode 100644
index 0000000000..f8970bc155
--- /dev/null
+++ b/src/java/org/apache/poi/hpsf/SpecialPropertySet.java
@@ -0,0 +1,169 @@
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2000 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" must
+ * not be used to endorse or promote products derived from this
+ * software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * nor may "Apache" appear in their name, without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ * Portions of this software are based upon public domain software
+ * originally written at the National Center for Supercomputing Applications,
+ * University of Illinois, Urbana-Champaign.
+ */
+
+package org.apache.poi.hpsf;
+
+import java.util.*;
+import org.apache.poi.hpsf.littleendian.*;
+
+/**
+ * <p>Abstract superclass for the convenience classes {@link
+ * SummaryInformation} and {@link DocumentSummaryInformation}.</p>
+ *
+ * <p>The motivation behind this class is quite nasty if you look
+ * behind the scenes, but it serves the application programmer well by
+ * providing him with the easy-to-use {@link SummaryInformation} and
+ * {@link DocumentSummaryInformation} classes. When parsing the data a
+ * property set stream consists of (possibly coming from an {@link
+ * java.io.InputStream}) we want to read and process each byte only
+ * once. Since we don't know in advance which kind of property set we
+ * have, we can expect only the most general {@link
+ * PropertySet}. Creating a special subclass should be as easy as
+ * calling the special subclass' constructor and pass the general
+ * {@link PropertySet} in. To make things easy internally, the special
+ * class just holds a reference to the general {@link PropertySet} and
+ * delegates all method calls to it.</p>
+ *
+ * <p>A cleaner implementation would have been like this: The {@link
+ * PropertySetFactory} parses the stream data into some internal
+ * object first. Then it finds out whether the stream is a {@link
+ * SummaryInformation}, a {@link DocumentSummaryInformation} or a
+ * general {@link PropertySet}. However, the current implementation
+ * went the other way round historically: the convenience classes came
+ * only late to my mind.</p>
+ *
+ * @author Rainer Klute (klute@rainer-klute.de)
+ * @version $Id$
+ * @since 2002-02-09
+ */
+public abstract class SpecialPropertySet extends PropertySet
+{
+
+ private PropertySet delegate;
+
+
+
+ public SpecialPropertySet(PropertySet ps)
+ {
+ delegate = ps;
+ }
+
+
+
+ public Word getByteOrder()
+ {
+ return delegate.getByteOrder();
+ }
+
+
+
+ public Word getFormat()
+ {
+ return delegate.getFormat();
+ }
+
+
+
+ public DWord getOSVersion()
+ {
+ return delegate.getOSVersion();
+ }
+
+
+
+ public ClassID getClassID()
+ {
+ return delegate.getClassID();
+ }
+
+
+
+ public int getSectionCount()
+ {
+ return delegate.getSectionCount();
+ }
+
+
+
+ public List getSections()
+ {
+ return delegate.getSections();
+ }
+
+
+
+ public boolean isSummaryInformation()
+ {
+ return delegate.isSummaryInformation();
+ }
+
+
+
+ public boolean isDocumentSummaryInformation()
+ {
+ return delegate.isDocumentSummaryInformation();
+ }
+
+
+
+ public Section getSingleSection()
+ {
+ return delegate.getSingleSection();
+ }
+
+}
diff --git a/src/java/org/apache/poi/hpsf/SummaryInformation.java b/src/java/org/apache/poi/hpsf/SummaryInformation.java
new file mode 100644
index 0000000000..1c591ab52e
--- /dev/null
+++ b/src/java/org/apache/poi/hpsf/SummaryInformation.java
@@ -0,0 +1,290 @@
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2000 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" must
+ * not be used to endorse or promote products derived from this
+ * software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * nor may "Apache" appear in their name, without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ * Portions of this software are based upon public domain software
+ * originally written at the National Center for Supercomputing Applications,
+ * University of Illinois, Urbana-Champaign.
+ */
+
+package org.apache.poi.hpsf;
+
+import java.io.*;
+import java.util.*;
+import org.apache.poi.hpsf.wellknown.*;
+
+/**
+ * <p>Convenience class representing a Summary Information stream in a
+ * Microsoft Office document.</p>
+ *
+ * @see DocumentSummaryInformation
+ *
+ * @author Rainer Klute (klute@rainer-klute.de)
+ * @version $Id$
+ * @since 2002-02-09
+ */
+public class SummaryInformation extends SpecialPropertySet
+{
+
+ /**
+ * <p>Creates a {@link SummaryInformation} from a given {@link
+ * PropertySet}.</p>
+ *
+ * @param ps A property set which should be created from a summary
+ * information stream.
+ *
+ * @throws UnexpectedPropertySetTypeException if <var>ps</var>
+ * does not contain a summary information stream.
+ */
+ public SummaryInformation(final PropertySet ps)
+ throws UnexpectedPropertySetTypeException
+ {
+ super(ps);
+ if (!isSummaryInformation())
+ throw new UnexpectedPropertySetTypeException
+ ("Not a " + getClass().getName());
+ }
+
+
+
+ /**
+ * <p>Returns the stream's title (or <code>null</code>).</p>
+ */
+ public String getTitle()
+ {
+ return (String) getProperty(PropertyIDMap.PID_TITLE);
+ }
+
+
+
+ /**
+ * <p>Returns the stream's subject (or <code>null</code>).</p>
+ */
+ public String getSubject()
+ {
+ return (String) getProperty(PropertyIDMap.PID_SUBJECT);
+ }
+
+
+
+ /**
+ * <p>Returns the stream's author (or <code>null</code>).</p>
+ */
+ public String getAuthor()
+ {
+ return (String) getProperty(PropertyIDMap.PID_AUTHOR);
+ }
+
+
+
+ /**
+ * <p>Returns the stream's keywords (or <code>null</code>).</p>
+ */
+ public String getKeywords()
+ {
+ return (String) getProperty(PropertyIDMap.PID_KEYWORDS);
+ }
+
+
+
+ /**
+ * <p>Returns the stream's comments (or <code>null</code>).</p>
+ */
+ public String getComments()
+ {
+ return (String) getProperty(PropertyIDMap.PID_COMMENTS);
+ }
+
+
+
+ /**
+ * <p>Returns the stream's template (or <code>null</code>).</p>
+ */
+ public String getTemplate()
+ {
+ return (String) getProperty(PropertyIDMap.PID_TEMPLATE);
+ }
+
+
+
+ /**
+ * <p>Returns the stream's last author (or <code>null</code>).</p>
+ */
+ public String getLastAuthor()
+ {
+ return (String) getProperty(PropertyIDMap.PID_LASTAUTHOR);
+ }
+
+
+
+ /**
+ * <p>Returns the stream's revision number (or
+ * <code>null</code>).
+ </p> */
+ public String getRevNumber()
+ {
+ return (String) getProperty(PropertyIDMap.PID_REVNUMBER);
+ }
+
+
+
+ /**
+ * <p>Returns the stream's edit time (or <code>null</code>).</p>
+ */
+ public Date getEditTime()
+ {
+ return (Date) getProperty(PropertyIDMap.PID_EDITTIME);
+ }
+
+
+
+ /**
+ * <p>Returns the stream's last printed time (or
+ * <code>null</code>).</p>
+ */
+ public Date getLastPrinted()
+ {
+ return (Date) getProperty(PropertyIDMap.PID_LASTPRINTED);
+ }
+
+
+
+ /**
+ * <p>Returns the stream's creation time (or
+ * <code>null</code>).</p>
+ */
+ public Date getCreateDateTime()
+ {
+ return (Date) getProperty(PropertyIDMap.PID_CREATE_DTM);
+ }
+
+
+
+ /**
+ * <p>Returns the stream's last save time (or
+ * <code>null</code>).</p>
+ */
+ public Date getLastSaveDateTime()
+ {
+ return (Date) getProperty(PropertyIDMap.PID_LASTSAVE_DTM);
+ }
+
+
+
+ /**
+ * <p>Returns the stream's page count or 0 if the {@link
+ * SummaryInformation} does not contain a page count.</p>
+ */
+ public int getPageCount()
+ {
+ return getPropertyIntValue(PropertyIDMap.PID_PAGECOUNT);
+ }
+
+
+
+ /**
+ * <p>Returns the stream's word count or 0 if the {@link
+ * SummaryInformation} does not contain a word count.</p>
+ */
+ public int getWordCount()
+ {
+ return getPropertyIntValue(PropertyIDMap.PID_WORDCOUNT);
+ }
+
+
+
+ /**
+ * <p>Returns the stream's char count or 0 if the {@link
+ * SummaryInformation} does not contain a char count.</p>
+ */
+ public int getCharCount()
+ {
+ return getPropertyIntValue(PropertyIDMap.PID_CHARCOUNT);
+ }
+
+
+
+ /**
+ * <p>Returns the stream's thumbnail (or <code>null</code>)
+ * <strong>when this method is implemented. Please note that the
+ * return type is likely to change!</strong>
+ */
+ public byte[] getThumbnail()
+ {
+ if (true)
+ throw new UnsupportedOperationException("FIXME");
+ return (byte[]) getProperty(PropertyIDMap.PID_THUMBNAIL);
+ }
+
+
+
+ /**
+ * <p>Returns the stream's application name (or
+ * <code>null</code>).</p>
+ */
+ public String getApplicationName()
+ {
+ return (String) getProperty(PropertyIDMap.PID_APPNAME);
+ }
+
+
+
+ /**
+ * <p>Returns the stream's security field or 0 if the {@link
+ * SummaryInformation} does not contain a security field.</p>
+ */
+ public int getSecurity()
+ {
+ return getPropertyIntValue(PropertyIDMap.PID_SECURITY);
+ }
+
+}
diff --git a/src/java/org/apache/poi/hpsf/UnexpectedPropertySetTypeException.java b/src/java/org/apache/poi/hpsf/UnexpectedPropertySetTypeException.java
new file mode 100644
index 0000000000..955a69729b
--- /dev/null
+++ b/src/java/org/apache/poi/hpsf/UnexpectedPropertySetTypeException.java
@@ -0,0 +1,97 @@
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2000 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" must
+ * not be used to endorse or promote products derived from this
+ * software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * nor may "Apache" appear in their name, without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ * Portions of this software are based upon public domain software
+ * originally written at the National Center for Supercomputing Applications,
+ * University of Illinois, Urbana-Champaign.
+ */
+
+package org.apache.poi.hpsf;
+
+/**
+ * <p>This exception is thrown if a certain type of property set is
+ * expected (e.g. a Document Summary Information) but the provided
+ * property set is not of that type.</p>
+ *
+ * <p>The constructors of this class are analogous to those of its
+ * superclass and documented there.</p>
+ *
+ * @author Rainer Klute (klute@rainer-klute.de)
+ * @version $Id$
+ * @since 2002-02-09
+ */
+public class UnexpectedPropertySetTypeException extends HPSFException
+{
+
+ public UnexpectedPropertySetTypeException()
+ {
+ super();
+ }
+
+ public UnexpectedPropertySetTypeException(final String msg)
+ {
+ super(msg);
+ }
+
+ public UnexpectedPropertySetTypeException(final Throwable reason)
+ {
+ super(reason);
+ }
+
+ public UnexpectedPropertySetTypeException(final String msg,
+ final Throwable reason)
+ {
+ super(msg, reason);
+ }
+
+}
diff --git a/src/java/org/apache/poi/hpsf/Util.java b/src/java/org/apache/poi/hpsf/Util.java
new file mode 100644
index 0000000000..28ae09d91b
--- /dev/null
+++ b/src/java/org/apache/poi/hpsf/Util.java
@@ -0,0 +1,188 @@
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2000 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" must
+ * not be used to endorse or promote products derived from this
+ * software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * nor may "Apache" appear in their name, without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ * Portions of this software are based upon public domain software
+ * originally written at the National Center for Supercomputing Applications,
+ * University of Illinois, Urbana-Champaign.
+ */
+
+package org.apache.poi.hpsf;
+
+import java.util.*;
+
+/**
+ * <p>Provides various static utility methods.</p>
+ *
+ * @author Rainer Klute (klute@rainer-klute.de)
+ * @version $Id$
+ * @since 2002-02-09
+ */
+public class Util
+{
+
+ /**
+ * <p>Checks whether two byte arrays <var>a</var> and <var>b</var>
+ * are equal. They are equal</p>
+ *
+ * <ul>
+ * <li><p>if they have the same length and</p></li>
+ *
+ * <li><p>if for each <var>i</var> with
+ * <var>i</var>&nbsp;&gt;=&nbsp;0 and
+ * <var>i</var>&nbsp;&lt;&nbsp;<var>a.length</var> holds
+ * <var>a</var>[<var>i</var>]&nbsp;==&nbsp;<var>b</var>[<var>i</var>].</p></li>
+ * </ul>
+ */
+ public static boolean equal(final byte[] a, final byte[] b)
+ {
+ if (a.length != b.length)
+ return false;
+ for (int i = 0; i < a.length; i++)
+ if (a[i] != b[i])
+ return false;
+ return true;
+ }
+
+
+
+ /**
+ * <p>Copies a part of a byte array into another byte array.</p>
+ */
+ public static void copy(final byte[] src, final int srcOffset,
+ final int length,
+ final byte[] dst, final int dstOffset)
+ {
+ for (int i = 0; i < length; i++)
+ dst[dstOffset + i] = src[srcOffset + i];
+ }
+
+
+
+ /**
+ * <p>Concatenates the contents of several byte arrays into a
+ * single one.</p>
+ *
+ * @param byteArrays The byte arrays to be concatened.
+ *
+ * @return A new byte array containing the concatenated byte
+ * arrays.
+ */
+ public static byte[] cat(final byte[][] byteArrays)
+ {
+ int capacity = 0;
+ for (int i = 0; i < byteArrays.length; i++)
+ capacity += byteArrays[i].length;
+ final byte[] result = new byte[capacity];
+ int r = 0;
+ for (int i = 0; i < byteArrays.length; i++)
+ for (int j = 0; j < byteArrays[i].length; j++)
+ result[r++] = byteArrays[i][j];
+ return result;
+ }
+
+
+
+ /**
+ * <p>Copies bytes from a source byte array into a new byte
+ * array.</p>
+ *
+ * @param src Copy from this byte array.
+ *
+ * @param offset Start copying here.
+ *
+ * @param length Copy this many bytes.
+ *
+ * @return The new byte array. Its length is number of copied bytes.
+ */
+ public static byte[] copy(final byte[] src, final int offset,
+ final int length)
+ {
+ final byte[] result = new byte[length];
+ copy(src, offset, length, result, 0);
+ return result;
+ }
+
+
+
+ /**
+ * <p>The difference between the Windows epoch (1601-01-01
+ * 00:00:00) and the Unix epoch (1970-01-01 00:00:00) in
+ * milliseconds: 11644473600000L. (Use your favorite spreadsheet
+ * program to verify the correctness of this value. By the way,
+ * did you notice that you can tell from the epochs which
+ * operating system is the modern one? :-))</p>
+ */
+ public final static long EPOCH_DIFF = 11644473600000L;
+
+ /**
+ * <p>Converts a Windows FILETIME into a {@link Date}. The Windows
+ * FILETIME structure holds a date and time associated with a
+ * file. The structure identifies a 64-bit integer specifying the
+ * number of 100-nanosecond intervals which have passed since
+ * January 1, 1601. This 64-bit value is split into the two double
+ * word stored in the structure.</p>
+ *
+ * @param high The higher double word of the FILETIME structure.
+ *
+ * @param low The lower double word of the FILETIME structure.
+ */
+ public static Date filetimeToDate(final int high, final int low)
+ {
+ final long filetime = ((long) high) << 32 | ((long) low);
+ final long ms_since_16010101 = filetime / (1000 * 10);
+ final long ms_since_19700101 = ms_since_16010101 - EPOCH_DIFF;
+ return new Date(ms_since_19700101);
+ }
+
+}
+
diff --git a/src/java/org/apache/poi/hpsf/Variant.java b/src/java/org/apache/poi/hpsf/Variant.java
new file mode 100644
index 0000000000..9d1b796b85
--- /dev/null
+++ b/src/java/org/apache/poi/hpsf/Variant.java
@@ -0,0 +1,341 @@
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2000 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" must
+ * not be used to endorse or promote products derived from this
+ * software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * nor may "Apache" appear in their name, without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ * Portions of this software are based upon public domain software
+ * originally written at the National Center for Supercomputing Applications,
+ * University of Illinois, Urbana-Champaign.
+ */
+
+package org.apache.poi.hpsf;
+
+/**
+ * <p>The <em>Variant</em> types as defined by Microsoft's COM. I
+ * found this information in <a href="http://www.marin.clara.net/COM/variant_type_definitions.htm">http://www.marin.clara.net/COM/variant_type_definitions.htm</a>.</p>
+ *
+ * <p>In the variant types descriptions the following shortcuts are
+ * used: <strong>[V]</strong> - may appear in a VARIANT,
+ * <strong>[T]</strong> - may appear in a TYPEDESC,
+ * <strong>[P]</strong> - may appear in an OLE property set,
+ * <strong>[S]</strong> - may appear in a Safe Array.</p>
+ *
+ * @author Rainer Klute (klute@rainer-klute.de)
+ * @version $Id$
+ * @since 2002-02-09
+ */
+public class Variant
+{
+
+ /**
+ * <p>[V][P] Nothing.</p>
+ */
+ public final static int VT_EMPTY = 0;
+
+ /**
+ * <p>[V][P] SQL style Null.</p>
+ */
+ public final static int VT_NULL = 1;
+
+ /**
+ * <p>[V][T][P][S] 2 byte signed int.</p>
+ */
+ public final static int VT_I2 = 2;
+
+ /**
+ * <p>[V][T][P][S] 4 byte signed int.</p>
+ */
+ public final static int VT_I4 = 3;
+
+ /**
+ * <p>[V][T][P][S] 4 byte real.</p>
+ */
+ public final static int VT_R4 = 4;
+
+ /**
+ * <p>[V][T][P][S] 8 byte real.</p>
+ */
+ public final static int VT_R8 = 5;
+
+ /**
+ * <p>[V][T][P][S] currency. <span style="background-color:
+ * #ffff00">How long is this? How is it to be
+ * interpreted?</span></p>
+ */
+ public final static int VT_CY = 6;
+
+ /**
+ * <p>[V][T][P][S] date. <span style="background-color:
+ * #ffff00">How long is this? How is it to be
+ * interpreted?</span></p>
+ */
+ public final static int VT_DATE = 7;
+
+ /**
+ * <p>[V][T][P][S] OLE Automation string. <span
+ * style="background-color: #ffff00">How long is this? How is it
+ * to be interpreted?</span></p>
+ */
+ public final static int VT_BSTR = 8;
+
+ /**
+ * <p>[V][T][P][S] IDispatch *. <span style="background-color:
+ * #ffff00">How long is this? How is it to be
+ * interpreted?</span></p>
+ */
+ public final static int VT_DISPATCH = 9;
+
+ /**
+ * <p>[V][T][S] SCODE. <span style="background-color:
+ * #ffff00">How long is this? How is it to be
+ * interpreted?</span></p>
+ */
+ public final static int VT_ERROR = 10;
+
+ /**
+ * <p>[V][T][P][S] True=-1, False=0.</p>
+ */
+ public final static int VT_BOOL = 11;
+
+ /**
+ * <p>[V][T][P][S] VARIANT *. <span style="background-color:
+ * #ffff00">How long is this? How is it to be
+ * interpreted?</span></p>
+ */
+ public final static int VT_VARIANT = 12;
+
+ /**
+ * <p>[V][T][S] IUnknown *. <span style="background-color:
+ * #ffff00">How long is this? How is it to be
+ * interpreted?</span></p>
+ */
+ public final static int VT_UNKNOWN = 13;
+
+ /**
+ * <p>[V][T][S] 16 byte fixed point.</p>
+ */
+ public final static int VT_DECIMAL = 14;
+
+ /**
+ * <p>[T] signed char.</p>
+ */
+ public final static int VT_I1 = 16;
+
+ /**
+ * <p>[V][T][P][S] unsigned char.</p>
+ */
+ public final static int VT_UI1 = 17;
+
+ /**
+ * <p>[T][P] unsigned short.</p>
+ */
+ public final static int VT_UI2 = 18;
+
+ /**
+ * <p>[T][P] unsigned int.</p>
+ */
+ public final static int VT_UI4 = 19;
+
+ /**
+ * <p>[T][P] signed 64-bit int.</p>
+ */
+ public final static int VT_I8 = 20;
+
+ /**
+ * <p>[T][P] unsigned 64-bit int.</p>
+ */
+ public final static int VT_UI8 = 21;
+
+ /**
+ * <p>[T] signed machine int.</p>
+ */
+ public final static int VT_INT = 22;
+
+ /**
+ * <p>[T] unsigned machine int.</p>
+ */
+ public final static int VT_UINT = 23;
+
+ /**
+ * <p>[T] C style void.</p>
+ */
+ public final static int VT_VOID = 24;
+
+ /**
+ * <p>[T] Standard return type. <span style="background-color:
+ * #ffff00">How long is this? How is it to be
+ * interpreted?</span></p>
+ */
+ public final static int VT_HRESULT = 25;
+
+ /**
+ * <p>[T] pointer type. <span style="background-color:
+ * #ffff00">How long is this? How is it to be
+ * interpreted?</span></p> */
+ public final static int VT_PTR = 26;
+
+ /**
+ * <p>[T] (use VT_ARRAY in VARIANT).</p> */
+ public final static int VT_SAFEARRAY = 27;
+
+ /**
+ * <p>[T] C style array. <span style="background-color:
+ * #ffff00">How long is this? How is it to be
+ * interpreted?</span></p>
+ */
+ public final static int VT_CARRAY = 28;
+
+ /**
+ * <p>[T] user defined type. <span style="background-color:
+ * #ffff00">How long is this? How is it to be
+ * interpreted?</span></p>
+ */
+ public final static int VT_USERDEFINED = 29;
+
+ /**
+ * <p>[T][P] null terminated string.</p>
+ */
+ public final static int VT_LPSTR = 30;
+
+ /**
+ * <p>[T][P] wide (Unicode) null terminated string.</p>
+ */
+ public final static int VT_LPWSTR = 31;
+
+ /**
+ * <p>[P] FILETIME. The FILETIME structure holds a date and time
+ * associated with a file. The structure identifies a 64-bit
+ * integer specifying the number of 100-nanosecond intervals which
+ * have passed since January 1, 1601. This 64-bit value is split
+ * into the two dwords stored in the structure.</p>
+ */
+ public final static int VT_FILETIME = 64;
+
+ /**
+ * <p>[P] Length prefixed bytes.</p>
+ */
+ public final static int VT_BLOB = 65;
+
+ /**
+ * <p>[P] Name of the stream follows.</p>
+ */
+ public final static int VT_STREAM = 66;
+
+ /**
+ * <p>[P] Name of the storage follows.</p>
+ */
+ public final static int VT_STORAGE = 67;
+
+ /**
+ * <p>[P] Stream contains an object. <span style="background-color:
+ * #ffff00">How long is this? How is it to be
+ * interpreted?</span></p>
+ */
+ public final static int VT_STREAMED_OBJECT = 68;
+
+ /**
+ * <p>[P] Storage contains an object. <span style="background-color:
+ * #ffff00">How long is this? How is it to be
+ * interpreted?</span></p>
+ */
+ public final static int VT_STORED_OBJECT = 69;
+
+ /**
+ * <p>[P] Blob contains an object. <span style="background-color:
+ * #ffff00">How long is this? How is it to be
+ * interpreted?</span></p>
+ */
+ public final static int VT_BLOB_OBJECT = 70;
+
+ /**
+ * <p>[P] Clipboard format. <span style="background-color:
+ * #ffff00">How long is this? How is it to be
+ * interpreted?</span></p>
+ */
+ public final static int VT_CF = 71;
+
+ /**
+ * <p>[P] A Class ID. <span style="background-color:
+ * #ffff00">How long is this? How is it to be
+ * interpreted?</span></p>
+ */
+ public final static int VT_CLSID = 72;
+
+ /**
+ * <p>[P] simple counted array. <span style="background-color:
+ * #ffff00">How long is this? How is it to be
+ * interpreted?</span></p>
+ */
+ public final static int VT_VECTOR = 0x1000;
+
+ /**
+ * <p>[V] SAFEARRAY*. <span style="background-color:
+ * #ffff00">How long is this? How is it to be
+ * interpreted?</span></p>
+ */
+ public final static int VT_ARRAY = 0x2000;
+
+ /**
+ * <p>[V] void* for local use. <span style="background-color:
+ * #ffff00">How long is this? How is it to be
+ * interpreted?</span></p>
+ */
+ public final static int VT_BYREF = 0x4000;
+
+ public final static int VT_RESERVED = 0x8000;
+
+ public final static int VT_ILLEGAL = 0xFFFF;
+
+ public final static int VT_ILLEGALMASKED = 0xFFF;
+
+ public final static int VT_TYPEMASK = 0xFFF;
+
+}
diff --git a/src/java/org/apache/poi/hpsf/littleendian/Byte.java b/src/java/org/apache/poi/hpsf/littleendian/Byte.java
new file mode 100644
index 0000000000..05c9cf6869
--- /dev/null
+++ b/src/java/org/apache/poi/hpsf/littleendian/Byte.java
@@ -0,0 +1,93 @@
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2000 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" must
+ * not be used to endorse or promote products derived from this
+ * software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * nor may "Apache" appear in their name, without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ * Portions of this software are based upon public domain software
+ * originally written at the National Center for Supercomputing Applications,
+ * University of Illinois, Urbana-Champaign.
+ */
+
+package org.apache.poi.hpsf.littleendian;
+
+/**
+ * <p>Represents a byte.</p>
+ *
+ * @author Rainer Klute (klute@rainer-klute.de)
+ * @version $Id$
+ * @since 2002-02-09
+ */
+public class Byte extends LittleEndian
+{
+
+ /**
+ * <p>Creates a {@link Byte} and reads its value from a byte
+ * array.</p>
+ *
+ * @param src The byte array to read from.
+ *
+ * @param offset The offset of the byte to read.
+ */
+ public Byte(final byte[] src, final int offset)
+ {
+ super(src, offset);
+ }
+
+
+
+ public final static int LENGTH = 1;
+
+ public int length()
+ {
+ return LENGTH;
+ }
+
+}
diff --git a/src/java/org/apache/poi/hpsf/littleendian/ClassID.java b/src/java/org/apache/poi/hpsf/littleendian/ClassID.java
new file mode 100644
index 0000000000..5a5d8135a3
--- /dev/null
+++ b/src/java/org/apache/poi/hpsf/littleendian/ClassID.java
@@ -0,0 +1,130 @@
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2000 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" must
+ * not be used to endorse or promote products derived from this
+ * software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * nor may "Apache" appear in their name, without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ * Portions of this software are based upon public domain software
+ * originally written at the National Center for Supercomputing Applications,
+ * University of Illinois, Urbana-Champaign.
+ */
+
+package org.apache.poi.hpsf.littleendian;
+
+import java.io.*;
+
+/**
+ * <p>Represents a class ID (16 bytes). Unlike other little-endian
+ * type the {@link ClassID} is not just 16 bytes stored in the wrong
+ * order. Instead, it is a double word (4 bytes) followed by two words
+ * (2 bytes each) followed by 8 bytes.</p>
+ *
+ * @see LittleEndian
+ *
+ * @author Rainer Klute (klute@rainer-klute.de)
+ * @version $Id$
+ * @since 2002-02-09
+ */
+public class ClassID extends LittleEndian
+{
+
+ /**
+ * <p>Creates a {@link ClassID} and reads its value from a byte
+ * array.</p>
+ *
+ * @param src The byte array to read from.
+ *
+ * @param offset The offset of the first byte to read.
+ */
+ public ClassID(final byte[] src, final int offset)
+ {
+ super(src, offset);
+ }
+
+
+
+ public final static int LENGTH = 16;
+
+ public int length()
+ {
+ return LENGTH;
+ }
+
+
+
+ public byte[] read(byte[] src, int offset)
+ {
+ LittleEndian[] b = new LittleEndian[11];
+ b[0] = new DWord(src, offset);
+ b[1] = new Word(src, offset += DWord.LENGTH);
+ b[2] = new Word(src, offset += Word.LENGTH);
+ b[3] = new Byte(src, offset += Word.LENGTH);
+ b[4] = new Byte(src, offset += Byte.LENGTH);
+ b[5] = new Byte(src, offset += Byte.LENGTH);
+ b[6] = new Byte(src, offset += Byte.LENGTH);
+ b[7] = new Byte(src, offset += Byte.LENGTH);
+ b[8] = new Byte(src, offset += Byte.LENGTH);
+ b[9] = new Byte(src, offset += Byte.LENGTH);
+ b[10] = new Byte(src, offset += Byte.LENGTH);
+ int capacity = 0;
+ for (int i = 0; i < b.length; i++)
+ capacity += b[i].getBytes().length;
+ bytes = new byte[capacity];
+ int pos = 0;
+ for (int i = 0; i < b.length; i++)
+ {
+ byte[] s = b[i].getBytes();
+ for (int j = 0; j < s.length; j++)
+ bytes[pos++] = s[j];
+ }
+ return bytes;
+ }
+
+}
diff --git a/src/java/org/apache/poi/hpsf/littleendian/DWord.java b/src/java/org/apache/poi/hpsf/littleendian/DWord.java
new file mode 100644
index 0000000000..353e4a5722
--- /dev/null
+++ b/src/java/org/apache/poi/hpsf/littleendian/DWord.java
@@ -0,0 +1,113 @@
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2000 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" must
+ * not be used to endorse or promote products derived from this
+ * software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * nor may "Apache" appear in their name, without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ * Portions of this software are based upon public domain software
+ * originally written at the National Center for Supercomputing Applications,
+ * University of Illinois, Urbana-Champaign.
+ */
+
+package org.apache.poi.hpsf.littleendian;
+
+/**
+ * <p>Represents a double word (4 bytes).</p>
+ *
+ * @author Rainer Klute (klute@rainer-klute.de)
+ * @version $Id$
+ * @since 2002-02-09
+ */
+public class DWord extends LittleEndian
+{
+
+ /**
+ * <p>Creates a {@link DWord} and reads its value from a byte
+ * array.</p>
+ *
+ * @param src The byte array to read from.
+ *
+ * @param offset The offset of the first byte to read.
+ */
+ public DWord(final byte[] src, final int offset)
+ {
+ super(src, offset);
+ }
+
+
+
+ public final static int LENGTH = 4;
+
+ public int length()
+ {
+ return LENGTH;
+ }
+
+
+
+ /**
+ * <p>Return the integral value of this {@link DWord}.</p>
+ *
+ * <p><strong>FIXME:</strong> Introduce a superclass for the
+ * numeric types and make this a method of the superclass!</p>
+ */
+ public int intValue()
+ {
+ int value = 0;
+ final int length = length();
+ for (int i = 0; i < length; i++)
+ {
+ final int b = 0xFF & bytes[i];
+ value = value << 8 | b;
+ }
+ return value;
+ }
+
+}
diff --git a/src/java/org/apache/poi/hpsf/littleendian/LittleEndian.java b/src/java/org/apache/poi/hpsf/littleendian/LittleEndian.java
new file mode 100644
index 0000000000..289ca88246
--- /dev/null
+++ b/src/java/org/apache/poi/hpsf/littleendian/LittleEndian.java
@@ -0,0 +1,134 @@
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2000 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" must
+ * not be used to endorse or promote products derived from this
+ * software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * nor may "Apache" appear in their name, without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ * Portions of this software are based upon public domain software
+ * originally written at the National Center for Supercomputing Applications,
+ * University of Illinois, Urbana-Champaign.
+ */
+
+package org.apache.poi.hpsf.littleendian;
+
+/**
+ * <p>A data item in the little-endian format. Little-endian means
+ * that lower bytes come before higher bytes.</p>
+ *
+ * @author Rainer Klute (klute@rainer-klute.de)
+ * @version $Id$
+ * @since 2002-02-09
+ */
+public abstract class LittleEndian
+{
+
+ /* This class could be optimized by not copying the bytes, but
+ * instead maintaining just references to the original byte
+ * arrays. However, before implementing this it should be
+ * investigated whether it is worth the while. */
+
+
+ /**
+ * <p>The bytes making out the little-endian field. They are in
+ * correct order, i.e. high-endian.</p>
+ */
+ protected byte[] bytes;
+
+
+
+ /**
+ * <p>Creates a {@link LittleEndian} and reads its value from a
+ * byte array.</p>
+ *
+ * @param src The byte array to read from.
+ *
+ * @param offset The offset of the first byte to read.
+ */
+ public LittleEndian(final byte[] src, final int offset)
+ {
+ read(src, offset);
+ }
+
+
+
+ /**
+ * <p>Returns the bytes making out the little-endian field in
+ * big-endian order.
+ </p> */
+ public byte[] getBytes()
+ {
+ return bytes;
+ }
+
+
+
+ /**
+ * <p>Reads the little-endian field from a byte array.</p>
+ *
+ * @param src The byte array to read from
+ *
+ * @param offset The offset within the <var>src</var> byte array
+ */
+ public byte[] read(final byte[] src, final int offset)
+ {
+ final int length = length();
+ bytes = new byte[length];
+ for (int i = 0; i < length; i++)
+ bytes[i] = src[offset + length - 1 - i];
+ return bytes;
+ }
+
+
+ /**
+ * <p>Returns the number of bytes of this little-endian field.</p>
+ */
+ public abstract int length();
+
+}
diff --git a/src/java/org/apache/poi/hpsf/littleendian/Word.java b/src/java/org/apache/poi/hpsf/littleendian/Word.java
new file mode 100644
index 0000000000..384ab4a313
--- /dev/null
+++ b/src/java/org/apache/poi/hpsf/littleendian/Word.java
@@ -0,0 +1,92 @@
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2000 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" must
+ * not be used to endorse or promote products derived from this
+ * software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * nor may "Apache" appear in their name, without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ * Portions of this software are based upon public domain software
+ * originally written at the National Center for Supercomputing Applications,
+ * University of Illinois, Urbana-Champaign.
+ */
+
+package org.apache.poi.hpsf.littleendian;
+
+/**
+ * <p>Represents a word (2 bytes).</p>
+ *
+ * @author Rainer Klute (klute@rainer-klute.de)
+ * @version $Id$
+ * @since 2002-02-09
+ */
+public class Word extends LittleEndian
+{
+
+ /**
+ * <p>Creates a {@link Word} and reads its value from a byte
+ * array.</p>
+ *
+ * @param src The byte array to read from.
+ *
+ * @param offset The offset of the first byte to read.
+ */
+ public Word(final byte[] src, final int offset)
+ {
+ super(src, offset);
+ }
+
+
+ public final static int LENGTH = 2;
+
+ public int length()
+ {
+ return LENGTH;
+ }
+
+}
diff --git a/src/java/org/apache/poi/hpsf/littleendian/package.html b/src/java/org/apache/poi/hpsf/littleendian/package.html
new file mode 100644
index 0000000000..c8ca6694b3
--- /dev/null
+++ b/src/java/org/apache/poi/hpsf/littleendian/package.html
@@ -0,0 +1,43 @@
+<!doctype html public "-//W3C//DTD HTML 4.0//EN//">
+
+<html>
+ <head>
+ <title></title>
+ </head>
+
+ <body>
+ <div>
+
+ <p>Handles little endian data types. Presently only reading little-endian
+ data from byte arrays is supported.</p>
+
+ <p><strong>FIXME:</strong> Implement writing little-endian data!</p>
+
+ <p>
+ @author Rainer Klute (klute@rainer-klute.de)
+ @version $Id$
+ @since 2002-02-09
+ </p>
+ </div>
+
+ </body>
+</html>
+
+<!-- Keep this comment at the end of the file
+Local variables:
+sgml-default-dtd-file:"HTML_4.0_Strict.ced"
+mode: html
+sgml-omittag:t
+sgml-shorttag:nil
+sgml-namecase-general:t
+sgml-general-insert-case:lower
+sgml-minimize-attributes:nil
+sgml-always-quote-attributes:t
+sgml-indent-step:1
+sgml-indent-data:t
+sgml-parent-document:nil
+sgml-exposed-tags:nil
+sgml-local-catalogs:nil
+sgml-local-ecat-files:nil
+End:
+-->
diff --git a/src/java/org/apache/poi/hpsf/package.html b/src/java/org/apache/poi/hpsf/package.html
new file mode 100644
index 0000000000..a4699c9f0f
--- /dev/null
+++ b/src/java/org/apache/poi/hpsf/package.html
@@ -0,0 +1,133 @@
+<!doctype html public "-//W3C//DTD HTML 4.0//EN//">
+
+<html>
+ <head>
+ <title>HPSF</title>
+ </head>
+
+ <body>
+ <div>
+
+ <p>Processes streams in the Horrible Property Set Format (HPSF) in POI
+ filesystems. Microsoft Office documents, i.e. POI filesystems, usually
+ contain meta data like author, title, last editing date etc. These items
+ are called <strong>properties</strong> and stored in
+ <strong>property set streams</strong> along with the document itself. These
+ streams are commonly named <tt>\005SummaryInformation</tt> and
+ <tt>\005DocumentSummaryInformation</tt>. However, a POI filesystem may
+ contain further property sets of other names or types.</p>
+
+ <p>In order to extract the properties from a POI filesystem, a property set
+ stream's contents must be parsed into a {@link
+ org.apache.poi.hpsf.PropertySet} instance. Its subclasses {@link
+ org.apache.poi.hpsf.SummaryInformation} and {@link
+ org.apache.poi.hpsf.DocumentSummaryInformation} deal with the well-known
+ property set streams <tt>\005SummaryInformation</tt> and
+ <tt>\005DocumentSummaryInformation</tt>. (However, the streams' names are
+ irrelevant. What counts is the property set's first section's format ID -
+ see below.)</p>
+
+ <p>The factory method {@link org.apache.poi.hpsf.PropertySetFactory#create}
+ creates a {@link org.apache.poi.hpsf.PropertySet} instance. This method
+ always returns the <strong>most specific property set</strong>: If it
+ identifies the stream data as a Summary Information or as a Document
+ Summary Information it returns an instance of the corresponding class, else
+ the general {@link org.apache.poi.hpsf.PropertySet}.</p>
+
+ <p>A {@link org.apache.poi.hpsf.PropertySet} contains a list of {@link
+ org.apache.poi.hpsf.Section}s which can be retrieved with {@link
+ org.apache.poi.hpsf.PropertySet#getSections}. Each {@link
+ org.apache.poi.hpsf.Section} contains a {@link
+ org.apache.poi.hpsf.Property} array which can be retrieved with {@link
+ org.apache.poi.hpsf.Section#getProperties}. Since the vast majority of
+ {@link org.apache.poi.hpsf.PropertySet}s contains only a single {@link
+ org.apache.poi.hpsf.Section}, the convenience method {@link
+ org.apache.poi.hpsf.PropertySet#getProperties} returns the properties of a
+ {@link org.apache.poi.hpsf.PropertySet}'s {@link
+ org.apache.poi.hpsf.Section} (throwing a {@link
+ org.apache.poi.hpsf.NoSingleSectionException} if the {@link
+ org.apache.poi.hpsf.PropertySet} contains more (or less) than exactly one
+ {@link org.apache.poi.hpsf.Section}).</p>
+
+ <p>Each {@link org.apache.poi.hpsf.Property} has an <strong>ID</strong>, a
+ <strong>type</strong>, and a <strong>value</strong> which can be retrieved
+ with {@link org.apache.poi.hpsf.Property#getID}, {@link
+ org.apache.poi.hpsf.Property#getType}, and {@link
+ org.apache.poi.hpsf.Property#getValue}, respectively. The value's class
+ depends on the property's type. <!-- FIXME: --> The current implementation
+ does not yet support all property types and restricts the values' classes
+ to {@link java.lang.String}, {@link java.lang.Integer} and {@link
+ java.util.Date}. A value of a yet unknown type is returned as a byte array
+ containing the value's origin bytes from the property set stream.</p>
+
+ <p>To retrieve the value of a specific {@link org.apache.poi.hpsf.Property},
+ use {@link org.apache.poi.hpsf.Section#getProperty} or {@link
+ org.apache.poi.hpsf.Section#getPropertyIntValue}.</p>
+
+ <p>The {@link org.apache.poi.hpsf.SummaryInformation} and {@link
+ org.apache.poi.hpsf.DocumentSummaryInformation} classes provide convenience
+ methods for retrieving well-known properties. For example, an application
+ that wants to retrieve a document's title string just calls {@link
+ org.apache.poi.hpsf.SummaryInformation#getTitle} instead of going through
+ the hassle of first finding out what the title's property ID is and then
+ using this ID to get the property's value.</p>
+
+ <div>
+ <h2>To Do</h2>
+
+ <p>The following is still left to be implemented:</p>
+
+ <ul>
+
+ <li>
+ <p>Property dictionaries</p>
+ </li>
+
+ <li>
+ <p>Writing property sets</p>
+ </li>
+
+ <li>
+ <p>Codepage support</p>
+ </li>
+
+ <li>
+ <p>Property type Unicode string</p>
+ </li>
+
+ <li>
+ <p>Further property types</p>
+ </li>
+
+ </ul>
+
+ </div>
+
+ <p>
+ @author Rainer Klute (klute@rainer-klute.de)
+ @version $Id$
+ @since 2002-02-09
+ </p>
+ </div>
+
+ </body>
+</html>
+
+<!-- Keep this comment at the end of the file
+Local variables:
+sgml-default-dtd-file:"HTML_4.0_Strict.ced"
+mode: html
+sgml-omittag:t
+sgml-shorttag:nil
+sgml-namecase-general:t
+sgml-general-insert-case:lower
+sgml-minimize-attributes:nil
+sgml-always-quote-attributes:t
+sgml-indent-step:1
+sgml-indent-data:t
+sgml-parent-document:nil
+sgml-exposed-tags:nil
+sgml-local-catalogs:nil
+sgml-local-ecat-files:nil
+End:
+-->
diff --git a/src/java/org/apache/poi/hpsf/wellknown/PropertyIDMap.java b/src/java/org/apache/poi/hpsf/wellknown/PropertyIDMap.java
new file mode 100644
index 0000000000..d2501888fb
--- /dev/null
+++ b/src/java/org/apache/poi/hpsf/wellknown/PropertyIDMap.java
@@ -0,0 +1,234 @@
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2000 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" must
+ * not be used to endorse or promote products derived from this
+ * software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * nor may "Apache" appear in their name, without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ * Portions of this software are based upon public domain software
+ * originally written at the National Center for Supercomputing Applications,
+ * University of Illinois, Urbana-Champaign.
+ */
+
+package org.apache.poi.hpsf.wellknown;
+
+import java.util.*;
+
+/**
+ * <p>This is a dictionary mapping property IDs to property ID
+ * strings.</p>
+ *
+ * <p>The methods {@link #getSummaryInformationProperties} and {@link
+ * #getDocumentSummaryInformationProperties} return singleton {@link
+ * PropertyIDMap}s. An application that wants to extend these maps
+ * should treat them as unmodifiable, copy them and modifiy the
+ * copies.</p>
+ *
+ * <p><strong>FIXME:</strong> Make the singletons
+ * unmodifiable. However, since this requires use a {@link HashMap}
+ * delegate instead of extending {@link HashMap} and would require a
+ * lot of stupid typing, I won't do it for the time being.</p>
+ *
+ * @author Rainer Klute (klute@rainer-klute.de)
+ * @version $Id$
+ * @since 2002-02-09
+ */
+public class PropertyIDMap extends HashMap
+{
+
+ /* The following definitions are for the Summary Information. */
+ public static final int PID_TITLE = 2;
+ public static final int PID_SUBJECT = 3;
+ public static final int PID_AUTHOR = 4;
+ public static final int PID_KEYWORDS = 5;
+ public static final int PID_COMMENTS = 6;
+ public static final int PID_TEMPLATE = 7;
+ public static final int PID_LASTAUTHOR = 8;
+ public static final int PID_REVNUMBER = 9;
+ public static final int PID_EDITTIME = 10;
+ public static final int PID_LASTPRINTED = 11;
+ public static final int PID_CREATE_DTM = 12;
+ public static final int PID_LASTSAVE_DTM = 13;
+ public static final int PID_PAGECOUNT = 14;
+ public static final int PID_WORDCOUNT = 15;
+ public static final int PID_CHARCOUNT = 16;
+ public static final int PID_THUMBNAIL = 17;
+ public static final int PID_APPNAME = 18;
+ public static final int PID_SECURITY = 19;
+
+ /* The following definitions are for the Document Summary Information. */
+ public static final int PID_CATEGORY = 2;
+ public static final int PID_PRESFORMAT = 3;
+ public static final int PID_BYTECOUNT = 4;
+ public static final int PID_LINECOUNT = 5;
+ public static final int PID_PARCOUNT = 6;
+ public static final int PID_SLIDECOUNT = 7;
+ public static final int PID_NOTECOUNT = 8;
+ public static final int PID_HIDDENCOUNT = 9;
+ public static final int PID_MMCLIPCOUNT = 10;
+ public static final int PID_SCALE = 11;
+ public static final int PID_HEADINGPAIR = 12;
+ public static final int PID_DOCPARTS = 13;
+ public static final int PID_MANAGER = 14;
+ public static final int PID_COMPANY = 15;
+ public static final int PID_LINKSDIRTY = 16;
+
+ private static PropertyIDMap summaryInformationProperties;
+ private static PropertyIDMap documentSummaryInformationProperties;
+
+
+
+ public PropertyIDMap(int initialCapacity, float loadFactor)
+ {
+ super(initialCapacity, loadFactor);
+ }
+
+
+
+ /**
+ * <p>Puts a ID string for an ID into the {@link
+ * PropertyIDMap}.</p>
+ *
+ * @param id The ID.
+ *
+ * @param idString The ID string.
+ */
+ public Object put(int id, String idString)
+ {
+ return put(new Integer(id), idString);
+ }
+
+
+
+ /**
+ * <p>Gets the ID string for an ID from the {@link
+ * PropertyIDMap}.</p>
+ *
+ * @param id The ID.
+ */
+ public Object get(int id)
+ {
+ return get(new Integer(id));
+ }
+
+
+
+ /**
+ * <p>Returns the Summary Information properties singleton.</p>
+ */
+ public static PropertyIDMap getSummaryInformationProperties()
+ {
+ if (summaryInformationProperties == null)
+ {
+ PropertyIDMap m = new PropertyIDMap(17, (float) 1.0);
+ m.put(PID_TITLE, "PID_TITLE");
+ m.put(PID_SUBJECT, "PID_SUBJECT");
+ m.put(PID_AUTHOR, "PID_AUTHOR");
+ m.put(PID_KEYWORDS, "PID_KEYWORDS");
+ m.put(PID_COMMENTS, "PID_COMMENTS");
+ m.put(PID_TEMPLATE, "PID_TEMPLATE");
+ m.put(PID_LASTAUTHOR, "PID_LASTAUTHOR");
+ m.put(PID_REVNUMBER, "PID_REVNUMBER");
+ m.put(PID_EDITTIME, "PID_EDITTIME");
+ m.put(PID_LASTPRINTED, "PID_LASTPRINTED");
+ m.put(PID_CREATE_DTM, "PID_CREATE_DTM");
+ m.put(PID_LASTSAVE_DTM, "PID_LASTSAVE_DTM");
+ m.put(PID_PAGECOUNT, "PID_PAGECOUNT");
+ m.put(PID_WORDCOUNT, "PID_WORDCOUNT");
+ m.put(PID_CHARCOUNT, "PID_CHARCOUNT");
+ m.put(PID_THUMBNAIL, "PID_THUMBNAIL");
+ m.put(PID_APPNAME, "PID_APPNAME");
+ m.put(PID_SECURITY, "PID_SECURITY");
+ summaryInformationProperties = m;
+ }
+ return summaryInformationProperties;
+ }
+
+
+
+ /**
+ * <p>Returns the Summary Information properties singleton.</p>
+ */
+ public static PropertyIDMap getDocumentSummaryInformationProperties()
+ {
+ if (documentSummaryInformationProperties == null)
+ {
+ PropertyIDMap m = new PropertyIDMap(17, (float) 1.0);
+ m.put(PID_CATEGORY, "PID_CATEGORY");
+ m.put(PID_PRESFORMAT, "PID_PRESFORMAT");
+ m.put(PID_BYTECOUNT, "PID_BYTECOUNT");
+ m.put(PID_LINECOUNT, "PID_LINECOUNT");
+ m.put(PID_PARCOUNT, "PID_PARCOUNT");
+ m.put(PID_SLIDECOUNT, "PID_SLIDECOUNT");
+ m.put(PID_NOTECOUNT, "PID_NOTECOUNT");
+ m.put(PID_HIDDENCOUNT, "PID_HIDDENCOUNT");
+ m.put(PID_MMCLIPCOUNT, "PID_MMCLIPCOUNT");
+ m.put(PID_SCALE, "PID_SCALE");
+ m.put(PID_HEADINGPAIR, "PID_HEADINGPAIR");
+ m.put(PID_DOCPARTS, "PID_DOCPARTS");
+ m.put(PID_MANAGER, "PID_MANAGER");
+ m.put(PID_COMPANY, "PID_COMPANY");
+ m.put(PID_LINKSDIRTY, "PID_LINKSDIRTY");
+ documentSummaryInformationProperties = m;
+ }
+ return documentSummaryInformationProperties;
+
+ }
+
+
+
+ public static void main(String args[])
+ {
+ PropertyIDMap s1 = getSummaryInformationProperties();
+ PropertyIDMap s2 = getDocumentSummaryInformationProperties();
+ System.out.println("s1: " + s1);
+ System.out.println("s2: " + s2);
+ }
+
+}
diff --git a/src/java/org/apache/poi/hpsf/wellknown/SectionIDMap.java b/src/java/org/apache/poi/hpsf/wellknown/SectionIDMap.java
new file mode 100644
index 0000000000..f3b893686c
--- /dev/null
+++ b/src/java/org/apache/poi/hpsf/wellknown/SectionIDMap.java
@@ -0,0 +1,213 @@
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2000 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" must
+ * not be used to endorse or promote products derived from this
+ * software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * nor may "Apache" appear in their name, without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ * Portions of this software are based upon public domain software
+ * originally written at the National Center for Supercomputing Applications,
+ * University of Illinois, Urbana-Champaign.
+ */
+
+package org.apache.poi.hpsf.wellknown;
+
+import java.util.*;
+
+/**
+ * <p>Maps section format IDs to {@link PropertyIDMap}s. It is
+ * initialized with two well-known section format IDs: those of the
+ * <tt>\005SummaryInformation</tt> stream and the
+ * <tt>\005DocumentSummaryInformation stream.</p>
+ *
+ * <p>If you have a section format ID you can use it as a key to query
+ * this map. If you get a {@link PropertyIDMap} returned your section
+ * is well-known and you can query the {@link PropertyIDMap} for PID
+ * strings. If you get back <code>null</code> you are on your own.</p>
+ *
+ * <p>This {@link Map} expects the byte arrays of section format IDs
+ * as keys. A key maps to a {@link PropertyIDMap} describing the
+ * property IDs in sections with the specified section format ID.</p>
+ *
+ * @author Rainer Klute (klute@rainer-klute.de)
+ * @version $Id$
+ * @since 2002-02-09
+ */
+public class SectionIDMap extends HashMap
+{
+
+ /**
+ * <p>The SummaryInformation's section's format ID.</p>
+ */
+ public final static byte[] SUMMARY_INFORMATION_ID =
+ new byte[]{(byte) 0xF2, (byte) 0x9F, (byte) 0x85, (byte) 0xE0,
+ (byte) 0x4F, (byte) 0xF9, (byte) 0x10, (byte) 0x68,
+ (byte) 0xAB, (byte) 0x91, (byte) 0x08, (byte) 0x00,
+ (byte) 0x2B, (byte) 0x27, (byte) 0xB3, (byte) 0xD9};
+
+ /**
+ * <p>The DocumentSummaryInformation's first section's format
+ * ID. The second section has a different format ID which is not
+ * well-known.</p>
+ */
+ public final static byte[] DOCUMENT_SUMMARY_INFORMATION_ID =
+ new byte[]{(byte) 0xD5, (byte) 0xCD, (byte) 0xD5, (byte) 0x02,
+ (byte) 0x2E, (byte) 0x9C, (byte) 0x10, (byte) 0x1B,
+ (byte) 0x93, (byte) 0x97, (byte) 0x08, (byte) 0x00,
+ (byte) 0x2B, (byte) 0x2C, (byte) 0xF9, (byte) 0xAE};
+
+ public final static String UNDEFINED = "[undefined]";
+
+
+
+ private static SectionIDMap defaultMap;
+
+
+
+ /**
+ * <p>Returns the singleton instance of the default {@link
+ * SectionIDMap}.</p>
+ */
+ public static SectionIDMap getInstance()
+ {
+ if (defaultMap == null)
+ {
+ final SectionIDMap m = new SectionIDMap();
+ m.put(SUMMARY_INFORMATION_ID,
+ PropertyIDMap.getSummaryInformationProperties());
+ m.put(DOCUMENT_SUMMARY_INFORMATION_ID,
+ PropertyIDMap.getDocumentSummaryInformationProperties());
+ defaultMap = m;
+ }
+ return defaultMap;
+ }
+
+
+
+ /**
+ * <p>Returns the property ID string that is associated with a
+ * given property ID in a section format ID's namespace.</p>
+ *
+ * @param sectionFormatID Each section format ID has its own name
+ * space of property ID strings and thus must be specified.
+ *
+ * @param pid The property ID
+ *
+ * @return The well-known property ID string associated with the
+ * property ID <var>pid</var> in the name space spanned by
+ * <var>sectionFormatID</var>. If the
+ * <var>pid</var>/<var>sectionFormatID</var> combination is not
+ * well-known, the string "[undefined]" is returned.
+ */
+ public static String getPIDString(final byte[] sectionFormatID,
+ final int pid)
+ {
+ final PropertyIDMap m =
+ (PropertyIDMap) getInstance().get(sectionFormatID);
+ if (m == null)
+ return UNDEFINED;
+ else
+ {
+ final String s = (String) m.get(pid);
+ if (s == null)
+ return UNDEFINED;
+ return s;
+ }
+ }
+
+
+
+ /**
+ * <p>Returns the {@link PropertyIDMap} for a given section format
+ * ID.</p>
+ */
+ public PropertyIDMap get(final byte[] sectionFormatID)
+ {
+ return (PropertyIDMap) super.get(new String(sectionFormatID));
+ }
+
+
+
+ /**
+ * <p>Returns the {@link PropertyIDMap} for a given section format
+ * ID.</p>
+ *
+ * @param sectionFormatID A section format ID as a
+ * <tt>byte[]</tt>.
+ *
+ * @deprecated Use {@link #get(byte[])} instead!
+ */
+ public Object get(final Object sectionFormatID)
+ {
+ return get((byte[]) sectionFormatID);
+ }
+
+
+
+ /**
+ * <p>Associates a section format ID with a {@link
+ * PropertyIDMap}.</p>
+ */
+ public Object put(final byte[] sectionFormatID,
+ final PropertyIDMap propertyIDMap)
+ {
+ return super.put(new String(sectionFormatID), propertyIDMap);
+ }
+
+
+
+ /**
+ * @deprecated Use {@link #put(byte[], PropertyIDMap)} instead!
+ */
+ public Object put(final Object key, final Object value)
+ {
+ return put((byte[]) key, (PropertyIDMap) value);
+ }
+
+}
diff --git a/src/java/org/apache/poi/hpsf/wellknown/package.html b/src/java/org/apache/poi/hpsf/wellknown/package.html
new file mode 100644
index 0000000000..1d12cf3309
--- /dev/null
+++ b/src/java/org/apache/poi/hpsf/wellknown/package.html
@@ -0,0 +1,44 @@
+<!doctype html public "-//W3C//DTD HTML 4.0//EN//">
+
+<html>
+ <head>
+ <title></title>
+ </head>
+
+ <body>
+ <div>
+
+ <p>Support classes for "well-known" section format IDs and property IDs. The
+ streams <tt>\005DocumentSummaryInformation</tt> and
+ <tt>\005SummaryInformation</tt> (or any streams with the same section
+ format IDs as the aforementioned) are considered well-known. So are most
+ property IDs in these streams.</p>
+
+ <p>
+ @author Rainer Klute (klute@rainer-klute.de)
+ @version $Id$
+ @since 2002-02-09
+ </p>
+ </div>
+
+ </body>
+</html>
+
+<!-- Keep this comment at the end of the file
+Local variables:
+sgml-default-dtd-file:"HTML_4.0_Strict.ced"
+mode: html
+sgml-omittag:t
+sgml-shorttag:nil
+sgml-namecase-general:t
+sgml-general-insert-case:lower
+sgml-minimize-attributes:nil
+sgml-always-quote-attributes:t
+sgml-indent-step:1
+sgml-indent-data:t
+sgml-parent-document:nil
+sgml-exposed-tags:nil
+sgml-local-catalogs:nil
+sgml-local-ecat-files:nil
+End:
+-->