KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > portlet > PortletStaleLinkExceptionPresenter


1 // Copyright 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.tapestry.portlet;
16
17 import javax.portlet.ActionRequest;
18 import javax.portlet.ActionResponse;
19
20 import org.apache.hivemind.ApplicationRuntimeException;
21 import org.apache.tapestry.IRequestCycle;
22 import org.apache.tapestry.StaleLinkException;
23 import org.apache.tapestry.error.RequestExceptionReporter;
24 import org.apache.tapestry.error.StaleLinkExceptionPresenter;
25 import org.apache.tapestry.services.ServiceConstants;
26
27 /**
28  * Implementation of {@link org.apache.tapestry.error.StaleLinkExceptionPresenter} for Portlets.
29  *
30  * @author Howard M. Lewis Ship
31  * @since 4.0
32  */

33 public class PortletStaleLinkExceptionPresenter implements StaleLinkExceptionPresenter
34 {
35     private PortletRequestGlobals _globals;
36
37     private RequestExceptionReporter _requestExceptionReporter;
38
39     public void presentStaleLinkException(IRequestCycle cycle, StaleLinkException cause)
40     {
41         try
42         {
43             ActionRequest request = _globals.getActionRequest();
44
45             request.getPortletSession(true).setAttribute(
46                     PortletConstants.PORTLET_EXCEPTION_MARKUP_ATTRIBUTE,
47                     cause.getMessage());
48
49             ActionResponse response = _globals.getActionResponse();
50
51             response.setRenderParameter(
52                     ServiceConstants.SERVICE,
53                     PortletConstants.EXCEPTION_SERVICE);
54         }
55         catch (Exception JavaDoc ex)
56         {
57             // Worst case scenario. The exception page itself is broken, leaving
58
// us with no option but to write the cause to the output.
59

60             // Also, write the exception thrown when redendering the exception
61
// page, so that can get fixed as well.
62

63             _requestExceptionReporter.reportRequestException(PortletMessages
64                     .errorReportingException(ex), ex);
65
66             // And throw the exception.
67

68             throw new ApplicationRuntimeException(ex.getMessage(), ex);
69         }
70     }
71
72     public void setGlobals(PortletRequestGlobals globals)
73     {
74         _globals = globals;
75     }
76
77     public void setRequestExceptionReporter(RequestExceptionReporter requestExceptionReporter)
78     {
79         _requestExceptionReporter = requestExceptionReporter;
80     }
81
82 }
83
Popular Tags