Clover coverage report - QedeqKernelSe Coverage Report
Coverage timestamp: Do Dez 29 2005 18:38:29 CET
file stats: LOC: 176   Methods: 4
NCLOC: 111   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
Context2XPath.java 90,6% 93,4% 75% 92,1%
coverage coverage
 1    /* $Id: Context2XPath.java,v 1.15 2005/12/17 10:31:51 m31 Exp $
 2    *
 3    * This file is part of the project "Hilbert II" - http://www.qedeq.org
 4    *
 5    * Copyright 2000-2005, 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   
 18    package org.qedeq.kernel.xml.mapper;
 19   
 20    import java.util.StringTokenizer;
 21   
 22    import org.qedeq.kernel.bo.control.Context;
 23    import org.qedeq.kernel.log.Trace;
 24    import org.qedeq.kernel.utility.ReplaceUtility;
 25    import org.qedeq.kernel.xml.tracker.SimpleXPath;
 26   
 27    /**
 28    * Parses complete qedeq modules.
 29    *
 30    * @version $Revision: 1.15 $
 31    * @author Michael Meyling
 32    */
 33    public final class Context2XPath {
 34   
 35    /**
 36    * Constructor.
 37    */
 38  0 private Context2XPath() {
 39    // nothing to do
 40    }
 41   
 42    /**
 43    * Get file path out of context information.
 44    *
 45    * @param context Context information.
 46    * @return File path and name.
 47    */
 48  1 public static final String getFileName(final Context context) {
 49  1 return context.getModuleLocation();
 50    }
 51   
 52    /**
 53    * Get XPath out of context information.
 54    *
 55    * @param context Context information.
 56    * @return XPath.
 57    */
 58  402 public static final String getXPath(final Context context) {
 59  402 final String method = "getXPath(String)";
 60  402 String xpath = context.getLocationWithinModule();
 61  402 Trace.traceParam(Context2XPath.class, method, "context", xpath);
 62  402 xpath = ReplaceUtility.replace(xpath, ".get(", "[");
 63  402 xpath = ReplaceUtility.replace(xpath, "()", "");
 64  402 xpath = ReplaceUtility.replace(xpath, ")", "]");
 65  402 xpath = ReplaceUtility.replace(xpath, ".get", "/");
 66  402 xpath = ReplaceUtility.replace(xpath, "get", "/Qedeq/");
 67   
 68  402 xpath = incrementNumbers(xpath);
 69   
 70    // TODO mime 20050807: what if no Latex, Author, or other, exist? For regular files this is
 71    // ok, but if there is no element in the list?
 72    // TODO mime 20050708: isn't a replacement only one element by one better?
 73  402 xpath = ReplaceUtility.replace(xpath, "Title", "Title/Latex");
 74    // TODO mime 20050708: definition in XML file only formula
 75  402 xpath = ReplaceUtility.replace(xpath, "Definition/FormulaOrTerm", "Definition/Formula");
 76  402 xpath = ReplaceUtility.replace(xpath, "AuthorList", "Authors/Author");
 77  402 xpath = ReplaceUtility.replace(xpath, "ImportList", "Imports/Import");
 78  402 xpath = ReplaceUtility.replace(xpath, "UsedByList", "UsedBy/Specification");
 79  402 xpath = ReplaceUtility.replace(xpath, "ChapterList", "Chapter");
 80  402 xpath = ReplaceUtility.replace(xpath, "SectionList", "Section");
 81  402 xpath = ReplaceUtility.replace(xpath, "SubsectionList", "Subsections/*");
 82  402 xpath = ReplaceUtility.replace(xpath, "VariableList", "VARLIST/VAR");
 83  402 xpath = ReplaceUtility.replace(xpath, "List", "s");
 84  402 xpath = ReplaceUtility.replace(xpath, "/NodeType", "");
 85  402 xpath = ReplaceUtility.replace(xpath, "Summary", "Abstract/Latex");
 86  402 xpath = ReplaceUtility.replace(xpath, "Introduction", "Introduction/Latex");
 87  402 xpath = ReplaceUtility.replace(xpath, "PrecedingText", "PRECEDING/Latex");
 88  402 xpath = ReplaceUtility.replace(xpath, "SucceedingText", "SUCCEEDING/Latex");
 89  402 xpath = ReplaceUtility.replace(xpath, "Element", "*");
 90  402 xpath = ReplaceUtility.replace(xpath, "Proposition", "Theorem");
 91  402 xpath = ReplaceUtility.replace(xpath, "/Proofs", "");
 92   
 93    // TODO mime 20050807: integrate non formal proofs
 94  402 xpath = ReplaceUtility.replace(xpath, "/NonFormalProof", "/Proof/Latex");
 95   
 96  402 xpath = xpath.toUpperCase();
 97   
 98  402 SimpleXPath sxp = new SimpleXPath(xpath);
 99   
 100  402 final String beforeLast = sxp.getBeforeLastElement();
 101  402 final String last = sxp.getLastElement();
 102  402 if ("EMAIL".equals(last)) {
 103  3 sxp.deleteLastElement();
 104  3 sxp.setAttribute("email");
 105  399 } else if ("LABEL".equals(last)) {
 106  4 sxp.deleteLastElement();
 107  4 sxp.setAttribute("label");
 108  395 } else if ("ID".equals(last)) {
 109  7 sxp.deleteLastElement();
 110  7 sxp.setAttribute("id");
 111  388 } else if ("SPECIFICATION".equals(beforeLast) && "NAME".equals(last)) {
 112  5 sxp.deleteLastElement();
 113  5 sxp.setAttribute("name");
 114  383 } else if ("SPECIFICATION".equals(beforeLast) && "RULEVERSION".equals(last)) {
 115  5 sxp.deleteLastElement();
 116  5 sxp.setAttribute("ruleVersion");
 117  378 } else if ("CHAPTER".equals(beforeLast) && "NONUMBER".equals(last)) {
 118  3 sxp.deleteLastElement();
 119  3 sxp.setAttribute("noNumber");
 120  375 } else if ("SECTION".equals(beforeLast) && "NONUMBER".equals(last)) {
 121  0 sxp.deleteLastElement();
 122  0 sxp.setAttribute("noNumber");
 123  375 } else if ("*".equals(beforeLast) && "LATEX".equals(last)) {
 124  20 sxp.deleteLastElement();
 125  20 sxp.addElement("TEXT");
 126  20 sxp.addElement("LATEX");
 127  355 } else if ("DEFINITION".equals(beforeLast) && "TYPE".equals(last)) {
 128  4 sxp.deleteLastElement();
 129  4 sxp.setAttribute("kind");
 130  351 } else if ("DEFINITION".equals(beforeLast) && "ARGUMENTNUMBER".equals(last)) {
 131  4 sxp.deleteLastElement();
 132  4 sxp.setAttribute("arguments");
 133  347 } else if ("DEFINITION".equals(beforeLast) && "ARGUMENTNUMBER".equals(last)) {
 134  0 sxp.deleteLastElement();
 135  0 sxp.setAttribute("arguments");
 136  347 } else if ("*".equals(beforeLast) && "LEVEL".equals(last)) {
 137  1 sxp.deleteLastElement();
 138  1 sxp.setAttribute("level");
 139  346 } else if ("*".equals(beforeLast) && "NONUMBER".equals(last)) {
 140  0 sxp.deleteLastElement();
 141  0 sxp.setAttribute("noNumber");
 142  346 } else if ("*".equals(beforeLast) && "NAME".equals(last)) {
 143  18 final int len = sxp.getElementOccurrence(sxp.size() - 1);
 144  18 sxp.deleteLastElement();
 145  18 sxp.addElement("NAME");
 146  18 sxp.addElement("LATEX", len);
 147    }
 148   
 149  402 xpath = sxp.toString();
 150  402 Trace.traceParam(Context2XPath.class, method, "xpath", xpath);
 151  402 return xpath;
 152    }
 153   
 154    /**
 155    * Increment all element occurrence numbers in "[]" by one.
 156    *
 157    * @param xpath Like "a[0]b[1]".
 158    * @return Like "a[1]b[2]".
 159    */
 160  402 private static String incrementNumbers(final String xpath) {
 161  402 final StringTokenizer tokenizer = new StringTokenizer(xpath, "/", true);
 162  402 String newXpath = "";
 163  402 while (tokenizer.hasMoreTokens()) {
 164  3562 String token = tokenizer.nextToken();
 165  3562 if (token.indexOf('[') >= 0) {
 166  977 final StringTokenizer getnu = new StringTokenizer(token, "[]");
 167  977 newXpath += getnu.nextToken() + "[";
 168  977 newXpath += ((new Integer(getnu.nextToken())).intValue() + 1) + "]";
 169    } else {
 170  2585 newXpath += token;
 171    }
 172    }
 173  402 return newXpath;
 174    }
 175   
 176    }