]> source.dussan.org Git - poi.git/commitdiff
A bit more towards matching properties to chunks
authorNick Burch <nick@apache.org>
Mon, 4 Feb 2013 21:46:30 +0000 (21:46 +0000)
committerNick Burch <nick@apache.org>
Mon, 4 Feb 2013 21:46:30 +0000 (21:46 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1442388 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/src/org/apache/poi/hsmf/datatypes/MAPIProperty.java
src/scratchpad/src/org/apache/poi/hsmf/datatypes/PropertiesChunk.java

index a5ee6cdca5b22b2a2b9e2168406281638a6e6d3c..20a8a0a2d53b9c222dcf5dd079ce04b9052c3317 100644 (file)
@@ -1058,6 +1058,15 @@ public class MAPIProperty {
          attributes.put(id, this);
       }
    }
+   
+   public String asFileName() {
+      String str = Integer.toHexString(id).toUpperCase();
+      while(str.length() < 4) {
+         str = "0" + str;
+      }
+      return str + usualType.asFileEnding();
+   }
+
    public String toString() {
       StringBuffer str = new StringBuffer();
       str.append(name);
index 78034fec912cfac1169afdcc644578aca795a33a..6e1b12bdfc7ecc2ed498df378aba3f361487a922 100644 (file)
@@ -28,6 +28,7 @@ import java.util.Map;
 import org.apache.poi.hsmf.datatypes.PropertyValue.LongLongPropertyValue;
 import org.apache.poi.hsmf.datatypes.PropertyValue.TimePropertyValue;
 import org.apache.poi.hsmf.datatypes.Types.MAPIType;
+import org.apache.poi.util.HexDump;
 import org.apache.poi.util.IOUtils;
 import org.apache.poi.util.LittleEndian;
 import org.apache.poi.util.LittleEndian.BufferUnderrunException;
@@ -103,7 +104,33 @@ public abstract class PropertiesChunk extends Chunk {
     *  up the Chunks in it with our Variable Sized Properties.
     */
    protected void matchVariableSizedPropertiesToChunks() {
-      // TODO
+      // Index the Parent Group chunks for easy lookup
+      // TODO Is this the right way?
+      Map<Integer,Chunk> chunks = new HashMap<Integer, Chunk>();
+      for (Chunk chunk : parentGroup.getChunks()) {
+         chunks.put(chunk.chunkId, chunk);
+      }
+      
+      // Loop over our values, looking for chunk based ones
+      for (List<PropertyValue> vals : properties.values()) {
+         if (vals != null) {
+            for (PropertyValue val : vals) {
+               if (val instanceof ChunkBasedPropertyValue) {
+                  ChunkBasedPropertyValue cVal = (ChunkBasedPropertyValue)val;
+                  Chunk chunk = chunks.get(cVal.getProperty().id);
+//System.err.println(cVal + " -> " + HexDump.toHex(cVal.data));                  
+                  
+                  // TODO Make sense of the raw offset value
+                  
+                  if (chunk != null) {
+                     cVal.setValue(chunk);
+                  } else {
+                     logger.log(POILogger.WARN, "No chunk found matching Property " + cVal);
+                  }
+               }
+            }
+         }
+      }
    }
 
    protected void readProperties(InputStream value) throws IOException {