From 626180e0c394ad02b4e8b52496cad809dda9239c Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Wed, 28 Oct 2020 15:32:05 +0100 Subject: [PATCH] Refactored htmlizer with MVC concept (view search data). --- .../devinsy/statoolinfos/HtmlizerContext.java | 196 +++++++++ .../statoolinfos/htmlize/AboutPage.java | 30 +- .../statoolinfos/htmlize/CategoriesPage.java | 29 +- .../statoolinfos/htmlize/CategoryPage.java | 33 +- .../statoolinfos/htmlize/FederationPage.java | 68 ++- .../statoolinfos/htmlize/Htmlizer.java | 403 +----------------- .../htmlize/OrganizationPage.java | 81 +++- .../htmlize/PropertiesFilesPage.java | 30 +- .../htmlize/PropertyFileCheckPage.java | 44 +- .../htmlize/PropertyStatsPage.java | 44 +- .../statoolinfos/htmlize/ServicePage.java | 78 +++- .../statoolinfos/htmlize/ServicesPage.java | 25 +- .../htmlize/SocialNetworksPage.java | 37 +- .../statoolinfos/htmlize/SoftwarePage.java | 31 +- .../statoolinfos/htmlize/SoftwaresPage.java | 29 +- 15 files changed, 756 insertions(+), 402 deletions(-) create mode 100644 src/fr/devinsy/statoolinfos/HtmlizerContext.java diff --git a/src/fr/devinsy/statoolinfos/HtmlizerContext.java b/src/fr/devinsy/statoolinfos/HtmlizerContext.java new file mode 100644 index 0000000..b3b374f --- /dev/null +++ b/src/fr/devinsy/statoolinfos/HtmlizerContext.java @@ -0,0 +1,196 @@ +/* + * Copyright (C) 2020 Christian Pierre MOMON + * + * 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 . + */ +package fr.devinsy.statoolinfos; + +import java.io.File; +import java.io.IOException; + +import fr.devinsy.statoolinfos.core.Categories; +import fr.devinsy.statoolinfos.core.Configuration; +import fr.devinsy.statoolinfos.core.Factory; +import fr.devinsy.statoolinfos.core.Federation; +import fr.devinsy.statoolinfos.core.StatoolInfosException; +import fr.devinsy.statoolinfos.crawl.CrawlCache; + +/** + * The Class Manager. + */ +public class HtmlizerContext +{ + private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(HtmlizerContext.class); + + private static class SingletonHolder + { + private static final HtmlizerContext instance = new HtmlizerContext(); + } + + private Configuration configuration; + private Federation federation; + private Categories categories; + private CrawlCache cache; + + /** + * Instantiates a new manager. + */ + private HtmlizerContext() + { + } + + /** + * Configure. + * + * @param configurationFile + * the configuration file + * @throws IOException + * @throws StatoolInfosException + */ + public void configure(final File configurationFile) throws StatoolInfosException, IOException + { + this.configuration = Factory.loadConfiguration(configurationFile); + + logger.info("Cache setting: {}", this.configuration.getCrawlCachePath()); + logger.info("Htmlize input setting: {}", this.configuration.getHtmlizeInputPath()); + logger.info("Htmlize directory setting: {}", this.configuration.getHtmlizeDirectoryPath()); + + File htmlizeInput = this.configuration.getHtmlizeInput(); + File htmlizeDirectory = this.configuration.getHtmlizeDirectory(); + if (htmlizeInput == null) + { + throw new IllegalArgumentException("Htmlize input undefined."); + } + else if (!htmlizeInput.exists()) + { + throw new IllegalArgumentException("Htmlize input is missing."); + } + else if (htmlizeInput.isDirectory()) + { + throw new IllegalArgumentException("Htmlize input is a directory."); + } + else if (htmlizeDirectory == null) + { + throw new IllegalArgumentException("Htmlize directory undefined."); + } + else if (!htmlizeDirectory.exists()) + { + throw new IllegalArgumentException("Htmlize directory is missing."); + } + else if (!htmlizeDirectory.isDirectory()) + { + throw new IllegalArgumentException("Htmlize directory is not a directory."); + } + else + { + if (this.configuration.isFederation()) + { + this.cache = this.configuration.getCrawlCache(); + this.federation = Factory.loadFederation(this.configuration.getHtmlizeInput(), this.cache); + this.categories = Factory.loadCategories(this.configuration.getCategoryFile(), this.federation); + } + else + { + throw new IllegalArgumentException("Not a federation configuration."); + } + } + } + + /** + * Gets the cache. + * + * @return the cache + */ + public CrawlCache getCache() + { + CrawlCache result; + + result = this.cache; + + // + return result; + } + + /** + * Gets the categories. + * + * @return the categories + */ + public Categories getCategories() + { + Categories result; + + result = this.categories; + + // + return result; + } + + /** + * Gets the configuration. + * + * @return the configuration + */ + public Configuration getConfiguration() + { + Configuration result; + + result = this.configuration; + + // + return result; + } + + /** + * Gets the federation. + * + * @return the federation + */ + public Federation getFederation() + { + Federation result; + + result = this.federation; + + // + return result; + } + + /** + * Htmlize directory. + * + * @return the file + */ + public File getHtmlizeDirectory() + { + File result; + + result = this.configuration.getHtmlizeDirectory(); + + // + return result; + } + + /** + * Instance. + * + * @return the manager + */ + public static HtmlizerContext instance() + { + return SingletonHolder.instance; + } +} diff --git a/src/fr/devinsy/statoolinfos/htmlize/AboutPage.java b/src/fr/devinsy/statoolinfos/htmlize/AboutPage.java index 0d683c0..3d48037 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/AboutPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/AboutPage.java @@ -18,10 +18,18 @@ */ 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.HtmlizerContext; +import fr.devinsy.statoolinfos.core.Federation; import fr.devinsy.statoolinfos.core.StatoolInfosException; +import fr.devinsy.statoolinfos.crawl.CrawlCache; import fr.devinsy.xidyn.XidynException; import fr.devinsy.xidyn.data.TagDataManager; import fr.devinsy.xidyn.presenters.PresenterUtils; @@ -33,6 +41,26 @@ public class AboutPage { private static Logger logger = LoggerFactory.getLogger(AboutPage.class); + /** + * Builds the. + * + * @throws StatoolInfosException + * the statool infos exception + * @throws IOException + * Signals that an I/O exception has occurred. + */ + public static void build() throws StatoolInfosException, IOException + { + logger.info("Htmlize about page."); + + Federation federation = HtmlizerContext.instance().getFederation(); + CrawlCache cache = HtmlizerContext.instance().getCache(); + File htmlizeDirectory = HtmlizerContext.instance().getHtmlizeDirectory(); + + String page = htmlize(); + FileUtils.write(new File(htmlizeDirectory, "about.xhtml"), page, StandardCharsets.UTF_8); + } + /** * Builds the. * @@ -40,7 +68,7 @@ public class AboutPage * @throws StatoolInfosException * the statool infos exception */ - public static String build() throws StatoolInfosException + public static String htmlize() throws StatoolInfosException { String result; diff --git a/src/fr/devinsy/statoolinfos/htmlize/CategoriesPage.java b/src/fr/devinsy/statoolinfos/htmlize/CategoriesPage.java index 85f7451..c032e6a 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/CategoriesPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/CategoriesPage.java @@ -18,10 +18,19 @@ */ 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.HtmlizerContext; +import fr.devinsy.statoolinfos.core.Categories; +import fr.devinsy.statoolinfos.core.Federation; import fr.devinsy.statoolinfos.core.StatoolInfosException; +import fr.devinsy.statoolinfos.stats.StatAgent; import fr.devinsy.statoolinfos.stats.categories.CategoryStat; import fr.devinsy.statoolinfos.stats.categories.CategoryStats; import fr.devinsy.xidyn.XidynException; @@ -35,6 +44,24 @@ public class CategoriesPage { private static Logger logger = LoggerFactory.getLogger(CategoriesPage.class); + /** + * Builds the. + * + * @throws StatoolInfosException + * @throws IOException + */ + public static void build() throws StatoolInfosException, IOException + { + Federation federation = HtmlizerContext.instance().getFederation(); + File htmlizeDirectory = HtmlizerContext.instance().getHtmlizeDirectory(); + Categories categories = HtmlizerContext.instance().getCategories(); + + logger.info("Htmlize categories page."); + CategoryStats stats = StatAgent.statAllCategories(federation, categories); + String page = CategoriesPage.htmlize(stats); + FileUtils.write(new File(htmlizeDirectory, "categories.xhtml"), page, StandardCharsets.UTF_8); + } + /** * Builds the. * @@ -44,7 +71,7 @@ public class CategoriesPage * @throws StatoolInfosException * the statool infos exception */ - public static String build(final CategoryStats stats) throws StatoolInfosException + public static String htmlize(final CategoryStats stats) throws StatoolInfosException { String result; diff --git a/src/fr/devinsy/statoolinfos/htmlize/CategoryPage.java b/src/fr/devinsy/statoolinfos/htmlize/CategoryPage.java index ed363d5..5ccec3e 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/CategoryPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/CategoryPage.java @@ -18,12 +18,21 @@ */ 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.HtmlizerContext; +import fr.devinsy.statoolinfos.core.Categories; import fr.devinsy.statoolinfos.core.Category; +import fr.devinsy.statoolinfos.core.Federation; import fr.devinsy.statoolinfos.core.Services; import fr.devinsy.statoolinfos.core.StatoolInfosException; +import fr.devinsy.statoolinfos.crawl.CrawlCache; import fr.devinsy.xidyn.XidynException; import fr.devinsy.xidyn.data.TagDataManager; import fr.devinsy.xidyn.presenters.PresenterUtils; @@ -35,6 +44,28 @@ public class CategoryPage { private static Logger logger = LoggerFactory.getLogger(CategoryPage.class); + /** + * Builds the. + * + * @throws StatoolInfosException + * @throws IOException + */ + public static void buildAll() throws StatoolInfosException, IOException + { + Federation federation = HtmlizerContext.instance().getFederation(); + CrawlCache cache = HtmlizerContext.instance().getCache(); + File htmlizeDirectory = HtmlizerContext.instance().getHtmlizeDirectory(); + Categories categories = HtmlizerContext.instance().getCategories(); + + logger.info("Htmlize category pages."); + for (Category category : categories) + { + Services services = federation.getAllServices().getBy(category); + String page = CategoryPage.htmlize(category, services); + FileUtils.write(new File(htmlizeDirectory, "category-" + category.getTechnicalName() + ".xhtml"), page, StandardCharsets.UTF_8); + } + } + /** * Builds the. * @@ -46,7 +77,7 @@ public class CategoryPage * @throws StatoolInfosException * the statool infos exception */ - public static String build(final Category category, final Services services) throws StatoolInfosException + public static String htmlize(final Category category, final Services services) throws StatoolInfosException { String result; diff --git a/src/fr/devinsy/statoolinfos/htmlize/FederationPage.java b/src/fr/devinsy/statoolinfos/htmlize/FederationPage.java index cc1acbb..83a4fea 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/FederationPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/FederationPage.java @@ -18,25 +18,59 @@ */ 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.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import fr.devinsy.catgenerator.core.CatGenerator; +import fr.devinsy.statoolinfos.HtmlizerContext; import fr.devinsy.statoolinfos.core.Federation; import fr.devinsy.statoolinfos.core.Organization; import fr.devinsy.statoolinfos.core.StatoolInfosException; +import fr.devinsy.statoolinfos.crawl.CrawlCache; import fr.devinsy.xidyn.XidynException; import fr.devinsy.xidyn.data.DisplayMode; import fr.devinsy.xidyn.data.TagDataManager; import fr.devinsy.xidyn.presenters.PresenterUtils; /** - * The Class OrganizationPage. + * The Class FederationPage. */ public class FederationPage { private static Logger logger = LoggerFactory.getLogger(FederationPage.class); + /** + * Builds the. + * + * @throws StatoolInfosException + * the statool infos exception + * @throws IOException + */ + public static void build() throws StatoolInfosException, IOException + { + Federation federation = HtmlizerContext.instance().getFederation(); + CrawlCache cache = HtmlizerContext.instance().getCache(); + File htmlizeDirectory = HtmlizerContext.instance().getHtmlizeDirectory(); + + // + logger.info("PAGE FEDERATION Htmlize federation logo."); + htmlizeFederationLogo(federation, cache, htmlizeDirectory); + + // + logger.info("PAGE FEDERATION Htmlize federation properties files."); + FileUtils.copyFile(federation.getInputFile(), new File(htmlizeDirectory, federation.getTechnicalName() + ".properties")); + + logger.info("PAGE FEDERATION federation page: {}.", federation.getName()); + String page = htmlize(federation); + FileUtils.write(new File(htmlizeDirectory, "index.xhtml"), page, StandardCharsets.UTF_8); + } + /** * Builds the. * @@ -46,7 +80,7 @@ public class FederationPage * @throws StatoolInfosException * the statool infos exception */ - public static String build(final Federation federation) throws StatoolInfosException + public static String htmlize(final Federation federation) throws StatoolInfosException { String result; @@ -133,4 +167,34 @@ public class FederationPage // return result; } + + /** + * Htmlize federation logo. + * + * @param federation + * the federation + * @param cache + * the cache + * @param htmlizeDirectory + * the htmlize directory + * @throws IOException + * Signals that an I/O exception has occurred. + */ + private static void htmlizeFederationLogo(final Federation federation, final CrawlCache cache, final File htmlizeDirectory) throws IOException + { + logger.info("Htmlize federation logo."); + + File target = new File(htmlizeDirectory, federation.getLogoFileName()); + + File logoFile = cache.restoreFile(federation.getLogoURL()); + if (logoFile == null) + { + logger.info("CatGeneratoring cat avatar: {}", target.getAbsoluteFile()); + CatGenerator.buildAvatarTo(federation.getTechnicalName(), target); + } + else + { + FileUtils.copyFile(logoFile, target); + } + } } diff --git a/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java b/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java index 15321e9..a4a97e0 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java +++ b/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java @@ -20,38 +20,15 @@ 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.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import fr.devinsy.catgenerator.core.BirdGenerator; -import fr.devinsy.catgenerator.core.CatGenerator; -import fr.devinsy.statoolinfos.checker.PropertyChecker; -import fr.devinsy.statoolinfos.checker.PropertyChecks; -import fr.devinsy.statoolinfos.core.Categories; -import fr.devinsy.statoolinfos.core.Category; +import fr.devinsy.statoolinfos.HtmlizerContext; import fr.devinsy.statoolinfos.core.Configuration; -import fr.devinsy.statoolinfos.core.Factory; -import fr.devinsy.statoolinfos.core.Federation; -import fr.devinsy.statoolinfos.core.Organization; -import fr.devinsy.statoolinfos.core.Organizations; -import fr.devinsy.statoolinfos.core.Service; -import fr.devinsy.statoolinfos.core.Services; -import fr.devinsy.statoolinfos.core.SocialNetworks; -import fr.devinsy.statoolinfos.core.Software; -import fr.devinsy.statoolinfos.core.Softwares; import fr.devinsy.statoolinfos.core.StatoolInfosException; import fr.devinsy.statoolinfos.core.StatoolInfosUtils; -import fr.devinsy.statoolinfos.crawl.CrawlCache; -import fr.devinsy.statoolinfos.crawl.CrawlCache.DefaultLogoGenerator; -import fr.devinsy.statoolinfos.stats.StatAgent; -import fr.devinsy.statoolinfos.stats.categories.CategoryStats; -import fr.devinsy.statoolinfos.stats.properties.PropertyStats; -import fr.devinsy.statoolinfos.stats.propertyfiles.PropertiesFileStats; -import fr.devinsy.statoolinfos.stats.softwares.SoftwareStats; /** * The Class Htmlizer. @@ -214,65 +191,6 @@ public class Htmlizer } } - /** - * Htmlize. - * - * @param configuration - * the configuration - * @throws IOException - * Signals that an I/O exception has occurred. - * @throws StatoolInfosException - * the statool infos exception - */ - public static void htmlize(final Configuration configuration) throws IOException, StatoolInfosException - { - logger.info("Cache setting: {}", configuration.getCrawlCachePath()); - logger.info("Htmlize input setting: {}", configuration.getHtmlizeInputPath()); - logger.info("Htmlize directory setting: {}", configuration.getHtmlizeDirectoryPath()); - - File htmlizeInput = configuration.getHtmlizeInput(); - File htmlizeDirectory = configuration.getHtmlizeDirectory(); - if (htmlizeInput == null) - { - throw new IllegalArgumentException("Htmlize input undefined."); - } - else if (!htmlizeInput.exists()) - { - throw new IllegalArgumentException("Htmlize input is missing."); - } - else if (htmlizeInput.isDirectory()) - { - throw new IllegalArgumentException("Htmlize input is a directory."); - } - else if (htmlizeDirectory == null) - { - throw new IllegalArgumentException("Htmlize directory undefined."); - } - else if (!htmlizeDirectory.exists()) - { - throw new IllegalArgumentException("Htmlize directory is missing."); - } - else if (!htmlizeDirectory.isDirectory()) - { - throw new IllegalArgumentException("Htmlize directory is not a directory."); - } - else - { - if (configuration.isFederation()) - { - Htmlizer.htmlizeFederation(configuration); - } - else if (configuration.isOrganization()) - { - Htmlizer.htmlizeOrganisation(configuration); - } - else - { - logger.warn("No htmlize for this input: {}.", configuration.getClassName()); - } - } - } - /** * Htmlize. * @@ -287,312 +205,23 @@ public class Htmlizer { logger.info("Htmlize {}", configurationFile.getAbsolutePath()); - Configuration configuration = Factory.loadConfiguration(configurationFile); - - htmlize(configuration); - } - - /** - * Htmlize federation. - * - * @param configuration - * the configuration - * @throws IOException - * Signals that an I/O exception has occurred. - * @throws StatoolInfosException - * the statool infos exception - */ - 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); - Categories categories = Factory.loadCategories(configuration.getCategoryFile(), federation); + HtmlizerContext.instance().configure(configurationFile); + File htmlizeDirectory = HtmlizerContext.instance().getHtmlizeDirectory(); copyStuff(htmlizeDirectory); - // Manage the logo file. - logger.info("Htmlize federation logo."); - htmlizeFederationLogo(federation, cache, htmlizeDirectory); - logger.info("Htmlize federation properties files."); - FileUtils.copyFile(federation.getInputFile(), new File(htmlizeDirectory, federation.getTechnicalName() + ".properties")); - - // - logger.info("Htmlize about page."); - String page = AboutPage.build(); - FileUtils.write(new File(htmlizeDirectory, "about.xhtml"), page, StandardCharsets.UTF_8); - - // - logger.info("Htmlize federation page: {}.", federation.getName()); - page = FederationPage.build(federation); - FileUtils.write(new File(htmlizeDirectory, "index.xhtml"), page, StandardCharsets.UTF_8); - - for (Organization organization : federation.getOrganizations()) - { - // Manage the logo file. - logger.info("Htmlize organization logo: {}.", organization.getName()); - htmlizeOrganizationLogo(organization, cache, htmlizeDirectory); - logger.info("Htmlize organization properties file: {}.", organization.getName()); - FileUtils.copyFile(organization.getInputFile(), new File(htmlizeDirectory, organization.getTechnicalName() + ".properties")); - - // - logger.info("Htmlize organization page: {}.", organization.getName()); - page = OrganizationPage.build(organization); - FileUtils.write(new File(htmlizeDirectory, organization.getTechnicalName() + ".xhtml"), page, StandardCharsets.UTF_8); - - // - for (Service service : organization.getServices()) - { - // Manage the logo file. - logger.info("Htmlize service logo: {}.", service.getName()); - htmlizeServiceLogo(service, cache, htmlizeDirectory); - logger.info("Htmlize service properties file: {}.", service.getName()); - FileUtils.copyFile(service.getInputFile(), - new File(htmlizeDirectory, organization.getTechnicalName() + "-" + service.getTechnicalName() + ".properties")); - - logger.info("Htmlize service page: {}.", service.getName()); - page = ServicePage.build(organization, service); - FileUtils.write(new File(htmlizeDirectory, organization.getTechnicalName() + "-" + service.getTechnicalName() + ".xhtml"), page, StandardCharsets.UTF_8); - } - } - - // - logger.info("Htmlize services page."); - page = ServicesPage.build(federation.getAllServices()); - FileUtils.write(new File(htmlizeDirectory, "services.xhtml"), page, StandardCharsets.UTF_8); - - // - PropertyChecker checker = new PropertyChecker(); - - PropertyChecks checks = checker.checkFederation(federation.getInputFile()); - page = PropertyFileCheckPage.build("Fédération", checks); - FileUtils.write(new File(htmlizeDirectory, federation.getTechnicalName() + "-check.xhtml"), page, StandardCharsets.UTF_8); - - for (Organization organization : federation.getOrganizations()) - { - checks = checker.checkOrganization(organization.getInputFile()); - page = PropertyFileCheckPage.build("Organisation", checks); - FileUtils.write(new File(htmlizeDirectory, organization.getTechnicalName() + "-check.xhtml"), page, StandardCharsets.UTF_8); - - for (Service service : organization.getServices()) - { - checks = checker.checkService(service.getInputFile()); - page = PropertyFileCheckPage.build("Service", checks); - FileUtils.write(new File(htmlizeDirectory, organization.getTechnicalName() + "-" + service.getTechnicalName() + "-check.xhtml"), page, StandardCharsets.UTF_8); - } - } - - // - { - logger.info("Htmlize propertiesFiles page."); - PropertiesFileStats stats = StatAgent.statAllPropertiesFiles(federation, cache).sortByName(); - page = PropertiesFilesPage.build(stats); - FileUtils.write(new File(htmlizeDirectory, "propertiesFiles.xhtml"), page, StandardCharsets.UTF_8); - } - - // - { - logger.info("Htmlize propertyStats page."); - - PropertyStats stats = StatAgent.statAllProperties(federation); - page = PropertyStatsPage.build("Toutes les propriétés", stats); - FileUtils.write(new File(htmlizeDirectory, "propertyStats.xhtml"), page, StandardCharsets.UTF_8); - - PropertyStats federationStats = StatAgent.statFederationProperties(federation); - page = PropertyStatsPage.build("Les propriétés de la fédération", federationStats); - FileUtils.write(new File(htmlizeDirectory, "propertyStats-federation.xhtml"), page, StandardCharsets.UTF_8); - - PropertyStats organizationsStats = StatAgent.statOrganizationsProperties(federation.getOrganizations()); - page = PropertyStatsPage.build("Les propriétés des organizations", organizationsStats); - FileUtils.write(new File(htmlizeDirectory, "propertyStats-organizations.xhtml"), page, StandardCharsets.UTF_8); - - PropertyStats servicesStats = StatAgent.statServicesProperties(federation.getAllServices()); - page = PropertyStatsPage.build("Les propriétés des services", servicesStats); - FileUtils.write(new File(htmlizeDirectory, "propertyStats-services.xhtml"), page, StandardCharsets.UTF_8); - } - - // - { - logger.info("Htmlize categories page."); - CategoryStats stats = StatAgent.statAllCategories(federation, categories); - page = CategoriesPage.build(stats); - FileUtils.write(new File(htmlizeDirectory, "categories.xhtml"), page, StandardCharsets.UTF_8); - } - - // - { - logger.info("Htmlize category pages."); - for (Category category : categories) - { - Services services = federation.getAllServices().getBy(category); - page = CategoryPage.build(category, services); - FileUtils.write(new File(htmlizeDirectory, "category-" + category.getTechnicalName() + ".xhtml"), page, StandardCharsets.UTF_8); - } - } - - // - { - logger.info("Htmlize softwares page."); - SoftwareStats stats = StatAgent.statAllSoftwares(federation, categories); - page = SoftwaresPage.build(stats); - FileUtils.write(new File(htmlizeDirectory, "softwares.xhtml"), page, StandardCharsets.UTF_8); - } - - // - { - logger.info("Htmlize software pages."); - Softwares catalog = federation.getSoftwares(); - for (Software software : catalog.values()) - { - Services services = federation.getAllServices().getBy(software); - page = SoftwarePage.build(software, services); - FileUtils.write(new File(htmlizeDirectory, "software-" + software.getTechnicalName() + ".xhtml"), page, StandardCharsets.UTF_8); - } - } - - // - { - logger.info("Htmlize social networks pages."); - Organizations organizations = federation.getOrganizations().filterBySocialNetworks(); - page = SocialNetworksPage.build("Tous", organizations); - FileUtils.write(new File(htmlizeDirectory, "socialNetworks.xhtml"), page, StandardCharsets.UTF_8); - - organizations = federation.getOrganizations().filterBySocialNetwork(SocialNetworks.DIASPORA); - page = SocialNetworksPage.build("Disapora*", organizations); - FileUtils.write(new File(htmlizeDirectory, "socialNetworks-diaspora.xhtml"), page, StandardCharsets.UTF_8); - - organizations = federation.getOrganizations().filterBySocialNetwork(SocialNetworks.MASTODON); - page = SocialNetworksPage.build("Mastodon", organizations); - FileUtils.write(new File(htmlizeDirectory, "socialNetworks-mastodon.xhtml"), page, StandardCharsets.UTF_8); - } - } - - /** - * Htmlize federation logo. - * - * @param federation - * the federation - * @param cache - * the cache - * @param htmlizeDirectory - * the htmlize directory - * @throws IOException - * Signals that an I/O exception has occurred. - */ - private static void htmlizeFederationLogo(final Federation federation, final CrawlCache cache, final File htmlizeDirectory) throws IOException - { - logger.info("Htmlize federation logo."); - - File target = new File(htmlizeDirectory, federation.getLogoFileName()); - - File logoFile = cache.restoreFile(federation.getLogoURL()); - if (logoFile == null) - { - logger.info("CatGeneratoring cat avatar: {}", target.getAbsoluteFile()); - CatGenerator.buildAvatarTo(federation.getTechnicalName(), target); - } - else - { - FileUtils.copyFile(logoFile, target); - } - } - - /** - * Htmlize organisation. - * - * @param configuration - * the configuration - * @throws IOException - * Signals that an I/O exception has occurred. - * @throws StatoolInfosException - * the statool infos exception - */ - public static void htmlizeOrganisation(final Configuration configuration) throws IOException, StatoolInfosException - { - CrawlCache cache = configuration.getCrawlCache(); - File htmlizeInput = configuration.getHtmlizeInput(); - File htmlizeDirectory = configuration.getHtmlizeDirectory(); - - Organization organization = Factory.loadOrganization(configuration.getBuildInput(), cache); - - copyStuff(htmlizeDirectory); - - // Manage the logo file. - cache.restoreLogoTo(organization.getLogoURL(), new File(htmlizeDirectory, organization.getTechnicalName() + "-logo.jpg"), organization.getTechnicalName(), DefaultLogoGenerator.CAT); - - // - logger.info("Htmlize about page."); - String page = AboutPage.build(); - FileUtils.write(new File(htmlizeDirectory, "about.xhtml"), page, StandardCharsets.UTF_8); - - // - page = OrganizationPage.build(organization); - FileUtils.write(new File(htmlizeDirectory, "index.xhtml"), page, StandardCharsets.UTF_8); - - for (Service service : organization.getServices()) - { - // Manage the logo file. - cache.restoreLogoTo(service.getLogoURL(), new File(htmlizeDirectory, service.getTechnicalName() + "-logo.jpg"), service.getTechnicalName(), DefaultLogoGenerator.BIRD); - - // - page = ServicePage.build(organization, service); - FileUtils.write(new File(htmlizeDirectory, organization.getTechnicalName() + "-" + service.getTechnicalName() + ".xhtml"), page, StandardCharsets.UTF_8); - } - } - - /** - * Htmlize organization logo. - * - * @param organization - * the organization - * @param cache - * the cache - * @param htmlizeDirectory - * the htmlize directory - * @throws IOException - * Signals that an I/O exception has occurred. - */ - private static void htmlizeOrganizationLogo(final Organization organization, final CrawlCache cache, final File htmlizeDirectory) throws IOException - { - logger.info("Htmlize organization logo."); - - File target = new File(htmlizeDirectory, organization.getLogoFileName()); - - File logoFile = cache.restoreFile(organization.getLogoURL()); - if (logoFile == null) - { - logger.info("CatGeneratoring cat avatar: {}", target.getAbsoluteFile()); - CatGenerator.buildAvatarTo(organization.getTechnicalName(), target); - } - else - { - FileUtils.copyFile(logoFile, target); - } - } - - /** - * @param service - * @param cache - * @param htmlizeDirectory - * @throws IOException - */ - private static void htmlizeServiceLogo(final Service service, final CrawlCache cache, final File htmlizeDirectory) throws IOException - { - logger.info("Htmlize organization logo."); - - File target = new File(htmlizeDirectory, service.getLogoFileName()); - - File logoFile = cache.restoreFile(service.getLogoURL()); - if (logoFile == null) - { - logger.info("BirdGeneratoring cat avatar: {}", target.getAbsoluteFile()); - BirdGenerator.buildAvatarTo(service.getTechnicalName(), target); - } - else - { - FileUtils.copyFile(logoFile, target); - } + AboutPage.build(); + FederationPage.build(); + OrganizationPage.buildAll(); + ServicePage.buildAll(); + ServicesPage.build(); + PropertyFileCheckPage.buildAll(); + PropertiesFilesPage.build(); + PropertyStatsPage.buildAll(); + CategoriesPage.build(); + CategoryPage.buildAll(); + SoftwaresPage.build(); + SoftwarePage.buildAll(); + SocialNetworksPage.buildAll(); } } diff --git a/src/fr/devinsy/statoolinfos/htmlize/OrganizationPage.java b/src/fr/devinsy/statoolinfos/htmlize/OrganizationPage.java index 73f8f6c..e7896d4 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/OrganizationPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/OrganizationPage.java @@ -18,12 +18,20 @@ */ 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.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import fr.devinsy.catgenerator.core.CatGenerator; +import fr.devinsy.statoolinfos.HtmlizerContext; import fr.devinsy.statoolinfos.core.Organization; import fr.devinsy.statoolinfos.core.StatoolInfosException; +import fr.devinsy.statoolinfos.crawl.CrawlCache; import fr.devinsy.xidyn.XidynException; import fr.devinsy.xidyn.data.DisplayMode; import fr.devinsy.xidyn.data.TagDataManager; @@ -36,6 +44,47 @@ public class OrganizationPage { private static Logger logger = LoggerFactory.getLogger(OrganizationPage.class); + /** + * Builds the view. + * + * @param organization + * the organization + * @throws IOException + * @throws StatoolInfosException + */ + public static void build(final Organization organization) throws IOException, StatoolInfosException + { + CrawlCache cache = HtmlizerContext.instance().getCache(); + File htmlizeDirectory = HtmlizerContext.instance().getHtmlizeDirectory(); + + // Manage the logo file. + logger.info("Htmlize organization logo: {}.", organization.getName()); + htmlizeOrganizationLogo(organization, cache, htmlizeDirectory); + + // + logger.info("Htmlize organization properties file: {}.", organization.getName()); + FileUtils.copyFile(organization.getInputFile(), new File(htmlizeDirectory, organization.getTechnicalName() + ".properties")); + + // + logger.info("Htmlize organization page: {}.", organization.getName()); + String page = OrganizationPage.htmlize(organization); + FileUtils.write(new File(htmlizeDirectory, organization.getTechnicalName() + ".xhtml"), page, StandardCharsets.UTF_8); + } + + /** + * Builds the all. + * + * @throws StatoolInfosException + * @throws IOException + */ + public static void buildAll() throws IOException, StatoolInfosException + { + for (Organization organization : HtmlizerContext.instance().getFederation().getOrganizations()) + { + build(organization); + } + } + /** * Builds the. * @@ -45,7 +94,7 @@ public class OrganizationPage * @throws StatoolInfosException * the statool infos exception */ - public static String build(final Organization organization) throws StatoolInfosException + public static String htmlize(final Organization organization) throws StatoolInfosException { String result; @@ -118,4 +167,34 @@ public class OrganizationPage // return result; } + + /** + * Htmlize organization logo. + * + * @param organization + * the organization + * @param cache + * the cache + * @param htmlizeDirectory + * the htmlize directory + * @throws IOException + * Signals that an I/O exception has occurred. + */ + private static void htmlizeOrganizationLogo(final Organization organization, final CrawlCache cache, final File htmlizeDirectory) throws IOException + { + logger.info("Htmlize organization logo."); + + File target = new File(htmlizeDirectory, organization.getLogoFileName()); + + File logoFile = cache.restoreFile(organization.getLogoURL()); + if (logoFile == null) + { + logger.info("CatGeneratoring cat avatar: {}", target.getAbsoluteFile()); + CatGenerator.buildAvatarTo(organization.getTechnicalName(), target); + } + else + { + FileUtils.copyFile(logoFile, target); + } + } } diff --git a/src/fr/devinsy/statoolinfos/htmlize/PropertiesFilesPage.java b/src/fr/devinsy/statoolinfos/htmlize/PropertiesFilesPage.java index eeb4a07..7b6ea8d 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/PropertiesFilesPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/PropertiesFilesPage.java @@ -18,14 +18,23 @@ */ package fr.devinsy.statoolinfos.htmlize; +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.nio.charset.StandardCharsets; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.Locale; +import org.apache.commons.io.FileUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import fr.devinsy.statoolinfos.HtmlizerContext; +import fr.devinsy.statoolinfos.core.Federation; import fr.devinsy.statoolinfos.core.StatoolInfosException; +import fr.devinsy.statoolinfos.crawl.CrawlCache; +import fr.devinsy.statoolinfos.stats.StatAgent; import fr.devinsy.statoolinfos.stats.propertyfiles.PropertiesFileStat; import fr.devinsy.statoolinfos.stats.propertyfiles.PropertiesFileStats; import fr.devinsy.statoolinfos.util.BuildInformation; @@ -40,6 +49,25 @@ public class PropertiesFilesPage { private static Logger logger = LoggerFactory.getLogger(PropertiesFilesPage.class); + /** + * Builds the. + * + * @throws IOException + * @throws MalformedURLException + * @throws StatoolInfosException + */ + public static void build() throws MalformedURLException, IOException, StatoolInfosException + { + Federation federation = HtmlizerContext.instance().getFederation(); + CrawlCache cache = HtmlizerContext.instance().getCache(); + File htmlizeDirectory = HtmlizerContext.instance().getHtmlizeDirectory(); + + logger.info("Htmlize propertiesFiles page."); + PropertiesFileStats stats = StatAgent.statAllPropertiesFiles(federation, cache).sortByName(); + String page = PropertiesFilesPage.htmlize(stats); + FileUtils.write(new File(htmlizeDirectory, "propertiesFiles.xhtml"), page, StandardCharsets.UTF_8); + } + /** * Builds the. * @@ -49,7 +77,7 @@ public class PropertiesFilesPage * @throws StatoolInfosException * the statool infos exception */ - public static String build(final PropertiesFileStats stats) throws StatoolInfosException + public static String htmlize(final PropertiesFileStats stats) throws StatoolInfosException { String result; diff --git a/src/fr/devinsy/statoolinfos/htmlize/PropertyFileCheckPage.java b/src/fr/devinsy/statoolinfos/htmlize/PropertyFileCheckPage.java index e84c9b0..742a03d 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/PropertyFileCheckPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/PropertyFileCheckPage.java @@ -18,11 +18,21 @@ */ 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.HtmlizerContext; import fr.devinsy.statoolinfos.checker.PropertyCheck; +import fr.devinsy.statoolinfos.checker.PropertyChecker; import fr.devinsy.statoolinfos.checker.PropertyChecks; +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.xidyn.XidynException; import fr.devinsy.xidyn.data.TagDataManager; @@ -35,6 +45,38 @@ public class PropertyFileCheckPage { private static Logger logger = LoggerFactory.getLogger(PropertyFileCheckPage.class); + /** + * Builds the. + * + * @throws IOException + * @throws StatoolInfosException + */ + public static void buildAll() throws IOException, StatoolInfosException + { + Federation federation = HtmlizerContext.instance().getFederation(); + File htmlizeDirectory = HtmlizerContext.instance().getHtmlizeDirectory(); + + PropertyChecker checker = new PropertyChecker(); + + PropertyChecks checks = checker.checkFederation(federation.getInputFile()); + String page = PropertyFileCheckPage.htmlize("Fédération", checks); + FileUtils.write(new File(htmlizeDirectory, federation.getTechnicalName() + "-check.xhtml"), page, StandardCharsets.UTF_8); + + for (Organization organization : federation.getOrganizations()) + { + checks = checker.checkOrganization(organization.getInputFile()); + page = PropertyFileCheckPage.htmlize("Organisation", checks); + FileUtils.write(new File(htmlizeDirectory, organization.getTechnicalName() + "-check.xhtml"), page, StandardCharsets.UTF_8); + + for (Service service : organization.getServices()) + { + checks = checker.checkService(service.getInputFile()); + page = PropertyFileCheckPage.htmlize("Service", checks); + FileUtils.write(new File(htmlizeDirectory, organization.getTechnicalName() + "-" + service.getTechnicalName() + "-check.xhtml"), page, StandardCharsets.UTF_8); + } + } + } + /** * Builds the. * @@ -46,7 +88,7 @@ public class PropertyFileCheckPage * @throws StatoolInfosException * the statool infos exception */ - public static String build(final String title, final PropertyChecks checks) throws StatoolInfosException + public static String htmlize(final String title, final PropertyChecks checks) throws StatoolInfosException { String result; diff --git a/src/fr/devinsy/statoolinfos/htmlize/PropertyStatsPage.java b/src/fr/devinsy/statoolinfos/htmlize/PropertyStatsPage.java index d8053d9..4e563ee 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/PropertyStatsPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/PropertyStatsPage.java @@ -18,11 +18,20 @@ */ 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.HtmlizerContext; +import fr.devinsy.statoolinfos.core.Federation; import fr.devinsy.statoolinfos.core.StatoolInfosException; import fr.devinsy.statoolinfos.core.StatoolInfosUtils; +import fr.devinsy.statoolinfos.crawl.CrawlCache; +import fr.devinsy.statoolinfos.stats.StatAgent; import fr.devinsy.statoolinfos.stats.properties.PropertyStat; import fr.devinsy.statoolinfos.stats.properties.PropertyStatList; import fr.devinsy.statoolinfos.stats.properties.PropertyStats; @@ -37,6 +46,39 @@ public class PropertyStatsPage { private static Logger logger = LoggerFactory.getLogger(PropertyStatsPage.class); + /** + * Builds the. + * + * @throws StatoolInfosException + * the statool infos exception + * @throws IOException + * Signals that an I/O exception has occurred. + */ + public static void buildAll() throws StatoolInfosException, IOException + { + Federation federation = HtmlizerContext.instance().getFederation(); + CrawlCache cache = HtmlizerContext.instance().getCache(); + File htmlizeDirectory = HtmlizerContext.instance().getHtmlizeDirectory(); + + logger.info("Htmlize propertyStats page."); + + PropertyStats stats = StatAgent.statAllProperties(federation); + String page = PropertyStatsPage.htmlize("Toutes les propriétés", stats); + FileUtils.write(new File(htmlizeDirectory, "propertyStats.xhtml"), page, StandardCharsets.UTF_8); + + PropertyStats federationStats = StatAgent.statFederationProperties(federation); + page = PropertyStatsPage.htmlize("Les propriétés de la fédération", federationStats); + FileUtils.write(new File(htmlizeDirectory, "propertyStats-federation.xhtml"), page, StandardCharsets.UTF_8); + + PropertyStats organizationsStats = StatAgent.statOrganizationsProperties(federation.getOrganizations()); + page = PropertyStatsPage.htmlize("Les propriétés des organizations", organizationsStats); + FileUtils.write(new File(htmlizeDirectory, "propertyStats-organizations.xhtml"), page, StandardCharsets.UTF_8); + + PropertyStats servicesStats = StatAgent.statServicesProperties(federation.getAllServices()); + page = PropertyStatsPage.htmlize("Les propriétés des services", servicesStats); + FileUtils.write(new File(htmlizeDirectory, "propertyStats-services.xhtml"), page, StandardCharsets.UTF_8); + } + /** * Builds the. * @@ -48,7 +90,7 @@ public class PropertyStatsPage * @throws StatoolInfosException * the statool infos exception */ - public static String build(final String title, final PropertyStats stats) throws StatoolInfosException + public static String htmlize(final String title, final PropertyStats stats) throws StatoolInfosException { String result; diff --git a/src/fr/devinsy/statoolinfos/htmlize/ServicePage.java b/src/fr/devinsy/statoolinfos/htmlize/ServicePage.java index f19a9f0..9f76bd8 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/ServicePage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/ServicePage.java @@ -18,14 +18,22 @@ */ 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.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import fr.devinsy.catgenerator.core.BirdGenerator; +import fr.devinsy.statoolinfos.HtmlizerContext; import fr.devinsy.statoolinfos.core.Metric; import fr.devinsy.statoolinfos.core.Organization; import fr.devinsy.statoolinfos.core.Service; import fr.devinsy.statoolinfos.core.StatoolInfosException; +import fr.devinsy.statoolinfos.crawl.CrawlCache; import fr.devinsy.statoolinfos.htmlize.charts.BarMonthsChartView; import fr.devinsy.statoolinfos.htmlize.charts.ChartColors; import fr.devinsy.xidyn.XidynException; @@ -34,12 +42,54 @@ import fr.devinsy.xidyn.data.TagDataManager; import fr.devinsy.xidyn.presenters.PresenterUtils; /** - * The Class OrganizationPage. + * The Class ServicePage. */ public class ServicePage { private static Logger logger = LoggerFactory.getLogger(ServicePage.class); + /** + * Builds the view. + * + * @throws IOException + * @throws StatoolInfosException + */ + public static void build(final Service service) throws IOException, StatoolInfosException + { + CrawlCache cache = HtmlizerContext.instance().getCache(); + File htmlizeDirectory = HtmlizerContext.instance().getHtmlizeDirectory(); + + // Manage the logo file. + logger.info("Htmlize service logo: {}.", service.getName()); + htmlizeServiceLogo(service, cache, htmlizeDirectory); + + // + logger.info("Htmlize service properties file: {}.", service.getName()); + FileUtils.copyFile(service.getInputFile(), + new File(htmlizeDirectory, service.getOrganization().getTechnicalName() + "-" + service.getTechnicalName() + ".properties")); + + // + logger.info("Htmlize service page: {}.", service.getName()); + String page = ServicePage.htmlize(service.getOrganization(), service); + FileUtils.write(new File(htmlizeDirectory, service.getOrganization().getTechnicalName() + "-" + service.getTechnicalName() + ".xhtml"), page, StandardCharsets.UTF_8); + } + + /** + * Builds the all. + * + * @throws IOException + * Signals that an I/O exception has occurred. + * @throws StatoolInfosException + * the statool infos exception + */ + public static void buildAll() throws IOException, StatoolInfosException + { + for (Service service : HtmlizerContext.instance().getFederation().getAllServices()) + { + build(service); + } + } + /** * Builds the. * @@ -49,7 +99,7 @@ public class ServicePage * @throws StatoolInfosException * the statool infos exception */ - public static String build(final Organization organization, final Service service) throws StatoolInfosException + public static String htmlize(final Organization organization, final Service service) throws StatoolInfosException { String result; @@ -188,4 +238,28 @@ public class ServicePage // return result; } + + /** + * @param service + * @param cache + * @param htmlizeDirectory + * @throws IOException + */ + private static void htmlizeServiceLogo(final Service service, final CrawlCache cache, final File htmlizeDirectory) throws IOException + { + logger.info("Htmlize organization logo."); + + File target = new File(htmlizeDirectory, service.getLogoFileName()); + + File logoFile = cache.restoreFile(service.getLogoURL()); + if (logoFile == null) + { + logger.info("BirdGeneratoring cat avatar: {}", target.getAbsoluteFile()); + BirdGenerator.buildAvatarTo(service.getTechnicalName(), target); + } + else + { + FileUtils.copyFile(logoFile, target); + } + } } diff --git a/src/fr/devinsy/statoolinfos/htmlize/ServicesPage.java b/src/fr/devinsy/statoolinfos/htmlize/ServicesPage.java index 4d27759..f4b788a 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/ServicesPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/ServicesPage.java @@ -18,9 +18,16 @@ */ 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.HtmlizerContext; +import fr.devinsy.statoolinfos.core.Federation; import fr.devinsy.statoolinfos.core.Services; import fr.devinsy.statoolinfos.core.StatoolInfosException; import fr.devinsy.xidyn.XidynException; @@ -34,6 +41,22 @@ public class ServicesPage { private static Logger logger = LoggerFactory.getLogger(ServicesPage.class); + /** + * Builds the. + * + * @throws IOException + * @throws StatoolInfosException + */ + public static void build() throws IOException, StatoolInfosException + { + Federation federation = HtmlizerContext.instance().getFederation(); + File htmlizeDirectory = HtmlizerContext.instance().getHtmlizeDirectory(); + + logger.info("Htmlize services page."); + String page = ServicesPage.htmlize(federation.getAllServices()); + FileUtils.write(new File(htmlizeDirectory, "services.xhtml"), page, StandardCharsets.UTF_8); + } + /** * Builds the. * @@ -43,7 +66,7 @@ public class ServicesPage * @throws StatoolInfosException * the statool infos exception */ - public static String build(final Services services) throws StatoolInfosException + public static String htmlize(final Services services) throws StatoolInfosException { String result; diff --git a/src/fr/devinsy/statoolinfos/htmlize/SocialNetworksPage.java b/src/fr/devinsy/statoolinfos/htmlize/SocialNetworksPage.java index 5781be6..78cf234 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/SocialNetworksPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/SocialNetworksPage.java @@ -18,13 +18,22 @@ */ 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.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import fr.devinsy.statoolinfos.HtmlizerContext; +import fr.devinsy.statoolinfos.core.Federation; import fr.devinsy.statoolinfos.core.Organization; import fr.devinsy.statoolinfos.core.Organizations; +import fr.devinsy.statoolinfos.core.SocialNetworks; import fr.devinsy.statoolinfos.core.StatoolInfosException; +import fr.devinsy.statoolinfos.crawl.CrawlCache; import fr.devinsy.xidyn.XidynException; import fr.devinsy.xidyn.data.DisplayMode; import fr.devinsy.xidyn.data.TagDataManager; @@ -37,6 +46,32 @@ public class SocialNetworksPage { private static Logger logger = LoggerFactory.getLogger(SocialNetworksPage.class); + /** + * Builds the all. + * + * @throws StatoolInfosException + * @throws IOException + */ + public static void buildAll() throws StatoolInfosException, IOException + { + Federation federation = HtmlizerContext.instance().getFederation(); + CrawlCache cache = HtmlizerContext.instance().getCache(); + File htmlizeDirectory = HtmlizerContext.instance().getHtmlizeDirectory(); + + logger.info("Htmlize social networks pages."); + Organizations organizations = federation.getOrganizations().filterBySocialNetworks(); + String page = SocialNetworksPage.htmlize("Tous", organizations); + FileUtils.write(new File(htmlizeDirectory, "socialNetworks.xhtml"), page, StandardCharsets.UTF_8); + + organizations = federation.getOrganizations().filterBySocialNetwork(SocialNetworks.DIASPORA); + page = SocialNetworksPage.htmlize("Disapora*", organizations); + FileUtils.write(new File(htmlizeDirectory, "socialNetworks-diaspora.xhtml"), page, StandardCharsets.UTF_8); + + organizations = federation.getOrganizations().filterBySocialNetwork(SocialNetworks.MASTODON); + page = SocialNetworksPage.htmlize("Mastodon", organizations); + FileUtils.write(new File(htmlizeDirectory, "socialNetworks-mastodon.xhtml"), page, StandardCharsets.UTF_8); + } + /** * Builds the. * @@ -48,7 +83,7 @@ public class SocialNetworksPage * @throws StatoolInfosException * the statool infos exception */ - public static String build(final String title, final Organizations organizations) throws StatoolInfosException + public static String htmlize(final String title, final Organizations organizations) throws StatoolInfosException { String result; diff --git a/src/fr/devinsy/statoolinfos/htmlize/SoftwarePage.java b/src/fr/devinsy/statoolinfos/htmlize/SoftwarePage.java index 4fb7320..5a6109b 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/SoftwarePage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/SoftwarePage.java @@ -18,11 +18,19 @@ */ 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.HtmlizerContext; +import fr.devinsy.statoolinfos.core.Federation; import fr.devinsy.statoolinfos.core.Services; import fr.devinsy.statoolinfos.core.Software; +import fr.devinsy.statoolinfos.core.Softwares; import fr.devinsy.statoolinfos.core.StatoolInfosException; import fr.devinsy.xidyn.XidynException; import fr.devinsy.xidyn.data.TagDataManager; @@ -35,6 +43,27 @@ public class SoftwarePage { private static Logger logger = LoggerFactory.getLogger(SoftwarePage.class); + /** + * Builds the all. + * + * @throws StatoolInfosException + * @throws IOException + */ + public static void buildAll() throws StatoolInfosException, IOException + { + Federation federation = HtmlizerContext.instance().getFederation(); + File htmlizeDirectory = HtmlizerContext.instance().getHtmlizeDirectory(); + + logger.info("Htmlize software pages."); + Softwares catalog = federation.getSoftwares(); + for (Software software : catalog.values()) + { + Services services = federation.getAllServices().getBy(software); + String page = SoftwarePage.htmlize(software, services); + FileUtils.write(new File(htmlizeDirectory, "software-" + software.getTechnicalName() + ".xhtml"), page, StandardCharsets.UTF_8); + } + } + /** * Builds the. * @@ -46,7 +75,7 @@ public class SoftwarePage * @throws StatoolInfosException * the statool infos exception */ - public static String build(final Software software, final Services services) throws StatoolInfosException + public static String htmlize(final Software software, final Services services) throws StatoolInfosException { String result; diff --git a/src/fr/devinsy/statoolinfos/htmlize/SoftwaresPage.java b/src/fr/devinsy/statoolinfos/htmlize/SoftwaresPage.java index ac88b64..d79e446 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/SoftwaresPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/SoftwaresPage.java @@ -18,11 +18,20 @@ */ 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.HtmlizerContext; +import fr.devinsy.statoolinfos.core.Categories; +import fr.devinsy.statoolinfos.core.Federation; import fr.devinsy.statoolinfos.core.StatoolInfosException; import fr.devinsy.statoolinfos.htmlize.CategoriesView.Mode; +import fr.devinsy.statoolinfos.stats.StatAgent; import fr.devinsy.statoolinfos.stats.softwares.SoftwareStat; import fr.devinsy.statoolinfos.stats.softwares.SoftwareStats; import fr.devinsy.xidyn.XidynException; @@ -36,6 +45,24 @@ public class SoftwaresPage { private static Logger logger = LoggerFactory.getLogger(SoftwaresPage.class); + /** + * Builds the. + * + * @throws StatoolInfosException + * @throws IOException + */ + public static void build() throws StatoolInfosException, IOException + { + Federation federation = HtmlizerContext.instance().getFederation(); + File htmlizeDirectory = HtmlizerContext.instance().getHtmlizeDirectory(); + Categories categories = HtmlizerContext.instance().getCategories(); + + logger.info("Htmlize softwares page."); + SoftwareStats stats = StatAgent.statAllSoftwares(federation, categories); + String page = SoftwaresPage.htmlize(stats); + FileUtils.write(new File(htmlizeDirectory, "softwares.xhtml"), page, StandardCharsets.UTF_8); + } + /** * Builds the. * @@ -45,7 +72,7 @@ public class SoftwaresPage * @throws StatoolInfosException * the statool infos exception */ - public static String build(final SoftwareStats stats) throws StatoolInfosException + public static String htmlize(final SoftwareStats stats) throws StatoolInfosException { String result;