Clover coverage report - QedeqKernelSe Coverage Report
Coverage timestamp: Sa Dez 22 2007 01:35:21 CET
file stats: LOC: 123   Methods: 2
NCLOC: 75   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
Xml2Latex.java 75% 75,7% 50% 74,5%
coverage coverage
 1    /* $Id: Xml2Latex.java,v 1.11 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   
 18    package org.qedeq.kernel.latex;
 19   
 20    import java.io.File;
 21    import java.io.FileOutputStream;
 22    import java.io.IOException;
 23    import java.io.OutputStream;
 24   
 25    import org.qedeq.kernel.bo.module.ModuleDataException;
 26    import org.qedeq.kernel.bo.module.ModuleProperties;
 27    import org.qedeq.kernel.bo.module.QedeqBo;
 28    import org.qedeq.kernel.common.SourceFileExceptionList;
 29    import org.qedeq.kernel.context.KernelContext;
 30    import org.qedeq.kernel.trace.Trace;
 31    import org.qedeq.kernel.utility.IoUtility;
 32    import org.qedeq.kernel.utility.TextOutput;
 33    import org.qedeq.kernel.xml.mapper.ModuleDataException2XmlFileException;
 34    import org.qedeq.kernel.xml.parser.DefaultSourceFileExceptionList;
 35   
 36   
 37    /**
 38    * TODO mime 20070704: this content must be called by the KernelContext!
 39    *
 40    * @version $Revision: 1.11 $
 41    * @author Michael Meyling
 42    */
 43    public final class Xml2Latex {
 44   
 45    /**
 46    * Constructor.
 47    */
 48  0 private Xml2Latex() {
 49    // nothing to do
 50    }
 51   
 52    /**
 53    * Generate LaTeX file out of XML file.
 54    *
 55    * @param prop Take this QEDEQ module.
 56    * @param to Write to this file. Could be <code>null</code>.
 57    * @param language Resulting language. Could be <code>null</code>.
 58    * @param level Resulting detail level. Could be <code>null</code>.
 59    * @return File name of generated LaTeX file.
 60    * @throws SourceFileExceptionList Something went wrong.
 61    */
 62  21 public static String generate(final ModuleProperties prop, final File to, final String language,
 63    final String level) throws SourceFileExceptionList {
 64  21 final String method = "generate(String, String, String, String)";
 65  21 File destination = null;
 66  21 QedeqBo qedeqBo = null;
 67  21 try {
 68  21 Trace.begin(Xml2Latex.class, method);
 69  21 Trace.param(Xml2Latex.class, method, "prop", prop);
 70  21 Trace.param(Xml2Latex.class, method, "to", to);
 71  21 Trace.param(Xml2Latex.class, method, "language", language);
 72  21 Trace.param(Xml2Latex.class, method, "level", level);
 73  21 if (to == null) {
 74  9 String tex = prop.getModuleAddress().localizeInFileSystem(prop.getModuleAddress()
 75    .getURL());
 76  9 if (tex.toLowerCase().endsWith(".xml")) {
 77  9 tex = tex.substring(0, tex.length() - 4);
 78    }
 79  9 if (language != null && language.length() > 0) {
 80  6 tex = tex + "_" + language;
 81    }
 82    // the destination is the configured destination directory plus the (relative)
 83    // localized file (or path) name
 84  9 destination = new File(KernelContext.getInstance().getConfig()
 85    .getGenerationDirectory(), tex + ".tex").getCanonicalFile();
 86    } else {
 87  12 destination = to;
 88    }
 89    } catch (IOException e) {
 90  0 Trace.trace(Xml2Latex.class, method, e);
 91  0 throw new DefaultSourceFileExceptionList(e);
 92    }
 93  21 TextOutput printer = null;
 94  21 try {
 95  21 qedeqBo = prop.getModule();
 96  21 IoUtility.createNecessaryDirectories(destination);
 97  21 final OutputStream outputStream = new FileOutputStream(destination);
 98  21 printer = new TextOutput(destination.getName(), outputStream);
 99   
 100    // System.out.println(simple.getQedeq().toString());
 101  21 Qedeq2Latex.print(prop.getUrl(), qedeqBo, printer,
 102    language, level);
 103  21 return destination.getCanonicalPath();
 104    } catch (IOException e) {
 105  0 Trace.trace(Xml2Latex.class, method, e);
 106  0 throw new DefaultSourceFileExceptionList(e);
 107    } catch (RuntimeException e) {
 108  0 Trace.trace(Xml2Latex.class, method, e);
 109  0 throw new DefaultSourceFileExceptionList(e);
 110    } catch (ModuleDataException e) {
 111  0 Trace.trace(Xml2Latex.class, method, e);
 112  0 Trace.param(Xml2Latex.class, method, "context", e.getContext());
 113  0 throw ModuleDataException2XmlFileException.createXmlFileExceptionList(e,
 114    qedeqBo.getQedeq());
 115    } finally {
 116  21 if (printer != null) {
 117  21 printer.close();
 118    }
 119  21 Trace.end(Xml2Latex.class, method);
 120    }
 121    }
 122   
 123    }