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