Clover coverage report - QedeqKernelSe Coverage Report
Coverage timestamp: Do Mai 10 2007 03:16:40 CEST
file stats: LOC: 220   Methods: 2
NCLOC: 133   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
Context2XPathOld.java 0% 0% 0% 0%
coverage
 1    /* $Id: Context2XPathOld.java,v 1.2 2007/04/12 23:50:10 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   
 18    package org.qedeq.kernel.xml.mapper;
 19   
 20    import java.util.StringTokenizer;
 21   
 22    import org.qedeq.kernel.bo.module.ModuleContext;
 23    import org.qedeq.kernel.trace.Trace;
 24    import org.qedeq.kernel.utility.ReplaceUtility;
 25    import org.qedeq.kernel.xml.tracker.SimpleXPath;
 26   
 27    /**
 28    * This class is outdated. Worked with XSD version 0.03.01. Can not find locations
 29    * within formulas or terms.
 30    *
 31    * <p>
 32    * Map content string to SimpleXPath string. This class makes it possible to transfer an location
 33    * of an {@link org.qedeq.kernel.base.module.Qedeq} object into an XPath like position description
 34    * for an XML file representation of that object.
 35    * <p>
 36    * This class has maps something like<br>
 37    * <code>
 38    * getChapterList().get(4).getSectionList().get(0).getSubsectionList().get(4).getLatex().get(0)
 39    * </code><br>
 40    * into<br>
 41    * <code>QEDEQ/CHAPTER[5]/SECTION/SUBSECTIONS/*[5]/TEXT/LATEX</code>
 42    *
 43    * mime 20070109: use visitor and Qedeq-Object to get XPath; this is necessary because
 44    * an Atom (if it is the first in an ElementList) is always an attribute tag - therefore the
 45    * XML element counting doesn't work (you have to subtract one if the first element is an
 46    * Atom)
 47    *
 48    * @version $Revision: 1.2 $
 49    * @author Michael Meyling
 50    * @deprecated
 51    */
 52    public final class Context2XPathOld {
 53   
 54    /**
 55    * Constructor.
 56    */
 57  0 private Context2XPathOld() {
 58    // nothing to do
 59    }
 60   
 61    /**
 62    * Get file path out of context information.
 63    *
 64    * @param context Context information.
 65    * @return File path and name.
 66    * @deprecated
 67    */
 68    public static final String getFileName(final ModuleContext context) {
 69    return context.getModuleLocation();
 70    }
 71   
 72    /**
 73    * Get XPath out of context information.
 74    *
 75    * @param context Context information.
 76    * @return XPath.
 77    * @deprecated
 78    */
 79    public static final String getXPath(final ModuleContext context) {
 80    final String method = "getXPath(String)";
 81    String xpath = context.getLocationWithinModule();
 82    Trace.param(Context2XPathOld.class, method, "context", xpath);
 83    xpath = ReplaceUtility.replace(xpath, ".get(", "[");
 84    xpath = ReplaceUtility.replace(xpath, "()", "");
 85    xpath = ReplaceUtility.replace(xpath, ")", "]");
 86    xpath = ReplaceUtility.replace(xpath, ".get", "/");
 87    xpath = ReplaceUtility.replace(xpath, "get", "/Qedeq/");
 88   
 89    // mime 20050807: what if no Latex, Author, or other, exist? For regular files this is
 90    // ok, but if there is no element in the list?
 91    // mime 20050708: isn't a replacement only one element by one better?
 92    xpath = ReplaceUtility.replace(xpath, "Title[", "Title/Latex[");
 93    // mime 20050708: definition in XML file only formula
 94    xpath = ReplaceUtility.replace(xpath, "PredicateDefinition", "DEFINITION_PREDICATE");
 95    xpath = ReplaceUtility.replace(xpath, "FunctionDefinition", "DEFINITION_FUNCTION");
 96    xpath = ReplaceUtility.replace(xpath, "AuthorList[", "Authors/Author[");
 97    xpath = ReplaceUtility.replace(xpath, "ImportList[", "Imports/Import[");
 98    xpath = ReplaceUtility.replace(xpath, "LiteratureItemList[", "BIBLIOGRAPHY/ITEM[");
 99    xpath = ReplaceUtility.replace(xpath, "LiteratureItemList", "BIBLIOGRAPHY");
 100    xpath = ReplaceUtility.replace(xpath, "/Item[", "/Latex[");
 101    xpath = ReplaceUtility.replace(xpath, "/Item", "/Latex");
 102    xpath = ReplaceUtility.replace(xpath, "UsedByList[", "UsedBy/Specification[");
 103    xpath = ReplaceUtility.replace(xpath, "ChapterList[", "Chapter[");
 104    xpath = ReplaceUtility.replace(xpath, "AuthorList[", "Author[");
 105    xpath = ReplaceUtility.replace(xpath, "AuthorList", "Authors");
 106    xpath = ReplaceUtility.replace(xpath, "ImportList", "Imports");
 107    xpath = ReplaceUtility.replace(xpath, "LocationList", "Locations");
 108    xpath = ReplaceUtility.replace(xpath, "LinkList[", "Link[");
 109    xpath = ReplaceUtility.replace(xpath, "SectionList[", "Section[");
 110    xpath = ReplaceUtility.replace(xpath, "SubsectionList", "Subsections/*");
 111    xpath = ReplaceUtility.replace(xpath, "VariableList", "VARLIST/*");
 112    xpath = ReplaceUtility.replace(xpath, "ProofList[", "PROOF[");
 113    xpath = ReplaceUtility.replace(xpath, "ProofList", "PROOF");
 114    xpath = ReplaceUtility.replace(xpath, "/NodeType", "");
 115    xpath = ReplaceUtility.replace(xpath, "Summary", "Abstract/Latex");
 116    xpath = ReplaceUtility.replace(xpath, "Introduction", "Introduction/Latex");
 117    xpath = ReplaceUtility.replace(xpath, "PrecedingText", "PRECEDING/Latex");
 118    xpath = ReplaceUtility.replace(xpath, "SucceedingText", "SUCCEEDING/Latex");
 119    xpath = ReplaceUtility.replace(xpath, "Description[", "Description/Latex[");
 120    xpath = ReplaceUtility.replace(xpath, "Proposition", "Theorem");
 121    xpath = ReplaceUtility.replace(xpath, "Formula/Element/", "Formula/*/");
 122    xpath = ReplaceUtility.replace(xpath, "Element", "*");
 123   
 124    // TODO mime 20050807: integrate non formal proofs
 125    xpath = ReplaceUtility.replace(xpath, "/NonFormalProof[", "/Latex[");
 126    xpath = ReplaceUtility.replace(xpath, "/NonFormalProof", "/Latex");
 127   
 128    xpath = ReplaceUtility.replace(xpath, "/List", "");
 129    xpath = ReplaceUtility.replace(xpath, "List", "");
 130    xpath = ReplaceUtility.replace(xpath, "(", "[");
 131    xpath = xpath.toUpperCase();
 132   
 133    xpath = incrementNumbers(xpath);
 134   
 135   
 136    SimpleXPath sxp = new SimpleXPath(xpath);
 137   
 138    final String beforeLast = sxp.getBeforeLastElement();
 139    final String last = sxp.getLastElement();
 140    if ("EMAIL".equals(last)) {
 141    sxp.deleteLastElement();
 142    sxp.setAttribute("email");
 143    } else if ("LABEL".equals(last)) {
 144    sxp.deleteLastElement();
 145    sxp.setAttribute("label");
 146    } else if ("ID".equals(last)) {
 147    sxp.deleteLastElement();
 148    sxp.setAttribute("id");
 149    } else if ("SPECIFICATION".equals(beforeLast) && "NAME".equals(last)) {
 150    sxp.deleteLastElement();
 151    sxp.setAttribute("name");
 152    } else if ("SPECIFICATION".equals(beforeLast) && "RULEVERSION".equals(last)) {
 153    sxp.deleteLastElement();
 154    sxp.setAttribute("ruleVersion");
 155    } else if ("CHAPTER".equals(beforeLast) && "NONUMBER".equals(last)) {
 156    sxp.deleteLastElement();
 157    sxp.setAttribute("noNumber");
 158    } else if ("SECTION".equals(beforeLast) && "NONUMBER".equals(last)) {
 159    sxp.deleteLastElement();
 160    sxp.setAttribute("noNumber");
 161    } else if ("*".equals(beforeLast) && "LATEX".equals(last)) {
 162    sxp.deleteLastElement();
 163    sxp.addElement("TEXT");
 164    sxp.addElement("LATEX");
 165    } else if ("DEFINITION_PREDICATE".equals(beforeLast) && "ARGUMENTNUMBER".equals(last)) {
 166    sxp.deleteLastElement();
 167    sxp.setAttribute("arguments");
 168    } else if ("DEFINITION_PREDICATE".equals(beforeLast) && "NAME".equals(last)) {
 169    sxp.deleteLastElement();
 170    sxp.setAttribute("name");
 171    } else if ("DEFINITION_FUNCTION".equals(beforeLast) && "ARGUMENTNUMBER".equals(last)) {
 172    sxp.deleteLastElement();
 173    sxp.setAttribute("arguments");
 174    } else if ("DEFINITION_FUNCTION".equals(beforeLast) && "NAME".equals(last)) {
 175    sxp.deleteLastElement();
 176    sxp.setAttribute("name");
 177    } else if ("RULE".equals(beforeLast) && "NAME".equals(last)) {
 178    sxp.deleteLastElement();
 179    sxp.setAttribute("name");
 180    } else if ("*".equals(beforeLast) && "LEVEL".equals(last)) {
 181    sxp.deleteLastElement();
 182    sxp.setAttribute("level");
 183    } else if ("*".equals(beforeLast) && "NONUMBER".equals(last)) {
 184    sxp.deleteLastElement();
 185    sxp.setAttribute("noNumber");
 186    } else if ("*".equals(beforeLast) && "NAME".equals(last)) {
 187    final int len = sxp.getElementOccurrence(sxp.size() - 1);
 188    sxp.deleteLastElement();
 189    sxp.addElement("NAME");
 190    sxp.addElement("LATEX", len);
 191    }
 192   
 193    xpath = sxp.toString();
 194    Trace.param(Context2XPathOld.class, method, "xpath", xpath);
 195    return xpath;
 196    }
 197   
 198    /**
 199    * Increment all element occurrence numbers in "[]" by one.
 200    *
 201    * @param xpath Like "a[0]b[1]".
 202    * @return Like "a[1]b[2]".
 203    */
 204  0 private static String incrementNumbers(final String xpath) {
 205  0 final StringTokenizer tokenizer = new StringTokenizer(xpath, "/", true);
 206  0 String newXpath = "";
 207  0 while (tokenizer.hasMoreTokens()) {
 208  0 String token = tokenizer.nextToken();
 209  0 if (token.indexOf('[') >= 0) {
 210  0 final StringTokenizer getnu = new StringTokenizer(token, "[]");
 211  0 newXpath += getnu.nextToken() + "[";
 212  0 newXpath += ((new Integer(getnu.nextToken())).intValue() + 1) + "]";
 213    } else {
 214  0 newXpath += token;
 215    }
 216    }
 217  0 return newXpath;
 218    }
 219   
 220    }