]> source.dussan.org Git - poi.git/commitdiff
Start converting HSMF code to use the new strongly type MAPIAttribute class for looku...
authorNick Burch <nick@apache.org>
Tue, 11 Jan 2011 15:35:29 +0000 (15:35 +0000)
committerNick Burch <nick@apache.org>
Tue, 11 Jan 2011 15:35:29 +0000 (15:35 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1057698 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java
src/scratchpad/src/org/apache/poi/hsmf/datatypes/AttachmentChunks.java
src/scratchpad/src/org/apache/poi/hsmf/datatypes/Chunks.java
src/scratchpad/src/org/apache/poi/hsmf/datatypes/MAPIAttribute.java
src/scratchpad/src/org/apache/poi/hsmf/datatypes/Types.java
src/scratchpad/src/org/apache/poi/hsmf/dev/TypesLister.java [new file with mode: 0644]
src/scratchpad/src/org/apache/poi/hsmf/parsers/POIFSChunkParser.java
src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestChunkData.java
src/scratchpad/testcases/org/apache/poi/hsmf/parsers/TestPOIFSChunkParser.java

index 3db17180fd7a1dbd50f25d1ab94741dcd87f2c57..f9bfa4477f113f11ee339e37d32f2fc123a07959 100644 (file)
@@ -102,7 +102,7 @@ public class MAPIMessage extends POIDocument {
     * @throws IOException
     */
    public MAPIMessage(DirectoryNode poifsDir, POIFSFileSystem fs) throws IOException {
-      super(poifsDir, fs);
+      super(poifsDir);
 
       // Grab all the chunks
       ChunkGroup[] chunkGroups = POIFSChunkParser.parse(poifsDir);
index 106a1c4b2d874b05886fd0ca518f63692c32d779..56bd9cd63f11fa805486d21bc280dbb3266e0f8e 100644 (file)
 ==================================================================== */
 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 ChunkGroup {
     * 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 ChunkGroup {
          } 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);
index 33935703c80878bacc8acee10849fec38d0152f4..bb989d1d96227fb40ef340f61ab030678b53e17c 100644 (file)
@@ -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 ChunkGroup {
     * 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;
index b66183ca7c5f4b19e3f9e9c88b0dfc8859a38278..6d679a4bc1f2b9d038b6c280198d7ee3c13e3cbb 100644 (file)
@@ -24,6 +24,8 @@ import static org.apache.poi.hsmf.datatypes.Types.DIRECTORY;
 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() );
+   }
 }
index 8346fee7e2e7f983d00256a38b8feb6d16b037f2..d46c18b2f226d129bd5396687a17d11e74f4d4f9 100644 (file)
@@ -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);
+       }
 }
diff --git a/src/scratchpad/src/org/apache/poi/hsmf/dev/TypesLister.java b/src/scratchpad/src/org/apache/poi/hsmf/dev/TypesLister.java
new file mode 100644 (file)
index 0000000..dad622a
--- /dev/null
@@ -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);
+   }
+}
index 8ff74b7bcc46b8aba2bb385cad05bf7557b0d148..84d595f890b62a2d0d74a9002128fdf658effd13 100644 (file)
@@ -26,6 +26,7 @@ import org.apache.poi.hsmf.datatypes.Chunk;
 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) {
index 4e2e9a7cdcdf60d23d94618d884abe4e76bb8095..23b2faecd671160b4c0e63f6159b6d03b82000ce 100644 (file)
@@ -79,7 +79,7 @@ public final class TestChunkData extends TestCase {
 
        public void testSubjectChunk() {
                Chunk chunk = new StringChunk(0x0037, Types.UNICODE_STRING);
-      assertEquals(chunk.getChunkId(), Chunks.SUBJECT);
+      assertEquals(chunk.getChunkId(), MAPIAttribute.SUBJECT.id);
        }
 
 }
index 8dcc6bf5fde20e10e649d76f165f5b4d3a430943..ee6f17db8e2384136b3ae89fc366b8fdc4484c40 100644 (file)
@@ -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 extends TestCase {
       
       // 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()