@Test public void resolveWhenNoMap() throws Exception { XWikiContext context = mock(XWikiContext.class); PDFURIResolver resolver = new PDFURIResolver(context); Source source = resolver.resolve("href", "base"); assertNull(source); }
@Override public Source resolve(String href, String base) throws TransformerException { if (this.attachmentMap != null) { if (href.contains(TEX_ACTION)) { AttachmentReference reference = this.attachmentMap.get(href.replace(TEX_ACTION, "/download/")); if (reference != null) { ImageStorage storage = Utils.getComponent(ImageStorage.class); ImageData image = storage.get(reference.getName()); return new StreamSource(new ByteArrayInputStream(image.getData())); } } AttachmentReference reference = this.attachmentMap.get(href); if (reference != null) { try { XWikiDocument xdoc = this.context.getWiki().getDocument( reference.extractReference(EntityType.DOCUMENT), this.context); 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); } } } return null; }
PDFURIResolver implements URIResolver { @Override public Source resolve(String href, String base) throws TransformerException { if (this.attachmentMap != null) { if (href.contains(TEX_ACTION)) { AttachmentReference reference = this.attachmentMap.get(href.replace(TEX_ACTION, "/download/")); if (reference != null) { ImageStorage storage = Utils.getComponent(ImageStorage.class); ImageData image = storage.get(reference.getName()); return new StreamSource(new ByteArrayInputStream(image.getData())); } } AttachmentReference reference = this.attachmentMap.get(href); if (reference != null) { try { XWikiDocument xdoc = this.context.getWiki().getDocument( reference.extractReference(EntityType.DOCUMENT), this.context); 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); } } } return null; } }
PDFURIResolver implements URIResolver { @Override public Source resolve(String href, String base) throws TransformerException { if (this.attachmentMap != null) { if (href.contains(TEX_ACTION)) { AttachmentReference reference = this.attachmentMap.get(href.replace(TEX_ACTION, "/download/")); if (reference != null) { ImageStorage storage = Utils.getComponent(ImageStorage.class); ImageData image = storage.get(reference.getName()); return new StreamSource(new ByteArrayInputStream(image.getData())); } } AttachmentReference reference = this.attachmentMap.get(href); if (reference != null) { try { XWikiDocument xdoc = this.context.getWiki().getDocument( reference.extractReference(EntityType.DOCUMENT), this.context); 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); } } } return null; } PDFURIResolver(XWikiContext context); }
PDFURIResolver implements URIResolver { @Override public Source resolve(String href, String base) throws TransformerException { if (this.attachmentMap != null) { if (href.contains(TEX_ACTION)) { AttachmentReference reference = this.attachmentMap.get(href.replace(TEX_ACTION, "/download/")); if (reference != null) { ImageStorage storage = Utils.getComponent(ImageStorage.class); ImageData image = storage.get(reference.getName()); return new StreamSource(new ByteArrayInputStream(image.getData())); } } AttachmentReference reference = this.attachmentMap.get(href); if (reference != null) { try { XWikiDocument xdoc = this.context.getWiki().getDocument( reference.extractReference(EntityType.DOCUMENT), this.context); 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); } } } return null; } PDFURIResolver(XWikiContext context); @Override Source resolve(String href, String base); }
PDFURIResolver implements URIResolver { @Override public Source resolve(String href, String base) throws TransformerException { if (this.attachmentMap != null) { if (href.contains(TEX_ACTION)) { AttachmentReference reference = this.attachmentMap.get(href.replace(TEX_ACTION, "/download/")); if (reference != null) { ImageStorage storage = Utils.getComponent(ImageStorage.class); ImageData image = storage.get(reference.getName()); return new StreamSource(new ByteArrayInputStream(image.getData())); } } AttachmentReference reference = this.attachmentMap.get(href); if (reference != null) { try { XWikiDocument xdoc = this.context.getWiki().getDocument( reference.extractReference(EntityType.DOCUMENT), this.context); 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); } } } return null; } PDFURIResolver(XWikiContext context); @Override Source resolve(String href, String base);  }