org.dom4j.samples
abstract public class: AbstractDemo [javadoc |
source]
java.lang.Object
org.dom4j.samples.AbstractDemo
Direct Known Subclasses:
RoundTripDemo, LargeDocumentDemo, XercesDemo, SAXValidatorDemo, PullParserDemo, HTMLWriterDemo, CountDemo, DOMDemo, WriterDemo, FilterDemo, SAXDemo, SAXDOMDemo, PrettyPrintDemo, JTidyDemo, PullParseTest, CreateXMLDemo, VisitorDemo2, XPathDemo, VisitorDemo, DatatypeDemo, XSLTNativeDOMDemo, XSLTDemo, BeanDemo, LinkChecker, PerformanceSupport, XPathValueOf, RoundTripDemo, RoundTripDemo, XPathTool, JTreeDemo, NativeDOMDemo, ToTextTest, XPathGrep, LargeDocumentDemo2, ParseTest
An abstract base class for the demo programs.
- author:
< - a href="mailto:james.strachan@metastuff.com">James Strachan
- version:
$ - Revision: 1.4 $
| Field Summary |
|---|
| protected OutputFormat | format | The format of XML / HTML that is output by the demo program |
| protected XMLWriter | writer | The writer of XML |
| Method from org.dom4j.samples.AbstractDemo Detail: |
protected XMLWriter createXMLWriter() throws Exception {
return new XMLWriter(System.out, format);
}
A Factory Method to create an XMLWriter instance allowing
derived classes to change this behaviour |
protected XMLWriter getXMLWriter() throws Exception {
if (writer == null) {
writer = createXMLWriter();
}
return writer;
}
|
protected Document parse(String xmlFile) throws Exception {
throw new RuntimeException(
"parse(String xmlFile) not implemented in this demo");
}
|
protected void print(String text) {
System.out.print(text);
}
|
protected void printUsage(String text) {
println("Usage: java " + getClass().getName() + " " + text);
}
|
protected void println(String text) {
System.out.println(text);
}
|
protected void process(Document document) throws Exception {
getXMLWriter().write(document);
getXMLWriter().flush();
}
|
public void run(String[] args) throws Exception {
if (args.length < 1) {
printUsage("no XML document URL specified");
return;
}
int idx = format.parseOptions(args, 0);
if (idx >= args.length) {
printUsage("no XML document URL specified");
return;
} else {
writer = createXMLWriter();
Document document = parse(args[idx]);
process(document);
}
}
|
protected static void run(AbstractDemo demo,
String[] args) {
try {
demo.run(args);
} catch (DocumentException e) {
System.out.println("Exception occurred: " + e);
Throwable nestedException = e.getNestedException();
if (nestedException != null) {
System.out.println("NestedException: " + nestedException);
nestedException.printStackTrace();
} else {
e.printStackTrace();
}
} catch (Throwable t) {
System.out.println("Exception occurred: " + t);
t.printStackTrace();
}
}
|