public class SpincastUtils extends Object implements ISpincastUtils
| Modifier and Type | Field and Description |
|---|---|
protected org.slf4j.Logger |
logger |
| Constructor and Description |
|---|
SpincastUtils(ISpincastConfig 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 ISpincastConfig |
getSpincastConfig() |
String |
getSpincastCurrentVersion()
Gets the current Spincast version.
|
boolean |
isContentTypeToSkipGziping(String contentType)
Should the specified
Content-Type be gzipped? |
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 SpincastUtils(ISpincastConfig spincastConfig)
protected ISpincastConfig getSpincastConfig()
public boolean isContentTypeToSkipGziping(String contentType)
ISpincastUtilsContent-Type be gzipped?isContentTypeToSkipGziping in interface ISpincastUtilspublic String getMimeTypeFromMultipleSources(String responseContentTypeHeader, String resourcePath, String requestPath)
ISpincastUtilsmime type using multiple sources of information.getMimeTypeFromMultipleSources in interface ISpincastUtilsresourcePath - 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)
ISpincastUtilsmime type from a path, using its extension.getMimeTypeFromPath in interface ISpincastUtilsmime type or null if it can't be
decided.public String getMimeTypeFromExtension(String extension)
ISpincastUtilsmime type from the extension.getMimeTypeFromExtension in interface ISpincastUtilsmime type or null if it can't be
decided.public Locale getLocaleBestMatchFromAcceptLanguageHeader(String header)
ISpincastUtilsgetLocaleBestMatchFromAcceptLanguageHeader in interface ISpincastUtilsnull
if the given header can't be parsed.public File getAppJarDirectory()
ISpincastUtilsgetAppJarDirectory in interface ISpincastUtilsnull if the application is
running inside an IDE.public String getSpincastCurrentVersion()
ISpincastUtilsgetSpincastCurrentVersion in interface ISpincastUtilsprotected String getCurrentVersionFromPom()
public void zipDirectory(File directoryToZip, File targetZipFile, boolean includeDirItself)
ISpincastUtilszipDirectory in interface ISpincastUtilstargetZipFile - the target .zip file. If the parent directories don't
exist, tries to create them.public void zipExtract(File zipFile, File targetDir)
ISpincastUtilszipExtract in interface ISpincastUtilstargetDir - The target directory. If it doesn't exist, tried to
create it (and its parents, if required).public String getCacheBusterCode()
ISpincastUtilsThis 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 ISpincastUtilspublic String removeCacheBusterCodes(String text)
ISpincastUtilsNote 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 ISpincastUtilsCopyright © 2016. All rights reserved.