Class XMLCatalogImpl

All Implemented Interfaces:
Serializable, Cloneable, Comparable<MediaPackageElement>, Catalog, ManifestContributor, MediaPackageElement, XMLCatalog

public abstract class XMLCatalogImpl extends CatalogImpl implements 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:
  • Field Details

    • XML_LANG_ATTR

      public static final EName XML_LANG_ATTR
      Expanded name of the XML language attribute xml:lang.
    • XSI_NS_PREFIX

      public static final String XSI_NS_PREFIX
      Namespace prefix for XML schema instance.
      See Also:
    • includeEmpty

      protected boolean includeEmpty
      To marshaling empty fields to remove existing values during merge, default is not to marshal empty elements
    • XSI_TYPE_ATTR

      public static final EName XSI_TYPE_ATTR
      Expanded name of the XSI type attribute.

      See http://www.w3.org/TR/xmlschema-1/#xsi_type for the definition.

    • data

      protected final Map<EName,List<XMLCatalogImpl.CatalogEntry>> data
      Key (QName) value meta data
    • bindings

      protected XmlNamespaceContext bindings
      Namespace - prefix bindings
  • Constructor Details

  • Method Details

    • addBinding

      protected void addBinding(XmlNamespaceBinding binding)
    • getBindings

      protected XmlNamespaceContext getBindings()
    • clear

      protected void clear()
      Clears the catalog.
    • addElement

      protected void addElement(EName element, String value)
      Adds the element to the metadata collection.
      Parameters:
      element - the expanded name of the element
      value - the value
    • addLocalizedElement

      protected void addLocalizedElement(EName element, String value, String language)
      Adds the element with the xml:lang attribute to the metadata collection.
      Parameters:
      element - the expanded name of the element
      value - the value
      language - the language identifier (two letter ISO 639)
    • addTypedElement

      protected void addTypedElement(EName element, String value, EName type)
      Adds the element with the xsi:type attribute to the metadata collection.
      Parameters:
      value - the value
      type - the element type
    • addTypedLocalizedElement

      protected void addTypedLocalizedElement(EName element, String value, String language, EName type)
      Adds an element with the xml:lang and xsi:type attributes to the metadata collection.
      Parameters:
      element - the expanded name of the element
      value - the value
      language - the language identifier (two letter ISO 639)
      type - the element type
    • addElement

      protected void addElement(EName element, String value, Attributes attributes)
      Adds an element with attributes to the catalog.
      Parameters:
      element - the expanded name of the element
      value - the element's value
      attributes - the attributes. May be null
    • removeElement

      protected void removeElement(EName element)
      Completely removes an element.
      Parameters:
      element - the expanded name of the element
    • removeLocalizedValues

      protected void removeLocalizedValues(EName element, String language)
      Removes all entries in a certain language from an element.
      Parameters:
      element - the expanded name of the element
      language - the language code (two letter ISO 639) or null to only remove entries without an xml:lang attribute
    • getValues

      protected XMLCatalogImpl.CatalogEntry[] getValues(EName element)
      Returns the values that are associated with the specified key.
      Parameters:
      element - the expanded name of the element
      Returns:
      the elements
    • getEntriesSorted

      protected List<XMLCatalogImpl.CatalogEntry> getEntriesSorted()
    • getValuesAsList

      protected List<XMLCatalogImpl.CatalogEntry> getValuesAsList(EName element)
      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 element
      language - a language code or null to get values without xml:lang attribute
      Returns:
      all values of the element
    • getFirstValue

      protected XMLCatalogImpl.CatalogEntry getFirstValue(EName element)
      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 element
      attributeEName - the expanded attribute name
      attributeValue - the attribute value
      Returns:
      the first value
    • getFirstLocalizedValue

      protected XMLCatalogImpl.CatalogEntry getFirstLocalizedValue(EName element, String language)
      Returns the first value that is associated with the specified name and language.
      Parameters:
      element - the expanded name of the element
      language - the language identifier or null to get only elements without xml:lang attribute
      Returns:
      the first value
    • getFirstTypedValue

      protected XMLCatalogImpl.CatalogEntry getFirstTypedValue(EName element, String type)
      Returns the first value that is associated with the specified name and language.
      Parameters:
      element - the expanded name of the element
      type - the xsi:type value
      Returns:
      the element
    • equal

      protected boolean equal(Object a, Object b)
      Tests two objects for equality.
    • newDocument

      protected Document newDocument() throws ParserConfigurationException
      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: ManifestContributor
      This 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 use MediaPackageElementBuilder.elementFromManifest(org.w3c.dom.Node, MediaPackageSerializer). All other objects shall provide their own implementation specific reconstruction mechanism.

      Specified by:
      toManifest in interface ManifestContributor
      Overrides:
      toManifest in class AbstractMediaPackageElement
      Parameters:
      document - the parent
      serializer - the media package serializer
      Returns:
      the object's xml representation
      Throws:
      MediaPackageException - if the mediapackage can't be serialized
      See Also:
    • getPrefix

      protected String getPrefix(String namespaceURI)
      Get a prefix from bindings but throw a NamespaceBindingException if none found.
    • includeEmpty

      public void includeEmpty(boolean includeEmpty)
      Description copied from interface: XMLCatalog
      Marshal elements with empty values to support remove existing values during catalog merge.
      Specified by:
      includeEmpty in interface XMLCatalog
      Parameters:
      includeEmpty -
      See Also:
    • toQName

      protected String toQName(EName eName)
      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

      protected EName toEName(String prefix, String localName)
      Transform an qualified name consisting of prefix and local part to an expanded name, based on the registered binding.
      Parameters:
      prefix - the prefix
      localName - the local part
      Returns:
      the expanded name
      Throws:
      NamespaceBindingException - if the namespace name is not bound to a prefix
    • toEName

      protected EName toEName(String qName)
      Transform a qualified name to an expanded name, based on the registered binding.
      Parameters:
      qName - the qualified name, e.g. dcterms:title or title
      Returns:
      the expanded name
      Throws:
      NamespaceBindingException - if the namespace name is not bound to a prefix
    • toXml

      public void toXml(OutputStream out, boolean format) throws IOException
      Writes an xml representation of this Catalog to a stream.
      Specified by:
      toXml in interface XMLCatalog
      Parameters:
      out - The output stream
      format - Whether to format the output for readability, or not (false gives better performance)
      Throws:
      IOException
      See Also:
    • toXmlString

      public String toXmlString() throws IOException
      Writes an xml representation of this Catalog to a string.
      Specified by:
      toXmlString in interface XMLCatalog
      Returns:
      the Catalog serialized to a string
      Throws:
      IOException
      See Also: