001: package com.etymon.pjx.util;
002:
003: import java.io.*;
004: import java.util.*;
005: import com.etymon.pjx.*;
006:
007: /**
008: Examines a specified page dictionary and returns the set of all
009: objects it references that are required for the page to be
010: extracted from the document. This class is synchronized.
011: @author Nassib Nassar
012: */
013: public class PdfPageObjects extends PdfReferencedObjects {
014:
015: /**
016: The manager to use for resolving references.
017: */
018: protected PdfManager _mgr;
019:
020: /**
021: Constructs a <code>PdfPageObjects</code> instance.
022: @param manager the manager associated with the document.
023: */
024: public PdfPageObjects(PdfManager manager) {
025: super (manager);
026: _mgr = manager;
027: }
028:
029: /**
030: Returns the set of all objects referenced by the specified
031: page object that are required for the page to be extracted
032: from the document.
033: @param obj the object to examine.
034: @throws PdfFormatException
035: */
036: public Set getReferenced(PdfObject obj) throws IOException,
037: PdfFormatException {
038: synchronized (this ) {
039: synchronized (_mgr) {
040:
041: return super .getReferenced(obj);
042:
043: }
044: }
045: }
046:
047: /**
048: A <code>PdfName</code> object representing the name
049: <code>Annot</code>.
050: */
051: protected static final PdfName PDFNAME_ANNOT = new PdfName("Annot");
052:
053: /**
054: A <code>PdfName</code> object representing the name
055: <code>P</code>.
056: */
057: protected static final PdfName PDFNAME_P = new PdfName("P");
058:
059: /**
060: A <code>PdfName</code> object representing the name
061: <code>Page</code>.
062: */
063: protected static final PdfName PDFNAME_PAGE = new PdfName("Page");
064:
065: /**
066: A <code>PdfName</code> object representing the name
067: <code>Parent</code>.
068: */
069: protected static final PdfName PDFNAME_PARENT = new PdfName(
070: "Parent");
071:
072: /**
073: A <code>PdfName</code> object representing the name
074: <code>Type</code>.
075: */
076: protected static final PdfName PDFNAME_TYPE = new PdfName("Type");
077:
078: /**
079: This method is used by {@link #getReferenced(PdfObject)
080: getReferenced(PdfObject)} and <b>should not be called
081: externally</b>. (It is not synchronized.)
082: @param obj the object to filter.
083: @return the filtered object.
084: @throws PdfFormatException
085: */
086: public PdfObject preFilter(PdfObject obj) throws PdfFormatException {
087:
088: // check if it is a dictionary
089: if (obj instanceof PdfDictionary) {
090:
091: Map map = ((PdfDictionary) obj).getMap();
092:
093: // check if it is a page dictionary
094: Object j = map.get(PDFNAME_TYPE);
095: if ((PdfNull.isNull(j) == false) && (j instanceof PdfName)
096: && (((PdfName) j).equals(PDFNAME_PAGE))) {
097:
098: Map newMap = new HashMap(map);
099: newMap.remove(PDFNAME_PARENT);
100: return new PdfDictionary(newMap);
101: }
102:
103: // check if it is an annotation dictionary
104: j = map.get(PDFNAME_TYPE);
105: if ((PdfNull.isNull(j) == false) && (j instanceof PdfName)
106: && (((PdfName) j).equals(PDFNAME_ANNOT))) {
107:
108: Map newMap = new HashMap(map);
109: newMap.remove(PDFNAME_P);
110: return new PdfDictionary(newMap);
111: }
112:
113: }
114:
115: return obj;
116: }
117:
118: }
|