Exemplo n.º 1
0
 protected String getPortletFname(HttpServletRequest request, IPortletWindowId portletWindowId) {
   final IPortletWindow portletWindow =
       this.portletWindowRegistry.getPortletWindow(request, portletWindowId);
   final IPortletEntity portletEntity = portletWindow.getPortletEntity();
   final IPortletDefinition portletDefinition = portletEntity.getPortletDefinition();
   return portletDefinition.getFName();
 }
  @Override
  public void storePortletWindow(HttpServletRequest request, IPortletWindow portletWindow) {
    if (isDisablePersistentWindowStates(request)) {
      return;
    }

    final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
    final IPerson person = userInstance.getPerson();
    if (person.isGuest()) {
      // Never persist things for the guest user, just rely on in-memory storage
      return;
    }

    final IStylesheetDescriptor themeStylesheetDescriptor =
        this.getThemeStylesheetDescriptor(request);

    final WindowState windowState = portletWindow.getWindowState();

    final IPortletEntity portletEntity = portletWindow.getPortletEntity();
    final WindowState entityWindowState = portletEntity.getWindowState(themeStylesheetDescriptor);

    // If the window and entity states are different
    if (windowState != entityWindowState && !windowState.equals(entityWindowState)) {
      final WindowState defaultWindowState = this.getDefaultWindowState(themeStylesheetDescriptor);

      // If a window state is set and is one of the persistent states set it on the entity
      if (!defaultWindowState.equals(windowState) && persistentWindowStates.contains(windowState)) {
        portletEntity.setWindowState(themeStylesheetDescriptor, windowState);
      }
      // If not remove the state from the entity
      else if (entityWindowState != null) {
        portletEntity.setWindowState(themeStylesheetDescriptor, null);
      }

      // Persist the modified entity
      this.portletEntityRegistry.storePortletEntity(request, portletEntity);
    }
  }
  @Override
  public IPortletWindow getOrCreateStatelessPortletWindow(
      HttpServletRequest request, IPortletWindowId basePortletWindowId) {
    // Need the basePortletWindowId to be an instance of PortletWindowIdImpl so that we can extract
    // the entity ID
    if (!(basePortletWindowId instanceof PortletWindowIdImpl)) {
      final String basePortletWindowIdStr = basePortletWindowId.getStringId();
      basePortletWindowId = this.getPortletWindowId(request, basePortletWindowIdStr);
    }

    // Get the entity ID for the portlet window
    final IPortletEntityId portletEntityId =
        ((PortletWindowIdImpl) basePortletWindowId).getPortletEntityId();

    // Create the stateless ID
    final PortletWindowIdImpl statelessPortletWindowId =
        this.createPortletWindowId(STATELESS_PORTLET_WINDOW_ID, portletEntityId);

    // See if there is already a request cached stateless window
    IPortletWindow statelessPortletWindow =
        this.getPortletWindow(request, statelessPortletWindowId);
    if (statelessPortletWindow != null) {
      return statelessPortletWindow;
    }

    // Lookup the base portlet window to clone the stateless from
    final IPortletWindow basePortletWindow = this.getPortletWindow(request, basePortletWindowId);

    final PortletWindowCache<PortletWindowData> statelessPortletWindowDataMap =
        this.getStatelessPortletWindowDataMap(request, true);

    // If no base to clone from lookup the entity and pluto definition data
    if (basePortletWindow == null) {
      final IPortletEntity portletEntity =
          this.portletEntityRegistry.getPortletEntity(request, portletEntityId);
      if (portletEntity == null) {
        throw new IllegalArgumentException(
            "No IPortletEntity could be found for "
                + portletEntity
                + " while creating stateless portlet window for "
                + basePortletWindowId);
      }

      final IPortletDefinition portletDefinition = portletEntity.getPortletDefinition();
      final IPortletDefinitionId portletDefinitionId = portletDefinition.getPortletDefinitionId();
      final PortletDefinition portletDescriptor =
          this.portletDefinitionRegistry.getParentPortletDescriptor(portletDefinitionId);

      final PortletWindowData portletWindowData =
          new PortletWindowData(statelessPortletWindowId, portletEntityId);
      statelessPortletWindowDataMap.storeWindow(portletWindowData);

      statelessPortletWindow =
          new StatelessPortletWindowImpl(portletWindowData, portletEntity, portletDescriptor);
    }
    // Clone the existing base window
    else {
      final PortletWindowData portletWindowData =
          new PortletWindowData(statelessPortletWindowId, portletEntityId);
      portletWindowData.setExpirationCache(basePortletWindow.getExpirationCache());
      portletWindowData.setPortletMode(basePortletWindow.getPortletMode());
      portletWindowData.setWindowState(basePortletWindow.getWindowState());
      portletWindowData.setPublicRenderParameters(basePortletWindow.getPublicRenderParameters());
      portletWindowData.setRenderParameters(basePortletWindow.getRenderParameters());

      statelessPortletWindowDataMap.storeWindow(portletWindowData);

      final IPortletEntity portletEntity = basePortletWindow.getPortletEntity();
      final PortletDefinition portletDescriptor =
          basePortletWindow.getPlutoPortletWindow().getPortletDefinition();
      statelessPortletWindow =
          new StatelessPortletWindowImpl(portletWindowData, portletEntity, portletDescriptor);
    }

    // Cache the stateless window in the request
    final PortletWindowCache<IPortletWindow> portletWindowMap = this.getPortletWindowMap(request);
    portletWindowMap.storeWindow(statelessPortletWindow);

    return statelessPortletWindow;
  }