001 // Copyright 2005 The Apache Software Foundation
002 //
003 // Licensed under the Apache License, Version 2.0 (the "License");
004 // you may not use this file except in compliance with the License.
005 // You may obtain a copy of the License at
006 //
007 // http://www.apache.org/licenses/LICENSE-2.0
008 //
009 // Unless required by applicable law or agreed to in writing, software
010 // distributed under the License is distributed on an "AS IS" BASIS,
011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012 // See the License for the specific language governing permissions and
013 // limitations under the License.
014
015 package org.apache.tapestry.portlet;
016
017 import java.io.IOException;
018 import java.io.PrintWriter;
019
020 import javax.portlet.PortletURL;
021
022 import org.apache.tapestry.IRequestCycle;
023 import org.apache.tapestry.engine.IEngineService;
024 import org.apache.tapestry.engine.ILink;
025 import org.apache.tapestry.util.ContentType;
026 import org.apache.tapestry.web.WebRequest;
027 import org.apache.tapestry.web.WebResponse;
028 import org.apache.tapestry.web.WebSession;
029
030 /**
031 * @author Howard M. Lewis Ship
032 * @since 4.0
033 * @see org.apache.tapestry.portlet.PortletConstants#PORTLET_EXCEPTION_MARKUP_ATTRIBUTE
034 */
035 public class ExceptionService implements IEngineService
036 {
037 private WebRequest _request;
038
039 private WebResponse _response;
040
041 private PortletRequestGlobals _globals;
042
043 public ILink getLink(boolean post, Object parameter)
044 {
045 throw new UnsupportedOperationException(PortletMessages.unsupportedMethod("getLink"));
046 }
047
048 public void service(IRequestCycle cycle) throws IOException
049 {
050 WebSession session = _request.getSession(true);
051 String markup = (String) session
052 .getAttribute(PortletConstants.PORTLET_EXCEPTION_MARKUP_ATTRIBUTE);
053
054 PrintWriter writer = _response.getPrintWriter(new ContentType("text/html"));
055
056 PortletURL url = _globals.getRenderResponse().createActionURL();
057
058 writer.println("<span class=\"portlet-msg-error\">An exception has occured.</span>");
059 writer.println("<br/>");
060 writer.println("<a href=\"" + url.toString() + "\">Click here to continue</a>");
061 writer.print("<br/><hr/>");
062 writer.println();
063
064 writer.print(markup);
065 }
066
067 public String getName()
068 {
069 return PortletConstants.EXCEPTION_SERVICE;
070 }
071
072 public void setRequest(WebRequest request)
073 {
074 _request = request;
075 }
076
077 public void setResponse(WebResponse response)
078 {
079 _response = response;
080 }
081
082 public void setGlobals(PortletRequestGlobals globals)
083 {
084 _globals = globals;
085 }
086 }