KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.io.IOException JavaDoc;
18 import java.io.PrintWriter JavaDoc;
19
20 import javax.portlet.PortletURL;
21
22 import org.apache.tapestry.IRequestCycle;
23 import org.apache.tapestry.engine.IEngineService;
24 import org.apache.tapestry.engine.ILink;
25 import org.apache.tapestry.util.ContentType;
26 import org.apache.tapestry.web.WebRequest;
27 import org.apache.tapestry.web.WebResponse;
28 import org.apache.tapestry.web.WebSession;
29
30 /**
31  * @author Howard M. Lewis Ship
32  * @since 4.0
33  * @see org.apache.tapestry.portlet.PortletConstants#PORTLET_EXCEPTION_MARKUP_ATTRIBUTE
34  */

35 public class ExceptionService implements IEngineService
36 {
37     private WebRequest _request;
38
39     private WebResponse _response;
40
41     private PortletRequestGlobals _globals;
42
43     public ILink getLink(IRequestCycle cycle, Object JavaDoc parameter)
44     {
45         throw new UnsupportedOperationException JavaDoc(PortletMessages.unsupportedMethod("getLink"));
46     }
47
48     public void service(IRequestCycle cycle) throws IOException JavaDoc
49     {
50         WebSession session = _request.getSession(true);
51         String JavaDoc markup = (String JavaDoc) session
52                 .getAttribute(PortletConstants.PORTLET_EXCEPTION_MARKUP_ATTRIBUTE);
53
54         PrintWriter JavaDoc writer = _response.getPrintWriter(new ContentType("text/html"));
55
56         PortletURL url = _globals.getRenderResponse().createActionURL();
57
58         writer.println("<span class=\"portlet-msg-error\">An exception has occured.</span>");
59         writer.println("<br/>");
60         writer.println("<a HREF=\"" + url.toString() + "\">Click here to continue</a>");
61         writer.print("<br/><hr/>");
62         writer.println();
63
64         writer.print(markup);
65     }
66
67     public String JavaDoc getName()
68     {
69         return PortletConstants.EXCEPTION_SERVICE;
70     }
71
72     public void setRequest(WebRequest request)
73     {
74         _request = request;
75     }
76
77     public void setResponse(WebResponse response)
78     {
79         _response = response;
80     }
81
82     public void setGlobals(PortletRequestGlobals globals)
83     {
84         _globals = globals;
85     }
86 }
Popular Tags