Clover Coverage Report
Coverage timestamp: Sa Aug 2 2008 13:56:27 CEST
../../../../../img/srcFileCovDistChart0.png 88% of files have more coverage
68   155   14   22,67
16   106   0,21   3
3     4,67  
1    
 
  XPathLocationFinder       Line # 36 68 14 0% 0.0
 
No Tests
 
1    /* $Id: XPathLocationFinder.java,v 1.1 2008/07/26 08:00:50 m31 Exp $
2    *
3    * This file is part of the project "Hilbert II" - http://www.qedeq.org
4    *
5    * Copyright 2000-2008, Michael Meyling <mime@qedeq.org>.
6    *
7    * "Hilbert II" is free software; you can redistribute
8    * it and/or modify it under the terms of the GNU General Public
9    * License as published by the Free Software Foundation; either
10    * version 2 of the License, or (at your option) any later version.
11    *
12    * This program is distributed in the hope that it will be useful,
13    * but WITHOUT ANY WARRANTY; without even the implied warranty of
14    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15    * GNU General Public License for more details.
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.base.io.IoUtility;
25    import org.qedeq.base.utility.StringUtility;
26    import org.qedeq.kernel.bo.context.KernelContext;
27    import org.xml.sax.SAXException;
28   
29   
30    /**
31    * Find position of simple XPath expressions within an XML file.
32    *
33    * @version $Revision: 1.1 $
34    * @author Michael Meyling
35    */
 
36    public final class XPathLocationFinder {
37   
38    /**
39    * Constructor.
40    */
 
41  0 toggle private XPathLocationFinder() {
42    // nothing to do
43    }
44   
45    /**
46    * Main method.
47    *
48    * @param args Various parameters. See implementation of
49    * {@link #printProgramInformation()}.
50    * @throws ParserConfigurationException
51    * @throws SAXException
52    * @throws IOException
53    */
 
54  0 toggle public static final void main(final String[] args) throws ParserConfigurationException,
55    SAXException, IOException {
56  0 String from = null;
57  0 String xpath = null;
58   
59  0 if (args.length == 0) {
60  0 printProgramInformation();
61  0 return;
62    }
63   
64  0 for (int i = 0; i < args.length; i++) {
65  0 if (args[i].startsWith("-")) { // option
66  0 final String option = args[i].substring(1).toLowerCase();
67  0 if (option.equals("help") || option.equals("h")
68    || option.equals("?")) {
69  0 printProgramInformation();
70  0 return;
71    }
72  0 if (option.equals("xpath") || option.equals("xp")) {
73  0 if (i + 1 >= args.length) {
74  0 printProgramInformation();
75  0 System.err.println("\"-xpath\" must be followed by a xpath.");
76  0 return;
77    }
78  0 xpath = args[i + 1];
79  0 i++;
80    } else { // unknown option
81  0 printProgramInformation();
82  0 System.err.println("Unknown option: " + option);
83  0 return;
84    }
85    } else { // no option, must be file name
86  0 from = args[i];
87    }
88    }
89  0 if (from == null) {
90  0 printProgramInformation();
91  0 System.err.println("XML file must be specified.");
92  0 return;
93    }
94  0 if (xpath == null) {
95  0 printProgramInformation();
96  0 System.err.println("XPath file must be specified.");
97  0 return;
98    }
99  0 System.out.println(StringUtility.getClassName(XPathLocationFinder.class) + ", running on: "
100    + KernelContext.getInstance().getDescriptiveKernelVersion());
101  0 XPathLocationParser.getXPathLocation(new File(from), xpath,
102    IoUtility.toUrl(new File(from)));
103    }
104   
105    /**
106    * Writes calling convention to <code>System.err</code>.
107    */
 
108  0 toggle public static final void printProgramInformation() {
109  0 System.err.println("Name");
110  0 System.err.println("----");
111  0 System.err.println(StringUtility.getClassName(XPathLocationFinder.class)
112    + " - find simple XML paths");
113  0 System.err.println();
114  0 System.err.println("Synopsis");
115  0 System.err.println("-------------------");
116  0 System.err.println("[-h] -xp[ath] <simpleXPath> <xmlFile>");
117  0 System.err.println();
118  0 System.err.println("Description");
119  0 System.err.println("-----------");
120  0 System.err.println(
121    "This program finds the location of a given simple XPath in an XML file.");
122  0 System.err.println();
123  0 System.err.println("Options and Parameter");
124  0 System.err.println("---------------------");
125  0 System.err.println("-h writes this text and returns");
126  0 System.err.println("-xpath set the language filter (default: \"en\")");
127  0 System.err.println(
128    "<simpleXPath> simple XML XPath, a subset of the abbreviation XPath notation");
129  0 System.err.println(
130    " \"/element1/element2[3]@attribute\" is an example for such a");
131  0 System.err.println(
132    " notation. This selects from the first occurrence of \"element1\"");
133  0 System.err.println(
134    " and from the third occurrence of subnode \"element2\" the attribute");
135  0 System.err.println(
136    " \"attribute\". The attribute is optional. It is always exactly one");
137  0 System.err.println(" node or the attribute of one node specified.");
138  0 System.err.println(" General syntax:");
139  0 System.err.println(" {<element>\"[\"<index>\"]}+[\"@\"<attribute>]");
140  0 System.err.println("<xmlFile> XML file");
141  0 System.err.println();
142  0 System.err.println("Parameter Examples");
143  0 System.err.println("------------------");
144  0 System.err.println(
145    "-xp QEDEQ/CHAPTER/SECTION/NODE[2]/PRECEDING/AXIOM/FORMULA/FORALL/VAR@id");
146  0 System.err.println("sample/qedeq_basic_concept.xml");
147  0 System.err.println();
148  0 System.err.println("Further information");
149  0 System.err.println("-------------------");
150  0 System.err.println("For more information about *Hilbert II* look at:");
151  0 System.err.println("\thttp://www.qedeq.org/");
152  0 System.err.println();
153    }
154   
155    }