diff --git a/log4j.properties b/log4j.properties index 56336f4..8a18d37 100644 --- a/log4j.properties +++ b/log4j.properties @@ -3,7 +3,7 @@ # priority setting: DEBUG < INFO < WARN < ERROR log4j.rootLogger = DEBUG, console -log4j.logger.fr.devinsy.tatoolinfos = INFO +log4j.logger.fr.devinsy.statoolinfos = INFO log4j.logger.fr.devinsy.xidyn = WARN #-- diff --git a/resources/statoolinfos-logo-name.jpg b/resources/statoolinfos-logo-name.jpg new file mode 100644 index 0000000..ed3ead0 Binary files /dev/null and b/resources/statoolinfos-logo-name.jpg differ diff --git a/resources/statoolinfos-logo-sans.jpg b/resources/statoolinfos-logo-sans.jpg new file mode 100644 index 0000000..94a8a2f Binary files /dev/null and b/resources/statoolinfos-logo-sans.jpg differ diff --git a/resources/statoolinfos-logo.ico b/resources/statoolinfos-logo.ico new file mode 100644 index 0000000..eb85b69 Binary files /dev/null and b/resources/statoolinfos-logo.ico differ diff --git a/resources/statoolinfos-logo.jpg b/resources/statoolinfos-logo.jpg index ed3ead0..5d30f48 100644 Binary files a/resources/statoolinfos-logo.jpg and b/resources/statoolinfos-logo.jpg differ diff --git a/src/fr/devinsy/statoolinfos/cli/StatoolInfosCLI.java b/src/fr/devinsy/statoolinfos/cli/StatoolInfosCLI.java index f65e3ef..fb600de 100644 --- a/src/fr/devinsy/statoolinfos/cli/StatoolInfosCLI.java +++ b/src/fr/devinsy/statoolinfos/cli/StatoolInfosCLI.java @@ -101,8 +101,9 @@ public final class StatoolInfosCLI message.appendln("Usage:"); message.appendln(" statoolinfos [ -h | -help | --help ]"); message.appendln(" statoolinfos [ -v | -version | --version ]"); - message.appendln(" statoolinfos [ build | crawl | htmlize ] [ directory | file ]"); message.appendln(" statoolinfos clear [ directory | file ]"); + message.appendln(" statoolinfos crawl [ directory | file ]"); + message.appendln(" statoolinfos htmlize [ directory | file ]"); logger.info(message.toString()); } diff --git a/src/fr/devinsy/statoolinfos/core/CrawlCache.java b/src/fr/devinsy/statoolinfos/core/CrawlCache.java index 1963204..9119daa 100644 --- a/src/fr/devinsy/statoolinfos/core/CrawlCache.java +++ b/src/fr/devinsy/statoolinfos/core/CrawlCache.java @@ -20,8 +20,10 @@ package fr.devinsy.statoolinfos.core; import java.io.File; import java.io.IOException; +import java.net.URL; import org.apache.commons.codec.digest.DigestUtils; +import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -66,16 +68,18 @@ public class CrawlCache } } - private File buildFile(final String url, final String additionalName) + /** + * Builds the file. + * + * @param key + * the key + * @return the file + */ + private File buildFile(final String key) { File result; - result = new File(this.directory, DigestUtils.md5Hex(url) + additionalName); - - // result = new File(this.directory, DigestUtils.sha1Hex(url)); - // String normalizeUrl = StringUtils.removeAll(url, - // "^https*://").replace('/', '+'); - // result = new File(this.directory, normalizeUrl); + result = new File(this.directory, DigestUtils.md5Hex(key)); // return result; @@ -88,7 +92,7 @@ public class CrawlCache { for (File file : this.directory.listFiles()) { - if ((file.isFile()) && (file.getName().endsWith(".properties"))) + if ((file.isFile()) && ((file.getName().endsWith(".properties")) || file.getName().length() == 32)) { logger.info("Deleting " + file.getName()); file.delete(); @@ -97,7 +101,31 @@ public class CrawlCache } /** - * Load. + * Restore file. + * + * @param url + * the url + * @return the file + */ + public File restoreFile(final URL url) + { + File result; + + if (url == null) + { + throw new IllegalArgumentException("Null parameter."); + } + else + { + result = buildFile(url.toString()); + } + + // + return result; + } + + /** + * Restore properties. * * @param url * the url @@ -105,13 +133,46 @@ public class CrawlCache * @throws IOException * Signals that an I/O exception has occurred. */ - public PathPropertyList load(final String url) throws IOException + public PathPropertyList restoreProperties(final URL url) throws IOException { PathPropertyList result; - File file = buildFile(url, ".properties"); + if (url == null) + { + result = new PathPropertyList(); + } + else + { + File file = buildFile(url.toString() + ".properties"); + result = PathPropertyUtils.load(file); + } - result = PathPropertyUtils.load(file); + // + return result; + } + + /** + * Store. + * + * @param url + * the url + * @return the file + * @throws IOException + */ + public File store(final URL url) throws IOException + { + File result; + + if (StringUtils.startsWith(url.getProtocol(), "http")) + { + final int TIMEOUT = 5000; + result = restoreFile(url); + FileUtils.copyURLToFile(url, result, TIMEOUT, TIMEOUT); + } + else + { + result = null; + } // return result; @@ -128,18 +189,53 @@ public class CrawlCache * @throws IOException * Signals that an I/O exception has occurred. */ - public File store(final String url, final PathPropertyList properties) throws IOException + public File storeProperties(final URL url, final PathPropertyList properties) throws IOException { File result; - if (StringUtils.startsWith(url, "http")) + if ((url == null) || (!StringUtils.startsWith(url.getProtocol(), "http"))) { - result = buildFile(url, ".properties"); - - PathPropertyUtils.save(result, properties); + result = null; } else { + String key = url.toString() + ".properties"; + result = buildFile(key); + + PathPropertyUtils.save(result, properties); + } + + // + return result; + } + + /** + * Store quietly. + * + * @param url + * the url + * @return the file + */ + public File storeQuietly(final URL url) + { + File result; + + try + { + if ((url == null) || (!StringUtils.startsWith(url.getProtocol(), "http"))) + { + result = null; + } + else + { + final int TIMEOUT = 5000; + result = restoreFile(url); + FileUtils.copyURLToFile(url, result, TIMEOUT, TIMEOUT); + } + } + catch (IOException exception) + { + logger.info("Store faile for {}: {}", url, exception.getMessage()); result = null; } diff --git a/src/fr/devinsy/statoolinfos/core/Factory.java b/src/fr/devinsy/statoolinfos/core/Factory.java index 9623c45..5cee9d4 100644 --- a/src/fr/devinsy/statoolinfos/core/Factory.java +++ b/src/fr/devinsy/statoolinfos/core/Factory.java @@ -61,16 +61,14 @@ public class Factory result = new Federation(properties); - PathPropertyList section = result.getByPrefix("subs"); - for (PathProperty property : section) + PathPropertyList subs = result.getByPrefix("subs"); + for (PathProperty property : subs) { if (StringUtils.startsWith(property.getValue(), "http")) { - URL url = new URL(property.getValue()); + PathPropertyList subProperties = cache.restoreProperties(new URL(property.getValue())); - PathPropertyList subProperties = cache.load(property.getValue()); - - Organization organization = loadOrganization(subProperties); + Organization organization = loadOrganization(subProperties, cache); result.getOrganizations().add(organization); } } @@ -122,7 +120,7 @@ public class Factory { if (StringUtils.startsWith(property.getValue(), "http")) { - PathPropertyList subProperties = cache.load(property.getValue()); + PathPropertyList subProperties = cache.restoreProperties(new URL(property.getValue())); Service service = loadService(subProperties); result.getServices().add(service); diff --git a/src/fr/devinsy/statoolinfos/core/Federation.java b/src/fr/devinsy/statoolinfos/core/Federation.java index 92df723..eb84153 100644 --- a/src/fr/devinsy/statoolinfos/core/Federation.java +++ b/src/fr/devinsy/statoolinfos/core/Federation.java @@ -18,6 +18,8 @@ */ package fr.devinsy.statoolinfos.core; +import org.apache.commons.lang3.StringUtils; + import fr.devinsy.statoolinfos.properties.PathPropertyList; /** @@ -33,7 +35,8 @@ public class Federation extends PathPropertyList */ public Federation() { - super(null); + super(); + this.organizations = new Organizations(); } /** @@ -45,7 +48,15 @@ public class Federation extends PathPropertyList public Federation(final PathPropertyList properties) { super(properties); - this.organizations = new Organizations(); + + if ((properties == null) || (StringUtils.isBlank(properties.get("federation.name")))) + { + throw new IllegalArgumentException("Not a federation."); + } + else + { + this.organizations = new Organizations(); + } } /** @@ -72,7 +83,7 @@ public class Federation extends PathPropertyList { String result; - result = get("service.name"); + result = get("federation.name"); // return result; @@ -82,4 +93,19 @@ public class Federation extends PathPropertyList { return this.organizations; } + + /** + * Gets the technical name. + * + * @return the technical name + */ + public String getTechnicalName() + { + String result; + + result = StatoolInfosUtils.buildTechnicalName(getName()); + + // + return result; + } } diff --git a/src/fr/devinsy/statoolinfos/core/Organization.java b/src/fr/devinsy/statoolinfos/core/Organization.java index 206afee..a2a5565 100644 --- a/src/fr/devinsy/statoolinfos/core/Organization.java +++ b/src/fr/devinsy/statoolinfos/core/Organization.java @@ -18,6 +18,8 @@ */ package fr.devinsy.statoolinfos.core; +import org.apache.commons.lang3.StringUtils; + import fr.devinsy.statoolinfos.properties.PathPropertyList; /** @@ -33,7 +35,8 @@ public class Organization extends PathPropertyList */ public Organization() { - super(null); + super(); + this.services = new Services(); } /** @@ -45,7 +48,15 @@ public class Organization extends PathPropertyList public Organization(final PathPropertyList properties) { super(properties); - this.services = new Services(); + + if ((properties == null) || (StringUtils.isBlank(properties.get("organization.name")))) + { + throw new IllegalArgumentException("Not an organization."); + } + else + { + this.services = new Services(); + } } public String getDescription() @@ -87,7 +98,22 @@ public class Organization extends PathPropertyList { String result; - result = getName().toLowerCase().replace("[^a-z_0-9]", ""); + result = StatoolInfosUtils.buildTechnicalName(getName()); + + // + return result; + } + + /** + * Gets the website. + * + * @return the website + */ + public String getWebsite() + { + String result; + + result = get("organization.website"); // return result; diff --git a/src/fr/devinsy/statoolinfos/core/Service.java b/src/fr/devinsy/statoolinfos/core/Service.java index 633100d..d62b314 100644 --- a/src/fr/devinsy/statoolinfos/core/Service.java +++ b/src/fr/devinsy/statoolinfos/core/Service.java @@ -87,11 +87,26 @@ public class Service extends PathPropertyList } /** - * Gets the url. + * Gets the technical name. * - * @return the url + * @return the technical name */ - public String getURL() + public String getTechnicalName() + { + String result; + + result = StatoolInfosUtils.buildTechnicalName(getName()); + + // + return result; + } + + /** + * Gets the website. + * + * @return the website + */ + public String getWebsite() { String result; diff --git a/src/fr/devinsy/statoolinfos/core/StatoolInfos.java b/src/fr/devinsy/statoolinfos/core/StatoolInfos.java index f0750bc..ae553c1 100644 --- a/src/fr/devinsy/statoolinfos/core/StatoolInfos.java +++ b/src/fr/devinsy/statoolinfos/core/StatoolInfos.java @@ -21,15 +21,13 @@ package fr.devinsy.statoolinfos.core; import java.io.File; import java.io.IOException; import java.net.URL; -import java.nio.charset.StandardCharsets; import java.time.LocalDateTime; -import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import fr.devinsy.statoolinfos.htmlize.OrganizationPage; +import fr.devinsy.statoolinfos.htmlize.Htmlizer; import fr.devinsy.statoolinfos.properties.PathProperty; import fr.devinsy.statoolinfos.properties.PathPropertyList; import fr.devinsy.statoolinfos.properties.PathPropertyUtils; @@ -174,8 +172,8 @@ public class StatoolInfos logger.info("Cache setting: {}", configuration.get("conf.crawl.cache")); CrawlCache cache = new CrawlCache(new File(crawlCachePath)); - PathPropertyList section = configuration.getByPrefix("subs"); - for (PathProperty property : section) + PathPropertyList subs = configuration.getByPrefix("subs"); + for (PathProperty property : subs) { URL url = new URL(property.getValue()); crawl(url, cache); @@ -196,23 +194,28 @@ public class StatoolInfos */ public static void crawl(final URL url, final CrawlCache cache) throws StatoolInfosException, IOException { - PathPropertyList inputProperties = PathPropertyUtils.load(url); - logger.info("Crawling " + url); - PathPropertyList target = PathPropertyUtils.load(url); + File file = cache.store(url); + PathPropertyList properties = PathPropertyUtils.load(file); PathPropertyList crawlSection = new PathPropertyList(); crawlSection.put("crawl.crawler", "StatoolInfos"); crawlSection.put("crawl.datetime", LocalDateTime.now().toString()); crawlSection.put("crawl.url", url.toString()); - target.addAll(crawlSection); + properties.addAll(crawlSection); + cache.storeProperties(url, properties); - cache.store(url.toString(), target); + cache.storeQuietly(properties.getURL("federation.logo")); + cache.storeQuietly(properties.getURL("federation.logo.url")); + cache.storeQuietly(properties.getURL("organization.logo")); + cache.storeQuietly(properties.getURL("organization.logo.url")); + cache.storeQuietly(properties.getURL("service.logo")); + cache.storeQuietly(properties.getURL("service.logo.url")); // - PathPropertyList section = inputProperties.getByPrefix("subs"); - for (PathProperty property : section) + PathPropertyList subs = properties.getByPrefix("subs"); + for (PathProperty property : subs) { URL subUrl = new URL(property.getValue()); crawl(subUrl, cache); @@ -237,94 +240,21 @@ public class StatoolInfos if (StringUtils.equals(className, "federation")) { Federation federation = Factory.loadFederation(properties); - htmlizeFederation(federation); + Htmlizer.htmlize(federation); } else if (StringUtils.equals(className, "organization")) { Organization organization = Factory.loadOrganization(properties); - htmlizeOrganization(organization); + Htmlizer.htmlize(organization); } else if (StringUtils.equals(className, "service")) { Service service = Factory.loadService(properties); - htmlizeService(service); + Htmlizer.htmlize(service); } else { // TODO } } - - /** - * Htmlize federation. - * - * @param federation - * the federation - * @param cache - * the cache - */ - private static void htmlizeFederation(final PathPropertyList federation) - { - - } - - /** - * Htmlize organization. - * - * @param federation - * the federation - * @param targetDirectory - * the target directory - * @throws IOException - * @throws StatoolInfosException - */ - private static void htmlizeOrganization(final Organization organization) throws IOException, StatoolInfosException - { - 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 - { - // Copy commons files (index, images, favicon, css…). - if (!new File(targetDirectory, "index.html").exists()) - { - FileUtils.copyURLToFile(StatoolInfos.class.getResource("/fr/devinsy/statoolinfos/htmlize/stuff/index.html"), new File(targetDirectory, "index.html")); - FileUtils.copyURLToFile(StatoolInfos.class.getResource("/fr/devinsy/statoolinfos/htmlize/stuff/statoolinfos.css"), new File(targetDirectory, "statoolinfos.css")); - FileUtils.copyURLToFile(StatoolInfos.class.getResource("/fr/devinsy/statoolinfos/htmlize/stuff/Chart.bundle.min.js"), new File(targetDirectory, "Chart.bundle.min.js")); - } - - // - String page = OrganizationPage.build(organization); - FileUtils.write(new File(targetDirectory, organization.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 service. - * - * @param federation - * the federation - */ - private static void htmlizeService(final PathPropertyList federation) - { - - } } diff --git a/src/fr/devinsy/statoolinfos/core/StatoolInfosUtils.java b/src/fr/devinsy/statoolinfos/core/StatoolInfosUtils.java index 96951e4..f16c06e 100644 --- a/src/fr/devinsy/statoolinfos/core/StatoolInfosUtils.java +++ b/src/fr/devinsy/statoolinfos/core/StatoolInfosUtils.java @@ -34,6 +34,7 @@ import javax.net.ssl.TrustManager; import javax.net.ssl.X509TrustManager; import org.apache.commons.io.FileUtils; +import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.math.NumberUtils; import org.slf4j.Logger; @@ -52,6 +53,55 @@ public class StatoolInfosUtils public static final DateTimeFormatter PATTERN_SHORTDATE = DateTimeFormatter.ofPattern("dd/MM/yyyy", Locale.FRANCE); public static final DateTimeFormatter PATTERN_LONGDATE = DateTimeFormatter.ofPattern("dd/MM/yyyy HH':'mm", Locale.FRANCE); + /** + * Builds the technical name. + * + * @return the string + */ + public static String buildTechnicalName(final String source) + { + String result; + + if (source == null) + { + result = null; + } + else + { + result = source.toLowerCase().replaceAll("[^a-z_0-9]", ""); + } + + // + return result; + } + + /** + * Copy ressource. + * + * @param source + * the source + * @param target + * the target directory + * @throws IOException + */ + public static void copyRessource(final String source, final File target) throws IOException + { + URL url = StatoolInfosUtils.class.getResource(source); + + File finalTarget; + if (target.isDirectory()) + { + String fileName = FilenameUtils.getName(source); + finalTarget = new File(target, fileName); + } + else + { + finalTarget = target; + } + + FileUtils.copyURLToFile(url, finalTarget); + } + /** * Generate cat logo. * diff --git a/src/fr/devinsy/statoolinfos/htmlize/FederationPage.java b/src/fr/devinsy/statoolinfos/htmlize/FederationPage.java new file mode 100644 index 0000000..62136bf --- /dev/null +++ b/src/fr/devinsy/statoolinfos/htmlize/FederationPage.java @@ -0,0 +1,90 @@ +/* + * 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.htmlize; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.Locale; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import fr.devinsy.statoolinfos.core.Federation; +import fr.devinsy.statoolinfos.core.Organization; +import fr.devinsy.statoolinfos.core.StatoolInfosException; +import fr.devinsy.xidyn.XidynException; +import fr.devinsy.xidyn.data.TagDataManager; +import fr.devinsy.xidyn.presenters.PresenterUtils; +import utils.BuildInformation; + +/** + * The Class OrganizationPage. + */ +public class FederationPage +{ + private static Logger logger = LoggerFactory.getLogger(FederationPage.class); + + /** + * Builds the. + * + * @param federation + * the organization + * @return the string + * @throws StatoolInfosException + * the statool infos exception + */ + public static String build(final Federation federation) throws StatoolInfosException + { + String result; + + try + { + logger.debug("Building federation page {}…", federation.getName()); + + TagDataManager data = new TagDataManager(); + + data.setContent("versionsup", BuildInformation.instance().version()); + data.setContent("lastUpdateDate", LocalDateTime.now().format(DateTimeFormatter.ofPattern("dd/MM/yyyy HH':'mm", Locale.FRANCE))); + + data.setEscapedContent("federationName", federation.getName()); + data.setEscapedContent("federationDescription", federation.getDescription()); + data.setContent("organizationCount", federation.getOrganizations().size()); + + int index = 0; + for (Organization organization : federation.getOrganizations()) + { + data.setEscapedContent("organizationListLine", index, "organizationListLineNameLink", organization.getName()); + data.setAttribute("organizationListLine", index, "organizationListLineNameLink", "href", organization.getTechnicalName() + ".xhtml"); + data.setEscapedContent("organizationListLine", index, "organizationListLineUrlLink", organization.getWebsite()); + data.setAttribute("organizationListLine", index, "organizationListLineUrlLink", "href", organization.getWebsite()); + + index += 1; + } + + result = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/federation.xhtml", data).toString(); + } + catch (XidynException exception) + { + throw new StatoolInfosException("Error building federation page: " + exception.getMessage(), exception); + } + + // + return result; + } +} diff --git a/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java b/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java new file mode 100644 index 0000000..edd3add --- /dev/null +++ b/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java @@ -0,0 +1,188 @@ +/* + * 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.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.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 htmlize(final Federation federation) throws IOException, StatoolInfosException + { + 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); + + // + 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 + */ + public static void htmlize(final Organization organization) throws IOException, StatoolInfosException + { + 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. + } + } + + /** + * Htmlize. + * + * @param service + * the service + */ + public static void htmlize(final Service service) + { + + } +} diff --git a/src/fr/devinsy/statoolinfos/htmlize/OrganizationPage.java b/src/fr/devinsy/statoolinfos/htmlize/OrganizationPage.java index 133e72c..cad1e91 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/OrganizationPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/OrganizationPage.java @@ -69,9 +69,10 @@ public class OrganizationPage int index = 0; for (Service service : organization.getServices()) { - data.setEscapedContent("serviceListLine", index, "serviceListLineName", service.getName()); - data.setEscapedContent("serviceListLine", index, "serviceListLineUrlLink", service.getURL()); - data.setAttribute("serviceListLine", index, "serviceListLineUrlLink", "href", service.getURL()); + data.setEscapedContent("serviceListLine", index, "serviceListLineNameLink", service.getName()); + data.setAttribute("serviceListLine", index, "serviceListLineNameLink", "href", organization.getTechnicalName() + "-" + service.getTechnicalName() + ".xhtml"); + data.setEscapedContent("serviceListLine", index, "serviceListLineWebsiteLink", service.getWebsite()); + data.setAttribute("serviceListLine", index, "serviceListLineWebsiteLink", "href", service.getWebsite()); data.setEscapedContent("serviceListLine", index, "serviceListLineSoftware", service.getSoftware()); index += 1; diff --git a/src/fr/devinsy/statoolinfos/htmlize/ServicePage.java b/src/fr/devinsy/statoolinfos/htmlize/ServicePage.java new file mode 100644 index 0000000..90ee6d8 --- /dev/null +++ b/src/fr/devinsy/statoolinfos/htmlize/ServicePage.java @@ -0,0 +1,95 @@ +/* + * 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.htmlize; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.Locale; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import fr.devinsy.statoolinfos.core.Service; +import fr.devinsy.statoolinfos.core.StatoolInfosException; +import fr.devinsy.xidyn.XidynException; +import fr.devinsy.xidyn.data.TagDataManager; +import fr.devinsy.xidyn.presenters.PresenterUtils; +import utils.BuildInformation; + +/** + * The Class OrganizationPage. + */ +public class ServicePage +{ + private static Logger logger = LoggerFactory.getLogger(ServicePage.class); + + /** + * Builds the. + * + * @param service + * the service + * @return the string + * @throws StatoolInfosException + * the statool infos exception + */ + public static String build(final Service service) throws StatoolInfosException + { + String result; + + try + { + logger.debug("Building organization page {}…", service.get("organization.name")); + + TagDataManager data = new TagDataManager(); + + data.setContent("versionsup", BuildInformation.instance().version()); + data.setContent("lastUpdateDate", LocalDateTime.now().format(DateTimeFormatter.ofPattern("dd/MM/yyyy HH':'mm", Locale.FRANCE))); + + data.setEscapedContent("serviceName", service.getName()); + data.setEscapedContent("serviceDescription", service.getDescription()); + + // int index = 0; + // for (Service service : service.getServices()) + // { + // data.setEscapedContent("serviceListLine", index, + // "serviceListLineNameLink", service.getName()); + // data.setAttribute("serviceListLine", index, + // "serviceListLineNameLink", "href", service.getTechnicalName() + + // ".xhtml"); + // data.setEscapedContent("serviceListLine", index, + // "serviceListLineUrlLink", service.getURL()); + // data.setAttribute("serviceListLine", index, + // "serviceListLineUrlLink", "href", service.getURL()); + // data.setEscapedContent("serviceListLine", index, + // "serviceListLineSoftware", service.getSoftware()); + // + // index += 1; + // } + + result = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/service.xhtml", data).toString(); + } + catch (XidynException exception) + { + throw new StatoolInfosException("Error building service page: " + exception.getMessage(), exception); + } + + // + return result; + } +} diff --git a/src/fr/devinsy/statoolinfos/htmlize/federation.xhtml b/src/fr/devinsy/statoolinfos/htmlize/federation.xhtml new file mode 100644 index 0000000..c77af55 --- /dev/null +++ b/src/fr/devinsy/statoolinfos/htmlize/federation.xhtml @@ -0,0 +1,38 @@ + + + + + StatoolInfos + + + + + + + +
+

StatoolInfosv0.0.14AboutPage updated on
xx/xx/xxxx xx:xx

+ + + +

Federation name

+

Bla bla description

+
Nombre de membres : n/a
+
+ + + + + + + + + +
Nom du membreURL
n/an/a
+
+
+ + diff --git a/src/fr/devinsy/statoolinfos/htmlize/organization.xhtml b/src/fr/devinsy/statoolinfos/htmlize/organization.xhtml index 09702bb..19f5633 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/organization.xhtml +++ b/src/fr/devinsy/statoolinfos/htmlize/organization.xhtml @@ -4,7 +4,7 @@ StatoolInfos - + + + +
+

StatoolInfosv0.0.14AboutPage updated on
xx/xx/xxxx xx:xx

+ +

Service name

+

Bla bla description

+
 
+
+ + + + + + + + + + + +
Nom du serviceURLLogiciel
n/an/an/a
+
+ +
+ + diff --git a/src/fr/devinsy/statoolinfos/htmlize/stuff/about.xhtml b/src/fr/devinsy/statoolinfos/htmlize/stuff/about.xhtml new file mode 100644 index 0000000..fa09f0d --- /dev/null +++ b/src/fr/devinsy/statoolinfos/htmlize/stuff/about.xhtml @@ -0,0 +1,29 @@ + + + + + StatoolInfos + + + + + + + +
+

StatoolInfosAboutPage updated on
xx/xx/xxxx xx:xx

+ +

Introduction

+

StatoolInfos is a simple tool of statistics about federation, organizations and services.

+ +

License and source repository

+

The original author of StatoolInfos is Christian P. MOMON.

+

StatoolInfo is a free software released under the GNU AGPL license.

+

The official source repository is:

+ +
+ + diff --git a/src/fr/devinsy/statoolinfos/htmlize/stuff/statoolinfos-logo-name.jpg b/src/fr/devinsy/statoolinfos/htmlize/stuff/statoolinfos-logo-name.jpg new file mode 100644 index 0000000..ed3ead0 Binary files /dev/null and b/src/fr/devinsy/statoolinfos/htmlize/stuff/statoolinfos-logo-name.jpg differ diff --git a/src/fr/devinsy/statoolinfos/htmlize/stuff/statoolinfos-logo.ico b/src/fr/devinsy/statoolinfos/htmlize/stuff/statoolinfos-logo.ico new file mode 100644 index 0000000..eb85b69 Binary files /dev/null and b/src/fr/devinsy/statoolinfos/htmlize/stuff/statoolinfos-logo.ico differ diff --git a/src/fr/devinsy/statoolinfos/htmlize/stuff/statoolinfos-logo.jpg b/src/fr/devinsy/statoolinfos/htmlize/stuff/statoolinfos-logo.jpg new file mode 100644 index 0000000..5d30f48 Binary files /dev/null and b/src/fr/devinsy/statoolinfos/htmlize/stuff/statoolinfos-logo.jpg differ diff --git a/src/fr/devinsy/statoolinfos/properties/PathProperties.java b/src/fr/devinsy/statoolinfos/properties/PathProperties.java index 3eedbc3..342fff1 100644 --- a/src/fr/devinsy/statoolinfos/properties/PathProperties.java +++ b/src/fr/devinsy/statoolinfos/properties/PathProperties.java @@ -18,6 +18,9 @@ */ package fr.devinsy.statoolinfos.properties; +import java.net.MalformedURLException; +import java.net.URL; + import fr.devinsy.strings.StringList; import fr.devinsy.strings.StringSet; @@ -74,6 +77,15 @@ public interface PathProperties */ PathProperty getProperty(final String path); + /** + * Gets the url. + * + * @param path + * the path + * @return the url + */ + public URL getURL(String path) throws MalformedURLException; + /** * Put. * diff --git a/src/fr/devinsy/statoolinfos/properties/PathProperty.java b/src/fr/devinsy/statoolinfos/properties/PathProperty.java index 5017c36..645f9ac 100644 --- a/src/fr/devinsy/statoolinfos/properties/PathProperty.java +++ b/src/fr/devinsy/statoolinfos/properties/PathProperty.java @@ -89,7 +89,7 @@ public class PathProperty { String result; - result = "(" + this.path + "," + this.value + ")"; + result = "[" + this.path + "=" + this.value + "]"; // return result; diff --git a/src/fr/devinsy/statoolinfos/properties/PathPropertyList.java b/src/fr/devinsy/statoolinfos/properties/PathPropertyList.java index 943dbd8..9072e81 100644 --- a/src/fr/devinsy/statoolinfos/properties/PathPropertyList.java +++ b/src/fr/devinsy/statoolinfos/properties/PathPropertyList.java @@ -18,6 +18,8 @@ */ package fr.devinsy.statoolinfos.properties; +import java.net.MalformedURLException; +import java.net.URL; import java.util.ArrayList; import java.util.Iterator; @@ -298,6 +300,33 @@ public class PathPropertyList extends ArrayList implements PathPro return result; } + /** + * Gets the url. + * + * @param path + * the path + * @return the url + * @throws MalformedURLException + */ + @Override + public URL getURL(final String path) throws MalformedURLException + { + URL result; + + String value = get(path); + if ((path == null) || (!StringUtils.startsWith(value, "http"))) + { + result = null; + } + else + { + result = new URL(value); + } + + // + return result; + } + /** * Put. *