ro.isdc.wro.util
Class WroUtil

java.lang.Object
  extended by ro.isdc.wro.util.WroUtil

public final class WroUtil
extends Object

Utility class.

Author:
Alex Objelean

Field Summary
static Pattern EMTPY_LINE_PATTERN
          Empty line pattern.
 
Constructor Summary
WroUtil()
           
 
Method Summary
static void addNoCacheHeaders(javax.servlet.http.HttpServletResponse response)
          Add no-cache headers to response.
static ThreadFactory createDaemonThreadFactory(String name)
           
static String getFilterPath(String filterName, InputStream is)
          Returns the filter path read from the web.xml
static String getPathInfoFromLocation(String location)
          Retrieve pathInfo from a given location.
static String getServletPathFromLocation(String location)
          Retrieve servletPath from a given location.
static boolean isGzipSupported(javax.servlet.http.HttpServletRequest request)
          Analyze headers of the request and searches for mangled (by proxy) for "Accept-Encoding" header and its mangled variations and gzip header value and its mangled variations.
static ResourcePostProcessor newResourceProcessor(Resource resource, ResourcePreProcessor preProcessor)
          A factory method for creating a ResourceProcessor based on provided ResourcePreProcessor.
static
<T> ObjectFactory<T>
simpleObjectFactory(T object)
           
static boolean startsWithIgnoreCase(String str, String prefix)
           Case insensitive check if a String starts with a specified prefix.
static String toDateAsString(long milliseconds)
          Transforms milliseconds into date format for response header of this form: Sat, 10 Apr 2010 17:31:31 GMT.
static String toJSMultiLineString(String data)
          Transforms a java multi-line string into javascript multi-line string.
static String toPackageAsFolder(Class<?> clazz)
          Creates a folder like implementation for a class.
static void wrapWithWroRuntimeException(Exception e)
          Wraps original exception into WroRuntimeException and throw it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMTPY_LINE_PATTERN

public static final Pattern EMTPY_LINE_PATTERN
Empty line pattern.

Constructor Detail

WroUtil

public WroUtil()
Method Detail

createDaemonThreadFactory

public static ThreadFactory createDaemonThreadFactory(String name)
Returns:
ThreadFactory with daemon threads.

toDateAsString

public static String toDateAsString(long milliseconds)
Transforms milliseconds into date format for response header of this form: Sat, 10 Apr 2010 17:31:31 GMT.

Parameters:
milliseconds - to transform
Returns:
string representation of the date.

getPathInfoFromLocation

public static String getPathInfoFromLocation(String location)
Retrieve pathInfo from a given location.

Parameters:
location - where to search contextPath.
Returns:
pathInfo value.

startsWithIgnoreCase

public static boolean startsWithIgnoreCase(String str,
                                           String prefix)

Case insensitive check if a String starts with a specified prefix.

nulls are handled without exceptions. Two null references are considered to be equal. The comparison is case insensitive.

 StringUtils.startsWithIgnoreCase(null, null)      = true
 StringUtils.startsWithIgnoreCase(null, "abcdef")  = false
 StringUtils.startsWithIgnoreCase("abc", null)     = false
 StringUtils.startsWithIgnoreCase("abc", "abcdef") = true
 StringUtils.startsWithIgnoreCase("abc", "ABCDEF") = true
 

Parameters:
str - the String to check, may be null
prefix - the prefix to find, may be null
Returns:
true if the String starts with the prefix, case insensitive, or both null
Since:
2.4
See Also:
String.startsWith(String)

toPackageAsFolder

public static String toPackageAsFolder(Class<?> clazz)
Creates a folder like implementation for a class. Ex: com.mycompany.MyClass -> com/mycompany/

Parameters:
clazz - used as a base location for determining the package path.
Returns:
a string representation of the path where the class resides.

getServletPathFromLocation

public static String getServletPathFromLocation(String location)
Retrieve servletPath from a given location.

Parameters:
location - where to search the servletPath.
Returns:
ServletPath string value.

isGzipSupported

public static boolean isGzipSupported(javax.servlet.http.HttpServletRequest request)
Analyze headers of the request and searches for mangled (by proxy) for "Accept-Encoding" header and its mangled variations and gzip header value and its mangled variations.

Returns:
true if this request support gzip encoding.

toJSMultiLineString

public static String toJSMultiLineString(String data)
Transforms a java multi-line string into javascript multi-line string. This technique was found at http://stackoverflow.com/questions/805107/multiline-strings-in-javascript/

Parameters:
data - a string containing new lines.
Returns:
a string which being evaluated on the client-side will be treated as a correct multi-line string.

getFilterPath

public static String getFilterPath(String filterName,
                                   InputStream is)
                            throws javax.servlet.ServletException
Returns the filter path read from the web.xml

Parameters:
filterName - the name of the searched filter.
is - Stream of the web.xml file.
Returns:
the filterPath for the searched filterName with wildcard removed.
Throws:
javax.servlet.ServletException

addNoCacheHeaders

public static void addNoCacheHeaders(javax.servlet.http.HttpServletResponse response)
Add no-cache headers to response.


newResourceProcessor

public static ResourcePostProcessor newResourceProcessor(Resource resource,
                                                         ResourcePreProcessor preProcessor)
A factory method for creating a ResourceProcessor based on provided ResourcePreProcessor.

Parameters:
preProcessor - ResourcePreProcessor to use as a ResourceProcessor.
Returns:
instance of ResourceProcessor.

simpleObjectFactory

public static <T> ObjectFactory<T> simpleObjectFactory(T object)

wrapWithWroRuntimeException

public static void wrapWithWroRuntimeException(Exception e)
Wraps original exception into WroRuntimeException and throw it.

Parameters:
e - the exception to wrap.


Copyright © 2008-2011. All Rights Reserved.