[Jsxe-cvs] SF.net SVN: jsxe: [999] branches/jsxe2/src/net/sourceforge/jsxe/dom
Status: Inactive
Brought to you by:
ian_lewis
From: <ian...@us...> - 2006-07-07 20:59:32
|
Revision: 999 Author: ian_lewis Date: 2006-07-07 13:59:23 -0700 (Fri, 07 Jul 2006) ViewCVS: http://svn.sourceforge.net/jsxe/?rev=999&view=rev Log Message: ----------- updated new data model Modified Paths: -------------- branches/jsxe2/src/net/sourceforge/jsxe/dom/AdapterNode.java branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLDocument.java branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLElement.java branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLNode.java Modified: branches/jsxe2/src/net/sourceforge/jsxe/dom/AdapterNode.java =================================================================== --- branches/jsxe2/src/net/sourceforge/jsxe/dom/AdapterNode.java 2006-07-07 04:43:06 UTC (rev 998) +++ branches/jsxe2/src/net/sourceforge/jsxe/dom/AdapterNode.java 2006-07-07 20:59:23 UTC (rev 999) @@ -40,11 +40,18 @@ //}}} //{{{ Java Base Classes -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; +import java.util.ListIterator; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; //}}} //{{{ DOM classes import org.w3c.dom.*; +import org.w3c.dom.events.*; //}}} //}}} @@ -109,6 +116,12 @@ throw new NullPointerException(); } m_domNode = document; + ((EventTarget)m_domNode).addEventListener("DOMSubtreeModified", + new EventListener() { + public void handleEvent(Event evt) { + Log.log(Log.DEBUG, this, evt.toString()); + } + }, true); m_rootDocument = xmlDocument; }//}}} @@ -951,6 +964,8 @@ AdapterNodeListener listener = (AdapterNodeListener)iterator.next(); listener.nodeAdded(source, child); } + + Node doc = getOwnerDocument().getAdapterNode().getNode(); fireStructureChanged(); }//}}} Modified: branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLDocument.java =================================================================== --- branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLDocument.java 2006-07-07 04:43:06 UTC (rev 998) +++ branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLDocument.java 2006-07-07 20:59:23 UTC (rev 999) @@ -1192,6 +1192,8 @@ DocumentBuilder builder = factory.newDocumentBuilder(); + DOMImplementation imp = builder.getDOMImplementation(); + builder.setErrorHandler(null); if (m_entityResolver != null) { Modified: branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLElement.java =================================================================== --- branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLElement.java 2006-07-07 04:43:06 UTC (rev 998) +++ branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLElement.java 2006-07-07 20:59:23 UTC (rev 999) @@ -25,7 +25,8 @@ package net.sourceforge.jsxe.dom; //{{{ Imports -import java.util.HashMap; +import org.w3c.dom.*; +import org.w3c.dom.events.*; //}}} /** @@ -42,49 +43,15 @@ //{{{ XMLElement constructor /** * Creates a new XMLElement - * @param document the document that owns this element - * @param localName the local name of the element. + * @param element the element node that this node wraps. */ - XMLElement(XMLDocument document, String localName) throws XMLException { - super(document); - setLocalName(localName); - m_attributes = new HashMap(); + XMLElement(Element element) { + super(element); }//}}} - //{{{ XMLElement constructor - /** - * Creates a new XMLElement - * @param document the document that owns this element - * @param prefix the namespace prefix for this element - * @param localName the local name of the element. - */ - XMLElement(XMLDocument document, String prefix, String localName) throws XMLException { - super(document); - setNSPrefix(prefix); - setLocalName(localName); - m_attributes = new HashMap(); - }//}}} - - //{{{ getAttributes() - /** - * Returns a HashMap of attribute names to XMLAttribute objects. - */ - public HashMap getAttributes() { - return m_attributes; - }//}}} - //{{{ getNodeType() public int getNodeType() { - return ELEMENT_NODE; + return Node.ELEMENT_NODE; }//}}} - //{{{ setLocalName() - public void setLocalName(String localName) throws XMLException { - //TODO: error checking for invalid name - super.setLocalName(localName); - }//}}} - - //{{{ Private Members - private HashMap m_attributes; - //}}} } Modified: branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLNode.java =================================================================== --- branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLNode.java 2006-07-07 04:43:06 UTC (rev 998) +++ branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLNode.java 2006-07-07 20:59:23 UTC (rev 999) @@ -29,13 +29,12 @@ //{{{ jsXe classes import net.sourceforge.jsxe.jsXe; import net.sourceforge.jsxe.util.Log; -import net.sourceforge.jsxe.util.MiscUtilities; import net.sourceforge.jsxe.dom.completion.*; -import net.sourceforge.jsxe.gui.Messages; //}}} -//{{{ Java Base Classes -import java.util.*; +//{{{ DOM classes +import org.w3c.dom.*; +import org.w3c.dom.events.*; //}}} //}}} @@ -46,6 +45,9 @@ * allows tree modifications only, however these modifications * will correspond to text modifications to the XMLDocument. Direct text * modifications are only allowed at the XMLDocument level.</p> + * + * <p>It implements a subset of the support offered by standard w3c DOM + * interfaces.</p> * * @author Ian Lewis (<a href="mailto:Ian...@me...">Ian...@me...</a>) * @version $Id$ @@ -54,393 +56,47 @@ */ public abstract class XMLNode { - //{{{ Public static properties - /** - * An attribute node. - */ - public static final short ATTRIBUTE_NODE = 1; - /** - * A CDATA Section Node - */ - public static final short CDATA_SECTION_NODE = 2; - /** - * A Comment Node - */ - public static final short COMMENT_NODE = 3; - /** - * A Document Fragment - */ - public static final short DOCUMENT_FRAGMENT_NODE = 4; - /** - * A Document Node - */ - public static final short DOCUMENT_NODE = 5; - /** - * A DOCTYPE node - */ - public static final short DOCUMENT_TYPE_NODE = 6; - /** - * An Element Node - */ - public static final short ELEMENT_NODE = 7; - /** - * An Entity - */ - public static final short ENTITY_NODE = 8; - /** - * An Entity Reference - */ - public static final short ENTITY_REFERENCE_NODE = 9; - /** - * A Notation - */ - public static final short NOTATION_NODE = 10; - /** - * A Processing Instruction - */ - public static final short PROCESSING_INSTRUCTION_NODE = 11; - /** - * A Text Node - */ - public static final short TEXT_NODE = 12; - //}}} + private static final String USER_DATA_KEY = "net.sourceforge.jsxe.dom.XMLNode"; - //{{{ XMLNode constructor - /** - * TODO - * @param document the XMLDocument that owns this node. - */ - XMLNode(XMLDocument document) { - m_properties=new Properties(); - m_rootDocument=document; - }//}}} + //{{{ Private members - //{{{ addXMLNodeListener() /** - * <p>Adds an XMLNodeListener to be notified when this node changes</p> - * @param listener the listener to add + * The w3c Node that this node wraps. It must support the EventTarget + * interface in org.w3c.dom.events */ - public void addXMLNodeListener(XMLNodeListener listener) { - m_listeners.add(listener); - }//}}} + private Node m_domNode; - //{{{ removeXMLNodeListener() - /** - * <p>Removes a listener from this node if it exists</p> - * @param listener the listener to remove - */ - public void removeXMLNodeListener(XMLNodeListener listener) { - m_listeners.remove(m_listeners.indexOf(listener)); - }//}}} + //}}} - //{{{ getNodeType() - /** - * <p>Gets the type of the node.</p> - * @return the node type - */ - public abstract int getNodeType();//}}} - - //{{{ getOwnerDocument() - /** - * Gets the XMLDocument that owns this AdapterNode - * @return The owning XMLDocument - */ - public XMLDocument getOwnerDocument() { - return m_rootDocument; + //{{{ XMLNode constructor + XMLNode(Node node) { + m_domNode = node; }//}}} - //{{{ indexOf() - /** - * <p>Returns the index of the given XMLNode if it is a child.</p> - * @param child the child node of this node - * @return the index where the child is located. -1 if the XMLNode is - * not a child - */ - public int indexOf(AdapterNode child) { - int count = getChildCount(); - for (int i=0; i<count; i++) { - XMLNode n = this.getChildNode(i); - if (child.equals(n)) return i; - } - //Returns here when child not in tree - return -1; + //{{{ addEventListener() + public void addEventListener(java.lang.String type, EventListener listener, boolean useCapture) { + ((EventTarget)m_domNode).addEventListener(type, listener, useCapture); }//}}} - //{{{ getChildCount() - /** - * <p>Gets the number of children that this node has.</p> - * @return the number of children of this node - */ - public int getChildCount() { - return m_children.size(); + //{{{ removeEventListener() + public void removeEventListener(java.lang.String type, EventListener listener, boolean useCapture) { + ((EventTarget)m_domNode).removeEventListener(type, listener, useCapture); }//}}} - //{{{ getChildNode() - /** - * <p>Gets the child node at the given index.</p> - * @param index the index of the requested node - * @return an XMLNode representing the node at the given index, - * null if the index is out of bounds - */ - public XMLNode getChildNode(int index) { - //TODO: create a way to instantiate nodes when they are requested. - return (XMLNode)m_children.get(index); + //{{{ appendNode() + public XMLNode appendChild(XMLNode newChild) { + + m_domNode.appendChild(newChild.getNode()); + + return newChild; }//}}} - //{{{ addChildNode() - /** - * <p>Adds a new child to this node given the node name, value, and type.</p> - * @param name the name of the new child node - * @param value the value of the new child node - * @param type the type of the new child node - * @param index the index where to add the new child node. - * @return the new child that was created - * @throws XMLException INVALID_CHARACTER_ERR: Raised if the specified name - * or value contains an illegal character. - * @throws XMLException NOT_SUPPORTED_ERR: Raised if the node type is not - * supported. - * @throws XMLException HIERARCHY_REQUEST_ERR: Raised if this node is of a - * type that does not allow children of the type of the - * newChild node, or if the node to append is one of this - * node's ancestors or this node itself. - * @throws XMLException NO_MODIFICATION_ALLOWED_ERR: Raised if this node is - * readonly or if the previous parent of the node being - * inserted is readonly. - */ - public XMLNode addChildNode(String name, String value, short type, int index) throws XMLException { - //TODO: error checking - //TODO: update the XMLDocument text - //TODO: create node and add it to m_children. - //TODO: notify listeners that the document has changed. - return null; - }//}}} + //{{{ Protected Members - //{{{ addChildNode() - /** - * Adds an already existing XMLNode to this node as a child. The node - * is added after all child nodes that this node contains. - * @param node the node to be added. - * @return a reference to the node that was added. - * @throws XMLException HIERARCHY_REQUEST_ERR: Raised if this node is of a - * type that does not allow children of the type of the - * newChild node, or if the node to append is one of this - * node's ancestors or this node itself. - * @throws XMLException WRONG_DOCUMENT_ERR: Raised if newChild was created - * from a different document than the one that created - * this node. - * @throws XMLException NO_MODIFICATION_ALLOWED_ERR: Raised if this node is - * readonly or if the previous parent of the node being - * inserted is readonly. - */ - public XMLNode addChildNode(XMLNode node) throws XMLException { - //TODO: error checking - //TODO: updated XMLDocument text - //TODO: update listeners that the doc has changed - return addChildNodeAt(node, getChildCount()); + //{{{ getNode() + protected Node getNode() { + return m_domNode; }//}}} - //{{{ addChildNodeAt() - /** - * Adds an already existing XMLNode to this node at a specified - * location. The index is zero indexed so it can be any number greater - * than or equal to zero and less than or equal to the number of children - * contained currently. Using a location that is one index greater than - * the last child's index <code>(index == getChildCount())</code> then the - * node is added at the end. - * @param node the node to add to this parent node. - * @param index the index to add it at. - * @return the node added. - * @throws XMLException HIERARCHY_REQUEST_ERR: Raised if this node is of a - * type that does not allow children of the type of the - * newChild node, or if the node to append is one of this - * node's ancestors or this node itself. - * @throws XMLException WRONG_DOCUMENT_ERR: Raised if newChild was created - * from a different document than the one that created - * this node. - * @throws XMLException NO_MODIFICATION_ALLOWED_ERR: Raised if this node is - * readonly or if the previous parent of the node being - * inserted is readonly. - */ - public XMLNode addChildNodeAt(XMLNode node, int index) throws XMLException { - //TODO: error checking - //TODO: updated XMLDocument text - //TODO: update listeners that the doc has changed - if (index >= 0 && index < getChildCount()) { - m_children.add(index, node); - } else { - if (index == getChildCount()) { - m_children.add(node); - } else { - throw new XMLException(XMLException.INDEX_SIZE_ERR, Messages.getMessage("Index.Out.Of.Bounds.Error")); - } - } - return node; - }//}}} - - //{{{ remove() - /** - * <p>Removes a child from this node.</p> - * @param child the child node to remove from this node - * @throws XMLException NO_MODIFICATION_ALLOWED_ERR: Raised if this node is - * readonly. - * @throws XMLException NOT_FOUND_ERR: Raised if oldChild is not - * a child of this node. - */ - public void remove(XMLNode child) throws XMLException { - //TODO: error checking - //TODO: updated XMLDocument text - //TODO: update listeners that the doc has changed - m_children.remove(child); - }//}}} - - //{{{ getNodeName() - /** - * Gets the full qualified name for this node including the local name - * and namespace prefix. - * @return the full qualified name of this node - */ - public String getNodeName() { - return getNSPrefix()+":"+getLocalName(); - }//}}} - - //{{{ getLocalName() - /** - * <p>Gets the local name of this node.</p> - * @return the local name of the node - */ - public String getLocalName() { - return m_localName; - }//}}} - - //{{{ setLocalName() - /** - * <p>Sets the local name of the node.</p> - * @param newValue the new local name for this node - * @throws XMLException INVALID_CHARACTER_ERR: Raised if the specified name - * contains an illegal character. - */ - public void setLocalName(String localName) throws XMLException { - //checking for illegal characters etc will be done by subclasses. - //TODO: Notify listeners that the local name has changed - //TODO: Update XMLDocument text with the change. - m_localName = localName; - }//}}} - - //{{{ getNSPrefix() - /** - * Gets the namespace prefix for this node. If this node is not a member - * of a namespace then this method returns null. - * @return the namespace prefix for this node. null if no namespace - */ - public String getNSPrefix() { - return m_namespacePrefix; - }//}}} - - //{{{ setNSPrefix() - /** - * Sets the namespace prefix for this node. To remove this node from a - * namespace this method should be passed null. - * @param prefix The new prefix for this node - * @throws XMLException INVALID_CHARACTER_ERR: Raised if the specified - * prefix contains an illegal character, per the - * XML 1.0 specification . - * @throws XMLException NO_MODIFICATION_ALLOWED_ERR: Raised if this node is - * readonly. - * @throws XMLException NAMESPACE_ERR: Raised if the specified prefix is - * malformed per the Namespaces in XML specification, - * if the namespaceURI of this node is null, if the - * specified prefix is "xml" and the namespaceURI of - * this node is different from - * "http://www.w3.org/XML/1998/namespace", if this node - * is an attribute and the specified prefix is "xmlns" - * and the namespaceURI of this node is different from - * " http://www.w3.org/2000/xmlns/", or if this node is - * an attribute and the qualifiedName of this node is - * "xmlns" . - */ - public void setNSPrefix(String prefix) throws XMLException { - //TODO: Error checking - //TODO: Notify listeners that the namespaces has changed - //TODO: Updated XMLDocument text with the change - m_namespacePrefix = prefix; - }//}}} - - //{{{ getProperty() - /** - * Gets a property for the key given. - * @param key the key to the properties list - * @return the value of the property for the given key. - */ - public String getProperty(String key) { - return m_properties.getProperty(key); - }//}}} - - //{{{ getProperty() - /** - * Gets a property for the key given or returns the default value - * if there is no property for the given key. - * @param key the key to the properties list - * @param defaultValue the default value for the property requested - * @return the value of the property for the given key. - */ - public String getProperty(String key, String defaultValue) { - return m_properties.getProperty(key, defaultValue); - }//}}} - - //{{{ setProperty() - /** - * Sets a property of the AdapterNode - * @param key the key to the property - * @param value the value of the property - * @return the old value of the property - */ - public String setProperty(String key, String value) { - Object oldValue = m_properties.setProperty(key, value); - if (oldValue != null) { - return oldValue.toString(); - } else { - return null; - } - //TODO: notify listeners that the properties have changed? - }//}}} - - //{{{ Private members - /** - * The node type - */ - private int m_nodeType; - /** - * The local name property - */ - private String m_localName; - /** - * The namespace prefix property - */ - private String m_namespacePrefix; - - /** - * The properties of this node. Some may be defined by plugins. - */ - private Properties m_properties; - /** - * The document that owns this node. - */ - private XMLDocument m_rootDocument; - /** - * The offset in the root document where this node starts - */ - private int m_startOffset; - /** - * The offset in the root document where this node ends. - */ - private int m_endOffset; - /** - * A list of listeners to be notified when the document changes. - */ - private ArrayList m_listeners = new ArrayList(); - /** - * A list of child nodes of this node. - */ - private ArrayList m_children = new ArrayList(); //}}} } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |