DLESE Tools
v1.6.0

org.dlese.dpc.schemedit
Class SchemEditUtils

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

public class SchemEditUtils
extends Object

Utility methods for SchemEdit

Author:
ostwald

Field Summary
static SimpleDateFormat fullDateFormat
          * Formats and parses dates according to fullDateFormatString.
static String fullDateFormatString
          same as utcDateFormatString
static SimpleDateFormat simpleDateFormat
          Formats and parses dates according to simpleDateFormatString.
static String simpleDateFormatString
          "yyyy-MM-dd"
static SimpleDateFormat utcDateFormat
          Formats and parses dates according to utcDateFormatString.
static String utcDateFormatString
          "yyyy-MM-dd'T'HH:mm:ss'Z'"
 
Constructor Summary
SchemEditUtils()
           
 
Method Summary
static void box(String s)
          Description of the Method
static String contractAmpersands(String in)
          Contract expanded ampersands (&) that are part of entity references.
static String escapeUriSpaces(String uriStr)
          Escape spaces in the given uriStr so that it may be accepted by URI constructor.
static String expandAmpersands(String in)
          Expand expanded ampersands that are part of entities.
static String formatQuery(String q)
          Encodes query strings beginning with "id:" or "url:" using SimpleLuceneIndex.encodeToTerm(java.lang.String).
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.
static String fullDateString(Date date)
          Converts a Date object into a string formatted with fullDateFormat
static Object getAttr(Object obj, String attr)
          Based on attribute name, attempts to get the value of that attribute using a bean-style "gettter".
static String getCollectionFromIndex(String id, SimpleLuceneIndex index)
          DEPRECIATED - use getCollectionOfIndexedRecord Returns the collection associated with an indexed record.
static String getCollectionOfIndexedRecord(String id, RepositoryManager rm)
          Returns the collection associated with an indexed record.
static DcsSetInfo getDcsSetInfo(String collection, List dcsSetInfos)
          pick a given DcsSetInfo from a list
static DcsSetInfo getDcsSetInfo(String collection, RepositoryManager rm)
          Gets the dcsSetInfo attribute of the SchemEditUtils class
static Document getEditableDocument(String docUri, MetaDataFramework framework)
          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.
static String getEditableXml(File file)
          Gets the editableXml attribute of the SchemEditUtils class
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").
static File getFileFromIndex(String id, RepositoryManager rm)
          Returns the file associated with an id in an index.
static Document getLocalizedXmlDocument(URI uri)
          Returns a localized xmlDocument for the given uri.
static List getMirrorUrls(String recordXml)
          Extracts mirrorUrl values from an adn record
static SetInfo getSetInfo(String collection, RepositoryManager rm)
          Gets the setInfo attribute of the SchemEditUtils class
static String getUniqueId()
          Gets the uniqueId attribute of the SchemEditUtils class
static Object getUriRef(String uriStr)
          Gets the uriRef attribute of the SchemEditUtils class
static Object getUriRef(String uriStr, String docRoot)
          Gets the uriRef attribute of the SchemEditUtils class
static Object getUriRef(URI uri)
          Gets the uriRef attribute of the SchemEditUtils class
static Object getUriRef(URI uri, String docRoot)
          Given a string representation of a uri, returns either a File or URL instance.
static Date getUtcTime()
          Gets the utcTime attribute of the SchemEditUtils class
static Date getUtcTime(Date date)
          Gets the utcTime attribute of the SchemEditUtils class
static boolean hasBadChar(String s)
          Checks given string for characters outside the range of ASCII values
static void main(String[] args)
          The main program for the SchemEditUtils class
static void prtln(String s)
          Print a line to standard out.
static void prtln(String s, String prefix)
          Description of the Method
static String quoteWrap(String s)
          Return the given string wrapped in quotation marks
static void showReferer(HttpServletRequest request)
          Displays request params for debugging.
static void showRequestHeaders(HttpServletRequest request)
          Display request headers for debugging.
static void showRequestParameters(HttpServletRequest request)
          Displays request params for debugging.
static void showRequestParameters(HttpServletRequest request, String[] paramFilter)
          Description of the Method
static void showRoleInfo(User sessionUser, org.apache.struts.action.ActionMapping mapping)
          Description of the Method
static String simpleDateString(Date date)
          Converts a Date object into a string formatted with simpleDateFormat
static String stuffId(String recordXml, String id, MetaDataFramework framework)
          Insert a new id into an existing metadata record
static String toWinPath(String path)
          Replace forward slashes in provided path with backward slashes
static String utcDateString(Date date)
          formats the given date in the form "yyyy-MM-dd'T'HH:mm:ss'Z'".
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

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 Detail

SchemEditUtils

public SchemEditUtils()
Method Detail

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 "©". "&" 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 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:

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:
docRoot - Path to docRoot for this application to aid in resolving relative paths.
uri - Description of the Parameter
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 Document getEditableDocument(String docUri,
                                           MetaDataFramework framework)
                                    throws 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:
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.,

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

DLESE Tools
v1.6.0