ek1975 wrote:
> I didn't request that you fix anything for me.

It sounded that way. And in the meanwhile, here's the patch:

Log Message:
-----------
Updating the XMP stream assumed that there were three child nodes: an 
xpacket start PI, an xmpmeta tag, and an xpacket end PI. However: 
somebody posted an example that didn't have the xpacket PIs. This 
changes makes sure the PIs are added.

Modified Paths:
--------------
     trunk/src/core/com/lowagie/text/xml/xmp/XmpReader.java
     trunk/src/core/com/lowagie/text/xml/xmp/XmpWriter.java

Modified: trunk/src/core/com/lowagie/text/xml/xmp/XmpReader.java
===================================================================
--- trunk/src/core/com/lowagie/text/xml/xmp/XmpReader.java      2009-06-03 
15:17:22 UTC (rev 3948)
+++ trunk/src/core/com/lowagie/text/xml/xmp/XmpReader.java      2009-06-03 
15:19:04 UTC (rev 3949)
@@ -168,15 +168,15 @@
                XmlDomWriter xw = new XmlDomWriter();
          ByteArrayOutputStream fout = new ByteArrayOutputStream();
          xw.setOutput(fout, null);
-        Node first = domDocument.getFirstChild();
-        xw.write(first);
-        fout.write('\n');
-        xw.write(first.getNextSibling());
+        NodeList xmpmeta = domDocument.getElementsByTagName("x:xmpmeta");
+        fout.write(XmpWriter.XPACKET_PI_BEGIN.getBytes("UTF-8"));
          fout.flush();
+        xw.write(xmpmeta.item(0));
+        fout.flush();
                for (int i = 0; i < 20; i++) {
                        fout.write(XmpWriter.EXTRASPACE.getBytes());
                }
-        xw.write(domDocument.getLastChild());
+        fout.write(XmpWriter.XPACKET_PI_END_W.getBytes());
          fout.close();
          return fout.toByteArray();
        }

Modified: trunk/src/core/com/lowagie/text/xml/xmp/XmpWriter.java
===================================================================
--- trunk/src/core/com/lowagie/text/xml/xmp/XmpWriter.java      2009-06-03 
15:17:22 UTC (rev 3948)
+++ trunk/src/core/com/lowagie/text/xml/xmp/XmpWriter.java      2009-06-03 
15:19:04 UTC (rev 3949)
@@ -89,7 +89,25 @@
        
        /** The about string that goes into the rdf:Description tags. */
        protected String about;
+
+       /**
+        * Processing Instruction required at the start of an XMP stream
+        * @since iText 2.1.6
+        */
+       public static final String XPACKET_PI_BEGIN = "<?xpacket 
begin=\"\uFEFF\" id=\"W5M0MpCehiHzreSzNTczkc9d\"?>\n";
        
+       /**
+        * Processing Instruction required at the end of an XMP stream for XMP 
streams that can be updated
+        * @since iText 2.1.6
+        */
+       public static final String XPACKET_PI_END_W = "<?xpacket end=\"w\"?>";
+       
+       /**
+        * Processing Instruction required at the end of an XMP stream for XMP 
streams that are read only
+        * @since iText 2.1.6
+        */
+       public static final String XPACKET_PI_END_R = "<?xpacket end=\"r\"?>";
+       
        /** The end attribute. */
        protected char end = 'w';
        
@@ -103,7 +121,7 @@
        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(XPACKET_PI_BEGIN);
                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 = "";
@@ -171,7 +189,7 @@
                for (int i = 0; i < extraSpace; i++) {
                        writer.write(EXTRASPACE);
                }
-               writer.write("<?xpacket end=\"" + end + "\"?>");
+               writer.write(end == 'r' ? XPACKET_PI_END_R : XPACKET_PI_END_W);
                writer.flush();
                writer.close();
        }
-- 
This answer is provided by 1T3XT BVBA
http://www.1t3xt.com/ - http://www.1t3xt.info

------------------------------------------------------------------------------
OpenSolaris 2009.06 is a cutting edge operating system for enterprises 
looking to deploy the next generation of Solaris that includes the latest 
innovations from Sun and the OpenSource community. Download a copy and 
enjoy capabilities such as Networking, Storage and Virtualization. 
Go to: http://p.sf.net/sfu/opensolaris-get
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php
Check the site with examples before you ask questions: 
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/

Reply via email to