001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.catalina.deploy;
019:
020: import org.apache.catalina.util.RequestUtil;
021: import java.io.Serializable;
022:
023: /**
024: * Representation of an error page element for a web application,
025: * as represented in a <code><error-page></code> element in the
026: * deployment descriptor.
027: *
028: * @author Craig R. McClanahan
029: * @version $Revision: 467222 $ $Date: 2006-10-24 05:17:11 +0200 (mar., 24 oct. 2006) $
030: */
031:
032: public class ErrorPage implements Serializable {
033:
034: // ----------------------------------------------------- Instance Variables
035:
036: /**
037: * The error (status) code for which this error page is active.
038: */
039: private int errorCode = 0;
040:
041: /**
042: * The exception type for which this error page is active.
043: */
044: private String exceptionType = null;
045:
046: /**
047: * The context-relative location to handle this error or exception.
048: */
049: private String location = null;
050:
051: // ------------------------------------------------------------- Properties
052:
053: /**
054: * Return the error code.
055: */
056: public int getErrorCode() {
057:
058: return (this .errorCode);
059:
060: }
061:
062: /**
063: * Set the error code.
064: *
065: * @param errorCode The new error code
066: */
067: public void setErrorCode(int errorCode) {
068:
069: this .errorCode = errorCode;
070:
071: }
072:
073: /**
074: * Set the error code (hack for default XmlMapper data type).
075: *
076: * @param errorCode The new error code
077: */
078: public void setErrorCode(String errorCode) {
079:
080: try {
081: this .errorCode = Integer.parseInt(errorCode);
082: } catch (Throwable t) {
083: this .errorCode = 0;
084: }
085:
086: }
087:
088: /**
089: * Return the exception type.
090: */
091: public String getExceptionType() {
092:
093: return (this .exceptionType);
094:
095: }
096:
097: /**
098: * Set the exception type.
099: *
100: * @param exceptionType The new exception type
101: */
102: public void setExceptionType(String exceptionType) {
103:
104: this .exceptionType = exceptionType;
105:
106: }
107:
108: /**
109: * Return the location.
110: */
111: public String getLocation() {
112:
113: return (this .location);
114:
115: }
116:
117: /**
118: * Set the location.
119: *
120: * @param location The new location
121: */
122: public void setLocation(String location) {
123:
124: // if ((location == null) || !location.startsWith("/"))
125: // throw new IllegalArgumentException
126: // ("Error Page Location must start with a '/'");
127: this .location = RequestUtil.URLDecode(location);
128:
129: }
130:
131: // --------------------------------------------------------- Public Methods
132:
133: /**
134: * Render a String representation of this object.
135: */
136: public String toString() {
137:
138: StringBuffer sb = new StringBuffer("ErrorPage[");
139: if (exceptionType == null) {
140: sb.append("errorCode=");
141: sb.append(errorCode);
142: } else {
143: sb.append("exceptionType=");
144: sb.append(exceptionType);
145: }
146: sb.append(", location=");
147: sb.append(location);
148: sb.append("]");
149: return (sb.toString());
150:
151: }
152:
153: }
|