001: /**
002: * Copyright (c) 2005, www.pdfbox.org
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions are met:
007: *
008: * 1. Redistributions of source code must retain the above copyright notice,
009: * this list of conditions and the following disclaimer.
010: * 2. Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: * 3. Neither the name of pdfbox; nor the names of its
014: * contributors may be used to endorse or promote products derived from this
015: * software without specific prior written permission.
016: *
017: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
018: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
019: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
020: * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
021: * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
022: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
023: * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
024: * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
025: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
026: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
027: *
028: * http://www.pdfbox.org
029: *
030: */package org.pdfbox.pdmodel.interactive.documentnavigation.destination;
031:
032: import org.pdfbox.cos.COSArray;
033: import org.pdfbox.cos.COSBase;
034: import org.pdfbox.cos.COSDictionary;
035: import org.pdfbox.cos.COSNumber;
036:
037: import org.pdfbox.pdmodel.PDPage;
038:
039: /**
040: * This represents a destination to a page, see subclasses for specific parameters.
041: *
042: * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
043: * @version $Revision: 1.2 $
044: */
045: public abstract class PDPageDestination extends PDDestination {
046: /**
047: * Storage for the page destination.
048: */
049: protected COSArray array;
050:
051: /**
052: * Constructor to create empty page destination.
053: *
054: */
055: protected PDPageDestination() {
056: array = new COSArray();
057: }
058:
059: /**
060: * Constructor to create empty page destination.
061: *
062: * @param arr A page destination array.
063: */
064: protected PDPageDestination(COSArray arr) {
065: array = arr;
066: }
067:
068: /**
069: * This will get the page for this destination. A page destination
070: * can either reference a page or a page number(when doing a remote destination to
071: * another PDF). If this object is referencing by page number then this method will
072: * return null and getPageNumber should be used.
073: *
074: * @return The page for this destination.
075: */
076: public PDPage getPage() {
077: PDPage retval = null;
078: if (array.size() > 0) {
079: COSBase page = array.getObject(0);
080: if (page instanceof COSDictionary) {
081: retval = new PDPage((COSDictionary) page);
082: }
083: }
084: return retval;
085: }
086:
087: /**
088: * Set the page for this destination.
089: *
090: * @param page The page for the destination.
091: */
092: public void setPage(PDPage page) {
093: array.set(0, page);
094: }
095:
096: /**
097: * This will get the page number for this destination. A page destination
098: * can either reference a page or a page number(when doing a remote destination to
099: * another PDF). If this object is referencing by page number then this method will
100: * return that number, otherwise -1 will be returned.
101: *
102: * @return The page number for this destination.
103: */
104: public int getPageNumber() {
105: int retval = -1;
106: if (array.size() > 0) {
107: COSBase page = array.getObject(0);
108: if (page instanceof COSNumber) {
109: retval = ((COSNumber) page).intValue();
110: }
111: }
112: return retval;
113: }
114:
115: /**
116: * Set the page number for this destination.
117: *
118: * @param pageNumber The page for the destination.
119: */
120: public void setPageNumber(int pageNumber) {
121: array.set(0, pageNumber);
122: }
123:
124: /**
125: * Convert this standard java object to a COS object.
126: *
127: * @return The cos object that matches this Java object.
128: */
129: public COSBase getCOSObject() {
130: return array;
131: }
132:
133: /**
134: * Convert this standard java object to a COS object.
135: *
136: * @return The cos object that matches this Java object.
137: */
138: public COSArray getCOSArray() {
139: return array;
140: }
141: }
|