Class DocumentImpl

java.lang.Object
edu.ucsb.nceas.metacat.DocumentImpl

public class DocumentImpl extends Object
A class that represents an XML document. It can be created with a simple document identifier from a database connection. It also will write an XML text document to a database connection using SAX.
  • Field Details

  • Constructor Details

    • DocumentImpl

      public DocumentImpl()
      Default constructor
    • DocumentImpl

      public DocumentImpl(String accNum, boolean readNodes) throws McdbException
      Constructor used to create a document and read the document information from the database. If readNodes is false, then the node data is not read at this time, but is deferred until it is needed (such as when a call to toXml() is made).
      Parameters:
      conn - the database connection from which to read the document
      readNodes - flag indicating whether the xmlnodes should be read
      Throws:
      McdbException
    • DocumentImpl

      public DocumentImpl(String docid) throws McdbException
      Constructor, creates document from database connection, used for reading the document
      Parameters:
      conn - the database connection from which to read the document
      docid - the identifier of the document to be created
      Throws:
      McdbException
  • Method Details

    • registerDocument

      public static void registerDocument(String docname, String doctype, DBConnection conn, String accnum, String user) throws SQLException, AccessionNumberException, edu.ucsb.nceas.utilities.PropertyNotFoundException, MetacatException
      Register a document that resides on the filesystem with the database. (ie, just an entry in xml_documents). Creates a reference to a filesystem document (used for non-xml data files).
      Parameters:
      docname - - the name of DTD, i.e. the name immediately following the DOCTYPE keyword ( should be the root element name ) or the root element name if no DOCTYPE declaration provided (Oracle's and IBM parsers are not aware if it is not the root element name)
      doctype - - Public ID of the DTD, i.e. the name immediately following the PUBLIC keyword in DOCTYPE declaration or the docname if no Public ID provided or null if no DOCTYPE declaration provided
      conn - the connection to database
      accnum - the accession number to use for the INSERT OR UPDATE, which includes a revision number for this revision of the document (e.g., knb.1.1)
      user - the user that owns the document
      Throws:
      SQLException
      AccessionNumberException
      MetacatException
      edu.ucsb.nceas.utilities.PropertyNotFoundException
    • getDocname

      public String getDocname()
      get the document name
    • getDoctype

      public String getDoctype()
      get the document type (which is the PublicID)
    • getSystemID

      public String getSystemID()
      get the system identifier
    • getRootNodeID

      public long getRootNodeID()
      get the root node identifier
    • getCreateDate

      public Date getCreateDate()
      get the creation date
    • getUpdateDate

      public Date getUpdateDate()
      get the update date
    • getDocID

      public String getDocID()
      Get the document identifier (docid)
    • getUserowner

      public String getUserowner()
    • getUserupdated

      public String getUserupdated()
    • getRev

      public int getRev()
    • getValidateType

      public String getValidateType()
    • toString

      public String toString()
      Print a string representation of the XML document NOTE: this detects the character encoding, or uses the XML default
      Overrides:
      toString in class Object
    • toXml

      public InputStream toXml(OutputStream out, String user, String[] groups, boolean withInLineData) throws McdbException
      Print a text representation of the XML document to a Writer
      Parameters:
      pw - the Writer to which we print the document Now we decide no matter withinInlineData's value, the document will
      Throws:
      McdbException
    • readFromFileSystem

      public InputStream readFromFileSystem(OutputStream out, String user, String[] groups, String documentPath) throws McdbException
      Read the XML document from the file system and write to a Writer. Strip out any inline data that the user does not have permission to read.
      Parameters:
      pw - the Writer to which we print the document
      user - the user we will use to verify inline data access
      groups - the groups we will use to verify inline data access
      documentPath - the location of the document on disk
      Throws:
      McdbException
    • deleteFromFileSystem

      public static void deleteFromFileSystem(String accNumber, boolean isXml) throws McdbException
      Deletes a doc or data file from the filesystem using the accession number.
      Parameters:
      accNumber -
      isXml -
      Throws:
      McdbException
    • delete

      public static void delete(String accnum, org.dataone.service.types.v1.Identifier guid) throws SQLException, org.dataone.service.exceptions.InvalidRequest, McdbDocNotFoundException, org.dataone.service.exceptions.ServiceFailure
      Delete an object totally from the db and file system. It doesn't check permission
      Parameters:
      accnum - the local id (including the rev) will be deleted
      guid - the dataone identifier associated with accnum
      Throws:
      SQLException
      org.dataone.service.exceptions.InvalidRequest
      McdbDocNotFoundException
      org.dataone.service.exceptions.ServiceFailure
    • archive

      public static void archive(String accnum, org.dataone.service.types.v1.Identifier guid, String user, boolean changeDateModified, SystemMetadataManager.SysMetaVersion sysMetaCheck) throws SQLException, org.dataone.service.exceptions.InvalidRequest, org.dataone.service.exceptions.ServiceFailure
      Archive an object. Set the archived flag true, also move the object from the xml_documents table to the xml_revisions table if it exists in the xml_documents table. This method will submit the reindex task as well.
      Parameters:
      accnum - the local id (including the revision) will be applied.
      guid - the dataone identifier associated with the given accnum
      user - the identity of operator
      changeDateModified - if it needs to change the dateModified field in the system metadata
      sysMetaCheck - check whether the version of the provided '@param sysMeta' matches the version of the existing system metadata
      Throws:
      SQLException
      org.dataone.service.exceptions.InvalidRequest
      org.dataone.service.exceptions.ServiceFailure
    • hasWritePermission

      public static boolean hasWritePermission(String user, String[] groups, String docid) throws SQLException, Exception
      Check for "WRITE" permission on @docid for @user and/or @groups from DB connection
      Throws:
      SQLException
      Exception
    • hasAllPermission

      public static boolean hasAllPermission(String user, String[] groups, String docid) throws SQLException, Exception
      Check for "ALL" or "CHMOD" permission on @docid for @user and/or @groups from DB connection
      Throws:
      SQLException
      Exception
    • initializeParser

      public static XMLReader initializeParser(Vector<XMLSchema> schemaList, Reader dtd, String ruleBase, boolean needValidation, String schemaLocation) throws org.dataone.service.exceptions.ServiceFailure, edu.ucsb.nceas.utilities.PropertyNotFoundException, SAXException
      Set up the parser handlers for writing the document to the database
      Parameters:
      schemaList - the list of schema will be used
      dtd - the dtd content
      ruleBase - the validation base - schema or dtd
      needValidation - if the document needs to be validated
      schemaLocation - the string contains the schema location
      Returns:
      the XMLReader object
      Throws:
      edu.ucsb.nceas.utilities.PropertyNotFoundException
      SAXException
      org.dataone.service.exceptions.ServiceFailure