java.lang.Object
org.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.
|
Constructor Summary |
XmlModel(int undoLevels)
Constructor. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
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
XmlModel
public XmlModel(int undoLevels)
- Constructor. By default, this will create an empty file in text mode.
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()