edu.ucsb.nceas.metacat.clientview

## Class ClientViewHelper

- java.lang.Object
- - edu.ucsb.nceas.metacat.clientview.ClientViewHelper

-     public class ClientViewHelper
      extends java.lang.Object

  Author:
    barteau

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static java.lang.String` | `DOWNLOAD_ACTION`
    `static java.lang.String` | `PERMISSION_TYPE_ALLOW`
    `static java.lang.String` | `PERMISSION_TYPE_DISALLOW`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ClientViewHelper(javax.servlet.http.HttpServletRequest request)` Creates a new instance of ClientViewHelper, using info in an HttpServletRequest for initializing.
    `ClientViewHelper(java.lang.String host, java.lang.String context, ClientView bean)` Creates a new instance of ClientViewHelper, using parameter values for initializing.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `java.lang.String` | `clientRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)` Main web API method for handling various actions.
    `static ClientViewHelper` | `clientViewHelperInstance(javax.servlet.http.HttpServletRequest request)` This is a convenience method to reduce the amount of code in a Metacat Client.
    `MetacatClient` | `getMetacatClient()`
    `org.w3c.dom.Document` | `getMetadataDoc()`
    `static org.w3c.dom.Node` | `getNode(javax.xml.xpath.XPath xPath, java.lang.String expression, org.w3c.dom.Node root)`
    `static java.lang.String` | `getNodeText(javax.xml.xpath.XPath xPath, java.lang.String expression, org.w3c.dom.Node root)`
    `static java.lang.String[]` | `getNodeTextList(javax.xml.xpath.XPath xPath, java.lang.String expression, org.w3c.dom.Node root)`
    `static java.util.Stack` | `getNodeTextStack(javax.xml.xpath.XPath xpathInstance, java.lang.String xpathExpr, org.w3c.dom.Node parentNode)`
    `java.util.TreeMap` | `getSelectQueryMap()` Queries Metacat for document listings, and returns the results in a TreeMap, where the key is the Doc Id, and the value is the Create Date.
    `static java.lang.String` | `getStringFromInputStream(java.io.InputStream input)`
    `static java.lang.String` | `getTextContent(javax.xml.xpath.XPath xPath, org.w3c.dom.Node elementNode)`
    `java.util.HashMap<java.lang.String,java.lang.Object>` | `handleClientRequest(com.oreilly.servlet.multipart.MultipartParser multipartParser)` Main method for handling various actions.
    `java.lang.String` | `handleDocIdSelect()`
    `java.lang.String` | `handleFileUpdate(com.oreilly.servlet.multipart.MultipartParser multipartParser)`
    `java.lang.String` | `handlePackageUpload(ClientView clientViewBean, com.oreilly.servlet.multipart.MultipartParser multipartParser)` Handles metadata file and data file uploads for inserting new Metacat data packages.
    `static boolean` | `isElementContentWhitespace(org.w3c.dom.Text textNode)`
    `boolean` | `isLoggedIn()` A convenience method to be used by client code that requires the user to be logged in.
    `java.lang.String` | `makeRedirectUrl()`
    `java.lang.String` | `nextVersion(java.lang.String lastDocId, java.lang.String xPathQuery)`
    `static java.lang.String[]` | `parseFileInfo(java.lang.String fileName)`
    `java.lang.String` | `parseXml(java.lang.String elementName, java.lang.String xml)`
    `org.w3c.dom.Document` | `query(java.lang.String pathExpr, java.lang.String pathValue, java.lang.String returnFld)` Query metacat for documents that 'CONTAINS' the value at the specified XPath expression.
    `void` | `setLoggedIn(boolean isLoggedIn)`
    `void` | `setLoggedIn(java.lang.String serverResponse)` After calling "login(ldapUserName, pwd)", call this with the username and servers response message.
    `void` | `setMetadataDoc(org.w3c.dom.Document doc)`
    `void` | `setMetadataDoc(java.io.InputStream ioStream)`
    `void` | `setMetadataDoc(java.lang.String docId)`
    `static void` | `setTextContent(javax.xml.xpath.XPath xPath, org.w3c.dom.Node elementNode, java.lang.String content)`
    `void` | `setUserName(java.lang.String userName)`
    `static java.lang.String` | `toZipFileName(java.lang.String fileName)`
    `static void` | `updateNodeText(org.w3c.dom.Node root, javax.xml.xpath.XPath xPath, java.lang.String expression, java.lang.String text)`

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

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

- - ### Field Detail

    - #### DOWNLOAD_ACTION

          public static final java.lang.String DOWNLOAD_ACTION

      See Also:
        Constant Field Values

    - #### PERMISSION_TYPE_ALLOW

          public static final java.lang.String PERMISSION_TYPE_ALLOW

      See Also:
        Constant Field Values

    - #### PERMISSION_TYPE_DISALLOW

          public static final java.lang.String PERMISSION_TYPE_DISALLOW

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### ClientViewHelper

          public ClientViewHelper(javax.servlet.http.HttpServletRequest request)
                           throws MetacatInaccessibleException

      Creates a new instance of ClientViewHelper, using info in an HttpServletRequest for initializing.
      Parameters:
        `request` - HttpServletRequest, sent from the client browser.
      Throws:
        `MetacatInaccessibleException` - Thrown

    - #### ClientViewHelper

          public ClientViewHelper(java.lang.String host,
                                  java.lang.String context,
                                  ClientView bean)
                           throws MetacatInaccessibleException

      Creates a new instance of ClientViewHelper, using parameter values for initializing. This constructor is plain java code so it's the portal of choice for JUnit testing.
      Parameters:
        `host` - The host with port (if needed), such as "localhost:8084".
        `context` - The application root context.
        `bean` - ClientView instance, with pre-populated values.
      Throws:
        `MetacatInaccessibleException` - thrown

  - ### Method Detail

    - #### clientRequest

          public java.lang.String clientRequest(javax.servlet.http.HttpServletRequest request,
                                                javax.servlet.http.HttpServletResponse response)

      Main web API method for handling various actions.
      Parameters:
        `request` - HttpServletRequest
        `response` - HttpServletResponse
      Returns:
        String message

    - #### handleClientRequest

          public java.util.HashMap<java.lang.String,java.lang.Object> handleClientRequest(com.oreilly.servlet.multipart.MultipartParser multipartParser)

      Main method for handling various actions. Note: This is mostly plain java code so it is JUnit friendly (pass null as the MulipartParser).
      Parameters:
        `multipartParser` - Only needed if the action is "Upload".
      Returns:
        HashMap containing "message", and possibly several other values. If the action is Download, than this will contain all needed values to pass to handleDownloadResponse.

    - #### clientViewHelperInstance

          public static ClientViewHelper clientViewHelperInstance(javax.servlet.http.HttpServletRequest request)

      This is a convenience method to reduce the amount of code in a Metacat Client. It handles creating/reusing (per session) an instance of a ClientViewHelper.
      Parameters:
        `request` - Since this is intended to be used by an Http client, it is passed the available "request" variable (the HttpServletRequest).
      Returns:
        ClientViewHelper instance.
      Throws:
        `MetacatInaccessibleException` - Received by MetacatFactory.

    - #### isLoggedIn

          public boolean isLoggedIn()

      A convenience method to be used by client code that requires the user to be logged in. NOTE: setUser() must have been called first, otherwise it will always return false.
      Returns:
        boolean true if user has logged in for this session, false otherwise.

    - #### setLoggedIn

          public void setLoggedIn(java.lang.String serverResponse)

      After calling "login(ldapUserName, pwd)", call this with the username and servers response message. You can than use isLoggedIn() to determine if the user is logged in, getLoginResponseElement(), etc. The user name will also used by calls to doMetadataUpload() for Document Id creation (scope).
      Parameters:
        `userName` - User name
        `serverResponse` - XML login response sent from Metacat.

    - #### setLoggedIn

          public void setLoggedIn(boolean isLoggedIn)

    - #### setUserName

          public void setUserName(java.lang.String userName)

    - #### parseXml

          public java.lang.String parseXml(java.lang.String elementName,
                                           java.lang.String xml)

    - #### handleDocIdSelect

          public java.lang.String handleDocIdSelect()

    - #### handlePackageUpload

          public java.lang.String handlePackageUpload(ClientView clientViewBean,
                                                      com.oreilly.servlet.multipart.MultipartParser multipartParser)
                                               throws java.lang.Exception

      Handles metadata file and data file uploads for inserting new Metacat data packages. Note: if content type is not "multipart/form-data", nothing will happen.
      Parameters:
        `request` - HTTP request.
      Returns:
        A 1-line status message for the user.
      Throws:
        `java.lang.Exception`

    - #### handleFileUpdate

          public java.lang.String handleFileUpdate(com.oreilly.servlet.multipart.MultipartParser multipartParser)
                                            throws java.lang.Exception

      Throws:
        `java.lang.Exception`

    - #### getSelectQueryMap

          public java.util.TreeMap getSelectQueryMap()

      Queries Metacat for document listings, and returns the results in a TreeMap, where the key is the Doc Id, and the value is the Create Date. If the document contains the specified 'returnfield', an addtional entry will be created with the value being a Vector of sub-DocId's. The key of this entry will be the original DocId with some addtional text added. Reads bean properties 'pathExpr' (String[]), 'pathValue' (String) and 'returnfield' (String).
      Returns:
        TreeMap

    - #### query

          public org.w3c.dom.Document query(java.lang.String pathExpr,
                                            java.lang.String pathValue,
                                            java.lang.String returnFld)

      Query metacat for documents that 'CONTAINS' the value at the specified XPath expression. Additionally, returns another non-standard field value. Standard info contains: DocId, DocName, DocType, CreateDate, and UpdateDate.
      Parameters:
        `pathExpr` - String contianing an XPath expression.
        `pathValue` - String containing a comparison value at the XPath expression.
        `returnFld` - String containing an XPath expression to a field which will be returned in addition to the standard info.
      Returns:
        DOM Document containing the results.

    - #### setMetadataDoc

          public void setMetadataDoc(org.w3c.dom.Document doc)

    - #### setMetadataDoc

          public void setMetadataDoc(java.lang.String docId)
                              throws java.lang.Exception

      Throws:
        `java.lang.Exception`

    - #### setMetadataDoc

          public void setMetadataDoc(java.io.InputStream ioStream)
                              throws java.io.IOException

      Throws:
        `java.io.IOException`

    - #### getMetadataDoc

          public org.w3c.dom.Document getMetadataDoc()

    - #### nextVersion

          public java.lang.String nextVersion(java.lang.String lastDocId,
                                              java.lang.String xPathQuery)
                                       throws javax.xml.xpath.XPathExpressionException

      Throws:
        `javax.xml.xpath.XPathExpressionException`

    - #### getMetacatClient

          public MetacatClient getMetacatClient()

    - #### parseFileInfo

          public static java.lang.String[] parseFileInfo(java.lang.String fileName)

    - #### updateNodeText

          public static void updateNodeText(org.w3c.dom.Node root,
                                            javax.xml.xpath.XPath xPath,
                                            java.lang.String expression,
                                            java.lang.String text)

    - #### getNode

          public static org.w3c.dom.Node getNode(javax.xml.xpath.XPath xPath,
                                                 java.lang.String expression,
                                                 org.w3c.dom.Node root)

    - #### getNodeText

          public static java.lang.String getNodeText(javax.xml.xpath.XPath xPath,
                                                     java.lang.String expression,
                                                     org.w3c.dom.Node root)

    - #### getNodeTextList

          public static java.lang.String[] getNodeTextList(javax.xml.xpath.XPath xPath,
                                                           java.lang.String expression,
                                                           org.w3c.dom.Node root)

    - #### getNodeTextStack

          public static java.util.Stack getNodeTextStack(javax.xml.xpath.XPath xpathInstance,
                                                         java.lang.String xpathExpr,
                                                         org.w3c.dom.Node parentNode)

    - #### getStringFromInputStream

          public static java.lang.String getStringFromInputStream(java.io.InputStream input)

    - #### makeRedirectUrl

          public java.lang.String makeRedirectUrl()

    - #### toZipFileName

          public static java.lang.String toZipFileName(java.lang.String fileName)

    - #### setTextContent

          public static void setTextContent(javax.xml.xpath.XPath xPath,
                                            org.w3c.dom.Node elementNode,
                                            java.lang.String content)
                                     throws org.w3c.dom.DOMException

      Throws:
        `org.w3c.dom.DOMException`

    - #### getTextContent

          public static java.lang.String getTextContent(javax.xml.xpath.XPath xPath,
                                                        org.w3c.dom.Node elementNode)
                                                 throws org.w3c.dom.DOMException

      Throws:
        `org.w3c.dom.DOMException`

    - #### isElementContentWhitespace

          public static boolean isElementContentWhitespace(org.w3c.dom.Text textNode)

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