@Override
  protected String upgradePreferences(
      long companyId, long ownerId, int ownerType, long plid, String portletId, String xml)
      throws Exception {

    PortletPreferences preferences =
        PortletPreferencesFactoryUtil.fromXML(companyId, ownerId, ownerType, plid, portletId, xml);

    if (portletId.startsWith(_PORTLET_ID_ASSET_PUBLISHER)) {
      updatePreferencesClassPKs(preferences, "anyClassTypeJournalArticleAssetRendererFactory");
      updatePreferencesClassPKs(preferences, "classTypeIds");
      updatePreferencesClassPKs(preferences, "classTypeIdsJournalArticleAssetRendererFactory");
    } else if (portletId.startsWith(_PORTLET_ID_JOURNAL_CONTENT)) {
      String templateId = preferences.getValue("templateId", StringPool.BLANK);

      if (Validator.isNotNull(templateId)) {
        preferences.reset("templateId");

        preferences.setValue("ddmTemplateKey", templateId);
      }
    } else if (portletId.startsWith(_PORTLET_ID_JOURNAL_CONTENT_LIST)) {
      String structureId = preferences.getValue("structureId", StringPool.BLANK);

      if (Validator.isNotNull(structureId)) {
        preferences.reset("structureId");

        preferences.setValue("ddmStructureKey", structureId);
      }
    }

    return PortletPreferencesFactoryUtil.toXML(preferences);
  }
  protected void copyPreferences(long userId, String sourcePortletId, String targetPortletId) {

    Layout layout = getLayout();

    try {
      PortletPreferencesIds portletPreferencesIds =
          PortletPreferencesFactoryUtil.getPortletPreferencesIds(
              layout.getGroupId(), 0, layout, sourcePortletId, false);

      javax.portlet.PortletPreferences sourcePortletPreferences =
          PortletPreferencesLocalServiceUtil.getStrictPreferences(portletPreferencesIds);

      portletPreferencesIds =
          PortletPreferencesFactoryUtil.getPortletPreferencesIds(
              layout.getGroupId(), userId, layout, targetPortletId, false);

      PortletPreferencesLocalServiceUtil.updatePreferences(
          portletPreferencesIds.getOwnerId(),
          portletPreferencesIds.getOwnerType(),
          portletPreferencesIds.getPlid(),
          portletPreferencesIds.getPortletId(),
          sourcePortletPreferences);
    } catch (Exception e) {
    }
  }
  public String getDDLRecordSetDisplayStyle() {
    if (_ddlRecordDisplayStyle == null) {
      PortalPreferences portalPreferences =
          PortletPreferencesFactoryUtil.getPortalPreferences(_ddlRequestHelper.getRenderRequest());

      _ddlRecordDisplayStyle =
          ParamUtil.getString(_ddlRequestHelper.getRenderRequest(), "displayStyle");

      if (Validator.isNull(_ddlRecordDisplayStyle)) {
        _ddlRecordDisplayStyle =
            portalPreferences.getValue(
                DDLPortletKeys.DYNAMIC_DATA_LISTS,
                "display-style",
                _ddlWebConfiguration.defaultDisplayView());
      } else if (ArrayUtil.contains(getDDLRecordSetDisplayViews(), _ddlRecordDisplayStyle)) {

        portalPreferences.setValue(
            DDLPortletKeys.DYNAMIC_DATA_LISTS, "display-style", _ddlRecordDisplayStyle);
      }

      if (!ArrayUtil.contains(getDDLRecordSetDisplayViews(), _ddlRecordDisplayStyle)) {

        _ddlRecordDisplayStyle = getDDLRecordSetDisplayViews()[0];
      }
    }

    return _ddlRecordDisplayStyle;
  }
  /**
   * @deprecated As of 4.0.0, replaced by {@link deletePortletData(PortletDataContext
   *     portletDataContext, javax.portlet.PortletPreferences portletPreferences)}
   */
  @Deprecated
  protected String deletePortletData(
      PortletDataContext portletDataContext, PortletPreferences portletPreferences)
      throws Exception {

    javax.portlet.PortletPreferences portletPreferencesImpl =
        PortletPreferencesFactoryUtil.fromDefaultXML(portletPreferences.getPreferences());

    return deletePortletData(portletDataContext, portletPreferencesImpl);
  }
  protected boolean isCommentsEnabled(ActionRequest actionRequest) throws Exception {

    PortletPreferences portletPreferences =
        PortletPreferencesFactoryUtil.getExistingPortletSetup(actionRequest);

    if (portletPreferences == null) {
      portletPreferences = actionRequest.getPreferences();
    }

    return GetterUtil.getBoolean(portletPreferences.getValue("enableComments", null), true);
  }
  public RecordSearch(
      PortletRequest portletRequest, PortletURL iteratorURL, List<String> headerNames) {

    super(
        portletRequest,
        new DisplayTerms(portletRequest),
        null,
        DEFAULT_CUR_PARAM,
        DEFAULT_DELTA,
        iteratorURL,
        headerNames,
        EMPTY_RESULTS_MESSAGE);

    try {
      PortalPreferences preferences =
          PortletPreferencesFactoryUtil.getPortalPreferences(portletRequest);

      String orderByCol = ParamUtil.getString(portletRequest, "orderByCol");
      String orderByType = ParamUtil.getString(portletRequest, "orderByType");

      if (Validator.isNotNull(orderByCol) && Validator.isNotNull(orderByType)) {

        preferences.setValue(
            DDLFormPortletKeys.DYNAMIC_DATA_LISTS_FORM_ADMIN,
            "view-entries-order-by-col",
            orderByCol);
        preferences.setValue(
            DDLFormPortletKeys.DYNAMIC_DATA_LISTS_FORM_ADMIN,
            "view-entries-order-by-type",
            orderByType);
      } else {
        orderByCol =
            preferences.getValue(
                DDLFormPortletKeys.DYNAMIC_DATA_LISTS_FORM_ADMIN,
                "view-entries-order-by-col",
                "id");
        orderByType =
            preferences.getValue(
                DDLFormPortletKeys.DYNAMIC_DATA_LISTS_FORM_ADMIN,
                "view-entries-order-by-type",
                "asc");
      }

      OrderByComparator<DDLRecord> orderByComparator =
          getRecordOrderByComparator(orderByCol, orderByType);

      setOrderableHeaders(orderableHeaders);
      setOrderByCol(orderByCol);
      setOrderByType(orderByType);
      setOrderByComparator(orderByComparator);
    } catch (Exception e) {
      _log.error(e, e);
    }
  }
  protected String deletePortletData(
      PortletDataContext portletDataContext, javax.portlet.PortletPreferences portletPreferences)
      throws Exception {

    Group group = _groupLocalService.getGroup(portletDataContext.getGroupId());

    if (!group.isStagedPortlet(portletDataContext.getPortletId())) {
      if (_log.isDebugEnabled()) {
        _log.debug(
            "Do not delete portlet data for "
                + portletDataContext.getPortletId()
                + " because the portlet is not staged");
      }

      return null;
    }

    PortletDataHandler portletDataHandler =
        _portletDataHandlerProvider.provide(
            portletDataContext.getCompanyId(), portletDataContext.getPortletId());

    if (portletDataHandler == null) {
      if (_log.isDebugEnabled()) {
        StringBundler sb = new StringBundler(4);

        sb.append("Do not delete portlet data for ");
        sb.append(portletDataContext.getPortletId());
        sb.append(" because the portlet does not have a ");
        sb.append("PortletDataHandler");

        _log.debug(sb.toString());
      }

      return null;
    }

    if (_log.isDebugEnabled()) {
      _log.debug("Deleting data for " + portletDataContext.getPortletId());
    }

    try {
      portletPreferences =
          portletDataHandler.deleteData(
              portletDataContext, portletDataContext.getPortletId(), portletPreferences);
    } finally {
      portletDataContext.setGroupId(portletDataContext.getScopeGroupId());
    }

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

    return PortletPreferencesFactoryUtil.toXML(portletPreferences);
  }
  @Override
  protected String upgradePreferences(
      long companyId, long ownerId, int ownerType, long plid, String portletId, String xml)
      throws Exception {

    PortletPreferences portletPreferences =
        PortletPreferencesFactoryUtil.fromXML(companyId, ownerId, ownerType, plid, portletId, xml);

    String selectionStyle = portletPreferences.getValue("selection-style", null);

    if (Validator.isNotNull(selectionStyle) && !selectionStyle.equals("dynamic")) {

      String[] assetEntryXmls = portletPreferences.getValues("asset-entry-xml", new String[0]);

      String[] newAssetEntryXmls = getAssetEntryXmls(assetEntryXmls);

      portletPreferences.setValues("asset-entry-xml", newAssetEntryXmls);
    }

    return PortletPreferencesFactoryUtil.toXML(portletPreferences);
  }
  public String getDisplayStyle() {
    if (Validator.isNotNull(_displayStyle)) {
      return _displayStyle;
    }

    PortalPreferences portalPreferences =
        PortletPreferencesFactoryUtil.getPortalPreferences(_request);

    _displayStyle =
        portalPreferences.getValue(SiteBrowserPortletKeys.SITE_BROWSER, "display-style", "list");

    return _displayStyle;
  }
  @Override
  public boolean isShow() {
    PortletPreferences portletSetup =
        PortletPreferencesFactoryUtil.getStrictLayoutPortletSetup(
            themeDisplay.getLayout(), portletDisplay.getId());

    boolean lfrNetvibesShowAddAppLink =
        GetterUtil.getBoolean(portletSetup.getValue("lfrNetvibesShowAddAppLink", StringPool.BLANK));

    if (lfrNetvibesShowAddAppLink) {
      return true;
    }

    return false;
  }
  public String importPortletData(
      PortletDataContext portletDataContext,
      javax.portlet.PortletPreferences portletPreferences,
      Element portletDataElement)
      throws Exception {

    PortletDataHandler portletDataHandler =
        _portletDataHandlerProvider.provide(
            portletDataContext.getCompanyId(), portletDataContext.getPortletId());

    if ((portletDataHandler == null) || portletDataHandler.isDataPortletInstanceLevel()) {

      if (_log.isDebugEnabled()) {
        StringBundler sb = new StringBundler(4);

        sb.append("Do not import portlet data for ");
        sb.append(portletDataContext.getPortletId());
        sb.append(" because the portlet does not have a portlet data ");
        sb.append("handler");

        _log.debug(sb.toString());
      }

      return null;
    }

    if (_log.isDebugEnabled()) {
      _log.debug("Importing data for " + portletDataContext.getPortletId());
    }

    String portletData =
        portletDataContext.getZipEntryAsString(portletDataElement.attributeValue("path"));

    if (Validator.isNull(portletData)) {
      return null;
    }

    portletPreferences =
        portletDataHandler.importData(
            portletDataContext, portletDataContext.getPortletId(), portletPreferences, portletData);

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

    return PortletPreferencesFactoryUtil.toXML(portletPreferences);
  }
  /**
   * @deprecated As of 4.0.0, replaced by {@link #importPortletData(PortletDataContext
   *     portletDataContext, javax.portlet.PortletPreferences portletPreferences, Element
   *     portletDataElement)}
   */
  @Deprecated
  public String importPortletData(
      PortletDataContext portletDataContext,
      PortletPreferences portletPreferences,
      Element portletDataElement)
      throws Exception {

    PortletPreferencesImpl portletPreferencesImpl = null;

    if (portletPreferences != null) {
      portletPreferencesImpl =
          (PortletPreferencesImpl)
              PortletPreferencesFactoryUtil.fromDefaultXML(portletPreferences.getPreferences());
    }

    return importPortletData(portletDataContext, portletPreferencesImpl, portletDataElement);
  }
  public void importPortletPreferences(
      PortletDataContext portletDataContext,
      long companyId,
      long groupId,
      Layout layout,
      Element parentElement,
      boolean preserveScopeLayoutId,
      boolean importPortletArchivedSetups,
      boolean importPortletData,
      boolean importPortletSetup,
      boolean importPortletUserPreferences)
      throws Exception {

    long plid = LayoutConstants.DEFAULT_PLID;
    String scopeType = StringPool.BLANK;
    String scopeLayoutUuid = StringPool.BLANK;

    if (layout != null) {
      plid = layout.getPlid();

      if (preserveScopeLayoutId) {
        javax.portlet.PortletPreferences jxPortletPreferences =
            PortletPreferencesFactoryUtil.getLayoutPortletSetup(
                layout, portletDataContext.getPortletId());

        scopeType = GetterUtil.getString(jxPortletPreferences.getValue("lfrScopeType", null));
        scopeLayoutUuid =
            GetterUtil.getString(jxPortletPreferences.getValue("lfrScopeLayoutUuid", null));

        portletDataContext.setScopeType(scopeType);
        portletDataContext.setScopeLayoutUuid(scopeLayoutUuid);
      }
    }

    List<Element> portletPreferencesElements = parentElement.elements("portlet-preferences");

    for (Element portletPreferencesElement : portletPreferencesElements) {
      String path = portletPreferencesElement.attributeValue("path");

      if (portletDataContext.isPathNotProcessed(path)) {
        String xml = null;

        Element element = null;

        try {
          xml = portletDataContext.getZipEntryAsString(path);

          Document preferencesDocument = SAXReaderUtil.read(xml);

          element = preferencesDocument.getRootElement();
        } catch (DocumentException de) {
          throw new SystemException(de);
        }

        long ownerId = GetterUtil.getLong(element.attributeValue("owner-id"));
        int ownerType = GetterUtil.getInteger(element.attributeValue("owner-type"));

        if ((ownerType == PortletKeys.PREFS_OWNER_TYPE_COMPANY) || !importPortletSetup) {

          continue;
        }

        if ((ownerType == PortletKeys.PREFS_OWNER_TYPE_ARCHIVED) && !importPortletArchivedSetups) {

          continue;
        }

        if ((ownerType == PortletKeys.PREFS_OWNER_TYPE_USER)
            && (ownerId != PortletKeys.PREFS_OWNER_ID_DEFAULT)
            && !importPortletUserPreferences) {

          continue;
        }

        long curPlid = plid;
        String curPortletId = portletDataContext.getPortletId();

        if (ownerType == PortletKeys.PREFS_OWNER_TYPE_GROUP) {
          curPlid = PortletKeys.PREFS_PLID_SHARED;
          curPortletId = portletDataContext.getRootPortletId();
          ownerId = portletDataContext.getScopeGroupId();
        }

        long elementPlid = GetterUtil.getLong(element.attributeValue("plid"));

        if ((ownerType == PortletKeys.PREFS_OWNER_TYPE_LAYOUT)
            && (ownerId != PortletKeys.PREFS_OWNER_ID_DEFAULT)
            && (elementPlid == PortletKeys.PREFS_PLID_SHARED)) {

          curPlid = PortletKeys.PREFS_PLID_SHARED;
          ownerId = portletDataContext.getScopeGroupId();
        }

        if (ownerType == PortletKeys.PREFS_OWNER_TYPE_ARCHIVED) {
          String userUuid = element.attributeValue("archive-user-uuid");

          long userId = portletDataContext.getUserId(userUuid);

          String name = element.attributeValue("archive-name");

          curPortletId = portletDataContext.getRootPortletId();

          PortletItem portletItem =
              _portletItemLocalService.updatePortletItem(
                  userId, groupId, name, curPortletId, PortletPreferences.class.getName());

          curPlid = LayoutConstants.DEFAULT_PLID;
          ownerId = portletItem.getPortletItemId();
        }

        if (ownerType == PortletKeys.PREFS_OWNER_TYPE_USER) {
          String userUuid = element.attributeValue("user-uuid");

          ownerId = portletDataContext.getUserId(userUuid);
        }

        boolean defaultUser = GetterUtil.getBoolean(element.attributeValue("default-user"));

        if (defaultUser) {
          ownerId = _userLocalService.getDefaultUserId(companyId);
        }

        javax.portlet.PortletPreferences jxPortletPreferences =
            PortletPreferencesFactoryUtil.fromXML(
                companyId, ownerId, ownerType, curPlid, curPortletId, xml);

        Element importDataRootElement = portletDataContext.getImportDataRootElement();

        try {
          Element preferenceDataElement = portletPreferencesElement.element("preference-data");

          if (preferenceDataElement != null) {
            portletDataContext.setImportDataRootElement(preferenceDataElement);
          }

          ExportImportPortletPreferencesProcessor exportImportPortletPreferencesProcessor =
              ExportImportPortletPreferencesProcessorRegistryUtil
                  .getExportImportPortletPreferencesProcessor(
                      PortletConstants.getRootPortletId(curPortletId));

          if (exportImportPortletPreferencesProcessor != null) {
            List<Capability> importCapabilities =
                exportImportPortletPreferencesProcessor.getImportCapabilities();

            if (ListUtil.isNotEmpty(importCapabilities)) {
              for (Capability importCapability : importCapabilities) {

                importCapability.process(portletDataContext, jxPortletPreferences);
              }
            }

            exportImportPortletPreferencesProcessor.processImportPortletPreferences(
                portletDataContext, jxPortletPreferences);
          } else {
            PortletDataHandler portletDataHandler =
                _portletDataHandlerProvider.provide(
                    portletDataContext.getCompanyId(), curPortletId);

            if (portletDataHandler != null) {
              jxPortletPreferences =
                  portletDataHandler.processImportPortletPreferences(
                      portletDataContext, curPortletId, jxPortletPreferences);
            }
          }
        } finally {
          portletDataContext.setImportDataRootElement(importDataRootElement);
        }

        updatePortletPreferences(
            portletDataContext,
            ownerId,
            ownerType,
            curPlid,
            curPortletId,
            PortletPreferencesFactoryUtil.toXML(jxPortletPreferences),
            importPortletData);
      }
    }

    if (preserveScopeLayoutId && (layout != null)) {
      javax.portlet.PortletPreferences jxPortletPreferences =
          PortletPreferencesFactoryUtil.getLayoutPortletSetup(
              layout, portletDataContext.getPortletId());

      try {
        jxPortletPreferences.setValue("lfrScopeType", scopeType);
        jxPortletPreferences.setValue("lfrScopeLayoutUuid", scopeLayoutUuid);

        jxPortletPreferences.store();
      } finally {
        portletDataContext.setScopeType(scopeType);
        portletDataContext.setScopeLayoutUuid(scopeLayoutUuid);
      }
    }
  }
  protected void updatePortletPreferences(
      PortletDataContext portletDataContext,
      long ownerId,
      int ownerType,
      long plid,
      String portletId,
      String xml,
      boolean importData)
      throws Exception {

    PortletDataHandler portletDataHandler =
        _portletDataHandlerProvider.provide(portletDataContext.getCompanyId(), portletId);

    // Current portlet preferences

    javax.portlet.PortletPreferences portletPreferences =
        _portletPreferencesLocalService.getPreferences(
            portletDataContext.getCompanyId(), ownerId, ownerType, plid, portletId);

    // New portlet preferences

    javax.portlet.PortletPreferences jxPortletPreferences =
        PortletPreferencesFactoryUtil.fromXML(
            portletDataContext.getCompanyId(), ownerId, ownerType, plid, portletId, xml);

    if (importData || !MergeLayoutPrototypesThreadLocal.isInProgress()) {
      String currentLastPublishDate = portletPreferences.getValue("last-publish-date", null);
      String newLastPublishDate = jxPortletPreferences.getValue("last-publish-date", null);

      if (Validator.isNotNull(currentLastPublishDate)) {
        jxPortletPreferences.setValue("last-publish-date", currentLastPublishDate);
      } else if (Validator.isNotNull(newLastPublishDate)) {
        jxPortletPreferences.reset("last-publish-date");
      }

      _portletPreferencesLocalService.updatePreferences(
          ownerId,
          ownerType,
          plid,
          portletId,
          PortletPreferencesFactoryUtil.toXML(jxPortletPreferences));

      return;
    }

    // Portlet preferences will be updated only when importing data

    String[] dataPortletPreferences = portletDataHandler.getDataPortletPreferences();

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

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

      String scopeLayoutUuid = portletDataContext.getScopeLayoutUuid();
      String scopeType = portletDataContext.getScopeType();

      if (!ArrayUtil.contains(dataPortletPreferences, name)
          || (Validator.isNull(scopeLayoutUuid) && scopeType.equals("company"))) {

        String[] values = jxPortletPreferences.getValues(name, null);

        portletPreferences.setValues(name, values);
      }
    }

    _portletPreferencesLocalService.updatePreferences(
        ownerId, ownerType, plid, portletId, portletPreferences);
  }
Exemple #15
0
  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();
    }
  }