@Test public void build() throws Exception { DocumentReference documentReference = new DocumentReference("wiki", Arrays.asList("Path", "To"), "Page"); when(this.entityReferenceSerializer.serialize(documentReference)).thenReturn("wiki:Path.To.Page"); DocumentModelBridge document = mock(DocumentModelBridge.class); DocumentAccessBridge dab = this.componentManager.getInstance(DocumentAccessBridge.class); when(dab.getTranslatedDocumentInstance(documentReference)).thenReturn(document); when(document.getSyntax()).thenReturn(Syntax.XWIKI_2_1); InputStream officeFileStream = new ByteArrayInputStream("Presentation content".getBytes()); Map<String, byte[]> artifacts = new HashMap<String, byte[]>(); byte[] firstSlide = "first slide".getBytes(); byte[] secondSlide = "second slide".getBytes(); artifacts.put("img0.jpg", firstSlide); artifacts.put("img0.html", new byte[0]); artifacts.put("text0.html", new byte[0]); artifacts.put("img1.jpg", secondSlide); artifacts.put("img1.html", new byte[0]); artifacts.put("text1.html", new byte[0]); when(this.officeConverter.convert(Collections.singletonMap("file.odp", officeFileStream), "file.odp", "img0.html")).thenReturn(artifacts); HTMLCleanerConfiguration config = mock(HTMLCleanerConfiguration.class); when(this.officeHTMLCleaner.getDefaultConfiguration()).thenReturn(config); Document xhtmlDoc = XMLUtils.createDOMDocument(); xhtmlDoc.appendChild(xhtmlDoc.createElement("html")); String presentationHTML = "<p><img src=\"file-slide0.jpg\"/></p><p><img src=\"file-slide1.jpg\"/></p>"; when(this.officeHTMLCleaner.clean(any(Reader.class), eq(config))) .then(returnMatchingDocument(presentationHTML, xhtmlDoc)); XDOM galleryContent = new XDOM(Collections.<Block>emptyList()); when(this.xhtmlParser.parse(any(Reader.class))).thenReturn(galleryContent); XDOMOfficeDocument result = this.presentationBuilder.build(officeFileStream, "file.odp", documentReference); verify(config).setParameters(Collections.singletonMap("targetDocument", "wiki:Path.To.Page")); Map<String, byte[]> expectedArtifacts = new HashMap<String, byte[]>(); expectedArtifacts.put("file-slide0.jpg", firstSlide); expectedArtifacts.put("file-slide1.jpg", secondSlide); assertEquals(expectedArtifacts, result.getArtifacts()); assertEquals("wiki:Path.To.Page", result.getContentDocument().getMetaData().getMetaData(MetaData.BASE)); List<ExpandedMacroBlock> macros = result.getContentDocument().getBlocks(new ClassBlockMatcher(ExpandedMacroBlock.class), Block.Axes.CHILD); assertEquals(1, macros.size()); assertEquals("gallery", macros.get(0).getId()); assertEquals(galleryContent, macros.get(0).getChildren().get(0)); }
@Override public XDOMOfficeDocument build(InputStream officeFileStream, String officeFileName, DocumentReference documentReference) throws OfficeImporterException { String cleanedOfficeFileName = StringUtils.stripAccents(officeFileName); Map<String, byte[]> artifacts = importPresentation(officeFileStream, cleanedOfficeFileName); String html = buildPresentationHTML(artifacts, StringUtils.substringBeforeLast(cleanedOfficeFileName, ".")); html = cleanPresentationHTML(html, documentReference); XDOM xdom = buildPresentationXDOM(html, documentReference); return new XDOMOfficeDocument(xdom, artifacts, this.contextComponentManagerProvider.get()); }
DefaultPresentationBuilder implements PresentationBuilder { @Override public XDOMOfficeDocument build(InputStream officeFileStream, String officeFileName, DocumentReference documentReference) throws OfficeImporterException { String cleanedOfficeFileName = StringUtils.stripAccents(officeFileName); Map<String, byte[]> artifacts = importPresentation(officeFileStream, cleanedOfficeFileName); String html = buildPresentationHTML(artifacts, StringUtils.substringBeforeLast(cleanedOfficeFileName, ".")); html = cleanPresentationHTML(html, documentReference); XDOM xdom = buildPresentationXDOM(html, documentReference); return new XDOMOfficeDocument(xdom, artifacts, this.contextComponentManagerProvider.get()); } }
DefaultPresentationBuilder implements PresentationBuilder { @Override public XDOMOfficeDocument build(InputStream officeFileStream, String officeFileName, DocumentReference documentReference) throws OfficeImporterException { String cleanedOfficeFileName = StringUtils.stripAccents(officeFileName); Map<String, byte[]> artifacts = importPresentation(officeFileStream, cleanedOfficeFileName); String html = buildPresentationHTML(artifacts, StringUtils.substringBeforeLast(cleanedOfficeFileName, ".")); html = cleanPresentationHTML(html, documentReference); XDOM xdom = buildPresentationXDOM(html, documentReference); return new XDOMOfficeDocument(xdom, artifacts, this.contextComponentManagerProvider.get()); }  }
DefaultPresentationBuilder implements PresentationBuilder { @Override public XDOMOfficeDocument build(InputStream officeFileStream, String officeFileName, DocumentReference documentReference) throws OfficeImporterException { String cleanedOfficeFileName = StringUtils.stripAccents(officeFileName); Map<String, byte[]> artifacts = importPresentation(officeFileStream, cleanedOfficeFileName); String html = buildPresentationHTML(artifacts, StringUtils.substringBeforeLast(cleanedOfficeFileName, ".")); html = cleanPresentationHTML(html, documentReference); XDOM xdom = buildPresentationXDOM(html, documentReference); return new XDOMOfficeDocument(xdom, artifacts, this.contextComponentManagerProvider.get()); }  @Override XDOMOfficeDocument build(InputStream officeFileStream, String officeFileName,
        DocumentReference documentReference); }
DefaultPresentationBuilder implements PresentationBuilder { @Override public XDOMOfficeDocument build(InputStream officeFileStream, String officeFileName, DocumentReference documentReference) throws OfficeImporterException { String cleanedOfficeFileName = StringUtils.stripAccents(officeFileName); Map<String, byte[]> artifacts = importPresentation(officeFileStream, cleanedOfficeFileName); String html = buildPresentationHTML(artifacts, StringUtils.substringBeforeLast(cleanedOfficeFileName, ".")); html = cleanPresentationHTML(html, documentReference); XDOM xdom = buildPresentationXDOM(html, documentReference); return new XDOMOfficeDocument(xdom, artifacts, this.contextComponentManagerProvider.get()); }  @Override XDOMOfficeDocument build(InputStream officeFileStream, String officeFileName,
        DocumentReference documentReference);  }