Search in sources :

Example 16 with XMLSlideShow

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

the class TestEmbedOLEPackage method getSamplePPT.

static byte[] getSamplePPT(boolean ooxml) throws IOException {
    SlideShow<?, ?> ppt = (ooxml) ? new XMLSlideShow() : new org.apache.poi.hslf.usermodel.HSLFSlideShow();
    Slide<?, ?> slide = ppt.createSlide();
    AutoShape<?, ?> sh1 = slide.createAutoShape();
    sh1.setShapeType(ShapeType.STAR_32);
    sh1.setAnchor(new java.awt.Rectangle(50, 50, 100, 200));
    sh1.setFillColor(java.awt.Color.red);
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ppt.write(bos);
    ppt.close();
    return bos.toByteArray();
}
Also used : XMLSlideShow(org.apache.poi.xslf.usermodel.XMLSlideShow) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 17 with XMLSlideShow

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

the class TestXSLFSlideShow method testMasterBackground.

@Test
public void testMasterBackground() throws IOException {
    XMLSlideShow ppt = new XMLSlideShow();
    XSLFBackground b = ppt.getSlideMasters().get(0).getBackground();
    b.setFillColor(Color.RED);
    XSLFSlide sl = ppt.createSlide();
    XSLFAutoShape as = sl.createAutoShape();
    as.setAnchor(new Rectangle2D.Double(100, 100, 100, 100));
    as.setShapeType(ShapeType.CLOUD);
    XMLSlideShow ppt2 = XSLFTestDataSamples.writeOutAndReadBack(ppt);
    ppt.close();
    XSLFBackground b2 = ppt2.getSlideMasters().get(0).getBackground();
    assertEquals(Color.RED, b2.getFillColor());
    ppt2.close();
}
Also used : XSLFSlide(org.apache.poi.xslf.usermodel.XSLFSlide) XMLSlideShow(org.apache.poi.xslf.usermodel.XMLSlideShow) XSLFAutoShape(org.apache.poi.xslf.usermodel.XSLFAutoShape) Rectangle2D(java.awt.geom.Rectangle2D) XSLFBackground(org.apache.poi.xslf.usermodel.XSLFBackground) Test(org.junit.Test)

Example 18 with XMLSlideShow

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

the class TestPOIXMLDocument method testOSGIClassLoadingAsIs.

@Test(expected = IllegalStateException.class)
public void testOSGIClassLoadingAsIs() throws IOException {
    Thread thread = Thread.currentThread();
    ClassLoader cl = thread.getContextClassLoader();
    InputStream is = POIDataSamples.getSlideShowInstance().openResourceAsStream("table_test.pptx");
    try {
        thread.setContextClassLoader(cl.getParent());
        XMLSlideShow ppt = new XMLSlideShow(is);
        ppt.getSlides().get(0).getShapes();
        ppt.close();
    } finally {
        thread.setContextClassLoader(cl);
        is.close();
    }
}
Also used : InputStream(java.io.InputStream) XMLSlideShow(org.apache.poi.xslf.usermodel.XMLSlideShow) Test(org.junit.Test)

Example 19 with XMLSlideShow

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

the class TestPOIXMLDocument method testOSGIClassLoadingFixed.

@Test
public void testOSGIClassLoadingFixed() throws IOException {
    Thread thread = Thread.currentThread();
    ClassLoader cl = thread.getContextClassLoader();
    InputStream is = POIDataSamples.getSlideShowInstance().openResourceAsStream("table_test.pptx");
    try {
        thread.setContextClassLoader(cl.getParent());
        POIXMLTypeLoader.setClassLoader(cl);
        XMLSlideShow ppt = new XMLSlideShow(is);
        ppt.getSlides().get(0).getShapes();
        ppt.close();
    } finally {
        thread.setContextClassLoader(cl);
        POIXMLTypeLoader.setClassLoader(null);
        is.close();
    }
}
Also used : InputStream(java.io.InputStream) XMLSlideShow(org.apache.poi.xslf.usermodel.XMLSlideShow) Test(org.junit.Test)

Example 20 with XMLSlideShow

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

the class OOXMLExtractorFactory method parse.

public static void parse(InputStream stream, ContentHandler baseHandler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException {
    Locale locale = context.get(Locale.class, Locale.getDefault());
    ExtractorFactory.setThreadPrefersEventExtractors(true);
    try {
        OOXMLExtractor extractor;
        OPCPackage pkg;
        // Locate or Open the OPCPackage for the file
        TikaInputStream tis = TikaInputStream.cast(stream);
        if (tis != null && tis.getOpenContainer() instanceof OPCPackage) {
            pkg = (OPCPackage) tis.getOpenContainer();
        } else if (tis != null && tis.hasFile()) {
            pkg = OPCPackage.open(tis.getFile().getPath(), PackageAccess.READ);
            tis.setOpenContainer(pkg);
        } else {
            InputStream shield = new CloseShieldInputStream(stream);
            pkg = OPCPackage.open(shield);
        }
        // Get the type, and ensure it's one we handle
        MediaType type = ZipContainerDetector.detectOfficeOpenXML(pkg);
        if (type == null || OOXMLParser.UNSUPPORTED_OOXML_TYPES.contains(type)) {
            // Not a supported type, delegate to Empty Parser
            EmptyParser.INSTANCE.parse(stream, baseHandler, metadata, context);
            return;
        }
        metadata.set(Metadata.CONTENT_TYPE, type.toString());
        // Have the appropriate OOXML text extractor picked
        POIXMLTextExtractor poiExtractor = null;
        // This has already been set by OOXMLParser's call to configure()
        // We can rely on this being non-null.
        OfficeParserConfig config = context.get(OfficeParserConfig.class);
        if (config.getUseSAXDocxExtractor()) {
            poiExtractor = trySXWPF(pkg);
        }
        if (poiExtractor == null && config.getUseSAXPptxExtractor()) {
            poiExtractor = trySXSLF(pkg);
        }
        if (poiExtractor == null) {
            poiExtractor = ExtractorFactory.createExtractor(pkg);
        }
        POIXMLDocument document = poiExtractor.getDocument();
        if (poiExtractor instanceof XSSFBEventBasedExcelExtractor) {
            extractor = new XSSFBExcelExtractorDecorator(context, poiExtractor, locale);
        } else if (poiExtractor instanceof XSSFEventBasedExcelExtractor) {
            extractor = new XSSFExcelExtractorDecorator(context, poiExtractor, locale);
        } else if (poiExtractor instanceof XWPFEventBasedWordExtractor) {
            extractor = new SXWPFWordExtractorDecorator(metadata, context, (XWPFEventBasedWordExtractor) poiExtractor);
            metadata.add("X-Parsed-By", XWPFEventBasedWordExtractor.class.getCanonicalName());
        } else if (poiExtractor instanceof XSLFEventBasedPowerPointExtractor) {
            extractor = new SXSLFPowerPointExtractorDecorator(metadata, context, (XSLFEventBasedPowerPointExtractor) poiExtractor);
            metadata.add("X-Parsed-By", XSLFEventBasedPowerPointExtractor.class.getCanonicalName());
        } else if (document == null) {
            throw new TikaException("Expecting UserModel based POI OOXML extractor with a document, but none found. " + "The extractor returned was a " + poiExtractor);
        } else if (document instanceof XMLSlideShow) {
            extractor = new XSLFPowerPointExtractorDecorator(context, (org.apache.poi.xslf.extractor.XSLFPowerPointExtractor) poiExtractor);
        } else if (document instanceof XWPFDocument) {
            extractor = new XWPFWordExtractorDecorator(context, (XWPFWordExtractor) poiExtractor);
        } else {
            extractor = new POIXMLTextExtractorDecorator(context, poiExtractor);
        }
        // Get the bulk of the metadata first, so that it's accessible during
        //  parsing if desired by the client (see TIKA-1109)
        extractor.getMetadataExtractor().extract(metadata);
        // Extract the text, along with any in-document metadata
        extractor.getXHTML(baseHandler, metadata, context);
    } catch (IllegalArgumentException e) {
        if (e.getMessage() != null && e.getMessage().startsWith("No supported documents found")) {
            throw new TikaException("TIKA-418: RuntimeException while getting content" + " for thmx and xps file types", e);
        } else {
            throw new TikaException("Error creating OOXML extractor", e);
        }
    } catch (InvalidFormatException e) {
        throw new TikaException("Error creating OOXML extractor", e);
    } catch (OpenXML4JException e) {
        throw new TikaException("Error creating OOXML extractor", e);
    } catch (XmlException e) {
        throw new TikaException("Error creating OOXML extractor", e);
    }
}
Also used : Locale(java.util.Locale) TikaInputStream(org.apache.tika.io.TikaInputStream) XWPFEventBasedWordExtractor(org.apache.tika.parser.microsoft.ooxml.xwpf.XWPFEventBasedWordExtractor) InvalidFormatException(org.apache.poi.openxml4j.exceptions.InvalidFormatException) OpenXML4JException(org.apache.poi.openxml4j.exceptions.OpenXML4JException) XSSFEventBasedExcelExtractor(org.apache.poi.xssf.extractor.XSSFEventBasedExcelExtractor) OfficeParserConfig(org.apache.tika.parser.microsoft.OfficeParserConfig) MediaType(org.apache.tika.mime.MediaType) XWPFDocument(org.apache.poi.xwpf.usermodel.XWPFDocument) XSLFEventBasedPowerPointExtractor(org.apache.tika.parser.microsoft.ooxml.xslf.XSLFEventBasedPowerPointExtractor) TikaException(org.apache.tika.exception.TikaException) XSSFBEventBasedExcelExtractor(org.apache.poi.xssf.extractor.XSSFBEventBasedExcelExtractor) CloseShieldInputStream(org.apache.commons.io.input.CloseShieldInputStream) TikaInputStream(org.apache.tika.io.TikaInputStream) InputStream(java.io.InputStream) XWPFWordExtractor(org.apache.poi.xwpf.extractor.XWPFWordExtractor) POIXMLDocument(org.apache.poi.POIXMLDocument) POIXMLTextExtractor(org.apache.poi.POIXMLTextExtractor) XmlException(org.apache.xmlbeans.XmlException) XMLSlideShow(org.apache.poi.xslf.usermodel.XMLSlideShow) OPCPackage(org.apache.poi.openxml4j.opc.OPCPackage) CloseShieldInputStream(org.apache.commons.io.input.CloseShieldInputStream)

Aggregations

XMLSlideShow (org.apache.poi.xslf.usermodel.XMLSlideShow)25 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)4 FileInputStream (java.io.FileInputStream)3 IOException (java.io.IOException)3 XSLFTextShape (org.apache.poi.xslf.usermodel.XSLFTextShape)3 XWPFDocument (org.apache.poi.xwpf.usermodel.XWPFDocument)3 Rectangle2D (java.awt.geom.Rectangle2D)2 FileOutputStream (java.io.FileOutputStream)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 PackagePart (org.apache.poi.openxml4j.opc.PackagePart)2 XSLFShape (org.apache.poi.xslf.usermodel.XSLFShape)2