protected URL getResource(String templatePath) { if (useCache) { URL cachedURL = cache.get(templatePath); if (cachedURL != null) { return cachedURL; } } URL resource = ClasspathUtils.locateOnClasspath(templatePath); return resource; } }
/** * Attempts to load a message resource. */ private Properties loadMessages(String fileOrUrl) { URL url = ClasspathUtils.locateOnClasspath(fileOrUrl); if (url != null) { try (InputStreamReader reader = new InputStreamReader(url.openStream(), StandardCharsets.UTF_8)) { Properties messages = new Properties(); messages.load(reader); return messages; } catch (IOException e) { log.error("Failed to load {}", fileOrUrl, e); } } return null; }
/** * Simply reads a property resource file that contains the version of this * Pippo build. Helps to identify the Pippo version currently running. * * @return The version of Pippo. Eg. "1.6-SNAPSHOT" while developing of "1.6" when released. */ public static String getPippoVersion() { // and the key inside the properties file. String pippoVersionPropertyKey = "pippo.version"; String pippoVersion; try { Properties prop = new Properties(); URL url = ClasspathUtils.locateOnClasspath(PippoConstants.LOCATION_OF_PIPPO_BUILTIN_PROPERTIES); InputStream stream = url.openStream(); prop.load(stream); pippoVersion = prop.getProperty(pippoVersionPropertyKey); } catch (Exception e) { //this should not happen. Never. throw new PippoRuntimeException("Something is wrong with your build. Cannot find resource {}", PippoConstants.LOCATION_OF_PIPPO_BUILTIN_PROPERTIES); } return pippoVersion; }
url = ClasspathUtils.locateOnClasspath(PippoConstants.LOCATION_OF_PIPPO_CLASSPATH_PROPERTIES); url = ClasspathUtils.locateOnClasspath(PippoConstants.LOCATION_OF_PIPPO_BUILTIN_PROPERTIES);
for (String pomProperties : locatePomProperties()) { log.debug("Parsing Webjars metadata {}", pomProperties); URL url = ClasspathUtils.locateOnClasspath(pomProperties); Properties pom = new Properties(); try (InputStream is = url.openStream()) {
private void init() { // Load default mimetypes from the framework URL url = ClasspathUtils.locateOnClasspath(PippoConstants.LOCATION_OF_PIPPO_MIMETYPE_PROPERTIES); if (url == null) { log.error("Could not locate '{}'!", PippoConstants.LOCATION_OF_PIPPO_MIMETYPE_PROPERTIES); } else { try (InputStream is = url.openStream()) { mimetypes.load(is); } catch (Exception e) { log.warn(e.getMessage()); } } // Load custom mimetypes from the application configuration List<String> settingNames = pippoSettings.getSettingNames(PippoConstants.SETTING_MIMETYPE_PREFIX); for (String key : settingNames) { String type = key.substring(PippoConstants.SETTING_MIMETYPE_PREFIX.length()).toLowerCase(); String value = pippoSettings.getString(key, null); if (!StringUtils.isNullOrEmpty(value)) { mimetypes.setProperty(type, value); } } }
@Override public Reader getReader(String templateName) throws LoaderException { StringBuilder path = new StringBuilder(); if (getPrefix() != null) { path.append(getPrefix()); if (!getPrefix().endsWith(String.valueOf('/'))) { path.append('/'); } } String resource = path.toString() + templateName + (getSuffix() == null ? "" : getSuffix()); String location = resource; if (resource.charAt(0) == '/') { location = resource.substring(1); } URL url = ClasspathUtils.locateOnClasspath(location); if (url == null) { throw new LoaderException(null, "Could not find template \"" + location + "\""); } Reader reader; try { InputStream is = url.openStream(); InputStreamReader isr = new InputStreamReader(is, getCharset()); reader = new BufferedReader(isr); } catch (IOException e) { throw new PippoRuntimeException(e); } return reader; }
protected URL getResource(String templatePath) { if (useCache) { URL cachedURL = cache.get(templatePath); if (cachedURL != null) { return cachedURL; } } URL resource = ClasspathUtils.locateOnClasspath(templatePath); return resource; } }