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