From e5884f2f66b6e76758009f962ed74a123eb0af37 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Thu, 7 Jan 2010 12:56:39 +0000 Subject: [PATCH] Add a couple more HSMF chunk types, and use Generics in a few places git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@896868 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/poi/hsmf/datatypes/Chunks.java | 29 ++++++++++---- .../org/apache/poi/hsmf/datatypes/Types.java | 12 ++++-- .../poi/hsmf/parsers/POIFSChunkParser.java | 40 ++++++++----------- 3 files changed, 45 insertions(+), 36 deletions(-) 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 ae7e77b70..68dcc0728 100644 --- a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Chunks.java +++ b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Chunks.java @@ -44,17 +44,30 @@ public final class Chunks { public StringChunk conversationTopic; /** Type of server that the message originated from (SMTP, etc). */ public StringChunk sentByServerType; + /** TODO */ + public StringChunk dateChunk; + /** TODO */ + public StringChunk emailFromChunk; + /** TODO */ + public StringChunk recipientSearchChunk; + /** TODO */ + public StringChunk recipientEmailChunk; private Chunks(boolean newStringType) { - messageClass = new StringChunk(0x001A, newStringType); - textBodyChunk = new StringChunk(0x1000, newStringType); - subjectChunk = new StringChunk(0x0037, newStringType); - displayToChunk = new StringChunk(0x0E04, newStringType); - displayFromChunk = new StringChunk(0x0C1A, newStringType); - displayCCChunk = new StringChunk(0x0E03, newStringType); - displayBCCChunk = new StringChunk(0x0E02, newStringType); + messageClass = new StringChunk(0x001A, newStringType); + subjectChunk = new StringChunk(0x0037, newStringType); + dateChunk = new StringChunk(0x0047, newStringType); conversationTopic = new StringChunk(0x0070, newStringType); - sentByServerType = new StringChunk(0x0075, newStringType); + sentByServerType = new StringChunk(0x0075, newStringType); + // RECEIVEDEMAIL = 76 + displayToChunk = new StringChunk(0x0E04, newStringType); + displayFromChunk = new StringChunk(0x0C1A, newStringType); + emailFromChunk = new StringChunk(0x0C1F, newStringType); + displayCCChunk = new StringChunk(0x0E03, newStringType); + displayBCCChunk = new StringChunk(0x0E02, newStringType); + recipientSearchChunk = new StringChunk(0x300B, newStringType); + recipientEmailChunk = new StringChunk(0x39FE, newStringType); + textBodyChunk = new StringChunk(0x1000, newStringType); } public static Chunks getInstance(boolean newStringType) { 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 2949ba190..3deaa97e2 100644 --- a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Types.java +++ b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Types.java @@ -20,10 +20,14 @@ package org.apache.poi.hsmf.datatypes; public final class Types { public static int BINARY = 0x0102; - /** A string, until Outlook 3.0 */ - public static int OLD_STRING = 0x001E; - /** A string, from Outlook 3.0 onwards */ - public static int NEW_STRING = 0x001F; + /** + * An 8-bit string, probably in US-ASCII, but don't quote us... + * Normally used for everything before Outlook 3.0, and some + * fields in Outlook 3.0 + */ + public static int ASCII_STRING = 0x001E; + /** A string, from Outlook 3.0 onwards. Normally unicode */ + public static int UNICODE_STRING = 0x001F; public static int LONG = 0x0003; public static int TIME = 0x0040; 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 47af9dfc5..a278996a1 100644 --- a/src/scratchpad/src/org/apache/poi/hsmf/parsers/POIFSChunkParser.java +++ b/src/scratchpad/src/org/apache/poi/hsmf/parsers/POIFSChunkParser.java @@ -35,6 +35,7 @@ import org.apache.poi.hsmf.exceptions.DirectoryChunkNotFoundException; import org.apache.poi.poifs.filesystem.DirectoryEntry; import org.apache.poi.poifs.filesystem.DirectoryNode; import org.apache.poi.poifs.filesystem.DocumentNode; +import org.apache.poi.poifs.filesystem.Entry; import org.apache.poi.poifs.filesystem.POIFSDocument; import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.poifs.property.DirectoryProperty; @@ -77,7 +78,7 @@ public final class POIFSChunkParser { public void reparseFileSystem() throws IOException { // first clear this object of all chunks DirectoryEntry root = this.fs.getRoot(); - Iterator iter = root.getEntries(); + Iterator iter = root.getEntries(); this.directoryMap = this.processPOIIterator(iter); } @@ -219,33 +220,24 @@ public final class POIFSChunkParser { * @return * @throws IOException */ - private HashMap processPOIIterator(Iterator iter) throws IOException { - HashMap currentNode = new HashMap(); + private HashMap> processPOIIterator(Iterator iter) throws IOException { + HashMap> currentNode = new HashMap>(); while(iter.hasNext()) { - Object obj = iter.next(); - if(obj instanceof DocumentNode) { - this.processDocumentNode((DocumentNode)obj, currentNode); - } else if(obj instanceof DirectoryNode) { - String blockName = ((DirectoryNode)obj).getName(); - Iterator viewIt = null; - if( ((DirectoryNode)obj).preferArray()) { - Object[] arr = ((DirectoryNode)obj).getViewableArray(); - ArrayList viewList = new ArrayList(arr.length); - - for(int i = 0; i < arr.length; i++) { - viewList.add(arr[i]); - } - viewIt = viewList.iterator(); - } else { - viewIt = ((DirectoryNode)obj).getViewableIterator(); - } - //store the next node on the hashmap - currentNode.put(blockName, processPOIIterator(viewIt)); - } else if(obj instanceof DirectoryProperty) { + Entry entry = iter.next(); + if(entry instanceof DocumentNode) { + this.processDocumentNode((DocumentNode)entry, currentNode); + } else if(entry instanceof DirectoryNode) { + DirectoryNode dir = (DirectoryNode)entry; + + String blockName = dir.getName(); + + // Recurse down, storing on the hashmap + currentNode.put(blockName, processPOIIterator(dir.getEntries())); + } else if(entry instanceof DirectoryProperty) { //don't do anything with the directory property chunk... } else { - System.err.println("Unknown node: " + obj.toString()); + System.err.println("Unknown node: " + entry.toString()); } } return currentNode;