|
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.getDescriptiveKernelVersion()); |
|
99 |
0
| getXPathLocation(from, xpath);
|
|
100 |
| } |
|
101 |
| |
|
102 |
| |
|
103 |
| |
|
104 |
| |
|
105 |
| |
|
106 |
| |
|
107 |
| |
|
108 |
| |
|
109 |
| |
|
110 |
| |
|
111 |
| |
|
112 |
3160
| public static final SimpleXPath getXPathLocation(final String xmlFile, final String xpath)
|
|
113 |
| throws ParserConfigurationException, SAXException, IOException { |
|
114 |
3160
| final XPathLocationParser parser = new XPathLocationParser(xpath);
|
|
115 |
3160
| parser.parse(xmlFile);
|
|
116 |
3160
| return parser.getFind();
|
|
117 |
| } |
|
118 |
| |
|
119 |
| |
|
120 |
| |
|
121 |
| |
|
122 |
0
| public static final void printProgramInformation() {
|
|
123 |
0
| System.err.println("Name");
|
|
124 |
0
| System.err.println("----");
|
|
125 |
0
| System.err.println(IoUtility.getClassName(XPathLocationFinder.class)
|
|
126 |
| + " - find simple XML paths"); |
|
127 |
0
| System.err.println();
|
|
128 |
0
| System.err.println("Synopsis");
|
|
129 |
0
| System.err.println("-------------------");
|
|
130 |
0
| System.err.println("[-h] -xp[ath] <simpleXPath> <xmlFile>");
|
|
131 |
0
| System.err.println();
|
|
132 |
0
| System.err.println("Description");
|
|
133 |
0
| System.err.println("-----------");
|
|
134 |
0
| System.err.println(
|
|
135 |
| "This program finds the location of a given simple XPath in an XML file."); |
|
136 |
0
| System.err.println();
|
|
137 |
0
| System.err.println("Options and Parameter");
|
|
138 |
0
| System.err.println("---------------------");
|
|
139 |
0
| System.err.println("-h writes this text and returns");
|
|
140 |
0
| System.err.println("-xpath set the language filter (default: \"en\")");
|
|
141 |
0
| System.err.println(
|
|
142 |
| "<simpleXPath> simple XML XPath, a subset of the abbreviation XPath notation"); |
|
143 |
0
| System.err.println(
|
|
144 |
| " \"/element1/element2[3]@attribute\" is an example for such a"); |
|
145 |
0
| System.err.println(
|
|
146 |
| " notation. This selects from the first occurrence of \"element1\""); |
|
147 |
0
| System.err.println(
|
|
148 |
| " and from the third occurrence of subnode \"element2\" the attribute"); |
|
149 |
0
| System.err.println(
|
|
150 |
| " \"attribute\". The attribute is optional. It is always exactly one"); |
|
151 |
0
| System.err.println(" node or the attribute of one node specified.");
|
|
152 |
0
| System.err.println(" General syntax:");
|
|
153 |
0
| System.err.println(" {<element>\"[\"<index>\"]}+[\"@\"<attribute>]");
|
|
154 |
0
| System.err.println("<xmlFile> XML file");
|
|
155 |
0
| System.err.println();
|
|
156 |
0
| System.err.println("Parameter Examples");
|
|
157 |
0
| System.err.println("------------------");
|
|
158 |
0
| System.err.println(
|
|
159 |
| "-xp QEDEQ/CHAPTER/SECTION/NODE[2]/PRECEDING/AXIOM/FORMULA/FORALL/VAR@id"); |
|
160 |
0
| System.err.println("sample/qedeq_basic_concept.xml");
|
|
161 |
0
| System.err.println();
|
|
162 |
0
| System.err.println("Further information");
|
|
163 |
0
| System.err.println("-------------------");
|
|
164 |
0
| System.err.println("For more information about *Hilbert II* look at:");
|
|
165 |
0
| System.err.println("\thttp://www.qedeq.org/");
|
|
166 |
0
| System.err.println();
|
|
167 |
| } |
|
168 |
| |
|
169 |
| } |