aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremias Maerki <jeremias@apache.org>2006-04-05 14:08:10 +0000
committerJeremias Maerki <jeremias@apache.org>2006-04-05 14:08:10 +0000
commit05ff967d64a3050a5ce08cc435bd91844efcf89d (patch)
tree672292e325d2ad955e83e38989898d0d4f9e374e
parent0aaecd54e21c8413e3b870bea0d9a488f0c05aa9 (diff)
downloadxmlgraphics-fop-05ff967d64a3050a5ce08cc435bd91844efcf89d.tar.gz
xmlgraphics-fop-05ff967d64a3050a5ce08cc435bd91844efcf89d.zip
Reestablishing PDF 1.3 compatibility ("Z" is not available under JDK 1.3).
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@391622 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/java/org/apache/fop/pdf/PDFMetadata.java49
1 files changed, 39 insertions, 10 deletions
diff --git a/src/java/org/apache/fop/pdf/PDFMetadata.java b/src/java/org/apache/fop/pdf/PDFMetadata.java
index 1dad2b5a5..42aaed1b0 100644
--- a/src/java/org/apache/fop/pdf/PDFMetadata.java
+++ b/src/java/org/apache/fop/pdf/PDFMetadata.java
@@ -22,6 +22,7 @@ import java.io.IOException;
import java.io.OutputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
+import java.util.Calendar;
import java.util.Date;
import javax.xml.transform.OutputKeys;
@@ -48,7 +49,7 @@ public class PDFMetadata extends PDFStream {
private static final String XMLNS = "http://www.w3.org/2000/xmlns/";
private static DateFormat pseudoISO8601DateFormat = new SimpleDateFormat(
- "yyyy'-'MM'-'dd'T'HH':'mm':'ssZ");
+ "yyyy'-'MM'-'dd'T'HH':'mm':'ss");
private Document xmpMetadata;
private boolean readOnly = true;
@@ -148,14 +149,42 @@ public class PDFMetadata extends PDFStream {
return sb.toString();
}
- private static String formatDate(Date dt) {
- String s = pseudoISO8601DateFormat.format(dt);
+ /**
+ * Formats a Date using ISO 8601 format in the default time zone.
+ * @param dt the date
+ * @return the formatted date
+ */
+ public static String formatISO8601Date(Date dt) {
+ //ISO 8601 cannot be expressed directly using SimpleDateFormat
+ StringBuffer sb = new StringBuffer(pseudoISO8601DateFormat.format(dt));
+ Calendar cal = Calendar.getInstance();
+ cal.setTime(dt);
+ int offset = cal.get(Calendar.ZONE_OFFSET);
+ offset += cal.get(Calendar.DST_OFFSET);
+ offset /= (1000 * 60); //Convert to minutes
- //Now insert the colon that's not possible using SimpleDateFormat
- int tzpos = s.length() - 4;
- String tz = s.substring(tzpos);
- s = s.substring(0, tzpos) + tz.substring(0, 2) + ":" + tz.substring(2);
- return s;
+ if (offset == 0) {
+ sb.append('Z');
+ } else {
+ int zoh = offset / 60;
+ int zom = Math.abs(offset % 60);
+ if (zoh > 0) {
+ sb.append('+');
+ } else {
+ sb.append('-');
+ }
+ if (zoh < 10) {
+ sb.append('0');
+ }
+ sb.append(zoh);
+ sb.append(':');
+ if (zom < 10) {
+ sb.append('0');
+ }
+ sb.append(zom);
+ }
+
+ return sb.toString();
}
/**
@@ -209,7 +238,7 @@ public class PDFMetadata extends PDFStream {
}
el = doc.createElementNS(XMPConstants.DUBLIN_CORE_NAMESPACE, "dc:date");
desc.appendChild(el);
- el.appendChild(doc.createTextNode(formatDate(info.getCreationDate())));
+ el.appendChild(doc.createTextNode(formatISO8601Date(info.getCreationDate())));
//XMP Basic Schema
desc = doc.createElementNS(XMPConstants.RDF_NAMESPACE, "rdf:Description");
@@ -218,7 +247,7 @@ public class PDFMetadata extends PDFStream {
rdf.appendChild(desc);
el = doc.createElementNS(XMPConstants.XMP_BASIC_NAMESPACE, "xmp:CreateDate");
desc.appendChild(el);
- el.appendChild(doc.createTextNode(formatDate(info.getCreationDate())));
+ el.appendChild(doc.createTextNode(formatISO8601Date(info.getCreationDate())));
if (info.getCreator() != null) {
el = doc.createElementNS(XMPConstants.XMP_BASIC_NAMESPACE, "xmp:CreatorTool");
desc.appendChild(el);