@Test public void testViewPresentation() throws Exception { AttachmentResourceReference attachResourceRef = new AttachmentResourceReference("xwiki:Some.Page@presentation.odp"); DocumentReference documentReference = new DocumentReference("wiki", "Some", "Page"); AttachmentReference attachmentReference = new AttachmentReference("presentation.odp", documentReference); AttachmentReferenceResolver<String> attachmentReferenceResolver = mocker.getInstance(AttachmentReferenceResolver.TYPE_STRING, "current"); when(attachmentReferenceResolver.resolve(attachResourceRef.getReference())).thenReturn(attachmentReference); when(documentAccessBridge.getAttachmentReferences(attachmentReference.getDocumentReference())).thenReturn( Arrays.asList(attachmentReference)); when(documentAccessBridge.getAttachmentVersion(attachmentReference)).thenReturn("3.2"); ByteArrayInputStream attachmentContent = new ByteArrayInputStream(new byte[256]); when(documentAccessBridge.getAttachmentContent(attachmentReference)).thenReturn(attachmentContent); ResourceReference imageReference = new ResourceReference("slide0.png", ResourceType.URL); ExpandedMacroBlock galleryMacro = new ExpandedMacroBlock("gallery", Collections.singletonMap("width", "300px"), null, false); galleryMacro.addChild(new ImageBlock(imageReference, true)); XDOM xdom = new XDOM(Collections.<Block>singletonList(galleryMacro)); Map<String, byte[]> artifacts = Collections.singletonMap("slide0.png", new byte[8]); XDOMOfficeDocument xdomOfficeDocument = new XDOMOfficeDocument(xdom, artifacts, mocker); PresentationBuilder presentationBuilder = mocker.getInstance(PresentationBuilder.class); when(presentationBuilder.build(attachmentContent, attachmentReference.getName(), documentReference)) .thenReturn(xdomOfficeDocument); Map<String, ?> viewParameters = Collections.singletonMap("ownerDocument", documentReference); TemporaryResourceReference temporaryResourceReference = new TemporaryResourceReference("officeviewer", Arrays.asList(String.valueOf(viewParameters.hashCode()), "slide0.png"), documentReference); Type type = new DefaultParameterizedType(null, ResourceReferenceSerializer.class, TemporaryResourceReference.class, ExtendedURL.class); ResourceReferenceSerializer<TemporaryResourceReference, ExtendedURL> urlTemporaryResourceReferenceSerializer = mocker.getInstance(type, "standard/tmp"); ExtendedURL extendedURL = new ExtendedURL(Arrays.asList("url", "to", "slide0.png")); when(urlTemporaryResourceReferenceSerializer.serialize(temporaryResourceReference)).thenReturn(extendedURL); XDOM output = this.mocker.getComponentUnderTest().createView(attachResourceRef, viewParameters); ImageBlock imageBlock = (ImageBlock) output.getBlocks(new ClassBlockMatcher(ImageBlock.class), Block.Axes.DESCENDANT).get(0); assertEquals("/url/to/slide0.png", imageBlock.getReference().getReference()); galleryMacro = (ExpandedMacroBlock) output .getBlocks(new ClassBlockMatcher(ExpandedMacroBlock.class), Block.Axes.DESCENDANT).get(0); assertFalse(galleryMacro.getParent() instanceof XDOM); assertEquals(Syntax.XWIKI_2_1, ((MetaDataBlock) galleryMacro.getParent()).getMetaData().getMetaData(MetaData.SYNTAX)); TemporaryResourceStore store = mocker.getInstance(TemporaryResourceStore.class); verify(store).createTemporaryFile(eq(temporaryResourceReference), any(InputStream.class)); }
@Override public XDOM createView(ResourceReference reference, Map<String, ?> parameters) throws Exception { OfficeDocumentView view; if (reference.getType().equals(ResourceType.ATTACHMENT) || reference.getType().equals(ResourceType.UNKNOWN)) { AttachmentReference attachmentReference = this.attachmentResolver.resolve(reference.getReference()); view = getView(reference, attachmentReference, parameters); } else { view = getView(reference, parameters); } return view.getXDOM().clone(); }
DefaultOfficeResourceViewer implements OfficeResourceViewer, Initializable { @Override public XDOM createView(ResourceReference reference, Map<String, ?> parameters) throws Exception { OfficeDocumentView view; if (reference.getType().equals(ResourceType.ATTACHMENT) || reference.getType().equals(ResourceType.UNKNOWN)) { AttachmentReference attachmentReference = this.attachmentResolver.resolve(reference.getReference()); view = getView(reference, attachmentReference, parameters); } else { view = getView(reference, parameters); } return view.getXDOM().clone(); } }
DefaultOfficeResourceViewer implements OfficeResourceViewer, Initializable { @Override public XDOM createView(ResourceReference reference, Map<String, ?> parameters) throws Exception { OfficeDocumentView view; if (reference.getType().equals(ResourceType.ATTACHMENT) || reference.getType().equals(ResourceType.UNKNOWN)) { AttachmentReference attachmentReference = this.attachmentResolver.resolve(reference.getReference()); view = getView(reference, attachmentReference, parameters); } else { view = getView(reference, parameters); } return view.getXDOM().clone(); }  }
DefaultOfficeResourceViewer implements OfficeResourceViewer, Initializable { @Override public XDOM createView(ResourceReference reference, Map<String, ?> parameters) throws Exception { OfficeDocumentView view; if (reference.getType().equals(ResourceType.ATTACHMENT) || reference.getType().equals(ResourceType.UNKNOWN)) { AttachmentReference attachmentReference = this.attachmentResolver.resolve(reference.getReference()); view = getView(reference, attachmentReference, parameters); } else { view = getView(reference, parameters); } return view.getXDOM().clone(); }  @Override void initialize(); @Override XDOM createView(ResourceReference reference, Map<String, ?> parameters); }
DefaultOfficeResourceViewer implements OfficeResourceViewer, Initializable { @Override public XDOM createView(ResourceReference reference, Map<String, ?> parameters) throws Exception { OfficeDocumentView view; if (reference.getType().equals(ResourceType.ATTACHMENT) || reference.getType().equals(ResourceType.UNKNOWN)) { AttachmentReference attachmentReference = this.attachmentResolver.resolve(reference.getReference()); view = getView(reference, attachmentReference, parameters); } else { view = getView(reference, parameters); } return view.getXDOM().clone(); }  @Override void initialize(); @Override XDOM createView(ResourceReference reference, Map<String, ?> parameters);  }