From 17da836e8596aa8eff34323f6a533f4554c36839 Mon Sep 17 00:00:00 2001 From: Rainer Klute Date: Sat, 13 Sep 2003 12:31:28 +0000 Subject: [PATCH] - PropertySetFactory.create(InputStream) no longer throws an UnexpectedPropertySetTypeException. - HPSFRuntimeException is thrown when the application tries to read a non-integer property with Section.getPropertyIntValue(long). - Package description updated. - ClassIDhashCode() implemented. git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353349 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/poi/hpsf/ClassID.java | 2 +- .../org/apache/poi/hpsf/MutableSection.java | 1 - .../apache/poi/hpsf/PropertySetFactory.java | 24 ++++++++---- src/java/org/apache/poi/hpsf/Section.java | 13 +++++-- .../apache/poi/hpsf/SummaryInformation.java | 17 +++++--- src/java/org/apache/poi/hpsf/package.html | 39 ++++++++++++------- 6 files changed, 65 insertions(+), 31 deletions(-) diff --git a/src/java/org/apache/poi/hpsf/ClassID.java b/src/java/org/apache/poi/hpsf/ClassID.java index e179a6352..ddd52c686 100644 --- a/src/java/org/apache/poi/hpsf/ClassID.java +++ b/src/java/org/apache/poi/hpsf/ClassID.java @@ -236,7 +236,7 @@ public class ClassID */ public int hashCode() { - throw new UnsupportedOperationException("FIXME: Not yet implemented."); + return new String(bytes).hashCode(); } } diff --git a/src/java/org/apache/poi/hpsf/MutableSection.java b/src/java/org/apache/poi/hpsf/MutableSection.java index 0249269a8..10945426a 100644 --- a/src/java/org/apache/poi/hpsf/MutableSection.java +++ b/src/java/org/apache/poi/hpsf/MutableSection.java @@ -62,7 +62,6 @@ import java.util.LinkedList; import java.util.List; import org.apache.poi.util.LittleEndian; -import org.apache.poi.util.LittleEndianConsts; /** *

Adds writing capability to the {@link Section} class.

diff --git a/src/java/org/apache/poi/hpsf/PropertySetFactory.java b/src/java/org/apache/poi/hpsf/PropertySetFactory.java index 39b4ac88a..6f6d8e6ed 100644 --- a/src/java/org/apache/poi/hpsf/PropertySetFactory.java +++ b/src/java/org/apache/poi/hpsf/PropertySetFactory.java @@ -56,6 +56,7 @@ package org.apache.poi.hpsf; import java.io.InputStream; import java.io.IOException; +import java.rmi.UnexpectedException; /** *

Factory class to create instances of {@link SummaryInformation}, @@ -89,15 +90,24 @@ public class PropertySetFactory */ public static PropertySet create(final InputStream stream) throws NoPropertySetStreamException, MarkUnsupportedException, - UnexpectedPropertySetTypeException, IOException + 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; + try + { + if (ps.isSummaryInformation()) + return new SummaryInformation(ps); + else if (ps.isDocumentSummaryInformation()) + return new DocumentSummaryInformation(ps); + else + return ps; + } + catch (UnexpectedPropertySetTypeException ex) + { + /* This exception will never be throws because we already checked + * explicitly for this case above. */ + throw new UnexpectedException(ex.toString()); + } } } diff --git a/src/java/org/apache/poi/hpsf/Section.java b/src/java/org/apache/poi/hpsf/Section.java index a85894dcf..9a27a3ded 100644 --- a/src/java/org/apache/poi/hpsf/Section.java +++ b/src/java/org/apache/poi/hpsf/Section.java @@ -401,11 +401,16 @@ public class Section */ protected int getPropertyIntValue(final long id) { - final Long i = (Long) getProperty(id); - if (i != null) - return i.intValue(); - else + final Long i; + final Object o = getProperty(id); + if (o == null) return 0; + if (!(o instanceof Long)) + throw new HPSFRuntimeException + ("This property is not an integer type, but " + + o.getClass().getName() + "."); + i = (Long) o; + return i.intValue(); } diff --git a/src/java/org/apache/poi/hpsf/SummaryInformation.java b/src/java/org/apache/poi/hpsf/SummaryInformation.java index 5384ae4ee..2b32f3fc3 100644 --- a/src/java/org/apache/poi/hpsf/SummaryInformation.java +++ b/src/java/org/apache/poi/hpsf/SummaryInformation.java @@ -204,13 +204,19 @@ public class SummaryInformation extends SpecialPropertySet /** - *

Returns the stream's edit time (or null).

+ *

Returns the total time spent in editing the document + * (or 0).

* - * @return The edit time or null + * @return The total time spent in editing the document or 0 if the {@link + * SummaryInformation} does not contain this information. */ - public Date getEditTime() + public long getEditTime() { - return (Date) getProperty(PropertyIDMap.PID_EDITTIME); + final Date d = (Date) getProperty(PropertyIDMap.PID_EDITTIME); + if (d == null) + return 0; + else + return Util.dateToFileTime(d); } @@ -258,7 +264,8 @@ public class SummaryInformation extends SpecialPropertySet *

Returns the stream's page count or 0 if the {@link * SummaryInformation} does not contain a page count.

* - * @return The page count or null + * @return The page count or 0 if the {@link SummaryInformation} does not + * contain a page count. */ public int getPageCount() { diff --git a/src/java/org/apache/poi/hpsf/package.html b/src/java/org/apache/poi/hpsf/package.html index 31fcb05bf..346b5c1bc 100644 --- a/src/java/org/apache/poi/hpsf/package.html +++ b/src/java/org/apache/poi/hpsf/package.html @@ -9,7 +9,7 @@

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 + contain meta data like author, title, last saving time etc. These items are called properties and stored in property set streams along with the document itself. These streams are commonly named \005SummaryInformation and @@ -71,31 +71,44 @@ the hassle of first finding out what the title's property ID is and then using this ID to get the property's value.

+

Writing properties can be done with the classes + {@link org.apache.poi.hpsf.MutablePropertySet}, {@link + org.apache.poi.hpsf.MutableSection}, and {@link + org.apache.poi.hpsf.MutableProperty}.

+ +
+

History

+ +
+
2003-09-11:
+ +
+

{@link org.apache.poi.hpsf.PropertySetFactory#create(InputStream)} no + longer throws an + {@link org.apache.poi.hpsf.UnexpectedPropertySetTypeException}.

+
+
+ +

To Do

-

The following is still left to be implemented:

+

The following is still left to be implemented. Sponsering could foster + these issues considerably.

  • -

    Property dictionaries

    +

    Convenience methods for setting summary information and document + summary information properties

  • -

    Writing property sets

    +

    Better codepage support

  • -

    Codepage support

    -
  • - -
  • -

    Property type Unicode string

    -
  • - -
  • -

    Further property types

    +

    Support for more property (variant) types