01: /*
02: * Copyright 2005-2007 Noelios Consulting.
03: *
04: * The contents of this file are subject to the terms of the Common Development
05: * and Distribution License (the "License"). You may not use this file except in
06: * compliance with the License.
07: *
08: * You can obtain a copy of the license at
09: * http://www.opensource.org/licenses/cddl1.txt See the License for the specific
10: * language governing permissions and limitations under the License.
11: *
12: * When distributing Covered Code, include this CDDL HEADER in each file and
13: * include the License file at http://www.opensource.org/licenses/cddl1.txt If
14: * applicable, add the following below this CDDL HEADER, with the fields
15: * enclosed by brackets "[]" replaced with your own identifying information:
16: * Portions Copyright [yyyy] [name of copyright owner]
17: */
18:
19: package com.noelios.restlet.application;
20:
21: import org.restlet.Application;
22: import org.restlet.data.Request;
23: import org.restlet.data.Response;
24: import org.restlet.data.Status;
25: import org.restlet.resource.Representation;
26:
27: import com.noelios.restlet.StatusFilter;
28:
29: /**
30: * Status filter that tries to obtain ouput representation from an application.
31: *
32: * @author Jerome Louvel (contact@noelios.com)
33: */
34: public class ApplicationStatusFilter extends StatusFilter {
35: /** The application. */
36: private Application application;
37:
38: /**
39: * Constructor.
40: *
41: * @param application
42: * The application.
43: */
44: public ApplicationStatusFilter(Application application) {
45: super (application.getContext(), application.getStatusService()
46: .isOverwrite(), application.getStatusService()
47: .getContactEmail(), "/");
48: this .application = application;
49: }
50:
51: /**
52: * Returns the application.
53: *
54: * @return The application.
55: */
56: public Application getApplication() {
57: return this .application;
58: }
59:
60: @Override
61: public Representation getRepresentation(Status status,
62: Request request, Response response) {
63: Representation result = getApplication().getStatusService()
64: .getRepresentation(status, request, response);
65: if (result == null)
66: result = super .getRepresentation(status, request, response);
67: return result;
68: }
69:
70: @Override
71: public Status getStatus(Throwable throwable, Request request,
72: Response response) {
73: Status result = getApplication().getStatusService().getStatus(
74: throwable, request, response);
75: if (result == null)
76: result = super.getStatus(throwable, request, response);
77: return result;
78: }
79:
80: }
|