Class ClientViewHelper

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

public class ClientViewHelper extends Object
Author:
barteau
  • Field Details

  • Constructor Details

    • 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(String host, 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 Details

    • clientRequest

      public 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 HashMap<String,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(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(String userName)
    • parseXml

      public String parseXml(String elementName, String xml)
    • handleDocIdSelect

      public String handleDocIdSelect()
    • handlePackageUpload

      public String handlePackageUpload(ClientView clientViewBean, com.oreilly.servlet.multipart.MultipartParser multipartParser) throws 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:
      Exception
    • handleFileUpdate

      public String handleFileUpdate(com.oreilly.servlet.multipart.MultipartParser multipartParser) throws Exception
      Throws:
      Exception
    • getSelectQueryMap

      public 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 Document query(String pathExpr, String pathValue, 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(Document doc)
    • setMetadataDoc

      public void setMetadataDoc(String docId) throws Exception
      Throws:
      Exception
    • setMetadataDoc

      public void setMetadataDoc(InputStream ioStream) throws IOException
      Throws:
      IOException
    • getMetadataDoc

      public Document getMetadataDoc()
    • nextVersion

      public String nextVersion(String lastDocId, String xPathQuery) throws XPathExpressionException
      Throws:
      XPathExpressionException
    • getMetacatClient

      public MetacatClient getMetacatClient()
    • parseFileInfo

      public static String[] parseFileInfo(String fileName)
    • updateNodeText

      public static void updateNodeText(Node root, XPath xPath, String expression, String text)
    • getNode

      public static Node getNode(XPath xPath, String expression, Node root)
    • getNodeText

      public static String getNodeText(XPath xPath, String expression, Node root)
    • getNodeTextList

      public static String[] getNodeTextList(XPath xPath, String expression, Node root)
    • getNodeTextStack

      public static Stack getNodeTextStack(XPath xpathInstance, String xpathExpr, Node parentNode)
    • getStringFromInputStream

      public static String getStringFromInputStream(InputStream input)
    • makeRedirectUrl

      public String makeRedirectUrl()
    • toZipFileName

      public static String toZipFileName(String fileName)
    • setTextContent

      public static void setTextContent(XPath xPath, Node elementNode, String content) throws DOMException
      Throws:
      DOMException
    • getTextContent

      public static String getTextContent(XPath xPath, Node elementNode) throws DOMException
      Throws:
      DOMException
    • isElementContentWhitespace

      public static boolean isElementContentWhitespace(Text textNode)