jodtemplate.pptx.Presentation.java Source code

Java tutorial

Introduction

Here is the source code for jodtemplate.pptx.Presentation.java

Source

/*
 * 
 * Copyright 2015 Andrey Yakovlev
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */
package jodtemplate.pptx;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import jodtemplate.Image;
import jodtemplate.Relationship;
import jodtemplate.util.Utils;

import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;

public class Presentation {

    private final List<Slide> slides = new ArrayList<>();

    private final List<Relationship> otherRelationships = new ArrayList<>();

    private final Map<String, Image> images = new HashMap<>();

    private final String fullPath;

    private final String xmlPath;

    private final String xmlRelsPath;

    public Presentation(final String xmlPath) {
        this.xmlPath = xmlPath;
        this.fullPath = FilenameUtils.getFullPath(xmlPath);
        this.xmlRelsPath = Utils.getRelsPath(xmlPath);
    }

    public String getFullPath() {
        return fullPath;
    }

    public String getXmlPath() {
        return xmlPath;
    }

    public String getXmlRelsPath() {
        return xmlRelsPath;
    }

    public void addSlide(final Slide slide) {
        if (slide != null) {
            slides.add(slide);
        }
    }

    public void addOtherRelationship(final Relationship relationship) {
        if (relationship != null) {
            otherRelationships.add(relationship);
        }
    }

    public List<Slide> getSlides() {
        return Collections.unmodifiableList(new ArrayList<>(slides));
    }

    public List<Relationship> getOtherRelationships() {
        return Collections.unmodifiableList(new ArrayList<>(otherRelationships));
    }

    public boolean containsImage(final String md5) {
        return images.containsKey(md5);
    }

    public Image getImage(final String md5) {
        return images.get(md5);
    }

    public void addImage(final Image image) {
        if (StringUtils.isNotBlank(image.getMd5())) {
            images.put(image.getMd5(), image);
        }
    }

    public List<Image> getImages() {
        return Collections.unmodifiableList(new ArrayList<>(images.values()));
    }

    public int getNumberOfImages() {
        return images.size();
    }

}