
com.liferay.fragment.internal.renderer.ContentObjectFragmentRenderer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of com.liferay.fragment.impl
Show all versions of com.liferay.fragment.impl
Liferay Fragment Implementation
The newest version!
/**
* SPDX-FileCopyrightText: (c) 2000 Liferay, Inc. https://liferay.com
* SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
*/
package com.liferay.fragment.internal.renderer;
import com.liferay.fragment.model.FragmentEntryLink;
import com.liferay.fragment.renderer.FragmentRenderer;
import com.liferay.fragment.renderer.FragmentRendererContext;
import com.liferay.fragment.util.configuration.FragmentEntryConfigurationParser;
import com.liferay.info.constants.InfoDisplayWebKeys;
import com.liferay.info.exception.NoSuchInfoItemException;
import com.liferay.info.field.InfoFieldValue;
import com.liferay.info.item.ClassPKInfoItemIdentifier;
import com.liferay.info.item.ERCInfoItemIdentifier;
import com.liferay.info.item.InfoItemDetails;
import com.liferay.info.item.InfoItemFieldValues;
import com.liferay.info.item.InfoItemIdentifier;
import com.liferay.info.item.InfoItemReference;
import com.liferay.info.item.InfoItemServiceRegistry;
import com.liferay.info.item.provider.InfoItemFieldValuesProvider;
import com.liferay.info.item.provider.InfoItemObjectProvider;
import com.liferay.info.item.provider.InfoItemObjectVariationProvider;
import com.liferay.info.item.provider.InfoItemPermissionProvider;
import com.liferay.info.item.provider.filter.InfoItemServiceFilter;
import com.liferay.info.item.renderer.InfoItemRenderer;
import com.liferay.info.item.renderer.InfoItemRendererRegistry;
import com.liferay.info.item.renderer.InfoItemTemplatedRenderer;
import com.liferay.layout.display.page.LayoutDisplayPageProvider;
import com.liferay.layout.display.page.constants.LayoutDisplayPageWebKeys;
import com.liferay.petra.string.StringBundler;
import com.liferay.petra.string.StringPool;
import com.liferay.portal.kernel.feature.flag.FeatureFlagManagerUtil;
import com.liferay.portal.kernel.json.JSONObject;
import com.liferay.portal.kernel.json.JSONUtil;
import com.liferay.portal.kernel.language.Language;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.security.permission.ActionKeys;
import com.liferay.portal.kernel.theme.ThemeDisplay;
import com.liferay.portal.kernel.util.Tuple;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.kernel.util.WebKeys;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
import java.util.List;
import java.util.Locale;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
/**
* @author Jorge Ferrer
*/
@Component(service = FragmentRenderer.class)
public class ContentObjectFragmentRenderer implements FragmentRenderer {
@Override
public String getCollectionKey() {
return "content-display";
}
@Override
public String getConfiguration(
FragmentRendererContext fragmentRendererContext) {
return JSONUtil.put(
"fieldSets",
JSONUtil.putAll(
JSONUtil.put(
"fields",
JSONUtil.putAll(
JSONUtil.put(
"label", "item"
).put(
"name", "itemSelector"
).put(
"type", "itemSelector"
).put(
"typeOptions",
JSONUtil.put("enableSelectTemplate", true)
))
).put(
"label",
_language.format(
fragmentRendererContext.getLocale(), "x-options",
"content-display", true)
))
).toString();
}
@Override
public String getIcon() {
return "web-content";
}
@Override
public String getLabel(Locale locale) {
return _language.get(locale, "content-display");
}
@Override
public boolean hasViewPermission(
FragmentRendererContext fragmentRendererContext,
HttpServletRequest httpServletRequest) {
JSONObject jsonObject = _getFieldValueJSONObject(
fragmentRendererContext);
InfoItemReference infoItemReference =
fragmentRendererContext.getContextInfoItemReference();
if ((infoItemReference == null) &&
((jsonObject == null) || (jsonObject.length() == 0))) {
return true;
}
String className = StringPool.BLANK;
Object displayObject = null;
if (jsonObject != null) {
className = jsonObject.getString("className");
displayObject = _getDisplayObject(
className, jsonObject.getLong("classPK"),
jsonObject.getString("externalReferenceCode"),
httpServletRequest, infoItemReference);
}
else {
displayObject = _getInfoItem(infoItemReference);
}
if (displayObject == null) {
return true;
}
if (Validator.isNull(className) && (infoItemReference != null)) {
className = infoItemReference.getClassName();
}
Tuple tuple = _getTuple(
className, displayObject.getClass(), fragmentRendererContext);
if ((tuple == null) || (tuple.getObject(0) == null) ||
_hasPermission(httpServletRequest, className, displayObject)) {
return true;
}
return false;
}
@Override
public void render(
FragmentRendererContext fragmentRendererContext,
HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) {
JSONObject jsonObject = _getFieldValueJSONObject(
fragmentRendererContext);
InfoItemReference infoItemReference =
fragmentRendererContext.getContextInfoItemReference();
if ((infoItemReference == null) &&
((jsonObject == null) || (jsonObject.length() == 0))) {
if (fragmentRendererContext.isEditMode()) {
FragmentRendererUtil.printPortletMessageInfo(
httpServletRequest, httpServletResponse,
"the-selected-content-will-be-shown-here");
}
return;
}
String className = StringPool.BLANK;
Object displayObject = null;
if (jsonObject != null) {
className = jsonObject.getString("className");
displayObject = _getDisplayObject(
className, jsonObject.getLong("classPK"),
jsonObject.getString("externalReferenceCode"),
httpServletRequest, infoItemReference);
}
else {
displayObject = _getInfoItem(infoItemReference);
}
if (displayObject == null) {
if (fragmentRendererContext.isEditMode()) {
FragmentRendererUtil.printPortletMessageInfo(
httpServletRequest, httpServletResponse,
"the-selected-content-is-no-longer-available.-please-" +
"select-another");
}
return;
}
if (Validator.isNull(className) && (infoItemReference != null)) {
className = infoItemReference.getClassName();
}
Tuple tuple = _getTuple(
className, displayObject.getClass(), fragmentRendererContext);
if ((tuple == null) || (tuple.getObject(0) == null)) {
if (fragmentRendererContext.isEditMode()) {
FragmentRendererUtil.printPortletMessageInfo(
httpServletRequest, httpServletResponse,
"there-are-no-available-renderers-for-the-selected-" +
"content");
}
return;
}
if (!_hasPermission(httpServletRequest, className, displayObject)) {
if (fragmentRendererContext.isEditMode()) {
FragmentRendererUtil.printRestrictedContentMessage(
httpServletRequest, httpServletResponse);
}
return;
}
long classPK = _getClassPK(infoItemReference, jsonObject);
ThemeDisplay themeDisplay =
(ThemeDisplay)httpServletRequest.getAttribute(
WebKeys.THEME_DISPLAY);
if (!FeatureFlagManagerUtil.isEnabled(
themeDisplay.getCompanyId(), "LPD-39437") ||
!fragmentRendererContext.isViewMode() || (classPK <= 0)) {
_render(
displayObject, httpServletRequest, httpServletResponse,
(InfoItemRenderer
© 2015 - 2025 Weber Informatics LLC | Privacy Policy