- 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
This commit is contained in:
Rainer Klute 2003-10-23 20:44:24 +00:00
parent 53b75e9c11
commit e237bc3edd
6 changed files with 45 additions and 22 deletions

View File

@ -54,6 +54,10 @@
*/ */
package org.apache.poi.hpsf; package org.apache.poi.hpsf;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.apache.poi.hpsf.wellknown.PropertyIDMap; import org.apache.poi.hpsf.wellknown.PropertyIDMap;
/** /**
@ -63,6 +67,7 @@ import org.apache.poi.hpsf.wellknown.PropertyIDMap;
* @author Rainer Klute <a * @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>
* @author Drew Varner (Drew.Varner closeTo sc.edu) * @author Drew Varner (Drew.Varner closeTo sc.edu)
* @author robert_flaherty@hyperion.com
* @see SummaryInformation * @see SummaryInformation
* @version $Id$ * @version $Id$
* @since 2002-02-09 * @since 2002-02-09
@ -300,4 +305,35 @@ public class DocumentSummaryInformation extends SpecialPropertySet
return getPropertyBooleanValue(PropertyIDMap.PID_LINKSDIRTY); return getPropertyBooleanValue(PropertyIDMap.PID_LINKSDIRTY);
} }
/**
* <p>Gets the custom properties as a map from the property name to
* value.</p>
*
* @return The custom properties if any exist, <code>null</code> 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;
}
} }

View File

@ -106,7 +106,6 @@ public class MutablePropertySet extends PropertySet
* one section it is added right here. */ * one section it is added right here. */
sections = new LinkedList(); sections = new LinkedList();
sections.add(new MutableSection()); sections.add(new MutableSection());
sectionCount = 1;
} }
@ -204,7 +203,6 @@ public class MutablePropertySet extends PropertySet
public void clearSections() public void clearSections()
{ {
sections = null; sections = null;
sectionCount = 0;
} }
@ -221,7 +219,6 @@ public class MutablePropertySet extends PropertySet
if (sections == null) if (sections == null)
sections = new LinkedList(); sections = new LinkedList();
sections.add(section); sections.add(section);
sectionCount = sections.size();
} }

View File

@ -553,8 +553,8 @@ public class MutableSection extends Section
/** /**
* <p>Sets the section's dictionary. All keys in the dictionary must be * <p>Sets the section's dictionary. All keys in the dictionary must be
* {@see java.lang.Long} instances, all values must be * {@link java.lang.Long} instances, all values must be
* {@see java.lang.String}s. This method overwrites the properties with IDs * {@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 * 0 and 1 since they are reserved for the dictionary and the dictionary's
* codepage. Setting these properties explicitly might have surprising * codepage. Setting these properties explicitly might have surprising
* effects. An application should never do this but always use this * effects. An application should never do this but always use this

View File

@ -207,15 +207,6 @@ public class PropertySet
/**
* <p>The number of sections in this {@link PropertySet}.</p>
*
* <p>FIXME (2): Get rid of this! The number of sections is implicitly
* available.</p>
*/
protected int sectionCount;
/** /**
* <p>Returns the number of {@link Section}s in the property * <p>Returns the number of {@link Section}s in the property
* set.</p> * set.</p>
@ -224,7 +215,7 @@ public class PropertySet
*/ */
public int getSectionCount() public int getSectionCount()
{ {
return sectionCount; return sections.size();
} }
@ -459,7 +450,7 @@ public class PropertySet
o += LittleEndian.INT_SIZE; o += LittleEndian.INT_SIZE;
classID = new ClassID(src, o); classID = new ClassID(src, o);
o += ClassID.LENGTH; o += ClassID.LENGTH;
sectionCount = LittleEndian.getInt(src, o); final int sectionCount = LittleEndian.getInt(src, o);
o += LittleEndian.INT_SIZE; o += LittleEndian.INT_SIZE;
if (sectionCount <= 0) if (sectionCount <= 0)
throw new HPSFRuntimeException("Section count " + sectionCount + throw new HPSFRuntimeException("Section count " + sectionCount +
@ -635,6 +626,7 @@ public class PropertySet
*/ */
public Section getSingleSection() public Section getSingleSection()
{ {
final int sectionCount = getSectionCount();
if (sectionCount != 1) if (sectionCount != 1)
throw new NoSingleSectionException throw new NoSingleSectionException
("Property set contains " + sectionCount + " sections."); ("Property set contains " + sectionCount + " sections.");

View File

@ -515,9 +515,7 @@ public class Section
/* Extract properties 0 and 1 and remove them from the copy of the /* Extract properties 0 and 1 and remove them from the copy of the
* arrays. */ * arrays. */
Property p10 = null; Property p10 = null;
Property p11;
Property p20 = null; Property p20 = null;
Property p21;
for (int i = 0; i < pa1.length; i++) for (int i = 0; i < pa1.length; i++)
{ {
final long id = pa1[i].getID(); final long id = pa1[i].getID();
@ -529,7 +527,7 @@ public class Section
} }
if (id == 1) if (id == 1)
{ {
p11 = pa1[i]; // p11 = pa1[i];
pa1 = remove(pa1, i); pa1 = remove(pa1, i);
i--; i--;
} }
@ -545,7 +543,7 @@ public class Section
} }
if (id == 1) if (id == 1)
{ {
p21 = pa2[i]; // p21 = pa2[i];
pa2 = remove(pa2, i); pa2 = remove(pa2, i);
i--; i--;
} }

View File

@ -280,9 +280,9 @@ public class VariantSupport extends Variant
// final int first = offset + LittleEndian.INT_SIZE; // final int first = offset + LittleEndian.INT_SIZE;
long bool = LittleEndian.getUInt(src, o1); long bool = LittleEndian.getUInt(src, o1);
if (bool != 0) if (bool != 0)
value = new Boolean(true); value = Boolean.TRUE;
else else
value = new Boolean(false); value = Boolean.FALSE;
break; break;
} }
default: default: