001package org.nuxeo.box.api.marshalling.dao;
002
003import org.nuxeo.box.api.marshalling.exceptions.BoxRestException;
004
005import java.io.InputStream;
006
007/**
008 * Preview of a file.
009 */
010public class BoxPreview extends BoxObject {
011
012    public final static String MIN_WIDTH = "min_width";
013
014    public final static String MIN_HEIGHT = "min_height";
015
016    public final static String MAX_WIDTH = "max_width";
017
018    public final static String MAX_HEIGHT = "max_height";
019
020    public final static String PAGE = "page";
021
022    private int firstPage = 1;
023
024    private int lastPage = 1;
025
026    private InputStream content;
027
028    /**
029     * Get the first page number.
030     *
031     * @return the first page number.
032     */
033    public Integer getFirstPage() {
034        return this.firstPage;
035    }
036
037    /**
038     * @param firstPage first page number
039     */
040    public void setFirstPage(Integer firstPage) {
041        this.firstPage = firstPage;
042    }
043
044    /**
045     * Get the last page number.
046     *
047     * @return the last page number
048     */
049    public Integer getLastPage() {
050        return this.lastPage;
051    }
052
053    /**
054     * Set the last page number.
055     *
056     * @param lastPage last page number
057     */
058    public void setLastPage(int lastPage) {
059        this.lastPage = lastPage;
060    }
061
062    /**
063     * Get content of the preview. Caller is responsible for closing the InputStream.
064     *
065     * @return preview input stream.
066     * @throws org.nuxeo.box.api.marshalling.exceptions.BoxRestException
067     */
068    public InputStream getContent() throws BoxRestException {
069        return content;
070    }
071
072    /**
073     * Set content.
074     *
075     * @param content content
076     */
077    public void setContent(InputStream content) {
078        this.content = content;
079    }
080
081    /**
082     * Get number of pages.
083     *
084     * @return number of pages
085     */
086    public Integer getNumPages() {
087        return getLastPage() - getFirstPage() + 1;
088    }
089
090}