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

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

Introduction

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

Prototype

@Internal
public CTSlideIdList getSlideReferences() 

Source Link

Document

Returns the references from the presentation to its slides.

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 .  j a v  a  2s  .  com
@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;
}