xmlgraphics-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gad...@apache.org
Subject svn commit: r1311929 - in /xmlgraphics/commons/trunk: src/java/org/apache/xmlgraphics/xmp/XMPArray.java src/java/org/apache/xmlgraphics/xmp/XMPHandler.java src/java/org/apache/xmlgraphics/xmp/XMPProperty.java status.xml
Date Tue, 10 Apr 2012 19:00:49 GMT
Author: gadams
Date: Tue Apr 10 19:00:48 2012
New Revision: 1311929

URL: http://svn.apache.org/viewvc?rev=1311929&view=rev
Log:
Bugzilla #50497: Support rdf:resource attributes in XMP.

Modified:
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/XMPArray.java
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/XMPHandler.java
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/XMPProperty.java
    xmlgraphics/commons/trunk/status.xml

Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/XMPArray.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/XMPArray.java?rev=1311929&r1=1311928&r2=1311929&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/XMPArray.java (original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/XMPArray.java Tue Apr 10
19:00:48 2012
@@ -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 @@ public class XMPArray extends XMPComplex
         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);

Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/XMPHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/XMPHandler.java?rev=1311929&r1=1311928&r2=1311929&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/XMPHandler.java (original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/XMPHandler.java Tue Apr
10 19:00:48 2012
@@ -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;
@@ -227,6 +230,17 @@ public class XMPHandler extends DefaultH
                         } else {
                             getCurrentArray(true).add(s);
                         }
+                    } else {
+                        String res = atts.getValue(XMPConstants.RDF_NAMESPACE,
+                                "resource");
+                        if ( res != null ) {
+                            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 +275,18 @@ public class XMPHandler extends DefaultH
                 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");

Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/XMPProperty.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/XMPProperty.java?rev=1311929&r1=1311928&r2=1311929&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/XMPProperty.java (original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/XMPProperty.java Tue Apr
10 19:00:48 2012
@@ -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 @@ public class XMPProperty implements XMLi
     private Object value;
     private String xmllang;
     private Map qualifiers;
+    private boolean uri;
 
     /**
      * Creates a new XMP property.
@@ -47,6 +50,7 @@ public class XMPProperty implements XMLi
     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 class XMPProperty implements XMLi
     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);
         }

Modified: xmlgraphics/commons/trunk/status.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/status.xml?rev=1311929&r1=1311928&r2=1311929&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/status.xml (original)
+++ xmlgraphics/commons/trunk/status.xml Tue Apr 10 19:00:48 2012
@@ -41,6 +41,9 @@
   </contexts>
   <changes>
     <release version="Trunk" date="n/a">
+      <action context="Code" dev="GA" type="fix" fixes-bug="50497" due-to="Brian Carlson">
+        Support rdf:resource attributes in XMP.
+      </action>
       <action context="Code" dev="GA" type="fix" fixes-bug="47174" due-to="Sebastian Bazley">
         Should never use Error to report runtime errors.
       </action>



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: commits-help@xmlgraphics.apache.org


Mime
View raw message