|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| package org.qedeq.kernel.xml.tracker; |
|
18 |
| |
|
19 |
| import java.io.File; |
|
20 |
| import java.io.IOException; |
|
21 |
| |
|
22 |
| import javax.xml.parsers.ParserConfigurationException; |
|
23 |
| |
|
24 |
| import org.qedeq.kernel.context.KernelContext; |
|
25 |
| import org.qedeq.kernel.utility.IoUtility; |
|
26 |
| import org.xml.sax.SAXException; |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| public final class XPathLocationFinder { |
|
36 |
| |
|
37 |
| |
|
38 |
| |
|
39 |
| |
|
40 |
0
| private XPathLocationFinder() {
|
|
41 |
| |
|
42 |
| } |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
| |
|
51 |
| |
|
52 |
| |
|
53 |
0
| public static final void main(final String[] args) throws ParserConfigurationException,
|
|
54 |
| SAXException, IOException { |
|
55 |
0
| String from = null;
|
|
56 |
0
| String xpath = null;
|
|
57 |
| |
|
58 |
0
| if (args.length == 0) {
|
|
59 |
0
| printProgramInformation();
|
|
60 |
0
| return;
|
|
61 |
| } |
|
62 |
| |
|
63 |
0
| for (int i = 0; i < args.length; i++) {
|
|
64 |
0
| if (args[i].startsWith("-")) {
|
|
65 |
0
| final String option = args[i].substring(1).toLowerCase();
|
|
66 |
0
| if (option.equals("help") || option.equals("h")
|
|
67 |
| || option.equals("?")) { |
|
68 |
0
| printProgramInformation();
|
|
69 |
0
| return;
|
|
70 |
| } |
|
71 |
0
| if (option.equals("xpath") || option.equals("xp")) {
|
|
72 |
0
| if (i + 1 >= args.length) {
|
|
73 |
0
| printProgramInformation();
|
|
74 |
0
| System.err.println("\"-xpath\" must be followed by a xpath.");
|
|
75 |
0
| return;
|
|
76 |
| } |
|
77 |
0
| xpath = args[i + 1];
|
|
78 |
0
| i++;
|
|
79 |
| } else { |
|
80 |
0
| printProgramInformation();
|
|
81 |
0
| System.err.println("Unknown option: " + option);
|
|
82 |
0
| return;
|
|
83 |
| } |
|
84 |
| } else { |
|
85 |
0
| from = args[i];
|
|
86 |
| } |
|
87 |
| } |
|
88 |
0
| if (from == null) {
|
|
89 |
0
| printProgramInformation();
|
|
90 |
0
| System.err.println("XML file must be specified.");
|
|
91 |
0
| return;
|
|
92 |
| } |
|
93 |
0
| if (xpath == null) {
|
|
94 |
0
| printProgramInformation();
|
|
95 |
0
| System.err.println("XPath file must be specified.");
|
|
96 |
0
| return;
|
|
97 |
| } |
|
98 |
0
| System.out.println(IoUtility.getClassName(XPathLocationFinder.class) + ", running on: "
|
|
99 |
| + KernelContext.getInstance().getDescriptiveKernelVersion()); |
|
100 |
0
| XPathLocationParser.getXPathLocation(new File(from), xpath,
|
|
101 |
| IoUtility.toUrl(new File(from))); |
|
102 |
| } |
|
103 |
| |
|
104 |
| |
|
105 |
| |
|
106 |
| |
|
107 |
0
| public static final void printProgramInformation() {
|
|
108 |
0
| System.err.println("Name");
|
|
109 |
0
| System.err.println("----");
|
|
110 |
0
| System.err.println(IoUtility.getClassName(XPathLocationFinder.class)
|
|
111 |
| + " - find simple XML paths"); |
|
112 |
0
| System.err.println();
|
|
113 |
0
| System.err.println("Synopsis");
|
|
114 |
0
| System.err.println("-------------------");
|
|
115 |
0
| System.err.println("[-h] -xp[ath] <simpleXPath> <xmlFile>");
|
|
116 |
0
| System.err.println();
|
|
117 |
0
| System.err.println("Description");
|
|
118 |
0
| System.err.println("-----------");
|
|
119 |
0
| System.err.println(
|
|
120 |
| "This program finds the location of a given simple XPath in an XML file."); |
|
121 |
0
| System.err.println();
|
|
122 |
0
| System.err.println("Options and Parameter");
|
|
123 |
0
| System.err.println("---------------------");
|
|
124 |
0
| System.err.println("-h writes this text and returns");
|
|
125 |
0
| System.err.println("-xpath set the language filter (default: \"en\")");
|
|
126 |
0
| System.err.println(
|
|
127 |
| "<simpleXPath> simple XML XPath, a subset of the abbreviation XPath notation"); |
|
128 |
0
| System.err.println(
|
|
129 |
| " \"/element1/element2[3]@attribute\" is an example for such a"); |
|
130 |
0
| System.err.println(
|
|
131 |
| " notation. This selects from the first occurrence of \"element1\""); |
|
132 |
0
| System.err.println(
|
|
133 |
| " and from the third occurrence of subnode \"element2\" the attribute"); |
|
134 |
0
| System.err.println(
|
|
135 |
| " \"attribute\". The attribute is optional. It is always exactly one"); |
|
136 |
0
| System.err.println(" node or the attribute of one node specified.");
|
|
137 |
0
| System.err.println(" General syntax:");
|
|
138 |
0
| System.err.println(" {<element>\"[\"<index>\"]}+[\"@\"<attribute>]");
|
|
139 |
0
| System.err.println("<xmlFile> XML file");
|
|
140 |
0
| System.err.println();
|
|
141 |
0
| System.err.println("Parameter Examples");
|
|
142 |
0
| System.err.println("------------------");
|
|
143 |
0
| System.err.println(
|
|
144 |
| "-xp QEDEQ/CHAPTER/SECTION/NODE[2]/PRECEDING/AXIOM/FORMULA/FORALL/VAR@id"); |
|
145 |
0
| System.err.println("sample/qedeq_basic_concept.xml");
|
|
146 |
0
| System.err.println();
|
|
147 |
0
| System.err.println("Further information");
|
|
148 |
0
| System.err.println("-------------------");
|
|
149 |
0
| System.err.println("For more information about *Hilbert II* look at:");
|
|
150 |
0
| System.err.println("\thttp://www.qedeq.org/");
|
|
151 |
0
| System.err.println();
|
|
152 |
| } |
|
153 |
| |
|
154 |
| } |