Clover coverage report - QedeqKernelSe Coverage Report
Coverage timestamp: Sa Jan 26 2008 14:11:34 CET
file stats: LOC: 154   Methods: 3
NCLOC: 105   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
XPathLocationFinder.java 0% 0% 0% 0%
coverage
 1    /* $Id: XPathLocationFinder.java,v 1.18 2008/01/26 12:39:11 m31 Exp $
 2    *
 3    * This file is part of the project "Hilbert II" - http://www.qedeq.org
 4    *
 5    * Copyright 2000-2007, 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.kernel.context.KernelContext;
 25    import org.qedeq.kernel.utility.IoUtility;
 26    import org.xml.sax.SAXException;
 27   
 28   
 29    /**
 30    * Find position of simple XPath expressions within an XML file.
 31    *
 32    * @version $Revision: 1.18 $
 33    * @author Michael Meyling
 34    */
 35    public final class XPathLocationFinder {
 36   
 37    /**
 38    * Constructor.
 39    */
 40  0 private XPathLocationFinder() {
 41    // nothing to do
 42    }
 43   
 44    /**
 45    * Main method.
 46    *
 47    * @param args Various parameters. See implementation of
 48    * {@link #printProgramInformation()}.
 49    * @throws ParserConfigurationException
 50    * @throws SAXException
 51    * @throws IOException
 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("-")) { // option
 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 { // unknown option
 80  0 printProgramInformation();
 81  0 System.err.println("Unknown option: " + option);
 82  0 return;
 83    }
 84    } else { // no option, must be file name
 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    * Writes calling convention to <code>System.err</code>.
 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    }