com.uwyn.rife.cmf
Class Content

java.lang.Object
  extended by com.uwyn.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
Version:
$Revision: 3634 $
Author:
Geert Bevin (gbevin[remove] at uwyn dot com)

Constructor Summary
Content(MimeType mimeType, Object data)
          Creates a new Content instance with the minimal required arguments.
 
Method Summary
 Content attribute(String name, boolean value)
          Sets a named content attribute that will be converted internally to a String value.
 Content attribute(String name, byte value)
          Sets a named content attribute that will be converted internally to a String value.
 Content attribute(String name, char value)
          Sets a named content attribute that will be converted internally to a String value.
 Content attribute(String name, double value)
          Sets a named content attribute that will be converted internally to a String value.
 Content attribute(String name, float value)
          Sets a named content attribute that will be converted internally to a String value.
 Content attribute(String name, int value)
          Sets a named content attribute that will be converted internally to a String value.
 Content attribute(String name, long value)
          Sets a named content attribute that will be converted internally to a String value.
 Content attribute(String name, short value)
          Sets a named content attribute that will be converted internally to a String value.
 Content attribute(String name, String value)
          Sets a named content attribute.
 Content attributes(Map<String,String> attributes)
          Replaces the map of named content attributes.
 Content cachedLoadedData(Object data)
          Sets the cached loaded data.
 Content clone()
          Simply clones the instance with the default clone method since we want to create a shallow copy
 Content fragment(boolean fragment)
          Sets whether the content data is a fragment.
 String getAttribute(String name)
          Retrieves the value of a named content attribute.
 Map<String,String> getAttributes()
          Retrieves the map of named content attributes.
 Object getCachedLoadedData()
          Retrieves the cached loaded content data.
 Object getData()
          Retrieves the data of the content.
 MimeType getMimeType()
          Retrieves the mime type of the content.
 String getName()
          Retrieves the name of the content.
 Map<String,String> getProperties()
          Retrieves the content properties.
 String getProperty(String name)
          Retrieves the value of a named content property.
 boolean hasAttribute(String name)
          Indicates whether a specific named content attribute is present.
 boolean hasAttributes()
          Indicates whether named content attributes are present.
 boolean hasCachedLoadedData()
          Indicates whether cached loaded content data is present.
 boolean hasName()
          Indicates whether the content data has a name.
 boolean hasProperties()
          Indicates whether content properties are present
 boolean hasProperty(String name)
          Indicates whether a specific named content property is present.
 boolean isFragment()
          Indicates whether the content data is a fragment.
 Content name(String name)
          Sets the name of the content.
 Content properties(Map<String,String> properties)
          Replaces the content properties.
 Content property(String name, boolean value)
          Sets a named content property that will be converted internally to a String value.
 Content property(String name, byte value)
          Sets a named content property that will be converted internally to a String value.
 Content property(String name, char value)
          Sets a named content property that will be converted internally to a String value.
 Content property(String name, double value)
          Sets a named content property that will be converted internally to a String value.
 Content property(String name, float value)
          Sets a named content property that will be converted internally to a String value.
 Content property(String name, int value)
          Sets a named content property that will be converted internally to a String value.
 Content property(String name, long value)
          Sets a named content property that will be converted internally to a String value.
 Content property(String name, short value)
          Sets a named content property that will be converted internally to a String value.
 Content property(String name, String value)
          Sets a named content property.
 void setAttributes(Map<String,String> attributes)
          Replaces the map of named content attributes.
 void setCachedLoadedData(Object data)
          Sets the cached loaded data.
 void setData(Object data)
          Sets the data of the content.
 void setFragment(boolean fragment)
          Sets whether the content data is a fragment.
 void setName(String name)
          Sets the name of the content.
 void setProperties(Map<String,String> properties)
          Replaces the content properties.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

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 has 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 Detail

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 a 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(boolean), isFragment()

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:
fragment(boolean), isFragment()

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:
fragment(boolean), setFragment(boolean)

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(String), getName(), hasName()

setName

public void setName(String name)
Sets the name of the content.

Parameters:
name - the name
Since:
1.0
See Also:
name(String), getName(), hasName()

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:
name(String), setName(String), hasName()

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:
name(String), setName(String), getName()

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:
setAttributes(Map), getAttributes(), hasAttributes()

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:
getAttribute(String), hasAttribute(String)

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:
getAttribute(String), hasAttribute(String)

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:
getAttribute(String), hasAttribute(String)

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:
getAttribute(String), hasAttribute(String)

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:
getAttribute(String), hasAttribute(String)

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:
getAttribute(String), hasAttribute(String)

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:
getAttribute(String), hasAttribute(String)

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:
getAttribute(String), hasAttribute(String)

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:
getAttribute(String), hasAttribute(String)

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:
attributes(Map), getAttributes(), hasAttributes()

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:
attributes(Map), setAttributes(Map), hasAttributes()

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:
attributes(Map), setAttributes(Map), getAttributes()

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(String)

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:
hasAttribute(String)

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:
setProperties(Map), hasProperties(), getProperties()

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:
getProperty(String), hasProperty(String)

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:
getProperty(String), hasProperty(String)

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:
getProperty(String), hasProperty(String)

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:
getProperty(String), hasProperty(String)

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:
getProperty(String), hasProperty(String)

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:
getProperty(String), hasProperty(String)

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:
getProperty(String), hasProperty(String)

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:
getProperty(String), hasProperty(String)

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:
getProperty(String), hasProperty(String)

setProperties

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

Parameters:
properties - the content properties
Since:
1.0
See Also:
properties(Map), hasProperties(), getProperties()

hasProperties

public boolean hasProperties()
Indicates whether content properties are present

Returns:
true if properties are present; or

false otherwise

Since:
1.0
See Also:
properties(Map), setProperties(Map), getProperties()

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(String)

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:
hasProperty(String)

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:
properties(Map), setProperties(Map), hasProperties()

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(Object), hasCachedLoadedData(), getCachedLoadedData()

setCachedLoadedData

public void setCachedLoadedData(Object data)
Sets the cached loaded data.

Parameters:
data - the loaded data
Since:
1.0
See Also:
cachedLoadedData(Object), hasCachedLoadedData(), getCachedLoadedData()

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:
cachedLoadedData(Object), setCachedLoadedData(Object), getCachedLoadedData()

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:
cachedLoadedData(Object), setCachedLoadedData(Object), hasCachedLoadedData()

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


Copyright © 2001-2007 Uwyn sprl/bvba. All Rights Reserved.