. Code cleanup and javadoc for Outlook email extractor

. Moved cm:emailed aspect and property definitions to ContentModel public fields

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@3427 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Kevin Roast
2006-07-27 09:48:45 +00:00
parent b0d5e15985
commit 65d0eb742e
2 changed files with 45 additions and 31 deletions

View File

@@ -175,6 +175,14 @@ public interface ContentModel
public static final QName TYPE_LINK = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "link"); public static final QName TYPE_LINK = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "link");
public static final QName PROP_LINK_DESTINATION = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "destination"); public static final QName PROP_LINK_DESTINATION = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "destination");
// email aspect
public static final QName ASPECT_MAILED = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "emailed");
public static final QName PROP_SENTDATE = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "sentdate");
public static final QName PROP_ORIGINATOR = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "originator");
public static final QName PROP_ADDRESSEE = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "addressee");
public static final QName PROP_ADDRESSEES = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "addressees");
public static final QName PROP_SUBJECT = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "subjectline");
// //
// Application Model Definitions // Application Model Definitions
// //

View File

@@ -26,6 +26,7 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.alfresco.model.ContentModel;
import org.alfresco.service.cmr.repository.ContentIOException; import org.alfresco.service.cmr.repository.ContentIOException;
import org.alfresco.service.cmr.repository.ContentReader; import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.NamespaceService;
@@ -48,16 +49,8 @@ public class MailMetadataExtracter extends AbstractMetadataExtracter
private static final String STREAM_PREFIX = "__substg1.0_"; private static final String STREAM_PREFIX = "__substg1.0_";
private static final int STREAM_PREFIX_LENGTH = STREAM_PREFIX.length(); private static final int STREAM_PREFIX_LENGTH = STREAM_PREFIX.length();
private static final QName ASPECT_MAILED = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "emailed");
private static final QName PROP_SENTDATE = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "sentdate");
private static final QName PROP_ORIGINATOR = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "originator");
private static final QName PROP_ADDRESSEE = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "addressee");
private static final QName PROP_ADDRESSEES = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "addressees");
private static final QName PROP_SUBJECT = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "subjectline");
// the CC: email addresses // the CC: email addresses
private ThreadLocal<List<String>> receipientEmails = new ThreadLocal<List<String>>(); private ThreadLocal<List<String>> receipientEmails = new ThreadLocal<List<String>>();
//private StringBuilder debug = null;
public MailMetadataExtracter() public MailMetadataExtracter()
{ {
@@ -72,13 +65,12 @@ public class MailMetadataExtracter extends AbstractMetadataExtracter
{ {
try try
{ {
//String name = event.getName(); if (event.getName().startsWith(STREAM_PREFIX))
//String path = event.getPath().toString(); {
//debug.append(path).append(" - ").append(name).append(" (").append(event.getStream().available()).append(")\r\n");
StreamHandler handler = new StreamHandler(event.getName(), event.getStream()); StreamHandler handler = new StreamHandler(event.getName(), event.getStream());
handler.process(destination); handler.process(destination);
} }
}
catch (Exception ex) catch (Exception ex)
{ {
throw new ContentIOException("Property set stream: " + event.getPath() + event.getName(), ex); throw new ContentIOException("Property set stream: " + event.getPath() + event.getName(), ex);
@@ -89,7 +81,6 @@ public class MailMetadataExtracter extends AbstractMetadataExtracter
InputStream is = null; InputStream is = null;
try try
{ {
//debug = new StringBuilder(1024);
this.receipientEmails.set(new ArrayList<String>()); this.receipientEmails.set(new ArrayList<String>());
is = reader.getContentInputStream(); is = reader.getContentInputStream();
@@ -109,10 +100,8 @@ public class MailMetadataExtracter extends AbstractMetadataExtracter
// store multi-value extracted property // store multi-value extracted property
if (receipientEmails.get().size() != 0) if (receipientEmails.get().size() != 0)
{ {
destination.put(PROP_ADDRESSEES, (Serializable)receipientEmails.get()); destination.put(ContentModel.PROP_ADDRESSEES, (Serializable)receipientEmails.get());
} }
//logger.warn(debug);
} }
finally finally
{ {
@@ -139,6 +128,7 @@ public class MailMetadataExtracter extends AbstractMetadataExtracter
private static final String ENCODING_TEXT = "001E"; private static final String ENCODING_TEXT = "001E";
private static final String ENCODING_BINARY = "0102"; private static final String ENCODING_BINARY = "0102";
private static final String ENCODING_UNICODE = "001F"; private static final String ENCODING_UNICODE = "001F";
private static final String SUBSTG_MESSAGEBODY = "1000"; private static final String SUBSTG_MESSAGEBODY = "1000";
private static final String SUBSTG_RECIPIENTEMAIL = "39FE"; private static final String SUBSTG_RECIPIENTEMAIL = "39FE";
private static final String SUBSTG_RECEIVEDEMAIL = "0076"; private static final String SUBSTG_RECEIVEDEMAIL = "0076";
@@ -146,6 +136,9 @@ public class MailMetadataExtracter extends AbstractMetadataExtracter
private static final String SUBSTG_DATE = "0047"; private static final String SUBSTG_DATE = "0047";
private static final String SUBSTG_SUBJECT = "0037"; private static final String SUBSTG_SUBJECT = "0037";
/**
* Class to handle stream types. Can process and extract specific streams.
*/
private class StreamHandler private class StreamHandler
{ {
StreamHandler(String name, DocumentInputStream stream) StreamHandler(String name, DocumentInputStream stream)
@@ -160,7 +153,7 @@ public class MailMetadataExtracter extends AbstractMetadataExtracter
{ {
if (type.equals(SUBSTG_SENDEREMAIL)) if (type.equals(SUBSTG_SENDEREMAIL))
{ {
destination.put(PROP_ORIGINATOR, convertExchangeAddress(extractText())); destination.put(ContentModel.PROP_ORIGINATOR, convertExchangeAddress(extractText()));
} }
else if (type.equals(SUBSTG_RECIPIENTEMAIL)) else if (type.equals(SUBSTG_RECIPIENTEMAIL))
{ {
@@ -168,11 +161,11 @@ public class MailMetadataExtracter extends AbstractMetadataExtracter
} }
else if (type.equals(SUBSTG_RECEIVEDEMAIL)) else if (type.equals(SUBSTG_RECEIVEDEMAIL))
{ {
destination.put(PROP_ADDRESSEE, convertExchangeAddress(extractText())); destination.put(ContentModel.PROP_ADDRESSEE, convertExchangeAddress(extractText()));
} }
else if (type.equals(SUBSTG_SUBJECT)) else if (type.equals(SUBSTG_SUBJECT))
{ {
destination.put(PROP_SUBJECT, extractText()); destination.put(ContentModel.PROP_SUBJECT, extractText());
} }
else if (type.equals(SUBSTG_DATE)) else if (type.equals(SUBSTG_DATE))
{ {
@@ -195,23 +188,32 @@ public class MailMetadataExtracter extends AbstractMetadataExtracter
int hour = Integer.parseInt(strHour); int hour = Integer.parseInt(strHour);
String strMinute = date.substring(dateIndex + 10, dateIndex + 12); String strMinute = date.substring(dateIndex + 10, dateIndex + 12);
int minute = Integer.parseInt(strMinute); int minute = Integer.parseInt(strMinute);
destination.put(PROP_SENTDATE, new Date(year, month, day, hour, minute)); destination.put(ContentModel.PROP_SENTDATE, new Date(year, month, day, hour, minute));
} }
} }
} }
} }
/**
* Extract the text from the stream based on the encoding
*
* @return String
*
* @throws IOException
*/
private String extractText() private String extractText()
throws IOException throws IOException
{ {
byte[] data = new byte[stream.available()]; byte[] data = new byte[stream.available()];
stream.read(data); stream.read(data);
if (this.encoding.equals(ENCODING_TEXT) || this.encoding.equals(ENCODING_BINARY)) if (this.encoding.equals(ENCODING_TEXT) || this.encoding.equals(ENCODING_BINARY))
{ {
return new String(data); return new String(data);
} }
else else if (this.encoding.equals(ENCODING_UNICODE))
{ {
// convert double-byte encoding to single byte for String conversion
byte[] b = new byte[data.length >> 1]; byte[] b = new byte[data.length >> 1];
for (int i=0; i<b.length; i++) for (int i=0; i<b.length; i++)
{ {
@@ -219,6 +221,10 @@ public class MailMetadataExtracter extends AbstractMetadataExtracter
} }
return new String(b); return new String(b);
} }
else
{
return new String(data);
}
} }
private String type; private String type;