PageRenderTime 50ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/apache-tomcat-7.0.28-src/java/org/apache/catalina/deploy/ErrorPage.java

#
Java | 181 lines | 56 code | 54 blank | 71 comment | 6 complexity | 05983ea0cccbbe976c75742dd5635671 MD5 | raw file
Possible License(s): Apache-2.0
  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. package org.apache.catalina.deploy;
  18. import java.io.Serializable;
  19. import org.apache.catalina.util.RequestUtil;
  20. /**
  21. * Representation of an error page element for a web application,
  22. * as represented in a <code>&lt;error-page&gt;</code> element in the
  23. * deployment descriptor.
  24. *
  25. * @author Craig R. McClanahan
  26. * @version $Id: ErrorPage.java 1001915 2010-09-27 21:32:25Z markt $
  27. */
  28. public class ErrorPage implements Serializable {
  29. private static final long serialVersionUID = 1L;
  30. // ----------------------------------------------------- Instance Variables
  31. /**
  32. * The error (status) code for which this error page is active.
  33. */
  34. private int errorCode = 0;
  35. /**
  36. * The exception type for which this error page is active.
  37. */
  38. private String exceptionType = null;
  39. /**
  40. * The context-relative location to handle this error or exception.
  41. */
  42. private String location = null;
  43. // ------------------------------------------------------------- Properties
  44. /**
  45. * Return the error code.
  46. */
  47. public int getErrorCode() {
  48. return (this.errorCode);
  49. }
  50. /**
  51. * Set the error code.
  52. *
  53. * @param errorCode The new error code
  54. */
  55. public void setErrorCode(int errorCode) {
  56. this.errorCode = errorCode;
  57. }
  58. /**
  59. * Set the error code (hack for default XmlMapper data type).
  60. *
  61. * @param errorCode The new error code
  62. */
  63. public void setErrorCode(String errorCode) {
  64. try {
  65. this.errorCode = Integer.parseInt(errorCode);
  66. } catch (NumberFormatException nfe) {
  67. this.errorCode = 0;
  68. }
  69. }
  70. /**
  71. * Return the exception type.
  72. */
  73. public String getExceptionType() {
  74. return (this.exceptionType);
  75. }
  76. /**
  77. * Set the exception type.
  78. *
  79. * @param exceptionType The new exception type
  80. */
  81. public void setExceptionType(String exceptionType) {
  82. this.exceptionType = exceptionType;
  83. }
  84. /**
  85. * Return the location.
  86. */
  87. public String getLocation() {
  88. return (this.location);
  89. }
  90. /**
  91. * Set the location.
  92. *
  93. * @param location The new location
  94. */
  95. public void setLocation(String location) {
  96. // if ((location == null) || !location.startsWith("/"))
  97. // throw new IllegalArgumentException
  98. // ("Error Page Location must start with a '/'");
  99. this.location = RequestUtil.URLDecode(location);
  100. }
  101. // --------------------------------------------------------- Public Methods
  102. /**
  103. * Render a String representation of this object.
  104. */
  105. @Override
  106. public String toString() {
  107. StringBuilder sb = new StringBuilder("ErrorPage[");
  108. if (exceptionType == null) {
  109. sb.append("errorCode=");
  110. sb.append(errorCode);
  111. } else {
  112. sb.append("exceptionType=");
  113. sb.append(exceptionType);
  114. }
  115. sb.append(", location=");
  116. sb.append(location);
  117. sb.append("]");
  118. return (sb.toString());
  119. }
  120. public String getName() {
  121. if (exceptionType == null) {
  122. return Integer.toString(errorCode);
  123. } else {
  124. return exceptionType;
  125. }
  126. }
  127. }