it.unimi.di.mg4j.document
Class JavamailDocumentCollection

java.lang.Object
  extended by it.unimi.di.mg4j.document.AbstractDocumentSequence
      extended by it.unimi.di.mg4j.document.AbstractDocumentCollection
          extended by it.unimi.di.mg4j.document.JavamailDocumentCollection
All Implemented Interfaces:
DocumentCollection, DocumentSequence, SafelyCloseable, FlyweightPrototype<DocumentCollection>, Closeable, Serializable

public class JavamailDocumentCollection
extends AbstractDocumentCollection
implements Serializable

A DocumentCollection corresponding to a Javamail Store.

This class is very simple: for instance, it will not understand correctly multipart MIME messages, which will seen as without content. You are invited to extend it.

This implementation is an example of a document collection that does not use a factory: more precisely, there is an internal class that act as a wired factory. This structure is made necessary by the fact that Javamail provide no means to parse messages starting from an InputStream, which makes a separate implementation of DocumentFactory.getDocument(InputStream,Reference2ObjectMap) impossible.

Note that to be able to use this class you must configure properly Javamail: this involves setting up a javamail.properties file describing the providers you want to use for the various access schemes. GNU Javamail, for instance, contains providers for files, IMAP, POP, etc.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class it.unimi.di.mg4j.document.AbstractDocumentCollection
AbstractDocumentCollection.PropertyKeys
 
Field Summary
static Date NO_DATE
          A special date (actually, 1 January 1970) representing no date.
 
Fields inherited from interface it.unimi.di.mg4j.document.DocumentCollection
DEFAULT_EXTENSION
 
Constructor Summary
  JavamailDocumentCollection(String storeUrl, String folderName)
           
protected JavamailDocumentCollection(String storeUrl, String folderName, it.unimi.di.mg4j.document.JavamailDocumentCollection.JavamailDocumentFactory factory)
          Builds a document collection corresponding to a given store URL and folder name.
  JavamailDocumentCollection(String storeUrl, String folderName, Properties properties)
           
  JavamailDocumentCollection(String storeUrl, String folderName, Reference2ObjectMap<Enum<?>,Object> defaultMetadata)
           
  JavamailDocumentCollection(String storeUrl, String folderName, String[] property)
           
 
Method Summary
 void close()
          Closes this document sequence, releasing all resources.
 JavamailDocumentCollection copy()
           
 Document document(int index)
          Returns the document given its index.
 DocumentFactory factory()
          Returns the factory used by this sequence.
static void main(String[] arg)
           
 Reference2ObjectMap<Enum<?>,Object> metadata(int index)
          Returns the metadata map for a document.
 int size()
          Returns the number of documents in this collection.
 InputStream stream(int index)
          Returns an input stream for the raw content of a document.
 
Methods inherited from class it.unimi.di.mg4j.document.AbstractDocumentCollection
ensureDocumentIndex, iterator, printAllDocuments, toString
 
Methods inherited from class it.unimi.di.mg4j.document.AbstractDocumentSequence
filename, finalize, load
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface it.unimi.di.mg4j.document.DocumentSequence
filename
 

Field Detail

NO_DATE

public static final Date NO_DATE
A special date (actually, 1 January 1970) representing no date.

Constructor Detail

JavamailDocumentCollection

protected JavamailDocumentCollection(String storeUrl,
                                     String folderName,
                                     it.unimi.di.mg4j.document.JavamailDocumentCollection.JavamailDocumentFactory factory)
                              throws javax.mail.MessagingException
Builds a document collection corresponding to a given store URL and folder name.

Beware. This class is not suited for large mbox files!

Parameters:
storeUrl - the javamail URL of the store.
folderName - the folder name.
factory - the factory that will be used to create documents.
Throws:
javax.mail.MessagingException

JavamailDocumentCollection

public JavamailDocumentCollection(String storeUrl,
                                  String folderName)
                           throws javax.mail.MessagingException
Throws:
javax.mail.MessagingException

JavamailDocumentCollection

public JavamailDocumentCollection(String storeUrl,
                                  String folderName,
                                  Properties properties)
                           throws javax.mail.MessagingException,
                                  ConfigurationException
Throws:
javax.mail.MessagingException
ConfigurationException

JavamailDocumentCollection

public JavamailDocumentCollection(String storeUrl,
                                  String folderName,
                                  String[] property)
                           throws javax.mail.MessagingException,
                                  ConfigurationException
Throws:
javax.mail.MessagingException
ConfigurationException

JavamailDocumentCollection

public JavamailDocumentCollection(String storeUrl,
                                  String folderName,
                                  Reference2ObjectMap<Enum<?>,Object> defaultMetadata)
                           throws javax.mail.MessagingException
Throws:
javax.mail.MessagingException
Method Detail

copy

public JavamailDocumentCollection copy()
Specified by:
copy in interface DocumentCollection
Specified by:
copy in interface FlyweightPrototype<DocumentCollection>

factory

public DocumentFactory factory()
Description copied from interface: DocumentSequence
Returns the factory used by this sequence.

Every document sequence is based on a document factory that transforms raw bytes into a sequence of characters. The factory contains useful information such as the number of fields.

Specified by:
factory in interface DocumentSequence
Returns:
the factory used by this sequence.

size

public int size()
Description copied from interface: DocumentCollection
Returns the number of documents in this collection.

Specified by:
size in interface DocumentCollection
Returns:
the number of documents in this collection.

close

public void close()
           throws IOException
Description copied from interface: DocumentSequence
Closes this document sequence, releasing all resources.

You should always call this method after having finished with this document sequence. Implementations are invited to call this method in a finaliser as a safety net (even better, implement SafelyCloseable), but since there is no guarantee as to when finalisers are invoked, you should not depend on this behaviour.

Specified by:
close in interface DocumentSequence
Specified by:
close in interface Closeable
Overrides:
close in class AbstractDocumentSequence
Throws:
IOException

document

public Document document(int index)
                  throws IOException
Description copied from interface: DocumentCollection
Returns the document given its index.

Specified by:
document in interface DocumentCollection
Parameters:
index - an index between 0 (inclusive) and DocumentCollection.size() (exclusive).
Returns:
the index-th document.
Throws:
IOException

metadata

public Reference2ObjectMap<Enum<?>,Object> metadata(int index)
Description copied from interface: DocumentCollection
Returns the metadata map for a document.

Specified by:
metadata in interface DocumentCollection
Parameters:
index - an index between 0 (inclusive) and DocumentCollection.size() (exclusive).
Returns:
the metadata map for the document.

stream

public InputStream stream(int index)
                   throws IOException
Description copied from interface: DocumentCollection
Returns an input stream for the raw content of a document.

Specified by:
stream in interface DocumentCollection
Parameters:
index - an index between 0 (inclusive) and DocumentCollection.size() (exclusive).
Returns:
the raw content of the document as an input stream.
Throws:
IOException

main

public static void main(String[] arg)
                 throws IOException,
                        com.martiansoftware.jsap.JSAPException,
                        IllegalAccessException,
                        InvocationTargetException,
                        NoSuchMethodException,
                        InstantiationException,
                        javax.mail.MessagingException,
                        ConfigurationException
Throws:
IOException
com.martiansoftware.jsap.JSAPException
IllegalAccessException
InvocationTargetException
NoSuchMethodException
InstantiationException
javax.mail.MessagingException
ConfigurationException