SonarCube fix - make members private
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1773907 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6a8332a173
commit
269dd9e0af
@ -38,15 +38,15 @@ import org.apache.poi.util.POILogger;
|
|||||||
* attachment.
|
* attachment.
|
||||||
*/
|
*/
|
||||||
public class AttachmentChunks implements ChunkGroup {
|
public class AttachmentChunks implements ChunkGroup {
|
||||||
private static POILogger logger = POILogFactory.getLogger(AttachmentChunks.class);
|
private static final POILogger LOG = POILogFactory.getLogger(AttachmentChunks.class);
|
||||||
public static final String PREFIX = "__attach_version1.0_#";
|
public static final String PREFIX = "__attach_version1.0_#";
|
||||||
|
|
||||||
public ByteChunk attachData;
|
private ByteChunk attachData;
|
||||||
public StringChunk attachExtension;
|
private StringChunk attachExtension;
|
||||||
public StringChunk attachFileName;
|
private StringChunk attachFileName;
|
||||||
public StringChunk attachLongFileName;
|
private StringChunk attachLongFileName;
|
||||||
public StringChunk attachMimeTag;
|
private StringChunk attachMimeTag;
|
||||||
public DirectoryChunk attachmentDirectory;
|
private DirectoryChunk attachmentDirectory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is in WMF Format. You'll probably want to pass it to Apache Batik to
|
* This is in WMF Format. You'll probably want to pass it to Apache Batik to
|
||||||
@ -99,6 +99,7 @@ public class AttachmentChunks implements ChunkGroup {
|
|||||||
return allChunks.toArray(new Chunk[allChunks.size()]);
|
return allChunks.toArray(new Chunk[allChunks.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Chunk[] getChunks() {
|
public Chunk[] getChunks() {
|
||||||
return getAll();
|
return getAll();
|
||||||
}
|
}
|
||||||
@ -107,9 +108,59 @@ public class AttachmentChunks implements ChunkGroup {
|
|||||||
return poifsName;
|
return poifsName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the ATTACH_DATA chunk
|
||||||
|
*/
|
||||||
|
public ByteChunk getAttachData() {
|
||||||
|
return attachData;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the attachment extension
|
||||||
|
*/
|
||||||
|
public StringChunk getAttachExtension() {
|
||||||
|
return attachExtension;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the attachment (short) filename
|
||||||
|
*/
|
||||||
|
public StringChunk getAttachFileName() {
|
||||||
|
return attachFileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the attachment (long) filename
|
||||||
|
*/
|
||||||
|
public StringChunk getAttachLongFileName() {
|
||||||
|
return attachLongFileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the attachment mimetag
|
||||||
|
*/
|
||||||
|
public StringChunk getAttachMimeTag() {
|
||||||
|
return attachMimeTag;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the attachment directory
|
||||||
|
*/
|
||||||
|
public DirectoryChunk getAttachmentDirectory() {
|
||||||
|
return attachmentDirectory;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the attachment preview bytes
|
||||||
|
*/
|
||||||
|
public ByteChunk getAttachRenderingWMF() {
|
||||||
|
return attachRenderingWMF;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called by the parser whenever a chunk is found.
|
* Called by the parser whenever a chunk is found.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public void record(Chunk chunk) {
|
public void record(Chunk chunk) {
|
||||||
// TODO: add further members for other properties like:
|
// TODO: add further members for other properties like:
|
||||||
// - ATTACH_ADDITIONAL_INFO
|
// - ATTACH_ADDITIONAL_INFO
|
||||||
@ -127,7 +178,7 @@ public class AttachmentChunks implements ChunkGroup {
|
|||||||
} else if (chunk instanceof DirectoryChunk) {
|
} else if (chunk instanceof DirectoryChunk) {
|
||||||
attachmentDirectory = (DirectoryChunk) chunk;
|
attachmentDirectory = (DirectoryChunk) chunk;
|
||||||
} else {
|
} else {
|
||||||
logger.log(POILogger.ERROR, "Unexpected data chunk of type " + chunk);
|
LOG.log(POILogger.ERROR, "Unexpected data chunk of type " + chunk);
|
||||||
}
|
}
|
||||||
} else if (chunkId == ATTACH_EXTENSION.id) {
|
} else if (chunkId == ATTACH_EXTENSION.id) {
|
||||||
attachExtension = (StringChunk) chunk;
|
attachExtension = (StringChunk) chunk;
|
||||||
@ -148,6 +199,7 @@ public class AttachmentChunks implements ChunkGroup {
|
|||||||
/**
|
/**
|
||||||
* Used to flag that all the chunks of the attachment have now been located.
|
* Used to flag that all the chunks of the attachment have now been located.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public void chunksComplete() {
|
public void chunksComplete() {
|
||||||
// Currently, we don't need to do anything special once
|
// Currently, we don't need to do anything special once
|
||||||
// all the chunks have been located
|
// all the chunks have been located
|
||||||
@ -157,7 +209,8 @@ public class AttachmentChunks implements ChunkGroup {
|
|||||||
* Orders by the attachment number.
|
* Orders by the attachment number.
|
||||||
*/
|
*/
|
||||||
public static class AttachmentChunksSorter
|
public static class AttachmentChunksSorter
|
||||||
implements Comparator<AttachmentChunks>, Serializable {
|
implements Comparator<AttachmentChunks>, Serializable {
|
||||||
|
@Override
|
||||||
public int compare(AttachmentChunks a, AttachmentChunks b) {
|
public int compare(AttachmentChunks a, AttachmentChunks b) {
|
||||||
return a.poifsName.compareTo(b.poifsName);
|
return a.poifsName.compareTo(b.poifsName);
|
||||||
}
|
}
|
||||||
|
@ -46,10 +46,12 @@ public class ByteChunk extends Chunk {
|
|||||||
super(chunkId, type);
|
super(chunkId, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void readValue(InputStream value) throws IOException {
|
public void readValue(InputStream value) throws IOException {
|
||||||
this.value = IOUtils.toByteArray(value);
|
this.value = IOUtils.toByteArray(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void writeValue(OutputStream out) throws IOException {
|
public void writeValue(OutputStream out) throws IOException {
|
||||||
out.write(value);
|
out.write(value);
|
||||||
}
|
}
|
||||||
@ -65,6 +67,7 @@ public class ByteChunk extends Chunk {
|
|||||||
/**
|
/**
|
||||||
* Returns the data in a debug-friendly string format
|
* Returns the data in a debug-friendly string format
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return toDebugFriendlyString(value);
|
return toDebugFriendlyString(value);
|
||||||
}
|
}
|
||||||
@ -74,8 +77,9 @@ public class ByteChunk extends Chunk {
|
|||||||
* array, and the start of a longer one.
|
* array, and the start of a longer one.
|
||||||
*/
|
*/
|
||||||
protected static String toDebugFriendlyString(byte[] value) {
|
protected static String toDebugFriendlyString(byte[] value) {
|
||||||
if (value == null)
|
if (value == null) {
|
||||||
return "(Null Byte Array)";
|
return "(Null Byte Array)";
|
||||||
|
}
|
||||||
|
|
||||||
StringBuffer text = new StringBuffer();
|
StringBuffer text = new StringBuffer();
|
||||||
text.append("Bytes len=").append(value.length);
|
text.append("Bytes len=").append(value.length);
|
||||||
@ -86,8 +90,9 @@ public class ByteChunk extends Chunk {
|
|||||||
limit = 12;
|
limit = 12;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < limit; i++) {
|
for (int i = 0; i < limit; i++) {
|
||||||
if (i > 0)
|
if (i > 0) {
|
||||||
text.append(',');
|
text.append(',');
|
||||||
|
}
|
||||||
text.append(value[i]);
|
text.append(value[i]);
|
||||||
}
|
}
|
||||||
if (value.length > 16) {
|
if (value.length > 16) {
|
||||||
|
@ -27,9 +27,9 @@ import org.apache.poi.hsmf.datatypes.Types.MAPIType;
|
|||||||
public abstract class Chunk {
|
public abstract class Chunk {
|
||||||
public static final String DEFAULT_NAME_PREFIX = "__substg1.0_";
|
public static final String DEFAULT_NAME_PREFIX = "__substg1.0_";
|
||||||
|
|
||||||
protected int chunkId;
|
private int chunkId;
|
||||||
protected MAPIType type;
|
private MAPIType type;
|
||||||
protected String namePrefix;
|
private String namePrefix;
|
||||||
|
|
||||||
protected Chunk(String namePrefix, int chunkId, MAPIType type) {
|
protected Chunk(String namePrefix, int chunkId, MAPIType type) {
|
||||||
this.namePrefix = namePrefix;
|
this.namePrefix = namePrefix;
|
||||||
@ -63,8 +63,9 @@ public abstract class Chunk {
|
|||||||
String type = this.type.asFileEnding();
|
String type = this.type.asFileEnding();
|
||||||
|
|
||||||
String chunkId = Integer.toHexString(this.chunkId);
|
String chunkId = Integer.toHexString(this.chunkId);
|
||||||
while (chunkId.length() < 4)
|
while (chunkId.length() < 4) {
|
||||||
chunkId = "0" + chunkId;
|
chunkId = "0" + chunkId;
|
||||||
|
}
|
||||||
|
|
||||||
return this.namePrefix
|
return this.namePrefix
|
||||||
+ chunkId.toUpperCase(Locale.ROOT)
|
+ chunkId.toUpperCase(Locale.ROOT)
|
||||||
|
@ -37,7 +37,7 @@ import org.apache.poi.util.POILogger;
|
|||||||
* TODO Deprecate the public Chunks in favour of Property Lookups
|
* TODO Deprecate the public Chunks in favour of Property Lookups
|
||||||
*/
|
*/
|
||||||
public final class Chunks implements ChunkGroupWithProperties {
|
public final class Chunks implements ChunkGroupWithProperties {
|
||||||
private static POILogger logger = POILogFactory.getLogger(Chunks.class);
|
private static final POILogger LOG = POILogFactory.getLogger(Chunks.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds all the chunks that were found, indexed by their MAPIProperty.
|
* Holds all the chunks that were found, indexed by their MAPIProperty.
|
||||||
@ -47,60 +47,64 @@ public final class Chunks implements ChunkGroupWithProperties {
|
|||||||
private Map<MAPIProperty, List<Chunk>> allChunks = new HashMap<MAPIProperty, List<Chunk>>();
|
private Map<MAPIProperty, List<Chunk>> allChunks = new HashMap<MAPIProperty, List<Chunk>>();
|
||||||
|
|
||||||
/** Type of message that the MSG represents (ie. IPM.Note) */
|
/** Type of message that the MSG represents (ie. IPM.Note) */
|
||||||
public StringChunk messageClass;
|
private StringChunk messageClass;
|
||||||
/** BODY Chunk, for plain/text messages */
|
/** BODY Chunk, for plain/text messages */
|
||||||
public StringChunk textBodyChunk;
|
private StringChunk textBodyChunk;
|
||||||
/** BODY Html Chunk, for html messages */
|
/** BODY Html Chunk, for html messages */
|
||||||
public StringChunk htmlBodyChunkString;
|
private StringChunk htmlBodyChunkString;
|
||||||
public ByteChunk htmlBodyChunkBinary;
|
private ByteChunk htmlBodyChunkBinary;
|
||||||
/** BODY Rtf Chunk, for Rtf (Rich) messages */
|
/** BODY Rtf Chunk, for Rtf (Rich) messages */
|
||||||
public ByteChunk rtfBodyChunk;
|
private ByteChunk rtfBodyChunk;
|
||||||
/** Subject link chunk, in plain/text */
|
/** Subject link chunk, in plain/text */
|
||||||
public StringChunk subjectChunk;
|
private StringChunk subjectChunk;
|
||||||
/**
|
/**
|
||||||
* Value that is in the TO field (not actually the addresses as they are
|
* Value that is in the TO field (not actually the addresses as they are
|
||||||
* stored in recip directory nodes
|
* stored in recip directory nodes
|
||||||
*/
|
*/
|
||||||
public StringChunk displayToChunk;
|
private StringChunk displayToChunk;
|
||||||
/** Value that is in the FROM field */
|
/** Value that is in the FROM field */
|
||||||
public StringChunk displayFromChunk;
|
private StringChunk displayFromChunk;
|
||||||
/** value that shows in the CC field */
|
/** value that shows in the CC field */
|
||||||
public StringChunk displayCCChunk;
|
private StringChunk displayCCChunk;
|
||||||
/** Value that shows in the BCC field */
|
/** Value that shows in the BCC field */
|
||||||
public StringChunk displayBCCChunk;
|
private StringChunk displayBCCChunk;
|
||||||
/** Sort of like the subject line, but without the RE: and FWD: parts. */
|
/** Sort of like the subject line, but without the RE: and FWD: parts. */
|
||||||
public StringChunk conversationTopic;
|
private StringChunk conversationTopic;
|
||||||
/** Type of server that the message originated from (SMTP, etc). */
|
/** Type of server that the message originated from (SMTP, etc). */
|
||||||
public StringChunk sentByServerType;
|
private StringChunk sentByServerType;
|
||||||
/** The email headers */
|
/** The email headers */
|
||||||
public StringChunk messageHeaders;
|
private StringChunk messageHeaders;
|
||||||
/** TODO */
|
/** TODO */
|
||||||
public MessageSubmissionChunk submissionChunk;
|
private MessageSubmissionChunk submissionChunk;
|
||||||
/** TODO */
|
/** TODO */
|
||||||
public StringChunk emailFromChunk;
|
private StringChunk emailFromChunk;
|
||||||
/** The message ID */
|
/** The message ID */
|
||||||
public StringChunk messageId;
|
private StringChunk messageId;
|
||||||
/** The message properties */
|
/** The message properties */
|
||||||
private MessagePropertiesChunk messageProperties;
|
private MessagePropertiesChunk messageProperties;
|
||||||
|
|
||||||
|
@Override
|
||||||
public Map<MAPIProperty, List<PropertyValue>> getProperties() {
|
public Map<MAPIProperty, List<PropertyValue>> getProperties() {
|
||||||
if (messageProperties != null) {
|
if (messageProperties != null) {
|
||||||
return messageProperties.getProperties();
|
return messageProperties.getProperties();
|
||||||
} else
|
} else {
|
||||||
return Collections.emptyMap();
|
return Collections.emptyMap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<MAPIProperty, PropertyValue> getRawProperties() {
|
public Map<MAPIProperty, PropertyValue> getRawProperties() {
|
||||||
if (messageProperties != null) {
|
if (messageProperties != null) {
|
||||||
return messageProperties.getRawProperties();
|
return messageProperties.getRawProperties();
|
||||||
} else
|
} else {
|
||||||
return Collections.emptyMap();
|
return Collections.emptyMap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<MAPIProperty, List<Chunk>> getAll() {
|
public Map<MAPIProperty, List<Chunk>> getAll() {
|
||||||
return allChunks;
|
return allChunks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Chunk[] getChunks() {
|
public Chunk[] getChunks() {
|
||||||
ArrayList<Chunk> chunks = new ArrayList<Chunk>(allChunks.size());
|
ArrayList<Chunk> chunks = new ArrayList<Chunk>(allChunks.size());
|
||||||
for (List<Chunk> c : allChunks.values()) {
|
for (List<Chunk> c : allChunks.values()) {
|
||||||
@ -109,9 +113,78 @@ public final class Chunks implements ChunkGroupWithProperties {
|
|||||||
return chunks.toArray(new Chunk[chunks.size()]);
|
return chunks.toArray(new Chunk[chunks.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public StringChunk getMessageClass() {
|
||||||
|
return messageClass;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StringChunk getTextBodyChunk() {
|
||||||
|
return textBodyChunk;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StringChunk getHtmlBodyChunkString() {
|
||||||
|
return htmlBodyChunkString;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ByteChunk getHtmlBodyChunkBinary() {
|
||||||
|
return htmlBodyChunkBinary;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ByteChunk getRtfBodyChunk() {
|
||||||
|
return rtfBodyChunk;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StringChunk getSubjectChunk() {
|
||||||
|
return subjectChunk;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StringChunk getDisplayToChunk() {
|
||||||
|
return displayToChunk;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StringChunk getDisplayFromChunk() {
|
||||||
|
return displayFromChunk;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StringChunk getDisplayCCChunk() {
|
||||||
|
return displayCCChunk;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StringChunk getDisplayBCCChunk() {
|
||||||
|
return displayBCCChunk;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StringChunk getConversationTopic() {
|
||||||
|
return conversationTopic;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StringChunk getSentByServerType() {
|
||||||
|
return sentByServerType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StringChunk getMessageHeaders() {
|
||||||
|
return messageHeaders;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MessageSubmissionChunk getSubmissionChunk() {
|
||||||
|
return submissionChunk;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StringChunk getEmailFromChunk() {
|
||||||
|
return emailFromChunk;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StringChunk getMessageId() {
|
||||||
|
return messageId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MessagePropertiesChunk getMessageProperties() {
|
||||||
|
return messageProperties;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called by the parser whenever a chunk is found.
|
* Called by the parser whenever a chunk is found.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public void record(Chunk chunk) {
|
public void record(Chunk chunk) {
|
||||||
// Work out what MAPIProperty this corresponds to
|
// Work out what MAPIProperty this corresponds to
|
||||||
MAPIProperty prop = MAPIProperty.get(chunk.getChunkId());
|
MAPIProperty prop = MAPIProperty.get(chunk.getChunkId());
|
||||||
@ -172,11 +245,12 @@ public final class Chunks implements ChunkGroupWithProperties {
|
|||||||
allChunks.get(prop).add(chunk);
|
allChunks.get(prop).add(chunk);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void chunksComplete() {
|
public void chunksComplete() {
|
||||||
if (messageProperties != null) {
|
if (messageProperties != null) {
|
||||||
messageProperties.matchVariableSizedPropertiesToChunks();
|
messageProperties.matchVariableSizedPropertiesToChunks();
|
||||||
} else {
|
} else {
|
||||||
logger.log(POILogger.WARN,
|
LOG.log(POILogger.WARN,
|
||||||
"Message didn't contain a root list of properties!");
|
"Message didn't contain a root list of properties!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1071,6 +1071,7 @@ public class MAPIProperty {
|
|||||||
return str + usualType.asFileEnding();
|
return str + usualType.asFileEnding();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuffer str = new StringBuffer();
|
StringBuffer str = new StringBuffer();
|
||||||
str.append(name);
|
str.append(name);
|
||||||
|
@ -36,8 +36,7 @@ import org.apache.poi.util.POILogger;
|
|||||||
* used if you want to cancel a message or similar
|
* used if you want to cancel a message or similar
|
||||||
*/
|
*/
|
||||||
public class MessageSubmissionChunk extends Chunk {
|
public class MessageSubmissionChunk extends Chunk {
|
||||||
private static POILogger logger = POILogFactory
|
private static final POILogger LOG = POILogFactory.getLogger(MessageSubmissionChunk.class);
|
||||||
.getLogger(MessageSubmissionChunk.class);
|
|
||||||
private String rawId;
|
private String rawId;
|
||||||
private Calendar date;
|
private Calendar date;
|
||||||
|
|
||||||
@ -59,6 +58,7 @@ public class MessageSubmissionChunk extends Chunk {
|
|||||||
super(chunkId, type);
|
super(chunkId, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void readValue(InputStream value) throws IOException {
|
public void readValue(InputStream value) throws IOException {
|
||||||
// Stored in the file as us-ascii
|
// Stored in the file as us-ascii
|
||||||
byte[] data = IOUtils.toByteArray(value);
|
byte[] data = IOUtils.toByteArray(value);
|
||||||
@ -103,7 +103,7 @@ public class MessageSubmissionChunk extends Chunk {
|
|||||||
date.set(Calendar.SECOND, Integer.parseInt(m.group(6)));
|
date.set(Calendar.SECOND, Integer.parseInt(m.group(6)));
|
||||||
date.clear(Calendar.MILLISECOND);
|
date.clear(Calendar.MILLISECOND);
|
||||||
} else {
|
} else {
|
||||||
logger.log(POILogger.WARN,
|
LOG.log(POILogger.WARN,
|
||||||
"Warning - unable to make sense of date "
|
"Warning - unable to make sense of date "
|
||||||
+ dateS);
|
+ dateS);
|
||||||
}
|
}
|
||||||
@ -112,6 +112,7 @@ public class MessageSubmissionChunk extends Chunk {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void writeValue(OutputStream out) throws IOException {
|
public void writeValue(OutputStream out) throws IOException {
|
||||||
byte[] data = rawId.getBytes(Charset.forName("ASCII"));
|
byte[] data = rawId.getBytes(Charset.forName("ASCII"));
|
||||||
out.write(data);
|
out.write(data);
|
||||||
|
@ -33,6 +33,7 @@ public final class NameIdChunks implements ChunkGroup {
|
|||||||
return allChunks.toArray(new Chunk[allChunks.size()]);
|
return allChunks.toArray(new Chunk[allChunks.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Chunk[] getChunks() {
|
public Chunk[] getChunks() {
|
||||||
return getAll();
|
return getAll();
|
||||||
}
|
}
|
||||||
@ -40,6 +41,7 @@ public final class NameIdChunks implements ChunkGroup {
|
|||||||
/**
|
/**
|
||||||
* Called by the parser whenever a chunk is found.
|
* Called by the parser whenever a chunk is found.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public void record(Chunk chunk) {
|
public void record(Chunk chunk) {
|
||||||
allChunks.add(chunk);
|
allChunks.add(chunk);
|
||||||
}
|
}
|
||||||
@ -47,6 +49,7 @@ public final class NameIdChunks implements ChunkGroup {
|
|||||||
/**
|
/**
|
||||||
* Used to flag that all the chunks of the NameID have now been located.
|
* Used to flag that all the chunks of the NameID have now been located.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public void chunksComplete() {
|
public void chunksComplete() {
|
||||||
// Currently, we don't need to do anything special once
|
// Currently, we don't need to do anything special once
|
||||||
// all the chunks have been located
|
// all the chunks have been located
|
||||||
|
@ -137,7 +137,7 @@ public abstract class PropertiesChunk extends Chunk {
|
|||||||
// TODO Is this the right way?
|
// TODO Is this the right way?
|
||||||
Map<Integer, Chunk> chunks = new HashMap<Integer, Chunk>();
|
Map<Integer, Chunk> chunks = new HashMap<Integer, Chunk>();
|
||||||
for (Chunk chunk : parentGroup.getChunks()) {
|
for (Chunk chunk : parentGroup.getChunks()) {
|
||||||
chunks.put(chunk.chunkId, chunk);
|
chunks.put(chunk.getChunkId(), chunk);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loop over our values, looking for chunk based ones
|
// Loop over our values, looking for chunk based ones
|
||||||
|
@ -60,10 +60,12 @@ public class PropertyValue {
|
|||||||
this.data = value;
|
this.data = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
Object v = getValue();
|
Object v = getValue();
|
||||||
if (v == null)
|
if (v == null) {
|
||||||
return "(No value available)";
|
return "(No value available)";
|
||||||
|
}
|
||||||
|
|
||||||
if (v instanceof byte[]) {
|
if (v instanceof byte[]) {
|
||||||
return ByteChunk.toDebugFriendlyString((byte[]) v);
|
return ByteChunk.toDebugFriendlyString((byte[]) v);
|
||||||
@ -79,6 +81,7 @@ public class PropertyValue {
|
|||||||
super(property, flags, data);
|
super(property, flags, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Void getValue() {
|
public Void getValue() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -90,6 +93,7 @@ public class PropertyValue {
|
|||||||
super(property, flags, data);
|
super(property, flags, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Boolean getValue() {
|
public Boolean getValue() {
|
||||||
short val = LittleEndian.getShort(data);
|
short val = LittleEndian.getShort(data);
|
||||||
return val > 0;
|
return val > 0;
|
||||||
@ -111,6 +115,7 @@ public class PropertyValue {
|
|||||||
super(property, flags, data);
|
super(property, flags, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Short getValue() {
|
public Short getValue() {
|
||||||
return LittleEndian.getShort(data);
|
return LittleEndian.getShort(data);
|
||||||
}
|
}
|
||||||
@ -128,6 +133,7 @@ public class PropertyValue {
|
|||||||
super(property, flags, data);
|
super(property, flags, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Integer getValue() {
|
public Integer getValue() {
|
||||||
return LittleEndian.getInt(data);
|
return LittleEndian.getInt(data);
|
||||||
}
|
}
|
||||||
@ -146,6 +152,7 @@ public class PropertyValue {
|
|||||||
super(property, flags, data);
|
super(property, flags, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Long getValue() {
|
public Long getValue() {
|
||||||
return LittleEndian.getLong(data);
|
return LittleEndian.getLong(data);
|
||||||
}
|
}
|
||||||
@ -164,6 +171,7 @@ public class PropertyValue {
|
|||||||
super(property, flags, data);
|
super(property, flags, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Float getValue() {
|
public Float getValue() {
|
||||||
return LittleEndian.getFloat(data);
|
return LittleEndian.getFloat(data);
|
||||||
}
|
}
|
||||||
@ -181,6 +189,7 @@ public class PropertyValue {
|
|||||||
super(property, flags, data);
|
super(property, flags, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Double getValue() {
|
public Double getValue() {
|
||||||
return LittleEndian.getDouble(data);
|
return LittleEndian.getDouble(data);
|
||||||
}
|
}
|
||||||
@ -204,6 +213,7 @@ public class PropertyValue {
|
|||||||
super(property, flags, data);
|
super(property, flags, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public BigInteger getValue() {
|
public BigInteger getValue() {
|
||||||
long unshifted = LittleEndian.getLong(data);
|
long unshifted = LittleEndian.getLong(data);
|
||||||
return BigInteger.valueOf(unshifted).divide(SHIFT);
|
return BigInteger.valueOf(unshifted).divide(SHIFT);
|
||||||
@ -229,6 +239,7 @@ public class PropertyValue {
|
|||||||
super(property, flags, data);
|
super(property, flags, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Calendar getValue() {
|
public Calendar getValue() {
|
||||||
long time = LittleEndian.getLong(data);
|
long time = LittleEndian.getLong(data);
|
||||||
time = (time / 10 / 1000) - OFFSET;
|
time = (time / 10 / 1000) - OFFSET;
|
||||||
|
@ -33,7 +33,7 @@ import org.apache.poi.util.POILogger;
|
|||||||
* If a message has multiple recipients, there will be several of these.
|
* If a message has multiple recipients, there will be several of these.
|
||||||
*/
|
*/
|
||||||
public final class RecipientChunks implements ChunkGroupWithProperties {
|
public final class RecipientChunks implements ChunkGroupWithProperties {
|
||||||
private static POILogger logger = POILogFactory.getLogger(RecipientChunks.class);
|
private static final POILogger LOG = POILogFactory.getLogger(RecipientChunks.class);
|
||||||
|
|
||||||
public static final String PREFIX = "__recip_version1.0_#";
|
public static final String PREFIX = "__recip_version1.0_#";
|
||||||
|
|
||||||
@ -88,7 +88,7 @@ public final class RecipientChunks implements ChunkGroupWithProperties {
|
|||||||
try {
|
try {
|
||||||
recipientNumber = Integer.parseInt(number, 16);
|
recipientNumber = Integer.parseInt(number, 16);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
logger.log(POILogger.ERROR,
|
LOG.log(POILogger.ERROR,
|
||||||
"Invalid recipient number in name " + name);
|
"Invalid recipient number in name " + name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -161,17 +161,20 @@ public final class RecipientChunks implements ChunkGroupWithProperties {
|
|||||||
/** Holds all the chunks that were found. */
|
/** Holds all the chunks that were found. */
|
||||||
private List<Chunk> allChunks = new ArrayList<Chunk>();
|
private List<Chunk> allChunks = new ArrayList<Chunk>();
|
||||||
|
|
||||||
|
@Override
|
||||||
public Map<MAPIProperty, List<PropertyValue>> getProperties() {
|
public Map<MAPIProperty, List<PropertyValue>> getProperties() {
|
||||||
if (recipientProperties != null) {
|
if (recipientProperties != null) {
|
||||||
return recipientProperties.getProperties();
|
return recipientProperties.getProperties();
|
||||||
} else
|
} else {
|
||||||
return Collections.emptyMap();
|
return Collections.emptyMap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Chunk[] getAll() {
|
public Chunk[] getAll() {
|
||||||
return allChunks.toArray(new Chunk[allChunks.size()]);
|
return allChunks.toArray(new Chunk[allChunks.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Chunk[] getChunks() {
|
public Chunk[] getChunks() {
|
||||||
return getAll();
|
return getAll();
|
||||||
}
|
}
|
||||||
@ -179,6 +182,7 @@ public final class RecipientChunks implements ChunkGroupWithProperties {
|
|||||||
/**
|
/**
|
||||||
* Called by the parser whenever a chunk is found.
|
* Called by the parser whenever a chunk is found.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public void record(Chunk chunk) {
|
public void record(Chunk chunk) {
|
||||||
if (chunk.getChunkId() == RECIPIENT_SEARCH.id) {
|
if (chunk.getChunkId() == RECIPIENT_SEARCH.id) {
|
||||||
// TODO - parse
|
// TODO - parse
|
||||||
@ -201,11 +205,12 @@ public final class RecipientChunks implements ChunkGroupWithProperties {
|
|||||||
allChunks.add(chunk);
|
allChunks.add(chunk);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void chunksComplete() {
|
public void chunksComplete() {
|
||||||
if (recipientProperties != null) {
|
if (recipientProperties != null) {
|
||||||
recipientProperties.matchVariableSizedPropertiesToChunks();
|
recipientProperties.matchVariableSizedPropertiesToChunks();
|
||||||
} else {
|
} else {
|
||||||
logger.log(POILogger.WARN, "Recipeints Chunk didn't contain a list of properties!");
|
LOG.log(POILogger.WARN, "Recipeints Chunk didn't contain a list of properties!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -214,11 +219,14 @@ public final class RecipientChunks implements ChunkGroupWithProperties {
|
|||||||
*/
|
*/
|
||||||
public static class RecipientChunksSorter
|
public static class RecipientChunksSorter
|
||||||
implements Comparator<RecipientChunks>, Serializable {
|
implements Comparator<RecipientChunks>, Serializable {
|
||||||
|
@Override
|
||||||
public int compare(RecipientChunks a, RecipientChunks b) {
|
public int compare(RecipientChunks a, RecipientChunks b) {
|
||||||
if (a.recipientNumber < b.recipientNumber)
|
if (a.recipientNumber < b.recipientNumber) {
|
||||||
return -1;
|
return -1;
|
||||||
if (a.recipientNumber > b.recipientNumber)
|
}
|
||||||
|
if (a.recipientNumber > b.recipientNumber) {
|
||||||
return +1;
|
return +1;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,11 +66,12 @@ public class StringChunk extends Chunk {
|
|||||||
this.encoding7Bit = encoding;
|
this.encoding7Bit = encoding;
|
||||||
|
|
||||||
// Re-read the String if we're a 7 bit one
|
// Re-read the String if we're a 7 bit one
|
||||||
if (type == Types.ASCII_STRING) {
|
if (getType() == Types.ASCII_STRING) {
|
||||||
parseString();
|
parseString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void readValue(InputStream value) throws IOException {
|
public void readValue(InputStream value) throws IOException {
|
||||||
rawValue = IOUtils.toByteArray(value);
|
rawValue = IOUtils.toByteArray(value);
|
||||||
parseString();
|
parseString();
|
||||||
@ -78,29 +79,30 @@ public class StringChunk extends Chunk {
|
|||||||
|
|
||||||
private void parseString() {
|
private void parseString() {
|
||||||
String tmpValue;
|
String tmpValue;
|
||||||
if (type == Types.ASCII_STRING) {
|
if (getType() == Types.ASCII_STRING) {
|
||||||
tmpValue = parseAs7BitData(rawValue, encoding7Bit);
|
tmpValue = parseAs7BitData(rawValue, encoding7Bit);
|
||||||
} else if (type == Types.UNICODE_STRING) {
|
} else if (getType() == Types.UNICODE_STRING) {
|
||||||
tmpValue = StringUtil.getFromUnicodeLE(rawValue);
|
tmpValue = StringUtil.getFromUnicodeLE(rawValue);
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("Invalid type " + type + " for String Chunk");
|
throw new IllegalArgumentException("Invalid type " + getType() + " for String Chunk");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clean up
|
// Clean up
|
||||||
this.value = tmpValue.replace("\0", "");
|
this.value = tmpValue.replace("\0", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void writeValue(OutputStream out) throws IOException {
|
public void writeValue(OutputStream out) throws IOException {
|
||||||
out.write(rawValue);
|
out.write(rawValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void storeString() {
|
private void storeString() {
|
||||||
if (type == Types.ASCII_STRING) {
|
if (getType() == Types.ASCII_STRING) {
|
||||||
rawValue = value.getBytes(Charset.forName(encoding7Bit));
|
rawValue = value.getBytes(Charset.forName(encoding7Bit));
|
||||||
} else if (type == Types.UNICODE_STRING) {
|
} else if (getType() == Types.UNICODE_STRING) {
|
||||||
rawValue = StringUtil.getToUnicodeLE(value);
|
rawValue = StringUtil.getToUnicodeLE(value);
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("Invalid type " + type + " for String Chunk");
|
throw new IllegalArgumentException("Invalid type " + getType() + " for String Chunk");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,6 +122,7 @@ public class StringChunk extends Chunk {
|
|||||||
storeString();
|
storeString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return this.value;
|
return this.value;
|
||||||
}
|
}
|
||||||
|
@ -130,6 +130,7 @@ public final class Types {
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return id + " / 0x" + asFileEnding() + " - " + name + " @ "
|
return id + " / 0x" + asFileEnding() + " - " + name + " @ "
|
||||||
+ length;
|
+ length;
|
||||||
|
@ -25,61 +25,32 @@ import org.apache.poi.hwpf.usermodel.Paragraph;
|
|||||||
import org.apache.poi.hwpf.usermodel.Range;
|
import org.apache.poi.hwpf.usermodel.Range;
|
||||||
import org.apache.poi.hwpf.usermodel.Section;
|
import org.apache.poi.hwpf.usermodel.Section;
|
||||||
|
|
||||||
public final class QuickTest
|
public final class QuickTest {
|
||||||
{
|
public QuickTest() {
|
||||||
public QuickTest()
|
}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException
|
public static void main(String[] args) throws IOException {
|
||||||
{
|
HWPFDocument doc = new HWPFDocument(new FileInputStream(args[0]));
|
||||||
HWPFDocument doc = new HWPFDocument (new FileInputStream (args[0]));
|
Range r = doc.getRange();
|
||||||
Range r = doc.getRange();
|
|
||||||
|
|
||||||
System.out.println("Example you supplied:");
|
System.out.println("Example you supplied:");
|
||||||
System.out.println("---------------------");
|
System.out.println("---------------------");
|
||||||
for (int x = 0; x < r.numSections(); x++)
|
for (int x = 0; x < r.numSections(); x++) {
|
||||||
{
|
Section s = r.getSection(x);
|
||||||
Section s = r.getSection(x);
|
for (int y = 0; y < s.numParagraphs(); y++) {
|
||||||
for (int y = 0; y < s.numParagraphs(); y++)
|
Paragraph p = s.getParagraph(y);
|
||||||
{
|
for (int z = 0; z < p.numCharacterRuns(); z++) {
|
||||||
Paragraph p = s.getParagraph(y);
|
// character run
|
||||||
for (int z = 0; z < p.numCharacterRuns(); z++)
|
CharacterRun run = p.getCharacterRun(z);
|
||||||
{
|
// character run text
|
||||||
//character run
|
String text = run.text();
|
||||||
CharacterRun run = p.getCharacterRun(z);
|
// show us the text
|
||||||
//character run text
|
System.out.print(text);
|
||||||
String text = run.text();
|
}
|
||||||
// show us the text
|
// use a new line at the paragraph break
|
||||||
System.out.print(text);
|
System.out.println();
|
||||||
}
|
}
|
||||||
// use a new line at the paragraph break
|
|
||||||
System.out.println();
|
|
||||||
}
|
}
|
||||||
}
|
doc.close();
|
||||||
|
}
|
||||||
|
|
||||||
// System.out.println("\n\nExample using new method:");
|
|
||||||
// System.out.println("-------------------------");
|
|
||||||
// for (int x = 0; x < r.numSections(); x++)
|
|
||||||
// {
|
|
||||||
// Section s = r.getSection(x);
|
|
||||||
// for (int y = 0; y < s.numParagraphs(); y++)
|
|
||||||
// {
|
|
||||||
// Paragraph p = s.getParagraph(y);
|
|
||||||
// for (int z = 0; z < p.numCharacterRuns(); z++)
|
|
||||||
// {
|
|
||||||
// //character run
|
|
||||||
// CharacterRun run = p.getCharacterRun(z);
|
|
||||||
// //** get character run/paragraph common text **
|
|
||||||
// String text = run.commonText(p);
|
|
||||||
// // show us the text
|
|
||||||
// System.out.print(text);
|
|
||||||
// }
|
|
||||||
// // use a new line at the paragraph break
|
|
||||||
// System.out.println();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -69,11 +69,11 @@ public class TestFileWithAttachmentsRead extends TestCase {
|
|||||||
|
|
||||||
// Basic checks
|
// Basic checks
|
||||||
for (AttachmentChunks attachment : attachments) {
|
for (AttachmentChunks attachment : attachments) {
|
||||||
assertTrue(attachment.attachFileName.getValue().length() > 0);
|
assertTrue(attachment.getAttachFileName().getValue().length() > 0);
|
||||||
assertTrue(attachment.attachLongFileName.getValue().length() > 0);
|
assertTrue(attachment.getAttachLongFileName().getValue().length() > 0);
|
||||||
assertTrue(attachment.attachExtension.getValue().length() > 0);
|
assertTrue(attachment.getAttachExtension().getValue().length() > 0);
|
||||||
if(attachment.attachMimeTag != null) {
|
if(attachment.getAttachMimeTag() != null) {
|
||||||
assertTrue(attachment.attachMimeTag.getValue().length() > 0);
|
assertTrue(attachment.getAttachMimeTag().getValue().length() > 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,18 +81,18 @@ public class TestFileWithAttachmentsRead extends TestCase {
|
|||||||
|
|
||||||
// Now check in detail
|
// Now check in detail
|
||||||
attachment = twoSimpleAttachments.getAttachmentFiles()[0];
|
attachment = twoSimpleAttachments.getAttachmentFiles()[0];
|
||||||
assertEquals("TEST-U~1.DOC", attachment.attachFileName.toString());
|
assertEquals("TEST-U~1.DOC", attachment.getAttachFileName().toString());
|
||||||
assertEquals("test-unicode.doc", attachment.attachLongFileName.toString());
|
assertEquals("test-unicode.doc", attachment.getAttachLongFileName().toString());
|
||||||
assertEquals(".doc", attachment.attachExtension.getValue());
|
assertEquals(".doc", attachment.getAttachExtension().getValue());
|
||||||
assertEquals(null, attachment.attachMimeTag);
|
assertEquals(null, attachment.getAttachMimeTag());
|
||||||
assertEquals(24064, attachment.attachData.getValue().length);
|
assertEquals(24064, attachment.getAttachData().getValue().length);
|
||||||
|
|
||||||
attachment = twoSimpleAttachments.getAttachmentFiles()[1];
|
attachment = twoSimpleAttachments.getAttachmentFiles()[1];
|
||||||
assertEquals("pj1.txt", attachment.attachFileName.toString());
|
assertEquals("pj1.txt", attachment.getAttachFileName().toString());
|
||||||
assertEquals("pj1.txt", attachment.attachLongFileName.toString());
|
assertEquals("pj1.txt", attachment.getAttachLongFileName().toString());
|
||||||
assertEquals(".txt", attachment.attachExtension.getValue());
|
assertEquals(".txt", attachment.getAttachExtension().getValue());
|
||||||
assertEquals(null, attachment.attachMimeTag);
|
assertEquals(null, attachment.getAttachMimeTag());
|
||||||
assertEquals(89, attachment.attachData.getValue().length);
|
assertEquals(89, attachment.getAttachData().getValue().length);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -106,24 +106,24 @@ public class TestFileWithAttachmentsRead extends TestCase {
|
|||||||
|
|
||||||
// Second is a PDF
|
// Second is a PDF
|
||||||
attachment = pdfMsgAttachments.getAttachmentFiles()[1];
|
attachment = pdfMsgAttachments.getAttachmentFiles()[1];
|
||||||
assertEquals("smbprn~1.pdf", attachment.attachFileName.toString());
|
assertEquals("smbprn~1.pdf", attachment.getAttachFileName().toString());
|
||||||
assertEquals("smbprn.00009008.KdcPjl.pdf", attachment.attachLongFileName.toString());
|
assertEquals("smbprn.00009008.KdcPjl.pdf", attachment.getAttachLongFileName().toString());
|
||||||
assertEquals(".pdf", attachment.attachExtension.getValue());
|
assertEquals(".pdf", attachment.getAttachExtension().getValue());
|
||||||
assertEquals(null, attachment.attachMimeTag);
|
assertEquals(null, attachment.getAttachMimeTag());
|
||||||
assertEquals(null, attachment.attachmentDirectory);
|
assertEquals(null, attachment.getAttachmentDirectory());
|
||||||
assertEquals(13539, attachment.attachData.getValue().length);
|
assertEquals(13539, attachment.getAttachData().getValue().length);
|
||||||
|
|
||||||
// First in a nested message
|
// First in a nested message
|
||||||
attachment = pdfMsgAttachments.getAttachmentFiles()[0];
|
attachment = pdfMsgAttachments.getAttachmentFiles()[0];
|
||||||
assertEquals("Test Attachment", attachment.attachFileName.toString());
|
assertEquals("Test Attachment", attachment.getAttachFileName().toString());
|
||||||
assertEquals(null, attachment.attachLongFileName);
|
assertEquals(null, attachment.getAttachLongFileName());
|
||||||
assertEquals(null, attachment.attachExtension);
|
assertEquals(null, attachment.getAttachExtension());
|
||||||
assertEquals(null, attachment.attachMimeTag);
|
assertEquals(null, attachment.getAttachMimeTag());
|
||||||
assertEquals(null, attachment.attachData);
|
assertEquals(null, attachment.getAttachData());
|
||||||
assertNotNull(attachment.attachmentDirectory);
|
assertNotNull(attachment.getAttachmentDirectory());
|
||||||
|
|
||||||
// Check we can see some bits of it
|
// Check we can see some bits of it
|
||||||
MAPIMessage nested = attachment.attachmentDirectory.getAsEmbededMessage();
|
MAPIMessage nested = attachment.getAttachmentDirectory().getAsEmbededMessage();
|
||||||
assertEquals(1, nested.getRecipientNamesList().length);
|
assertEquals(1, nested.getRecipientNamesList().length);
|
||||||
assertEquals("Nick Booth", nested.getRecipientNames());
|
assertEquals("Nick Booth", nested.getRecipientNames());
|
||||||
assertEquals("Test Attachment", nested.getConversationTopic());
|
assertEquals("Test Attachment", nested.getConversationTopic());
|
||||||
|
@ -21,48 +21,43 @@ import java.io.ByteArrayInputStream;
|
|||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
|
||||||
public abstract class HWPFTestCase extends TestCase {
|
public abstract class HWPFTestCase {
|
||||||
protected HWPFDocFixture _hWPFDocFixture;
|
protected HWPFDocFixture _hWPFDocFixture;
|
||||||
|
|
||||||
protected HWPFTestCase() {
|
@Before
|
||||||
}
|
public void setUp() throws Exception {
|
||||||
|
/** @todo verify the constructors */
|
||||||
|
_hWPFDocFixture = new HWPFDocFixture(this, getTestFile());
|
||||||
|
|
||||||
@Override
|
_hWPFDocFixture.setUp();
|
||||||
protected void setUp() throws Exception {
|
}
|
||||||
super.setUp();
|
|
||||||
/** @todo verify the constructors */
|
|
||||||
_hWPFDocFixture = new HWPFDocFixture(this, getTestFile());
|
|
||||||
|
|
||||||
_hWPFDocFixture.setUp();
|
protected String getTestFile() {
|
||||||
}
|
return HWPFDocFixture.DEFAULT_TEST_FILE;
|
||||||
|
}
|
||||||
|
|
||||||
protected String getTestFile()
|
@After
|
||||||
{
|
public void tearDown() throws Exception {
|
||||||
return HWPFDocFixture.DEFAULT_TEST_FILE;
|
if (_hWPFDocFixture != null) {
|
||||||
}
|
_hWPFDocFixture.tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
_hWPFDocFixture = null;
|
||||||
protected void tearDown() throws Exception {
|
}
|
||||||
if (_hWPFDocFixture != null) {
|
|
||||||
_hWPFDocFixture.tearDown();
|
|
||||||
}
|
|
||||||
|
|
||||||
_hWPFDocFixture = null;
|
public HWPFDocument writeOutAndRead(HWPFDocument doc) {
|
||||||
super.tearDown();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
}
|
HWPFDocument newDoc;
|
||||||
|
try {
|
||||||
public HWPFDocument writeOutAndRead(HWPFDocument doc) {
|
doc.write(baos);
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
||||||
HWPFDocument newDoc;
|
newDoc = new HWPFDocument(bais);
|
||||||
try {
|
} catch (IOException e) {
|
||||||
doc.write(baos);
|
throw new RuntimeException(e);
|
||||||
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
}
|
||||||
newDoc = new HWPFDocument(bais);
|
return newDoc;
|
||||||
} catch (IOException e) {
|
}
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
return newDoc;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -19,86 +19,71 @@
|
|||||||
|
|
||||||
package org.apache.poi.hwpf;
|
package org.apache.poi.hwpf;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.apache.poi.hwpf.model.FieldsDocumentPart;
|
import org.apache.poi.hwpf.model.FieldsDocumentPart;
|
||||||
import org.apache.poi.hwpf.model.FieldsTables;
|
import org.apache.poi.hwpf.model.FieldsTables;
|
||||||
import org.apache.poi.hwpf.model.FileInformationBlock;
|
import org.apache.poi.hwpf.model.FileInformationBlock;
|
||||||
import org.apache.poi.hwpf.model.PlexOfField;
|
import org.apache.poi.hwpf.model.PlexOfField;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test case for the fields tables, this test is based on the test-fields.doc
|
* Test case for the fields tables, this test is based on the test-fields.doc
|
||||||
* file instead of the usual test.doc.
|
* file instead of the usual test.doc.
|
||||||
*
|
|
||||||
* @author Cedric Bosdonnat <cbosdonnat@novell.com>
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class TestFieldsTables extends HWPFTestCase
|
public class TestFieldsTables extends HWPFTestCase {
|
||||||
{
|
|
||||||
|
|
||||||
private static final String EXPECTED[] = {
|
private static final String EXPECTED[] = {
|
||||||
|
"[19, 43) - FLD - 0x13; 0x1f\n" + "[43, 54) - FLD - 0x14; 0xff\n"
|
||||||
|
+ "[54, 59) - FLD - 0x15; 0x81\n",
|
||||||
|
|
||||||
"[19, 43) - FLD - 0x13; 0x1f\n" + "[43, 54) - FLD - 0x14; 0xff\n"
|
"[31, 59) - FLD - 0x13; 0x45\n" + "[59, 61) - FLD - 0x14; 0xff\n"
|
||||||
+ "[54, 59) - FLD - 0x15; 0x81\n",
|
+ "[61, 66) - FLD - 0x15; 0x80\n",
|
||||||
|
|
||||||
"[31, 59) - FLD - 0x13; 0x45\n" + "[59, 61) - FLD - 0x14; 0xff\n"
|
"[23, 49) - FLD - 0x13; 0x11\n" + "[49, 64) - FLD - 0x14; 0xff\n"
|
||||||
+ "[61, 66) - FLD - 0x15; 0x80\n",
|
+ "[64, 69) - FLD - 0x15; 0x80\n",
|
||||||
|
|
||||||
"[23, 49) - FLD - 0x13; 0x11\n" + "[49, 64) - FLD - 0x14; 0xff\n"
|
"[18, 42) - FLD - 0x13; 0x21\n" + "[42, 44) - FLD - 0x14; 0xff\n"
|
||||||
+ "[64, 69) - FLD - 0x15; 0x80\n",
|
+ "[44, 47) - FLD - 0x15; 0x81\n"
|
||||||
|
+ "[47, 75) - FLD - 0x13; 0x1d\n"
|
||||||
|
+ "[75, 85) - FLD - 0x14; 0xff\n"
|
||||||
|
+ "[85, 91) - FLD - 0x15; 0x81\n",
|
||||||
|
|
||||||
"[18, 42) - FLD - 0x13; 0x21\n" + "[42, 44) - FLD - 0x14; 0xff\n"
|
"[30, 54) - FLD - 0x13; 0x20\n" + "[54, 62) - FLD - 0x14; 0xff\n"
|
||||||
+ "[44, 47) - FLD - 0x15; 0x81\n"
|
+ "[62, 68) - FLD - 0x15; 0x81\n",
|
||||||
+ "[47, 75) - FLD - 0x13; 0x1d\n"
|
|
||||||
+ "[75, 85) - FLD - 0x14; 0xff\n"
|
|
||||||
+ "[85, 91) - FLD - 0x15; 0x81\n",
|
|
||||||
|
|
||||||
"[30, 54) - FLD - 0x13; 0x20\n" + "[54, 62) - FLD - 0x14; 0xff\n"
|
"[1, 31) - FLD - 0x13; 0x15\n" + "[31, 51) - FLD - 0x14; 0xff\n"
|
||||||
+ "[62, 68) - FLD - 0x15; 0x81\n",
|
+ "[51, 541) - FLD - 0x15; 0x81\n",
|
||||||
|
|
||||||
"[1, 31) - FLD - 0x13; 0x15\n" + "[31, 51) - FLD - 0x14; 0xff\n"
|
|
||||||
+ "[51, 541) - FLD - 0x15; 0x81\n",
|
|
||||||
|
|
||||||
"[19, 47) - FLD - 0x13; 0x19\n" + "[47, 49) - FLD - 0x14; 0xff\n"
|
|
||||||
+ "[49, 55) - FLD - 0x15; 0x81\n"
|
|
||||||
|
|
||||||
|
"[19, 47) - FLD - 0x13; 0x19\n" + "[47, 49) - FLD - 0x14; 0xff\n"
|
||||||
|
+ "[49, 55) - FLD - 0x15; 0x81\n"
|
||||||
};
|
};
|
||||||
|
|
||||||
public TestFieldsTables()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getTestFile()
|
protected String getTestFile() {
|
||||||
{
|
|
||||||
return "test-fields.doc";
|
return "test-fields.doc";
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testReadFields()
|
@Test
|
||||||
{
|
public void testReadFields() {
|
||||||
FileInformationBlock fib = _hWPFDocFixture._fib;
|
FileInformationBlock fib = _hWPFDocFixture._fib;
|
||||||
byte[] tableStream = _hWPFDocFixture._tableStream;
|
byte[] tableStream = _hWPFDocFixture._tableStream;
|
||||||
|
|
||||||
FieldsTables fieldsTables = new FieldsTables( tableStream, fib );
|
FieldsTables fieldsTables = new FieldsTables(tableStream, fib);
|
||||||
|
|
||||||
for ( int i = 0; i < FieldsDocumentPart.values().length; i++ )
|
int i = 0;
|
||||||
{
|
for (FieldsDocumentPart part : FieldsDocumentPart.values()) {
|
||||||
FieldsDocumentPart part = FieldsDocumentPart.values()[i];
|
String result = dumpPlexes(fieldsTables.getFieldsPLCF(part));
|
||||||
|
assertEquals(EXPECTED[i++], result);
|
||||||
ArrayList<PlexOfField> fieldsPlexes = fieldsTables
|
|
||||||
.getFieldsPLCF( part );
|
|
||||||
String result = dumpPlexes( fieldsPlexes );
|
|
||||||
assertEquals( EXPECTED[i], result );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String dumpPlexes( ArrayList<PlexOfField> fieldsPlexes )
|
private String dumpPlexes(ArrayList<PlexOfField> fieldsPlexes) {
|
||||||
{
|
|
||||||
StringBuilder dump = new StringBuilder();
|
StringBuilder dump = new StringBuilder();
|
||||||
for ( int i = 0; i < fieldsPlexes.size(); i++ )
|
for (PlexOfField flds : fieldsPlexes) {
|
||||||
{
|
dump.append(flds.toString() + "\n");
|
||||||
final PlexOfField flds = fieldsPlexes.get( i );
|
|
||||||
dump.append( flds.toString() + "\n" );
|
|
||||||
}
|
}
|
||||||
return dump.toString();
|
return dump.toString();
|
||||||
}
|
}
|
||||||
|
@ -17,43 +17,41 @@
|
|||||||
|
|
||||||
package org.apache.poi.hwpf.model;
|
package org.apache.poi.hwpf.model;
|
||||||
|
|
||||||
import org.apache.poi.hwpf.*;
|
import static org.junit.Assert.assertEquals;
|
||||||
import org.apache.poi.hwpf.model.io.*;
|
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
public final class TestListTables
|
import org.apache.poi.hwpf.HWPFTestCase;
|
||||||
extends HWPFTestCase
|
import org.apache.poi.hwpf.model.io.HWPFFileSystem;
|
||||||
{
|
import org.apache.poi.hwpf.model.io.HWPFOutputStream;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
public TestListTables()
|
public final class TestListTables extends HWPFTestCase {
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testReadWrite()
|
@Test
|
||||||
throws Exception
|
public void testReadWrite() throws IOException {
|
||||||
{
|
FileInformationBlock fib = _hWPFDocFixture._fib;
|
||||||
FileInformationBlock fib = _hWPFDocFixture._fib;
|
byte[] tableStream = _hWPFDocFixture._tableStream;
|
||||||
byte[] tableStream = _hWPFDocFixture._tableStream;
|
|
||||||
|
|
||||||
int listOffset = fib.getFcPlfLst();
|
|
||||||
int lfoOffset = fib.getFcPlfLfo();
|
|
||||||
if (listOffset != 0 && fib.getLcbPlfLst() != 0)
|
|
||||||
{
|
|
||||||
ListTables listTables = new ListTables (tableStream, fib.getFcPlfLst(),
|
|
||||||
fib.getFcPlfLfo (), fib.getLcbPlfLfo());
|
|
||||||
HWPFFileSystem fileSys = new HWPFFileSystem ();
|
|
||||||
|
|
||||||
HWPFOutputStream tableOut = fileSys.getStream ("1Table");
|
|
||||||
|
|
||||||
listTables.writeListDataTo (fib, tableOut);
|
|
||||||
listTables.writeListOverridesTo( fib, tableOut);
|
|
||||||
|
|
||||||
ListTables newTables = new ListTables (tableOut.toByteArray (), fib.getFcPlfLst(),
|
|
||||||
fib.getFcPlfLfo (), fib.getLcbPlfLfo());
|
|
||||||
|
|
||||||
assertEquals(listTables, newTables);
|
|
||||||
|
|
||||||
|
int listOffset = fib.getFcPlfLst();
|
||||||
|
int lfoOffset = fib.getFcPlfLfo();
|
||||||
|
int bLfoOffset = fib.getLcbPlfLfo();
|
||||||
|
|
||||||
|
if (listOffset != 0 && bLfoOffset != 0) {
|
||||||
|
// TODO: this is actually never executed ...
|
||||||
|
|
||||||
|
ListTables listTables = new ListTables(tableStream, listOffset, lfoOffset, bLfoOffset);
|
||||||
|
HWPFFileSystem fileSys = new HWPFFileSystem();
|
||||||
|
|
||||||
|
HWPFOutputStream tableOut = fileSys.getStream("1Table");
|
||||||
|
|
||||||
|
listTables.writeListDataTo(fib, tableOut);
|
||||||
|
listTables.writeListOverridesTo(fib, tableOut);
|
||||||
|
|
||||||
|
ListTables newTables = new ListTables(tableOut.toByteArray(),
|
||||||
|
fib.getFcPlfLst(), fib.getFcPlfLfo(), fib.getLcbPlfLfo());
|
||||||
|
|
||||||
|
assertEquals(listTables, newTables);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,64 +17,67 @@
|
|||||||
|
|
||||||
package org.apache.poi.hwpf.model;
|
package org.apache.poi.hwpf.model;
|
||||||
|
|
||||||
import java.io.*;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import org.apache.poi.hwpf.HWPFDocument;
|
import org.apache.poi.hwpf.HWPFDocument;
|
||||||
import org.apache.poi.hwpf.HWPFTestDataSamples;
|
import org.apache.poi.hwpf.HWPFTestDataSamples;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit test for {@link SavedByTable} and {@link SavedByEntry}.
|
* Unit test for {@link SavedByTable} and {@link SavedByEntry}.
|
||||||
*
|
|
||||||
* @author Daniel Noll
|
|
||||||
*/
|
*/
|
||||||
public final class TestSavedByTable
|
public final class TestSavedByTable {
|
||||||
extends TestCase
|
|
||||||
{
|
|
||||||
|
|
||||||
/** The expected entries in the test document. */
|
/** The expected entries in the test document. */
|
||||||
private final List expected = Arrays.asList(new Object[] {
|
private final List<SavedByEntry> expected = Arrays.asList(
|
||||||
new SavedByEntry("cic22", "C:\\DOCUME~1\\phamill\\LOCALS~1\\Temp\\AutoRecovery save of Iraq - security.asd"),
|
new SavedByEntry("cic22", "C:\\DOCUME~1\\phamill\\LOCALS~1\\Temp\\AutoRecovery save of Iraq - security.asd"),
|
||||||
new SavedByEntry("cic22", "C:\\DOCUME~1\\phamill\\LOCALS~1\\Temp\\AutoRecovery save of Iraq - security.asd"),
|
new SavedByEntry("cic22", "C:\\DOCUME~1\\phamill\\LOCALS~1\\Temp\\AutoRecovery save of Iraq - security.asd"),
|
||||||
new SavedByEntry("cic22", "C:\\DOCUME~1\\phamill\\LOCALS~1\\Temp\\AutoRecovery save of Iraq - security.asd"),
|
new SavedByEntry("cic22", "C:\\DOCUME~1\\phamill\\LOCALS~1\\Temp\\AutoRecovery save of Iraq - security.asd"),
|
||||||
new SavedByEntry("JPratt", "C:\\TEMP\\Iraq - security.doc"),
|
new SavedByEntry("JPratt", "C:\\TEMP\\Iraq - security.doc"),
|
||||||
new SavedByEntry("JPratt", "A:\\Iraq - security.doc"),
|
new SavedByEntry("JPratt", "A:\\Iraq - security.doc"),
|
||||||
new SavedByEntry("ablackshaw", "C:\\ABlackshaw\\Iraq - security.doc"),
|
new SavedByEntry("ablackshaw", "C:\\ABlackshaw\\Iraq - security.doc"),
|
||||||
new SavedByEntry("ablackshaw", "C:\\ABlackshaw\\A;Iraq - security.doc"),
|
new SavedByEntry("ablackshaw", "C:\\ABlackshaw\\A;Iraq - security.doc"),
|
||||||
new SavedByEntry("ablackshaw", "A:\\Iraq - security.doc"),
|
new SavedByEntry("ablackshaw", "A:\\Iraq - security.doc"),
|
||||||
new SavedByEntry("MKhan", "C:\\TEMP\\Iraq - security.doc"),
|
new SavedByEntry("MKhan", "C:\\TEMP\\Iraq - security.doc"),
|
||||||
new SavedByEntry("MKhan", "C:\\WINNT\\Profiles\\mkhan\\Desktop\\Iraq.doc")
|
new SavedByEntry("MKhan", "C:\\WINNT\\Profiles\\mkhan\\Desktop\\Iraq.doc")
|
||||||
});
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests reading in the entries, comparing them against the expected entries.
|
* Tests reading in the entries, comparing them against the expected
|
||||||
* Then tests writing the document out and reading the entries yet again.
|
* entries. Then tests writing the document out and reading the entries yet
|
||||||
*
|
* again.
|
||||||
* @throws Exception if an unexpected error occurs.
|
*
|
||||||
*/
|
* @throws Exception if an unexpected error occurs.
|
||||||
public void testReadWrite()
|
*/
|
||||||
throws Exception
|
@Test
|
||||||
{
|
public void testReadWrite() throws IOException {
|
||||||
// This document is widely available on the internet as "blair.doc".
|
// This document is widely available on the internet as "blair.doc".
|
||||||
// I tried stripping the content and saving the document but my version
|
// I tried stripping the content and saving the document but my version
|
||||||
// of Word (from Office XP) strips this table out.
|
// of Word (from Office XP) strips this table out.
|
||||||
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("saved-by-table.doc");
|
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("saved-by-table.doc");
|
||||||
|
|
||||||
// Check what we just read.
|
// Check what we just read.
|
||||||
assertEquals("List of saved-by entries was not as expected",
|
assertEquals("List of saved-by entries was not as expected", expected,
|
||||||
expected, doc.getSavedByTable().getEntries());
|
doc.getSavedByTable().getEntries());
|
||||||
|
|
||||||
// Now write the entire document out, and read it back in...
|
// Now write the entire document out, and read it back in...
|
||||||
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
|
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
|
||||||
doc.write(byteStream);
|
doc.write(byteStream);
|
||||||
InputStream copyStream = new ByteArrayInputStream(byteStream.toByteArray());
|
InputStream copyStream = new ByteArrayInputStream(byteStream.toByteArray());
|
||||||
HWPFDocument copy = new HWPFDocument(copyStream);
|
doc.close();
|
||||||
|
HWPFDocument copy = new HWPFDocument(copyStream);
|
||||||
|
|
||||||
// And check again.
|
// And check again.
|
||||||
assertEquals("List of saved-by entries was incorrect after writing",
|
assertEquals("List of saved-by entries was incorrect after writing",
|
||||||
expected, copy.getSavedByTable().getEntries());
|
expected, copy.getSavedByTable().getEntries());
|
||||||
}
|
|
||||||
|
copy.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user