use of org.apache.xmlgraphics.io.Resource in project xwiki-platform by xwiki.
the class PDFResourceResolver method getResource.
@Override
public Resource getResource(URI uri) throws IOException {
XWikiContext xcontext = xcontextProvider.get();
Map<String, AttachmentReference> attachmentMap = (Map<String, AttachmentReference>) xcontext.get(PdfURLFactory.PDF_EXPORT_CONTEXT_KEY);
if (attachmentMap != null) {
String uriString = uri.toString();
// implemented for TemporaryResource...
if (uriString.contains(TEX_ACTION)) {
// Note: See the comments in FormulaMacro to understand why we do a replace...
AttachmentReference reference = attachmentMap.get(uriString.replace(TEX_ACTION, "/download/"));
if (reference != null) {
// Get the generated image's input stream
ImageStorage storage = Utils.getComponent(ImageStorage.class);
ImageData image = storage.get(reference.getName());
return new Resource(new ByteArrayInputStream(image.getData()));
}
}
// TODO: end HACK
AttachmentReference reference = attachmentMap.get(uriString);
if (reference != null) {
try {
XWikiDocument xdoc = xcontext.getWiki().getDocument(reference.extractReference(EntityType.DOCUMENT), xcontext);
// TODO: handle revisions
XWikiAttachment attachment = xdoc.getAttachment(reference.extractReference(EntityType.ATTACHMENT).getName());
return new Resource(attachment.getContentInputStream(xcontext));
} catch (Exception e) {
throw new IOException(String.format("Failed to resolve export URI [%s]", uriString), e);
}
}
}
return this.standardResolver.getResource(uri);
}
use of org.apache.xmlgraphics.io.Resource in project grafikon by jub77.
the class PdfTransformer method convertResolver.
private static ResourceResolver convertResolver(URIResolver uriResolver) {
return new ResourceResolver() {
@Override
public Resource getResource(URI uri) throws IOException {
String asciiUri = uri.toASCIIString();
InputStream is = PdfTransformer.class.getClassLoader().getResourceAsStream(asciiUri);
if (is == null && uriResolver != null) {
try {
StreamSource streamSource = (StreamSource) uriResolver.resolve(asciiUri, null);
if (streamSource != null) {
is = streamSource.getInputStream();
}
} catch (TransformerException e) {
throw new IOException(e);
}
}
return is == null ? null : new Resource(is);
}
@Override
public OutputStream getOutputStream(URI uri) throws IOException {
return null;
}
};
}
Aggregations