KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > catalina > deploy > ErrorPage


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18
19 package org.apache.catalina.deploy;
20
21
22 import org.apache.catalina.util.RequestUtil;
23 import java.io.Serializable JavaDoc;
24
25
26 /**
27  * Representation of an error page element for a web application,
28  * as represented in a <code>&lt;error-page&gt;</code> element in the
29  * deployment descriptor.
30  *
31  * @author Craig R. McClanahan
32  * @version $Revision: 467222 $ $Date: 2006-10-24 05:17:11 +0200 (mar., 24 oct. 2006) $
33  */

34
35 public class ErrorPage implements Serializable JavaDoc {
36
37
38     // ----------------------------------------------------- Instance Variables
39

40
41     /**
42      * The error (status) code for which this error page is active.
43      */

44     private int errorCode = 0;
45
46
47     /**
48      * The exception type for which this error page is active.
49      */

50     private String JavaDoc exceptionType = null;
51
52
53     /**
54      * The context-relative location to handle this error or exception.
55      */

56     private String JavaDoc location = null;
57
58
59     // ------------------------------------------------------------- Properties
60

61
62     /**
63      * Return the error code.
64      */

65     public int getErrorCode() {
66
67         return (this.errorCode);
68
69     }
70
71
72     /**
73      * Set the error code.
74      *
75      * @param errorCode The new error code
76      */

77     public void setErrorCode(int errorCode) {
78
79         this.errorCode = errorCode;
80
81     }
82
83
84     /**
85      * Set the error code (hack for default XmlMapper data type).
86      *
87      * @param errorCode The new error code
88      */

89     public void setErrorCode(String JavaDoc errorCode) {
90
91         try {
92             this.errorCode = Integer.parseInt(errorCode);
93         } catch (Throwable JavaDoc t) {
94             this.errorCode = 0;
95         }
96
97     }
98
99
100     /**
101      * Return the exception type.
102      */

103     public String JavaDoc getExceptionType() {
104
105         return (this.exceptionType);
106
107     }
108
109
110     /**
111      * Set the exception type.
112      *
113      * @param exceptionType The new exception type
114      */

115     public void setExceptionType(String JavaDoc exceptionType) {
116
117         this.exceptionType = exceptionType;
118
119     }
120
121
122     /**
123      * Return the location.
124      */

125     public String JavaDoc getLocation() {
126
127         return (this.location);
128
129     }
130
131
132     /**
133      * Set the location.
134      *
135      * @param location The new location
136      */

137     public void setLocation(String JavaDoc location) {
138
139         // if ((location == null) || !location.startsWith("/"))
140
// throw new IllegalArgumentException
141
// ("Error Page Location must start with a '/'");
142
this.location = RequestUtil.URLDecode(location);
143
144     }
145
146
147     // --------------------------------------------------------- Public Methods
148

149
150     /**
151      * Render a String representation of this object.
152      */

153     public String JavaDoc toString() {
154
155         StringBuffer JavaDoc sb = new StringBuffer JavaDoc("ErrorPage[");
156         if (exceptionType == null) {
157             sb.append("errorCode=");
158             sb.append(errorCode);
159         } else {
160             sb.append("exceptionType=");
161             sb.append(exceptionType);
162         }
163         sb.append(", location=");
164         sb.append(location);
165         sb.append("]");
166         return (sb.toString());
167
168     }
169
170
171 }
172
Popular Tags