Clover coverage report - QedeqKernelSe Coverage Report
Coverage timestamp: Sa Dez 22 2007 01:35:21 CET
file stats: LOC: 124   Methods: 3
NCLOC: 73   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
Xml2Xml.java 33,3% 62,9% 66,7% 59,1%
coverage coverage
 1    /* $Id: Xml2Xml.java,v 1.1 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.bo.save;
 19   
 20    import java.io.File;
 21    import java.io.FileOutputStream;
 22    import java.io.IOException;
 23    import java.io.OutputStream;
 24    import java.net.URL;
 25   
 26    import org.qedeq.kernel.bo.module.ModuleDataException;
 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.latex.Qedeq2Xml;
 31    import org.qedeq.kernel.trace.Trace;
 32    import org.qedeq.kernel.utility.IoUtility;
 33    import org.qedeq.kernel.utility.TextOutput;
 34    import org.qedeq.kernel.xml.mapper.ModuleDataException2XmlFileException;
 35    import org.qedeq.kernel.xml.parser.DefaultSourceFileExceptionList;
 36   
 37   
 38    /**
 39    * Test application.
 40    *
 41    * @version $Revision: 1.1 $
 42    * @author Michael Meyling
 43    */
 44    public final class Xml2Xml {
 45   
 46    /**
 47    * Constructor.
 48    */
 49  0 private Xml2Xml() {
 50    // nothing to do
 51    }
 52   
 53    /**
 54    * Generate XML file out of XML file.
 55    *
 56    * @param from Read this XML file.
 57    * @param to Write to this file. Could be <code>null</code>.
 58    * @throws SourceFileExceptionList Module could not be successfully loaded.
 59    * @return File name of generated LaTeX file.
 60    */
 61  3 public static String generate(final File from, final File to)
 62    throws SourceFileExceptionList {
 63  3 final String method = "generate(File, File)";
 64  3 File destination;
 65  3 try {
 66  3 if (to != null) {
 67  3 destination = to.getCanonicalFile();
 68    } else {
 69  0 String xml = from.getName();
 70  0 if (xml.toLowerCase().endsWith(".xml")) {
 71  0 xml = xml.substring(0, xml.length() - 4);
 72    }
 73  0 destination = new File(from.getParentFile(), xml + "_.xml").getCanonicalFile();
 74    }
 75    } catch (IOException e) {
 76  0 Trace.trace(Xml2Xml.class, method, e);
 77  0 throw new DefaultSourceFileExceptionList(e);
 78    }
 79  3 return generate(IoUtility.toUrl(from), destination);
 80    }
 81   
 82    /**
 83    * Generate LaTeX file out of XML file.
 84    *
 85    * @param from Read this XML file.
 86    * @param to Write to this file. Could not be <code>null</code>.
 87    * @throws SourceFileExceptionList Module could not be successfully loaded.
 88    * @return File name of generated LaTeX file.
 89    */
 90  3 public static String generate(final URL from, final File to)
 91    throws SourceFileExceptionList {
 92  3 final String method = "generate(URL, File)";
 93  3 Trace.begin(Xml2Xml.class, method);
 94  3 Trace.param(Xml2Xml.class, method, "from", from);
 95  3 Trace.param(Xml2Xml.class, method, "to", to);
 96  3 QedeqBo qedeqBo = null;
 97  3 TextOutput printer = null;
 98  3 try {
 99  3 qedeqBo = KernelContext.getInstance().loadModule(from);
 100  3 IoUtility.createNecessaryDirectories(to);
 101  3 final OutputStream outputStream = new FileOutputStream(to);
 102  3 printer = new TextOutput(to.getName(), outputStream);
 103  3 Qedeq2Xml.print(from, qedeqBo, printer);
 104  3 return to.getCanonicalPath();
 105    } catch (IOException e) {
 106  0 Trace.trace(Xml2Xml.class, method, e);
 107  0 throw new DefaultSourceFileExceptionList(e);
 108    } catch (RuntimeException e) {
 109  0 Trace.trace(Xml2Xml.class, method, e);
 110  0 throw new DefaultSourceFileExceptionList(e);
 111    } catch (ModuleDataException e) {
 112  0 Trace.trace(Xml2Xml.class, method, e);
 113  0 Trace.param(Xml2Xml.class, method, "context", e.getContext());
 114  0 throw ModuleDataException2XmlFileException.createXmlFileExceptionList(e,
 115    qedeqBo.getQedeq());
 116    } finally {
 117  3 if (printer != null) {
 118  3 printer.close();
 119    }
 120  3 Trace.end(Xml2Xml.class, method);
 121    }
 122    }
 123   
 124    }