Several bugfixes for Freemarker Libs
parent
2ef2de7d50
commit
9e466cf273
|
|
@ -72,13 +72,13 @@ public class CategoryTreeComponentRenderer
|
||||||
|
|
||||||
if (!parameters.containsKey(PARAMETER_CATEGORY)) {
|
if (!parameters.containsKey(PARAMETER_CATEGORY)) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"The parameters map passed to this GreetingItem component does "
|
"The parameters map passed to this CategoryTree component does "
|
||||||
+ "not include the parameter \"category\"");
|
+ "not include the parameter \"category\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(parameters.get(PARAMETER_CATEGORY) instanceof Category)) {
|
if (!(parameters.get(PARAMETER_CATEGORY) instanceof Category)) {
|
||||||
throw new IllegalArgumentException(String
|
throw new IllegalArgumentException(String
|
||||||
.format("The parameters map passed to this GreetingItem "
|
.format("The parameters map passed to this CategoryTree "
|
||||||
+ "component contains the parameter \"category\", but the "
|
+ "component contains the parameter \"category\", but the "
|
||||||
+ "parameter is not of type \"%s\" but of type \"%s\".",
|
+ "parameter is not of type \"%s\" but of type \"%s\".",
|
||||||
Category.class.getName(),
|
Category.class.getName(),
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@
|
||||||
*/
|
*/
|
||||||
package org.librecms.pages;
|
package org.librecms.pages;
|
||||||
|
|
||||||
import org.libreccm.categorization.CategoryManager;
|
import org.libreccm.categorization.Category;
|
||||||
import org.libreccm.pagemodel.AbstractPageRenderer;
|
import org.libreccm.pagemodel.AbstractPageRenderer;
|
||||||
import org.libreccm.pagemodel.PageRenderer;
|
import org.libreccm.pagemodel.PageRenderer;
|
||||||
|
|
||||||
|
|
@ -26,7 +26,6 @@ import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of {@link PageRenderer} for CMS pages.
|
* Implementation of {@link PageRenderer} for CMS pages.
|
||||||
|
|
@ -46,6 +45,12 @@ public class CmsPageRenderer extends AbstractPageRenderer {
|
||||||
PagesRouter.SITE_INFO, parameters.get(PagesRouter.SITE_INFO)
|
PagesRouter.SITE_INFO, parameters.get(PagesRouter.SITE_INFO)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (parameters.containsKey(PagesRouter.PAGE_PATH)) {
|
||||||
|
result.put(
|
||||||
|
PagesRouter.PAGE_PATH, parameters.get(PagesRouter.PAGE_PATH)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ import com.fasterxml.jackson.databind.SerializationFeature;
|
||||||
import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule;
|
import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule;
|
||||||
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
||||||
import org.libreccm.categorization.Category;
|
import org.libreccm.categorization.Category;
|
||||||
|
import org.libreccm.categorization.CategoryManager;
|
||||||
import org.libreccm.categorization.CategoryRepository;
|
import org.libreccm.categorization.CategoryRepository;
|
||||||
import org.libreccm.configuration.ConfigurationManager;
|
import org.libreccm.configuration.ConfigurationManager;
|
||||||
import org.libreccm.l10n.GlobalizationHelper;
|
import org.libreccm.l10n.GlobalizationHelper;
|
||||||
|
|
@ -43,6 +44,7 @@ import java.net.URI;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
@ -65,6 +67,7 @@ import javax.ws.rs.core.Context;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import javax.ws.rs.core.UriInfo;
|
import javax.ws.rs.core.UriInfo;
|
||||||
|
|
||||||
|
import static org.apache.logging.log4j.ThreadContext.*;
|
||||||
import static org.librecms.pages.PagesConstants.*;
|
import static org.librecms.pages.PagesConstants.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -76,6 +79,12 @@ import static org.librecms.pages.PagesConstants.*;
|
||||||
@Path("/")
|
@Path("/")
|
||||||
public class PagesRouter {
|
public class PagesRouter {
|
||||||
|
|
||||||
|
protected static final String PAGE_PATH = "pagePath";
|
||||||
|
|
||||||
|
protected static final String PAGE_PATH_CATEGORY_NAME = "categoryName";
|
||||||
|
|
||||||
|
protected static final String PAGE_PATH_CATEGORY_TITLE = "categoryTitle";
|
||||||
|
|
||||||
protected static final String SITE_INFO = "siteInfo";
|
protected static final String SITE_INFO = "siteInfo";
|
||||||
|
|
||||||
protected static final String SITE_INFO_NAME = "name";
|
protected static final String SITE_INFO_NAME = "name";
|
||||||
|
|
@ -86,6 +95,9 @@ public class PagesRouter {
|
||||||
|
|
||||||
protected static final String SITE_INFO_LANGS = "supportedLanguages";
|
protected static final String SITE_INFO_LANGS = "supportedLanguages";
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private CategoryManager categoryManager;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private CategoryRepository categoryRepo;
|
private CategoryRepository categoryRepo;
|
||||||
|
|
||||||
|
|
@ -673,6 +685,7 @@ public class PagesRouter {
|
||||||
|
|
||||||
globalizationHelper.setSelectedLocale(locale);
|
globalizationHelper.setSelectedLocale(locale);
|
||||||
|
|
||||||
|
parameters.put(PAGE_PATH, buildPageCategoriesPath(category, locale));
|
||||||
parameters.put(PARAMETER_CATEGORY, category);
|
parameters.put(PARAMETER_CATEGORY, category);
|
||||||
return pageManager.findPageForCategory(category);
|
return pageManager.findPageForCategory(category);
|
||||||
}
|
}
|
||||||
|
|
@ -754,6 +767,30 @@ public class PagesRouter {
|
||||||
return buildPage(pageModel, parameters);
|
return buildPage(pageModel, parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<Map<String, Object>> buildPageCategoriesPath(
|
||||||
|
final Category category, Locale language
|
||||||
|
) {
|
||||||
|
final List<Category> categoriesInPath = categoryManager
|
||||||
|
.getCategoriesInPath(category);
|
||||||
|
return categoriesInPath
|
||||||
|
.stream()
|
||||||
|
.map(cat -> buildPathCategoriesPathEntry(category, language))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, Object> buildPathCategoriesPathEntry(
|
||||||
|
final Category category, Locale language
|
||||||
|
) {
|
||||||
|
|
||||||
|
final Map<String, Object> result = new HashMap<>();
|
||||||
|
result.put(PAGE_PATH_CATEGORY_NAME, category.getName());
|
||||||
|
result.put(
|
||||||
|
PAGE_PATH_CATEGORY_TITLE, category.getTitle().getValue(language)
|
||||||
|
);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse the value of the {@code preview} query parameter.
|
* Parse the value of the {@code preview} query parameter.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@
|
||||||
<#--
|
<#--
|
||||||
Gets the path of the current page.
|
Gets the path of the current page.
|
||||||
|
|
||||||
@return A list of names (URL stubs/slugs) of all categories in the
|
@return A list of categories of all categories in the
|
||||||
path of the current page.
|
path of the current page.
|
||||||
-->
|
-->
|
||||||
<#function getPagePath>
|
<#function getPagePath>
|
||||||
|
|
@ -34,7 +34,13 @@
|
||||||
@return The currently selected category.
|
@return The currently selected category.
|
||||||
-->
|
-->
|
||||||
<#function getSelectedCategory>
|
<#function getSelectedCategory>
|
||||||
<#return getPathPath()?last>
|
<#if isRootPage()>
|
||||||
|
<#return null>
|
||||||
|
<#elseif getPagePath()??>
|
||||||
|
<#return getPathPath()?last>
|
||||||
|
<#else>
|
||||||
|
<#return null>
|
||||||
|
</#if>
|
||||||
</#function>
|
</#function>
|
||||||
|
|
||||||
<#--doc
|
<#--doc
|
||||||
|
|
@ -91,7 +97,7 @@
|
||||||
@return The URL of the root category of the navigation system with the
|
@return The URL of the root category of the navigation system with the
|
||||||
provided ID.
|
provided ID.
|
||||||
-->
|
-->
|
||||||
<#function getNavigationRootUrl navigationId="categoryMenu" containerId="container">
|
<#function getNavigationRootUrl navigationId="categoryTree" containerId="container">
|
||||||
<#return [container][navigationId].url>
|
<#return [container][navigationId].url>
|
||||||
</#function>
|
</#function>
|
||||||
|
|
||||||
|
|
@ -151,5 +157,5 @@
|
||||||
@return The model of the index item.
|
@return The model of the index item.
|
||||||
-->
|
-->
|
||||||
<#function getGreetingItem containerId="container">
|
<#function getGreetingItem containerId="container">
|
||||||
<#return [container].greetingItem>
|
<#return eval(containerId).greetingItem>
|
||||||
</#function>
|
</#function>
|
||||||
|
|
@ -31,7 +31,7 @@
|
||||||
@return The host name of the site.
|
@return The host name of the site.
|
||||||
-->
|
-->
|
||||||
<#function getSiteHostName>
|
<#function getSiteHostName>
|
||||||
<#return siteInfo.hostName>
|
<#return siteInfo.host>
|
||||||
</#function>
|
</#function>
|
||||||
|
|
||||||
<#--doc
|
<#--doc
|
||||||
|
|
@ -40,7 +40,16 @@
|
||||||
@return The name of the site.
|
@return The name of the site.
|
||||||
-->
|
-->
|
||||||
<#function getSiteName>
|
<#function getSiteName>
|
||||||
<#return siteInfo.siteName>
|
<#return siteInfo.name>
|
||||||
|
</#function>
|
||||||
|
|
||||||
|
<#--doc
|
||||||
|
Get the domain of the site.
|
||||||
|
|
||||||
|
@return The name of the site.
|
||||||
|
-->
|
||||||
|
<#function getSiteDomain>
|
||||||
|
<#return siteInfo.domain>
|
||||||
</#function>
|
</#function>
|
||||||
|
|
||||||
<#--doc
|
<#--doc
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,7 @@ import java.util.UUID;
|
||||||
*/
|
*/
|
||||||
@RequestScoped
|
@RequestScoped
|
||||||
public class CategoryManager implements Serializable {
|
public class CategoryManager implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = -3354487547729008811L;
|
private static final long serialVersionUID = -3354487547729008811L;
|
||||||
|
|
||||||
private static final Logger LOGGER = LogManager.getLogger(
|
private static final Logger LOGGER = LogManager.getLogger(
|
||||||
|
|
@ -865,6 +866,37 @@ public class CategoryManager implements Serializable {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a list of all categories in the path to the provided category.
|
||||||
|
*
|
||||||
|
* The first entry in the list is the root category, the last entry is the
|
||||||
|
* provided category.
|
||||||
|
*
|
||||||
|
* @param ofCategory The category for whic the tree is generated.
|
||||||
|
*
|
||||||
|
* @return A list of a categories in the path of the provided category.
|
||||||
|
*/
|
||||||
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
public List<Category> getCategoriesInPath(final Category ofCategory) {
|
||||||
|
|
||||||
|
Objects.requireNonNull(ofCategory);
|
||||||
|
|
||||||
|
List<Category> categories = new ArrayList<>();
|
||||||
|
|
||||||
|
Category current = categoryRepo.findById(ofCategory.getObjectId())
|
||||||
|
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
||||||
|
"No category with ID %d in the database. Where did that ID come from?",
|
||||||
|
ofCategory.getObjectId())));
|
||||||
|
|
||||||
|
while(current.getParentCategory() != null) {
|
||||||
|
categories.add(current);
|
||||||
|
current = current.getParentCategory();
|
||||||
|
}
|
||||||
|
Collections.reverse(categories);
|
||||||
|
|
||||||
|
return categories;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the path of a category as string. The path of a category are the
|
* Returns the path of a category as string. The path of a category are the
|
||||||
* names of all its parent categories and the category joined together,
|
* names of all its parent categories and the category joined together,
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,8 @@
|
||||||
<#import "/ccm-core/user-banner.ftl" as UserBanner>
|
<#import "/ccm-core/user-banner.ftl" as UserBanner>
|
||||||
|
<#import "/language.ftl" as Language>
|
||||||
|
<#import "/utils.ftl" as Utils>
|
||||||
|
<#import "/ccm-cms/pages.ftl" as Pages>
|
||||||
|
<#import "/ccm-navigation/navigation.ftl" as Navigation>
|
||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
|
|
@ -7,7 +11,7 @@
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>FTL Libs Test</h1>
|
<h1>FTL Libs Test</h1>
|
||||||
<h2>user-banner.ftl</h2>
|
<h2>ccm-core/user-banner.ftl as UserBanner</h2>
|
||||||
<dl>
|
<dl>
|
||||||
<div>
|
<div>
|
||||||
<dt>UserBanner.getGreeting</dt>
|
<dt>UserBanner.getGreeting</dt>
|
||||||
|
|
@ -54,5 +58,126 @@
|
||||||
<dd>${UserBanner.getUserFamilyName()}</dd>
|
<dd>${UserBanner.getUserFamilyName()}</dd>
|
||||||
</div>
|
</div>
|
||||||
</dl>
|
</dl>
|
||||||
|
<h2>language.ftl as Language</h2>
|
||||||
|
<dl>
|
||||||
|
<div>
|
||||||
|
<dt>Language.getSupportedLanguages</dt>
|
||||||
|
<dd>
|
||||||
|
<#list Language.getSupportedLanguages()>
|
||||||
|
<ul>
|
||||||
|
<#items as lang>
|
||||||
|
<li>${lang}</li>
|
||||||
|
</#items>
|
||||||
|
</ul>
|
||||||
|
<#else>
|
||||||
|
No supported languages
|
||||||
|
</#list>
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<dt>Language.getSupportedLanguages</dt>
|
||||||
|
<dd>
|
||||||
|
<#list Language.getAvailableLanguages()>
|
||||||
|
<ul>
|
||||||
|
<#items as lang>
|
||||||
|
<li>${lang}</li>
|
||||||
|
</#items>
|
||||||
|
</ul>
|
||||||
|
<#else>
|
||||||
|
No languages available
|
||||||
|
</#list>
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
</dt>
|
||||||
|
<h2>utils.ftl as Utils</h2>
|
||||||
|
<dl>
|
||||||
|
<div>
|
||||||
|
<dt>Utils.getPageApplication()</dt>
|
||||||
|
<dd>${Utils.getPageApplication()}</dd>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<dt>Utils.getPageTitle()</dt>
|
||||||
|
<dd>${Utils.getPageTitle()}</dd>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<dt>Utils.getSiteHostName()</dt>
|
||||||
|
<dd>${Utils.getSiteHostName()}</dd>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<dt>Utils.getSiteHDomain()</dt>
|
||||||
|
<dd>${Utils.getSiteDomain()}</dd>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<dt>Utils.getSiteName()</dt>
|
||||||
|
<dd>${Utils.getSiteName()!""}</dd>
|
||||||
|
</div>
|
||||||
|
</dl>
|
||||||
|
<h2>ccm-cms/pages.ftl as Pages</h2>
|
||||||
|
<dl>
|
||||||
|
<div>
|
||||||
|
<dt>Pages.getCategoryPath()</dt>
|
||||||
|
<dd>
|
||||||
|
Path length: ${Pages.getCategoryPath()?size}
|
||||||
|
<#list Pages.getCategoryPath()>
|
||||||
|
<ul>
|
||||||
|
<#items as cat>
|
||||||
|
<li>
|
||||||
|
<dl>
|
||||||
|
<dt>Name</dt>
|
||||||
|
<dd>${cat.categoryName}</dd>
|
||||||
|
<dt>Title</dt>
|
||||||
|
<dd>${cat.categoryTitle}</dd>
|
||||||
|
</dl>
|
||||||
|
</li>
|
||||||
|
</#items>
|
||||||
|
</ul>
|
||||||
|
</#list>
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<dt>Pages.getPagePath()</dt>
|
||||||
|
<dd>
|
||||||
|
Path length: ${Pages.getPagePath()?size}
|
||||||
|
<#list Pages.getPagePath()>
|
||||||
|
<ul>
|
||||||
|
<#items as cat>
|
||||||
|
<li>
|
||||||
|
<dl>
|
||||||
|
<dt>Name</dt>
|
||||||
|
<dd>${cat.categoryName}</dd>
|
||||||
|
<dt>Title</dt>
|
||||||
|
<dd>${cat.categoryTitle}</dd>
|
||||||
|
</dl>
|
||||||
|
</li>
|
||||||
|
</#items>
|
||||||
|
</ul>
|
||||||
|
</#list>
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<dt>Pages.isRootPage()</dt>
|
||||||
|
<dd>${Pages.isRootPage()?c}</dd>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<dt>Pages.getSelectedCategory()</dt>
|
||||||
|
<dd>
|
||||||
|
<#if Pages.getSelectedCategory()??>
|
||||||
|
${Pages.getSelectedCategory()}
|
||||||
|
<#else>
|
||||||
|
No category selected.
|
||||||
|
</#if>
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
</dl>
|
||||||
|
<h2>ccm-navigation/navigation.ftl as Navigation</h2>
|
||||||
|
<p>
|
||||||
|
Note: Deprecated, replaced by ccm-cms/pages.ftl
|
||||||
|
</p>
|
||||||
|
<dl>
|
||||||
|
<div>
|
||||||
|
<dt>Navigation.getCategoryPath</dt>
|
||||||
|
<dd>${Navigation.getCategoryPath()}</dd>
|
||||||
|
</div>
|
||||||
|
</dl>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
Loading…
Reference in New Issue