|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
SimpleHandler | Line # 30 | 15 | 9 | 87.5% |
0.875
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
(9) | |||
Result | |||
0.875
|
org.qedeq.kernel.xml.dao.GenerateXmlTest.testGeneration
![]() |
1 PASS | |
0.7916667
|
org.qedeq.kernel.xml.parser.CharsetParserTest.testParse2
![]() |
1 PASS | |
0.7916667
|
org.qedeq.kernel.xml.parser.CharsetParserTest.testParse1
![]() |
1 PASS | |
0.7083333
|
org.qedeq.kernel.xml.tracker.XPathLocationFinderTest.testGetXPathLocation
![]() |
1 PASS | |
0.7083333
|
org.qedeq.kernel.xml.tracker.XPathLocationParserTest.testGetXPathLocation
![]() |
1 PASS | |
0.7083333
|
org.qedeq.kernel.xml.tracker.XPathLocationFinderTest.testTagNotFound
![]() |
1 PASS | |
0.625
|
org.qedeq.kernel.xml.parser.QedeqParserTest.testParse2
![]() |
1 PASS | |
0.625
|
org.qedeq.kernel.xml.parser.QedeqParserTest.testParse1
![]() |
1 PASS | |
0.083333336
|
org.qedeq.kernel.xml.tracker.XPathLocationFinderTest.testFileNotOk
![]() |
1 PASS | |
1 | /* This file is part of the project "Hilbert II" - http://www.qedeq.org | |
2 | * | |
3 | * Copyright 2000-2014, 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 | 320 |
![]() |
48 | 320 | 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 | 308 |
![]() |
60 | 308 | this.locator = locator; |
61 | 308 | this.encoding = getEncoding(locator); |
62 | 308 | 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 |
![]() |
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 | 308 |
![]() |
84 | 308 | String encoding = null; |
85 | 308 | Method getEncoding = null; |
86 | 308 | try { |
87 | 308 | getEncoding = locator.getClass().getMethod("getEncoding", new Class[]{}); |
88 | 308 | if (getEncoding != null) { |
89 | 308 | 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 | 308 | 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 | 3848 |
![]() |
104 | 3848 | 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 | 574 |
![]() |
114 | 574 | 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 |
![]() |
124 | 208 | return url; |
125 | } | |
126 | ||
127 | } |
|