@Override public FeatureResource load(Uri uri, Map<String, String> attribs) throws GadgetException { lastAttribs = ImmutableMap.copyOf(attribs); return super.load(uri, attribs); }
private String get() { long nowTime = timeSource.currentTimeMillis(); if (content == null || (updateCheckFrequency > 0 && (lastUpdateCheckTime + updateCheckFrequency) < nowTime)) { // Only check for file updates at preconfigured intervals. This prevents // overwhelming the file system while maintaining a reasonable update rate w/o // implementing a full event-driven mechanism. lastUpdateCheckTime = nowTime; File file = new File(filePath); if (fileHasChanged(file, lastModified)) { // Only reload file content if it's changed (or if it's the first // load, when this check will succeed). String newContent = getFileContent(file); if (newContent != null) { content = newContent; lastModified = file.lastModified(); } else if (content != null) { // Content existed before, file removed - log error. LOG.warning("File existed before but is now missing! Name: " + filePath); } } } return content; } }
protected FeatureResource loadResource( String path, Map<String, String> attribs) throws IOException { return new DualModeStaticResource(path, getResourceContent(getOptPath(path)), getResourceContent(path)); }
/** * Primary, and only public, method of FeatureResourceLoader. Loads the resource * keyed at the given {@code uri}, which was decorated with the provided list of attributes. * * The default implementation loads both file and res-schema resources using * ResourceLoader, attempting to load optimized content for files named [file].js as [file].opt.js. * * Override this method to provide custom functionality. Basic loadFile, loadResource, and loadUri * methods are kept protected for easy reuse. * * @param uri Uri of resource to be loaded. * @param attribs Attributes decorating the resource in the corresponding feature.xml * @return FeatureResource object providing content and debugContent loading capability. * @throws GadgetException If any failure occurs during this process. */ public FeatureResource load(Uri uri, Map<String, String> attribs) throws GadgetException { try { if ("file".equals(uri.getScheme())) { return loadFile(uri.getPath(), attribs); } else if ("res".equals(uri.getScheme())) { return loadResource(uri.getPath(), attribs); } return loadUri(uri, attribs); } catch (IOException e) { throw new GadgetException(GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT, e); } }
@SuppressWarnings("unused") protected FeatureResource loadFile(String path, Map<String, String> attribs) throws IOException { return new DualModeFileResource(getOptPath(path), path, attribs); }
private void loadResources(List<String> resources, Map<String,FeatureNode> featureMapBuilder) throws GadgetException { try { for (String resource : resources) { if (LOG.isLoggable(Level.FINE)) { LOG.fine("Processing resource: " + resource); } String content = resourceLoader.getResourceContent(resource); Uri parent = new UriBuilder().setScheme(RESOURCE_SCHEME).setPath(resource).toUri(); loadFeature(parent, content, featureMapBuilder); } } catch (IOException e) { throw new GadgetException(GadgetException.Code.INVALID_PATH, e); } }
/** * Primary, and only public, method of FeatureResourceLoader. Loads the resource * keyed at the given {@code uri}, which was decorated with the provided list of attributes. * * The default implementation loads both file and res-schema resources using * ResourceLoader, attempting to load optimized content for files named [file].js as [file].opt.js. * * Override this method to provide custom functionality. Basic loadFile, loadResource, and loadUri * methods are kept protected for easy reuse. * * @param uri Uri of resource to be loaded. * @param attribs Attributes decorating the resource in the corresponding feature.xml * @return FeatureResource object providing content and debugContent loading capability. * @throws GadgetException If any failure occurs during this process. */ public FeatureResource load(Uri uri, Map<String, String> attribs) throws GadgetException { try { if ("file".equals(uri.getScheme())) { return loadFile(uri.getPath(), attribs); } else if ("res".equals(uri.getScheme())) { return loadResource(uri.getPath(), attribs); } return loadUri(uri, attribs); } catch (IOException e) { throw new GadgetException(GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT, e); } }
protected FeatureResource loadFile(String path, Map<String, String> attribs) throws IOException { return new DualModeFileResource(getOptPath(path), path); }
for (String resource : CRLF_SPLITTER.split(resourceLoader.getResourceContent(location))) { if (resource.charAt(0) != '#') {
@Override public FeatureResource load(Uri uri, Map<String, String> attribs) throws GadgetException { return new BrowserSpecificFeatureResource( uaProvider, super.load(uri, attribs), attribs.get("browser")); } }
/** * Primary, and only public, method of FeatureResourceLoader. Loads the resource * keyed at the given {@code uri}, which was decorated with the provided list of attributes. * * The default implementation loads both file and res-schema resources using * ResourceLoader, attempting to load optimized content for files named [file].js as [file].opt.js. * * Override this method to provide custom functionality. Basic loadFile, loadResource, and loadUri * methods are kept protected for easy reuse. * * @param uri Uri of resource to be loaded. * @param attribs Attributes decorating the resource in the corresponding feature.xml * @return FeatureResource object providing content and debugContent loading capability. * @throws GadgetException If any failure occurs during this process. */ public FeatureResource load(Uri uri, Map<String, String> attribs) throws GadgetException { try { if ("file".equals(uri.getScheme())) { return loadFile(uri.getPath(), attribs); } else if ("res".equals(uri.getScheme())) { return loadResource(uri.getPath(), attribs); } return loadUri(uri, attribs); } catch (IOException e) { throw new GadgetException(GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT, e); } }
protected FeatureResource loadResource( String path, Map<String, String> attribs) throws IOException { return new DualModeStaticResource(path, getResourceContent(getOptPath(path)), getResourceContent(path)); }
private String get() { long nowTime = timeSource.currentTimeMillis(); if (content == null || (updateCheckFrequency > 0 && (lastUpdateCheckTime + updateCheckFrequency) < nowTime)) { // Only check for file updates at preconfigured intervals. This prevents // overwhelming the file system while maintaining a reasonable update rate w/o // implementing a full event-driven mechanism. lastUpdateCheckTime = nowTime; File file = new File(filePath); if (fileHasChanged(file, lastModified)) { // Only reload file content if it's changed (or if it's the first // load, when this check will succeed). String newContent = getFileContent(file); if (newContent != null) { content = newContent; lastModified = file.lastModified(); } else if (content != null) { // Content existed before, file removed - log error. LOG.warning("File existed before but is now missing! Name: " + filePath); } } } return content; } }
protected FeatureResource loadFile(String path, Map<String, String> attribs) throws IOException { return new DualModeFileResource(getOptPath(path), path); }
@Override public FeatureResource load(Uri uri, Map<String, String> attribs) throws GadgetException { return new BrowserSpecificFeatureResource( uaProvider, super.load(uri, attribs), attribs.get("browser")); } }
@SuppressWarnings("unused") protected FeatureResource loadResource( String path, Map<String, String> attribs) throws IOException { String optContent = null, debugContent = null; try { optContent = getResourceContent(getOptPath(path)); } catch (IOException e) { // OK - optContent can be null. Error thrown downstream if both are null. } try { debugContent = getResourceContent(path); } catch (IOException e) { // See above; OK for debugContent to be null. } return new DualModeStaticResource(path, optContent, debugContent, attribs); }
return null; if (fileHasChanged(file, lastModified)) { String newContent = getFileContent(file); if (newContent != null) { content = newContent;
@Override public FeatureResource load(Uri uri, Map<String, String> attribs) throws GadgetException { return new BrowserSpecificFeatureResource( uaProvider, super.load(uri, attribs), attribs.get("browser")); } }
public FeatureResource load(Uri uri, Map<String, String> attribs) throws GadgetException { lastAttribs = ImmutableMap.copyOf(attribs); return super.load(uri, attribs); } @Override
} else { resources.add(resourceLoader.load(parsedResource.getSource(), getResourceAttribs(parsedBundle.getAttribs(), parsedResource.getAttribs())));