Clover Coverage Report
Coverage timestamp: Fri May 24 2013 13:47:27 UTC
../../../../../img/srcFileCovDistChart8.png 62% of files have more coverage
25   101   7   12.5
10   60   0.28   2
2     3.5  
1    
 
  SaxEntityResolver       Line # 36 25 7 73% 0.7297297
 
  (202)
 
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.parser;
17   
18    import java.io.FileNotFoundException;
19    import java.io.InputStream;
20   
21    import org.qedeq.base.trace.Trace;
22    import org.qedeq.kernel.bo.KernelContext;
23    import org.qedeq.kernel.xml.handler.common.SaxDefaultHandler;
24    import org.xml.sax.EntityResolver;
25    import org.xml.sax.InputSource;
26    import org.xml.sax.SAXException;
27    import org.xml.sax.SAXParseException;
28   
29   
30    /**
31    * Resolve QEDEQ module XML schema.
32    *
33    * @version $Revision: 1.1 $
34    * @author Michael Meyling
35    */
 
36    public class SaxEntityResolver implements EntityResolver {
37   
38    /** This class. */
39    private static final Class CLASS = SaxEntityResolver.class;
40   
41    /** Handler that parses the document. */
42    private final SaxDefaultHandler handler;
43   
44    /**
45    * Constructor.
46    *
47    * @param handler This one does the parsing.
48    */
 
49  715 toggle public SaxEntityResolver(final SaxDefaultHandler handler) {
50  715 this.handler = handler;
51    }
52   
53    /* (non-Javadoc)
54    * @see org.xml.sax.EntityResolver#resolveEntity(java.lang.String, java.lang.String)
55    */
 
56  1411 toggle public InputSource resolveEntity(final String publicId, final String systemId)
57    throws FileNotFoundException, SAXException {
58  1411 final String method = "resolveEntity";
59  1411 Trace.param(CLASS, this, method, "systemId", systemId);
60  1411 Trace.param(CLASS, this, method, "publicId", publicId);
61  1411 if ((systemId == null)) {
62  0 return null;
63    }
64  1411 if (systemId.equals("http://www.qedeq.org/" + KernelContext.getInstance()
65    .getKernelVersionDirectory() + "/xml/qedeq.xsd")) {
66  1207 InputStream in = SaxEntityResolver.class.getResourceAsStream(
67    "/org/qedeq/kernel/xml/schema/qedeq.xsd");
68  1207 if (in == null) {
69  0 throw new FileNotFoundException("/org/qedeq/kernel/xml/schema/qedeq.xsd");
70    }
71  1207 InputSource inputSource = new InputSource(in);
72  1207 inputSource.setPublicId(publicId);
73  1207 inputSource.setSystemId(systemId);
74  1207 return inputSource;
75  204 } else if (systemId.equals("http://www.qedeq.org/"
76    + KernelContext.getInstance().getKernelVersionDirectory()
77    + "/xml/parser.xsd")) {
78  204 InputStream in = SaxEntityResolver.class.getResourceAsStream(
79    "/org/qedeq/kernel/xml/schema/parser.xsd");
80  204 if (in == null) {
81  0 throw new FileNotFoundException("/org/qedeq/kernel/xml/schema/parser.xsd");
82    }
83  204 InputSource inputSource = new InputSource(in);
84  204 inputSource.setPublicId(publicId);
85  204 inputSource.setSystemId(systemId);
86  204 return inputSource;
87    }
88  0 Trace.trace(CLASS, this, method, "unknown entity");
89  0 SAXParseException sax = handler.createSAXParseException(
90    "this kernel supports only the following XSDs: "
91    + "\"http://www.qedeq.org/" + KernelContext.getInstance()
92    .getKernelVersionDirectory() + "/xml/qedeq.xsd\"" + " and \n"
93    + "\"http://www.qedeq.org/"
94    + KernelContext.getInstance().getKernelVersionDirectory()
95    + "/xml/parser.xsd\" "
96    + "\nbut the document \"" + handler.getUrl() + "\" referenced \n\"" + systemId + "\"");
97  0 throw sax;
98    // LATER mime 20070604: this error should have correct location information,
99    // but is hasn't! this problem should be solved later...
100    }
101    }