|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectspase.parser200.XMLParser
public class XMLParser
An example XML parser.
| Constructor Summary | |
|---|---|
XMLParser()
Creates an instance of a XML |
|
| Method Summary | |
|---|---|
void |
addRequired(java.lang.String value)
|
void |
dump()
Prints the XML document to the currently define System.out. |
void |
dumpData(java.io.PrintStream out)
Dump the CData sections of the XML |
void |
dumpNode(java.io.PrintStream out,
org.w3c.dom.Node node)
Dump the nodes of the XML |
static java.lang.String |
entityEncode(java.lang.String text)
Convert special characters in a string for use in an HTML document. |
org.w3c.dom.Node |
findNode(org.w3c.dom.Node node,
java.lang.String name)
Find the next node with the given name. |
java.util.ArrayList<java.lang.String> |
getAllValues(java.lang.String path)
Return the list of values of a member given the XPath like reference to the member. |
static java.lang.String |
getBranchText(org.w3c.dom.Node node)
Concatenate all the text under a node. |
java.lang.String |
getClassName()
|
static javax.xml.transform.stream.StreamSource |
getDefaultStyleSheet()
Obtain a StreamSource to the default XML Style Sheet. |
org.w3c.dom.Document |
getDocument()
Obtain the Document containing the representation of the parsed XML files. |
java.lang.String |
getElementPath(java.lang.String base,
int key)
Construct an abbreviated XPath for a a class node. |
java.lang.String |
getMemberName(java.lang.String name)
Extract the member name from an XPath string. |
XMLParser |
getMemberNode(java.lang.String name)
Locates a node in a structure based on the the "name" associated with the member. |
int |
getMemberNodeIndex(java.lang.String name)
Extracts the index portion of node reference. |
java.lang.String |
getMemberNodeName(java.lang.String name)
Extracts the name portion of node reference. |
XMLParser |
getMemberParent(java.lang.String name)
Find the parent class for a member. |
java.lang.String |
getMemberPath(java.lang.String name)
Extract the path to a member from an XPath string. |
java.util.ArrayList<XMLParser> |
getNodes(java.lang.String path)
Return the list of nodes of a member given the XPath like reference to the member. |
java.util.ArrayList<XMLParser> |
getNodes(java.lang.String path,
boolean alwaysOne)
Return the list of nodes of a member given the XPath like reference to the member. |
java.util.ArrayList<XMLParser> |
getNodes(XMLParser parent,
java.lang.String name)
Return the list of nodes given the name of the member. |
static java.lang.String |
getNodeText(org.w3c.dom.Node node)
Concatenate all the text under a node. |
java.lang.String |
getPath()
Return the path to the parsed document |
java.lang.String |
getPathName()
Return the pathname of the parsed document |
java.util.ArrayList |
getRequired()
|
java.io.StringReader |
getStringReader()
Return a StringReader for an XML representation of the document. |
java.lang.String |
getTagClose(int level,
java.lang.String tagName)
Return an close tag with the proper indentation. |
java.lang.String |
getTaggedList(int level,
java.lang.String tagName,
java.util.ArrayList<java.lang.String> list)
Return a list of tagged values, properly indented. |
java.lang.String |
getTaggedList(int level,
java.lang.String tagName,
java.util.ArrayList<java.lang.String> list,
boolean inUseOnly)
Return a list of tagged values, properly indented. |
java.lang.String |
getTaggedValue(int level,
java.lang.String tagName,
java.lang.String value)
Return a value enclosed in a tag and properly indented. |
java.lang.String |
getTaggedValue(int level,
java.lang.String tagName,
java.lang.String value,
boolean inUseOnly)
Return a value enclosed in a tag and properly indented. |
java.lang.String |
getTagOpen(int level,
java.lang.String tagName)
Return an open tag with the proper indentation. |
XMLParser |
getTopParent(java.lang.String name)
Find the top level parent class for a member. |
java.util.ArrayList<java.lang.String> |
getValues(java.lang.String path)
Return the list of values of a member given the XPath like reference to the member. |
java.util.ArrayList<java.lang.String> |
getValues(java.lang.String path,
boolean alwaysOne)
Return the list of values of a member given the XPath like reference to the member. |
java.util.ArrayList<java.lang.String> |
getWords()
Walk the internals of a class and collect a unique list of words from all String fields. |
java.lang.String |
getXMLDocument(int n)
Return a string containing an XML representation of this instance. |
java.lang.String |
getXMLDocument(int n,
boolean inUseOnly)
Return a string containing an XML representation of this instance. |
java.lang.String |
getXMLDocument(int n,
java.lang.String path,
int key)
Return a string containing an XML representation of this isntance. |
java.lang.String |
getXMLDocument(int n,
java.lang.String path,
int key,
boolean inUseOnly)
Return a string containing an XML representation of this isntance. |
static java.util.ArrayList<Pair> |
getXPathList(java.lang.String prefix,
java.util.ArrayList<java.lang.String> list)
Get a list of values labeled with an XPath. |
java.util.ArrayList<Pair> |
getXPathPairs()
Return an ArrayList of string Pairs which contains for each node in the XML document an XPath as the "left" value of the pair and the value as the "right" value of pair. |
java.util.ArrayList<Pair> |
getXPathPairs(java.lang.String prefix,
int index)
Return an ArrayList of string Pairs which contains for each node in the XML document an XPath as the "left" value of the pair and the value as the "right" value of pair. |
static java.lang.String |
indent(int level)
Return a string with spaces to format to indicated indentation level. |
boolean |
isCommonWord(java.lang.String value)
Determine if a word is a common word. |
boolean |
isInList(java.util.ArrayList<java.lang.String> value,
java.util.ArrayList<java.lang.String> list,
boolean all)
Determine if any or all items in a String ArrayList is in a string ArrayList. |
boolean |
isInList(java.lang.String value,
java.util.ArrayList<java.lang.String> list)
Determine if an item is in a string ArrayList. |
boolean |
isInList(java.lang.String base,
java.lang.String value,
java.util.ArrayList list,
int index)
Determine if a list is of the proper type and the index is within the range of the list. |
boolean |
isInUse(java.lang.String name,
java.lang.String value)
Determine if an element is in use. |
boolean |
isMatch(java.lang.String base,
java.lang.String value)
Return a list of tagged values, properly indented. |
boolean |
isRequired(java.lang.String name)
Determine if an element is required. |
void |
load(org.w3c.dom.Document document,
java.lang.String root)
Parses a Document which contains a parsed XML file
and set internal variables with the contents of the file. |
void |
load(java.lang.String pathName)
Parses a file containing XML into its constitute elments and sets internal variables with the contents of the file. |
void |
load(java.lang.String pathName,
java.lang.String root)
Parses a file containing XML into its constitute elments and sets internal variables with the contents of the file. |
static void |
main(java.lang.String[] args)
Entry point for testing |
void |
makeEditNodes()
Create an instance of all nodes for use when editing. |
void |
makeNewMember(java.lang.String name)
Create a new member. |
void |
makeSkeletonNodes()
Create all nodes for use when editing which currently do not exist. |
java.lang.String |
makeTagContent(java.lang.String tag,
java.lang.String content)
Return a string with content enclosed in tags with the passed name. |
java.util.ArrayList<java.lang.String> |
parseWords(java.lang.String text)
Parse a string into words and return a list of unique words. |
boolean |
parseXML(java.io.InputStream stream)
Parses a file containing XML into its constitute elments. |
boolean |
parseXML(java.lang.String pathName)
Parses a file containing XML into its constitute elments. |
boolean |
parseXMLString(java.lang.String text)
Parses a string containing XML into its constitute elments. |
void |
printXML(java.io.PrintStream out)
Generates an XML representation of the label and stream it to the print stream. |
void |
processNode(org.w3c.dom.Node node)
Walk the nodes of the Document and populate the resource classes. |
void |
removeMember(java.lang.String name,
int index)
Remove an elment of a member. |
void |
setClassName(java.lang.String name)
|
void |
setMember(java.lang.String name,
org.w3c.dom.Node value)
Call the set() method with a given name suffix and a DOM Node
as an argument. |
java.lang.String |
setMember(java.lang.String name,
java.lang.String value)
Call the set() method with a given name suffix and a String
as an argument. |
void |
setMember(java.lang.String name,
java.lang.String[] value)
Call the set() method with a given name suffix and an array of String
values as an argument. |
java.lang.String[] |
splitMixed(java.lang.String text)
Divide a string on capital letters that follow lowercase letters |
static java.lang.String |
toImproperCase(java.lang.String value)
Convert a string to "improper" case (make first letter lower case). |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public XMLParser()
| Method Detail |
|---|
public static void main(java.lang.String[] args)
public void load(java.lang.String pathName)
throws java.lang.Exception
pathName - the fully qualified path and name of the file to parse.
java.lang.Exception
public void load(java.lang.String pathName,
java.lang.String root)
throws java.lang.Exception
pathName - the fully qualified path and name of the file to parse.root - the name of the tag containg elements to process.
java.lang.Exception
public void load(org.w3c.dom.Document document,
java.lang.String root)
throws java.lang.Exception
Document which contains a parsed XML file
and set internal variables with the contents of the file.
document - the Document representation of a parsed XML file.root - the name of the tag containg elements to process.
java.lang.Exception
public boolean parseXML(java.lang.String pathName)
throws java.lang.Exception
pathName - the fully qualified path and name of the file to parse.
true if the file could be opened;
false otherwise.
java.lang.Exception
public boolean parseXMLString(java.lang.String text)
throws java.lang.Exception
text - the String conting the XML text.
true if the file could be opened;
false otherwise.
java.lang.Exception
public boolean parseXML(java.io.InputStream stream)
throws java.lang.Exception
stream - a connection to a pre-opened file.
true if the file could be read;
false otherwise.
java.lang.Exception
public void printXML(java.io.PrintStream out)
throws java.lang.Exception
out - the stream to print the element to.
java.lang.Exception
public void dumpData(java.io.PrintStream out)
throws java.lang.Exception
out - the stream to print the element to.
java.lang.Exception
public void dumpNode(java.io.PrintStream out,
org.w3c.dom.Node node)
out - the stream to print the element to.
public org.w3c.dom.Node findNode(org.w3c.dom.Node node,
java.lang.String name)
throws java.lang.Exception
node - the Node to start at.name - the name of the node to look for.
java.lang.Exceptionpublic static javax.xml.transform.stream.StreamSource getDefaultStyleSheet()
StreamSource which can be used to read the default
style sheet.public org.w3c.dom.Document getDocument()
Document containing the representation of the parsed XML file.
public void processNode(org.w3c.dom.Node node)
throws java.lang.Exception
String".
If such a method is found the text contained by the
element tags is passed to the method. Then a method with the prefix of "set" is
with a parameter of of type "Node" is attempted. If such a method is found
then method is called with the Node representing the element is passed as the argument.
node - the Node.
java.lang.Exception
public java.lang.String setMember(java.lang.String name,
java.lang.String value)
String
as an argument.
value - the String value to set.
public void setMember(java.lang.String name,
java.lang.String[] value)
String
values as an argument.
value - the String value to set.
public void setMember(java.lang.String name,
org.w3c.dom.Node value)
Node
as an argument.
name - the name of the member (suffix for setXXX() method).value - the String value to set.public XMLParser getMemberParent(java.lang.String name)
node - the Node.public XMLParser getTopParent(java.lang.String name)
name - the XPath name for for the member.public java.lang.String getMemberPath(java.lang.String name)
name - The full path name of the node.public java.lang.String getMemberName(java.lang.String name)
node - the Node.public XMLParser getMemberNode(java.lang.String name)
name - the name associated with a member.public java.lang.String getMemberNodeName(java.lang.String name)
name - the name associated with a member.public int getMemberNodeIndex(java.lang.String name)
name - the name associated with a member.public static java.lang.String getNodeText(org.w3c.dom.Node node)
node - the Node.
public static java.lang.String getBranchText(org.w3c.dom.Node node)
throws java.lang.Exception
node - the Node.
java.lang.Exceptionpublic java.lang.String getPathName()
public java.lang.String getPath()
public java.lang.String makeTagContent(java.lang.String tag,
java.lang.String content)
public static java.lang.String indent(int level)
public void dump()
public java.util.ArrayList<Pair> getXPathPairs()
public java.util.ArrayList<Pair> getXPathPairs(java.lang.String prefix,
int index)
prefix - the leading path to add to each XPath.index - the index of the item if part of an array.
Indexes start a 1, a value of 0 indicates it is
not part of an array.public java.lang.String getXMLDocument(int n)
n - the number of levels to indent the document.
public java.lang.String getXMLDocument(int n,
boolean inUseOnly)
n - the number of levels to indent the document.inUseOnly - indicates whether to include only those elements currently in use.
public java.lang.String getXMLDocument(int n,
java.lang.String path,
int key)
n - the number of levels to indent the document.path - the path to the element.key - the index (key) of the element at the path.
public java.lang.String getXMLDocument(int n,
java.lang.String path,
int key,
boolean inUseOnly)
n - the number of levels to indent the document.path - the path to the element.key - the index (key) of the element at the path.public void makeNewMember(java.lang.String name)
name - the name of the member to create.public void makeEditNodes()
public void makeSkeletonNodes()
public void removeMember(java.lang.String name,
int index)
name - the name of the member to create.index - the index of the element to remove.public java.util.ArrayList<XMLParser> getNodes(java.lang.String path)
Only returns nodes for items that are nodes.
Always returns a list with at least one entry. If no nodes are found then the returned entry is blank.
public java.util.ArrayList<XMLParser> getNodes(java.lang.String path,
boolean alwaysOne)
Only returns nodes for items that are nodes.
If no nodes are found then the returned list is empty unless alwaysOne is set to true.
public java.util.ArrayList<XMLParser> getNodes(XMLParser parent,
java.lang.String name)
Only returns nodes for items that are nodes.
If no nodes are found then the returned list is empty.
public java.util.ArrayList<java.lang.String> getAllValues(java.lang.String path)
Only returns values for items that return String values.
Always returns a list with at least one entry. If no nodes are found then the returned entry is blank.
public java.util.ArrayList<java.lang.String> getValues(java.lang.String path)
Only returns values for items that return String values.
Always returns a list with at least one entry. If no nodes are found then the returned entry is blank.
public java.util.ArrayList<java.lang.String> getValues(java.lang.String path,
boolean alwaysOne)
Only returns values for items that return String values.
If no nodes are found then the returned list is empty unless alwaysOne is set to true.
public java.io.StringReader getStringReader()
StringReader for an XML representation of the document.
Commonly used to pass the document through an XML stylesheet transformation
using Transform.
public java.lang.String getTaggedValue(int level,
java.lang.String tagName,
java.lang.String value)
public java.lang.String getTaggedValue(int level,
java.lang.String tagName,
java.lang.String value,
boolean inUseOnly)
public java.lang.String getTagOpen(int level,
java.lang.String tagName)
public java.lang.String getTagClose(int level,
java.lang.String tagName)
public java.lang.String getTaggedList(int level,
java.lang.String tagName,
java.util.ArrayList<java.lang.String> list)
public java.lang.String getTaggedList(int level,
java.lang.String tagName,
java.util.ArrayList<java.lang.String> list,
boolean inUseOnly)
public boolean isMatch(java.lang.String base,
java.lang.String value)
public java.lang.String getElementPath(java.lang.String base,
int key)
public boolean isInList(java.lang.String base,
java.lang.String value,
java.util.ArrayList list,
int index)
public boolean isInList(java.lang.String value,
java.util.ArrayList<java.lang.String> list)
public boolean isInList(java.util.ArrayList<java.lang.String> value,
java.util.ArrayList<java.lang.String> list,
boolean all)
all - if true then all words in value must be in list.
otherwise if any word is in list then true is returned.public boolean isCommonWord(java.lang.String value)
public static java.lang.String toImproperCase(java.lang.String value)
public java.util.ArrayList<java.lang.String> parseWords(java.lang.String text)
public java.lang.String[] splitMixed(java.lang.String text)
public java.util.ArrayList<java.lang.String> getWords()
public boolean isInUse(java.lang.String name,
java.lang.String value)
name - the name of the element.value - the value associated with the element.public boolean isRequired(java.lang.String name)
name - the name of the element.
public static java.util.ArrayList<Pair> getXPathList(java.lang.String prefix,
java.util.ArrayList<java.lang.String> list)
node - the Node.public static java.lang.String entityEncode(java.lang.String text)
public void setClassName(java.lang.String name)
public java.lang.String getClassName()
public void addRequired(java.lang.String value)
public java.util.ArrayList getRequired()
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||