Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## fr.gouv.culture.sdx.utils
Class Utilities

    java.lang.Object
      fr.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 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 boolean` | `copyFile(java.io.File srcFile, java.io.File dstDir)`
`static org.apache.avalon.framework.context.Context` | `createNewReadOnlyContext(org.apache.avalon.framework.context.Context context)`
`static java.io.File` | `createTempDirectory(org.apache.avalon.framework.logger.Logger logger, java.lang.String prefix, java.lang.String suffix, java.io.File parentDir)`
`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.service.ServiceManager manager, org.apache.avalon.framework.context.Context context)`
`static java.lang.String` | `getElementName(java.lang.String classNameSuffix)`
`static java.lang.Object` | `getObjectForClassName(org.apache.avalon.framework.logger.Logger logger, java.lang.String fullClassName, java.lang.String packageNamePrefix, java.lang.String shortName, java.lang.String classNameSuffix)`
`static java.lang.Object` | `getObjectFromContext(java.lang.String key, org.apache.avalon.framework.context.Context context)` Return's a string value from a hashtable by making the appropriate cast
`static RemoteIndex` | `getRemoteIndex(org.apache.avalon.framework.logger.Logger logger, java.lang.String remoteIndexName)`
`static java.lang.String` | `getStringFromContext(java.lang.String key, org.apache.avalon.framework.context.Context context)` Return's a string value from a hashtable by making the appropriate cast
`static java.io.File` | `getSystemTempDir()`
`static boolean` | `isNameMatchIndexFiles(java.lang.String name)` Is the name given in parameter is a correct index file name?
`static void` | `isObjectUnique(org.apache.avalon.framework.context.Context objs, java.lang.String key, java.lang.Object obj)`
`static void` | `isObjectUnique(java.util.Hashtable objs, java.lang.String key, java.lang.Object obj)`
`static java.lang.String` | `joinStrings(java.lang.String[] strings, java.lang.String delimiter)` Joins an array of strings
`static org.apache.lucene.search.BooleanQuery` | `newBooleanQuery()`
`static java.lang.String` | `prefixNodeNameSDX(java.lang.String elemName)`
`static java.lang.String` | `replaceAllSubString(java.lang.String source, java.lang.String what, java.lang.String with)` Replace all the substring given in parameter by another substring
`static java.io.File` | `resolveFile(org.apache.avalon.framework.logger.Logger logger, java.lang.String confLocation, org.apache.avalon.framework.context.Context context, java.lang.String path, boolean isConfDirectory)` This method will attempt to verify if a file or a directory exists
`static void` | `safeCopy(java.io.File src, java.io.File dst)` Copy an index to an other in a safe and efficient mode try to do a rename to do a "cut and paste", or if failed try a copy and delete
`static SdxObject` | `setUpSdxObject(SdxObject sdxObj, org.apache.avalon.framework.logger.Logger logger, org.apache.avalon.framework.context.Context context, org.apache.avalon.framework.service.ServiceManager manager)`

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`

### 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 super.getLog() 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 super.getLog() 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 super.getLog() for error handling
    `consumer` - The XMLConsumer to verify
  Throws:
    `SDXException`

### resolveFile

    public static java.io.File resolveFile(org.apache.avalon.framework.logger.Logger logger,
                                           java.lang.String confLocation,
                                           org.apache.avalon.framework.context.Context context,
                                           java.lang.String path,
                                           boolean isConfDirectory)
                                    throws SDXException

  This method will attempt to verify if a file or a directory exists

  Parameters:
    `logger` - Logger The super.getLog() if needed
    `confLocation` - String The location string from a configuration object, this way we can determine our current directory location, if needed
    `context` - Context The application properties object, containing the path needed to find the file
    `path` - String The path of the document, absolute or relative to see below:
    `isConfDirectory` - boolean 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`

### getStringFromContext

    public static java.lang.String getStringFromContext(java.lang.String key,
                                                        org.apache.avalon.framework.context.Context context)

  Return's a string value from a hashtable by making the appropriate cast

  Parameters:
    `key` - The key for the string value
    `context` - The ContextKeys
  Returns:
    String

### getObjectFromContext

    public static java.lang.Object getObjectFromContext(java.lang.String key,
                                                        org.apache.avalon.framework.context.Context context)

  Return's a string value from a hashtable by making the appropriate cast

  Parameters:
    `key` - The key for the string value
    `context` - The context
  Returns:
    Object

### 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:
    String

### 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.service.ServiceManager manager,
                                             org.apache.avalon.framework.context.Context context)
                                      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)

### prefixNodeNameSDX

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

### createTempDirectory

    public static java.io.File createTempDirectory(org.apache.avalon.framework.logger.Logger logger,
                                                   java.lang.String prefix,
                                                   java.lang.String suffix,
                                                   java.io.File parentDir)
                                            throws SDXException

  Throws:
    `SDXException`

### setUpSdxObject

    public static SdxObject setUpSdxObject(SdxObject sdxObj,
                                           org.apache.avalon.framework.logger.Logger logger,
                                           org.apache.avalon.framework.context.Context context,
                                           org.apache.avalon.framework.service.ServiceManager manager)
                                    throws org.apache.avalon.framework.configuration.ConfigurationException

  Throws:
    `org.apache.avalon.framework.configuration.ConfigurationException`

### isObjectUnique

    public static void isObjectUnique(java.util.Hashtable objs,
                                      java.lang.String key,
                                      java.lang.Object obj)
                               throws SDXException

  Throws:
    `SDXException`

### isObjectUnique

    public static void isObjectUnique(org.apache.avalon.framework.context.Context objs,
                                      java.lang.String key,
                                      java.lang.Object obj)
                               throws SDXException

  Throws:
    `SDXException`

### getObjectForClassName

    public static java.lang.Object getObjectForClassName(org.apache.avalon.framework.logger.Logger logger,
                                                         java.lang.String fullClassName,
                                                         java.lang.String packageNamePrefix,
                                                         java.lang.String shortName,
                                                         java.lang.String classNameSuffix)
                                                  throws org.apache.avalon.framework.configuration.ConfigurationException

  Throws:
    `org.apache.avalon.framework.configuration.ConfigurationException`

### getElementName

    public static java.lang.String getElementName(java.lang.String classNameSuffix)

### createNewReadOnlyContext

    public static org.apache.avalon.framework.context.Context createNewReadOnlyContext(org.apache.avalon.framework.context.Context context)

### newBooleanQuery

    public static org.apache.lucene.search.BooleanQuery newBooleanQuery()

### copyFile

    public static boolean copyFile(java.io.File srcFile,
                                   java.io.File dstDir)
                            throws java.io.IOException

  Throws:
    `java.io.IOException`

### safeCopy

    public static void safeCopy(java.io.File src,
                                java.io.File dst)

  Copy an index to an other in a safe and efficient mode try to do a rename to do a "cut and paste", or if failed try a copy and delete

### isNameMatchIndexFiles

    public static boolean isNameMatchIndexFiles(java.lang.String name)

  Is the name given in parameter is a correct index file name?

### replaceAllSubString

    public static java.lang.String replaceAllSubString(java.lang.String source,
                                                       java.lang.String what,
                                                       java.lang.String with)

  Replace all the substring given in parameter by another substring

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

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