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