You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PDFAMetadataTestCase.java 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /* $Id$ */
  18. package org.apache.fop.render.pdf;
  19. import static org.junit.Assert.assertEquals;
  20. import static org.junit.Assert.assertNull;
  21. import java.util.Calendar;
  22. import java.util.TimeZone;
  23. import org.apache.fop.pdf.PDFDocument;
  24. import org.apache.fop.pdf.PDFInfo;
  25. import org.apache.fop.pdf.PDFMetadata;
  26. import org.apache.xmlgraphics.xmp.Metadata;
  27. import org.apache.xmlgraphics.xmp.schemas.DublinCoreAdapter;
  28. import org.apache.xmlgraphics.xmp.schemas.DublinCoreSchema;
  29. import org.apache.xmlgraphics.xmp.schemas.XMPBasicAdapter;
  30. import org.apache.xmlgraphics.xmp.schemas.XMPBasicSchema;
  31. import org.apache.xmlgraphics.xmp.schemas.pdf.AdobePDFAdapter;
  32. import org.apache.xmlgraphics.xmp.schemas.pdf.AdobePDFSchema;
  33. import org.junit.Test;
  34. /**
  35. * Test case for PDF/A metadata handling.
  36. */
  37. public class PDFAMetadataTestCase {
  38. @Test
  39. public void testInfoUpdate() throws Exception {
  40. Metadata meta = new Metadata();
  41. DublinCoreAdapter dc = DublinCoreSchema.getAdapter(meta);
  42. dc.setTitle("MyTitle");
  43. dc.setDescription(null, "MySubject");
  44. dc.addCreator("That's me");
  45. AdobePDFAdapter pdf = AdobePDFSchema.getAdapter(meta);
  46. pdf.setKeywords("XSL-FO XML");
  47. pdf.setProducer("SuperFOP");
  48. XMPBasicAdapter xmp = XMPBasicSchema.getAdapter(meta);
  49. xmp.setCreatorTool("WonderFOP");
  50. Calendar cal1 = Calendar.getInstance(TimeZone.getTimeZone("Europe/Zurich"));
  51. cal1.set(2007, Calendar.JUNE, 5, 21, 49, 13);
  52. cal1.set(Calendar.MILLISECOND, 0);
  53. xmp.setCreateDate(cal1.getTime());
  54. Calendar cal2 = Calendar.getInstance(TimeZone.getTimeZone("Europe/Zurich"));
  55. cal2.set(2007, Calendar.JUNE, 6, 8, 15, 59);
  56. cal2.set(Calendar.MILLISECOND, 0);
  57. xmp.setModifyDate(cal2.getTime());
  58. PDFInfo info = new PDFInfo();
  59. assertNull(info.getTitle());
  60. PDFMetadata.updateInfoFromMetadata(meta, info);
  61. assertEquals("MyTitle", info.getTitle());
  62. assertEquals("MySubject", info.getSubject());
  63. assertEquals("That's me", info.getAuthor());
  64. assertEquals("XSL-FO XML", info.getKeywords());
  65. assertEquals("SuperFOP", info.getProducer());
  66. assertEquals("WonderFOP", info.getCreator());
  67. assertEquals(cal1.getTime(), info.getCreationDate());
  68. assertEquals(cal2.getTime(), info.getModDate());
  69. }
  70. @Test
  71. public void testXMPUpdate() throws Exception {
  72. PDFDocument doc = new PDFDocument("SuperFOP");
  73. PDFInfo info = doc.getInfo();
  74. info.setTitle("MyTitle");
  75. info.setSubject("MySubject");
  76. info.setAuthor("That's me");
  77. info.setKeywords("XSL-FO XML");
  78. //info.setProducer("SuperFOP");
  79. info.setCreator("WonderFOP");
  80. Calendar cal1 = Calendar.getInstance(TimeZone.getTimeZone("Europe/Zurich"));
  81. cal1.set(2007, Calendar.JUNE, 5, 21, 49, 13);
  82. cal1.set(Calendar.MILLISECOND, 0);
  83. info.setCreationDate(cal1.getTime());
  84. Calendar cal2 = Calendar.getInstance(TimeZone.getTimeZone("Europe/Zurich"));
  85. cal2.set(2007, Calendar.JUNE, 6, 8, 15, 59);
  86. cal2.set(Calendar.MILLISECOND, 0);
  87. info.setModDate(cal2.getTime());
  88. Metadata meta = PDFMetadata.createXMPFromPDFDocument(doc);
  89. DublinCoreAdapter dc = DublinCoreSchema.getAdapter(meta);
  90. assertEquals("MyTitle", dc.getTitle());
  91. assertEquals("MySubject", dc.getDescription());
  92. assertEquals(1, dc.getCreators().length);
  93. assertEquals("That's me", dc.getCreators()[0]);
  94. AdobePDFAdapter pdf = AdobePDFSchema.getAdapter(meta);
  95. assertEquals("XSL-FO XML", pdf.getKeywords());
  96. assertEquals("SuperFOP", pdf.getProducer());
  97. XMPBasicAdapter xmp = XMPBasicSchema.getAdapter(meta);
  98. assertEquals("WonderFOP", xmp.getCreatorTool());
  99. assertEquals(cal1.getTime(), xmp.getCreateDate());
  100. assertEquals(cal2.getTime(), xmp.getModifyDate());
  101. }
  102. }