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