PdfPageEventForwarder.java

1
/*
2
 * $Id: PdfPageEventForwarder.java 3373 2008-05-12 16:21:24Z xlv $
3
 *
4
 * Copyright 2005 Bruno Lowagie
5
 *
6
 * The contents of this file are subject to the Mozilla Public License Version 1.1
7
 * (the "License"); you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at http://www.mozilla.org/MPL/
9
 *
10
 * Software distributed under the License is distributed on an "AS IS" basis,
11
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
 * for the specific language governing rights and limitations under the License.
13
 *
14
 * The Original Code is 'iText, a free JAVA-PDF library'.
15
 *
16
 * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
17
 * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
18
 * All Rights Reserved.
19
 * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
20
 * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
21
 *
22
 * Contributor(s): all the names of the contributors are added in the source code
23
 * where applicable.
24
 *
25
 * Alternatively, the contents of this file may be used under the terms of the
26
 * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
27
 * provisions of LGPL are applicable instead of those above.  If you wish to
28
 * allow use of your version of this file only under the terms of the LGPL
29
 * License and not to allow others to use your version of this file under
30
 * the MPL, indicate your decision by deleting the provisions above and
31
 * replace them with the notice and other provisions required by the LGPL.
32
 * If you do not delete the provisions above, a recipient may use your version
33
 * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
34
 *
35
 * This library is free software; you can redistribute it and/or modify it
36
 * under the terms of the MPL as stated above or under the terms of the GNU
37
 * Library General Public License as published by the Free Software Foundation;
38
 * either version 2 of the License, or any later version.
39
 *
40
 * This library is distributed in the hope that it will be useful, but WITHOUT
41
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
42
 * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
43
 * details.
44
 *
45
 * If you didn't download this code from the following link, you should check if
46
 * you aren't using an obsolete version:
47
 * http://www.lowagie.com/iText/
48
 */
49
50
package com.lowagie.text.pdf.events;
51
52
import java.util.ArrayList;
53
54
import com.lowagie.text.Document;
55
import com.lowagie.text.Paragraph;
56
import com.lowagie.text.Rectangle;
57
import com.lowagie.text.pdf.PdfPageEvent;
58
import com.lowagie.text.pdf.PdfWriter;
59
60
/**
61
 * If you want to add more than one page event to a PdfWriter,
62
 * you have to construct a PdfPageEventForwarder, add the
63
 * different events to this object and add the forwarder to
64
 * the PdfWriter.
65
 */
66
67
public class PdfPageEventForwarder implements PdfPageEvent {
68
69
    /** ArrayList containing all the PageEvents that have to be executed. */
70
    protected ArrayList events = new ArrayList();
71
    
72
    /** 
73
     * Add a page event to the forwarder.
74
     * @param event an event that has to be added to the forwarder.
75
     */
76
    public void addPageEvent(PdfPageEvent event) {
77
        events.add(event);
78
    }
79
    
80
    /**
81
     * Called when the document is opened.
82
     * 
83
     * @param writer
84
     *            the <CODE>PdfWriter</CODE> for this document
85
     * @param document
86
     *            the document
87
     */
88
    public void onOpenDocument(PdfWriter writer, Document document) {
89
        PdfPageEvent event;
90
        for (Object event1 : events) {
91
            event = (PdfPageEvent) event1;
92 1 1. onOpenDocument : removed call to com/lowagie/text/pdf/PdfPageEvent::onOpenDocument → NO_COVERAGE
            event.onOpenDocument(writer, document);
93
        }
94
    }
95
96
    /**
97
     * Called when a page is initialized.
98
     * <P>
99
     * Note that if even if a page is not written this method is still called.
100
     * It is preferable to use <CODE>onEndPage</CODE> to avoid infinite loops.
101
     * 
102
     * @param writer
103
     *            the <CODE>PdfWriter</CODE> for this document
104
     * @param document
105
     *            the document
106
     */
107
    public void onStartPage(PdfWriter writer, Document document) {
108
        PdfPageEvent event;
109
        for (Object event1 : events) {
110
            event = (PdfPageEvent) event1;
111 1 1. onStartPage : removed call to com/lowagie/text/pdf/PdfPageEvent::onStartPage → NO_COVERAGE
            event.onStartPage(writer, document);
112
        }
113
    }
114
115
    /**
116
     * Called when a page is finished, just before being written to the
117
     * document.
118
     * 
119
     * @param writer
120
     *            the <CODE>PdfWriter</CODE> for this document
121
     * @param document
122
     *            the document
123
     */
124
    public void onEndPage(PdfWriter writer, Document document) {
125
        PdfPageEvent event;
126
        for (Object event1 : events) {
127
            event = (PdfPageEvent) event1;
128 1 1. onEndPage : removed call to com/lowagie/text/pdf/PdfPageEvent::onEndPage → NO_COVERAGE
            event.onEndPage(writer, document);
129
        }
130
    }
131
132
    /**
133
     * Called when the document is closed.
134
     * <P>
135
     * Note that this method is called with the page number equal to the last
136
     * page plus one.
137
     * 
138
     * @param writer
139
     *            the <CODE>PdfWriter</CODE> for this document
140
     * @param document
141
     *            the document
142
     */
143
    public void onCloseDocument(PdfWriter writer, Document document) {
144
        PdfPageEvent event;
145
        for (Object event1 : events) {
146
            event = (PdfPageEvent) event1;
147 1 1. onCloseDocument : removed call to com/lowagie/text/pdf/PdfPageEvent::onCloseDocument → NO_COVERAGE
            event.onCloseDocument(writer, document);
148
        }
149
    }
150
151
    /**
152
     * Called when a Paragraph is written.
153
     * <P>
154
     * <CODE>paragraphPosition</CODE> will hold the height at which the
155
     * paragraph will be written to. This is useful to insert bookmarks with
156
     * more control.
157
     * 
158
     * @param writer
159
     *            the <CODE>PdfWriter</CODE> for this document
160
     * @param document
161
     *            the document
162
     * @param paragraphPosition
163
     *            the position the paragraph will be written to
164
     */
165
    public void onParagraph(PdfWriter writer, Document document,
166
            float paragraphPosition) {
167
        PdfPageEvent event;
168
        for (Object event1 : events) {
169
            event = (PdfPageEvent) event1;
170 1 1. onParagraph : removed call to com/lowagie/text/pdf/PdfPageEvent::onParagraph → NO_COVERAGE
            event.onParagraph(writer, document, paragraphPosition);
171
        }
172
    }
173
174
    /**
175
     * Called when a Paragraph is written.
176
     * <P>
177
     * <CODE>paragraphPosition</CODE> will hold the height of the end of the
178
     * paragraph.
179
     * 
180
     * @param writer
181
     *            the <CODE>PdfWriter</CODE> for this document
182
     * @param document
183
     *            the document
184
     * @param paragraphPosition
185
     *            the position of the end of the paragraph
186
     */
187
    public void onParagraphEnd(PdfWriter writer, Document document,
188
            float paragraphPosition) {
189
        PdfPageEvent event;
190
        for (Object event1 : events) {
191
            event = (PdfPageEvent) event1;
192 1 1. onParagraphEnd : removed call to com/lowagie/text/pdf/PdfPageEvent::onParagraphEnd → NO_COVERAGE
            event.onParagraphEnd(writer, document, paragraphPosition);
193
        }
194
    }
195
196
    /**
197
     * Called when a Chapter is written.
198
     * <P>
199
     * <CODE>position</CODE> will hold the height at which the chapter will be
200
     * written to.
201
     * 
202
     * @param writer
203
     *            the <CODE>PdfWriter</CODE> for this document
204
     * @param document
205
     *            the document
206
     * @param paragraphPosition
207
     *            the position the chapter will be written to
208
     * @param title
209
     *            the title of the Chapter
210
     */
211
    public void onChapter(PdfWriter writer, Document document,
212
            float paragraphPosition, Paragraph title) {
213
        PdfPageEvent event;
214
        for (Object event1 : events) {
215
            event = (PdfPageEvent) event1;
216 1 1. onChapter : removed call to com/lowagie/text/pdf/PdfPageEvent::onChapter → NO_COVERAGE
            event.onChapter(writer, document, paragraphPosition, title);
217
        }
218
    }
219
220
    /**
221
     * Called when the end of a Chapter is reached.
222
     * <P>
223
     * <CODE>position</CODE> will hold the height of the end of the chapter.
224
     * 
225
     * @param writer
226
     *            the <CODE>PdfWriter</CODE> for this document
227
     * @param document
228
     *            the document
229
     * @param position
230
     *            the position of the end of the chapter.
231
     */
232
    public void onChapterEnd(PdfWriter writer, Document document, float position) {
233
        PdfPageEvent event;
234
        for (Object event1 : events) {
235
            event = (PdfPageEvent) event1;
236 1 1. onChapterEnd : removed call to com/lowagie/text/pdf/PdfPageEvent::onChapterEnd → NO_COVERAGE
            event.onChapterEnd(writer, document, position);
237
        }
238
    }
239
240
    /**
241
     * Called when a Section is written.
242
     * <P>
243
     * <CODE>position</CODE> will hold the height at which the section will be
244
     * written to.
245
     * 
246
     * @param writer
247
     *            the <CODE>PdfWriter</CODE> for this document
248
     * @param document
249
     *            the document
250
     * @param paragraphPosition
251
     *            the position the section will be written to
252
     * @param depth
253
     *            the number depth of the Section
254
     * @param title
255
     *            the title of the section
256
     */
257
    public void onSection(PdfWriter writer, Document document,
258
            float paragraphPosition, int depth, Paragraph title) {
259
        PdfPageEvent event;
260
        for (Object event1 : events) {
261
            event = (PdfPageEvent) event1;
262 1 1. onSection : removed call to com/lowagie/text/pdf/PdfPageEvent::onSection → NO_COVERAGE
            event.onSection(writer, document, paragraphPosition, depth, title);
263
        }
264
    }
265
266
    /**
267
     * Called when the end of a Section is reached.
268
     * <P>
269
     * <CODE>position</CODE> will hold the height of the section end.
270
     * 
271
     * @param writer
272
     *            the <CODE>PdfWriter</CODE> for this document
273
     * @param document
274
     *            the document
275
     * @param position
276
     *            the position of the end of the section
277
     */
278
    public void onSectionEnd(PdfWriter writer, Document document, float position) {
279
        PdfPageEvent event;
280
        for (Object event1 : events) {
281
            event = (PdfPageEvent) event1;
282 1 1. onSectionEnd : removed call to com/lowagie/text/pdf/PdfPageEvent::onSectionEnd → NO_COVERAGE
            event.onSectionEnd(writer, document, position);
283
        }
284
    }
285
286
    /**
287
     * Called when a <CODE>Chunk</CODE> with a generic tag is written.
288
     * <P>
289
     * It is useful to pinpoint the <CODE>Chunk</CODE> location to generate
290
     * bookmarks, for example.
291
     * 
292
     * @param writer
293
     *            the <CODE>PdfWriter</CODE> for this document
294
     * @param document
295
     *            the document
296
     * @param rect
297
     *            the <CODE>Rectangle</CODE> containing the <CODE>Chunk
298
     *            </CODE>
299
     * @param text
300
     *            the text of the tag
301
     */
302
    public void onGenericTag(PdfWriter writer, Document document,
303
            Rectangle rect, String text) {
304
        PdfPageEvent event;
305
        for (Object event1 : events) {
306
            event = (PdfPageEvent) event1;
307 1 1. onGenericTag : removed call to com/lowagie/text/pdf/PdfPageEvent::onGenericTag → NO_COVERAGE
            event.onGenericTag(writer, document, rect, text);
308
        }
309
    }
310
}

Mutations

92

1.1
Location : onOpenDocument
Killed by : none
removed call to com/lowagie/text/pdf/PdfPageEvent::onOpenDocument → NO_COVERAGE

111

1.1
Location : onStartPage
Killed by : none
removed call to com/lowagie/text/pdf/PdfPageEvent::onStartPage → NO_COVERAGE

128

1.1
Location : onEndPage
Killed by : none
removed call to com/lowagie/text/pdf/PdfPageEvent::onEndPage → NO_COVERAGE

147

1.1
Location : onCloseDocument
Killed by : none
removed call to com/lowagie/text/pdf/PdfPageEvent::onCloseDocument → NO_COVERAGE

170

1.1
Location : onParagraph
Killed by : none
removed call to com/lowagie/text/pdf/PdfPageEvent::onParagraph → NO_COVERAGE

192

1.1
Location : onParagraphEnd
Killed by : none
removed call to com/lowagie/text/pdf/PdfPageEvent::onParagraphEnd → NO_COVERAGE

216

1.1
Location : onChapter
Killed by : none
removed call to com/lowagie/text/pdf/PdfPageEvent::onChapter → NO_COVERAGE

236

1.1
Location : onChapterEnd
Killed by : none
removed call to com/lowagie/text/pdf/PdfPageEvent::onChapterEnd → NO_COVERAGE

262

1.1
Location : onSection
Killed by : none
removed call to com/lowagie/text/pdf/PdfPageEvent::onSection → NO_COVERAGE

282

1.1
Location : onSectionEnd
Killed by : none
removed call to com/lowagie/text/pdf/PdfPageEvent::onSectionEnd → NO_COVERAGE

307

1.1
Location : onGenericTag
Killed by : none
removed call to com/lowagie/text/pdf/PdfPageEvent::onGenericTag → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.4.2