edu.ucsb.nceas.metacat
Class MetaCatUtil

java.lang.Object
  extended by edu.ucsb.nceas.metacat.MetaCatUtil

public class MetaCatUtil
extends java.lang.Object

A suite of utility classes for the metadata catalog server


Field Summary
static AbstractDatabase dbAdapter
           
static java.util.Vector pathsForIndexing
           
 
Constructor Summary
MetaCatUtil()
           
 
Method Summary
static void addSkinConfig(java.lang.String skinName, java.util.Properties skinProperties)
          Adds the Properties and skin to the list of skin configurations.
static boolean canInsertOrUpdate(java.lang.String username, java.lang.String[] groups)
          A method to check if the specified user can insert the document
static void copyFile(java.lang.String sourceName, java.lang.String destName)
          Copy a file between two locations specified as strings.
static java.lang.Object createObject(java.lang.String className)
          Instantiate a class using the name of the class at runtime
static java.net.URL fileToURL(java.io.File file)
          Utility method to convert a file handle into a URL
static java.lang.String getAccessionNumberFromEcogridIdentifier(java.lang.String identifier)
          Eocgorid identifier will look like: ecogrid://knb/tao.1.1 The AccessionNumber tao.1.1 will be returned.
static java.lang.String getDocIdFromAccessionNumber(java.lang.String accessionNumber)
          This method will get docid from an AccessionNumber.
static java.lang.String getDocIdFromString(java.lang.String str)
          Utility method to get docid from a given string
static java.lang.String getDocIdWithoutRevFromInlineDataID(java.lang.String inlineDataID)
          Method to get docidwithrev from eml2 inline data id The eml inline data id would look like eml.200.2.3
static java.lang.String getDocIdWithRevFromOnlineURL(java.lang.String url)
          Get docid from online/url string
static java.lang.String getInlineDataIdWithoutRev(java.lang.String accessionNumber)
          This method will get inline data id without the revision number.
static java.lang.String getLocalReplicationServerName()
          Method to get the name of local replication server
static java.lang.String getOption(java.lang.String optionName)
          Utility method to get an option value from the properties file
static java.util.Vector getOptionList(java.lang.String optiontext)
           
static int getRevisionFromAccessionNumber(java.lang.String accessionNumber)
          This method will get revision from an AccessionNumber.
static java.lang.String getRevisionStringFromString(java.lang.String str)
          Utility method to get version string from a given string
static java.util.Properties getSkinConfig(java.lang.String skinName)
          Return the Properties for a given skin name.
static java.lang.String getSmartDocId(java.lang.String str)
          This method will call both getDocIdFromString and getDocIdFromAccessionNumber.
static void getUserAccessControlLists()
          A method to read administrators and moderators list from the metacat.properties
static int getVersionFromString(java.lang.String str)
          Utility method to get version number from a given string
static boolean hasSkinConfig(java.lang.String skinName)
          Returns true if Properties exist for a given skin name, false otherwise.
static boolean isAdministrator(java.lang.String username, java.lang.String[] groups)
          A method to check if the specified user is part of the administrators list
static boolean isAllowedSubmitter(java.lang.String username, java.lang.String[] groups)
          A method to check if the specified user is part of the moderators list
static boolean isDeniedSubmitter(java.lang.String username, java.lang.String[] groups)
          A method to check if the specified user is part of the moderators list
static boolean isModerator(java.lang.String username, java.lang.String[] groups)
          A method to check if the specified user is part of the moderators list
static java.lang.String normalize(java.lang.String s)
          Normalizes a string read from DB.
static java.util.Hashtable 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 java.util.Stack reviseStack(java.util.Stack stack)
          Revise stack change a stack to opposite order
static void setOption(java.lang.String optionName, java.lang.String newValue)
          Utility method to set an option value from the properties file
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.lang.String writeTempFile(com.oreilly.servlet.multipart.FilePart filePart, 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

dbAdapter

public static AbstractDatabase dbAdapter

pathsForIndexing

public static java.util.Vector pathsForIndexing
Constructor Detail

MetaCatUtil

public MetaCatUtil()
Method Detail

createObject

public static java.lang.Object createObject(java.lang.String className)
                                     throws java.lang.Exception
Instantiate a class using the name of the class at runtime

Parameters:
className - the fully qualified name of the class to instantiate
Throws:
java.lang.Exception

getOption

public static java.lang.String getOption(java.lang.String optionName)
Utility method to get an option value from the properties file

Parameters:
optionName - the name of the option requested
Returns:
the String value for the option, or null if not set

setOption

public static void setOption(java.lang.String optionName,
                             java.lang.String newValue)
Utility method to set an option value from the properties file

Parameters:
optionName - the name of the option requested

fileToURL

public static java.net.URL fileToURL(java.io.File file)
Utility method to convert a file handle into a URL


parseQuery

public static java.util.Hashtable 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 par tof 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 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


getDocIdWithRevFromOnlineURL

public static java.lang.String getDocIdWithRevFromOnlineURL(java.lang.String url)
Get docid from online/url string


getAccessionNumberFromEcogridIdentifier

public static java.lang.String getAccessionNumberFromEcogridIdentifier(java.lang.String identifier)
Eocgorid identifier will look like: ecogrid://knb/tao.1.1 The AccessionNumber tao.1.1 will be returned. If the given doesn't contains ecogrid, null will be returned.

Parameters:
identifier - String
Returns:
String

getDocIdFromString

public static java.lang.String getDocIdFromString(java.lang.String str)
Utility method to get docid from a given string

Parameters:
string, - the given string should be these two format: 1) str1.str2 in this case docid= str1.str2 2) str1.str2.str3, in this case docid =str1.str2
the - sperator char

getVersionFromString

public static int getVersionFromString(java.lang.String str)
                                throws java.lang.NumberFormatException
Utility method to get version number from a given string

Parameters:
string, - the given string should be these two format: 1) str1.str2(no version) version =-1; 2) str1.str2.str3, in this case version = str3; 3) other, vresion =-2
Throws:
java.lang.NumberFormatException

getRevisionStringFromString

public static java.lang.String getRevisionStringFromString(java.lang.String str)
                                                    throws java.lang.NumberFormatException
Utility method to get version string from a given string

Parameters:
string, - the given string should be these two format: 1) str1.str2(no version) version=null; 2) str1.str2.str3, in this case version = str3; 3) other, vresion =null;
Throws:
java.lang.NumberFormatException

getDocIdFromAccessionNumber

public static java.lang.String getDocIdFromAccessionNumber(java.lang.String accessionNumber)
This method will get docid from an AccessionNumber. There is no assumption the accessnumber will be str1.str2.str3. It can be more. So we think the docid will be get rid of last part


getInlineDataIdWithoutRev

public static java.lang.String getInlineDataIdWithoutRev(java.lang.String accessionNumber)
This method will get inline data id without the revision number. So if inlineData.1.2 is passed as input, inlineData.2 is returned.


getSmartDocId

public static java.lang.String getSmartDocId(java.lang.String str)
This method will call both getDocIdFromString and getDocIdFromAccessionNumber. So first, if the string looks str1.str2, the docid will be str1.str2. If the string is str1.str2.str3, the docid will be str1.str2. If the string is str1.str2.str3.str4 or more, the docid will be str1.str2.str3. If the string look like str1, null will be returned


getRevisionFromAccessionNumber

public static int getRevisionFromAccessionNumber(java.lang.String accessionNumber)
                                          throws java.lang.NumberFormatException
This method will get revision from an AccessionNumber. There is no assumption the accessnumber will be str1.str2.str3. It can be more. So we think the docid will be get rid of last part

Throws:
java.lang.NumberFormatException

getLocalReplicationServerName

public static java.lang.String getLocalReplicationServerName()
Method to get the name of local replication server


getDocIdWithoutRevFromInlineDataID

public static java.lang.String getDocIdWithoutRevFromInlineDataID(java.lang.String inlineDataID)
Method to get docidwithrev from eml2 inline data id The eml inline data id would look like eml.200.2.3


reviseStack

public static java.util.Stack reviseStack(java.util.Stack stack)
Revise stack change a stack to opposite order


replaceWhiteSpaceForURL

public static java.lang.String replaceWhiteSpaceForURL(java.lang.String urlHasWhiteSpace)
A method to replace whitespace in url


getUserAccessControlLists

public static void getUserAccessControlLists()
A method to read administrators and moderators list from the metacat.properties


isAdministrator

public static boolean isAdministrator(java.lang.String username,
                                      java.lang.String[] groups)
A method to check if the specified user is part of the administrators list


isModerator

public static boolean isModerator(java.lang.String username,
                                  java.lang.String[] groups)
A method to check if the specified user is part of the moderators list


isAllowedSubmitter

public static boolean isAllowedSubmitter(java.lang.String username,
                                         java.lang.String[] groups)
A method to check if the specified user is part of the moderators list


isDeniedSubmitter

public static boolean isDeniedSubmitter(java.lang.String username,
                                        java.lang.String[] groups)
A method to check if the specified user is part of the moderators list


canInsertOrUpdate

public static boolean canInsertOrUpdate(java.lang.String username,
                                        java.lang.String[] groups)
A method to check if the specified user can insert the document


writeDebugToFile

public static void writeDebugToFile(java.lang.String debugInfo)
Writes debug information into a file. In metacat.properties, if property writeDebugToFile is set to true, the debug information will be written to debug file, which value is the property 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

writeTempFile

public static java.lang.String writeTempFile(com.oreilly.servlet.multipart.FilePart filePart,
                                             java.lang.String fileName)
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

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

addSkinConfig

public static void addSkinConfig(java.lang.String skinName,
                                 java.util.Properties skinProperties)
Adds the Properties and skin to the list of skin configurations.

Parameters:
skinName - String qformat
skinProperties - Properties instance

getSkinConfig

public static java.util.Properties getSkinConfig(java.lang.String skinName)
Return the Properties for a given skin name.

Parameters:
skinName - String qformat
Returns:
Properties, or null if none exist for the skin.

hasSkinConfig

public static boolean hasSkinConfig(java.lang.String skinName)
Returns true if Properties exist for a given skin name, false otherwise.

Parameters:
skinName - String qformat
Returns:
boolean


Copyright © 2000 National Center for Ecological Analysis and Synthesis. All Rights Reserved.