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