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