Package rife.cmf.dam

Interface ContentStore

All Known Implementing Classes:
DatabaseContentStore, DatabaseImageStore, DatabaseRawStore, DatabaseTextStore

public interface ContentStore
A ContentStore stores the actual content data and is responsible for managing it.

The store doesn't work with paths, but with content ids. Each id identifies a specific content instance at a certain location and with a certain version number.

Each store is only capable of storing content with certain mime types. The store is optimized for a certain kind of content and will maybe not be able to correctly handle other types.

Since:
1.0
  • Method Details

    • install

      boolean install() throws ContentManagerException
      Installs a content store.
      Returns:
      true if the installation was successful; or

      false if it wasn't.

      Throws:
      ContentManagerException - if an unexpected error occurred
      Since:
      1.0
    • remove

      boolean remove() throws ContentManagerException
      Removes a content store.
      Returns:
      true if the removal was successful; or

      false if it wasn't.

      Throws:
      ContentManagerException - if an unexpected error occurred
      Since:
      1.0
    • getSupportedMimeTypes

      Collection<MimeType> getSupportedMimeTypes()
      Returns the collection of mime types that the content store supports.
      Returns:
      the collection of supported mime types
      Since:
      1.0
    • getContentType

      String getContentType(ContentInfo contentInfo)
      Generates the HTTP content type that corresponds best to the information in the provided ContentInfo.
      Parameters:
      contentInfo - the content info instance for which the content type has to be generated
      Returns:
      the generated content type
      Since:
      1.0
    • getFormatter

      default Formatter getFormatter(MimeType mimeType, boolean fragment)
      Returns a Formatter instance that will be used to load and to format the content data.
      Parameters:
      mimeType - the mime type for which the formatter will be returned
      fragment - true if the content that has to be formatter is a fragment; or

      false otherwise

      Returns:
      the corresponding formatter
      Since:
      1.0
    • storeContentData

      boolean storeContentData(int id, Content content, ContentTransformer transformer) throws ContentManagerException
      Stores the content data for a certain content id.
      Parameters:
      id - the id of the content whose data will be stored
      content - the content whose data has to be stored
      transformer - a transformer that will modify the content data; or

      null if the content data should stay intact

      Returns:
      true if the storing was successfully; or

      false if it wasn't.

      Throws:
      ContentManagerException - if an unexpected error occurred
      Since:
      1.0
    • deleteContentData

      boolean deleteContentData(int id) throws ContentManagerException
      Deletes the content data for a certain content id.
      Parameters:
      id - the id of the content whose data will be deleted
      Returns:
      true if the deletion was successfully; or

      false if it wasn't.

      Throws:
      ContentManagerException - if an unexpected error occurred
      Since:
      1.0
    • useContentData

      void useContentData(int id, ContentDataUserWithoutResult user) throws ContentManagerException
      Use the data of a certain content id.

      Some content data will only be available during this method call due to their volatile nature (certain streams for instance). Therefore, one has to be careful when trying to move the data that is provided to the content user outside this method. The behaviour is undefined.

      Parameters:
      id - the id of the content whose data will be used
      user - the content user instance that will be called to use content data
      Throws:
      ContentManagerException - if an unexpected error occurred
      Since:
      1.0
    • useContentDataResult

      <ResultType> ResultType useContentDataResult(int id, ContentDataUser<ResultType> user) throws ContentManagerException
      Use the data of a certain content id.

      Some content data will only be available during this method call due to their volatile nature (certain streams for instance). Therefore, one has to be careful when trying to move the data that is provided to the content user outside this method. The behaviour is undefined.

      Parameters:
      id - the id of the content whose data will be used
      user - the content user instance that will be called to use content data
      Returns:
      the data that the ContentDataUser.useContentData(Object) returns after its usage
      Throws:
      ContentManagerException - if an unexpected error occurred
      Since:
      1.0
    • hasContentData

      boolean hasContentData(int id) throws ContentManagerException
      Checks whether content data is available for a certain content id.
      Parameters:
      id - the id of the content whose data availability will be checked
      Returns:
      true if content data is available; or

      false if it isn't.

      Throws:
      ContentManagerException - if an expected error occurred
      Since:
      1.0
    • getSize

      int getSize(int id) throws ContentManagerException
      Retrieves the size of the content data for a certain content id.

      Note that the result is specific to the data store. For instance, text data could return the number of characters, while image data could return the number of bytes.

      Parameters:
      id - the id of the content whose data size will be returned
      Returns:
      -1 if no data is available for the provided content id; or

      the requested content data size.

      Throws:
      ContentManagerException - if an unexpected error occurred
      Since:
      1.0
    • serveContentData

      void serveContentData(Context context, int id) throws ContentManagerException
      Serves content data for a certain content id through the provided element.

      This is intended to take over the complete handling of the request, so no other content should be output and no headers manipulated in the element if this method is called.

      Parameters:
      context - an active web engine context
      id - the id of the content whose data will be served
      Throws:
      ContentManagerException - if an unexpected error occurred
      Since:
      1.0
    • getContentForHtml

      String getContentForHtml(int id, ContentInfo info, Context context, Route route) throws ContentManagerException
      Retrieves a content data representation for use in html.

      This is mainly used to integrate content data inside a html document. For instance, html content will be displayed as-is, while image content will cause an image tag to be generated with the correct source URL to serve the image.

      Parameters:
      id - the id of the content whose data will be displayed
      info - the content info instance for which the html content has to be generated
      context - an active web engine context
      route - a route that leads to a rife.cmf.elements.ServeContent element
      Returns:
      the html content representation
      Throws:
      ContentManagerException - if an unexpected error occurred
      Since:
      1.0