Clover coverage report - QedeqKernelSe Coverage Report
Coverage timestamp: Do Jan 11 2007 09:03:50 CET
file stats: LOC: 169   Methods: 4
NCLOC: 109   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
XPathLocationFinder.java 0% 4,2% 25% 4,4%
coverage coverage
 1    /* $Id: XPathLocationFinder.java,v 1.13 2006/10/20 20:23:06 m31 Exp $
 2    *
 3    * This file is part of the project "Hilbert II" - http://www.qedeq.org
 4    *
 5    * Copyright 2000-2006, 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.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    * Find position of simple XPath expressions within an XML file.
 30    *
 31    * @version $Revision: 1.13 $
 32    * @author Michael Meyling
 33    */
 34    public final class XPathLocationFinder {
 35   
 36    /**
 37    * Constructor.
 38    */
 39  0 private XPathLocationFinder() {
 40    // nothing to do
 41    }
 42   
 43    /**
 44    * Main method.
 45    *
 46    * @param args Various parameters. See implementation of
 47    * {@link #printProgramInformation()}.
 48    * @throws ParserConfigurationException
 49    * @throws SAXException
 50    * @throws IOException
 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("-")) { // option
 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 { // unknown option
 79  0 printProgramInformation();
 80  0 System.err.println("Unknown option: " + option);
 81  0 return;
 82    }
 83    } else { // no option, must be file name
 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    * Search simple XPath within an XML file.
 104    *
 105    * @param xmlFile Search this file.
 106    * @param xpath Search for this simple XPath.
 107    * @return Source position information.
 108    * @throws ParserConfigurationException
 109    * @throws SAXException
 110    * @throws IOException
 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    * Writes calling convention to <code>System.err</code>.
 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    }