edu.ucsb.nceas.metacat.util

## Class MetacatUtil

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

-     public class MetacatUtil
      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`
    `static java.lang.String` | `XMLFORMAT`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `MetacatUtil()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static void` | `copyFile(java.lang.String sourceName, java.lang.String destName)` Copy a file between two locations specified as strings.
    `static java.lang.String` | `getLocalReplicationServerName()` Method to get the name of local replication server
    `static java.util.Vector<java.lang.String>` | `getOptionList(java.lang.String optiontext)`
    `static java.lang.String` | `normalize(java.lang.String s)` Normalizes a string read from DB.
    `static java.util.Hashtable<java.lang.String,java.lang.String>` | `parseQuery(java.lang.String query)` Utility method to parse the query part of a URL into parameters.
    `static java.lang.String` | `replaceWhiteSpaceForURL(java.lang.String urlHasWhiteSpace)` A method to replace whitespace in url
    `static void` | `writeDebugToDelimiteredFile(java.lang.String debugInfo, boolean newLine)` Writes debug information into a file in delimitered format
    `static void` | `writeDebugToFile(java.lang.String debugInfo)` Writes debug information into a file.
    `static java.io.File` | `writeTempUploadFile(org.apache.commons.fileupload.FileItem fi, java.lang.String fileName)` Write the uploaded file to disk for temporary storage before moving it to its final Metacat location.

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

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

- - ### Field Detail

    - #### XMLFORMAT

          public static final java.lang.String XMLFORMAT

      See Also:
        Constant Field Values

    - #### dbAdapter

          public static AbstractDatabase dbAdapter

  - ### Constructor Detail

    - #### MetacatUtil

          public MetacatUtil()

  - ### Method Detail

    - #### parseQuery

          public static java.util.Hashtable<java.lang.String,java.lang.String> parseQuery(java.lang.String query)
                                                                                   throws java.net.MalformedURLException

      Utility method to parse the query part of a URL into parameters. This method assumes the format of the query part of the url is an ampersand separated list of name/value pairs, with equal signs separating the name from the value (e.g., name=tom&zip=99801 ). Returns a has of the name value pairs, hashed on name.
      Throws:
        `java.net.MalformedURLException`

    - #### getOptionList

          public static java.util.Vector<java.lang.String> getOptionList(java.lang.String optiontext)

    - #### normalize

          public static java.lang.String normalize(java.lang.String s)

      Normalizes a string read from DB. So it will be compatible to HTML

    - #### getLocalReplicationServerName

          public static java.lang.String getLocalReplicationServerName()

      Method to get the name of local replication server

    - #### replaceWhiteSpaceForURL

          public static java.lang.String replaceWhiteSpaceForURL(java.lang.String urlHasWhiteSpace)

      A method to replace whitespace in url

    - #### writeDebugToFile

          public static void writeDebugToFile(java.lang.String debugInfo)

      Writes debug information into a file. In metacat.properties, if property application.writeDebugToFile is set to true, the debug information will be written to debug file, which value is the property application.debugOutputFile in metacat.properties.

    - #### writeDebugToDelimiteredFile

          public static void writeDebugToDelimiteredFile(java.lang.String debugInfo,
                                                         boolean newLine)

      Writes debug information into a file in delimitered format
      Parameters:
        `debugInfo` - the debug information
        `newLine` - append the debug info to a line or not

    - #### writeTempUploadFile

          public static java.io.File writeTempUploadFile(org.apache.commons.fileupload.FileItem fi,
                                                         java.lang.String fileName)
                                                  throws java.lang.Exception

      Write the uploaded file to disk for temporary storage before moving it to its final Metacat location.
      Parameters:
        `filePart` - the FilePart object containing the file form element
        `fileName` - the name of the file to be written to disk
      Returns:
        tempFilePath a String containing location of temporary file
      Throws:
        `java.lang.Exception`

    - #### copyFile

          public static void copyFile(java.lang.String sourceName,
                                      java.lang.String destName)
                               throws java.io.IOException

      Copy a file between two locations specified as strings. Fails if either path cannot be created. Based on the public domain FileCopy class in _Java in a Nutshell_.
      Parameters:
        `sourceName` - the source file to read from disk
        `destName` - the destination file on disk
      Throws:
        `java.io.IOException`

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