]> source.dussan.org Git - poi.git/commitdiff
Support more OOXML custom properties for text extraction
authorNick Burch <nick@apache.org>
Wed, 11 Jan 2012 17:59:36 +0000 (17:59 +0000)
committerNick Burch <nick@apache.org>
Wed, 11 Jan 2012 17:59:36 +0000 (17:59 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1230168 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/POIXMLPropertiesTextExtractor.java

index 05528f6285e1b981b19e210765fa89a620e87fcf..51a4399f3fea7878c90461ba1c3a82567964e5df 100644 (file)
 
 package org.apache.poi;
 
-import org.apache.poi.openxml4j.opc.internal.PackagePropertiesPart;
-import org.openxmlformats.schemas.officeDocument.x2006.customProperties.CTProperty;
-
 import java.math.BigDecimal;
 import java.util.Date;
 import java.util.List;
 
+import org.apache.poi.openxml4j.opc.internal.PackagePropertiesPart;
+import org.openxmlformats.schemas.officeDocument.x2006.customProperties.CTProperty;
+
 /**
  * A {@link POITextExtractor} for returning the textual
  *  content of the OOXML file properties, eg author
@@ -122,58 +122,111 @@ public class POIXMLPropertiesTextExtractor extends POIXMLTextExtractor {
 
                return text.toString();
        }
-       /**
-        * Returns the custom document properties, if
-        *  there are any
-        */
-       public String getCustomPropertiesText() {
-               StringBuffer text = new StringBuffer();
-               org.openxmlformats.schemas.officeDocument.x2006.customProperties.CTProperties
-                       props = getDocument().getProperties().getCustomProperties().getUnderlyingProperties();
-
-               List<CTProperty> properties = props.getPropertyList();
-               for(CTProperty property : properties) {
-                       String val = "(not implemented!)";
-                       
-                       if (property.isSetLpwstr()) {
-                          val = property.getLpwstr(); 
-                       }
-                       else if (property.isSetFiletime()) {
-                          val = property.getFiletime().toString(); 
-                       }
-                       else if (property.isSetDate()) {
-                          val = property.getDate().toString(); 
-                       }
-                       else if (property.isSetDecimal()) {
-                          BigDecimal d = property.getDecimal();
-                          if (d == null) {
-                             val = null;
-                          } else {
-                             val = d.toPlainString();
-                          }
-                       }
-                       else if (property.isSetBool()) {
-                          val = Boolean.toString( property.getBool() );
-                       }
-                       else if (property.isSetInt()) {
-                          val = Integer.toString( property.getInt() ); 
-                       }
-                       else if (property.isSetLpstr()) {
-                          val = property.getLpstr(); 
-                       }
-                       else if (property.isSetI4()) {
-                          /* Number in Excel for example.... Why i4 ? Ask microsoft. */ 
-                          val = Integer.toString(property.getI4()); 
-                       }
-                       
-                       text.append(
-                                       property.getName() +
-                                       " = " + val + "\n"
-                       );
-               }
+   /**
+    * Returns the custom document properties, if
+    *  there are any
+    */
+   public String getCustomPropertiesText() {
+      StringBuffer text = new StringBuffer();
+      org.openxmlformats.schemas.officeDocument.x2006.customProperties.CTProperties
+      props = getDocument().getProperties().getCustomProperties().getUnderlyingProperties();
 
-               return text.toString();
-       }
+      List<CTProperty> properties = props.getPropertyList();
+      for(CTProperty property : properties) {
+         String val = "(not implemented!)";
+
+         if (property.isSetLpwstr()) {
+            val = property.getLpwstr(); 
+         }
+         else if (property.isSetLpstr()) {
+            val = property.getLpstr(); 
+         }
+         else if (property.isSetDate()) {
+            val = property.getDate().toString(); 
+         }
+         else if (property.isSetFiletime()) {
+            val = property.getFiletime().toString(); 
+         }
+         else if (property.isSetBool()) {
+            val = Boolean.toString( property.getBool() );
+         }
+
+         // Integers
+         else if (property.isSetI1()) {
+            val = Integer.toString(property.getI1()); 
+         }
+         else if (property.isSetI2()) {
+            val = Integer.toString(property.getI2()); 
+         }
+         else if (property.isSetI4()) {
+            val = Integer.toString(property.getI4()); 
+         }
+         else if (property.isSetI8()) {
+            val = Long.toString(property.getI8()); 
+         }
+         else if (property.isSetInt()) {
+            val = Integer.toString( property.getInt() ); 
+         }
+
+         // Unsigned Integers
+         else if (property.isSetUi1()) {
+            val = Integer.toString(property.getUi1()); 
+         }
+         else if (property.isSetUi2()) {
+            val = Integer.toString(property.getUi2()); 
+         }
+         else if (property.isSetUi4()) {
+            val = Long.toString(property.getUi4()); 
+         }
+         else if (property.isSetUi8()) {
+            val = property.getUi8().toString(); 
+         }
+         else if (property.isSetUint()) {
+            val = Long.toString(property.getUint()); 
+         }
+
+         // Reals
+         else if (property.isSetR4()) {
+            val = Float.toString( property.getR4() ); 
+         }
+         else if (property.isSetR8()) {
+            val = Double.toString( property.getR8() ); 
+         }
+         else if (property.isSetDecimal()) {
+            BigDecimal d = property.getDecimal();
+            if (d == null) {
+               val = null;
+            } else {
+               val = d.toPlainString();
+            }
+         }
+
+         else if (property.isSetArray()) {
+            // TODO Fetch the array values and output 
+         }
+         else if (property.isSetVector()) {
+            // TODO Fetch the vector values and output
+         }
+
+         else if (property.isSetBlob() || property.isSetOblob()) {
+            // TODO Decode, if possible
+         }
+         else if (property.isSetStream() || property.isSetOstream() ||
+                  property.isSetVstream()) {
+            // TODO Decode, if possible
+         }
+         else if (property.isSetStorage() || property.isSetOstorage()) {
+            // TODO Decode, if possible
+         }
+
+         text.append(
+               property.getName() +
+               " = " + val + "\n"
+         );
+      }
+
+      return text.toString();
+   }
 
        public String getText() {
                try {