Author: nick
Date: Wed Jul 3 11:36:11 2013
New Revision: 1499329
URL: http://svn.apache.org/r1499329
Log:
Refactor to avoid logic duplication on the property value -> string conversion
Modified:
poi/trunk/src/java/org/apache/poi/hpsf/SpecialPropertySet.java
poi/trunk/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java
Modified: poi/trunk/src/java/org/apache/poi/hpsf/SpecialPropertySet.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hpsf/SpecialPropertySet.java?rev=1499329&r1=1499328&r2=1499329&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hpsf/SpecialPropertySet.java (original)
+++ poi/trunk/src/java/org/apache/poi/hpsf/SpecialPropertySet.java Wed Jul 3
11:36:11 2013
@@ -51,17 +51,14 @@ import org.apache.poi.util.LittleEndian;
* general {@link PropertySet}. However, the current implementation
* went the other way round historically: the convenience classes came
* only late to my mind.</p>
- *
- * @author Rainer Klute <a
- * href="mailto:[email protected]"><[email protected]></a>
*/
public abstract class SpecialPropertySet extends MutablePropertySet
{
- /**
- * The id to name mapping of the properties
- * in this set.
- */
- public abstract PropertyIDMap getPropertySetIDMap();
+ /**
+ * The id to name mapping of the properties
+ * in this set.
+ */
+ public abstract PropertyIDMap getPropertySetIDMap();
/**
* <p>The "real" property set <code>SpecialPropertySet</code>
@@ -332,15 +329,17 @@ public abstract class SpecialPropertySet
* @return The property as a String, or null if unavailable
*/
protected String getPropertyStringValue(final int propertyId) {
- Object o = getProperty(propertyId);
-
+ Object propertyValue = getProperty(propertyId);
+ return getPropertyStringValue(propertyValue);
+ }
+ protected static String getPropertyStringValue(final Object propertyValue)
{
// Normal cases
- if (o == null) return null;
- if (o instanceof String) return (String)o;
+ if (propertyValue == null) return null;
+ if (propertyValue instanceof String) return (String)propertyValue;
// Do our best with some edge cases
- if (o instanceof byte[]) {
- byte[] b = (byte[])o;
+ if (propertyValue instanceof byte[]) {
+ byte[] b = (byte[])propertyValue;
if (b.length == 0) {
return "";
}
@@ -356,7 +355,7 @@ public abstract class SpecialPropertySet
// Maybe it's a string? who knows!
return new String(b);
}
- return o.toString();
+ return propertyValue.toString();
}
Modified:
poi/trunk/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java?rev=1499329&r1=1499328&r2=1499329&view=diff
==============================================================================
---
poi/trunk/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java
(original)
+++
poi/trunk/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java
Wed Jul 3 11:36:11 2013
@@ -32,7 +32,6 @@ import org.apache.poi.hpsf.SummaryInform
import org.apache.poi.hpsf.wellknown.PropertyIDMap;
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
-import org.apache.poi.util.LittleEndian;
/**
* Extracts all of the HPSF properties, both
@@ -66,7 +65,7 @@ public class HPSFPropertiesExtractor ext
Iterator<String> keys = cps.nameSet().iterator();
while (keys.hasNext()) {
String key = keys.next();
- String val = getPropertyValueText( cps.get(key) );
+ String val = HelperPropertySet.getPropertyValueText(
cps.get(key) );
text.append(key + " = " + val + "\n");
}
}
@@ -98,35 +97,12 @@ public class HPSFPropertiesExtractor ext
type = typeObj.toString();
}
- String val = getPropertyValueText( props[i].getValue() );
+ String val = HelperPropertySet.getPropertyValueText(
props[i].getValue() );
text.append(type + " = " + val + "\n");
}
return text.toString();
}
- private static String getPropertyValueText(Object val) {
- if (val == null) {
- return "(not set)";
- }
- if (val instanceof byte[]) {
- byte[] b = (byte[])val;
- if (b.length == 0) {
- return "";
- }
- if (b.length == 1) {
- return Byte.toString(b[0]);
- }
- if (b.length == 2) {
- return Integer.toString( LittleEndian.getUShort(b) );
- }
- if (b.length == 4) {
- return Long.toString( LittleEndian.getUInt(b) );
- }
- // Maybe it's a string? who knows!
- return new String(b);
- }
- return val.toString();
- }
/**
* @return the text of all the properties defined in
@@ -142,6 +118,18 @@ public class HPSFPropertiesExtractor ext
public POITextExtractor getMetadataTextExtractor() {
throw new IllegalStateException("You already have the Metadata Text
Extractor, not recursing!");
}
+
+ private static abstract class HelperPropertySet extends SpecialPropertySet
{
+ public HelperPropertySet() {
+ super(null);
+ }
+ public static String getPropertyValueText(Object val) {
+ if (val == null) {
+ return "(not set)";
+ }
+ return SpecialPropertySet.getPropertyStringValue(val);
+ }
+ }
public static void main(String[] args) throws IOException {
for (String file : args) {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]