use of com.liferay.portal.kernel.model.Layout in project sw360 by eclipse.
the class ChangeLogsPortletUtils method getModerationPortletUrl.
private LiferayPortletURL getModerationPortletUrl(PortletRequest request) {
Portlet portlet = PortletLocalServiceUtil.getPortletById(PortalConstants.MODERATION_PORTLET_NAME);
Optional<Layout> layout = LayoutLocalServiceUtil.getLayouts(portlet.getCompanyId()).stream().filter(l -> ("/moderation").equals(l.getFriendlyURL())).findFirst();
if (layout.isPresent()) {
long plId = layout.get().getPlid();
LiferayPortletURL modUrl = PortletURLFactoryUtil.create(request, PortalConstants.MODERATION_PORTLET_NAME, plId, PortletRequest.RENDER_PHASE);
modUrl.setParameter(PortalConstants.PAGENAME, PortalConstants.PAGENAME_EDIT);
return modUrl;
}
return null;
}
use of com.liferay.portal.kernel.model.Layout in project liferay-blade-samples by liferay.
the class HelloSoyViewMVCRenderCommand method render.
@Override
public String render(RenderRequest renderRequest, RenderResponse renderResponse) {
Template template = (Template) renderRequest.getAttribute(WebKeys.TEMPLATE);
ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
List<Layout> layouts = themeDisplay.getLayouts();
Stream<Layout> layoutsStream = layouts.stream();
template.put("layouts", layoutsStream.map(layout -> new HashMap<String, String>() {
{
put("friendlyURL", layout.getFriendlyURL());
put("nameCurrentValue", layout.getNameCurrentValue());
}
}).collect(Collectors.toList()));
PortletURL navigationURL = renderResponse.createRenderURL();
navigationURL.setParameter("mvcRenderCommandName", "Navigation");
template.put("navigationURL", navigationURL.toString());
template.put("releaseInfo", ReleaseInfo.getReleaseInfo());
return "View";
}
use of com.liferay.portal.kernel.model.Layout in project liferay-db-setup-core by ableneo.
the class ResolverUtil method lookupPageIdWithFriendlyUrl.
public static String lookupPageIdWithFriendlyUrl(final String content, final String locationHint, final long groupId, final long company, final boolean isPrivate, final IdMode mode) {
String contentCopy = content;
String lookUp = PAGE_ID_BY_FRIENDLY_URL;
if (isPrivate) {
lookUp = lookUp.replace("%%PTYPE%%", "PRIV");
} else {
lookUp = lookUp.replace("%%PTYPE%%", "PUB");
}
switch(mode) {
case ID:
lookUp = lookUp.replace(LAYOUTID, "PLID");
break;
case PLID:
lookUp = lookUp.replace(LAYOUTID, "ID");
break;
case UUID:
lookUp = lookUp.replace(LAYOUTID, "UUID");
break;
}
int pos = contentCopy.indexOf(lookUp);
while (pos > -1) {
int pos2 = contentCopy.indexOf(CLOSING_TAG, pos);
if (pos2 < 0) {
LOG.error(String.format("No closing Tag, pos %1$s for %2$s", pos, locationHint));
break;
} else {
// by default the referred file is looked up in current site.
long siteGroupId = groupId;
String fUrl = contentCopy.substring(pos + lookUp.length(), pos2).trim();
// check for the reference to another site
String[] refSegs = ResolverUtil.separateSiteRef(fUrl);
if (!refSegs[0].equals("")) {
siteGroupId = ResolverUtil.getSiteGroupIdByName(refSegs[0], company, locationHint);
fUrl = refSegs[1];
}
String pageId = "NOT FOUND";
Layout l = null;
try {
l = LayoutLocalServiceUtil.getFriendlyURLLayout(siteGroupId, isPrivate, fUrl);
} catch (PortalException | SystemException e) {
LOG.error(e);
}
if (l == null) {
LOG.error(String.format("Referred page %1$s is not found .", fUrl));
contentCopy = contentCopy.substring(0, pos) + " PAGE NOT FOUND!! " + contentCopy.substring(pos2 + CLOSING_TAG.length(), contentCopy.length());
} else {
switch(mode) {
case ID:
pageId = Long.toString(l.getLayoutId());
break;
case PLID:
pageId = Long.toString(l.getPlid());
break;
case UUID:
pageId = l.getUuid();
break;
}
contentCopy = contentCopy.substring(0, pos) + pageId + contentCopy.substring(pos2 + CLOSING_TAG.length(), contentCopy.length());
}
}
pos = contentCopy.indexOf(lookUp, pos + 1);
}
//
return contentCopy;
}
use of com.liferay.portal.kernel.model.Layout in project liferay-db-setup-core by ableneo.
the class SetupPages method updateLinkPage.
private static void updateLinkPage(final PageType page, final long groupId) {
try {
Layout layout = LayoutLocalServiceUtil.getFriendlyURLLayout(groupId, false, page.getFriendlyUrl());
if (layout.getLayoutType().getTypeSettingsProperties().get("url") == null) {
LOG.error("Could not update link page " + page.getFriendlyUrl() + " with link to url" + " " + page.getLinkToUrl() + " because page is not a link type page! " + " Maybe it has been imported before as non link type page. Please " + "delete it and rerun!");
} else {
UnicodeProperties props = layout.getTypeSettingsProperties();
props.put("url", page.getLinkToUrl());
layout.setTypeSettingsProperties(props);
layout.setHidden(page.isHidden());
LayoutLocalServiceUtil.updateLayout(layout.getGroupId(), layout.isPrivateLayout(), layout.getLayoutId(), layout.getTypeSettings());
}
} catch (PortalException | SystemException e) {
LOG.error(String.format("Could not update link page %1$s with link to url %2$s", page.getFriendlyUrl(), page.getLinkToUrl()), e);
}
}
use of com.liferay.portal.kernel.model.Layout in project liferay-db-setup-core by ableneo.
the class SetupPages method setupPageTemplates.
/**
* Set the page templates up. As this is heavily based on page (layout).
*
* @param pageTemplates The page template definitions that are imported.
*/
public static void setupPageTemplates(final PageTemplates pageTemplates) {
try {
for (PageTemplate pageTemplate : pageTemplates.getPageTemplate()) {
String name = pageTemplate.getName();
if (name != null) {
LayoutPrototype lp;
DynamicQuery dq = LayoutPrototypeLocalServiceUtil.dynamicQuery().add(PropertyFactoryUtil.forName("name").like("%" + name + "%"));
List<LayoutPrototype> listLayoutPrototype = LayoutPrototypeLocalServiceUtil.dynamicQuery(dq);
long groupId = SetupConfigurationThreadLocal.getRunInGroupId();
long userid = SetupConfigurationThreadLocal.getRunAsUserId();
long company = SetupConfigurationThreadLocal.getRunInCompanyId();
if (listLayoutPrototype != null && !listLayoutPrototype.isEmpty()) {
lp = listLayoutPrototype.get(0);
} else {
Map<Locale, String> titleMap = TranslationMapUtil.getTranslationMap(pageTemplate.getTitleTranslation(), groupId, name, String.format(" Page template %1$s", name));
Map<Locale, String> nameMap = TranslationMapUtil.getTranslationMap(pageTemplate.getTitleTranslation(), groupId, name, String.format(" Page template %1$s", name));
lp = LayoutPrototypeLocalServiceUtil.addLayoutPrototype(userid, company, titleMap, nameMap, true, new ServiceContext());
}
if (lp != null) {
Layout layout = lp.getLayout();
if (pageTemplate.getPage() != null) {
PageType page = pageTemplate.getPage();
if (page.getFriendlyUrl() != null && !page.getFriendlyUrl().equals("")) {
LOG.error(String.format("The page of page template %1$s may not have a friendly URL! Will ignore it!", name));
}
setupLiferayPage(layout, page, null, null, groupId, false, company, userid, name);
}
} else {
LOG.error(String.format("Could not create or find the page template %1$s", name));
}
}
}
} catch (PortalException | SystemException e) {
LOG.error("Problem during creating page templates ", e);
}
}
Aggregations