From 6d1eefc2eac5872073df2cb1e513ef5b5c1a0ec4 Mon Sep 17 00:00:00 2001 From: Rainer Klute Date: Thu, 23 Oct 2003 20:44:24 +0000 Subject: [PATCH] - Added Robert Flaherty's method getCustomProperties() (refactored) - Got rid of the PropertySet instance variable sectionCount. Use getSectionCount() instead! - Minor fixes git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353409 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/hpsf/DocumentSummaryInformation.java | 36 +++++++++++++++++++ .../apache/poi/hpsf/MutablePropertySet.java | 3 -- .../org/apache/poi/hpsf/MutableSection.java | 4 +-- src/java/org/apache/poi/hpsf/PropertySet.java | 14 ++------ src/java/org/apache/poi/hpsf/Section.java | 6 ++-- .../org/apache/poi/hpsf/VariantSupport.java | 4 +-- 6 files changed, 45 insertions(+), 22 deletions(-) diff --git a/src/java/org/apache/poi/hpsf/DocumentSummaryInformation.java b/src/java/org/apache/poi/hpsf/DocumentSummaryInformation.java index 704717cf91..9295b735e5 100644 --- a/src/java/org/apache/poi/hpsf/DocumentSummaryInformation.java +++ b/src/java/org/apache/poi/hpsf/DocumentSummaryInformation.java @@ -54,6 +54,10 @@ */ package org.apache.poi.hpsf; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + import org.apache.poi.hpsf.wellknown.PropertyIDMap; /** @@ -63,6 +67,7 @@ import org.apache.poi.hpsf.wellknown.PropertyIDMap; * @author Rainer Klute <klute@rainer-klute.de> * @author Drew Varner (Drew.Varner closeTo sc.edu) + * @author robert_flaherty@hyperion.com * @see SummaryInformation * @version $Id$ * @since 2002-02-09 @@ -300,4 +305,35 @@ public class DocumentSummaryInformation extends SpecialPropertySet return getPropertyBooleanValue(PropertyIDMap.PID_LINKSDIRTY); } + + + /** + *

Gets the custom properties as a map from the property name to + * value.

+ * + * @return The custom properties if any exist, null otherwise. + * @since 2003-10-22 + */ + public Map getCustomProperties() + { + Map nameToValue = null; + if (getSectionCount() >= 2) + { + final Section section = (Section) getSections().get(1); + final Map pidToName = + (Map) section.getProperty(PropertyIDMap.PID_DICTIONARY); + if (pidToName != null) + { + nameToValue = new HashMap(pidToName.size()); + for (Iterator i = pidToName.entrySet().iterator(); i.hasNext();) + { + final Map.Entry e = (Map.Entry) i.next(); + final long pid = ((Number) e.getKey()).longValue(); + nameToValue.put(e.getValue(), section.getProperty(pid)); + } + } + } + return nameToValue; + } + } diff --git a/src/java/org/apache/poi/hpsf/MutablePropertySet.java b/src/java/org/apache/poi/hpsf/MutablePropertySet.java index f9f1333eec..94bdfdc16b 100644 --- a/src/java/org/apache/poi/hpsf/MutablePropertySet.java +++ b/src/java/org/apache/poi/hpsf/MutablePropertySet.java @@ -106,7 +106,6 @@ public class MutablePropertySet extends PropertySet * one section it is added right here. */ sections = new LinkedList(); sections.add(new MutableSection()); - sectionCount = 1; } @@ -204,7 +203,6 @@ public class MutablePropertySet extends PropertySet public void clearSections() { sections = null; - sectionCount = 0; } @@ -221,7 +219,6 @@ public class MutablePropertySet extends PropertySet if (sections == null) sections = new LinkedList(); sections.add(section); - sectionCount = sections.size(); } diff --git a/src/java/org/apache/poi/hpsf/MutableSection.java b/src/java/org/apache/poi/hpsf/MutableSection.java index e60edf5bd4..871c133605 100644 --- a/src/java/org/apache/poi/hpsf/MutableSection.java +++ b/src/java/org/apache/poi/hpsf/MutableSection.java @@ -553,8 +553,8 @@ public class MutableSection extends Section /** *

Sets the section's dictionary. All keys in the dictionary must be - * {@see java.lang.Long} instances, all values must be - * {@see java.lang.String}s. This method overwrites the properties with IDs + * {@link java.lang.Long} instances, all values must be + * {@link java.lang.String}s. This method overwrites the properties with IDs * 0 and 1 since they are reserved for the dictionary and the dictionary's * codepage. Setting these properties explicitly might have surprising * effects. An application should never do this but always use this diff --git a/src/java/org/apache/poi/hpsf/PropertySet.java b/src/java/org/apache/poi/hpsf/PropertySet.java index d0af70efe0..dae88e73c5 100644 --- a/src/java/org/apache/poi/hpsf/PropertySet.java +++ b/src/java/org/apache/poi/hpsf/PropertySet.java @@ -207,15 +207,6 @@ public class PropertySet - /** - *

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

- * - *

FIXME (2): Get rid of this! The number of sections is implicitly - * available.

- */ - protected int sectionCount; - - /** *

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

@@ -224,7 +215,7 @@ public class PropertySet */ public int getSectionCount() { - return sectionCount; + return sections.size(); } @@ -459,7 +450,7 @@ public class PropertySet o += LittleEndian.INT_SIZE; classID = new ClassID(src, o); o += ClassID.LENGTH; - sectionCount = LittleEndian.getInt(src, o); + final int sectionCount = LittleEndian.getInt(src, o); o += LittleEndian.INT_SIZE; if (sectionCount <= 0) throw new HPSFRuntimeException("Section count " + sectionCount + @@ -635,6 +626,7 @@ public class PropertySet */ public Section getSingleSection() { + final int sectionCount = getSectionCount(); if (sectionCount != 1) throw new NoSingleSectionException ("Property set contains " + sectionCount + " sections."); diff --git a/src/java/org/apache/poi/hpsf/Section.java b/src/java/org/apache/poi/hpsf/Section.java index dcbea1b60d..2cc4cc1485 100644 --- a/src/java/org/apache/poi/hpsf/Section.java +++ b/src/java/org/apache/poi/hpsf/Section.java @@ -515,9 +515,7 @@ public class Section /* Extract properties 0 and 1 and remove them from the copy of the * arrays. */ Property p10 = null; - Property p11; Property p20 = null; - Property p21; for (int i = 0; i < pa1.length; i++) { final long id = pa1[i].getID(); @@ -529,7 +527,7 @@ public class Section } if (id == 1) { - p11 = pa1[i]; + // p11 = pa1[i]; pa1 = remove(pa1, i); i--; } @@ -545,7 +543,7 @@ public class Section } if (id == 1) { - p21 = pa2[i]; + // p21 = pa2[i]; pa2 = remove(pa2, i); i--; } diff --git a/src/java/org/apache/poi/hpsf/VariantSupport.java b/src/java/org/apache/poi/hpsf/VariantSupport.java index 3bc0c39c38..17892abd22 100644 --- a/src/java/org/apache/poi/hpsf/VariantSupport.java +++ b/src/java/org/apache/poi/hpsf/VariantSupport.java @@ -280,9 +280,9 @@ public class VariantSupport extends Variant // final int first = offset + LittleEndian.INT_SIZE; long bool = LittleEndian.getUInt(src, o1); if (bool != 0) - value = new Boolean(true); + value = Boolean.TRUE; else - value = new Boolean(false); + value = Boolean.FALSE; break; } default: