2020-09-17 02:03:56 +02:00
|
|
|
/*
|
|
|
|
* 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 java.io.File;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
|
|
|
|
import org.apache.commons.io.FileUtils;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
2020-09-17 03:59:11 +02:00
|
|
|
import fr.devinsy.statoolinfos.core.CrawlCache;
|
2020-09-17 02:03:56 +02:00
|
|
|
import fr.devinsy.statoolinfos.core.Federation;
|
|
|
|
import fr.devinsy.statoolinfos.core.Organization;
|
|
|
|
import fr.devinsy.statoolinfos.core.Service;
|
|
|
|
import fr.devinsy.statoolinfos.core.StatoolInfosException;
|
|
|
|
import fr.devinsy.statoolinfos.core.StatoolInfosUtils;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Class Htmlizer.
|
|
|
|
*/
|
|
|
|
public class Htmlizer
|
|
|
|
{
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(Htmlizer.class);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Instantiates a new htmlizer.
|
|
|
|
*/
|
|
|
|
private Htmlizer()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copy stuff.
|
|
|
|
*
|
|
|
|
* @param target
|
|
|
|
* the target
|
|
|
|
* @throws IOException
|
|
|
|
*/
|
|
|
|
private static void copyStuff(final File targetDirectory) throws IOException
|
|
|
|
{
|
|
|
|
// Copy commons files (index, images, favicon, css…).
|
|
|
|
if (!new File(targetDirectory, "index.html").exists())
|
|
|
|
{
|
|
|
|
|
|
|
|
StatoolInfosUtils.copyRessource("/fr/devinsy/statoolinfos/htmlize/stuff/index.html", targetDirectory);
|
|
|
|
StatoolInfosUtils.copyRessource("/fr/devinsy/statoolinfos/htmlize/stuff/statoolinfos.css", targetDirectory);
|
|
|
|
StatoolInfosUtils.copyRessource("/fr/devinsy/statoolinfos/htmlize/stuff/Chart.bundle.min.js", targetDirectory);
|
|
|
|
StatoolInfosUtils.copyRessource("/fr/devinsy/statoolinfos/htmlize/stuff/statoolinfos-logo.jpg", targetDirectory);
|
|
|
|
StatoolInfosUtils.copyRessource("/fr/devinsy/statoolinfos/htmlize/stuff/statoolinfos-logo.ico", targetDirectory);
|
|
|
|
StatoolInfosUtils.copyRessource("/fr/devinsy/statoolinfos/htmlize/stuff/statoolinfos-logo-name.jpg", targetDirectory);
|
|
|
|
StatoolInfosUtils.copyRessource("/fr/devinsy/statoolinfos/htmlize/stuff/statoolinfos-logo.jpg", new File(targetDirectory, "logo.jpg"));
|
|
|
|
StatoolInfosUtils.copyRessource("/fr/devinsy/statoolinfos/htmlize/stuff/statoolinfos-logo.ico", new File(targetDirectory, "favicon.ico"));
|
|
|
|
StatoolInfosUtils.copyRessource("/fr/devinsy/statoolinfos/htmlize/stuff/about.xhtml", targetDirectory);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Htmlize federation.
|
|
|
|
*
|
|
|
|
* @param federation
|
|
|
|
* the federation
|
|
|
|
* @param cache
|
|
|
|
* the cache
|
|
|
|
* @throws IOException
|
|
|
|
* @throws StatoolInfosException
|
|
|
|
*/
|
2020-09-17 03:59:11 +02:00
|
|
|
public static void htmlize(final Federation federation, final CrawlCache cache) throws IOException, StatoolInfosException
|
2020-09-17 02:03:56 +02:00
|
|
|
{
|
|
|
|
File targetDirectory = new File(federation.get("conf.htmlize.directory"));
|
|
|
|
logger.info("Htmlize target directory: {}", targetDirectory.getAbsoluteFile());
|
|
|
|
|
|
|
|
if (!targetDirectory.exists())
|
|
|
|
{
|
|
|
|
throw new IllegalArgumentException("Htmlize target directory is missing.");
|
|
|
|
}
|
|
|
|
else if (!targetDirectory.isDirectory())
|
|
|
|
{
|
|
|
|
throw new IllegalArgumentException("Htmlize target directory is not a directory.");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
copyStuff(targetDirectory);
|
2020-09-17 03:59:11 +02:00
|
|
|
cache.restoreLogoTo(federation.getLogoURL(), new File(targetDirectory, federation.getTechnicalName() + "-logo.jpg"));
|
2020-09-17 02:03:56 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
String page = FederationPage.build(federation);
|
|
|
|
FileUtils.write(new File(targetDirectory, "index.xhtml"), page, StandardCharsets.UTF_8);
|
|
|
|
|
|
|
|
for (Organization organization : federation.getOrganizations())
|
|
|
|
{
|
|
|
|
page = OrganizationPage.build(organization);
|
|
|
|
FileUtils.write(new File(targetDirectory, organization.getTechnicalName() + ".xhtml"), page, StandardCharsets.UTF_8);
|
|
|
|
|
|
|
|
for (Service service : organization.getServices())
|
|
|
|
{
|
|
|
|
page = ServicePage.build(service);
|
|
|
|
FileUtils.write(new File(targetDirectory, organization.getTechnicalName() + "-" + service.getTechnicalName() + ".xhtml"), page, StandardCharsets.UTF_8);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Download federation stuff (favicon, logo…).
|
|
|
|
// Build the federation page.
|
|
|
|
|
|
|
|
// For each organization
|
|
|
|
// Download organization stuff (favicon, logo…).
|
|
|
|
// Build organization page.
|
|
|
|
// for each service
|
|
|
|
// Download service stuff (favicon, logo…).
|
|
|
|
// Build service page.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Htmlize organization.
|
|
|
|
*
|
|
|
|
* @param federation
|
|
|
|
* the federation
|
|
|
|
* @param targetDirectory
|
|
|
|
* the target directory
|
|
|
|
* @throws IOException
|
|
|
|
* @throws StatoolInfosException
|
|
|
|
*/
|
2020-09-17 03:59:11 +02:00
|
|
|
public static void htmlize(final Organization organization, final CrawlCache cache) throws IOException, StatoolInfosException
|
2020-09-17 02:03:56 +02:00
|
|
|
{
|
|
|
|
File targetDirectory = new File(organization.get("conf.htmlize.directory"));
|
|
|
|
logger.info("Htmlize target directory: {}", targetDirectory.getAbsoluteFile());
|
|
|
|
|
|
|
|
if (!targetDirectory.exists())
|
|
|
|
{
|
|
|
|
throw new IllegalArgumentException("Htmlize target directory is missing.");
|
|
|
|
}
|
|
|
|
else if (!targetDirectory.isDirectory())
|
|
|
|
{
|
|
|
|
throw new IllegalArgumentException("Htmlize target directory is not a directory.");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
copyStuff(targetDirectory);
|
|
|
|
|
|
|
|
//
|
|
|
|
String page = OrganizationPage.build(organization);
|
|
|
|
FileUtils.write(new File(targetDirectory, "index.xhtml"), page, StandardCharsets.UTF_8);
|
|
|
|
|
|
|
|
for (Service service : organization.getServices())
|
|
|
|
{
|
|
|
|
page = ServicePage.build(service);
|
|
|
|
FileUtils.write(new File(targetDirectory, organization.getTechnicalName() + "-" + service.getTechnicalName() + ".xhtml"), page, StandardCharsets.UTF_8);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Download federation stuff (favicon, logo…).
|
|
|
|
// Build the federation page.
|
|
|
|
|
|
|
|
// For each organization
|
|
|
|
// Download organization stuff (favicon, logo…).
|
|
|
|
// Build organization page.
|
|
|
|
// for each service
|
|
|
|
// Download service stuff (favicon, logo…).
|
|
|
|
// Build service page.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|