Package rife.cmf

Class Content

java.lang.Object
rife.cmf.Content
All Implemented Interfaces:
Cloneable

public class Content extends Object implements Cloneable
Contains the information required to store new content data together with additional meta-data.

All content is determined by its mime type and the raw data that will be used to load the content. The type of the data is dependent on the mime type.

For example, images can be loaded from byte arrays and texts can be loaded from strings. If an unsupported data type is used or the format is incorrect, suitable exceptions will be thrown when the content is stored in the back-end.

Since:
1.0
  • Constructor Details

    • Content

      public Content(MimeType mimeType, Object data)
      Creates a new Content instance with the minimal required arguments.
      Parameters:
      mimeType - the mime type as which the content will be stored in the back-end, note that this doesn't necessarily have to correspond to the mime type of the provided data. Image formats can for example be automatically detected and converted to the target mime type by image loading and conversion libraries.
      data - the data of the content, if this is null, empty content should be stored
      Since:
      1.0
  • Method Details

    • getMimeType

      public MimeType getMimeType()
      Retrieves the mime type of the content.
      Returns:
      the mime type of the content
      Since:
      1.0
    • getData

      public Object getData()
      Retrieves the data of the content.
      Returns:
      the data of the content
      Since:
      1.0
    • setData

      public void setData(Object data)
      Sets the data of the content.
      Since:
      1.4
    • fragment

      public Content fragment(boolean fragment)
      Sets whether the content data is a fragment. A fragment means that it's not a complete document or a file, but rather a small part that is intended to be used within a larger document. For example an HTML snippet. This information is for example important when validating the data.
      Parameters:
      fragment - true if the content is a fragment; or

      false otherwise

      Returns:
      the current Content instance
      Since:
      1.0
      See Also:
    • setFragment

      public void setFragment(boolean fragment)
      Sets whether the content data is a fragment.
      Parameters:
      fragment - true if the content is a fragment; or

      false otherwise

      Since:
      1.0
      See Also:
    • isFragment

      public boolean isFragment()
      Indicates whether the content data is a fragment.
      Returns:
      true if the content is a fragment; or

      false otherwise

      Since:
      1.0
      See Also:
    • name

      public Content name(String name)
      Sets the name of the content.
      Parameters:
      name - the name
      Returns:
      the current Content instance
      Since:
      1.0
      See Also:
    • setName

      public void setName(String name)
      Sets the name of the content.
      Parameters:
      name - the name
      Since:
      1.0
      See Also:
    • getName

      public String getName()
      Retrieves the name of the content.
      Returns:
      null if the content has no name; or

      the name of the content

      Since:
      1.0
      See Also:
    • hasName

      public boolean hasName()
      Indicates whether the content data has a name.
      Returns:
      true if the content has a name; or

      false otherwise

      Since:
      1.0
      See Also:
    • attributes

      public Content attributes(Map<String,String> attributes)
      Replaces the map of named content attributes.

      Note that attributes provide information about how to load, convert and transform content into its stored data form. If you want to provide meta information about the content, you should provide it through properties instead.

      Parameters:
      attributes - the map of named content attributes
      Returns:
      the current Content instance
      Since:
      1.0
      See Also:
    • attribute

      public Content attribute(String name, boolean value)
      Sets a named content attribute that will be converted internally to a String value.
      Parameters:
      name - the name of the attribute
      value - the value of the attribute
      Returns:
      the current Content instance
      Since:
      1.0
      See Also:
    • attribute

      public Content attribute(String name, char value)
      Sets a named content attribute that will be converted internally to a String value.
      Parameters:
      name - the name of the attribute
      value - the value of the attribute
      Returns:
      the current Content instance
      Since:
      1.0
      See Also:
    • attribute

      public Content attribute(String name, byte value)
      Sets a named content attribute that will be converted internally to a String value.
      Parameters:
      name - the name of the attribute
      value - the value of the attribute
      Returns:
      the current Content instance
      Since:
      1.0
      See Also:
    • attribute

      public Content attribute(String name, short value)
      Sets a named content attribute that will be converted internally to a String value.
      Parameters:
      name - the name of the attribute
      value - the value of the attribute
      Returns:
      the current Content instance
      Since:
      1.0
      See Also:
    • attribute

      public Content attribute(String name, int value)
      Sets a named content attribute that will be converted internally to a String value.
      Parameters:
      name - the name of the attribute
      value - the value of the attribute
      Returns:
      the current Content instance
      Since:
      1.0
      See Also:
    • attribute

      public Content attribute(String name, long value)
      Sets a named content attribute that will be converted internally to a String value.
      Parameters:
      name - the name of the attribute
      value - the value of the attribute
      Returns:
      the current Content instance
      Since:
      1.0
      See Also:
    • attribute

      public Content attribute(String name, float value)
      Sets a named content attribute that will be converted internally to a String value.
      Parameters:
      name - the name of the attribute
      value - the value of the attribute
      Returns:
      the current Content instance
      Since:
      1.0
      See Also:
    • attribute

      public Content attribute(String name, double value)
      Sets a named content attribute that will be converted internally to a String value.
      Parameters:
      name - the name of the attribute
      value - the value of the attribute
      Returns:
      the current Content instance
      Since:
      1.0
      See Also:
    • attribute

      public Content attribute(String name, String value)
      Sets a named content attribute.
      Parameters:
      name - the name of the attribute
      value - the value of the attribute
      Returns:
      the current Content instance
      Since:
      1.0
      See Also:
    • setAttributes

      public void setAttributes(Map<String,String> attributes)
      Replaces the map of named content attributes.
      Parameters:
      attributes - the map of named content attributes
      Since:
      1.0
      See Also:
    • getAttributes

      public Map<String,String> getAttributes()
      Retrieves the map of named content attributes.
      Returns:
      the map of named content attributes; or

      null if no attributes are present

      Since:
      1.0
      See Also:
    • hasAttributes

      public boolean hasAttributes()
      Indicates whether named content attributes are present.
      Returns:
      true if named content attributes are present; or

      false otherwise

      Since:
      1.0
      See Also:
    • hasAttribute

      public boolean hasAttribute(String name)
      Indicates whether a specific named content attribute is present.
      Parameters:
      name - the name of the attribute
      Returns:
      true if the name content attribute is present; or

      false otherwise

      Since:
      1.0
      See Also:
    • getAttribute

      public String getAttribute(String name)
      Retrieves the value of a named content attribute.
      Parameters:
      name - the name of the attribute
      Returns:
      the value of the named content attribute; or

      null if no such attribute could be found

      Since:
      1.0
      See Also:
    • properties

      public Content properties(Map<String,String> properties)
      Replaces the content properties.

      This is also internally used by content formatters to provide additional information about the content that's stored after formatting and transformation. Note that this is not the same as content attributes, who provide infomration about how to format and transform the provided data before storage. The content properties describe the result as it's stored in the back-end.

      Parameters:
      properties - the content properties
      Returns:
      the current Content instance
      Since:
      1.0
      See Also:
    • property

      public Content property(String name, boolean value)
      Sets a named content property that will be converted internally to a String value.
      Parameters:
      name - the name of the property
      value - the value of the property
      Returns:
      the current Content instance
      Since:
      1.0
      See Also:
    • property

      public Content property(String name, char value)
      Sets a named content property that will be converted internally to a String value.
      Parameters:
      name - the name of the property
      value - the value of the property
      Returns:
      the current Content instance
      Since:
      1.0
      See Also:
    • property

      public Content property(String name, byte value)
      Sets a named content property that will be converted internally to a String value.
      Parameters:
      name - the name of the property
      value - the value of the property
      Returns:
      the current Content instance
      Since:
      1.0
      See Also:
    • property

      public Content property(String name, short value)
      Sets a named content property that will be converted internally to a String value.
      Parameters:
      name - the name of the property
      value - the value of the property
      Returns:
      the current Content instance
      Since:
      1.0
      See Also:
    • property

      public Content property(String name, int value)
      Sets a named content property that will be converted internally to a String value.
      Parameters:
      name - the name of the property
      value - the value of the property
      Returns:
      the current Content instance
      Since:
      1.0
      See Also:
    • property

      public Content property(String name, long value)
      Sets a named content property that will be converted internally to a String value.
      Parameters:
      name - the name of the property
      value - the value of the property
      Returns:
      the current Content instance
      Since:
      1.0
      See Also:
    • property

      public Content property(String name, float value)
      Sets a named content property that will be converted internally to a String value.
      Parameters:
      name - the name of the property
      value - the value of the property
      Returns:
      the current Content instance
      Since:
      1.0
      See Also:
    • property

      public Content property(String name, double value)
      Sets a named content property that will be converted internally to a String value.
      Parameters:
      name - the name of the property
      value - the value of the property
      Returns:
      the current Content instance
      Since:
      1.0
      See Also:
    • property

      public Content property(String name, String value)
      Sets a named content property.
      Parameters:
      name - the name of the property
      value - the value of the property
      Returns:
      the current Content instance
      Since:
      1.0
      See Also:
    • setProperties

      public void setProperties(Map<String,String> properties)
      Replaces the content properties.
      Parameters:
      properties - the content properties
      Since:
      1.0
      See Also:
    • hasProperties

      public boolean hasProperties()
      Indicates whether content properties are present
      Returns:
      true if properties are present; or

      false otherwise

      Since:
      1.0
      See Also:
    • hasProperty

      public boolean hasProperty(String name)
      Indicates whether a specific named content property is present.
      Parameters:
      name - the name of the property
      Returns:
      true if the name content property is present; or

      false otherwise

      Since:
      1.0
      See Also:
    • getProperty

      public String getProperty(String name)
      Retrieves the value of a named content property.
      Parameters:
      name - the name of the property
      Returns:
      the value of the named content property; or

      null if no such property could be found

      Since:
      1.0
      See Also:
    • getProperties

      public Map<String,String> getProperties()
      Retrieves the content properties.
      Returns:
      the content properties; or

      null if no content properties are present

      Since:
      1.0
      See Also:
    • cachedLoadedData

      public Content cachedLoadedData(Object data)
      Sets the cached loaded data.

      This is internally used by content loaders to prevent having to load and convert data to the specified mime type several times for the same content. It is for instance very resource intensive to detect an image format, validate the provided raw data and create a generic image instance for further processing. These operations are however required in several different locations in the content handling logic. Storing the result after the first successful loading and simply retrieving it later enhances the speed considerably.

      Parameters:
      data - the loaded data
      Returns:
      the current Content instance
      Since:
      1.0
      See Also:
    • setCachedLoadedData

      public void setCachedLoadedData(Object data)
      Sets the cached loaded data.
      Parameters:
      data - the loaded data
      Since:
      1.0
      See Also:
    • hasCachedLoadedData

      public boolean hasCachedLoadedData()
      Indicates whether cached loaded content data is present.
      Returns:
      true if cached loaded content data is present; or

      false otherwise

      Since:
      1.0
      See Also:
    • getCachedLoadedData

      public Object getCachedLoadedData()
      Retrieves the cached loaded content data.
      Returns:
      the cached loaded content data; or

      null if no loaded content data has been cached

      Since:
      1.0
      See Also:
    • clone

      public Content clone()
      Simply clones the instance with the default clone method since we want to create a shallow copy
      Overrides:
      clone in class Object
      Since:
      1.0