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 InputStream EMPTY_STREAM
           
static Pattern EMTPY_LINE_PATTERN
          Empty line pattern.
 
Constructor Summary
WroUtil()
           
 
Method Summary
static ThreadFactory createDaemonThreadFactory(String name)
           
static File createTempFile()
           
static File createTempFile(String extension)
          Creates a temp file which has a certain extension.
static WroModelFactory factoryFor(WroModel model)
          A simple way to create a WroModelFactory.
static String getImplementationVersion()
           
static String getPathInfoFromLocation(javax.servlet.http.HttpServletRequest request, String location)
          Retrieve pathInfo from a given location.
static String getServletPathFromLocation(javax.servlet.http.HttpServletRequest request, 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 String loadRegexpWithKey(String key)
          Load the regular expression stored in in regexp.properties resource file.
static boolean matchesUrl(javax.servlet.http.HttpServletRequest request, String path)
          Utility used to verify that requestURI matches provided path
static ResourcePostProcessor newResourceProcessor(Resource resource, ResourcePreProcessor preProcessor)
          A factory method for creating a ResourceProcessor based on provided ResourcePreProcessor.
static void safeCopy(Reader reader, Writer writer)
          Copy and close the reader and writer streams.
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)
          Deprecated. use WroRuntimeException.wrap(Exception)
 
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.


EMPTY_STREAM

public static final InputStream EMPTY_STREAM
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(javax.servlet.http.HttpServletRequest request,
                                             String location)
Retrieve pathInfo from a given location.

Parameters:
request -
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(javax.servlet.http.HttpServletRequest request,
                                                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 ://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.

matchesUrl

public static boolean matchesUrl(javax.servlet.http.HttpServletRequest request,
                                 String path)
Utility used to verify that requestURI matches provided path


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.

factoryFor

public static WroModelFactory factoryFor(WroModel model)
A simple way to create a WroModelFactory.

Parameters:
model - WroModel instance to be returned by the factory.

simpleObjectFactory

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

wrapWithWroRuntimeException

@Deprecated
public static void wrapWithWroRuntimeException(Exception e)
Deprecated. use WroRuntimeException.wrap(Exception)

Wraps original exception into WroRuntimeException and throw it.

Parameters:
e - the exception to wrap.

loadRegexpWithKey

public static String loadRegexpWithKey(String key)
Load the regular expression stored in in regexp.properties resource file.

Parameters:
key - the key of the regexp to load.
Returns:
regular expression value.

getImplementationVersion

public static String getImplementationVersion()
Returns:
the implementation version of wro4j.

safeCopy

public static void safeCopy(Reader reader,
                            Writer writer)
                     throws IOException
Copy and close the reader and writer streams.

Parameters:
reader - The source stream.
writer - The destination stream.
Throws:
IOException - If content cannot be copy.

createTempFile

public static File createTempFile()
Returns:
a generated File with unique name located in temp folder.

createTempFile

public static File createTempFile(String extension)
Creates a temp file which has a certain extension.

Parameters:
extension - of the created temp file.


Copyright © 2008-2013. All Rights Reserved.