statoolinfosweb/src/fr/devinsy/statoolinfos/htmlize/FederationHeaderView.java

140 lines
6.1 KiB
Java
Raw Normal View History

2021-06-03 03:05:12 +02:00
/*
* Copyright (C) 2020-2021 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 java.io.IOException;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.devinsy.statoolinfos.checker.PropertyChecks;
import fr.devinsy.statoolinfos.core.Federation;
import fr.devinsy.statoolinfos.core.StatoolInfosException;
import fr.devinsy.xidyn.XidynException;
import fr.devinsy.xidyn.data.DisplayMode;
import fr.devinsy.xidyn.data.TagDataManager;
import fr.devinsy.xidyn.presenters.PresenterUtils;
import fr.devinsy.xidyn.utils.XidynUtils;
/**
* The Class FederationHeaderView.
*/
public class FederationHeaderView
{
private static Logger logger = LoggerFactory.getLogger(FederationHeaderView.class);
/**
* Builds the.
*
* @param federation
* the organization
* @return the string
* @throws StatoolInfosException
* the statool infos exception
* @throws IOException
*/
public static String htmlize(final Federation federation) throws StatoolInfosException, IOException
{
String result;
try
{
TagDataManager data = new TagDataManager();
data.setAttribute("federationRawButton", "href", federation.getTechnicalName() + ".properties");
data.setAttribute("federationLogo", "src", federation.getLogoFileName());
data.setEscapedContent("federationName", federation.getName());
data.setEscapedContent("federationDescription", federation.getDescription());
data.setEscapedContent("federationURL", federation.getWebsite());
data.setEscapedAttribute("federationURL", "href", federation.getWebsite());
data.setContent("federationStartDate", StringUtils.defaultIfBlank(federation.getStartDate(), "n/a"));
data.setAttribute("subsLink", "href", "index.xhtml");
data.setAttribute("rawLink", "href", federation.getTechnicalName() + ".properties");
data.setAttribute("rawCheckLink", "href", federation.getTechnicalName() + "-check.xhtml");
data.setAttribute("statsLink", "href", federation.getTechnicalName() + "-stats.xhtml");
2021-06-03 04:25:16 +02:00
data.setAttribute("metricsLink", "href", federation.getTechnicalName() + "-metrics.xhtml");
2021-06-03 03:05:12 +02:00
data.setAttribute("crawlLink", "href", federation.getTechnicalName() + "-crawl.xhtml");
if (federation.getCrawlJournal().getErrors().isEmpty())
{
data.setAttribute("crawlLinkImg", "src", "circle-icons/download-mono.svg");
}
else
{
data.setAttribute("crawlLinkImg", "src", "circle-icons/download.svg");
}
{
PropertyChecks checks = federation.getInputChecksAll();
data.setContent("errorCount", checks.getErrorCount());
data.setContent("warningCount", checks.getWarningCount());
data.setContent("voidCount", checks.getVoidCount());
data.setAttribute("alertLink", "href", federation.getTechnicalName() + "-checkalerts.xhtml");
}
if (StringUtils.isNotBlank(federation.getLegalWebsite()))
{
data.setEscapedAttribute("legalLink", "href", federation.getLegalWebsite());
data.setAttribute("legalLinkImg", "class", "");
data.getIdData("legalLinkImg").getAttribute("class").setMode(DisplayMode.REPLACE);
}
if (StringUtils.isNotBlank(federation.getContactWebsite()))
{
data.setEscapedAttribute("contactLink", "href", federation.getContactWebsite());
data.setAttribute("contactLinkImg", "class", "");
data.getIdData("contactLinkImg").getAttribute("class").setMode(DisplayMode.REPLACE);
}
if (StringUtils.isNotBlank(federation.getContactEmail()))
{
data.setEscapedAttribute("emailLink", "href", "mailto:" + federation.getContactEmail());
data.setAttribute("emailLinkImg", "class", "");
data.getIdData("emailLinkImg").getAttribute("class").setMode(DisplayMode.REPLACE);
}
if (StringUtils.isNotBlank(federation.getUserDocWebsite()))
{
data.setEscapedAttribute("userDocLink", "href", federation.getUserDocWebsite());
data.setAttribute("userDocLinkImg", "class", "");
data.getIdData("userDocLinkImg").getAttribute("class").setMode(DisplayMode.REPLACE);
}
if (StringUtils.isNotBlank(federation.getTechnicalDocWebsite()))
{
data.setEscapedAttribute("technicalDocLink", "href", federation.getTechnicalDocWebsite());
data.setAttribute("technicalDocLinkImg", "class", "");
data.getIdData("technicalDocLinkImg").getAttribute("class").setMode(DisplayMode.REPLACE);
}
String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/federationHeaderView.xhtml", data).toString();
result = XidynUtils.extractBodyContent(content);
}
catch (XidynException exception)
{
throw new StatoolInfosException("Error building federation header view: " + exception.getMessage(), exception);
}
//
return result;
}
}