Package: libxmlgraphics-commons-java
Version: 1.4.dfsg-1
Severity: normal
Tags: patch

When converting RDF into XMP, libxmlgraphics-commons-java ignores
rdf:resource attributes and instead leaves the properties completely
empty.  This is problematic because certain common uses of RDF and XMP
(e.g. cc:license attributes) are best used with rdf:resource.  Attached
is a patch which parses and emits rdf:resource attributes normally.
This patch is the same as the patch for 605940.  The only part of the
patch which fixes 605490 is that for line 188 et seq of XMPHandler.java;
the rest are for this bug.

An example of metadata that would normally be handled poorly:

  <rdf:RDF>
        <rdf:Description rdf:about="">
                <cc:license>
                        <rdf:Alt>
                                <rdf:li
                                        
rdf:resource="http://creativecommons.org/licenses/GPL/2.0/"/>
                                <rdf:li
                                        
rdf:resource="http://creativecommons.org/licenses/by-sa/3.0/"/>
                        </rdf:Alt>
                </cc:license>
        </rdf:Description>
  </rdf:RDF>

Without the patch, this would end up as:

  <rdf:RDF>
        <rdf:Description rdf:about="">
                <cc:license>
                        <rdf:Alt/>
                </cc:license>
        </rdf:Description>
  </rdf:RDF>

which is not particularly useful.

-- System Information:
Debian Release: squeeze/sid
  APT prefers unstable
  APT policy: (500, 'unstable'), (1, 'experimental')
Architecture: amd64 (x86_64)

Kernel: Linux 2.6.32-5-amd64 (SMP w/2 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash

Versions of packages libxmlgraphics-commons-java depends on:
ii  default-jre-headless [java2- 1:1.6-40    Standard Java or Java compatible R
ii  gcj-4.4-jre-headless [java2- 4.4.5-9     Java runtime environment using GIJ
ii  gcj-jre-headless [java2-runt 4:4.4.5-1   Java runtime environment using GIJ
ii  openjdk-6-jre-headless [java 6b20~pre1-2 OpenJDK Java runtime, using Hotspo

libxmlgraphics-commons-java recommends no packages.

libxmlgraphics-commons-java suggests no packages.

-- no debconf information

-- 
brian m. carlson / brian with sandals: Houston, Texas, US
+1 832 623 2791 | http://www.crustytoothpaste.net/~bmc | My opinion only
OpenPGP: RSA v4 4096b: 88AC E9B2 9196 305B A994 7552 F1BA 225C 0223 B187
diff -ur xmlgraphics-commons.old/src/java/org/apache/xmlgraphics/xmp/XMPArray.java xmlgraphics-commons.work/src/java/org/apache/xmlgraphics/xmp/XMPArray.java
--- xmlgraphics-commons.old/src/java/org/apache/xmlgraphics/xmp/XMPArray.java	2010-12-04 18:46:09.000000000 +0000
+++ xmlgraphics-commons.work/src/java/org/apache/xmlgraphics/xmp/XMPArray.java	2010-12-04 20:18:25.000000000 +0000
@@ -19,6 +19,8 @@
 
 package org.apache.xmlgraphics.xmp;
 
+import java.net.URI;
+
 import java.util.List;
 
 import org.xml.sax.ContentHandler;
@@ -216,15 +218,19 @@
         for (int i = 0, c = values.size(); i < c; i++) {
             String lang = (String)xmllang.get(i);
             atts.clear();
+            Object v = values.get(i);
             if (lang != null) {
                 atts.addAttribute(XMPConstants.XML_NS, "lang", "xml:lang", "CDATA", lang);
             }
+            if (v instanceof URI) {
+                atts.addAttribute(XMPConstants.RDF_NAMESPACE, "resource",
+                        "rdf:resource", "CDATA", ((URI)v).toString());
+            }
             handler.startElement(XMPConstants.RDF_NAMESPACE,
                     "li", "rdf:li", atts);
-            Object v = values.get(i);
             if (v instanceof XMPComplexValue) {
                 ((XMPComplexValue)v).toSAX(handler);
-            } else {
+            } else if (!(v instanceof URI)) {
                 String value = (String)values.get(i);
                 char[] chars = value.toCharArray();
                 handler.characters(chars, 0, chars.length);
diff -ur xmlgraphics-commons.old/src/java/org/apache/xmlgraphics/xmp/XMPHandler.java xmlgraphics-commons.work/src/java/org/apache/xmlgraphics/xmp/XMPHandler.java
--- xmlgraphics-commons.old/src/java/org/apache/xmlgraphics/xmp/XMPHandler.java	2010-12-04 18:46:09.000000000 +0000
+++ xmlgraphics-commons.work/src/java/org/apache/xmlgraphics/xmp/XMPHandler.java	2010-12-04 20:35:47.000000000 +0000
@@ -19,6 +19,9 @@
 
 package org.apache.xmlgraphics.xmp;
 
+import java.net.URI;
+import java.net.URISyntaxException;
+
 import java.util.Stack;
 
 import org.xml.sax.Attributes;
@@ -188,6 +191,12 @@
                 throw new SAXException("Unexpected element in the RDF namespace: " + localName);
             }
         } else {
+            String about = attributes.getValue(XMPConstants.RDF_NAMESPACE, "about");
+            if (this.contextStack.peek().equals(this.meta) && (about != null)) {
+                //rdf:RDF is the parent, so this is a top-level item that isn't
+                //an rdf:Description, which isn't allowed.
+                throw new SAXException("Top-level element " + qName + " not an rdf:Description");
+            }
             if (getCurrentPropName() != null) {
                 //Structure (shorthand form)
                 startStructure();
@@ -227,6 +236,15 @@
                         } else {
                             getCurrentArray(true).add(s);
                         }
+                    } else {
+                        String res = atts.getValue(XMPConstants.RDF_NAMESPACE,
+                                "resource");
+                        try {
+                            URI resource = new URI(res);
+                            getCurrentArray(true).add(resource);
+                        } catch (URISyntaxException e) {
+                            throw new SAXException("rdf:resource value is not a well-formed URI", e);
+                        }
                     }
                 }
             } else if ("Description".equals(localName)) {
@@ -261,9 +279,18 @@
                 String s = content.toString().trim();
                 prop = new XMPProperty(name, s);
                 String lang = atts.getValue(XMPConstants.XML_NS, "lang");
+                String res = atts.getValue(XMPConstants.RDF_NAMESPACE, "resource");
                 if (lang != null) {
                     prop.setXMLLang(lang);
                 }
+                if (res != null) {
+                    try {
+                        URI resource = new URI(res);
+                        prop.setValue(resource);
+                    } catch (URISyntaxException e) {
+                        throw new SAXException("rdf:resource value is not a well-formed URI", e);
+                    }
+                }
             }
             if (prop.getName() == null) {
                 throw new IllegalStateException("No content in XMP property");
diff -ur xmlgraphics-commons.old/src/java/org/apache/xmlgraphics/xmp/XMPProperty.java xmlgraphics-commons.work/src/java/org/apache/xmlgraphics/xmp/XMPProperty.java
--- xmlgraphics-commons.old/src/java/org/apache/xmlgraphics/xmp/XMPProperty.java	2010-12-04 18:46:09.000000000 +0000
+++ xmlgraphics-commons.work/src/java/org/apache/xmlgraphics/xmp/XMPProperty.java	2010-12-04 20:15:46.000000000 +0000
@@ -19,6 +19,8 @@
 
 package org.apache.xmlgraphics.xmp;
 
+import java.net.URI;
+
 import java.util.Iterator;
 import java.util.Map;
 
@@ -38,6 +40,7 @@
     private Object value;
     private String xmllang;
     private Map qualifiers;
+    private boolean uri;
 
     /**
      * Creates a new XMP property.
@@ -47,6 +50,7 @@
     public XMPProperty(QName name, Object value) {
         this.name = name;
         this.value = value;
+        this.uri = false;
     }
 
     /** @return the qualified name of the property (namespace URI + local name) */
@@ -192,12 +196,15 @@
     public void toSAX(ContentHandler handler) throws SAXException {
         AttributesImpl atts = new AttributesImpl();
         String qName = getEffectiveQName();
+        if (value instanceof URI) {
+            atts.addAttribute(XMPConstants.RDF_NAMESPACE, "resource", "rdf:resource", "CDATA", ((URI)value).toString());
+        }
         handler.startElement(getName().getNamespaceURI(),
                 getName().getLocalName(), qName, atts);
         if (value instanceof XMPComplexValue) {
             XMPComplexValue cv = ((XMPComplexValue)value);
             cv.toSAX(handler);
-        } else {
+        } else if (!(value instanceof URI)) {
             char[] chars = value.toString().toCharArray();
             handler.characters(chars, 0, chars.length);
         }

Attachment: signature.asc
Description: Digital signature

__
This is the maintainer address of Debian's Java team
<http://lists.alioth.debian.org/mailman/listinfo/pkg-java-maintainers>. Please 
use
debian-j...@lists.debian.org for discussions and questions.

Reply via email to