private static InputStream safeLoad(FileLoader loader, FileId bundle, String name) { try { return loader.loadFromBundle(bundle, name).getData(); } catch (RuntimeException e) { logger.trace("Problem with safe load input stream...", e); return null; } }
/** * Loads a node from a file bundle. * @param loader File loader. * @param bundle File bundle. * @return The loaded node or {@code null} if there is an error. */ public static Node loadXMLNode(FileLoader loader, FileId bundle) { try { final FileData metadata = loader.loadFromBundle(bundle, FITEM_METADATA); final FileData data = loader.loadFromBundle(bundle, FITEM_XML); return NodeLoader.loadNode(metadata.getData(), data.getData()); } catch (Exception e) { logger.trace("Problem loading xml node...", e); return null; // TODO } }
@Override protected Transformer getTransformer() throws TransformerException { if (stylesheet == null) { return null; } final Source xslt = new StreamSource(fileLoader.load(stylesheet).getData()); return fopService.newTransformer(xslt); }
/** * (non-Javadoc) * @see freemarker.cache.TemplateLoader#getReader(java.lang.Object, java.lang.String) */ public Reader getReader(Object templateSource, String encoding) throws IOException { load(); final InputStream is; final String name = templateSource.toString(); if (bundle.contains(name)) { is = bundle.apply(name).getData(); } else { is = new ByteArrayInputStream(new byte[0]); } return new InputStreamReader(is, encoding); }
public Source resolve(String href, String base) throws TransformerException { if (href == null || href.length() <= SCHEME.length() || !href.startsWith(SCHEME)) { if (chain != null) { return chain.resolve(href, base); } return null; } if (bundle == null) { try { bundle = fileLoader.loadBundle(fileId); } catch (RuntimeException e) { return null; } } final String name = href.substring(SCHEME.length()); if (bundle.contains(name)) { return new StreamSource(bundle.apply(name).getData()); } return null; } }
private ResponseBuilder getFile(FileData data) { final EntityTag tag = new EntityTag(data.getId().toString().toLowerCase()); final ResponseBuilder builder = Response.ok(data.getData(), data.getMediaType()); builder.expires(expires()); builder.tag(tag); return builder; }
private ResponseBuilder getFile(FileData data) { final EntityTag tag = new EntityTag(data.getId().toString().toLowerCase()); final ResponseBuilder builder = Response.ok(data.getData(), data.getMediaType()); builder.expires(expires()); builder.tag(tag); return builder; }
fileBuilder.setContent(ByteString.copyFrom(toByteArray(data.getData())));
fileBuilder.setContent(ByteString.copyFrom(toByteArray(data.getData())));
/** * @see com.isotrol.impe3.api.component.EditModeComponent#edit() */ public void edit() { if (htmlConfig == null) { return; } // Encoding if (config != null && config.encoding() != null) { encoding = config.encoding(); } // HTML try { final FileData data; final FileId file = htmlConfig.file(); if (file != null) { data = fileLoader.load(file); } else if (htmlConfig.path() != null && config.bundle() != null) { data = fileLoader.loadFromBundle(config.bundle(), htmlConfig.path()); } else { return; } html = new String(Streams.consume(data.getData(), false), encoding); } catch (Exception e) { html = null; } }
/** * @see com.isotrol.impe3.api.component.EditModeComponent#edit() */ public void edit() { if (htmlConfig == null) { return; } // Encoding if (config != null && config.encoding() != null) { encoding = config.encoding(); } // HTML try { final FileData data; final FileId file = htmlConfig.file(); if (file != null) { data = fileLoader.load(file); } else if (htmlConfig.path() != null && config.bundle() != null) { data = fileLoader.loadFromBundle(config.bundle(), htmlConfig.path()); } else { return; } html = new String(Streams.consume(data.getData(), false), encoding); } catch (Exception e) { html = null; } }