1 | package com.lowagie.text.pdf.collection; | |
2 | ||
3 | import com.lowagie.text.pdf.PdfBoolean; | |
4 | import com.lowagie.text.pdf.PdfDate; | |
5 | import com.lowagie.text.pdf.PdfDictionary; | |
6 | import com.lowagie.text.pdf.PdfName; | |
7 | import com.lowagie.text.pdf.PdfNumber; | |
8 | import com.lowagie.text.pdf.PdfObject; | |
9 | import com.lowagie.text.pdf.PdfString; | |
10 | import com.lowagie.text.error_messages.MessageLocalization; | |
11 | ||
12 | /** | |
13 | * @author blowagie | |
14 | * | |
15 | */ | |
16 | public class PdfCollectionField extends PdfDictionary { | |
17 | /** A possible type of collection field. */ | |
18 | public static final int TEXT = 0; | |
19 | /** A possible type of collection field. */ | |
20 | public static final int DATE = 1; | |
21 | /** A possible type of collection field. */ | |
22 | public static final int NUMBER = 2; | |
23 | /** A possible type of collection field. */ | |
24 | public static final int FILENAME = 3; | |
25 | /** A possible type of collection field. */ | |
26 | public static final int DESC = 4; | |
27 | /** A possible type of collection field. */ | |
28 | public static final int MODDATE = 5; | |
29 | /** A possible type of collection field. */ | |
30 | public static final int CREATIONDATE = 6; | |
31 | /** A possible type of collection field. */ | |
32 | public static final int SIZE = 7; | |
33 | | |
34 | /** | |
35 | * The type of the PDF collection field. | |
36 | * @since 2.1.2 (was called <code>type</code> previously) | |
37 | */ | |
38 | protected int fieldType; | |
39 | ||
40 | /** | |
41 | * Creates a PdfCollectionField. | |
42 | * @param name the field name | |
43 | * @param type the field type | |
44 | */ | |
45 | public PdfCollectionField(String name, int type) { | |
46 | super(PdfName.COLLECTIONFIELD); | |
47 |
1
1. |
put(PdfName.N, new PdfString(name, PdfObject.TEXT_UNICODE)); |
48 | this.fieldType = type; | |
49 | switch(type) { | |
50 | default: | |
51 |
1
1. |
put(PdfName.SUBTYPE, PdfName.S); |
52 | break; | |
53 | case DATE: | |
54 |
1
1. |
put(PdfName.SUBTYPE, PdfName.D); |
55 | break; | |
56 | case NUMBER: | |
57 |
1
1. |
put(PdfName.SUBTYPE, PdfName.N); |
58 | break; | |
59 | case FILENAME: | |
60 |
1
1. |
put(PdfName.SUBTYPE, PdfName.F); |
61 | break; | |
62 | case DESC: | |
63 |
1
1. |
put(PdfName.SUBTYPE, PdfName.DESC); |
64 | break; | |
65 | case MODDATE: | |
66 |
1
1. |
put(PdfName.SUBTYPE, PdfName.MODDATE); |
67 | break; | |
68 | case CREATIONDATE: | |
69 |
1
1. |
put(PdfName.SUBTYPE, PdfName.CREATIONDATE); |
70 | break; | |
71 | case SIZE: | |
72 |
1
1. |
put(PdfName.SUBTYPE, PdfName.SIZE); |
73 | break; | |
74 | } | |
75 | } | |
76 | | |
77 | /** | |
78 | * The relative order of the field name. Fields are sorted in ascending order. | |
79 | * @param i a number indicating the order of the field | |
80 | */ | |
81 | public void setOrder(int i) { | |
82 |
1
1. setOrder : removed call to com/lowagie/text/pdf/collection/PdfCollectionField::put → NO_COVERAGE |
put(PdfName.O, new PdfNumber(i)); |
83 | } | |
84 | | |
85 | /** | |
86 | * Sets the initial visibility of the field. | |
87 | * @param visible the default is true (visible) | |
88 | */ | |
89 | public void setVisible(boolean visible) { | |
90 |
1
1. setVisible : removed call to com/lowagie/text/pdf/collection/PdfCollectionField::put → NO_COVERAGE |
put(PdfName.V, new PdfBoolean(visible)); |
91 | } | |
92 | | |
93 | /** | |
94 | * Indication if the field value should be editable in the viewer. | |
95 | * @param editable the default is false (not editable) | |
96 | */ | |
97 | public void setEditable(boolean editable) { | |
98 |
1
1. setEditable : removed call to com/lowagie/text/pdf/collection/PdfCollectionField::put → NO_COVERAGE |
put(PdfName.E, new PdfBoolean(editable)); |
99 | } | |
100 | ||
101 | /** | |
102 | * Checks if the type of the field is suitable for a Collection Item. | |
103 | */ | |
104 | public boolean isCollectionItem() { | |
105 | switch(fieldType) { | |
106 | case TEXT: | |
107 | case DATE: | |
108 | case NUMBER: | |
109 |
1
1. isCollectionItem : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return true; |
110 | default: | |
111 |
1
1. isCollectionItem : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return false; |
112 | } | |
113 | } | |
114 | | |
115 | /** | |
116 | * Returns a PdfObject that can be used as the value of a Collection Item. | |
117 | * @param v value the value that has to be changed into a PdfObject (PdfString, PdfDate or PdfNumber) | |
118 | */ | |
119 | public PdfObject getValue(String v) { | |
120 | switch(fieldType) { | |
121 | case TEXT: | |
122 |
1
1. getValue : mutated return of Object value for com/lowagie/text/pdf/collection/PdfCollectionField::getValue to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new PdfString(v, PdfObject.TEXT_UNICODE); |
123 | case DATE: | |
124 |
1
1. getValue : mutated return of Object value for com/lowagie/text/pdf/collection/PdfCollectionField::getValue to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new PdfDate(PdfDate.decode(v)); |
125 | case NUMBER: | |
126 |
1
1. getValue : mutated return of Object value for com/lowagie/text/pdf/collection/PdfCollectionField::getValue to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new PdfNumber(v); |
127 | } | |
128 | throw new IllegalArgumentException(MessageLocalization.getComposedMessage("1.is.not.an.acceptable.value.for.the.field.2", v, get(PdfName.N).toString())); | |
129 | } | |
130 | } | |
Mutations | ||
47 |
1.1 |
|
51 |
1.1 |
|
54 |
1.1 |
|
57 |
1.1 |
|
60 |
1.1 |
|
63 |
1.1 |
|
66 |
1.1 |
|
69 |
1.1 |
|
72 |
1.1 |
|
82 |
1.1 |
|
90 |
1.1 |
|
98 |
1.1 |
|
109 |
1.1 |
|
111 |
1.1 |
|
122 |
1.1 |
|
124 |
1.1 |
|
126 |
1.1 |