Example usage for com.liferay.portal.kernel.model Group isStaged

List of usage examples for com.liferay.portal.kernel.model Group isStaged

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.model Group isStaged.

Prototype

public boolean isStaged();

Source Link

Usage

From source file:com.liferay.asset.taglib.internal.display.context.InputAssetLinksDisplayContext.java

License:Open Source License

private boolean _isStagedLocally() {
    if (_stagedLocally != null) {
        return _stagedLocally;
    }//from  w  w w  .j  a v  a2 s  . c om

    Group scopeGroup = _themeDisplay.getScopeGroup();

    if (scopeGroup.isStaged() && !scopeGroup.isStagedRemotely()) {
        _stagedLocally = true;
    } else {
        _stagedLocally = false;
    }

    return _stagedLocally;
}

From source file:com.liferay.calendar.test.util.CalendarStagingTestUtil.java

License:Open Source License

public static Calendar getStagingCalendar(Group group, Calendar calendar) throws PortalException {

    if (group.hasStagingGroup()) {
        group = group.getStagingGroup();
    }// ww w.  j av a 2  s .  c o  m

    Assert.assertTrue(group.isStaged());

    return CalendarLocalServiceUtil.fetchCalendarByUuidAndGroupId(calendar.getUuid(), group.getGroupId());
}

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

License:Open Source License

protected String replaceExportDLReferences(PortletDataContext portletDataContext, StagedModel stagedModel,
        String content, boolean exportReferencedContent) throws Exception {

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

    if (group.isStagingGroup()) {
        group = group.getLiveGroup();/* w  ww  . j  a  va2s .  co m*/
    }

    if (group.isStaged() && !group.isStagedRemotely() && !group.isStagedPortlet(PortletKeys.DOCUMENT_LIBRARY)) {

        return content;
    }

    StringBuilder sb = new StringBuilder(content);

    String contextPath = PortalUtil.getPathContext();

    String[] patterns = { contextPath.concat("/c/document_library/get_file?"),
            contextPath.concat("/documents/"), contextPath.concat("/image/image_gallery?") };

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

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

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

        Map<String, String[]> dlReferenceParameters = getDLReferenceParameters(
                portletDataContext.getScopeGroupId(), content, beginPos + contextPath.length(), endPos);

        FileEntry fileEntry = getFileEntry(dlReferenceParameters);

        if (fileEntry == null) {
            endPos = beginPos - 1;

            continue;
        }

        endPos = MapUtil.getInteger(dlReferenceParameters, "endPos");

        try {
            if (exportReferencedContent && !fileEntry.isInTrash()) {
                StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, stagedModel,
                        fileEntry, PortletDataContext.REFERENCE_TYPE_DEPENDENCY);
            } else {
                Element entityElement = portletDataContext.getExportDataElement(stagedModel);

                String referenceType = PortletDataContext.REFERENCE_TYPE_DEPENDENCY;

                if (fileEntry.isInTrash()) {
                    referenceType = PortletDataContext.REFERENCE_TYPE_DEPENDENCY_DISPOSABLE;
                }

                portletDataContext.addReferenceElement(stagedModel, entityElement, fileEntry, referenceType,
                        true);
            }

            String path = ExportImportPathUtil.getModelPath(fileEntry);

            StringBundler exportedReferenceSB = new StringBundler(6);

            exportedReferenceSB.append("[$dl-reference=");
            exportedReferenceSB.append(path);
            exportedReferenceSB.append("$]");

            if (fileEntry.isInTrash()) {
                String originalReference = sb.substring(beginPos, endPos);

                exportedReferenceSB.append("[#dl-reference=");
                exportedReferenceSB.append(originalReference);
                exportedReferenceSB.append("#]");
            }

            sb.replace(beginPos, endPos, exportedReferenceSB.toString());

            int deleteTimestampParametersOffset = beginPos;

            if (fileEntry.isInTrash()) {
                deleteTimestampParametersOffset = sb.indexOf("[#dl-reference=", beginPos);
            }

            deleteTimestampParameters(sb, deleteTimestampParametersOffset);
        } catch (Exception e) {
            if (_log.isDebugEnabled()) {
                _log.debug(e, e);
            } else if (_log.isWarnEnabled()) {
                StringBundler exceptionSB = new StringBundler(6);

                exceptionSB.append("Unable to process file entry ");
                exceptionSB.append(fileEntry.getFileEntryId());
                exceptionSB.append(" for staged model ");
                exceptionSB.append(stagedModel.getModelClassName());
                exceptionSB.append(" with primary key ");
                exceptionSB.append(stagedModel.getPrimaryKeyObj());

                _log.warn(exceptionSB.toString());
            }
        }

        endPos = beginPos - 1;
    }

    return sb.toString();
}

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

License:Open Source License

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

    Group group = GroupLocalServiceUtil.getGroup(portletDataContext.getScopeGroupId());

    StringBuilder sb = new StringBuilder(content);

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

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

    while (true) {
        if (beginPos > -1) {
            endPos = beginPos - 1;//from  w  w w.  j  a  v a  2s.c  om
        }

        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);

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

        StringBundler urlSB = new StringBundler(6);

        try {
            url = replaceExportHostname(portletDataContext.getScopeGroupId(), url, urlSB);

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

            String pathContext = PortalUtil.getPathContext();

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

                urlSB.append(DATA_HANDLER_PATH_CONTEXT);

                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)) {

                    urlSB.append(localePath);

                    url = urlWithoutLocale;
                }
            }

            boolean privateLayout = false;

            if (url.startsWith(PRIVATE_GROUP_SERVLET_MAPPING)) {
                urlSB.append(DATA_HANDLER_PRIVATE_GROUP_SERVLET_MAPPING);

                url = url.substring(PRIVATE_GROUP_SERVLET_MAPPING.length() - 1);

                privateLayout = true;
            } else if (url.startsWith(PRIVATE_USER_SERVLET_MAPPING)) {
                urlSB.append(DATA_HANDLER_PRIVATE_USER_SERVLET_MAPPING);

                url = url.substring(PRIVATE_USER_SERVLET_MAPPING.length() - 1);

                privateLayout = true;
            } else if (url.startsWith(PUBLIC_GROUP_SERVLET_MAPPING)) {
                urlSB.append(DATA_HANDLER_PUBLIC_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();

                LayoutFriendlyURL layoutFriendlyUrl = LayoutFriendlyURLLocalServiceUtil
                        .fetchFirstLayoutFriendlyURL(group.getGroupId(), privateLayout, url);

                if (layoutFriendlyUrl == null) {
                    continue;
                }

                if (privateLayout) {
                    if (group.isUser()) {
                        urlSB.append(DATA_HANDLER_PRIVATE_USER_SERVLET_MAPPING);
                    } else {
                        urlSB.append(DATA_HANDLER_PRIVATE_GROUP_SERVLET_MAPPING);
                    }
                } else {
                    urlSB.append(DATA_HANDLER_PUBLIC_SERVLET_MAPPING);
                }

                urlSB.append(DATA_HANDLER_GROUP_FRIENDLY_URL);

                continue;
            }

            long groupId = group.getGroupId();

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

            if (layout != null) {
                Element entityElement = portletDataContext.getExportDataElement(stagedModel);

                portletDataContext.addReferenceElement(stagedModel, entityElement, layout,
                        PortletDataContext.REFERENCE_TYPE_DEPENDENCY, true);

                continue;
            }

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

            String groupFriendlyURL = url;

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

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

            if (urlGroup == null) {
                throw new NoSuchLayoutException();
            }

            urlSB.append(DATA_HANDLER_GROUP_FRIENDLY_URL);

            // Append the UUID. This information will be used during the
            // import process when looking up the proper group for the link.

            urlSB.append(StringPool.AT);

            if (urlGroup.isStagedRemotely()) {
                String remoteGroupUuid = urlGroup.getTypeSettingsProperty("remoteGroupUUID");

                if (Validator.isNotNull(remoteGroupUuid)) {
                    urlSB.append(remoteGroupUuid);
                }
            } else if (urlGroup.isStaged()) {
                Group liveGroup = urlGroup.getLiveGroup();

                urlSB.append(liveGroup.getUuid());
            } else if (group.getGroupId() == urlGroup.getGroupId()) {
                urlSB.append(urlGroup.getFriendlyURL());
            } else {
                urlSB.append(urlGroup.getUuid());
            }

            urlSB.append(StringPool.AT);

            String siteAdminURL = GroupConstants.CONTROL_PANEL_FRIENDLY_URL
                    + PropsValues.CONTROL_PANEL_LAYOUT_FRIENDLY_URL;

            if (url.endsWith(siteAdminURL)) {
                urlSB.append(DATA_HANDLER_SITE_ADMIN_URL);

                url = StringPool.BLANK;

                continue;
            }

            if (pos == -1) {
                url = StringPool.BLANK;

                continue;
            }

            url = url.substring(pos);

            layout = LayoutLocalServiceUtil.getFriendlyURLLayout(urlGroup.getGroupId(), privateLayout, url);

            Element entityElement = portletDataContext.getExportDataElement(stagedModel);

            portletDataContext.addReferenceElement(stagedModel, entityElement, layout,
                    PortletDataContext.REFERENCE_TYPE_DEPENDENCY, true);
        } catch (Exception e) {
            if (e instanceof NoSuchLayoutException && !isValidateLayoutReferences()) {

                continue;
            }

            if (_log.isDebugEnabled()) {
                _log.debug(e, e);
            } else if (_log.isWarnEnabled()) {
                StringBundler exceptionSB = new StringBundler(6);

                exceptionSB.append("Unable to process layout URL ");
                exceptionSB.append(url);
                exceptionSB.append(" for staged model ");
                exceptionSB.append(stagedModel.getModelClassName());
                exceptionSB.append(" with primary key ");
                exceptionSB.append(stagedModel.getPrimaryKeyObj());

                _log.warn(exceptionSB.toString());
            }
        } finally {
            if (urlSB.length() > 0) {
                urlSB.append(url);

                url = urlSB.toString();
            }

            sb.replace(beginPos + offset, endPos, url);
        }
    }

    return sb.toString();
}

From source file:com.liferay.exportimport.controller.LayoutExportController.java

License:Open Source License

protected File doExport(PortletDataContext portletDataContext) throws Exception {

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

    boolean ignoreLastPublishDate = MapUtil.getBoolean(parameterMap,
            PortletDataHandlerKeys.IGNORE_LAST_PUBLISH_DATE);
    boolean permissions = MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.PERMISSIONS);

    if (_log.isDebugEnabled()) {
        _log.debug("Export permissions " + permissions);
    }/*from www .  ja  va 2  s.com*/

    long companyId = portletDataContext.getCompanyId();

    long defaultUserId = _userLocalService.getDefaultUserId(companyId);

    ServiceContext serviceContext = ServiceContextThreadLocal.popServiceContext();

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

    serviceContext.setCompanyId(companyId);
    serviceContext.setSignedIn(true);

    if (BackgroundTaskThreadLocal.hasBackgroundTask()) {
        BackgroundTask backgroundTask = _backgroundTaskLocalService
                .getBackgroundTask(BackgroundTaskThreadLocal.getBackgroundTaskId());

        serviceContext.setUserId(backgroundTask.getUserId());
    } else {
        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("schema-version", ExportImportConstants.EXPORT_IMPORT_SCHEMA_VERSION);

    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 = _groupLocalService.fetchGroup(portletDataContext.getGroupId());

    String type = "layout-set";

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

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

        headerElement.addAttribute("type-uuid", layoutPrototype.getUuid());
    } else if (group.isLayoutSetPrototype()) {
        type = "layout-set-prototype";

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

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

    headerElement.addAttribute("type", type);
    portletDataContext.setType(type);

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

    portletDataContext.setMissingReferencesElement(missingReferencesElement);

    rootElement.addElement("site-portlets");
    rootElement.addElement("site-services");

    // Export the group

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

    String layoutSetPrototypeUuid = layoutSet.getLayoutSetPrototypeUuid();

    boolean layoutSetPrototypeSettings = MapUtil.getBoolean(portletDataContext.getParameterMap(),
            PortletDataHandlerKeys.LAYOUT_SET_PROTOTYPE_SETTINGS);

    if (!group.isStaged() && Validator.isNotNull(layoutSetPrototypeUuid) && layoutSetPrototypeSettings) {

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

        headerElement.addAttribute("layout-set-prototype-uuid", layoutSetPrototypeUuid);

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

    StagedGroup stagedGroup = ModelAdapterUtil.adapt(group, Group.class, StagedGroup.class);

    StagedModelDataHandlerUtil.exportStagedModel(portletDataContext, stagedGroup);

    // Export other models

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

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

    _deletionSystemEventExporter.exportDeletionSystemEvents(portletDataContext);

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

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

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

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

    ZipWriter zipWriter = portletDataContext.getZipWriter();

    return zipWriter.getFile();
}

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

License:Open Source License

protected String replaceExportDLReferences(PortletDataContext portletDataContext, StagedModel stagedModel,
        String content, boolean exportReferencedContent) throws Exception {

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

    if (group.isStagingGroup()) {
        group = group.getLiveGroup();//from   www .j  ava2 s.  co m
    }

    if (group.isStaged() && !group.isStagedRemotely() && !group.isStagedPortlet(PortletKeys.DOCUMENT_LIBRARY)) {

        return content;
    }

    StringBuilder sb = new StringBuilder(content);

    String contextPath = _portal.getPathContext();

    String[] patterns = { contextPath.concat("/c/document_library/get_file?"),
            contextPath.concat("/documents/"), contextPath.concat("/image/image_gallery?") };

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

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

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

        Map<String, String[]> dlReferenceParameters = getDLReferenceParameters(
                portletDataContext.getScopeGroupId(), content, beginPos + contextPath.length(), endPos);

        FileEntry fileEntry = getFileEntry(dlReferenceParameters);

        if (fileEntry == null) {
            endPos = beginPos - 1;

            continue;
        }

        endPos = MapUtil.getInteger(dlReferenceParameters, "endPos");

        try {
            if (exportReferencedContent && !fileEntry.isInTrash()) {
                StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, stagedModel,
                        fileEntry, PortletDataContext.REFERENCE_TYPE_DEPENDENCY);
            } else {
                Element entityElement = portletDataContext.getExportDataElement(stagedModel);

                String referenceType = PortletDataContext.REFERENCE_TYPE_DEPENDENCY;

                if (fileEntry.isInTrash()) {
                    referenceType = PortletDataContext.REFERENCE_TYPE_DEPENDENCY_DISPOSABLE;
                }

                portletDataContext.addReferenceElement(stagedModel, entityElement, fileEntry, referenceType,
                        true);
            }

            String path = ExportImportPathUtil.getModelPath(fileEntry);

            StringBundler exportedReferenceSB = new StringBundler(6);

            exportedReferenceSB.append("[$dl-reference=");
            exportedReferenceSB.append(path);
            exportedReferenceSB.append("$]");

            if (fileEntry.isInTrash()) {
                String originalReference = sb.substring(beginPos, endPos);

                exportedReferenceSB.append("[#dl-reference=");
                exportedReferenceSB.append(originalReference);
                exportedReferenceSB.append("#]");
            }

            sb.replace(beginPos, endPos, exportedReferenceSB.toString());

            int deleteTimestampParametersOffset = beginPos;

            if (fileEntry.isInTrash()) {
                deleteTimestampParametersOffset = sb.indexOf("[#dl-reference=", beginPos);
            }

            deleteTimestampParameters(sb, deleteTimestampParametersOffset);
        } catch (Exception e) {
            if (_log.isDebugEnabled()) {
                _log.debug(e, e);
            } else if (_log.isWarnEnabled()) {
                StringBundler exceptionSB = new StringBundler(6);

                exceptionSB.append("Unable to process file entry ");
                exceptionSB.append(fileEntry.getFileEntryId());
                exceptionSB.append(" for staged model ");
                exceptionSB.append(stagedModel.getModelClassName());
                exceptionSB.append(" with primary key ");
                exceptionSB.append(stagedModel.getPrimaryKeyObj());

                _log.warn(exceptionSB.toString());
            }
        }

        endPos = beginPos - 1;
    }

    return sb.toString();
}

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

License:Open Source License

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

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

    StringBuilder sb = new StringBuilder(content);

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

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

    while (true) {
        if (beginPos > -1) {
            endPos = beginPos - 1;//from  w w w  .j  a  v a  2  s .  c om
        }

        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);

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

        StringBundler urlSB = new StringBundler(6);

        try {
            url = replaceExportHostname(portletDataContext.getScopeGroupId(), url, urlSB);

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

            String pathContext = _portal.getPathContext();

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

                urlSB.append(_DATA_HANDLER_PATH_CONTEXT);

                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)) {

                    urlSB.append(localePath);

                    url = urlWithoutLocale;
                }
            }

            boolean privateLayout = false;

            if (url.startsWith(_PRIVATE_GROUP_SERVLET_MAPPING)) {
                urlSB.append(_DATA_HANDLER_PRIVATE_GROUP_SERVLET_MAPPING);

                url = url.substring(_PRIVATE_GROUP_SERVLET_MAPPING.length() - 1);

                privateLayout = true;
            } else if (url.startsWith(_PRIVATE_USER_SERVLET_MAPPING)) {
                urlSB.append(_DATA_HANDLER_PRIVATE_USER_SERVLET_MAPPING);

                url = url.substring(_PRIVATE_USER_SERVLET_MAPPING.length() - 1);

                privateLayout = true;
            } else if (url.startsWith(_PUBLIC_GROUP_SERVLET_MAPPING)) {
                urlSB.append(_DATA_HANDLER_PUBLIC_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();

                LayoutFriendlyURL layoutFriendlyUrl = _layoutFriendlyURLLocalService
                        .fetchFirstLayoutFriendlyURL(group.getGroupId(), privateLayout, url);

                if (layoutFriendlyUrl == null) {
                    continue;
                }

                if (privateLayout) {
                    if (group.isUser()) {
                        urlSB.append(_DATA_HANDLER_PRIVATE_USER_SERVLET_MAPPING);
                    } else {
                        urlSB.append(_DATA_HANDLER_PRIVATE_GROUP_SERVLET_MAPPING);
                    }
                } else {
                    urlSB.append(_DATA_HANDLER_PUBLIC_SERVLET_MAPPING);
                }

                urlSB.append(_DATA_HANDLER_GROUP_FRIENDLY_URL);

                continue;
            }

            long groupId = group.getGroupId();

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

            if (layout != null) {
                Element entityElement = portletDataContext.getExportDataElement(stagedModel);

                portletDataContext.addReferenceElement(stagedModel, entityElement, layout,
                        PortletDataContext.REFERENCE_TYPE_DEPENDENCY, true);

                continue;
            }

            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();
            }

            urlSB.append(_DATA_HANDLER_GROUP_FRIENDLY_URL);

            // Append the UUID. This information will be used during the
            // import process when looking up the proper group for the link.

            urlSB.append(StringPool.AT);

            if (urlGroup.isStagedRemotely()) {
                String remoteGroupUuid = urlGroup.getTypeSettingsProperty("remoteGroupUUID");

                if (Validator.isNotNull(remoteGroupUuid)) {
                    urlSB.append(remoteGroupUuid);
                }
            } else if (urlGroup.isStaged()) {
                Group liveGroup = urlGroup.getLiveGroup();

                urlSB.append(liveGroup.getUuid());
            } else if (group.getGroupId() == urlGroup.getGroupId()) {
                urlSB.append(urlGroup.getFriendlyURL());
            } else {
                urlSB.append(urlGroup.getUuid());
            }

            urlSB.append(StringPool.AT);

            String siteAdminURL = GroupConstants.CONTROL_PANEL_FRIENDLY_URL
                    + PropsValues.CONTROL_PANEL_LAYOUT_FRIENDLY_URL;

            if (url.endsWith(siteAdminURL)) {
                urlSB.append(_DATA_HANDLER_SITE_ADMIN_URL);

                url = StringPool.BLANK;

                continue;
            }

            if (pos == -1) {
                url = StringPool.BLANK;

                continue;
            }

            url = url.substring(pos);

            layout = _layoutLocalService.getFriendlyURLLayout(urlGroup.getGroupId(), privateLayout, url);

            Element entityElement = portletDataContext.getExportDataElement(stagedModel);

            portletDataContext.addReferenceElement(stagedModel, entityElement, layout,
                    PortletDataContext.REFERENCE_TYPE_DEPENDENCY, true);
        } catch (Exception e) {
            if (e instanceof NoSuchLayoutException
                    && !_exportImportServiceConfiguration.validateLayoutReferences()) {

                continue;
            }

            if (_log.isDebugEnabled()) {
                _log.debug(e, e);
            } else if (_log.isWarnEnabled()) {
                StringBundler exceptionSB = new StringBundler(6);

                exceptionSB.append("Unable to process layout URL ");
                exceptionSB.append(url);
                exceptionSB.append(" for staged model ");
                exceptionSB.append(stagedModel.getModelClassName());
                exceptionSB.append(" with primary key ");
                exceptionSB.append(stagedModel.getPrimaryKeyObj());

                _log.warn(exceptionSB.toString());
            }
        } finally {
            if (urlSB.length() > 0) {
                urlSB.append(url);

                url = urlSB.toString();
            }

            sb.replace(beginPos + offset, endPos, url);
        }
    }

    return sb.toString();
}

From source file:com.liferay.exportimport.internal.upgrade.v1_0_0.UpgradePublisherRequest.java

License:Open Source License

protected List<Group> getGroups() {
    List<Group> groups = _groupLocalService.getGroups(QueryUtil.ALL_POS, QueryUtil.ALL_POS);

    List<Group> filteredGroups = new ArrayList<>(groups.size());

    for (Group group : groups) {
        if (!group.isStaged() && !group.hasLocalOrRemoteStagingGroup()) {
            continue;
        }//from   www  .  ja va2 s. c om

        filteredGroups.add(group);
    }

    return filteredGroups;
}

From source file:com.liferay.exportimport.lar.ExportImportHelperImpl.java

License:Open Source License

@Override
public void setPortletScope(PortletDataContext portletDataContext, Element portletElement) {

    // Portlet data scope

    String scopeLayoutUuid = GetterUtil.getString(portletElement.attributeValue("scope-layout-uuid"));
    String scopeLayoutType = GetterUtil.getString(portletElement.attributeValue("scope-layout-type"));

    portletDataContext.setScopeLayoutUuid(scopeLayoutUuid);
    portletDataContext.setScopeType(scopeLayoutType);

    // Layout scope

    try {/*from w ww .j a  v  a2  s.  c  o m*/
        Group scopeGroup = null;

        if (scopeLayoutType.equals("company")) {
            scopeGroup = _groupLocalService.getCompanyGroup(portletDataContext.getCompanyId());
        } else if (Validator.isNotNull(scopeLayoutUuid)) {
            Layout scopeLayout = _layoutLocalService.getLayoutByUuidAndGroupId(scopeLayoutUuid,
                    portletDataContext.getGroupId(), portletDataContext.isPrivateLayout());

            scopeGroup = _groupLocalService.checkScopeGroup(scopeLayout, portletDataContext.getUserId(null));

            Group group = scopeLayout.getGroup();

            if (group.isStaged() && !group.isStagedRemotely()) {
                try {
                    boolean privateLayout = GetterUtil
                            .getBoolean(portletElement.attributeValue("private-layout"));

                    Layout oldLayout = _layoutLocalService.getLayoutByUuidAndGroupId(scopeLayoutUuid,
                            portletDataContext.getSourceGroupId(), privateLayout);

                    Group oldScopeGroup = oldLayout.getScopeGroup();

                    if (group.isStagingGroup()) {
                        scopeGroup.setLiveGroupId(oldScopeGroup.getGroupId());

                        _groupLocalService.updateGroup(scopeGroup);
                    } else {
                        oldScopeGroup.setLiveGroupId(scopeGroup.getGroupId());

                        _groupLocalService.updateGroup(oldScopeGroup);
                    }
                } catch (NoSuchLayoutException nsle) {
                    if (_log.isWarnEnabled()) {
                        _log.warn(nsle);
                    }
                }
            }

            if (!ExportImportThreadLocal.isStagingInProcess() && group.isStagingGroup()
                    && !group.isStagedPortlet(portletDataContext.getPortletId())) {

                scopeGroup = group.getLiveGroup();

                Layout scopeLiveLayout = _layoutLocalService.fetchLayoutByUuidAndGroupId(scopeLayoutUuid,
                        group.getLiveGroupId(), portletDataContext.isPrivateLayout());

                if (scopeLiveLayout != null) {
                    scopeGroup = _groupLocalService.checkScopeGroup(scopeLiveLayout,
                            portletDataContext.getUserId(null));
                }
            }
        } else {
            Group group = _groupLocalService.getGroup(portletDataContext.getGroupId());

            if (!ExportImportThreadLocal.isStagingInProcess() && group.isStagingGroup()
                    && !group.isStagedPortlet(portletDataContext.getPortletId())) {

                scopeGroup = group.getLiveGroup();
            }
        }

        if (scopeGroup != null) {
            portletDataContext.setScopeGroupId(scopeGroup.getGroupId());

            Map<Long, Long> groupIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(Group.class);

            long oldScopeGroupId = GetterUtil.getLong(portletElement.attributeValue("scope-group-id"));

            groupIds.put(oldScopeGroupId, scopeGroup.getGroupId());
        }
    } catch (PortalException pe) {

        // LPS-52675

        if (_log.isDebugEnabled()) {
            _log.debug(pe, pe);
        }
    } catch (Exception e) {
        _log.error(e, e);
    }
}

From source file:com.liferay.exportimport.staging.LayoutStagingImpl.java

License:Open Source License

@Override
public boolean isBranchingLayoutSet(Group group, boolean privateLayout) {
    boolean isStagingGroup = false;

    if (group.isStagingGroup() && !group.isStagedRemotely()) {
        isStagingGroup = true;//  w w w .ja va  2  s .c o  m

        group = group.getLiveGroup();
    }

    UnicodeProperties typeSettingsProperties = group.getTypeSettingsProperties();

    if (typeSettingsProperties.isEmpty()) {
        return false;
    }

    boolean branchingEnabled = false;

    if (privateLayout) {
        branchingEnabled = GetterUtil.getBoolean(typeSettingsProperties.getProperty("branchingPrivate"));
    } else {
        branchingEnabled = GetterUtil.getBoolean(typeSettingsProperties.getProperty("branchingPublic"));
    }

    if (!branchingEnabled || !group.isStaged() || (!group.isStagedRemotely() && !isStagingGroup)) {

        return false;
    }

    Group stagingGroup = group;

    if (isStagingGroup) {
        stagingGroup = group.getStagingGroup();
    }

    try {
        _layoutSetBranchLocalService.getMasterLayoutSetBranch(stagingGroup.getGroupId(), privateLayout);

        return true;
    } catch (PortalException pe) {

        // LPS-52675

        if (_log.isDebugEnabled()) {
            _log.debug(pe, pe);
        }

        return false;
    }
}