public class SpincastUtilsDefault extends Object implements SpincastUtils
| Modifier and Type | Field and Description |
|---|---|
protected org.slf4j.Logger |
logger |
| Constructor and Description |
|---|
SpincastUtilsDefault(SpincastConfig spincastConfig) |
| Modifier and Type | Method and Description |
|---|---|
File |
getAppJarDirectory()
Returns the working directory: the directory
in which the executable .jar is located.
|
String |
getCacheBusterCode()
The cache buster to use.
|
protected String |
getCurrentVersionFromPom() |
Locale |
getLocaleBestMatchFromAcceptLanguageHeader(String header)
Gets the best Locale to use given a "Accept-Language" HTTP header.
|
String |
getMimeTypeFromExtension(String extension)
Gets the
mime type from the extension. |
String |
getMimeTypeFromMultipleSources(String responseContentTypeHeader,
String resourcePath,
String requestPath)
Gets the
mime type using multiple sources of information. |
String |
getMimeTypeFromPath(String path)
Gets the
mime type from a path, using its extension. |
protected SpincastConfig |
getSpincastConfig() |
String |
getSpincastCurrentVersion()
Gets the current Spincast version.
|
boolean |
isContentTypeToSkipGziping(String contentType)
Should the specified
Content-Type be gzipped? |
String |
readClasspathFile(String path)
Reads a file on the classpath on returns it as a
String.
|
String |
readClasspathFile(String path,
String encoding)
Reads a file on the classpath on returns it as a
String.
|
String |
removeCacheBusterCodes(String text)
Removes the cache buster code occurences from the
given text.
|
void |
zipDirectory(File directoryToZip,
File targetZipFile,
boolean includeDirItself)
Zips a directory.
|
void |
zipExtract(File zipFile,
File targetDir)
Extracts a .zip file to the specified directory.
|
@Inject public SpincastUtilsDefault(SpincastConfig spincastConfig)
protected SpincastConfig getSpincastConfig()
public boolean isContentTypeToSkipGziping(String contentType)
SpincastUtilsContent-Type be gzipped?isContentTypeToSkipGziping in interface SpincastUtilspublic String getMimeTypeFromMultipleSources(String responseContentTypeHeader, String resourcePath, String requestPath)
SpincastUtilsmime type using multiple sources of information.getMimeTypeFromMultipleSources in interface SpincastUtilsresourcePath - the path (absolute or relative) to the target resource. Can be null.requestPath - the path of the current request. Can be null.mime type or null if it can't be
decided.public String getMimeTypeFromPath(String path)
SpincastUtilsmime type from a path, using its extension.getMimeTypeFromPath in interface SpincastUtilsmime type or null if it can't be
decided.public String getMimeTypeFromExtension(String extension)
SpincastUtilsmime type from the extension.getMimeTypeFromExtension in interface SpincastUtilsmime type or null if it can't be
decided.public Locale getLocaleBestMatchFromAcceptLanguageHeader(String header)
SpincastUtilsgetLocaleBestMatchFromAcceptLanguageHeader in interface SpincastUtilsnull
if the given header can't be parsed.public File getAppJarDirectory()
SpincastUtilsgetAppJarDirectory in interface SpincastUtilsnull if the application is
running inside an IDE.public String getSpincastCurrentVersion()
SpincastUtilsgetSpincastCurrentVersion in interface SpincastUtilsprotected String getCurrentVersionFromPom()
public void zipDirectory(File directoryToZip, File targetZipFile, boolean includeDirItself)
SpincastUtilszipDirectory in interface SpincastUtilstargetZipFile - the target .zip file. If the parent directories don't
exist, tries to create them.public void zipExtract(File zipFile, File targetDir)
SpincastUtilszipExtract in interface SpincastUtilstargetDir - The target directory. If it doesn't exist, tried to
create it (and its parents, if required).public String getCacheBusterCode()
SpincastUtilsThis should probably change each time the application is restarted or at least redeployed.
It should also be in such a format that it's possible to remove it from a given text.
This must be kept in sync with
removeCacheBusterCode!
getCacheBusterCode in interface SpincastUtilspublic String removeCacheBusterCodes(String text)
SpincastUtilsNote that this won't simply remove the current cache busting code, it will remove any valid cache busting code... This is what we want since we don't want a client sending a request containing an old cache busting code to break!
This must be kept in sync with
getCacheBusterCode!
removeCacheBusterCodes in interface SpincastUtilspublic String readClasspathFile(String path)
SpincastUtilsPaths are always considered from the root at the classpath. You can start the path with a "/" or not, it makes no difference.
Uses the UTF-8 encoding.
readClasspathFile in interface SpincastUtilsnull
if not found.public String readClasspathFile(String path, String encoding)
SpincastUtilsPaths are always considered from the root at the classpath. You can start the path with a "/" or not, it makes no difference.
readClasspathFile in interface SpincastUtilsnull
if not found.Copyright © 2016. All rights reserved.