01: /*
02: * Copyright 2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.springframework.xml;
18:
19: import org.springframework.util.ClassUtils;
20:
21: /**
22: * Helper class used to find the current version of JAXP. We cannot depend on the Java version, since JAXP can be
23: * upgraded idenpendantly of the Java version.
24: * <p/>
25: * Only distinguishes between JAXP 1.0, 1.1, 1.3, and 1.4, since JAXP 1.2 was a maintenance release with no new
26: * classes.
27: *
28: * @author Arjen Poutsma
29: * @since 1.0.0
30: */
31: public abstract class JaxpVersion {
32:
33: public static final int JAXP_10 = 0;
34:
35: public static final int JAXP_11 = 1;
36:
37: public static final int JAXP_13 = 3;
38:
39: public static final int JAXP_14 = 4;
40:
41: private static final String JAXP_11_CLASS_NAME = "javax.xml.transform.Transformer";
42:
43: private static final String JAXP_13_CLASS_NAME = "javax.xml.xpath.XPath";
44:
45: private static final String JAXP_14_CLASS_NAME = "javax.xml.transform.stax.StAXSource";
46:
47: private static int jaxpVersion = JAXP_10;
48:
49: static {
50: try {
51: ClassUtils.forName(JAXP_14_CLASS_NAME);
52: jaxpVersion = JAXP_14;
53: } catch (ClassNotFoundException ex1) {
54: try {
55: ClassUtils.forName(JAXP_13_CLASS_NAME);
56: jaxpVersion = JAXP_13;
57: } catch (ClassNotFoundException ex2) {
58: try {
59: ClassUtils.forName(JAXP_11_CLASS_NAME);
60: jaxpVersion = JAXP_11;
61: } catch (ClassNotFoundException ex3) {
62: // default to JAXP 1.0
63: }
64: }
65: }
66: }
67:
68: /**
69: * Gets the JAXP version. This means we can do things like if <code>(getJaxpVersion() < JAXP_13)</code>.
70: *
71: * @return a code comparable to the JAXP_XX codes in this class
72: * @see #JAXP_10
73: * @see #JAXP_11
74: * @see #JAXP_13
75: * @see #JAXP_14
76: */
77: public static int getJaxpVersion() {
78: return jaxpVersion;
79: }
80: }
|