diff --git a/src/fr/devinsy/statoolinfos/core/CrawlCache.java b/src/fr/devinsy/statoolinfos/core/CrawlCache.java index cd163c5..4373d35 100644 --- a/src/fr/devinsy/statoolinfos/core/CrawlCache.java +++ b/src/fr/devinsy/statoolinfos/core/CrawlCache.java @@ -119,12 +119,68 @@ public class CrawlCache else { result = buildFile(url.toString()); + if (!result.exists()) + { + result = null; + } } // return result; } + /** + * Restore file to. + * + * @param url + * the url + * @param target + * the target + * @throws IOException + * Signals that an I/O exception has occurred. + */ + public void restoreFileTo(final URL url, final File target) throws IOException + { + if (url != null) + { + File logoFile = restoreFile(url); + if (logoFile != null) + { + FileUtils.copyFile(logoFile, target); + } + } + } + + /** + * Restore file to. + * + * @param url + * the url + * @param targetDirectory + * the target directory + * @throws IOException + * Signals that an I/O exception has occurred. + */ + public void restoreLogoTo(final URL url, final File target) throws IOException + { + if (url == null) + { + StatoolInfosUtils.generateCatLogo(target.getName(), target); + } + else + { + File logoFile = restoreFile(url); + if (logoFile == null) + { + StatoolInfosUtils.generateCatLogo(target.getName(), target); + } + else + { + FileUtils.copyFile(logoFile, target); + } + } + } + /** * Restore properties. * @@ -167,7 +223,7 @@ public class CrawlCache if (StringUtils.startsWith(url.getProtocol(), "http")) { final int TIMEOUT = 5000; - result = restoreFile(url); + result = buildFile(url.toString()); FileUtils.copyURLToFile(url, result, TIMEOUT, TIMEOUT); } else @@ -230,8 +286,9 @@ public class CrawlCache else { final int TIMEOUT = 5000; - result = restoreFile(url); + result = buildFile(url.toString()); FileUtils.copyURLToFile(url, result, TIMEOUT, TIMEOUT); + logger.info("Crawled {}", url); } } catch (IOException exception) diff --git a/src/fr/devinsy/statoolinfos/core/Factory.java b/src/fr/devinsy/statoolinfos/core/Factory.java index 45b2581..867ead1 100644 --- a/src/fr/devinsy/statoolinfos/core/Factory.java +++ b/src/fr/devinsy/statoolinfos/core/Factory.java @@ -66,7 +66,9 @@ public class Factory { if (StringUtils.startsWith(property.getValue(), "http")) { - PathProperties subProperties = cache.restoreProperties(new URL(property.getValue())); + URL url = new URL(property.getValue()); + result.setLocalFile(cache.restoreFile(url)); + PathProperties subProperties = cache.restoreProperties(url); Organization organization = loadOrganization(subProperties, cache); result.getOrganizations().add(organization); diff --git a/src/fr/devinsy/statoolinfos/core/Federation.java b/src/fr/devinsy/statoolinfos/core/Federation.java index ef6d1c1..4eb7cf7 100644 --- a/src/fr/devinsy/statoolinfos/core/Federation.java +++ b/src/fr/devinsy/statoolinfos/core/Federation.java @@ -18,6 +18,10 @@ */ package fr.devinsy.statoolinfos.core; +import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; + import org.apache.commons.lang3.StringUtils; import fr.devinsy.statoolinfos.properties.PathProperties; @@ -30,6 +34,7 @@ public class Federation extends PathPropertyList { private static final long serialVersionUID = -8970835291634661580L; private Organizations organizations; + private File localFile; /** * Instantiates a new federation. @@ -69,7 +74,36 @@ public class Federation extends PathPropertyList { String result; - result = get("service.description"); + result = get("federation.description"); + + // + return result; + } + + public File getLocalFile() + { + return this.localFile; + } + + /** + * Gets the logo URL. + * + * @return the logo URL + * @throws MalformedURLException + */ + public URL getLogoURL() throws MalformedURLException + { + URL result; + + String path = get("federation.logo"); + if ((StringUtils.isBlank(path)) || (!StringUtils.startsWith(path, "http"))) + { + result = null; + } + else + { + result = new URL(path); + } // return result; @@ -109,4 +143,9 @@ public class Federation extends PathPropertyList // return result; } + + public void setLocalFile(final File localFile) + { + this.localFile = localFile; + } } diff --git a/src/fr/devinsy/statoolinfos/core/Service.java b/src/fr/devinsy/statoolinfos/core/Service.java index fb1e2a4..9bb6520 100644 --- a/src/fr/devinsy/statoolinfos/core/Service.java +++ b/src/fr/devinsy/statoolinfos/core/Service.java @@ -111,7 +111,7 @@ public class Service extends PathPropertyList { String result; - result = get("service.website.url"); + result = get("service.website"); // return result; diff --git a/src/fr/devinsy/statoolinfos/core/StatoolInfos.java b/src/fr/devinsy/statoolinfos/core/StatoolInfos.java index 530d7b2..31751ff 100644 --- a/src/fr/devinsy/statoolinfos/core/StatoolInfos.java +++ b/src/fr/devinsy/statoolinfos/core/StatoolInfos.java @@ -172,6 +172,13 @@ public class StatoolInfos logger.info("Cache setting: {}", configuration.get("conf.crawl.cache")); CrawlCache cache = new CrawlCache(new File(crawlCachePath)); + cache.storeQuietly(configuration.getURL("federation.logo")); + cache.storeQuietly(configuration.getURL("federation.logo.url")); + cache.storeQuietly(configuration.getURL("organization.logo")); + cache.storeQuietly(configuration.getURL("organization.logo.url")); + cache.storeQuietly(configuration.getURL("service.logo")); + cache.storeQuietly(configuration.getURL("service.logo.url")); + PathProperties subs = configuration.getByPrefix("subs"); for (PathProperty property : subs) { @@ -236,21 +243,20 @@ public class StatoolInfos { PathProperties properties = PathPropertyUtils.load(input); + String crawlCachePath = properties.get("conf.crawl.cache"); + logger.info("Cache setting: {}", properties.get("conf.crawl.cache")); + CrawlCache cache = new CrawlCache(new File(crawlCachePath)); + String className = properties.get("conf.class"); if (StringUtils.equals(className, "federation")) { Federation federation = Factory.loadFederation(properties); - Htmlizer.htmlize(federation); + Htmlizer.htmlize(federation, cache); } else if (StringUtils.equals(className, "organization")) { Organization organization = Factory.loadOrganization(properties); - Htmlizer.htmlize(organization); - } - else if (StringUtils.equals(className, "service")) - { - Service service = Factory.loadService(properties); - Htmlizer.htmlize(service); + Htmlizer.htmlize(organization, cache); } else { diff --git a/src/fr/devinsy/statoolinfos/core/StatoolInfosUtils.java b/src/fr/devinsy/statoolinfos/core/StatoolInfosUtils.java index f16c06e..3ea7d16 100644 --- a/src/fr/devinsy/statoolinfos/core/StatoolInfosUtils.java +++ b/src/fr/devinsy/statoolinfos/core/StatoolInfosUtils.java @@ -116,7 +116,7 @@ public class StatoolInfosUtils { URL source = new URL("https://www.peppercarrot.com/extras/html/2016_cat-generator/avatar.php?seed=" + seed); - FileUtils.copyURLToFile(source, target); + FileUtils.copyURLToFile(source, target, 5000, 5000); } /** diff --git a/src/fr/devinsy/statoolinfos/htmlize/FederationPage.java b/src/fr/devinsy/statoolinfos/htmlize/FederationPage.java index 62136bf..3b977d1 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/FederationPage.java +++ b/src/fr/devinsy/statoolinfos/htmlize/FederationPage.java @@ -62,9 +62,11 @@ public class FederationPage data.setContent("versionsup", BuildInformation.instance().version()); data.setContent("lastUpdateDate", LocalDateTime.now().format(DateTimeFormatter.ofPattern("dd/MM/yyyy HH':'mm", Locale.FRANCE))); + data.setAttribute("federationLogo", "src", federation.getTechnicalName() + "-logo.jpg"); data.setEscapedContent("federationName", federation.getName()); data.setEscapedContent("federationDescription", federation.getDescription()); data.setContent("organizationCount", federation.getOrganizations().size()); + data.setAttribute("federationRawButton", "href", federation.getTechnicalName() + "-origin.properties"); int index = 0; for (Organization organization : federation.getOrganizations()) diff --git a/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java b/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java index edd3add..29562b1 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java +++ b/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java @@ -26,6 +26,7 @@ import org.apache.commons.io.FileUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import fr.devinsy.statoolinfos.core.CrawlCache; import fr.devinsy.statoolinfos.core.Federation; import fr.devinsy.statoolinfos.core.Organization; import fr.devinsy.statoolinfos.core.Service; @@ -81,7 +82,7 @@ public class Htmlizer * @throws IOException * @throws StatoolInfosException */ - public static void htmlize(final Federation federation) throws IOException, StatoolInfosException + public static void htmlize(final Federation federation, final CrawlCache cache) throws IOException, StatoolInfosException { File targetDirectory = new File(federation.get("conf.htmlize.directory")); logger.info("Htmlize target directory: {}", targetDirectory.getAbsoluteFile()); @@ -97,6 +98,7 @@ public class Htmlizer else { copyStuff(targetDirectory); + cache.restoreLogoTo(federation.getLogoURL(), new File(targetDirectory, federation.getTechnicalName() + "-logo.jpg")); // String page = FederationPage.build(federation); @@ -136,7 +138,7 @@ public class Htmlizer * @throws IOException * @throws StatoolInfosException */ - public static void htmlize(final Organization organization) throws IOException, StatoolInfosException + public static void htmlize(final Organization organization, final CrawlCache cache) throws IOException, StatoolInfosException { File targetDirectory = new File(organization.get("conf.htmlize.directory")); logger.info("Htmlize target directory: {}", targetDirectory.getAbsoluteFile()); @@ -174,15 +176,4 @@ public class Htmlizer // Build service page. } } - - /** - * Htmlize. - * - * @param service - * the service - */ - public static void htmlize(final Service service) - { - - } } diff --git a/src/fr/devinsy/statoolinfos/htmlize/federation.xhtml b/src/fr/devinsy/statoolinfos/htmlize/federation.xhtml index c77af55..c1bcbbd 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/federation.xhtml +++ b/src/fr/devinsy/statoolinfos/htmlize/federation.xhtml @@ -14,11 +14,8 @@
Bla bla description
Bla bla description