Class SchemEditUtils

java.lang.Object
org.dlese.dpc.schemedit.SchemEditUtils

public class SchemEditUtils extends Object
Utility methods for SchemEdit
Author:
ostwald
  • Field Details

    • utcDateFormatString

      public static String utcDateFormatString
      "yyyy-MM-dd'T'HH:mm:ss'Z'"
    • utcDateFormat

      public static SimpleDateFormat utcDateFormat
      Formats and parses dates according to utcDateFormatString.
    • fullDateFormatString

      public static String fullDateFormatString
      same as utcDateFormatString
    • fullDateFormat

      public static SimpleDateFormat fullDateFormat
      * Formats and parses dates according to fullDateFormatString.
    • simpleDateFormatString

      public static String simpleDateFormatString
      "yyyy-MM-dd"
    • simpleDateFormat

      public static SimpleDateFormat simpleDateFormat
      Formats and parses dates according to simpleDateFormatString.
  • Constructor Details

    • SchemEditUtils

      public SchemEditUtils()
  • Method Details

    • forwardToCaller

      public static org.apache.struts.action.ActionForward forwardToCaller(HttpServletRequest request, String editedRecId, SessionBean sessionBean)
      General method to forward control to the appropriate page (Collections, Search or View) after completing an operation. The editedRecId parameter is supplied by metadata editor. It is used to highlight a record in the search view. It may be different from SessionBean.getId(), which is set by the viewing tool.

      Parameters:
      request - the request object
      editedRecId - id of record edited in metadata editor (if any)
      sessionBean - a sessionBean instance
      Returns:
      ActionForward directing to the caller of last operation.
    • contractAmpersands

      public static String contractAmpersands(String in)
      Contract expanded ampersands (&) that are part of entity references. For example, "©" and "©" both become "invalid input: '&#169'". "&" by itself is not contracted. Used to convert xml record into a form desireable for xml files
      Parameters:
      in - String to be processed
      Returns:
      processed string
    • escapeUriSpaces

      public static String escapeUriSpaces(String uriStr)
      Escape spaces in the given uriStr so that it may be accepted by URI constructor.
      Parameters:
      uriStr - Description of the Parameter
      Returns:
      Description of the Return Value
    • expandAmpersands

      public static String expandAmpersands(String in)
      Expand expanded ampersands that are part of entities. For example, "©" becomes "&#169". Used to convert xml text from file form into a from preferred by dom4j.
      Parameters:
      in - Description of the Parameter
      Returns:
      Description of the Return Value
    • getLocalizedXmlDocument

      public static org.dom4j.Document getLocalizedXmlDocument(URI uri) throws Exception
      Returns a localized xmlDocument for the given uri. NOTE: URI's must have a scheme of either "file" or "http".

      NOTEs:

      • this method should use getUriRef to resolve the uri into either a file or url.
      • what is the difference between this and getEditableXml()?
      Parameters:
      uri - uri pointing to a file containing xml
      Returns:
      A localized Document
      Throws:
      Exception - If scheme is not recognized or if a Document could not be created
    • getUriRef

      public static Object getUriRef(String uriStr) throws Exception, URISyntaxException
      Gets the uriRef attribute of the SchemEditUtils class
      Parameters:
      uriStr - Description of the Parameter
      Returns:
      The uriRef value
      Throws:
      Exception - Description of the Exception
      URISyntaxException - Description of the Exception
    • getUriRef

      public static Object getUriRef(URI uri) throws Exception
      Gets the uriRef attribute of the SchemEditUtils class
      Parameters:
      uri - Description of the Parameter
      Returns:
      The uriRef value
      Throws:
      Exception - Description of the Exception
    • getUriRef

      public static Object getUriRef(String uriStr, String docRoot) throws Exception, URISyntaxException
      Gets the uriRef attribute of the SchemEditUtils class
      Parameters:
      uriStr - Description of the Parameter
      docRoot - Description of the Parameter
      Returns:
      The uriRef value
      Throws:
      Exception - Description of the Exception
      URISyntaxException - Description of the Exception
    • getUriRef

      public static Object getUriRef(URI uri, String docRoot) throws Exception
      Given a string representation of a uri, returns either a File or URL instance.

      Relative paths are assumed to be file paths relative to "docRoot" and expanded accordingly into absolute files.

      Parameters:
      uri - Description of the Parameter
      docRoot - Path to docRoot for this application to aid in resolving relative paths.
      Returns:
      The uriRef value
      Throws:
      Exception - NOT YET DOCUMENTED
    • getEditableXml

      public static String getEditableXml(File file) throws Exception
      Gets the editableXml attribute of the SchemEditUtils class
      Parameters:
      file - NOT YET DOCUMENTED
      Returns:
      The editableXml value
      Throws:
      Exception - NOT YET DOCUMENTED
    • getEditableDocument

      public static org.dom4j.Document getEditableDocument(String docUri, MetaDataFramework framework) throws org.dom4j.DocumentException
      Returns the localized dom4j.Document from the given uri after checking that the schemaLocation declared by the document at uri corresponds with the schemaLocation known to the MetaDataFramework parameter.

      called from MetaDataFramework.getEditableDocument.

      Parameters:
      docUri - uri of xml document
      framework - MetaDataFramework instance for consistency checking.
      Returns:
      localized dom4j.Document with ampersands expanded for editing.
      Throws:
      org.dom4j.DocumentException - Description of the Exception
    • showReferer

      public static void showReferer(HttpServletRequest request)
      Displays request params for debugging.
      Parameters:
      request - Description of the Parameter
    • showRequestParameters

      public static void showRequestParameters(HttpServletRequest request)
      Displays request params for debugging.

      Filtering out kinds of parameters. Construct an array containing strings which, if found in a parameter name, will filter that param from the display. E.g.,

      • metadata editor form values contain params: "("
      • metadata editor collapse params contain "_^_"
      Parameters:
      request - Description of the Parameter
    • showRequestParameters

      public static void showRequestParameters(HttpServletRequest request, String[] paramFilter)
      Description of the Method
      Parameters:
      request - Description of the Parameter
      paramFilter - Description of the Parameter
    • getCollectionFromIndex

      public static String getCollectionFromIndex(String id, SimpleLuceneIndex index)
      DEPRECIATED - use getCollectionOfIndexedRecord Returns the collection associated with an indexed record.
      Parameters:
      id - record id
      index - a SimpleLuceneIndex instance
      Returns:
      The collection attribute for the record identified by id
    • getCollectionOfIndexedRecord

      public static String getCollectionOfIndexedRecord(String id, RepositoryManager rm)
      Returns the collection associated with an indexed record.
      Parameters:
      id - record id
      rm - Description of the Parameter
      Returns:
      The collection attribute for the record identified by id
    • getSetInfo

      public static SetInfo getSetInfo(String collection, RepositoryManager rm)
      Gets the setInfo attribute of the SchemEditUtils class
      Parameters:
      collection - Description of the Parameter
      rm - Description of the Parameter
      Returns:
      The setInfo value
    • getDcsSetInfo

      public static DcsSetInfo getDcsSetInfo(String collection, RepositoryManager rm)
      Gets the dcsSetInfo attribute of the SchemEditUtils class
      Parameters:
      collection - Description of the Parameter
      rm - Description of the Parameter
      Returns:
      The dcsSetInfo value
    • getDcsSetInfo

      public static DcsSetInfo getDcsSetInfo(String collection, List dcsSetInfos)
      pick a given DcsSetInfo from a list
      Parameters:
      collection - Description of the Parameter
      dcsSetInfos - Description of the Parameter
      Returns:
      The dcsSetInfo value
    • getFileFromIndex

      public static File getFileFromIndex(String id, RepositoryManager rm)
      Returns the file associated with an id in an index.
      Parameters:
      id - record id
      rm - Description of the Parameter
      Returns:
      The source file for the record identified by id
    • showRoleInfo

      public static void showRoleInfo(User sessionUser, org.apache.struts.action.ActionMapping mapping)
      Description of the Method
      Parameters:
      sessionUser - Description of the Parameter
      mapping - Description of the Parameter
    • hasBadChar

      public static boolean hasBadChar(String s)
      Checks given string for characters outside the range of ASCII values
      Parameters:
      s - String to be checked
      Returns:
      true if String contains characters with ASCII value above 127.
    • getUniqueId

      public static String getUniqueId()
      Gets the uniqueId attribute of the SchemEditUtils class
      Returns:
      The uniqueId value
    • showRequestHeaders

      public static void showRequestHeaders(HttpServletRequest request)
      Display request headers for debugging.
      Parameters:
      request - Description of the Parameter
    • formatQuery

      public static String formatQuery(String q)
      Encodes query strings beginning with "id:" or "url:" using SimpleLuceneIndex.encodeToTerm(java.lang.String).
      Parameters:
      q - the query string
      Returns:
      thge formatted query string
    • quoteWrap

      public static String quoteWrap(String s)
      Return the given string wrapped in quotation marks
      Parameters:
      s - the string to quote wrap
      Returns:
      the quoted string
    • fullDateString

      public static String fullDateString(Date date)
      Converts a Date object into a string formatted with fullDateFormat
      Parameters:
      date - date to be formatted
      Returns:
      formatted date
    • simpleDateString

      public static String simpleDateString(Date date)
      Converts a Date object into a string formatted with simpleDateFormat
      Parameters:
      date - date to be formatted
      Returns:
      formatted date
    • utcDateString

      public static String utcDateString(Date date)
      formats the given date in the form "yyyy-MM-dd'T'HH:mm:ss'Z'". If given date is null the string return reflects "the epoch", namely January 1, 1970, 00:00:00 GMT.
      Parameters:
      date - a date object to be formatted
      Returns:
      the formatted string representation of date
    • getUtcTime

      public static Date getUtcTime()
      Gets the utcTime attribute of the SchemEditUtils class
      Returns:
      The utcTime value
    • getUtcTime

      public static Date getUtcTime(Date date)
      Gets the utcTime attribute of the SchemEditUtils class
      Parameters:
      date - the date object
      Returns:
      The utcTime value
    • getElapsedTimeSimple

      public static String getElapsedTimeSimple(long clicks)
      Return a string representation of the elapsed time since an event date (which is represented as "clicks" since "the epoch").

      NOTE: this method does not consider elapsed times greater than 24 hours (the elapsed days are simply not shown).

      Parameters:
      clicks - Description of the Parameter
      Returns:
      The elapsedTimeSimple value
    • main

      public static void main(String[] args) throws Exception
      The main program for the SchemEditUtils class
      Parameters:
      args - The command line arguments
      Throws:
      Exception - Description of the Exception
    • toWinPath

      public static String toWinPath(String path)
      Replace forward slashes in provided path with backward slashes
      Parameters:
      path - the path to convert
      Returns:
      converted path
    • getMirrorUrls

      public static List getMirrorUrls(String recordXml)
      Extracts mirrorUrl values from an adn record
      Parameters:
      recordXml - xml string to search for mirrorUrls
      Returns:
      The mirrorUrls value
    • stuffId

      public static String stuffId(String recordXml, String id, MetaDataFramework framework) throws Exception
      Insert a new id into an existing metadata record
      Parameters:
      recordXml - metadata record as xml string
      id - id to insert into the metadata record
      framework - MetaDataFramework object for the format of the record
      Returns:
      Description of the Return Value
      Throws:
      Exception - Description of the Exception
    • getAttr

      public static Object getAttr(Object obj, String attr)
      Based on attribute name, attempts to get the value of that attribute using a bean-style "gettter".
      Parameters:
      obj - object for which to get attr
      attr - attribute to get
      Returns:
      The attr value
    • prtln

      public static void prtln(String s, String prefix)
      Description of the Method
      Parameters:
      s - Description of the Parameter
      prefix - Description of the Parameter
    • prtln

      public static void prtln(String s)
      Print a line to standard out.
      Parameters:
      s - The String to print.
    • box

      public static void box(String s)
      Description of the Method
      Parameters:
      s - Description of the Parameter