Debian Codegraph @

src/main/java/org/jfree/pdf/dictionary/DictionaryObject.java

raw
1 /* =====================================================================
2 * JFreePDF : a fast, light-weight PDF library for the Java(tm) platform
3 * =====================================================================
4 *
5 * (C)opyright 2013-2022, by David Gilbert. All rights reserved.
6 *
7 * https://github.com/jfree/orsonpdf
8 *
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 *
22 * [Oracle and Java are registered trademarks of Oracle and/or its affiliates.
23 * Other names may be trademarks of their respective owners.]
24 *
25 * If you do not wish to be bound by the terms of the GPL, an alternative
26 * runtime license is available to JFree sponsors:
27 *
28 * https://github.com/sponsors/jfree
29 *
30 */
31
32
33 package org.jfree.pdf.dictionary;
34
35 import org.jfree.pdf.internal.PDFObject;
36 import org.jfree.pdf.util.Args;
37
38 /**
39 * A PDF object that is represented by a dictionary. This is used to
40 * represent the {@code Catalog} and the {@code Outlines} (the latter
41 * being a placeholder implementation only since we don't presently generate
42 * outlines).
43 */
44 public class DictionaryObject extends PDFObject {
45
46 protected Dictionary dictionary;
47
48 /**
49 * Creates a new instance.
50 *
51 * @param number the object number.
52 * @param type the object type (for example, "/Catalog").
53 */
54 public DictionaryObject(int number, String type) {
55 super(number);
56 this.dictionary = new Dictionary(type);
57 }
58
59 /**
60 * Puts an item in the dictionary.
61 *
62 * @param name the name (without the leading "/", {@code null} not
63 * permitted).
64 * @param value the value ({@code null} not permitted).
65 */
66 public void put(String name, Object value) {
67 Args.nullNotPermitted(value, "value");
68 this.dictionary.put("/" + name, value);
69 }
70
71 /**
72 * Removes an item from the dictionary.
73 *
74 * @param name the name (without the leading "/").
75 *
76 * @return The value that was previously stored with the given name.
77 */
78 public Object remove(String name) {
79 return this.dictionary.remove("/" + name);
80 }
81
82 /**
83 * Returns the bytes that go between the 'obj' and 'endobj' in the
84 * PDF output for this object.
85 *
86 * @return A byte array.
87 */
88 @Override
89 public byte[] getObjectBytes() {
90 return this.dictionary.toPDFBytes();
91 }
92 }