private CachedPage renderLocalAsset(URL localSourceUrl) throws IOException { return new CachedPage(Resources.toByteArray(localSourceUrl), ResourceURL.getLastModified(localSourceUrl), com.google.common.net.MediaType.CSS_UTF_8.toString()); }
@Override public Asset load(String key) throws Exception { for (Map.Entry<String, String> mapping : resourcePathToUriMappings.entrySet()) { if (!key.startsWith(mapping.getValue())) { continue; } Asset asset = loadOverride(key); if (asset != null) { return asset; } final String requestedResourcePath = SLASHES.trimFrom(key.substring(mapping.getValue().length())); final String absolutePath = SLASHES.trimFrom(mapping.getKey() + requestedResourcePath); try { URL requestedResourceUrl = UrlUtil.switchFromZipToJarProtocolIfNeeded(Resources.getResource(absolutePath)); if (ResourceURL.isDirectory(requestedResourceUrl)) { if (indexFilename != null) { requestedResourceUrl = Resources.getResource(absolutePath + '/' + indexFilename); requestedResourceUrl = UrlUtil.switchFromZipToJarProtocolIfNeeded(requestedResourceUrl); } else { // resource mapped to directory but no index file defined continue; } } long lastModified = ResourceURL.getLastModified(requestedResourceUrl); if (lastModified < 1) { // Something went wrong trying to get the last modified time: just use the current time lastModified = System.currentTimeMillis(); } // zero out the millis; the If-Modified-Since header will not have them lastModified = (lastModified / 1000) * 1000; return new StaticAsset(Resources.toByteArray(requestedResourceUrl), lastModified); } catch (IllegalArgumentException expected) { // Try another Mapping. } } return null; }