org.nuiton.wikitty
Class WikittyUtil

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

public class WikittyUtil
extends Object

Util static method for wikitty.

Version:
$Revision: 240 $ Last update: $Date: 2010-08-06 16:41:51 +0200 (ven., 06 août 2010) $ by : $Author: bleny $
Author:
poussin

Field Summary
protected static Locale CANONICAL_LOCALE
           
protected static TimeZone CANONICAL_TZ
          used to format date for solr
static String DATE_FORMAT
           
static String[] DATE_FORMAT_ALLOWED
           
static String DEFAULT_VERSION
           
protected static 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")
static Map<Class<?>,Class<?>> interfaceToClass
          contains mapping between interface and concret class that must be used
protected static org.apache.commons.lang.time.FastDateFormat solrDateFormat
           
protected static Pattern tagValuesPattern
           
protected static String tagValuesPatternString
          Pattern for tag value: tag="value" or tag=value. value can contains '"'
 
Constructor Summary
WikittyUtil()
           
 
Method Summary
static LinkedHashMap<String,FieldType> buildFieldMapExtension(String... definitions)
          Create map from string representation.
static
<E> E
cast(Object obj, Class<E> clazz)
          Try to cast obj to class passed in argument.
static Wikitty checkExtensionVersion(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 String formatDate(Date date)
           
static Object fromString(FieldType field, String s)
          Convert string field representation to correct value type.
static String genSecurityToken()
          SecurityToken is used like wikitty id and must begin with UUID_
static String genUID()
           
static Class<?> getClass(Object value)
          Return class of argument, if argument is null, return null.
static String incrementMajorRevision(String v)
          increment major version.
static String incrementMinorRevision(String v)
          Increment minor version.
static
<E extends BusinessEntity>
E
newInstance(Class<E> clazz)
          Create new instance of WikittyDto without Wikitty object passed in argument.
static
<E extends BusinessEntity>
E
newInstance(String securityToken, WikittyService wikittyService, Class<E> clazz, Wikitty w)
          Create new instance of BusinessEntity from Wikitty object passed in argument.
static String normalizeVersion(String version)
          if version if null return 0 else version If version is not in format .
static Date parseDate(String dateAsString)
           
static String parseField(String def, FieldType fieldType)
          parse FieldType definition and return field name.
static Map<String,String> tagValuesToMap(String tagValues)
          Deserialize tagValues to map
static String tagValuesToString(Map<String,String> tagValues)
          Serialize tagValues to string
static BigDecimal toBigDecimal(Object value)
          Get value as BigDecimal.
static boolean toBoolean(Object value)
          Convert object to boolean: - null => false - 0 => false - numeric => true - object.toString() == false => false - other => true
static Date toDate(Object value)
           
static
<E> List<E>
toList(Object value, Class<E> clazz)
          Convert value to list.
static String toString(FieldType field, Object o)
          Convert object o for indexation.
static String toString(Object value)
           
static String toWikitty(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(String v1, String v2)
          Return true if v1 and v2 are equals. 1.2.0 et 1.2 ne sont pas egaux
static boolean versionGreaterThan(String v1, 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_VERSION

public static final String DEFAULT_VERSION
See Also:
Constant Field Values

DATE_FORMAT

public static final String DATE_FORMAT
See Also:
Constant Field Values

DATE_FORMAT_ALLOWED

public static final String[] DATE_FORMAT_ALLOWED

CANONICAL_TZ

protected static TimeZone CANONICAL_TZ
used to format date for solr


CANONICAL_LOCALE

protected static final Locale CANONICAL_LOCALE

solrDateFormat

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

interfaceToClass

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


tagValuesPatternString

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


tagValuesPattern

protected static Pattern tagValuesPattern

fieldPattern

protected static 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 Date parseDate(String dateAsString)
                          throws ParseException
    Throws:
    ParseException

    formatDate

    public static String formatDate(Date date)
                             throws ParseException
    Throws:
    ParseException

    parseField

    public static String parseField(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 String tagValuesToString(Map<String,String> tagValues)
    Serialize tagValues to string

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

    tagValuesToMap

    public static Map<String,String> tagValuesToMap(String tagValues)
    Deserialize tagValues to map

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

    buildFieldMapExtension

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

    Parameters:
    definitions - extension definition
    Returns:
    extensions map

    normalizeVersion

    public static String normalizeVersion(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(String v1,
                                        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(String v1,
                                             String v2)
    Return true if v1 greater than v2.

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

    incrementMinorRevision

    public static String incrementMinorRevision(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 String incrementMajorRevision(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 BigDecimal toBigDecimal(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(Object value)
    Convert object to boolean:

    Parameters:
    value - value
    Returns:
    value as boolean

    toString

    public static String toString(Object value)

    toDate

    public static Date toDate(Object value)

    toWikitty

    public static String toWikitty(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> List<E> toList(Object value,
                                     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 String toString(FieldType field,
                                  Object o)
    Convert object o for indexation.

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

    fromString

    public static Object fromString(FieldType field,
                                    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 Class<?> getClass(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(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(String securityToken,
                                                           WikittyService wikittyService,
                                                           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(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(Object obj,
                             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

    genSecurityToken

    public static String genSecurityToken()
    SecurityToken is used like wikitty id and must begin with UUID_

    Returns:
    SecurityToken that can be used like wikitty id

    genUID

    public static String genUID()


    Copyright © 2009-2010 CodeLutin. All Rights Reserved.