Clover Coverage Report
Coverage timestamp: Sa Aug 2 2008 13:56:27 CEST
../../../../../img/srcFileCovDistChart8.png 47% of files have more coverage
15   131   9   2,14
2   44   0,6   7
7     1,29  
1    
 
  SimpleHandler       Line # 34 15 9 79,2% 0.7916667
 
  (136)
 
1    /* $Id: SimpleHandler.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    package org.qedeq.kernel.xml.parser;
18   
19    import java.lang.reflect.Method;
20    import java.net.URL;
21   
22    import org.qedeq.base.trace.Trace;
23    import org.xml.sax.Locator;
24    import org.xml.sax.helpers.DefaultHandler;
25   
26   
27    /**
28    * SAX handler that remembers {@link org.xml.sax.Locator} and possibly
29    * encoding of XML document.
30    *
31    * @version $Revision: 1.1 $
32    * @author Michael Meyling
33    */
 
34    public class SimpleHandler extends DefaultHandler {
35   
36    /** This class. */
37    private static final Class CLASS = SimpleHandler.class;
38   
39    /** Locator for current row and column information. */
40    private Locator locator;
41   
42    /** Which encoding was used to parse the document? */
43    private String encoding;
44   
45    /** File that is parsed. */
46    private URL url;
47   
48    /**
49    * Constructor.
50    */
 
51  33160 toggle public SimpleHandler() {
52  33160 super();
53    }
54   
55    /**
56    * Receive a Locator object for document events.
57    * Store the locator for use with other document events.
58    *
59    * @param locator A locator for all SAX document events.
60    * @see org.xml.sax.ContentHandler#setDocumentLocator
61    * @see org.xml.sax.Locator
62    */
 
63  33150 toggle public void setDocumentLocator(final Locator locator) {
64  33150 this.locator = locator;
65  33150 this.encoding = getEncoding(locator);
66  33150 Trace.paramInfo(CLASS, this, "setDocumentLocator(locator)", "encoding", encoding);
67    }
68   
69    /**
70    * Which encoding was used to parse the document?
71    *
72    * @return Encoding for parsed document. Maybe <code>null</code>.
73    */
 
74  0 toggle public String getEncoding() {
75  0 return this.encoding;
76    }
77   
78    /**
79    * There is no way in SAX 2.0.0 or 2.0.1 to get information about the encoding; the SAX
80    * Locator2 interface from the 1.1 extensions does provide methods to accomplish this,
81    * Assuming <code>Locator</code> is an instance of the SAX Locator interface that supports
82    * <code>Locator2</code> call we can get the information.
83    *
84    * @param locator Locator.
85    * @return Encoding. Maybe <code>null</code>.
86    */
 
87  33150 toggle private static String getEncoding(final Locator locator) {
88  33150 String encoding = null;
89  33150 Method getEncoding = null;
90  33150 try {
91  33150 getEncoding = locator.getClass().getMethod("getEncoding", new Class[]{});
92  33150 if (getEncoding != null) {
93  33150 encoding = (String) getEncoding.invoke(locator, null);
94    }
95    } catch (Exception e) {
96    // either this locator object doesn't have this
97    // method, or we're on an old JDK
98    }
99  33150 return encoding;
100    }
101   
102    /**
103    * Get document locator. This value set is set during parsing.
104    *
105    * @return Locator. Maybe <code>null</code>.
106    */
 
107  138780696 toggle protected Locator getLocator() {
108  138780696 return locator;
109    }
110   
111    /**
112    * Set original file URL.
113    *
114    * @param url Data from this source is parsed. This URL is only for information. The
115    * actual parsed data might be a local copy.
116    */
 
117  1053 toggle public final void setUrl(final URL url) {
118  1053 this.url = url;
119    }
120   
121    /**
122    * Get original file URL.
123    *
124    * @return Data from this source is parsed. This URL is only for information. The
125    * actual parsed data might be a local copy.
126    */
 
127  0 toggle public final URL getUrl() {
128  0 return url;
129    }
130   
131    }