001: /*
002: * StatusReport.java February 2004
003: *
004: * Copyright (C) 2004, Niall Gallagher <niallg@users.sf.net>
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013: * GNU Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General
016: * Public License along with this library; if not, write to the
017: * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
018: * Boston, MA 02111-1307 USA
019: */
020:
021: package simple.http.serve;
022:
023: import java.util.MissingResourceException;
024: import java.util.ResourceBundle;
025: import java.util.Locale;
026:
027: /**
028: * The <code>StatusReport</code> is used to describe HTTP status
029: * messages. Reporting the various HTTP status messages requires
030: * that status codes and textual descriptions of the status are
031: * provided. This will pair a provided status code with a short
032: * description of the status that HTTP status code represents as
033: * outlined by RFC 2612 section 6.1.1.
034: * <p>
035: * The <code>getCause</code> method will provide an empty
036: * description of the cause, as changes in status are typically
037: * driven by the service implementations and therefore are not
038: * directly caused by any specific event.
039: *
040: * @author Niall Gallagher
041: */
042: public class StatusReport implements Report {
043:
044: /**
045: * This is used to load the Error.properties file for
046: * a list of the matching HTTP status messages.
047: */
048: protected static ResourceBundle status;
049:
050: static {
051: try {
052: status = ResourceBundle
053: .getBundle("simple.http.serve.Error");
054: } catch (MissingResourceException e) {
055: e.printStackTrace();
056: }
057: }
058:
059: /**
060: * This is the status code that the report represents.
061: */
062: private int code;
063:
064: /**
065: * Constructor for the <code>StatusReport</code> object. This
066: * will create an instance that uses the HTTP status code
067: * provided to describe the status report.
068: *
069: * @param code this is the HTTP status code of the report
070: */
071: public StatusReport(int code) {
072: this .code = code;
073: }
074:
075: /**
076: * Returns the HTTP status code that this report represents.
077: * This can be used to describe a chenge in status using any
078: * of the valid HTTP status codes described in RFC 2616 section
079: * 6.1.1, typically this will be a 2xx, 3xx, 4xx, or 5xx code.
080: *
081: * @return the HTTP status code this report represents
082: */
083: public int getCode() {
084: return code;
085: }
086:
087: /**
088: * Returns a short description of what caused this report.
089: * This can be used to describe a chenge in status using any
090: * of the valid HTTP status codes described in RFC 2616 section
091: * 6.1.1, typically this will be a 2xx, 3xx, 4xx, or 5xx code.
092: *
093: * @return the short description of what caused the report
094: */
095: public String getText() {
096: try {
097: return status.getString(String.valueOf(code));
098: } catch (MissingResourceException e) {
099: return "Unknown";
100: }
101: }
102:
103: /**
104: * This is used to acquire a detailed message describing the
105: * cause of the error. For this implementation there will be
106: * no direct cause for the status report as this is typically
107: * used as a result of a change in status by the service.
108: *
109: * @return this provides an empty string for the cause
110: */
111: public String getCause() {
112: return "";
113: }
114: }
|