|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object
|
+--org.jdom.Document
|
+--net.sourceforge.spedit.core.XMLDocument
The XMLDocument class wraps a Swing Document
around a JDOM XML document. There is an article on the website that
describes how the design of this class was made, for further understanding
you should read the source code.
When using the XMLDocument API you should take great care
of the objects that you manipulate. Here are some points that should be
clear:
XMLNode interface,
there are currently only two types of wrappers :
XMLElementWrapper and XMLTextWrapper, which
respectively wrap JDOM Element and Text
nodes.TreeNode interface in
order to ease representation as in a JTree. This can lead to
some confusion as some methods may seem redundant. Do not worry in this
case sa you will always be able to cast to an XMLNode
interface.
| Inner Class Summary | |
static class |
XMLDocument.DocumentEvent
The DocumentEvent class represents a set of modifications
that have been done on the document. |
static class |
XMLDocument.ElementEdit
This class stores a single change made on an element of the document. |
static class |
XMLDocument.Position
Implements the Swing position interface in order to keep track of changes that occur in an XMLDocument. |
| Field Summary | |
protected GapContent |
content
|
protected Vector |
documentListeners
|
protected Position |
endPosition
|
protected Font |
font
|
protected static int |
GAP_LENGTH
|
static String |
PARSER
|
protected List |
positions
|
protected static int |
POSITIONS_THRESHOLD
|
protected Hashtable |
properties
|
protected Element[] |
roots
|
static org.jdom.input.SAXBuilder |
saxBuilder
|
protected Position |
startPosition
|
protected Vector |
treeModelListeners
|
protected Vector |
undoableEditListeners
|
static org.jdom.input.JDOMFactory |
xmlFactory
|
static org.jdom.output.XMLOutputter |
xmlOutputter
|
| Fields inherited from class org.jdom.Document |
docType |
| Fields inherited from interface javax.swing.text.Document |
StreamDescriptionProperty, TitleProperty |
| Constructor Summary | |
XMLDocument()
Creates a new blank XMLDocument. |
|
XMLDocument(org.jdom.Element rootElement)
Creates a new XMLDocument with the given
rootElement as a root node. |
|
XMLDocument(org.jdom.Element rootElement,
org.jdom.DocType docType)
Creates a new XMLDocument with the given
rootElement as a root node, with the specified document
type. |
|
| Method Summary | |
void |
addDocumentListener(DocumentListener dl)
|
Style |
addStyle(String nm,
Style parent)
|
void |
addTreeModelListener(TreeModelListener l)
Adds a listener for the TreeModelEvent posted after the tree changes. |
void |
addUndoableEditListener(UndoableEditListener ul)
|
protected org.jdom.Element |
convertElement(org.jdom.Element e)
Converts the given element into a natural JDOM element. |
org.jdom.Document |
convertToJDOM()
Generates a natural JDOM document. |
Position |
createBackwardPosition(int n)
|
Position |
createForwardPosition(int n)
|
Position |
createPosition(int n)
|
protected void |
filter(org.jdom.Element element,
XMLViewFactory factory)
Filters the given element recursively. |
void |
filter(XMLViewFactory factory)
Filters the given document, removing text nodes that contain no characters. |
protected void |
fireDocumentEvent(XMLDocument.DocumentEvent evt)
|
Color |
getBackground(AttributeSet attr)
|
Element |
getCharacterElement(int pos)
|
Object |
getChild(Object parent,
int index)
Returns the child of parent at index index in the parent's child array. |
int |
getChildCount(Object parent)
Returns the number of children of parent. |
Element |
getDefaultRootElement()
Returns the default root element of the document. |
Element |
getElementAt(int offset)
Search the Swing Element which is located at the specified position. |
Position |
getEndPosition()
|
Font |
getFont(AttributeSet attr)
|
Color |
getForeground(AttributeSet attr)
|
int |
getIndexOfChild(Object parent,
Object child)
Returns the index of child in parent. |
int |
getLength()
|
Style |
getLogicalStyle(int p)
|
Element |
getParagraphElement(int offset)
Returns the XMLElement that contains the specified offset.
|
Object |
getProperty(Object key)
|
Object |
getRoot()
Returns the root of the tree. |
Element[] |
getRootElements()
Returns an array of elements which only contains the default document root. |
Position |
getStartPosition()
|
Style |
getStyle(String nm)
|
String |
getText(int offset,
int length)
|
void |
getText(int offset,
int length,
Segment s)
Fetches the text contained within the given portion of the document. |
GapContent |
getTextContent()
Returns the Content object that represents the text
contained in this document. |
protected void |
init()
Initializes the XMLDocument. |
void |
insertElement(XMLElement element,
int offset)
Prepends the element at the given offset in the text. |
void |
insertString(int offset,
String text,
AttributeSet attrs)
Prepends the given string at the given offset in the text. |
protected boolean |
isGarbage(XMLText elt)
Tells wether or not the given element is a garbage element. |
boolean |
isLeaf(Object node)
Returns true if node is a leaf. |
static XMLDocument |
loadFromFile(File file,
XMLViewFactory fact)
Loads the given file and tries to generate an XMLDocument instance from its content. |
void |
putProperty(Object key,
Object value)
|
void |
remove(int start,
int end)
|
void |
removeDocumentListener(DocumentListener dl)
|
Object |
removeProperty(Object key)
|
void |
removeStyle(String nm)
|
void |
removeTreeModelListener(TreeModelListener l)
Removes a listener previously added with addTreeModelListener(). |
void |
removeUndoableEditListener(UndoableEditListener ul)
|
void |
render(Runnable renderer)
|
void |
saveToFile(File file)
Saves the current XMLDocument into the given file. |
void |
setCharacterAttributes(int offset,
int length,
AttributeSet s,
boolean replace)
|
void |
setLogicalStyle(int pos,
Style s)
|
void |
setParagraphAttributes(int offset,
int length,
AttributeSet s,
boolean replace)
|
org.jdom.Document |
setRootElement(org.jdom.Element elem)
|
String |
toString()
Returns a string rtpresenting the XML contained in this document. |
void |
updatePositions(int offset,
int length)
Update all the position objects registered inside the document. |
void |
valueForPathChanged(TreePath path,
Object newValue)
Messaged when the user has altered the value for the item identified by path to newValue. |
protected void |
writeLock()
|
protected void |
writeUnlock()
|
| Methods inherited from class org.jdom.Document |
addContent, addContent, clone, equals, getContent, getDocType, getMixedContent, getProcessingInstruction, getProcessingInstructions, getProcessingInstructions, getRootElement, getSerializedForm, hashCode, removeContent, removeContent, removeProcessingInstruction, removeProcessingInstructions, setContent, setDocType, setMixedContent, setProcessingInstructions |
| Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
public static final String PARSER
public static final org.jdom.input.SAXBuilder saxBuilder
public static final org.jdom.output.XMLOutputter xmlOutputter
public static final org.jdom.input.JDOMFactory xmlFactory
protected static final int POSITIONS_THRESHOLD
protected static final int GAP_LENGTH
protected Element[] roots
protected Vector documentListeners
protected Vector undoableEditListeners
protected Vector treeModelListeners
protected Hashtable properties
protected List positions
protected GapContent content
protected Position startPosition
protected Position endPosition
protected Font font
| Constructor Detail |
public XMLDocument()
XMLDocument.public XMLDocument(org.jdom.Element rootElement)
XMLDocument with the given
rootElement as a root node.rootElement - the root node of this
XMLDocument.
public XMLDocument(org.jdom.Element rootElement,
org.jdom.DocType docType)
Creates a new XMLDocument with the given
rootElement as a root node, with the specified document
type. This constructor is not really useful, you should not use it as
no consistency check is made with the given doctype.
This constructor is provided for JDOMFactory
consistency purposes.
rootElement - the root node of this
XMLDocument.docType - the root node of this
XMLDocument.| Method Detail |
protected void init()
XMLDocument. It should not be called after
document creation. This method is present to provide a common
initialization facility for the various constructors, which is a
technique cleaner that this(...) calls, as I allows
super(...) constructor calls with more paramters.
public static XMLDocument loadFromFile(File file,
XMLViewFactory fact)
Loads the given file and tries to generate an
XMLDocument instance from its content. This method returns
a new XMLDocument in case of success, or of course
null in case of failure.
If an exception occurs, it will be dumped on stderr.
file - Is the XML source file to be loadedfact - Is the XMLViewFactory used to filter the element
contents. It can be set to null.
public void saveToFile(File file)
throws IOException
Saves the current XMLDocument into the given file. If
an exception it will be thrown.
public org.jdom.Document convertToJDOM()
Generates a natural JDOM document. A natural JDOM document means
a document that does not have the fancy elements, such as
XMLText elements as children. Actually an XMLDocument can
not really be used "as is" with the JDOM facilities, you first have to
convert it using this method.
Note that if you plan to customize the XMLElement
content you should extend the convertElement
behaviour.
convertElement(org.jdom.Element)protected org.jdom.Element convertElement(org.jdom.Element e)
XMLText elements by strings added to the
new element using the addContent method of the
org.jdom.Element.e - The elements that will serve as a clone model for
the return value.public void filter(XMLViewFactory factory)
Filters the given document, removing text nodes that contain no characters. Those strings are always present inside an XML document that you have just loaded. This method should only be called when the document content has been (re)set.
In addition to that the filter looks in the given factory for information on how to filter element textual content, which can be for example stripping of leading and trailing spaces.
factory - The factory from which the information will be extracted.
protected void filter(org.jdom.Element element,
XMLViewFactory factory)
element - the element to filter.factory - the factory from which filtering information can be
found.protected boolean isGarbage(XMLText elt)
elt - The XMLText element to analyze.
This only applies to this kind of elements as they are the only
susceptible to contain only text in the XMLDocument model.
public void insertElement(XMLElement element,
int offset)
element - is the element that will be inserted.offset - is the offset of the insertion point in the
text.public Element getDefaultRootElement()
XMLDocument, there is a always a single root.getDefaultRootElement in interface Documentpublic Element[] getRootElements()
getRootElements in interface Documentpublic org.jdom.Document setRootElement(org.jdom.Element elem)
setRootElement in class org.jdom.Documentpublic Element getParagraphElement(int offset)
XMLElement that contains the specified offset.
The name of this method is a little bit abusive, as the actual
XMLElement may not a be a paragraph element, but
this is provided to conform to the Swing document interface.getParagraphElement in interface StyledDocumentpublic Element getElementAt(int offset)
offset - The offset in the text, starting at 0, ending
at document.getLength(), exclusive.Element or null if the position is
out of the document bounds.public void addDocumentListener(DocumentListener dl)
addDocumentListener in interface Documentpublic void removeDocumentListener(DocumentListener dl)
removeDocumentListener in interface Documentpublic void addUndoableEditListener(UndoableEditListener ul)
addUndoableEditListener in interface Documentpublic void removeUndoableEditListener(UndoableEditListener ul)
removeUndoableEditListener in interface Documentpublic Object getProperty(Object key)
getProperty in interface Document
public void putProperty(Object key,
Object value)
putProperty in interface Documentpublic Object removeProperty(Object key)
public void remove(int start,
int end)
remove in interface Document
public void insertString(int offset,
String text,
AttributeSet attrs)
insertString in interface Documentoffset - the offset at which text will be prepended.text - the text to be inserted.attrs - the attributes that will be merged (but will
never override the attributes already defined in the parent).
Important: these attributes must be XMLAttributes
to work.
public String getText(int offset,
int length)
throws BadLocationException
getText in interface Document
public void getText(int offset,
int length,
Segment s)
throws BadLocationException
getText in interface Documentpublic int getLength()
getLength in interface Documentpublic Position getStartPosition()
getStartPosition in interface Documentpublic Position getEndPosition()
getEndPosition in interface Documentpublic Position createPosition(int n)
createPosition in interface Documentpublic Position createBackwardPosition(int n)
public Position createForwardPosition(int n)
public GapContent getTextContent()
Content object that represents the text
contained in this document.public void render(Runnable renderer)
render in interface Documentprotected void writeLock()
protected void writeUnlock()
public Style addStyle(String nm,
Style parent)
addStyle in interface StyledDocumentpublic Style getStyle(String nm)
getStyle in interface StyledDocumentpublic void removeStyle(String nm)
removeStyle in interface StyledDocumentpublic Element getCharacterElement(int pos)
getCharacterElement in interface StyledDocumentpublic Color getBackground(AttributeSet attr)
getBackground in interface StyledDocumentpublic Font getFont(AttributeSet attr)
getFont in interface StyledDocumentpublic Color getForeground(AttributeSet attr)
getForeground in interface StyledDocumentpublic Style getLogicalStyle(int p)
getLogicalStyle in interface StyledDocument
public void setCharacterAttributes(int offset,
int length,
AttributeSet s,
boolean replace)
setCharacterAttributes in interface StyledDocument
public void setLogicalStyle(int pos,
Style s)
setLogicalStyle in interface StyledDocument
public void setParagraphAttributes(int offset,
int length,
AttributeSet s,
boolean replace)
setParagraphAttributes in interface StyledDocumentpublic Object getRoot()
getRoot in interface TreeModel
public Object getChild(Object parent,
int index)
getChild in interface TreeModelpublic int getChildCount(Object parent)
getChildCount in interface TreeModelparent - a node in the tree, obtained from this data sourcepublic boolean isLeaf(Object node)
isLeaf in interface TreeModelnode - a node in the tree, obtained from this data source
public void valueForPathChanged(TreePath path,
Object newValue)
valueForPathChanged in interface TreeModelpath - path to the node that the user has altered.newValue - the new value from the TreeCellEditor.
public int getIndexOfChild(Object parent,
Object child)
getIndexOfChild in interface TreeModelpublic void addTreeModelListener(TreeModelListener l)
addTreeModelListener in interface TreeModell - the listener to addremoveTreeModelListener(javax.swing.event.TreeModelListener)public void removeTreeModelListener(TreeModelListener l)
removeTreeModelListener in interface TreeModell - the listener to removeaddTreeModelListener(javax.swing.event.TreeModelListener)protected void fireDocumentEvent(XMLDocument.DocumentEvent evt)
public String toString()
toString in class org.jdom.Document
public void updatePositions(int offset,
int length)
XMLDocument. It is called by the
fire method of DocumentEvent.ElementChange
objects.offset - is the offset where the changed has occured
in the document. offset >=0length - indicates the length of the change. If
length>0 then the change is an insertion of
length characters from offset.length <= 0 then the change is interpreted
as a deletion of lenght characters starting at
offset.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||