105 lines
3.8 KiB
Java
105 lines
3.8 KiB
Java
/*
|
|
* Copyright (C) 2020 Christian Pierre MOMON <christian@momon.org>
|
|
*
|
|
* This file is part of StatoolInfos, simple service statistics tool.
|
|
*
|
|
* StatoolInfos is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Affero General Public License as
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
* License, or (at your option) any later version.
|
|
*
|
|
* StatoolInfos is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU Affero General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
* along with StatoolInfos. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
package fr.devinsy.statoolinfos.htmlize;
|
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import fr.devinsy.statoolinfos.core.Categories;
|
|
import fr.devinsy.statoolinfos.core.Category;
|
|
import fr.devinsy.statoolinfos.core.StatoolInfosException;
|
|
import fr.devinsy.xidyn.XidynException;
|
|
import fr.devinsy.xidyn.data.TagDataManager;
|
|
import fr.devinsy.xidyn.presenters.PresenterUtils;
|
|
import fr.devinsy.xidyn.utils.XidynUtils;
|
|
|
|
/**
|
|
* The Class CategoriesView.
|
|
*/
|
|
public class CategoriesView
|
|
{
|
|
private static Logger logger = LoggerFactory.getLogger(CategoriesView.class);
|
|
|
|
public enum Mode
|
|
{
|
|
ALL,
|
|
ICONS_ONLY,
|
|
LABELS_ONLY
|
|
}
|
|
|
|
/**
|
|
* Builds the.
|
|
*
|
|
* @param categories
|
|
* the categories
|
|
* @param mode
|
|
* the mode
|
|
* @return the string
|
|
* @throws StatoolInfosException
|
|
* the statool infos exception
|
|
*/
|
|
public static String build(final Categories categories, final Mode mode) throws StatoolInfosException
|
|
{
|
|
String result;
|
|
|
|
try
|
|
{
|
|
logger.debug("Building categories view.");
|
|
|
|
TagDataManager data = new TagDataManager();
|
|
|
|
int index = 0;
|
|
for (Category category : categories)
|
|
{
|
|
data.setAttribute("category", index, "categoryLink", "href", "category-" + category.getTechnicalName() + ".xhtml");
|
|
|
|
if (mode == Mode.ALL)
|
|
{
|
|
data.setAttribute("category", index, "categoryLink", "title", category.getDescription());
|
|
data.setAttribute("category", index, "categoryLogo", "src", category.getLogoPath());
|
|
data.setEscapedContent("category", index, "categoryName", category.getName());
|
|
}
|
|
else if (mode == Mode.ICONS_ONLY)
|
|
{
|
|
data.setAttribute("category", index, "categoryLink", "title", category.getName());
|
|
data.setAttribute("category", index, "categoryLogo", "src", category.getLogoPath());
|
|
data.setAttribute("category", index, "categoryName", "class", "xid:nodisplay");
|
|
}
|
|
else if (mode == Mode.LABELS_ONLY)
|
|
{
|
|
data.setAttribute("category", index, "categoryLink", "title", category.getDescription());
|
|
data.setAttribute("category", index, "categoryLogo", "class", "xid:nodisplay");
|
|
data.setEscapedContent("category", index, "categoryName", category.getName());
|
|
}
|
|
|
|
index += 1;
|
|
}
|
|
|
|
String page = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/categoriesView.xhtml", data).toString();
|
|
result = XidynUtils.extractBodyContent(page.replaceAll("id=\"[^\"]*\"", ""));
|
|
}
|
|
catch (XidynException exception)
|
|
{
|
|
throw new StatoolInfosException("Error building categories view: " + exception.getMessage(), exception);
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
}
|