Clover coverage report - QedeqKernelSe Coverage Report
Coverage timestamp: Sa Dez 22 2007 01:35:21 CET
file stats: LOC: 190   Methods: 5
NCLOC: 117   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
XPathLocationFinder.java 0% 5,6% 40% 6,5%
coverage coverage
 1    /* $Id: XPathLocationFinder.java,v 1.17 2007/12/21 23:33:48 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    import java.net.URL;
 22   
 23    import javax.xml.parsers.ParserConfigurationException;
 24   
 25    import org.qedeq.kernel.context.KernelContext;
 26    import org.qedeq.kernel.utility.IoUtility;
 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.17 $
 34    * @author Michael Meyling
 35    */
 36    public final class XPathLocationFinder {
 37   
 38    /**
 39    * Constructor.
 40    */
 41  0 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 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(IoUtility.getClassName(XPathLocationFinder.class) + ", running on: "
 100    + KernelContext.getInstance().getDescriptiveKernelVersion());
 101  0 getXPathLocation(new File(from), xpath, IoUtility.toUrl(new File(from)));
 102    }
 103   
 104    /**
 105    * Search simple XPath within an XML file.
 106    *
 107    * @param xmlFile Search this file.
 108    * @param xpath Search for this simple XPath.
 109    * @param original Original file location.
 110    * @return Source position information.
 111    * @throws ParserConfigurationException
 112    * @throws SAXException
 113    * @throws IOException
 114    */
 115  23096 public static final SimpleXPath getXPathLocation(final File xmlFile, final SimpleXPath xpath,
 116    final URL original)
 117    throws ParserConfigurationException, SAXException, IOException {
 118  23096 return getXPathLocation(xmlFile, xpath.toString(), original);
 119    }
 120   
 121    /**
 122    * Search simple XPath within an XML file.
 123    *
 124    * @param xmlFile Search this file.
 125    * @param xpath Search for this simple XPath.
 126    * @param original Original file location.
 127    * @return Source position information.
 128    * @throws ParserConfigurationException
 129    * @throws SAXException
 130    * @throws IOException
 131    */
 132  32954 public static final SimpleXPath getXPathLocation(final File xmlFile, final String xpath,
 133    final URL original)
 134    throws ParserConfigurationException, SAXException, IOException {
 135  32954 final XPathLocationParser parser = new XPathLocationParser(xpath);
 136  32950 parser.parse(xmlFile, original);
 137  32950 return parser.getFind();
 138    }
 139   
 140    /**
 141    * Writes calling convention to <code>System.err</code>.
 142    */
 143  0 public static final void printProgramInformation() {
 144  0 System.err.println("Name");
 145  0 System.err.println("----");
 146  0 System.err.println(IoUtility.getClassName(XPathLocationFinder.class)
 147    + " - find simple XML paths");
 148  0 System.err.println();
 149  0 System.err.println("Synopsis");
 150  0 System.err.println("-------------------");
 151  0 System.err.println("[-h] -xp[ath] <simpleXPath> <xmlFile>");
 152  0 System.err.println();
 153  0 System.err.println("Description");
 154  0 System.err.println("-----------");
 155  0 System.err.println(
 156    "This program finds the location of a given simple XPath in an XML file.");
 157  0 System.err.println();
 158  0 System.err.println("Options and Parameter");
 159  0 System.err.println("---------------------");
 160  0 System.err.println("-h writes this text and returns");
 161  0 System.err.println("-xpath set the language filter (default: \"en\")");
 162  0 System.err.println(
 163    "<simpleXPath> simple XML XPath, a subset of the abbreviation XPath notation");
 164  0 System.err.println(
 165    " \"/element1/element2[3]@attribute\" is an example for such a");
 166  0 System.err.println(
 167    " notation. This selects from the first occurrence of \"element1\"");
 168  0 System.err.println(
 169    " and from the third occurrence of subnode \"element2\" the attribute");
 170  0 System.err.println(
 171    " \"attribute\". The attribute is optional. It is always exactly one");
 172  0 System.err.println(" node or the attribute of one node specified.");
 173  0 System.err.println(" General syntax:");
 174  0 System.err.println(" {<element>\"[\"<index>\"]}+[\"@\"<attribute>]");
 175  0 System.err.println("<xmlFile> XML file");
 176  0 System.err.println();
 177  0 System.err.println("Parameter Examples");
 178  0 System.err.println("------------------");
 179  0 System.err.println(
 180    "-xp QEDEQ/CHAPTER/SECTION/NODE[2]/PRECEDING/AXIOM/FORMULA/FORALL/VAR@id");
 181  0 System.err.println("sample/qedeq_basic_concept.xml");
 182  0 System.err.println();
 183  0 System.err.println("Further information");
 184  0 System.err.println("-------------------");
 185  0 System.err.println("For more information about *Hilbert II* look at:");
 186  0 System.err.println("\thttp://www.qedeq.org/");
 187  0 System.err.println();
 188    }
 189   
 190    }