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