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