From 2ac503512a9f8381a0ce71c575ebe446df5ef2bd Mon Sep 17 00:00:00 2001 From: Rainer Klute Date: Fri, 3 May 2002 07:29:09 +0000 Subject: [PATCH] Enhancements from Drew for boolean properties. Plus doc change for DWord. git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@352594 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/hpsf/DocumentSummaryInformation.java | 24 ++++++------ src/java/org/apache/poi/hpsf/Property.java | 39 +++++++++++++++---- src/java/org/apache/poi/hpsf/PropertySet.java | 21 ++++++++++ src/java/org/apache/poi/hpsf/Section.java | 20 ++++++++++ .../apache/poi/hpsf/littleendian/DWord.java | 4 +- 5 files changed, 86 insertions(+), 22 deletions(-) diff --git a/src/java/org/apache/poi/hpsf/DocumentSummaryInformation.java b/src/java/org/apache/poi/hpsf/DocumentSummaryInformation.java index a950c0db8..3cc2499f7 100644 --- a/src/java/org/apache/poi/hpsf/DocumentSummaryInformation.java +++ b/src/java/org/apache/poi/hpsf/DocumentSummaryInformation.java @@ -65,6 +65,8 @@ import org.apache.poi.hpsf.wellknown.*; * @see SummaryInformation * * @author Rainer Klute (klute@rainer-klute.de) + * @author Drew Varner (Drew.Varner closeTo sc.edu) + * * @version $Id$ * @since 2002-02-09 */ @@ -191,16 +193,12 @@ public class DocumentSummaryInformation extends SpecialPropertySet /** - *

Returns the stream's scale (or null) - * when this method is implemented. Please note that the - * return type is likely to change! + *

Returns true when scaling of the thumbnail is + * desired, false if cropping is desired.

*/ public boolean getScale() { - if (true) - throw new UnsupportedOperationException("FIXME"); - // return (byte[]) getProperty(PropertyIDMap.PID_SCALE); - return false; + return getPropertyBooleanValue(PropertyIDMap.PID_SCALE); } @@ -254,15 +252,15 @@ public class DocumentSummaryInformation extends SpecialPropertySet /** - *

Returns the stream's links dirty information when - * this method is implemented. + *

Returns true if the custom links are hampered + * by excessive noise, for all applications.

+ * + *

FIXME: Explain this some more! I (Rainer) + * don't understand it.

*/ public boolean getLinksDirty() { - if (true) - throw new UnsupportedOperationException("FIXME"); - // return (byte[]) getProperty(PropertyIDMap.PID_LINKSDIRTY); - return false; + return getPropertyBooleanValue(PropertyIDMap.PID_LINKSDIRTY); } } diff --git a/src/java/org/apache/poi/hpsf/Property.java b/src/java/org/apache/poi/hpsf/Property.java index 282655802..943260383 100644 --- a/src/java/org/apache/poi/hpsf/Property.java +++ b/src/java/org/apache/poi/hpsf/Property.java @@ -90,6 +90,7 @@ import org.apache.poi.hpsf.littleendian.*; * * @author Rainer Klute (klute@rainer-klute.de) * @author Drew Varner (Drew.Varner InAndAround sc.edu) + * * @version $Id$ * @since 2002-02-09 */ @@ -207,21 +208,45 @@ public class Property } case Variant.VT_CF: { - // the first four bytes in src, from - // src[offset] to src[offset + 3] contain - // the DWord for VT_CF, so skip it, we don't - // need it + /* The first four bytes in src, from rc[offset] to + * src[offset + 3] contain the DWord for VT_CF, so + * skip it, we don't need it. */ - // truncate the length of the return array by - // a DWord length (4 bytes) + /* Truncate the length of the return array by a DWord + * length (4 bytes). */ length = length - DWord.LENGTH; final byte[] v = new byte[length]; for (int i = 0; i < length; i++) - v[i] = src[offset + i + DWord.LENGTH]; + v[i] = src[o + i]; value = v; break; } + case Variant.VT_BOOL: + { + /* The first four bytes in src, from src[offset] to + * src[offset + 3] contain the DWord for VT_BOOL, so + * skip it, we don't need it. */ + final int first = o + DWord.LENGTH; + DWord bool = new DWord(src,o); + if (bool.intValue() == -1) + { + value = new Boolean(true); + } + else if (bool.intValue() == 0) + { + value = new Boolean(false); + } + else + /* FIXME: Someone might invent a new + * HPSFRuntimeException subclass + * IllegalPropertySetDataException for this and + * similar cases. */ + throw new HPSFRuntimeException + ("Illegal property set data: A boolean must be " + + "either -1 (true) or 0 (false)."); + break; + } default: { final byte[] v = new byte[length]; diff --git a/src/java/org/apache/poi/hpsf/PropertySet.java b/src/java/org/apache/poi/hpsf/PropertySet.java index b32899329..0ac0e3783 100644 --- a/src/java/org/apache/poi/hpsf/PropertySet.java +++ b/src/java/org/apache/poi/hpsf/PropertySet.java @@ -91,6 +91,8 @@ import org.apache.poi.poifs.filesystem.*; * Section}). * * @author Rainer Klute (klute@rainer-klute.de) + * @author Drew Varner (Drew.Varner hanginIn sc.edu) + * * @version $Id$ * @since 2002-02-09 */ @@ -465,6 +467,25 @@ public class PropertySet + /** + *

Convenience method returning the value of a boolean property + * with the specified ID. If the property is not available, + * false is returned. A subsequent call to {@link + * #wasNull} will return true to let the caller + * distinguish that case from a real property value of + * false.

+ * + * @throws NoSingleSectionException if the {@link PropertySet} has + * more or less than one {@link Section}. + */ + protected boolean getPropertyBooleanValue(final int id) + throws NoSingleSectionException + { + return getSingleSection().getPropertyBooleanValue(id); + } + + + /** *

Convenience method returning the value of the numeric * property with the specified ID. If the property is not diff --git a/src/java/org/apache/poi/hpsf/Section.java b/src/java/org/apache/poi/hpsf/Section.java index cc0c68230..03072bfd0 100644 --- a/src/java/org/apache/poi/hpsf/Section.java +++ b/src/java/org/apache/poi/hpsf/Section.java @@ -62,6 +62,8 @@ import org.apache.poi.hpsf.wellknown.*; *

Represents a section in a {@link PropertySet}.

* * @author Rainer Klute (klute@rainer-klute.de) + * @author Drew Varner (Drew.Varner allUpIn sc.edu) + * * @version $Id$ * @since 2002-02-09 */ @@ -231,6 +233,24 @@ public class Section + /** + *

Returns the value of the boolean property with the specified + * ID. If the property is not available, false is + * returned. A subsequent call to {@link #wasNull} will return + * true to let the caller distinguish that case from + * a real property value of false.

+ */ + protected boolean getPropertyBooleanValue(final int id) + { + final Boolean b = (Boolean) getProperty(id); + if (b != null) + return b.booleanValue(); + else + return false; + } + + + private boolean wasNull; /** diff --git a/src/java/org/apache/poi/hpsf/littleendian/DWord.java b/src/java/org/apache/poi/hpsf/littleendian/DWord.java index 2a7fb34dc..d369716c2 100644 --- a/src/java/org/apache/poi/hpsf/littleendian/DWord.java +++ b/src/java/org/apache/poi/hpsf/littleendian/DWord.java @@ -63,7 +63,7 @@ package org.apache.poi.hpsf.littleendian; /** - *

Represents a double word (4 bytes).

+ *

Represents an unsigned double word (4 bytes).

* * @author Rainer Klute (klute@rainer-klute.de) * @version $Id$ @@ -97,7 +97,7 @@ public class DWord extends LittleEndian /** - *

Return the integral value of this {@link DWord}.

+ *

Returns the integral value of this {@link DWord}.

* *

FIXME: Introduce a superclass for the * numeric types and make this a method of the superclass!