Step in htmlize dev. Refactored CrawlCache.

This commit is contained in:
Christian P. MOMON 2020-09-17 02:03:56 +02:00
parent fddef5ad76
commit 1d49fd1871
27 changed files with 796 additions and 131 deletions

View file

@ -3,7 +3,7 @@
# priority setting: DEBUG < INFO < WARN < ERROR # priority setting: DEBUG < INFO < WARN < ERROR
log4j.rootLogger = DEBUG, console log4j.rootLogger = DEBUG, console
log4j.logger.fr.devinsy.tatoolinfos = INFO log4j.logger.fr.devinsy.statoolinfos = INFO
log4j.logger.fr.devinsy.xidyn = WARN log4j.logger.fr.devinsy.xidyn = WARN
#-- #--

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 15 KiB

View file

@ -101,8 +101,9 @@ public final class StatoolInfosCLI
message.appendln("Usage:"); message.appendln("Usage:");
message.appendln(" statoolinfos [ -h | -help | --help ]"); message.appendln(" statoolinfos [ -h | -help | --help ]");
message.appendln(" statoolinfos [ -v | -version | --version ]"); message.appendln(" statoolinfos [ -v | -version | --version ]");
message.appendln(" statoolinfos [ build | crawl | htmlize ] [ directory | file ]");
message.appendln(" statoolinfos clear [ directory | file ]"); message.appendln(" statoolinfos clear [ directory | file ]");
message.appendln(" statoolinfos crawl [ directory | file ]");
message.appendln(" statoolinfos htmlize [ directory | file ]");
logger.info(message.toString()); logger.info(message.toString());
} }

View file

@ -20,8 +20,10 @@ package fr.devinsy.statoolinfos.core;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.URL;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; 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; File result;
result = new File(this.directory, DigestUtils.md5Hex(url) + additionalName); result = new File(this.directory, DigestUtils.md5Hex(key));
// result = new File(this.directory, DigestUtils.sha1Hex(url));
// String normalizeUrl = StringUtils.removeAll(url,
// "^https*://").replace('/', '+');
// result = new File(this.directory, normalizeUrl);
// //
return result; return result;
@ -88,7 +92,7 @@ public class CrawlCache
{ {
for (File file : this.directory.listFiles()) 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()); logger.info("Deleting " + file.getName());
file.delete(); 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 * @param url
* the url * the url
@ -105,13 +133,46 @@ public class CrawlCache
* @throws IOException * @throws IOException
* Signals that an I/O exception has occurred. * 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; 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; return result;
@ -128,18 +189,53 @@ public class CrawlCache
* @throws IOException * @throws IOException
* Signals that an I/O exception has occurred. * 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; File result;
if (StringUtils.startsWith(url, "http")) if ((url == null) || (!StringUtils.startsWith(url.getProtocol(), "http")))
{ {
result = buildFile(url, ".properties"); result = null;
PathPropertyUtils.save(result, properties);
} }
else 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; result = null;
} }

View file

@ -61,16 +61,14 @@ public class Factory
result = new Federation(properties); result = new Federation(properties);
PathPropertyList section = result.getByPrefix("subs"); PathPropertyList subs = result.getByPrefix("subs");
for (PathProperty property : section) for (PathProperty property : subs)
{ {
if (StringUtils.startsWith(property.getValue(), "http")) 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, cache);
Organization organization = loadOrganization(subProperties);
result.getOrganizations().add(organization); result.getOrganizations().add(organization);
} }
} }
@ -122,7 +120,7 @@ public class Factory
{ {
if (StringUtils.startsWith(property.getValue(), "http")) if (StringUtils.startsWith(property.getValue(), "http"))
{ {
PathPropertyList subProperties = cache.load(property.getValue()); PathPropertyList subProperties = cache.restoreProperties(new URL(property.getValue()));
Service service = loadService(subProperties); Service service = loadService(subProperties);
result.getServices().add(service); result.getServices().add(service);

View file

@ -18,6 +18,8 @@
*/ */
package fr.devinsy.statoolinfos.core; package fr.devinsy.statoolinfos.core;
import org.apache.commons.lang3.StringUtils;
import fr.devinsy.statoolinfos.properties.PathPropertyList; import fr.devinsy.statoolinfos.properties.PathPropertyList;
/** /**
@ -33,7 +35,8 @@ public class Federation extends PathPropertyList
*/ */
public Federation() public Federation()
{ {
super(null); super();
this.organizations = new Organizations();
} }
/** /**
@ -45,7 +48,15 @@ public class Federation extends PathPropertyList
public Federation(final PathPropertyList properties) public Federation(final PathPropertyList properties)
{ {
super(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; String result;
result = get("service.name"); result = get("federation.name");
// //
return result; return result;
@ -82,4 +93,19 @@ public class Federation extends PathPropertyList
{ {
return this.organizations; return this.organizations;
} }
/**
* Gets the technical name.
*
* @return the technical name
*/
public String getTechnicalName()
{
String result;
result = StatoolInfosUtils.buildTechnicalName(getName());
//
return result;
}
} }

View file

@ -18,6 +18,8 @@
*/ */
package fr.devinsy.statoolinfos.core; package fr.devinsy.statoolinfos.core;
import org.apache.commons.lang3.StringUtils;
import fr.devinsy.statoolinfos.properties.PathPropertyList; import fr.devinsy.statoolinfos.properties.PathPropertyList;
/** /**
@ -33,7 +35,8 @@ public class Organization extends PathPropertyList
*/ */
public Organization() public Organization()
{ {
super(null); super();
this.services = new Services();
} }
/** /**
@ -45,7 +48,15 @@ public class Organization extends PathPropertyList
public Organization(final PathPropertyList properties) public Organization(final PathPropertyList properties)
{ {
super(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() public String getDescription()
@ -87,7 +98,22 @@ public class Organization extends PathPropertyList
{ {
String result; 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; return result;

View file

@ -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; String result;

View file

@ -21,15 +21,13 @@ package fr.devinsy.statoolinfos.core;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; 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.PathProperty;
import fr.devinsy.statoolinfos.properties.PathPropertyList; import fr.devinsy.statoolinfos.properties.PathPropertyList;
import fr.devinsy.statoolinfos.properties.PathPropertyUtils; import fr.devinsy.statoolinfos.properties.PathPropertyUtils;
@ -174,8 +172,8 @@ public class StatoolInfos
logger.info("Cache setting: {}", configuration.get("conf.crawl.cache")); logger.info("Cache setting: {}", configuration.get("conf.crawl.cache"));
CrawlCache cache = new CrawlCache(new File(crawlCachePath)); CrawlCache cache = new CrawlCache(new File(crawlCachePath));
PathPropertyList section = configuration.getByPrefix("subs"); PathPropertyList subs = configuration.getByPrefix("subs");
for (PathProperty property : section) for (PathProperty property : subs)
{ {
URL url = new URL(property.getValue()); URL url = new URL(property.getValue());
crawl(url, cache); crawl(url, cache);
@ -196,23 +194,28 @@ public class StatoolInfos
*/ */
public static void crawl(final URL url, final CrawlCache cache) throws StatoolInfosException, IOException public static void crawl(final URL url, final CrawlCache cache) throws StatoolInfosException, IOException
{ {
PathPropertyList inputProperties = PathPropertyUtils.load(url);
logger.info("Crawling " + url); logger.info("Crawling " + url);
PathPropertyList target = PathPropertyUtils.load(url); File file = cache.store(url);
PathPropertyList properties = PathPropertyUtils.load(file);
PathPropertyList crawlSection = new PathPropertyList(); PathPropertyList crawlSection = new PathPropertyList();
crawlSection.put("crawl.crawler", "StatoolInfos"); crawlSection.put("crawl.crawler", "StatoolInfos");
crawlSection.put("crawl.datetime", LocalDateTime.now().toString()); crawlSection.put("crawl.datetime", LocalDateTime.now().toString());
crawlSection.put("crawl.url", url.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"); PathPropertyList subs = properties.getByPrefix("subs");
for (PathProperty property : section) for (PathProperty property : subs)
{ {
URL subUrl = new URL(property.getValue()); URL subUrl = new URL(property.getValue());
crawl(subUrl, cache); crawl(subUrl, cache);
@ -237,94 +240,21 @@ public class StatoolInfos
if (StringUtils.equals(className, "federation")) if (StringUtils.equals(className, "federation"))
{ {
Federation federation = Factory.loadFederation(properties); Federation federation = Factory.loadFederation(properties);
htmlizeFederation(federation); Htmlizer.htmlize(federation);
} }
else if (StringUtils.equals(className, "organization")) else if (StringUtils.equals(className, "organization"))
{ {
Organization organization = Factory.loadOrganization(properties); Organization organization = Factory.loadOrganization(properties);
htmlizeOrganization(organization); Htmlizer.htmlize(organization);
} }
else if (StringUtils.equals(className, "service")) else if (StringUtils.equals(className, "service"))
{ {
Service service = Factory.loadService(properties); Service service = Factory.loadService(properties);
htmlizeService(service); Htmlizer.htmlize(service);
} }
else else
{ {
// TODO // 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)
{
}
} }

View file

@ -34,6 +34,7 @@ import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager; import javax.net.ssl.X509TrustManager;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils; import org.apache.commons.lang3.math.NumberUtils;
import org.slf4j.Logger; 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_SHORTDATE = DateTimeFormatter.ofPattern("dd/MM/yyyy", Locale.FRANCE);
public static final DateTimeFormatter PATTERN_LONGDATE = DateTimeFormatter.ofPattern("dd/MM/yyyy HH':'mm", 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. * Generate cat logo.
* *

View file

@ -0,0 +1,90 @@
/*
* Copyright (C) 2020 Christian Pierre MOMON <christian@momon.org>
*
* This file is part of StatoolInfos, simple service statistics tool.
*
* StatoolInfos is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* StatoolInfos is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with StatoolInfos. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.devinsy.statoolinfos.htmlize;
import java.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;
}
}

View file

@ -0,0 +1,188 @@
/*
* Copyright (C) 2020 Christian Pierre MOMON <christian@momon.org>
*
* This file is part of StatoolInfos, simple service statistics tool.
*
* StatoolInfos is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* StatoolInfos is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with StatoolInfos. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.devinsy.statoolinfos.htmlize;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.devinsy.statoolinfos.core.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)
{
}
}

View file

@ -69,9 +69,10 @@ public class OrganizationPage
int index = 0; int index = 0;
for (Service service : organization.getServices()) for (Service service : organization.getServices())
{ {
data.setEscapedContent("serviceListLine", index, "serviceListLineName", service.getName()); data.setEscapedContent("serviceListLine", index, "serviceListLineNameLink", service.getName());
data.setEscapedContent("serviceListLine", index, "serviceListLineUrlLink", service.getURL()); data.setAttribute("serviceListLine", index, "serviceListLineNameLink", "href", organization.getTechnicalName() + "-" + service.getTechnicalName() + ".xhtml");
data.setAttribute("serviceListLine", index, "serviceListLineUrlLink", "href", service.getURL()); data.setEscapedContent("serviceListLine", index, "serviceListLineWebsiteLink", service.getWebsite());
data.setAttribute("serviceListLine", index, "serviceListLineWebsiteLink", "href", service.getWebsite());
data.setEscapedContent("serviceListLine", index, "serviceListLineSoftware", service.getSoftware()); data.setEscapedContent("serviceListLine", index, "serviceListLineSoftware", service.getSoftware());
index += 1; index += 1;

View file

@ -0,0 +1,95 @@
/*
* Copyright (C) 2020 Christian Pierre MOMON <christian@momon.org>
*
* This file is part of StatoolInfos, simple service statistics tool.
*
* StatoolInfos is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* StatoolInfos is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with StatoolInfos. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.devinsy.statoolinfos.htmlize;
import java.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;
}
}

View file

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>StatoolInfos</title>
<meta charset="UTF-8" />
<meta name="keywords" content="statoolinfos,devinsy,federation" />
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
<link rel="stylesheet" type="text/css" href="statoolinfos.css" />
<script src="sorttable.js" />
<script src="Chart.bundle.min.js"></script>
</head>
<body>
<div style="margin: 5px 10px 10px 10px;">
<h1><a href="index.xhtml"><img src="logo.jpg" style="width: 35px;"/> StatoolInfos</a><sup id="versionsup" style="font-size: 9px;">v0.0.14</sup> <a href="about.xhtml">About</a><span style="font-size: 9px; float: right;">Page updated on<br/><span id="lastUpdateDate" style="font-size: 9px;">xx/xx/xxxx xx:xx</span></span></h1>
<div style="margin: 5px;">
<a id="federationRawButton" href="#" class="button">Raw properties</a>
</div>
<h2 id="federationName">Federation name</h2>
<p id="federationDescription">Bla bla description</p>
<div>Nombre de membres : <span id="organizationCount">n/a</span></div>
<div>
<table class="table_classic">
<tr>
<th class="">Nom du membre</th>
<th class="">URL</th>
</tr>
<tr id="organizationListLine">
<td id="organizationListLineName"><a href="#" id="organizationListLineNameLink">n/a</a></td>
<td id="organizationListLineUrl"><a href="#" id="organizationListLineUrlLink">n/a</a></td>
</tr>
</table>
</div>
</div>
</body>
</html>

View file

@ -4,7 +4,7 @@
<head> <head>
<title>StatoolInfos</title> <title>StatoolInfos</title>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta content="statoolinfos" name="keywords" /> <meta name="keywords" content="statoolinfos,devinsy,federation" />
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" /> <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
<link rel="stylesheet" type="text/css" href="statoolinfos.css" /> <link rel="stylesheet" type="text/css" href="statoolinfos.css" />
<script src="sorttable.js" /> <script src="sorttable.js" />
@ -12,7 +12,11 @@
</head> </head>
<body> <body>
<div style="margin: 5px 10px 10px 10px;"> <div style="margin: 5px 10px 10px 10px;">
<h1><a href="index.xhtml">StatoolInfos</a><sup id="versionsup" style="font-size: 9px;">v0.0.14</sup> <a href="about.xhtml">About</a><span style="font-size: 9px; float: right;">Page updated on<br/><span id="lastUpdateDate" style="font-size: 9px;">xx/xx/xxxx xx:xx</span></span></h1> <h1><a href="index.xhtml"><img src="logo.jpg" style="width: 35px;"/> StatoolInfos</a><sup id="versionsup" style="font-size: 9px;">v0.0.14</sup> <a href="about.xhtml">About</a><span style="font-size: 9px; float: right;">Page updated on<br/><span id="lastUpdateDate" style="font-size: 9px;">xx/xx/xxxx xx:xx</span></span></h1>
<div style="margin: 5px;">
<a id="organizationRawButton" href="#" class="button">Raw properties</a>
</div>
<h2 id="organizationName">Organization name</h2> <h2 id="organizationName">Organization name</h2>
<p id="organizationDescription">Bla bla description</p> <p id="organizationDescription">Bla bla description</p>
@ -25,8 +29,8 @@
<th class="">Logiciel</th> <th class="">Logiciel</th>
</tr> </tr>
<tr id="serviceListLine"> <tr id="serviceListLine">
<td id="serviceListLineName">n/a</td> <td id="serviceListLineName"><a href="#" id="serviceListLineNameLink">n/a</a></td>
<td id="serviceListLineUrl"><a href="#" id="serviceListLineUrlLink">n/a</a></td> <td id="serviceListLineWebsite"><a href="#" id="serviceListLineWebsiteLink">n/a</a></td>
<td id="serviceListLineSoftware">n/a</td> <td id="serviceListLineSoftware">n/a</td>
</tr> </tr>
</table> </table>

View file

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>StatoolInfos</title>
<meta charset="UTF-8" />
<meta name="keywords" content="statoolinfos,devinsy,federation" />
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
<link rel="stylesheet" type="text/css" href="statoolinfos.css" />
<script src="sorttable.js" />
<script src="Chart.bundle.min.js"></script>
</head>
<body>
<div style="margin: 5px 10px 10px 10px;">
<h1><a href="index.xhtml"><img src="logo.jpg" style="width: 35px;"/> StatoolInfos</a><sup id="versionsup" style="font-size: 9px;">v0.0.14</sup> <a href="about.xhtml">About</a><span style="font-size: 9px; float: right;">Page updated on<br/><span id="lastUpdateDate" style="font-size: 9px;">xx/xx/xxxx xx:xx</span></span></h1>
<h2 id="serviceName">Service name</h2>
<p id="serviceDescription">Bla bla description</p>
<div>&#160;</div>
<div>
<table class="table_classic">
<tr>
<th class="">Nom du service</th>
<th class="">URL</th>
<th class="">Logiciel</th>
</tr>
<tr id="serviceListLine">
<td id="serviceListLineName"><a href="#" id="serviceListLineNameLink">n/a</a></td>
<td id="serviceListLineUrl"><a href="#" id="serviceListLineUrlLink">n/a</a></td>
<td id="serviceListLineSoftware">n/a</td>
</tr>
</table>
</div>
</div>
</body>
</html>

View file

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>StatoolInfos</title>
<meta charset="UTF-8" />
<meta name="keywords" content="statoolinfos,devinsy,federation" />
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
<link rel="stylesheet" type="text/css" href="statoolinfos.css" />
<script src="sorttable.js" />
<script src="Chart.bundle.min.js"></script>
</head>
<body>
<div style="margin: 5px 10px 10px 10px;">
<h1><a href="index.xhtml"><img src="logo.jpg" style="width: 35px;"/> StatoolInfos</a> <a href="about.xhtml">About</a><span style="font-size: 9px; float: right;">Page updated on<br/><span id="lastUpdateDate" style="font-size: 9px;">xx/xx/xxxx xx:xx</span></span></h1>
<h2>Introduction</h2>
<p>StatoolInfos is a simple tool of statistics about federation, organizations and services.</p>
<h2>License and source repository</h2>
<p>The original author of StatoolInfos is Christian P. MOMON.</p>
<p>StatoolInfo is a free software released under the GNU AGPL license.</p>
<p>The official source repository is:</p>
<ul>
<li><a href="https://forge.devinsy.fr/devinsy/statoolinfos">https://forge.devinsy.fr/devinsy/statoolinfos</a></li>
</ul>
</div>
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View file

@ -18,6 +18,9 @@
*/ */
package fr.devinsy.statoolinfos.properties; package fr.devinsy.statoolinfos.properties;
import java.net.MalformedURLException;
import java.net.URL;
import fr.devinsy.strings.StringList; import fr.devinsy.strings.StringList;
import fr.devinsy.strings.StringSet; import fr.devinsy.strings.StringSet;
@ -74,6 +77,15 @@ public interface PathProperties
*/ */
PathProperty getProperty(final String path); PathProperty getProperty(final String path);
/**
* Gets the url.
*
* @param path
* the path
* @return the url
*/
public URL getURL(String path) throws MalformedURLException;
/** /**
* Put. * Put.
* *

View file

@ -89,7 +89,7 @@ public class PathProperty
{ {
String result; String result;
result = "(" + this.path + "," + this.value + ")"; result = "[" + this.path + "=" + this.value + "]";
// //
return result; return result;

View file

@ -18,6 +18,8 @@
*/ */
package fr.devinsy.statoolinfos.properties; package fr.devinsy.statoolinfos.properties;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
@ -298,6 +300,33 @@ public class PathPropertyList extends ArrayList<PathProperty> implements PathPro
return result; 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. * Put.
* *