[Jsxe-cvs] SF.net SVN: jsxe: [1000] branches/jsxe2/src/net/sourceforge/jsxe
Status: Inactive
Brought to you by:
ian_lewis
From: <ian...@us...> - 2006-07-07 23:54:29
|
Revision: 1000 Author: ian_lewis Date: 2006-07-07 16:54:05 -0700 (Fri, 07 Jul 2006) ViewCVS: http://svn.sourceforge.net/jsxe/?rev=1000&view=rev Log Message: ----------- updated the new document model and gave it it's own package Added Paths: ----------- branches/jsxe2/src/net/sourceforge/jsxe/dom2/ branches/jsxe2/src/net/sourceforge/jsxe/dom2/XMLDocument.java branches/jsxe2/src/net/sourceforge/jsxe/dom2/XMLElement.java branches/jsxe2/src/net/sourceforge/jsxe/dom2/XMLNode.java Removed Paths: ------------- 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 Deleted: branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLElement.java =================================================================== --- branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLElement.java 2006-07-07 20:59:23 UTC (rev 999) +++ branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLElement.java 2006-07-07 23:54:05 UTC (rev 1000) @@ -1,57 +0,0 @@ -/* -XMLElement.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; - -//{{{ Imports -import org.w3c.dom.*; -import org.w3c.dom.events.*; -//}}} - -/** - * The XMLElement class represents an element in the XMLDocument tree. It allows - * attibute modifications which will translate to text modifications in the - * XMLDocument. - * @author Ian Lewis (<a href="mailto:Ian...@me...">Ian...@me...</a>) - * @version $Id$ - * @see XMLDocument - * @since jsXe 0.5 pre2 - */ -public class XMLElement extends XMLNode { - - //{{{ XMLElement constructor - /** - * Creates a new XMLElement - * @param element the element node that this node wraps. - */ - XMLElement(Element element) { - super(element); - }//}}} - - //{{{ getNodeType() - public int getNodeType() { - return Node.ELEMENT_NODE; - }//}}} - -} Deleted: branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLException.java =================================================================== --- branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLException.java 2006-07-07 20:59:23 UTC (rev 999) +++ branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLException.java 2006-07-07 23:54:05 UTC (rev 1000) @@ -1,122 +0,0 @@ -/* -XMLException.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; - -/** - * XMLExceptions represent any type of exception that may occur when editing - * an XML document. This can include when the document would cause the - * structure to be non-well-formed though a method call. Operations on - * the structure of the XMLDocument should always result in a well-formed - * document. - * - * @author Ian Lewis (<a href="mailto:Ian...@me...">Ian...@me...</a>) - * @version $Id$ - * @see XMLDocument - * @see XMLNode - * @since jsXe 0.5 pre2 - */ -public class XMLException extends RuntimeException { - - //{{{ Exception types - /** - * Indicates a Node is inserted somewhere it doesn't belong. - */ - public static final short HIERARCHY_REQUEST_ERR = 1; - - /** - * If index or size is negative, or greater than the allowed value. - */ - public static final short INDEX_SIZE_ERR = 2; - /** - * If an invalid or illegal character is specified, such as in an XML name. - */ - public static final short INVALID_CHARACTER_ERR = 3; - /** - * If an attempt is made to modify the type of the underlying object. - */ - public static final short INVALID_MODIFICATION_ERR = 4; - /** - * If an attempt is made to use an object that is not, or is no longer, usable. - */ - public static final short INVALID_STATE_ERR = 5; - /** - * If an attempt is made to create or change an object in a way which is incorrect with regard to namespaces. - */ - public static final short NAMESPACE_ERR = 6; - /** - * If data is specified for a Node which does not support data. - */ - public static final short NO_DATA_ALLOWED_ERR = 7; - /** - * If an attempt is made to modify an object where modifications are not allowed. - */ - public static final short NO_MODIFICATION_ALLOWED_ERR = 8; - /** - * If an attempt is made to reference a Node in a context where it does not exist. - */ - //public static final short NOT_FOUND_ERR = 9; - /** - * If an invalid or illegal string is specified. - */ - //public static final short SYNTAX_ERR = 10; - /** - * If the type of an object is incompatible with the expected type of the parameter associated to the object. - */ - public static final short TYPE_MISMATCH_ERR = 11; - /** - * If a call to a method such as insertBefore or removeChild would make the - * Node invalid with respect to "partial validity", this exception would be - * raised and the operation would not be done. - */ - //public static final short VALIDATION_ERR = 12; - /** - * If a Node is used in a different document than the one that created it (that doesn't support it). - */ - public static final short WRONG_DOCUMENT_ERR = 13; - //}}} - - //{{{ XMLException constructor - /** - * Creates a new XMLException with the given message. - * @param type The exception type - * @param message The message - */ - public XMLException(short type, String message) { - super(message); - m_type = type; - }//}}} - - //{{{ getType() - /** - * Returts the type of the exception - */ - public short getType() { - return m_type; - }//}}} - - //{{{ Private Members - private short m_type; - //}}} -} Deleted: branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLNode.java =================================================================== --- branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLNode.java 2006-07-07 20:59:23 UTC (rev 999) +++ branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLNode.java 2006-07-07 23:54:05 UTC (rev 1000) @@ -1,102 +0,0 @@ -/* -XMLNode.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; - -//{{{ imports - -//{{{ jsXe classes -import net.sourceforge.jsxe.jsXe; -import net.sourceforge.jsxe.util.Log; -import net.sourceforge.jsxe.dom.completion.*; -//}}} - -//{{{ DOM classes -import org.w3c.dom.*; -import org.w3c.dom.events.*; -//}}} - -//}}} - -/** - * <p>The XMLNode class is meant to represent an XMLNode in a XMLDocument tree - * but also as a section of text within that document tree. It - * 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$ - * @see XMLDocument - * @since jsXe 0.5 pre2 - */ -public abstract class XMLNode { - - private static final String USER_DATA_KEY = "net.sourceforge.jsxe.dom.XMLNode"; - - //{{{ Private members - - /** - * The w3c Node that this node wraps. It must support the EventTarget - * interface in org.w3c.dom.events - */ - private Node m_domNode; - - //}}} - - //{{{ XMLNode constructor - XMLNode(Node node) { - m_domNode = node; - }//}}} - - //{{{ addEventListener() - public void addEventListener(java.lang.String type, EventListener listener, boolean useCapture) { - ((EventTarget)m_domNode).addEventListener(type, listener, useCapture); - }//}}} - - //{{{ removeEventListener() - public void removeEventListener(java.lang.String type, EventListener listener, boolean useCapture) { - ((EventTarget)m_domNode).removeEventListener(type, listener, useCapture); - }//}}} - - //{{{ appendNode() - public XMLNode appendChild(XMLNode newChild) { - - m_domNode.appendChild(newChild.getNode()); - - return newChild; - }//}}} - - //{{{ Protected Members - - //{{{ getNode() - protected Node getNode() { - return m_domNode; - }//}}} - - //}}} -} Deleted: branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLNodeListener.java =================================================================== --- branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLNodeListener.java 2006-07-07 20:59:23 UTC (rev 999) +++ branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLNodeListener.java 2006-07-07 23:54:05 UTC (rev 1000) @@ -1,39 +0,0 @@ -/* -XMLNodeListener.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; - -/** - * XMLNodeListener is used to notify objects of a change to a specific XMLNode. - * These changes can occur via changes to the text or document structure. Both - * are maintained by the XMLDocument class. - * - * @author Ian Lewis (<a href="mailto:Ian...@me...">Ian...@me...</a>) - * @version $Id$ - * @since jsXe 0.5 pre2 - * @see XMLDocument - */ -public interface XMLNodeListener { - -} Added: branches/jsxe2/src/net/sourceforge/jsxe/dom2/XMLDocument.java =================================================================== --- branches/jsxe2/src/net/sourceforge/jsxe/dom2/XMLDocument.java (rev 0) +++ branches/jsxe2/src/net/sourceforge/jsxe/dom2/XMLDocument.java 2006-07-07 23:54:05 UTC (rev 1000) @@ -0,0 +1,502 @@ +/* +XMLDocument.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.dom2; + +//{{{ imports + +//{{{ jsXe classes +import net.sourceforge.jsxe.jsXe; +import net.sourceforge.jsxe.util.Log; +import net.sourceforge.jsxe.util.MiscUtilities; +//}}} + +//{{{ DOM classes +import org.w3c.dom.*; +import org.w3c.dom.events.*; +//}}} + +//{{{ Java base classes +import java.io.IOException; +import java.io.Writer; +import java.util.ArrayList; +import java.util.HashMap; +//}}} + +//{{{ Swing classes +import javax.swing.text.*; +import javax.swing.event.DocumentListener; +import javax.swing.event.UndoableEditListener; +//}}} + +//}}} + +/** + * The XMLDocument class represents an XML document as a tree structure + * that has nodes, implemented as AdapterNodes, as well as text. Methods are + * provided to allow user objects to interact with the XML document as text + * or as a tree structure seamlessly. + * + * @author Ian Lewis (<a href="mailto:Ian...@me...">Ian...@me...</a>) + * @version $Id: XMLDocument.java 999 2006-07-07 20:59:23Z ian_lewis $ + * @see AdapterNode + */ +public class XMLDocument /* implements javax.swing.text.Document */ { + + //{{{ XMLDocument constructor + XMLDocument() { + + }//}}} + + //{{{ swing.text.Document methods + + //{{{ addDocumentListener + /** + * Registers a change listener with the XMLDocument + * @param listener the listener to register with this document + */ + public void addDocumentListener(DocumentListener listener) { + if (listener != null) { + m_docListeners.add(listener); + } + }//}}} + + //{{{ addUndoableEditListener() + + public void addUndoableEditListener(UndoableEditListener listener) { + if (listener != null) { + m_undoListeners.add(listener); + } + }//}}} + + //{{{ createPosition() + + public Position createPosition(int offs) throws BadLocationException { + if (offs < 0 || offs > m_content.getLength()) { + //TODO: fix error messages + throw new BadLocationException("createPosition(): Bad offset", offs); + } + + final int offset = offs; + return new Position() { + public int getOffset() { + return offset; + } + }; + }//}}} + + //{{{ getDefaultRootElement() + + public javax.swing.text.Element getDefaultRootElement() { + //TODO: return root element + return null; + }//}}} + + //{{{ getEndPosition() + + public Position getEndPosition() { + try { + return createPosition(getLength()-1); + } catch (BadLocationException e) { + //Guaranteed to be good. + return null; + } + }//}}} + + //{{{ getLength() + /** + * Gets the total number of characters in the document. + * @return the length of the document + */ + public int getLength() { + return m_content.getLength(); + }//}}} + + //{{{ getProperty() + + public Object getProperty(Object key) { + return m_properties.get(key); + }//}}} + + //{{{ getRootElements() + + public javax.swing.text.Element[] getRootElements() { + //TODO: return root nodes + return null; + }//}}} + + //{{{ getStartPosition() + + public Position getStartPosition() { + try { + return createPosition(0); + } catch (BadLocationException e) { + //Guaranteed to be good. + return null; + } + }//}}} + + //{{{ getText() + public String getText(int offset, int length) throws BadLocationException { + if (offset < 0 || length < 0 || offset + length > m_content.getLength()) { + //TODO: fix error messages + throw new BadLocationException("insertString(): Bad Offset", offset); + } + + return m_content.getText(offset,length); + }//}}} + + //{{{ getText() + + public void getText(int offset, int length, Segment txt) throws BadLocationException { + + if (offset < 0 || length < 0 || offset + length > m_content.getLength()) { + //TODO: fix error messages + throw new BadLocationException("insertString(): Bad Offset", offset); + } + + m_content.getText(offset, length, txt); + }//}}} + + //{{{ insertString() + /** + * <p>Inserts a string of content. This will cause a DocumentEvent of type + * DocumentEvent.EventType.INSERT to be sent to the registered + * DocumentListers, unless an exception is thrown. The DocumentEvent will + * be delivered by calling the insertUpdate method on the + * DocumentListener. The offset and length of the generated DocumentEvent + * will indicate what change was actually made to the Document.</p> + * + * <p>If the Document structure changed as result of the insertion, the + * details of what Elements were inserted and removed in response to the + * change will also be contained in the generated DocumentEvent. It is up + * to the implementation of a Document to decide how the structure should + * change in response to an insertion.</p> + * + * <p>If the Document supports undo/redo, an UndoableEditEvent will also be + * generated.</p> + * @param offset the offset into the document to insert the content >= 0. + * All positions that track change at or after the given + * location will move. + * @param str the string to insert + * @param a the attributes to associate with the inserted content. + * This attribute is ignored by XMLDocuments. + */ + public void insertString(int offset, String str, AttributeSet a) throws BadLocationException { + if (offset < 0 || str.length() < 0 || offset + str.length() > m_content.getLength()) { + //TODO: fix error messages + throw new BadLocationException("insertString(): Bad Offset", offset); + } + + m_content.insert(offset, str); + + //TODO: document structure must change + //TODO: notify listeners + //TODO: implement undo + }//}}} + + //{{{ putProperty() + + public void putProperty(Object key, Object value) { + m_properties.put(key, value); + }//}}} + + //{{{ remove() + + public void remove(int offs, int len) throws BadLocationException { + if (offs < 0 || len < 0 || offs + len > m_content.getLength()) { + //TODO: fix error messages + throw new BadLocationException("insertString(): Bad Offset", offs); + } + + m_content.remove(offs, len); + + //TODO: document structure must change + //TODO: notify listeners + //TODO: implement undo + }//}}} + + //{{{ removeDocumentListener() + + public void removeDocumentListener(DocumentListener listener) { + if (listener != null) { + m_docListeners.remove(listener); + } + }//}}} + + //{{{ removeUndoableEditListener() + + public void removeUndoableEditListener(UndoableEditListener listener) { + if (listener != null) { + m_undoListeners.remove(listener); + } + }//}}} + + //{{{ render() + + public void render(Runnable r) { + //TODO: implement concurrency support. + }//}}} + + //}}} + + //{{{ Private members + + //{{{ ContentManager class + /** + * Text content manager based off of jEdit's ContentManager class. + */ + private static class ContentManager { + + // {{{ ContentManager constructor + public ContentManager() { + text = new char[1024]; + } //}}} + + //{{{ getLength() + + public final int getLength() { + return length; + } //}}} + + //{{{ getCharAt() + public char getCharAt(int start) { + if(start >= gapStart) { + return text[start + gapEnd - gapStart]; + } else { + if(start + 1 <= gapStart) { + return text[start]; + } else { + if (gapStart - start > 0) { + return text[start]; + } else { + return text[gapEnd + start - 1]; + } + } + } + }//}}} + + //{{{ getText() + public String getText(int start, int len) { + if(start >= gapStart) { + return new String(text,start + gapEnd - gapStart,len); + } else { + if(start + len <= gapStart) { + return new String(text,start,len); + } else { + return new String(text,start,gapStart - start).concat(new String(text,gapEnd,start + len - gapStart)); + } + } + } //}}} + + //{{{ getText() + public void getText(int start, int len, Segment seg) { + if(start >= gapStart) { + seg.array = text; + seg.offset = start + gapEnd - gapStart; + seg.count = len; + } else { + if(start + len <= gapStart) { + seg.array = text; + seg.offset = start; + seg.count = len; + } else { + seg.array = new char[len]; + + // copy text before gap + System.arraycopy(text,start,seg.array,0,gapStart - start); + + // copy text after gap + System.arraycopy(text,gapEnd,seg.array,gapStart - start, + len + start - gapStart); + + seg.offset = 0; + seg.count = len; + } + } + } //}}} + + //{{{ insert() + public void insert(int start, String str) { + int len = str.length(); + moveGapStart(start); + + if(gapEnd - gapStart < len) { + ensureCapacity(length + len + 1024); + moveGapEnd(start + len + 1024); + } + + str.getChars(0,len,text,start); + gapStart += len; + length += len; + } //}}} + + //{{{ insert() + public void insert(int start, Segment seg) { + moveGapStart(start); + + if(gapEnd - gapStart < seg.count) { + ensureCapacity(length + seg.count + 1024); + moveGapEnd(start + seg.count + 1024); + } + + System.arraycopy(seg.array,seg.offset,text,start,seg.count); + gapStart += seg.count; + length += seg.count; + } //}}} + + //{{{ _setContent() + public void _setContent(char[] text, int length) { + this.text = text; + this.gapStart = this.gapEnd = 0; + this.length = length; + } //}}} + + //{{{ remove() + public void remove(int start, int len) { + moveGapStart(start); + gapEnd += len; + length -= len; + } //}}} + + //{{{ Private members + private char[] text; + private int gapStart = 0; + private int gapEnd = 0; + private int length = 0; + + private void moveGapStart(int newStart) {//{{{ + int newEnd = gapEnd + (newStart - gapStart); + + if(newStart == gapStart) { + // nothing to do + } else { + if(newStart > gapStart) { + System.arraycopy(text,gapEnd,text,gapStart, newStart - gapStart); + } else { + if(newStart < gapStart) { + System.arraycopy(text,newStart,text,newEnd, gapStart - newStart); + } + } + } + + gapStart = newStart; + gapEnd = newEnd; + } //}}} + + private void moveGapEnd(int newEnd) {//{{{ + System.arraycopy(text,gapEnd,text,newEnd,length - gapStart); + gapEnd = newEnd; + } //}}} + + private void ensureCapacity(int capacity) {//{{{ + + if(capacity >= text.length) { + char[] textN = new char[capacity * 2]; + System.arraycopy(text,0,textN,0,length + (gapEnd - gapStart)); + text = textN; + } + + } //}}} + + //}}} + }//}}} + + //{{{ ContentManagerWriter class + /** + * Character Stream used to write to the content manager when + * serialized. Used when syncing the source with the current Document. + */ + private static class ContentManagerWriter extends Writer { + + //{{{ ContentManagerWriter constructor + public ContentManagerWriter(ContentManager content) { + m_m_content = content; + }//}}} + + //{{{ write() + public void write(char[] cbuf) throws IOException { + if (m_m_closed) { + throw new IOException("ContentManagerWriter is closed"); + } + m_m_content.insert(m_m_content.getLength(), new String(cbuf)); + }//}}} + + //{{{ write() + public void write(char[] cbuf, int off, int len) throws IOException { + if (m_m_closed) { + throw new IOException("ContentManagerWriter is closed"); + } + m_m_content.insert(m_m_content.getLength(), new String(cbuf, off, len)); + }//}}} + + //{{{ write() + public void write(int b) throws IOException { + if (m_m_closed) { + throw new IOException("ContentManagerWriter is closed"); + } + char []carray = { (char)b }; + m_m_content.insert(m_m_content.getLength(), new String(carray)); + }//}}} + + //{{{ write() + public void write(String str) throws IOException { + if (m_m_closed) { + throw new IOException("ContentManagerWriter is closed"); + } + m_m_content.insert(m_m_content.getLength(), str); + }//}}} + + //{{{ flush() + public void flush() throws IOException { + if (m_m_closed) { + throw new IOException("ContentManagerWriter is closed"); + } + //writes happen immediately so this does nothing. + }//}}} + + //{{{ close() + public void close() { + //honoring the contract for Writer class + m_m_closed = true; + }//}}} + + //{{{ Private members + private ContentManager m_m_content; + private boolean m_m_closed = false; + //}}} + }//}}} + + private org.w3c.dom.Document m_document; + + private ContentManager m_content; + + private HashMap m_properties = new HashMap(); + + private ArrayList m_docListeners = new ArrayList(); + private ArrayList m_undoListeners = new ArrayList(); + + //}}} + +} Copied: branches/jsxe2/src/net/sourceforge/jsxe/dom2/XMLElement.java (from rev 999, branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLElement.java) =================================================================== --- branches/jsxe2/src/net/sourceforge/jsxe/dom2/XMLElement.java (rev 0) +++ branches/jsxe2/src/net/sourceforge/jsxe/dom2/XMLElement.java 2006-07-07 23:54:05 UTC (rev 1000) @@ -0,0 +1,57 @@ +/* +XMLElement.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.dom2; + +//{{{ Imports +import org.w3c.dom.*; +import org.w3c.dom.events.*; +//}}} + +/** + * The XMLElement class represents an element in the XMLDocument tree. It allows + * attibute modifications which will translate to text modifications in the + * XMLDocument. + * @author Ian Lewis (<a href="mailto:Ian...@me...">Ian...@me...</a>) + * @version $Id$ + * @see XMLDocument + * @since jsXe 0.5 pre2 + */ +public class XMLElement extends XMLNode { + + //{{{ XMLElement constructor + /** + * Creates a new XMLElement + * @param element the element node that this node wraps. + */ + XMLElement(Element element) { + super(element); + }//}}} + + //{{{ getNodeType() + public int getNodeType() { + return Node.ELEMENT_NODE; + }//}}} + +} Copied: branches/jsxe2/src/net/sourceforge/jsxe/dom2/XMLNode.java (from rev 999, branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLNode.java) =================================================================== --- branches/jsxe2/src/net/sourceforge/jsxe/dom2/XMLNode.java (rev 0) +++ branches/jsxe2/src/net/sourceforge/jsxe/dom2/XMLNode.java 2006-07-07 23:54:05 UTC (rev 1000) @@ -0,0 +1,102 @@ +/* +XMLNode.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.dom2; + +//{{{ imports + +//{{{ jsXe classes +import net.sourceforge.jsxe.jsXe; +import net.sourceforge.jsxe.util.Log; +import net.sourceforge.jsxe.dom.completion.*; +//}}} + +//{{{ DOM classes +import org.w3c.dom.*; +import org.w3c.dom.events.*; +//}}} + +//}}} + +/** + * <p>The XMLNode class is meant to represent an XMLNode in a XMLDocument tree + * but also as a section of text within that document tree. It + * 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$ + * @see XMLDocument + * @since jsXe 0.5 pre2 + */ +public abstract class XMLNode /* implements javax.swing.text.Element */ { + + private static final String USER_DATA_KEY = "net.sourceforge.jsxe.dom.XMLNode"; + + //{{{ Private members + + /** + * The w3c Node that this node wraps. It must support the EventTarget + * interface in org.w3c.dom.events + */ + private Node m_domNode; + + //}}} + + //{{{ XMLNode constructor + XMLNode(Node node) { + m_domNode = node; + }//}}} + + //{{{ addEventListener() + public void addEventListener(java.lang.String type, EventListener listener, boolean useCapture) { + ((EventTarget)m_domNode).addEventListener(type, listener, useCapture); + }//}}} + + //{{{ removeEventListener() + public void removeEventListener(java.lang.String type, EventListener listener, boolean useCapture) { + ((EventTarget)m_domNode).removeEventListener(type, listener, useCapture); + }//}}} + + //{{{ appendNode() + public XMLNode appendChild(XMLNode newChild) { + + m_domNode.appendChild(newChild.getNode()); + + return newChild; + }//}}} + + //{{{ Protected Members + + //{{{ getNode() + protected Node getNode() { + return m_domNode; + }//}}} + + //}}} +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |