1 /*
2 * Copyright 2008-2019 by Emeric Vernat
3 *
4 * This file is part of Java Melody.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18 package net.bull.javamelody.internal.web.pdf;
19
20 import java.io.IOException;
21
22 import com.lowagie.text.Document;
23 import com.lowagie.text.DocumentException;
24 import com.lowagie.text.Element;
25
26 import net.bull.javamelody.internal.common.I18N;
27
28 /**
29 * Parent abstrait des classes de rapport pdf.
30 * @author Emeric Vernat
31 */
32 abstract class PdfAbstractReport {
33 private final Document document;
34
35 PdfAbstractReport(Document document) {
36 super();
37 assert document != null;
38 this.document = document;
39 }
40
41 /**
42 * Perform the default pdf rendering of the report into the document.
43 * @throws DocumentException e
44 * @throws IOException e
45 */
46 abstract void toPdf() throws DocumentException, IOException;
47
48 Document getDocument() {
49 return document;
50 }
51
52 /**
53 * Adds an <CODE>Element</CODE> to the <CODE>Document</CODE>.
54 *
55 * @param element
56 * the <CODE>Element</CODE> to add
57 * @return <CODE>true</CODE> if the element was added, <CODE>false
58 * </CODE> if not
59 * @throws DocumentException
60 * when a document isn't open yet, or has been closed
61 */
62 boolean addToDocument(Element element) throws DocumentException {
63 return document.add(element);
64 }
65
66 /**
67 * Signals that an new page has to be started.
68 *
69 * @return <CODE>true</CODE> if the page was added, <CODE>false</CODE>
70 * if not.
71 */
72 boolean newPage() {
73 return document.newPage();
74 }
75
76 /**
77 * Retourne une traduction dans la locale courante.
78 * @param key clé d'un libellé dans les fichiers de traduction
79 * @return String
80 */
81 static String getString(String key) {
82 return I18N.getString(key);
83 }
84
85 /**
86 * Retourne une traduction dans la locale courante et insère les arguments aux positions {i}.
87 * @param key clé d'un libellé dans les fichiers de traduction
88 * @param arguments Valeur à inclure dans le résultat
89 * @return String
90 */
91 static String getFormattedString(String key, Object... arguments) {
92 return I18N.getFormattedString(key, arguments);
93 }
94 }
95