edu.ucsb.nceas.metacat.util

## Class DocumentUtil

- java.lang.Object
- - edu.ucsb.nceas.metacat.util.DocumentUtil

-     public class DocumentUtil
      extends java.lang.Object

  A suite of utility classes for the metadata catalog server

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static AbstractDatabase` | `dbAdapter`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `DocumentUtil()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static java.lang.String` | `appendRev(java.lang.String docid)` If the given docid only have one seperter, we need append rev for it.
    `static java.lang.String` | `generateDocumentId(int revision)` Create a unique docid for use in inserts and updates using the default prefix from the document.accNumPrefix property.
    `static java.lang.String` | `generateDocumentId(java.lang.String idPrefix, int revision)` Create a unique docid for use in inserts and updates using the prefix that is provided.
    `static java.lang.String` | `getAccessionNumberFromEcogridIdentifier(java.lang.String identifier)` Eocgorid identifier will look like: ecogrid://knb/tao.1.1 The AccessionNumber tao.1.1 will be returned.
    `static java.lang.String` | `getDocIdFromAccessionNumber(java.lang.String accessionNumber)` This method will get docid from an AccessionNumber.
    `static java.lang.String` | `getDocIdFromInlineDataID(java.lang.String inlineDataID)` Method to get docidwithrev from eml2 inline data id The eml inline data id would look like eml.200.2.3
    `static java.lang.String` | `getDocIdFromString(java.lang.String str)` Utility method to get docid from a given string
    `static java.lang.String` | `getDocIdWithRevFromOnlineURL(java.lang.String url)` Get docid from online/url string
    `static java.lang.String` | `getInlineDataIdWithoutRev(java.lang.String accessionNumber)` This method will get inline data id without the revision number.
    `static int` | `getRevisionFromAccessionNumber(java.lang.String accessionNumber)` This method will get revision from an AccessionNumber.
    `static java.lang.String` | `getRevisionStringFromString(java.lang.String str)` Utility method to get version string from a given string
    `static java.lang.String` | `getSmartDocId(java.lang.String str)` This method will call both getDocIdFromString and getDocIdFromAccessionNumber.
    `static int` | `getVersionFromString(java.lang.String str)` Utility method to get version number from a given string
    `static void` | `isAuthorized(java.io.PrintWriter out, java.util.Hashtable<java.lang.String,java.lang.String[]> params, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)`
    `static java.util.Stack<NodeRecord>` | `reviseStack(java.util.Stack<NodeRecord> stack)` Revise stack change a stack to opposite order

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

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

- - ### Field Detail

    - #### dbAdapter

          public static AbstractDatabase dbAdapter

  - ### Constructor Detail

    - #### DocumentUtil

          public DocumentUtil()

  - ### Method Detail

    - #### getDocIdWithRevFromOnlineURL

          public static java.lang.String getDocIdWithRevFromOnlineURL(java.lang.String url)

      Get docid from online/url string

    - #### getAccessionNumberFromEcogridIdentifier

          public static java.lang.String getAccessionNumberFromEcogridIdentifier(java.lang.String identifier)

      Eocgorid identifier will look like: ecogrid://knb/tao.1.1 The AccessionNumber tao.1.1 will be returned. If the given doesn't contains ecogrid, null will be returned.
      Parameters:
        `identifier` - String
      Returns:
        String

    - #### getDocIdFromString

          public static java.lang.String getDocIdFromString(java.lang.String str)

      Utility method to get docid from a given string
      Parameters:
        `string,` - the given string should be these two format: 1) str1.str2 in this case docid= str1.str2 2) str1.str2.str3, in this case docid =str1.str2
        `the` - sperator char

    - #### getVersionFromString

          public static int getVersionFromString(java.lang.String str)
                                          throws java.lang.NumberFormatException

      Utility method to get version number from a given string
      Parameters:
        `string,` - the given string should be these two format: 1) str1.str2(no version) version =-1; 2) str1.str2.str3, in this case version = str3; 3) other, vresion =-2
      Throws:
        `java.lang.NumberFormatException`

    - #### getRevisionStringFromString

          public static java.lang.String getRevisionStringFromString(java.lang.String str)
                                                              throws java.lang.NumberFormatException

      Utility method to get version string from a given string
      Parameters:
        `string,` - the given string should be these two format: 1) str1.str2(no version) version=null; 2) str1.str2.str3, in this case version = str3; 3) other, vresion =null;
      Throws:
        `java.lang.NumberFormatException`

    - #### appendRev

          public static java.lang.String appendRev(java.lang.String docid)
                                            throws edu.ucsb.nceas.utilities.PropertyNotFoundException,
                                                   java.sql.SQLException,
                                                   McdbDocNotFoundException

      If the given docid only have one seperter, we need append rev for it. The rev come from xml_documents
      Throws:
        `edu.ucsb.nceas.utilities.PropertyNotFoundException`
        `java.sql.SQLException`
        `McdbDocNotFoundException`

    - #### getDocIdFromAccessionNumber

          public static java.lang.String getDocIdFromAccessionNumber(java.lang.String accessionNumber)

      This method will get docid from an AccessionNumber. There is no assumption the accessnumber will be str1.str2.str3. It can be more. So we think the docid will be get rid of last part

    - #### getInlineDataIdWithoutRev

          public static java.lang.String getInlineDataIdWithoutRev(java.lang.String accessionNumber)

      This method will get inline data id without the revision number. So if inlineData.1.2 is passed as input, inlineData.2 is returned.

    - #### getSmartDocId

          public static java.lang.String getSmartDocId(java.lang.String str)

      This method will call both getDocIdFromString and getDocIdFromAccessionNumber. So first, if the string looks str1.str2, the docid will be str1.str2. If the string is str1.str2.str3, the docid will be str1.str2. If the string is str1.str2.str3.str4 or more, the docid will be str1.str2.str3. If the string look like str1, null will be returned

    - #### getRevisionFromAccessionNumber

          public static int getRevisionFromAccessionNumber(java.lang.String accessionNumber)
                                                    throws java.lang.NumberFormatException

      This method will get revision from an AccessionNumber. There is no assumption the accessnumber will be str1.str2.str3. It can be more. So we think the docid will be get rid of last part
      Throws:
        `java.lang.NumberFormatException`

    - #### getDocIdFromInlineDataID

          public static java.lang.String getDocIdFromInlineDataID(java.lang.String inlineDataID)

      Method to get docidwithrev from eml2 inline data id The eml inline data id would look like eml.200.2.3

    - #### reviseStack

          public static java.util.Stack<NodeRecord> reviseStack(java.util.Stack<NodeRecord> stack)

      Revise stack change a stack to opposite order

    - #### isAuthorized

          public static void isAuthorized(java.io.PrintWriter out,
                                          java.util.Hashtable<java.lang.String,java.lang.String[]> params,
                                          javax.servlet.http.HttpServletRequest request,
                                          javax.servlet.http.HttpServletResponse response)
                                   throws MetacatUtilException

      Throws:
        `MetacatUtilException`

    - #### generateDocumentId

          public static java.lang.String generateDocumentId(int revision)

      Create a unique docid for use in inserts and updates using the default prefix from the document.accNumPrefix property. Does not include the 'revision' part of the id if revision is '0', otherwise sets the revision number to 'revision'.
      Parameters:
        `idPrefix` - the prefix to be used to construct the scope portion of the docid
        `revision` - the integer revision to use for this docid
      Returns:
        a String docid based on the current date and time

    - #### generateDocumentId

          public static java.lang.String generateDocumentId(java.lang.String idPrefix,
                                                            int revision)

      Create a unique docid for use in inserts and updates using the prefix that is provided. Does not include the 'revision' part of the id if revision is '0', otherwise sets the revision number to 'revision'.
      Parameters:
        `idPrefix` - the prefix to be used to construct the scope portion of the docid
        `revision` - the integer revision to use for this docid
      Returns:
        a String docid based on the current date and time

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