Class MCRObjectMetadata

java.lang.Object
org.mycore.datamodel.metadata.MCRObjectMetadata
All Implemented Interfaces:
Iterable<MCRMetaElement>

public class MCRObjectMetadata extends Object implements Iterable<MCRMetaElement>
This class implements all methode for handling one object metadata part. This class uses only metadata type classes of the general datamodel code of MyCoRe.
Version:
$Revision$ $Date$
Author:
Jens Kupferschmidt, Mathias Hegner
  • Constructor Details

    • MCRObjectMetadata

      public MCRObjectMetadata() throws MCRConfigurationException
      This is the constructor of the MCRObjectMetadata class. It set the default language for all metadata to the value from the configuration propertie MCR.Metadata.DefaultLang.
      Throws:
      MCRConfigurationException - a special exception for configuartion data
  • Method Details

    • size

      public int size()
      size returns the number of tag names in the ArrayList.
      Returns:
      int number of tags and meta elements
    • getHeritableMetadata

      public final MCRObjectMetadata getHeritableMetadata()
      getHeritableMetadata returns an instance of MCRObjectMetadata containing all the heritable MetaElement's of this object.
      Returns:
      MCRObjectMetadata the heritable part of this MCRObjectMetadata
    • removeInheritedMetadata

      public final void removeInheritedMetadata()
      removeInheritedMetadata removes all inherited metadata elements
    • appendMetadata

      public final void appendMetadata(MCRObjectMetadata input)
      This method append MCRMetaElement's from a given MCRObjectMetadata to this data set.
      Parameters:
      input - the MCRObjectMetadata, that should merged into this data set
    • getMetadataElement

      public final MCRMetaElement getMetadataElement(String tag)
      This method return the MCRMetaElement selected by tag. If this was not found, null was returned.
      Parameters:
      tag - the element tag
      Returns:
      the MCRMetaElement for the tag
    • getMetadataElement

      public final MCRMetaElement getMetadataElement(int index)
      This method return the MCRMetaElement selected by an index. If this was not found, null was returned.
      Parameters:
      index - the element index
      Returns:
      the MCRMetaElement for the index
    • setMetadataElement

      public final void setMetadataElement(MCRMetaElement obj)
      sets the given MCRMetaElement to the list. If the tag exists the MCRMetaElement was replaced.
      Parameters:
      obj - the MCRMetaElement object
    • removeMetadataElement

      public final boolean removeMetadataElement(MCRMetaElement element)
      Removes the given element.
      Parameters:
      element - the meta element to remove
      Returns:
      true if the element was removed
    • removeMetadataElement

      public final MCRMetaElement removeMetadataElement(String tag)
      This method remove the MCRMetaElement selected by tag from the list.
      Returns:
      true if set was successful, otherwise false
    • removeMetadataElement

      public final MCRMetaElement removeMetadataElement(int index)
      This method remove the MCRMetaElement selected a index from the list.
      Returns:
      true if set was successful, otherwise false
    • findFirst

      public final <T extends MCRMetaInterface> Optional<T> findFirst(String tag)
      Finds the first, not inherited MCRMetaInterface with the given tag.
      Parameters:
      tag - the metadata tag e.g. 'maintitles'
      Returns:
      an optional of the first meta interface
    • findFirst

      public final <T extends MCRMetaInterface> Optional<T> findFirst(String tag, String type)
      Finds the first, not inherited MCRMetaInterface with the given tag where the @type attribute is equal to the given type. If the type is null, this method doesn't care if the @type attribute is set or not.
      Parameters:
      tag - the metadata tag e.g. 'subtitles'
      type - the @type attribute which have to match
      Returns:
      an optional of the first meta interface
    • findFirst

      public final <T extends MCRMetaInterface> Optional<T> findFirst(String tag, Integer inherited)
      Finds the first MCRMetaInterface with the given tag where the inheritance level is equal the inherited value.
      Parameters:
      tag - the metadata tag e.g. 'maintitles'
      inherited - level of inheritance. Zero is the current level, parent is one and so on.
      Returns:
      an optional of the first meta interface
    • findFirst

      public final <T extends MCRMetaInterface> Optional<T> findFirst(String tag, String type, Integer inherited)
      Finds the first MCRMetaInterface with the given tag where the inheritance level is equal the inherited value and the @type attribute is equal to the given type. If the type is null, this method doesn't care if the @type attribute is set or not.
      Parameters:
      tag - the metadata tag e.g. 'subtitles'
      type - the @type attribute which have to match
      inherited - level of inheritance. Zero is the current level, parent is one and so on.
      Returns:
      an optional of the first meta interface
    • stream

      public final Stream<MCRMetaElement> stream()
      Streams the MCRMetaElement's.
      Returns:
      stream of MCRMetaElement's
    • stream

      public final <T extends MCRMetaInterface> Stream<T> stream(String tag)
      Streams the MCRMetaInterfaces of the given tag.
       
         Stream<MCRMetaLangText> stream = mcrObjectMetadata.stream("maintitles");
       
       
      Parameters:
      tag - tag the metadata tag e.g. 'maintitles'
      Returns:
      a stream of the requested meta interfaces
    • list

      public final <T extends MCRMetaInterface> List<T> list(String tag)
      Lists the MCRMetaInterfaces of the given tag. This is not a live list. Removals or adds are not reflected on the MCRMetaElement. Use getMetadataElement(String) for those operations.
       
         List<MCRMetaLangText> list = mcrObjectMetadata.list("maintitles");
       
       
      Parameters:
      tag - tag the metadata tag e.g. 'maintitles'
      Returns:
      a list of the requested meta interfaces
    • setFromDOM

      public final void setFromDOM(Element element) throws MCRException
      This methode read the XML input stream part from a DOM part for the metadata of the document.
      Parameters:
      element - a list of relevant DOM elements for the metadata
      Throws:
      MCRException - if a problem occured
    • createXML

      public final Element createXML() throws MCRException
      This methode create a XML stream for all metadata.
      Returns:
      a JDOM Element with the XML data of the metadata part
      Throws:
      MCRException - if the content of this class is not valid
    • createJSON

      public com.google.gson.JsonObject createJSON()
      Creates the JSON representation of this metadata container.
         {
          "def.maintitles": {
            MCRMetaLangText.createJSON()
          }
          "def.dates": {
            MCRMetaISO8601Date.createJSON()
          }
          ...
         }
       
      Returns:
      a json gson representation of this metadata container
    • isValid

      public final boolean isValid()
      This methode check the validation of the content of this class. The methode returns true if
      • the array is empty
      • the default lang value was supported
      otherwise the methode return false
      Returns:
      a boolean value
    • validate

      public void validate() throws MCRException
      Validates this MCRObjectMetadata. This method throws an exception if:
      • one of the MCRMetaElement children is invalid
      Throws:
      MCRException - the MCRObjectMetadata is invalid
    • debug

      public final void debug()
      This method put debug data to the logger (for the debug mode).
    • iterator

      public Iterator<MCRMetaElement> iterator()
      Specified by:
      iterator in interface Iterable<MCRMetaElement>