@Override public List<Event> getEvents() { return Arrays.<Event>asList(new PermanentFileEvent()); }
private Optional<Path> getInvoicingDirectory(Tenant tenant) { if (tenant != null) { Path localInvoicingDirectory = fileManager.resolvePermanentFilePath( Paths.get("tenants").resolve(tenant.getSlug()).resolve("invoicing")); if (localInvoicingDirectory.resolve(INVOICE_TEMPLATE_FILE_NAME).toFile().isFile()) { return Optional.of(localInvoicingDirectory); } } Path globalInvoicingDirectory = fileManager.resolvePermanentFilePath(Paths.get("invoicing")); if (globalInvoicingDirectory.resolve(INVOICE_TEMPLATE_FILE_NAME).toFile().isFile()) { return Optional.of(globalInvoicingDirectory); } return Optional.absent(); }
Path watched = (Path) watchKey.watchable(); for (WatchEvent event : events) { PermanentFileEvent permanentFileEvent = new PermanentFileEvent(); Path context = watched.resolve((Path) event.context()); WatchEvent.Kind eventKind = event.kind(); PermanentFileEvent.Data memo = new PermanentFileEvent.Data(context, eventKind); observationManager.notify(permanentFileEvent, this, memo);
public void initialize() throws InitializationException { loadImage = new LoadImageFunction(imageProcessor); imageFileCache = fileManager.resolvePermanentFilePath(Paths.get("imagecache")); if (!imageFileCache.toFile().isDirectory()) { // The image cache directory for this image does not exist, create it try { Files.createDirectory(imageFileCache); } catch (IOException e) { throw new InitializationException("Failed to initialize image cache. Is the data directory writable ?"); } } }
private Optional<Path> resolveTemplate(Path base, MailTemplate mail) { Path templatePath = null; if (mail.locale().isPresent()) { templatePath = fileManager.resolvePermanentFilePath( base.resolve("emails")).resolve("localized") .resolve(mail.locale().get().toLanguageTag()) .resolve(mail.template() + ".twig"); if (!templatePath.toFile().isFile()) { templatePath = fileManager.resolvePermanentFilePath( base.resolve("emails")).resolve("localized") .resolve(mail.locale().get().getLanguage()) .resolve(mail.template() + ".twig"); } } if (templatePath == null || !templatePath.toFile().isFile()) { // Failed to find a localized mail, try the default one templatePath = fileManager.resolvePermanentFilePath(base.resolve("emails")) .resolve(mail.template() + ".twig"); } return templatePath.toFile().isFile() ? Optional.of(templatePath) : Optional.<Path>absent(); }
@Override public String renderAsString(Path templatePath, Map<String, Object> data) throws TemplateRenderingException { JtwigTemplate template = new JtwigTemplate(new JailedPathJtwigResource(fileManager.resolvePermanentFilePath(Paths.get(".")), templatePath), new JtwigConfiguration()); JtwigModelMap model = new JtwigModelMap(); model.add(data); try { return template.output(model); } catch (CompileException | RenderException | ParseException e) { throw new TemplateRenderingException(e); } } }
@Override public void render(Path templatePath, Map<String, Object> data, OutputStream outputStream) throws TemplateRenderingException { JtwigTemplate template = new JtwigTemplate(new JailedPathJtwigResource(fileManager.resolvePermanentFilePath(Paths.get(".")), templatePath), new JtwigConfiguration()); JtwigModelMap model = new JtwigModelMap(); model.add(data); try { template.output(outputStream, model); } catch (CompileException | RenderException | ParseException e) { throw new TemplateRenderingException(e); } }