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