Clover Coverage Report
Coverage timestamp: Fri May 24 2013 13:47:27 UTC
../../../../../img/srcFileCovDistChart9.png 45% of files have more coverage
34   95   7   11.33
0   69   0.21   3
3     2.33  
1    
 
  XmlNormalizer       Line # 37 34 7 81.1% 0.8108108
 
  (1)
 
1    /* This file is part of the project "Hilbert II" - http://www.qedeq.org
2    *
3    * Copyright 2000-2013, Michael Meyling <mime@qedeq.org>.
4    *
5    * "Hilbert II" is free software; you can redistribute
6    * it and/or modify it under the terms of the GNU General Public
7    * License as published by the Free Software Foundation; either
8    * version 2 of the License, or (at your option) any later version.
9    *
10    * This program is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13    * GNU General Public License for more details.
14    */
15   
16    package org.qedeq.kernel.xml.test;
17   
18    import java.io.File;
19    import java.io.FileInputStream;
20    import java.io.FileOutputStream;
21    import java.io.IOException;
22    import java.io.InputStream;
23    import java.io.OutputStream;
24   
25    import javax.xml.parsers.ParserConfigurationException;
26    import javax.xml.parsers.SAXParser;
27    import javax.xml.parsers.SAXParserFactory;
28   
29    import org.qedeq.base.io.IoUtility;
30    import org.xml.sax.ErrorHandler;
31    import org.xml.sax.SAXException;
32    import org.xml.sax.SAXNotRecognizedException;
33    import org.xml.sax.SAXNotSupportedException;
34    import org.xml.sax.SAXParseException;
35    import org.xml.sax.XMLReader;
36   
 
37    public class XmlNormalizer {
38   
39    private XmlNormalizerHandler normalize;
40   
 
41  0 toggle public static void main (String args[]) throws Exception {
42  0 normalize(new File(args[0]), new File(args[1]));
43    }
44   
 
45  260 toggle public XmlNormalizer () throws SAXException {
46  260 ExceptionList parseErrorCollector = new ExceptionList();
47  260 ErrorHandler errorHandler = new SaxErrorHandler(parseErrorCollector);
48  260 SAXParserFactory factory = SAXParserFactory.newInstance();
49  260 factory.setNamespaceAware(true);
50  260 SAXParser parser;
51  260 try {
52  260 factory.setFeature("http://apache.org/xml/features/continue-after-fatal-error", false);
53  260 factory.setFeature("http://xml.org/sax/features/namespaces", false);
54  260 factory.setFeature("http://xml.org/sax/features/validation", false);
55  260 factory.setFeature("http://apache.org/xml/features/validation/schema", false);
56  260 factory.setValidating(false);
57  260 parser = factory.newSAXParser();
58    } catch (SAXNotRecognizedException e) {
59  0 throw new RuntimeException(e);
60    } catch (SAXNotSupportedException e) {
61  0 throw new RuntimeException(e);
62    } catch (ParserConfigurationException e) {
63  0 throw new RuntimeException(e);
64    }
65  260 XMLReader reader = parser.getXMLReader();
66  260 reader.setErrorHandler(errorHandler);
67   
68  260 normalize = new XmlNormalizerHandler();
69  260 reader.setContentHandler(normalize);
70   
71    }
72   
 
73  260 toggle public final static void normalize(final File from, final File to) throws IOException, SAXException {
74  260 XmlNormalizer g = new XmlNormalizer();
75  260 try {
76  260 InputStream is = null;
77  260 OutputStream os = null;
78  260 try {
79  260 System.out.println("\tnormalizing: " + from.getName());
80  260 System.out.println("\tinto: " + to.getName());
81  260 is = new FileInputStream(from);
82  260 os = new FileOutputStream(to);
83  260 g.normalize.parse(is, os);
84    } finally {
85  260 IoUtility.close(is);
86  260 IoUtility.close(os);
87    }
88    } catch (SAXParseException e) {
89  0 System.out.println(from.getName() + " Zeile: " + e.getLineNumber() + " Spalte: " + e.getColumnNumber()
90    + " " + e.getMessage());
91  0 throw e;
92    }
93    }
94   
95    }