PdfCollectionField extends PdfObjectWrapper<PdfDictionary> { public PdfObject getValue(String value) { switch (subType) { case TEXT: return new PdfString(value); case DATE: return new PdfDate(PdfDate.decode(value)).getPdfObject(); case NUMBER: return new PdfNumber(Double.parseDouble(value.trim())); } throw new PdfException(PdfException._1IsNotAnAcceptableValueForTheField2).setMessageParams(value, getPdfObject().getAsString(PdfName.N).getValue()); } protected  PdfCollectionField(PdfDictionary pdfObject);  PdfCollectionField(String name, int subType); PdfCollectionField setOrder(int order); PdfNumber getOrder(); PdfCollectionField setVisibility(boolean visible); PdfBoolean getVisibility(); PdfCollectionField setEditable(boolean editable); PdfBoolean getEditable(); PdfObject getValue(String value); static final int TEXT; static final int DATE; static final int NUMBER; static final int FILENAME; static final int DESC; static final int MODDATE; static final int CREATIONDATE; static final int SIZE; }
@Test public void getTextValueTest() { final String textValue = "some text"; PdfDictionary pdfObject = new PdfDictionary(); pdfObject.put(PdfName.Subtype, PdfName.S); PdfCollectionField field = new PdfCollectionField(pdfObject); Assert.assertEquals(new PdfString(textValue), field.getValue(textValue)); }
@Test public void getNumberValueTest() { final double numberValue = 125; final String numberValueAsString = String.valueOf(numberValue); PdfDictionary pdfObject = new PdfDictionary(); pdfObject.put(PdfName.Subtype, PdfName.N); PdfCollectionField field = new PdfCollectionField(pdfObject); Assert.assertEquals(numberValue, ((PdfNumber)field.getValue(numberValueAsString)).getValue(), 0.0001); }
@Test public void getDateValueTest() { final String timeValueAsString = "D:19860426012347+04'00'"; PdfDictionary pdfObject = new PdfDictionary(); pdfObject.put(PdfName.Subtype, PdfName.D); PdfCollectionField field = new PdfCollectionField(pdfObject); Assert.assertTrue(((PdfString)field.getValue(timeValueAsString)).getValue().startsWith("D:1986")); }
@Test public void getUnsupportedTypeValueTest() { final String stringValue = "string value"; final String fieldName = "fieldName"; junitExpectedException.expect(PdfException.class); junitExpectedException.expectMessage(MessageFormatUtil.format(PdfException._1IsNotAnAcceptableValueForTheField2, stringValue, fieldName)); PdfCollectionField field = new PdfCollectionField(fieldName, PdfCollectionField.FILENAME); field.getValue(stringValue); }