Example usage for org.apache.poi.sl.usermodel SlideShowFactory create

List of usage examples for org.apache.poi.sl.usermodel SlideShowFactory create

Introduction

In this page you can find the example usage for org.apache.poi.sl.usermodel SlideShowFactory create.

Prototype

public static <S extends Shape<S, P>, P extends TextParagraph<S, P, ? extends TextRun>> SlideShow<S, P> create(
        File file) throws IOException, EncryptedDocumentException 

Source Link

Document

Creates the appropriate HSLFSlideShow / XMLSlideShow from the given File, which must exist and be readable.

Usage

From source file:ddf.catalog.transformer.input.pptx.PptxInputTransformer.java

License:Open Source License

/**
 * SlideShowFactory.create() will perform the tests for password protected files.
 * <p/>/*from  ww w  .  j ava2s. c o m*/
 * Because Apache POI dynamically loads the classes needed to handle a PPTX file, the default
 * class loader is unable to find the dependencies during runtime. Therefore, the original class
 * loader is saved, then current class loader is set to this class's class loader, and finally
 * the original class loader is restored.
 *
 * @param metacard
 * @param input
 * @throws IOException
 */
private void extractThumbnail(Metacard metacard, InputStream input) throws IOException {

    ClassLoader originalContextClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
        SlideShow<?, ?> genericSlideShow = SlideShowFactory.create(input);

        if (genericSlideShow instanceof XMLSlideShow) {
            XMLSlideShow xmlSlideShow = (XMLSlideShow) genericSlideShow;

            byte[] thumbnail = generatePptxThumbnail(xmlSlideShow);
            if (thumbnail != null) {
                metacard.setAttribute(new AttributeImpl(Metacard.THUMBNAIL, thumbnail));
            }

        } else {
            LOGGER.debug("Cannot transform old style (OLE2) ppt : id = {}", metacard.getId());
        }

    } finally {
        Thread.currentThread().setContextClassLoader(originalContextClassLoader);
    }
}