You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ni...@apache.org on 2011/01/11 16:35:30 UTC

svn commit: r1057698 - in /poi/trunk/src/scratchpad: src/org/apache/poi/hsmf/ src/org/apache/poi/hsmf/datatypes/ src/org/apache/poi/hsmf/dev/ src/org/apache/poi/hsmf/parsers/ testcases/org/apache/poi/hsmf/datatypes/ testcases/org/apache/poi/hsmf/parsers/

Author: nick
Date: Tue Jan 11 15:35:29 2011
New Revision: 1057698

URL: http://svn.apache.org/viewvc?rev=1057698&view=rev
Log:
Start converting HSMF code to use the new strongly type MAPIAttribute class for lookups, and add a dev class for listing the defined attributes

Added:
    poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/dev/
    poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/dev/TypesLister.java
Modified:
    poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/AttachmentChunks.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Chunks.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/MAPIAttribute.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Types.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/parsers/POIFSChunkParser.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestChunkData.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/parsers/TestPOIFSChunkParser.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=1057698&r1=1057697&r2=1057698&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 Tue Jan 11 15:35:29 2011
@@ -102,7 +102,7 @@ public class MAPIMessage extends POIDocu
     * @throws IOException
     */
    public MAPIMessage(DirectoryNode poifsDir, POIFSFileSystem fs) throws IOException {
-      super(poifsDir, fs);
+      super(poifsDir);
 
       // Grab all the chunks
       ChunkGroup[] chunkGroups = POIFSChunkParser.parse(poifsDir);

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/AttachmentChunks.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/AttachmentChunks.java?rev=1057698&r1=1057697&r2=1057698&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/AttachmentChunks.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/AttachmentChunks.java Tue Jan 11 15:35:29 2011
@@ -16,6 +16,21 @@
 ==================================================================== */
 package org.apache.poi.hsmf.datatypes;
 
+import static org.apache.poi.hsmf.datatypes.MAPIAttribute.ATTACH_ADDITIONAL_INFO;
+import static org.apache.poi.hsmf.datatypes.MAPIAttribute.ATTACH_CONTENT_BASE;
+import static org.apache.poi.hsmf.datatypes.MAPIAttribute.ATTACH_CONTENT_LOCATION;
+import static org.apache.poi.hsmf.datatypes.MAPIAttribute.ATTACH_DATA;
+import static org.apache.poi.hsmf.datatypes.MAPIAttribute.ATTACH_DISPOSITION;
+import static org.apache.poi.hsmf.datatypes.MAPIAttribute.ATTACH_ENCODING;
+import static org.apache.poi.hsmf.datatypes.MAPIAttribute.ATTACH_EXTENSION;
+import static org.apache.poi.hsmf.datatypes.MAPIAttribute.ATTACH_FILENAME;
+import static org.apache.poi.hsmf.datatypes.MAPIAttribute.ATTACH_FLAGS;
+import static org.apache.poi.hsmf.datatypes.MAPIAttribute.ATTACH_LONG_FILENAME;
+import static org.apache.poi.hsmf.datatypes.MAPIAttribute.ATTACH_LONG_PATHNAME;
+import static org.apache.poi.hsmf.datatypes.MAPIAttribute.ATTACH_MIME_TAG;
+import static org.apache.poi.hsmf.datatypes.MAPIAttribute.ATTACH_RENDERING;
+import static org.apache.poi.hsmf.datatypes.MAPIAttribute.ATTACH_SIZE;
+
 import java.util.ArrayList;
 import java.util.Comparator;
 import java.util.List;
@@ -26,17 +41,6 @@ import java.util.List;
 public class AttachmentChunks implements ChunkGroup {
    public static final String PREFIX = "__attach_version1.0_#";
    
-   /* String parts of Outlook Messages Attachments that are currently known */
-   public static final int ATTACH_DATA          = 0x3701;
-   // 0x3702 might be "attach encoding"
-   public static final int ATTACH_EXTENSION     = 0x3703;
-   public static final int ATTACH_FILENAME      = 0x3704;
-   // 0x3705 might be "attach method"
-   public static final int ATTACH_LONG_FILENAME = 0x3707;
-   public static final int ATTACH_RENDERING_WMF = 0x3709;
-   // 0x370B might be "rendering position"
-   public static final int ATTACH_MIME_TAG      = 0x370E;
-
    public ByteChunk attachData;
    public StringChunk attachExtension;
    public StringChunk attachFileName;
@@ -79,8 +83,16 @@ public class AttachmentChunks implements
     * Called by the parser whenever a chunk is found.
     */
    public void record(Chunk chunk) {
-      switch(chunk.getChunkId()) {
-      case ATTACH_DATA:
+      if(chunk.getChunkId() == ATTACH_ADDITIONAL_INFO.id) {
+         // TODO
+      }
+      else if(chunk.getChunkId() == ATTACH_CONTENT_BASE.id) {
+         // TODO
+      }
+      else if(chunk.getChunkId() == ATTACH_CONTENT_LOCATION.id) {
+         // TODO
+      }
+      else if(chunk.getChunkId() == ATTACH_DATA.id) {
          if(chunk instanceof ByteChunk) {
              attachData = (ByteChunk)chunk;
          } else if(chunk instanceof DirectoryChunk) {
@@ -88,22 +100,37 @@ public class AttachmentChunks implements
          } else {
              System.err.println("Unexpected data chunk of type " + chunk);
          }
-         break;
-      case ATTACH_EXTENSION:
+      }
+      else if(chunk.getChunkId() == ATTACH_DISPOSITION.id) {
+         // TODO
+      }
+      else if(chunk.getChunkId() == ATTACH_ENCODING.id) {
+         // TODO
+      }
+      else if(chunk.getChunkId() == ATTACH_EXTENSION.id) {
          attachExtension = (StringChunk)chunk;
-         break;
-      case ATTACH_FILENAME:
+      }
+      else if(chunk.getChunkId() == ATTACH_FILENAME.id) {
          attachFileName = (StringChunk)chunk;
-         break;
-      case ATTACH_LONG_FILENAME:
+      }
+      else if(chunk.getChunkId() == ATTACH_FLAGS.id) {
+         // TODO
+      }
+      else if(chunk.getChunkId() == ATTACH_LONG_FILENAME.id) {
          attachLongFileName = (StringChunk)chunk;
-         break;
-      case ATTACH_MIME_TAG:
+      }
+      else if(chunk.getChunkId() == ATTACH_LONG_PATHNAME.id) {
+         // TODO
+      }
+      else if(chunk.getChunkId() == ATTACH_MIME_TAG.id) {
          attachMimeTag = (StringChunk)chunk;
-         break;
-      case ATTACH_RENDERING_WMF:
+      }
+      else if(chunk.getChunkId() == ATTACH_RENDERING.id) {
          attachRenderingWMF = (ByteChunk)chunk;
       }
+      else if(chunk.getChunkId() == ATTACH_SIZE.id) {
+         // TODO
+      }
 
       // And add to the main list
       allChunks.add(chunk);

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=1057698&r1=1057697&r2=1057698&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 Tue Jan 11 15:35:29 2011
@@ -30,12 +30,6 @@ import java.util.List;
  *  http://msdn.microsoft.com/en-us/library/ms526356%28v=exchg.10%29.aspx
  */
 public final class Chunks implements ChunkGroup {
-   /* String parts of Outlook Messages that are currently known */
-   public static final int MESSAGE_CLASS       = 0x001A;
-   public static final int SUBJECT             = 0x0037;
-   // "PidTagMessageSubmissionId" as given by accepting server
-   public static final int RECEIVED_REPRESENTING_NAME = 0x0044;
-   public static final int SUBMISSION_ID_DATE  = 0x0047;
    // 0x0050 -> 0x006F seem to be routing info or similar
    public static final int CONVERSATION_TOPIC  = 0x0070;
    public static final int CONVERSATION_INDEX  = 0x0071;
@@ -95,19 +89,23 @@ public final class Chunks implements Chu
     * Called by the parser whenever a chunk is found.
     */
    public void record(Chunk chunk) {
-      switch(chunk.getChunkId()) {
-      case MESSAGE_CLASS:
+      if(chunk.getChunkId() == MAPIAttribute.MESSAGE_CLASS.id) {
          messageClass = (StringChunk)chunk;
-         break;
-      case MESSAGE_ID:
-         messageId = (StringChunk)chunk;
-         break;
-      case SUBJECT:
+      }
+      else if(chunk.getChunkId() == MAPIAttribute.SUBJECT.id) {
          subjectChunk = (StringChunk)chunk;
-         break;
-      case SUBMISSION_ID_DATE:
+      }
+      else if(chunk.getChunkId() == MAPIAttribute.ORIGINAL_SUBJECT.id) {
+         // TODO
+      }
+      else if(chunk.getChunkId() == MAPIAttribute.MESSAGE_SUBMISSION_ID.id) {
          // TODO - parse
          submissionChunk = (MessageSubmissionChunk)chunk;
+      }
+      
+      switch(chunk.getChunkId()) {
+      case MESSAGE_ID:
+         messageId = (StringChunk)chunk;
          break;
       case CONVERSATION_TOPIC:
          conversationTopic = (StringChunk)chunk;

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/MAPIAttribute.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/MAPIAttribute.java?rev=1057698&r1=1057697&r2=1057698&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/MAPIAttribute.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/MAPIAttribute.java Tue Jan 11 15:35:29 2011
@@ -24,6 +24,8 @@ import static org.apache.poi.hsmf.dataty
 import static org.apache.poi.hsmf.datatypes.Types.LONG;
 import static org.apache.poi.hsmf.datatypes.Types.TIME;
 
+import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -1061,4 +1063,7 @@ public final class MAPIAttribute {
          return UNKNOWN;
       }
    }
+   public static Collection<MAPIAttribute> getAll() {
+      return Collections.unmodifiableCollection( attributes.values() );
+   }
 }

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Types.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Types.java?rev=1057698&r1=1057697&r2=1057698&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Types.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Types.java Tue Jan 11 15:35:29 2011
@@ -41,4 +41,25 @@ public final class Types {
 		}
 		return str;
 	}
+	public static String asName(int type) {
+	   switch(type) {
+	      case BINARY:
+	         return "Binary";
+	      case ASCII_STRING:
+	         return "ASCII String";
+	      case UNICODE_STRING:
+	         return "Unicode String";
+	      case LONG:
+	         return "Long";
+	      case TIME:
+	         return "Time";
+	      case BOOLEAN:
+	         return "Boolean";
+	      case DIRECTORY:
+	         return "Directory";
+	      case -1:
+	         return "Unknown";
+	   }
+	   return "0x" + Integer.toHexString(type);
+	}
 }

Added: poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/dev/TypesLister.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/dev/TypesLister.java?rev=1057698&view=auto
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/dev/TypesLister.java (added)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/dev/TypesLister.java Tue Jan 11 15:35:29 2011
@@ -0,0 +1,72 @@
+/* ====================================================================
+   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.dev;
+
+import java.io.PrintStream;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+
+import org.apache.poi.hsmf.datatypes.MAPIAttribute;
+import org.apache.poi.hsmf.datatypes.Types;
+
+/**
+ * Lists the different MAPI types
+ */
+public class TypesLister {
+   public TypesLister() {}
+   
+   public void listByName(PrintStream out) {
+      ArrayList<MAPIAttribute> all = new ArrayList<MAPIAttribute>(MAPIAttribute.getAll());
+      Collections.sort(all, new Comparator<MAPIAttribute>() {
+         public int compare(MAPIAttribute a, MAPIAttribute b) {
+            return a.name.compareTo(b.name);
+         }
+      });
+      list(all, out);
+   }
+   public void listById(PrintStream out) {
+      ArrayList<MAPIAttribute> all = new ArrayList<MAPIAttribute>(MAPIAttribute.getAll());
+      Collections.sort(all, new Comparator<MAPIAttribute>() {
+         public int compare(MAPIAttribute a, MAPIAttribute b) {
+            if(a.id < b.id) return -1;
+            if(a.id > b.id) return +1;
+            return 0;
+         }
+      });
+      list(all, out);
+   }
+   private void list(ArrayList<MAPIAttribute> list, PrintStream out) {
+      for(MAPIAttribute attr : list) {
+         String id = Integer.toHexString(attr.id);
+         while(id.length() < 4) { id = "0"+id; }
+         
+         out.println("0x" + id + " - " + attr.name);
+         out.println("   " + attr.id + " - " + Types.asName(attr.usualType) + 
+               " (" + attr.usualType + ") - " + attr.mapiProperty);
+      }
+   }
+   
+   public static void main(String[] args) {
+      TypesLister lister = new TypesLister();
+      
+      lister.listByName(System.out);
+      System.out.println();
+      lister.listById(System.out);
+   }
+}

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=1057698&r1=1057697&r2=1057698&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 Tue Jan 11 15:35:29 2011
@@ -26,6 +26,7 @@ import org.apache.poi.hsmf.datatypes.Chu
 import org.apache.poi.hsmf.datatypes.ChunkGroup;
 import org.apache.poi.hsmf.datatypes.Chunks;
 import org.apache.poi.hsmf.datatypes.DirectoryChunk;
+import org.apache.poi.hsmf.datatypes.MAPIAttribute;
 import org.apache.poi.hsmf.datatypes.MessageSubmissionChunk;
 import org.apache.poi.hsmf.datatypes.NameIdChunks;
 import org.apache.poi.hsmf.datatypes.RecipientChunks;
@@ -134,11 +135,10 @@ public final class POIFSChunkParser {
          Chunk chunk = null;
          
          // Special cases based on the ID
-         switch(chunkId) {
-         case Chunks.SUBMISSION_ID_DATE:
+         if(chunkId == MAPIAttribute.MESSAGE_SUBMISSION_ID.id) {
             chunk = new MessageSubmissionChunk(namePrefix, chunkId, type);
-            break;
-         default:
+         } 
+         else {
             // Nothing special about this ID
             // So, do the usual thing which is by type
             switch(type) {

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestChunkData.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestChunkData.java?rev=1057698&r1=1057697&r2=1057698&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestChunkData.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestChunkData.java Tue Jan 11 15:35:29 2011
@@ -79,7 +79,7 @@ public final class TestChunkData extends
 
 	public void testSubjectChunk() {
 		Chunk chunk = new StringChunk(0x0037, Types.UNICODE_STRING);
-      assertEquals(chunk.getChunkId(), Chunks.SUBJECT);
+      assertEquals(chunk.getChunkId(), MAPIAttribute.SUBJECT.id);
 	}
 
 }

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/parsers/TestPOIFSChunkParser.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/parsers/TestPOIFSChunkParser.java?rev=1057698&r1=1057697&r2=1057698&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/parsers/TestPOIFSChunkParser.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/parsers/TestPOIFSChunkParser.java Tue Jan 11 15:35:29 2011
@@ -28,6 +28,7 @@ import org.apache.poi.hsmf.MAPIMessage;
 import org.apache.poi.hsmf.datatypes.AttachmentChunks;
 import org.apache.poi.hsmf.datatypes.ChunkGroup;
 import org.apache.poi.hsmf.datatypes.Chunks;
+import org.apache.poi.hsmf.datatypes.MAPIAttribute;
 import org.apache.poi.hsmf.datatypes.NameIdChunks;
 import org.apache.poi.hsmf.datatypes.RecipientChunks;
 import org.apache.poi.hsmf.datatypes.RecipientChunks.RecipientChunksSorter;
@@ -56,7 +57,7 @@ public final class TestPOIFSChunkParser 
       
       // Check a few core things are present
       simple.getRoot().getEntry(
-            (new StringChunk(Chunks.SUBJECT, Types.ASCII_STRING)).getEntryName()
+            (new StringChunk(MAPIAttribute.SUBJECT.id, Types.ASCII_STRING)).getEntryName()
       );
       simple.getRoot().getEntry(
             (new StringChunk(Chunks.DISPLAY_FROM, Types.ASCII_STRING)).getEntryName()



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org