use of org.apache.wicket.request.cycle.RequestCycle in project wicket by apache.
the class FilenameWithVersionResourceCachingStrategy method undecorateUrl.
@Override
public void undecorateUrl(ResourceUrl url) {
final String filename = url.getFileName();
// check for extension
int pos = filename.lastIndexOf('.');
// get name of file without extension (but with version string)
final String fullname = pos == -1 ? filename : filename.substring(0, pos);
// get extension of file if present
final String extension = pos == -1 ? null : filename.substring(pos);
// get position of version string
pos = fullname.lastIndexOf(versionPrefix);
// remove version string if it exists
if (pos != -1 && isVersion(fullname.substring(pos + versionPrefix.length()))) {
// get filename before version string
final String basename = fullname.substring(0, pos);
// create filename without version string
// (required for working resource lookup)
url.setFileName(extension == null ? basename : basename + extension);
// store the version in the request cycle
RequestCycle requestCycle = RequestCycle.get();
if (requestCycle != null) {
int idx = fullname.indexOf(versionPrefix);
String urlVersion = fullname.substring(idx + versionPrefix.length());
requestCycle.setMetaData(URL_VERSION, urlVersion);
}
}
}
use of org.apache.wicket.request.cycle.RequestCycle in project wicket by apache.
the class DynamicJQueryResourceReference method getName.
@Override
public String getName() {
RequestCycle requestCycle = RequestCycle.get();
String name = requestCycle.getMetaData(KEY);
if (name == null) {
WebClientInfo clientInfo;
name = getVersion2();
if (Session.exists()) {
WebSession session = WebSession.get();
clientInfo = session.getClientInfo();
} else {
clientInfo = new WebClientInfo(requestCycle);
}
ClientProperties clientProperties = clientInfo.getProperties();
if (clientProperties.isBrowserInternetExplorer() && clientProperties.getBrowserVersionMajor() < 9) {
name = getVersion1();
}
requestCycle.setMetaData(KEY, name);
}
return name;
}
use of org.apache.wicket.request.cycle.RequestCycle in project wicket by apache.
the class FileSystemResource method createResourceResponse.
/**
* Creates a resource response based on the given attributes
*
* @param path
* the path to create the resource response with
* @param attributes
* request attributes
* @return the actual resource response
*/
protected ResourceResponse createResourceResponse(Attributes attributes, Path path) {
try {
if (path == null) {
throw new WicketRuntimeException("Please override #newResourceResponse() and provide a path if using a constructor which doesn't take one as argument.");
}
this.path = new PathModel(path);
long size = getSize();
ResourceResponse resourceResponse = new ResourceResponse();
resourceResponse.setContentType(getMimeType());
resourceResponse.setAcceptRange(ContentRangeType.BYTES);
resourceResponse.setContentLength(size);
if (path.getFileName() != null) {
resourceResponse.setFileName(path.getFileName().toString());
}
RequestCycle cycle = RequestCycle.get();
Long startbyte = cycle.getMetaData(CONTENT_RANGE_STARTBYTE);
Long endbyte = cycle.getMetaData(CONTENT_RANGE_ENDBYTE);
resourceResponse.setWriteCallback(new PartWriterCallback(getInputStream(), size, startbyte, endbyte).setClose(true));
return resourceResponse;
} catch (IOException e) {
throw new WicketRuntimeException("An error occurred while processing the media resource response", e);
}
}
use of org.apache.wicket.request.cycle.RequestCycle in project wicket by apache.
the class PackageResourceReference method getResource.
/**
* @see org.apache.wicket.request.resource.ResourceReference#getResource()
*/
@Override
public PackageResource getResource() {
final String extension = getExtension();
final PackageResource resource;
RequestCycle requestCycle = RequestCycle.get();
UrlAttributes urlAttributes = null;
if (requestCycle != null) {
// resource attributes (locale, style, variation) might be encoded in the URL
final Url url = requestCycle.getRequest().getUrl();
urlAttributes = ResourceUtil.decodeResourceReferenceAttributes(url);
}
final String currentVariation = getCurrentVariation(urlAttributes);
final String currentStyle = getCurrentStyle(urlAttributes);
final Locale currentLocale = getCurrentLocale(urlAttributes);
final Class<?> scope = getScope();
final String name = getName();
if (CSS_EXTENSION.equals(extension)) {
resource = new CssPackageResource(scope, name, currentLocale, currentStyle, currentVariation);
} else if (JAVASCRIPT_EXTENSION.equals(extension)) {
resource = new JavaScriptPackageResource(scope, name, currentLocale, currentStyle, currentVariation);
} else {
resource = new PackageResource(scope, name, currentLocale, currentStyle, currentVariation);
}
resource.readBuffered(readBuffered);
removeCompressFlagIfUnnecessary(resource);
return resource;
}
use of org.apache.wicket.request.cycle.RequestCycle in project wicket by apache.
the class RequestCycleCachedResourceVersion method getVersion.
@Override
public String getVersion(IStaticCacheableResource resource) {
// get current request cycle
final RequestCycle requestCycle = ThreadContext.getRequestCycle();
// cache instance
Map<Serializable, String> cache = null;
// cache key
Serializable key = null;
// is request cycle available?
if (requestCycle != null) {
// retrieve cache from current request cycle
cache = requestCycle.getMetaData(CACHE_KEY);
// create caching key
key = resource.getCacheKey();
// does cache exist within current request cycle?
if (cache == null) {
// no, so create it
requestCycle.setMetaData(CACHE_KEY, cache = Generics.newHashMap());
} else if (cache.containsKey(key)) {
// lookup timestamp from cache (may contain NULL values which are valid)
return cache.get(key);
}
}
// no cache entry found, query version from delegate
final String version = delegate.getVersion(resource);
// store value in cache (if it is available)
if (cache != null && key != null) {
cache.put(key, version);
}
return version;
}
Aggregations