org.apache.stanbol.enhancer.servicesapi
Interface ContentItem

All Known Implementing Classes:
ContentItemImpl, InMemoryContentItem, WebContentItem

public interface ContentItem

A unit of content that Stanbol Enhancer can enhance.

Gives access to the binary content that was registered, and the Graph that represents its metadata (provided by client and/or generated).


Method Summary
 java.lang.Object addPart(org.apache.clerezza.rdf.core.UriRef uriRef, java.lang.Object object)
          Add a new part to this ContentItem
 Blob getBlob()
          The main content of this content item
 java.util.concurrent.locks.ReadWriteLock getLock()
          Read/write lock used to synchronise access to the metadata and the content parts of this content item.
 org.apache.clerezza.rdf.core.access.LockableMGraph getMetadata()
          Optional metadata
 java.lang.String getMimeType()
          The MimeType.
<T> T
getPart(int index, java.lang.Class<T> clazz)
          A content item may consists of multiple parts, while the part with index 0 should always be a blob, higher position may be used by Enhancer to story arbitrary objects, such objects can be used for accessing the precomputations of EnhancementEngines previous in the chain.
<T> T
getPart(org.apache.clerezza.rdf.core.UriRef uri, java.lang.Class<T> clazz)
          Each part of the content item has a URI.
 org.apache.clerezza.rdf.core.UriRef getPartUri(int index)
          Get the uri of the part at the specified index
 java.io.InputStream getStream()
          The binary content stream.
 org.apache.clerezza.rdf.core.UriRef getUri()
          The Uri of this ContentItem (either supplied by client or generated by Stanbol Enhancer)
 void removePart(int index)
          Removes a part - other than the main content part - from this ContentItem
 void removePart(org.apache.clerezza.rdf.core.UriRef uriRef)
          Removes a part - other than the main content part - from this ContentItem
 

Method Detail

getUri

org.apache.clerezza.rdf.core.UriRef getUri()
The Uri of this ContentItem (either supplied by client or generated by Stanbol Enhancer)


getStream

java.io.InputStream getStream()
The binary content stream. Shortcut for getBlob().getStream()

Returns:
the InputStream

getMimeType

java.lang.String getMimeType()
The MimeType. Shortcut for getBlob().getMimeType().

Returns:
the MimeType as string

getLock

java.util.concurrent.locks.ReadWriteLock getLock()
Read/write lock used to synchronise access to the metadata and the content parts of this content item.

The lock used by the LockableMGraph.getLock() MUST BE the same as the lock returned by this Instance. This is to avoid deadlocks when using a lock while iterating over the metadata and simultaneously accessing the content parts. In other words calling contentItem.getLock() == contentItem.getMetadata().getLock() MUST BE true

Returns:
the lock used for the content parts and the LockableMGraph containing the metadata of this content item.

getMetadata

org.apache.clerezza.rdf.core.access.LockableMGraph getMetadata()
Optional metadata


getBlob

Blob getBlob()
The main content of this content item

Returns:
the blob at index 0

getPart

<T> T getPart(int index,
              java.lang.Class<T> clazz)
          throws NoSuchPartException
A content item may consists of multiple parts, while the part with index 0 should always be a blob, higher position may be used by Enhancer to story arbitrary objects, such objects can be used for accessing the precomputations of EnhancementEngines previous in the chain.

Throws:
NoSuchPartException - if no part with the parsed index exists
java.lang.ClassCastException - if the class of the part is not compatiple with the requested class
java.lang.IllegalArgumentException - if null is parsed as clazz.

getPart

<T> T getPart(org.apache.clerezza.rdf.core.UriRef uri,
              java.lang.Class<T> clazz)
          throws NoSuchPartException
Each part of the content item has a URI. EnhancementEngines typically access parts by their Uri as the position may vary depending on the chain.

Throws:
NoSuchPartException - if no part with the parsed uri exists
java.lang.ClassCastException - if the class of the part is not compatiple with the requested class
java.lang.IllegalArgumentException - if null is parsed as uri or clazz.

getPartUri

org.apache.clerezza.rdf.core.UriRef getPartUri(int index)
                                               throws NoSuchPartException
Get the uri of the part at the specified index

Throws:
NoSuchPartException - if no part with the parsed index exists

addPart

java.lang.Object addPart(org.apache.clerezza.rdf.core.UriRef uriRef,
                         java.lang.Object object)
Add a new part to this ContentItem

Parameters:
uriRef - the URI of the part
object - the part
Returns:
the part replaced by the parsed object or null if no part with the parsed URI was present
Throws:
java.lang.IllegalArgumentException - if null is parsed as uriRef or object.

removePart

void removePart(int index)
Removes a part - other than the main content part - from this ContentItem

Parameters:
index - the index of the part to remove. NOTE that index '0' - the main content part - can NOT be removed!
Throws:
NoSuchPartException - if no ContentPart with the parsed id exists
java.lang.IllegalArgumentException - it the parsed index < 0
java.lang.IllegalStateException - if '0' is parsed as index. The index '0' - the main content part - can NOT be removed!

removePart

void removePart(org.apache.clerezza.rdf.core.UriRef uriRef)
Removes a part - other than the main content part - from this ContentItem

Parameters:
uriRef - the uri of the part to remove. NOTE that the part with the uri getPartUri(0) - the main content part - can NOT be removed!
Throws:
NoSuchPartException - if no ContentPart with the parsed uri exists
java.lang.IllegalArgumentException - it the parsed uri is null
java.lang.IllegalStateException - if the parsed uri is equals to getPartUri(0). This uri refers to the main content part. This part can NOT be removed by this method


Copyright © 2010-2012 The Apache Software Foundation. All Rights Reserved.