Refactored PathProperties.
This commit is contained in:
parent
1d49fd1871
commit
3de7de0ef1
9 changed files with 79 additions and 47 deletions
|
@ -28,6 +28,7 @@ import org.apache.commons.lang3.StringUtils;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import fr.devinsy.statoolinfos.properties.PathProperties;
|
||||
import fr.devinsy.statoolinfos.properties.PathPropertyList;
|
||||
import fr.devinsy.statoolinfos.properties.PathPropertyUtils;
|
||||
|
||||
|
@ -133,9 +134,9 @@ public class CrawlCache
|
|||
* @throws IOException
|
||||
* Signals that an I/O exception has occurred.
|
||||
*/
|
||||
public PathPropertyList restoreProperties(final URL url) throws IOException
|
||||
public PathProperties restoreProperties(final URL url) throws IOException
|
||||
{
|
||||
PathPropertyList result;
|
||||
PathProperties result;
|
||||
|
||||
if (url == null)
|
||||
{
|
||||
|
@ -189,7 +190,7 @@ public class CrawlCache
|
|||
* @throws IOException
|
||||
* Signals that an I/O exception has occurred.
|
||||
*/
|
||||
public File storeProperties(final URL url, final PathPropertyList properties) throws IOException
|
||||
public File storeProperties(final URL url, final PathProperties properties) throws IOException
|
||||
{
|
||||
File result;
|
||||
|
||||
|
|
|
@ -26,8 +26,8 @@ import org.apache.commons.lang3.StringUtils;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import fr.devinsy.statoolinfos.properties.PathProperties;
|
||||
import fr.devinsy.statoolinfos.properties.PathProperty;
|
||||
import fr.devinsy.statoolinfos.properties.PathPropertyList;
|
||||
|
||||
/**
|
||||
* The Class PathProperty.
|
||||
|
@ -50,7 +50,7 @@ public class Factory
|
|||
* @throws StatoolInfosException
|
||||
* @throws IOException
|
||||
*/
|
||||
public static Federation loadFederation(final PathPropertyList properties) throws StatoolInfosException, IOException
|
||||
public static Federation loadFederation(final PathProperties properties) throws StatoolInfosException, IOException
|
||||
{
|
||||
Federation result;
|
||||
|
||||
|
@ -61,12 +61,12 @@ public class Factory
|
|||
|
||||
result = new Federation(properties);
|
||||
|
||||
PathPropertyList subs = result.getByPrefix("subs");
|
||||
PathProperties subs = result.getByPrefix("subs");
|
||||
for (PathProperty property : subs)
|
||||
{
|
||||
if (StringUtils.startsWith(property.getValue(), "http"))
|
||||
{
|
||||
PathPropertyList subProperties = cache.restoreProperties(new URL(property.getValue()));
|
||||
PathProperties subProperties = cache.restoreProperties(new URL(property.getValue()));
|
||||
|
||||
Organization organization = loadOrganization(subProperties, cache);
|
||||
result.getOrganizations().add(organization);
|
||||
|
@ -84,7 +84,7 @@ public class Factory
|
|||
* @throws StatoolInfosException
|
||||
* @throws IOException
|
||||
*/
|
||||
public static Organization loadOrganization(final PathPropertyList properties) throws StatoolInfosException, IOException
|
||||
public static Organization loadOrganization(final PathProperties properties) throws StatoolInfosException, IOException
|
||||
{
|
||||
Organization result;
|
||||
|
||||
|
@ -109,18 +109,18 @@ public class Factory
|
|||
* @return the organization
|
||||
* @throws IOException
|
||||
*/
|
||||
public static Organization loadOrganization(final PathPropertyList properties, final CrawlCache cache) throws IOException
|
||||
public static Organization loadOrganization(final PathProperties properties, final CrawlCache cache) throws IOException
|
||||
{
|
||||
Organization result;
|
||||
|
||||
result = new Organization(properties);
|
||||
|
||||
PathPropertyList section = result.getByPrefix("subs");
|
||||
PathProperties section = result.getByPrefix("subs");
|
||||
for (PathProperty property : section)
|
||||
{
|
||||
if (StringUtils.startsWith(property.getValue(), "http"))
|
||||
{
|
||||
PathPropertyList subProperties = cache.restoreProperties(new URL(property.getValue()));
|
||||
PathProperties subProperties = cache.restoreProperties(new URL(property.getValue()));
|
||||
|
||||
Service service = loadService(subProperties);
|
||||
result.getServices().add(service);
|
||||
|
@ -136,7 +136,7 @@ public class Factory
|
|||
*
|
||||
* @return the service
|
||||
*/
|
||||
public static Service loadService(final PathPropertyList properties)
|
||||
public static Service loadService(final PathProperties properties)
|
||||
{
|
||||
Service result;
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ package fr.devinsy.statoolinfos.core;
|
|||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import fr.devinsy.statoolinfos.properties.PathProperties;
|
||||
import fr.devinsy.statoolinfos.properties.PathPropertyList;
|
||||
|
||||
/**
|
||||
|
@ -45,7 +46,7 @@ public class Federation extends PathPropertyList
|
|||
* @param properties
|
||||
* the properties
|
||||
*/
|
||||
public Federation(final PathPropertyList properties)
|
||||
public Federation(final PathProperties properties)
|
||||
{
|
||||
super(properties);
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ package fr.devinsy.statoolinfos.core;
|
|||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import fr.devinsy.statoolinfos.properties.PathProperties;
|
||||
import fr.devinsy.statoolinfos.properties.PathPropertyList;
|
||||
|
||||
/**
|
||||
|
@ -45,7 +46,7 @@ public class Organization extends PathPropertyList
|
|||
* @param properties
|
||||
* the properties
|
||||
*/
|
||||
public Organization(final PathPropertyList properties)
|
||||
public Organization(final PathProperties properties)
|
||||
{
|
||||
super(properties);
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
package fr.devinsy.statoolinfos.core;
|
||||
|
||||
import fr.devinsy.statoolinfos.properties.PathProperties;
|
||||
import fr.devinsy.statoolinfos.properties.PathPropertyList;
|
||||
|
||||
/**
|
||||
|
@ -41,7 +42,7 @@ public class Service extends PathPropertyList
|
|||
* @param properties
|
||||
* the properties
|
||||
*/
|
||||
public Service(final PathPropertyList properties)
|
||||
public Service(final PathProperties properties)
|
||||
{
|
||||
super(properties);
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import fr.devinsy.statoolinfos.htmlize.Htmlizer;
|
||||
import fr.devinsy.statoolinfos.properties.PathProperties;
|
||||
import fr.devinsy.statoolinfos.properties.PathProperty;
|
||||
import fr.devinsy.statoolinfos.properties.PathPropertyList;
|
||||
import fr.devinsy.statoolinfos.properties.PathPropertyUtils;
|
||||
|
@ -52,7 +53,7 @@ public class StatoolInfos
|
|||
public static void build(final File input) throws StatoolInfosException, IOException
|
||||
{
|
||||
logger.info("Build {}", input.getAbsolutePath());
|
||||
PathPropertyList inputProperties = PathPropertyUtils.load(input);
|
||||
PathProperties inputProperties = PathPropertyUtils.load(input);
|
||||
|
||||
String buildDirectoryName = inputProperties.get("conf.build.directory");
|
||||
if (StringUtils.isBlank(buildDirectoryName))
|
||||
|
@ -66,26 +67,25 @@ public class StatoolInfos
|
|||
if (targetDirectory.exists())
|
||||
{
|
||||
// Load configuration file.
|
||||
File targetFile = new File(targetDirectory, input.getName());
|
||||
|
||||
//
|
||||
PathPropertyList targetProperties = new PathPropertyList();
|
||||
PathProperties targetProperties = new PathPropertyList();
|
||||
|
||||
// Add generator paths.
|
||||
PathPropertyList fileSection = new PathPropertyList();
|
||||
PathProperties fileSection = new PathPropertyList();
|
||||
fileSection.put("file.class", inputProperties.get("conf.class"));
|
||||
fileSection.put("file.generator", "StatoolInfos");
|
||||
fileSection.put("file.datetime", LocalDateTime.now().toString());
|
||||
fileSection.put("file.protocol", inputProperties.get("conf.protocol"));
|
||||
targetProperties.addAll(fileSection);
|
||||
targetProperties.add(fileSection);
|
||||
|
||||
//
|
||||
targetProperties.addAll(inputProperties);
|
||||
targetProperties.add(inputProperties);
|
||||
|
||||
// Clear configuration paths.
|
||||
targetProperties.removeSection("conf");
|
||||
|
||||
// Save target file.
|
||||
File targetFile = new File(targetDirectory, input.getName());
|
||||
PathPropertyUtils.save(targetFile, targetProperties);
|
||||
}
|
||||
else
|
||||
|
@ -107,7 +107,7 @@ public class StatoolInfos
|
|||
*/
|
||||
public static void clear(final File input) throws StatoolInfosException, IOException
|
||||
{
|
||||
PathPropertyList inputProperties = PathPropertyUtils.load(input);
|
||||
PathProperties inputProperties = PathPropertyUtils.load(input);
|
||||
|
||||
{
|
||||
String crawlCacheName = inputProperties.get("conf.crawl.cache");
|
||||
|
@ -166,13 +166,13 @@ public class StatoolInfos
|
|||
*/
|
||||
public static void crawl(final File input) throws StatoolInfosException, IOException
|
||||
{
|
||||
PathPropertyList configuration = PathPropertyUtils.load(input);
|
||||
PathProperties configuration = PathPropertyUtils.load(input);
|
||||
|
||||
String crawlCachePath = configuration.get("conf.crawl.cache");
|
||||
logger.info("Cache setting: {}", configuration.get("conf.crawl.cache"));
|
||||
CrawlCache cache = new CrawlCache(new File(crawlCachePath));
|
||||
|
||||
PathPropertyList subs = configuration.getByPrefix("subs");
|
||||
PathProperties subs = configuration.getByPrefix("subs");
|
||||
for (PathProperty property : subs)
|
||||
{
|
||||
URL url = new URL(property.getValue());
|
||||
|
@ -197,13 +197,13 @@ public class StatoolInfos
|
|||
logger.info("Crawling " + url);
|
||||
|
||||
File file = cache.store(url);
|
||||
PathPropertyList properties = PathPropertyUtils.load(file);
|
||||
PathProperties properties = PathPropertyUtils.load(file);
|
||||
|
||||
PathPropertyList crawlSection = new PathPropertyList();
|
||||
PathProperties crawlSection = new PathPropertyList();
|
||||
crawlSection.put("crawl.crawler", "StatoolInfos");
|
||||
crawlSection.put("crawl.datetime", LocalDateTime.now().toString());
|
||||
crawlSection.put("crawl.url", url.toString());
|
||||
properties.addAll(crawlSection);
|
||||
properties.add(crawlSection);
|
||||
cache.storeProperties(url, properties);
|
||||
|
||||
cache.storeQuietly(properties.getURL("federation.logo"));
|
||||
|
@ -214,7 +214,7 @@ public class StatoolInfos
|
|||
cache.storeQuietly(properties.getURL("service.logo.url"));
|
||||
|
||||
//
|
||||
PathPropertyList subs = properties.getByPrefix("subs");
|
||||
PathProperties subs = properties.getByPrefix("subs");
|
||||
for (PathProperty property : subs)
|
||||
{
|
||||
URL subUrl = new URL(property.getValue());
|
||||
|
@ -234,7 +234,7 @@ public class StatoolInfos
|
|||
*/
|
||||
public static void htmlize(final File input) throws StatoolInfosException, IOException
|
||||
{
|
||||
PathPropertyList properties = PathPropertyUtils.load(input);
|
||||
PathProperties properties = PathPropertyUtils.load(input);
|
||||
|
||||
String className = properties.get("conf.class");
|
||||
if (StringUtils.equals(className, "federation"))
|
||||
|
|
|
@ -20,6 +20,7 @@ package fr.devinsy.statoolinfos.properties;
|
|||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.Iterator;
|
||||
|
||||
import fr.devinsy.strings.StringList;
|
||||
import fr.devinsy.strings.StringSet;
|
||||
|
@ -27,8 +28,12 @@ import fr.devinsy.strings.StringSet;
|
|||
/**
|
||||
* The Interface PathProperties.
|
||||
*/
|
||||
public interface PathProperties
|
||||
public interface PathProperties extends Iterable<PathProperty>
|
||||
{
|
||||
void add(PathProperties source);
|
||||
|
||||
boolean add(PathProperty property);
|
||||
|
||||
/**
|
||||
* Gets the.
|
||||
*
|
||||
|
@ -45,7 +50,7 @@ public interface PathProperties
|
|||
* the prefix
|
||||
* @return the by prefix
|
||||
*/
|
||||
public PathProperties getByPrefix(String prefix);
|
||||
PathProperties getByPrefix(String prefix);
|
||||
|
||||
/**
|
||||
* Gets the keys.
|
||||
|
@ -84,7 +89,15 @@ public interface PathProperties
|
|||
* the path
|
||||
* @return the url
|
||||
*/
|
||||
public URL getURL(String path) throws MalformedURLException;
|
||||
URL getURL(String path) throws MalformedURLException;
|
||||
|
||||
/**
|
||||
* Iterator.
|
||||
*
|
||||
* @return the iterator
|
||||
*/
|
||||
@Override
|
||||
Iterator<PathProperty> iterator();
|
||||
|
||||
/**
|
||||
* Put.
|
||||
|
|
|
@ -63,7 +63,7 @@ public class PathPropertyList extends ArrayList<PathProperty> implements PathPro
|
|||
* @param source
|
||||
* the source
|
||||
*/
|
||||
public PathPropertyList(final PathPropertyList source)
|
||||
public PathPropertyList(final PathProperties source)
|
||||
{
|
||||
super();
|
||||
if (source != null)
|
||||
|
@ -77,6 +77,21 @@ public class PathPropertyList extends ArrayList<PathProperty> implements PathPro
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the.
|
||||
*
|
||||
* @param source
|
||||
* the source
|
||||
*/
|
||||
@Override
|
||||
public void add(final PathProperties source)
|
||||
{
|
||||
for (PathProperty property : source)
|
||||
{
|
||||
add(property);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the.
|
||||
*
|
||||
|
@ -468,7 +483,7 @@ public class PathPropertyList extends ArrayList<PathProperty> implements PathPro
|
|||
{
|
||||
result.add("# [" + StringUtils.capitalize(prefix) + "]");
|
||||
|
||||
PathPropertyList section = getByPrefix(prefix);
|
||||
PathProperties section = getByPrefix(prefix);
|
||||
result.addAll(section.toStringList());
|
||||
|
||||
result.add("");
|
||||
|
|
|
@ -78,9 +78,9 @@ public class PathPropertyUtils
|
|||
* @throws IOException
|
||||
* Signals that an I/O exception has occurred.
|
||||
*/
|
||||
public static PathPropertyList load(final File file) throws IOException
|
||||
public static PathProperties load(final File file) throws IOException
|
||||
{
|
||||
PathPropertyList result;
|
||||
PathProperties result;
|
||||
|
||||
result = load(file, DEFAULT_CHARSET_NAME);
|
||||
|
||||
|
@ -99,9 +99,9 @@ public class PathPropertyUtils
|
|||
* @throws IOException
|
||||
* Signals that an I/O exception has occurred.
|
||||
*/
|
||||
public static PathPropertyList load(final File file, final String charsetName) throws IOException
|
||||
public static PathProperties load(final File file, final String charsetName) throws IOException
|
||||
{
|
||||
PathPropertyList result;
|
||||
PathProperties result;
|
||||
|
||||
result = new PathPropertyList();
|
||||
|
||||
|
@ -129,9 +129,9 @@ public class PathPropertyUtils
|
|||
* @throws IOException
|
||||
* Signals that an I/O exception has occurred.
|
||||
*/
|
||||
public static PathPropertyList load(final URL url) throws IOException
|
||||
public static PathProperties load(final URL url) throws IOException
|
||||
{
|
||||
PathPropertyList result;
|
||||
PathProperties result;
|
||||
|
||||
StringList lines = StringsUtils.load(url);
|
||||
|
||||
|
@ -150,9 +150,9 @@ public class PathPropertyUtils
|
|||
* @throws IOException
|
||||
* Signals that an I/O exception has occurred.
|
||||
*/
|
||||
public static PathPropertyList read(final BufferedReader in) throws IOException
|
||||
public static PathProperties read(final BufferedReader in) throws IOException
|
||||
{
|
||||
PathPropertyList result;
|
||||
PathProperties result;
|
||||
|
||||
result = new PathPropertyList();
|
||||
|
||||
|
@ -184,9 +184,9 @@ public class PathPropertyUtils
|
|||
* @throws IOException
|
||||
* Signals that an I/O exception has occurred.
|
||||
*/
|
||||
public static PathPropertyList read(final StringList source) throws IOException
|
||||
public static PathProperties read(final StringList source) throws IOException
|
||||
{
|
||||
PathPropertyList result;
|
||||
PathProperties result;
|
||||
|
||||
result = new PathPropertyList();
|
||||
|
||||
|
@ -277,7 +277,7 @@ public class PathPropertyUtils
|
|||
* @throws IOException
|
||||
* Signals that an I/O exception has occurred.
|
||||
*/
|
||||
public static void save(final File file, final PathPropertyList source) throws IOException
|
||||
public static void save(final File file, final PathProperties source) throws IOException
|
||||
{
|
||||
PrintWriter out = null;
|
||||
try
|
||||
|
@ -327,7 +327,7 @@ public class PathPropertyUtils
|
|||
* @throws IOException
|
||||
* Signals that an I/O exception has occurred.
|
||||
*/
|
||||
public static void write(final PrintWriter out, final PathPropertyList source) throws IOException
|
||||
public static void write(final PrintWriter out, final PathProperties source) throws IOException
|
||||
{
|
||||
if (source != null)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue