1 |
|
package org.apache.torque.engine.database.transform; |
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
import java.io.IOException; |
23 |
|
import java.io.InputStream; |
24 |
|
|
25 |
|
import org.apache.commons.logging.Log; |
26 |
|
import org.apache.commons.logging.LogFactory; |
27 |
|
import org.xml.sax.EntityResolver; |
28 |
|
import org.xml.sax.InputSource; |
29 |
|
import org.xml.sax.SAXException; |
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
@author |
35 |
|
@author |
36 |
|
@author |
37 |
|
@version |
38 |
|
|
|
|
| 0% |
Uncovered Elements: 24 (24) |
Complexity: 7 |
Complexity Density: 0.47 |
|
39 |
|
public class DTDResolver implements EntityResolver |
40 |
|
{ |
41 |
|
|
42 |
|
public static final String WEB_SITE_DTD |
43 |
|
= "http://db.apache.org/torque/dtd/database_3_3.dtd"; |
44 |
|
|
45 |
|
|
46 |
|
public static final String WEB_SITE_DTD_3_2 |
47 |
|
= "http://db.apache.org/torque/dtd/database_3_2.dtd"; |
48 |
|
|
49 |
|
|
50 |
|
private static Log log = LogFactory.getLog(DTDResolver.class); |
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
55 |
0
|
public DTDResolver()... |
56 |
|
throws SAXException |
57 |
|
{ |
58 |
|
} |
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
@param |
68 |
|
@param |
69 |
|
@return |
70 |
|
|
71 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
72 |
0
|
public InputSource resolveEntity(String publicId, String systemId)... |
73 |
|
throws IOException, SAXException |
74 |
|
{ |
75 |
0
|
if (WEB_SITE_DTD.equals(systemId)) |
76 |
|
{ |
77 |
0
|
return readFromClasspath("database.dtd"); |
78 |
|
} |
79 |
0
|
else if (WEB_SITE_DTD_3_2.equals(systemId)) |
80 |
|
{ |
81 |
0
|
return readFromClasspath("database_3_2.dtd"); |
82 |
|
} |
83 |
|
else |
84 |
|
{ |
85 |
0
|
log.debug("Resolver: used default behaviour"); |
86 |
0
|
return null; |
87 |
|
} |
88 |
|
} |
89 |
|
|
90 |
|
|
91 |
|
|
92 |
|
|
93 |
|
@param |
94 |
|
@return |
95 |
|
|
96 |
|
@throws |
97 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0.33 |
|
98 |
0
|
private InputSource readFromClasspath(String resourceName)... |
99 |
|
throws SAXException |
100 |
|
{ |
101 |
0
|
try |
102 |
|
{ |
103 |
0
|
InputStream dtdStream |
104 |
|
= getClass().getResourceAsStream(resourceName); |
105 |
|
|
106 |
|
|
107 |
|
|
108 |
|
|
109 |
0
|
if (dtdStream != null) |
110 |
|
{ |
111 |
0
|
String pkg = getClass().getName().substring(0, |
112 |
|
getClass().getName().lastIndexOf('.')); |
113 |
0
|
log.debug("Resolver: used " + resourceName + " from '" |
114 |
|
+ pkg + "' package"); |
115 |
0
|
return new InputSource(dtdStream); |
116 |
|
} |
117 |
|
else |
118 |
|
{ |
119 |
0
|
log.warn("Could not locate database.dtd"); |
120 |
0
|
return null; |
121 |
|
} |
122 |
|
} |
123 |
|
catch (Exception ex) |
124 |
|
{ |
125 |
0
|
throw new SAXException( |
126 |
|
"Could not get stream for " + resourceName, |
127 |
|
ex); |
128 |
|
} |
129 |
|
} |
130 |
|
} |