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:

Author:
P.Murray-Rust, 1998

Variable Index

 o ATTRIBUTES
the attributes as a table
 o attributeVector
 o attributeXTable
 o CASE
case in attributes must be matched
 o CONTENT
heuristically rendered content; may be subclassed
 o contentText
 o displayTypeStrings
 o ELEMENTNAME
the element name as a text field
 o elementStyle
highlights the elementName in content display
 o elementTextField
 o EXACT
attributes names must be matched exactly(modulated by (IGNORE)CASE)
 o IGNORECASE
case in attributes need not be matched
 o nComponentTypes
 o PRETTY
the event stream pretty printed
 o TAGGED
the event stream with tags (at present identical to XML)
 o UNTAGGED
the event stream with tag removed
 o WHITESPACE
the event stream with whitespace highlighted by comments
 o WILD
attributes names need not be matched exactly(modulated by (IGNORE)CASE)
 o XMLCONTENT
the CONTENT as raw XML stream

Constructor Index

 o XNode()
default XNode with no name
 o XNode(Object)
XNode with elementName defaulting to "XNode".
 o XNode(String, Object)
as above, but with defined elementName
 o XNode(XNode)
copy constructor (== deep copy) XNode.

Method Index

 o addAttribute(Attribute)
add an attribute; if name already exists, overwrites it.
 o addAttribute(String, String, int)
add an attribute; if name already exists, overwrites it
 o addContent(XText, int)
default formatting of content in absence of stylesheet.
 o addDisplayComponentTo(Container, int)
add component display to an existing Container.
 o deleteWhitespaceDescendants()
delete all whitespace descendants(uses PCDATANode.isWhitespace()) Once deleted, these cannot be returned.
 o display()
dummy, to be overridden
 o display(TextArea)
probably obsolete (or at least to be subclassed)
 o displayInFrame()
display displayComponent in free window, probably obsolete
 o getAttribute(String, int)
gets the attribute with a given name (ignored if name is null or bad value of sensitivity)
 o getAttributeString()
returns the attributes in concatenated text form (suitable for insertion to start tags).
 o getAttributeValue(String, int)
gets the value for an attribute with a given name (ignored if name is null or bad value of sensitivity)
 o getAttributeVector()
returns a Vector containing the attributes.
 o getChildWithAttributeValue(String, int, String, int)
gets first child with given value of attribute (ignored if name is null or bad value of sensitivity).
 o getChildWithElementName(String, int)
gets first child with given element name (ignored if name is null or bad value of sensitivity).
 o getColor()
get any Color associated with the XNode (Fonts and Colors are still being developed).
 o getDefaultColor()
get any default Color associated with an XNode
 o getDefaultFont()
get any default Font associated with an XNode
 o getDisplayComponent(int)
returns a choice of document components, for different 'views' of the node.
 o getElementName()
return the elementName
 o getEventStream(int, int)
gets the event stream (as XML or text).
 o getFont()
get any Font associated with the XNode (Fonts and Colors are still being developed).
 o getIcon()
get an Icon associated with the XNode (still being developed).
 o getPCDATAContent()
if this has a single PCDATA child, returns its string value, else null
 o getTitle()
gets a title for the XNode.
 o isElementNode()
is the XNode an element Node (as opposed to a PCDATA node or PI or other...
 o makeSubClassedNode(XNode, String)
replace a child XNode by its specialised version.
 o onClick()
dummy, to be overridden by specialised classes
 o removeAttribute(String)
delete an attribute.
 o replaceWith(XNode)
replace this XNode with another; if this==root, new tree is created.
 o setColor(Color)
set the Color associated with an XNode
 o setFont(Font)
set the Font associated with an XNode
 o toString()
used by a variety of Swing routines.
 o writeEventStream(PrintWriter, int, int)
as for getEventStream, but writes to a PrintWriter.

Variables

 o ELEMENTNAME
 public static final int ELEMENTNAME
the element name as a text field

 o ATTRIBUTES
 public static final int ATTRIBUTES
the attributes as a table

 o XMLCONTENT
 public static final int XMLCONTENT
the CONTENT as raw XML stream

 o CONTENT
 public static final int CONTENT
heuristically rendered content; may be subclassed

 o TAGGED
 public static final int TAGGED
the event stream with tags (at present identical to XML)

 o UNTAGGED
 public static final int UNTAGGED
the event stream with tag removed

 o PRETTY
 public static final int PRETTY
the event stream pretty printed

 o WHITESPACE
 public static final int WHITESPACE
the event stream with whitespace highlighted by comments

 o nComponentTypes
 public static final int nComponentTypes
 o displayTypeStrings
 public static final String displayTypeStrings[]
 o CASE
 public static final int CASE
case in attributes must be matched

 o IGNORECASE
 public static final int IGNORECASE
case in attributes need not be matched

 o EXACT
 public static final int EXACT
attributes names must be matched exactly(modulated by (IGNORE)CASE)

 o WILD
 public static final int WILD
attributes names need not be matched exactly(modulated by (IGNORE)CASE)

 o attributeVector
 protected Vector attributeVector
 o attributeXTable
 protected XTable attributeXTable
 o elementTextField
 protected TextField elementTextField
 o contentText
 protected XText contentText
 o elementStyle
 public static final SimpleAttributeSet elementStyle
highlights the elementName in content display

Constructors

 o XNode
 public XNode()
default XNode with no name

 o 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
 o 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
 o XNode
 public XNode(XNode xNode)
copy constructor (== deep copy) XNode. This creates new child Nodes, attributes and content rather than simply copying references

Methods

 o 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
 o 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
 o 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)
 o 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)
 o getAttributeVector
 public Vector getAttributeVector()
returns a Vector containing the attributes. If none, returns null

Returns:
Vector attributeVector (contains zero or more Attributes)
 o 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
 o 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)
 o 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)
 o 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
 o 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
 o 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)
 o getTitle
 public String getTitle()
gets a title for the XNode. There are several cascading heuristics here: This will always result in a non-null title (i.e. "XNode"). The title is cached.

Returns:
String the title
 o 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
 o isElementNode
 public boolean isElementNode()
is the XNode an element Node (as opposed to a PCDATA node or PI or other...

 o getElementName
 public String getElementName()
return the elementName

Returns:
String element name
 o getEventStream
 public String getEventStream(int type,
                              int level)
gets the event stream (as XML or text). Options for type

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.
 o 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...

 o display
 public void display()
dummy, to be overridden

 o onClick
 public void onClick()
dummy, to be overridden by specialised classes

 o 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
 o 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.)
 o 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)
 o 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.

 o displayInFrame
 public void displayInFrame()
display displayComponent in free window, probably obsolete

 o display
 public void display(TextArea ta)
probably obsolete (or at least to be subclassed)

 o getFont
 public Font getFont()
get any Font associated with the XNode (Fonts and Colors are still being developed).

Returns:
Font the font
 o getDefaultFont
 public static Font getDefaultFont()
get any default Font associated with an XNode

Returns:
Font the font
 o setFont
 public void setFont(Font font)
set the Font associated with an XNode

Parameters:
Font - the font
 o getColor
 public Color getColor()
get any Color associated with the XNode (Fonts and Colors are still being developed).

Returns:
Color the color
 o getDefaultColor
 public static Color getDefaultColor()
get any default Color associated with an XNode

Returns:
Color the color
 o setColor
 public void setColor(Color color)
set the Color associated with an XNode

Parameters:
Color - the color
 o getIcon
 public Icon getIcon()
get an Icon associated with the XNode (still being developed).

Returns:
Icon the icon (possibly an XMLIcon)
 o 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