Class ContentRepresentations
- java.lang.Object
-
- nl.gx.webmanager.services.contentrepresentation.ContentRepresentations
-
public final class ContentRepresentations extends Object
This is a utility class to createContentRepresentation
instances andContentRepresentationEntry
instances via the#create(String, Collection)
,createEntry(String, List)
andcreateRefEntry(String, List)
methods respectively.This class also has methods to write
ContentRepresentation
instances toString
s and vice versa. The createdString
is an XML representation which includes a version number for future extensions and compatibility.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ContentRepresentation
create(String contentType, WmId wmId, Set<String> interfaceNames, Collection<ContentRepresentationEntry> data)
Creates aContentRepresentation
from the given values.static ContentRepresentationValueEntry
createEntry(String name, List<String> values)
Creates aContentRepresentationEntry
instance from the given values.static ContentRepresentationReferenceEntry
createRefEntry(String name, List<ContentRepresentation> values)
Creates aContentRepresentationEntry
instance from the given values.static ContentRepresentation
fromXml(String representation)
Converts aString
representation to aContentRepresentation
instance.static String
toXml(ContentRepresentation representation)
Flattens the givenContentRepresentation
to an XMLString
.
-
-
-
Method Detail
-
create
public static ContentRepresentation create(String contentType, WmId wmId, Set<String> interfaceNames, Collection<ContentRepresentationEntry> data)
Creates aContentRepresentation
from the given values. Note that the names of theContentRepresentationEntry
instances in the givenCollection
should be unique. If they are not unique, then entries get lost in the returned representation.- Parameters:
contentType
- the content typedata
- the collection ofContentRepresentationEntry
s which must have unique nameswmId
- the wmId of the represented content iteminterfaceNames
- the names of the interfaces that the represented content item implements- Returns:
- an immutable
ContentRepresentation
instance
-
createEntry
public static ContentRepresentationValueEntry createEntry(String name, List<String> values)
Creates aContentRepresentationEntry
instance from the given values.- Parameters:
name
- the name of the entry, not nullvalues
- the values of the entry, not null- Returns:
- an immutable
ContentRepresentationEntry
instance for the given values
-
createRefEntry
public static ContentRepresentationReferenceEntry createRefEntry(String name, List<ContentRepresentation> values)
Creates aContentRepresentationEntry
instance from the given values.- Parameters:
name
- the name of the entryvalues
- the reference values of the entry- Returns:
- an immutable
ContentRepresentationEntry
instance for the given values
-
toXml
public static String toXml(ContentRepresentation representation)
Flattens the givenContentRepresentation
to an XMLString
. ThisString
representation can be converted back to aContentRepresentation
instance using thefromXml(String)
method.Note that this method assumes a tree-structure and does not check for cycles.
- Parameters:
representation
- theContentRepresentation
to flatten- Returns:
- an
String
representation in XML format
-
fromXml
public static ContentRepresentation fromXml(String representation) throws ContentRepresentationException
Converts aString
representation to aContentRepresentation
instance. Use in combination withtoXml(ContentRepresentation)
.- Parameters:
representation
- theString
representation- Returns:
- a
ContentRepresentation
instance of the givenString
- Throws:
ContentRepresentationException
- on error
-
-