1 12 package org.displaytag.portlet; 13 14 import java.util.Map ; 15 16 import javax.portlet.PortletRequest; 17 import javax.portlet.RenderResponse; 18 import javax.servlet.jsp.PageContext ; 19 20 import org.displaytag.util.Href; 21 import org.displaytag.util.RequestHelper; 22 23 24 34 public class PortletRequestHelper implements RequestHelper 35 { 36 37 public static final String JAVAX_PORTLET_RESPONSE = "javax.portlet.response"; 38 39 public static final String JAVAX_PORTLET_REQUEST = "javax.portlet.request"; 40 41 private final PortletRequest portletRequest; 42 43 private final RenderResponse renderResponse; 44 45 51 public PortletRequestHelper(PageContext pageContext) 52 { 53 if (pageContext == null) 54 { 55 throw new IllegalArgumentException ("pageContext may not be null"); 56 } 57 58 this.portletRequest = (PortletRequest) pageContext.findAttribute(JAVAX_PORTLET_REQUEST); 59 if (this.portletRequest == null) 60 { 61 throw new IllegalStateException ("A PortletRequest could not be found in the PageContext for the key='" 62 + JAVAX_PORTLET_REQUEST 63 + "'"); 64 } 65 66 this.renderResponse = (RenderResponse) pageContext.findAttribute(JAVAX_PORTLET_RESPONSE); 67 if (this.portletRequest == null) 68 { 69 throw new IllegalStateException ("A RenderResponse could not be found in the PageContext for the key='" 70 + JAVAX_PORTLET_RESPONSE 71 + "'"); 72 } 73 } 74 75 78 public Href getHref() 79 { 80 final PortletHref href = new PortletHref(this.portletRequest, this.renderResponse); 81 href.setParameterMap(this.portletRequest.getParameterMap()); 82 83 if (this.portletRequest.isSecure()) 84 { 85 href.setRequestedSecure(true); 86 } 87 88 return href; 89 } 90 91 94 public String getParameter(String key) 95 { 96 return this.portletRequest.getParameter(key); 97 } 98 99 102 public Integer getIntParameter(String key) 103 { 104 try 105 { 106 return new Integer (this.getParameter(key)); 107 } 108 catch (NumberFormatException nfe) 109 { 110 return null; 111 } 112 } 113 114 117 public Map getParameterMap() 118 { 119 return this.portletRequest.getParameterMap(); 120 } 121 } 122 | Popular Tags |