All Packages Class Hierarchy This Package Previous Next Index
Class jumbo.xml.XNode
java.lang.Object
|
+----com.sun.java.swing.tree.DefaultMutableTreeNode
|
+----jumbo.xml.XNode
- public class XNode
- extends DefaultMutableTreeNode
the workhorse of jumbo.xml. Most of the operations are done on XNodes or
relate to the context of XNodes. XNodes inherit a large number of valuable
methods from DefaultMutableTreeNode (e.g. navigation, node structure, etc.)
, and you may wish to study this carefully.
All SAX-retained components of an XML document are XNodes (including
PCDATANodes and PINodes at present). In the future XNode will be expanded to
support the DOM (at least in part). PCDATA and PIs are subclasses of XNode).
An XNode supports many operations common to all XML documents (e.g. navigation) and
also provides heuristics for display (e.g. getTitle()). An XNode has two main
parts:
- Attributes, held as a Vector (attributeVector). These can be accessed
directly, but there are also many generic operations (e.g. searching
for atttribute names and values, etc.). Attributes can be displayed in
a special component.
- Content. This consists of child nodes which may be a mixture of
elements and PCDATA (along with PIs). How these are displayed depends
on a large number of heuristics which (hopefully) cover most common cases.
These include event streams, pretty-printing, etc. XNode can be subclassed
to provide element-specific rendering.
- Author:
- P.Murray-Rust, 1998
-
ATTRIBUTES
- the attributes as a table
-
attributeVector
-
-
attributeXTable
-
-
CASE
- case in attributes must be matched
-
CONTENT
- heuristically rendered content; may be subclassed
-
contentText
-
-
displayTypeStrings
-
-
ELEMENTNAME
- the element name as a text field
-
elementStyle
- highlights the elementName in content display
-
elementTextField
-
-
EXACT
- attributes names must be matched exactly(modulated by (IGNORE)CASE)
-
IGNORECASE
- case in attributes need not be matched
-
nComponentTypes
-
-
PRETTY
- the event stream pretty printed
-
TAGGED
- the event stream with tags (at present identical to XML)
-
UNTAGGED
- the event stream with tag removed
-
WHITESPACE
- the event stream with whitespace highlighted by comments
-
WILD
- attributes names need not be matched exactly(modulated by (IGNORE)CASE)
-
XMLCONTENT
- the CONTENT as raw XML stream
-
XNode()
- default XNode with no name
-
XNode(Object)
- XNode with elementName defaulting to "XNode".
-
XNode(String, Object)
- as above, but with defined elementName
-
XNode(XNode)
- copy constructor (== deep copy) XNode.
-
addAttribute(Attribute)
- add an attribute; if name already exists, overwrites it.
-
addAttribute(String, String, int)
- add an attribute; if name already exists, overwrites it
-
addContent(XText, int)
- default formatting of content in absence of stylesheet.
-
addDisplayComponentTo(Container, int)
- add component display to an existing Container.
-
deleteWhitespaceDescendants()
- delete all whitespace descendants(uses PCDATANode.isWhitespace())
Once deleted, these cannot be returned.
-
display()
- dummy, to be overridden
-
display(TextArea)
- probably obsolete (or at least to be subclassed)
-
displayInFrame()
- display displayComponent in free window, probably obsolete
-
getAttribute(String, int)
- gets the attribute with a given name (ignored if name is
null or bad value of sensitivity)
-
getAttributeString()
- returns the attributes in concatenated text form (suitable for
insertion to start tags).
-
getAttributeValue(String, int)
- gets the value for an attribute with a given name
(ignored if name is null or bad value of sensitivity)
-
getAttributeVector()
- returns a Vector containing the attributes.
-
getChildWithAttributeValue(String, int, String, int)
- gets first child with given value of attribute
(ignored if name is null or bad value of sensitivity).
-
getChildWithElementName(String, int)
- gets first child with given element name
(ignored if name is null or bad value of sensitivity).
-
getColor()
- get any Color associated with the XNode (Fonts and Colors are still
being developed).
-
getDefaultColor()
- get any default Color associated with an XNode
-
getDefaultFont()
- get any default Font associated with an XNode
-
getDisplayComponent(int)
- returns a choice of document components, for different 'views'
of the node.
-
getElementName()
- return the elementName
-
getEventStream(int, int)
- gets the event stream (as XML or text).
-
getFont()
- get any Font associated with the XNode (Fonts and Colors are still
being developed).
-
getIcon()
- get an Icon associated with the XNode (still being developed).
-
getPCDATAContent()
- if this has a single PCDATA child, returns its string value, else null
-
getTitle()
- gets a title for the XNode.
-
isElementNode()
- is the XNode an element Node (as opposed to a PCDATA node or
PI or other...
-
makeSubClassedNode(XNode, String)
- replace a child XNode by its specialised version.
-
onClick()
- dummy, to be overridden by specialised classes
-
removeAttribute(String)
- delete an attribute.
-
replaceWith(XNode)
- replace this XNode with another; if this==root, new tree is created.
-
setColor(Color)
- set the Color associated with an XNode
-
setFont(Font)
- set the Font associated with an XNode
-
toString()
- used by a variety of Swing routines.
-
writeEventStream(PrintWriter, int, int)
- as for getEventStream, but writes to a PrintWriter.
ELEMENTNAME
public static final int ELEMENTNAME
- the element name as a text field
ATTRIBUTES
public static final int ATTRIBUTES
- the attributes as a table
XMLCONTENT
public static final int XMLCONTENT
- the CONTENT as raw XML stream
CONTENT
public static final int CONTENT
- heuristically rendered content; may be subclassed
TAGGED
public static final int TAGGED
- the event stream with tags (at present identical to XML)
UNTAGGED
public static final int UNTAGGED
- the event stream with tag removed
PRETTY
public static final int PRETTY
- the event stream pretty printed
WHITESPACE
public static final int WHITESPACE
- the event stream with whitespace highlighted by comments
nComponentTypes
public static final int nComponentTypes
displayTypeStrings
public static final String displayTypeStrings[]
CASE
public static final int CASE
- case in attributes must be matched
IGNORECASE
public static final int IGNORECASE
- case in attributes need not be matched
EXACT
public static final int EXACT
- attributes names must be matched exactly(modulated by (IGNORE)CASE)
WILD
public static final int WILD
- attributes names need not be matched exactly(modulated by (IGNORE)CASE)
attributeVector
protected Vector attributeVector
attributeXTable
protected XTable attributeXTable
elementTextField
protected TextField elementTextField
contentText
protected XText contentText
elementStyle
public static final SimpleAttributeSet elementStyle
- highlights the elementName in content display
XNode
public XNode()
- default XNode with no name
XNode
public XNode(Object object)
- XNode with elementName defaulting to "XNode". Object is userObject
as defined in DefaultMutableTreeNode. At present I am not clear whether
I shall use it (null can be used if unsure)
- Parameters:
- Object - object a userObject associated with the Node
XNode
public XNode(String elementName,
Object object)
- as above, but with defined elementName
- Parameters:
- String - elementName the elementName (as defined in xml-spec)
- Object - object a userObject associated with the Node
XNode
public XNode(XNode xNode)
- copy constructor (== deep copy) XNode. This creates new child Nodes,
attributes and content rather than simply copying references
replaceWith
public void replaceWith(XNode newNode)
- replace this XNode with another; if this==root, new tree is created.
If there is an associated tree, it will be reset with resetTree()
- Parameters:
- XNode - newNode node to replace this.XNode in tree
addAttribute
public boolean addAttribute(String name,
String value,
int type)
- add an attribute; if name already exists, overwrites it
- Parameters:
- String - name the attribute name (as defined in xml-spec)
- String - value the attribute value (as defined in xml-spec)
- int - type the attribute type (as defined in xml-spec). Possible values are
CDATA, ID, IDREF, IDREFS, NMTOKEN, NMTOKENS, NOTATION and NDATA
- Returns:
- boolean true if attribute already exists
addAttribute
public boolean addAttribute(Attribute attribute)
- add an attribute; if name already exists, overwrites it. If attribute
is null, no-op.
- Parameters:
- Attribute - the attribute
- Returns:
- boolean true if attribute already exists (and therefore has been changed)
removeAttribute
public void removeAttribute(String name)
- delete an attribute. If name is null, or not found, no action.
- Parameters:
- String - name the attribute name (as defined in xml-spec)
getAttributeVector
public Vector getAttributeVector()
- returns a Vector containing the attributes. If none, returns null
- Returns:
- Vector attributeVector (contains zero or more Attributes)
getAttributeString
public String getAttributeString()
- returns the attributes in concatenated text form (suitable for
insertion to start tags). If none, returns "". Example:
xml:link="simple" href="http://www.some/where"
- Returns:
- String the attribute String
getAttribute
public Attribute getAttribute(String name,
int sensitivity)
- gets the attribute with a given name (ignored if name is
null or bad value of sensitivity)
- Parameters:
- String - name the attribute name
- int - sensitivity can take values CASE or IGNORECASE
- Returns:
- Attribute the attribute (or null if not found)
getAttributeValue
public String getAttributeValue(String name,
int sensitivity)
- gets the value for an attribute with a given name
(ignored if name is null or bad value of sensitivity)
- Parameters:
- String - name the attribute name
- int - sensitivity can take values CASE or IGNORECASE
- Returns:
- Attribute the attribute (or null if not found)
getChildWithElementName
public XNode getChildWithElementName(String name,
int sensitivity)
- gets first child with given element name
(ignored if name is null or bad value of sensitivity). In principle
you could search for PCDATA or PI but we shall provide other methods
- Parameters:
- String - name the elementName (must match exactly other than case)
- int - sensitivity can take values CASE or IGNORECASE
- Returns:
- XNode the child
getChildWithAttributeValue
public XNode getChildWithAttributeValue(String name,
int nameSensitivity,
String value,
int valueSensitivity)
- gets first child with given value of attribute
(ignored if name is null or bad value of sensitivity).
- Parameters:
- String - name the attributeName (must match exactly other than case)
- int - nameSensitivity can take values CASE or IGNORECASE
- String - value the attributeValue (must match exactly other than case)
- int - valueSensitivity can take values CASE or IGNORECASE
- Returns:
- XNode the child
makeSubClassedNode
public static XNode makeSubClassedNode(XNode xNode,
String subClassName) throws XException
- replace a child XNode by its specialised version. Thus if the child
has an elementType of FOO a new FOONode is made to which are transferred
all the attributes and content of child. In this way, specialised Nodes
can be made after the tree is constructed. Experimental.
- Parameters:
- XNode - xNode node to be transformed. essentially destroyed
- String - subClassName class of specialied Node
- Returns:
- XNode new Node of class subClassName (null if error)
- Throws: XException
- various (subClass is not subClass of XNode; bugs)
getTitle
public String getTitle()
- gets a title for the XNode. There are several cascading heuristics here:
- If this is a PCDATA node, return the content value
- If the PCDATA is whitespace, returns "<!---->"
- If this has an attribute with a common name (e.g. TITLE, ID, etc.)
uses the attribute value. These names may be resettable in later versions.
- If this has a child with a common elementName (e.g. TITLE) and the
child contains only a PCDATA node, returns the string content
- Return elementName if not null
- Return the (Java) class of the node
This will always result in a non-null title (i.e. "XNode"). The title
is cached.
- Returns:
- String the title
getPCDATAContent
public String getPCDATAContent()
- if this has a single PCDATA child, returns its string value, else null
- Returns:
- String String content of single PCDATA child
isElementNode
public boolean isElementNode()
- is the XNode an element Node (as opposed to a PCDATA node or
PI or other...
getElementName
public String getElementName()
- return the elementName
- Returns:
- String element name
getEventStream
public String getEventStream(int type,
int level)
- gets the event stream (as XML or text). Options for type
- XMLCONTENT rendering of content as XML
- TAGGED precise rendering of XML (at present == XML)
- UNTAGGED all tags removed
- PRETTY pretty printed (indented tags)
- WHITESPACE with whitespace elements highlighted by comments
- Parameters:
- int - type type chosen from list above
- int - level of indentation (normally set to 0 when called, and expanded
recursively internally);
- Returns:
- String the event stream, escaped where needed. If there are newlines, etc. they are
embedded in the stream.
writeEventStream
public void writeEventStream(PrintWriter pw,
int type,
int level)
- as for getEventStream, but writes to a PrintWriter. It must be
possible to avoid the duplication...
display
public void display()
- dummy, to be overridden
onClick
public void onClick()
- dummy, to be overridden by specialised classes
getDisplayComponent
public JComponent getDisplayComponent(int type)
- returns a choice of document components, for different 'views'
of the node. Values are ATTRIBUTE, XMLCONTENT, TAGGED, etc. The returned
component is a fully functioning (e.g. scrollable) component
that can be add()ed to a Container.
- Parameters:
- int - type type of component to return
- Returns:
- JComponent the component
addDisplayComponentTo
public void addDisplayComponentTo(Container container,
int type)
- add component display to an existing Container. Will create a
JComponent through getDisplayComponent() above. If Container is a
TabbedPane, will create toolTips according to the type.
- Parameters:
- Container - container the container to add the component to
- int - the component type (XMLCONTENT, TAGGED, etc.)
addContent
protected void addContent(XText xText,
int level)
- default formatting of content in absence of stylesheet. Often
likely to be overridden.
- Parameters:
- XText - xText an existing XText JComponent. The content will be
appended to the text already inside
- int - level the level of recursion (use 0 by default)
deleteWhitespaceDescendants
public void deleteWhitespaceDescendants()
- delete all whitespace descendants(uses PCDATANode.isWhitespace())
Once deleted, these cannot be returned.
(the display is not updated, since I don't
have a strong enough grasp of the MVC relationship yet. Therefore
best place to do it is after SAXTree.
Modifies the children of this XNode. JTree may have to be recreated
if necessary.
displayInFrame
public void displayInFrame()
- display displayComponent in free window, probably obsolete
display
public void display(TextArea ta)
- probably obsolete (or at least to be subclassed)
getFont
public Font getFont()
- get any Font associated with the XNode (Fonts and Colors are still
being developed).
- Returns:
- Font the font
getDefaultFont
public static Font getDefaultFont()
- get any default Font associated with an XNode
- Returns:
- Font the font
setFont
public void setFont(Font font)
- set the Font associated with an XNode
- Parameters:
- Font - the font
getColor
public Color getColor()
- get any Color associated with the XNode (Fonts and Colors are still
being developed).
- Returns:
- Color the color
getDefaultColor
public static Color getDefaultColor()
- get any default Color associated with an XNode
- Returns:
- Color the color
setColor
public void setColor(Color color)
- set the Color associated with an XNode
- Parameters:
- Color - the color
getIcon
public Icon getIcon()
- get an Icon associated with the XNode (still being developed).
- Returns:
- Icon the icon (possibly an XMLIcon)
toString
public String toString()
- used by a variety of Swing routines. Simply calls getTitle().
- Returns:
- String result of getTitle()
- Overrides:
- toString in class DefaultMutableTreeNode
All Packages Class Hierarchy This Package Previous Next Index