Example usage for com.liferay.portal.kernel.exception NoSuchLayoutException NoSuchLayoutException

List of usage examples for com.liferay.portal.kernel.exception NoSuchLayoutException NoSuchLayoutException

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.exception NoSuchLayoutException NoSuchLayoutException.

Prototype

public NoSuchLayoutException(Throwable cause) 

Source Link

Usage

From source file:com.liferay.exportimport.internal.content.processor.LayoutReferencesExportImportContentProcessor.java

License:Open Source License

protected void validateLayoutReferences(long groupId, String content) throws PortalException {

    if (!_exportImportServiceConfiguration.validateLayoutReferences()) {
        return;/*from ww w  . j av  a  2 s . co m*/
    }

    Group group = _groupLocalService.getGroup(groupId);

    String[] patterns = { "href=", "[[" };

    int beginPos = -1;
    int endPos = content.length();
    int offset = 0;

    while (true) {
        if (beginPos > -1) {
            endPos = beginPos - 1;
        }

        beginPos = StringUtil.lastIndexOfAny(content, patterns, endPos);

        if (beginPos == -1) {
            break;
        }

        if (content.startsWith("href=", beginPos)) {
            offset = 5;

            char c = content.charAt(beginPos + offset);

            if ((c == CharPool.APOSTROPHE) || (c == CharPool.QUOTE)) {
                offset++;
            }
        } else if (content.charAt(beginPos) == CharPool.OPEN_BRACKET) {
            offset = 2;
        }

        endPos = StringUtil.indexOfAny(content, _LAYOUT_REFERENCE_STOP_CHARS, beginPos + offset, endPos);

        if (endPos == -1) {
            continue;
        }

        String url = content.substring(beginPos + offset, endPos);

        endPos = url.indexOf(Portal.FRIENDLY_URL_SEPARATOR);

        if (endPos != -1) {
            url = url.substring(0, endPos);
        }

        if (url.endsWith(StringPool.SLASH)) {
            url = url.substring(0, url.length() - 1);
        }

        StringBundler urlSB = new StringBundler(1);

        url = replaceExportHostname(groupId, url, urlSB);

        if (!url.startsWith(StringPool.SLASH)) {
            continue;
        }

        String pathContext = _portal.getPathContext();

        if (pathContext.length() > 1) {
            if (!url.startsWith(pathContext)) {
                continue;
            }

            url = url.substring(pathContext.length());
        }

        if (!url.startsWith(StringPool.SLASH)) {
            continue;
        }

        int pos = url.indexOf(StringPool.SLASH, 1);

        String localePath = StringPool.BLANK;

        Locale locale = null;

        if (pos != -1) {
            localePath = url.substring(0, pos);

            locale = LocaleUtil.fromLanguageId(localePath.substring(1), true, false);
        }

        if (locale != null) {
            String urlWithoutLocale = url.substring(localePath.length());

            if (urlWithoutLocale.startsWith(_PRIVATE_GROUP_SERVLET_MAPPING)
                    || urlWithoutLocale.startsWith(_PRIVATE_USER_SERVLET_MAPPING)
                    || urlWithoutLocale.startsWith(_PUBLIC_GROUP_SERVLET_MAPPING)) {

                url = urlWithoutLocale;
            }
        }

        boolean privateLayout = false;

        if (url.startsWith(_PRIVATE_GROUP_SERVLET_MAPPING)) {
            url = url.substring(_PRIVATE_GROUP_SERVLET_MAPPING.length() - 1);

            privateLayout = true;
        } else if (url.startsWith(_PRIVATE_USER_SERVLET_MAPPING)) {
            url = url.substring(_PRIVATE_USER_SERVLET_MAPPING.length() - 1);

            privateLayout = true;
        } else if (url.startsWith(_PUBLIC_GROUP_SERVLET_MAPPING)) {
            url = url.substring(_PUBLIC_GROUP_SERVLET_MAPPING.length() - 1);
        } else {
            String urlSBString = urlSB.toString();

            LayoutSet layoutSet = null;

            if (urlSBString.contains(_DATA_HANDLER_PUBLIC_LAYOUT_SET_SECURE_URL)
                    || urlSBString.contains(_DATA_HANDLER_PUBLIC_LAYOUT_SET_URL)) {

                layoutSet = group.getPublicLayoutSet();
            } else if (urlSBString.contains(_DATA_HANDLER_PRIVATE_LAYOUT_SET_SECURE_URL)
                    || urlSBString.contains(_DATA_HANDLER_PRIVATE_LAYOUT_SET_URL)) {

                layoutSet = group.getPrivateLayoutSet();
            }

            if (layoutSet == null) {
                continue;
            }

            privateLayout = layoutSet.isPrivateLayout();
        }

        Layout layout = _layoutLocalService.fetchLayoutByFriendlyURL(groupId, privateLayout, url);

        if (layout != null) {
            continue;
        }

        String siteAdminURL = GroupConstants.CONTROL_PANEL_FRIENDLY_URL
                + PropsValues.CONTROL_PANEL_LAYOUT_FRIENDLY_URL;

        if (url.endsWith(VirtualLayoutConstants.CANONICAL_URL_SEPARATOR + siteAdminURL)) {

            url = url.substring(url.indexOf(siteAdminURL));
        }

        pos = url.indexOf(StringPool.SLASH, 1);

        String groupFriendlyURL = url;

        if (pos != -1) {
            groupFriendlyURL = url.substring(0, pos);
        }

        Group urlGroup = _groupLocalService.fetchFriendlyURLGroup(group.getCompanyId(), groupFriendlyURL);

        if (urlGroup == null) {
            throw new NoSuchLayoutException(
                    "Unable validate referenced page because it cannot be " + "found with url: " + url);
        }

        if (pos == -1) {
            continue;
        }

        url = url.substring(pos);

        try {
            layout = _layoutLocalService.getFriendlyURLLayout(urlGroup.getGroupId(), privateLayout, url);
        } catch (NoSuchLayoutException nsle) {
            throw new NoSuchLayoutException("Unable to validate referenced page because the page "
                    + "group cannot be found: " + groupId, nsle);
        }
    }
}

From source file:com.liferay.exportimport.internal.content.processor.LinksToLayoutsExportImportContentProcessor.java

License:Open Source License

protected void validateLinksToLayoutsReferences(String content) throws PortalException {

    Matcher matcher = _exportLinksToLayoutPattern.matcher(content);

    while (matcher.find()) {
        long groupId = GetterUtil.getLong(matcher.group(5));

        String type = matcher.group(2);

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

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

        Layout layout = _layoutLocalService.fetchLayout(groupId, privateLayout, layoutId);

        if (layout == null) {
            StringBundler sb = new StringBundler(8);

            sb.append("Unable to validate referenced page because it ");
            sb.append("cannot be found with the following parameters: ");
            sb.append("groupId ");
            sb.append(groupId);/*from  ww w  .jav  a  2  s. co  m*/
            sb.append(", layoutId ");
            sb.append(layoutId);
            sb.append(", privateLayout ");
            sb.append(privateLayout);

            throw new NoSuchLayoutException(sb.toString());
        }
    }
}

From source file:com.liferay.journal.service.impl.JournalArticleLocalServiceImpl.java

License:Open Source License

protected void validateReferences(long groupId, String ddmStructureKey, String ddmTemplateKey,
        String layoutUuid, boolean smallImage, String smallImageURL, byte[] smallImageBytes, long smallImageId,
        String content) throws PortalException {

    long classNameId = classNameLocalService.getClassNameId(JournalArticle.class.getName());

    if (Validator.isNotNull(ddmStructureKey)) {
        DDMStructure ddmStructure = ddmStructureLocalService.fetchStructure(groupId, classNameId,
                ddmStructureKey, true);//ww  w.  j av a  2 s  . com

        if (ddmStructure == null) {
            throw new NoSuchStructureException();
        }
    }

    classNameId = classNameLocalService.getClassNameId(DDMStructure.class.getName());

    if (Validator.isNotNull(ddmTemplateKey)) {
        DDMTemplate ddmTemplate = ddmTemplateLocalService.fetchTemplate(groupId, classNameId, ddmTemplateKey,
                true);

        if (ddmTemplate == null) {
            throw new NoSuchTemplateException();
        }
    }

    if (Validator.isNotNull(layoutUuid)) {
        Layout layout = JournalUtil.getArticleLayout(layoutUuid, groupId);

        if (layout == null) {
            throw new NoSuchLayoutException(JournalArticleConstants.DISPLAY_PAGE);
        }
    }

    if (smallImage && Validator.isNull(smallImageURL) && ArrayUtil.isEmpty(smallImageBytes)) {

        Image image = imageLocalService.fetchImage(smallImageId);

        if (image == null) {
            throw new NoSuchImageException();
        }
    }

    ExportImportContentProcessor exportImportContentProcessor = ExportImportContentProcessorRegistryUtil
            .getExportImportContentProcessor(JournalArticle.class.getName());

    exportImportContentProcessor.validateContentReferences(groupId, content);
}