Search in sources :

Example 11 with XMLSlideShow

use of org.apache.poi.xslf.usermodel.XMLSlideShow in project textdb by TextDB.

the class FileSourcePptPdfTest method createPPT.

private static void createPPT(String path) throws IOException {
    // creating a new empty slide show
    XMLSlideShow ppt = new XMLSlideShow();
    // creating an FileOutputStream object
    File file = new File(path);
    FileOutputStream out = new FileOutputStream(file);
    // saving the changes to a file
    ppt.write(out);
    out.close();
    ppt.close();
}
Also used : XMLSlideShow(org.apache.poi.xslf.usermodel.XMLSlideShow) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 12 with XMLSlideShow

use of org.apache.poi.xslf.usermodel.XMLSlideShow in project bigbluebutton by bigbluebutton.

the class OfficeDocumentValidator method isValid.

public boolean isValid(UploadedPresentation pres) {
    boolean valid = true;
    if (FilenameUtils.isExtension(pres.getUploadedFile().getName(), FileTypeConstants.PPTX)) {
        XMLSlideShow xmlSlideShow;
        try {
            xmlSlideShow = new XMLSlideShow(new FileInputStream(pres.getUploadedFile()));
            valid &= !embedsEmf(xmlSlideShow);
            valid &= !containsTinyTileBackground(xmlSlideShow);
            // Close the resource once we finished reading it
            xmlSlideShow.close();
        } catch (IOException e) {
            log.error("Cannot open PPTX file " + pres.getName());
            valid = false;
        }
    }
    return valid;
}
Also used : XMLSlideShow(org.apache.poi.xslf.usermodel.XMLSlideShow) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Example 13 with XMLSlideShow

use of org.apache.poi.xslf.usermodel.XMLSlideShow in project poi by apache.

the class TestXSLFPowerPointExtractor method testGetSimpleText.

/**
	 * Get text out of the simple file
	 * @throws XmlException
	 * @throws OpenXML4JException
	 */
@Test
public void testGetSimpleText() throws IOException, XmlException, OpenXML4JException {
    XMLSlideShow xmlA = openPPTX("sample.pptx");
    @SuppressWarnings("resource") OPCPackage pkg = xmlA.getPackage();
    new XSLFPowerPointExtractor(xmlA).close();
    new XSLFPowerPointExtractor(pkg).close();
    XSLFPowerPointExtractor extractor = new XSLFPowerPointExtractor(xmlA);
    extractor.getText();
    String text = extractor.getText();
    assertTrue(text.length() > 0);
    // Check Basics
    assertStartsWith(text, "Lorem ipsum dolor sit amet\n");
    assertContains(text, "amet\n\n");
    // Our placeholder master text
    // This shouldn't show up in the output
    // String masterText =
    //     "Click to edit Master title style\n" +
    //     "Click to edit Master subtitle style\n" +
    //     "\n\n\n\n\n\n" +
    //     "Click to edit Master title style\n" +
    //     "Click to edit Master text styles\n" +
    //     "Second level\n" +
    //     "Third level\n" +
    //     "Fourth level\n" +
    //     "Fifth level\n";
    // Just slides, no notes
    text = extractor.getText(true, false, false);
    String slideText = "Lorem ipsum dolor sit amet\n" + "Nunc at risus vel erat tempus posuere. Aenean non ante.\n" + "\n" + "Lorem ipsum dolor sit amet\n" + "Lorem\n" + "ipsum\n" + "dolor\n" + "sit\n" + "amet\n" + "\n";
    assertEquals(slideText, text);
    // Just notes, no slides
    text = extractor.getText(false, true);
    assertEquals("\n\n1\n\n\n2\n", text);
    // Both
    text = extractor.getText(true, true, false);
    String bothText = "Lorem ipsum dolor sit amet\n" + "Nunc at risus vel erat tempus posuere. Aenean non ante.\n" + "\n\n\n1\n" + "Lorem ipsum dolor sit amet\n" + "Lorem\n" + "ipsum\n" + "dolor\n" + "sit\n" + "amet\n" + "\n\n\n2\n";
    assertEquals(bothText, text);
    // With Slides and Master Text
    text = extractor.getText(true, false, true);
    String smText = "Lorem ipsum dolor sit amet\n" + "Nunc at risus vel erat tempus posuere. Aenean non ante.\n" + "\n" + "Lorem ipsum dolor sit amet\n" + "Lorem\n" + "ipsum\n" + "dolor\n" + "sit\n" + "amet\n" + "\n";
    assertEquals(smText, text);
    // With Slides, Notes and Master Text
    text = extractor.getText(true, true, true);
    String snmText = "Lorem ipsum dolor sit amet\n" + "Nunc at risus vel erat tempus posuere. Aenean non ante.\n" + "\n\n\n1\n" + "Lorem ipsum dolor sit amet\n" + "Lorem\n" + "ipsum\n" + "dolor\n" + "sit\n" + "amet\n" + "\n\n\n2\n";
    assertEquals(snmText, text);
    // Via set defaults
    extractor.setSlidesByDefault(false);
    extractor.setNotesByDefault(true);
    text = extractor.getText();
    assertEquals("\n\n1\n\n\n2\n", text);
    extractor.close();
    xmlA.close();
}
Also used : XMLSlideShow(org.apache.poi.xslf.usermodel.XMLSlideShow) OPCPackage(org.apache.poi.openxml4j.opc.OPCPackage) Test(org.junit.Test)

Example 14 with XMLSlideShow

use of org.apache.poi.xslf.usermodel.XMLSlideShow in project poi by apache.

the class TestXSLFPowerPointExtractor method testDifferentSubformats.

/**
     * Test that we can get the text from macro enabled,
     *  template, theme, slide enabled etc formats, as
     *  well as from the normal file
     */
@Test
public void testDifferentSubformats() throws Exception {
    String[] extensions = new String[] { "pptx", "pptm", "ppsm", "ppsx", "thmx" };
    for (String extension : extensions) {
        String filename = "testPPT." + extension;
        XMLSlideShow xml = openPPTX(filename);
        XSLFPowerPointExtractor extractor = new XSLFPowerPointExtractor(xml);
        String text = extractor.getText();
        if (extension.equals("thmx")) {
            // Theme file doesn't have any textual content
            assertEquals(filename, 0, text.length());
            continue;
        }
        assertTrue(filename, text.length() > 0);
        assertContains(filename, text, "Attachment Test");
        assertContains(filename, text, "This is a test file data with the same content");
        assertContains(filename, text, "content parsing");
        assertContains(filename, text, "Different words to test against");
        assertContains(filename, text, "Mystery");
        extractor.close();
        xml.close();
    }
}
Also used : XMLSlideShow(org.apache.poi.xslf.usermodel.XMLSlideShow) Test(org.junit.Test)

Example 15 with XMLSlideShow

use of org.apache.poi.xslf.usermodel.XMLSlideShow in project poi by apache.

the class TestXSLFPowerPointExtractor method testGetComments.

public void testGetComments() throws IOException {
    XMLSlideShow xml = openPPTX("45545_Comment.pptx");
    XSLFPowerPointExtractor extractor = new XSLFPowerPointExtractor(xml);
    String text = extractor.getText();
    assertTrue(text.length() > 0);
    // Check comments are there
    assertContains(text, "testdoc");
    assertContains(text, "test phrase");
    // Check the authors came through too
    assertContains(text, "XPVMWARE01");
    extractor.close();
    xml.close();
}
Also used : XMLSlideShow(org.apache.poi.xslf.usermodel.XMLSlideShow)

Aggregations

XMLSlideShow (org.apache.poi.xslf.usermodel.XMLSlideShow)27 Test (org.junit.Test)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 InputStream (java.io.InputStream)6 Metacard (ddf.catalog.data.Metacard)5 XSLFSlide (org.apache.poi.xslf.usermodel.XSLFSlide)5 FileInputStream (java.io.FileInputStream)4 IOException (java.io.IOException)4 XSLFTextShape (org.apache.poi.xslf.usermodel.XSLFTextShape)4 FileOutputStream (java.io.FileOutputStream)3 XSLFShape (org.apache.poi.xslf.usermodel.XSLFShape)3 XWPFDocument (org.apache.poi.xwpf.usermodel.XWPFDocument)3 Rectangle2D (java.awt.geom.Rectangle2D)2 File (java.io.File)2 Date (java.util.Date)2 HSLFSlideShow (org.apache.poi.hslf.usermodel.HSLFSlideShow)2 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)2 HWPFDocument (org.apache.poi.hwpf.HWPFDocument)2 OPCPackage (org.apache.poi.openxml4j.opc.OPCPackage)2