com.flexive.shared
Class FxSharedUtils

java.lang.Object
  extended by com.flexive.shared.FxSharedUtils

public final class FxSharedUtils
extends java.lang.Object

Flexive shared utility functions.

Author:
Markus Plesser (markus.plesser@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)

Nested Class Summary
static class FxSharedUtils.AssignmentPositionSorter
          Comparator for sorting Assignments according to their position.
(package private) static class FxSharedUtils.AsyncStreamBuffer
          Helper thread to asynchronously read and buffer an InputStream
static class FxSharedUtils.BundleReference
          A resource bundle reference.
static class FxSharedUtils.ItemLabelSorter
          Item sorter by label
static class FxSharedUtils.ItemPositionSorter
          Item sorter by position
static class FxSharedUtils.MessageKey
          Resource message key for caching
static interface FxSharedUtils.ParameterMapper<K,V>
          Maps keys to values.
static class FxSharedUtils.ProcessResult
          Helperclass holding the result of the executeCommand method
static class FxSharedUtils.SelectableObjectSorter
          Comparator for sorting SelectableObjectWithName instances by ID.
static class FxSharedUtils.SelectableObjectWithLabelSorter
          Comparator for sorting SelectableObjectWithLabel instances by label.
static class FxSharedUtils.SelectableObjectWithNameSorter
          Comparator for sorting SelectableObjectWithName instances by name.
static class FxSharedUtils.SQLExecutor
          An SQL executor, similar to ant's sql task An important addition are raw blocks: lines starting with '-- @START@' indicate the start of a raw block and lines starting with '-- @END@' indicate the end of a raw block.
 
Field Summary
static java.lang.String COOKIE_FORCE_TEST_DIVISION
          Browser tests set this cookie to force using the test division instead of the actual division defined by the URL domain.
static java.lang.String FLEXIVE_DROP_PROPERTIES
           
static java.lang.String FLEXIVE_STORAGE_PROPERTIES
           
static java.lang.String PROP_RUNONCE_MINIMAL
          System property to force a minimum set of runonce scripts when set (e.g.
static java.lang.String SHARED_BUNDLE
          Shared message resources bundle
static boolean WINDOWS
           
static java.lang.String XPATH_ENCODEDSLASH
          The character(s) representing a "xpath slash" (/) in a public URL.
 
Method Summary
static java.util.List<FxSharedUtils.BundleReference> addMessageResources(java.lang.String baseName)
          Add a resource reference for the given resource base name.
static
<T extends FxAssignment>
boolean
checkAssignmentInherited(T assignment)
          This method checks if the current assignment is a derived assignment subject to the following conditions: 1.) must be assigned to a derived type 2.) must be inherited from the derived type's parent 3.) XPaths must match
static void checkParameterEmpty(java.lang.Object value, java.lang.String parameterName)
          Check if the given value is empty (empty string or null for String objects, empty collection, null for other objects) and throw an exception if empty.
static void checkParameterMultilang(FxValue value, java.lang.String paramName)
          Check if the given parameter is multilingual and throw an exception if not
static void checkParameterNull(java.lang.Object value, java.lang.String parameterName)
          Check if the given value is empty (empty string or null for String objects, empty collection, null for other objects) and throw an exception if empty.
static void close(java.io.Closeable... resources)
          Close the given resources and log a warning message if closing fails.
static int compare(int i1, int i2)
          Primitive int comparison method (when JDK7's Integer#compare cannot be used).
static int compare(long i1, long i2)
          Primitive long comparison method (when JDK7's Long#compare cannot be used).
static java.lang.String decodeXPath(java.lang.String escapedXPath)
          Decodes a previously escaped XPath.
static java.lang.String escapePath(java.lang.String path)
          Escape a path for usage on the current operating systems shell
static java.lang.String escapeXPath(java.lang.String xpath)
          Escapes the given XPath for use in a public URI.
static FxSharedUtils.ProcessResult executeCommand(java.lang.String command, java.lang.String... arguments)
          Execute a command on the operating system
static
<T extends SelectableObject>
java.util.List<T>
filterSelectableObjectsById(java.lang.Iterable<T> values, java.util.Collection<java.lang.Long> ids)
          Return the elements of values that match the given ids.
static
<T extends SelectableObjectWithName>
java.util.List<T>
filterSelectableObjectsByName(java.lang.Iterable<T> values, java.util.Collection<java.lang.String> names)
          Return the elements of values that match the given names.
static
<K,V> V
get(java.util.Map<K,V> map, K key, V defaultValue)
          Returns map.get(key) if key exists, defaultValue otherwise.
static java.lang.String getApplicationServerName()
          Get the name of the application server [fleXive] is running on
static java.lang.String getBuildDate()
          Get the date flexive was compiled
static java.lang.String getBuildNumber()
          Get the subversion build number
static java.lang.String getBuildUser()
          Get the name of the user that built flexive
static java.lang.String getBundledGroovyVersion()
          Get the version of the bundled groovy runtime
static byte[] getBytes(java.lang.String s)
          Returns the UTF-8 byte representation of the given string.
static java.text.Collator getCollator()
          Returns a collator for the calling user's locale.
static int getColumnIndex(java.util.List<java.lang.String> columnNames, java.lang.String name)
          Return the index of the given column name.
static int getColumnIndex(java.lang.String[] columnNames, java.lang.String name)
          Return the index of the given column name.
static java.util.Map<java.lang.String,java.lang.String> getContentsFromJarStream(java.util.jar.JarInputStream jarStream, java.lang.String searchPattern, boolean isFile)
          This method returns all entries in a JarInputStream for a given search pattern within the jar as a Map having the filename as the key and the file content as its respective value (String).
static long getDBVersion()
          Get the database version
static FxDropApplication getDropApplication(java.lang.String name)
          Returns the drop application with the given name.
static java.util.List<FxDropApplication> getDropApplications()
          Get a list of all installed and deployed drops.
static java.util.List<java.lang.String> getDrops()
          Get a list of all installed and deployed drops
static java.lang.String getEmptyResultMessage()
          Returns the localized "empty" message for empty result fields
static FxString getEnumLabel(java.lang.Enum<?> value, java.lang.Object... args)
          Returns the localized label for the given enum value.
static java.util.List<java.lang.String> getEnumNames(java.util.Collection<? extends java.lang.Enum> values)
          Extracts the names of the given enum elements and returns them as string.
static java.lang.String getFlexiveEdition()
          Get the name of this flexive edition
static java.lang.String getFlexiveEditionFull()
          Get the name of this flexive edition with the product name
static java.lang.String getFlexiveVersion()
          Get the flexive version
static java.lang.String getHeader()
          Get the default html header title
static java.lang.String getHostName()
          Get the current hosts name
static java.lang.String getLocalizedMessage(java.lang.String resourceBundle, long localeId, java.lang.String localeIso, java.lang.String key, java.lang.Object... args)
          Get the localized message for a given language code and ISO
static
<K,V> java.util.Map<K,V>
getMappedFunction(FxSharedUtils.ParameterMapper<K,V> mapper)
          Projects a single-parameter function on a hashmap.
static
<K,V> java.util.Map<K,V>
getMappedFunction(FxSharedUtils.ParameterMapper<K,V> mapper, boolean cacheResults)
          Projects a single-parameter function on a hashmap.
static java.lang.String getMD5Sum(java.io.File file)
          Calculate an MD5 checksum for a file
static FxString getMessage(java.lang.String resourceBundle, java.lang.String key, java.lang.Object... args)
          Returns a multilingual FxString with all translations for the given property key.
static java.lang.String getNodeId()
           
static java.io.InputStream getResourceStream(java.lang.String name)
          Get the named resource from the current thread's classloader
static
<T extends SelectableObject>
T
getSelectableObject(java.util.List<T> values, long id)
          Return a SelectableObject by its ID.
static java.util.List<java.lang.Long> getSelectableObjectIdList(java.lang.Iterable<? extends SelectableObject> values)
          Extract the unique IDs of the given SelectableObject collection.
static java.util.List<java.lang.String> getSelectableObjectNameList(java.lang.Iterable<? extends SelectableObjectWithName> values)
          Extract the unique names of the given SelectableObject collection.
static java.util.List<java.lang.String> getStorageImplementations()
          Scan all flexive storage implementations to get the name of the factory classes
static java.util.Map<java.lang.String,java.lang.String> getStorageScriptResources(java.lang.String storageVendor)
          Add all resources found in the resource subfolder for the requested vendor to the map (key=script name, value=script code)
static java.util.List<java.lang.String> getTranslatedLocales()
          Returns the list of translated locales, as specified in flexive.properties (flexive.translatedLocales).
static java.util.List<StepDefinition> getUsedStepDefinitions(java.util.List<? extends Step> steps, java.util.List<? extends StepDefinition> stepDefinitions)
          Returns a list of all used step definitions for the given steps
static java.lang.String hashPassword(long accountId, java.lang.String password)
          Compute the hash of the given flexive password, using the user ID.
static java.lang.String hashPassword(long accountId, java.lang.String loginName, java.lang.String password)
          Compute the hash of the given password according to the setting in SystemParameters.PASSWORD_SALT_METHOD (either with the user ID, or the user name).
static java.lang.String hashPassword(java.lang.String loginName, java.lang.String password)
          Compute the hash of the given flexive password using the login name.
static int indexOfSelectableObject(java.util.List<? extends SelectableObject> values, long id)
          Returns the index of the SelectableObject with the given ID, or -1 if none was found.
static boolean isGroovyScript(java.lang.String name)
          Is the script (most likely) a groovy script?
static boolean isMinimalRunOnceScripts()
           
static boolean isQuoted(java.lang.String value, char quoteChar)
          Returns true if the given string value is quoted with the given character (e.g.
static boolean isSnapshotVersion()
          Returns true if this instance is a -SNAPSHOT version.
static boolean isTranslatedLocale(java.lang.String localeIsoCode)
          Returns true if the given locale is localized in the flexive application (compile-time parameter flexive.translatedLocales set in flexive.properties).
static java.lang.String loadFile(java.io.File file)
          Load the contents of a file, returning it as a String.
static java.lang.String loadFromInputStream(java.io.InputStream in)
          Load a String from an InputStream (until end of stream)
static java.lang.String loadFromInputStream(java.io.InputStream in, int length)
          Load a String from an InputStream (until end of stream)
static java.lang.String lookupResource(java.lang.String resourceBundle, java.lang.String key, java.lang.String localeIso)
          Try to find a localized resource messages
static java.lang.String readFromJarEntry(java.util.jar.JarInputStream jarStream, java.util.jar.JarEntry entry)
          Reads the content of a given entry in a Jar file (JarInputStream) and returns it as a String
static java.lang.String sha1Hash(byte[] bytes)
          Creates a SHA-1 hash for the given data and returns it in hexadecimal string encoding.
static java.lang.String[] splitLiterals(java.lang.String text)
          Splits the given comma-separated text.
static java.lang.String[] splitLiterals(java.lang.String text, char[] stringDelims, char separator)
          Splits the given text using separator.
static boolean storeFile(java.lang.String contents, java.io.File file)
          Rather primitive "write String to file" helper, returns false if failed
static java.lang.String stripQuotes(java.lang.String value, char quoteChar)
          Strips the quotes from the given string if it is quoted, otherwise it returns the input value itself.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SHARED_BUNDLE

public static final java.lang.String SHARED_BUNDLE
Shared message resources bundle

See Also:
Constant Field Values

XPATH_ENCODEDSLASH

public static final java.lang.String XPATH_ENCODEDSLASH
The character(s) representing a "xpath slash" (/) in a public URL.

See Also:
Constant Field Values

COOKIE_FORCE_TEST_DIVISION

public static final java.lang.String COOKIE_FORCE_TEST_DIVISION
Browser tests set this cookie to force using the test division instead of the actual division defined by the URL domain. TODO: security?

See Also:
Constant Field Values

WINDOWS

public static final boolean WINDOWS

FLEXIVE_DROP_PROPERTIES

public static final java.lang.String FLEXIVE_DROP_PROPERTIES
See Also:
Constant Field Values

FLEXIVE_STORAGE_PROPERTIES

public static final java.lang.String FLEXIVE_STORAGE_PROPERTIES
See Also:
Constant Field Values

PROP_RUNONCE_MINIMAL

public static final java.lang.String PROP_RUNONCE_MINIMAL
System property to force a minimum set of runonce scripts when set (e.g. UI icons are not installed). This should not be enabled for flexive's own test suite, but for tests in external projects that can assume that the stock run-once scripts work.

See Also:
Constant Field Values
Method Detail

getHostName

public static java.lang.String getHostName()
Get the current hosts name

Returns:
current hosts name
Since:
3.1

getApplicationServerName

public static java.lang.String getApplicationServerName()
Get the name of the application server [fleXive] is running on

Returns:
name of the application server [fleXive] is running on
Since:
3.1

getResourceStream

public static java.io.InputStream getResourceStream(java.lang.String name)
Get the named resource from the current thread's classloader

Parameters:
name - name of the resource
Returns:
inputstream for the resource

getContentsFromJarStream

public static java.util.Map<java.lang.String,java.lang.String> getContentsFromJarStream(java.util.jar.JarInputStream jarStream,
                                                                                        java.lang.String searchPattern,
                                                                                        boolean isFile)
                                                                                 throws java.io.IOException
This method returns all entries in a JarInputStream for a given search pattern within the jar as a Map having the filename as the key and the file content as its respective value (String). The boolean flag "isFile" marks the search pattern as a file, otherwise the pattern will be treated as a path to be found in the jarStream A successful search either returns a map of all entries for a given path or a map of all entries for a given file (again, depending on the "isFile" flag). Null will be returned if no occurrences of the search pattern were found.

Parameters:
jarStream - the given JarInputStream
searchPattern - the pattern to be examined as a String
isFile - if true, the searchPattern is treated as a file name, if false, the searchPattern will be treated as a path
Returns:
Returns all entries found for the given search pattern as a Map, or null if no matches were found
Throws:
java.io.IOException - on I/O errors

readFromJarEntry

public static java.lang.String readFromJarEntry(java.util.jar.JarInputStream jarStream,
                                                java.util.jar.JarEntry entry)
                                         throws java.io.IOException
Reads the content of a given entry in a Jar file (JarInputStream) and returns it as a String

Parameters:
jarStream - the given JarInputStream
entry - the given entry in the jar file
Returns:
the entry's content as a String
Throws:
java.io.IOException - on errors

getDrops

public static java.util.List<java.lang.String> getDrops()
Get a list of all installed and deployed drops

Returns:
list of all installed and deployed drops

getDropApplications

public static java.util.List<FxDropApplication> getDropApplications()
Get a list of all installed and deployed drops.

Returns:
a list of all installed and deployed drops.
Since:
3.0.2

getDropApplication

public static FxDropApplication getDropApplication(java.lang.String name)
Returns the drop application with the given name.

Parameters:
name - the application name
Returns:
the drop application with the given name.
Since:
3.0.2

getStorageImplementations

public static java.util.List<java.lang.String> getStorageImplementations()
Scan all flexive storage implementations to get the name of the factory classes

Returns:
list containing the name of all storage factory classes

getStorageScriptResources

public static java.util.Map<java.lang.String,java.lang.String> getStorageScriptResources(java.lang.String storageVendor)
Add all resources found in the resource subfolder for the requested vendor to the map (key=script name, value=script code)

Parameters:
storageVendor - requested vendor
Returns:
map with key=script name and value=script code

getColumnIndex

public static int getColumnIndex(java.lang.String[] columnNames,
                                 java.lang.String name)
Return the index of the given column name. If name has no prefix (e.g. "co."), then only a suffix match is performed (e.g. "name" matches "co.name" or "abc.name", whichever comes first.)

Parameters:
columnNames - all column names to be searched
name - the requested column name
Returns:
the 1-based index of the given column, or -1 if it does not exist

getColumnIndex

public static int getColumnIndex(java.util.List<java.lang.String> columnNames,
                                 java.lang.String name)
Return the index of the given column name. If name has no prefix (e.g. "co."), then only a suffix match is performed (e.g. "name" matches "co.name" or "abc.name", whichever comes first.)

Parameters:
columnNames - all column names to be searched
name - the requested column name
Returns:
the 1-based index of the given column, or -1 if it does not exist

hashPassword

public static java.lang.String hashPassword(long accountId,
                                            java.lang.String password)
Compute the hash of the given flexive password, using the user ID.

Parameters:
accountId - the user account ID
password - the cleartext password
Returns:
a hashed password

hashPassword

public static java.lang.String hashPassword(java.lang.String loginName,
                                            java.lang.String password)
Compute the hash of the given flexive password using the login name. This is the default algorithm for installations since flexive 3.1.6.

Parameters:
loginName - the user login name
password - the cleartext password
Returns:
the hashed password
Since:
3.1.6

hashPassword

public static java.lang.String hashPassword(long accountId,
                                            java.lang.String loginName,
                                            java.lang.String password)
Compute the hash of the given password according to the setting in SystemParameters.PASSWORD_SALT_METHOD (either with the user ID, or the user name).

Parameters:
accountId - the user account ID
loginName - the login name
password - the cleartext password
Returns:
the hashed password
Since:
3.1.6

getCollator

public static java.text.Collator getCollator()
Returns a collator for the calling user's locale.

Returns:
a collator for the calling user's locale.

isGroovyScript

public static boolean isGroovyScript(java.lang.String name)
Is the script (most likely) a groovy script?

Parameters:
name - script name to check
Returns:
if this script could be a groovy script

checkParameterMultilang

public static void checkParameterMultilang(FxValue value,
                                           java.lang.String paramName)
Check if the given parameter is multilingual and throw an exception if not

Parameters:
value - the value to check
paramName - name of the parameter

sha1Hash

public static java.lang.String sha1Hash(byte[] bytes)
                                 throws java.security.NoSuchAlgorithmException
Creates a SHA-1 hash for the given data and returns it in hexadecimal string encoding.

Parameters:
bytes - data to be hashed
Returns:
hex-encoded hash
Throws:
java.security.NoSuchAlgorithmException - if the SHA-1 provider does not exist

getMD5Sum

public static java.lang.String getMD5Sum(java.io.File file)
Calculate an MD5 checksum for a file

Parameters:
file - file to calculate checksum for
Returns:
MD5 checksum (16 characters)

executeCommand

public static FxSharedUtils.ProcessResult executeCommand(java.lang.String command,
                                                         java.lang.String... arguments)
Execute a command on the operating system

Parameters:
command - name of the command
arguments - arguments to pass to the command (one argument per String!)
Returns:
result

loadFile

public static java.lang.String loadFile(java.io.File file)
Load the contents of a file, returning it as a String. This method should only be used when really necessary since no real error handling is performed!!!

Parameters:
file - the File to load
Returns:
file contents

loadFromInputStream

public static java.lang.String loadFromInputStream(java.io.InputStream in)
Load a String from an InputStream (until end of stream)

Parameters:
in - InputStream
Returns:
the input stream contents, or an empty string if in was null.
Since:
3.0.2

loadFromInputStream

public static java.lang.String loadFromInputStream(java.io.InputStream in,
                                                   int length)
Load a String from an InputStream (until end of stream)

Parameters:
in - InputStream
length - length of the string if > -1 (NOT number of bytes to read!)
Returns:
the input stream contents, or an empty string if in was null.

storeFile

public static boolean storeFile(java.lang.String contents,
                                java.io.File file)
Rather primitive "write String to file" helper, returns false if failed

Parameters:
contents - the String to store
file - the file, if existing it will be overwritten
Returns:
if successful

getFlexiveVersion

public static java.lang.String getFlexiveVersion()
Get the flexive version

Returns:
flexive version

isSnapshotVersion

public static boolean isSnapshotVersion()
Returns true if this instance is a -SNAPSHOT version.

Returns:
true if this instance is a -SNAPSHOT version.
Since:
3.1

getBuildNumber

public static java.lang.String getBuildNumber()
Get the subversion build number

Returns:
subversion build number

getDBVersion

public static long getDBVersion()
Get the database version

Returns:
database version

getBuildDate

public static java.lang.String getBuildDate()
Get the date flexive was compiled

Returns:
compile date

getFlexiveEdition

public static java.lang.String getFlexiveEdition()
Get the name of this flexive edition

Returns:
flexive edition

getFlexiveEditionFull

public static java.lang.String getFlexiveEditionFull()
Get the name of this flexive edition with the product name

Returns:
flexive edition with product name

getBuildUser

public static java.lang.String getBuildUser()
Get the name of the user that built flexive

Returns:
build user

getHeader

public static java.lang.String getHeader()
Get the default html header title

Returns:
html header title

getBundledGroovyVersion

public static java.lang.String getBundledGroovyVersion()
Get the version of the bundled groovy runtime

Returns:
version of the bundled groovy runtime

getEmptyResultMessage

public static java.lang.String getEmptyResultMessage()
Returns the localized "empty" message for empty result fields

Returns:
the localized "empty" message for empty result fields

checkParameterNull

public static void checkParameterNull(java.lang.Object value,
                                      java.lang.String parameterName)
Check if the given value is empty (empty string or null for String objects, empty collection, null for other objects) and throw an exception if empty.

Parameters:
value - value to check
parameterName - name of the value (for the exception)

checkParameterEmpty

public static void checkParameterEmpty(java.lang.Object value,
                                       java.lang.String parameterName)
Check if the given value is empty (empty string or null for String objects, empty collection, null for other objects) and throw an exception if empty.

Parameters:
value - value to check
parameterName - name of the value (for the exception)

lookupResource

public static java.lang.String lookupResource(java.lang.String resourceBundle,
                                              java.lang.String key,
                                              java.lang.String localeIso)
Try to find a localized resource messages

Parameters:
resourceBundle - the name of the resource bundle to retrieve the message from
key - resource key
localeIso - locale of the resource bundle
Returns:
resource from a localized bundle

getLocalizedMessage

public static java.lang.String getLocalizedMessage(java.lang.String resourceBundle,
                                                   long localeId,
                                                   java.lang.String localeIso,
                                                   java.lang.String key,
                                                   java.lang.Object... args)
Get the localized message for a given language code and ISO

Parameters:
resourceBundle - the resource bundle to use
localeId - used locale if args contain FxString instances
localeIso - ISO code of the requested locale
key - the key in the resource bundle
args - arguments to replace in the message ({n})
Returns:
localized message

isTranslatedLocale

public static boolean isTranslatedLocale(java.lang.String localeIsoCode)
Returns true if the given locale is localized in the flexive application (compile-time parameter flexive.translatedLocales set in flexive.properties).

Parameters:
localeIsoCode - the locale ISO code, e.g. "en" or "de"
Returns:
true if the given locale is localized (at least for some messages).
Since:
3.1

getTranslatedLocales

public static java.util.List<java.lang.String> getTranslatedLocales()
Returns the list of translated locales, as specified in flexive.properties (flexive.translatedLocales).

Returns:
the list of translated locales, in lowercase
Since:
3.1

getMessage

public static FxString getMessage(java.lang.String resourceBundle,
                                  java.lang.String key,
                                  java.lang.Object... args)
Returns a multilingual FxString with all translations for the given property key.

Parameters:
resourceBundle - the resource bundle to be used
key - the message key
args - optional parameters to be replaced in the property translations
Returns:
a multilingual FxString with all translations for the given property key.

getEnumLabel

public static FxString getEnumLabel(java.lang.Enum<?> value,
                                    java.lang.Object... args)
Returns the localized label for the given enum value. The enum translations are stored in FxSharedMessages.properties and are standardized as FQCN.value, e.g. com.flexive.shared.search.query.ValueComparator.LIKE.

Parameters:
value - the enum value to be translated
args - optional arguments to be replaced in the localized messages
Returns:
the localized label for the given enum value

getUsedStepDefinitions

public static java.util.List<StepDefinition> getUsedStepDefinitions(java.util.List<? extends Step> steps,
                                                                    java.util.List<? extends StepDefinition> stepDefinitions)
Returns a list of all used step definitions for the given steps

Parameters:
steps - list of steps to be examined
stepDefinitions - all defined step definitions
Returns:
a list of all used step definitions for this workflow

splitLiterals

public static java.lang.String[] splitLiterals(java.lang.String text,
                                               char[] stringDelims,
                                               char separator)
Splits the given text using separator. String literals are supported, e.g. abc,def yields two elements, but 'abc,def' yields one (stringDelims = ['\''], separator = ',').

Parameters:
text - the text to be splitted
stringDelims - delimiters for literal string values, usually ' and "
separator - separator between tokens
Returns:
split string

splitLiterals

public static java.lang.String[] splitLiterals(java.lang.String text)
Splits the given comma-separated text. String literals are supported, e.g. abc,def yields two elements, but 'abc,def' yields one.

Parameters:
text - the text to be splitted
Returns:
split string

getMappedFunction

public static <K,V> java.util.Map<K,V> getMappedFunction(FxSharedUtils.ParameterMapper<K,V> mapper)
Projects a single-parameter function on a hashmap. Useful for calling parameterized functions from JSF-EL. Results are not cached by default, use getMappedFunction(com.flexive.shared.FxSharedUtils.ParameterMapper, boolean) to create a caching mapper.

Parameters:
mapper - the parameter mapper wrapping the function to be called
Returns:
a hashmap projected on the given parameter mapper

getMappedFunction

public static <K,V> java.util.Map<K,V> getMappedFunction(FxSharedUtils.ParameterMapper<K,V> mapper,
                                                         boolean cacheResults)
Projects a single-parameter function on a hashmap. Useful for calling parameterized functions from JSF-EL. Values returned by the mapper can be cached in the hash map.

Parameters:
mapper - the parameter mapper wrapping the function to be called
cacheResults - if the mapper results should be cached by the map
Returns:
a hashmap projected on the given parameter mapper
Since:
3.1

escapePath

public static java.lang.String escapePath(java.lang.String path)
Escape a path for usage on the current operating systems shell

Parameters:
path - path to escape
Returns:
escaped path

escapeXPath

public static java.lang.String escapeXPath(java.lang.String xpath)
Escapes the given XPath for use in a public URI.

Parameters:
xpath - the xpath to be escaped
Returns:
the given XPath for use in a public URI.
See Also:
decodeXPath(String)

decodeXPath

public static java.lang.String decodeXPath(java.lang.String escapedXPath)
Decodes a previously escaped XPath.

Parameters:
escapedXPath - the escaped XPath
Returns:
the decoded XPath
See Also:
escapeXPath(String)

get

public static <K,V> V get(java.util.Map<K,V> map,
                          K key,
                          V defaultValue)
Returns map.get(key) if key exists, defaultValue otherwise.

Parameters:
map - a map
key - the required key
defaultValue - the default value to be returned if key does not exist in map
Returns:
map.get(key) if key exists, defaultValue otherwise.

isQuoted

public static boolean isQuoted(java.lang.String value,
                               char quoteChar)
Returns true if the given string value is quoted with the given character (e.g. 'value').

Parameters:
value - the string value to be checked
quoteChar - the quote character, for example '
Returns:
true if the given string value is quoted with the given character (e.g. 'value').

stripQuotes

public static java.lang.String stripQuotes(java.lang.String value,
                                           char quoteChar)
Strips the quotes from the given string if it is quoted, otherwise it returns the input value itself.

Parameters:
value - the value to be "unquoted"
quoteChar - the quote character, for example '
Returns:
the unquoted string, or value, if it was not quoted

getBytes

public static byte[] getBytes(java.lang.String s)
Returns the UTF-8 byte representation of the given string. Use this instead of String.getBytes(), since the latter will fail if the system locale is not UTF-8.

Parameters:
s - the string to be processed
Returns:
the UTF-8 byte representation of the given string

getEnumNames

public static java.util.List<java.lang.String> getEnumNames(java.util.Collection<? extends java.lang.Enum> values)
Extracts the names of the given enum elements and returns them as string. Useful if the toString() method of the Enum class was overwritten.

Parameters:
values - the enum values
Returns:
the names of the given enum elements

getSelectableObjectIdList

public static java.util.List<java.lang.Long> getSelectableObjectIdList(java.lang.Iterable<? extends SelectableObject> values)
Extract the unique IDs of the given SelectableObject collection.

Parameters:
values - the input values
Returns:
the IDs of the input values
Since:
3.1

getSelectableObjectNameList

public static java.util.List<java.lang.String> getSelectableObjectNameList(java.lang.Iterable<? extends SelectableObjectWithName> values)
Extract the unique names of the given SelectableObject collection.

Parameters:
values - the input values
Returns:
the IDs of the input values
Since:
3.1

indexOfSelectableObject

public static int indexOfSelectableObject(java.util.List<? extends SelectableObject> values,
                                          long id)
Returns the index of the SelectableObject with the given ID, or -1 if none was found.

Parameters:
values - the values to be examined
id - the target ID
Returns:
the index of the SelectableObject with the given ID, or -1 if none was found.

getSelectableObject

public static <T extends SelectableObject> T getSelectableObject(java.util.List<T> values,
                                                                 long id)
Return a SelectableObject by its ID.

Type Parameters:
T - the value type
Parameters:
values - the values to search
id - the ID to look for
Returns:
the first matching value
Throws:
FxRuntimeException - if no element with the given ID was found
Since:
3.2.0

filterSelectableObjectsById

public static <T extends SelectableObject> java.util.List<T> filterSelectableObjectsById(java.lang.Iterable<T> values,
                                                                                         java.util.Collection<java.lang.Long> ids)
Return the elements of values that match the given ids.

Type Parameters:
T - the value type
Parameters:
values - the values to be search
ids - the required IDs
Returns:
the elements of values that match the given ids.
Since:
3.1

filterSelectableObjectsByName

public static <T extends SelectableObjectWithName> java.util.List<T> filterSelectableObjectsByName(java.lang.Iterable<T> values,
                                                                                                   java.util.Collection<java.lang.String> names)
Return the elements of values that match the given names.

Type Parameters:
T - the value type
Parameters:
values - the values to be search
names - the required IDs
Returns:
the elements of values that match the given names.
Since:
3.1

compare

public static int compare(int i1,
                          int i2)
Primitive int comparison method (when JDK7's Integer#compare cannot be used). For float and double, see NumberUtils.

Parameters:
i1 - the first value
i2 - the second value
Returns:
see Integer.compareTo(java.lang.Integer)
Since:
3.2.0

compare

public static int compare(long i1,
                          long i2)
Primitive long comparison method (when JDK7's Long#compare cannot be used). For float and double, see NumberUtils.

Parameters:
i1 - the first value
i2 - the second value
Returns:
see Integer.compareTo(java.lang.Integer)
Since:
3.2.0

addMessageResources

public static java.util.List<FxSharedUtils.BundleReference> addMessageResources(java.lang.String baseName)
                                                                         throws java.io.IOException
Add a resource reference for the given resource base name.

Parameters:
baseName - the resource name (e.g. "ApplicationResources")
Returns:
a List of BundleReferences
Throws:
java.io.IOException - if an I/O error occured while looking for resources

close

public static void close(java.io.Closeable... resources)
Close the given resources and log a warning message if closing fails.

Parameters:
resources - the resource(s) to be closed
Since:
3.1

isMinimalRunOnceScripts

public static boolean isMinimalRunOnceScripts()
Returns:
true if only a minimum set of runonce scripts should be installed.
Since:
3.1
See Also:
PROP_RUNONCE_MINIMAL

checkAssignmentInherited

public static <T extends FxAssignment> boolean checkAssignmentInherited(T assignment)
This method checks if the current assignment is a derived assignment subject to the following conditions: 1.) must be assigned to a derived type 2.) must be inherited from the derived type's parent 3.) XPaths must match

Type Parameters:
T - extends FxAssignment
Parameters:
assignment - an FxAssignment
Returns:
true if conditions are met
Since:
3.1.1

getNodeId

public static java.lang.String getNodeId()
Returns:
the name of the current network node (used by flexive for the NodeConfigurationEngine.
Since:
3.2.0