use of org.xwiki.formula.ImageStorage in project xwiki-platform by xwiki.
the class TexAction method render.
@Override
public String render(XWikiContext context) throws XWikiException {
XWikiRequest request = context.getRequest();
XWikiResponse response = context.getResponse();
String path = request.getRequestURI();
// Expected /xwiki/bin/tex/Current/Document/image_identifier
String filename = Util.decodeURI(path.substring(path.lastIndexOf("/") + 1), context);
ImageStorage storage = Utils.getComponent(ImageStorage.class);
ImageData image = storage.get(filename);
if (image == null) {
return "docdoesnotexist";
}
response.setContentLength(image.getData().length);
response.setContentType(image.getMimeType());
try {
response.getOutputStream().write(image.getData());
} catch (IOException e) {
LOGGER.info("Failed to send image to the client");
}
return null;
}
use of org.xwiki.formula.ImageStorage 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.xwiki.formula.ImageStorage in project xwiki-platform by xwiki.
the class IntegrationTests method initialize.
@RenderingTestSuite.Initialized
public void initialize(MockingComponentManager componentManager) throws Exception {
Mockery mockery = new JUnit4Mockery();
// Document Access Bridge Mock
final DocumentAccessBridge mockDocumentAccessBridge = componentManager.registerMockComponent(mockery, DocumentAccessBridge.class);
// Image Storage Mock
final ImageStorage mockImageStorage = componentManager.registerMockComponent(mockery, ImageStorage.class);
// Configuration Mock
final FormulaMacroConfiguration mockConfiguration = componentManager.registerMockComponent(mockery, FormulaMacroConfiguration.class);
mockery.checking(new Expectations() {
{
atLeast(1).of(mockDocumentAccessBridge).getCurrentDocumentReference();
DocumentReference documentReference = new DocumentReference("wiki", "space", "page");
will(returnValue(documentReference));
AttachmentReference attachmentReference = new AttachmentReference("06fbba0acf130efd9e147fdfe91a943cc4f3e29972c6cd1d972e9aabf0900966", documentReference);
atLeast(2).of(mockDocumentAccessBridge).getAttachmentURL(attachmentReference, false);
will(returnValue("/xwiki/bin/view/space/page/06fbba0acf130efd9e147fdfe91a943cc4f3e29972c6cd1d972e9aabf0900966"));
atLeast(2).of(mockConfiguration).getRenderer();
will(returnValue("snuggletex"));
atLeast(2).of(mockImageStorage).get(with(any(String.class)));
will(returnValue(null));
atLeast(2).of(mockImageStorage).put(with(any(String.class)), with(any(ImageData.class)));
}
});
}
use of org.xwiki.formula.ImageStorage in project xwiki-platform by xwiki.
the class PDFURIResolver method resolve.
@Override
public Source resolve(String href, String base) throws TransformerException {
if (this.attachmentMap != null) {
// implemented for TemporaryResource...
if (href.contains(TEX_ACTION)) {
// Note: See the comments in FormulaMacro to understand why we do a replace...
AttachmentReference reference = this.attachmentMap.get(href.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 StreamSource(new ByteArrayInputStream(image.getData()));
}
}
// TODO: end HACK
AttachmentReference reference = this.attachmentMap.get(href);
if (reference != null) {
try {
XWikiDocument xdoc = this.context.getWiki().getDocument(reference.extractReference(EntityType.DOCUMENT), this.context);
// TODO: handle revisions
XWikiAttachment attachment = xdoc.getAttachment(reference.extractReference(EntityType.ATTACHMENT).getName());
return new StreamSource(attachment.getContentInputStream(this.context));
} catch (Exception e) {
throw new TransformerException(String.format("Failed to resolve export URI [%s]", href), e);
}
}
}
// Defaults to the default URI Resolver in FO
return null;
}
Aggregations