Class NdrObjectReader

java.lang.Object
org.dlese.dpc.ndr.reader.NdrObjectReader
Direct Known Subclasses:
AgentReader, GroupingObjectReader, MetadataReader

public class NdrObjectReader extends Object
Base Class for reading NDR responses to GET Requests, used primarily to support NDR Import operations. Extended to read specific types of NDR Objects, such as Metadata and MetadataProvider.
Author:
ostwald
  • Field Details

    • doc

      protected org.dom4j.Document doc
    • dsFormats

      protected List dsFormats
    • handle

      protected String handle
    • objectType

      protected NDRConstants.NDRObjectType objectType
    • lastModifiedDate

      protected String lastModifiedDate
    • createdDate

      protected String createdDate
    • nativeDataStreamFormat

      protected String nativeDataStreamFormat
      Native data stream format for this object
    • nsContext

      protected org.jaxen.SimpleNamespaceContext nsContext
      nsContext to support xpath ops
  • Constructor Details

    • NdrObjectReader

      public NdrObjectReader(org.dom4j.Document response) throws Exception
      Constructor for the NdrObjectReader object with a XML Document (for testing purposes)
      Parameters:
      response - NOT YET DOCUMENTED
      Throws:
      Exception - NOT YET DOCUMENTED
    • NdrObjectReader

      public NdrObjectReader(String handle) throws Exception
      Constructor for the NdrObjectReader object with ndrHandle
      Parameters:
      handle - handle of NDR object to read
      Throws:
      Exception - if object cannot be read from NDR
    • NdrObjectReader

      public NdrObjectReader(String handle, String nativeDataStreamFormat) throws Exception
      Constructor for the NdrObjectReader object with ndrHandle and specified nativeDataStreamFormat.
      Parameters:
      handle - handle of NDR object to read
      nativeDataStreamFormat - native metadata format (helps extract native data_stream)
      Throws:
      Exception - NOT YET DOCUMENTED
    • NdrObjectReader

      public NdrObjectReader(org.dom4j.Document ndrResponse, String nativeDataStreamFormat) throws Exception
      Constructor for the NdrObjectReader object
      Parameters:
      ndrResponse - NOT YET DOCUMENTED
      nativeDataStreamFormat - NOT YET DOCUMENTED
      Throws:
      Exception - NOT YET DOCUMENTED
  • Method Details

    • getNsContext

      protected org.jaxen.SimpleNamespaceContext getNsContext()
      Returns a namespace context instance, containing namespaces occuring in NDR objects, that is used in xpath operations.
      Returns:
      The nsContext value
    • getDocument

      public org.dom4j.Document getDocument()
      Gets the original "get" response for this reader object as a dom4j.Document instance.
      Returns:
      The document value
    • getProperty

      public String getProperty(String prop)
      Gets the specified property of the NdrObjectReader object (returning the first if more than one property is present). If provide prop is not qualified, a namespace prefix of "nsdl" is assumed. If a namespace prefix is provided (e.g., "ncs:status"), it must be contained in the nameSpace Context for this reader.
      Parameters:
      prop - Description of the Parameter
      Returns:
      The property value
    • getPropertyValues

      public List getPropertyValues(String name)
      Gets a list of values for the specified property
      Parameters:
      name - propertyname, qualifed with "nsdl" if no namespace prefix is present.
      Returns:
      a list of property values for specified property.
    • getRelationship

      public String getRelationship(String name)
      Gets the FIRST relationship (there may be more) with specified name, which is assumed to be in "nsdl" namespace if no prefix is present.
      Parameters:
      name - relationship name ("auth:authorizedToChange")
      Returns:
      the relationship value (a ndrHandle)
    • getRelationshipValues

      public List getRelationshipValues(String name)
      Gets all the relationships for the specified name.
      Parameters:
      name - Relationship name ("auth:authorizedToChange)
      Returns:
      List of relationship values (ndr handles) for provided name
    • getHandle

      public String getHandle()
      Gets the handle attribute of the NdrObjectReader object.
      Returns:
      The handle value
    • getObjectType

      public NDRConstants.NDRObjectType getObjectType()
      Gets the objectType property of the NdrObject. Can be used as integrity check.
      Returns:
      The objectType value
    • getState

      public NDRConstants.ObjectState getState()
      Gets the fedora-model:state property of the NdrObject
      Returns:
      The state value
    • getLastModifiedDate

      public String getLastModifiedDate()
      Gets the fedora-view:lastModifiedDate property of the NdrObject as a string
      Returns:
      The lastModifiedDate value
    • getLastModified

      public Date getLastModified()
      Gets the fedora-view:lastModifiedDate property of the NdrObject as a Date object
      Returns:
      The lastModified value
    • getCreatedDate

      public String getCreatedDate()
      Gets the fedora-view:createdDate property of the NdrObject
      Returns:
      The createdDate value
    • getCreated

      public Date getCreated()
      Gets the fedora-view:createdDate property of the NdrObject as a Date object
      Returns:
      The created value
    • initDataStreams

      protected void initDataStreams()
      Builds a map containing entries for each datastream format in this object, but does not populate the values of the map until necessary.

      NOTE: datastreams ending in "_info" are ignored and therefore not accessible by "getDataStream"

      DataStream elements have format attribute named "format_"+DATA_STREAM_FORMAT"

    • getFormats

      public Set getFormats()
      Returns the data stream formats as a Set.
      Returns:
      The formats value
    • getNativeDataStream

      public org.dom4j.Element getNativeDataStream(String format)
      Gets the native dataStream of the NdrObject for the specified native "format".

      Note: this method cannot return a non-native datastream.

      Parameters:
      format - native datastream format (e.g., "oai_dc")
      Returns:
      The dataStream value
    • getNativeDataStream

      public org.dom4j.Element getNativeDataStream(String format, String version)
      Gets the navite dataStream of the NdrObject for specified format and version. If version is provided, the datastream must exactly match the version.

      Note: this method cannot return a non-native datastream.

      Parameters:
      format - native datastream format (.e.g, "oai_dc")
      version - version (e.g., "v1.01")
      Returns:
      The nativeDataStream value
    • getDataStream

      public org.dom4j.Element getDataStream(String format)
      Gets the dataStream of the NdrObjectReader for specified format.
      Parameters:
      format - datastream format (e.g., "nsdl_dc")
      Returns:
      The dataStream value
    • getDataStream

      public org.dom4j.Element getDataStream(String format, String version)
      Gets the dataStream matching the provided formatSpec, or null if requested stream is not present. Examples of formatSpec:
      • "nsdl_dc"
      • "native_nsdl_dc", "v1.02"
      • "native_msp2"
      Parameters:
      format - datastream format (e.g., "nsdl_dc")
      version - version (e.g., "v1.01")
      Returns:
      The dataStream value
    • getCanonicalNsdlDcDataStream

      public org.dom4j.Element getCanonicalNsdlDcDataStream()
      Returns the NON_NATIVE data stream labeled simply as "nsdl_dc" with no version
      Returns:
      The canonicalNsdlDcDataStream value
    • getNodes

      protected List getNodes(String path)
      Get all Nodes satisfying the given xpath.
      Parameters:
      path - NOT YET DOCUMENTED
      Returns:
      a List of all nodes satisfying given XPath, or null if path does not exist.
    • getXPath

      protected org.dom4j.XPath getXPath(String path)
      Converts the provided xpath string into an XPath instance using the nsContext (see getNsContext())
      Parameters:
      path - string representation of an xpath
      Returns:
      The xPath value
    • getNode

      protected org.dom4j.Node getNode(String xpath)
      Gets a single Node satisfying give XPath. If more than one Node is found, the first is returned (and a msg is printed).
      Parameters:
      xpath - an XPath
      Returns:
      a dom4j Node
    • getNodeText

      protected String getNodeText(String xpath)
      Return the Text of a Node satisfying the given XPath.
      Parameters:
      xpath - an XPath
      Returns:
      Text of Node or empty String if no Node is found
    • setDebug

      public static void setDebug(boolean bool)
      Sets the debug attribute of the NdrObjectReader class
      Parameters:
      bool - The new debug value
    • pp

      protected static void pp(org.dom4j.Node node)
      Prints a dom4j.Node as formatted string.
      Parameters:
      node - NOT YET DOCUMENTED