hillion 01/09/27 02:57:13 Modified: sources/org/apache/batik/dom AbstractAttr.java AbstractElement.java sources/org/apache/batik/dom/svg AbstractElement.java LiveAttributeValue.java sources/org/apache/batik/transcoder/svg2svg PrettyPrinter.java Log: - Attr events fixes, - pretty-printer fix. Revision Changes Path 1.4 +15 -3 xml-batik/sources/org/apache/batik/dom/AbstractAttr.java Index: AbstractAttr.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/dom/AbstractAttr.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- AbstractAttr.java 2000/12/28 09:37:17 1.3 +++ AbstractAttr.java 2001/09/27 09:57:13 1.4 @@ -14,11 +14,13 @@ import org.w3c.dom.Element; import org.w3c.dom.Node; +import org.w3c.dom.events.MutationEvent; + /** * This class implements the {@link org.w3c.dom.Attr} interface. * * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a> - * @version $Id: AbstractAttr.java,v 1.3 2000/12/28 09:37:17 hillion Exp $ + * @version $Id: AbstractAttr.java,v 1.4 2001/09/27 09:57:13 hillion Exp $ */ public abstract class AbstractAttr extends AbstractParentNode implements Attr { /** @@ -34,7 +36,7 @@ /** * The owner element. */ - protected transient Element ownerElement; + protected transient AbstractElement ownerElement; /** * Creates a new Attr object. @@ -114,6 +116,8 @@ getNodeName() }); } + String s = getNodeValue(); + // Remove all the children Node n; while ((n = getFirstChild()) != null) { @@ -125,6 +129,14 @@ ? "" : nodeValue); appendChild(n); + + if (ownerElement != null) { + ownerElement.fireDOMAttrModifiedEvent(nodeName, + this, + s, + nodeValue, + MutationEvent.MODIFICATION); + } } /** @@ -168,7 +180,7 @@ /** * Sets the owner element. */ - public void setOwnerElement(Element v) { + public void setOwnerElement(AbstractElement v) { ownerElement = v; } 1.11 +75 -23 xml-batik/sources/org/apache/batik/dom/AbstractElement.java Index: AbstractElement.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/dom/AbstractElement.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- AbstractElement.java 2001/09/12 08:54:33 1.10 +++ AbstractElement.java 2001/09/27 09:57:13 1.11 @@ -29,7 +29,7 @@ * This class implements the {@link org.w3c.dom.Element} interface. * * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a> - * @version $Id: AbstractElement.java,v 1.10 2001/09/12 08:54:33 hillion Exp $ + * @version $Id: AbstractElement.java,v 1.11 2001/09/27 09:57:13 hillion Exp $ */ public abstract class AbstractElement extends AbstractParentChildNode @@ -120,9 +120,14 @@ if (attributes == null) { attributes = createAttributes(); } - Attr attr = getOwnerDocument().createAttribute(name); - attr.setValue(value); - attributes.setNamedItem(attr); + Attr attr = getAttributeNode(name); + if (attr == null) { + attr = getOwnerDocument().createAttribute(name); + attr.setValue(value); + attributes.setNamedItem(attr); + } else { + attr.setValue(value); + } } /** @@ -223,10 +228,21 @@ if (attributes == null) { attributes = createAttributes(); } - Attr attr = getOwnerDocument().createAttributeNS(namespaceURI, - qualifiedName); - attr.setValue(value); - attributes.setNamedItemNS(attr); + Attr attr = getAttributeNodeNS(namespaceURI, qualifiedName); + if (attr == null) { + attr = getOwnerDocument().createAttributeNS(namespaceURI, + qualifiedName); + attr.setValue(value); + attributes.setNamedItemNS(attr); + } else { + String s = attr.getValue(); + attr.setValue(value); + fireDOMAttrModifiedEvent(qualifiedName, + attr, + s, + value, + MutationEvent.MODIFICATION); + } } /** @@ -446,29 +462,61 @@ * <!> WARNING: public accessor because of compilation problems * on Solaris. Do not change. * - * @param name The attribute name. + * @param name The attribute's name. + * @param node The attribute's node. * @param oldv The old value of the attribute. * @param newv The new value of the attribute. + * @param change The modification type. */ - public void fireDOMAttrModifiedEvent(String name, String oldv, - String newv) { + public void fireDOMAttrModifiedEvent(String name, Attr node, String oldv, + String newv, short change) { + switch (change) { + case MutationEvent.ADDITION: + attrAdded(node, newv); + break; + + case MutationEvent.MODIFICATION: + attrModified(node, oldv, newv); + break; + + default: // MutationEvent.REMOVAL: + attrRemoved(node, oldv); + } AbstractDocument doc = getCurrentDocument(); if (doc.getEventsEnabled() && !oldv.equals(newv)) { DocumentEvent de = (DocumentEvent)doc; MutationEvent ev = (MutationEvent)de.createEvent("MutationEvents"); ev.initMutationEvent("DOMAttrModified", - true, // canBubbleArg - false, // cancelableArg - null, // relatedNodeArg - oldv, // prevValueArg - newv, // newValueArg - name, // attrNameArg - ev.MODIFICATION); + true, // canBubbleArg + false, // cancelableArg + node, // relatedNodeArg + oldv, // prevValueArg + newv, // newValueArg + name, // attrNameArg + change); // attrChange dispatchEvent(ev); } } /** + * Called when an attribute has been added. + */ + protected void attrAdded(Attr node, String newv) { + } + + /** + * Called when an attribute has been modified. + */ + protected void attrModified(Attr node, String oldv, String newv) { + } + + /** + * Called when an attribute has been removed. + */ + protected void attrRemoved(Attr node, String oldv) { + } + + /** * An implementation of the {@link org.w3c.dom.NamedNodeMap}. */ public class NamedNodeHashMap implements NamedNodeMap, Serializable { @@ -606,7 +654,8 @@ n.setOwnerElement(null); // Mutation event - fireDOMAttrModifiedEvent(n.getNodeName(), n.getNodeValue(), ""); + fireDOMAttrModifiedEvent(n.getNodeName(), n, n.getNodeValue(), "", + MutationEvent.REMOVAL); return n; } @@ -620,13 +669,16 @@ if (result != null) { result.setOwnerElement(null); fireDOMAttrModifiedEvent(name, + result, result.getNodeValue(), - arg.getNodeValue()); - } else { - fireDOMAttrModifiedEvent(name, "", - arg.getNodeValue()); + MutationEvent.REMOVAL); } + fireDOMAttrModifiedEvent(name, + (Attr)arg, + "", + arg.getNodeValue(), + MutationEvent.ADDITION); return result; } 1.4 +45 -16 xml-batik/sources/org/apache/batik/dom/svg/AbstractElement.java Index: AbstractElement.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/dom/svg/AbstractElement.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- AbstractElement.java 2001/09/13 14:01:11 1.3 +++ AbstractElement.java 2001/09/27 09:57:13 1.4 @@ -26,12 +26,14 @@ import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; +import org.w3c.dom.events.MutationEvent; + /** * This class provides a superclass to implement an SVG element, or * an element interoperable with the SVG elements. * * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a> - * @version $Id: AbstractElement.java,v 1.3 2001/09/13 14:01:11 hillion Exp $ + * @version $Id: AbstractElement.java,v 1.4 2001/09/27 09:57:13 hillion Exp $ */ public abstract class AbstractElement extends org.apache.batik.dom.AbstractElement @@ -209,6 +211,46 @@ } /** + * Called when an attribute has been added. + */ + protected void attrAdded(Attr node, String newv) { + LiveAttributeValue lav = getLiveAttributeValue(node); + if (lav != null) { + lav.attrAdded(node, newv); + } + } + + /** + * Called when an attribute has been modified. + */ + protected void attrModified(Attr node, String oldv, String newv) { + LiveAttributeValue lav = getLiveAttributeValue(node); + if (lav != null) { + lav.attrModified(node, oldv, newv); + } + } + + /** + * Called when an attribute has been removed. + */ + protected void attrRemoved(Attr node, String oldv) { + LiveAttributeValue lav = getLiveAttributeValue(node); + if (lav != null) { + lav.attrRemoved(node, oldv); + } + } + + /** + * Gets Returns the live attribute value associated with given attribute, if any. + */ + private LiveAttributeValue getLiveAttributeValue(Attr node) { + String ns = node.getNamespaceURI(); + return getLiveAttributeValue(ns, (ns == null) + ? node.getNodeName() + : node.getLocalName()); + } + + /** * An implementation of the {@link NamedNodeMap}. */ protected class ExtendedNamedNodeHashMap extends NamedNodeHashMap { @@ -219,20 +261,6 @@ public ExtendedNamedNodeHashMap() { } - /** - * Adds a node to the map. - */ - public Node setNamedItem(String ns, String name, Node arg) throws DOMException { - Attr result = (Attr)super.setNamedItem(ns, name, arg); - - LiveAttributeValue lav = getLiveAttributeValue(ns, name); - if (lav != null) { - lav.valueChanged(result, (Attr)arg); - } - - return result; - } - /** * Adds an unspecified attribute to the map. * @param nsURI The attribute namespace URI. @@ -274,7 +302,8 @@ // Reset the attribute to its default value if (!resetAttribute(namespaceURI, prefix, localName)) { // Mutation event - fireDOMAttrModifiedEvent(n.getNodeName(), n.getNodeValue(), ""); + fireDOMAttrModifiedEvent(n.getNodeName(), n, n.getNodeValue(), "", + MutationEvent.REMOVAL); } return n; } 1.4 +13 -5 xml-batik/sources/org/apache/batik/dom/svg/LiveAttributeValue.java Index: LiveAttributeValue.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/dom/svg/LiveAttributeValue.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- LiveAttributeValue.java 2001/09/13 14:01:11 1.3 +++ LiveAttributeValue.java 2001/09/27 09:57:13 1.4 @@ -15,13 +15,21 @@ * objects that must be updated when the attribute node is modified. * * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a> - * @version $Id: LiveAttributeValue.java,v 1.3 2001/09/13 14:01:11 hillion Exp $ + * @version $Id: LiveAttributeValue.java,v 1.4 2001/09/27 09:57:13 hillion Exp $ */ public interface LiveAttributeValue { /** - * Called when the string representation of the value as been modified. - * @param oldValue The old Attr node. - * @param newValue The new Attr node. + * Called when an Attr node has been added. */ - void valueChanged(Attr oldValue, Attr newValue); + void attrAdded(Attr node, String newv); + + /** + * Called when an Attr node has been modified. + */ + void attrModified(Attr node, String oldv, String newv); + + /** + * Called when an Attr node has been removed. + */ + void attrRemoved(Attr node, String oldv); } 1.4 +5 -6 xml-batik/sources/org/apache/batik/transcoder/svg2svg/PrettyPrinter.java Index: PrettyPrinter.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/transcoder/svg2svg/PrettyPrinter.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- PrettyPrinter.java 2001/02/15 15:57:52 1.3 +++ PrettyPrinter.java 2001/09/27 09:57:13 1.4 @@ -28,7 +28,7 @@ * This class represents an SVG source files pretty-printer. * * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a> - * @version $Id: PrettyPrinter.java,v 1.3 2001/02/15 15:57:52 hillion Exp $ + * @version $Id: PrettyPrinter.java,v 1.4 2001/09/27 09:57:13 hillion Exp $ */ public class PrettyPrinter { @@ -494,12 +494,11 @@ char[] target = scanner.currentValue(); int t = scanner.next(); - if (t != LexicalUnits.S) { - throw fatalError("space", null); + char[] space = {}; + if (t == LexicalUnits.S) { + space = scanner.currentValue(); + t = scanner.next(); } - char[] space = scanner.currentValue(); - t = scanner.next(); - if (t != LexicalUnits.PI_DATA) { throw fatalError("pi.data", null); }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]