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

185 lines
7.7 KiB
Java
Raw Normal View History

/*
* 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;
import fr.devinsy.statoolinfos.core.Configuration;
2020-09-17 03:59:11 +02:00
import fr.devinsy.statoolinfos.core.CrawlCache;
import fr.devinsy.statoolinfos.core.Factory;
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
*/
public static void htmlizeFederation(final Configuration configuration) throws IOException, StatoolInfosException
{
CrawlCache cache = configuration.getCrawlCache();
File htmlizeInput = configuration.getHtmlizeInput();
File htmlizeDirectory = configuration.getHtmlizeDirectory();
Federation federation = Factory.loadFederation(htmlizeInput, cache);
copyStuff(htmlizeDirectory);
2020-09-19 02:37:52 +02:00
// Manage the logo file.
cache.restoreLogoTo(federation.getLogoURL(), new File(htmlizeDirectory, federation.getTechnicalName() + "-logo.jpg"), federation.getTechnicalName());
FileUtils.copyFile(federation.getLocalFile(), new File(htmlizeDirectory, federation.getTechnicalName() + "-raw.properties"));
//
String page = FederationPage.build(federation);
FileUtils.write(new File(htmlizeDirectory, "index.xhtml"), page, StandardCharsets.UTF_8);
for (Organization organization : federation.getOrganizations())
{
2020-09-19 02:37:52 +02:00
// Manage the logo file.
cache.restoreLogoTo(organization.getLogoURL(), new File(htmlizeDirectory, organization.getTechnicalName() + "-logo.jpg"), organization.getTechnicalName());
FileUtils.copyFile(organization.getLocalFile(), new File(htmlizeDirectory, organization.getTechnicalName() + "-raw.properties"));
//
page = OrganizationPage.build(organization);
FileUtils.write(new File(htmlizeDirectory, organization.getTechnicalName() + ".xhtml"), page, StandardCharsets.UTF_8);
for (Service service : organization.getServices())
{
2020-09-19 02:37:52 +02:00
// Manage the logo file.
cache.restoreLogoTo(service.getLogoURL(), new File(htmlizeDirectory, service.getTechnicalName() + "-logo.jpg"), service.getTechnicalName());
FileUtils.copyFile(service.getLocalFile(), new File(htmlizeDirectory, service.getTechnicalName() + "-raw.properties"));
page = ServicePage.build(service);
FileUtils.write(new File(htmlizeDirectory, 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
*/
public static void htmlizeOrganisation(final Configuration configuration) throws IOException, StatoolInfosException
{
CrawlCache cache = configuration.getCrawlCache();
2020-09-19 02:37:52 +02:00
File htmlizeInput = configuration.getHtmlizeInput();
File htmlizeDirectory = configuration.getHtmlizeDirectory();
Organization organization = Factory.loadOrganization(configuration.getBuildInput(), cache);
2020-09-19 02:37:52 +02:00
copyStuff(htmlizeDirectory);
// Manage the logo file.
cache.restoreLogoTo(organization.getLogoURL(), new File(htmlizeDirectory, organization.getTechnicalName() + "-logo.jpg"), organization.getTechnicalName());
2020-09-19 02:37:52 +02:00
//
String page = OrganizationPage.build(organization);
FileUtils.write(new File(htmlizeDirectory, "index.xhtml"), page, StandardCharsets.UTF_8);
for (Service service : organization.getServices())
{
2020-09-19 02:37:52 +02:00
// Manage the logo file.
cache.restoreLogoTo(service.getLogoURL(), new File(htmlizeDirectory, service.getTechnicalName() + "-logo.jpg"), service.getTechnicalName());
//
2020-09-19 02:37:52 +02:00
page = ServicePage.build(service);
FileUtils.write(new File(htmlizeDirectory, organization.getTechnicalName() + "-" + service.getTechnicalName() + ".xhtml"), page, StandardCharsets.UTF_8);
}
2020-09-19 02:37:52 +02:00
// Download federation stuff (favicon, logo…).
// Build the federation page.
2020-09-19 02:37:52 +02:00
// For each organization
// Download organization stuff (favicon, logo…).
// Build organization page.
// for each service
// Download service stuff (favicon, logo…).
// Build service page.
}
}