aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/lowagie/text/xml/xmp
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/lowagie/text/xml/xmp')
-rw-r--r--src/main/java/com/lowagie/text/xml/xmp/DublinCoreSchema.java187
-rw-r--r--src/main/java/com/lowagie/text/xml/xmp/PdfSchema.java105
-rw-r--r--src/main/java/com/lowagie/text/xml/xmp/XmpArray.java99
-rw-r--r--src/main/java/com/lowagie/text/xml/xmp/XmpBasicSchema.java141
-rw-r--r--src/main/java/com/lowagie/text/xml/xmp/XmpMMSchema.java97
-rw-r--r--src/main/java/com/lowagie/text/xml/xmp/XmpSchema.java158
-rw-r--r--src/main/java/com/lowagie/text/xml/xmp/XmpWriter.java276
7 files changed, 1063 insertions, 0 deletions
diff --git a/src/main/java/com/lowagie/text/xml/xmp/DublinCoreSchema.java b/src/main/java/com/lowagie/text/xml/xmp/DublinCoreSchema.java
new file mode 100644
index 0000000..53b1ade
--- /dev/null
+++ b/src/main/java/com/lowagie/text/xml/xmp/DublinCoreSchema.java
@@ -0,0 +1,187 @@
+/*
+ * $Id: DublinCoreSchema.java,v 1.5 2005/09/08 07:50:15 blowagie Exp $
+ * $Name: $
+ *
+ * Copyright 2005 by Bruno Lowagie.
+ *
+ * The contents of this file are subject to the Mozilla Public License Version 1.1
+ * (the "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the License.
+ *
+ * The Original Code is 'iText, a free JAVA-PDF library'.
+ *
+ * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
+ * the Initial Developer are Copyright (C) 1999-2005 by Bruno Lowagie.
+ * All Rights Reserved.
+ * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
+ * are Copyright (C) 2000-2005 by Paulo Soares. All Rights Reserved.
+ *
+ * Contributor(s): all the names of the contributors are added in the source code
+ * where applicable.
+ *
+ * Alternatively, the contents of this file may be used under the terms of the
+ * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
+ * provisions of LGPL are applicable instead of those above. If you wish to
+ * allow use of your version of this file only under the terms of the LGPL
+ * License and not to allow others to use your version of this file under
+ * the MPL, indicate your decision by deleting the provisions above and
+ * replace them with the notice and other provisions required by the LGPL.
+ * If you do not delete the provisions above, a recipient may use your version
+ * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the MPL as stated above or under the terms of the GNU
+ * Library General Public License as published by the Free Software Foundation;
+ * either version 2 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU LIBRARY GENERAL PUBLIC LICENSE for more
+ * details.
+ *
+ * If you didn't download this code from the following link, you should check if
+ * you aren't using an obsolete version:
+ * http://www.lowagie.com/iText/
+ */
+
+package com.lowagie.text.xml.xmp;
+
+import java.io.IOException;
+
+/**
+ * An implementation of an XmpSchema.
+ */
+public class DublinCoreSchema extends XmpSchema {
+
+ /** default namespace identifier*/
+ public static final String DEFAULT_XPATH_ID = "dc";
+ /** default namespace uri*/
+ public static final String DEFAULT_XPATH_URI = "http://purl.org/dc/elements/1.1/";
+
+ /** External Contributors to the resource (other than the authors). */
+ public static final String CONTRIBUTOR = "dc:contributor";
+ /** The extent or scope of the resource. */
+ public static final String COVERAGE = "dc:coverage";
+ /** The authors of the resource (listed in order of precedence, if significant). */
+ public static final String CREATOR = "dc:creator";
+ /** Date(s) that something interesting happened to the resource. */
+ public static final String DATE = "dc:date";
+ /** A textual description of the content of the resource. Multiple values may be present for different languages. */
+ public static final String DESCRIPTION = "dc:description";
+ /** The file format used when saving the resource. Tools and applications should set this property to the save format of the data. It may include appropriate qualifiers. */
+ public static final String FORMAT = "dc:format";
+ /** Unique identifier of the resource. */
+ public static final String IDENTIFIER = "dc:identifier";
+ /** An unordered array specifying the languages used in the resource. */
+ public static final String LANGUAGE = "dc:language";
+ /** Publishers. */
+ public static final String PUBLISHER = "dc:publisher";
+ /** Relationships to other documents. */
+ public static final String RELATION = "dc:relation";
+ /** Informal rights statement, selected by language. */
+ public static final String RIGHTS = "dc:rights";
+ /** Unique identifier of the work from which this resource was derived. */
+ public static final String SOURCE = "dc:source";
+ /** An unordered array of descriptive phrases or keywords that specify the topic of the content of the resource. */
+ public static final String SUBJECT = "dc:subject";
+ /** The title of the document, or the name given to the resource. Typically, it will be a name by which the resource is formally known. */
+ public static final String TITLE = "dc:title";
+ /** A document type; for example, novel, poem, or working paper. */
+ public static final String TYPE = "dc:type";
+
+
+ /**
+ * @throws IOException
+ */
+ public DublinCoreSchema() throws IOException {
+ super("xmlns:" + DEFAULT_XPATH_ID + "=\"" + DEFAULT_XPATH_URI + "\"");
+ setProperty(FORMAT, "application/pdf");
+ }
+
+ /**
+ * Adds a title.
+ * @param title
+ */
+ public void addTitle(String title) {
+ setProperty(TITLE, title);
+ }
+
+ /**
+ * Adds a description.
+ * @param desc
+ */
+ public void addDescription(String desc) {
+ setProperty(DESCRIPTION, desc);
+ }
+
+ /**
+ * Adds a subject.
+ * @param subject
+ */
+ public void addSubject(String subject) {
+ XmpArray array = new XmpArray(XmpArray.UNORDERED);
+ array.add(subject);
+ setProperty(SUBJECT, array);
+ }
+
+
+ /**
+ * Adds a subject.
+ * @param subject array of subjects
+ */
+ public void addSubject(String[] subject) {
+ XmpArray array = new XmpArray(XmpArray.UNORDERED);
+ for (int i = 0; i < subject.length; i++) {
+ array.add(subject[i]);
+ }
+ setProperty(SUBJECT, array);
+ }
+
+ /**
+ * Adds a single author.
+ * @param author
+ */
+ public void addAuthor(String author) {
+ XmpArray array = new XmpArray(XmpArray.ORDERED);
+ array.add(author);
+ setProperty(CREATOR, array);
+ }
+
+ /**
+ * Adds an array of authors.
+ * @param author
+ */
+ public void addAuthor(String[] author) {
+ XmpArray array = new XmpArray(XmpArray.ORDERED);
+ for (int i = 0; i < author.length; i++) {
+ array.add(author[i]);
+ }
+ setProperty(CREATOR, array);
+ }
+
+ /**
+ * Adds a single publisher.
+ * @param publisher
+ */
+ public void addPublisher(String publisher) {
+ XmpArray array = new XmpArray(XmpArray.ORDERED);
+ array.add(publisher);
+ setProperty(PUBLISHER, array);
+ }
+
+ /**
+ * Adds an array of publishers.
+ * @param publisher
+ */
+ public void addPublisher(String[] publisher) {
+ XmpArray array = new XmpArray(XmpArray.ORDERED);
+ for (int i = 0; i < publisher.length; i++) {
+ array.add(publisher[i]);
+ }
+ setProperty(PUBLISHER, array);
+ }
+}
diff --git a/src/main/java/com/lowagie/text/xml/xmp/PdfSchema.java b/src/main/java/com/lowagie/text/xml/xmp/PdfSchema.java
new file mode 100644
index 0000000..2793e57
--- /dev/null
+++ b/src/main/java/com/lowagie/text/xml/xmp/PdfSchema.java
@@ -0,0 +1,105 @@
+/*
+ * $Id: PdfSchema.java,v 1.4 2005/09/08 07:50:15 blowagie Exp $
+ * $Name: $
+ *
+ * Copyright 2005 by Bruno Lowagie.
+ *
+ * The contents of this file are subject to the Mozilla Public License Version 1.1
+ * (the "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the License.
+ *
+ * The Original Code is 'iText, a free JAVA-PDF library'.
+ *
+ * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
+ * the Initial Developer are Copyright (C) 1999-2005 by Bruno Lowagie.
+ * All Rights Reserved.
+ * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
+ * are Copyright (C) 2000-2005 by Paulo Soares. All Rights Reserved.
+ *
+ * Contributor(s): all the names of the contributors are added in the source code
+ * where applicable.
+ *
+ * Alternatively, the contents of this file may be used under the terms of the
+ * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
+ * provisions of LGPL are applicable instead of those above. If you wish to
+ * allow use of your version of this file only under the terms of the LGPL
+ * License and not to allow others to use your version of this file under
+ * the MPL, indicate your decision by deleting the provisions above and
+ * replace them with the notice and other provisions required by the LGPL.
+ * If you do not delete the provisions above, a recipient may use your version
+ * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the MPL as stated above or under the terms of the GNU
+ * Library General Public License as published by the Free Software Foundation;
+ * either version 2 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU LIBRARY GENERAL PUBLIC LICENSE for more
+ * details.
+ *
+ * If you didn't download this code from the following link, you should check if
+ * you aren't using an obsolete version:
+ * http://www.lowagie.com/iText/
+ */
+
+package com.lowagie.text.xml.xmp;
+
+import com.lowagie.text.Document;
+import java.io.IOException;
+
+/**
+ * An implementation of an XmpSchema.
+ */
+public class PdfSchema extends XmpSchema {
+
+ /** default namespace identifier*/
+ public static final String DEFAULT_XPATH_ID = "pdf";
+ /** default namespace uri*/
+ public static final String DEFAULT_XPATH_URI = "http://ns.adobe.com/pdf/1.3/";
+
+ /** Keywords. */
+ public static final String KEYWORDS = "pdf:Keywords";
+ /** The PDF file version (for example: 1.0, 1.3, and so on). */
+ public static final String VERSION = "pdf:PDFVersion";
+ /** The Producer. */
+ public static final String PRODUCER = "pdf:Producer";
+
+
+ /**
+ * @throws IOException
+ */
+ public PdfSchema() throws IOException {
+ super("xmlns:" + DEFAULT_XPATH_ID + "=\"" + DEFAULT_XPATH_URI + "\"");
+ addProducer(Document.getVersion());
+ }
+
+ /**
+ * Adds keywords.
+ * @param keywords
+ */
+ public void addKeywords(String keywords) {
+ setProperty(KEYWORDS, keywords);
+ }
+
+ /**
+ * Adds the producer.
+ * @param producer
+ */
+ public void addProducer(String producer) {
+ setProperty(PRODUCER, producer);
+ }
+
+ /**
+ * Adds the version.
+ * @param version
+ */
+ public void addVersion(String version) {
+ setProperty(VERSION, version);
+ }
+}
diff --git a/src/main/java/com/lowagie/text/xml/xmp/XmpArray.java b/src/main/java/com/lowagie/text/xml/xmp/XmpArray.java
new file mode 100644
index 0000000..39016a7
--- /dev/null
+++ b/src/main/java/com/lowagie/text/xml/xmp/XmpArray.java
@@ -0,0 +1,99 @@
+/*
+ * $Id: XmpArray.java,v 1.3 2005/09/08 07:50:15 blowagie Exp $
+ * $Name: $
+ *
+ * Copyright 2005 by Bruno Lowagie.
+ *
+ * The contents of this file are subject to the Mozilla Public License Version 1.1
+ * (the "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the License.
+ *
+ * The Original Code is 'iText, a free JAVA-PDF library'.
+ *
+ * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
+ * the Initial Developer are Copyright (C) 1999-2005 by Bruno Lowagie.
+ * All Rights Reserved.
+ * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
+ * are Copyright (C) 2000-2005 by Paulo Soares. All Rights Reserved.
+ *
+ * Contributor(s): all the names of the contributors are added in the source code
+ * where applicable.
+ *
+ * Alternatively, the contents of this file may be used under the terms of the
+ * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
+ * provisions of LGPL are applicable instead of those above. If you wish to
+ * allow use of your version of this file only under the terms of the LGPL
+ * License and not to allow others to use your version of this file under
+ * the MPL, indicate your decision by deleting the provisions above and
+ * replace them with the notice and other provisions required by the LGPL.
+ * If you do not delete the provisions above, a recipient may use your version
+ * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the MPL as stated above or under the terms of the GNU
+ * Library General Public License as published by the Free Software Foundation;
+ * either version 2 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU LIBRARY GENERAL PUBLIC LICENSE for more
+ * details.
+ *
+ * If you didn't download this code from the following link, you should check if
+ * you aren't using an obsolete version:
+ * http://www.lowagie.com/iText/
+ */
+
+package com.lowagie.text.xml.xmp;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+/**
+ * StringBuffer to construct an XMP array.
+ */
+public class XmpArray extends ArrayList {
+
+ /** An array that is unordered. */
+ public static final String UNORDERED = "rdf:Bag";
+ /** An array that is ordered. */
+ public static final String ORDERED = "rdf:Seq";
+ /** An array with alternatives. */
+ public static final String ALTERNATIVE = "rdf:Alt";
+
+ /** the type of array. */
+ protected String type;
+
+ /**
+ * Creates an XmpArray.
+ * @param type the type of array: UNORDERED, ORDERED or ALTERNATIVE.
+ */
+ public XmpArray(String type) {
+ this.type = type;
+ }
+
+ /**
+ * Returns the String representation of the XmpArray.
+ * @return a String representation
+ */
+ public String toString() {
+ StringBuffer buf = new StringBuffer("<");
+ buf.append(type);
+ buf.append(">");
+ String s;
+ for (Iterator i = iterator(); i.hasNext(); ) {
+ s = (String) i.next();
+ buf.append("<rdf:li>");
+ buf.append(XmpSchema.escape(s));
+ buf.append("</rdf:li>");
+ }
+ buf.append("</");
+ buf.append(type);
+ buf.append(">");
+ return buf.toString();
+ }
+} \ No newline at end of file
diff --git a/src/main/java/com/lowagie/text/xml/xmp/XmpBasicSchema.java b/src/main/java/com/lowagie/text/xml/xmp/XmpBasicSchema.java
new file mode 100644
index 0000000..03e8e54
--- /dev/null
+++ b/src/main/java/com/lowagie/text/xml/xmp/XmpBasicSchema.java
@@ -0,0 +1,141 @@
+/*
+ * $Id: XmpBasicSchema.java,v 1.4 2005/09/08 07:50:15 blowagie Exp $
+ * $Name: $
+ *
+ * Copyright 2005 by Bruno Lowagie.
+ *
+ * The contents of this file are subject to the Mozilla Public License Version 1.1
+ * (the "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the License.
+ *
+ * The Original Code is 'iText, a free JAVA-PDF library'.
+ *
+ * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
+ * the Initial Developer are Copyright (C) 1999-2005 by Bruno Lowagie.
+ * All Rights Reserved.
+ * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
+ * are Copyright (C) 2000-2005 by Paulo Soares. All Rights Reserved.
+ *
+ * Contributor(s): all the names of the contributors are added in the source code
+ * where applicable.
+ *
+ * Alternatively, the contents of this file may be used under the terms of the
+ * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
+ * provisions of LGPL are applicable instead of those above. If you wish to
+ * allow use of your version of this file only under the terms of the LGPL
+ * License and not to allow others to use your version of this file under
+ * the MPL, indicate your decision by deleting the provisions above and
+ * replace them with the notice and other provisions required by the LGPL.
+ * If you do not delete the provisions above, a recipient may use your version
+ * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the MPL as stated above or under the terms of the GNU
+ * Library General Public License as published by the Free Software Foundation;
+ * either version 2 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU LIBRARY GENERAL PUBLIC LICENSE for more
+ * details.
+ *
+ * If you didn't download this code from the following link, you should check if
+ * you aren't using an obsolete version:
+ * http://www.lowagie.com/iText/
+ */
+
+package com.lowagie.text.xml.xmp;
+
+import java.io.IOException;
+
+/**
+ * An implementation of an XmpSchema.
+ */
+public class XmpBasicSchema extends XmpSchema {
+
+ /** default namespace identifier*/
+ public static final String DEFAULT_XPATH_ID = "xmp";
+ /** default namespace uri*/
+ public static final String DEFAULT_XPATH_URI = "http://ns.adobe.com/xap/1.0/";
+
+ /** An unordered array specifying properties that were edited outside the authoring application. Each item should contain a single namespace and XPath separated by one ASCII space (U+0020). */
+ public static final String ADVISORY = "xmp:Advisory";
+ /** The base URL for relative URLs in the document content. If this document contains Internet links, and those links are relative, they are relative to this base URL. This property provides a standard way for embedded relative URLs to be interpreted by tools. Web authoring tools should set the value based on their notion of where URLs will be interpreted. */
+ public static final String BASEURL = "xmp:BaseURL";
+ /** The date and time the resource was originally created. */
+ public static final String CREATEDATE = "xmp:CreateDate";
+ /** The name of the first known tool used to create the resource. If history is present in the metadata, this value should be equivalent to that of xmpMM:History’s softwareAgent property. */
+ public static final String CREATORTOOL = "xmp:CreatorTool";
+ /** An unordered array of text strings that unambiguously identify the resource within a given context. */
+ public static final String IDENTIFIER = "xmp:Identifier";
+ /** The date and time that any metadata for this resource was last changed. */
+ public static final String METADATADATE = "xmp:MetadataDate";
+ /** The date and time the resource was last modified. */
+ public static final String MODIFYDATE = "xmp:ModifyDate";
+ /** A short informal name for the resource. */
+ public static final String NICKNAME = "xmp:Nickname";
+ /** An alternative array of thumbnail images for a file, which can differ in characteristics such as size or image encoding. */
+ public static final String THUMBNAILS = "xmp:Thumbnails";
+
+
+ /**
+ * @throws IOException
+ */
+ public XmpBasicSchema() throws IOException {
+ super("xmlns:" + DEFAULT_XPATH_ID + "=\"" + DEFAULT_XPATH_URI + "\"");
+ }
+
+ /**
+ * Adds the creatortool.
+ * @param creator
+ */
+ public void addCreatorTool(String creator) {
+ setProperty(CREATORTOOL, creator);
+ }
+
+ /**
+ * Adds the creation date.
+ * @param date
+ */
+ public void addCreateDate(String date) {
+ setProperty(CREATEDATE, date);
+ }
+
+ /**
+ * Adds the modification date.
+ * @param date
+ */
+ public void addModDate(String date) {
+ setProperty(MODIFYDATE, date);
+ }
+
+ /**
+ * Adds the meta data date.
+ * @param date
+ */
+ public void addMetaDataDate(String date) {
+ setProperty(METADATADATE, date);
+ }
+
+ /** Adds the identifier.
+ * @param id
+ */
+ public void addIdentifiers(String[] id) {
+ XmpArray array = new XmpArray(XmpArray.UNORDERED);
+ for (int i = 0; i < id.length; i++) {
+ array.add(id[i]);
+ }
+ setProperty(IDENTIFIER, array);
+ }
+
+ /** Adds the nickname.
+ * @param name
+ */
+ public void addNickname(String name) {
+ setProperty(NICKNAME, name);
+ }
+}
diff --git a/src/main/java/com/lowagie/text/xml/xmp/XmpMMSchema.java b/src/main/java/com/lowagie/text/xml/xmp/XmpMMSchema.java
new file mode 100644
index 0000000..f19e7f0
--- /dev/null
+++ b/src/main/java/com/lowagie/text/xml/xmp/XmpMMSchema.java
@@ -0,0 +1,97 @@
+/*
+ * $Id: XmpMMSchema.java,v 1.3 2005/09/08 07:50:15 blowagie Exp $
+ * $Name: $
+ *
+ * Copyright 2005 by Bruno Lowagie.
+ *
+ * The contents of this file are subject to the Mozilla Public License Version 1.1
+ * (the "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the License.
+ *
+ * The Original Code is 'iText, a free JAVA-PDF library'.
+ *
+ * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
+ * the Initial Developer are Copyright (C) 1999-2005 by Bruno Lowagie.
+ * All Rights Reserved.
+ * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
+ * are Copyright (C) 2000-2005 by Paulo Soares. All Rights Reserved.
+ *
+ * Contributor(s): all the names of the contributors are added in the source code
+ * where applicable.
+ *
+ * Alternatively, the contents of this file may be used under the terms of the
+ * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
+ * provisions of LGPL are applicable instead of those above. If you wish to
+ * allow use of your version of this file only under the terms of the LGPL
+ * License and not to allow others to use your version of this file under
+ * the MPL, indicate your decision by deleting the provisions above and
+ * replace them with the notice and other provisions required by the LGPL.
+ * If you do not delete the provisions above, a recipient may use your version
+ * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the MPL as stated above or under the terms of the GNU
+ * Library General Public License as published by the Free Software Foundation;
+ * either version 2 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU LIBRARY GENERAL PUBLIC LICENSE for more
+ * details.
+ *
+ * If you didn't download this code from the following link, you should check if
+ * you aren't using an obsolete version:
+ * http://www.lowagie.com/iText/
+ */
+
+package com.lowagie.text.xml.xmp;
+
+import java.io.IOException;
+
+/**
+ * An implementation of an XmpSchema.
+ */
+public class XmpMMSchema extends XmpSchema {
+
+ /** default namespace identifier*/
+ public static final String DEFAULT_XPATH_ID = "xmpMM";
+ /** default namespace uri*/
+ public static final String DEFAULT_XPATH_URI = "http://ns.adobe.com/xap/1.0/mm/";
+
+
+ /** A reference to the original document from which this one is derived. It is a minimal reference; missing components can be assumed to be unchanged. For example, a new version might only need to specify the instance ID and version number of the previous version, or a rendition might only need to specify the instance ID and rendition class of the original. */
+ public static final String DERIVEDFROM = "xmpMM:DerivedFrom";
+ /** The common identifier for all versions and renditions of a document. */
+ public static final String DOCUMENTID = "xmpMM:DocumentID";
+ /** An ordered array of high-level user actions that resulted in this resource. It is intended to give human readers a general indication of the steps taken to make the changes from the previous version to this one. The list should be at an abstract level; it is not intended to be an exhaustive keystroke or other detailed history. */
+ public static final String HISTORY = "xmpMM:History";
+ /** A reference to the document as it was prior to becoming managed. It is set when a managed document is introduced to an asset management system that does not currently own it. It may or may not include references to different management systems. */
+ public static final String MANAGEDFROM = "xmpMM:ManagedFrom";
+ /** The name of the asset management system that manages this resource. */
+ public static final String MANAGER = "xmpMM:Manager";
+ /** A URI identifying the managed resource to the asset management system; the presence of this property is the formal indication that this resource is managed. The form and content of this URI is private to the asset management system. */
+ public static final String MANAGETO = "xmpMM:ManageTo";
+ /** A URI that can be used to access information about the managed resource through a web browser. It might require a custom browser plugin. */
+ public static final String MANAGEUI = "xmpMM:ManageUI";
+ /** Specifies a particular variant of the asset management system. The format of this property is private to the specific asset management system. */
+ public static final String MANAGERVARIANT = "xmpMM:ManagerVariant";
+ /** The rendition class name for this resource.*/
+ public static final String RENDITIONCLASS = "xmpMM:RenditionClass";
+ /** Can be used to provide additional rendition parameters that are too complex or verbose to encode in xmpMM: RenditionClass. */
+ public static final String RENDITIONPARAMS = "xmpMM:RenditionParams";
+ /** The document version identifier for this resource. */
+ public static final String VERSIONID = "xmpMM:VersionID";
+ /** The version history associated with this resource.*/
+ public static final String VERSIONS = "xmpMM:Versions";
+
+ /**
+ * @throws IOException
+ */
+ public XmpMMSchema() throws IOException {
+ super("xmlns:" + DEFAULT_XPATH_ID + "=\"" + DEFAULT_XPATH_URI + "\"");
+ }
+}
diff --git a/src/main/java/com/lowagie/text/xml/xmp/XmpSchema.java b/src/main/java/com/lowagie/text/xml/xmp/XmpSchema.java
new file mode 100644
index 0000000..1b66cc8
--- /dev/null
+++ b/src/main/java/com/lowagie/text/xml/xmp/XmpSchema.java
@@ -0,0 +1,158 @@
+/*
+ * $Id: XmpSchema.java,v 1.5 2005/09/08 10:27:29 blowagie Exp $
+ * $Name: $
+ *
+ * Copyright 2005 by Bruno Lowagie.
+ *
+ * The contents of this file are subject to the Mozilla Public License Version 1.1
+ * (the "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the License.
+ *
+ * The Original Code is 'iText, a free JAVA-PDF library'.
+ *
+ * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
+ * the Initial Developer are Copyright (C) 1999-2005 by Bruno Lowagie.
+ * All Rights Reserved.
+ * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
+ * are Copyright (C) 2000-2005 by Paulo Soares. All Rights Reserved.
+ *
+ * Contributor(s): all the names of the contributors are added in the source code
+ * where applicable.
+ *
+ * Alternatively, the contents of this file may be used under the terms of the
+ * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
+ * provisions of LGPL are applicable instead of those above. If you wish to
+ * allow use of your version of this file only under the terms of the LGPL
+ * License and not to allow others to use your version of this file under
+ * the MPL, indicate your decision by deleting the provisions above and
+ * replace them with the notice and other provisions required by the LGPL.
+ * If you do not delete the provisions above, a recipient may use your version
+ * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the MPL as stated above or under the terms of the GNU
+ * Library General Public License as published by the Free Software Foundation;
+ * either version 2 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU LIBRARY GENERAL PUBLIC LICENSE for more
+ * details.
+ *
+ * If you didn't download this code from the following link, you should check if
+ * you aren't using an obsolete version:
+ * http://www.lowagie.com/iText/
+ */
+
+package com.lowagie.text.xml.xmp;
+
+import java.util.Enumeration;
+import java.util.Properties;
+
+/**
+ * Abstract superclass of the XmpSchemas supported by iText.
+ */
+public abstract class XmpSchema extends Properties {
+
+ /** the namesspace */
+ protected String xmlns;
+
+ /** Constructs an XMP schema.
+ * @param xmlns
+ */
+ public XmpSchema(String xmlns) {
+ super();
+ this.xmlns = xmlns;
+ }
+ /**
+ * The String representation of the contents.
+ * @return a String representation.
+ */
+ public String toString() {
+ StringBuffer buf = new StringBuffer();
+ for (Enumeration e = this.propertyNames(); e.hasMoreElements(); ) {
+ process(buf, e.nextElement());
+ }
+ return buf.toString();
+ }
+ /**
+ * Processes a property
+ * @param buf
+ * @param p
+ */
+ protected void process(StringBuffer buf, Object p) {
+ buf.append("<");
+ buf.append(p);
+ buf.append(">");
+ buf.append(this.get(p));
+ buf.append("</");
+ buf.append(p);
+ buf.append(">");
+ }
+ /**
+ * @return Returns the xmlns.
+ */
+ public String getXmlns() {
+ return xmlns;
+ }
+
+ /**
+ * @param key
+ * @param value
+ * @return the previous property (null if there wasn't one)
+ */
+ public synchronized Object addProperty(String key, String value) {
+ return this.setProperty(key, value);
+ }
+
+ /**
+ * @see java.util.Properties#setProperty(java.lang.String, java.lang.String)
+ */
+ public synchronized Object setProperty(String key, String value) {
+ return super.setProperty(key, escape(value));
+ }
+
+ /**
+ * @see java.util.Properties#setProperty(java.lang.String, java.lang.String)
+ *
+ * @param key
+ * @param value
+ * @return the previous property (null if there wasn't one)
+ */
+ public synchronized Object setProperty(String key, XmpArray value) {
+ return super.setProperty(key, value.toString());
+ }
+ /**
+ * @param content
+ * @return an escaped string
+ */
+ public static String escape(String content) {
+ StringBuffer buf = new StringBuffer();
+ for (int i = 0; i < content.length(); i++) {
+ switch(content.charAt(i)) {
+ case '<':
+ buf.append("&lt;");
+ break;
+ case '>':
+ buf.append("&gt;");
+ break;
+ case '\'':
+ buf.append("&apos;");
+ break;
+ case '\"':
+ buf.append("&quot;");
+ break;
+ case '&':
+ buf.append("&amp;");
+ break;
+ default:
+ buf.append(content.charAt(i));
+ }
+ }
+ return buf.toString();
+ }
+}
diff --git a/src/main/java/com/lowagie/text/xml/xmp/XmpWriter.java b/src/main/java/com/lowagie/text/xml/xmp/XmpWriter.java
new file mode 100644
index 0000000..8cec5f8
--- /dev/null
+++ b/src/main/java/com/lowagie/text/xml/xmp/XmpWriter.java
@@ -0,0 +1,276 @@
+/*
+ * $Id: XmpWriter.java,v 1.8 2005/11/14 15:21:45 blowagie Exp $
+ * $Name: $
+ *
+ * Copyright 2005 by Bruno Lowagie.
+ *
+ * The contents of this file are subject to the Mozilla Public License Version 1.1
+ * (the "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the License.
+ *
+ * The Original Code is 'iText, a free JAVA-PDF library'.
+ *
+ * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
+ * the Initial Developer are Copyright (C) 1999-2005 by Bruno Lowagie.
+ * All Rights Reserved.
+ * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
+ * are Copyright (C) 2000-2005 by Paulo Soares. All Rights Reserved.
+ *
+ * Contributor(s): all the names of the contributors are added in the source code
+ * where applicable.
+ *
+ * Alternatively, the contents of this file may be used under the terms of the
+ * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
+ * provisions of LGPL are applicable instead of those above. If you wish to
+ * allow use of your version of this file only under the terms of the LGPL
+ * License and not to allow others to use your version of this file under
+ * the MPL, indicate your decision by deleting the provisions above and
+ * replace them with the notice and other provisions required by the LGPL.
+ * If you do not delete the provisions above, a recipient may use your version
+ * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the MPL as stated above or under the terms of the GNU
+ * Library General Public License as published by the Free Software Foundation;
+ * either version 2 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU LIBRARY GENERAL PUBLIC LICENSE for more
+ * details.
+ *
+ * If you didn't download this code from the following link, you should check if
+ * you aren't using an obsolete version:
+ * http://www.lowagie.com/iText/
+ */
+
+package com.lowagie.text.xml.xmp;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.util.Map;
+import java.util.Iterator;
+
+import com.lowagie.text.pdf.PdfDate;
+import com.lowagie.text.pdf.PdfDictionary;
+import com.lowagie.text.pdf.PdfName;
+import com.lowagie.text.pdf.PdfObject;
+import com.lowagie.text.pdf.PdfString;
+
+/**
+ * With this class you can create an Xmp Stream that can be used for adding
+ * Metadata to a PDF Dictionary. Remark that this class doesn't cover the
+ * complete XMP specification.
+ */
+public class XmpWriter {
+
+ /** A possible charset for the XMP. */
+ public static final String UTF8 = "UTF-8";
+ /** A possible charset for the XMP. */
+ public static final String UTF16 = "UTF-16";
+ /** A possible charset for the XMP. */
+ public static final String UTF16BE = "UTF-16BE";
+ /** A possible charset for the XMP. */
+ public static final String UTF16LE = "UTF-16LE";
+
+ /** String used to fill the extra space. */
+ public static final String EXTRASPACE = " \n";
+
+ /** You can add some extra space in the XMP packet; 1 unit in this variable represents 100 spaces and a newline. */
+ protected int extraSpace;
+
+ /** The writer to which you can write bytes for the XMP stream. */
+ protected OutputStreamWriter writer;
+
+ /** The about string that goes into the rdf:Description tags. */
+ protected String about;
+
+ /** The end attribute. */
+ protected char end = 'w';
+
+ /**
+ * Creates an XmpWriter.
+ * @param os
+ * @param utfEncoding
+ * @param extraSpace
+ * @throws IOException
+ */
+ public XmpWriter(OutputStream os, String utfEncoding, int extraSpace) throws IOException {
+ this.extraSpace = extraSpace;
+ writer = new OutputStreamWriter(os, utfEncoding);
+ writer.write("<?xpacket begin='\uFEFF' id='W5M0MpCehiHzreSzNTczkc9d' ?>\n");
+ writer.write("<x:xmpmeta xmlns:x='adobe:ns:meta/'>\n");
+ writer.write("<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>\n");
+ about = "";
+ }
+
+ /**
+ * Creates an XmpWriter.
+ * @param os
+ * @throws IOException
+ */
+ public XmpWriter(OutputStream os) throws IOException {
+ this(os, UTF8, 20);
+ }
+
+ /** Sets the XMP to read-only */
+ public void setReadOnly() {
+ end = 'r';
+ }
+
+ /**
+ * @param about The about to set.
+ */
+ public void setAbout(String about) {
+ this.about = about;
+ }
+
+ /**
+ * Adds an rdf:Description.
+ * @param xmlns
+ * @param content
+ * @throws IOException
+ */
+ public void addRdfDescription(String xmlns, String content) throws IOException {
+ writer.write("<rdf:Description rdf:about='");
+ writer.write(about);
+ writer.write("' ");
+ writer.write(xmlns);
+ writer.write(">");
+ writer.write(content);
+ writer.write("</rdf:Description>\n");
+ }
+
+ /**
+ * Adds an rdf:Description.
+ * @param s
+ * @throws IOException
+ */
+ public void addRdfDescription(XmpSchema s) throws IOException {
+ writer.write("<rdf:Description rdf:about='");
+ writer.write(about);
+ writer.write("' ");
+ writer.write(s.getXmlns());
+ writer.write(">");
+ writer.write(s.toString());
+ writer.write("</rdf:Description>\n");
+ }
+
+ /**
+ * Flushes and closes the XmpWriter.
+ * @throws IOException
+ */
+ public void close() throws IOException {
+ writer.write("</rdf:RDF>");
+ writer.write("</x:xmpmeta>\n");
+ for (int i = 0; i < extraSpace; i++) {
+ writer.write(EXTRASPACE);
+ }
+ writer.write("<?xpacket ends='" + end + "' ?>");
+ writer.flush();
+ writer.close();
+ }
+
+ /**
+ * @param os
+ * @param info
+ * @throws IOException
+ */
+ public XmpWriter(OutputStream os, PdfDictionary info) throws IOException {
+ this(os);
+ if (info != null) {
+ DublinCoreSchema dc = new DublinCoreSchema();
+ PdfSchema p = new PdfSchema();
+ XmpBasicSchema basic = new XmpBasicSchema();
+ PdfName key;
+ PdfObject obj;
+ for (Iterator it = info.getKeys().iterator(); it.hasNext();) {
+ key = (PdfName)it.next();
+ obj = info.get(key);
+ if (obj == null)
+ continue;
+ if (PdfName.TITLE.equals(key)) {
+ dc.addTitle(((PdfString)obj).toUnicodeString());
+ }
+ if (PdfName.AUTHOR.equals(key)) {
+ dc.addAuthor(((PdfString)obj).toUnicodeString());
+ }
+ if (PdfName.SUBJECT.equals(key)) {
+ dc.addSubject(((PdfString)obj).toUnicodeString());
+ }
+ if (PdfName.KEYWORDS.equals(key)) {
+ p.addKeywords(((PdfString)obj).toUnicodeString());
+ }
+ if (PdfName.CREATOR.equals(key)) {
+ basic.addCreatorTool(((PdfString)obj).toUnicodeString());
+ }
+ if (PdfName.PRODUCER.equals(key)) {
+ p.addProducer(((PdfString)obj).toUnicodeString());
+ }
+ if (PdfName.CREATIONDATE.equals(key)) {
+ basic.addCreateDate(((PdfDate)obj).getW3CDate());
+ }
+ if (PdfName.MODDATE.equals(key)) {
+ basic.addModDate(((PdfDate)obj).getW3CDate());
+ }
+ }
+ if (dc.size() > 0) addRdfDescription(dc);
+ if (p.size() > 0) addRdfDescription(p);
+ if (basic.size() > 0) addRdfDescription(basic);
+ }
+ }
+
+ /**
+ * @param os
+ * @param info
+ * @throws IOException
+ */
+ public XmpWriter(OutputStream os, Map info) throws IOException {
+ this(os);
+ if (info != null) {
+ DublinCoreSchema dc = new DublinCoreSchema();
+ PdfSchema p = new PdfSchema();
+ XmpBasicSchema basic = new XmpBasicSchema();
+ String key;
+ String value;
+ for (Iterator it = info.keySet().iterator(); it.hasNext();) {
+ key = (String)it.next();
+ value = (String)info.get(key);
+ if (value == null)
+ continue;
+ if ("Title".equals(key)) {
+ dc.addTitle(value);
+ }
+ if ("Author".equals(key)) {
+ dc.addAuthor(value);
+ }
+ if ("Subject".equals(key)) {
+ dc.addSubject(value);
+ }
+ if ("Keywords".equals(key)) {
+ p.addKeywords(value);
+ }
+ if ("Creator".equals(key)) {
+ basic.addCreatorTool(value);
+ }
+ if ("Producer".equals(key)) {
+ p.addProducer(value);
+ }
+ if ("CreationDate".equals(key)) {
+ basic.addCreateDate(PdfDate.getW3CDate(value));
+ }
+ if ("ModDate".equals(key)) {
+ basic.addModDate(PdfDate.getW3CDate(value));
+ }
+ }
+ if (dc.size() > 0) addRdfDescription(dc);
+ if (p.size() > 0) addRdfDescription(p);
+ if (basic.size() > 0) addRdfDescription(basic);
+ }
+ }
+} \ No newline at end of file