KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > etymon > pjx > util > PdfPageObjects


1 package com.etymon.pjx.util;
2
3 import java.io.*;
4 import java.util.*;
5 import com.etymon.pjx.*;
6
7 /**
8    Examines a specified page dictionary and returns the set of all
9    objects it references that are required for the page to be
10    extracted from the document. This class is synchronized.
11    @author Nassib Nassar
12 */

13 public class PdfPageObjects extends PdfReferencedObjects {
14
15     /**
16        The manager to use for resolving references.
17      */

18     protected PdfManager _mgr;
19     
20     /**
21        Constructs a <code>PdfPageObjects</code> instance.
22        @param manager the manager associated with the document.
23      */

24     public PdfPageObjects(PdfManager manager) {
25         super(manager);
26         _mgr = manager;
27     }
28
29     /**
30        Returns the set of all objects referenced by the specified
31        page object that are required for the page to be extracted
32        from the document.
33        @param obj the object to examine.
34        @throws PdfFormatException
35      */

36     public Set getReferenced(PdfObject obj) throws IOException, PdfFormatException {
37         synchronized (this) {
38             synchronized (_mgr) {
39
40                 return super.getReferenced(obj);
41
42             }
43         }
44     }
45
46     /**
47            A <code>PdfName</code> object representing the name
48            <code>Annot</code>.
49     */

50     protected static final PdfName PDFNAME_ANNOT = new PdfName("Annot");
51
52     /**
53            A <code>PdfName</code> object representing the name
54            <code>P</code>.
55     */

56     protected static final PdfName PDFNAME_P = new PdfName("P");
57
58     /**
59            A <code>PdfName</code> object representing the name
60            <code>Page</code>.
61     */

62     protected static final PdfName PDFNAME_PAGE = new PdfName("Page");
63
64     /**
65            A <code>PdfName</code> object representing the name
66            <code>Parent</code>.
67     */

68     protected static final PdfName PDFNAME_PARENT = new PdfName("Parent");
69
70     /**
71            A <code>PdfName</code> object representing the name
72            <code>Type</code>.
73     */

74     protected static final PdfName PDFNAME_TYPE = new PdfName("Type");
75
76     /**
77        This method is used by {@link #getReferenced(PdfObject)
78        getReferenced(PdfObject)} and <b>should not be called
79        externally</b>. (It is not synchronized.)
80        @param obj the object to filter.
81        @return the filtered object.
82        @throws PdfFormatException
83      */

84     public PdfObject preFilter(PdfObject obj) throws PdfFormatException {
85
86         // check if it is a dictionary
87
if (obj instanceof PdfDictionary) {
88
89             Map map = ((PdfDictionary)obj).getMap();
90             
91             // check if it is a page dictionary
92
Object JavaDoc j = map.get(PDFNAME_TYPE);
93             if ( ( PdfNull.isNull(j) == false ) &&
94                  ( j instanceof PdfName ) &&
95                  ( ((PdfName)j).equals(PDFNAME_PAGE) ) ) {
96
97                 Map newMap = new HashMap(map);
98                 newMap.remove(PDFNAME_PARENT);
99                 return new PdfDictionary(newMap);
100             }
101
102             // check if it is an annotation dictionary
103
j = map.get(PDFNAME_TYPE);
104             if ( ( PdfNull.isNull(j) == false ) &&
105                  ( 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 }
119
Popular Tags