1 | package com.lowagie.text.pdf.collection; | |
2 | ||
3 | import java.util.Calendar; | |
4 | import com.lowagie.text.error_messages.MessageLocalization; | |
5 | ||
6 | import com.lowagie.text.pdf.PdfDate; | |
7 | import com.lowagie.text.pdf.PdfDictionary; | |
8 | import com.lowagie.text.pdf.PdfName; | |
9 | import com.lowagie.text.pdf.PdfNumber; | |
10 | import com.lowagie.text.pdf.PdfObject; | |
11 | import com.lowagie.text.pdf.PdfString; | |
12 | ||
13 | public class PdfCollectionItem extends PdfDictionary { | |
14 | | |
15 | /** The PdfCollectionSchema with the names and types of the items. */ | |
16 | PdfCollectionSchema schema; | |
17 | | |
18 | /** | |
19 | * Constructs a Collection Item that can be added to a PdfFileSpecification. | |
20 | */ | |
21 | public PdfCollectionItem(PdfCollectionSchema schema) { | |
22 | super(PdfName.COLLECTIONITEM); | |
23 | this.schema = schema; | |
24 | } | |
25 | | |
26 | /** | |
27 | * Sets the value of the collection item. | |
28 | * @param value | |
29 | */ | |
30 | public void addItem(String key, String value) { | |
31 | PdfName fieldname = new PdfName(key); | |
32 | PdfCollectionField field = (PdfCollectionField)schema.get(fieldname); | |
33 |
1
1. addItem : removed call to com/lowagie/text/pdf/collection/PdfCollectionItem::put → NO_COVERAGE |
put(fieldname, field.getValue(value)); |
34 | } | |
35 | | |
36 | /** | |
37 | * Sets the value of the collection item. | |
38 | * @param value | |
39 | */ | |
40 | public void addItem(String key, PdfString value) { | |
41 | PdfName fieldname = new PdfName(key); | |
42 | PdfCollectionField field = (PdfCollectionField)schema.get(fieldname); | |
43 |
1
1. addItem : negated conditional → NO_COVERAGE |
if (field.fieldType == PdfCollectionField.TEXT) { |
44 |
1
1. addItem : removed call to com/lowagie/text/pdf/collection/PdfCollectionItem::put → NO_COVERAGE |
put(fieldname, value); |
45 | } | |
46 | } | |
47 | | |
48 | /** | |
49 | * Sets the value of the collection item. | |
50 | * @param d | |
51 | */ | |
52 | public void addItem(String key, PdfDate d) { | |
53 | PdfName fieldname = new PdfName(key); | |
54 | PdfCollectionField field = (PdfCollectionField)schema.get(fieldname); | |
55 |
1
1. addItem : negated conditional → NO_COVERAGE |
if (field.fieldType == PdfCollectionField.DATE) { |
56 |
1
1. addItem : removed call to com/lowagie/text/pdf/collection/PdfCollectionItem::put → NO_COVERAGE |
put(fieldname, d); |
57 | } | |
58 | } | |
59 | | |
60 | /** | |
61 | * Sets the value of the collection item. | |
62 | * @param n | |
63 | */ | |
64 | public void addItem(String key, PdfNumber n) { | |
65 | PdfName fieldname = new PdfName(key); | |
66 | PdfCollectionField field = (PdfCollectionField)schema.get(fieldname); | |
67 |
1
1. addItem : negated conditional → NO_COVERAGE |
if (field.fieldType == PdfCollectionField.NUMBER) { |
68 |
1
1. addItem : removed call to com/lowagie/text/pdf/collection/PdfCollectionItem::put → NO_COVERAGE |
put(fieldname, n); |
69 | } | |
70 | } | |
71 | | |
72 | /** | |
73 | * Sets the value of the collection item. | |
74 | * @param c | |
75 | */ | |
76 | public void addItem(String key, Calendar c) { | |
77 |
1
1. addItem : removed call to com/lowagie/text/pdf/collection/PdfCollectionItem::addItem → NO_COVERAGE |
addItem(key, new PdfDate(c)); |
78 | } | |
79 | | |
80 | /** | |
81 | * Sets the value of the collection item. | |
82 | * @param i | |
83 | */ | |
84 | public void addItem(String key, int i) { | |
85 |
1
1. addItem : removed call to com/lowagie/text/pdf/collection/PdfCollectionItem::addItem → NO_COVERAGE |
addItem(key, new PdfNumber(i)); |
86 | } | |
87 | | |
88 | /** | |
89 | * Sets the value of the collection item. | |
90 | * @param f | |
91 | */ | |
92 | public void addItem(String key, float f) { | |
93 |
1
1. addItem : removed call to com/lowagie/text/pdf/collection/PdfCollectionItem::addItem → NO_COVERAGE |
addItem(key, new PdfNumber(f)); |
94 | } | |
95 | | |
96 | /** | |
97 | * Sets the value of the collection item. | |
98 | * @param d | |
99 | */ | |
100 | public void addItem(String key, double d) { | |
101 |
1
1. addItem : removed call to com/lowagie/text/pdf/collection/PdfCollectionItem::addItem → NO_COVERAGE |
addItem(key, new PdfNumber(d)); |
102 | } | |
103 | | |
104 | /** | |
105 | * Adds a prefix for the Collection item. | |
106 | * You can only use this method after you have set the value of the item. | |
107 | * @param prefix a prefix | |
108 | */ | |
109 | public void setPrefix(String key, String prefix) { | |
110 | PdfName fieldname = new PdfName(key); | |
111 | PdfObject o = get(fieldname); | |
112 |
1
1. setPrefix : negated conditional → NO_COVERAGE |
if (o == null) |
113 | throw new IllegalArgumentException(MessageLocalization.getComposedMessage("you.must.set.a.value.before.adding.a.prefix")); | |
114 | PdfDictionary dict = new PdfDictionary(PdfName.COLLECTIONSUBITEM); | |
115 |
1
1. setPrefix : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
dict.put(PdfName.D, o); |
116 |
1
1. setPrefix : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
dict.put(PdfName.P, new PdfString(prefix, PdfObject.TEXT_UNICODE)); |
117 |
1
1. setPrefix : removed call to com/lowagie/text/pdf/collection/PdfCollectionItem::put → NO_COVERAGE |
put(fieldname, dict); |
118 | } | |
119 | } | |
Mutations | ||
33 |
1.1 |
|
43 |
1.1 |
|
44 |
1.1 |
|
55 |
1.1 |
|
56 |
1.1 |
|
67 |
1.1 |
|
68 |
1.1 |
|
77 |
1.1 |
|
85 |
1.1 |
|
93 |
1.1 |
|
101 |
1.1 |
|
112 |
1.1 |
|
115 |
1.1 |
|
116 |
1.1 |
|
117 |
1.1 |