use of org.apache.jempbox.xmp.XMPSchemaBasic in project openolat by klemens.
the class PdfDocument method addMetadata.
public void addMetadata(String title, String subject, String author) throws IOException, TransformerException {
PDDocumentCatalog catalog = document.getDocumentCatalog();
PDDocumentInformation info = document.getDocumentInformation();
Calendar date = Calendar.getInstance();
info.setAuthor(author);
info.setCreator(author);
info.setCreationDate(date);
info.setModificationDate(date);
info.setTitle(title);
info.setSubject(subject);
XMPMetadata metadata = new XMPMetadata();
XMPSchemaPDF pdfSchema = metadata.addPDFSchema();
pdfSchema.setProducer("OpenOLAT");
XMPSchemaBasic basicSchema = metadata.addBasicSchema();
basicSchema.setModifyDate(date);
basicSchema.setCreateDate(date);
basicSchema.setCreatorTool("OpenOLAT");
basicSchema.setMetadataDate(date);
XMPSchemaDublinCore dcSchema = metadata.addDublinCoreSchema();
dcSchema.setTitle(title);
dcSchema.addCreator(author);
dcSchema.setDescription(subject);
PDMetadata metadataStream = new PDMetadata(document);
metadataStream.importXMPMetadata(metadata);
catalog.setMetadata(metadataStream);
}
use of org.apache.jempbox.xmp.XMPSchemaBasic in project jabref by JabRef.
the class XMPUtilTest method testSimpleUpdate.
/**
* Tests whether writing BibTex.xmp will preserve existing XMP-descriptions.
*
* @throws Exception (indicating an failure)
*/
@Test
public void testSimpleUpdate() throws Exception {
String s = " <rdf:Description rdf:about=''" + " xmlns:xmp='http://ns.adobe.com/xap/1.0/'>" + " <xmp:CreatorTool>Acrobat PDFMaker 7.0.7</xmp:CreatorTool>" + " <xmp:ModifyDate>2006-08-07T18:50:24+02:00</xmp:ModifyDate>" + " <xmp:CreateDate>2006-08-07T14:44:24+02:00</xmp:CreateDate>" + " <xmp:MetadataDate>2006-08-07T18:50:24+02:00</xmp:MetadataDate>" + " </rdf:Description>" + " <rdf:Description rdf:about=''" + " xmlns:xapMM='http://ns.adobe.com/xap/1.0/mm/'>" + " <xapMM:DocumentID>uuid:843cd67d-495e-4c1e-a4cd-64178f6b3299</xapMM:DocumentID>" + " <xapMM:InstanceID>uuid:1e56b4c0-6782-440d-ba76-d2b3d87547d1</xapMM:InstanceID>" + " <xapMM:VersionID>" + " <rdf:Seq>" + " <rdf:li>17</rdf:li>" + " </rdf:Seq>" + " </xapMM:VersionID>" + " </rdf:Description>" + " <rdf:Description rdf:about=''" + " xmlns:dc='http://purl.org/dc/elements/1.1/'>" + " <dc:format>application/pdf</dc:format>" + "</rdf:Description>";
writeManually(pdfFile, XMPUtilTest.bibtexXPacket(s));
// Nothing there yet, but should not crash
Assert.assertEquals(Collections.emptyList(), XMPUtil.readXMP(pdfFile, xmpPreferences));
s = " <rdf:Description rdf:about=''" + " xmlns:xmp='http://ns.adobe.com/xap/1.0/'>" + " <xmp:CreatorTool>Acrobat PDFMaker 7.0.7</xmp:CreatorTool>" + " <xmp:ModifyDate>2006-08-07T18:50:24+02:00</xmp:ModifyDate>" + " <xmp:CreateDate>2006-08-07T14:44:24+02:00</xmp:CreateDate>" + " <xmp:MetadataDate>2006-08-07T18:50:24+02:00</xmp:MetadataDate>" + " </rdf:Description>" + " <rdf:Description rdf:about=''" + " xmlns:xapMM='http://ns.adobe.com/xap/1.0/mm/'>" + " <xapMM:DocumentID>uuid:843cd67d-495e-4c1e-a4cd-64178f6b3299</xapMM:DocumentID>" + " <xapMM:InstanceID>uuid:1e56b4c0-6782-440d-ba76-d2b3d87547d1</xapMM:InstanceID>" + " <xapMM:VersionID>" + " <rdf:Seq>" + " <rdf:li>17</rdf:li>" + " </rdf:Seq>" + " </xapMM:VersionID>" + " </rdf:Description>" + " <rdf:Description rdf:about=''" + " xmlns:dc='http://purl.org/dc/elements/1.1/'>" + " <dc:format>application/pdf</dc:format>" + " <dc:title>" + " <rdf:Alt>" + " <rdf:li xml:lang='x-default'>Questionnaire.pdf</rdf:li>" + " </rdf:Alt>" + " </dc:title>" + "</rdf:Description>";
writeManually(pdfFile, XMPUtilTest.bibtexXPacket(s));
// Title is Questionnaire.pdf so the DublinCore fallback should hit
// in...
Assert.assertEquals(1, XMPUtil.readXMP(pdfFile, xmpPreferences).size());
{
// Now write new packet and check if it was correctly written
XMPUtil.writeXMP(pdfFile, t1BibtexEntry(), null, xmpPreferences);
List<BibEntry> l = XMPUtil.readXMP(pdfFile.getAbsoluteFile(), xmpPreferences);
Assert.assertEquals(1, l.size());
BibEntry e = l.get(0);
assertEqualsBibtexEntry(t1BibtexEntry(), e);
try (PDDocument document = PDDocument.load(pdfFile.getAbsoluteFile())) {
if (document.isEncrypted()) {
throw new IOException("Error: Cannot read metadata from encrypted document.");
}
PDDocumentCatalog catalog = document.getDocumentCatalog();
PDMetadata metaRaw = catalog.getMetadata();
XMPMetadata meta;
if (metaRaw == null) {
meta = new XMPMetadata();
} else {
meta = new XMPMetadata(XMLUtil.parse(metaRaw.createInputStream()));
}
meta.addXMLNSMapping(XMPSchemaBibtex.NAMESPACE, XMPSchemaBibtex.class);
List<XMPSchema> schemas = meta.getSchemas();
Assert.assertEquals(4, schemas.size());
schemas = meta.getSchemasByNamespaceURI(XMPSchemaBibtex.NAMESPACE);
Assert.assertEquals(1, schemas.size());
schemas = meta.getSchemasByNamespaceURI(XMPSchemaDublinCore.NAMESPACE);
Assert.assertEquals(1, schemas.size());
XMPSchemaDublinCore dc = (XMPSchemaDublinCore) schemas.get(0);
Assert.assertEquals("application/pdf", dc.getFormat());
schemas = meta.getSchemasByNamespaceURI(XMPSchemaBasic.NAMESPACE);
Assert.assertEquals(1, schemas.size());
XMPSchemaBasic bs = (XMPSchemaBasic) schemas.get(0);
Assert.assertEquals("Acrobat PDFMaker 7.0.7", bs.getCreatorTool());
Calendar c = Calendar.getInstance();
c.clear();
c.set(Calendar.YEAR, 2006);
c.set(Calendar.MONTH, Calendar.AUGUST);
c.set(Calendar.DATE, 7);
c.set(Calendar.HOUR, 14);
c.set(Calendar.MINUTE, 44);
c.set(Calendar.SECOND, 24);
c.setTimeZone(TimeZone.getTimeZone("GMT+2"));
Calendar other = bs.getCreateDate();
Assert.assertEquals(c.get(Calendar.YEAR), other.get(Calendar.YEAR));
Assert.assertEquals(c.get(Calendar.MONTH), other.get(Calendar.MONTH));
Assert.assertEquals(c.get(Calendar.DATE), other.get(Calendar.DATE));
Assert.assertEquals(c.get(Calendar.HOUR), other.get(Calendar.HOUR));
Assert.assertEquals(c.get(Calendar.MINUTE), other.get(Calendar.MINUTE));
Assert.assertEquals(c.get(Calendar.SECOND), other.get(Calendar.SECOND));
Assert.assertTrue(c.getTimeZone().hasSameRules(other.getTimeZone()));
schemas = meta.getSchemasByNamespaceURI(XMPSchemaMediaManagement.NAMESPACE);
Assert.assertEquals(1, schemas.size());
XMPSchemaMediaManagement mm = (XMPSchemaMediaManagement) schemas.get(0);
Assert.assertEquals("17", mm.getSequenceList("xapMM:VersionID").get(0));
}
}
// Now alter the Bibtex entry, write it and do all the checks again
BibEntry toSet = t1BibtexEntry();
toSet.setField("author", "Pokemon!");
XMPUtil.writeXMP(pdfFile, toSet, null, xmpPreferences);
List<BibEntry> l = XMPUtil.readXMP(pdfFile.getAbsoluteFile(), xmpPreferences);
Assert.assertEquals(1, l.size());
BibEntry e = l.get(0);
assertEqualsBibtexEntry(toSet, e);
try (PDDocument document = PDDocument.load(pdfFile.getAbsoluteFile())) {
if (document.isEncrypted()) {
throw new IOException("Error: Cannot read metadata from encrypted document.");
}
PDDocumentCatalog catalog = document.getDocumentCatalog();
PDMetadata metaRaw = catalog.getMetadata();
XMPMetadata meta;
if (metaRaw == null) {
meta = new XMPMetadata();
} else {
meta = new XMPMetadata(XMLUtil.parse(metaRaw.createInputStream()));
}
meta.addXMLNSMapping(XMPSchemaBibtex.NAMESPACE, XMPSchemaBibtex.class);
List<XMPSchema> schemas = meta.getSchemas();
Assert.assertEquals(4, schemas.size());
schemas = meta.getSchemasByNamespaceURI(XMPSchemaBibtex.NAMESPACE);
Assert.assertEquals(1, schemas.size());
schemas = meta.getSchemasByNamespaceURI(XMPSchemaDublinCore.NAMESPACE);
Assert.assertEquals(1, schemas.size());
XMPSchemaDublinCore dc = (XMPSchemaDublinCore) schemas.get(0);
Assert.assertEquals("application/pdf", dc.getFormat());
schemas = meta.getSchemasByNamespaceURI(XMPSchemaBasic.NAMESPACE);
Assert.assertEquals(1, schemas.size());
XMPSchemaBasic bs = (XMPSchemaBasic) schemas.get(0);
Assert.assertEquals("Acrobat PDFMaker 7.0.7", bs.getCreatorTool());
Calendar c = Calendar.getInstance();
c.clear();
c.set(Calendar.YEAR, 2006);
c.set(Calendar.MONTH, 7);
c.set(Calendar.DATE, 7);
c.set(Calendar.HOUR, 14);
c.set(Calendar.MINUTE, 44);
c.set(Calendar.SECOND, 24);
c.setTimeZone(TimeZone.getTimeZone("GMT+2"));
Calendar other = bs.getCreateDate();
Assert.assertEquals(c.get(Calendar.YEAR), other.get(Calendar.YEAR));
Assert.assertEquals(c.get(Calendar.MONTH), other.get(Calendar.MONTH));
Assert.assertEquals(c.get(Calendar.DATE), other.get(Calendar.DATE));
Assert.assertEquals(c.get(Calendar.HOUR), other.get(Calendar.HOUR));
Assert.assertEquals(c.get(Calendar.MINUTE), other.get(Calendar.MINUTE));
Assert.assertEquals(c.get(Calendar.SECOND), other.get(Calendar.SECOND));
Assert.assertTrue(c.getTimeZone().hasSameRules(other.getTimeZone()));
schemas = meta.getSchemasByNamespaceURI(XMPSchemaMediaManagement.NAMESPACE);
Assert.assertEquals(1, schemas.size());
XMPSchemaMediaManagement mm = (XMPSchemaMediaManagement) schemas.get(0);
Assert.assertEquals("17", mm.getSequenceList("xapMM:VersionID").get(0));
}
}
use of org.apache.jempbox.xmp.XMPSchemaBasic in project OpenOLAT by OpenOLAT.
the class PdfDocument method addMetadata.
public void addMetadata(String title, String subject, String author) throws IOException, TransformerException {
PDDocumentCatalog catalog = document.getDocumentCatalog();
PDDocumentInformation info = document.getDocumentInformation();
Calendar date = Calendar.getInstance();
info.setAuthor(author);
info.setCreator(author);
info.setCreationDate(date);
info.setModificationDate(date);
info.setTitle(title);
info.setSubject(subject);
XMPMetadata metadata = new XMPMetadata();
XMPSchemaPDF pdfSchema = metadata.addPDFSchema();
pdfSchema.setProducer("OpenOLAT");
XMPSchemaBasic basicSchema = metadata.addBasicSchema();
basicSchema.setModifyDate(date);
basicSchema.setCreateDate(date);
basicSchema.setCreatorTool("OpenOLAT");
basicSchema.setMetadataDate(date);
XMPSchemaDublinCore dcSchema = metadata.addDublinCoreSchema();
dcSchema.setTitle(title);
dcSchema.addCreator(author);
dcSchema.setDescription(subject);
PDMetadata metadataStream = new PDMetadata(document);
metadataStream.importXMPMetadata(metadata);
catalog.setMetadata(metadataStream);
}
Aggregations