/** * Reads contents of file fully and returns as string. * * @param fileName file name. * @return contents of entire file. */ public static String readFile(String fileName) { return readFile(fileName, "UTF-8"); }
/** * Reads contents of file fully and returns as string. * * @param fileName file name. * @return contents of entire file. */ public static String readFile(String fileName) { return readFile(fileName, "UTF-8"); }
/** * Reads contents of file fully and returns as string. * * @param fileName file name. * @return contents of entire file. */ public static String readFile(String fileName) { return readFile(fileName, "UTF-8"); }
private String loadTemplate(String templateName){ String slash = templateName.startsWith("/") ? "" : "/"; //for tests, load from location if (templateLocation != null) { return readFile(templateLocation + slash + templateName, "UTF-8"); } //proceed to load from servlet context String fullPath = "/WEB-INF/views" + slash + templateName; // First try to open as plain file (to bypass servlet container resource caches). String realPath = servletContext.getRealPath(fullPath); try { if (realPath != null) { File file = new File(realPath); if (!file.isFile()) { throw new TemplateException(realPath + " is not a file"); } if (file.canRead()) { return readFile(realPath, "UTF-8"); } } } catch (SecurityException ignore) {} try { URL url = servletContext.getResource(fullPath); return Util.read(url.openStream(), "UTF-8"); } catch (Exception e) {throw new TemplateException(e);} }