mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
add method read(url) to config-reader
This commit is contained in:
parent
8f27dee476
commit
69c3b631ba
2 changed files with 38 additions and 1 deletions
|
|
@ -64,7 +64,7 @@ public class SchrimpfFactory {
|
||||||
public VehicleRoutingAlgorithm createAlgorithm(VehicleRoutingProblem vrp){
|
public VehicleRoutingAlgorithm createAlgorithm(VehicleRoutingProblem vrp){
|
||||||
AlgorithmConfig algorithmConfig = new AlgorithmConfig();
|
AlgorithmConfig algorithmConfig = new AlgorithmConfig();
|
||||||
URL resource = Resource.getAsURL("schrimpf.xml");
|
URL resource = Resource.getAsURL("schrimpf.xml");
|
||||||
new AlgorithmConfigXmlReader(algorithmConfig).read(resource.getPath());
|
new AlgorithmConfigXmlReader(algorithmConfig).read(resource);
|
||||||
return VehicleRoutingAlgorithms.createAlgorithm(vrp, algorithmConfig);
|
return VehicleRoutingAlgorithms.createAlgorithm(vrp, algorithmConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,43 @@ public class AlgorithmConfigXmlReader {
|
||||||
this.algorithmConfig = algorithmConfig;
|
this.algorithmConfig = algorithmConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void read(URL url){
|
||||||
|
log.info("read algorithm-config from file " + url);
|
||||||
|
algorithmConfig.getXMLConfiguration().setURL(url);
|
||||||
|
algorithmConfig.getXMLConfiguration().setAttributeSplittingDisabled(true);
|
||||||
|
algorithmConfig.getXMLConfiguration().setDelimiterParsingDisabled(true);
|
||||||
|
|
||||||
|
if(schemaValidation){
|
||||||
|
final URL resource = Resource.getAsURL("algorithm_schema.xsd");
|
||||||
|
if(resource != null) {
|
||||||
|
EntityResolver resolver = new EntityResolver() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
|
||||||
|
{
|
||||||
|
InputSource is = new InputSource(resource.getFile());
|
||||||
|
return is;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
algorithmConfig.getXMLConfiguration().setEntityResolver(resolver);
|
||||||
|
algorithmConfig.getXMLConfiguration().setSchemaValidation(true);
|
||||||
|
log.info("validating " + url + " with xsd-schema");
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
log.warn("cannot find schema-xsd file (algorithm_xml_schema.xsd). try to read xml without xml-file-validation.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
algorithmConfig.getXMLConfiguration().load();
|
||||||
|
} catch (ConfigurationException e) {
|
||||||
|
log.error(e);
|
||||||
|
e.printStackTrace();
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void read(String filename){
|
public void read(String filename){
|
||||||
log.info("read algorithm-config from file " + filename);
|
log.info("read algorithm-config from file " + filename);
|
||||||
algorithmConfig.getXMLConfiguration().setFileName(filename);
|
algorithmConfig.getXMLConfiguration().setFileName(filename);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue