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; }
/** * Constructor. * @param bundle File bundle. * @param name File name. * @param downloadable Whether the file is downloadable. * @param files Files contained in the bundle. */ public static FileBundleData create(FileData bundle, Map<String, FileData> files) { checkNotNull(bundle, "File bundle"); checkArgument(bundle.isBundle(), "Not a bundle"); return new FileBundleData(bundle.getId(), bundle.getName(), bundle.isDownloadable(), files); }
/** * Creates an item file. * @param bundle Bundle containing the file. * @param name File name. * @param mediaType Media type. * @param data File data. * @param copy If the constructor should perform a copy of the provided data. */ public static FileData item(FileData bundle, final String name, MediaType mediaType, byte[] data, boolean copy) { checkNotNull(bundle, "File bundle"); checkArgument(bundle.isBundle(), "Not a bundle"); return new FileData(bundle.getId(), name, mediaType, bundle.isDownloadable(), FileType.ITEM, data, copy); }
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; } }
private Response getUploadedFile(FileData data) { return getFile(data).header("Content-Disposition", "attachment; filename=" + data.getName()).build(); }
/** * @see com.isotrol.impe3.api.component.EditModeComponent#edit() */ public void edit() { if (config != null) { rel = config.rel(); if (rel == null) { rel = "icon"; } FileData file = fileLoader.load(config.icon()); type = file.getMediaType(); uri = uriGenerator.getURI(config.icon()); } }
private Response getDownloadableFile(FileData data) { checkArgument(data.isDownloadable()); return getFile(data).build(); }
private FileData getFile(FileEntity entity) throws PMSException { final String savedName = entity.getName(); return new FileData(entity.getId(), savedName, FileLoaderSupport.getMediaType(savedName), entity.isDownloadable(), entity.isBundle(), entity.getData(), false); }
public boolean isBundle() { return getType() == FileType.BUNDLE; }
/** * 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 } }
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; }
@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; } }
/** * @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; } }