コード例 #1
0
  private void _doServeResource(
      HttpServletRequest request, HttpServletResponse response, Portlet portlet) throws Exception {

    HttpServletRequest ownerLayoutRequest = getOwnerLayoutRequestWrapper(request, portlet);

    Layout ownerLayout = (Layout) ownerLayoutRequest.getAttribute(WebKeys.LAYOUT);

    boolean allowAddPortletDefaultResource =
        PortalUtil.isAllowAddPortletDefaultResource(ownerLayoutRequest, portlet);

    if (!allowAddPortletDefaultResource) {
      String url = null;

      LastPath lastPath = (LastPath) request.getAttribute(WebKeys.LAST_PATH);

      if (lastPath != null) {
        StringBundler sb = new StringBundler(3);

        sb.append(PortalUtil.getPortalURL(request));
        sb.append(lastPath.getContextPath());
        sb.append(lastPath.getPath());

        url = sb.toString();
      } else {
        url = String.valueOf(request.getRequestURI());
      }

      response.setHeader(HttpHeaders.CACHE_CONTROL, HttpHeaders.CACHE_CONTROL_NO_CACHE_VALUE);
      response.setStatus(HttpServletResponse.SC_BAD_REQUEST);

      _log.error("Reject serveResource for " + url + " on " + portlet.getPortletId());

      return;
    }

    WindowState windowState = (WindowState) request.getAttribute(WebKeys.WINDOW_STATE);

    PortletMode portletMode =
        PortletModeFactory.getPortletMode(ParamUtil.getString(request, "p_p_mode"));

    PortletPreferencesIds portletPreferencesIds =
        PortletPreferencesFactoryUtil.getPortletPreferencesIds(request, portlet.getPortletId());

    PortletPreferences portletPreferences =
        PortletPreferencesLocalServiceUtil.getPreferences(portletPreferencesIds);

    ServletContext servletContext = (ServletContext) request.getAttribute(WebKeys.CTX);

    InvokerPortlet invokerPortlet = PortletInstanceFactoryUtil.create(portlet, servletContext);

    PortletConfig portletConfig = PortletConfigFactoryUtil.create(portlet, servletContext);
    PortletContext portletContext = portletConfig.getPortletContext();

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

    Layout layout = (Layout) request.getAttribute(WebKeys.LAYOUT);

    String portletPrimaryKey =
        PortletPermissionUtil.getPrimaryKey(layout.getPlid(), portlet.getPortletId());

    portletDisplay.setId(portlet.getPortletId());
    portletDisplay.setRootPortletId(portlet.getRootPortletId());
    portletDisplay.setInstanceId(portlet.getInstanceId());
    portletDisplay.setResourcePK(portletPrimaryKey);
    portletDisplay.setPortletName(portletConfig.getPortletName());
    portletDisplay.setNamespace(PortalUtil.getPortletNamespace(portlet.getPortletId()));

    WebDAVStorage webDAVStorage = portlet.getWebDAVStorageInstance();

    if (webDAVStorage != null) {
      portletDisplay.setWebDAVEnabled(true);
    } else {
      portletDisplay.setWebDAVEnabled(false);
    }

    ResourceRequestImpl resourceRequestImpl =
        ResourceRequestFactory.create(
            request,
            portlet,
            invokerPortlet,
            portletContext,
            windowState,
            portletMode,
            portletPreferences,
            layout.getPlid());

    long companyId = PortalUtil.getCompanyId(request);

    ResourceResponseImpl resourceResponseImpl =
        ResourceResponseFactory.create(
            resourceRequestImpl, response, portlet.getPortletId(), companyId);

    resourceRequestImpl.defineObjects(portletConfig, resourceResponseImpl);

    try {
      ServiceContext serviceContext = ServiceContextFactory.getInstance(resourceRequestImpl);

      ServiceContextThreadLocal.pushServiceContext(serviceContext);

      PermissionChecker permissionChecker = PermissionThreadLocal.getPermissionChecker();

      long scopeGroupId = themeDisplay.getScopeGroupId();

      boolean access =
          PortletPermissionUtil.hasAccessPermission(
              permissionChecker, scopeGroupId, ownerLayout, portlet, portletMode);

      if (access) {
        invokerPortlet.serveResource(resourceRequestImpl, resourceResponseImpl);

        resourceResponseImpl.transferHeaders(response);
      }
    } finally {
      ServiceContextThreadLocal.popServiceContext();
    }
  }
コード例 #2
0
  public void copyTo(PortletDisplay slave) {
    slave.setActive(_active);
    slave.setColumnCount(_columnCount);
    slave.setColumnId(_columnId);
    slave.setColumnPos(_columnPos);
    slave.setContent(_content);
    slave.setControlPanelCategory(_controlPanelCategory);
    slave.setCustomCSSClassName(_customCSSClassName);
    slave.setDescription(_description);
    slave.setId(_id);
    slave.setInstanceId(_instanceId);
    slave.setModeAbout(_modeAbout);
    slave.setModeConfig(_modeConfig);
    slave.setModeEdit(_modeEdit);
    slave.setModeEditDefaults(_modeEditDefaults);
    slave.setModeEditGuest(_modeEditGuest);
    slave.setModeHelp(_modeHelp);
    slave.setModePreview(_modePreview);
    slave.setModePrint(_modePrint);
    slave.setModeView(_modeView);
    slave.setNamespace(_namespace);
    slave.setPortletName(_portletName);
    slave.setPortletResource(_portletResource);
    slave.setPortletSetup(_portletSetup);
    slave.setResourcePK(_resourcePK);
    slave.setRestoreCurrentView(_restoreCurrentView);
    slave.setRootPortletId(_rootPortletId);
    slave.setShowBackIcon(_showBackIcon);
    slave.setShowCloseIcon(_showCloseIcon);
    slave.setShowConfigurationIcon(_showConfigurationIcon);
    slave.setShowEditDefaultsIcon(_showEditDefaultsIcon);
    slave.setShowEditGuestIcon(_showEditGuestIcon);
    slave.setShowEditIcon(_showEditIcon);
    slave.setShowExportImportIcon(_showExportImportIcon);
    slave.setShowHelpIcon(_showHelpIcon);
    slave.setShowMaxIcon(_showMaxIcon);
    slave.setShowMinIcon(_showMinIcon);
    slave.setShowMoveIcon(_showMoveIcon);
    slave.setShowPortletCssIcon(_showPortletCssIcon);
    slave.setShowPortletIcon(_showPortletIcon);
    slave.setShowPrintIcon(_showPrintIcon);
    slave.setShowRefreshIcon(_showRefreshIcon);
    slave.setStateExclusive(_stateExclusive);
    slave.setStateMax(_stateMax);
    slave.setStateMin(_stateMin);
    slave.setStateNormal(_stateNormal);
    slave.setStatePopUp(_statePopUp);
    slave.setThemeDisplay(_themeDisplay);
    slave.setURLBack(_urlBack);
    slave.setURLClose(_urlClose);
    slave.setURLConfiguration(_urlConfiguration);
    slave.setURLEdit(_urlEdit);
    slave.setURLEditDefaults(_urlEditDefaults);
    slave.setURLEditGuest(_urlEditGuest);
    slave.setURLExportImport(_urlExportImport);
    slave.setURLHelp(_urlHelp);
    slave.setURLMax(_urlMax);
    slave.setURLMin(_urlMin);
    slave.setURLPortlet(_urlPortlet);
    slave.setURLPortletCss(_urlPortletCss);
    slave.setURLPrint(_urlPrint);
    slave.setURLRefresh(_urlRefresh);
    slave.setWebDAVEnabled(_webDAVEnabled);

    slave._title = _title;
  }
コード例 #3
0
  private void _doServeResource(
      HttpServletRequest request, HttpServletResponse response, Portlet portlet) throws Exception {

    WindowState windowState = (WindowState) request.getAttribute(WebKeys.WINDOW_STATE);

    PortletMode portletMode =
        PortletModeFactory.getPortletMode(ParamUtil.getString(request, "p_p_mode"));

    PortletPreferencesIds portletPreferencesIds =
        PortletPreferencesFactoryUtil.getPortletPreferencesIds(request, portlet.getPortletId());

    PortletPreferences portletPreferences =
        PortletPreferencesLocalServiceUtil.getStrictPreferences(portletPreferencesIds);

    ServletContext servletContext = (ServletContext) request.getAttribute(WebKeys.CTX);

    InvokerPortlet invokerPortlet = PortletInstanceFactoryUtil.create(portlet, servletContext);

    PortletConfig portletConfig = PortletConfigFactoryUtil.create(portlet, servletContext);
    PortletContext portletContext = portletConfig.getPortletContext();

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

    Layout layout = (Layout) request.getAttribute(WebKeys.LAYOUT);

    String portletPrimaryKey =
        PortletPermissionUtil.getPrimaryKey(layout.getPlid(), portlet.getPortletId());

    portletDisplay.setControlPanelCategory(portlet.getControlPanelEntryCategory());
    portletDisplay.setId(portlet.getPortletId());
    portletDisplay.setInstanceId(portlet.getInstanceId());
    portletDisplay.setNamespace(PortalUtil.getPortletNamespace(portlet.getPortletId()));
    portletDisplay.setPortletName(portletConfig.getPortletName());
    portletDisplay.setResourcePK(portletPrimaryKey);
    portletDisplay.setRootPortletId(portlet.getRootPortletId());

    WebDAVStorage webDAVStorage = portlet.getWebDAVStorageInstance();

    if (webDAVStorage != null) {
      portletDisplay.setWebDAVEnabled(true);
    } else {
      portletDisplay.setWebDAVEnabled(false);
    }

    ResourceRequestImpl resourceRequestImpl =
        ResourceRequestFactory.create(
            request,
            portlet,
            invokerPortlet,
            portletContext,
            windowState,
            portletMode,
            portletPreferences,
            layout.getPlid());

    long companyId = PortalUtil.getCompanyId(request);

    ResourceResponseImpl resourceResponseImpl =
        ResourceResponseFactory.create(
            resourceRequestImpl, response, portlet.getPortletId(), companyId);

    resourceRequestImpl.defineObjects(portletConfig, resourceResponseImpl);

    try {
      ServiceContext serviceContext = ServiceContextFactory.getInstance(resourceRequestImpl);

      ServiceContextThreadLocal.pushServiceContext(serviceContext);

      invokerPortlet.serveResource(resourceRequestImpl, resourceResponseImpl);

      resourceResponseImpl.transferHeaders(response);
    } finally {
      ServiceContextThreadLocal.popServiceContext();
    }
  }