org.nuiton.wikitty
Class WikittyUtil

java.lang.Object
  extended by org.nuiton.wikitty.WikittyUtil

public class WikittyUtil
extends java.lang.Object

Util static method for wikitty.

Version:
$Revision: 444 $ Last update: $Date: 2010-10-21 16:32:50 +0200 (jeu., 21 oct. 2010) $ by : $Author: bpoussin $
Author:
poussin

Field Summary
protected static java.util.Locale CANONICAL_LOCALE
           
protected static java.util.TimeZone CANONICAL_TZ
          used to format date for solr
static java.lang.String DATE_FORMAT
           
static java.lang.String[] DATE_FORMAT_ALLOWED
           
static java.lang.String DEFAULT_MAJOR_VERSION
           
static java.lang.String DEFAULT_MAJOR_VERSION_PREFIX
           
static java.lang.String DEFAULT_MINOR_VERSION
           
static java.lang.String DEFAULT_VERSION
           
protected static java.util.regex.Pattern fieldPattern
          Field pattern parser group 1: type (string) group 2: name (string) group 3: lower bound (number) can be null group 4: upper bound (number) can be null, mutually exclusive with group 5 group 5: upper bound (n or *) can be null group 6: unique can be null (legacy configuration, prefer use of unique="true" group 7: not null can be null (legacy configuration, prefer use of notNull="true" group 8: all tag/value (toto=titi tutu=tata;lala tata="truc bidulle")
protected static java.lang.String FQ_FIELD_NAME_SEPARATOR
           
protected static java.lang.String FQ_FIELD_NAME_SEPARATOR_REGEX
           
protected static java.lang.String FQ_META_EXTENSION_SEPARATOR
           
protected static java.lang.String FQ_META_EXTENSION_SEPARATOR_REGEX
           
static java.util.Map<java.lang.Class<?>,java.lang.Class<?>> interfaceToClass
          contains mapping between interface and concret class that must be used
protected static org.apache.commons.lang.time.FastDateFormat solrDateFormat
           
protected static java.util.regex.Pattern tagValuesPattern
           
protected static java.lang.String tagValuesPatternString
          Pattern for tag value: tag="value" or tag=value. value can contains '"'
 
Constructor Summary
WikittyUtil()
           
 
Method Summary
static java.util.LinkedHashMap<java.lang.String,FieldType> buildFieldMapExtension(java.lang.String... definitions)
          Create map from string representation.
static
<E> E
cast(java.lang.Object obj, java.lang.Class<E> clazz)
          Try to cast obj to class passed in argument.
static Wikitty checkExtensionVersion(java.lang.String securityToken, WikittyService wikittyService, Wikitty wikitty, BusinessEntityWikitty entity)
          Check extension default, i.e. if bean contain a extension with a great version as in wikitty.
static java.lang.String formatDate(java.util.Date date)
           
static java.lang.Object fromString(FieldType field, java.lang.String s)
          Convert string field representation to correct value type.
static java.lang.String genSecurityTokenId()
          SecurityToken is used like wikitty id and must begin with UUID_
static java.lang.String genUID()
           
static java.lang.Class<?> getClass(java.lang.Object value)
          Return class of argument, if argument is null, return null.
static java.lang.String getExtensionNameFromFQFieldName(java.lang.String fqFieldName)
          given a fully qualified field name, return the name of the extension
static java.lang.String getExtensionNameFromFQMetaExtensionName(java.lang.String fqFieldName)
          given a fully qualified meta-extension name, return the name of the extension
static java.lang.String getFieldNameFromFQFieldName(java.lang.String fqFieldName)
          given a fully qualified field name, return the name of the field
static java.lang.String getFQFieldName(java.lang.String extensionName, java.lang.String fieldName)
          given names of extension and field, return a fully qualified field name
static java.lang.String getFQMetaExtensionName(java.lang.String metaExtensionName, java.lang.String extensionName)
          given names of meta-extension and extension, return a fully qualified meta-extension name
static java.lang.String getMetaExtensionNameFromFQMetaExtensionName(java.lang.String fqFieldName)
          given a fully qualified meta-extension name, return the name of the meta-extension.
static java.lang.String getMetaFieldName(java.lang.String metaExtensionName, java.lang.String extensionName, java.lang.String fieldName)
          Get the FQN of a metaExtension field.
static java.lang.String incrementMajorRevision(java.lang.String v)
          increment major version.
static java.lang.String incrementMinorRevision(java.lang.String v)
          Increment minor version.
static
<E extends BusinessEntity>
E
newInstance(java.lang.Class<E> clazz)
          Create new instance of WikittyDto without Wikitty object passed in argument.
static
<E extends BusinessEntity>
E
newInstance(java.lang.String securityToken, WikittyService wikittyService, java.lang.Class<E> clazz, Wikitty w)
          Create new instance of BusinessEntity from Wikitty object passed in argument.
static java.lang.String normalizeVersion(java.lang.String version)
          if version if null return 0 else version If version is not in format .
static java.util.Date parseDate(java.lang.String dateAsString)
           
static java.lang.String parseField(java.lang.String def, FieldType fieldType)
          parse FieldType definition and return field name.
static java.util.Map<java.lang.String,java.lang.String> tagValuesToMap(java.lang.String tagValues)
          Deserialize tagValues to map
static java.lang.String tagValuesToString(java.util.Map<java.lang.String,java.lang.String> tagValues)
          Serialize tagValues to string
static java.math.BigDecimal toBigDecimal(java.lang.Object value)
          Get value as BigDecimal.
static boolean toBoolean(java.lang.Object value)
          Convert object to boolean: - null => false - 0 => false - numeric => true - object.toString() == false => false - other => true
static java.util.Date toDate(java.lang.Object value)
           
static
<E> java.util.List<E>
toList(java.lang.Object value, java.lang.Class<E> clazz)
          Convert value to list.
static java.lang.String toString(FieldType field, java.lang.Object o)
          Convert object o for indexation.
static java.lang.String toString(java.lang.Object value)
           
static java.lang.String toWikitty(java.lang.Object value)
          Return wikitty id and not wikitty objet because this method can be call on server or client side and it's better to keep conversion between id and objet to the caller
static boolean versionEquals(java.lang.String v1, java.lang.String v2)
          Return true if v1 and v2 are equals. 1.2.0 et 1.2 ne sont pas egaux
static boolean versionGreaterThan(java.lang.String v1, java.lang.String v2)
          Return true if v1 greater than v2.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_MAJOR_VERSION

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

DEFAULT_MINOR_VERSION

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

DEFAULT_MAJOR_VERSION_PREFIX

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

DEFAULT_VERSION

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

DATE_FORMAT

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

DATE_FORMAT_ALLOWED

public static final java.lang.String[] DATE_FORMAT_ALLOWED

CANONICAL_TZ

protected static java.util.TimeZone CANONICAL_TZ
used to format date for solr


CANONICAL_LOCALE

protected static final java.util.Locale CANONICAL_LOCALE

solrDateFormat

protected static final org.apache.commons.lang.time.FastDateFormat solrDateFormat

FQ_FIELD_NAME_SEPARATOR

protected static final java.lang.String FQ_FIELD_NAME_SEPARATOR
See Also:
Constant Field Values

FQ_FIELD_NAME_SEPARATOR_REGEX

protected static final java.lang.String FQ_FIELD_NAME_SEPARATOR_REGEX
See Also:
Constant Field Values

FQ_META_EXTENSION_SEPARATOR

protected static final java.lang.String FQ_META_EXTENSION_SEPARATOR
See Also:
Constant Field Values

FQ_META_EXTENSION_SEPARATOR_REGEX

protected static final java.lang.String FQ_META_EXTENSION_SEPARATOR_REGEX
See Also:
Constant Field Values

interfaceToClass

public static java.util.Map<java.lang.Class<?>,java.lang.Class<?>> interfaceToClass
contains mapping between interface and concret class that must be used


tagValuesPatternString

protected static java.lang.String tagValuesPatternString
Pattern for tag value: tag="value" or tag=value. value can contains '"'


tagValuesPattern

protected static java.util.regex.Pattern tagValuesPattern

fieldPattern

protected static java.util.regex.Pattern fieldPattern
Field pattern parser
  • group 1: type (string)
  • group 2: name (string)
  • group 3: lower bound (number) can be null
  • group 4: upper bound (number) can be null, mutually exclusive with group 5
  • group 5: upper bound (n or *) can be null
  • group 6: unique can be null (legacy configuration, prefer use of unique="true"
  • group 7: not null can be null (legacy configuration, prefer use of notNull="true"
  • group 8: all tag/value (toto=titi tutu=tata;lala tata="truc bidulle")

  • Constructor Detail

    WikittyUtil

    public WikittyUtil()
    Method Detail

    parseDate

    public static java.util.Date parseDate(java.lang.String dateAsString)
                                    throws java.text.ParseException
    Throws:
    java.text.ParseException

    formatDate

    public static java.lang.String formatDate(java.util.Date date)
                                       throws java.text.ParseException
    Throws:
    java.text.ParseException

    parseField

    public static java.lang.String parseField(java.lang.String def,
                                              FieldType fieldType)
    parse FieldType definition and return field name. All field information are stored in fieldType object passed in argument

    Parameters:
    def - string field definition
    fieldType - object used to put parsed information
    Returns:
    field name parsed in definition

    tagValuesToString

    public static java.lang.String tagValuesToString(java.util.Map<java.lang.String,java.lang.String> tagValues)
    Serialize tagValues to string

    Parameters:
    tagValues - tagValues as map
    Returns:
    string represent tagValues

    tagValuesToMap

    public static java.util.Map<java.lang.String,java.lang.String> tagValuesToMap(java.lang.String tagValues)
    Deserialize tagValues to map

    Parameters:
    tagValues - tagValues as string
    Returns:
    map represent tagValues

    buildFieldMapExtension

    public static java.util.LinkedHashMap<java.lang.String,FieldType> buildFieldMapExtension(java.lang.String... definitions)
    Create map from string representation. ex: "String name", "Wikitty attachment[0-*]"

    Parameters:
    definitions - extension definition
    Returns:
    extensions map

    normalizeVersion

    public static java.lang.String normalizeVersion(java.lang.String version)
    if version if null return 0 else version If version is not in format ., ".0" is added to the version

    Parameters:
    version - version
    Returns:
    the normalized version

    versionEquals

    public static boolean versionEquals(java.lang.String v1,
                                        java.lang.String v2)
    Return true if v1 and v2 are equals. 1.2.0 et 1.2 ne sont pas egaux

    Parameters:
    v1 - version
    v2 - version
    Returns:
    true if v1 == v2

    versionGreaterThan

    public static boolean versionGreaterThan(java.lang.String v1,
                                             java.lang.String v2)
    Return true if v1 greater than v2.

    Parameters:
    v1 - version
    v2 - version
    Returns:
    true if v1 > v2

    incrementMinorRevision

    public static java.lang.String incrementMinorRevision(java.lang.String v)
    Increment minor version.

    Parameters:
    v - version as 3.1 where 1 is minor and 3 major
    Returns:
    incremented minor number (3.1 -> 3.2)

    incrementMajorRevision

    public static java.lang.String incrementMajorRevision(java.lang.String v)
    increment major version.

    Parameters:
    v - version as 3.2 where 2 is minor and 3 major
    Returns:
    incremented major number and reset minor number (3.2 -> 4.0)

    toBigDecimal

    public static java.math.BigDecimal toBigDecimal(java.lang.Object value)
    Get value as BigDecimal.

    Parameters:
    value - null and empty string are casted to '0' value.
    Returns:
    value as BigDecimal
    Throws:
    WikittyException - on NumberFormatException or if value object can't be casted to number.

    toBoolean

    public static boolean toBoolean(java.lang.Object value)
    Convert object to boolean:

    Parameters:
    value - value
    Returns:
    value as boolean

    toString

    public static java.lang.String toString(java.lang.Object value)

    toDate

    public static java.util.Date toDate(java.lang.Object value)

    toWikitty

    public static java.lang.String toWikitty(java.lang.Object value)
    Return wikitty id and not wikitty objet because this method can be call on server or client side and it's better to keep conversion between id and objet to the caller

    Parameters:
    value -
    Returns:
    id of wikitty object or null

    toList

    public static <E> java.util.List<E> toList(java.lang.Object value,
                                               java.lang.Class<E> clazz)
    Convert value to list.

    Type Parameters:
    E - elements type
    Parameters:
    value - value to convert
    clazz - element class
    Returns:
    unmodifiable list

    toString

    public static java.lang.String toString(FieldType field,
                                            java.lang.Object o)
    Convert object o for indexation.

    Parameters:
    field - field description
    o - field value
    Returns:
    solr representation

    fromString

    public static java.lang.Object fromString(FieldType field,
                                              java.lang.String s)
    Convert string field representation to correct value type.

    Parameters:
    field - field description
    s - string value
    Returns:
    object in type of field

    getClass

    public static java.lang.Class<?> getClass(java.lang.Object value)
    Return class of argument, if argument is null, return null.

    Parameters:
    value -
    Returns:
    class of value or null

    newInstance

    public static <E extends BusinessEntity> E newInstance(java.lang.Class<E> clazz)
    Create new instance of WikittyDto without Wikitty object passed in argument. If arguement is Interface try to add 'Impl' to find instanciable class.

    clazz parameter must be child of WikittyDto or business interface

    Type Parameters:
    E - element type
    Parameters:
    clazz - class of the new instance
    Returns:
    new instance of clazz

    newInstance

    public static <E extends BusinessEntity> E newInstance(java.lang.String securityToken,
                                                           WikittyService wikittyService,
                                                           java.lang.Class<E> clazz,
                                                           Wikitty w)
    Create new instance of BusinessEntity from Wikitty object passed in argument. If argument is Interface try to add 'Impl' to find instanciable class.

    clazz parameter must be child of Business interface

    Type Parameters:
    E - entity type
    Parameters:
    wikittyService - wikitty service
    clazz - class of the new instance
    w - wikitty object to use internaly for in new instance
    Returns:
    new instance

    checkExtensionVersion

    public static Wikitty checkExtensionVersion(java.lang.String securityToken,
                                                WikittyService wikittyService,
                                                Wikitty wikitty,
                                                BusinessEntityWikitty entity)
    Check extension default, i.e. if bean contain a extension with a great version as in wikitty. In this case the extension is stored in last version and wikitty it is restored again. The upgrade data is during the restoration.

    Parameters:
    wikittyService -
    wikitty -
    entity -
    Returns:

    cast

    public static <E> E cast(java.lang.Object obj,
                             java.lang.Class<E> clazz)
    Try to cast obj to class passed in argument.

    Type Parameters:
    E - element type
    Parameters:
    obj - object to cast
    clazz - new type of object
    Returns:
    the same object but casted to class wanted, except for primitive where is new object if obj BigDecimal

    genSecurityTokenId

    public static java.lang.String genSecurityTokenId()
    SecurityToken is used like wikitty id and must begin with UUID_

    Returns:
    SecurityToken that can be used like wikitty id

    genUID

    public static java.lang.String genUID()

    getExtensionNameFromFQFieldName

    public static java.lang.String getExtensionNameFromFQFieldName(java.lang.String fqFieldName)
    given a fully qualified field name, return the name of the extension


    getFieldNameFromFQFieldName

    public static java.lang.String getFieldNameFromFQFieldName(java.lang.String fqFieldName)
    given a fully qualified field name, return the name of the field


    getFQFieldName

    public static java.lang.String getFQFieldName(java.lang.String extensionName,
                                                  java.lang.String fieldName)
    given names of extension and field, return a fully qualified field name


    getMetaExtensionNameFromFQMetaExtensionName

    public static java.lang.String getMetaExtensionNameFromFQMetaExtensionName(java.lang.String fqFieldName)
    given a fully qualified meta-extension name, return the name of the meta-extension.

    Returns:
    null if fqFieldName doesn't contains a meta extension

    getExtensionNameFromFQMetaExtensionName

    public static java.lang.String getExtensionNameFromFQMetaExtensionName(java.lang.String fqFieldName)
    given a fully qualified meta-extension name, return the name of the extension


    getFQMetaExtensionName

    public static java.lang.String getFQMetaExtensionName(java.lang.String metaExtensionName,
                                                          java.lang.String extensionName)
    given names of meta-extension and extension, return a fully qualified meta-extension name


    getMetaFieldName

    public static java.lang.String getMetaFieldName(java.lang.String metaExtensionName,
                                                    java.lang.String extensionName,
                                                    java.lang.String fieldName)
    Get the FQN of a metaExtension field. The FQN may depend of an extension getMetaFieldName(metaExt, ext, field) returns "ext:metaExt.field" getMetaFieldName(metaExt, null, field) returns "metaExt.field"



    Copyright © 2009-2010 CodeLutin. All Rights Reserved.