org.semanticdesktop.aperture.runtime
Class ApertureRuntime

java.lang.Object
  extended by org.semanticdesktop.aperture.runtime.ApertureRuntime

public class ApertureRuntime
extends Object

A facade to the Aperture functionality. This class provides simple methods that allow you to accomplish the basic Aperture use cases in as little as two lines of code.


Constructor Summary
ApertureRuntime()
           
 
Method Summary
 RDFContainer extractFrom(File file)
          Tries to extract as much information from the given file as possible.
 RDFContainer extractFrom(InputStream stream, String nameOrPathOrUrl)
          Tries to extract as much information from the given input stream as possible.
 RDFContainer extractFrom(String uriString)
          Tries to extract as much information from the given URI as possible.
 ExtractorRegistry getExtractorRegistry()
          Returns the extractor registry.
 MimeTypeIdentifier getMimeTypeIdentifier()
          Returns the mime type identifier.
 String identifyMimeType(InputStream stream, String nameOrPathOrUrl)
          Tries to identify the MIME type of the given input stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ApertureRuntime

public ApertureRuntime()
Method Detail

extractFrom

public RDFContainer extractFrom(String uriString)
                         throws IOException
Tries to extract as much information from the given URI as possible.

Parameters:
uri - the uri from which information is to be extracted. Only the URU with schemes supported by the DefaultDataAccessorRegistry registry and DefaultSubCrawlerRegistry can be accessed and extracted. In most cases the resulting InputStream will be read in its entirety, and the method may try download the content into a temporary file (created with File.createTempFile(String, String). The file will be deleted before this method returns, yet there must be enough room on the partition that houses the temporary folder.
Returns:
an RDFContainer instance containing the data extracted from the URL. It must be disposed properly by the caller of this method, with a call to RDFContainer.dispose(). This method may return null if an object with this URI has not been found.
Throws:
IllegalArgumentException - if the uriString is invalid
IOException - if an I/O error occurs during processing

extractFrom

public RDFContainer extractFrom(InputStream stream,
                                String nameOrPathOrUrl)
                         throws IOException
Tries to extract as much information from the given input stream as possible.

Parameters:
stream - the stream from which information is to be extracted. In most cases the stream will be read in its entirety, so it will probably be unusable after this method returns. THIS METHOD may try to download the entire file to a temporary file
nameOrPathOrUrl - (obligatory) this argument has two purposes: firstly, the file name and extension will be extracted from it which in turn will be used to aid the MIME type detection. Secondly it will serve as the basis for the creation of the URI for the returned RDFContainer. If this argument is already a valid URI it will be used unchanged. Otherwise a new uri will be created, with a 'file:' prefix, and the name or path appended to that prefix, correctly URL-encoded. The process is heuristic, so in a general case the user should make no assumptions what will the URI exactly look like. It should always be checked by calling RDFContainer.getDescribedUri() on the returned RDFContainer instance.
Returns:
an RDFContainer instance containing the data extracted from the InputStream.
Throws:
IOException - if an I/O error occurs in the process.

extractFrom

public RDFContainer extractFrom(File file)
                         throws IOException
Tries to extract as much information from the given file as possible.

Parameters:
file - the file from which information is to be extracted
Returns:
an RDFContainer instance containing the data extracted from the file.
Throws:
IOException - if an I/O error occurs in the process.

identifyMimeType

public String identifyMimeType(InputStream stream,
                               String nameOrPathOrUrl)
                        throws IOException
Tries to identify the MIME type of the given input stream.

Parameters:
stream - the input stream you'd like to identify. If the stream supports mark() and reset(), it's InputStream.markSupported() method returns true, the stream is marked and then reset at the end. If not, then it's not. If you would like to use that stream afterwards, make sure it does support InputStream.mark(int) or wrap it in a BufferedInputStream if it doesn't. Closing the stream is YOUR responsiblity so make so remember about this. You can also leave this argument as NULL in which case the identifier will try to guess the MIME type from the file name or url.
nameOrPathOrUrl - an optional argument, that may help with checking. Many MIME types can be detected by looking at the extension of that file. It can be the name of the file, its path or an URL.
Returns:
a string with the MIME type or null if the MIME type has not been recognized
Throws:
IOException - if an I/O error occurs while reading from the stream

getExtractorRegistry

public ExtractorRegistry getExtractorRegistry()
Returns the extractor registry.

Returns:
the extractor registry.

getMimeTypeIdentifier

public MimeTypeIdentifier getMimeTypeIdentifier()
Returns the mime type identifier.

Returns:
the mime type identifier.


Copyright © 2010 Aperture Development Team. All Rights Reserved.