Thread: [Jsxe-cvs] SF.net SVN: jsxe: [894] branches/jsxe2/src/net/sourceforge/jsxe/dom
Status: Inactive
Brought to you by:
ian_lewis
From: <ian...@us...> - 2006-06-02 03:32:50
|
Revision: 894 Author: ian_lewis Date: 2006-06-01 20:32:42 -0700 (Thu, 01 Jun 2006) ViewCVS: http://svn.sourceforge.net/jsxe/?rev=894&view=rev Log Message: ----------- added new event classes to drive the event model Added Paths: ----------- branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLDocumentEvent.java branches/jsxe2/src/net/sourceforge/jsxe/dom/event/ branches/jsxe2/src/net/sourceforge/jsxe/dom/event/XMLDocumentInsertEvent.java branches/jsxe2/src/net/sourceforge/jsxe/dom/event/XMLDocumentRemoveEvent.java Added: branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLDocumentEvent.java =================================================================== --- branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLDocumentEvent.java (rev 0) +++ branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLDocumentEvent.java 2006-06-02 03:32:42 UTC (rev 894) @@ -0,0 +1,92 @@ +/* +XMLDocumentEvent.java +:tabSize=4:indentSize=4:noTabs=true: +:folding=explicit:collapseFolds=1: + +Copyright (C) 2006 Ian Lewis (Ian...@me...) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +Optionally, you may find a copy of the GNU General Public License +from http://www.fsf.org/copyleft/gpl.txt +*/ + + +package net.sourceforge.jsxe.dom; + +/** + * An XMLDocumentEvent represents a change to an XMLDocument. It can occur + * whenever any change is made to the document whether through normal text + * insertion or removal, or by changing values or structure which maps to text + * within the XMLDocument. All types of events occurring on an XMLDocument will + * extend this class. + * + * @author Ian Lewis (<a href="mailto:Ian...@me...">Ian...@me...</a>) + * @version $Id$ + * @see XMLDocument + * @since jsXe 0.5 pre1 + */ +public abstract class XMLDocumentEvent { + + //{{{ XMLDocumentEvent constructor + /** + * Creates a new event signifying text being updated in the document + * @param source the source document + * @param offset the offset into the document where the insert occurred + * @param text the text that was updated in the modification. + */ + public XMLDocumentEvent(XMLDocument source, int offset, String text) { + m_document = source; + m_offset = offset; + m_text = text; + }//}}} + + //{{{ getXMLDocument() + /** + * Gets the document that is the source of this change event. + */ + public XMLDocument getXMLDocument() { + return m_document; + }//}}} + + //{{{ getLength() + /** + * Gets the length of the change to the document + */ + public int getLength() { + return m_text.length(); + }//}}} + + //{{{ getOffset() + /** + * Gets the offset into the document where the change occurred + */ + public int getOffset() { + return m_offset; + }//}}} + + //{{{ getText() + /** + * Gets the text associated with this event. + */ + public String getText() { + return m_text; + }//}}} + + //{{{ Private Members + private XMLDocument m_document; + private String m_text; + private int m_offset; + //}}} +} Property changes on: branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLDocumentEvent.java ___________________________________________________________________ Name: svn:executable + * Added: branches/jsxe2/src/net/sourceforge/jsxe/dom/event/XMLDocumentInsertEvent.java =================================================================== --- branches/jsxe2/src/net/sourceforge/jsxe/dom/event/XMLDocumentInsertEvent.java (rev 0) +++ branches/jsxe2/src/net/sourceforge/jsxe/dom/event/XMLDocumentInsertEvent.java 2006-06-02 03:32:42 UTC (rev 894) @@ -0,0 +1,50 @@ +/* +XMLDocumentInsertEvent.java +:tabSize=4:indentSize=4:noTabs=true: +:folding=explicit:collapseFolds=1: + +Copyright (C) 2006 Ian Lewis (Ian...@me...) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +Optionally, you may find a copy of the GNU General Public License +from http://www.fsf.org/copyleft/gpl.txt +*/ + +package net.sourceforge.jsxe.dom.event; + +import net.sourceforge.jsxe.dom.*; + +/** + * XMLDocumentInsertEvent signifies an event where text being inserted into the + * document. + * @author Ian Lewis (<a href="mailto:Ian...@me...">Ian...@me...</a>) + * @version $Id$ + * @see XMLDocument + * @since jsXe 0.5 pre1 + */ +public class XMLDocumentInsertEvent extends XMLDocumentEvent { + + //{{{ XMLDocumentInsertEvent constructor + /** + * Creates a new event signifying text being inserted into the document + * @param source the source document + * @param offset the offset into the document where the insert occurred + * @param text the text that was updated in the modification. + */ + public XMLDocumentInsertEvent(XMLDocument source, int offset, String text) { + super(source, offset, text); + }//}}} + +} Property changes on: branches/jsxe2/src/net/sourceforge/jsxe/dom/event/XMLDocumentInsertEvent.java ___________________________________________________________________ Name: svn:executable + * Added: branches/jsxe2/src/net/sourceforge/jsxe/dom/event/XMLDocumentRemoveEvent.java =================================================================== --- branches/jsxe2/src/net/sourceforge/jsxe/dom/event/XMLDocumentRemoveEvent.java (rev 0) +++ branches/jsxe2/src/net/sourceforge/jsxe/dom/event/XMLDocumentRemoveEvent.java 2006-06-02 03:32:42 UTC (rev 894) @@ -0,0 +1,50 @@ +/* +XMLDocumentRemoveEvent.java +:tabSize=4:indentSize=4:noTabs=true: +:folding=explicit:collapseFolds=1: + +Copyright (C) 2006 Ian Lewis (Ian...@me...) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +Optionally, you may find a copy of the GNU General Public License +from http://www.fsf.org/copyleft/gpl.txt +*/ + +package net.sourceforge.jsxe.dom.event; + +import net.sourceforge.jsxe.dom.*; + +/** + * XMLDocumentRemoveEvent signifies an event where text being removed from the + * document. + * @author Ian Lewis (<a href="mailto:Ian...@me...">Ian...@me...</a>) + * @version $Id$ + * @see XMLDocument + * @since jsXe 0.5 pre1 + */ +public class XMLDocumentRemoveEvent extends XMLDocumentEvent { + + //{{{ XMLDocumentRemoveEvent constructor + /** + * Creates a new event signifying text being inserted into the document + * @param source the source document + * @param offset the offset into the document where the removal occurred + * @param text the text that was removed from the document. + */ + public XMLDocumentRemoveEvent(XMLDocument source, int offset, String text) { + super(source, offset, text); + }//}}} + +} Property changes on: branches/jsxe2/src/net/sourceforge/jsxe/dom/event/XMLDocumentRemoveEvent.java ___________________________________________________________________ Name: svn:executable + * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ian...@us...> - 2006-07-06 16:51:46
|
Revision: 988 Author: ian_lewis Date: 2006-07-06 09:51:38 -0700 (Thu, 06 Jul 2006) ViewCVS: http://svn.sourceforge.net/jsxe/?rev=988&view=rev Log Message: ----------- XMLElement will now compile; AdapterNode is not deprecated to avoid so many warnings Modified Paths: -------------- branches/jsxe2/src/net/sourceforge/jsxe/dom/AdapterNode.java branches/jsxe2/src/net/sourceforge/jsxe/dom/AdapterNodeListener.java branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLDocument.java branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLDocumentEvent.java branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLElement.java branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLException.java branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLNode.java branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLNodeListener.java Modified: branches/jsxe2/src/net/sourceforge/jsxe/dom/AdapterNode.java =================================================================== --- branches/jsxe2/src/net/sourceforge/jsxe/dom/AdapterNode.java 2006-07-05 18:50:43 UTC (rev 987) +++ branches/jsxe2/src/net/sourceforge/jsxe/dom/AdapterNode.java 2006-07-06 16:51:38 UTC (rev 988) @@ -62,7 +62,6 @@ * @version $Id$ * @see XMLDocument * @see XMLDocument#addAdapterNode(AdapterNode, String, String, short) - * @deprecated */ public class AdapterNode { Modified: branches/jsxe2/src/net/sourceforge/jsxe/dom/AdapterNodeListener.java =================================================================== --- branches/jsxe2/src/net/sourceforge/jsxe/dom/AdapterNodeListener.java 2006-07-05 18:50:43 UTC (rev 987) +++ branches/jsxe2/src/net/sourceforge/jsxe/dom/AdapterNodeListener.java 2006-07-06 16:51:38 UTC (rev 988) @@ -46,9 +46,6 @@ //}}} -/** - * @deprecated - */ public interface AdapterNodeListener { //{{{ nodeAdded() Modified: branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLDocument.java =================================================================== --- branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLDocument.java 2006-07-05 18:50:43 UTC (rev 987) +++ branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLDocument.java 2006-07-06 16:51:38 UTC (rev 988) @@ -999,7 +999,7 @@ * in the event that specs that will alter how the document is serialized or * parsed are changed. * @param location the location of the change. null if unknown - * @deprecated structureCHange + * @deprecated use fireInsert() or fireRemove() instead. */ protected void fireStructureChanged(AdapterNode location) { ListIterator iterator = listeners.listIterator(); Modified: branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLDocumentEvent.java =================================================================== --- branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLDocumentEvent.java 2006-07-05 18:50:43 UTC (rev 987) +++ branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLDocumentEvent.java 2006-07-06 16:51:38 UTC (rev 988) @@ -35,7 +35,7 @@ * @author Ian Lewis (<a href="mailto:Ian...@me...">Ian...@me...</a>) * @version $Id$ * @see XMLDocument - * @since jsXe 0.5 pre1 + * @since jsXe 0.5 pre2 */ public abstract class XMLDocumentEvent { Modified: branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLElement.java =================================================================== --- branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLElement.java 2006-07-05 18:50:43 UTC (rev 987) +++ branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLElement.java 2006-07-06 16:51:38 UTC (rev 988) @@ -35,7 +35,7 @@ * @author Ian Lewis (<a href="mailto:Ian...@me...">Ian...@me...</a>) * @version $Id$ * @see XMLDocument - * @since jsXe 0.5 pre1 + * @since jsXe 0.5 pre2 */ public class XMLElement extends XMLNode { @@ -43,11 +43,28 @@ /** * Creates a new XMLElement * @param document the document that owns this element + * @param localName the local name of the element. */ - XMLElement(XMLDocument document) { + XMLElement(XMLDocument document, String localName) throws XMLException { + super(document); + setLocalName(localName); m_attributes = new HashMap(); }//}}} + //{{{ 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. @@ -56,6 +73,17 @@ return m_attributes; }//}}} + //{{{ getNodeType() + public int getNodeType() { + return 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/XMLException.java =================================================================== --- branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLException.java 2006-07-05 18:50:43 UTC (rev 987) +++ branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLException.java 2006-07-06 16:51:38 UTC (rev 988) @@ -35,7 +35,7 @@ * @version $Id$ * @see XMLDocument * @see XMLNode - * @since jsXe 0.5 pre1 + * @since jsXe 0.5 pre2 */ public class XMLException extends RuntimeException { Modified: branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLNode.java =================================================================== --- branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLNode.java 2006-07-05 18:50:43 UTC (rev 987) +++ branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLNode.java 2006-07-06 16:51:38 UTC (rev 988) @@ -50,7 +50,7 @@ * @author Ian Lewis (<a href="mailto:Ian...@me...">Ian...@me...</a>) * @version $Id$ * @see XMLDocument - * @since jsXe 0.5 pre1 + * @since jsXe 0.5 pre2 */ public abstract class XMLNode { Modified: branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLNodeListener.java =================================================================== --- branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLNodeListener.java 2006-07-05 18:50:43 UTC (rev 987) +++ branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLNodeListener.java 2006-07-06 16:51:38 UTC (rev 988) @@ -31,7 +31,7 @@ * * @author Ian Lewis (<a href="mailto:Ian...@me...">Ian...@me...</a>) * @version $Id$ - * @since jsXe 0.5 pre1 + * @since jsXe 0.5 pre2 * @see XMLDocument */ public interface XMLNodeListener { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ian...@us...> - 2006-09-06 19:27:02
|
Revision: 1239 http://svn.sourceforge.net/jsxe/?rev=1239&view=rev Author: ian_lewis Date: 2006-09-06 12:26:53 -0700 (Wed, 06 Sep 2006) Log Message: ----------- Moved serialization classes to net.sourceforge.jsxe.dom.ls Added Paths: ----------- branches/jsxe2/src/net/sourceforge/jsxe/dom/ls/DOMSerializer.java branches/jsxe2/src/net/sourceforge/jsxe/dom/ls/DOMSerializerConfiguration.java branches/jsxe2/src/net/sourceforge/jsxe/dom/ls/DOMSerializerException.java Removed Paths: ------------- branches/jsxe2/src/net/sourceforge/jsxe/dom/DOMSerializer.java branches/jsxe2/src/net/sourceforge/jsxe/dom/DOMSerializerConfiguration.java branches/jsxe2/src/net/sourceforge/jsxe/dom/DOMSerializerException.java Deleted: branches/jsxe2/src/net/sourceforge/jsxe/dom/DOMSerializer.java =================================================================== --- branches/jsxe2/src/net/sourceforge/jsxe/dom/DOMSerializer.java 2006-09-06 19:20:54 UTC (rev 1238) +++ branches/jsxe2/src/net/sourceforge/jsxe/dom/DOMSerializer.java 2006-09-06 19:26:53 UTC (rev 1239) @@ -1,825 +0,0 @@ -/* -DOMSerializer.java -:tabSize=4:indentSize=4:noTabs=true: -:folding=explicit:collapseFolds=1: - -This attempts to conform to the DOM3 implementation in Xerces. It tries to -conform to DOM3 as of Xerces 2.6.0. I'm not one to stay on the bleeding edge -but it is as close to a standard interface for load & save as you can get -and I didn't want to work around the fact that current serializers aren't -very good. - -Copyright (C) 2002 Ian Lewis (Ian...@me...) - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -Optionally, you may find a copy of the GNU General Public License -from http://www.fsf.org/copyleft/gpl.txt -*/ - -package net.sourceforge.jsxe.dom; - -//{{{ imports -/* -All classes are listed explicitly so -it is easy to see which package it -belongs to. -*/ - -//{{{ DOM classes -import org.w3c.dom.Attr; -import org.w3c.dom.Document; -import org.w3c.dom.DocumentType; -import org.w3c.dom.DOMException; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.w3c.dom.Notation; -import org.w3c.dom.ls.LSSerializer; -import org.w3c.dom.ls.LSSerializerFilter; -import org.w3c.dom.ls.LSOutput; -import org.w3c.dom.DOMConfiguration; -import org.w3c.dom.DOMLocator; -import org.w3c.dom.DOMError; -import org.w3c.dom.DOMErrorHandler; -//}}} - -//{{{ Java base classes -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.StringWriter; -import java.io.UnsupportedEncodingException; -import java.io.Writer; -import java.net.URL; -import java.net.URLConnection; -import java.net.MalformedURLException; -import java.util.ArrayList; -import java.util.Hashtable; -import java.util.Vector; -//}}} - -//}}} - -/** - * An implementation of the DOM3 LSSerializer interface. This class supports - * everything that is supported by the DOMSerializerConfiguration class. Clients - * can check if a feature is supported by calling canSetParameter() on the - * appropriate DOMSerializerConfiguration object. - * - * @author <a href="mailto:IanLewis at member dot fsf dot org">Ian Lewis</a> - * @version $Id$ - */ -public class DOMSerializer implements LSSerializer { - - //{{{ DOMSerializer constructor - /** - * Creates a default DOMSerializer using the default options. - */ - public DOMSerializer() { - config = new DOMSerializerConfiguration(); - m_newLine = System.getProperty("line.separator"); - }//}}} - - //{{{ DOMSerializer constructor - /** - * Creates a DOMSerializer that uses the configuration specified. - * @param config The configuration to be used by this DOMSerializer object - */ - public DOMSerializer(DOMSerializerConfiguration config) { - this.config = config; - m_newLine = System.getProperty("line.separator"); - }//}}} - - //{{{ Implemented LSSerializer methods - - //{{{ getConfig() - - public DOMConfiguration getDomConfig() { - return config; - }//}}} - - //{{{ getFilter() - - public LSSerializerFilter getFilter() { - return m_filter; - }//}}} - - //{{{ getNewLine() - - public String getNewLine() { - return m_newLine; - }//}}} - - //{{{ setFilter() - - public void setFilter(LSSerializerFilter filter) { - m_filter=filter; - }//}}} - - //{{{ setNewLine() - - public void setNewLine(String newLine) { - m_newLine=newLine; - }//}}} - - //{{{ write() - - public boolean write(Node nodeArg, LSOutput destination) { - if (m_filter == null || m_filter.acceptNode(nodeArg) == 1) { - - //{{{ try to get the Writer object for our destination - Writer writer = destination.getCharacterStream(); - String encoding = null; - - if (writer == null) { - //no character stream specified, try the byte stream. - OutputStream out = destination.getByteStream(); - if (out != null) { - - try { - writer = new OutputStreamWriter(out, destination.getEncoding()); - encoding = destination.getEncoding(); - } catch (UnsupportedEncodingException uee) { - DefaultDOMLocator loc = new DefaultDOMLocator(nodeArg, 1, 1, 0, null); - try { - throwError(loc, "unsupported-encoding", DOMError.SEVERITY_FATAL_ERROR, uee); - } catch (DOMSerializerException e) {/*we know this will happen*/} - //This is a fatal error, quit. - return false; - } - } else { - //no char stream or byte stream, try the uri - String id = destination.getSystemId(); - if (id != null) { - - try { - //We use URL since outputing to any other type of URI - //is not possible. - URL uri = new URL(id); - URLConnection con = uri.openConnection(); - - try { - //We want to try to output to the URI - con.setDoOutput(true); - //I don't see a problem with using caches - //do you? - con.setUseCaches(true); - } catch (IllegalStateException ise) { - //we are guaranteed to not be connected - } - - con.connect(); - - writer = new OutputStreamWriter(con.getOutputStream(), destination.getEncoding()); - - } catch (MalformedURLException mue) { - DefaultDOMLocator loc = new DefaultDOMLocator(nodeArg, 1, 1, 0, null); - try { - throwError(loc, "bad-uri", DOMError.SEVERITY_FATAL_ERROR, mue); - } catch (DOMSerializerException e) {/*we know this will happen*/} - //this is a fatal error - return false; - } catch (IOException ioe) { - DefaultDOMLocator loc = new DefaultDOMLocator(nodeArg, 1, 1, 0, null); - try { - throwError(loc, "io-error", DOMError.SEVERITY_FATAL_ERROR, ioe); - } catch (DOMSerializerException e) {/*we know this will happen*/} - //this is a fatal error - return false; - } - - } else { - DefaultDOMLocator loc = new DefaultDOMLocator(nodeArg, 1, 1, 0, null); - try { - throwError(loc, "no-output-specified", DOMError.SEVERITY_FATAL_ERROR, null); - } catch (DOMSerializerException e) {/*we know this will happen*/} - //this is a fatal error - return false; - } - } - }//}}} - - BufferedWriter bufWriter = new BufferedWriter(writer, IO_BUFFER_SIZE); - - try { - serializeNode(bufWriter, nodeArg, encoding); - bufWriter.close(); - return true; - } catch (IOException ioe) { - Object rawHandler = config.getParameter(DOMSerializerConfiguration.ERROR_HANDLER); - if (rawHandler != null) { - DOMErrorHandler handler = (DOMErrorHandler)rawHandler; - DefaultDOMLocator loc = new DefaultDOMLocator(nodeArg, 1, 1, 0, null); - DOMSerializerError error = new DOMSerializerError(loc, ioe, DOMError.SEVERITY_FATAL_ERROR, "io-error"); - handler.handleError(error); - } - } catch (DOMSerializerException dse) { - Object rawHandler = config.getParameter(DOMSerializerConfiguration.ERROR_HANDLER); - if (rawHandler != null) { - DOMErrorHandler handler = (DOMErrorHandler)rawHandler; - DOMError error = dse.getError(); - handler.handleError(error); - } - //This is a fatal error, quit. - } - } - return false; - }//}}} - - //{{{ writeToString() - - public String writeToString(Node nodeArg) throws DOMException { - StringWriter writer = new StringWriter(); - try { - serializeNode(writer, nodeArg); - //flush the output-stream. Without this - //files are sometimes not written at all. - writer.flush(); - } catch (DOMSerializerException dse) { - throw new DOMException(DOMException.INVALID_STATE_ERR, dse.getMessage()); - } - return writer.toString(); - }//}}} - - //{{{ writeToURI() - - public boolean writeToURI(Node nodeArg, java.lang.String uri) { - return write(nodeArg, new DOMOutput(uri, "UTF-8")); - }//}}} - - //}}} - - //{{{ Private static members - private static final int IO_BUFFER_SIZE = 32768; - //}}} - - //{{{ Private members - - //{{{ DOMSerializerError class - - private static class DOMSerializerError implements DOMError { - - //{{{ DOMSerializerError constructor - - public DOMSerializerError(DOMLocator locator, Exception e, short s, String type) { - m_exception = e; - m_location = locator; - m_severity = s; - m_type = type; - }//}}} - - //{{{ getLocation() - - public DOMLocator getLocation() { - return m_location; - }//}}} - - //{{{ getMessage() - - public String getMessage() { - return m_exception.getMessage(); - }//}}} - - //{{{ getRelatedData() - - public Object getRelatedData() { - return m_location.getRelatedNode(); - }//}}} - - //{{{ getRelatedException() - - public Object getRelatedException() { - return m_exception; - }//}}} - - //{{{ getSeverity() - - public short getSeverity() { - return m_severity; - }//}}} - - //{{{ getType() - - public String getType() { - return m_type; - }//}}} - - //{{{ Private members - - private Exception m_exception; - private DOMLocator m_location; - private short m_severity; - private String m_type; - //}}} - - }//}}} - - //{{{ serializeNode() - - private void serializeNode(Writer writer, Node node) throws DOMSerializerException { - serializeNode(writer, node, null); - }//}}} - - //{{{ serializeNode() - /** - * Serializes the node to the writer specified - */ - private void serializeNode(Writer writer, Node node, String encoding) throws DOMSerializerException { - rSerializeNode(writer, node, encoding, "", 1, 1, 0); - }//}}} - - //{{{ rSerializeNode() - /** - * Designed to be called recursively and maintain the state of the - * serialization. - */ - private void rSerializeNode(Writer writer, Node node, String encoding, String currentIndent, int line, int column, int offset) throws DOMSerializerException { - - boolean formatting = config.getFeature(DOMSerializerConfiguration.FORMAT_XML); - // boolean whitespace = config.getFeature(DOMSerializerConfiguration.WS_IN_ELEMENT_CONTENT); - - //This is used many times below as a temporary variable. - String str = ""; - - if (m_filter == null || m_filter.acceptNode(node) == 1) { - switch (node.getNodeType()) { - case Node.DOCUMENT_NODE://{{{ - if (config.getFeature(DOMSerializerConfiguration.XML_DECLARATION)) { - String header = "<?xml version=\"1.0\""; - String realEncoding = (String)config.getParameter(DOMSerializerConfiguration.XML_ENCODING); - if (realEncoding == null) { - realEncoding = encoding; - } - if (realEncoding != null) - header += " encoding=\""+realEncoding+"\""; - header +="?>"; - doWrite(writer, header, node, line, column, offset); - offset += header.length(); - column += header.length(); - - - //if not formatting write newLine here. - if (!formatting) { - column = 0; - line += 1; - doWrite(writer, m_newLine, node, line, column, offset); - offset += m_newLine.length(); - } - } - - NodeList nodes = node.getChildNodes(); - if (nodes != null) { - for (int i=0; i<nodes.getLength(); i++) { - rSerializeNode(writer, nodes.item(i), encoding, currentIndent, line, column, offset); - } - } - - break;//}}} - case Node.ELEMENT_NODE://{{{ - String nodeName = node.getLocalName(); - String nodePrefix = node.getPrefix(); - if (nodeName == null) { - nodeName = node.getNodeName(); - } - - if (formatting) { - //set to zero here for error handling (if doWrite throws exception). - column = 0; - str = m_newLine + currentIndent; - doWrite(writer, str, node, line, column, offset); - column += currentIndent.length(); - offset += str.length(); - } - - if (config.getFeature(DOMSerializerConfiguration.NAMESPACES) && nodePrefix != null) { - str = "<" + nodePrefix + ":" + nodeName; - } else { - str = "<" + nodeName; - } - - doWrite(writer, str, node, line, column, offset); - column += str.length(); - offset += str.length(); - - NamedNodeMap attr = node.getAttributes(); - for (int i=0; i<attr.getLength(); i++) { - Attr currentAttr = (Attr)attr.item(i); - boolean writeAttr = false; - - /* - if we discard default content check if the attribute - was specified in the original document. - */ - if (config.getFeature(DOMSerializerConfiguration.DISCARD_DEFAULT_CONTENT)) { - if (currentAttr.getSpecified()) { - writeAttr = true; - } - } else { - writeAttr = true; - } - - if (writeAttr) { - str = " " + currentAttr.getNodeName() + "=\"" + normalizeCharacters(currentAttr.getNodeValue()) + "\""; - doWrite(writer, str, node, line, column, offset); - column += str.length(); - offset += str.length(); - } - } - - NodeList children = node.getChildNodes(); - if (children != null) { - - //check if element is empty or has - //only whitespace-only nodes - boolean elementEmpty = false; - if (children.getLength() <= 0) { - elementEmpty = true; - } else { - if (!config.getFeature(DOMSerializerConfiguration.WS_IN_ELEMENT_CONTENT)) { - boolean hasWSOnlyElements = true; - for(int i=0; i<children.getLength();i++) { - hasWSOnlyElements = hasWSOnlyElements && - children.item(i).getNodeType()==Node.TEXT_NODE && - children.item(i).getNodeValue().trim().equals(""); - } - elementEmpty = formatting && hasWSOnlyElements; - } - } - if (!elementEmpty) { - - str = ">"; - doWrite(writer, str, node, line, column, offset); - column += str.length(); - offset += str.length(); - - String indentUnit = ""; - - if (formatting) { - if (config.getFeature(DOMSerializerConfiguration.SOFT_TABS)) { - //get the indent size and use it when serializing the children nodes. - Integer indentSize = (Integer)config.getParameter("indent"); - if (indentSize != null) { - int size = indentSize.intValue(); - StringBuffer buf = new StringBuffer(); - for (int i=0; i < size; i++) { - buf.append(" "); - } - indentUnit = buf.toString(); - } - } else { - indentUnit = "\t"; - } - } - - - for(int i=0; i<children.getLength();i++) { - rSerializeNode(writer, children.item(i), encoding, currentIndent + indentUnit, line, column, offset); - } - - //don't add a new line if there is only text node children - if (formatting) { - - boolean allText = true; - for(int i=0; i<children.getLength();i++) { - if (!(children.item(i).getNodeType()==Node.TEXT_NODE) && - !(children.item(i).getNodeType()==Node.CDATA_SECTION_NODE)) - { - allText = false; - break; - } - } - - if (!allText) { - //set to zero here for error handling (if doWrite throws exception). - column = 0; - str = m_newLine + currentIndent; - doWrite(writer, str, node, line, column, offset); - column += currentIndent.length(); - offset += str.length(); - } - } - if (config.getFeature(DOMSerializerConfiguration.NAMESPACES) && nodePrefix != null) { - str = "</" + nodePrefix + ":" +nodeName + ">"; - } else { - str = "</" + nodeName + ">"; - } - doWrite(writer, str, node, line, column, offset); - column += str.length(); - offset += str.length(); - - } else { - str = "/>"; - doWrite(writer, str, node, line, column, offset); - column += str.length(); - offset += str.length(); - } - } - break;//}}} - case Node.TEXT_NODE://{{{ - String text = node.getNodeValue(); - //formatting implies no whitespace - //but to be explicit... - // if (!whitespace || formatting) { - // text = text.trim(); - // } - if (!text.equals("")) { - if (formatting) { - if (text.trim().equals("")) { - //ignore this whitespace only text if formatting - return; - } - - /* - don't format text nodes - if (node.getNextSibling() != null || node.getPreviousSibling() != null) { - line++; - column=0; - doWrite(writer, m_newLine, node, line, column, offset); - offset += m_newLine.length(); - } - */ - } - - //TODO: This is a dumb quick fix and should probably be changed. - for (int i=0; i<text.length();i++) { - //this must be first or it picks up the other - //entities. - str = text.substring(i, i+1); - if (str.equals("&")) { - str = "&"; - } - if (str.equals(">")) { - str = ">"; - } - if (str.equals("<")) { - str = "<"; - } - if (str.equals("\'")) { - str = "'"; - } - if (str.equals("\"")) { - str = """; - } - if (str.equals(m_newLine)) { - line++; - column=0; - doWrite(writer, m_newLine, node, line, column, offset); - offset += m_newLine.length(); - } else { - doWrite(writer, str, node, line, column, offset); - column += str.length(); - offset += str.length(); - } - } - } - break;//}}} - case Node.CDATA_SECTION_NODE://{{{ - if (config.getFeature(DOMSerializerConfiguration.CDATA_SECTIONS)) { - //shouldn't add newlines for - // if (formatting) { - // //set to zero here for error handling (if doWrite throws exception) - // column = 0; - // str = m_newLine + currentIndent; - // doWrite(writer, str, node, line, column, offset); - // column += currentIndent.length(); - // offset += str.length(); - // } - str = "<![CDATA["; - doWrite(writer, str, node, line, column, offset); - column += str.length(); - offset += str.length(); - - String cdata = node.getNodeValue(); - for (int i=0; i<cdata.length(); i++) { - - str = cdata.substring(i, i+1); - if (str.equals("]") && i+3 < cdata.length() && cdata.substring(i, i+3).equals("]]>")) { - //split the cdata - DefaultDOMLocator loc = new DefaultDOMLocator(node, line, column, offset, null); - if (config.getFeature(DOMSerializerConfiguration.SPLIT_CDATA)) { - i+=2; - str = "]]]]>"; - /* - if (formatting) { - str += (m_newLine + currentIndent); - column = currentIndent.length(); - offset += (m_newLine.length() + currentIndent.length()); - } - */ - str += "<![CDATA[>"; - throwError(loc, "cdata-sections-splitted", DOMError.SEVERITY_WARNING, null); - } else { - throwError(loc, "invalid-data-in-cdata-section", DOMError.SEVERITY_FATAL_ERROR, null); - } - } - if (str.equals(m_newLine)) { - line++; - column=0; - doWrite(writer, m_newLine, node, line, column, offset); - offset += m_newLine.length(); - } else { - doWrite(writer, str, node, line, column, offset); - column += str.length(); - offset += str.length(); - } - - } - - str = "]]>"; - doWrite(writer, str, node, line, column, offset); - column += str.length(); - offset += str.length(); - } else { - //transform to text node. - Node textNode = node.getOwnerDocument().createTextNode(node.getNodeValue()); - rSerializeNode(writer, textNode, encoding, currentIndent, line, column, offset); - } - break;//}}} - case Node.COMMENT_NODE://{{{ - if (config.getFeature("comments")) { - if (formatting) { - //set to zero here for error handling (if doWrite throws exception) - column = 0; - str = m_newLine + currentIndent; - doWrite(writer, str, node, line, column, offset); - column += currentIndent.length(); - offset += str.length(); - } - str = "<!--"+node.getNodeValue()+"-->"; - doWrite(writer, str, node, line, column, offset); - column += str.length(); - offset += str.length(); - } - break;//}}} - case Node.PROCESSING_INSTRUCTION_NODE://{{{ - - if (formatting) { - //set to zero here for error handling (if doWrite throws exception) - column = 0; - str = m_newLine + currentIndent; - doWrite(writer, str, node, line, column, offset); - column += currentIndent.length(); - offset += str.length(); - } - - str = "<?" + node.getNodeName() + " " + node.getNodeValue() + "?>"; - doWrite(writer, str, node, line, column, offset); - column += str.length(); - offset += str.length(); - - break;//}}} - case Node.ENTITY_REFERENCE_NODE://{{{ - str = "&" + node.getNodeName() + ";"; - doWrite(writer, str, node, line, column, offset); - column += str.length(); - offset += str.length(); - break;//}}} - case Node.DOCUMENT_TYPE_NODE://{{{ - DocumentType docType = (DocumentType)node; - - if (formatting) { - //set to zero here for error handling (if doWrite throws exception). - column = 0; - str = m_newLine + currentIndent; - doWrite(writer, str, node, line, column, offset); - column += currentIndent.length(); - offset += str.length(); - } - - str = "<!DOCTYPE " + docType.getName(); - doWrite(writer, str, node, line, column, offset); - column += str.length(); - offset += str.length(); - if (docType.getPublicId() != null) { - str = " PUBLIC \"" + docType.getPublicId() + "\" "; - doWrite(writer, str, node, line, column, offset); - column += str.length(); - offset += str.length(); - } - if (docType.getSystemId() != null) { - if (docType.getPublicId() == null) { - str = " SYSTEM "; - } else { - str = ""; - } - str += "\"" + docType.getSystemId() + "\""; - doWrite(writer, str, node, line, column, offset); - column += str.length(); - offset += str.length(); - } - - String internalSubset = docType.getInternalSubset(); - if (internalSubset != null && !internalSubset.equals("")) { - str = " [ "+internalSubset+" ]"; - doWrite(writer, str, node, line, column, offset); - column += str.length(); - offset += str.length(); - } - - str = ">"; - doWrite(writer, str, node, line, column, offset); - column += str.length(); - offset += str.length(); - - //need to add a newline so that the next item is on a new line - //since text nodes are not included outside of the root element - if (!formatting) { - column = 0; - str = m_newLine + currentIndent; - doWrite(writer, str, node, line, column, offset); - column += currentIndent.length(); - offset += str.length(); - } - - break;//}}} - } - } - }//}}} - - //{{{ doWrite() - /** - * Performs an actual write and implements error handling. - */ - private void doWrite(Writer writer, String str, Node wnode, int line, int column, int offset) throws DOMSerializerException { - try { - writer.write(str, 0, str.length()); - } catch (IOException ioe) { - - DefaultDOMLocator loc = new DefaultDOMLocator(wnode, line, column, offset, null); - - throwError(loc, "io-error", DOMError.SEVERITY_FATAL_ERROR, ioe); - } - }//}}} - - //{{{ throwError() - /** - * Throws an error, notifying the ErrorHandler object if necessary. - * @return the value returned by the error handler or false if the severity was SEVERITY_FATAL_ERROR - */ - private void throwError(DOMLocator loc, String type, short severity, Exception e) throws DOMSerializerException { - Object rawHandler = config.getParameter(DOMSerializerConfiguration.ERROR_HANDLER); - boolean handled = false; - if (severity == DOMError.SEVERITY_WARNING) { - handled = true; - } - DOMSerializerError error = new DOMSerializerError(loc, e, severity, type); - if (rawHandler != null) { - DOMErrorHandler handler = (DOMErrorHandler)rawHandler; - handled = handler.handleError(error); - } - - if ((severity == DOMError.SEVERITY_ERROR && !handled) || severity == DOMError.SEVERITY_FATAL_ERROR) { - throw new DOMSerializerException(error); - } - }//}}} - - //{{{ normalizeCharacters() - - private String normalizeCharacters(String text) { - StringBuffer newText = new StringBuffer(); - //This is a dumb quick fix and should be changed. - for (int i=0; i<text.length();i++) { - //this must be first or it picks up the other - //entities. - String str = text.substring(i, i+1); - if (str.equals("&")) { - str = "&"; - } - if (str.equals(">")) { - str = ">"; - } - if (str.equals("<")) { - str = "<"; - } - if (str.equals("\'")) { - str = "'"; - } - if (str.equals("\"")) { - str = """; - } - newText.append(str); - } - return newText.toString(); - }//}}} - - private DOMSerializerConfiguration config; - private LSSerializerFilter m_filter; - private String m_newLine; - - //}}} -} Deleted: branches/jsxe2/src/net/sourceforge/jsxe/dom/DOMSerializerConfiguration.java =================================================================== --- branches/jsxe2/src/net/sourceforge/jsxe/dom/DOMSerializerConfiguration.java 2006-09-06 19:20:54 UTC (rev 1238) +++ branches/jsxe2/src/net/sourceforge/jsxe/dom/DOMSerializerConfiguration.java 2006-09-06 19:26:53 UTC (rev 1239) @@ -1,478 +0,0 @@ -/* -DOMSerializerConfiguration.java -:tabSize=4:indentSize=4:noTabs=true: -:folding=explicit:collapseFolds=1: - -This attempts to conform to the DOM3 implementation in Xerces. It conforms -to DOM3 as of Xerces 2.3.0. I'm not one to stay on the bleeding edge but -there is as close to a standard interface for load & save as you can get and I -didn't want to work around the fact that current serializers aren't very good. - -Copyright (C) 2002 Ian Lewis (Ian...@me...) - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -Optionally, you may find a copy of the GNU General Public License -from http://www.fsf.org/copyleft/gpl.txt -*/ - -package net.sourceforge.jsxe.dom; - -//{{{ imports - -//{{{ DOM classes -import org.w3c.dom.DOMException; -import org.w3c.dom.DOMConfiguration; -import org.w3c.dom.DOMError; -import org.w3c.dom.DOMErrorHandler; -import org.w3c.dom.DOMLocator; -import org.w3c.dom.DOMStringList; -//}}} - -//{{{ Java classes -import java.util.ArrayList; -import java.util.Hashtable; -import java.util.Iterator; -//}}} - -import net.sourceforge.jsxe.util.Log; - -//}}} - -/** - * <p>DOMSerializerConfiguration is the default implementation of the DOMConfiguration - * interface to be used with the DOMSerializer class.</p> - * - * <p>Currently, this class only supports the required options with few exceptions. - * The <code>"format-pretty-print"</code> option is supported. - * A <code>"soft-tabs"</code> option is supported which specifies whether - * to emulate tabs with spaces. - * An <code>"indent"</code> option is supported to specify the indent/tab - * size when the <code>"soft-tabs"</code> feature is true. This has no effect - * if <code>"soft-tabs"</code> is false.</p> - * - * @author <a href="mailto:IanLewis at member dot fsf dot org">Ian Lewis</a> - * @version $Id$ - * @see DOMSerializer - */ -public class DOMSerializerConfiguration implements DOMConfiguration { - - //{{{ DOMConfiguration defined parameters - public static final String CANONICAL_FORM = "canonical-form"; - public static final String CDATA_SECTIONS = "cdata-sections"; - public static final String CHAR_NORMALIZATION = "check-character-normalization"; - public static final String COMMENTS = "comments"; - public static final String DATATYPE_NORMALIZATION = "datatype-normalization"; - public static final String ENTITIES = "entities"; - public static final String ERROR_HANDLER = "error-handler"; - public static final String INFOSET = "infoset"; - public static final String NAMESPACES = "namespaces"; - public static final String NAMESPACE_DECLARATIONS = "namespace-declarations"; - public static final String NORMALIZE_CHARS = "normalize-characters"; - public static final String SPLIT_CDATA = "split-cdata-sections"; - public static final String VALIDATE_XML = "validate"; - public static final String VALIDATE_IF_SCHEMA = "validate-if-schema"; - public static final String WELL_FORMED = "well-formed"; - public static final String WS_IN_ELEMENT_CONTENT = "element-content-whitespace"; - //}}} - - //{{{ LSSerializer defined parameters - public static final String DISCARD_DEFAULT_CONTENT = "discard-default-content"; - public static final String FORMAT_XML = "format-pretty-print"; - public static final String IGNORE_UNKNOWN_CHAR_DENORM = "ignore-unknown-character-denormalizations"; - public static final String XML_DECLARATION = "xml-declaration"; - //}}} - - //{{{ Additional parameters supported by DOMSerializerConfiguration - /** - * Use spaces instead of tabs if this is true. - */ - public static final String SOFT_TABS = "soft-tabs"; - /** - * The number of spaces to use as an tab when SOFT_TABS is true. - */ - public static final String INDENT = "indent"; - /** - * The encoding to use in the XML declaration. - */ - public static final String XML_ENCODING = "encoding"; - //}}} - - //{{{ DOMSerializerConfiguration constructor - - public DOMSerializerConfiguration() { - - //set the default boolean parameters for a DOMConfiguration - setFeature(CANONICAL_FORM, false); - setFeature(CDATA_SECTIONS, true); - setFeature(CHAR_NORMALIZATION, false); - setFeature(COMMENTS, true); - setFeature(DATATYPE_NORMALIZATION, false); - setFeature(ENTITIES, true); - //infoset is not present because it is determined - //by checking the values of other features. - setFeature(NAMESPACES, true); - setFeature(NAMESPACE_DECLARATIONS, true); - setFeature(NORMALIZE_CHARS, true); - setFeature(SPLIT_CDATA, true); - setFeature(VALIDATE_XML, false); - setFeature(VALIDATE_IF_SCHEMA, false); - setFeature(WELL_FORMED, true); - setFeature(WS_IN_ELEMENT_CONTENT, true); - - //LSSeraializer features - setFeature(DISCARD_DEFAULT_CONTENT, true); - setFeature(FORMAT_XML, false); - setFeature(IGNORE_UNKNOWN_CHAR_DENORM, true); - setFeature(XML_DECLARATION, true); - - //DOMSerializer parameters - setFeature(SOFT_TABS, false); - setParameter(INDENT, new Integer(4)); - setParameter(XML_ENCODING, null); - }//}}} - - //{{{ DOMSerializerConfiguration constructor - - public DOMSerializerConfiguration(DOMConfiguration config) throws DOMException { - this(); - Iterator iterator = m_supportedParameters.iterator(); - while (iterator.hasNext()) { - String param = iterator.next().toString(); - setParameter(param, config.getParameter(param)); - } - }//}}} - - //{{{ Implemented DOMConfiguration methods - - //{{{ canSetParameter() - - public boolean canSetParameter(String name, Object value) { - - if (value == null) { - return (m_supportedParameters.indexOf(name) != -1); - } - - if (value instanceof Boolean) { - boolean booleanValue = ((Boolean)value).booleanValue(); - - //couldn't think of a slicker way to do this - //that was worth the time to implement - //and extra processing. - if (name.equals(CANONICAL_FORM)) { - return !booleanValue; - } - if (name.equals(CDATA_SECTIONS)) { - return true; - } - if (name.equals(CHAR_NORMALIZATION)) { - return !booleanValue; - } - if (name.equals(COMMENTS)) { - return true; - } - if (name.equals(DATATYPE_NORMALIZATION)) { - return true; - } - if (name.equals(ENTITIES)) { - return true; - } - if (name.equals(WELL_FORMED)) { - return true; - } - if (name.equals(INFOSET)) { - return true; - } - if (name.equals(NAMESPACES)) { - return true; - } - if (name.equals(NAMESPACE_DECLARATIONS)) { - return true; - } - if (name.equals(NORMALIZE_CHARS)) { - return true; - } - if (name.equals(SPLIT_CDATA)) { - return true; - } - if (name.equals(VALIDATE_XML)) { - return !booleanValue; - } - if (name.equals(VALIDATE_IF_SCHEMA)) { - return !booleanValue; - } - if (name.equals(WS_IN_ELEMENT_CONTENT)) { - return true; - } - - if (name.equals(DISCARD_DEFAULT_CONTENT)) { - return true; - } - if (name.equals(FORMAT_XML)) { - return true; - } - if (name.equals(IGNORE_UNKNOWN_CHAR_DENORM)) { - return booleanValue; - } - if (name.equals(XML_DECLARATION)) { - return true; - } - if (name.equals(SOFT_TABS)) { - return true; - } - - return false; - } else { - if (name.equals(ERROR_HANDLER)) { - if (value instanceof DOMErrorHandler) { - return true; - } - } - if (name.equals(INDENT)) { - if (value instanceof Integer) { - return true; - } - } - if (name.equals(XML_ENCODING)) { - if (value instanceof String) { - return true; - } - } - } - return false; - }//}}} - - //{{{ getParameter() - - public Object getParameter(String name) throws DOMException { - - if (m_supportedParameters.indexOf(name) != -1) { - - if (name.equals("infoset")) { - boolean namespaceDeclarations = getFeature(NAMESPACE_DECLARATIONS); - boolean validateIfSchema = getFeature(VALIDATE_IF_SCHEMA); - boolean entities = getFeature(ENTITIES); - boolean datatypeNormalization = getFeature(DATATYPE_NORMALIZATION); - boolean cdataSections = getFeature(CDATA_SECTIONS); - - boolean whitespace = getFeature(WS_IN_ELEMENT_CONTENT); - boolean comments = getFeature(COMMENTS); - boolean namespaces = getFeature(NAMESPACES); - - return (Boolean.valueOf(!namespaceDeclarations && - !validateIfSchema && - !entities && - !datatypeNormalization && - !cdataSections && - whitespace && - comments && - namespaces)); - } else { - return m_parameters.get(name); - } - - } else { - - throw new DOMException(DOMException.NOT_FOUND_ERR ,"NOT_FOUND_ERR: Parameter "+name+" not recognized"); - - } - }//}}} - - //{{{ getParameterNames() - - public DOMStringList getParameterNames() { - return new DOMStringListImpl(m_supportedParameters); - }//}}} - - //{{{ setParameter() - - public void setParameter(String name, Object value) throws DOMException { - - if (value instanceof String && - (value.toString().equalsIgnoreCase("true") || - value.toString().equalsIgnoreCase("false"))) - { - Log.log(Log.WARNING,this, "Possibly setting XML serializer config boolean feature "+name+" with string value"); - } - - if (m_supportedParameters.indexOf(name) != -1) { - if ( value != null ) { - if (canSetParameter(name, value)) { - /* - if the parameter is infoset - then force the other parameters to - values that the infoset option - requires. - */ - if (name.equals(INFOSET)) { - setFeature(NAMESPACE_DECLARATIONS,false); - setFeature(VALIDATE_IF_SCHEMA, false); - setFeature(ENTITIES, false); - setFeature(DATATYPE_NORMALIZATION,false); - setFeature(CDATA_SECTIONS, false); - - setFeature(WS_IN_ELEMENT_CONTENT, true); - setFeature(COMMENTS, true); - setFeature(NAMESPACES, true); - return; - } - if (name.equals(FORMAT_XML) && ((Boolean)value).booleanValue()) { - /* - The element-content-whitespace parameter is ignored - when serializing since the parameter only makes sense - when the document is validated by DTD or Schema that - specifies that an element MUST have only child elements - (element-content). - - Also if the DOM validates this info when being edited - then the serializer could never write out whitespace - in element content without invalidating the document. - See - http://xml.apache.org/xerces2-j/javadocs/dom3-api/index.html - Section 2.10 - */ - // setFeature(WS_IN_ELEMENT_CONTENT, false); - setFeature(CANONICAL_FORM, false); - } - // if (name.equals(WS_IN_ELEMENT_CONTENT) && ((Boolean)value).booleanValue()) { - // setFeature(FORMAT_XML, false); - // } - - m_parameters.put(name, value); - - } else { - throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Parameter "+name+" and value "+value.toString()+" not supported."); - } - } else { - m_parameters.remove(name); - } - } else { - throw new DOMException(DOMException.NOT_FOUND_ERR, "Parameter "+name+" is not recognized."); - } - }//}}} - - //}}} - - //{{{ getFeature() - - /** - * <p>A convenience method to retrieve the value that a boolean - * parameter (feature) is set to.</p> - * @param name The name of the feature to get the value of - * @return The current setting for the given feature - */ - public boolean getFeature(String name) throws DOMException { - Object parameter = getParameter(name); - - if (name.equals("error-handler") || name.equals("indent") || !(parameter instanceof Boolean)) { - throw new DOMException(DOMException.NOT_FOUND_ERR, "NOT_FOUND_ERR: "+name+" is not a feature."); - } - return ((Boolean)parameter).booleanValue(); - - }//}}} - - //{{{ setFeature() - - /** - * <p>A convenience method to set the value of a boolean parameter (feature)</p> - * @param name The feature to set the value of - * @param value The boolean value to set to the feature - */ - public void setFeature(String name, boolean value) throws DOMException { - setParameter(name, Boolean.valueOf(value)); - }//}}} - - //{{{ Private static members - - private static ArrayList m_supportedParameters = null; - - static { - //create a vector of the supported parameters - m_supportedParameters = new ArrayList(22); - - //DOMConfiguration defined parameters - m_supportedParameters.add(CANONICAL_FORM); - m_supportedParameters.add(CDATA_SECTIONS); - m_supportedParameters.add(CHAR_NORMALIZATION); - m_supportedParameters.add(COMMENTS); - m_supportedParameters.add(DATATYPE_NORMALIZATION); - m_supportedParameters.add(ENTITIES); - m_supportedParameters.add(ERROR_HANDLER); - m_supportedParameters.add(INFOSET); - m_supportedParameters.add(NAMESPACES); - m_supportedParameters.add(NAMESPACE_DECLARATIONS); - m_supportedParameters.add(NORMALIZE_CHARS); - m_supportedParameters.add(SPLIT_CDATA); - m_supportedParameters.add(VALIDATE_XML); - m_supportedParameters.add(VALIDATE_IF_SCHEMA); - m_supportedParameters.add(WELL_FORMED); - m_supportedParameters.add(WS_IN_ELEMENT_CONTENT); - - //LSSerializer defined parameters - m_supportedParameters.add(DISCARD_DEFAULT_CONTENT); - m_supportedParameters.add(FORMAT_XML); - m_supportedParameters.add(IGNORE_UNKNOWN_CHAR_DENORM); - m_supportedParameters.add(XML_DECLARATION); - - //Additional parameters supported by DOMSerializerConfiguration - m_supportedParameters.add(SOFT_TABS); - m_supportedParameters.add(INDENT); - m_supportedParameters.add(XML_ENCODING); - }//}}} - - //{{{ Private members - - //{{{ DOMStringListImpl class - - private static class DOMStringListImpl implements DOMStringList { - - //{{{ DOMStringListImpl constructor - - public DOMStringListImpl(ArrayList list) { - m_list = list; - }//}}} - - //{{{ contains() - - public boolean contains(String str) { - for (int i=0; i<m_list.size(); i++) { - if (m_list.get(i).toString().equals(str)) { - return true; - } - } - return false; - }//}}} - - //{{{ getLength() - - public int getLength() { - return m_list.size(); - }//}}} - - //{{{ item() - - public String item(int index) { - return m_list.get(index).toString(); - }//}}} - - //{{{ Private members - private ArrayList m_list; - //}}} - - }//}}} - - private Hashtable m_parameters = new Hashtable(16); - - //}}} -} Deleted: branches/jsxe2/src/net/sourceforge/jsxe/dom/DOMSerializerException.java =================================================================== --- branches/jsxe2/src/net/sourceforge/jsxe/dom/DOMSerializerException.java 2006-09-06 19:20:54 UTC (rev 1238) +++ branches/jsxe2/src/net/sourceforge/jsxe/dom/DOMSerializerException.java 2006-09-06 19:26:53 UTC (rev 1239) @@ -1,65 +0,0 @@ -/* -DOMSerializerException.java -:tabSize=4:indentSize=4:noTabs=true: -:folding=explicit:collapseFolds=1: - -Copyright (C) 2002 Ian Lewis (Ian...@me...) - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -Optionally, you may find a copy of the GNU General Public License -from http://www.fsf.org/copyleft/gpl.txt -*/ - -package net.sourceforge.jsxe.dom; - -//{{{ imports -/* -All classes are listed explicitly so -it is easy to see which package it -belongs to. -*/ - -//{{{ DOM classes -import org.w3c.dom.DOMError; -//}}} - -//}}} - -/** - * Signals that a serialization error of some kind has occurred. - * @author <a href="mailto:IanLewis at member dot fsf dot org">Ian Lewis</a> - * @version $Id$ - * @see DOMSerializer - */ -public class DOMSerializerException extends Exception { - - //{{{ DOMSerializerException constructor - - public DOMSerializerException(DOMError err) { - super(((Throwable)err.getRelatedException()).getMessage()); - error = err; - }//}}} - - //{{{ getError() - - public DOMError getError() { - return error; - }//}}} - - //{{{ Private members - private DOMError error; - //}}} - -} Copied: branches/jsxe2/src/net/sourceforge/jsxe/dom/ls/DOMSerializer.java (from rev 1232, branches/jsxe2/src/net/sourceforge/jsxe/dom/DOMSerializer.java) =================================================================== --- branches/jsxe2/src/net/sourceforge/jsxe/dom/ls/DOMSerializer.java (rev 0) +++ branches/jsxe2/src/net/sourceforge/jsxe/dom/ls/DOMSerializer.java 2006-09-06 19:26:53 UTC (rev 1239) @@ -0,0 +1,825 @@ +/* +DOMSerializer.java +:tabSize=4:indentSize=4:noTabs=true: +:folding=explicit:collapseFolds=1: + +This attempts to conform to the DOM3 implementation in Xerces. It tries to +conform to DOM3 as of Xerces 2.6.0. I'm not one to stay on the bleeding edge +but it is as close to a standard interface for load & save as you can get +and I didn't want to work around the fact that current serializers aren't +very good. + +Copyright (C) 2002 Ian Lewis (Ian...@me...) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +Optionally, you may find a copy of the GNU General Public License +from http://www.fsf.org/copyleft/gpl.txt +*/ + +package net.sourceforge.jsxe.dom.ls; + +//{{{ imports +/* +All classes are listed explicitly so +it is easy to see which ... [truncated message content] |
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. |