public interface SpincastUtils
| Modifier and Type | Method and Description |
|---|---|
File |
getAppJarDirectory()
If the project is running from an executable
.jar file, this will return the directory containing
this .jar file.
|
File |
getAppRootDirectoryNoJar()
If the project is not running from an executable
.jar file, this will return the root directory of the
project on the file system.
|
String |
getCacheBusterCode()
The cache buster to use.
|
Locale |
getLocaleBestMatchFromAcceptLanguageHeader(String acceptLanguageHeader)
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. |
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 and returns it as a
String.
|
String |
readClasspathFile(String path,
String encoding)
Reads a file on the classpath and 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.
|
void zipDirectory(File directoryToZip, File targetZipFile, boolean includeDirItself)
targetZipFile - the target .zip file. If the parent directories don't
exist, tries to create them.If - true, the directory itself will be included in the
zip file, otherwise only its content will be.void zipExtract(File zipFile, File targetDir)
targetDir - The target directory. If it doesn't exist, tried to
create it (and its parents, if required).String getMimeTypeFromMultipleSources(String responseContentTypeHeader, String resourcePath, String requestPath)
mime type using multiple sources of information.contentTypeHeader - an already existing Content-Type header on the
response. Can be null.resourcePath - 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.String getMimeTypeFromPath(String path)
mime type from a path, using its extension.mime type or null if it can't be
decided.String getMimeTypeFromExtension(String extension)
mime type from the extension.mime type or null if it can't be
decided.Locale getLocaleBestMatchFromAcceptLanguageHeader(String acceptLanguageHeader)
null
if the given header can't be parsed.boolean isContentTypeToSkipGziping(String contentType)
Content-Type be gzipped?File getAppJarDirectory()
null if the
application is not running from an executable .jar
file.File getAppRootDirectoryNoJar()
null if the
application is running from an executable .jar
file.String getSpincastCurrentVersion()
String getCacheBusterCode()
This 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!
String removeCacheBusterCodes(String text)
Note 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!
String readClasspathFile(String path)
Paths 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.
null
if not found.String readClasspathFile(String path, String encoding)
Paths are always considered from the root at the classpath. You can start the path with a "/" or not, it makes no difference.
null
if not found.Copyright © 2017. All rights reserved.