KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.etymon.pjx.util;
2
3 import com.etymon.pjx.*;
4
5 /**
6    Modifies indirect references within a PDF object, adding a
7    specified offset to each object number in a reference. {@link
8    PdfObjectFilter PdfObjectFilter} is used to filter the indirect
9    references. This class is synchronized.
10    @author Nassib Nassar
11 */

12 public class PdfRenumberOffset implements PdfObjectFilter {
13
14     /**
15        The offset value to add to each object number.
16     */

17     protected int _offset;
18
19     /**
20        Controls whether generation numbers will be set to 0 during
21        the renumbering process. If so, the value is
22        <code>true</code>.
23     */

24     protected boolean _resetG;
25
26     /**
27        Constructs a <code>PdfRenumberOffset</code> instance. By
28        default, generation numbers will not be modified (see
29        {@link #resetGeneration(boolean)
30        resetGeneration(boolean)}). The offset value defaults to 0
31        (see {@link #setOffset(int) setOffset(int)}).
32      */

33     public PdfRenumberOffset() {
34
35         _offset = 0;
36         _resetG = false;
37         
38     }
39
40     /**
41        Sets the offset value to add to each object number during
42        renumbering.
43        @param offset the offset to use.
44      */

45     public void setOffset(int offset) {
46         synchronized (this) {
47
48             _offset = offset;
49             
50         }
51     }
52
53     /**
54        Controls whether generation numbers will be set to 0 during
55        the renumbering process.
56        @param reset if <code>true</code>, generation numbers will
57        be set to 0; otherwise they are not modified.
58      */

59     public void resetGeneration(boolean reset) {
60         synchronized (this) {
61
62             _resetG = reset;
63             
64         }
65     }
66
67     /**
68        Adds an offset to the object number in each {@link
69        PdfReference PdfReference} within the specified object.
70        The generation number may optionally be reset to 0 (see
71        {@link #resetGeneration(boolean)
72        resetGeneration(boolean)}). The offset is specified with
73        {@link #setOffset(int) setOffset(int)}.
74        @param obj the object to renumber.
75        @return the renumbered object.
76        @throws PdfFormatException
77      */

78     public PdfObject renumber(PdfObject obj) throws PdfFormatException {
79         synchronized (this) {
80
81             return obj.filter(this);
82             
83         }
84     }
85
86     /**
87        This method is used by {@link #renumber(PdfObject)
88        renumber(PdfObject)} to filter indirect references and
89        <b>should not be called externally</b>. (It is not
90        synchronized.)
91        @param obj the object to filter.
92        @return the filtered object.
93        @throws PdfFormatException
94      */

95     public PdfObject preFilter(PdfObject obj) throws PdfFormatException {
96         if (obj instanceof PdfReference) {
97             PdfReference r = (PdfReference)obj;
98             return new PdfReference( r.getObjectNumber() + _offset,
99                          _resetG ? 0 : r.getGenerationNumber() );
100         } else {
101             return obj;
102         }
103     }
104     
105     /**
106        This method is used by {@link #renumber(PdfObject)
107        renumber(PdfObject)} to filter indirect references and
108        <b>should not be called externally</b>. (It is not
109        synchronized.)
110        @param obj the object to filter.
111        @return the filtered object.
112        @throws PdfFormatException
113      */

114     public PdfObject postFilter(PdfObject obj) throws PdfFormatException {
115         return obj;
116     }
117     
118 }
119
Popular Tags