xmlgraphics-batik-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c..@apache.org
Subject svn commit: r569762 - in /xmlgraphics/batik/trunk/sources/org/apache/batik/dom: AbstractDocument.java AbstractElement.java svg/AbstractElement.java svg/SVGOMDocument.java svg/SVGOMElement.java
Date Sun, 26 Aug 2007 04:30:25 GMT
Author: cam
Date: Sat Aug 25 21:30:19 2007
New Revision: 569762

URL: http://svn.apache.org/viewvc?rev=569762&view=rev
Log:
1. Implement xml:id support, including the special rules for handling
   the SVGElement.id IDL attribute for SVG 1.2 documents.

Modified:
    xmlgraphics/batik/trunk/sources/org/apache/batik/dom/AbstractDocument.java
    xmlgraphics/batik/trunk/sources/org/apache/batik/dom/AbstractElement.java
    xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/AbstractElement.java
    xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGOMDocument.java
    xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGOMElement.java

Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/dom/AbstractDocument.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/dom/AbstractDocument.java?rev=569762&r1=569761&r2=569762&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/dom/AbstractDocument.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/dom/AbstractDocument.java Sat Aug 25
21:30:19 2007
@@ -327,11 +327,15 @@
     }
 
     /**
-     * Imports the given node 'importNode' to this document.
-     * It does so deeply if 'deep' is set to true.
-     * It will not mark id attributes as id's if 'trimId' is set false.
-     * this is used primarily for the clone trees of the 'use' element
-     * so they don't clutter the hashtable.
+     * Imports the given node into this document.
+     * It does so deeply if <code>deep</code> is set to true.
+     * It will not mark ID attributes as IDs if <code>trimId</code> is set to
+     * true.  This is used primarily for the shadow trees of the 'use' elements
+     * so they don't clutter the hash table.
+     *
+     * @param importedNode The node to import into this document.
+     * @param deep Whether to perform a deep importation.
+     * @param trimId Whether to make all cloned attributes not be ID attributes.
      */
     public Node importNode(Node importedNode, boolean deep, boolean trimId) {
         /*

Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/dom/AbstractElement.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/dom/AbstractElement.java?rev=569762&r1=569761&r2=569762&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/dom/AbstractElement.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/dom/AbstractElement.java Sat Aug 25 21:30:19
2007
@@ -386,9 +386,9 @@
             return null;
         }
         int len = nnm.getLength();
-        for ( int i = 0; i < len; i++ ) {
-            AbstractAttr a = (AbstractAttr)nnm.item( i );
-            if ( a.isId() ) {
+        for (int i = 0; i < len; i++) {
+            AbstractAttr a = (AbstractAttr)nnm.item(i);
+            if (a.isId()) {
                 return a;
             }
         }

Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/AbstractElement.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/AbstractElement.java?rev=569762&r1=569761&r2=569762&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/AbstractElement.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/AbstractElement.java Sat Aug
25 21:30:19 2007
@@ -23,6 +23,7 @@
 import org.apache.batik.dom.AbstractDocument;
 import org.apache.batik.dom.events.NodeEventTarget;
 import org.apache.batik.dom.util.DoublyIndexedTable;
+import org.apache.batik.util.SVGConstants;
 
 import org.w3c.dom.Attr;
 import org.w3c.dom.DOMException;
@@ -39,7 +40,7 @@
  */
 public abstract class AbstractElement
         extends org.apache.batik.dom.AbstractElement
-        implements NodeEventTarget, CSSNavigableNode {
+        implements NodeEventTarget, CSSNavigableNode, SVGConstants {
 
     /**
      * The live attribute values.
@@ -111,6 +112,34 @@
 
     // Attributes /////////////////////////////////////////////////////////
 
+    public void fireDOMAttrModifiedEvent(String name, Attr node, String oldv,
+                                         String newv, short change) {
+        super.fireDOMAttrModifiedEvent(name, node, oldv, newv, change);
+        // This handles the SVG 1.2 behaviour where setting the value of
+        // 'id' must also change 'xml:id', and vice versa.
+        if (((SVGOMDocument) ownerDocument).isSVG12
+                && (change == MutationEvent.ADDITION
+                    || change == MutationEvent.MODIFICATION)) {
+            if (node.getNamespaceURI() == null
+                    && node.getNodeName().equals(SVG_ID_ATTRIBUTE)) {
+                Attr a =
+                    getAttributeNodeNS(XML_NAMESPACE_URI, SVG_ID_ATTRIBUTE);
+                if (a == null) {
+                    setAttributeNS(XML_NAMESPACE_URI, SVG_ID_ATTRIBUTE, newv);
+                } else if (!a.getNodeValue().equals(newv)) {
+                    a.setNodeValue(newv);
+                }
+            } else if (node.getNodeName().equals(XML_ID_QNAME)) {
+                Attr a = getAttributeNodeNS(null, SVG_ID_ATTRIBUTE);
+                if (a == null) {
+                    setAttributeNS(null, SVG_ID_ATTRIBUTE, newv);
+                } else if (!a.getNodeValue().equals(newv)) {
+                    a.setNodeValue(newv);
+                }
+            }
+        }
+    }
+
     /**
      * Returns the live attribute value associated with given
      * attribute, if any.
@@ -316,5 +345,4 @@
             return n;
         }
     }
-
 }

Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGOMDocument.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGOMDocument.java?rev=569762&r1=569761&r2=569762&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGOMDocument.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGOMDocument.java Sat Aug 25
21:30:19 2007
@@ -369,8 +369,10 @@
      * for this document.
      */
     public boolean isId(Attr node) {
-        if (node.getNamespaceURI() != null) return false;
-        return SVG_ID_ATTRIBUTE.equals(node.getNodeName());
+        if (node.getNamespaceURI() == null) {
+            return SVG_ID_ATTRIBUTE.equals(node.getNodeName());
+        }
+        return node.getNodeName().equals(XML_ID_QNAME);
     }
 
     // CSSNavigableDocument ///////////////////////////////////////////

Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGOMElement.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGOMElement.java?rev=569762&r1=569761&r2=569762&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGOMElement.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/SVGOMElement.java Sat Aug 25
21:30:19 2007
@@ -60,7 +60,6 @@
 public abstract class SVGOMElement
     extends    AbstractElement
     implements SVGElement,
-               SVGConstants,
                ExtendedTraitAccess,
                AnimationTarget {
 
@@ -145,18 +144,27 @@
      * <b>DOM</b>: Implements {@link SVGElement#getId()}.
      */
     public String getId() {
-        return super.getId();
+        if (((SVGOMDocument) ownerDocument).isSVG12) {
+            Attr a = getAttributeNodeNS(XML_NAMESPACE_URI, SVG_ID_ATTRIBUTE);
+            if (a != null) {
+                return a.getNodeValue();
+            }
+        }
+        return getAttributeNS(null, SVG_ID_ATTRIBUTE);
     }
 
     /**
      * <b>DOM</b>: Implements {@link SVGElement#setId(String)}.
      */
     public void setId(String id) {
-        Attr a = getIdAttribute();
-        if (a == null) {
-            setAttributeNS(null, "id", id);
+        if (((SVGOMDocument) ownerDocument).isSVG12) {
+            setAttributeNS(XML_NAMESPACE_URI, SVG_ID_ATTRIBUTE, id);
+            Attr a = getAttributeNodeNS(null, SVG_ID_ATTRIBUTE);
+            if (a != null) {
+                a.setNodeValue(id);
+            }
         } else {
-            a.setNodeValue(id);
+            setAttributeNS(null, SVG_ID_ATTRIBUTE, id);
         }
     }
 



Mime
View raw message