org.semanticdesktop.aperture.crawler.mail
Class DataObjectFactory

java.lang.Object
  extended by org.semanticdesktop.aperture.crawler.mail.DataObjectFactory

public class DataObjectFactory
extends Object

Creates a set of DataObjects from a MimeMessage.

DataObjectFactory interprets the structure of a MimeMessage and creates a list of DataObjects that model its contents in a way that is most natural to users. Practically this means that the DataObject list should be as similar as possible to how mail readers present the mail.

For example, a multipart/alternative message may have a rather complex object structure (a Part with a MultiPart content, on its turn containing two BodyParts), but this is translated to a single DataObject holding all the mail metadata (sender, receiver, etc) as well as an InputStream accessing the simplest of the two body parts (typically the text/plain part).

Known bugs/features:


Nested Class Summary
static interface DataObjectFactory.PartStreamFactory
          Obtains InputStreams from Part instances.
 
Constructor Summary
DataObjectFactory(javax.mail.internet.MimeMessage message, RDFContainerFactory containerFactory, DataObjectFactory.PartStreamFactory streamFactory, DataSource dataSource, URI messageUri, URI folderUri)
          A simplified constructor that implies the default part uri delimiter
DataObjectFactory(javax.mail.internet.MimeMessage message, RDFContainerFactory containerFactory, DataObjectFactory.PartStreamFactory streamFactory, DataSource dataSource, URI messageUri, URI folderUri, String partUriDelimiter)
          A little simplified constructor that implies the attachment uri prefix to be the same as the message URI.
DataObjectFactory(javax.mail.internet.MimeMessage message, RDFContainerFactory containerFactory, DataObjectFactory.PartStreamFactory streamFactory, DataSource dataSource, URI messageUri, URI folderUri, String partUriDelimiter, String attachmentUriPrefix)
          Constructs a data object factory for the given message
 
Method Summary
 void disposeRemainingObjects()
          Disposes of the data objects remaining on the list of objects to return.
 Map<URI,DataObject> getAllDataObjects()
          Returns a map containing all data objects, indexed by their URIs (from DataObject.getID()
 DataObject getObject()
          Returns a DataObject representing a single message.
 DataObject getObject(String url)
          Returns a data object with the given url, the data object will be removed from the list of data objects to remove.
 DataObject getObjectAndDisposeAllOtherObjects(String url)
          Returns a data object with the given url chosen from the set of objects created from the MimeMessage instance passed to the constructor of this DataObjectFactory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataObjectFactory

public DataObjectFactory(javax.mail.internet.MimeMessage message,
                         RDFContainerFactory containerFactory,
                         DataObjectFactory.PartStreamFactory streamFactory,
                         DataSource dataSource,
                         URI messageUri,
                         URI folderUri,
                         String partUriDelimiter,
                         String attachmentUriPrefix)
                  throws IOException,
                         javax.mail.MessagingException
Constructs a data object factory for the given message

Parameters:
message -
containerFactory -
executorService -
streamFactory - a factory of streams for mail parts, this parameter can be null, in which case a default implementation will be used, that simply calls Part.getInputStream()
dataSource -
messageUri -
folderUri -
partUriDelimiter -
attachmentUriPrefix -
Throws:
IOException
javax.mail.MessagingException

DataObjectFactory

public DataObjectFactory(javax.mail.internet.MimeMessage message,
                         RDFContainerFactory containerFactory,
                         DataObjectFactory.PartStreamFactory streamFactory,
                         DataSource dataSource,
                         URI messageUri,
                         URI folderUri,
                         String partUriDelimiter)
                  throws IOException,
                         javax.mail.MessagingException
A little simplified constructor that implies the attachment uri prefix to be the same as the message URI.

Parameters:
message -
containerFactory -
streamFactory -
dataSource -
messageUri -
folderUri -
partUriDelimiter -
Throws:
IOException
javax.mail.MessagingException

DataObjectFactory

public DataObjectFactory(javax.mail.internet.MimeMessage message,
                         RDFContainerFactory containerFactory,
                         DataObjectFactory.PartStreamFactory streamFactory,
                         DataSource dataSource,
                         URI messageUri,
                         URI folderUri)
                  throws IOException,
                         javax.mail.MessagingException
A simplified constructor that implies the default part uri delimiter

Parameters:
message -
containerFactory -
executorService -
streamFactory -
dataSource -
messageUri -
folderUri -
Throws:
IOException
javax.mail.MessagingException
Method Detail

getObject

public DataObject getObject()
                     throws javax.mail.MessagingException,
                            IOException
Returns a DataObject representing a single message. This data object contains a flattened version of the (arbitrary complex) tree-like MIME structure of the message. This method is called repeatedly for a single MimeMessage. At the first call it creates a cachedDataObjectsMap of all dataObjects that are to be returned from this message. On all subsequent calls DataObjects from this map are returned.

Returns:
a DataObject instance for the given message
Throws:
javax.mail.MessagingException
IOException

disposeRemainingObjects

public void disposeRemainingObjects()
Disposes of the data objects remaining on the list of objects to return. This method must be called if the user stopped calling the getObject() method BEFORE it returned null, thus marking the fact that all objects have been read.


getObject

public DataObject getObject(String url)
Returns a data object with the given url, the data object will be removed from the list of data objects to remove. It will not be disposed by the disposeRemainingObjects() method and therefore must be disposed manually by the user.

Parameters:
url -
Returns:
a data object with the given url, chosen from among the objects created from the MimeMessage instance passed to the constructor of this DataObjectFactory

getObjectAndDisposeAllOtherObjects

public DataObject getObjectAndDisposeAllOtherObjects(String url)
Returns a data object with the given url chosen from the set of objects created from the MimeMessage instance passed to the constructor of this DataObjectFactory. All other data objects from that set are disposed. If there is no data object with the given url - all data objects are disposed.

Parameters:
url -
Returns:
a data object with the given url, or null if no such data object exists

getAllDataObjects

public Map<URI,DataObject> getAllDataObjects()
                                      throws javax.mail.MessagingException,
                                             IOException
Returns a map containing all data objects, indexed by their URIs (from DataObject.getID()

Returns:
a map containing all data objects, indexed by their URIs (from DataObject.getID()
Throws:
javax.mail.MessagingException
IOException


Copyright © 2010 Aperture Development Team. All Rights Reserved.