|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
WebXmlVersion.java | 100% | 85.7% | 70% | 84.6% |
|
1 |
/*
|
|
2 |
* ====================================================================
|
|
3 |
*
|
|
4 |
* The Apache Software License, Version 1.1
|
|
5 |
*
|
|
6 |
* Copyright (c) 2003 The Apache Software Foundation. All rights
|
|
7 |
* reserved.
|
|
8 |
*
|
|
9 |
* Redistribution and use in source and binary forms, with or without
|
|
10 |
* modification, are permitted provided that the following conditions
|
|
11 |
* are met:
|
|
12 |
*
|
|
13 |
* 1. Redistributions of source code must retain the above copyright
|
|
14 |
* notice, this list of conditions and the following disclaimer.
|
|
15 |
*
|
|
16 |
* 2. Redistributions in binary form must reproduce the above copyright
|
|
17 |
* notice, this list of conditions and the following disclaimer in
|
|
18 |
* the documentation and/or other materials provided with the
|
|
19 |
* distribution.
|
|
20 |
*
|
|
21 |
* 3. The end-user documentation included with the redistribution, if
|
|
22 |
* any, must include the following acknowlegement:
|
|
23 |
* "This product includes software developed by the
|
|
24 |
* Apache Software Foundation (http://www.apache.org/)."
|
|
25 |
* Alternately, this acknowlegement may appear in the software itself,
|
|
26 |
* if and wherever such third-party acknowlegements normally appear.
|
|
27 |
*
|
|
28 |
* 4. The names "The Jakarta Project", "Cactus" and "Apache Software
|
|
29 |
* Foundation" must not be used to endorse or promote products
|
|
30 |
* derived from this software without prior written permission. For
|
|
31 |
* written permission, please contact apache@apache.org.
|
|
32 |
*
|
|
33 |
* 5. Products derived from this software may not be called "Apache"
|
|
34 |
* nor may "Apache" appear in their names without prior written
|
|
35 |
* permission of the Apache Group.
|
|
36 |
*
|
|
37 |
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
|
38 |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
39 |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
40 |
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
|
|
41 |
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
42 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
43 |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
|
44 |
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
45 |
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
46 |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
|
47 |
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
48 |
* SUCH DAMAGE.
|
|
49 |
* ====================================================================
|
|
50 |
*
|
|
51 |
* This software consists of voluntary contributions made by many
|
|
52 |
* individuals on behalf of the Apache Software Foundation. For more
|
|
53 |
* information on the Apache Software Foundation, please see
|
|
54 |
* <http://www.apache.org/>.
|
|
55 |
*
|
|
56 |
*/
|
|
57 |
package org.apache.cactus.integration.ant.deployment;
|
|
58 |
|
|
59 |
import org.w3c.dom.DocumentType;
|
|
60 |
|
|
61 |
/**
|
|
62 |
* Enumerated type that represents the version of the web deployment descriptor.
|
|
63 |
*
|
|
64 |
* @author <a href="mailto:cmlenz@apache.org">Christopher Lenz</a>
|
|
65 |
*
|
|
66 |
* @since Cactus 1.5
|
|
67 |
* @version $Id: WebXmlVersion.java,v 1.3.2.3 2003/10/23 18:20:45 vmassol Exp $
|
|
68 |
*/
|
|
69 |
public final class WebXmlVersion implements Comparable |
|
70 |
{ |
|
71 |
|
|
72 |
// Public Constants --------------------------------------------------------
|
|
73 |
|
|
74 |
/**
|
|
75 |
* Instance for version 2.2.
|
|
76 |
*/
|
|
77 |
public static final WebXmlVersion V2_2 = new WebXmlVersion("2.2", |
|
78 |
"-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN",
|
|
79 |
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd");
|
|
80 |
|
|
81 |
/**
|
|
82 |
* Instance for version 2.3.
|
|
83 |
*/
|
|
84 |
public static final WebXmlVersion V2_3 = new WebXmlVersion("2.3", |
|
85 |
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN",
|
|
86 |
"http://java.sun.com/dtd/web-app_2_3.dtd");
|
|
87 |
|
|
88 |
// Instance Variables ------------------------------------------------------
|
|
89 |
|
|
90 |
/**
|
|
91 |
* The version as strnig,
|
|
92 |
*/
|
|
93 |
private String version;
|
|
94 |
|
|
95 |
/**
|
|
96 |
* The public ID of the corresponding document type.
|
|
97 |
*/
|
|
98 |
private String publicId;
|
|
99 |
|
|
100 |
/**
|
|
101 |
* The system ID of the corresponding document type.
|
|
102 |
*/
|
|
103 |
public String systemId;
|
|
104 |
|
|
105 |
// Constructors ------------------------------------------------------------
|
|
106 |
|
|
107 |
/**
|
|
108 |
* Constructor.
|
|
109 |
*
|
|
110 |
* @param theVersion The version as string
|
|
111 |
* @param thePublicId The public ID of the correspondig document type
|
|
112 |
* @param theSystemId The system ID of the correspondig document type
|
|
113 |
*/
|
|
114 | 6 |
private WebXmlVersion(String theVersion, String thePublicId,
|
115 |
String theSystemId) |
|
116 |
{ |
|
117 | 6 |
this.version = theVersion;
|
118 | 6 |
this.publicId = thePublicId;
|
119 | 6 |
this.systemId = theSystemId;
|
120 |
} |
|
121 |
|
|
122 |
// Public Methods ----------------------------------------------------------
|
|
123 |
|
|
124 |
/**
|
|
125 |
* @see java.lang.Comparable#compareTo
|
|
126 |
*/
|
|
127 | 21 |
public int compareTo(Object theOther) |
128 |
{ |
|
129 | 21 |
if (theOther == this) |
130 |
{ |
|
131 | 13 |
return 0;
|
132 |
} |
|
133 | 8 |
WebXmlVersion otherVersion = (WebXmlVersion) theOther; |
134 | 8 |
if (otherVersion == V2_3)
|
135 |
{ |
|
136 | 1 |
return -1;
|
137 |
} |
|
138 | 7 |
return 1;
|
139 |
} |
|
140 |
|
|
141 |
/**
|
|
142 |
* @see java.lang.Object#toString
|
|
143 |
*/
|
|
144 | 8 |
public boolean equals(Object theOther) |
145 |
{ |
|
146 | 8 |
return super.equals(theOther); |
147 |
} |
|
148 |
|
|
149 |
/**
|
|
150 |
* @see java.lang.Object#hashCode
|
|
151 |
*/
|
|
152 | 0 |
public int hashCode() |
153 |
{ |
|
154 | 0 |
return super.hashCode(); |
155 |
} |
|
156 |
|
|
157 |
/**
|
|
158 |
* Returns the tag name.
|
|
159 |
*
|
|
160 |
* @return The tag name
|
|
161 |
*/
|
|
162 | 0 |
public String getVersion()
|
163 |
{ |
|
164 | 0 |
return this.version; |
165 |
} |
|
166 |
|
|
167 |
/**
|
|
168 |
* Returns the public ID of the document type corresponding to the
|
|
169 |
* descriptor version.
|
|
170 |
*
|
|
171 |
* @return The public ID
|
|
172 |
*/
|
|
173 | 88 |
public String getPublicId()
|
174 |
{ |
|
175 | 88 |
return publicId;
|
176 |
} |
|
177 |
|
|
178 |
/**
|
|
179 |
* Returns the system ID of the document type corresponding to the
|
|
180 |
* descriptor version.
|
|
181 |
*
|
|
182 |
* @return The system ID
|
|
183 |
*/
|
|
184 | 52 |
public String getSystemId()
|
185 |
{ |
|
186 | 52 |
return systemId;
|
187 |
} |
|
188 |
|
|
189 |
/**
|
|
190 |
* @see java.lang.Object#toString
|
|
191 |
*/
|
|
192 | 0 |
public String toString()
|
193 |
{ |
|
194 | 0 |
return getVersion();
|
195 |
} |
|
196 |
|
|
197 |
/**
|
|
198 |
* Returns the version corresponding to the given document type.
|
|
199 |
*
|
|
200 |
* @param theDocType The document type
|
|
201 |
* @return The version that matches the document type, or <code>null</code>
|
|
202 |
* if the doctype is not recognized
|
|
203 |
* @throws NullPointerException If the document type is <code>null</code>
|
|
204 |
*/
|
|
205 | 25 |
public static WebXmlVersion valueOf(DocumentType theDocType) |
206 |
throws NullPointerException
|
|
207 |
{ |
|
208 | 25 |
return valueOf(theDocType.getPublicId());
|
209 |
} |
|
210 |
|
|
211 |
/**
|
|
212 |
* Returns the version corresponding to the given public ID.
|
|
213 |
*
|
|
214 |
* @param thePublicId The public ID
|
|
215 |
* @return The version that matches the public ID, or <code>null</code>
|
|
216 |
* if the ID is not recognized
|
|
217 |
*/
|
|
218 | 48 |
public static WebXmlVersion valueOf(String thePublicId) |
219 |
{ |
|
220 | 48 |
if (V2_2.getPublicId().equals(thePublicId))
|
221 |
{ |
|
222 | 12 |
return WebXmlVersion.V2_2;
|
223 |
} |
|
224 | 36 |
else if (V2_3.getPublicId().equals(thePublicId)) |
225 |
{ |
|
226 | 34 |
return WebXmlVersion.V2_3;
|
227 |
} |
|
228 | 2 |
return null; |
229 |
} |
|
230 |
|
|
231 |
} |
|
232 |
|
|