List of usage examples for org.apache.wicket.request.resource JavaScriptPackageResource JavaScriptPackageResource
public JavaScriptPackageResource(Class<?> scope, String name, Locale locale, String style, String variation)
From source file:name.martingeisse.webeco.SpecialStringResourceLoader.java
License:Open Source License
/** * @param key//ww w.j a va2s . c om * @return */ private String lookup(String key, Locale locale, String style, String variation) { if (key.equals("webeco.path.js.base")) { JavaScriptPackageResource resource = new JavaScriptPackageResource(Dummy.class, "jquery-1.6.4-with-tools-1.2.6.js", locale, style, variation); String version = FirstLineResourceVersion.getVersionFrom(resource); return "base-revision-" + version + ".js"; } else { return null; } }
From source file:org.wicketstuff.offline.mode.ServiceWorker.java
License:Apache License
/** * If the service worker resource is shipped the first time the script is filled with the URLs * of the resources to be cached.//from ww w . j a va 2 s . c o m * * @return the java script package resource to provide the script with the URLs to be cached */ @Override public JavaScriptPackageResource getResource() { final JavaScriptPackageResource resource = new JavaScriptPackageResource(getScope(), getName(), getLocale(), getStyle(), getVariation()) { private static final long serialVersionUID = 5615537870274839300L; @Override protected void setResponseHeaders(ResourceResponse resourceResponse, Attributes attributes) { super.setResponseHeaders(resourceResponse, attributes); ((WebResponse) attributes.getResponse()).disableCaching(); } @SuppressWarnings("unchecked") @Override protected byte[] processResponse(Attributes attributes, byte[] bytes) { byte[] bytesToReturn = null; try { RequestCycle requestCycle = RequestCycle.get(); String script = new String(bytes, "UTF-8"); script = script.replace("$(cacheName)", cacheName); JSONArray urlJsonArray = new JSONArray(); for (OfflineCacheEntry offlineCacheEntry : offlineCacheEntries) { Object cacheObject = offlineCacheEntry.getCacheObject(); PageParameters pageParameters = offlineCacheEntry.getPageParameters(); String suffix = offlineCacheEntry.getSuffix(); Cors cors = offlineCacheEntry.getCors(); if (cacheObject == null) { throw new WicketRuntimeException( "Please provide a cache object to each OfflineCacheEntry."); } CharSequence urlFor; if (cacheObject instanceof ResourceReference) { urlFor = requestCycle.urlFor((ResourceReference) cacheObject, pageParameters); } else if (cacheObject instanceof Class) { urlFor = requestCycle.urlFor((Class<? extends Page>) cacheObject, pageParameters); } else if (cacheObject instanceof IRequestHandler) { urlFor = requestCycle.urlFor((IRequestHandler) offlineCacheEntry); } else { urlFor = cacheObject.toString(); } if (urlFor.toString().equals(".")) { urlFor = "/"; } else if (urlFor.toString().startsWith(".")) { urlFor = urlFor.toString().substring(1); } String url = urlFor.toString() + (suffix != null ? suffix : ""); JSONObject object = new JSONObject(); if (cors != null) { object.put("cors", cors.getRealName()); } object.put("url", url); urlJsonArray.put(object); } String urlJsonArrayAsString = urlJsonArray.toString(); script = script.replace("$(offlineCacheEntries)", urlJsonArrayAsString); bytesToReturn = script.getBytes(); } catch (UnsupportedEncodingException e) { // NOOP } return super.processResponse(attributes, bytesToReturn); } }; removeCompressFlagIfUnnecessary(resource); return resource; }
From source file:org.wicketstuff.offline.mode.ServiceWorkerRegistration.java
License:Apache License
/** * Override getResource() because it has be ensured that there is no cache applied to the * resource/* www . j av a 2 s . co m*/ */ @Override public JavaScriptPackageResource getResource() { final JavaScriptPackageResource resource = new JavaScriptPackageResource(getScope(), getName(), getLocale(), getStyle(), getVariation()) { private static final long serialVersionUID = 6651316937259448962L; @Override protected void setResponseHeaders(ResourceResponse resourceResponse, Attributes attributes) { super.setResponseHeaders(resourceResponse, attributes); ((WebResponse) attributes.getResponse()).disableCaching(); } }; removeCompressFlagIfUnnecessary(resource); return resource; }