You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by kl...@apache.org on 2006/03/03 17:58:00 UTC

svn commit: r382887 [2/3] - in /jakarta/poi/trunk/src: contrib/src/org/apache/poi/contrib/poibrowser/ documentation/content/xdocs/hpsf/ examples/src/org/apache/poi/hpsf/examples/ java/org/apache/poi/hpsf/ java/org/apache/poi/hpsf/wellknown/ java/org/ap...

Modified: jakarta/poi/trunk/src/java/org/apache/poi/hpsf/HPSFException.java
URL: http://svn.apache.org/viewcvs/jakarta/poi/trunk/src/java/org/apache/poi/hpsf/HPSFException.java?rev=382887&r1=382886&r2=382887&view=diff
==============================================================================
--- jakarta/poi/trunk/src/java/org/apache/poi/hpsf/HPSFException.java (original)
+++ jakarta/poi/trunk/src/java/org/apache/poi/hpsf/HPSFException.java Fri Mar  3 08:57:55 2006
@@ -1,4 +1,3 @@
-
 /* ====================================================================
    Copyright 2002-2004   Apache Software Foundation
 
@@ -18,12 +17,12 @@
 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>
- *
+ * <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 <a
- * href="mailto:klute@rainer-klute.de">&lt;klute@rainer-klute.de&gt;</a>
+ *         href="mailto:klute@rainer-klute.de">&lt;klute@rainer-klute.de&gt;</a>
  * @version $Id$
  * @since 2002-02-09
  */

Modified: jakarta/poi/trunk/src/java/org/apache/poi/hpsf/HPSFRuntimeException.java
URL: http://svn.apache.org/viewcvs/jakarta/poi/trunk/src/java/org/apache/poi/hpsf/HPSFRuntimeException.java?rev=382887&r1=382886&r2=382887&view=diff
==============================================================================
--- jakarta/poi/trunk/src/java/org/apache/poi/hpsf/HPSFRuntimeException.java (original)
+++ jakarta/poi/trunk/src/java/org/apache/poi/hpsf/HPSFRuntimeException.java Fri Mar  3 08:57:55 2006
@@ -1,4 +1,3 @@
-
 /* ====================================================================
    Copyright 2002-2004   Apache Software Foundation
 

Modified: jakarta/poi/trunk/src/java/org/apache/poi/hpsf/IllegalPropertySetDataException.java
URL: http://svn.apache.org/viewcvs/jakarta/poi/trunk/src/java/org/apache/poi/hpsf/IllegalPropertySetDataException.java?rev=382887&r1=382886&r2=382887&view=diff
==============================================================================
--- jakarta/poi/trunk/src/java/org/apache/poi/hpsf/IllegalPropertySetDataException.java (original)
+++ jakarta/poi/trunk/src/java/org/apache/poi/hpsf/IllegalPropertySetDataException.java Fri Mar  3 08:57:55 2006
@@ -1,4 +1,3 @@
-
 /* ====================================================================
    Copyright 2002-2004   Apache Software Foundation
 

Modified: jakarta/poi/trunk/src/java/org/apache/poi/hpsf/MarkUnsupportedException.java
URL: http://svn.apache.org/viewcvs/jakarta/poi/trunk/src/java/org/apache/poi/hpsf/MarkUnsupportedException.java?rev=382887&r1=382886&r2=382887&view=diff
==============================================================================
--- jakarta/poi/trunk/src/java/org/apache/poi/hpsf/MarkUnsupportedException.java (original)
+++ jakarta/poi/trunk/src/java/org/apache/poi/hpsf/MarkUnsupportedException.java Fri Mar  3 08:57:55 2006
@@ -1,4 +1,3 @@
-
 /* ====================================================================
    Copyright 2002-2004   Apache Software Foundation
 

Added: jakarta/poi/trunk/src/java/org/apache/poi/hpsf/MissingSectionException.java
URL: http://svn.apache.org/viewcvs/jakarta/poi/trunk/src/java/org/apache/poi/hpsf/MissingSectionException.java?rev=382887&view=auto
==============================================================================
--- jakarta/poi/trunk/src/java/org/apache/poi/hpsf/MissingSectionException.java (added)
+++ jakarta/poi/trunk/src/java/org/apache/poi/hpsf/MissingSectionException.java Fri Mar  3 08:57:55 2006
@@ -0,0 +1,76 @@
+/* ====================================================================
+   Copyright 2002-2006   Apache Software Foundation
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+        
+package org.apache.poi.hpsf;
+
+/**
+ * <p>This exception is thrown if one of the {@link PropertySet}'s
+ * convenience methods does not find a required {@link Section}.</p>
+ *
+ * <p>The constructors of this class are analogous to those of its
+ * superclass and documented there.</p>
+ *
+ * @author Rainer Klute <a
+ * href="mailto:klute@rainer-klute.de">&lt;klute@rainer-klute.de&gt;</a>
+ * @version $Id: NoSingleSectionException.java 353545 2004-04-09 13:05:39Z glens $
+ * @since 2006-02-08
+ */
+public class MissingSectionException extends HPSFRuntimeException
+{
+
+    /**
+     * <p>Constructor</p>
+     */
+    public MissingSectionException()
+    {
+        super();
+    }
+
+
+    /**
+     * <p>Constructor</p>
+     * 
+     * @param msg The exception's message string
+     */
+    public MissingSectionException(final String msg)
+    {
+        super(msg);
+    }
+
+
+    /**
+     * <p>Constructor</p>
+     * 
+     * @param reason This exception's underlying reason
+     */
+    public MissingSectionException(final Throwable reason)
+    {
+        super(reason);
+    }
+
+
+    /**
+     * <p>Constructor</p>
+     * 
+     * @param msg The exception's message string
+     * @param reason This exception's underlying reason
+     */
+    public MissingSectionException(final String msg, final Throwable reason)
+    {
+        super(msg, reason);
+    }
+
+}

Modified: jakarta/poi/trunk/src/java/org/apache/poi/hpsf/MutablePropertySet.java
URL: http://svn.apache.org/viewcvs/jakarta/poi/trunk/src/java/org/apache/poi/hpsf/MutablePropertySet.java?rev=382887&r1=382886&r2=382887&view=diff
==============================================================================
--- jakarta/poi/trunk/src/java/org/apache/poi/hpsf/MutablePropertySet.java (original)
+++ jakarta/poi/trunk/src/java/org/apache/poi/hpsf/MutablePropertySet.java Fri Mar  3 08:57:55 2006
@@ -1,5 +1,5 @@
 /* ====================================================================
-   Copyright 2002-2004   Apache Software Foundation
+   Copyright 2002-2006   Apache Software Foundation
 
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -26,6 +27,8 @@
 import java.util.LinkedList;
 import java.util.ListIterator;
 
+import org.apache.poi.poifs.filesystem.DirectoryEntry;
+import org.apache.poi.poifs.filesystem.Entry;
 import org.apache.poi.util.LittleEndian;
 import org.apache.poi.util.LittleEndianConsts;
 
@@ -151,7 +154,7 @@
      *
      * @param classID The property set stream's low-level "class ID" field.
      *
-     * @see #getClassID
+     * @see PropertySet#getClassID()
      */
     public void setClassID(final ClassID classID)
     {
@@ -205,9 +208,9 @@
         /* Write the property set's header. */
         length += TypeWriter.writeToStream(out, (short) getByteOrder());
         length += TypeWriter.writeToStream(out, (short) getFormat());
-        length += TypeWriter.writeToStream(out, (int) getOSVersion());
+        length += TypeWriter.writeToStream(out, getOSVersion());
         length += TypeWriter.writeToStream(out, getClassID());
-        length += TypeWriter.writeToStream(out, (int) nrSections);
+        length += TypeWriter.writeToStream(out, nrSections);
         int offset = OFFSET_HEADER;
 
         /* Write the section list, i.e. the references to the sections. Each
@@ -270,6 +273,33 @@
         psStream.close();
         final byte[] streamData = psStream.toByteArray();
         return new ByteArrayInputStream(streamData);
+    }
+
+    /**
+     * <p>Writes a property set to a document in a POI filesystem directory.</p>
+     *
+     * @param dir The directory in the POI filesystem to write the document to.
+     * @param name The document's name. If there is already a document with the
+     * same name in the directory the latter will be overwritten.
+     * 
+     * @throws WritingNotSupportedException
+     * @throws IOException
+     */
+    public void write(final DirectoryEntry dir, final String name)
+    throws WritingNotSupportedException, IOException
+    {
+        /* If there is already an entry with the same name, remove it. */
+        try
+        {
+            final Entry e = dir.getEntry(name);
+            e.delete();
+        }
+        catch (FileNotFoundException ex)
+        {
+            /* Entry not found, no need to remove it. */
+        }
+        /* Create the new entry. */
+        dir.createDocument(name, toInputStream());
     }
 
 }

Modified: jakarta/poi/trunk/src/java/org/apache/poi/hpsf/MutableSection.java
URL: http://svn.apache.org/viewcvs/jakarta/poi/trunk/src/java/org/apache/poi/hpsf/MutableSection.java?rev=382887&r1=382886&r2=382887&view=diff
==============================================================================
--- jakarta/poi/trunk/src/java/org/apache/poi/hpsf/MutableSection.java (original)
+++ jakarta/poi/trunk/src/java/org/apache/poi/hpsf/MutableSection.java Fri Mar  3 08:57:55 2006
@@ -1,5 +1,5 @@
 /* ====================================================================
-   Copyright 2002-2004   Apache Software Foundation
+   Copyright 2002-2006   Apache Software Foundation
 
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@
 import java.io.OutputStream;
 import java.util.Collections;
 import java.util.Comparator;
+import java.util.Date;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
@@ -107,7 +108,7 @@
      * @param formatID The section's format ID
      *
      * @see #setFormatID(byte[])
-     * @see #getFormatID
+     * @see Section#getFormatID
      */
     public void setFormatID(final ClassID formatID)
     {
@@ -123,7 +124,7 @@
      * are in big-endian format.
      *
      * @see #setFormatID(ClassID)
-     * @see #getFormatID
+     * @see Section#getFormatID
      */
     public void setFormatID(final byte[] formatID)
     {
@@ -155,10 +156,7 @@
 
 
     /**
-     * <p>Sets the value of the property with the specified ID. If a
-     * property with this ID is not yet present in the section, it
-     * will be added. An already present property with the specified
-     * ID will be overwritten.</p>
+     * <p>Sets the string value of the property with the specified ID.</p>
      *
      * @param id The property's ID
      * @param value The property's value. It will be written as a Unicode
@@ -176,6 +174,57 @@
 
 
     /**
+     * <p>Sets the int value of the property with the specified ID.</p>
+     *
+     * @param id The property's ID
+     * @param value The property's value.
+     *
+     * @see #setProperty(int, long, Object)
+     * @see #getProperty
+     */
+    public void setProperty(final int id, final int value)
+    {
+        setProperty(id, Variant.VT_I4, new Integer(value));
+        dirty = true;
+    }
+
+
+
+    /**
+     * <p>Sets the long value of the property with the specified ID.</p>
+     *
+     * @param id The property's ID
+     * @param value The property's value.
+     *
+     * @see #setProperty(int, long, Object)
+     * @see #getProperty
+     */
+    public void setProperty(final int id, final long value)
+    {
+        setProperty(id, Variant.VT_I8, new Long(value));
+        dirty = true;
+    }
+
+
+
+    /**
+     * <p>Sets the boolean value of the property with the specified ID.</p>
+     *
+     * @param id The property's ID
+     * @param value The property's value.
+     *
+     * @see #setProperty(int, long, Object)
+     * @see #getProperty
+     */
+    public void setProperty(final int id, final boolean value)
+    {
+        setProperty(id, Variant.VT_BOOL, new Boolean(value));
+        dirty = true;
+    }
+
+
+
+    /**
      * <p>Sets the value and the variant type of the property with the
      * specified ID. If a property with this ID is not yet present in
      * the section, it will be added. An already present property with
@@ -204,15 +253,11 @@
 
 
     /**
-     * <p>Sets a property. If a property with the same ID is not yet present in
-     * the section, the property will be added to the section. If there is
-     * already a property with the same ID present in the section, it will be
-     * overwritten.</p>
+     * <p>Sets a property.</p>
      *
-     * @param p The property to be added to the section
+     * @param p The property to be set.
      *
      * @see #setProperty(int, long, Object)
-     * @see #setProperty(int, String)
      * @see #getProperty
      * @see Variant
      */
@@ -257,7 +302,7 @@
      */
     protected void setPropertyBooleanValue(final int id, final boolean value)
     {
-        setProperty(id, (long) Variant.VT_BOOL, new Boolean(value));
+        setProperty(id, Variant.VT_BOOL, new Boolean(value));
     }
 
 
@@ -296,6 +341,8 @@
      * properties) and the properties themselves.</p>
      *
      * @return the section's length in bytes.
+     * @throws WritingNotSupportedException 
+     * @throws IOException 
      */
     private int calcSize() throws WritingNotSupportedException, IOException 
     {
@@ -372,7 +419,7 @@
                 /* Warning: The codepage property is not set although a
                  * dictionary is present. In order to cope with this problem we
                  * add the codepage property and set it to Unicode. */
-                setProperty(PropertyIDMap.PID_CODEPAGE, (long) Variant.VT_I2,
+                setProperty(PropertyIDMap.PID_CODEPAGE, Variant.VT_I2,
                             new Integer(Constants.CP_UNICODE));
             codepage = getCodepage();
         }
@@ -474,16 +521,15 @@
                     sLength++;
                 length += TypeWriter.writeUIntToStream(out, key.longValue());
                 length += TypeWriter.writeUIntToStream(out, sLength);
-                final char[] ca = value.toCharArray();
-                for (int j = 0; j < ca.length; j++)
+                final byte[] ca =
+                    value.getBytes(VariantSupport.codepageToEncoding(codepage));
+                for (int j = 2; j < ca.length; j += 2)
                 {
-                    int high = (ca[j] & 0x0ff00) >> 8;
-                    int low  = (ca[j] & 0x000ff);
-                    out.write(low);
-                    out.write(high);
+                    out.write(ca[j+1]);
+                    out.write(ca[j]);
                     length += 2;
-                    sLength--;
                 }
+                sLength -= value.length();
                 while (sLength > 0)
                 {
                     out.write(0x00);
@@ -608,6 +654,62 @@
             /* Setting the dictionary to null means to remove property 0.
              * However, it does not mean to remove property 1 (codepage). */
             removeProperty(PropertyIDMap.PID_DICTIONARY);
+    }
+
+
+
+    /**
+     * <p>Sets a property.</p>
+     * 
+     * @param id The property ID.
+     * @param value The property's value. The value's class must be one of those
+     *        supported by HPSF.
+     */
+    public void setProperty(final int id, final Object value)
+    {
+        if (value instanceof String)
+            setProperty(id, (String) value);
+        else if (value instanceof Long)
+            setProperty(id, ((Long) value).longValue());
+        else if (value instanceof Integer)
+            setProperty(id, ((Integer) value).intValue());
+        else if (value instanceof Short)
+            setProperty(id, ((Short) value).intValue());
+        else if (value instanceof Boolean)
+            setProperty(id, ((Boolean) value).booleanValue());
+        else if (value instanceof Date)
+            setProperty(id, Variant.VT_FILETIME, value);
+        else
+            throw new HPSFRuntimeException(
+                    "HPSF does not support properties of type " +
+                    value.getClass().getName() + ".");
+    }
+
+
+
+    /**
+     * <p>Removes all properties from the section including 0 (dictionary) and
+     * 1 (codepage).</p>
+     */
+    public void clear()
+    {
+        final Property[] properties = getProperties();
+        for (int i = 0; i < properties.length; i++)
+        {
+            final Property p = properties[i];
+            removeProperty(p.getID());
+        }
+    }
+
+    /**
+     * <p>Sets the codepage.</p>
+     *
+     * @param codepage the codepage
+     */
+    public void setCodepage(final int codepage)
+    {
+        setProperty(PropertyIDMap.PID_CODEPAGE, Variant.VT_I2,
+                new Integer(codepage));
     }
 
 }

Modified: jakarta/poi/trunk/src/java/org/apache/poi/hpsf/NoFormatIDException.java
URL: http://svn.apache.org/viewcvs/jakarta/poi/trunk/src/java/org/apache/poi/hpsf/NoFormatIDException.java?rev=382887&r1=382886&r2=382887&view=diff
==============================================================================
--- jakarta/poi/trunk/src/java/org/apache/poi/hpsf/NoFormatIDException.java (original)
+++ jakarta/poi/trunk/src/java/org/apache/poi/hpsf/NoFormatIDException.java Fri Mar  3 08:57:55 2006
@@ -1,4 +1,3 @@
-
 /* ====================================================================
    Copyright 2002-2004   Apache Software Foundation
 

Modified: jakarta/poi/trunk/src/java/org/apache/poi/hpsf/NoSingleSectionException.java
URL: http://svn.apache.org/viewcvs/jakarta/poi/trunk/src/java/org/apache/poi/hpsf/NoSingleSectionException.java?rev=382887&r1=382886&r2=382887&view=diff
==============================================================================
--- jakarta/poi/trunk/src/java/org/apache/poi/hpsf/NoSingleSectionException.java (original)
+++ jakarta/poi/trunk/src/java/org/apache/poi/hpsf/NoSingleSectionException.java Fri Mar  3 08:57:55 2006
@@ -1,4 +1,3 @@
-
 /* ====================================================================
    Copyright 2002-2004   Apache Software Foundation
 

Modified: jakarta/poi/trunk/src/java/org/apache/poi/hpsf/Property.java
URL: http://svn.apache.org/viewcvs/jakarta/poi/trunk/src/java/org/apache/poi/hpsf/Property.java?rev=382887&r1=382886&r2=382887&view=diff
==============================================================================
--- jakarta/poi/trunk/src/java/org/apache/poi/hpsf/Property.java (original)
+++ jakarta/poi/trunk/src/java/org/apache/poi/hpsf/Property.java Fri Mar  3 08:57:55 2006
@@ -1,5 +1,5 @@
 /* ====================================================================
-   Copyright 2002-2004   Apache Software Foundation
+   Copyright 2002-2006   Apache Software Foundation
 
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
@@ -108,6 +108,22 @@
 
 
     /**
+     * <p>Creates a property.</p>
+     * 
+     * @param id the property's ID.
+     * @param type the property's type, see {@link Variant}.
+     * @param value the property's value. Only certain types are allowed, see {@link Variant}. 
+     */
+    public Property(final long id, final long type, final Object value)
+    {
+        this.id = id;
+        this.type = type;
+        this.value = value;
+    }
+
+
+
+    /**
      * <p>Creates a {@link Property} instance by reading its bytes
      * from the property set stream.</p>
      *
@@ -222,12 +238,15 @@
                 {
                     /* The length is the number of characters, i.e. the number
                      * of bytes is twice the number of the characters. */
-                    for (int j = 0; j < sLength; j++)
+                    final int nrBytes = (int) (sLength * 2);
+                    final byte[] h = new byte[nrBytes];
+                    for (int i2 = 0; i2 < nrBytes; i2 += 2)
                     {
-                        final int i1 = o + (j * 2);
-                        final int i2 = i1 + 1;
-                        b.append((char) ((src[i2] << 8) + src[i1]));
+                        h[i2] = src[o + i2 + 1];
+                        h[i2 + 1] = src[o + i2];
                     }
+                    b.append(new String(h, 0, nrBytes,
+                            VariantSupport.codepageToEncoding(codepage)));
                     break;
                 }
                 default:

Modified: jakarta/poi/trunk/src/java/org/apache/poi/hpsf/PropertySet.java
URL: http://svn.apache.org/viewcvs/jakarta/poi/trunk/src/java/org/apache/poi/hpsf/PropertySet.java?rev=382887&r1=382886&r2=382887&view=diff
==============================================================================
--- jakarta/poi/trunk/src/java/org/apache/poi/hpsf/PropertySet.java (original)
+++ jakarta/poi/trunk/src/java/org/apache/poi/hpsf/PropertySet.java Fri Mar  3 08:57:55 2006
@@ -1,6 +1,5 @@
-
 /* ====================================================================
-   Copyright 2002-2004   Apache Software Foundation
+   Copyright 2002-2006   Apache Software Foundation
 
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
@@ -402,8 +401,10 @@
      *
      * @param src Byte array containing the property set stream
      * @param offset The property set stream starts at this offset
-     * from the beginning of <var>src</src>
+     * from the beginning of <var>src</var>
      * @param length Length of the property set stream.
+     * @throws UnsupportedEncodingException if HPSF does not (yet) support the
+     * property set's character encoding.
      */
     private void init(final byte[] src, final int offset, final int length)
     throws UnsupportedEncodingException
@@ -482,7 +483,7 @@
     public boolean isDocumentSummaryInformation()
     {
         return Util.equal(((Section) sections.get(0)).getFormatID().getBytes(),
-                          SectionIDMap.DOCUMENT_SUMMARY_INFORMATION_ID);
+                          SectionIDMap.DOCUMENT_SUMMARY_INFORMATION_ID[0]);
     }
 
 
@@ -492,9 +493,7 @@
      * 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>
+     * Section}.</p>
      *
      * @return The properties of the only {@link Section} of this
      * {@link PropertySet}.
@@ -504,7 +503,7 @@
     public Property[] getProperties()
         throws NoSingleSectionException
     {
-        return getSingleSection().getProperties();
+        return getFirstSection().getProperties();
     }
 
 
@@ -522,7 +521,7 @@
      */
     protected Object getProperty(final int id) throws NoSingleSectionException
     {
-        return getSingleSection().getProperty(id);
+        return getFirstSection().getProperty(id);
     }
 
 
@@ -543,7 +542,7 @@
     protected boolean getPropertyBooleanValue(final int id)
         throws NoSingleSectionException
     {
-        return getSingleSection().getPropertyBooleanValue(id);
+        return getFirstSection().getPropertyBooleanValue(id);
     }
 
 
@@ -563,7 +562,7 @@
     protected int getPropertyIntValue(final int id)
         throws NoSingleSectionException
     {
-        return getSingleSection().getPropertyIntValue(id);
+        return getFirstSection().getPropertyIntValue(id);
     }
 
 
@@ -585,7 +584,21 @@
      */
     public boolean wasNull() throws NoSingleSectionException
     {
-        return getSingleSection().wasNull();
+        return getFirstSection().wasNull();
+    }
+
+
+
+    /**
+     * <p>Gets the {@link PropertySet}'s first section.</p>
+     *
+     * @return The {@link PropertySet}'s first section.
+     */
+    public Section getFirstSection()
+    {
+        if (getSectionCount() < 1)
+            throw new MissingSectionException("Property set does not contain any sections.");
+        return ((Section) sections.get(0));
     }
 
 

Modified: jakarta/poi/trunk/src/java/org/apache/poi/hpsf/PropertySetFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/poi/trunk/src/java/org/apache/poi/hpsf/PropertySetFactory.java?rev=382887&r1=382886&r2=382887&view=diff
==============================================================================
--- jakarta/poi/trunk/src/java/org/apache/poi/hpsf/PropertySetFactory.java (original)
+++ jakarta/poi/trunk/src/java/org/apache/poi/hpsf/PropertySetFactory.java Fri Mar  3 08:57:55 2006
@@ -1,6 +1,5 @@
-
 /* ====================================================================
-   Copyright 2002-2004   Apache Software Foundation
+   Copyright 2002-2006   Apache Software Foundation
 
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
@@ -22,6 +21,8 @@
 import java.io.UnsupportedEncodingException;
 import java.rmi.UnexpectedException;
 
+import org.apache.poi.hpsf.wellknown.SectionIDMap;
+
 /**
  * <p>Factory class to create instances of {@link SummaryInformation},
  * {@link DocumentSummaryInformation} and {@link PropertySet}.</p>
@@ -71,6 +72,52 @@
             /* This exception will never be throws because we already checked
              * explicitly for this case above. */
             throw new UnexpectedException(ex.toString());
+        }
+    }
+
+
+
+    /**
+     * <p>Creates a new summary information.</p>
+     *
+     * @return the new summary information.
+     */
+    public static SummaryInformation newSummaryInformation()
+    {
+        final MutablePropertySet ps = new MutablePropertySet();
+        final MutableSection s = (MutableSection) ps.getFirstSection();
+        s.setFormatID(SectionIDMap.SUMMARY_INFORMATION_ID);
+        try
+        {
+            return new SummaryInformation(ps);
+        }
+        catch (UnexpectedPropertySetTypeException ex)
+        {
+            /* This should never happen. */
+            throw new HPSFRuntimeException(ex);
+        }
+    }
+
+
+
+    /**
+     * <p>Creates a new document summary information.</p>
+     *
+     * @return the new document summary information.
+     */
+    public static DocumentSummaryInformation newDocumentSummaryInformation()
+    {
+        final MutablePropertySet ps = new MutablePropertySet();
+        final MutableSection s = (MutableSection) ps.getFirstSection();
+        s.setFormatID(SectionIDMap.DOCUMENT_SUMMARY_INFORMATION_ID[0]);
+        try
+        {
+            return new DocumentSummaryInformation(ps);
+        }
+        catch (UnexpectedPropertySetTypeException ex)
+        {
+            /* This should never happen. */
+            throw new HPSFRuntimeException(ex);
         }
     }
 

Modified: jakarta/poi/trunk/src/java/org/apache/poi/hpsf/ReadingNotSupportedException.java
URL: http://svn.apache.org/viewcvs/jakarta/poi/trunk/src/java/org/apache/poi/hpsf/ReadingNotSupportedException.java?rev=382887&r1=382886&r2=382887&view=diff
==============================================================================
--- jakarta/poi/trunk/src/java/org/apache/poi/hpsf/ReadingNotSupportedException.java (original)
+++ jakarta/poi/trunk/src/java/org/apache/poi/hpsf/ReadingNotSupportedException.java Fri Mar  3 08:57:55 2006
@@ -1,4 +1,3 @@
-
 /* ====================================================================
    Copyright 2002-2004   Apache Software Foundation
 

Modified: jakarta/poi/trunk/src/java/org/apache/poi/hpsf/Section.java
URL: http://svn.apache.org/viewcvs/jakarta/poi/trunk/src/java/org/apache/poi/hpsf/Section.java?rev=382887&r1=382886&r2=382887&view=diff
==============================================================================
--- jakarta/poi/trunk/src/java/org/apache/poi/hpsf/Section.java (original)
+++ jakarta/poi/trunk/src/java/org/apache/poi/hpsf/Section.java Fri Mar  3 08:57:55 2006
@@ -1,6 +1,5 @@
-
 /* ====================================================================
-   Copyright 2002-2004   Apache Software Foundation
+   Copyright 2002-2006   Apache Software Foundation
 
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
@@ -278,9 +277,12 @@
         for (final Iterator i = propertyList.iterator(); i.hasNext();)
         {
             ple = (PropertyListEntry) i.next();
-            properties[i1++] = new Property(ple.id, src,
-                                            this.offset + ple.offset,
-                                            ple.length, codepage);
+            Property p = new Property(ple.id, src,
+                    this.offset + ple.offset,
+                    ple.length, codepage);
+            if (p.getID() == PropertyIDMap.PID_CODEPAGE)
+                p = new Property(p.getID(), p.getType(), new Integer(codepage));
+            properties[i1++] = p;
         }
 
         /*
@@ -359,15 +361,15 @@
      */
     protected int getPropertyIntValue(final long id)
     {
-        final Long i;
+        final Number i;
         final Object o = getProperty(id);
         if (o == null)
             return 0;
-        if (!(o instanceof Long))
+        if (!(o instanceof Long || o instanceof Integer))
             throw new HPSFRuntimeException
                 ("This property is not an integer type, but " +
                  o.getClass().getName() + ".");
-        i = (Long) o;
+        i = (Number) o;
         return i.intValue();
     }
 
@@ -545,6 +547,10 @@
     /**
      * <p>Removes a field from a property array. The resulting array is
      * compactified and returned.</p>
+     *
+     * @param pa The property array. 
+     * @param i The index of the field to be removed.
+     * @return the compactified array.
      */
     private Property[] remove(final Property[] pa, final int i)
     {
@@ -629,7 +635,10 @@
     {
         final Integer codepage =
             (Integer) getProperty(PropertyIDMap.PID_CODEPAGE);
-        return codepage != null ? codepage.intValue() : -1;
+        if (codepage == null)
+            return -1;
+        int cp = codepage.intValue();
+        return cp;
     }
 
 }

Modified: jakarta/poi/trunk/src/java/org/apache/poi/hpsf/SpecialPropertySet.java
URL: http://svn.apache.org/viewcvs/jakarta/poi/trunk/src/java/org/apache/poi/hpsf/SpecialPropertySet.java?rev=382887&r1=382886&r2=382887&view=diff
==============================================================================
--- jakarta/poi/trunk/src/java/org/apache/poi/hpsf/SpecialPropertySet.java (original)
+++ jakarta/poi/trunk/src/java/org/apache/poi/hpsf/SpecialPropertySet.java Fri Mar  3 08:57:55 2006
@@ -1,6 +1,5 @@
-
 /* ====================================================================
-   Copyright 2002-2004   Apache Software Foundation
+   Copyright 2002-2006   Apache Software Foundation
 
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
@@ -17,8 +16,13 @@
         
 package org.apache.poi.hpsf;
 
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
 import java.util.List;
 
+import org.apache.poi.poifs.filesystem.DirectoryEntry;
+
 /**
  * <p>Abstract superclass for the convenience classes {@link
  * SummaryInformation} and {@link DocumentSummaryInformation}.</p>
@@ -50,25 +54,38 @@
  * @version $Id$
  * @since 2002-02-09
  */
-public abstract class SpecialPropertySet extends PropertySet
+public abstract class SpecialPropertySet extends MutablePropertySet
 {
 
     /**
      * <p>The "real" property set <code>SpecialPropertySet</code>
      * delegates to.</p>
      */
-    private PropertySet delegate;
+    private MutablePropertySet delegate;
 
 
 
     /**
      * <p>Creates a <code>SpecialPropertySet</code>.
      *
-     * @param ps The property set encapsulated by the
+     * @param ps The property set to be encapsulated by the
      * <code>SpecialPropertySet</code>
      */
     public SpecialPropertySet(final PropertySet ps)
     {
+        delegate = new MutablePropertySet(ps);
+    }
+
+
+
+    /**
+     * <p>Creates a <code>SpecialPropertySet</code>.
+     *
+     * @param ps The mutable property set to be encapsulated by the
+     * <code>SpecialPropertySet</code>
+     */
+    public SpecialPropertySet(final MutablePropertySet ps)
+    {
         delegate = ps;
     }
 
@@ -157,9 +174,178 @@
     /**
      * @see PropertySet#getSingleSection
      */
-    public Section getSingleSection()
+    public Section getFirstSection()
+    {
+        return delegate.getFirstSection();
+    }
+
+
+    /**
+     * @see org.apache.poi.hpsf.MutablePropertySet#addSection(org.apache.poi.hpsf.Section)
+     */
+    public void addSection(final Section section)
+    {
+        delegate.addSection(section);
+    }
+
+
+
+    /**
+     * @see org.apache.poi.hpsf.MutablePropertySet#clearSections()
+     */
+    public void clearSections()
+    {
+        delegate.clearSections();
+    }
+
+
+
+    /**
+     * @see org.apache.poi.hpsf.MutablePropertySet#setByteOrder(int)
+     */
+    public void setByteOrder(final int byteOrder)
+    {
+        delegate.setByteOrder(byteOrder);
+    }
+
+
+
+    /**
+     * @see org.apache.poi.hpsf.MutablePropertySet#setClassID(org.apache.poi.hpsf.ClassID)
+     */
+    public void setClassID(final ClassID classID)
+    {
+        delegate.setClassID(classID);
+    }
+
+
+
+    /**
+     * @see org.apache.poi.hpsf.MutablePropertySet#setFormat(int)
+     */
+    public void setFormat(final int format)
+    {
+        delegate.setFormat(format);
+    }
+
+
+
+    /**
+     * @see org.apache.poi.hpsf.MutablePropertySet#setOSVersion(int)
+     */
+    public void setOSVersion(final int osVersion)
+    {
+        delegate.setOSVersion(osVersion);
+    }
+
+
+
+    /**
+     * @see org.apache.poi.hpsf.MutablePropertySet#toInputStream()
+     */
+    public InputStream toInputStream() throws IOException, WritingNotSupportedException
+    {
+        return delegate.toInputStream();
+    }
+
+
+
+    /**
+     * @see org.apache.poi.hpsf.MutablePropertySet#write(org.apache.poi.poifs.filesystem.DirectoryEntry, java.lang.String)
+     */
+    public void write(final DirectoryEntry dir, final String name) throws WritingNotSupportedException, IOException
+    {
+        delegate.write(dir, name);
+    }
+
+
+
+    /**
+     * @see org.apache.poi.hpsf.MutablePropertySet#write(java.io.OutputStream)
+     */
+    public void write(final OutputStream out) throws WritingNotSupportedException, IOException
+    {
+        delegate.write(out);
+    }
+
+
+
+    /**
+     * @see org.apache.poi.hpsf.PropertySet#equals(java.lang.Object)
+     */
+    public boolean equals(final Object o)
+    {
+        return delegate.equals(o);
+    }
+
+
+
+    /**
+     * @see org.apache.poi.hpsf.PropertySet#getProperties()
+     */
+    public Property[] getProperties() throws NoSingleSectionException
+    {
+        return delegate.getProperties();
+    }
+
+
+
+    /**
+     * @see org.apache.poi.hpsf.PropertySet#getProperty(int)
+     */
+    protected Object getProperty(final int id) throws NoSingleSectionException
+    {
+        return delegate.getProperty(id);
+    }
+
+
+
+    /**
+     * @see org.apache.poi.hpsf.PropertySet#getPropertyBooleanValue(int)
+     */
+    protected boolean getPropertyBooleanValue(final int id) throws NoSingleSectionException
+    {
+        return delegate.getPropertyBooleanValue(id);
+    }
+
+
+
+    /**
+     * @see org.apache.poi.hpsf.PropertySet#getPropertyIntValue(int)
+     */
+    protected int getPropertyIntValue(final int id) throws NoSingleSectionException
+    {
+        return delegate.getPropertyIntValue(id);
+    }
+
+
+
+    /**
+     * @see org.apache.poi.hpsf.PropertySet#hashCode()
+     */
+    public int hashCode()
+    {
+        return delegate.hashCode();
+    }
+
+
+
+    /**
+     * @see org.apache.poi.hpsf.PropertySet#toString()
+     */
+    public String toString()
+    {
+        return delegate.toString();
+    }
+
+
+
+    /**
+     * @see org.apache.poi.hpsf.PropertySet#wasNull()
+     */
+    public boolean wasNull() throws NoSingleSectionException
     {
-        return delegate.getSingleSection();
+        return delegate.wasNull();
     }
 
 }

Modified: jakarta/poi/trunk/src/java/org/apache/poi/hpsf/SummaryInformation.java
URL: http://svn.apache.org/viewcvs/jakarta/poi/trunk/src/java/org/apache/poi/hpsf/SummaryInformation.java?rev=382887&r1=382886&r2=382887&view=diff
==============================================================================
--- jakarta/poi/trunk/src/java/org/apache/poi/hpsf/SummaryInformation.java (original)
+++ jakarta/poi/trunk/src/java/org/apache/poi/hpsf/SummaryInformation.java Fri Mar  3 08:57:55 2006
@@ -1,31 +1,33 @@
+/*
+ * ====================================================================
+ * Copyright 2002-2006 Apache Software Foundation
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ * ====================================================================
+ */
 
-/* ====================================================================
-   Copyright 2002-2004   Apache Software Foundation
-
-   Licensed under the Apache License, Version 2.0 (the "License");
-   you may not use this file except in compliance with the License.
-   You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.
-==================================================================== */
-        
 package org.apache.poi.hpsf;
 
 import java.util.Date;
+
 import org.apache.poi.hpsf.wellknown.PropertyIDMap;
 
 /**
  * <p>Convenience class representing a Summary Information stream in a
  * Microsoft Office document.</p>
- *
+ * 
  * @author Rainer Klute <a
- * href="mailto:klute@rainer-klute.de">&lt;klute@rainer-klute.de&gt;</a>
+ *         href="mailto:klute@rainer-klute.de">&lt;klute@rainer-klute.de&gt;</a>
  * @see DocumentSummaryInformation
  * @version $Id$
  * @since 2002-02-09
@@ -34,8 +36,8 @@
 {
 
     /**
-     * <p>The document name a summary information stream usually has
-     * in a POIFS filesystem.</p>
+     * <p>The document name a summary information stream usually has in a POIFS
+     * filesystem.</p>
      */
     public static final String DEFAULT_STREAM_NAME = "\005SummaryInformation";
 
@@ -44,26 +46,26 @@
     /**
      * <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.
+     *        information stream.
+     * @throws UnexpectedPropertySetTypeException if <var>ps</var> does not
+     *         contain a summary information stream.
      */
     public SummaryInformation(final PropertySet ps)
-        throws UnexpectedPropertySetTypeException
+            throws UnexpectedPropertySetTypeException
     {
         super(ps);
         if (!isSummaryInformation())
-            throw new UnexpectedPropertySetTypeException
-                ("Not a " + getClass().getName());
+            throw new UnexpectedPropertySetTypeException("Not a "
+                    + getClass().getName());
     }
 
 
 
     /**
-     * <p>Returns the stream's title (or <code>null</code>).</p>
-     *
+     * <p>Returns the title (or <code>null</code>).</p>
+     * 
      * @return The title or <code>null</code>
      */
     public String getTitle()
@@ -74,8 +76,32 @@
 
 
     /**
-     * <p>Returns the stream's subject (or <code>null</code>).</p>
-     *
+     * <p>Sets the title.</p>
+     * 
+     * @param title The title to set.
+     */
+    public void setTitle(final String title)
+    {
+        final MutableSection s = (MutableSection) getFirstSection();
+        s.setProperty(PropertyIDMap.PID_TITLE, title);
+    }
+
+
+
+    /**
+     * <p>Removes the title.</p>
+     */
+    public void removeTitle()
+    {
+        final MutableSection s = (MutableSection) getFirstSection();
+        s.removeProperty(PropertyIDMap.PID_TITLE);
+    }
+
+
+
+    /**
+     * <p>Returns the subject (or <code>null</code>).</p>
+     * 
      * @return The subject or <code>null</code>
      */
     public String getSubject()
@@ -86,8 +112,32 @@
 
 
     /**
-     * <p>Returns the stream's author (or <code>null</code>).</p>
-     *
+     * <p>Sets the subject.</p>
+     * 
+     * @param subject The subject to set.
+     */
+    public void setSubject(final String subject)
+    {
+        final MutableSection s = (MutableSection) getFirstSection();
+        s.setProperty(PropertyIDMap.PID_SUBJECT, subject);
+    }
+
+
+
+    /**
+     * <p>Removes the subject.</p>
+     */
+    public void removeSubject()
+    {
+        final MutableSection s = (MutableSection) getFirstSection();
+        s.removeProperty(PropertyIDMap.PID_SUBJECT);
+    }
+
+
+
+    /**
+     * <p>Returns the author (or <code>null</code>).</p>
+     * 
      * @return The author or <code>null</code>
      */
     public String getAuthor()
@@ -98,8 +148,32 @@
 
 
     /**
-     * <p>Returns the stream's keywords (or <code>null</code>).</p>
-     *
+     * <p>Sets the author.</p>
+     * 
+     * @param author The author to set.
+     */
+    public void setAuthor(final String author)
+    {
+        final MutableSection s = (MutableSection) getFirstSection();
+        s.setProperty(PropertyIDMap.PID_AUTHOR, author);
+    }
+
+
+
+    /**
+     * <p>Removes the author.</p>
+     */
+    public void removeAuthor()
+    {
+        final MutableSection s = (MutableSection) getFirstSection();
+        s.removeProperty(PropertyIDMap.PID_AUTHOR);
+    }
+
+
+
+    /**
+     * <p>Returns the keywords (or <code>null</code>).</p>
+     * 
      * @return The keywords or <code>null</code>
      */
     public String getKeywords()
@@ -110,8 +184,32 @@
 
 
     /**
-     * <p>Returns the stream's comments (or <code>null</code>).</p>
-     *
+     * <p>Sets the keywords.</p>
+     * 
+     * @param keywords The keywords to set.
+     */
+    public void setKeywords(final String keywords)
+    {
+        final MutableSection s = (MutableSection) getFirstSection();
+        s.setProperty(PropertyIDMap.PID_KEYWORDS, keywords);
+    }
+
+
+
+    /**
+     * <p>Removes the keywords.</p>
+     */
+    public void removeKeywords()
+    {
+        final MutableSection s = (MutableSection) getFirstSection();
+        s.removeProperty(PropertyIDMap.PID_KEYWORDS);
+    }
+
+
+
+    /**
+     * <p>Returns the comments (or <code>null</code>).</p>
+     * 
      * @return The comments or <code>null</code>
      */
     public String getComments()
@@ -122,8 +220,32 @@
 
 
     /**
-     * <p>Returns the stream's template (or <code>null</code>).</p>
-     *
+     * <p>Sets the comments.</p>
+     * 
+     * @param comments The comments to set.
+     */
+    public void setComments(final String comments)
+    {
+        final MutableSection s = (MutableSection) getFirstSection();
+        s.setProperty(PropertyIDMap.PID_COMMENTS, comments);
+    }
+
+
+
+    /**
+     * <p>Removes the comments.</p>
+     */
+    public void removeComments()
+    {
+        final MutableSection s = (MutableSection) getFirstSection();
+        s.removeProperty(PropertyIDMap.PID_COMMENTS);
+    }
+
+
+
+    /**
+     * <p>Returns the template (or <code>null</code>).</p>
+     * 
      * @return The template or <code>null</code>
      */
     public String getTemplate()
@@ -134,8 +256,32 @@
 
 
     /**
-     * <p>Returns the stream's last author (or <code>null</code>).</p>
-     *
+     * <p>Sets the template.</p>
+     * 
+     * @param template The template to set.
+     */
+    public void setTemplate(final String template)
+    {
+        final MutableSection s = (MutableSection) getFirstSection();
+        s.setProperty(PropertyIDMap.PID_TEMPLATE, template);
+    }
+
+
+
+    /**
+     * <p>Removes the template.</p>
+     */
+    public void removeTemplate()
+    {
+        final MutableSection s = (MutableSection) getFirstSection();
+        s.removeProperty(PropertyIDMap.PID_TEMPLATE);
+    }
+
+
+
+    /**
+     * <p>Returns the last author (or <code>null</code>).</p>
+     * 
      * @return The last author or <code>null</code>
      */
     public String getLastAuthor()
@@ -146,9 +292,32 @@
 
 
     /**
-     * <p>Returns the stream's revision number (or
-     * <code>null</code>). </p>
-     *
+     * <p>Sets the last author.</p>
+     * 
+     * @param lastAuthor The last author to set.
+     */
+    public void setLastAuthor(final String lastAuthor)
+    {
+        final MutableSection s = (MutableSection) getFirstSection();
+        s.setProperty(PropertyIDMap.PID_LASTAUTHOR, lastAuthor);
+    }
+
+
+
+    /**
+     * <p>Removes the last author.</p>
+     */
+    public void removeLastAuthor()
+    {
+        final MutableSection s = (MutableSection) getFirstSection();
+        s.removeProperty(PropertyIDMap.PID_LASTAUTHOR);
+    }
+
+
+
+    /**
+     * <p>Returns the revision number (or <code>null</code>). </p>
+     * 
      * @return The revision number or <code>null</code>
      */
     public String getRevNumber()
@@ -159,11 +328,35 @@
 
 
     /**
-     * <p>Returns the total time spent in editing the document
-     * (or <code>0</code>).</p>
-     *
+     * <p>Sets the revision number.</p>
+     * 
+     * @param revNumber The revision number to set.
+     */
+    public void setRevNumber(final String revNumber)
+    {
+        final MutableSection s = (MutableSection) getFirstSection();
+        s.setProperty(PropertyIDMap.PID_REVNUMBER, revNumber);
+    }
+
+
+
+    /**
+     * <p>Removes the revision number.</p>
+     */
+    public void removeRevNumber()
+    {
+        final MutableSection s = (MutableSection) getFirstSection();
+        s.removeProperty(PropertyIDMap.PID_REVNUMBER);
+    }
+
+
+
+    /**
+     * <p>Returns the total time spent in editing the document (or
+     * <code>0</code>).</p>
+     * 
      * @return The total time spent in editing the document or 0 if the {@link
-     * SummaryInformation} does not contain this information.
+     *         SummaryInformation} does not contain this information.
      */
     public long getEditTime()
     {
@@ -177,9 +370,33 @@
 
 
     /**
-     * <p>Returns the stream's last printed time (or
-     * <code>null</code>).</p>
-     *
+     * <p>Sets the total time spent in editing the document.</p>
+     * 
+     * @param time The time to set.
+     */
+    public void setEditTime(final long time)
+    {
+        final Date d = Util.filetimeToDate(time);
+        final MutableSection s = (MutableSection) getFirstSection();
+        s.setProperty(PropertyIDMap.PID_EDITTIME, Variant.VT_FILETIME, d);
+    }
+
+
+
+    /**
+     * <p>Remove the total time spent in editing the document.</p>
+     */
+    public void removeEditTime()
+    {
+        final MutableSection s = (MutableSection) getFirstSection();
+        s.removeProperty(PropertyIDMap.PID_EDITTIME);
+    }
+
+
+
+    /**
+     * <p>Returns the last printed time (or <code>null</code>).</p>
+     * 
      * @return The last printed time or <code>null</code>
      */
     public Date getLastPrinted()
@@ -190,9 +407,33 @@
 
 
     /**
-     * <p>Returns the stream's creation time (or
-     * <code>null</code>).</p>
-     *
+     * <p>Sets the lastPrinted.</p>
+     * 
+     * @param lastPrinted The lastPrinted to set.
+     */
+    public void setLastPrinted(final Date lastPrinted)
+    {
+        final MutableSection s = (MutableSection) getFirstSection();
+        s.setProperty(PropertyIDMap.PID_LASTPRINTED, Variant.VT_FILETIME,
+                lastPrinted);
+    }
+
+
+
+    /**
+     * <p>Removes the lastPrinted.</p>
+     */
+    public void removeLastPrinted()
+    {
+        final MutableSection s = (MutableSection) getFirstSection();
+        s.removeProperty(PropertyIDMap.PID_LASTPRINTED);
+    }
+
+
+
+    /**
+     * <p>Returns the creation time (or <code>null</code>).</p>
+     * 
      * @return The creation time or <code>null</code>
      */
     public Date getCreateDateTime()
@@ -203,9 +444,33 @@
 
 
     /**
-     * <p>Returns the stream's last save time (or
-     * <code>null</code>).</p>
-     *
+     * <p>Sets the creation time.</p>
+     * 
+     * @param createDateTime The creation time to set.
+     */
+    public void setCreateDateTime(final Date createDateTime)
+    {
+        final MutableSection s = (MutableSection) getFirstSection();
+        s.setProperty(PropertyIDMap.PID_CREATE_DTM, Variant.VT_FILETIME,
+                createDateTime);
+    }
+
+
+
+    /**
+     * <p>Removes the creation time.</p>
+     */
+    public void removeCreateDateTime()
+    {
+        final MutableSection s = (MutableSection) getFirstSection();
+        s.removeProperty(PropertyIDMap.PID_CREATE_DTM);
+    }
+
+
+
+    /**
+     * <p>Returns the last save time (or <code>null</code>).</p>
+     * 
      * @return The last save time or <code>null</code>
      */
     public Date getLastSaveDateTime()
@@ -216,11 +481,37 @@
 
 
     /**
-     * <p>Returns the stream's page count or 0 if the {@link
-     * SummaryInformation} does not contain a page count.</p>
-     *
+     * <p>Sets the total time spent in editing the document.</p>
+     * 
+     * @param time The time to set.
+     */
+    public void setLastSaveDateTime(final Date time)
+    {
+        final MutableSection s = (MutableSection) getFirstSection();
+        s
+                .setProperty(PropertyIDMap.PID_LASTSAVE_DTM,
+                        Variant.VT_FILETIME, time);
+    }
+
+
+
+    /**
+     * <p>Remove the total time spent in editing the document.</p>
+     */
+    public void removeLastSaveDateTime()
+    {
+        final MutableSection s = (MutableSection) getFirstSection();
+        s.removeProperty(PropertyIDMap.PID_LASTSAVE_DTM);
+    }
+
+
+
+    /**
+     * <p>Returns the page count or 0 if the {@link SummaryInformation} does
+     * not contain a page count.</p>
+     * 
      * @return The page count or 0 if the {@link SummaryInformation} does not
-     * contain a page count.
+     *         contain a page count.
      */
     public int getPageCount()
     {
@@ -230,9 +521,33 @@
 
 
     /**
-     * <p>Returns the stream's word count or 0 if the {@link
-     * SummaryInformation} does not contain a word count.</p>
-     *
+     * <p>Sets the page count.</p>
+     * 
+     * @param pageCount The page count to set.
+     */
+    public void setPageCount(final int pageCount)
+    {
+        final MutableSection s = (MutableSection) getFirstSection();
+        s.setProperty(PropertyIDMap.PID_PAGECOUNT, pageCount);
+    }
+
+
+
+    /**
+     * <p>Removes the page count.</p>
+     */
+    public void removePageCount()
+    {
+        final MutableSection s = (MutableSection) getFirstSection();
+        s.removeProperty(PropertyIDMap.PID_PAGECOUNT);
+    }
+
+
+
+    /**
+     * <p>Returns the word count or 0 if the {@link SummaryInformation} does
+     * not contain a word count.</p>
+     * 
      * @return The word count or <code>null</code>
      */
     public int getWordCount()
@@ -243,9 +558,33 @@
 
 
     /**
-     * <p>Returns the stream's character count or 0 if the {@link
-     * SummaryInformation} does not contain a char count.</p>
-     *
+     * <p>Sets the word count.</p>
+     * 
+     * @param wordCount The word count to set.
+     */
+    public void setWordCount(final int wordCount)
+    {
+        final MutableSection s = (MutableSection) getFirstSection();
+        s.setProperty(PropertyIDMap.PID_WORDCOUNT, wordCount);
+    }
+
+
+
+    /**
+     * <p>Removes the word count.</p>
+     */
+    public void removeWordCount()
+    {
+        final MutableSection s = (MutableSection) getFirstSection();
+        s.removeProperty(PropertyIDMap.PID_WORDCOUNT);
+    }
+
+
+
+    /**
+     * <p>Returns the character count or 0 if the {@link SummaryInformation}
+     * does not contain a char count.</p>
+     * 
      * @return The character count or <code>null</code>
      */
     public int getCharCount()
@@ -256,15 +595,39 @@
 
 
     /**
-     * <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></p>
-     *
-     * <p><strong>Hint to developers:</strong> Drew Varner &lt;Drew.Varner -at-
-     * sc.edu&gt; said that this is an image in WMF or Clipboard (BMP?) format.
-     * However, we won't do any conversion into any image type but instead just
-     * return a byte array.</p>
-     *
+     * <p>Sets the character count.</p>
+     * 
+     * @param charCount The character count to set.
+     */
+    public void setCharCount(final int charCount)
+    {
+        final MutableSection s = (MutableSection) getFirstSection();
+        s.setProperty(PropertyIDMap.PID_CHARCOUNT, charCount);
+    }
+
+
+
+    /**
+     * <p>Removes the character count.</p>
+     */
+    public void removeCharCount()
+    {
+        final MutableSection s = (MutableSection) getFirstSection();
+        s.removeProperty(PropertyIDMap.PID_CHARCOUNT);
+    }
+
+
+
+    /**
+     * <p>Returns the thumbnail (or <code>null</code>) <strong>when this
+     * method is implemented. Please note that the return type is likely to
+     * change!</strong></p>
+     * 
+     * <p><strong>Hint to developers:</strong> Drew Varner &lt;Drew.Varner
+     * -at- sc.edu&gt; said that this is an image in WMF or Clipboard (BMP?)
+     * format. However, we won't do any conversion into any image type but
+     * instead just return a byte array.</p>
+     * 
      * @return The thumbnail or <code>null</code>
      */
     public byte[] getThumbnail()
@@ -275,9 +638,33 @@
 
 
     /**
-     * <p>Returns the stream's application name (or
-     * <code>null</code>).</p>
-     *
+     * <p>Sets the thumbnail.</p>
+     * 
+     * @param thumbnail The thumbnail to set.
+     */
+    public void setThumbnail(final byte[] thumbnail)
+    {
+        final MutableSection s = (MutableSection) getFirstSection();
+        s.setProperty(PropertyIDMap.PID_THUMBNAIL, /* FIXME: */
+                Variant.VT_LPSTR, thumbnail);
+    }
+
+
+
+    /**
+     * <p>Removes the thumbnail.</p>
+     */
+    public void removeThumbnail()
+    {
+        final MutableSection s = (MutableSection) getFirstSection();
+        s.removeProperty(PropertyIDMap.PID_THUMBNAIL);
+    }
+
+
+
+    /**
+     * <p>Returns the application name (or <code>null</code>).</p>
+     * 
      * @return The application name or <code>null</code>
      */
     public String getApplicationName()
@@ -288,40 +675,78 @@
 
 
     /**
-     * <p>Returns a security code which is one of the following
-     * values:</p>
-     *
+     * <p>Sets the application name.</p>
+     * 
+     * @param applicationName The application name to set.
+     */
+    public void setApplicationName(final String applicationName)
+    {
+        final MutableSection s = (MutableSection) getFirstSection();
+        s.setProperty(PropertyIDMap.PID_APPNAME, applicationName);
+    }
+
+
+
+    /**
+     * <p>Removes the application name.</p>
+     */
+    public void removeApplicationName()
+    {
+        final MutableSection s = (MutableSection) getFirstSection();
+        s.removeProperty(PropertyIDMap.PID_APPNAME);
+    }
+
+
+
+    /**
+     * <p>Returns a security code which is one of the following values:</p>
+     * 
      * <ul>
-     *  <li>
-     *   <p>0 if the {@link SummaryInformation} does not contain a
-     *   security field or if there is no security on the
-     *   document. Use {@link #wasNull} to distinguish between the
-     *   two cases!</p>
-     *  </li>
-     *
-     *  <li>
-     *   <p>1 if the document is password protected</p>
-     *  </li>
-     *
-     *   <li>
-     *    <p>2 if the document is read-only recommended</p>
-     *   </li>
-     *
-     *   <li>
-     *    <p>4 if the document is read-only enforced</p>
-     *   </li>
-     *
-     *   <li>
-     *    <p>8 if the document is locked for annotations</p>
-     *   </li>
-     *
+     * 
+     * <li><p>0 if the {@link SummaryInformation} does not contain a
+     * security field or if there is no security on the document. Use
+     * {@link PropertySet#wasNull()} to distinguish between the two
+     * cases!</p></li>
+     * 
+     * <li><p>1 if the document is password protected</p></li>
+     * 
+     * <li><p>2 if the document is read-only recommended</p></li>
+     * 
+     * <li><p>4 if the document is read-only enforced</p></li>
+     * 
+     * <li><p>8 if the document is locked for annotations</p></li>
+     * 
      * </ul>
-     *
+     * 
      * @return The security code or <code>null</code>
      */
     public int getSecurity()
     {
         return getPropertyIntValue(PropertyIDMap.PID_SECURITY);
+    }
+
+
+
+    /**
+     * <p>Sets the security code.</p>
+     * 
+     * @param security The security code to set.
+     */
+    public void setSecurity(final int security)
+    {
+        final MutableSection s = (MutableSection) getFirstSection();
+        s.setProperty(PropertyIDMap.PID_SECURITY, security);
+    }
+
+
+
+    /**
+     * <p>Removes the security code.</p>
+     */
+    public void removeSecurity()
+    {
+        final MutableSection s = (MutableSection) getFirstSection();
+        s.removeProperty(PropertyIDMap.PID_SECURITY);
     }
 
 }

Modified: jakarta/poi/trunk/src/java/org/apache/poi/hpsf/Thumbnail.java
URL: http://svn.apache.org/viewcvs/jakarta/poi/trunk/src/java/org/apache/poi/hpsf/Thumbnail.java?rev=382887&r1=382886&r2=382887&view=diff
==============================================================================
--- jakarta/poi/trunk/src/java/org/apache/poi/hpsf/Thumbnail.java (original)
+++ jakarta/poi/trunk/src/java/org/apache/poi/hpsf/Thumbnail.java Fri Mar  3 08:57:55 2006
@@ -1,4 +1,3 @@
-
 /* ====================================================================
    Copyright 2002-2004   Apache Software Foundation
 

Modified: jakarta/poi/trunk/src/java/org/apache/poi/hpsf/TypeWriter.java
URL: http://svn.apache.org/viewcvs/jakarta/poi/trunk/src/java/org/apache/poi/hpsf/TypeWriter.java?rev=382887&r1=382886&r2=382887&view=diff
==============================================================================
--- jakarta/poi/trunk/src/java/org/apache/poi/hpsf/TypeWriter.java (original)
+++ jakarta/poi/trunk/src/java/org/apache/poi/hpsf/TypeWriter.java Fri Mar  3 08:57:55 2006
@@ -1,6 +1,5 @@
-
 /* ====================================================================
-   Copyright 2002-2004   Apache Software Foundation
+   Copyright 2002-2006   Apache Software Foundation
 
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
@@ -46,7 +45,7 @@
     {
         final int length = LittleEndian.SHORT_SIZE;
         byte[] buffer = new byte[length];
-        LittleEndian.putUShort(buffer, 0, n);
+        LittleEndian.putShort(buffer, 0, n); // FIXME: unsigned
         out.write(buffer, 0, length);
         return length;
     }
@@ -75,6 +74,27 @@
 
 
     /**
+     * <p>Writes a eight-byte value to an output stream.</p>
+     *
+     * @param out The stream to write to.
+     * @param n The value to write.
+     * @exception IOException if an I/O error occurs
+     * @return The number of bytes written to the output stream. 
+     */
+    public static int writeToStream(final OutputStream out, final long n)
+        throws IOException
+    {
+        final int l = LittleEndian.LONG_SIZE;
+        final byte[] buffer = new byte[l];
+        LittleEndian.putLong(buffer, 0, n);
+        out.write(buffer, 0, l);
+        return l;
+        
+    }
+
+
+
+    /**
      * <p>Writes an unsigned two-byte value to an output stream.</p>
      *
      * @param out The stream to write to
@@ -118,6 +138,7 @@
      *
      * @param out The stream to write to
      * @param n The value to write
+     * @return The number of bytes written
      * @exception IOException if an I/O error occurs
      */
     public static int writeToStream(final OutputStream out, final ClassID n)
@@ -134,10 +155,13 @@
     /**
      * <p>Writes an array of {@link Property} instances to an output stream
      * according to the Horrible Property Stream Format.</p>
-     *
+     * 
      * @param out The stream to write to
      * @param properties The array to write to the stream
+     * @param codepage The codepage number to use for writing strings
      * @exception IOException if an I/O error occurs
+     * @throws UnsupportedVariantTypeException if HPSF does not support some
+     *         variant type.
      */
     public static void writeToStream(final OutputStream out,
                                      final Property[] properties,
@@ -152,7 +176,7 @@
          * ID and offset into the stream. */
         for (int i = 0; i < properties.length; i++)
         {
-            final Property p = (Property) properties[i];
+            final Property p = properties[i];
             writeUIntToStream(out, p.getID());
             writeUIntToStream(out, p.getSize());
         }
@@ -160,7 +184,7 @@
         /* Write the properties themselves. */
         for (int i = 0; i < properties.length; i++)
         {
-            final Property p = (Property) properties[i];
+            final Property p = properties[i];
             long type = p.getType();
             writeUIntToStream(out, type);
             VariantSupport.write(out, (int) type, p.getValue(), codepage);

Modified: jakarta/poi/trunk/src/java/org/apache/poi/hpsf/UnexpectedPropertySetTypeException.java
URL: http://svn.apache.org/viewcvs/jakarta/poi/trunk/src/java/org/apache/poi/hpsf/UnexpectedPropertySetTypeException.java?rev=382887&r1=382886&r2=382887&view=diff
==============================================================================
--- jakarta/poi/trunk/src/java/org/apache/poi/hpsf/UnexpectedPropertySetTypeException.java (original)
+++ jakarta/poi/trunk/src/java/org/apache/poi/hpsf/UnexpectedPropertySetTypeException.java Fri Mar  3 08:57:55 2006
@@ -1,4 +1,3 @@
-
 /* ====================================================================
    Copyright 2002-2004   Apache Software Foundation
 

Modified: jakarta/poi/trunk/src/java/org/apache/poi/hpsf/UnsupportedVariantTypeException.java
URL: http://svn.apache.org/viewcvs/jakarta/poi/trunk/src/java/org/apache/poi/hpsf/UnsupportedVariantTypeException.java?rev=382887&r1=382886&r2=382887&view=diff
==============================================================================
--- jakarta/poi/trunk/src/java/org/apache/poi/hpsf/UnsupportedVariantTypeException.java (original)
+++ jakarta/poi/trunk/src/java/org/apache/poi/hpsf/UnsupportedVariantTypeException.java Fri Mar  3 08:57:55 2006
@@ -21,7 +21,7 @@
 /**
  * <p>This exception is thrown if HPSF encounters a variant type that isn't
  * supported yet. Although a variant type is unsupported the value can still be
- * retrieved using the {@link #getValue} method.</p>
+ * retrieved using the {@link VariantTypeException#getValue} method.</p>
  * 
  * <p>Obviously this class should disappear some day.</p>
  *

Modified: jakarta/poi/trunk/src/java/org/apache/poi/hpsf/Util.java
URL: http://svn.apache.org/viewcvs/jakarta/poi/trunk/src/java/org/apache/poi/hpsf/Util.java?rev=382887&r1=382886&r2=382887&view=diff
==============================================================================
--- jakarta/poi/trunk/src/java/org/apache/poi/hpsf/Util.java (original)
+++ jakarta/poi/trunk/src/java/org/apache/poi/hpsf/Util.java Fri Mar  3 08:57:55 2006
@@ -1,6 +1,5 @@
-
 /* ====================================================================
-   Copyright 2002-2004   Apache Software Foundation
+   Copyright 2002-2006   Apache Software Foundation
 
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
@@ -152,6 +151,21 @@
     public static Date filetimeToDate(final int high, final int low)
     {
         final long filetime = ((long) high) << 32 | (low & 0xffffffffL);
+        return filetimeToDate(filetime);
+    }
+
+    /**
+     * <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.</p>
+     *
+     * @param filetime The filetime to convert.
+     * @return The Windows FILETIME as a {@link Date}.
+     */
+    public static Date filetimeToDate(final long filetime)
+    {
         final long ms_since_16010101 = filetime / (1000 * 10);
         final long ms_since_19700101 = ms_since_16010101 - EPOCH_DIFF;
         return new Date(ms_since_19700101);
@@ -165,7 +179,8 @@
      * @param date The date to be converted
      * @return The filetime
      * 
-     * @see #filetimeToDate
+     * @see #filetimeToDate(long)
+     * @see #filetimeToDate(int, int)
      */
     public static long dateToFileTime(final Date date)
     {

Modified: jakarta/poi/trunk/src/java/org/apache/poi/hpsf/Variant.java
URL: http://svn.apache.org/viewcvs/jakarta/poi/trunk/src/java/org/apache/poi/hpsf/Variant.java?rev=382887&r1=382886&r2=382887&view=diff
==============================================================================
--- jakarta/poi/trunk/src/java/org/apache/poi/hpsf/Variant.java (original)
+++ jakarta/poi/trunk/src/java/org/apache/poi/hpsf/Variant.java Fri Mar  3 08:57:55 2006
@@ -1,4 +1,3 @@
-
 /* ====================================================================
    Copyright 2002-2004   Apache Software Foundation
 

Modified: jakarta/poi/trunk/src/java/org/apache/poi/hpsf/VariantSupport.java
URL: http://svn.apache.org/viewcvs/jakarta/poi/trunk/src/java/org/apache/poi/hpsf/VariantSupport.java?rev=382887&r1=382886&r2=382887&view=diff
==============================================================================
--- jakarta/poi/trunk/src/java/org/apache/poi/hpsf/VariantSupport.java (original)
+++ jakarta/poi/trunk/src/java/org/apache/poi/hpsf/VariantSupport.java Fri Mar  3 08:57:55 2006
@@ -1,5 +1,5 @@
 /* ====================================================================
-   Copyright 2002-2004   Apache Software Foundation
+   Copyright 2002-2006   Apache Software Foundation
 
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
@@ -157,16 +157,25 @@
                  * Read a short. In Java it is represented as an
                  * Integer object.
                  */
-                value = new Integer(LittleEndian.getUShort(src, o1));
+                value = new Integer(LittleEndian.getShort(src, o1));
                 break;
             }
             case Variant.VT_I4:
             {
                 /*
-                 * Read a word. In Java it is represented as a
+                 * Read a word. In Java it is represented as an
+                 * Integer object.
+                 */
+                value = new Integer(LittleEndian.getInt(src, o1));
+                break;
+            }
+            case Variant.VT_I8:
+            {
+                /*
+                 * Read a double word. In Java it is represented as a
                  * Long object.
                  */
-                value = new Long(LittleEndian.getUInt(src, o1));
+                value = new Long(LittleEndian.getLong(src, o1));
                 break;
             }
             case Variant.VT_R8:
@@ -204,9 +213,9 @@
                     last--;
                 final int l = (int) (last - first + 1);
                 value = codepage != -1 ?
-                    new String(src, (int) first, l,
+                    new String(src, first, l,
                                codepageToEncoding(codepage)) :
-                    new String(src, (int) first, l);
+                    new String(src, first, l);
                 break;
             }
             case Variant.VT_LPWSTR:
@@ -240,7 +249,7 @@
             {
                 final byte[] v = new byte[l1];
                 for (int i = 0; i < l1; i++)
-                    v[i] = src[(int) (o1 + i)];
+                    v[i] = src[(o1 + i)];
                 value = v;
                 break;
             }
@@ -263,7 +272,7 @@
             {
                 final byte[] v = new byte[l1];
                 for (int i = 0; i < l1; i++)
-                    v[i] = src[(int) (o1 + i)];
+                    v[i] = src[(o1 + i)];
                 throw new ReadingNotSupportedException(type, v);
             }
         }
@@ -397,8 +406,8 @@
                 char[] s = Util.pad4((String) value);
                 for (int i = 0; i < s.length; i++)
                 {
-                    final int high = (int) ((s[i] & 0x0000ff00) >> 8);
-                    final int low = (int) (s[i] & 0x000000ff);
+                    final int high = ((s[i] & 0x0000ff00) >> 8);
+                    final int low = (s[i] & 0x000000ff);
                     final byte highb = (byte) high;
                     final byte lowb = (byte) low;
                     out.write(lowb);
@@ -431,8 +440,21 @@
             }
             case Variant.VT_I4:
             {
+                if (!(value instanceof Integer))
+                {
+                    throw new ClassCastException("Could not cast an object to "
+                            + Integer.class.toString() + ": "
+                            + value.getClass().toString() + ", "
+                            + value.toString());
+                }
                 length += TypeWriter.writeToStream(out, 
-                          ((Long) value).intValue());
+                          ((Integer) value).intValue());
+                break;
+            }
+            case Variant.VT_I8:
+            {
+                TypeWriter.writeToStream(out, ((Long) value).longValue());
+                length = LittleEndianConsts.LONG_SIZE;
                 break;
             }
             case Variant.VT_R8:

Modified: jakarta/poi/trunk/src/java/org/apache/poi/hpsf/WritingNotSupportedException.java
URL: http://svn.apache.org/viewcvs/jakarta/poi/trunk/src/java/org/apache/poi/hpsf/WritingNotSupportedException.java?rev=382887&r1=382886&r2=382887&view=diff
==============================================================================
--- jakarta/poi/trunk/src/java/org/apache/poi/hpsf/WritingNotSupportedException.java (original)
+++ jakarta/poi/trunk/src/java/org/apache/poi/hpsf/WritingNotSupportedException.java Fri Mar  3 08:57:55 2006
@@ -1,4 +1,3 @@
-
 /* ====================================================================
    Copyright 2002-2004   Apache Software Foundation
 

Modified: jakarta/poi/trunk/src/java/org/apache/poi/hpsf/wellknown/PropertyIDMap.java
URL: http://svn.apache.org/viewcvs/jakarta/poi/trunk/src/java/org/apache/poi/hpsf/wellknown/PropertyIDMap.java?rev=382887&r1=382886&r2=382887&view=diff
==============================================================================
--- jakarta/poi/trunk/src/java/org/apache/poi/hpsf/wellknown/PropertyIDMap.java (original)
+++ jakarta/poi/trunk/src/java/org/apache/poi/hpsf/wellknown/PropertyIDMap.java Fri Mar  3 08:57:55 2006
@@ -1,4 +1,3 @@
-
 /* ====================================================================
    Copyright 2002-2004   Apache Software Foundation
 
@@ -231,6 +230,11 @@
      * re-evaluated.</p>
      */
     public static final int PID_LINKSDIRTY = 16;
+    
+    /**
+     * <p>The highest well-known property ID. Applications are free to use higher values for custom purposes.</p>
+     */
+    public static final int PID_MAX = PID_LINKSDIRTY;
 
 
 

Modified: jakarta/poi/trunk/src/java/org/apache/poi/hpsf/wellknown/SectionIDMap.java
URL: http://svn.apache.org/viewcvs/jakarta/poi/trunk/src/java/org/apache/poi/hpsf/wellknown/SectionIDMap.java?rev=382887&r1=382886&r2=382887&view=diff
==============================================================================
--- jakarta/poi/trunk/src/java/org/apache/poi/hpsf/wellknown/SectionIDMap.java (original)
+++ jakarta/poi/trunk/src/java/org/apache/poi/hpsf/wellknown/SectionIDMap.java Fri Mar  3 08:57:55 2006
@@ -1,6 +1,5 @@
-
 /* ====================================================================
-   Copyright 2002-2004   Apache Software Foundation
+   Copyright 2002-2006   Apache Software Foundation
 
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
@@ -53,16 +52,23 @@
     };
 
     /**
-     * <p>The DocumentSummaryInformation's first section's format
-     * ID. The second section has a different format ID which is not
-     * well-known.</p>
-     */
-    public static final 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
+     * <p>The DocumentSummaryInformation's first and second sections' format
+     * ID.</p>
+     */
+    public static final 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
+        },
+        {
+            (byte) 0xD5, (byte) 0xCD, (byte) 0xD5, (byte) 0x05,
+            (byte) 0x2E, (byte) 0x9C, (byte) 0x10, (byte) 0x1B,
+            (byte) 0x93, (byte) 0x97, (byte) 0x08, (byte) 0x00,
+            (byte) 0x2B, (byte) 0x2C, (byte) 0xF9, (byte) 0xAE
+        }
     };
 
     /**
@@ -91,7 +97,7 @@
             final SectionIDMap m = new SectionIDMap();
             m.put(SUMMARY_INFORMATION_ID,
                   PropertyIDMap.getSummaryInformationProperties());
-            m.put(DOCUMENT_SUMMARY_INFORMATION_ID,
+            m.put(DOCUMENT_SUMMARY_INFORMATION_ID[0],
                   PropertyIDMap.getDocumentSummaryInformationProperties());
             defaultMap = m;
         }
@@ -116,8 +122,7 @@
     public static String getPIDString(final byte[] sectionFormatID,
                                       final long pid)
     {
-        final PropertyIDMap m =
-            (PropertyIDMap) getInstance().get(sectionFormatID);
+        final PropertyIDMap m = getInstance().get(sectionFormatID);
         if (m == null)
             return UNDEFINED;
         else
@@ -178,7 +183,8 @@
 
     /**
      * @deprecated Use {@link #put(byte[], PropertyIDMap)} instead!
-     * @link #put(byte[], PropertyIDMap)
+     *
+     * @see #put(byte[], PropertyIDMap)
      * 
      * @param key This parameter remains undocumented since the method is
      * deprecated.

Modified: jakarta/poi/trunk/src/java/org/apache/poi/util/LittleEndian.java
URL: http://svn.apache.org/viewcvs/jakarta/poi/trunk/src/java/org/apache/poi/util/LittleEndian.java?rev=382887&r1=382886&r2=382887&view=diff
==============================================================================
--- jakarta/poi/trunk/src/java/org/apache/poi/util/LittleEndian.java (original)
+++ jakarta/poi/trunk/src/java/org/apache/poi/util/LittleEndian.java Fri Mar  3 08:57:55 2006
@@ -1,5 +1,5 @@
 /* ====================================================================
-   Copyright 2003-2004   Apache Software Foundation
+   Copyright 2003-2006   Apache Software Foundation
 
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
@@ -64,9 +64,9 @@
         short num = (short) getNumber(data, offset, SHORT_SIZE);
         int retNum;
         if (num < 0) {
-            retNum = ((int) Short.MAX_VALUE + 1) * 2 + (int) num;
+            retNum = (Short.MAX_VALUE + 1) * 2 + num;
         } else {
-            retNum = (int) num;
+            retNum = num;
         }
         return retNum;
     }
@@ -163,9 +163,9 @@
         int num = (int) getNumber(data, offset, INT_SIZE);
         long retNum;
         if (num < 0) {
-            retNum = ((long) Integer.MAX_VALUE + 1) * 2 + (long) num;
+            retNum = ((long) Integer.MAX_VALUE + 1) * 2 + num;
         } else {
-            retNum = (int) num;
+            retNum = num;
         }
         return retNum;
     }
@@ -522,7 +522,7 @@
      *@return    Description of the Return Value
      */
     public static int ubyteToInt(byte b) {
-        return ((b & 0x80) == 0 ? (int) b : (int) (b & (byte) 0x7f) + 0x80);
+        return ((b & 0x80) == 0 ? (int) b : (b & (byte) 0x7f) + 0x80);
     }
 
 
@@ -566,5 +566,22 @@
         return copy;
     }
 
+    /**
+     * <p>Gets an unsigned int value (8 bytes) from a byte array.</p>
+     * 
+     * @param data the byte array
+     * @param offset a starting offset into the byte array
+     * @return the unsigned int (32-bit) value in a long
+     */
+    public static long getULong(final byte[] data, final int offset)
+    {
+        int num = (int) getNumber(data, offset, LONG_SIZE);
+        long retNum;
+        if (num < 0)
+            retNum = ((long) Integer.MAX_VALUE + 1) * 2 + num;
+        else
+            retNum = num;
+        return retNum;
+    }
 
 }

Added: jakarta/poi/trunk/src/testcases/org/apache/poi/hpsf/basic/AllDataFilesTester.java
URL: http://svn.apache.org/viewcvs/jakarta/poi/trunk/src/testcases/org/apache/poi/hpsf/basic/AllDataFilesTester.java?rev=382887&view=auto
==============================================================================
--- jakarta/poi/trunk/src/testcases/org/apache/poi/hpsf/basic/AllDataFilesTester.java (added)
+++ jakarta/poi/trunk/src/testcases/org/apache/poi/hpsf/basic/AllDataFilesTester.java Fri Mar  3 08:57:55 2006
@@ -0,0 +1,82 @@
+/* ====================================================================
+   Copyright 2002-2006   Apache Software Foundation
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hpsf.basic;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.util.logging.Logger;
+
+/**
+ * <p>Processes a test method for all OLE2 files in the HPSF test data
+ * directory. Well, this class does not check whether a file is an OLE2 file but
+ * rather whether its name begins with "Test".</p>
+ * 
+ * @author Rainer Klute <a
+ *         href="mailto:klute@rainer-klute.de">&lt;klute@rainer-klute.de&gt;</a>
+ * @since 2006-02-11
+ * @version $Id$
+ */
+public class AllDataFilesTester
+{
+
+    /**
+     * <p>Interface specifying how to run a test on a single file.</p>
+     *
+     * @author Rainer Klute <a
+     * href="mailto:klute@rainer-klute.de">&lt;klute@rainer-klute.de&gt;</a>
+     * @since 2006-02-11
+     * @version $Id$
+     */
+    public interface TestTask
+    {
+        /**
+         * <p>Executes a test on a single file.</p>
+         *
+         * @param file the file
+         * @throws Throwable if the method throws anything.
+         */
+        void runTest(File file) throws Throwable;
+    }
+
+    /**
+     * <p>Tests the simplified custom properties.</p>
+     *
+     * @param task the task to execute
+     * @throws Throwable 
+     */
+    public void runTests(final TestTask task) throws Throwable
+    {
+        final String dataDirName = System.getProperty("HPSF.testdata.path");
+        final File dataDir = new File(dataDirName);
+        final File[] docs = dataDir.listFiles(new FileFilter()
+        {
+            public boolean accept(final File file)
+            {
+                return file.isFile() && file.getName().startsWith("Test");
+            }});
+        for (int i = 0; i < docs.length; i++)
+        {
+            final File doc = docs[i];
+            final Logger logger = Logger.getLogger(getClass().getName());
+            logger.info("Processing file \" " + doc.toString() + "\".");
+
+            /* Execute the test task. */
+            task.runTest(doc);
+        }
+    }
+
+}

Propchange: jakarta/poi/trunk/src/testcases/org/apache/poi/hpsf/basic/AllDataFilesTester.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/poi/trunk/src/testcases/org/apache/poi/hpsf/basic/AllDataFilesTester.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: jakarta/poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestBasic.java
URL: http://svn.apache.org/viewcvs/jakarta/poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestBasic.java?rev=382887&r1=382886&r2=382887&view=diff
==============================================================================
--- jakarta/poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestBasic.java (original)
+++ jakarta/poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestBasic.java Fri Mar  3 08:57:55 2006
@@ -112,10 +112,8 @@
     /**
      * <p>Checks the names of the files in the POI filesystem. They
      * are expected to be in a certain order.</p>
-     * 
-     * @exception IOException if an I/O exception occurs
      */
-    public void testReadFiles() throws IOException
+    public void testReadFiles()
     {
         String[] expected = POI_FILES;
         for (int i = 0; i < expected.length; i++)
@@ -166,7 +164,7 @@
                 o = ex;
             }
             in.close();
-            Assert.assertEquals(o.getClass(), expected[i]);
+            Assert.assertEquals(expected[i], o.getClass());
         }
     }
 
@@ -223,7 +221,7 @@
         Assert.assertNotNull(s.getProperties());
         Assert.assertEquals(17, s.getPropertyCount());
         Assert.assertEquals("Titel", s.getProperty(2));
-        Assert.assertEquals(1764, s.getSize());
+        Assert.assertEquals(1748, s.getSize());
     }
 
 

Modified: jakarta/poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestClassID.java
URL: http://svn.apache.org/viewcvs/jakarta/poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestClassID.java?rev=382887&r1=382886&r2=382887&view=diff
==============================================================================
Binary files - no diff available.

Propchange: jakarta/poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestClassID.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestClassID.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: jakarta/poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestClassID.java
            ('svn:mime-type' removed)

Modified: jakarta/poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestEmptyProperties.java
URL: http://svn.apache.org/viewcvs/jakarta/poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestEmptyProperties.java?rev=382887&r1=382886&r2=382887&view=diff
==============================================================================
--- jakarta/poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestEmptyProperties.java (original)
+++ jakarta/poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestEmptyProperties.java Fri Mar  3 08:57:55 2006
@@ -1,4 +1,3 @@
-
 /* ====================================================================
    Copyright 2002-2004   Apache Software Foundation
 
@@ -27,16 +26,18 @@
 import junit.framework.Assert;
 import junit.framework.TestCase;
 
+import org.apache.poi.hpsf.DocumentSummaryInformation;
 import org.apache.poi.hpsf.HPSFException;
 import org.apache.poi.hpsf.MarkUnsupportedException;
 import org.apache.poi.hpsf.NoPropertySetStreamException;
 import org.apache.poi.hpsf.PropertySet;
 import org.apache.poi.hpsf.PropertySetFactory;
 import org.apache.poi.hpsf.SummaryInformation;
+import org.apache.poi.hpsf.Variant;
 
 /**
  * <p>Test case for OLE2 files with empty properties. An empty property's type
- * is {@link Variant.VT_EMPTY}.</p>
+ * is {@link Variant#VT_EMPTY}.</p>
  *
  * @author Rainer Klute <a
  * href="mailto:klute@rainer-klute.de">&lt;klute@rainer-klute.de&gt;</a>
@@ -96,10 +97,8 @@
     /**
      * <p>Checks the names of the files in the POI filesystem. They
      * are expected to be in a certain order.</p>
-     * 
-     * @exception IOException if an I/O exception occurs
      */
-    public void testReadFiles() throws IOException
+    public void testReadFiles()
     {
         String[] expected = POI_FILES;
         for (int i = 0; i < expected.length; i++)



---------------------------------------------------------------------
To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
Mailing List:    http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta POI Project: http://jakarta.apache.org/poi/