edu.ucsb.nceas.metacat

## Class DocumentImpl

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

-     public class DocumentImpl
      extends java.lang.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 Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static java.lang.String` | `BIN`
    `protected DBConnection` | `connection`
    `static java.lang.String` | `DECLARATIONHANDLERPROPERTY`
    `protected java.lang.String` | `docid`
    `protected java.lang.String` | `docname`
    `static java.lang.String` | `DOCNAME`
    `protected java.lang.String` | `doctype`
    `static java.lang.String` | `DOCUMENTTABLE`
    `static java.lang.String` | `DTD`
    `static java.lang.String` | `EML2_0_0NAMESPACE`
    `static java.lang.String` | `EML2_0_1NAMESPACE`
    `static java.lang.String` | `EML2_1_0NAMESPACE`
    `static java.lang.String` | `EML2_1_1NAMESPACE`
    `static java.lang.String` | `EML2_2_0NAMESPACE`
    `static java.lang.String` | `EML200`
    `static java.lang.String` | `EML210`
    `static java.lang.String` | `EXTERNALNONAMESPACESCHEMALOCATIONPROPERTY`
    `static java.lang.String` | `EXTERNALSCHEMALOCATIONPROPERTY`
    `static java.lang.String` | `FULLSCHEMAVALIDATIONFEATURE`
    `static java.lang.String` | `LEXICALPROPERTY`
    `static java.lang.String` | `NAMESPACEFEATURE`
    `static java.lang.String` | `NAMESPACEPREFIXESFEATURE`
    `static java.lang.String` | `NONAMESPACESCHEMA`
    `static java.lang.String` | `PUBLICID`
    `static java.lang.String` | `RDF_SYNTAX_NAMESPACE`
    `static java.lang.String` | `REVISIONTABLE`
    `protected long` | `rootnodeid`
    `static java.lang.String` | `SCHEMA`
    `static java.lang.String` | `SCHEMAVALIDATIONFEATURE`
    `static java.lang.String` | `SYSTEMID`
    `static java.lang.String` | `VALIDATIONFEATURE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `DocumentImpl()` Default constructor
    `DocumentImpl(DBConnection conn, long rootNodeId, java.lang.String docName, java.lang.String docType, java.lang.String docId, java.lang.String newRevision, java.lang.String action, java.lang.String user, java.lang.String pub, java.lang.String catalogId, int serverCode, java.util.Date createDate, java.util.Date updateDate)` Construct a new document instance, writing the contents to the database.
    `DocumentImpl(java.lang.String docid)` Constructor, creates document from database connection, used for reading the document
    `DocumentImpl(java.lang.String accNum, boolean readNodes)` Constructor used to create a document and read the document information from the database.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `buildIndex()` Build the index records for this document.
    `static void` | `delete(java.lang.String accnum, boolean ignoreRev, java.lang.String user, java.lang.String[] groups, java.lang.String notifyServer, boolean removeAll)` Archive an object from the xml_documents table to the xml_revision table (including other changes as well).
    `static void` | `delete(java.lang.String accnum, java.lang.String user, java.lang.String[] groups, java.lang.String notifyServer, boolean removeAll)` Archive an object from the xml_documents table to the xml_revision table (including other changes as well).
    `static void` | `deleteFromFileSystem(java.lang.String accNumber, boolean isXml)` Deletes a doc or data file from the filesystem using the accession number.
    `byte[]` | `getBytes()`
    `java.util.Date` | `getCreateDate()` get the creation date
    `static boolean` | `getDataFileLockGrant(java.lang.String accnum)` Get a lock for a given document.
    `static boolean` | `getDataFileLockGrant(java.lang.String accnum, int serverCode)` The method will check if metacat can get data file lock grant If server code is 1, it get.
    `java.lang.String` | `getDocHomeServer()`
    `java.lang.String` | `getDocID()` Get the document identifier (docid)
    `java.lang.String` | `getDocname()` get the document name
    `java.lang.String` | `getDoctype()` get the document type (which is the PublicID)
    `java.lang.String` | `getPublicaccess()`
    `int` | `getRev()`
    `long` | `getRootNodeID()` get the root node identifier
    `static int` | `getServerCode(java.lang.String serverName)` Given a server name, return its servercode in xml_replication table.
    `int` | `getServerlocation()`
    `java.lang.String` | `getSystemID()` get the system identifier
    `java.util.Date` | `getUpdateDate()` get the update date
    `java.lang.String` | `getUserowner()`
    `java.lang.String` | `getUserupdated()`
    `java.lang.String` | `getValidateType()`
    `static boolean` | `hasAllPermission(java.lang.String user, java.lang.String[] groups, java.lang.String docid)` Check for "ALL" or "CHMOD" permission on @docid for @user and/or @groups from DB connection
    `static boolean` | `hasReadPermission(java.lang.String user, java.lang.String[] groups, java.lang.String docId)` Check for "READ" permission base on docid, user and group
    `static boolean` | `hasWritePermission(java.lang.String user, java.lang.String[] groups, java.lang.String docid)` Check for "WRITE" permission on @docid for @user and/or @groups from DB connection
    `static void` | `main(java.lang.String[] args)` the main routine used to test the DBWriter utility.
    `java.io.InputStream` | `readFromFileSystem(java.io.OutputStream out, java.lang.String user, java.lang.String[] groups, java.lang.String documentPath)` Read the XML document from the file system and write to a Writer.
    `java.lang.String` | `readUsingSlowAlgorithm()` Get a text representation of the XML document as a string This older algorithm uses a recursive tree of Objects to represent the nodes of the tree.
    `static void` | `registerDocument(java.lang.String docname, java.lang.String doctype, java.lang.String accnum, java.lang.String user, java.lang.String[] groupnames)` This method will be call in handleUploadRequest in MetacatServlet class
    `static void` | `registerDocument(java.lang.String docname, java.lang.String doctype, java.lang.String accnum, java.lang.String user, java.lang.String[] groups, int serverCode)` Register a document that resides on the filesystem with the database.
    `static void` | `registerDocumentInReplication(java.lang.String docname, java.lang.String doctype, java.lang.String accnum, java.lang.String user, int serverCode, java.lang.String tableName, java.util.Date createDate, java.util.Date updateDate)` Register a document that resides on the filesystem with the database.
    `java.lang.String` | `toString()` Print a string representation of the XML document NOTE: this detects the character encoding, or uses the XML default
    `java.lang.String` | `toString(java.lang.String user, java.lang.String[] groups, boolean withInlinedata)` Print a string representation of the XML document NOTE: this detects the character encoding, or uses the XML default
    `java.io.InputStream` | `toXml(java.io.OutputStream out, java.lang.String user, java.lang.String[] groups, boolean withInLineData)` Print a text representation of the XML document to a Writer
    `void` | `toXmlFromDb(java.io.OutputStream outputStream, java.lang.String user, java.lang.String[] groups, boolean withInLineData)` Print a text representation of the XML document to a Writer
    `static java.lang.String` | `write(DBConnection conn, java.lang.String xmlString, java.lang.String pub, java.io.Reader dtd, java.lang.String action, java.lang.String accnum, java.lang.String user, java.lang.String[] groups, int serverCode, boolean override, java.lang.String ruleBase, boolean needValidation, boolean writeAccessRules, byte[] xmlBytes, java.lang.String schemaLocation, org.dataone.service.types.v1.Checksum checksum, java.io.File objectFile)` Write an XML file to the database, given a Reader
    `static java.lang.String` | `write(DBConnection conn, java.lang.String xmlString, java.lang.String pub, java.io.Reader dtd, java.lang.String action, java.lang.String docid, java.lang.String user, java.lang.String[] groups, java.lang.String ruleBase, boolean needValidation, boolean writeAccessRules, byte[] xmlBytes, java.lang.String schemaLocation, org.dataone.service.types.v1.Checksum checksum, java.io.File objectFile)` Write an XML file to the database, given a filename
    `static void` | `writeDataFileInReplication(java.io.InputStream input, java.lang.String filePath, java.lang.String docname, java.lang.String doctype, java.lang.String accnum, java.lang.String user, java.lang.String docHomeServer, java.lang.String notificationServer, java.lang.String tableName, boolean timedReplication, java.util.Date createDate, java.util.Date updateDate)` This method will register a data file entry in xml_documents and save a data file input Stream into file system..
    `static java.lang.String` | `writeReplication(DBConnection conn, java.lang.String xmlString, byte[] xmlBytes, java.lang.String pub, java.io.Reader dtd, java.lang.String action, java.lang.String accnum, java.lang.String user, java.lang.String[] groups, java.lang.String homeServer, java.lang.String notifyServer, java.lang.String ruleBase, boolean needValidation, java.lang.String tableName, boolean timedReplication, java.util.Date createDate, java.util.Date updateDate, java.lang.String schemaLocation)` Write an XML file to the database during replication

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### SCHEMA

          public static final java.lang.String SCHEMA

      See Also:
        Constant Field Values

    - #### NONAMESPACESCHEMA

          public static final java.lang.String NONAMESPACESCHEMA

      See Also:
        Constant Field Values

    - #### DTD

          public static final java.lang.String DTD

      See Also:
        Constant Field Values

    - #### EML200

          public static final java.lang.String EML200

      See Also:
        Constant Field Values

    - #### EML210

          public static final java.lang.String EML210

      See Also:
        Constant Field Values

    - #### EXTERNALSCHEMALOCATIONPROPERTY

          public static final java.lang.String EXTERNALSCHEMALOCATIONPROPERTY

      See Also:
        Constant Field Values

    - #### EXTERNALNONAMESPACESCHEMALOCATIONPROPERTY

          public static final java.lang.String EXTERNALNONAMESPACESCHEMALOCATIONPROPERTY

      See Also:
        Constant Field Values

    - #### REVISIONTABLE

          public static final java.lang.String REVISIONTABLE

      See Also:
        Constant Field Values

    - #### DOCUMENTTABLE

          public static final java.lang.String DOCUMENTTABLE

      See Also:
        Constant Field Values

    - #### BIN

          public static final java.lang.String BIN

      See Also:
        Constant Field Values

    - #### DECLARATIONHANDLERPROPERTY

          public static final java.lang.String DECLARATIONHANDLERPROPERTY

      See Also:
        Constant Field Values

    - #### LEXICALPROPERTY

          public static final java.lang.String LEXICALPROPERTY

      See Also:
        Constant Field Values

    - #### VALIDATIONFEATURE

          public static final java.lang.String VALIDATIONFEATURE

      See Also:
        Constant Field Values

    - #### SCHEMAVALIDATIONFEATURE

          public static final java.lang.String SCHEMAVALIDATIONFEATURE

      See Also:
        Constant Field Values

    - #### FULLSCHEMAVALIDATIONFEATURE

          public static final java.lang.String FULLSCHEMAVALIDATIONFEATURE

      See Also:
        Constant Field Values

    - #### NAMESPACEFEATURE

          public static final java.lang.String NAMESPACEFEATURE

      See Also:
        Constant Field Values

    - #### NAMESPACEPREFIXESFEATURE

          public static final java.lang.String NAMESPACEPREFIXESFEATURE

      See Also:
        Constant Field Values

    - #### EML2_0_0NAMESPACE

          public static final java.lang.String EML2_0_0NAMESPACE

    - #### EML2_0_1NAMESPACE

          public static final java.lang.String EML2_0_1NAMESPACE

    - #### EML2_1_0NAMESPACE

          public static final java.lang.String EML2_1_0NAMESPACE

    - #### EML2_1_1NAMESPACE

          public static final java.lang.String EML2_1_1NAMESPACE

    - #### EML2_2_0NAMESPACE

          public static final java.lang.String EML2_2_0NAMESPACE

    - #### RDF_SYNTAX_NAMESPACE

          public static final java.lang.String RDF_SYNTAX_NAMESPACE

    - #### DOCNAME

          public static final java.lang.String DOCNAME

      See Also:
        Constant Field Values

    - #### PUBLICID

          public static final java.lang.String PUBLICID

      See Also:
        Constant Field Values

    - #### SYSTEMID

          public static final java.lang.String SYSTEMID

      See Also:
        Constant Field Values

    - #### connection

          protected DBConnection connection

    - #### docname

          protected java.lang.String docname

    - #### doctype

          protected java.lang.String doctype

    - #### docid

          protected java.lang.String docid

    - #### rootnodeid

          protected long rootnodeid

  - ### Constructor Detail

    - #### DocumentImpl

          public DocumentImpl()

      Default constructor

    - #### DocumentImpl

          public DocumentImpl(java.lang.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
        `docid` - the identifier of the document to be created, it should be with revision
        `readNodes` - flag indicating whether the xmlnodes should be read
      Throws:
        `McdbException`

    - #### DocumentImpl

          public DocumentImpl(java.lang.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`

    - #### DocumentImpl

          public DocumentImpl(DBConnection conn,
                              long rootNodeId,
                              java.lang.String docName,
                              java.lang.String docType,
                              java.lang.String docId,
                              java.lang.String newRevision,
                              java.lang.String action,
                              java.lang.String user,
                              java.lang.String pub,
                              java.lang.String catalogId,
                              int serverCode,
                              java.util.Date createDate,
                              java.util.Date updateDate)
                       throws java.sql.SQLException,
                              java.lang.Exception

      Construct a new document instance, writing the contents to the database. This method is called from DBSAXHandler because we need to know the root element name for documents without a DOCTYPE before creating it. In this constructor, the docid is without rev. There is a string rev to specify the revision user want to upadate. The revion is only need to be greater than current one. It is not need to be sequent number just after current one. So it is only used in update action
      Parameters:
        `conn` - the JDBC Connection to which all information is written
        `rootnodeid` - - sequence id of the root node in the document
        `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
        `docid` - the docid to use for the UPDATE, no version number
        `version,` - need to be update
        `action` - the action to be performed (INSERT OR UPDATE)
        `user` - the user that owns the document
        `pub` - flag for public "read" access on document
        `serverCode` - the serverid from xml_replication on which this document resides.
      Throws:
        `java.sql.SQLException`
        `java.lang.Exception`

  - ### Method Detail

    - #### registerDocument

          public static void registerDocument(java.lang.String docname,
                                              java.lang.String doctype,
                                              java.lang.String accnum,
                                              java.lang.String user,
                                              java.lang.String[] groupnames)
                                       throws java.sql.SQLException,
                                              AccessionNumberException,
                                              java.lang.Exception

      This method will be call in handleUploadRequest in MetacatServlet class
      Throws:
        `java.sql.SQLException`
        `AccessionNumberException`
        `java.lang.Exception`

    - #### registerDocument

          public static void registerDocument(java.lang.String docname,
                                              java.lang.String doctype,
                                              java.lang.String accnum,
                                              java.lang.String user,
                                              java.lang.String[] groups,
                                              int serverCode)
                                       throws java.sql.SQLException,
                                              AccessionNumberException,
                                              java.lang.Exception

      Register a document that resides on the filesystem with the database. (ie, just an entry in xml_documents, nothing in xml_nodes). Creates a reference to a filesystem document (used for non-xml data files). This class only be called in MetaCatServerlet.
      Parameters:
        `conn` - the JDBC Connection to which all information is written
        `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
        `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
        `groupnames` - the groups that owns the document
        `serverCode` - the serverid from xml_replication on which this document resides.
      Throws:
        `java.sql.SQLException`
        `AccessionNumberException`
        `java.lang.Exception`

    - #### registerDocumentInReplication

          public static void registerDocumentInReplication(java.lang.String docname,
                                                           java.lang.String doctype,
                                                           java.lang.String accnum,
                                                           java.lang.String user,
                                                           int serverCode,
                                                           java.lang.String tableName,
                                                           java.util.Date createDate,
                                                           java.util.Date updateDate)
                                                    throws java.sql.SQLException,
                                                           AccessionNumberException,
                                                           java.lang.Exception

      Register a document that resides on the filesystem with the database. (ie, just an entry in xml_documents, nothing in xml_nodes). Creates a reference to a filesystem document (used for non-xml data files) This method will be called for register data file in xml_documents in Replication. This method is revised from registerDocument.
      Parameters:
        `conn` - the JDBC Connection to which all information is written
        `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
        `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
        `serverCode` - the serverid from xml_replication on which this document resides.
      Throws:
        `java.sql.SQLException`
        `AccessionNumberException`
        `java.lang.Exception`

    - #### writeDataFileInReplication

          public static void writeDataFileInReplication(java.io.InputStream input,
                                                        java.lang.String filePath,
                                                        java.lang.String docname,
                                                        java.lang.String doctype,
                                                        java.lang.String accnum,
                                                        java.lang.String user,
                                                        java.lang.String docHomeServer,
                                                        java.lang.String notificationServer,
                                                        java.lang.String tableName,
                                                        boolean timedReplication,
                                                        java.util.Date createDate,
                                                        java.util.Date updateDate)
                                                 throws java.sql.SQLException,
                                                        AccessionNumberException,
                                                        java.lang.Exception

      This method will register a data file entry in xml_documents and save a data file input Stream into file system.. It is only used in replication
      Parameters:
        `input,` - the input stream which contain the file content.
        `,` - the input stream which contain the file content
        `docname` - - the name of DTD, for data file, it is a docid number.
        `doctype` - - "BIN" for data file
        `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
        `docHomeServer,` - the home server of the docid
        `notificationServer,` - the server to notify force replication info to local metacat
      Throws:
        `java.sql.SQLException`
        `AccessionNumberException`
        `java.lang.Exception`

    - #### getDataFileLockGrant

          public static boolean getDataFileLockGrant(java.lang.String accnum)
                                              throws java.lang.Exception

      Get a lock for a given document.
      Throws:
        `java.lang.Exception`

    - #### getDataFileLockGrant

          public static boolean getDataFileLockGrant(java.lang.String accnum,
                                                     int serverCode)
                                              throws java.lang.Exception

      The method will check if metacat can get data file lock grant If server code is 1, it get. If server code is not 1 but call replication getlock successfully, it get else, it didn't get
      Parameters:
        `accnum,` - the ID of the document
        `action,` - the action to the document
        `serverCode,` - the server location code
      Throws:
        `java.lang.Exception`

    - #### getDocname

          public java.lang.String getDocname()

      get the document name

    - #### getDoctype

          public java.lang.String getDoctype()

      get the document type (which is the PublicID)

    - #### getSystemID

          public java.lang.String getSystemID()

      get the system identifier

    - #### getRootNodeID

          public long getRootNodeID()

      get the root node identifier

    - #### getCreateDate

          public java.util.Date getCreateDate()

      get the creation date

    - #### getUpdateDate

          public java.util.Date getUpdateDate()

      get the update date

    - #### getDocID

          public java.lang.String getDocID()

      Get the document identifier (docid)

    - #### getUserowner

          public java.lang.String getUserowner()

    - #### getUserupdated

          public java.lang.String getUserupdated()

    - #### getServerlocation

          public int getServerlocation()

    - #### getDocHomeServer

          public java.lang.String getDocHomeServer()

    - #### getPublicaccess

          public java.lang.String getPublicaccess()

    - #### getRev

          public int getRev()

    - #### getValidateType

          public java.lang.String getValidateType()

    - #### toString

          public java.lang.String toString(java.lang.String user,
                                           java.lang.String[] groups,
                                           boolean withInlinedata)

      Print a string representation of the XML document NOTE: this detects the character encoding, or uses the XML default

    - #### toString

          public java.lang.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 `java.lang.Object`

    - #### getBytes

          public byte[] getBytes()

    - #### readUsingSlowAlgorithm

          public java.lang.String readUsingSlowAlgorithm()
                                                  throws McdbException

      Get a text representation of the XML document as a string This older algorithm uses a recursive tree of Objects to represent the nodes of the tree. Each object is passed the data for the document and searches all of the document data to find its children nodes and recursively build. Thus, because each node reads the whole document, this algorithm is extremely slow for larger documents, and the time to completion is O(N^N) wrt the number of nodes. See toXml() for a better algorithm.
      Throws:
        `McdbException`

    - #### toXml

          public java.io.InputStream toXml(java.io.OutputStream out,
                                           java.lang.String user,
                                           java.lang.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`

    - #### toXmlFromDb

          public void toXmlFromDb(java.io.OutputStream outputStream,
                                  java.lang.String user,
                                  java.lang.String[] groups,
                                  boolean withInLineData)
                           throws McdbException,
                                  java.io.IOException

      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`
        `java.io.IOException`

    - #### readFromFileSystem

          public java.io.InputStream readFromFileSystem(java.io.OutputStream out,
                                                        java.lang.String user,
                                                        java.lang.String[] groups,
                                                        java.lang.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(java.lang.String accNumber,
                                                  boolean isXml)
                                           throws McdbException

      Deletes a doc or data file from the filesystem using the accession number.
      Parameters:
        `accNumber` -
        `isXml` -
      Throws:
        `McdbException`

    - #### buildIndex

          public void buildIndex()
                          throws McdbException

      Build the index records for this document. For each node, all absolute and relative paths to the root of the document are created and inserted into the xml_index table. This requires that the DocumentImpl instance exists, so first call the constructor that reads the document from the database.
      Throws:
        `McdbException` - on error getting the node records for the document

    - #### write

          public static java.lang.String write(DBConnection conn,
                                               java.lang.String xmlString,
                                               java.lang.String pub,
                                               java.io.Reader dtd,
                                               java.lang.String action,
                                               java.lang.String docid,
                                               java.lang.String user,
                                               java.lang.String[] groups,
                                               java.lang.String ruleBase,
                                               boolean needValidation,
                                               boolean writeAccessRules,
                                               byte[] xmlBytes,
                                               java.lang.String schemaLocation,
                                               org.dataone.service.types.v1.Checksum checksum,
                                               java.io.File objectFile)
                                        throws java.lang.Exception

      Write an XML file to the database, given a filename
      Parameters:
        `conn` - the JDBC connection to the database
        `filename` - the filename to be loaded into the database
        `pub` - flag for public "read" access on document
        `dtdfilename` - the dtd to be uploaded on server's file system
        `action` - the action to be performed (INSERT OR UPDATE)
        `docid` - the docid to use for the INSERT OR UPDATE
        `user` - the user that owns the document
        `groups` - the groups to which user belongs
        `writeAccessRules` -
      Throws:
        `java.lang.Exception`

    - #### write

          public static java.lang.String write(DBConnection conn,
                                               java.lang.String xmlString,
                                               java.lang.String pub,
                                               java.io.Reader dtd,
                                               java.lang.String action,
                                               java.lang.String accnum,
                                               java.lang.String user,
                                               java.lang.String[] groups,
                                               int serverCode,
                                               boolean override,
                                               java.lang.String ruleBase,
                                               boolean needValidation,
                                               boolean writeAccessRules,
                                               byte[] xmlBytes,
                                               java.lang.String schemaLocation,
                                               org.dataone.service.types.v1.Checksum checksum,
                                               java.io.File objectFile)
                                        throws java.lang.Exception

      Write an XML file to the database, given a Reader
      Parameters:
        `conn` - the JDBC connection to the database
        `xml` - the xml stream to be loaded into the database
        `pub` - flag for public "read" access on xml document
        `dtd` - the dtd to be uploaded on server's file system
        `action` - the action to be performed (INSERT or UPDATE)
        `accnum` - the docid + rev# to use on INSERT or UPDATE
        `user` - the user that owns the document
        `groups` - the groups to which user belongs
        `serverCode` - the serverid from xml_replication on which this document resides.
        `override` - flag to stop insert replication checking. if override = true then a document not belonging to the local server will not be checked upon update for a file lock. if override = false then a document not from this server, upon update will be locked and version checked.
        `writeAccessRules` -
      Throws:
        `java.lang.Exception`

    - #### writeReplication

          public static java.lang.String writeReplication(DBConnection conn,
                                                          java.lang.String xmlString,
                                                          byte[] xmlBytes,
                                                          java.lang.String pub,
                                                          java.io.Reader dtd,
                                                          java.lang.String action,
                                                          java.lang.String accnum,
                                                          java.lang.String user,
                                                          java.lang.String[] groups,
                                                          java.lang.String homeServer,
                                                          java.lang.String notifyServer,
                                                          java.lang.String ruleBase,
                                                          boolean needValidation,
                                                          java.lang.String tableName,
                                                          boolean timedReplication,
                                                          java.util.Date createDate,
                                                          java.util.Date updateDate,
                                                          java.lang.String schemaLocation)
                                                   throws java.lang.Exception

      Write an XML file to the database during replication
      Parameters:
        `conn` - the JDBC connection to the database
        `xml` - the xml stream to be loaded into the database
        `pub` - flag for public "read" access on xml document
        `dtd` - the dtd to be uploaded on server's file system
        `action` - the action to be performed (INSERT or UPDATE)
        `accnum` - the docid + rev# to use on INSERT or UPDATE
        `user` - the user that owns the document
        `groups` - the groups to which user belongs
        `homeServer` - the name of server which the document origanlly create
        `validate,` - if the xml document is valid or not
        `notifyServer,` - the server which notify local server the force replication command
      Throws:
        `java.lang.Exception`

    - #### delete

          public static void delete(java.lang.String accnum,
                                    java.lang.String user,
                                    java.lang.String[] groups,
                                    java.lang.String notifyServer,
                                    boolean removeAll)
                             throws java.sql.SQLException,
                                    InsufficientKarmaException,
                                    McdbDocNotFoundException,
                                    java.lang.Exception

      Archive an object from the xml_documents table to the xml_revision table (including other changes as well). Or delete an object totally from the db. The parameter "removeAll" decides which action will be taken.
      Parameters:
        `accnum` - the local id (including the rev) will be applied.
        `user` - the subject who does the action.
        `groups` - the groups which the user belongs to.
        `notifyServer` - the server will be notified in the replication. It can be null.
        `removeAll` - it will be the delete action if this is true; otherwise it will be the archive action
      Throws:
        `java.sql.SQLException`
        `InsufficientKarmaException`
        `McdbDocNotFoundException`
        `java.lang.Exception`

    - #### delete

          public static void delete(java.lang.String accnum,
                                    boolean ignoreRev,
                                    java.lang.String user,
                                    java.lang.String[] groups,
                                    java.lang.String notifyServer,
                                    boolean removeAll)
                             throws java.sql.SQLException,
                                    InsufficientKarmaException,
                                    McdbDocNotFoundException,
                                    java.lang.Exception

      Archive an object from the xml_documents table to the xml_revision table (including other changes as well). Or delete an object totally from the db. The parameter "removeAll" decides which action will be taken.
      Parameters:
        `accnum` - the local id (including the rev) will be applied.
        `ignoreRev` - if the archive action should only match docid and ignore the rev
        `user` - the subject who does the action.
        `groups` - the groups which the user belongs to.
        `notifyServer` - the server will be notified in the replication. It can be null.
        `removeAll` - it will be the delete action if this is true; otherwise it will be the archive action.
      Throws:
        `java.sql.SQLException`
        `InsufficientKarmaException`
        `McdbDocNotFoundException`
        `java.lang.Exception`

    - #### hasWritePermission

          public static boolean hasWritePermission(java.lang.String user,
                                                   java.lang.String[] groups,
                                                   java.lang.String docid)
                                            throws java.sql.SQLException,
                                                   java.lang.Exception

      Check for "WRITE" permission on @docid for @user and/or @groups from DB connection
      Throws:
        `java.sql.SQLException`
        `java.lang.Exception`

    - #### hasReadPermission

          public static boolean hasReadPermission(java.lang.String user,
                                                  java.lang.String[] groups,
                                                  java.lang.String docId)
                                           throws java.sql.SQLException,
                                                  McdbException

      Check for "READ" permission base on docid, user and group
      Parameters:
        `docid,` - the document
        `user,` - user name
        `groups,` - user's group
      Throws:
        `java.sql.SQLException`
        `McdbException`

    - #### hasAllPermission

          public static boolean hasAllPermission(java.lang.String user,
                                                 java.lang.String[] groups,
                                                 java.lang.String docid)
                                          throws java.sql.SQLException,
                                                 java.lang.Exception

      Check for "ALL" or "CHMOD" permission on @docid for @user and/or @groups from DB connection
      Throws:
        `java.sql.SQLException`
        `java.lang.Exception`

    - #### getServerCode

          public static int getServerCode(java.lang.String serverName)

      Given a server name, return its servercode in xml_replication table. If no server is found, -1 will return
      Parameters:
        `serverName,` -

    - #### main

          public static void main(java.lang.String[] args)

      the main routine used to test the DBWriter utility.

      Usage: java DocumentImpl <-f filename -a action -d docid>

      Parameters:
        `filename` - the filename to be loaded into the database
        `action` - the action to perform (READ, INSERT, UPDATE, DELETE)
        `docid` - the id of the document to process

Copyright © 2023 Regents of the University of California. All Rights Reserved.