statoolinfosweb/src/fr/devinsy/statoolinfos/core/Configuration.java

398 lines
7.6 KiB
Java
Raw Normal View History

/*
* 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.core;
import java.io.File;
import org.apache.commons.lang3.StringUtils;
import fr.devinsy.statoolinfos.crawl.CrawlCache;
import fr.devinsy.statoolinfos.properties.PathProperties;
import fr.devinsy.statoolinfos.properties.PathPropertyList;
/**
* The Class PathProperty.
*/
public class Configuration extends PathPropertyList
{
private static final long serialVersionUID = 2085950843956966741L;
/**
* Instantiates a new federation.
*/
public Configuration()
{
super();
}
/**
* Instantiates a new federation.
*
* @param properties
* the properties
*/
public Configuration(final PathProperties properties)
{
super(properties);
}
/**
* Gets the builds the directory.
*
* @return the builds the directory
*/
public File getBuildDirectory()
{
File result;
String path = getBuildDirectoryPath();
if (StringUtils.isBlank(path))
{
result = null;
}
else
{
result = new File(path);
}
//
return result;
}
/**
* Gets the builds the directory path.
*
* @return the builds the directory path
*/
public String getBuildDirectoryPath()
{
String result;
result = get("conf.build.directory");
//
return result;
}
/**
* Gets the builds the directory valid.
*
* @return the builds the directory valid
*/
public File getBuildDirectoryValid()
{
File result;
result = getBuildDirectory();
if (result == null)
{
throw new IllegalArgumentException("Undefined build directory.");
}
else if (!result.exists())
{
throw new IllegalArgumentException("Build directory does not exist: " + result.getAbsolutePath());
}
//
return result;
}
/**
* Gets the builds the input.
*
* @return the builds the input
*/
public File getBuildInput()
{
File result;
String path = get("conf.build.input");
if (StringUtils.isBlank(path))
{
result = null;
}
else
{
result = new File(path);
}
2020-09-25 04:36:38 +02:00
//
return result;
}
/**
* Gets the category file.
*
* @return the category file
* @throws StatoolInfosException
*/
public File getCategoryFile() throws StatoolInfosException
{
File result;
String path = get("conf.htmlize.categories");
if (StringUtils.isBlank(path))
{
throw new StatoolInfosException("Entry conf.htmlize.categories is missing in configuration file.");
}
else
{
result = new File(path);
}
//
return result;
}
/**
* Gets the class name.
*
* @return the class name
*/
public String getClassName()
{
String result;
result = get("conf.class");
//
return result;
}
/**
* Gets the cache.
*
* @return the cache
* @throws StatoolInfosException
*/
public CrawlCache getCrawlCache() throws StatoolInfosException
{
CrawlCache result;
String path = getCrawlCachePath();
result = new CrawlCache(new File(path));
//
return result;
}
/**
* Gets the crawl cache path.
*
* @return the crawl cache path
*/
public String getCrawlCachePath()
{
String result;
result = get("conf.crawl.cache");
//
return result;
}
/**
* Gets the crawl input.
*
* @return the crawl input
*/
2020-09-23 21:56:40 +02:00
public File getCrawlInputFile()
{
File result;
String path = getCrawlInputPath();
if (StringUtils.isBlank(path))
{
result = null;
}
else
{
result = new File(path);
}
//
return result;
}
/**
* Gets the crawl input path.
*
* @return the crawl input path
*/
public String getCrawlInputPath()
{
String result;
result = get("conf.crawl.input");
//
return result;
}
/**
* Gets the htmlize directory.
*
* @return the htmlize directory
*/
public File getHtmlizeDirectory()
{
File result;
String path = getHtmlizeDirectoryPath();
if (StringUtils.isBlank(path))
{
result = null;
}
else
{
result = new File(path);
}
//
return result;
}
/**
* Gets the htmlize directory path.
*
* @return the htmlize directory path
*/
public String getHtmlizeDirectoryPath()
{
String result;
result = get("conf.htmlize.directory");
//
return result;
}
/**
* Gets the htmlize input.
*
* @return the htmlize input
*/
public File getHtmlizeInput()
{
File result;
String path = getHtmlizeInputPath();
if (StringUtils.isBlank(path))
{
result = null;
}
else
{
result = new File(path);
}
//
return result;
}
/**
* Gets the htmlize input path.
*
* @return the htmlize input path
*/
public String getHtmlizeInputPath()
{
String result;
result = get("conf.htmlize.input");
//
return result;
}
/**
* Checks for valid cache.
*
* @return true, if successful
*/
public boolean hasValidCache()
{
boolean result;
String path = get("conf.crawl.cache");
if (StringUtils.isBlank(path))
{
result = false;
}
else if (!new File(path).exists())
{
result = false;
}
else
{
result = true;
}
//
return result;
}
/**
* Checks if is federation.
*
* @return true, if is federation
*/
public boolean isFederation()
{
boolean result;
result = StringUtils.equals(getClassName(), "federation");
//
return result;
}
/**
* Checks if is organization.
*
* @return true, if is organization
*/
public boolean isOrganization()
{
boolean result;
result = StringUtils.equals(getClassName(), "organization");
//
return result;
}
/**
* Checks if is service.
*
* @return true, if is service
*/
public boolean isService()
{
boolean result;
result = StringUtils.equals(getClassName(), "service");
//
return result;
}
}