コード例 #1
0
  protected void copyResourcePermissions(String sourcePortletId, String targetPortletId) {

    Layout layout = getLayout();

    Portlet portlet = PortletLocalServiceUtil.getPortletById(getCompanyId(), sourcePortletId);

    String sourcePortletPrimaryKey =
        PortletPermissionUtil.getPrimaryKey(layout.getPlid(), sourcePortletId);

    List<ResourcePermission> resourcePermissions =
        ResourcePermissionLocalServiceUtil.getResourcePermissions(
            portlet.getCompanyId(),
            portlet.getPortletName(),
            PortletKeys.PREFS_OWNER_TYPE_USER,
            sourcePortletPrimaryKey);

    for (ResourcePermission resourcePermission : resourcePermissions) {
      String targetPortletPrimaryKey =
          PortletPermissionUtil.getPrimaryKey(layout.getPlid(), targetPortletId);

      resourcePermission.setResourcePermissionId(CounterLocalServiceUtil.increment());
      resourcePermission.setPrimKey(targetPortletPrimaryKey);

      ResourcePermissionLocalServiceUtil.addResourcePermission(resourcePermission);
    }
  }
コード例 #2
0
  @Override
  public void movePortletId(long userId, String portletId, String columnId, int columnPos) {

    if (!hasPortletId(portletId)) {
      return;
    }

    _enablePortletLayoutListener = false;

    try {
      removePortletId(userId, portletId, false);
      addPortletId(userId, portletId, columnId, columnPos, false, true);
    } finally {
      _enablePortletLayoutListener = true;
    }

    Layout layout = getLayout();

    try {
      Portlet portlet = PortletLocalServiceUtil.getPortletById(layout.getCompanyId(), portletId);

      if (portlet != null) {
        PortletLayoutListener portletLayoutListener = portlet.getPortletLayoutListenerInstance();

        if (portletLayoutListener != null) {
          portletLayoutListener.onMoveInLayout(portletId, layout.getPlid());
        }
      }
    } catch (Exception e) {
      _log.error("Unable to fire portlet layout listener event", e);
    }
  }
コード例 #3
0
  public void initPermissions(List<Company> companies, Portlet portlet) {
    String rootPortletId = portlet.getRootPortletId();

    for (Company company : companies) {
      long companyId = company.getCompanyId();

      Role powerUserRole = getPowerUserRole(companyId);

      if (powerUserRole == null) {
        continue;
      }

      Group userPersonalSiteGroup = getUserPersonalSiteGroup(companyId);

      if (userPersonalSiteGroup == null) {
        continue;
      }

      try {
        initPermissions(
            companyId,
            powerUserRole.getRoleId(),
            rootPortletId,
            userPersonalSiteGroup.getGroupId());
      } catch (PortalException pe) {
        _log.error(
            "Unable to initialize user personal site permissions "
                + "for portlet "
                + portlet.getPortletId()
                + " in company "
                + companyId,
            pe);
      }
    }
  }
コード例 #4
0
  @Override
  public void clear(Portlet portlet, boolean resetRemotePortletBag) {
    String rootPortletId = portlet.getRootPortletId();

    Map<String, InvokerPortlet> portletInstances = _pool.remove(rootPortletId);

    if (portletInstances != null) {
      InvokerPortlet rootInvokerPortletInstance = portletInstances.remove(rootPortletId);

      if (rootInvokerPortletInstance != null) {
        rootInvokerPortletInstance.destroy();
      }

      portletInstances.clear();
    }

    PortletApp portletApp = portlet.getPortletApp();

    if (resetRemotePortletBag && portletApp.isWARFile()) {
      PortletBag portletBag = PortletBagPool.remove(rootPortletId);

      if (portletBag != null) {
        portletBag.destroy();
      }
    }
  }
コード例 #5
0
  public void initPermissions(long companyId, List<Portlet> portlets) {
    Role powerUserRole = getPowerUserRole(companyId);

    if (powerUserRole == null) {
      return;
    }

    Group userPersonalSiteGroup = getUserPersonalSiteGroup(companyId);

    if (userPersonalSiteGroup == null) {
      return;
    }

    for (Portlet portlet : portlets) {
      try {
        initPermissions(
            companyId,
            powerUserRole.getRoleId(),
            portlet.getRootPortletId(),
            userPersonalSiteGroup.getGroupId());
      } catch (PortalException pe) {
        _log.error(
            "Unable to initialize user personal site permissions "
                + "for portlet "
                + portlet.getPortletId()
                + " in company "
                + companyId,
            pe);
      }
    }
  }
コード例 #6
0
  public void deleteArchivedSetups(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    Portlet portlet = ActionUtil.getPortlet(actionRequest);

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

    String[] names = null;

    String name = ParamUtil.getString(actionRequest, "name");

    if (Validator.isNotNull(name)) {
      names = new String[] {name};
    } else {
      names = ParamUtil.getStringValues(actionRequest, "rowIds");
    }

    for (String curName : names) {
      ArchivedSettings archivedSettings =
          SettingsFactoryUtil.getPortletInstanceArchivedSettings(
              themeDisplay.getSiteGroupId(), portlet.getRootPortletId(), curName);

      archivedSettings.delete();
    }
  }
コード例 #7
0
  public void editConfiguration(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    Portlet portlet = ActionUtil.getPortlet(actionRequest);

    PortletConfig portletConfig =
        (PortletConfig) actionRequest.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG);

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

    String settingsScope = ParamUtil.getString(actionRequest, "settingsScope");

    PortletPreferences portletPreferences =
        getPortletPreferences(themeDisplay, portlet.getPortletId(), settingsScope);

    actionRequest = ActionUtil.getWrappedActionRequest(actionRequest, portletPreferences);

    ConfigurationAction configurationAction = getConfigurationAction(portlet);

    if (configurationAction == null) {
      return;
    }

    configurationAction.processAction(portletConfig, actionRequest, actionResponse);

    Layout layout = themeDisplay.getLayout();

    PortletLayoutListener portletLayoutListener = portlet.getPortletLayoutListenerInstance();

    if (portletLayoutListener != null) {
      portletLayoutListener.onSetup(portlet.getPortletId(), layout.getPlid());
    }
  }
コード例 #8
0
  public void restoreArchivedSetup(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    Portlet portlet = ActionUtil.getPortlet(actionRequest);

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

    Settings portletInstanceSettings =
        SettingsFactoryUtil.getSettings(
            new PortletInstanceSettingsLocator(themeDisplay.getLayout(), portlet.getPortletId()));

    ModifiableSettings portletInstanceModifiableSettings =
        portletInstanceSettings.getModifiableSettings();

    String name = ParamUtil.getString(actionRequest, "name");

    ArchivedSettings archivedSettings =
        SettingsFactoryUtil.getPortletInstanceArchivedSettings(
            themeDisplay.getSiteGroupId(), portlet.getRootPortletId(), name);

    portletInstanceModifiableSettings.reset();

    portletInstanceModifiableSettings.setValues(archivedSettings);

    portletInstanceModifiableSettings.store();

    String portletResource = ParamUtil.getString(actionRequest, "portletResource");

    SessionMessages.add(
        actionRequest,
        PortalUtil.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_REFRESH_PORTLET,
        portletResource);
  }
コード例 #9
0
  @Override
  public void delete(Portlet portlet) {
    if (PortletConstants.hasInstanceId(portlet.getPortletId())) {
      Map<String, InvokerPortlet> portletInstances = _pool.get(portlet.getRootPortletId());

      if (portletInstances != null) {
        portletInstances.remove(portlet.getPortletId());
      }
    }
  }
コード例 #10
0
  protected String getCssClasses() {
    Portlet portlet = (Portlet) request.getAttribute(WebKeys.RENDER_PORTLET);

    String cssClasses = "portlet ";

    if (portlet != null) {
      cssClasses += portlet.getCssClassWrapper();
    }

    return cssClasses;
  }
コード例 #11
0
  @Override
  protected void doDispatch(RenderRequest renderRequest, RenderResponse renderResponse)
      throws IOException, PortletException {

    try {
      String mvcPath = renderRequest.getParameter("mvcPath");

      if (mvcPath.equals("/edit_permissions.jsp")) {
        checkEditPermissionsJSP(renderRequest);

        super.doDispatch(renderRequest, renderResponse);

        return;
      }

      Portlet portlet = ActionUtil.getPortlet(renderRequest);

      if (mvcPath.endsWith("edit_configuration.jsp")) {
        ThemeDisplay themeDisplay =
            (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);

        String settingsScope = renderRequest.getParameter("settingsScope");

        PortletPreferences portletPreferences =
            getPortletPreferences(themeDisplay, portlet.getPortletId(), settingsScope);

        renderRequest = ActionUtil.getWrappedRenderRequest(renderRequest, portletPreferences);

        renderEditConfiguration(renderRequest, portlet);
      } else {
        PortletPreferences portletPreferences =
            ActionUtil.getLayoutPortletSetup(renderRequest, portlet);

        renderRequest = ActionUtil.getWrappedRenderRequest(renderRequest, portletPreferences);

        if (mvcPath.endsWith("edit_public_render_parameters.jsp")) {
          renderEditPublicParameters(renderRequest, portlet);
        }
      }

      renderResponse.setTitle(ActionUtil.getTitle(portlet, renderRequest));

      super.doDispatch(renderRequest, renderResponse);
    } catch (Exception e) {
      _log.error(e.getMessage());

      SessionErrors.add(renderRequest, e.getClass());

      include("/error.jsp", renderRequest, renderResponse);
    }
  }
コード例 #12
0
  protected ConfigurationAction getConfigurationAction(Portlet portlet) throws Exception {

    if (portlet == null) {
      return null;
    }

    ConfigurationAction configurationAction = portlet.getConfigurationActionInstance();

    if (configurationAction == null) {
      _log.error("Configuration action for portlet " + portlet.getPortletId() + " is null");
    }

    return configurationAction;
  }
コード例 #13
0
ファイル: RuntimeTag.java プロジェクト: jpince/liferay-portal
  /** @see com.liferay.portal.model.impl.LayoutTypePortletImpl#getStaticPortlets( String) */
  protected static Portlet getPortlet(long companyId, String portletId) throws Exception {

    Portlet portlet = PortletLocalServiceUtil.getPortletById(companyId, portletId);

    // See LayoutTypePortletImpl#getStaticPortlets for why we only clone
    // non-instanceable portlets

    if (!portlet.isInstanceable()) {
      portlet = (Portlet) portlet.clone();
    }

    portlet.setStatic(true);

    return portlet;
  }
コード例 #14
0
  @Override
  public List<Portlet> getAllPortlets(boolean includeSystem) {
    List<Portlet> filteredPortlets = new ArrayList<>();

    List<Portlet> portlets = getAllPortlets();

    for (Portlet portlet : portlets) {
      if (portlet.isSystem() && !includeSystem) {
        continue;
      }

      filteredPortlets.add(portlet);
    }

    return filteredPortlets;
  }
  @Override
  public List<String> getDefaultViews(String portletId) {
    List<String> defaultViews = new ArrayList<>();

    Portlet portlet = _portletLocalService.getPortletById(portletId);

    if (portlet == null) {
      return defaultViews;
    }

    Map<String, String> initParams = portlet.getInitParams();

    String[] mvcCommandNamesDefaultViews =
        StringUtil.split(initParams.get("mvc-command-names-default-views"));

    return ListUtil.fromArray(mvcCommandNamesDefaultViews);
  }
コード例 #16
0
  public void editPublicRenderParameters(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    Portlet portlet = ActionUtil.getPortlet(actionRequest);

    PortletPreferences portletPreferences =
        ActionUtil.getLayoutPortletSetup(actionRequest, portlet);

    actionRequest = ActionUtil.getWrappedActionRequest(actionRequest, portletPreferences);

    Enumeration<String> enu = portletPreferences.getNames();

    while (enu.hasMoreElements()) {
      String name = enu.nextElement();

      if (name.startsWith(PublicRenderParameterConfiguration.IGNORE_PREFIX)
          || name.startsWith(PublicRenderParameterConfiguration.MAPPING_PREFIX)) {

        portletPreferences.reset(name);
      }
    }

    for (PublicRenderParameter publicRenderParameter : portlet.getPublicRenderParameters()) {

      String ignoreKey = PublicRenderParameterConfiguration.getIgnoreKey(publicRenderParameter);

      boolean ignoreValue = ParamUtil.getBoolean(actionRequest, ignoreKey);

      if (ignoreValue) {
        portletPreferences.setValue(ignoreKey, String.valueOf(Boolean.TRUE));
      } else {
        String mappingKey = PublicRenderParameterConfiguration.getMappingKey(publicRenderParameter);

        String mappingValue = ParamUtil.getString(actionRequest, mappingKey);

        if (Validator.isNotNull(mappingValue)) {
          portletPreferences.setValue(mappingKey, mappingValue);
        }
      }
    }

    if (SessionErrors.isEmpty(actionRequest)) {
      portletPreferences.store();
    }
  }
コード例 #17
0
  public void editSupportedClients(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    Portlet portlet = ActionUtil.getPortlet(actionRequest);

    PortletPreferences portletPreferences = actionRequest.getPreferences();

    actionRequest = ActionUtil.getWrappedActionRequest(actionRequest, portletPreferences);

    Set<String> allPortletModes = portlet.getAllPortletModes();

    for (String portletMode : allPortletModes) {
      String mobileDevicesParam = "portletSetupSupportedClientsMobileDevices_" + portletMode;

      boolean mobileDevices = ParamUtil.getBoolean(actionRequest, mobileDevicesParam);

      portletPreferences.setValue(mobileDevicesParam, String.valueOf(mobileDevices));
    }

    portletPreferences.store();
  }
コード例 #18
0
  public void updateArchivedSetup(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    Portlet portlet = ActionUtil.getPortlet(actionRequest);

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

    String name = ParamUtil.getString(actionRequest, "name");

    ArchivedSettings archivedSettings =
        SettingsFactoryUtil.getPortletInstanceArchivedSettings(
            themeDisplay.getSiteGroupId(), portlet.getRootPortletId(), name);

    Settings portletInstanceSettings =
        SettingsFactoryUtil.getSettings(
            new PortletInstanceSettingsLocator(themeDisplay.getLayout(), portlet.getPortletId()));

    ModifiableSettings portletInstanceModifiableSettings =
        portletInstanceSettings.getModifiableSettings();

    archivedSettings.setValues(portletInstanceModifiableSettings);

    archivedSettings.store();
  }
コード例 #19
0
  protected List<Portlet> getStaticPortlets(String position) {
    String[] portletIds = getStaticPortletIds(position);

    List<Portlet> portlets = new ArrayList<>();

    for (String portletId : portletIds) {
      if (Validator.isNull(portletId) || hasNonstaticPortletId(portletId)) {

        continue;
      }

      Portlet portlet = PortletLocalServiceUtil.getPortletById(getCompanyId(), portletId);

      if (portlet != null) {
        Portlet staticPortlet = portlet;

        if (portlet.isInstanceable()) {

          // Instanceable portlets do not need to be cloned because
          // they are already cloned. See the method getPortletById in
          // the class PortletLocalServiceImpl and how it references
          // the method getClonedInstance in the class PortletImpl.

        } else {
          staticPortlet = (Portlet) staticPortlet.clone();
        }

        staticPortlet.setStatic(true);

        if (position.startsWith("layout.static.portlets.start")) {
          staticPortlet.setStaticStart(true);
        }

        portlets.add(staticPortlet);
      }
    }

    return portlets;
  }
コード例 #20
0
  public void updateRolePermissions(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

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

    String portletResource = ParamUtil.getString(actionRequest, "portletResource");
    String modelResource = ParamUtil.getString(actionRequest, "modelResource");
    long[] roleIds =
        StringUtil.split(ParamUtil.getString(actionRequest, "rolesSearchContainerPrimaryKeys"), 0L);

    String selResource = PortletConstants.getRootPortletId(portletResource);

    if (Validator.isNotNull(modelResource)) {
      selResource = modelResource;
    }

    long resourceGroupId =
        ParamUtil.getLong(actionRequest, "resourceGroupId", themeDisplay.getScopeGroupId());
    String resourcePrimKey = ParamUtil.getString(actionRequest, "resourcePrimKey");

    Map<Long, String[]> roleIdsToActionIds = new HashMap<>();

    if (_resourceBlockLocalService.isSupported(selResource)) {
      for (long roleId : roleIds) {
        List<String> actionIds = getActionIdsList(actionRequest, roleId, true);

        roleIdsToActionIds.put(roleId, actionIds.toArray(new String[actionIds.size()]));
      }

      _resourceBlockService.setIndividualScopePermissions(
          themeDisplay.getCompanyId(),
          resourceGroupId,
          selResource,
          GetterUtil.getLong(resourcePrimKey),
          roleIdsToActionIds);
    } else {
      for (long roleId : roleIds) {
        String[] actionIds = getActionIds(actionRequest, roleId, false);

        roleIdsToActionIds.put(roleId, actionIds);
      }

      _resourcePermissionService.setIndividualResourcePermissions(
          resourceGroupId,
          themeDisplay.getCompanyId(),
          selResource,
          resourcePrimKey,
          roleIdsToActionIds);
    }

    if (PropsValues.PERMISSIONS_PROPAGATION_ENABLED) {
      Portlet portlet =
          _portletLocalService.getPortletById(themeDisplay.getCompanyId(), portletResource);

      PermissionPropagator permissionPropagator = portlet.getPermissionPropagatorInstance();

      if (permissionPropagator != null) {
        permissionPropagator.propagateRolePermissions(
            actionRequest, modelResource, resourcePrimKey, roleIds);
      }
    }

    if (Validator.isNull(modelResource)) {

      // Force update of layout modified date. See LPS-59246.

      Portlet portlet = ActionUtil.getPortlet(actionRequest);

      PortletPreferences portletPreferences =
          ActionUtil.getLayoutPortletSetup(actionRequest, portlet);

      portletPreferences.store();
    }
  }
コード例 #21
0
  protected File doExport(PortletDataContext portletDataContext, long[] layoutIds)
      throws Exception {

    Map<String, String[]> parameterMap = portletDataContext.getParameterMap();

    boolean ignoreLastPublishDate =
        MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.IGNORE_LAST_PUBLISH_DATE);
    boolean layoutSetPrototypeSettings =
        MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.LAYOUT_SET_PROTOTYPE_SETTINGS);
    boolean layoutSetSettings =
        MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.LAYOUT_SET_SETTINGS);
    boolean logo = MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.LOGO);
    boolean permissions = MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.PERMISSIONS);

    if (_log.isDebugEnabled()) {
      _log.debug("Export permissions " + permissions);
    }

    LayoutSet layoutSet =
        _layoutSetLocalService.getLayoutSet(
            portletDataContext.getGroupId(), portletDataContext.isPrivateLayout());

    long companyId = layoutSet.getCompanyId();
    long defaultUserId = _userLocalService.getDefaultUserId(companyId);

    ServiceContext serviceContext = ServiceContextThreadLocal.popServiceContext();

    if (serviceContext == null) {
      serviceContext = new ServiceContext();
    }

    serviceContext.setCompanyId(companyId);
    serviceContext.setSignedIn(false);
    serviceContext.setUserId(defaultUserId);

    serviceContext.setAttribute("exporting", Boolean.TRUE);

    long layoutSetBranchId = MapUtil.getLong(parameterMap, "layoutSetBranchId");

    serviceContext.setAttribute("layoutSetBranchId", layoutSetBranchId);

    ServiceContextThreadLocal.pushServiceContext(serviceContext);

    if (ignoreLastPublishDate) {
      portletDataContext.setEndDate(null);
      portletDataContext.setStartDate(null);
    }

    StopWatch stopWatch = new StopWatch();

    stopWatch.start();

    Document document = SAXReaderUtil.createDocument();

    Element rootElement = document.addElement("root");

    portletDataContext.setExportDataRootElement(rootElement);

    Element headerElement = rootElement.addElement("header");

    headerElement.addAttribute(
        "available-locales",
        StringUtil.merge(LanguageUtil.getAvailableLocales(portletDataContext.getScopeGroupId())));
    headerElement.addAttribute("build-number", String.valueOf(ReleaseInfo.getBuildNumber()));
    headerElement.addAttribute("export-date", Time.getRFC822());

    if (portletDataContext.hasDateRange()) {
      headerElement.addAttribute("start-date", String.valueOf(portletDataContext.getStartDate()));
      headerElement.addAttribute("end-date", String.valueOf(portletDataContext.getEndDate()));
    }

    headerElement.addAttribute("company-id", String.valueOf(portletDataContext.getCompanyId()));
    headerElement.addAttribute(
        "company-group-id", String.valueOf(portletDataContext.getCompanyGroupId()));
    headerElement.addAttribute("group-id", String.valueOf(portletDataContext.getGroupId()));
    headerElement.addAttribute(
        "user-personal-site-group-id",
        String.valueOf(portletDataContext.getUserPersonalSiteGroupId()));
    headerElement.addAttribute(
        "private-layout", String.valueOf(portletDataContext.isPrivateLayout()));

    Group group = layoutSet.getGroup();

    String type = "layout-set";

    if (group.isLayoutPrototype()) {
      type = "layout-prototype";

      LayoutPrototype layoutPrototype =
          _layoutPrototypeLocalService.getLayoutPrototype(group.getClassPK());

      headerElement.addAttribute("type-uuid", layoutPrototype.getUuid());

      layoutIds =
          ExportImportHelperUtil.getAllLayoutIds(
              portletDataContext.getGroupId(), portletDataContext.isPrivateLayout());
    } else if (group.isLayoutSetPrototype()) {
      type = "layout-set-prototype";

      LayoutSetPrototype layoutSetPrototype =
          _layoutSetPrototypeLocalService.getLayoutSetPrototype(group.getClassPK());

      headerElement.addAttribute("type-uuid", layoutSetPrototype.getUuid());
    }

    headerElement.addAttribute("type", type);

    LayoutSetBranch layoutSetBranch =
        _layoutSetBranchLocalService.fetchLayoutSetBranch(layoutSetBranchId);

    if (logo) {
      Image image = null;

      if (layoutSetBranch != null) {
        image = _imageLocalService.getImage(layoutSetBranch.getLogoId());
      } else {
        image = _imageLocalService.getImage(layoutSet.getLogoId());
      }

      if ((image != null) && (image.getTextObj() != null)) {
        String logoPath = ExportImportPathUtil.getRootPath(portletDataContext);

        logoPath += "/logo";

        headerElement.addAttribute("logo-path", logoPath);

        portletDataContext.addZipEntry(logoPath, image.getTextObj());
      }
    }

    String layoutSetPrototypeUuid = layoutSet.getLayoutSetPrototypeUuid();

    if (layoutSetPrototypeSettings && Validator.isNotNull(layoutSetPrototypeUuid)) {

      LayoutSetPrototype layoutSetPrototype =
          _layoutSetPrototypeLocalService.getLayoutSetPrototypeByUuidAndCompanyId(
              layoutSetPrototypeUuid, companyId);

      headerElement.addAttribute("layout-set-prototype-uuid", layoutSetPrototypeUuid);
      headerElement.addAttribute(
          "layout-set-prototype-name", layoutSetPrototype.getName(LocaleUtil.getDefault()));
    }

    Element missingReferencesElement = rootElement.addElement("missing-references");

    portletDataContext.setMissingReferencesElement(missingReferencesElement);

    if (layoutSetBranch != null) {
      _themeExporter.exportTheme(portletDataContext, layoutSetBranch);
    } else {
      _themeExporter.exportTheme(portletDataContext, layoutSet);
    }

    if (layoutSetSettings) {
      Element settingsElement = headerElement.addElement("settings");

      if (layoutSetBranch != null) {
        settingsElement.addCDATA(layoutSetBranch.getSettings());
      } else {
        settingsElement.addCDATA(layoutSet.getSettings());
      }
    }

    Map<String, Object[]> portletIds = new LinkedHashMap<>();

    List<Layout> layouts =
        _layoutLocalService.getLayouts(
            portletDataContext.getGroupId(), portletDataContext.isPrivateLayout());

    if (group.isStagingGroup()) {
      group = group.getLiveGroup();
    }

    // Collect data portlets

    for (Portlet portlet : ExportImportHelperUtil.getDataSiteLevelPortlets(companyId)) {

      String portletId = portlet.getRootPortletId();

      if (ExportImportThreadLocal.isStagingInProcess() && !group.isStagedPortlet(portletId)) {

        continue;
      }

      // Calculate the amount of exported data

      if (BackgroundTaskThreadLocal.hasBackgroundTask()) {
        PortletDataHandler portletDataHandler = portlet.getPortletDataHandlerInstance();

        portletDataHandler.prepareManifestSummary(portletDataContext);
      }

      // Add portlet ID to exportable portlets list

      portletIds.put(
          PortletPermissionUtil.getPrimaryKey(0, portletId),
          new Object[] {
            portletId,
            LayoutConstants.DEFAULT_PLID,
            portletDataContext.getGroupId(),
            StringPool.BLANK,
            StringPool.BLANK
          });

      if (!portlet.isScopeable()) {
        continue;
      }

      // Scoped data

      for (Layout layout : layouts) {
        if (!ArrayUtil.contains(layoutIds, layout.getLayoutId())
            || !layout.isTypePortlet()
            || !layout.hasScopeGroup()) {

          continue;
        }

        Group scopeGroup = layout.getScopeGroup();

        portletIds.put(
            PortletPermissionUtil.getPrimaryKey(layout.getPlid(), portlet.getPortletId()),
            new Object[] {
              portlet.getPortletId(),
              layout.getPlid(),
              scopeGroup.getGroupId(),
              StringPool.BLANK,
              layout.getUuid()
            });
      }
    }

    // Collect layout portlets

    for (Layout layout : layouts) {
      getLayoutPortlets(portletDataContext, layoutIds, portletIds, layout);
    }

    if (BackgroundTaskThreadLocal.hasBackgroundTask()) {
      ManifestSummary manifestSummary = portletDataContext.getManifestSummary();

      PortletDataHandlerStatusMessageSenderUtil.sendStatusMessage(
          "layout", ArrayUtil.toStringArray(portletIds.keySet()), manifestSummary);

      manifestSummary.resetCounters();
    }

    // Export actual data

    portletDataContext.addDeletionSystemEventStagedModelTypes(new StagedModelType(Layout.class));

    // Force to always have a layout group element

    portletDataContext.getExportDataGroupElement(Layout.class);

    for (Layout layout : layouts) {
      exportLayout(portletDataContext, layoutIds, layout);
    }

    Element portletsElement = rootElement.addElement("portlets");

    Element servicesElement = rootElement.addElement("services");

    long previousScopeGroupId = portletDataContext.getScopeGroupId();

    for (Map.Entry<String, Object[]> portletIdsEntry : portletIds.entrySet()) {

      Object[] portletObjects = portletIdsEntry.getValue();

      String portletId = null;
      long plid = LayoutConstants.DEFAULT_PLID;
      long scopeGroupId = 0;
      String scopeType = StringPool.BLANK;
      String scopeLayoutUuid = null;

      if (portletObjects.length == 4) {
        portletId = (String) portletIdsEntry.getValue()[0];
        plid = (Long) portletIdsEntry.getValue()[1];
        scopeGroupId = (Long) portletIdsEntry.getValue()[2];
        scopeLayoutUuid = (String) portletIdsEntry.getValue()[3];
      } else {
        portletId = (String) portletIdsEntry.getValue()[0];
        plid = (Long) portletIdsEntry.getValue()[1];
        scopeGroupId = (Long) portletIdsEntry.getValue()[2];
        scopeType = (String) portletIdsEntry.getValue()[3];
        scopeLayoutUuid = (String) portletIdsEntry.getValue()[4];
      }

      Layout layout = _layoutLocalService.fetchLayout(plid);

      if (layout == null) {
        layout = new LayoutImpl();

        layout.setCompanyId(companyId);
        layout.setGroupId(portletDataContext.getGroupId());
      }

      portletDataContext.setPlid(plid);
      portletDataContext.setOldPlid(plid);
      portletDataContext.setPortletId(portletId);
      portletDataContext.setScopeGroupId(scopeGroupId);
      portletDataContext.setScopeType(scopeType);
      portletDataContext.setScopeLayoutUuid(scopeLayoutUuid);

      Map<String, Boolean> exportPortletControlsMap =
          ExportImportHelperUtil.getExportPortletControlsMap(
              companyId, portletId, parameterMap, type);

      try {
        _exportImportLifecycleManager.fireExportImportLifecycleEvent(
            EVENT_PORTLET_EXPORT_STARTED,
            getProcessFlag(),
            PortletDataContextFactoryUtil.clonePortletDataContext(portletDataContext));

        _portletExportController.exportPortlet(
            portletDataContext,
            layout,
            portletsElement,
            permissions,
            exportPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_ARCHIVED_SETUPS),
            exportPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_DATA),
            exportPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_SETUP),
            exportPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_USER_PREFERENCES));
        _portletExportController.exportService(
            portletDataContext,
            servicesElement,
            exportPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_SETUP));

        _exportImportLifecycleManager.fireExportImportLifecycleEvent(
            EVENT_PORTLET_EXPORT_SUCCEEDED,
            getProcessFlag(),
            PortletDataContextFactoryUtil.clonePortletDataContext(portletDataContext));
      } catch (Throwable t) {
        _exportImportLifecycleManager.fireExportImportLifecycleEvent(
            EVENT_PORTLET_EXPORT_FAILED,
            getProcessFlag(),
            PortletDataContextFactoryUtil.clonePortletDataContext(portletDataContext),
            t);

        throw t;
      }
    }

    portletDataContext.setScopeGroupId(previousScopeGroupId);

    _portletExportController.exportAssetLinks(portletDataContext);
    _portletExportController.exportExpandoTables(portletDataContext);
    _portletExportController.exportLocks(portletDataContext);

    _deletionSystemEventExporter.exportDeletionSystemEvents(portletDataContext);

    if (permissions) {
      _permissionExporter.exportPortletDataPermissions(portletDataContext);
    }

    ExportImportHelperUtil.writeManifestSummary(document, portletDataContext.getManifestSummary());

    if (_log.isInfoEnabled()) {
      _log.info("Exporting layouts takes " + stopWatch.getTime() + " ms");
    }

    boolean updateLastPublishDate =
        MapUtil.getBoolean(
            portletDataContext.getParameterMap(), PortletDataHandlerKeys.UPDATE_LAST_PUBLISH_DATE);

    if (ExportImportThreadLocal.isStagingInProcess() && updateLastPublishDate) {

      ExportImportProcessCallbackRegistryUtil.registerCallback(
          new UpdateLayoutSetLastPublishDateCallable(
              portletDataContext.getDateRange(),
              portletDataContext.getGroupId(),
              portletDataContext.isPrivateLayout()));
    }

    portletDataContext.addZipEntry("/manifest.xml", document.formattedString());

    ZipWriter zipWriter = portletDataContext.getZipWriter();

    return zipWriter.getFile();
  }
コード例 #22
0
  protected void getLayoutPortlets(
      PortletDataContext portletDataContext,
      long[] layoutIds,
      Map<String, Object[]> portletIds,
      Layout layout)
      throws Exception {

    if (!ArrayUtil.contains(layoutIds, layout.getLayoutId())) {
      return;
    }

    if (!prepareLayoutStagingHandler(portletDataContext, layout)
        || !layout.isSupportsEmbeddedPortlets()) {

      // Only portlet type layouts support page scoping

      return;
    }

    LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType();

    // The getAllPortlets method returns all effective nonsystem portlets
    // for any layout type, including embedded portlets, or in the case of
    // panel type layout, selected portlets

    for (Portlet portlet : layoutTypePortlet.getAllPortlets(false)) {
      String portletId = portlet.getPortletId();

      Settings portletInstanceSettings =
          SettingsFactoryUtil.getSettings(new PortletInstanceSettingsLocator(layout, portletId));

      String scopeType = portletInstanceSettings.getValue("lfrScopeType", null);
      String scopeLayoutUuid = portletInstanceSettings.getValue("lfrScopeLayoutUuid", null);

      long scopeGroupId = portletDataContext.getScopeGroupId();

      if (Validator.isNotNull(scopeType)) {
        Group scopeGroup = null;

        if (scopeType.equals("company")) {
          scopeGroup = _groupLocalService.getCompanyGroup(layout.getCompanyId());
        } else if (scopeType.equals("layout")) {
          Layout scopeLayout = null;

          scopeLayout =
              _layoutLocalService.fetchLayoutByUuidAndGroupId(
                  scopeLayoutUuid,
                  portletDataContext.getGroupId(),
                  portletDataContext.isPrivateLayout());

          if (scopeLayout == null) {
            continue;
          }

          scopeGroup = scopeLayout.getScopeGroup();
        } else {
          throw new IllegalArgumentException("Scope type " + scopeType + " is invalid");
        }

        if (scopeGroup != null) {
          scopeGroupId = scopeGroup.getGroupId();
        }
      }

      String key = PortletPermissionUtil.getPrimaryKey(layout.getPlid(), portletId);

      portletIds.put(
          key,
          new Object[] {portletId, layout.getPlid(), scopeGroupId, scopeType, scopeLayoutUuid});
    }
  }
コード例 #23
0
  @Override
  public InvokerPortlet create(
      Portlet portlet, ServletContext servletContext, boolean destroyPrevious)
      throws PortletException {

    if (destroyPrevious) {
      destroyRelated(portlet);
    }

    boolean instanceable = false;

    boolean deployed = !portlet.isUndeployedPortlet();

    if (portlet.isInstanceable()
        && deployed
        && PortletConstants.hasInstanceId(portlet.getPortletId())) {

      instanceable = true;
    }

    String rootPortletId = portlet.getRootPortletId();

    InvokerPortlet rootInvokerPortletInstance = null;

    Map<String, InvokerPortlet> portletInstances = null;

    if (deployed) {
      portletInstances = _pool.get(rootPortletId);

      if (portletInstances == null) {
        portletInstances = new ConcurrentHashMap<>();

        _pool.put(rootPortletId, portletInstances);
      } else {
        if (instanceable) {
          InvokerPortlet instanceInvokerPortletInstance =
              portletInstances.get(portlet.getPortletId());

          if (instanceInvokerPortletInstance != null) {
            return instanceInvokerPortletInstance;
          }
        }

        rootInvokerPortletInstance = portletInstances.get(rootPortletId);
      }
    }

    if (rootInvokerPortletInstance == null) {
      PortletBag portletBag = PortletBagPool.get(rootPortletId);

      // Portlet bag should never be null unless the portlet has been
      // undeployed

      if (portletBag == null) {
        PortletBagFactory portletBagFactory = new PortletBagFactory();

        portletBagFactory.setClassLoader(ClassLoaderUtil.getPortalClassLoader());
        portletBagFactory.setServletContext(servletContext);
        portletBagFactory.setWARFile(false);

        try {
          portletBag = portletBagFactory.create(portlet);
        } catch (Exception e) {
          throw new PortletException(e);
        }
      }

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

      rootInvokerPortletInstance = init(portlet, portletConfig, portletBag.getPortletInstance());

      if (deployed) {
        portletInstances.put(rootPortletId, rootInvokerPortletInstance);
      }
    }

    if (!instanceable) {
      return rootInvokerPortletInstance;
    }

    javax.portlet.Portlet portletInstance = rootInvokerPortletInstance.getPortletInstance();

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

    PortletContext portletContext = portletConfig.getPortletContext();
    boolean checkAuthToken = rootInvokerPortletInstance.isCheckAuthToken();
    boolean facesPortlet = rootInvokerPortletInstance.isFacesPortlet();
    boolean strutsPortlet = rootInvokerPortletInstance.isStrutsPortlet();
    boolean strutsBridgePortlet = rootInvokerPortletInstance.isStrutsBridgePortlet();

    InvokerPortlet instanceInvokerPortletInstance =
        _invokerPortletFactory.create(
            portlet,
            portletInstance,
            portletConfig,
            portletContext,
            (InvokerFilterContainer) rootInvokerPortletInstance,
            checkAuthToken,
            facesPortlet,
            strutsPortlet,
            strutsBridgePortlet);

    if (deployed) {
      portletInstances.put(portlet.getPortletId(), instanceInvokerPortletInstance);
    }

    return instanceInvokerPortletInstance;
  }
コード例 #24
0
  protected String addPortletId(
      long userId,
      String portletId,
      String columnId,
      int columnPos,
      boolean checkPermission,
      boolean strictHasPortlet) {

    portletId = JS.getSafeName(portletId);

    Layout layout = getLayout();

    Portlet portlet = null;

    try {
      portlet = PortletLocalServiceUtil.getPortletById(layout.getCompanyId(), portletId);

      if (portlet == null) {
        if (_log.isWarnEnabled()) {
          _log.warn("Portlet " + portletId + " cannot be added because it is not registered");
        }

        return null;
      }

      PermissionChecker permissionChecker = PermissionThreadLocal.getPermissionChecker();

      if (checkPermission
          && !PortletPermissionUtil.contains(
              permissionChecker, layout, portlet, ActionKeys.ADD_TO_PAGE)) {

        return null;
      }
    } catch (Exception e) {
      _log.error(e, e);
    }

    if (portlet.isSystem()) {
      return null;
    }

    if (portlet.isInstanceable() && !PortletConstants.hasInstanceId(portletId)) {

      portletId =
          PortletConstants.assemblePortletId(portletId, PortletConstants.generateInstanceId());
    }

    if (hasPortletId(portletId, strictHasPortlet)) {
      return null;
    }

    if (columnId == null) {
      LayoutTemplate layoutTemplate = getLayoutTemplate();

      List<String> columns = layoutTemplate.getColumns();

      if (!columns.isEmpty()) {
        columnId = columns.get(0);
      }
    }

    if (columnId == null) {
      return null;
    }

    if (isCustomizable()) {
      if (isColumnDisabled(columnId)) {
        return null;
      }

      if ((PortletConstants.hasInstanceId(portletId) || portlet.isPreferencesUniquePerLayout())
          && hasUserPreferences()) {

        portletId = PortletConstants.assemblePortletId(portletId, userId);
      }
    }

    String columnValue = StringPool.BLANK;

    if (hasUserPreferences()) {
      columnValue = getUserPreference(columnId);
    } else {
      columnValue = getTypeSettingsProperty(columnId);
    }

    if ((columnValue == null) && columnId.startsWith(_NESTED_PORTLETS_NAMESPACE)) {

      addNestedColumn(columnId);
    }

    if (columnPos >= 0) {
      List<String> portletIds = ListUtil.fromArray(StringUtil.split(columnValue));

      if (columnPos <= portletIds.size()) {
        portletIds.add(columnPos, portletId);
      } else {
        portletIds.add(portletId);
      }

      columnValue = StringUtil.merge(portletIds);
    } else {
      columnValue = StringUtil.add(columnValue, portletId);
    }

    if (hasUserPreferences()) {
      setUserPreference(columnId, columnValue);
    } else {
      setTypeSettingsProperty(columnId, columnValue);
    }

    try {
      if (_enablePortletLayoutListener && !portlet.isUndeployedPortlet()) {

        PortletLayoutListener portletLayoutListener = portlet.getPortletLayoutListenerInstance();

        if (portletLayoutListener != null) {
          portletLayoutListener.onAddToLayout(portletId, layout.getPlid());
        }
      }
    } catch (Exception e) {
      _log.error("Unable to fire portlet layout listener event", e);
    }

    return portletId;
  }
コード例 #25
0
  protected String getUserPreference(String key) {
    String value = StringPool.BLANK;

    if (!hasUserPreferences()) {
      return value;
    }

    value =
        _portalPreferences.getValue(CustomizedPages.namespacePlid(getPlid()), key, StringPool.NULL);

    if (!value.equals(StringPool.NULL)) {
      return value;
    }

    value = getTypeSettingsProperty(key);

    if (Validator.isNull(value)) {
      return value;
    }

    List<String> newPortletIds = new ArrayList<>();

    PermissionChecker permissionChecker = PermissionThreadLocal.getPermissionChecker();

    String[] portletIds = StringUtil.split(value);

    for (String portletId : portletIds) {
      try {
        if (!PortletPermissionUtil.contains(
            permissionChecker, getLayout(), portletId, ActionKeys.VIEW, true)) {

          continue;
        }

        String rootPortletId = PortletConstants.getRootPortletId(portletId);

        if (!PortletPermissionUtil.contains(
            permissionChecker, rootPortletId, ActionKeys.ADD_TO_PAGE)) {

          continue;
        }
      } catch (Exception e) {
        _log.error(e, e);
      }

      String newPortletId = null;

      boolean preferencesUniquePerLayout = false;

      try {
        Portlet portlet = PortletLocalServiceUtil.getPortletById(getCompanyId(), portletId);

        preferencesUniquePerLayout = portlet.isPreferencesUniquePerLayout();
      } catch (SystemException se) {
        _log.error(se, se);
      }

      if (PortletConstants.hasInstanceId(portletId) || preferencesUniquePerLayout) {

        String instanceId = null;

        if (PortletConstants.hasInstanceId(portletId)) {
          instanceId = PortletConstants.generateInstanceId();
        }

        newPortletId =
            PortletConstants.assemblePortletId(
                portletId, _portalPreferences.getUserId(), instanceId);

        copyPreferences(_portalPreferences.getUserId(), portletId, newPortletId);

        copyResourcePermissions(portletId, newPortletId);
      } else {
        newPortletId = portletId;
      }

      newPortletIds.add(newPortletId);
    }

    value = StringUtil.merge(newPortletIds);

    setUserPreference(key, value);

    return value;
  }
コード例 #26
0
  protected void onRemoveFromLayout(String[] portletIds) {
    Set<String> portletIdList = new HashSet<>();

    for (String portletId : portletIds) {
      removeModesPortletId(portletId);
      removeStatesPortletId(portletId);

      portletIdList.add(portletId);

      String rootPortletId = PortletConstants.getRootPortletId(portletId);

      if (rootPortletId.equals(PortletKeys.NESTED_PORTLETS)) {
        String portletNamespace = PortalUtil.getPortletNamespace(portletId);

        UnicodeProperties typeSettingsProperties = getTypeSettingsProperties();

        for (Map.Entry<String, String> entry : typeSettingsProperties.entrySet()) {

          String key = entry.getKey();

          if (!key.startsWith(portletNamespace)) {
            continue;
          }

          String nestedPortletIds = entry.getValue();

          for (String nestedPortletId : StringUtil.split(nestedPortletIds)) {

            removeModesPortletId(nestedPortletId);
            removeStatesPortletId(nestedPortletId);

            portletIdList.add(nestedPortletId);
          }
        }

        removeNestedColumns(portletNamespace);
      }

      Portlet portlet = PortletLocalServiceUtil.getPortletById(portletId);

      if (portlet == null) {
        continue;
      }

      PortletLayoutListener portletLayoutListener = portlet.getPortletLayoutListenerInstance();

      if (portletLayoutListener == null) {
        continue;
      }

      portletLayoutListener.updatePropertiesOnRemoveFromLayout(
          portletId, getTypeSettingsProperties());
    }

    try {
      PortletLocalServiceUtil.deletePortlets(
          getCompanyId(), portletIdList.toArray(new String[portletIdList.size()]), getPlid());
    } catch (PortalException pe) {
      _log.error(pe, pe);
    }
  }
コード例 #27
0
ファイル: RuntimeTag.java プロジェクト: jpince/liferay-portal
  public static void doTag(
      String portletName,
      String instanceId,
      String queryString,
      String settingsScope,
      String defaultPreferences,
      boolean persistSettings,
      PageContext pageContext,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    if (pageContext != null) {
      response = new PipingServletResponse(response, pageContext.getOut());
    }

    PortletInstance portletInstance = PortletInstance.fromPortletInstanceKey(portletName);

    if (Validator.isNotNull(instanceId)) {
      portletInstance =
          new PortletInstance(
              portletInstance.getPortletName(), portletInstance.getUserId(), instanceId);
    }

    RestrictPortletServletRequest restrictPortletServletRequest =
        new RestrictPortletServletRequest(PortalUtil.getOriginalServletRequest(request));

    queryString =
        PortletParameterUtil.addNamespace(portletInstance.getPortletInstanceKey(), queryString);

    Map<String, String[]> parameterMap = request.getParameterMap();

    if (!Objects.equals(portletInstance.getPortletInstanceKey(), request.getParameter("p_p_id"))) {

      parameterMap = MapUtil.filterByKeys(parameterMap, (key) -> !key.startsWith("p_p_"));
    }

    request =
        DynamicServletRequest.addQueryString(
            restrictPortletServletRequest, parameterMap, queryString, false);

    try {
      request.setAttribute(WebKeys.RENDER_PORTLET_RESOURCE, Boolean.TRUE);

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

      Portlet portlet =
          getPortlet(themeDisplay.getCompanyId(), portletInstance.getPortletInstanceKey());

      Stack<String> embeddedPortletIds = _embeddedPortletIds.get();

      if (embeddedPortletIds == null) {
        embeddedPortletIds = new Stack<>();

        _embeddedPortletIds.set(embeddedPortletIds);
      }

      if (embeddedPortletIds.search(portlet.getPortletId()) > -1) {
        String errorMessage = LanguageUtil.get(request, "the-application-cannot-include-itself");

        request.setAttribute("liferay-portlet:runtime:errorMessage", errorMessage);

        PortalIncludeUtil.include(pageContext, _ERROR_PAGE);

        return;
      }

      if (themeDisplay.isStateMaximized()) {
        LayoutTypePortlet layoutTypePortlet = themeDisplay.getLayoutTypePortlet();

        if (layoutTypePortlet.hasStateMaxPortletId(portletInstance.getPortletInstanceKey())) {

          // A portlet in the maximized state has already been
          // processed

          return;
        }
      }

      Layout layout = themeDisplay.getLayout();

      request.setAttribute(WebKeys.SETTINGS_SCOPE, settingsScope);

      JSONObject jsonObject = null;

      boolean writeJSONObject = false;

      LayoutTypePortlet layoutTypePortlet = themeDisplay.getLayoutTypePortlet();

      if (persistSettings && !layoutTypePortlet.isPortletEmbedded(portlet.getPortletId())) {

        PortletPreferencesFactoryUtil.getLayoutPortletSetup(
            themeDisplay.getCompanyId(),
            themeDisplay.getScopeGroupId(),
            PortletKeys.PREFS_OWNER_TYPE_LAYOUT,
            PortletKeys.PREFS_PLID_SHARED,
            portletInstance.getPortletInstanceKey(),
            defaultPreferences);

        writeJSONObject = true;
      }

      if (PortletPreferencesLocalServiceUtil.getPortletPreferencesCount(
              PortletKeys.PREFS_OWNER_TYPE_LAYOUT,
              themeDisplay.getPlid(),
              portletInstance.getPortletInstanceKey())
          < 1) {

        PortletPreferencesFactoryUtil.getLayoutPortletSetup(
            layout, portletInstance.getPortletInstanceKey(), defaultPreferences);
        PortletPreferencesFactoryUtil.getPortletSetup(
            request, portletInstance.getPortletInstanceKey(), defaultPreferences);

        PortletLayoutListener portletLayoutListener = portlet.getPortletLayoutListenerInstance();

        if (portletLayoutListener != null) {
          portletLayoutListener.onAddToLayout(
              portletInstance.getPortletInstanceKey(), themeDisplay.getPlid());
        }

        writeJSONObject = true;
      }

      if (writeJSONObject) {
        jsonObject = JSONFactoryUtil.createJSONObject();

        PortletJSONUtil.populatePortletJSONObject(request, StringPool.BLANK, portlet, jsonObject);
      }

      if (jsonObject != null) {
        PortletJSONUtil.writeHeaderPaths(response, jsonObject);
      }

      embeddedPortletIds.push(portletInstance.getPortletInstanceKey());

      PortletContainerUtil.render(request, response, portlet);

      embeddedPortletIds.pop();

      if (jsonObject != null) {
        PortletJSONUtil.writeFooterPaths(response, jsonObject);
      }
    } finally {
      restrictPortletServletRequest.mergeSharedAttributes();
    }
  }
コード例 #28
0
  @Override
  public boolean isCacheable() {
    List<Portlet> portlets = new ArrayList<>();

    for (String columnId : getColumns()) {
      List<Portlet> columnPortlets = getAllPortlets(columnId);

      for (Portlet portlet : columnPortlets) {
        Portlet rootPortlet = portlet.getRootPortlet();

        if (!rootPortlet.isLayoutCacheable()) {
          return false;
        }
      }

      portlets.addAll(columnPortlets);
    }

    List<Portlet> staticPortlets = getStaticPortlets(PropsKeys.LAYOUT_STATIC_PORTLETS_ALL);

    for (Portlet portlet : staticPortlets) {
      Portlet rootPortlet = portlet.getRootPortlet();

      if (!rootPortlet.isLayoutCacheable()) {
        return false;
      }
    }

    List<Portlet> embeddedPortlets = getEmbeddedPortlets();

    for (Portlet portlet : embeddedPortlets) {
      Portlet rootPortlet = portlet.getRootPortlet();

      if (!rootPortlet.isLayoutCacheable()) {
        return false;
      }
    }

    return true;
  }
コード例 #29
0
  protected String getDetails() {
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    ResourceBundle resourceBundle = TagResourceBundleUtil.getResourceBundle(pageContext);

    String details = null;

    if (_alt != null) {
      details = " alt=\"" + LanguageUtil.get(resourceBundle, _alt) + "\"";
    } else if (isLabel()) {
      details = " alt=\"\"";
    } else {
      StringBundler sb = new StringBundler(5);

      sb.append(" alt=\"");
      sb.append(LanguageUtil.get(resourceBundle, getProcessedMessage()));
      sb.append("\" title=\"");
      sb.append(LanguageUtil.get(resourceBundle, getProcessedMessage()));
      sb.append("\"");

      details = sb.toString();
    }

    if (Validator.isNull(_src) || !themeDisplay.isThemeImagesFastLoad() || isAUIImage()) {

      return details;
    }

    SpriteImage spriteImage = null;
    String spriteFileName = null;
    String spriteFileURL = null;

    String imageFileName = StringUtil.replace(_src, "common/../", "");

    if (imageFileName.contains(Http.PROTOCOL_DELIMITER)) {
      String portalURL = PortalUtil.getPortalURL(request);

      if (imageFileName.startsWith(portalURL)) {
        imageFileName = imageFileName.substring(portalURL.length());
      } else {
        URL imageURL = null;

        try {
          imageURL = new URL(imageFileName);

          imageFileName = imageURL.getPath();
        } catch (MalformedURLException murle) {
        }
      }
    }

    Theme theme = themeDisplay.getTheme();

    String contextPath = theme.getContextPath();

    String imagesPath = contextPath.concat(theme.getImagesPath());

    if (imageFileName.startsWith(imagesPath)) {
      spriteImage = theme.getSpriteImage(imageFileName);

      if (spriteImage != null) {
        spriteFileName = spriteImage.getSpriteFileName();

        if (BrowserSnifferUtil.isIe(request) && (BrowserSnifferUtil.getMajorVersion(request) < 7)) {

          spriteFileName = StringUtil.replace(spriteFileName, ".png", ".gif");
        }

        String cdnBaseURL = themeDisplay.getCDNBaseURL();

        spriteFileURL = cdnBaseURL.concat(spriteFileName);
      }
    }

    if (spriteImage == null) {
      Portlet portlet = (Portlet) request.getAttribute("liferay-portlet:icon_portlet:portlet");

      if (portlet == null) {
        portlet = (Portlet) request.getAttribute(WebKeys.RENDER_PORTLET);
      }

      if (portlet != null) {
        PortletApp portletApp = portlet.getPortletApp();

        spriteImage = portletApp.getSpriteImage(imageFileName);

        if (spriteImage != null) {
          spriteFileName = spriteImage.getSpriteFileName();

          if (BrowserSnifferUtil.isIe(request)
              && (BrowserSnifferUtil.getMajorVersion(request) < 7)) {

            spriteFileName = StringUtil.replace(spriteFileName, ".png", ".gif");
          }

          String cdnBaseURL = themeDisplay.getCDNBaseURL();

          spriteFileURL = cdnBaseURL.concat(spriteFileName);
        }
      }
    }

    if (spriteImage != null) {
      String themeImagesPath = themeDisplay.getPathThemeImages();

      _src = themeImagesPath.concat("/spacer.png");

      StringBundler sb = new StringBundler(10);

      sb.append(details);
      sb.append(" style=\"background-image: url('");
      sb.append(spriteFileURL);
      sb.append("'); background-position: 50% -");
      sb.append(spriteImage.getOffset());
      sb.append("px; background-repeat: no-repeat; height: ");
      sb.append(spriteImage.getHeight());
      sb.append("px; width: ");
      sb.append(spriteImage.getWidth());
      sb.append("px;\"");

      details = sb.toString();
    }

    return details;
  }