Example usage for org.apache.poi.xslf.usermodel XSLFSlideShow getSlidePart

List of usage examples for org.apache.poi.xslf.usermodel XSLFSlideShow getSlidePart

Introduction

In this page you can find the example usage for org.apache.poi.xslf.usermodel XSLFSlideShow getSlidePart.

Prototype

public PackagePart getSlidePart(CTSlideIdListEntry slide) throws IOException, XmlException 

Source Link

Usage

From source file:org.apache.tika.parser.microsoft.ooxml.XSLFPowerPointExtractorDecorator.java

License:Apache License

/**
 * In PowerPoint files, slides have things embedded in them,
 * and slide drawings which have the images
 *///from w w  w .ja  va  2  s  .  c  o  m
@Override
protected List<PackagePart> getMainDocumentParts() throws TikaException {
    List<PackagePart> parts = new ArrayList<>();
    XSLFSlideShow document = null;
    try {
        document = new XSLFSlideShow(extractor.getPackage());
    } catch (Exception e) {
        throw new TikaException(e.getMessage()); // Shouldn't happen
    }

    CTSlideIdList ctSlideIdList = document.getSlideReferences();
    if (ctSlideIdList != null) {
        for (int i = 0; i < ctSlideIdList.sizeOfSldIdArray(); i++) {
            CTSlideIdListEntry ctSlide = ctSlideIdList.getSldIdArray(i);
            // Add the slide
            PackagePart slidePart;
            try {
                slidePart = document.getSlidePart(ctSlide);
            } catch (IOException e) {
                throw new TikaException("Broken OOXML file", e);
            } catch (XmlException xe) {
                throw new TikaException("Broken OOXML file", xe);
            }
            parts.add(slidePart);

            // If it has drawings, return those too
            try {
                for (PackageRelationship rel : slidePart
                        .getRelationshipsByType(XSLFRelation.VML_DRAWING.getRelation())) {
                    if (rel.getTargetMode() == TargetMode.INTERNAL) {
                        PackagePartName relName = PackagingURIHelper.createPartName(rel.getTargetURI());
                        parts.add(rel.getPackage().getPart(relName));
                    }
                }
            } catch (InvalidFormatException e) {
                throw new TikaException("Broken OOXML file", e);
            }
        }
    }
    return parts;
}