fr.gouv.culture.sdx.utils
Class Utilities

java.lang.Object
  extended byfr.gouv.culture.sdx.utils.Utilities

public class Utilities
extends java.lang.Object

Useful programming utilities for SDX. Contains some useful static methods.


Constructor Summary
Utilities()
           
 
Method Summary
static java.lang.String attId(java.lang.String baseId, java.lang.String relId)
          Build an id for an attached document from : the parent document id (@refId) a name unique relatively to the parent document (@relId) Used to store and attach files to a parent document (example: images)
static java.net.URL attUrl(java.net.URL refURL, java.lang.String path)
          Build an URL for an attached document from : the parent document URL (@refURL) a path relative to the parent document (@path) Used for relative URL like in an HTML document
static java.util.Locale buildLocale(org.apache.avalon.framework.configuration.Configuration conf, java.util.Locale defaultLocale)
          Returns a locale from a configuration object
static java.util.Locale buildLocale(java.lang.String xmlLang, java.lang.String variant, java.util.Locale defaultLocale)
          Returns a locale from a String
static java.lang.String buildRmiName(java.lang.String rmiHost, int rmiPort, java.lang.String appId, java.lang.String dbId)
          Builds a rmi url string for RemoteIndex lookups
static void checkConfAttributeValue(java.lang.String attName, java.lang.String attValue, java.lang.String attLocation)
          Verifies a configuration attribute value, ie it should not be null or an empty String
static void checkConfiguration(org.apache.avalon.framework.configuration.Configuration configuration)
          Verifies a configuration object
static java.io.File checkDirectory(java.lang.String dirPath, org.apache.avalon.framework.logger.Logger logger)
          Verifies if a given directory exists, if not the directory is created.
static void checkDocument(org.apache.avalon.framework.logger.Logger logger, Document doc)
          Checks a document to ensure the object is not null and that it's id is not null or an empty string
static void checkOutputStream(org.apache.avalon.framework.logger.Logger logger, java.io.OutputStream os)
          Verifies that an OutputStream is not null
static boolean checkString(java.lang.String s)
          Returns true if a string is not null or empty
static void checkXmlConsumer(org.apache.avalon.framework.logger.Logger logger, org.apache.cocoon.xml.XMLConsumer consumer)
          Verifies that an XMLConsumer is not null
static FieldsDefinition configureFieldList(org.apache.avalon.framework.logger.Logger logger, org.apache.avalon.framework.configuration.Configuration configuration, java.util.Hashtable props)
           
static Repository createRepository(org.apache.avalon.framework.configuration.Configuration repoConf, org.apache.avalon.framework.component.ComponentManager manager, java.util.Hashtable props, org.apache.avalon.framework.logger.Logger logger)
          Used to create a repository based upon a 'type' attribute
static java.lang.String decodeURL(java.lang.String url, java.lang.String encoding)
           
static java.lang.String encodeURL(java.lang.String url, java.lang.String encoding)
           
static Application getApplication(org.apache.avalon.framework.component.ComponentManager manager, java.util.Hashtable props)
           
static RemoteIndex getRemoteIndex(org.apache.avalon.framework.logger.Logger logger, java.lang.String remoteIndexName)
           
static java.lang.String getStringFromHashtable(java.lang.String key, java.util.Hashtable table)
          Return's a string value from a hashtable by making the appropriate cast
static java.io.File getSystemTempDir()
           
static java.lang.String joinStrings(java.lang.String[] strings, java.lang.String delimiter)
          Joins an array of strings
static void logDebug(org.apache.avalon.framework.logger.Logger logger, java.lang.String s, java.lang.Exception e)
          Verifies the logger and logs a message
static void logError(org.apache.avalon.framework.logger.Logger logger, java.lang.String s, java.lang.Exception e)
          Verifies the logger and logs a message
static void logException(org.apache.avalon.framework.logger.Logger logger, java.lang.Exception e)
          Verifies the logger and logs an exception
static void logInfo(org.apache.avalon.framework.logger.Logger logger, java.lang.String s)
          Verifies the logger and logs a message
static void logWarn(org.apache.avalon.framework.logger.Logger logger, java.lang.String s, java.lang.Exception e)
          Verifies the logger and logs a message
static java.lang.String prefixNodeNameSDX(java.lang.String elemName)
           
static java.io.File resolveFile(org.apache.avalon.framework.logger.Logger logger, java.lang.String confLocation, java.util.Hashtable props, java.lang.String path, boolean isConfDirectory)
          This method will attempt to verify if a file exists
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Utilities

public Utilities()
Method Detail

getSystemTempDir

public static java.io.File getSystemTempDir()

checkDirectory

public static java.io.File checkDirectory(java.lang.String dirPath,
                                          org.apache.avalon.framework.logger.Logger logger)
                                   throws SDXException
Verifies if a given directory exists, if not the directory is created.

Parameters:
dirPath - The path for the directory to verify.
logger - Logger to use for error handling
Throws:
SDXException

createRepository

public static Repository createRepository(org.apache.avalon.framework.configuration.Configuration repoConf,
                                          org.apache.avalon.framework.component.ComponentManager manager,
                                          java.util.Hashtable props,
                                          org.apache.avalon.framework.logger.Logger logger)
                                   throws SDXException,
                                          org.apache.avalon.framework.configuration.ConfigurationException
Used to create a repository based upon a 'type' attribute

Parameters:
repoConf - The configuration object made up of an 'repository' element.
manager - The component manager to pass to the repository
props - The properties object to pass to the repository
logger - The logger to pass to the repository and for error handling
Throws:
SDXException
org.apache.avalon.framework.configuration.ConfigurationException

logInfo

public static void logInfo(org.apache.avalon.framework.logger.Logger logger,
                           java.lang.String s)
Verifies the logger and logs a message

Parameters:
logger - The logger
s - The message

logDebug

public static void logDebug(org.apache.avalon.framework.logger.Logger logger,
                            java.lang.String s,
                            java.lang.Exception e)
Verifies the logger and logs a message

Parameters:
logger - The logger
s - The message (maybe null)
e - The exception (maybe null)

logError

public static void logError(org.apache.avalon.framework.logger.Logger logger,
                            java.lang.String s,
                            java.lang.Exception e)
Verifies the logger and logs a message

Parameters:
logger - The logger
s - The message (maybe null)
e - The exception (maybe null)

logWarn

public static void logWarn(org.apache.avalon.framework.logger.Logger logger,
                           java.lang.String s,
                           java.lang.Exception e)
Verifies the logger and logs a message

Parameters:
logger - The logger
s - The message (maybe null)
e - The exception (maybe null)

logException

public static void logException(org.apache.avalon.framework.logger.Logger logger,
                                java.lang.Exception e)
Verifies the logger and logs an exception

Parameters:
logger - The logger
e - The exception (maybe null)

checkDocument

public static void checkDocument(org.apache.avalon.framework.logger.Logger logger,
                                 Document doc)
                          throws SDXException
Checks a document to ensure the object is not null and that it's id is not null or an empty string

Parameters:
logger - The logger for error handling
doc - The document object to verify
Throws:
SDXException - Thrown if the object is null, or its id is null or an empty String

checkOutputStream

public static void checkOutputStream(org.apache.avalon.framework.logger.Logger logger,
                                     java.io.OutputStream os)
                              throws SDXException
Verifies that an OutputStream is not null

Parameters:
logger - The logger for error handling
os - The OutputStream to verify
Throws:
SDXException

checkXmlConsumer

public static void checkXmlConsumer(org.apache.avalon.framework.logger.Logger logger,
                                    org.apache.cocoon.xml.XMLConsumer consumer)
                             throws SDXException
Verifies that an XMLConsumer is not null

Parameters:
logger - The logger for error handling
consumer - The XMLConsumer to verify
Throws:
SDXException

checkConfiguration

public static void checkConfiguration(org.apache.avalon.framework.configuration.Configuration configuration)
                               throws org.apache.avalon.framework.configuration.ConfigurationException
Verifies a configuration object

Parameters:
configuration - The object to verify
Throws:
org.apache.avalon.framework.configuration.ConfigurationException - Thrown if the object is null

checkConfAttributeValue

public static void checkConfAttributeValue(java.lang.String attName,
                                           java.lang.String attValue,
                                           java.lang.String attLocation)
                                    throws org.apache.avalon.framework.configuration.ConfigurationException
Verifies a configuration attribute value, ie it should not be null or an empty String

Parameters:
attName - The name of the attribute
attValue - The value of the attribute
attLocation - The location of the configuration object
Throws:
org.apache.avalon.framework.configuration.ConfigurationException - Thrown if null or an empty String

resolveFile

public static java.io.File resolveFile(org.apache.avalon.framework.logger.Logger logger,
                                       java.lang.String confLocation,
                                       java.util.Hashtable props,
                                       java.lang.String path,
                                       boolean isConfDirectory)
                                throws SDXException
This method will attempt to verify if a file exists

Parameters:
logger - The logger if needed
confLocation - The location string from a configuration object, this way we can determine our current directory location, if needed
props - The application properties object, containing the path needed to find the file
path - The path of the document, absolute or relative to see below:
isConfDirectory - Indicates whether the file trying to be resolved could be a non-existent FSRepository base directory, if so we would like to create it

This method will attempt to do this in the following order:

1)build a file object using the absolute file path, "file:/..."

2)a file object using the base path of the web application directory and the relative path provided, must begin with a "/"

3)a file object using the base path of the current directory (sdx configuration directory or the application configuration directory) and the relative path provided, could be something like: "../dir1/dir2/file.extension" or "dir1/file.extension", etc.

Returns:
A File object for the file if we are able to build a correct path to the existing file
Throws:
SDXException

checkString

public static boolean checkString(java.lang.String s)
Returns true if a string is not null or empty

Parameters:
s - The string to verify

buildLocale

public static java.util.Locale buildLocale(org.apache.avalon.framework.configuration.Configuration conf,
                                           java.util.Locale defaultLocale)
Returns a locale from a configuration object

Parameters:
conf - The configuration object for the element which contains the "xml:lang" attribute with an optional "variant" attribute.
defaultLocale - A default locale to use if the building of the local fails if a null defaultLocale is passed, the system default is used.

buildLocale

public static java.util.Locale buildLocale(java.lang.String xmlLang,
                                           java.lang.String variant,
                                           java.util.Locale defaultLocale)
Returns a locale from a String

Parameters:
xmlLang - A valid xml:lang attribute value.
variant - A variant from the Java specs,can be null
defaultLocale - A default locale to use if the building of the local fails if a null defaultLocale is passed, the system default is used.

attId

public static java.lang.String attId(java.lang.String baseId,
                                     java.lang.String relId)
Build an id for an attached document from : the parent document id (@refId) a name unique relatively to the parent document (@relId) Used to store and attach files to a parent document (example: images)

Parameters:
baseId - the id of parent document
relId - an id relative to the parent document
Returns:
an id surely unique in scope of a document base

attUrl

public static java.net.URL attUrl(java.net.URL refURL,
                                  java.lang.String path)
                           throws java.net.MalformedURLException
Build an URL for an attached document from : the parent document URL (@refURL) a path relative to the parent document (@path) Used for relative URL like in an HTML document

Parameters:
refURL - a well-formed URL
path - a path string it could be relative or absolute
Returns:
a URL for a
Throws:
java.net.MalformedURLException

getStringFromHashtable

public static java.lang.String getStringFromHashtable(java.lang.String key,
                                                      java.util.Hashtable table)
Return's a string value from a hashtable by making the appropriate cast

Parameters:
key - The key for the string value
table - The hashtable
Returns:

buildRmiName

public static java.lang.String buildRmiName(java.lang.String rmiHost,
                                            int rmiPort,
                                            java.lang.String appId,
                                            java.lang.String dbId)
Builds a rmi url string for RemoteIndex lookups

Parameters:
rmiHost - The host name or ip address of the machine
rmiPort - The port number for the rmi registry
appId - The id of the application to which the RemoteIndex belongs
dbId - The id of the document base to which the RemoteIndex belongs
Returns:

getRemoteIndex

public static RemoteIndex getRemoteIndex(org.apache.avalon.framework.logger.Logger logger,
                                         java.lang.String remoteIndexName)
                                  throws SDXException
Throws:
SDXException

joinStrings

public static java.lang.String joinStrings(java.lang.String[] strings,
                                           java.lang.String delimiter)
Joins an array of strings

Parameters:
strings - The array of strings
delimiter - The delimiter, if none desired use null
Returns:
The joined string, or null if the array was null or empty

getApplication

public static Application getApplication(org.apache.avalon.framework.component.ComponentManager manager,
                                         java.util.Hashtable props)
                                  throws SDXException
Throws:
SDXException

encodeURL

public static java.lang.String encodeURL(java.lang.String url,
                                         java.lang.String encoding)

decodeURL

public static java.lang.String decodeURL(java.lang.String url,
                                         java.lang.String encoding)

configureFieldList

public static FieldsDefinition configureFieldList(org.apache.avalon.framework.logger.Logger logger,
                                                  org.apache.avalon.framework.configuration.Configuration configuration,
                                                  java.util.Hashtable props)
                                           throws org.apache.avalon.framework.configuration.ConfigurationException
Throws:
org.apache.avalon.framework.configuration.ConfigurationException

prefixNodeNameSDX

public static java.lang.String prefixNodeNameSDX(java.lang.String elemName)


Copyright © 2000-2004 Ministere de la culture et de la communication / AJLSM. All Rights Reserved.