Package org.opencastproject.mediapackage
Class XMLCatalogImpl
java.lang.Object
org.opencastproject.mediapackage.AbstractMediaPackageElement
org.opencastproject.mediapackage.CatalogImpl
org.opencastproject.mediapackage.XMLCatalogImpl
- All Implemented Interfaces:
Serializable,Cloneable,Comparable<MediaPackageElement>,Catalog,ManifestContributor,MediaPackageElement,XMLCatalog
This is a basic implementation for handling simple catalogs of metadata. It provides utility methods to store
key-value data.
For a definition of the terms expanded name, qualified name or QName, namespace prefix, local part and local name, please see http://www.w3.org/TR/REC-xml-names
By default the following namespace prefixes are bound:
- xml - http://www.w3.org/XML/1998/namespace
- xmlns - http://www.w3.org/2000/xmlns/
- xsi - http://www.w3.org/2001/XMLSchema-instance
Limitations
XMLCatalog supports only one prefix binding per namespace name, so you cannot create documents like the following using XMLCatalog:<root xmlns:x="http://x.demo.org" xmlns:y="http://x.demo.org"> <x:elem>value</x:elem> <y:elem>value</y:elem> </root>However, reading of those documents is supported.
- See Also:
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class org.opencastproject.mediapackage.CatalogImpl
CatalogImpl.AdapterNested classes/interfaces inherited from interface org.opencastproject.mediapackage.MediaPackageElement
MediaPackageElement.Type -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected XmlNamespaceContextNamespace - prefix bindingsprotected final Map<EName, List<XMLCatalogImpl.CatalogEntry>> Key (QName) value meta dataprotected booleanTo marshaling empty fields to remove existing values during merge, default is not to marshal empty elementsstatic final ENameExpanded name of the XML language attributexml:lang.static final StringNamespace prefix for XML schema instance.static final ENameExpanded name of the XSI type attribute.Fields inherited from class org.opencastproject.mediapackage.AbstractMediaPackageElement
checksum, description, elementType, flavor, id, mediaPackage, mimeType, reference, size, tags, uri -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCreate an empty catalog and register theXMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URInamespace. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddBinding(XmlNamespaceBinding binding) protected voidaddElement(EName element, String value) Adds the element to the metadata collection.protected voidaddElement(EName element, String value, Attributes attributes) Adds an element with attributes to the catalog.protected voidaddLocalizedElement(EName element, String value, String language) Adds the element with thexml:langattribute to the metadata collection.protected voidaddTypedElement(EName element, String value, EName type) Adds the element with thexsi:typeattribute to the metadata collection.protected voidaddTypedLocalizedElement(EName element, String value, String language, EName type) Adds an element with thexml:langandxsi:typeattributes to the metadata collection.protected voidclear()Clears the catalog.protected booleanTests two objects for equality.protected XmlNamespaceContextprotected List<XMLCatalogImpl.CatalogEntry> protected XMLCatalogImpl.CatalogEntrygetFirstLocalizedValue(EName element, String language) Returns the first value that is associated with the specified name and language.protected XMLCatalogImpl.CatalogEntrygetFirstTypedValue(EName element, String type) Returns the first value that is associated with the specified name and language.protected XMLCatalogImpl.CatalogEntrygetFirstValue(EName element) Returns the first value that is associated with the specified name.protected XMLCatalogImpl.CatalogEntrygetFirstValue(EName element, EName attributeEName, String attributeValue) Returns the first element that is associated with the specified name and attribute.protected List<XMLCatalogImpl.CatalogEntry> getLocalizedValuesAsList(EName element, String language) Returns the values that are associated with the specified key.protected StringGet a prefix frombindingsbut throw aNamespaceBindingExceptionif none found.protected XMLCatalogImpl.CatalogEntry[]Returns the values that are associated with the specified key.protected List<XMLCatalogImpl.CatalogEntry> getValuesAsList(EName element) Returns the values that are associated with the specified key.voidincludeEmpty(boolean includeEmpty) Marshal elements with empty values to support remove existing values during catalog merge.protected DocumentCreates an xml document root and returns it.protected voidremoveElement(EName element) Completely removes an element.protected voidremoveLocalizedValues(EName element, String language) Removes all entries in a certain language from an element.protected ENameTransform a qualified name to an expanded name, based on the registered binding.protected ENameTransform an qualified name consisting of prefix and local part to an expanded name, based on the registered binding.toManifest(Document document, MediaPackageSerializer serializer) This method returns an XML serialization of the object to be stored in the media package manifest.protected StringTransform an expanded name to a qualified name based on the registered binding.voidtoXml(OutputStream out, boolean format) Writes an xml representation of this Catalog to a stream.Writes an xml representation of this Catalog to a string.Methods inherited from class org.opencastproject.mediapackage.CatalogImpl
fromURI, newInstanceMethods inherited from class org.opencastproject.mediapackage.AbstractMediaPackageElement
addTag, clearReference, clearTags, clone, compareTo, containsTag, containsTag, equals, generateIdentifier, getChecksum, getElementDescription, getElementType, getFlavor, getIdentifier, getMediaPackage, getMimeType, getReference, getSize, getTags, getURI, hashCode, referTo, referTo, removeTag, setChecksum, setElementDescription, setFlavor, setIdentifier, setMimeType, setReference, setSize, setTags, setURI, toString, verifyMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Comparable
compareToMethods inherited from interface org.opencastproject.mediapackage.MediaPackageElement
addTag, clearReference, clearTags, clone, containsTag, containsTag, generateIdentifier, getChecksum, getElementDescription, getElementType, getFlavor, getIdentifier, getMediaPackage, getMimeType, getReference, getSize, getTags, getURI, referTo, referTo, removeTag, setChecksum, setElementDescription, setFlavor, setIdentifier, setMimeType, setReference, setSize, setTags, setURI, verifyMethods inherited from interface org.opencastproject.mediapackage.XMLCatalog
toJson, toXml
-
Field Details
-
XML_LANG_ATTR
Expanded name of the XML language attributexml:lang. -
XSI_NS_PREFIX
Namespace prefix for XML schema instance.- See Also:
-
includeEmpty
protected boolean includeEmptyTo marshaling empty fields to remove existing values during merge, default is not to marshal empty elements -
XSI_TYPE_ATTR
Expanded name of the XSI type attribute.See http://www.w3.org/TR/xmlschema-1/#xsi_type for the definition.
-
data
Key (QName) value meta data -
bindings
Namespace - prefix bindings
-
-
Constructor Details
-
XMLCatalogImpl
protected XMLCatalogImpl()Create an empty catalog and register theXMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URInamespace.
-
-
Method Details
-
addBinding
-
getBindings
-
clear
protected void clear()Clears the catalog. -
addElement
Adds the element to the metadata collection.- Parameters:
element- the expanded name of the elementvalue- the value
-
addLocalizedElement
Adds the element with thexml:langattribute to the metadata collection.- Parameters:
element- the expanded name of the elementvalue- the valuelanguage- the language identifier (two letter ISO 639)
-
addTypedElement
Adds the element with thexsi:typeattribute to the metadata collection.- Parameters:
value- the valuetype- the element type
-
addTypedLocalizedElement
Adds an element with thexml:langandxsi:typeattributes to the metadata collection.- Parameters:
element- the expanded name of the elementvalue- the valuelanguage- the language identifier (two letter ISO 639)type- the element type
-
addElement
Adds an element with attributes to the catalog.- Parameters:
element- the expanded name of the elementvalue- the element's valueattributes- the attributes. May be null
-
removeElement
Completely removes an element.- Parameters:
element- the expanded name of the element
-
removeLocalizedValues
Removes all entries in a certain language from an element.- Parameters:
element- the expanded name of the elementlanguage- the language code (two letter ISO 639) or null to only remove entries without anxml:langattribute
-
getValues
Returns the values that are associated with the specified key.- Parameters:
element- the expanded name of the element- Returns:
- the elements
-
getEntriesSorted
-
getValuesAsList
Returns the values that are associated with the specified key.- Parameters:
element- the expanded name of the element- Returns:
- all values of the element or an empty list if this element does not exist or does not have any values
-
getLocalizedValuesAsList
protected List<XMLCatalogImpl.CatalogEntry> getLocalizedValuesAsList(EName element, String language) Returns the values that are associated with the specified key.- Parameters:
element- the expandend name of the elementlanguage- a language code or null to get values withoutxml:langattribute- Returns:
- all values of the element
-
getFirstValue
Returns the first value that is associated with the specified name.- Parameters:
element- the expanded name of the element- Returns:
- the first value
-
getFirstValue
protected XMLCatalogImpl.CatalogEntry getFirstValue(EName element, EName attributeEName, String attributeValue) Returns the first element that is associated with the specified name and attribute.- Parameters:
element- the expanded name of the elementattributeEName- the expanded attribute nameattributeValue- the attribute value- Returns:
- the first value
-
getFirstLocalizedValue
Returns the first value that is associated with the specified name and language.- Parameters:
element- the expanded name of the elementlanguage- the language identifier or null to get only elements withoutxml:langattribute- Returns:
- the first value
-
getFirstTypedValue
Returns the first value that is associated with the specified name and language.- Parameters:
element- the expanded name of the elementtype- thexsi:typevalue- Returns:
- the element
-
equal
Tests two objects for equality. -
newDocument
Creates an xml document root and returns it.- Returns:
- the document
- Throws:
ParserConfigurationException- If the xml parser environment is not correctly configured
-
toManifest
public Node toManifest(Document document, MediaPackageSerializer serializer) throws MediaPackageException Description copied from interface:ManifestContributorThis method returns an XML serialization of the object to be stored in the media package manifest. It should be possible to reconstruct the object from this data.For creating
MediaPackageElements from a manifest, please useMediaPackageElementBuilder.elementFromManifest(org.w3c.dom.Node, MediaPackageSerializer). All other objects shall provide their own implementation specific reconstruction mechanism.- Specified by:
toManifestin interfaceManifestContributor- Overrides:
toManifestin classAbstractMediaPackageElement- Parameters:
document- the parentserializer- the media package serializer- Returns:
- the object's xml representation
- Throws:
MediaPackageException- if the mediapackage can't be serialized- See Also:
-
getPrefix
Get a prefix frombindingsbut throw aNamespaceBindingExceptionif none found. -
includeEmpty
public void includeEmpty(boolean includeEmpty) Description copied from interface:XMLCatalogMarshal elements with empty values to support remove existing values during catalog merge.- Specified by:
includeEmptyin interfaceXMLCatalog- Parameters:
includeEmpty-- See Also:
-
toQName
Transform an expanded name to a qualified name based on the registered binding.- Parameters:
eName- the expanded name to transform- Returns:
- the qualified name, e.g.
dcterms:title - Throws:
NamespaceBindingException- if the namespace name is not bound to a prefix
-
toEName
Transform an qualified name consisting of prefix and local part to an expanded name, based on the registered binding.- Parameters:
prefix- the prefixlocalName- the local part- Returns:
- the expanded name
- Throws:
NamespaceBindingException- if the namespace name is not bound to a prefix
-
toEName
Transform a qualified name to an expanded name, based on the registered binding.- Parameters:
qName- the qualified name, e.g.dcterms:titleortitle- Returns:
- the expanded name
- Throws:
NamespaceBindingException- if the namespace name is not bound to a prefix
-
toXml
Writes an xml representation of this Catalog to a stream.- Specified by:
toXmlin interfaceXMLCatalog- Parameters:
out- The output streamformat- Whether to format the output for readability, or not (false gives better performance)- Throws:
IOException- See Also:
-
toXmlString
Writes an xml representation of this Catalog to a string.- Specified by:
toXmlStringin interfaceXMLCatalog- Returns:
- the Catalog serialized to a string
- Throws:
IOException- See Also:
-