@Override public JtwigResource resolve(String relativePath) throws ResourceException { throw new ResourceException("Cannot resolve relative resources in a String resource"); } }
@Override public JtwigResource resolve(String relativePath) throws ResourceException { throw new ResourceException("Cannot resolve relative resources in a String resource"); } }
@Override public InputStream retrieve() throws ResourceException { try { return new FileInputStream(file); } catch (FileNotFoundException e) { throw new ResourceException(e); } }
@Override public InputStream retrieve() throws ResourceException { InputStream resourceAsStream = servletContext.getResourceAsStream(url); if (resourceAsStream == null) throw new ResourceException("Resource "+url+" not found"); return resourceAsStream; }
@Override public InputStream retrieve() throws ResourceException { try { return new FileInputStream(file); } catch (FileNotFoundException e) { throw new ResourceException(e); } }
@Override public InputStream retrieve() throws ResourceException { try { return new FileInputStream(resourcePath.toFile()); } catch (FileNotFoundException e) { throw new ResourceException(e); } }
@Override public InputStream retrieve() throws ResourceException { InputStream resourceAsStream = this.getClass().getClassLoader().getResourceAsStream(this.resource); if (resourceAsStream == null) throw new ResourceException("Resource '"+ this.resource +"' not found"); return resourceAsStream; }
@Override public InputStream retrieve() throws ResourceException { InputStream resourceAsStream = this.getClass().getClassLoader().getResourceAsStream(this.resource); if (resourceAsStream == null) throw new ResourceException("Resource '"+ this.resource +"' not found"); return resourceAsStream; }
@Override public JtwigResource resolve(String relativePath) throws ResourceException { if (resourcePath.getParent().resolve(relativePath).toFile().isFile()) { return new JailedPathJtwigResource(jail, resourcePath.getParent().resolve(relativePath)); } // If not found, try to find a not-localized version of the template Path path = resourcePath.getParent(); Stack<Path> saved = new Stack<>(); while (path.toAbsolutePath().startsWith(this.jail.toAbsolutePath())) { if (path.getFileName().toString().equals("localized")) { saved.pop(); // pop language (like "fr", etc.) Path notLocalized = path.getParent(); while(!saved.empty()) { notLocalized = notLocalized.resolve(saved.pop()); } return new JailedPathJtwigResource(jail, notLocalized.resolve(relativePath)); } else { saved.push(path.getFileName()); path = path.getParent(); } } throw new ResourceException("Not found"); } }