From: Nick Burch Date: Tue, 11 Jan 2011 15:35:29 +0000 (+0000) Subject: Start converting HSMF code to use the new strongly type MAPIAttribute class for looku... X-Git-Tag: REL_3_8_BETA1~43 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=d702bca35f54cc090b9141f35940069a0a0d9d6f;p=poi.git Start converting HSMF code to use the new strongly type MAPIAttribute class for lookups, and add a dev class for listing the defined attributes git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1057698 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java b/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java index 3db17180fd..f9bfa4477f 100644 --- a/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java +++ b/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java @@ -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); diff --git a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/AttachmentChunks.java b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/AttachmentChunks.java index 106a1c4b2d..56bd9cd63f 100644 --- a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/AttachmentChunks.java +++ b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/AttachmentChunks.java @@ -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 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); diff --git a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Chunks.java b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Chunks.java index 33935703c8..bb989d1d96 100644 --- a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Chunks.java +++ b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Chunks.java @@ -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; diff --git a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/MAPIAttribute.java b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/MAPIAttribute.java index b66183ca7c..6d679a4bc1 100644 --- a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/MAPIAttribute.java +++ b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/MAPIAttribute.java @@ -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 getAll() { + return Collections.unmodifiableCollection( attributes.values() ); + } } diff --git a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Types.java b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Types.java index 8346fee7e2..d46c18b2f2 100644 --- a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Types.java +++ b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Types.java @@ -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 index 0000000000..dad622aeb8 --- /dev/null +++ b/src/scratchpad/src/org/apache/poi/hsmf/dev/TypesLister.java @@ -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 all = new ArrayList(MAPIAttribute.getAll()); + Collections.sort(all, new Comparator() { + public int compare(MAPIAttribute a, MAPIAttribute b) { + return a.name.compareTo(b.name); + } + }); + list(all, out); + } + public void listById(PrintStream out) { + ArrayList all = new ArrayList(MAPIAttribute.getAll()); + Collections.sort(all, new Comparator() { + 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 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); + } +} diff --git a/src/scratchpad/src/org/apache/poi/hsmf/parsers/POIFSChunkParser.java b/src/scratchpad/src/org/apache/poi/hsmf/parsers/POIFSChunkParser.java index 8ff74b7bcc..84d595f890 100644 --- a/src/scratchpad/src/org/apache/poi/hsmf/parsers/POIFSChunkParser.java +++ b/src/scratchpad/src/org/apache/poi/hsmf/parsers/POIFSChunkParser.java @@ -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) { diff --git a/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestChunkData.java b/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestChunkData.java index 4e2e9a7cdc..23b2faecd6 100644 --- a/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestChunkData.java +++ b/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestChunkData.java @@ -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); } } diff --git a/src/scratchpad/testcases/org/apache/poi/hsmf/parsers/TestPOIFSChunkParser.java b/src/scratchpad/testcases/org/apache/poi/hsmf/parsers/TestPOIFSChunkParser.java index 8dcc6bf5fd..ee6f17db8e 100644 --- a/src/scratchpad/testcases/org/apache/poi/hsmf/parsers/TestPOIFSChunkParser.java +++ b/src/scratchpad/testcases/org/apache/poi/hsmf/parsers/TestPOIFSChunkParser.java @@ -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()