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
This commit is contained in:
parent
7978095929
commit
d9197ba3a4
@ -102,7 +102,7 @@ public class MAPIMessage extends POIDocument {
|
|||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public MAPIMessage(DirectoryNode poifsDir, POIFSFileSystem fs) throws IOException {
|
public MAPIMessage(DirectoryNode poifsDir, POIFSFileSystem fs) throws IOException {
|
||||||
super(poifsDir, fs);
|
super(poifsDir);
|
||||||
|
|
||||||
// Grab all the chunks
|
// Grab all the chunks
|
||||||
ChunkGroup[] chunkGroups = POIFSChunkParser.parse(poifsDir);
|
ChunkGroup[] chunkGroups = POIFSChunkParser.parse(poifsDir);
|
||||||
|
@ -16,6 +16,21 @@
|
|||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.hsmf.datatypes;
|
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.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -26,17 +41,6 @@ import java.util.List;
|
|||||||
public class AttachmentChunks implements ChunkGroup {
|
public class AttachmentChunks implements ChunkGroup {
|
||||||
public static final String PREFIX = "__attach_version1.0_#";
|
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 ByteChunk attachData;
|
||||||
public StringChunk attachExtension;
|
public StringChunk attachExtension;
|
||||||
public StringChunk attachFileName;
|
public StringChunk attachFileName;
|
||||||
@ -79,8 +83,16 @@ public class AttachmentChunks implements ChunkGroup {
|
|||||||
* Called by the parser whenever a chunk is found.
|
* Called by the parser whenever a chunk is found.
|
||||||
*/
|
*/
|
||||||
public void record(Chunk chunk) {
|
public void record(Chunk chunk) {
|
||||||
switch(chunk.getChunkId()) {
|
if(chunk.getChunkId() == ATTACH_ADDITIONAL_INFO.id) {
|
||||||
case ATTACH_DATA:
|
// 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) {
|
if(chunk instanceof ByteChunk) {
|
||||||
attachData = (ByteChunk)chunk;
|
attachData = (ByteChunk)chunk;
|
||||||
} else if(chunk instanceof DirectoryChunk) {
|
} else if(chunk instanceof DirectoryChunk) {
|
||||||
@ -88,22 +100,37 @@ public class AttachmentChunks implements ChunkGroup {
|
|||||||
} else {
|
} else {
|
||||||
System.err.println("Unexpected data chunk of type " + chunk);
|
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;
|
attachExtension = (StringChunk)chunk;
|
||||||
break;
|
}
|
||||||
case ATTACH_FILENAME:
|
else if(chunk.getChunkId() == ATTACH_FILENAME.id) {
|
||||||
attachFileName = (StringChunk)chunk;
|
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;
|
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;
|
attachMimeTag = (StringChunk)chunk;
|
||||||
break;
|
}
|
||||||
case ATTACH_RENDERING_WMF:
|
else if(chunk.getChunkId() == ATTACH_RENDERING.id) {
|
||||||
attachRenderingWMF = (ByteChunk)chunk;
|
attachRenderingWMF = (ByteChunk)chunk;
|
||||||
}
|
}
|
||||||
|
else if(chunk.getChunkId() == ATTACH_SIZE.id) {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
// And add to the main list
|
// And add to the main list
|
||||||
allChunks.add(chunk);
|
allChunks.add(chunk);
|
||||||
|
@ -30,12 +30,6 @@ import java.util.List;
|
|||||||
* http://msdn.microsoft.com/en-us/library/ms526356%28v=exchg.10%29.aspx
|
* http://msdn.microsoft.com/en-us/library/ms526356%28v=exchg.10%29.aspx
|
||||||
*/
|
*/
|
||||||
public final class Chunks implements ChunkGroup {
|
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
|
// 0x0050 -> 0x006F seem to be routing info or similar
|
||||||
public static final int CONVERSATION_TOPIC = 0x0070;
|
public static final int CONVERSATION_TOPIC = 0x0070;
|
||||||
public static final int CONVERSATION_INDEX = 0x0071;
|
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.
|
* Called by the parser whenever a chunk is found.
|
||||||
*/
|
*/
|
||||||
public void record(Chunk chunk) {
|
public void record(Chunk chunk) {
|
||||||
switch(chunk.getChunkId()) {
|
if(chunk.getChunkId() == MAPIAttribute.MESSAGE_CLASS.id) {
|
||||||
case MESSAGE_CLASS:
|
|
||||||
messageClass = (StringChunk)chunk;
|
messageClass = (StringChunk)chunk;
|
||||||
break;
|
}
|
||||||
case MESSAGE_ID:
|
else if(chunk.getChunkId() == MAPIAttribute.SUBJECT.id) {
|
||||||
messageId = (StringChunk)chunk;
|
|
||||||
break;
|
|
||||||
case SUBJECT:
|
|
||||||
subjectChunk = (StringChunk)chunk;
|
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
|
// TODO - parse
|
||||||
submissionChunk = (MessageSubmissionChunk)chunk;
|
submissionChunk = (MessageSubmissionChunk)chunk;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch(chunk.getChunkId()) {
|
||||||
|
case MESSAGE_ID:
|
||||||
|
messageId = (StringChunk)chunk;
|
||||||
break;
|
break;
|
||||||
case CONVERSATION_TOPIC:
|
case CONVERSATION_TOPIC:
|
||||||
conversationTopic = (StringChunk)chunk;
|
conversationTopic = (StringChunk)chunk;
|
||||||
|
@ -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.LONG;
|
||||||
import static org.apache.poi.hsmf.datatypes.Types.TIME;
|
import static org.apache.poi.hsmf.datatypes.Types.TIME;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -1061,4 +1063,7 @@ public final class MAPIAttribute {
|
|||||||
return UNKNOWN;
|
return UNKNOWN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public static Collection<MAPIAttribute> getAll() {
|
||||||
|
return Collections.unmodifiableCollection( attributes.values() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,4 +41,25 @@ public final class Types {
|
|||||||
}
|
}
|
||||||
return str;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
72
src/scratchpad/src/org/apache/poi/hsmf/dev/TypesLister.java
Normal file
72
src/scratchpad/src/org/apache/poi/hsmf/dev/TypesLister.java
Normal file
@ -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);
|
||||||
|
}
|
||||||
|
}
|
@ -26,6 +26,7 @@ import org.apache.poi.hsmf.datatypes.Chunk;
|
|||||||
import org.apache.poi.hsmf.datatypes.ChunkGroup;
|
import org.apache.poi.hsmf.datatypes.ChunkGroup;
|
||||||
import org.apache.poi.hsmf.datatypes.Chunks;
|
import org.apache.poi.hsmf.datatypes.Chunks;
|
||||||
import org.apache.poi.hsmf.datatypes.DirectoryChunk;
|
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.MessageSubmissionChunk;
|
||||||
import org.apache.poi.hsmf.datatypes.NameIdChunks;
|
import org.apache.poi.hsmf.datatypes.NameIdChunks;
|
||||||
import org.apache.poi.hsmf.datatypes.RecipientChunks;
|
import org.apache.poi.hsmf.datatypes.RecipientChunks;
|
||||||
@ -134,11 +135,10 @@ public final class POIFSChunkParser {
|
|||||||
Chunk chunk = null;
|
Chunk chunk = null;
|
||||||
|
|
||||||
// Special cases based on the ID
|
// Special cases based on the ID
|
||||||
switch(chunkId) {
|
if(chunkId == MAPIAttribute.MESSAGE_SUBMISSION_ID.id) {
|
||||||
case Chunks.SUBMISSION_ID_DATE:
|
|
||||||
chunk = new MessageSubmissionChunk(namePrefix, chunkId, type);
|
chunk = new MessageSubmissionChunk(namePrefix, chunkId, type);
|
||||||
break;
|
}
|
||||||
default:
|
else {
|
||||||
// Nothing special about this ID
|
// Nothing special about this ID
|
||||||
// So, do the usual thing which is by type
|
// So, do the usual thing which is by type
|
||||||
switch(type) {
|
switch(type) {
|
||||||
|
@ -79,7 +79,7 @@ public final class TestChunkData extends TestCase {
|
|||||||
|
|
||||||
public void testSubjectChunk() {
|
public void testSubjectChunk() {
|
||||||
Chunk chunk = new StringChunk(0x0037, Types.UNICODE_STRING);
|
Chunk chunk = new StringChunk(0x0037, Types.UNICODE_STRING);
|
||||||
assertEquals(chunk.getChunkId(), Chunks.SUBJECT);
|
assertEquals(chunk.getChunkId(), MAPIAttribute.SUBJECT.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@ import org.apache.poi.hsmf.MAPIMessage;
|
|||||||
import org.apache.poi.hsmf.datatypes.AttachmentChunks;
|
import org.apache.poi.hsmf.datatypes.AttachmentChunks;
|
||||||
import org.apache.poi.hsmf.datatypes.ChunkGroup;
|
import org.apache.poi.hsmf.datatypes.ChunkGroup;
|
||||||
import org.apache.poi.hsmf.datatypes.Chunks;
|
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.NameIdChunks;
|
||||||
import org.apache.poi.hsmf.datatypes.RecipientChunks;
|
import org.apache.poi.hsmf.datatypes.RecipientChunks;
|
||||||
import org.apache.poi.hsmf.datatypes.RecipientChunks.RecipientChunksSorter;
|
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
|
// Check a few core things are present
|
||||||
simple.getRoot().getEntry(
|
simple.getRoot().getEntry(
|
||||||
(new StringChunk(Chunks.SUBJECT, Types.ASCII_STRING)).getEntryName()
|
(new StringChunk(MAPIAttribute.SUBJECT.id, Types.ASCII_STRING)).getEntryName()
|
||||||
);
|
);
|
||||||
simple.getRoot().getEntry(
|
simple.getRoot().getEntry(
|
||||||
(new StringChunk(Chunks.DISPLAY_FROM, Types.ASCII_STRING)).getEntryName()
|
(new StringChunk(Chunks.DISPLAY_FROM, Types.ASCII_STRING)).getEntryName()
|
||||||
|
Loading…
Reference in New Issue
Block a user