/** * Extracts (constructs) resource cache key validator/transmogrifier parameters. * <p/> * Per default, the key equals to the resource location. * * @param params validator/transmogrifier parameters. * @return cache key as a String. */ protected String resourceCacheKey(Object... params) { return resourceLocation(params); }
/** * Loads the resource into memory and returns it as a Stream. * <p/> * This method does not need to be re-entrant. * * @param params validator/transmogrifier parameters. * @return resource of the configured type. */ protected StreamSource resourceContent(Object... params) { String location = resourceLocation(params); URL url; try { if (location.startsWith("/")) { url = getClass().getResource(location); } else { try { // Try to parse the location as a URL... url = new URL(location); } catch (MalformedURLException ex) { // No URL -> resolve as resource path. url = getClass().getClassLoader().getResource(location); if (url == null) throw new IOException("Location not found"); } } return new StreamSource(url.openStream(), url.toExternalForm()); } catch (IOException e) { throw new IllegalArgumentException("The resource " + location + " is not valid", e); } }