|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object fr.gouv.culture.sdx.utils.Utilities
public class Utilities
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.lang.String |
buildSuggestRegexValue(java.lang.String str)
Converts a string into a regular expression, using the encoding "ISO-8859-1". |
static java.lang.String |
buildSuggestRegexValue(java.lang.String string,
java.lang.String encoding)
Converts a string into a regular expression. |
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 |
---|
public Utilities()
Method Detail |
---|
public static java.io.File getSystemTempDir()
public static java.io.File checkDirectory(java.lang.String dirPath, org.apache.avalon.framework.logger.Logger logger) throws SDXException
dirPath
- The path for the directory to verify.logger
- Logger to use for error handling
SDXException
public static void checkDocument(org.apache.avalon.framework.logger.Logger logger, Document doc) throws SDXException
logger
- The super.getLog() for error handlingdoc
- The document object to verify
SDXException
- Thrown if the object is null, or its id is null
or an empty Stringpublic static void checkOutputStream(org.apache.avalon.framework.logger.Logger logger, java.io.OutputStream os) throws SDXException
logger
- The super.getLog() for error handlingos
- The OutputStream to verify
SDXException
public static void checkXmlConsumer(org.apache.avalon.framework.logger.Logger logger, org.apache.cocoon.xml.XMLConsumer consumer) throws SDXException
logger
- The super.getLog() for error handlingconsumer
- The XMLConsumer to verify
SDXException
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
logger
- Logger The super.getLog() if neededconfLocation
- String The location string from a configuration object, this way we can determine our current directory location, if neededcontext
- Context The application properties object, containing the path needed to find the filepath
- 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:
SDXException
public static boolean checkString(java.lang.String s)
s
- The string to verifypublic static java.util.Locale buildLocale(org.apache.avalon.framework.configuration.Configuration conf, java.util.Locale defaultLocale)
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.public static java.util.Locale buildLocale(java.lang.String xmlLang, java.lang.String variant, java.util.Locale defaultLocale)
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.public static java.lang.String attId(java.lang.String baseId, java.lang.String relId)
baseId
- the id of parent documentrelId
- an id relative to the parent document
public static java.net.URL attUrl(java.net.URL refURL, java.lang.String path) throws java.net.MalformedURLException
refURL
- a well-formed URLpath
- a path string it could be relative or absolute
java.net.MalformedURLException
public static java.lang.String getStringFromContext(java.lang.String key, org.apache.avalon.framework.context.Context context)
key
- The key for the string valuecontext
- The ContextKeys
public static java.lang.Object getObjectFromContext(java.lang.String key, org.apache.avalon.framework.context.Context context)
key
- The key for the string valuecontext
- The context
public static java.lang.String buildRmiName(java.lang.String rmiHost, int rmiPort, java.lang.String appId, java.lang.String dbId)
rmiHost
- The host name or ip address of the machinermiPort
- The port number for the rmi registryappId
- The id of the application to which the RemoteIndex belongsdbId
- The id of the document base to which the RemoteIndex belongs
public static RemoteIndex getRemoteIndex(org.apache.avalon.framework.logger.Logger logger, java.lang.String remoteIndexName) throws SDXException
SDXException
public static java.lang.String joinStrings(java.lang.String[] strings, java.lang.String delimiter)
strings
- The array of stringsdelimiter
- The delimiter, if none desired use null
null
if the array was null or emptypublic static Application getApplication(org.apache.avalon.framework.service.ServiceManager manager, org.apache.avalon.framework.context.Context context) throws SDXException
SDXException
public static java.lang.String encodeURL(java.lang.String url, java.lang.String encoding)
public static java.lang.String decodeURL(java.lang.String url, java.lang.String encoding)
public static java.lang.String prefixNodeNameSDX(java.lang.String elemName)
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
SDXException
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
org.apache.avalon.framework.configuration.ConfigurationException
public static void isObjectUnique(java.util.Hashtable objs, java.lang.String key, java.lang.Object obj) throws SDXException
SDXException
public static void isObjectUnique(org.apache.avalon.framework.context.Context objs, java.lang.String key, java.lang.Object obj) throws SDXException
SDXException
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
org.apache.avalon.framework.configuration.ConfigurationException
public static java.lang.String getElementName(java.lang.String classNameSuffix)
public static org.apache.avalon.framework.context.Context createNewReadOnlyContext(org.apache.avalon.framework.context.Context context)
public static org.apache.lucene.search.BooleanQuery newBooleanQuery()
public static boolean copyFile(java.io.File srcFile, java.io.File dstDir) throws java.io.IOException
java.io.IOException
public static void safeCopy(java.io.File src, java.io.File dst)
public static boolean isNameMatchIndexFiles(java.lang.String name)
public static java.lang.String replaceAllSubString(java.lang.String source, java.lang.String what, java.lang.String with)
public static java.lang.String buildSuggestRegexValue(java.lang.String string, java.lang.String encoding)
Converts a string into a regular expression suitable to search
a string regardless of diacritics.
Exemple: for "église", this method returns the regular expression
"[eéèêëgliseéèêë]".
string
- The string to convert in regular expressionencoding
- The encoding used to convert the string
public static java.lang.String buildSuggestRegexValue(java.lang.String str)
The
- String
to convert.
String
representation of the regular expression.buildSuggestRegexValue(String, String)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |