Example usage for com.liferay.portal.kernel.service LayoutLocalServiceUtil getLayout

List of usage examples for com.liferay.portal.kernel.service LayoutLocalServiceUtil getLayout

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.service LayoutLocalServiceUtil getLayout.

Prototype

public static com.liferay.portal.kernel.model.Layout getLayout(long groupId, boolean privateLayout,
        long layoutId) throws com.liferay.portal.kernel.exception.PortalException 

Source Link

Document

Returns the layout matching the layout ID, group, and privacy; throws a NoSuchLayoutException otherwise.

Usage

From source file:com.liferay.dynamic.data.lists.web.internal.template.DDLDisplayTemplateHelper.java

License:Open Source License

public static String getLayoutFriendlyURL(DDMFormFieldValue recordFieldValue, ThemeDisplay themeDisplay)
        throws PortalException {

    Value value = recordFieldValue.getValue();

    String valueString = value.getString(themeDisplay.getLocale());

    if (Validator.isNull(valueString)) {
        return StringPool.BLANK;
    }//from  w w  w.j  a v a 2 s  . c  o m

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject(valueString);

    long groupId = jsonObject.getLong("groupId");
    boolean privateLayout = jsonObject.getBoolean("privateLayout");
    long layoutId = jsonObject.getLong("layoutId");

    Layout layout = LayoutLocalServiceUtil.getLayout(groupId, privateLayout, layoutId);

    return PortalUtil.getLayoutFriendlyURL(layout, themeDisplay);
}

From source file:com.liferay.exportimport.content.processor.base.BaseTextExportImportContentProcessor.java

License:Open Source License

protected String replaceExportLinksToLayouts(PortletDataContext portletDataContext, StagedModel stagedModel,
        String content) throws Exception {

    List<String> oldLinksToLayout = new ArrayList<>();
    List<String> newLinksToLayout = new ArrayList<>();

    Matcher matcher = exportLinksToLayoutPattern.matcher(content);

    while (matcher.find()) {
        long layoutId = GetterUtil.getLong(matcher.group(1));

        String type = matcher.group(2);

        boolean privateLayout = type.startsWith("private");

        try {// w w  w .j  a  va  2s  . c  o m
            Layout layout = LayoutLocalServiceUtil.getLayout(portletDataContext.getScopeGroupId(),
                    privateLayout, layoutId);

            String oldLinkToLayout = matcher.group(0);

            StringBundler sb = new StringBundler(3);

            sb.append(type);
            sb.append(StringPool.AT);
            sb.append(layout.getPlid());

            String newLinkToLayout = StringUtil.replace(oldLinkToLayout, type, sb.toString());

            oldLinksToLayout.add(oldLinkToLayout);
            newLinksToLayout.add(newLinkToLayout);

            Element entityElement = portletDataContext.getExportDataElement(stagedModel);

            portletDataContext.addReferenceElement(stagedModel, entityElement, layout,
                    PortletDataContext.REFERENCE_TYPE_DEPENDENCY, true);
        } catch (Exception e) {
            if (_log.isDebugEnabled() || _log.isWarnEnabled()) {
                String message = StringBundler.concat("Unable to get layout with ID ", String.valueOf(layoutId),
                        " in group ", String.valueOf(portletDataContext.getScopeGroupId()));

                if (_log.isDebugEnabled()) {
                    _log.debug(message, e);
                } else {
                    _log.warn(message);
                }
            }
        }
    }

    content = StringUtil.replace(content, ArrayUtil.toStringArray(oldLinksToLayout.toArray()),
            ArrayUtil.toStringArray(newLinksToLayout.toArray()));

    return content;
}

From source file:com.liferay.exportimport.internal.background.task.LayoutRemoteStagingBackgroundTaskExecutor.java

License:Open Source License

/**
 * @see com.liferay.portal.lar.ExportImportHelperImpl#getMissingParentLayouts(
 *      Layout, long)//from w  ww  .j  a v  a2s .  co m
 */
protected List<Layout> getMissingRemoteParentLayouts(HttpPrincipal httpPrincipal, Layout layout,
        long remoteGroupId) throws PortalException {

    List<Layout> missingRemoteParentLayouts = new ArrayList<>();

    long parentLayoutId = layout.getParentLayoutId();

    while (parentLayoutId > 0) {
        Layout parentLayout = LayoutLocalServiceUtil.getLayout(layout.getGroupId(), layout.isPrivateLayout(),
                parentLayoutId);

        if (StagingServiceHttp.hasRemoteLayout(httpPrincipal, parentLayout.getUuid(), remoteGroupId,
                parentLayout.getPrivateLayout())) {

            // If one parent is found, all others are assumed to exist

            break;
        } else {
            missingRemoteParentLayouts.add(parentLayout);

            parentLayoutId = parentLayout.getParentLayoutId();
        }
    }

    return missingRemoteParentLayouts;
}

From source file:com.liferay.journal.web.asset.JournalArticleAssetRenderer.java

License:Open Source License

protected String getHitLayoutURL(boolean privateLayout, String noSuchEntryRedirect, ThemeDisplay themeDisplay)
        throws PortalException {

    List<Long> hitLayoutIds = JournalContentSearchLocalServiceUtil.getLayoutIds(_article.getGroupId(),
            privateLayout, _article.getArticleId());

    for (Long hitLayoutId : hitLayoutIds) {
        Layout hitLayout = LayoutLocalServiceUtil.getLayout(_article.getGroupId(), privateLayout,
                hitLayoutId.longValue());

        if (LayoutPermissionUtil.contains(themeDisplay.getPermissionChecker(), hitLayout, ActionKeys.VIEW)) {

            return PortalUtil.getLayoutURL(hitLayout, themeDisplay);
        }/*from  w  w w  .  ja v a2s. c  o  m*/
    }

    return noSuchEntryRedirect;
}