You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PortletListenerNotifier.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright 2000-2018 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.server.communication;
  17. import java.io.IOException;
  18. import javax.portlet.ActionRequest;
  19. import javax.portlet.ActionResponse;
  20. import javax.portlet.EventRequest;
  21. import javax.portlet.EventResponse;
  22. import javax.portlet.PortletRequest;
  23. import javax.portlet.PortletResponse;
  24. import javax.portlet.RenderRequest;
  25. import javax.portlet.RenderResponse;
  26. import javax.portlet.ResourceRequest;
  27. import javax.portlet.ResourceResponse;
  28. import com.vaadin.server.ServletPortletHelper;
  29. import com.vaadin.server.SynchronizedRequestHandler;
  30. import com.vaadin.server.VaadinPortletRequest;
  31. import com.vaadin.server.VaadinPortletResponse;
  32. import com.vaadin.server.VaadinPortletSession;
  33. import com.vaadin.server.VaadinPortletSession.PortletListener;
  34. import com.vaadin.server.VaadinRequest;
  35. import com.vaadin.server.VaadinResponse;
  36. import com.vaadin.server.VaadinSession;
  37. import com.vaadin.ui.UI;
  38. /**
  39. * Notifies {@link PortletListener}s of a received portlet request.
  40. *
  41. * @author Vaadin Ltd
  42. * @since 7.1
  43. */
  44. public class PortletListenerNotifier extends SynchronizedRequestHandler {
  45. /**
  46. * Fires portlet request events to any {@link PortletListener}s registered
  47. * to the given session using
  48. * {@link VaadinPortletSession#addPortletListener(PortletListener)}. The
  49. * PortletListener method corresponding to the request type is invoked.
  50. */
  51. @Override
  52. public boolean synchronizedHandleRequest(VaadinSession session,
  53. VaadinRequest request, VaadinResponse response) throws IOException {
  54. VaadinPortletSession sess = (VaadinPortletSession) session;
  55. PortletRequest portletRequest = ((VaadinPortletRequest) request)
  56. .getPortletRequest();
  57. PortletResponse portletResponse = ((VaadinPortletResponse) response)
  58. .getPortletResponse();
  59. // Finds the right UI
  60. UI uI = null;
  61. if (ServletPortletHelper.isUIDLRequest(request)) {
  62. uI = session.getService().findUI(request);
  63. }
  64. if (portletRequest instanceof RenderRequest) {
  65. sess.firePortletRenderRequest(uI, (RenderRequest) portletRequest,
  66. (RenderResponse) portletResponse);
  67. } else if (portletRequest instanceof ActionRequest) {
  68. sess.firePortletActionRequest(uI, (ActionRequest) portletRequest,
  69. (ActionResponse) portletResponse);
  70. } else if (portletRequest instanceof EventRequest) {
  71. sess.firePortletEventRequest(uI, (EventRequest) portletRequest,
  72. (EventResponse) portletResponse);
  73. } else if (portletRequest instanceof ResourceRequest) {
  74. sess.firePortletResourceRequest(uI,
  75. (ResourceRequest) portletRequest,
  76. (ResourceResponse) portletResponse);
  77. }
  78. return false;
  79. }
  80. }