Clover Coverage Report
Coverage timestamp: Sat Sep 18 2010 04:09:52 UTC
../../../../../../img/srcFileCovDistChart9.png 34% of files have more coverage
39   125   8   13
4   80   0.21   3
3     2.67  
1    
 
  TestParser       Line # 38 39 8 84.8% 0.84782606
 
No Tests
 
1    /* This file is part of the project "Hilbert II" - http://www.qedeq.org
2    *
3    * Copyright 2000-2010, 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.bo.logic.wf;
17   
18    import java.io.BufferedReader;
19    import java.io.IOException;
20    import java.io.Reader;
21   
22    import javax.xml.parsers.ParserConfigurationException;
23    import javax.xml.parsers.SAXParser;
24    import javax.xml.parsers.SAXParserFactory;
25   
26    import org.qedeq.base.io.IoUtility;
27    import org.qedeq.base.trace.Trace;
28    import org.qedeq.kernel.base.list.Element;
29    import org.qedeq.kernel.common.DefaultSourceFileExceptionList;
30    import org.qedeq.kernel.common.DummyPlugin;
31    import org.qedeq.kernel.xml.handler.list.ElementHandler;
32    import org.qedeq.kernel.xml.parser.SaxDefaultHandler;
33    import org.qedeq.kernel.xml.parser.SaxErrorHandler;
34    import org.xml.sax.InputSource;
35    import org.xml.sax.SAXException;
36    import org.xml.sax.XMLReader;
37   
 
38    public class TestParser {
39   
40    /** This class. */
41    private static final Class CLASS = TestParser.class;
42   
43    private SaxDefaultHandler handler;
44    private XMLReader reader;
45   
46    /**
47    * Constructor.
48    *
49    * @param handler Default handler for this application.
50    * @throws ParserConfigurationException Severe parser configuration problem.
51    * @throws SAXException
52    */
 
53  137 toggle public TestParser(final SaxDefaultHandler handler) throws ParserConfigurationException,
54    SAXException {
55  137 super();
56   
57  137 this.handler = handler;
58   
59  137 final String factoryImpl = System.getProperty("javax.xml.parsers.SAXParserFactory");
60  137 if (factoryImpl == null) {
61  10 System.setProperty("javax.xml.parsers.SAXParserFactory",
62    "org.apache.xerces.jaxp.SAXParserFactoryImpl");
63    }
64  137 SAXParserFactory factory = SAXParserFactory.newInstance();
65  137 factory.setNamespaceAware(false);
66  137 factory.setValidating(false);
67   
68  137 final SAXParser parser = factory.newSAXParser();
69  137 reader = parser.getXMLReader();
70    }
71   
72    /**
73    * Parse input source.
74    *
75    * @param url Source URL. Only for information.
76    * @param in Parse data from this source.
77    * @throws SAXException Syntactical or semantical problem occurred.
78    * @throws IOException Technical problem occurred.
79    */
 
80  137 toggle private void parse(final String url, final Reader in)
81    throws IOException, SAXException {
82  137 final String method = "parse(URL, boolean, InputStream)";
83  137 BufferedReader dis = null;
84  137 DefaultSourceFileExceptionList exceptionList = new DefaultSourceFileExceptionList();;
85  137 try {
86  137 dis = new BufferedReader(in);
87  137 final InputSource input = new InputSource(dis);
88   
89  137 reader.setErrorHandler(new SaxErrorHandler(DummyPlugin.getInstance(), url, exceptionList));
90  137 handler.setExceptionList(exceptionList);
91  137 reader.setContentHandler(handler);
92  137 handler.setUrl(url);
93  137 reader.parse(input);
94    } finally {
95  137 if (dis != null) {
96  137 try {
97  137 dis.close();
98    } catch (Exception e) {
99  0 Trace.trace(CLASS, this, method, e);
100    }
101    }
102    }
103    }
104   
 
105  137 toggle static protected final Element createElement(final String xml) throws ParserConfigurationException,
106    SAXException, IOException {
107  137 try {
108  137 String data = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" + xml;
109  137 SaxDefaultHandler handler = new SaxDefaultHandler(new DummyPlugin());
110  137 ElementHandler simple = new ElementHandler(handler);
111  137 handler.setBasisDocumentHandler(simple);
112  137 TestParser parser = new TestParser(handler);
113  137 parser.parse(null, IoUtility.stringToReader(data));
114  137 return simple.getElement();
115    } catch (SAXException e) {
116  0 Trace.trace(TestParser.class, "createElement", e);
117  0 Trace.trace(TestParser.class, "createElement", e.getCause());
118  0 throw e;
119    } catch (IOException e) {
120  0 Trace.trace(TestParser.class, "createElement", e);
121  0 throw e;
122    }
123    }
124   
125    }