001: package com.etymon.pj.object;
002:
003: import java.io.*;
004: import java.util.*;
005: import com.etymon.pj.*;
006: import com.etymon.pj.exception.*;
007:
008: /**
009: A representation of a PDF page dictionary.
010: @author Nassib Nassar
011: */
012: public class PjPage extends PjPagesNode {
013:
014: /**
015: Creates a new page dictionary.
016: */
017: public PjPage() {
018: super ();
019: _h.put(PjName.TYPE, PjName.PAGE);
020: }
021:
022: /**
023: Creates a page dictionary as a wrapper around a Hashtable.
024: @param h the Hashtable to use for this dictionary.
025: */
026: public PjPage(Hashtable h) {
027: super (h);
028: }
029:
030: public void setContents(PjArray contents) {
031: _h.put(PjName.CONTENTS, contents);
032: }
033:
034: public void setContents(PjReference contents) {
035: _h.put(PjName.CONTENTS, contents);
036: }
037:
038: public PjObject getContents() throws InvalidPdfObjectException {
039: return hget(PjName.CONTENTS);
040: }
041:
042: public void setThumb(PjReference thumb) {
043: _h.put(PjName.THUMB, thumb);
044: }
045:
046: public PjReference getThumb() throws InvalidPdfObjectException {
047: return hgetReference(PjName.THUMB);
048: }
049:
050: public void setAnnots(PjArray annots) {
051: _h.put(PjName.ANNOTS, annots);
052: }
053:
054: public void setAnnots(PjReference annots) {
055: _h.put(PjName.ANNOTS, annots);
056: }
057:
058: public PjObject getAnnots() throws InvalidPdfObjectException {
059: return hget(PjName.ANNOTS);
060: }
061:
062: public void setB(PjArray b) {
063: _h.put(PjName.B, b);
064: }
065:
066: public void setB(PjReference b) {
067: _h.put(PjName.B, b);
068: }
069:
070: public PjObject getB() throws InvalidPdfObjectException {
071: return hget(PjName.B);
072: }
073:
074: /**
075: Examines a dictionary to see if it is a PDF page.
076: @param dictionary the dictionary to examine.
077: @return true if the dictionary could be interpreted as a
078: valid PjPage object.
079: */
080: public static boolean isLike(PjDictionary dictionary) {
081: Hashtable h = dictionary.getHashtable();
082: // check if the Type is Page
083: try {
084: PjName type = (PjName) (h.get(PjName.TYPE));
085: if (type == null) {
086: return false;
087: }
088: if (!type.equals(PjName.PAGE)) {
089: return false;
090: }
091: } catch (ClassCastException e) {
092: return false;
093: }
094: return true;
095: }
096:
097: /**
098: Returns a deep copy of this object.
099: @return a deep copy of this object.
100: @exception CloneNotSupportedException if the instance can not be cloned.
101: */
102: public Object clone() throws CloneNotSupportedException {
103: return new PjPage(cloneHt());
104: }
105:
106: }
|