com.groupdocs.annotation.utils
Class Utils

java.lang.Object
  extended by com.groupdocs.annotation.utils.Utils

public class Utils
extends Object

Utils methods

Author:
Alex Bobkov

Constructor Summary
Utils()
           
 
Method Summary
static
<T extends com.groupdocs.annotation.db.tables.GroupDocsAnnotationTable>
T
assetEntity(T t)
          Asset entity for null
static
<T extends com.groupdocs.annotation.db.tables.GroupDocsAnnotationTable>
T
assetEntity(T t, String errorMessage)
          Asset entity for null
static void closeStreams(Object... streams)
          For each parameters if it extends @{InputStream} or @{OutputStream} will call .close() method
static String decodeData(String data)
          Decode base64 data
static String dt2s(Date date)
          Date to String format for database
static String encodeData(String data)
          Encode data to base64
static
<T> T
fromJson(String jsonString, Class<T> clazz)
          Convert json to object
static String getBody(javax.servlet.http.HttpServletRequest request)
          Get body from HTTP servlet request
static
<T> T
getObjectData(String request, Class<T> clazz)
          Get object from request
static String makeAppPath(javax.servlet.http.HttpServletRequest request)
          Make base application path using parameters from request object
static String processTemplate(String templateName, Map<String,String> replaceValues)
          Process template (replace all ${some_word|default_value} to value in params map)
static Date s2dt(String strDate)
          Parse String to Date format (default date format "yyyy-MM-dd HH:mm:ss" )
static Date s2dt(String strDate, String dateFormat)
          Parse String to Date format
static String toJson(Object obj)
          Convert object to json
static long utcToLocal(long utcTime)
          Convert UTC time to local time using TimeZone.getDefault()
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Utils

public Utils()
Method Detail

processTemplate

public static String processTemplate(String templateName,
                                     Map<String,String> replaceValues)
                              throws IOException
Process template (replace all ${some_word|default_value} to value in params map)

Parameters:
templateName - template name
replaceValues - map with params
Returns:
processed output
Throws:
IOException

getObjectData

public static <T> T getObjectData(String request,
                                  Class<T> clazz)
                       throws IOException
Get object from request

Type Parameters:
T - object type
Parameters:
request - request
clazz - class type
Returns:
object with parsed and filled data from request
Throws:
IOException

getBody

public static String getBody(javax.servlet.http.HttpServletRequest request)
                      throws IOException
Get body from HTTP servlet request

Parameters:
request - HTTP servlet request
Returns:
body request body string
Throws:
IOException

toJson

public static String toJson(Object obj)
Convert object to json

Parameters:
obj - object to convert
Returns:
converted object as json

fromJson

public static <T> T fromJson(String jsonString,
                             Class<T> clazz)
Convert json to object

Type Parameters:
T - object type
Parameters:
jsonString - json
clazz - object type class
Returns:
object created from json

assetEntity

public static <T extends com.groupdocs.annotation.db.tables.GroupDocsAnnotationTable> T assetEntity(T t)
                                                                                         throws NullPointerException
Asset entity for null

Type Parameters:
T - entity type
Parameters:
t - entity
Returns:
entity
Throws:
NullPointerException

assetEntity

public static <T extends com.groupdocs.annotation.db.tables.GroupDocsAnnotationTable> T assetEntity(T t,
                                                                                                    String errorMessage)
                                                                                         throws NullPointerException
Asset entity for null

Type Parameters:
T - entity type
Parameters:
t - entity
errorMessage - error message
Returns:
entity
Throws:
NullPointerException

dt2s

public static String dt2s(Date date)
Date to String format for database

Parameters:
date - input date
Returns:
date as String

s2dt

public static Date s2dt(String strDate)
Parse String to Date format (default date format "yyyy-MM-dd HH:mm:ss" )

Parameters:
strDate - date as String
Returns:
parsed date or null

s2dt

public static Date s2dt(String strDate,
                        String dateFormat)
Parse String to Date format

Parameters:
strDate - date as String
dateFormat - date format to parse (sample "yyyy-MM-dd HH:mm:ss" )
Returns:
parsed date or null

decodeData

public static String decodeData(String data)
Decode base64 data

Parameters:
data - data to be decoded
Returns:
decoded data

encodeData

public static String encodeData(String data)
Encode data to base64

Parameters:
data - data to be encoded
Returns:
encoded data

closeStreams

public static void closeStreams(Object... streams)
For each parameters if it extends @{InputStream} or @{OutputStream} will call .close() method

Parameters:
streams - streams to close

utcToLocal

public static long utcToLocal(long utcTime)
Convert UTC time to local time using TimeZone.getDefault()

Parameters:
utcTime - UTC time
Returns:
local time

makeAppPath

public static String makeAppPath(javax.servlet.http.HttpServletRequest request)
Make base application path using parameters from request object

Parameters:
request - http servlet request
Returns:
base application path with context (like http://annotation.local:8080/context-path/ )


Copyright © 2014. All rights reserved.