|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectExploreXML
public class ExploreXML
Field Summary | |
---|---|
private static java.lang.StringBuffer |
blanks
Lazy buffer string containing a given number of spaces |
private static org.w3c.dom.Node |
bottom
Bottom node of the skeleton document |
private static int |
count
count the number of successful extractions |
static boolean |
debug
Global option (-d): will show debugging information during execution |
private static org.w3c.dom.Document |
doc
To keep the skeleton document |
private static long |
fileLength
number of bytes in the input file (does not take into account included files) |
private static java.lang.String |
inputFileName
Last parameter: Name of the input file, if it is null then standard input is used |
private static int |
maxRes
Extract option (-max): stop reading the file after a given number of results (infinite if not specified) |
private static java.lang.String |
moreHelp
|
private static int |
nbTests
count the number of effective tests on the skeleton documents during execution |
private static NamespaceContext |
nsContext
keep track of the namespaces used in the input document |
private static boolean |
onlyCount
Extract option (-c): return only the number of extracted nodes |
private static java.io.PrintStream |
out
print stream corresponding to the output file |
private static boolean |
outAttr
Explore option (-a): output attribute names in XPath expression |
private static boolean |
outAttrVal
Explore option (-av): output attribute names and values in XPath expression |
private static java.io.OutputStream |
output
corresponding to the output file |
private static java.lang.String |
outputFileName
Global option (-o): Name of the output file, if it is null then standard output is used |
private static boolean |
outVal
Explore option (-v): output element values in XPath expression |
private static java.util.SortedMap<java.lang.String,PathCount> |
pathCounts
To keep the count of each XPath expression |
private static boolean |
prettyPrint
Extract option (-pp): output a prettyprinted version of the extracted node |
private static java.lang.String |
rootName
Extract option (-r): name of the root element ( root if not given) |
private static boolean |
showNamespaces
Explore option (-ns): show the values of the namespaces used in XPath expressions |
private static boolean |
sortAlpha
Explore option (-sa): sort the XPath expressions alphabetically |
private static boolean |
sortFreq
Explore option (-sf): sort the XPath expression by decreasing frequency |
private static boolean |
statistics
Global option (-st): will show statistics information at the end of execution |
private static javax.xml.transform.Transformer |
trans
Tranformer of each output element |
private static javax.xml.transform.TransformerFactory |
transFact
Factory for the transformation of each output element |
private static javax.xml.transform.Result |
transResult
Output of the transformation, is linked to the output file |
private static java.lang.String |
usageStr
display of usage of the program with the list of possible command line arguments |
private static java.lang.String |
XML_NS
|
private static javax.xml.stream.XMLStreamReader |
xmlsr
Pull parser |
private static java.lang.String[] |
XMLStreamConstantsNames
|
private static javax.xml.stream.XMLStreamWriter |
xmlsw
To create the output with a stream writer |
private static java.lang.String |
xpathStr
Extract option (-xp): XPath expression used to select nodes to extract |
private static java.lang.String |
xsltFile
Extract option (-xsl): XSLT stylesheet to apply to each extracted node |
private static javax.xml.transform.Source |
xsltSource
Source of the transformation : will be linked to the skeleton document |
Constructor Summary | |
---|---|
ExploreXML()
|
Method Summary | |
---|---|
private static void |
addBottom(boolean full)
Read the next node (full or not) and insert it at the bottom of the spine document Initialize the spine document if necessary Modify the bottom global variable |
private static java.lang.String |
blanks(int n)
returns a string of spaces with a lazy StringBuffer |
private static java.lang.String |
buildXPath(org.w3c.dom.Node node)
Creates a string representation of the skeleton document starting from a given node |
static void |
compact(org.w3c.dom.Node node,
java.lang.String indent)
print a compact form of a Node (used here only for debugging) |
static void |
dumpElem(java.lang.String mess,
org.w3c.dom.Node elem)
Prints a message followed by the compact form of a document Node Only used for debugging purpose |
private static void |
ignore(javax.xml.stream.XMLStreamReader xmlsr)
ignore the token (if debugging is enabled, it prints the token skipped) |
static void |
main(java.lang.String[] argv)
Main program that parses arguments, sets up the input and output files and prints the results |
private static void |
parseArgs(java.lang.String[] args)
Parse program arguments and set appropriate options will stop on -h : prints usage of the program -xpt: prints the xpath expression as it is seen by the program will stop on an unrecognized arguments |
private static org.w3c.dom.Node |
pullFullNode(javax.xml.stream.XMLStreamReader xmlsr,
org.w3c.dom.Document doc)
read a Node (created with the doc) from pull parser reader read a complete element (including embedded elements if necessary) |
private static org.w3c.dom.Node |
pullNode(javax.xml.stream.XMLStreamReader reader,
org.w3c.dom.Document doc)
Read a Node (created with the doc) from pull parser reader We read only the start of an element or a single text/comment/processing-intruction node |
private static java.lang.String |
quotedString(java.lang.String s)
Create a properly quoted string taking into account the fact that it can contain either single or double quote or both |
private static void |
removeBottom()
remove the bottom node (and its children) by modifying the bottom global variable |
private static void |
skip(javax.xml.stream.XMLStreamReader xmlsr,
int level)
Skip the rest of an element, taking into account the possibility of embedded elements |
private static void |
usage()
Prints a short help about the use of the program called with the -h program argument |
private static void |
xplore()
Explore an XML file by generating a series of Path expression describing leafs of the skeleton document; called when no -xp argument is given |
private static void |
xtract()
Create a new XML document for each node matching the XPath expression given by the -xp parameter in order to save on memory each node is generated one by one as the input file is read |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final java.lang.String XML_NS
public static boolean debug
private static boolean statistics
private static java.lang.String inputFileName
private static java.lang.String outputFileName
private static boolean outAttr
private static boolean outAttrVal
private static boolean outVal
private static boolean sortAlpha
private static boolean sortFreq
private static boolean showNamespaces
private static java.lang.String xpathStr
private static java.lang.String xsltFile
private static java.lang.String rootName
root
if not given)
private static boolean onlyCount
private static boolean prettyPrint
private static int maxRes
private static java.lang.String usageStr
private static java.lang.String moreHelp
private static int count
private static int nbTests
private static long fileLength
private static java.util.SortedMap<java.lang.String,PathCount> pathCounts
private static javax.xml.stream.XMLStreamReader xmlsr
private static javax.xml.stream.XMLStreamWriter xmlsw
private static java.io.PrintStream out
private static java.io.OutputStream output
private static javax.xml.transform.Source xsltSource
private static javax.xml.transform.TransformerFactory transFact
private static javax.xml.transform.Transformer trans
private static javax.xml.transform.Result transResult
private static NamespaceContext nsContext
private static org.w3c.dom.Document doc
private static org.w3c.dom.Node bottom
private static java.lang.String[] XMLStreamConstantsNames
private static java.lang.StringBuffer blanks
Constructor Detail |
---|
public ExploreXML()
Method Detail |
---|
private static void parseArgs(java.lang.String[] args)
args
- String array as given to the main programpublic static void main(java.lang.String[] argv)
argv
- arguments as given the systemprivate static void usage()
private static void xplore() throws org.w3c.dom.DOMException, javax.xml.stream.XMLStreamException
org.w3c.dom.DOMException
javax.xml.stream.XMLStreamException
private static java.lang.String buildXPath(org.w3c.dom.Node node)
node
- node of the skeleton document
private static java.lang.String quotedString(java.lang.String s)
s
- input string
private static void xtract() throws javax.xml.stream.XMLStreamException, javax.xml.transform.TransformerException
javax.xml.stream.XMLStreamException
javax.xml.transform.TransformerException
private static org.w3c.dom.Node pullNode(javax.xml.stream.XMLStreamReader reader, org.w3c.dom.Document doc) throws javax.xml.stream.XMLStreamException
reader
- pull parserdoc
- document used to create new nodes
javax.xml.stream.XMLStreamException
private static org.w3c.dom.Node pullFullNode(javax.xml.stream.XMLStreamReader xmlsr, org.w3c.dom.Document doc) throws javax.xml.stream.XMLStreamException
xmlsr
- the pull-parserdoc
- the document to create new nodes
javax.xml.stream.XMLStreamException
private static void addBottom(boolean full) throws org.w3c.dom.DOMException, javax.xml.stream.XMLStreamException
bottom
global variable
full
- boolean indicating if the full node must be read or only the start
org.w3c.dom.DOMException
javax.xml.stream.XMLStreamException
private static void removeBottom()
bottom
global variable
private static void skip(javax.xml.stream.XMLStreamReader xmlsr, int level) throws javax.xml.stream.XMLStreamException
xmlsr
- pull-parserlevel
- indicates how many starting elements have been encountered without closing
javax.xml.stream.XMLStreamException
private static void ignore(javax.xml.stream.XMLStreamReader xmlsr) throws javax.xml.stream.XMLStreamException
xmlsr
-
javax.xml.stream.XMLStreamException
public static void dumpElem(java.lang.String mess, org.w3c.dom.Node elem)
mess
- String giving the message to showelem
- Node to print in compact formpublic static void compact(org.w3c.dom.Node node, java.lang.String indent)
node
- starting node to compactindent
- string added at the start of each new lineprivate static java.lang.String blanks(int n)
n
- number of spaces to return
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |