001/* 002 * Copyright 2002-2012 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.web.portlet.context; 018 019import org.springframework.web.context.support.RequestHandledEvent; 020 021/** 022 * Portlet-specific subclass of RequestHandledEvent, 023 * adding portlet-specific context information. 024 * 025 * @author Juergen Hoeller 026 * @author John A. Lewis 027 * @since 2.0 028 * @see org.springframework.web.portlet.FrameworkPortlet 029 * @see org.springframework.context.ApplicationContext#publishEvent 030 */ 031@SuppressWarnings("serial") 032public class PortletRequestHandledEvent extends RequestHandledEvent { 033 034 /** Name of the portlet that handled the request */ 035 private final String portletName; 036 037 /** PortletMode of the request */ 038 private final String portletMode; 039 040 /** Type of Portlet Request */ 041 private final String requestType; 042 043 044 /** 045 * Create a new PortletRequestHandledEvent. 046 * @param source the component that published the event 047 * @param portletName the name of the portlet that handled the request 048 * @param portletMode the PortletMode of the request (usually 'view', 'edit', or 'help') 049 * @param requestType the type of Portlet request ('action' or 'render') 050 * @param sessionId the id of the HTTP session, if any 051 * @param userName the name of the user that was associated with the 052 * request, if any (usually the UserPrincipal) 053 * @param processingTimeMillis the processing time of the request in milliseconds 054 */ 055 public PortletRequestHandledEvent(Object source, String portletName, 056 String portletMode, String requestType, String sessionId, 057 String userName, long processingTimeMillis) { 058 059 super(source, sessionId, userName, processingTimeMillis); 060 this.portletName = portletName; 061 this.portletMode = portletMode; 062 this.requestType = requestType; 063 } 064 065 /** 066 * Create a new PortletRequestHandledEvent. 067 * @param source the component that published the event 068 * @param portletName the name of the portlet that handled the request 069 * @param portletMode the PortletMode of the request (usually 'view', 'edit', or 'help') 070 * @param requestType the type of Portlet request ('action' or 'render') 071 * @param sessionId the id of the HTTP session, if any 072 * @param userName the name of the user that was associated with the 073 * request, if any (usually the UserPrincipal) 074 * @param processingTimeMillis the processing time of the request in milliseconds 075 * @param failureCause the cause of failure, if any 076 */ 077 public PortletRequestHandledEvent(Object source, String portletName, 078 String portletMode, String requestType, String sessionId, 079 String userName, long processingTimeMillis, Throwable failureCause) { 080 081 super(source, sessionId, userName, processingTimeMillis, failureCause); 082 this.portletName = portletName; 083 this.portletMode = portletMode; 084 this.requestType = requestType; 085 } 086 087 088 /** 089 * Return the name of the portlet that handled the request. 090 */ 091 public String getPortletName() { 092 return this.portletName; 093 } 094 095 /** 096 * Return the mode of the portlet request (usually 'view', 'edit', or 'help'). 097 */ 098 public String getPortletMode() { 099 return this.portletMode; 100 } 101 102 /** 103 * Return the type of Portlet Request ('action' or 'render'). 104 */ 105 public String getRequestType() { 106 return this.requestType; 107 } 108 109 110 @Override 111 public String getShortDescription() { 112 StringBuilder sb = new StringBuilder(); 113 sb.append("portlet=[").append(this.portletName).append("]; "); 114 sb.append(super.getShortDescription()); 115 return sb.toString(); 116 } 117 118 @Override 119 public String getDescription() { 120 StringBuilder sb = new StringBuilder(); 121 sb.append("portlet=[").append(this.portletName).append("]; "); 122 sb.append("mode=[").append(this.portletMode).append("]; "); 123 sb.append("type=[").append(this.requestType).append("]; "); 124 sb.append(super.getDescription()); 125 return sb.toString(); 126 } 127 128 @Override 129 public String toString() { 130 return "PortletRequestHandledEvent: " + getDescription(); 131 } 132 133}