diff --git a/.classpath b/.classpath
index 2f6c669..1eb27be 100644
--- a/.classpath
+++ b/.classpath
@@ -24,5 +24,6 @@
+
diff --git a/lib/tika-core-1.24.1-sources.jar b/lib/tika-core-1.24.1-sources.jar
new file mode 100644
index 0000000..f33c6b5
Binary files /dev/null and b/lib/tika-core-1.24.1-sources.jar differ
diff --git a/lib/tika-core-1.24.1.jar b/lib/tika-core-1.24.1.jar
new file mode 100644
index 0000000..54edcb0
Binary files /dev/null and b/lib/tika-core-1.24.1.jar differ
diff --git a/src/fr/devinsy/statoolinfos/core/Factory.java b/src/fr/devinsy/statoolinfos/core/Factory.java
index 03906cb..de18d98 100644
--- a/src/fr/devinsy/statoolinfos/core/Factory.java
+++ b/src/fr/devinsy/statoolinfos/core/Factory.java
@@ -164,6 +164,7 @@ public class Factory
PathProperties properties = PathPropertyUtils.load(federationFile);
result = new Federation(properties);
result.setInputFile(federationFile);
+ result.setLogoFileName(result.getTechnicalName() + "-logo" + StringUtils.defaultIfBlank(cache.getExtension(result.getLogoURL()), ".png"));
PathProperties subs = result.getByPrefix("subs");
for (PathProperty property : subs)
@@ -236,6 +237,7 @@ public class Factory
result = new Organization(properties);
result.setInputFile(inputFile);
result.setInputURL(inputURL);
+ result.setLogoFileName(result.getTechnicalName() + "-logo" + StringUtils.defaultIfBlank(cache.getExtension(result.getLogoURL()), ".png"));
PathProperties subs = result.getByPrefix("subs");
for (PathProperty property : subs)
@@ -245,6 +247,7 @@ public class Factory
URL serviceInputURL = new URL(property.getValue());
Service service = loadService(serviceInputURL, cache);
service.setOrganization(result);
+ result.setLogoFileName(result.getTechnicalName() + "-" + result.getLogoFileName());
result.getServices().add(service);
}
}
@@ -269,6 +272,7 @@ public class Factory
result = new Service(properties);
result.setInputFile(inputFile);
result.setInputURL(inputURL);
+ result.setLogoFileName(result.getTechnicalName() + "-logo" + StringUtils.defaultIfBlank(cache.getExtension(result.getLogoURL()), ".png"));
//
return result;
diff --git a/src/fr/devinsy/statoolinfos/core/Federation.java b/src/fr/devinsy/statoolinfos/core/Federation.java
index ed9e74a..64049e9 100644
--- a/src/fr/devinsy/statoolinfos/core/Federation.java
+++ b/src/fr/devinsy/statoolinfos/core/Federation.java
@@ -36,6 +36,7 @@ public class Federation extends PathPropertyList
private static final long serialVersionUID = -8970835291634661580L;
private Organizations organizations;
private File inputFile;
+ private String logoFileName;
/**
* Instantiates a new federation.
@@ -63,6 +64,7 @@ public class Federation extends PathPropertyList
else
{
this.organizations = new Organizations();
+
}
}
@@ -166,6 +168,11 @@ public class Federation extends PathPropertyList
return result;
}
+ public String getLogoFileName()
+ {
+ return this.logoFileName;
+ }
+
/**
* Gets the logo URL.
*
@@ -352,8 +359,19 @@ public class Federation extends PathPropertyList
return result;
}
+ /**
+ * Sets the input file.
+ *
+ * @param inputFile
+ * the new input file
+ */
public void setInputFile(final File inputFile)
{
this.inputFile = inputFile;
}
+
+ public void setLogoFileName(final String logoFileName)
+ {
+ this.logoFileName = logoFileName;
+ }
}
diff --git a/src/fr/devinsy/statoolinfos/core/Organization.java b/src/fr/devinsy/statoolinfos/core/Organization.java
index d6974bb..e1f9949 100644
--- a/src/fr/devinsy/statoolinfos/core/Organization.java
+++ b/src/fr/devinsy/statoolinfos/core/Organization.java
@@ -38,6 +38,7 @@ public class Organization extends PathPropertyList
private Services services;
private File inputFile;
private URL inputURL;
+ private String logoFileName;
/**
* Instantiates a new organization.
@@ -208,6 +209,21 @@ public class Organization extends PathPropertyList
return result;
}
+ /**
+ * Gets the logo file name.
+ *
+ * @return the logo file name
+ */
+ public String getLogoFileName()
+ {
+ String result;
+
+ result = this.logoFileName;
+
+ //
+ return result;
+ }
+
/**
* Gets the logo URL.
*
@@ -491,4 +507,9 @@ public class Organization extends PathPropertyList
{
this.inputURL = inputURL;
}
+
+ public void setLogoFileName(final String logoFileName)
+ {
+ this.logoFileName = logoFileName;
+ }
}
diff --git a/src/fr/devinsy/statoolinfos/core/Service.java b/src/fr/devinsy/statoolinfos/core/Service.java
index 254948c..c39f06b 100644
--- a/src/fr/devinsy/statoolinfos/core/Service.java
+++ b/src/fr/devinsy/statoolinfos/core/Service.java
@@ -25,6 +25,7 @@ import java.time.LocalDateTime;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.RegExUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
@@ -56,8 +57,8 @@ public class Service extends PathPropertyList
private Organization organization;
private File inputFile;
-
private URL inputURL;
+ private String logoFileName;
/**
* Instantiates a new service.
@@ -188,6 +189,11 @@ public class Service extends PathPropertyList
return result;
}
+ public String getLogoFileName()
+ {
+ return this.logoFileName;
+ }
+
/**
* Gets the logo URL.
*
@@ -293,6 +299,12 @@ public class Service extends PathPropertyList
result = get("service.name");
+ if (StringUtils.isBlank(result))
+ {
+ String seed = get("crawl.url");
+ result = DigestUtils.md5Hex(seed).substring(0, 8);
+ }
+
//
return result;
}
@@ -653,6 +665,11 @@ public class Service extends PathPropertyList
this.inputURL = inputURL;
}
+ public void setLogoFileName(final String logoFileName)
+ {
+ this.logoFileName = logoFileName;
+ }
+
public void setOrganization(final Organization organization)
{
this.organization = organization;
diff --git a/src/fr/devinsy/statoolinfos/core/StatoolInfosUtils.java b/src/fr/devinsy/statoolinfos/core/StatoolInfosUtils.java
index c36ff9e..2cb87be 100644
--- a/src/fr/devinsy/statoolinfos/core/StatoolInfosUtils.java
+++ b/src/fr/devinsy/statoolinfos/core/StatoolInfosUtils.java
@@ -40,6 +40,10 @@ 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.apache.tika.Tika;
+import org.apache.tika.mime.MimeType;
+import org.apache.tika.mime.MimeTypeException;
+import org.apache.tika.mime.MimeTypes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -119,6 +123,34 @@ public class StatoolInfosUtils
return result;
}
+ /**
+ * Find extension.
+ *
+ * @param file
+ * the file
+ * @return the string
+ */
+ public static String findExtension(final File file)
+ {
+ String result;
+
+ try
+ {
+ Tika tika = new Tika();
+ String mimeTypeLabel = tika.detect(file);
+ MimeType mimeType = MimeTypes.getDefaultMimeTypes().forName(mimeTypeLabel);
+ result = mimeType.getExtension();
+ }
+ catch (IOException | MimeTypeException exception)
+ {
+ exception.printStackTrace();
+ result = "";
+ }
+
+ //
+ return result;
+ }
+
/**
* Generate cat logo.
*
diff --git a/src/fr/devinsy/statoolinfos/crawl/CrawlCache.java b/src/fr/devinsy/statoolinfos/crawl/CrawlCache.java
index c72d106..9014361 100644
--- a/src/fr/devinsy/statoolinfos/crawl/CrawlCache.java
+++ b/src/fr/devinsy/statoolinfos/crawl/CrawlCache.java
@@ -111,6 +111,31 @@ public class CrawlCache
}
}
+ /**
+ * Gets the extension.
+ *
+ * @param url
+ * the url
+ * @return the extension
+ */
+ public String getExtension(final URL url)
+ {
+ String result;
+
+ File file = restoreFile(url);
+ if (file == null)
+ {
+ result = null;
+ }
+ else
+ {
+ result = StatoolInfosUtils.findExtension(file);
+ }
+
+ //
+ return result;
+ }
+
/**
* Restore file.
*
@@ -124,7 +149,7 @@ public class CrawlCache
if (StringUtils.isBlank(key))
{
- throw new IllegalArgumentException("Null parameter.");
+ result = null;
}
else
{
@@ -150,7 +175,14 @@ public class CrawlCache
{
File result;
- result = restoreFile(url.toString());
+ if (url == null)
+ {
+ result = null;
+ }
+ else
+ {
+ result = restoreFile(url.toString());
+ }
//
return result;
@@ -417,7 +449,7 @@ public class CrawlCache
try
{
- if ((url == null) || (!StringUtils.startsWith(url.getProtocol(), "http")))
+ if ((url == null) || (!StringUtils.startsWithIgnoreCase(url.getProtocol(), "http")))
{
result = null;
}
diff --git a/src/fr/devinsy/statoolinfos/crawl/Crawler.java b/src/fr/devinsy/statoolinfos/crawl/Crawler.java
index fe35a31..ae9a3ed 100644
--- a/src/fr/devinsy/statoolinfos/crawl/Crawler.java
+++ b/src/fr/devinsy/statoolinfos/crawl/Crawler.java
@@ -100,7 +100,7 @@ public class Crawler
cache.store(input.get("federation.name"), configuration.getCrawlInputFile());
cache.storeQuietly(input.getURL("federation.logo"));
}
- else
+ else if (configuration.isOrganization())
{
cache.store(input.get("organization.name"), configuration.getCrawlInputFile());
cache.storeQuietly(input.getURL("organization.logo"));
diff --git a/src/fr/devinsy/statoolinfos/htmlize/FederationPage.java b/src/fr/devinsy/statoolinfos/htmlize/FederationPage.java
index fe9c53c..cc1acbb 100644
--- a/src/fr/devinsy/statoolinfos/htmlize/FederationPage.java
+++ b/src/fr/devinsy/statoolinfos/htmlize/FederationPage.java
@@ -57,7 +57,7 @@ public class FederationPage
TagDataManager data = new TagDataManager();
data.setAttribute("federationRawButton", "href", federation.getTechnicalName() + ".properties");
- data.setAttribute("federationLogo", "src", federation.getTechnicalName() + "-logo.png");
+ data.setAttribute("federationLogo", "src", federation.getLogoFileName());
data.setEscapedContent("federationName", federation.getName());
data.setEscapedContent("federationDescription", federation.getDescription());
@@ -106,7 +106,7 @@ public class FederationPage
for (Organization organization : federation.getOrganizations().sortByReverseServiceCount())
{
data.setAttribute("organizationListLine", index, "organizationListLineNameLink", "href", organization.getTechnicalName() + ".xhtml");
- data.setAttribute("organizationListLine", index, "organizationListLineLogo", "src", organization.getTechnicalName() + "-logo.png");
+ data.setAttribute("organizationListLine", index, "organizationListLineLogo", "src", organization.getLogoFileName());
data.setAttribute("organizationListLine", index, "organizationListLineLogo", "alt", organization.getName());
data.setEscapedContent("organizationListLine", index, "organizationListLineNameValue", organization.getName());
diff --git a/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java b/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java
index 87e9f0b..d4228ce 100644
--- a/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java
+++ b/src/fr/devinsy/statoolinfos/htmlize/Htmlizer.java
@@ -27,6 +27,8 @@ 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;
@@ -315,7 +317,7 @@ public class Htmlizer
// Manage the logo file.
logger.info("Htmlize federation logo.");
- cache.restoreLogoTo(federation.getLogoURL(), new File(htmlizeDirectory, federation.getTechnicalName() + "-logo.png"), federation.getTechnicalName(), DefaultLogoGenerator.CAT);
+ htmlizeFederationLogo(federation, cache, htmlizeDirectory);
logger.info("Htmlize federation properties files.");
FileUtils.copyFile(federation.getInputFile(), new File(htmlizeDirectory, federation.getTechnicalName() + ".properties"));
@@ -333,7 +335,7 @@ public class Htmlizer
{
// Manage the logo file.
logger.info("Htmlize organization logo: {}.", organization.getName());
- cache.restoreLogoTo(organization.getLogoURL(), new File(htmlizeDirectory, organization.getTechnicalName() + "-logo.png"), organization.getTechnicalName(), DefaultLogoGenerator.CAT);
+ htmlizeOrganizationLogo(organization, cache, htmlizeDirectory);
logger.info("Htmlize organization properties file: {}.", organization.getName());
FileUtils.copyFile(organization.getInputFile(), new File(htmlizeDirectory, organization.getTechnicalName() + ".properties"));
@@ -347,8 +349,7 @@ public class Htmlizer
{
// Manage the logo file.
logger.info("Htmlize service logo: {}.", service.getName());
- cache.restoreLogoTo(service.getLogoURL(), new File(htmlizeDirectory, organization.getTechnicalName() + "-" + service.getTechnicalName() + "-logo.png"), service.getTechnicalName(),
- DefaultLogoGenerator.BIRD);
+ htmlizeServiceLogo(service, cache, htmlizeDirectory);
logger.info("Htmlize service properties file: {}.", service.getName());
FileUtils.copyFile(service.getInputFile(),
new File(htmlizeDirectory, organization.getTechnicalName() + "-" + service.getTechnicalName() + ".properties"));
@@ -470,6 +471,36 @@ public class Htmlizer
}
}
+ /**
+ * 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.
*
@@ -512,4 +543,58 @@ public class Htmlizer
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);
+ }
+ }
}
diff --git a/src/fr/devinsy/statoolinfos/htmlize/OrganizationPage.java b/src/fr/devinsy/statoolinfos/htmlize/OrganizationPage.java
index f4d651a..73f8f6c 100644
--- a/src/fr/devinsy/statoolinfos/htmlize/OrganizationPage.java
+++ b/src/fr/devinsy/statoolinfos/htmlize/OrganizationPage.java
@@ -57,7 +57,7 @@ public class OrganizationPage
data.setAttribute("organizationRawButton", "href", organization.getTechnicalName() + ".properties");
- data.setAttribute("organizationLogo", "src", organization.getTechnicalName() + "-logo.png");
+ data.setAttribute("organizationLogo", "src", organization.getLogoFileName());
data.setEscapedContent("organizationName", organization.get("organization.name"));
data.setEscapedContent("organizationURL", organization.getWebsite());
diff --git a/src/fr/devinsy/statoolinfos/htmlize/ServiceListView.java b/src/fr/devinsy/statoolinfos/htmlize/ServiceListView.java
index a6f333c..9ca9cf4 100644
--- a/src/fr/devinsy/statoolinfos/htmlize/ServiceListView.java
+++ b/src/fr/devinsy/statoolinfos/htmlize/ServiceListView.java
@@ -60,12 +60,12 @@ public class ServiceListView
int index = 0;
for (Service service : services.sortByName())
{
- data.setAttribute("serviceListLine", index, "serviceListLineLogo", "src", service.getOrganization().getTechnicalName() + "-" + service.getTechnicalName() + "-logo.png");
+ data.setAttribute("serviceListLine", index, "serviceListLineLogo", "src", service.getLogoFileName());
data.setEscapedContent("serviceListLine", index, "serviceListLineNameValue", service.getName());
data.setAttribute("serviceListLine", index, "serviceListLineNameLink", "href", service.getOrganization().getTechnicalName() + "-" + service.getTechnicalName() + ".xhtml");
data.setAttribute("serviceListLine", index, "serviceListLineOrganizationLink", "href", service.getOrganization().getTechnicalName() + ".xhtml");
- data.setAttribute("serviceListLine", index, "serviceListLineOrganizationLogo", "src", service.getOrganization().getTechnicalName() + "-logo.png");
+ data.setAttribute("serviceListLine", index, "serviceListLineOrganizationLogo", "src", service.getOrganization().getLogoFileName());
data.setEscapedContent("serviceListLine", index, "serviceListLineOrganizationValue", service.getOrganization().getName());
data.setEscapedContent("serviceListLine", index, "serviceListLineUrlLink", service.getWebsite());