Clover coverage report - QedeqKernelSe Coverage Report
Coverage timestamp: Do Mrz 27 2008 21:46:26 CET
file stats: LOC: 113   Methods: 2
NCLOC: 64   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
Xml2Latex.java 75% 81,2% 50% 78,6%
coverage coverage
 1    /* $Id: Xml2Latex.java,v 1.13 2008/03/27 05:16:25 m31 Exp $
 2    *
 3    * This file is part of the project "Hilbert II" - http://www.qedeq.org
 4    *
 5    * Copyright 2000-2008, 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.control.KernelQedeqBo;
 26    import org.qedeq.kernel.common.DefaultSourceFileExceptionList;
 27    import org.qedeq.kernel.common.SourceFileExceptionList;
 28    import org.qedeq.kernel.context.KernelContext;
 29    import org.qedeq.kernel.trace.Trace;
 30    import org.qedeq.kernel.utility.IoUtility;
 31    import org.qedeq.kernel.utility.TextOutput;
 32   
 33   
 34    /**
 35    * TODO mime 20070704: this content must be called by the KernelContext!
 36    *
 37    * @version $Revision: 1.13 $
 38    * @author Michael Meyling
 39    */
 40    public final class Xml2Latex {
 41   
 42    /** This class. */
 43    private static final Class CLASS = Xml2Latex.class;
 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  28 public static String generate(final KernelQedeqBo prop, final File to, final String language,
 63    final String level) throws SourceFileExceptionList {
 64  28 final String method = "generate(String, String, String, String)";
 65  28 File destination = null;
 66  28 try {
 67  28 Trace.begin(CLASS, method);
 68  28 Trace.param(CLASS, method, "prop", prop);
 69  28 Trace.param(CLASS, method, "to", to);
 70  28 Trace.param(CLASS, method, "language", language);
 71  28 Trace.param(CLASS, method, "level", level);
 72  28 if (to == null) {
 73  19 String tex = prop.getModuleAddress().getFileName();
 74  19 if (tex.toLowerCase().endsWith(".xml")) {
 75  19 tex = tex.substring(0, tex.length() - 4);
 76    }
 77  19 if (language != null && language.length() > 0) {
 78  14 tex = tex + "_" + language;
 79    }
 80    // the destination is the configured destination directory plus the (relative)
 81    // localized file (or path) name
 82  19 destination = new File(KernelContext.getInstance().getConfig()
 83    .getGenerationDirectory(), tex + ".tex").getCanonicalFile();
 84    } else {
 85  9 destination = to;
 86    }
 87    } catch (IOException e) {
 88  0 Trace.trace(CLASS, method, e);
 89  0 throw new DefaultSourceFileExceptionList(e);
 90    }
 91  28 TextOutput printer = null;
 92  28 try {
 93  28 IoUtility.createNecessaryDirectories(destination);
 94  28 final OutputStream outputStream = new FileOutputStream(destination);
 95  28 printer = new TextOutput(destination.getName(), outputStream);
 96   
 97  28 Qedeq2Latex.print(prop, printer, language, level);
 98  28 return destination.getCanonicalPath();
 99    } catch (IOException e) {
 100  0 Trace.trace(CLASS, method, e);
 101  0 throw new DefaultSourceFileExceptionList(e);
 102    } catch (RuntimeException e) {
 103  0 Trace.trace(CLASS, method, e);
 104  0 throw new DefaultSourceFileExceptionList(e);
 105    } finally {
 106  28 if (printer != null) {
 107  28 printer.close();
 108    }
 109  28 Trace.end(CLASS, method);
 110    }
 111    }
 112   
 113    }