List of usage examples for com.liferay.portal.kernel.util PortalUtil getPathContext
public static String getPathContext()
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();/*from w w w . j av a2 s. c o 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;/* ww w . j a va2 s. co m*/ } 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.content.processor.base.BaseTextExportImportContentProcessor.java
License:Open Source License
protected String replaceImportLayoutReferences(PortletDataContext portletDataContext, String content) throws Exception { String companyPortalURL = StringPool.BLANK; String privateLayoutSetPortalURL = StringPool.BLANK; String publicLayoutSetPortalURL = StringPool.BLANK; Group group = GroupLocalServiceUtil.getGroup(portletDataContext.getScopeGroupId()); Company company = CompanyLocalServiceUtil.getCompany(group.getCompanyId()); LayoutSet privateLayoutSet = group.getPrivateLayoutSet(); LayoutSet publicLayoutSet = group.getPublicLayoutSet(); int serverPort = PortalUtil.getPortalServerPort(false); if (serverPort != -1) { if (Validator.isNotNull(company.getVirtualHostname())) { companyPortalURL = PortalUtil.getPortalURL(company.getVirtualHostname(), serverPort, false); }//from w ww . ja va 2s . c o m if (Validator.isNotNull(privateLayoutSet.getVirtualHostname())) { privateLayoutSetPortalURL = PortalUtil.getPortalURL(privateLayoutSet.getVirtualHostname(), serverPort, false); } if (Validator.isNotNull(publicLayoutSet.getVirtualHostname())) { publicLayoutSetPortalURL = PortalUtil.getPortalURL(publicLayoutSet.getVirtualHostname(), serverPort, false); } } int secureSecurePort = PortalUtil.getPortalServerPort(true); String companySecurePortalURL = StringPool.BLANK; String privateLayoutSetSecurePortalURL = StringPool.BLANK; String publicLayoutSetSecurePortalURL = StringPool.BLANK; if (secureSecurePort != -1) { if (Validator.isNotNull(company.getVirtualHostname())) { companySecurePortalURL = PortalUtil.getPortalURL(company.getVirtualHostname(), secureSecurePort, true); } if (Validator.isNotNull(privateLayoutSet.getVirtualHostname())) { privateLayoutSetSecurePortalURL = PortalUtil.getPortalURL(privateLayoutSet.getVirtualHostname(), secureSecurePort, true); } if (Validator.isNotNull(publicLayoutSet.getVirtualHostname())) { publicLayoutSetSecurePortalURL = PortalUtil.getPortalURL(publicLayoutSet.getVirtualHostname(), secureSecurePort, true); } } StringBundler sb = new StringBundler(3); sb.append(VirtualLayoutConstants.CANONICAL_URL_SEPARATOR); sb.append(GroupConstants.CONTROL_PANEL_FRIENDLY_URL); sb.append(PropsValues.CONTROL_PANEL_LAYOUT_FRIENDLY_URL); content = StringUtil.replace(content, DATA_HANDLER_COMPANY_SECURE_URL, companySecurePortalURL); content = StringUtil.replace(content, DATA_HANDLER_COMPANY_URL, companyPortalURL); // Group friendly URLs while (true) { int groupFriendlyUrlPos = content.indexOf(DATA_HANDLER_GROUP_FRIENDLY_URL); if (groupFriendlyUrlPos == -1) { break; } int groupUuidPos = groupFriendlyUrlPos + DATA_HANDLER_GROUP_FRIENDLY_URL.length(); int endIndex = content.indexOf(StringPool.AT, groupUuidPos + 1); if (endIndex < (groupUuidPos + 1)) { content = StringUtil.replaceFirst(content, DATA_HANDLER_GROUP_FRIENDLY_URL, StringPool.BLANK, groupFriendlyUrlPos); continue; } String groupUuid = content.substring(groupUuidPos + 1, endIndex); Group groupFriendlyUrlGroup = GroupLocalServiceUtil.fetchGroupByUuidAndCompanyId(groupUuid, portletDataContext.getCompanyId()); if ((groupFriendlyUrlGroup == null) || groupUuid.startsWith(StringPool.SLASH)) { content = StringUtil.replaceFirst(content, DATA_HANDLER_GROUP_FRIENDLY_URL, group.getFriendlyURL(), groupFriendlyUrlPos); content = StringUtil.replaceFirst(content, StringPool.AT + groupUuid + StringPool.AT, StringPool.BLANK, content.indexOf(group.getFriendlyURL())); continue; } content = StringUtil.replaceFirst(content, DATA_HANDLER_GROUP_FRIENDLY_URL, StringPool.BLANK, groupFriendlyUrlPos); content = StringUtil.replaceFirst(content, StringPool.AT + groupUuid + StringPool.AT, groupFriendlyUrlGroup.getFriendlyURL(), groupFriendlyUrlPos); } content = StringUtil.replace(content, DATA_HANDLER_PATH_CONTEXT, PortalUtil.getPathContext()); content = StringUtil.replace(content, DATA_HANDLER_PRIVATE_GROUP_SERVLET_MAPPING, PropsValues.LAYOUT_FRIENDLY_URL_PRIVATE_GROUP_SERVLET_MAPPING); content = StringUtil.replace(content, DATA_HANDLER_PRIVATE_LAYOUT_SET_SECURE_URL, privateLayoutSetSecurePortalURL); content = StringUtil.replace(content, DATA_HANDLER_PRIVATE_LAYOUT_SET_URL, privateLayoutSetPortalURL); content = StringUtil.replace(content, DATA_HANDLER_PRIVATE_USER_SERVLET_MAPPING, PropsValues.LAYOUT_FRIENDLY_URL_PRIVATE_USER_SERVLET_MAPPING); content = StringUtil.replace(content, DATA_HANDLER_PUBLIC_LAYOUT_SET_SECURE_URL, publicLayoutSetSecurePortalURL); content = StringUtil.replace(content, DATA_HANDLER_PUBLIC_LAYOUT_SET_URL, publicLayoutSetPortalURL); content = StringUtil.replace(content, DATA_HANDLER_PUBLIC_SERVLET_MAPPING, PropsValues.LAYOUT_FRIENDLY_URL_PUBLIC_SERVLET_MAPPING); content = StringUtil.replace(content, DATA_HANDLER_SITE_ADMIN_URL, sb.toString()); return content; }
From source file:com.liferay.exportimport.content.processor.base.BaseTextExportImportContentProcessor.java
License:Open Source License
protected void validateDLReferences(long groupId, String content) throws PortalException { String portalURL = PortalUtil.getPathContext(); ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext(); if ((serviceContext != null) && (serviceContext.getThemeDisplay() != null)) { ThemeDisplay themeDisplay = serviceContext.getThemeDisplay(); portalURL = PortalUtil.getPortalURL(themeDisplay) + PortalUtil.getPathContext(); }// w w w . j av a 2 s . c om String[] patterns = { portalURL.concat("/c/document_library/get_file?"), portalURL.concat("/documents/"), portalURL.concat("/image/image_gallery?") }; String[] completePatterns = new String[patterns.length]; long[] companyIds = PortalUtil.getCompanyIds(); for (long companyId : companyIds) { Company company = CompanyLocalServiceUtil.getCompany(companyId); String webId = company.getWebId(); int i = 0; for (String pattern : patterns) { completePatterns[i] = webId.concat(pattern); i++; } int beginPos = -1; int endPos = content.length(); while (true) { beginPos = StringUtil.lastIndexOfAny(content, completePatterns, endPos); if (beginPos == -1) { break; } Map<String, String[]> dlReferenceParameters = getDLReferenceParameters(groupId, content, beginPos + portalURL.length() + webId.length(), endPos); FileEntry fileEntry = getFileEntry(dlReferenceParameters); if (fileEntry == null) { throw new NoSuchFileEntryException(); } endPos = beginPos - 1; } } }
From source file:com.liferay.exportimport.content.processor.base.BaseTextExportImportContentProcessor.java
License:Open Source License
protected void validateLayoutReferences(long groupId, String content) throws PortalException { if (!isValidateLayoutReferences()) { return;//w w w .j av a 2s . c o m } Group group = GroupLocalServiceUtil.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 = PortalUtil.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 = LayoutLocalServiceUtil.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 = GroupLocalServiceUtil.fetchFriendlyURLGroup(group.getCompanyId(), groupFriendlyURL); if (urlGroup == null) { throw new NoSuchLayoutException(); } if (pos == -1) { continue; } url = url.substring(pos); layout = LayoutLocalServiceUtil.getFriendlyURLLayout(urlGroup.getGroupId(), privateLayout, url); } }
From source file:com.liferay.exportimport.internal.content.processor.test.DefaultExportImportContentProcessorTest.java
License:Open Source License
@Test public void testInvalidLayoutReferencesCauseNoSuchLayoutException() throws Exception { PortalImpl portalImpl = new PortalImpl() { @Override// w ww .j a v a2s . c o m public String getPathContext() { return "/de"; } }; PortalUtil portalUtil = new PortalUtil(); portalUtil.setPortal(portalImpl); String content = replaceParameters(getContent("invalid_layout_references.txt"), _fileEntry); String[] layoutReferences = StringUtil.split(content, StringPool.NEW_LINE); for (String layoutReference : layoutReferences) { if (!layoutReference.contains(PortalUtil.getPathContext())) { continue; } boolean noSuchLayoutExceptionThrown = false; try { _exportImportContentProcessor.validateContentReferences(_stagingGroup.getGroupId(), layoutReference); } catch (NoSuchLayoutException nsle) { noSuchLayoutExceptionThrown = true; } Assert.assertTrue(layoutReference + " was not flagged as invalid", noSuchLayoutExceptionThrown); } portalUtil.setPortal(new PortalImpl()); }
From source file:com.liferay.exportimport.internal.content.processor.test.DefaultExportImportContentProcessorTest.java
License:Open Source License
protected String replaceParameters(String content, FileEntry fileEntry) { Company company = CompanyLocalServiceUtil.fetchCompany(fileEntry.getCompanyId()); content = replaceMultiLocaleLayoutFriendlyURLs(content); Map<Locale, String> livePublicLayoutFriendlyURLMap = _livePublicLayout.getFriendlyURLMap(); Map<Locale, String> stagingPrivateLayoutFriendlyURLMap = _stagingPrivateLayout.getFriendlyURLMap(); Map<Locale, String> stagingPublicLayoutFriendlyURLMap = _stagingPublicLayout.getFriendlyURLMap(); content = StringUtil.replace(content, new String[] { "[$CANONICAL_URL_SEPARATOR$]", "[$CONTROL_PANEL_FRIENDLY_URL$]", "[$CONTROL_PANEL_LAYOUT_FRIENDLY_URL$]", "[$GROUP_FRIENDLY_URL$]", "[$GROUP_ID$]", "[$IMAGE_ID$]", "[$LIVE_GROUP_FRIENDLY_URL$]", "[$LIVE_GROUP_ID$]", "[$LIVE_PUBLIC_LAYOUT_FRIENDLY_URL$]", "[$NON_DEFAULT_LIVE_PUBLIC_LAYOUT_FRIENDLY_URL$]", "[$NON_DEFAULT_PRIVATE_LAYOUT_FRIENDLY_URL$]", "[$NON_DEFAULT_PUBLIC_LAYOUT_FRIENDLY_URL$]", "[$PATH_CONTEXT$]", "[$PATH_FRIENDLY_URL_PRIVATE_GROUP$]", "[$PATH_FRIENDLY_URL_PRIVATE_USER$]", "[$PATH_FRIENDLY_URL_PUBLIC$]", "[$PRIVATE_LAYOUT_FRIENDLY_URL$]", "[$PUBLIC_LAYOUT_FRIENDLY_URL$]", "[$TITLE$]", "[$UUID$]", "[$WEB_ID$]" }, new String[] { VirtualLayoutConstants.CANONICAL_URL_SEPARATOR, GroupConstants.CONTROL_PANEL_FRIENDLY_URL, PropsValues.CONTROL_PANEL_LAYOUT_FRIENDLY_URL, _stagingGroup.getFriendlyURL(), String.valueOf(fileEntry.getGroupId()), String.valueOf(fileEntry.getFileEntryId()), _liveGroup.getFriendlyURL(), String.valueOf(_liveGroup.getGroupId()), _livePublicLayout.getFriendlyURL(), livePublicLayoutFriendlyURLMap.get(_nonDefaultLocale), stagingPrivateLayoutFriendlyURLMap.get(_nonDefaultLocale), stagingPublicLayoutFriendlyURLMap.get(_nonDefaultLocale), PortalUtil.getPathContext(), PropsValues.LAYOUT_FRIENDLY_URL_PRIVATE_GROUP_SERVLET_MAPPING, PropsValues.LAYOUT_FRIENDLY_URL_PRIVATE_USER_SERVLET_MAPPING, PropsValues.LAYOUT_FRIENDLY_URL_PUBLIC_SERVLET_MAPPING, _stagingPrivateLayout.getFriendlyURL(), _stagingPublicLayout.getFriendlyURL(), fileEntry.getTitle(), fileEntry.getUuid(), company.getWebId() }); if (!content.contains("[$TIMESTAMP")) { return content; }// ww w .ja va 2s . co m return replaceTimestampParameters(content); }
From source file:com.liferay.exportimport.system.event.test.SystemEventTest.java
License:Open Source License
public long doTestRemoteStaging() throws Exception { setPortalProperty("TUNNELING_SERVLET_SHARED_SECRET", "F0E1D2C3B4A5968778695A4B3C2D1E0F"); setPortalProperty("TUNNELING_SERVLET_SHARED_SECRET_HEX", true); _stagingGroup = GroupTestUtil.addGroup(); ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(); serviceContext.setAddGroupPermissions(true); serviceContext.setAddGuestPermissions(true); serviceContext.setScopeGroupId(_stagingGroup.getGroupId()); Map<String, Serializable> attributes = serviceContext.getAttributes(); attributes.putAll(ExportImportConfigurationParameterMapFactory.buildParameterMap()); attributes.put(PortletDataHandlerKeys.PORTLET_CONFIGURATION_ALL, new String[] { Boolean.FALSE.toString() }); attributes.put(PortletDataHandlerKeys.PORTLET_DATA_ALL, new String[] { Boolean.FALSE.toString() }); int serverPort = PortalUtil.getPortalServerPort(false); String pathContext = PortalUtil.getPathContext(); ServiceTestUtil.setUser(TestPropsValues.getUser()); StagingLocalServiceUtil.enableRemoteStaging(TestPropsValues.getUserId(), _stagingGroup, false, false, "localhost", serverPort, pathContext, false, _liveGroup.getGroupId(), serviceContext); _exportImportConfiguration = ExportImportConfigurationFactory .buildDefaultRemotePublishingExportImportConfiguration(TestPropsValues.getUser(), _stagingGroup.getGroupId(), false, "localhost", serverPort, pathContext, false, _liveGroup.getGroupId()); JournalArticle journalArticle = JournalTestUtil.addArticle(_stagingGroup.getGroupId(), JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID); StagingUtil.publishLayouts(TestPropsValues.getUserId(), _exportImportConfiguration); List<JournalArticle> articles = JournalArticleLocalServiceUtil.getArticles(_liveGroup.getGroupId()); Assert.assertEquals(articles.toString(), 1, articles.size()); JournalArticleLocalServiceUtil.deleteArticle(_stagingGroup.getGroupId(), journalArticle.getArticleId(), new ServiceContext()); SystemEvent systemEvent = SystemEventLocalServiceUtil.fetchSystemEvent(_stagingGroup.getGroupId(), ClassNameLocalServiceUtil.getClassNameId(JournalArticle.class), journalArticle.getResourcePrimKey(), SystemEventConstants.TYPE_DELETE); Assert.assertNotNull(systemEvent);/*from w ww.j a va2 s . com*/ GroupUtil.clearCache(); StagingUtil.publishLayouts(TestPropsValues.getUserId(), _exportImportConfiguration); Assert.assertEquals(0, JournalArticleLocalServiceUtil.getArticlesCount(_liveGroup.getGroupId())); journalArticle = articles.get(0); return journalArticle.getResourcePrimKey(); }
From source file:com.liferay.screens.service.impl.ScreensAssetEntryServiceImpl.java
License:Open Source License
protected String getFileEntryPreviewURL(FileEntry fileEntry) { StringBundler sb = new StringBundler(9); sb.append(PortalUtil.getPathContext()); sb.append("/documents/"); sb.append(fileEntry.getRepositoryId()); sb.append(StringPool.SLASH);//w w w . j a v a 2 s . c om sb.append(fileEntry.getFolderId()); sb.append(StringPool.SLASH); sb.append(URLCodec.encodeURL(HtmlUtil.unescape(fileEntry.getTitle()))); sb.append(StringPool.SLASH); sb.append(fileEntry.getUuid()); return sb.toString(); }
From source file:com.liferay.testopensocialoauthconsumer.messaging.TestOpenSocialOAuthConsumerHotDeployMessageListener.java
License:Open Source License
protected String getFileEntryURL(FileEntry fileEntry) { StringBundler sb = new StringBundler(10); sb.append("http://localhost:8080"); sb.append(PortalUtil.getPathContext()); sb.append("/documents/"); sb.append(fileEntry.getRepositoryId()); sb.append(StringPool.SLASH);//from ww w.j av a 2s. com sb.append(fileEntry.getFolderId()); sb.append(StringPool.SLASH); sb.append(HttpUtil.encodeURL(HtmlUtil.unescape(fileEntry.getTitle()))); sb.append(StringPool.SLASH); sb.append(fileEntry.getUuid()); return sb.toString(); }