|
|
|
@ -7,6 +7,8 @@ import org.apache.commons.cli.*; |
|
|
|
import org.apache.logging.log4j.LogManager; |
|
|
|
import org.apache.logging.log4j.LogManager; |
|
|
|
import org.apache.logging.log4j.Logger; |
|
|
|
import org.apache.logging.log4j.Logger; |
|
|
|
import org.leolo.map.osm.extract.model.*; |
|
|
|
import org.leolo.map.osm.extract.model.*; |
|
|
|
|
|
|
|
import org.leolo.map.osm.extract.util.InputFile; |
|
|
|
|
|
|
|
import org.leolo.map.osm.extract.util.InputUtil; |
|
|
|
import org.xml.sax.SAXException; |
|
|
|
import org.xml.sax.SAXException; |
|
|
|
|
|
|
|
|
|
|
|
import javax.xml.parsers.ParserConfigurationException; |
|
|
|
import javax.xml.parsers.ParserConfigurationException; |
|
|
|
@ -58,13 +60,33 @@ public class ExtractElement { |
|
|
|
.required(true) |
|
|
|
.required(true) |
|
|
|
.desc("output format") |
|
|
|
.desc("output format") |
|
|
|
.build(); |
|
|
|
.build(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Option httpUserName = Option.builder() |
|
|
|
|
|
|
|
.longOpt("http-user") |
|
|
|
|
|
|
|
.argName("user name") |
|
|
|
|
|
|
|
.hasArg(true) |
|
|
|
|
|
|
|
.optionalArg(true) |
|
|
|
|
|
|
|
.desc("User name sent during HTTP request") |
|
|
|
|
|
|
|
.build(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Option httpPassword = Option.builder() |
|
|
|
|
|
|
|
.longOpt("http-password") |
|
|
|
|
|
|
|
.argName("passsword") |
|
|
|
|
|
|
|
.hasArg(true) |
|
|
|
|
|
|
|
.optionalArg(true) |
|
|
|
|
|
|
|
.desc("Password sent during HTTP request") |
|
|
|
|
|
|
|
.build(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private Map<Long, MapEntry> allEntry = new Hashtable<>(); |
|
|
|
private Map<Long, MapEntry> allEntry = new Hashtable<>(); |
|
|
|
private Map<Long, Relation> relations = new Hashtable<>(); |
|
|
|
private Map<Long, Relation> relations = new Hashtable<>(); |
|
|
|
private Map<Long, Way> ways = new Hashtable<>(); |
|
|
|
private Map<Long, Way> ways = new Hashtable<>(); |
|
|
|
private Map<Long, Node> nodes = new Hashtable<>(); |
|
|
|
private Map<Long, Node> nodes = new Hashtable<>(); |
|
|
|
private Set<Integer> strings = new HashSet<>(); |
|
|
|
|
|
|
|
|
|
|
|
private HashSet<Long> pendingRelations = new HashSet<>(); |
|
|
|
|
|
|
|
private HashSet<Long> pendingWays = new HashSet<>(); |
|
|
|
|
|
|
|
private HashSet<Long> pendingNodes = new HashSet<>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private CliOpt cliOpt = new CliOpt(); |
|
|
|
private CliOpt cliOpt = new CliOpt(); |
|
|
|
@ -79,6 +101,8 @@ public class ExtractElement { |
|
|
|
String outputFilePath = null; |
|
|
|
String outputFilePath = null; |
|
|
|
String actionFilePath; |
|
|
|
String actionFilePath; |
|
|
|
String format; |
|
|
|
String format; |
|
|
|
|
|
|
|
InputFile dbFile; |
|
|
|
|
|
|
|
InputFile actionFile; |
|
|
|
try { |
|
|
|
try { |
|
|
|
CommandLine cmd = parser.parse(getOptions(), args); |
|
|
|
CommandLine cmd = parser.parse(getOptions(), args); |
|
|
|
if(args.length == 0 || cmd.hasOption(cliOpt.help)){ |
|
|
|
if(args.length == 0 || cmd.hasOption(cliOpt.help)){ |
|
|
|
@ -109,16 +133,8 @@ public class ExtractElement { |
|
|
|
System.exit(2); |
|
|
|
System.exit(2); |
|
|
|
} |
|
|
|
} |
|
|
|
PrintStream outputStream = outputFilePath==null?System.out:new PrintStream(new File(outputFilePath)); |
|
|
|
PrintStream outputStream = outputFilePath==null?System.out:new PrintStream(new File(outputFilePath)); |
|
|
|
File dbFile = new File(dbFilePath); |
|
|
|
dbFile = InputUtil.getInputFile(dbFilePath); |
|
|
|
if(!dbFile.exists() || !dbFile.canRead()){ |
|
|
|
actionFile = InputUtil.getInputFile(actionFilePath); |
|
|
|
log.atError().log("Unable to read db file {}", dbFilePath); |
|
|
|
|
|
|
|
System.exit(2); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
File actionFile = new File(actionFilePath); |
|
|
|
|
|
|
|
if(!actionFile.exists() || !actionFile.canRead()){ |
|
|
|
|
|
|
|
log.atError().log("Unable to read action file {}", actionFilePath); |
|
|
|
|
|
|
|
System.exit(2); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
log.atInfo().log("Database file size {}MB", dbFile.length()/1_000_000); |
|
|
|
log.atInfo().log("Database file size {}MB", dbFile.length()/1_000_000); |
|
|
|
log.atInfo().log("Action file size {}kB", actionFile.length()/1_000); |
|
|
|
log.atInfo().log("Action file size {}kB", actionFile.length()/1_000); |
|
|
|
doExtract(dbFile, actionFile, outputStream); |
|
|
|
doExtract(dbFile, actionFile, outputStream); |
|
|
|
@ -130,13 +146,13 @@ public class ExtractElement { |
|
|
|
System.err.println("Fatal error - unable to parse command line input!"); |
|
|
|
System.err.println("Fatal error - unable to parse command line input!"); |
|
|
|
e.printStackTrace(); |
|
|
|
e.printStackTrace(); |
|
|
|
System.exit(1); |
|
|
|
System.exit(1); |
|
|
|
} catch (FileNotFoundException e) { |
|
|
|
} catch (IOException e) { |
|
|
|
log.atError().withThrowable(e).log("Unable to locate the specified file"); |
|
|
|
log.atError().withThrowable(e).log("Unable to locate the specified file"); |
|
|
|
System.exit(1); |
|
|
|
System.exit(1); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void doExtract(File dbFile, File actionFile, PrintStream outputStream) { |
|
|
|
private void doExtract(InputFile dbFile, InputFile actionFile, PrintStream outputStream) { |
|
|
|
//Step 1: parse the actionFile
|
|
|
|
//Step 1: parse the actionFile
|
|
|
|
ActionFile af; |
|
|
|
ActionFile af; |
|
|
|
try { |
|
|
|
try { |
|
|
|
@ -146,21 +162,34 @@ public class ExtractElement { |
|
|
|
System.exit(3); |
|
|
|
System.exit(3); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
expandRelations(dbFile, af, af.getRelation()); |
|
|
|
doSearch(dbFile, af); |
|
|
|
processWay(dbFile, af); |
|
|
|
expandRelations(dbFile); |
|
|
|
processNode(dbFile, af); |
|
|
|
processWay(dbFile); |
|
|
|
|
|
|
|
processNode(dbFile); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void processNode(File dbFile, ActionFile af) { |
|
|
|
/** |
|
|
|
|
|
|
|
* Perform search as defined in the action file, and add them to relevant pending items |
|
|
|
|
|
|
|
* @param dbFile The database file going to be searched |
|
|
|
|
|
|
|
* @param af The file which defines the action to be performed |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private void doSearch(InputFile dbFile, ActionFile af) { |
|
|
|
|
|
|
|
//Placeholder
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void processWay(File dbFile, ActionFile af) { |
|
|
|
private void processNode(InputFile dbFile) { |
|
|
|
|
|
|
|
if(pendingNodes.isEmpty()) |
|
|
|
|
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void expandRelations(File dbFile, ActionFile af, Collection<ExtractItem> relations) { |
|
|
|
private void processWay(InputFile dbFile) { |
|
|
|
|
|
|
|
if(pendingWays.isEmpty()) |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void expandRelations(InputFile dbFile) { |
|
|
|
|
|
|
|
if(pendingRelations.isEmpty()) |
|
|
|
|
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void printHelp(int returnValue){ |
|
|
|
private void printHelp(int returnValue){ |
|
|
|
@ -179,6 +208,9 @@ public class ExtractElement { |
|
|
|
options.addOption(cliOpt.actionFile); |
|
|
|
options.addOption(cliOpt.actionFile); |
|
|
|
options.addOption(cliOpt.help); |
|
|
|
options.addOption(cliOpt.help); |
|
|
|
options.addOption(cliOpt.outputFormat); |
|
|
|
options.addOption(cliOpt.outputFormat); |
|
|
|
|
|
|
|
//Commented first, need to find some way to pass the parameters to the function
|
|
|
|
|
|
|
|
// options.addOption(cliOpt.httpUserName);
|
|
|
|
|
|
|
|
// options.addOption(cliOpt.httpPassword);
|
|
|
|
} |
|
|
|
} |
|
|
|
return options; |
|
|
|
return options; |
|
|
|
} |
|
|
|
} |
|
|
|
|