/projects/displaytag-1.2/displaytag-portlet/src/main/java/org/displaytag/portlet/PortletRequestHelper.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus · Java · 121 lines · 64 code · 18 blank · 39 comment · 7 complexity · f52395a89d2359d840dd8c52fba702fc MD5 · raw file

  1. /**
  2. * Licensed under the Artistic License; you may not use this file
  3. * except in compliance with the License.
  4. * You may obtain a copy of the License at
  5. *
  6. * http://displaytag.sourceforge.net/license.html
  7. *
  8. * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
  9. * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  10. * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  11. */
  12. package org.displaytag.portlet;
  13. import java.util.Map;
  14. import javax.portlet.PortletRequest;
  15. import javax.portlet.RenderResponse;
  16. import javax.servlet.jsp.PageContext;
  17. import org.displaytag.util.Href;
  18. import org.displaytag.util.RequestHelper;
  19. /**
  20. * Reads parameters and generates URLs using javax.portlet APIs. The {@link javax.servlet.jsp.PageContext} passed into
  21. * the constructor must provide the {@link javax.portlet.PortletRequest} via an attribute named
  22. * {@link #JAVAX_PORTLET_REQUEST} and {@link javax.portlet.RenderResponse} via an attribute named
  23. * {@link #JAVAX_PORTLET_RESPONSE}. <br>
  24. * <br>
  25. * If the pluto portlet container is being used these objects should be setup appropriatly already.
  26. * @author Eric Dalquist <a href="mailto:dalquist@gmail.com">dalquist@gmail.com</a>
  27. * @version $Id: PortletRequestHelper.java 996 2006-01-06 15:34:08Z fgiust $
  28. */
  29. public class PortletRequestHelper implements RequestHelper
  30. {
  31. public static final String JAVAX_PORTLET_RESPONSE = "javax.portlet.response";
  32. public static final String JAVAX_PORTLET_REQUEST = "javax.portlet.request";
  33. private final PortletRequest portletRequest;
  34. private final RenderResponse renderResponse;
  35. /**
  36. * Creates a new request helper for the specified PageContext. Retrieves the PortletRequest and RenderResponse from
  37. * the PageContext.
  38. * @param pageContext Current JSP context.
  39. * @throws IllegalStateException If the PortletRequest or RenderResponse are not found in the PageContext.
  40. */
  41. public PortletRequestHelper(PageContext pageContext)
  42. {
  43. if (pageContext == null)
  44. {
  45. throw new IllegalArgumentException("pageContext may not be null");
  46. }
  47. this.portletRequest = (PortletRequest) pageContext.findAttribute(JAVAX_PORTLET_REQUEST);
  48. if (this.portletRequest == null)
  49. {
  50. throw new IllegalStateException("A PortletRequest could not be found in the PageContext for the key='"
  51. + JAVAX_PORTLET_REQUEST
  52. + "'");
  53. }
  54. this.renderResponse = (RenderResponse) pageContext.findAttribute(JAVAX_PORTLET_RESPONSE);
  55. if (this.portletRequest == null)
  56. {
  57. throw new IllegalStateException("A RenderResponse could not be found in the PageContext for the key='"
  58. + JAVAX_PORTLET_RESPONSE
  59. + "'");
  60. }
  61. }
  62. /**
  63. * @see org.displaytag.util.RequestHelper#getHref()
  64. */
  65. public Href getHref()
  66. {
  67. final PortletHref href = new PortletHref(this.portletRequest, this.renderResponse);
  68. href.setParameterMap(this.portletRequest.getParameterMap());
  69. if (this.portletRequest.isSecure())
  70. {
  71. href.setRequestedSecure(true);
  72. }
  73. return href;
  74. }
  75. /**
  76. * @see org.displaytag.util.RequestHelper#getParameter(java.lang.String)
  77. */
  78. public String getParameter(String key)
  79. {
  80. return this.portletRequest.getParameter(key);
  81. }
  82. /**
  83. * @see org.displaytag.util.RequestHelper#getIntParameter(java.lang.String)
  84. */
  85. public Integer getIntParameter(String key)
  86. {
  87. try
  88. {
  89. return new Integer(this.getParameter(key));
  90. }
  91. catch (NumberFormatException nfe)
  92. {
  93. return null;
  94. }
  95. }
  96. /**
  97. * @see org.displaytag.util.RequestHelper#getParameterMap()
  98. */
  99. public Map getParameterMap()
  100. {
  101. return this.portletRequest.getParameterMap();
  102. }
  103. }