]> source.dussan.org Git - poi.git/commitdiff
Continue with support for property lookups of chunks
authorNick Burch <nick@apache.org>
Fri, 1 Feb 2013 12:43:58 +0000 (12:43 +0000)
committerNick Burch <nick@apache.org>
Fri, 1 Feb 2013 12:43:58 +0000 (12:43 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1441427 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java
src/scratchpad/src/org/apache/poi/hsmf/datatypes/ChunkGroupWithProperties.java [new file with mode: 0644]
src/scratchpad/src/org/apache/poi/hsmf/datatypes/Chunks.java
src/scratchpad/src/org/apache/poi/hsmf/datatypes/PropertiesChunk.java
src/scratchpad/src/org/apache/poi/hsmf/datatypes/RecipientChunks.java
src/scratchpad/src/org/apache/poi/hsmf/parsers/POIFSChunkParser.java

index 4c5176c8bf5fd1fd215a3db9f811fafc01c52d6f..5e2c1d9642dce32d9e0a398710c27e9eb57b1fe8 100644 (file)
@@ -25,6 +25,7 @@ import java.io.OutputStream;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Calendar;
+import java.util.List;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -516,15 +517,15 @@ public class MAPIMessage extends POIDocument {
       if (mainChunks.submissionChunk != null) {
          return mainChunks.submissionChunk.getAcceptedAtTime();
       }
-      else if (mainChunks.messageProperties != null) {
+      else {
          // Try a few likely suspects...
          for (MAPIProperty prop : new MAPIProperty[] {
                MAPIProperty.CLIENT_SUBMIT_TIME, MAPIProperty.LAST_MODIFICATION_TIME,
                MAPIProperty.CREATION_TIME
          }) {
-            PropertyValue val = mainChunks.messageProperties.getValue(prop);
-            if (val != null) {
-               return ((TimePropertyValue)val).getValue();
+            List<PropertyValue> val = mainChunks.getProperties().get(prop);
+            if (val != null && val.size() > 0) {
+               return ((TimePropertyValue)val.get(0)).getValue();
             }
          }
       }
diff --git a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/ChunkGroupWithProperties.java b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/ChunkGroupWithProperties.java
new file mode 100644 (file)
index 0000000..3d99ea3
--- /dev/null
@@ -0,0 +1,38 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hsmf.datatypes;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * A group of chunks which is indexable by {@link MAPIProperty}
+ *  entries.
+ */
+public interface ChunkGroupWithProperties extends ChunkGroup {
+   /**
+    * Returns all the Properties contained in the Chunk, along
+    *  with their Values.
+    * Normally, each property will have one value, sometimes
+    *  none, and rarely multiple (normally for Unknown etc).
+    * For fixed sized properties, the value can be fetched 
+    *  straight from the {@link PropertyValue}. For variable
+    *  sized properties, you'll need to go via the chunk.
+    */
+   public Map<MAPIProperty,List<PropertyValue>> getProperties();
+}
index b4897b4fcc685df343d3b9cf446aaa63257f2a38..d7ad2f00990598ca093b337c6720e87279f643b7 100644 (file)
 package org.apache.poi.hsmf.datatypes;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.poi.util.POILogFactory;
+import org.apache.poi.util.POILogger;
+
 
 /**
  * Collection of convenience chunks for standard parts of the MSG file.
@@ -30,9 +34,17 @@ import java.util.Map;
  * 
  * A partial list is available at:
  *  http://msdn.microsoft.com/en-us/library/ms526356%28v=exchg.10%29.aspx
+ *  
+ * TODO Deprecate the public Chunks in favour of Property Lookups
  */
-public final class Chunks implements ChunkGroup {
-   /** Holds all the chunks that were found, indexed by their MAPIProperty */
+public final class Chunks implements ChunkGroupWithProperties {
+   private static POILogger logger = POILogFactory.getLogger(Chunks.class);
+
+   /** 
+    * Holds all the chunks that were found, indexed by their MAPIProperty.
+    * Normally a property will have zero chunks (fixed sized) or one chunk 
+    *  (variable size), but in some cases (eg Unknown) you may get more.
+    */
    private Map<MAPIProperty,List<Chunk>> allChunks = new HashMap<MAPIProperty,List<Chunk>>();
    
    /** Type of message that the MSG represents (ie. IPM.Note) */
@@ -70,8 +82,14 @@ public final class Chunks implements ChunkGroup {
    /** The message ID */
    public StringChunk messageId;
    /** The message properties */
-   public MessagePropertiesChunk messageProperties;
+   private MessagePropertiesChunk messageProperties;
 
+   public Map<MAPIProperty,List<PropertyValue>> getProperties() {
+      if (messageProperties != null) {
+         return messageProperties.getProperties();
+      }
+      else return Collections.emptyMap();
+   }
    public Map<MAPIProperty,List<Chunk>> getAll() {
       return allChunks;
    }
@@ -160,6 +178,10 @@ public final class Chunks implements ChunkGroup {
    }
    
    public void chunksComplete() {
-      // TODO Match variable sized properties to their chunks + index
+      if (messageProperties != null) {
+         messageProperties.matchVariableSizedPropertiesToChunks();
+      } else {
+         logger.log(POILogger.WARN, "Message didn't contain a root list of properties!");
+      }
    }
-}
+}
\ No newline at end of file
index 5e57adb729293fd371dd900e79616b940728a994..78034fec912cfac1169afdcc644578aca795a33a 100644 (file)
@@ -56,7 +56,6 @@ public abstract class PropertiesChunk extends Chunk {
    /**
     * The ChunkGroup that these properties apply to. Used when
     *  matching chunks to variable sized properties
-    * TODO Make use of this
     */
    private ChunkGroup parentGroup;
    
@@ -73,31 +72,39 @@ public abstract class PropertiesChunk extends Chunk {
           return NAME;
    }
        
-       /**
-        * Returns all the properties in the chunk
-        */
-       public Map<MAPIProperty, List<PropertyValue>> getProperties() {
-          return properties;
-       }
-       
-       /**
-        * Returns all values for the given property, of null if none exist
-        */
-       public List<PropertyValue> getValues(MAPIProperty property) {
-          return properties.get(property);
-       }
+   /**
+    * Returns all the properties in the chunk
+    */
+   public Map<MAPIProperty, List<PropertyValue>> getProperties() {
+      return properties;
+   }
+
+   /**
+    * Returns all values for the given property, of null if none exist
+    */
+   public List<PropertyValue> getValues(MAPIProperty property) {
+      return properties.get(property);
+   }
+
+   /**
+    * Returns the (first/only) value for the given property, or
+    *  null if none exist
+    */
+   public PropertyValue getValue(MAPIProperty property) {
+      List<PropertyValue> values = properties.get(property);
+      if (values != null && values.size() > 0) {
+         return values.get(0);
+      }
+      return null;
+   }
        
-       /**
-        * Returns the (first/only) value for the given property, or
-        *  null if none exist
-        */
-       public PropertyValue getValue(MAPIProperty property) {
-          List<PropertyValue> values = properties.get(property);
-          if (values != null && values.size() > 0) {
-             return values.get(0);
-          }
-          return null;
-       }
+   /**
+    * Called once the parent ChunkGroup has been populated, to match
+    *  up the Chunks in it with our Variable Sized Properties.
+    */
+   protected void matchVariableSizedPropertiesToChunks() {
+      // TODO
+   }
 
    protected void readProperties(InputStream value) throws IOException {
       boolean going = true;
@@ -141,6 +148,7 @@ public abstract class PropertiesChunk extends Chunk {
             // Wrap and store
             PropertyValue propVal = null;
             if (isPointer) {
+               // We'll match up the chunk later
                propVal = new ChunkBasedPropertyValue(prop, flags, data);
             }
             else if (type == Types.LONG_LONG) {
index 2ac4eee19abe708dc6f1a857546302d2225225cf..1da3e7f6cecb30b01b5b5ba85ba03216284aa3a1 100644 (file)
 package org.apache.poi.hsmf.datatypes;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.Comparator;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.poi.util.POILogFactory;
 import org.apache.poi.util.POILogger;
@@ -32,7 +34,7 @@ import org.apache.poi.util.POILogger;
  * If a message has multiple recipients, there will be
  *  several of these.
  */
-public final class RecipientChunks implements ChunkGroup {
+public final class RecipientChunks implements ChunkGroupWithProperties {
    private static POILogger logger = POILogFactory.getLogger(RecipientChunks.class);
 
    public static final String PREFIX = "__recip_version1.0_#";
@@ -165,6 +167,12 @@ public final class RecipientChunks implements ChunkGroup {
    /** Holds all the chunks that were found. */
    private List<Chunk> allChunks = new ArrayList<Chunk>();
 
+   public Map<MAPIProperty,List<PropertyValue>> getProperties() {
+      if (recipientProperties != null) {
+         return recipientProperties.getProperties();
+      }
+      else return Collections.emptyMap();
+   }
    public Chunk[] getAll() {
       return allChunks.toArray(new Chunk[allChunks.size()]);
    }
@@ -204,7 +212,11 @@ public final class RecipientChunks implements ChunkGroup {
    }
    
    public void chunksComplete() {
-      // TODO Match variable sized properties to their chunks + index
+      if (recipientProperties != null) {
+         recipientProperties.matchVariableSizedPropertiesToChunks();
+      } else {
+         logger.log(POILogger.WARN, "Recipeints Chunk didn't contain a list of properties!");
+      }
    }
 
    /**
index 5709643cec4ff8f43ca8f6c8aba0302c0ebc89d9..cac6c551cb9e265797ee5b02ef972330bb2d9dc3 100644 (file)
@@ -95,7 +95,7 @@ public final class POIFSChunkParser {
       // All chunks are now processed, have the ChunkGroup
       // match up variable-length properties and their chunks
       for (ChunkGroup group : groups) {
-         // TODO
+         group.chunksComplete();
       }
       
       // Finish