/** * Create a StringResource with the cached value read from the resource location. * @param location * @param escapeNeeded */ public StringResource(String location, boolean escapeNeeded) { this.content = get(location); this.escapeNeeded = escapeNeeded; } /**
/** * Return a StringResource for rendering the text available at <code>location</code> * @param location , the file on the classpath containing the resource text * @return a new StringResource */ public static StringResource valueOf(String location) { return new StringResource(location); } /**
/** * Access the String contents from the given resource location. * @param location * @param doCache * @return resource contents , never null */ public static String get(String location, boolean doCache) { String content = null; if (doCache) { content = CACHE.get(location); } if (content == null) { content = contentOrNull(location); if (content == null) { content = "[StringResource] Missing or error reading resource:" + location; } else { if (doCache) { CACHE.put(location, content); } } } return content; } /**
/** * Use the resource location to read the String contents. * @param location * @return String | null if resource is not available */ @SuppressWarnings("PMD.EmptyCatchBlock") private static String contentOrNull(String location) { if (location.startsWith("http://")) { return fetchContentOrNull(location); } String content = null; InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(location); if (is == null) { // retry different loader is = StringResource.class.getResourceAsStream(location); } if (is != null) { try { BufferedReader reader = new BufferedReader(new InputStreamReader(is)); StringBuilder builder = new StringBuilder(256); while (reader.ready()) builder.append(reader.readLine()).append('\n'); content = builder.toString(); } catch (IOException e) { Logger.getAnonymousLogger().log(Level.WARNING, "Unable to fetch content from:"+ location); // eat it, content stays null } } return content; }
/** * Create a StringResource with the cached value read from the resource location * @param location */ public StringResource(String location) { this.content = get(location); } /**
/** * Access the String contents from the given resource location. * The contents is cached by StringResource. Use get(location,false); for non-cached access. * @param location * @return resource contents , never null */ public static String get(String location) { return get(location, true); } /**
private static void amendReport() throws IOException { html.script().content(StringResource.get("/raphael/raphael-min.js"), NO_ESCAPE); html.script().content(StringResource.get("/prototype/prototype.js"), NO_ESCAPE); html.script().content(StringResource.get("/grafico/grafico-min.js"), NO_ESCAPE); html.write(graphs.toString(), NO_ESCAPE); html._body()._html(); }
private void writeCss() throws IOException { html.style().write(StringResource.get("reportStyle.css"), NO_ESCAPE) ._style(); }
private static void writeCss() throws IOException { html.style().write(StringResource.get("testCaseStyle.css"), NO_ESCAPE) ._style(); }