Skip to content

Instantly share code, notes, and snippets.

@evaldeslacasa
Last active August 29, 2015 14:14
Show Gist options
  • Save evaldeslacasa/86789c54ae7176bef3f6 to your computer and use it in GitHub Desktop.
Save evaldeslacasa/86789c54ae7176bef3f6 to your computer and use it in GitHub Desktop.
Retrieve Web Content article in HTML (Part II) - Liferay 6.1.1 CE. To retrieve the HTML of a web content from Site Scope... but if in the Site Scope is not available...retrieve it from Global Scope
protected String retrieveHTMLContent(ThemeDisplay themeDisplay) throws SystemException, PortalException{
String structureId="MY_STRUCTURE_ID";
String templateId = "MY_TEMPLATE_ID";
Company company = CompanyLocalServiceUtil.getCompanyByMx(PropsUtil.get(PropsKeys.COMPANY_DEFAULT_WEB_ID));
long globalGroupId = company.getGroup().getGroupId();
long groupId = themeDisplay.getLayout().getGroupId();
JournalStructure rememberMe = JournalStructureLocalServiceUtil.getStructure(globalGroupId,structureId);
JournalArticle rememberMeContent;
String articleId;
String content;
try{
// try to retrieve from site scope
rememberMeContent =
JournalArticleLocalServiceUtil.getStructureArticles(groupId, structureId).get(0);
articleId = rememberMeContent.getArticleId();
content = JournalContentUtil.
getContent(groupId, articleId, templateId, themeDisplay.getLocale().toString(), themeDisplay);
} catch ( IndexOutOfBoundsException e) {
// retrieve from global scope
rememberMeContent =
JournalArticleLocalServiceUtil.getStructureArticles(globalGroupId, structureId).get(0);
articleId = rememberMeContent.getArticleId();
content = JournalContentUtil.
getContent(globalGroupId, articleId, templateId, themeDisplay.getLocale().toString(), themeDisplay);
}
return content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment