[Jsxe-cvs] SF.net SVN: jsxe: [893] branches/jsxe2/src/net/sourceforge/jsxe
Status: Inactive
Brought to you by:
ian_lewis
From: <ian...@us...> - 2006-06-02 03:27:05
|
Revision: 893 Author: ian_lewis Date: 2006-06-01 20:26:57 -0700 (Thu, 01 Jun 2006) ViewCVS: http://svn.sourceforge.net/jsxe/?rev=893&view=rev Log Message: ----------- Updated the listener event model to make use of the new document listeners which now support insert and remove updates. Modified Paths: -------------- branches/jsxe2/src/net/sourceforge/jsxe/DocumentBuffer.java branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLDocument.java branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLDocumentListener.java Modified: branches/jsxe2/src/net/sourceforge/jsxe/DocumentBuffer.java =================================================================== --- branches/jsxe2/src/net/sourceforge/jsxe/DocumentBuffer.java 2006-06-01 04:21:50 UTC (rev 892) +++ branches/jsxe2/src/net/sourceforge/jsxe/DocumentBuffer.java 2006-06-02 03:26:57 UTC (rev 893) @@ -481,6 +481,35 @@ super.fireStructureChanged(location); }//}}} + //{{{ DocumentBufferResolver class + /** + * <p>The DocumentBufferResolver class is the default class that is used + * for resolving external entities in documents that jsXe is editing. + * It implements caching external entities to the local disk and finding + * the cached version later for faster retrieval.</p> + * <p>The external entities are searched for in locations relative to the + * opened document or if they are URLs then they are retrieved from the + * network resource.</p> + * @author Ian Lewis (<a href="mailto:Ian...@me...">Ian...@me...</a>) + * @since jsXe 0.5 pre1 + */ + public class DocumentBufferResolver implements EntityResolver { + + //{{{ resolveEntity() + public InputSource resolveEntity(String publicId, String systemId) throws SAXException { + try { + if (isUntitled()) { + return CatalogManager.resolve(null, publicId, systemId); + } else { + return CatalogManager.resolve(getFile().toURI().toString(), publicId, systemId); + } + } catch (Exception e) { + throw new SAXException(e); + } + }//}}} + + }//}}} + //{{{ Private members //{{{ setDirty() @@ -830,56 +859,6 @@ } }//}}} - //{{{ DocumentBufferResolver class - - private class DocumentBufferResolver implements EntityResolver { - - //{{{ resolveEntity() - - public InputSource resolveEntity(String publicId, String systemId) throws SAXException { - - // String entity = systemId; - // InputSource source = null; - // - // if (m_file != null) { - // - // try { - // String filePathURI = m_file.toURL().toExternalForm(); - // int index = filePathURI.lastIndexOf("/")+1; - // if (index != -1) { - // filePathURI = filePathURI.substring(0, index); - // } - // - // index = entity.lastIndexOf("/")+1; - // if (index != -1) { - // entity = entity.substring(index); - // } - // - // //create the path to the entity relative to the document - // filePathURI += entity; - // source = new InputSource((new URL(filePathURI)).openStream()); - // - // } catch (MalformedURLException e) { - // //Do nothing and try to open this entity normally - // } catch (IOException e) { - // //Probobly file not found. - // //Do nothing and try to open this entity normally - // } - // } - // return source; - try { - if (isUntitled()) { - return CatalogManager.resolve(null, publicId, systemId); - } else { - return CatalogManager.resolve(getFile().toURI().toString(), publicId, systemId); - } - } catch (Exception e) { - throw new SAXException(e); - } - }//}}} - - }//}}} - private String m_name; private File m_file; private ArrayList m_listeners = new ArrayList(); Modified: branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLDocument.java =================================================================== --- branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLDocument.java 2006-06-01 04:21:50 UTC (rev 892) +++ branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLDocument.java 2006-06-02 03:26:57 UTC (rev 893) @@ -36,6 +36,7 @@ import net.sourceforge.jsxe.util.Log; import net.sourceforge.jsxe.util.MiscUtilities; import net.sourceforge.jsxe.dom.completion.*; +import net.sourceforge.jsxe.dom.event.*; //}}} //{{{ DOM classes @@ -81,6 +82,9 @@ * @version $Id$ * @see AdapterNode */ + /* + TODO: XMLDocument should extend AdapterNode + */ public class XMLDocument { //{{{ XMLDocument defined properties @@ -271,27 +275,27 @@ }//}}} //{{{ getDocumentCopy() - /** - * Gets a copy of the underlying Document object. - * @return a deep copy of the underlying document object - */ - public Document getDocumentCopy() { - //makes a deep copy of the document node - try { - checkWellFormedness(); - } catch (SAXParseException e) { - } catch (SAXException e) { - } catch (ParserConfigurationException e) { - } catch (IOException e) { - //If an error occurs then we're in trouble - jsXe.exiterror(this, e, 1); - } - if (m_document != null) { - return (Document)m_document.cloneNode(true); - } else { - return null; - } - }//}}} + // /** + // * Gets a copy of the underlying Document object. + // * @return a deep copy of the underlying document object + // */ + // public Document getDocumentCopy() { + // //makes a deep copy of the document node + // try { + // checkWellFormedness(); + // } catch (SAXParseException e) { + // } catch (SAXException e) { + // } catch (ParserConfigurationException e) { + // } catch (IOException e) { + // //If an error occurs then we're in trouble + // jsXe.exiterror(this, e, 1); + // } + // if (m_document != null) { + // return (Document)m_document.cloneNode(true); + // } else { + // return null; + // } + // }//}}} //{{{ getDocType() /** @@ -407,7 +411,7 @@ */ public AdapterNode newAdapterNode(AdapterNode parent, String name, String value, short type) { Node newNode = null; - + //TODO: creating adapter nodes needs to be reworked. //Only handle text and element nodes right now. switch(type) { case Node.ELEMENT_NODE: @@ -721,6 +725,7 @@ String value = null; try { LSSerializer serializer = getSerializer(); + //TODO: this call to writeToString() should change value = serializer.writeToString(node.getNode()); } catch (DOMException e) {} return value; @@ -771,7 +776,7 @@ m_adapterNode = null; //may have some algorithm to determine the modified node(s) in the //future - fireStructureChanged(null); + fireInsert(offset, text); } }//}}} @@ -785,12 +790,13 @@ public void removeText(int offset, int length) throws IOException { if (length > 0) { syncContentWithDOM(); + String text = getText(offset, length); m_content.remove(offset, length); m_parsedMode = false; m_adapterNode = null; //may have some algorithm to determine the modified node(s) in the //future - fireStructureChanged(null); + fireRemove(offset, text); } }//}}} @@ -993,6 +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 */ protected void fireStructureChanged(AdapterNode location) { ListIterator iterator = listeners.listIterator(); @@ -1003,6 +1010,38 @@ m_syncedWithContent = false; }//}}} + //{{{ fireInsert() + /** + * Called when the a text insert into the document has been made. This + * can occur when structural changes have been made as well, such as a + * node insertion. + * @param offset the offset into the document where the text was inserted + * @param text the text that was inserted + */ + protected void fireInsert(int offset, String text) { + ListIterator iterator = listeners.listIterator(); + while (iterator.hasNext()) { + XMLDocumentListener listener = (XMLDocumentListener)iterator.next(); + listener.insertUpdate(new XMLDocumentInsertEvent(this, offset, text)); + } + }//}}} + + //{{{ fireRemove() + /** + * Called when text is removed from the document. This + * can occur when structural changes have been made as well, such as a + * node removal. + * @param offset the offset into the document where the text was inserted + * @param text the text that was inserted + */ + protected void fireRemove(int offset, String text) { + ListIterator iterator = listeners.listIterator(); + while (iterator.hasNext()) { + XMLDocumentListener listener = (XMLDocumentListener)iterator.next(); + listener.removeUpdate(new XMLDocumentRemoveEvent(this, offset, text)); + } + }//}}} + //{{{ getCompletionInfoMappings() /** * Gets the namespace uri to CompletionInfo Mappings for this document. @@ -1047,6 +1086,9 @@ * Write the DOM to the content manager given the current serialization and * formatting options. */ + /* + TODO: update serialization + */ private void syncContentWithDOM() { if (m_parsedMode) { if (!m_syncedWithContent) { @@ -1128,6 +1170,9 @@ * m_adapterNode and m_parsedMode must be updated. * @since jsXe 0.4 pre1 */ + /* + * TODO: Update parsing + */ public void parseDocument() throws SAXParseException, SAXException, ParserConfigurationException, IOException { Log.log(Log.MESSAGE, this, (m_uri != null ? "Parsing Document: "+m_uri.toString() : "Parsing Document")); Modified: branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLDocumentListener.java =================================================================== --- branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLDocumentListener.java 2006-06-01 04:21:50 UTC (rev 892) +++ branches/jsxe2/src/net/sourceforge/jsxe/dom/XMLDocumentListener.java 2006-06-02 03:26:57 UTC (rev 893) @@ -24,16 +24,20 @@ package net.sourceforge.jsxe.dom; + /** * XMLDocumentListener is used to notify objects of a change to the XMLDocument. + * 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 pre1 * @see XMLDocument */ public interface XMLDocumentListener { //{{{ propertyChanged() - /** * Called when a property associated with the XMLDocument has changed. * @param source The source XMLDocument @@ -43,7 +47,6 @@ public void propertyChanged(XMLDocument source, String key, String oldValue);//}}} //{{{ structureChanged() - /** * Called when the structure of the XMLDocument has changed. * @param source The source XMLDocument @@ -51,7 +54,34 @@ * If a node was removed then this is the parent of the * node that was removed. This could be null if the location * is unknown. + * @deprecated insertUpdate and removeUpdate will be used instead. */ public void structureChanged(XMLDocument source, AdapterNode location);//}}} + //{{{ insertUpdate() + /** + * Called when text is inserted into the XML document. This will called + * whenever text is inserted into the document via a normal text update or + * a change to the document structure, such as a node insertion. + * @param event the document update event. + */ + public void insertUpdate(XMLDocumentEvent event);//}}} + + //{{{ removeUpdate() + /** + * Called when text is removed from the document. This will be whenever + * text is removed directly or when a change to the document structure is + * made such as a node is removal. + * @param event the document update event. + */ + public void removeUpdate(XMLDocumentEvent event);//}}} + + //{{{ changeUpdate() + /** + * Called when a part of the XMLDocument is changed in some way. This may + * occur with changes to properties or attributes within the document + * structure. + * @param event the document update event. + */ + public void changeUpdate(XMLDocumentEvent event);//}}} } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |