Author: nick
Date: Fri Feb  1 12:43:58 2013
New Revision: 1441427

URL: http://svn.apache.org/viewvc?rev=1441427&view=rev
Log:
Continue with support for property lookups of chunks

Added:
    
poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/ChunkGroupWithProperties.java
Modified:
    poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Chunks.java
    
poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/PropertiesChunk.java
    
poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/RecipientChunks.java
    
poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/parsers/POIFSChunkParser.java

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java?rev=1441427&r1=1441426&r2=1441427&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java Fri Feb  
1 12:43:58 2013
@@ -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 POIDocu
       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();
             }
          }
       }

Added: 
poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/ChunkGroupWithProperties.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/ChunkGroupWithProperties.java?rev=1441427&view=auto
==============================================================================
--- 
poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/ChunkGroupWithProperties.java
 (added)
+++ 
poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/ChunkGroupWithProperties.java
 Fri Feb  1 12:43:58 2013
@@ -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();
+}

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Chunks.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Chunks.java?rev=1441427&r1=1441426&r2=1441427&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Chunks.java 
(original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Chunks.java Fri 
Feb  1 12:43:58 2013
@@ -18,10 +18,14 @@
 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 Chu
    /** 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 Chu
    }
    
    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

Modified: 
poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/PropertiesChunk.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/PropertiesChunk.java?rev=1441427&r1=1441426&r2=1441427&view=diff
==============================================================================
--- 
poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/PropertiesChunk.java 
(original)
+++ 
poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/PropertiesChunk.java 
Fri Feb  1 12:43:58 2013
@@ -56,7 +56,6 @@ public abstract class PropertiesChunk ex
    /**
     * 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 ex
           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 ex
             // 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) {

Modified: 
poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/RecipientChunks.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/RecipientChunks.java?rev=1441427&r1=1441426&r2=1441427&view=diff
==============================================================================
--- 
poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/RecipientChunks.java 
(original)
+++ 
poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/RecipientChunks.java 
Fri Feb  1 12:43:58 2013
@@ -18,8 +18,10 @@
 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 imple
    /** 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 imple
    }
    
    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!");
+      }
    }
 
    /**

Modified: 
poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/parsers/POIFSChunkParser.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/parsers/POIFSChunkParser.java?rev=1441427&r1=1441426&r2=1441427&view=diff
==============================================================================
--- 
poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/parsers/POIFSChunkParser.java 
(original)
+++ 
poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/parsers/POIFSChunkParser.java 
Fri Feb  1 12:43:58 2013
@@ -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



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to