Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.outerj.pollo.xmleditor.model
Class XmlModel  view XmlModel download XmlModel.java

java.lang.Object
  extended byorg.outerj.pollo.xmleditor.model.XmlModel

public class XmlModel
extends java.lang.Object

In-memory representation of an XML file. The XML file can be in two formats: as a DOM-tree ('parsed mode'), or as XmlTextDocument ('text mode'). All views on the XmlModel should reflect this, they should be all in parsed mode or text mode. This class also has methods for loading and storing the file. There are some utility functions for searching namespace declarations and getting nodes using xpath expressions.


Nested Class Summary
 class XmlModel.TextDocumentModifiedListener
           
 
Field Summary
protected  org.w3c.dom.Document domDocument
           
protected  java.io.File file
           
static int FILE_CHANGED
           
static int FILE_SAVED
           
static int FILENAME_CHANGED
           
static int LAST_VIEW_CLOSED
           
protected  int mode
           
protected  boolean modified
           
protected  boolean modifiedWhileInTextMode
           
static int PARSED_MODE
           
protected  java.util.ArrayList registeredViewsList
           
static int SWITCH_TO_PARSED_MODE
           
static int SWITCH_TO_TEXT_MODE
           
static int TEXT_MODE
           
protected  org.outerj.pollo.texteditor.XmlTextDocument textDocument
           
protected  XmlModel.TextDocumentModifiedListener textModifiedListener
           
protected  Undo undo
           
protected static int untitledCount
           
protected  int untitledNumber
           
protected  java.util.ArrayList xmlModelListeners
           
 
Constructor Summary
XmlModel(int undoLevels)
          Constructor.
 
Method Summary
 void addListener(XmlModelListener listener)
           
 boolean askToSave(java.awt.Component parent)
           
 boolean closeAllViews(java.awt.Component parent)
           
 boolean closeView(View view)
           
 org.apache.xml.serialize.OutputFormat createOutputFormat()
           
 java.lang.String findDefaultNamespace(org.w3c.dom.Element element)
          Finds a default namespace declaration.
 java.util.HashMap findNamespaceDeclarations(org.w3c.dom.Element element)
          Returns a list of all the namespace prefixes that are known in the given context.
 java.lang.String findNamespaceForPrefix(org.w3c.dom.Element element, java.lang.String prefix)
          Finds the namespace with which the prefix is associated, or null if not found.
 java.lang.String findPrefixForNamespace(org.w3c.dom.Element element, java.lang.String ns)
          Finds a prefix declaration for the given namespace, or null if not found.
 int getCurrentMode()
           
 org.w3c.dom.Document getDocument()
           
 java.io.File getFile()
           
 java.lang.String getLongTitle()
           
 org.w3c.dom.Element getNextElementSibling(org.w3c.dom.Element element)
           
 org.w3c.dom.Element getNode(java.lang.String xpathExpr)
           
 java.lang.String getShortTitle()
           
 org.outerj.pollo.texteditor.XmlTextDocument getTextDocument()
           
 java.lang.String getTextDocumentText()
          Returns the contents of the text document as a String.
 Undo getUndo()
           
 boolean isInParsedMode()
           
 boolean isInTextMode()
           
 boolean isModified()
           
 void markModified()
           
 void notify(int eventtype)
           
 void readFromResource(java.io.File file)
           
 void readFromResource(org.xml.sax.InputSource inputSource, java.io.File file)
          Reades the xml document given by the inputSource.
 void registerView(View view)
           
 void removeListener(XmlModelListener listener)
           
 void save(java.awt.Component parent)
           
 void saveAs(java.awt.Component parent)
           
 void setFeatures(PolloDOMParser parser)
           
 void setModifiedWhileInTextMode(boolean modified)
          When set to true, the document will be reparsed when switching to parsed mode, otherwise not.
 void setTextDocumentText(java.lang.String text)
          Sets the text of the textdocument.
 void store()
           
 void store(java.lang.String filename)
           
 void switchToParsedMode()
           
 void switchToTextMode()
           
 java.lang.String toXMLString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PARSED_MODE

public static final int PARSED_MODE
See Also:
Constant Field Values

TEXT_MODE

public static final int TEXT_MODE
See Also:
Constant Field Values

domDocument

protected org.w3c.dom.Document domDocument

textDocument

protected org.outerj.pollo.texteditor.XmlTextDocument textDocument

mode

protected int mode

file

protected java.io.File file

undo

protected Undo undo

registeredViewsList

protected java.util.ArrayList registeredViewsList

xmlModelListeners

protected java.util.ArrayList xmlModelListeners

modified

protected boolean modified

modifiedWhileInTextMode

protected boolean modifiedWhileInTextMode

textModifiedListener

protected XmlModel.TextDocumentModifiedListener textModifiedListener

untitledCount

protected static int untitledCount

untitledNumber

protected int untitledNumber

FILENAME_CHANGED

public static final int FILENAME_CHANGED
See Also:
Constant Field Values

LAST_VIEW_CLOSED

public static final int LAST_VIEW_CLOSED
See Also:
Constant Field Values

FILE_CHANGED

public static final int FILE_CHANGED
See Also:
Constant Field Values

FILE_SAVED

public static final int FILE_SAVED
See Also:
Constant Field Values

SWITCH_TO_TEXT_MODE

public static final int SWITCH_TO_TEXT_MODE
See Also:
Constant Field Values

SWITCH_TO_PARSED_MODE

public static final int SWITCH_TO_PARSED_MODE
See Also:
Constant Field Values
Constructor Detail

XmlModel

public XmlModel(int undoLevels)
Constructor. By default, this will create an empty file in text mode.

Method Detail

readFromResource

public void readFromResource(org.xml.sax.InputSource inputSource,
                             java.io.File file)
                      throws java.lang.Exception
Reades the xml document given by the inputSource. File is an optional parameter that is used for saving the document and displaying the file name to the user. It may be null, in wich case the document will be shown as 'Untitled'. By default, the document will be parsed and hence the XmlModel will be in parsed mode. If parsing fails, the XmlModel will be in text mode. The inputstream provided by the InputSource must be closed by the caller.


readFromResource

public void readFromResource(java.io.File file)
                      throws java.lang.Exception

setFeatures

public void setFeatures(PolloDOMParser parser)
                 throws java.lang.Exception

getDocument

public org.w3c.dom.Document getDocument()

getTextDocument

public org.outerj.pollo.texteditor.XmlTextDocument getTextDocument()

setTextDocumentText

public void setTextDocumentText(java.lang.String text)
Sets the text of the textdocument.


setModifiedWhileInTextMode

public void setModifiedWhileInTextMode(boolean modified)
When set to true, the document will be reparsed when switching to parsed mode, otherwise not.


getTextDocumentText

public java.lang.String getTextDocumentText()
Returns the contents of the text document as a String.


store

public void store(java.lang.String filename)
           throws java.lang.Exception

store

public void store()
           throws java.lang.Exception

createOutputFormat

public org.apache.xml.serialize.OutputFormat createOutputFormat()

toXMLString

public java.lang.String toXMLString()
                             throws java.lang.Exception

getNextElementSibling

public org.w3c.dom.Element getNextElementSibling(org.w3c.dom.Element element)

findNamespaceForPrefix

public java.lang.String findNamespaceForPrefix(org.w3c.dom.Element element,
                                               java.lang.String prefix)
Finds the namespace with which the prefix is associated, or null if not found.


findPrefixForNamespace

public java.lang.String findPrefixForNamespace(org.w3c.dom.Element element,
                                               java.lang.String ns)
Finds a prefix declaration for the given namespace, or null if not found.


findNamespaceDeclarations

public java.util.HashMap findNamespaceDeclarations(org.w3c.dom.Element element)
Returns a list of all the namespace prefixes that are known in the given context.


findDefaultNamespace

public java.lang.String findDefaultNamespace(org.w3c.dom.Element element)
Finds a default namespace declaration.


getNode

public org.w3c.dom.Element getNode(java.lang.String xpathExpr)

getUndo

public Undo getUndo()

getFile

public java.io.File getFile()

getShortTitle

public java.lang.String getShortTitle()

getLongTitle

public java.lang.String getLongTitle()

switchToParsedMode

public void switchToParsedMode()
                        throws java.lang.Exception

switchToTextMode

public void switchToTextMode()
                      throws java.lang.Exception

getCurrentMode

public int getCurrentMode()

isInParsedMode

public boolean isInParsedMode()

isInTextMode

public boolean isInTextMode()

markModified

public void markModified()

registerView

public void registerView(View view)

addListener

public void addListener(XmlModelListener listener)

removeListener

public void removeListener(XmlModelListener listener)

closeView

public boolean closeView(View view)
                  throws java.lang.Exception

notify

public void notify(int eventtype)

save

public void save(java.awt.Component parent)
          throws java.lang.Exception

saveAs

public void saveAs(java.awt.Component parent)
            throws java.lang.Exception

closeAllViews

public boolean closeAllViews(java.awt.Component parent)
                      throws java.lang.Exception

askToSave

public boolean askToSave(java.awt.Component parent)
                  throws java.lang.Exception

isModified

public boolean isModified()