Compare commits
14 Commits
master
...
feature/km
| Author | SHA1 | Date |
|---|---|---|
|
|
fc2164d128 | 3 years ago |
|
|
e3744724c3 | 3 years ago |
|
|
9be4e2aadc | 3 years ago |
|
|
ea72d46a96 | 3 years ago |
|
|
cea17139d2 | 3 years ago |
|
|
6fd5e347fa | 3 years ago |
|
|
b351edc496 | 3 years ago |
|
|
c3ace41c95 | 3 years ago |
|
|
bedc142778 | 3 years ago |
|
|
bf690877dd | 3 years ago |
|
|
a9ae27b53a | 3 years ago |
|
|
0343559f84 | 3 years ago |
|
|
34bb1b202e | 3 years ago |
|
|
61af1ddbd9 | 3 years ago |
25 changed files with 959 additions and 226 deletions
@ -1,174 +0,0 @@ |
|||||||
<?xml version="1.0" encoding="UTF-8"?> |
|
||||||
<project version="4"> |
|
||||||
<component name="AutoImportSettings"> |
|
||||||
<option name="autoReloadType" value="SELECTIVE" /> |
|
||||||
</component> |
|
||||||
<component name="ChangeListManager"> |
|
||||||
<list default="true" id="aada2b3d-ba01-45e9-89c7-a596447b137a" name="Changes" comment=""> |
|
||||||
<change afterPath="$PROJECT_DIR$/src/test/java/MainTest.java" afterDir="false" /> |
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> |
|
||||||
<change beforePath="$PROJECT_DIR$/pom.xml" beforeDir="false" afterPath="$PROJECT_DIR$/pom.xml" afterDir="false" /> |
|
||||||
</list> |
|
||||||
<option name="SHOW_DIALOG" value="false" /> |
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" /> |
|
||||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" /> |
|
||||||
<option name="LAST_RESOLUTION" value="IGNORE" /> |
|
||||||
</component> |
|
||||||
<component name="FileTemplateManagerImpl"> |
|
||||||
<option name="RECENT_TEMPLATES"> |
|
||||||
<list> |
|
||||||
<option value="AnnotationType" /> |
|
||||||
<option value="Interface" /> |
|
||||||
<option value="Class" /> |
|
||||||
</list> |
|
||||||
</option> |
|
||||||
</component> |
|
||||||
<component name="Git.Settings"> |
|
||||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" /> |
|
||||||
</component> |
|
||||||
<component name="MarkdownSettingsMigration"> |
|
||||||
<option name="stateVersion" value="1" /> |
|
||||||
</component> |
|
||||||
<component name="ProjectId" id="2Eykj2SggZ4KtR6OJyjcndHtTWt" /> |
|
||||||
<component name="ProjectLevelVcsManager" settingsEditedManually="true" /> |
|
||||||
<component name="ProjectViewState"> |
|
||||||
<option name="hideEmptyMiddlePackages" value="true" /> |
|
||||||
<option name="showLibraryContents" value="true" /> |
|
||||||
</component> |
|
||||||
<component name="PropertiesComponent"><![CDATA[{ |
|
||||||
"keyToString": { |
|
||||||
"RunOnceActivity.OpenProjectViewOnStart": "true", |
|
||||||
"RunOnceActivity.ShowReadmeOnStart": "true", |
|
||||||
"SHARE_PROJECT_CONFIGURATION_FILES": "true", |
|
||||||
"WebServerToolWindowFactoryState": "false" |
|
||||||
} |
|
||||||
}]]></component> |
|
||||||
<component name="RecentsManager"> |
|
||||||
<key name="CreateClassDialog.RecentsKey"> |
|
||||||
<recent name="org.leolo.map.osm.extract.model" /> |
|
||||||
</key> |
|
||||||
<key name="MoveFile.RECENT_KEYS"> |
|
||||||
<recent name="D:\IdeaProjects\OSM extract" /> |
|
||||||
<recent name="D:\IdeaProjects\OSM extract\src\main\resources" /> |
|
||||||
</key> |
|
||||||
<key name="MoveClassesOrPackagesDialog.RECENTS_KEY"> |
|
||||||
<recent name="org.leolo.map.osm.extract.model" /> |
|
||||||
</key> |
|
||||||
</component> |
|
||||||
<component name="RunManager" selected="Application.Main"> |
|
||||||
<configuration name="Main" type="Application" factoryName="Application"> |
|
||||||
<option name="MAIN_CLASS_NAME" value="org.leolo.map.osm.extract.ExtractElement" /> |
|
||||||
<module name="OSM extract" /> |
|
||||||
<option name="PROGRAM_PARAMETERS" value="-d "D:\Downloads\isle-of-man-latest.osm.pbf" -a action.xml --format plain" /> |
|
||||||
<extension name="software.aws.toolkits.jetbrains.core.execution.JavaAwsConnectionExtension"> |
|
||||||
<option name="credential" /> |
|
||||||
<option name="region" /> |
|
||||||
<option name="useCurrentConnection" value="false" /> |
|
||||||
</extension> |
|
||||||
<method v="2"> |
|
||||||
<option name="Make" enabled="true" /> |
|
||||||
</method> |
|
||||||
</configuration> |
|
||||||
<configuration name="OSM-extract [clean,compile]" type="MavenRunConfiguration" factoryName="Maven" nameIsGenerated="true"> |
|
||||||
<MavenSettings> |
|
||||||
<option name="myGeneralSettings" /> |
|
||||||
<option name="myRunnerSettings" /> |
|
||||||
<option name="myRunnerParameters"> |
|
||||||
<MavenRunnerParameters> |
|
||||||
<option name="profiles"> |
|
||||||
<set /> |
|
||||||
</option> |
|
||||||
<option name="goals"> |
|
||||||
<list> |
|
||||||
<option value="clean" /> |
|
||||||
<option value="compile" /> |
|
||||||
</list> |
|
||||||
</option> |
|
||||||
<option name="pomFileName" /> |
|
||||||
<option name="profilesMap"> |
|
||||||
<map /> |
|
||||||
</option> |
|
||||||
<option name="resolveToWorkspace" value="false" /> |
|
||||||
<option name="workingDirPath" value="$PROJECT_DIR$" /> |
|
||||||
</MavenRunnerParameters> |
|
||||||
</option> |
|
||||||
</MavenSettings> |
|
||||||
<extension name="software.aws.toolkits.jetbrains.core.execution.JavaAwsConnectionExtension"> |
|
||||||
<option name="credential" /> |
|
||||||
<option name="region" /> |
|
||||||
<option name="useCurrentConnection" value="false" /> |
|
||||||
</extension> |
|
||||||
<method v="2" /> |
|
||||||
</configuration> |
|
||||||
<configuration name="OSM-extract [clean,compile,test]" type="MavenRunConfiguration" factoryName="Maven" nameIsGenerated="true"> |
|
||||||
<MavenSettings> |
|
||||||
<option name="myGeneralSettings" /> |
|
||||||
<option name="myRunnerSettings" /> |
|
||||||
<option name="myRunnerParameters"> |
|
||||||
<MavenRunnerParameters> |
|
||||||
<option name="profiles"> |
|
||||||
<set /> |
|
||||||
</option> |
|
||||||
<option name="goals"> |
|
||||||
<list> |
|
||||||
<option value="clean" /> |
|
||||||
<option value="compile" /> |
|
||||||
<option value="test" /> |
|
||||||
</list> |
|
||||||
</option> |
|
||||||
<option name="pomFileName" /> |
|
||||||
<option name="profilesMap"> |
|
||||||
<map /> |
|
||||||
</option> |
|
||||||
<option name="resolveToWorkspace" value="false" /> |
|
||||||
<option name="workingDirPath" value="$PROJECT_DIR$" /> |
|
||||||
</MavenRunnerParameters> |
|
||||||
</option> |
|
||||||
</MavenSettings> |
|
||||||
<extension name="software.aws.toolkits.jetbrains.core.execution.JavaAwsConnectionExtension"> |
|
||||||
<option name="credential" /> |
|
||||||
<option name="region" /> |
|
||||||
<option name="useCurrentConnection" value="false" /> |
|
||||||
</extension> |
|
||||||
<method v="2" /> |
|
||||||
</configuration> |
|
||||||
<list> |
|
||||||
<item itemvalue="Application.Main" /> |
|
||||||
<item itemvalue="Maven.OSM-extract [clean,compile,test]" /> |
|
||||||
<item itemvalue="Maven.OSM-extract [clean,compile]" /> |
|
||||||
</list> |
|
||||||
</component> |
|
||||||
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" /> |
|
||||||
<component name="TaskManager"> |
|
||||||
<task active="true" id="Default" summary="Default task"> |
|
||||||
<changelist id="aada2b3d-ba01-45e9-89c7-a596447b137a" name="Changes" comment="" /> |
|
||||||
<created>1663575347472</created> |
|
||||||
<option name="number" value="Default" /> |
|
||||||
<option name="presentableId" value="Default" /> |
|
||||||
<updated>1663575347472</updated> |
|
||||||
<workItem from="1663575350840" duration="42097000" /> |
|
||||||
</task> |
|
||||||
<servers /> |
|
||||||
</component> |
|
||||||
<component name="TypeScriptGeneratedFilesManager"> |
|
||||||
<option name="version" value="3" /> |
|
||||||
</component> |
|
||||||
<component name="Vcs.Log.Tabs.Properties"> |
|
||||||
<option name="TAB_STATES"> |
|
||||||
<map> |
|
||||||
<entry key="MAIN"> |
|
||||||
<value> |
|
||||||
<State /> |
|
||||||
</value> |
|
||||||
</entry> |
|
||||||
</map> |
|
||||||
</option> |
|
||||||
</component> |
|
||||||
<component name="XDebuggerManager"> |
|
||||||
<watches-manager> |
|
||||||
<configuration name="Application"> |
|
||||||
<watch expression="((Long)((Hashtable.Entry)((Hashtable)((ExtractElement)this).allEntry).entrySet().toArray()[1]).getKey()).value" custom="java.lang.Long,org.leolo.map.osm.extract.ExtractElement,java.util.Hashtable.Entry,java.util.Hashtable" /> |
|
||||||
</configuration> |
|
||||||
</watches-manager> |
|
||||||
</component> |
|
||||||
</project> |
|
||||||
@ -0,0 +1,21 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8" ?> |
||||||
|
<actions> |
||||||
|
<properties> |
||||||
|
<lang> |
||||||
|
<default>en</default> |
||||||
|
<other>de</other> |
||||||
|
<other>es</other> |
||||||
|
<other>fr</other> |
||||||
|
<other>ja</other> |
||||||
|
</lang> |
||||||
|
<tags> |
||||||
|
<display>short_name</display> |
||||||
|
<display>website</display> |
||||||
|
</tags> |
||||||
|
</properties> |
||||||
|
<extracts> |
||||||
|
<relation id="9936954"/> |
||||||
|
<way id="79289788"/> |
||||||
|
<node id="6720935522"/> |
||||||
|
</extracts> |
||||||
|
</actions> |
||||||
@ -0,0 +1,40 @@ |
|||||||
|
package org.leolo.map.osm.extract; |
||||||
|
|
||||||
|
import org.leolo.map.osm.extract.model.MapEntry; |
||||||
|
import org.leolo.map.osm.extract.model.Node; |
||||||
|
import org.leolo.map.osm.extract.model.Relation; |
||||||
|
import org.leolo.map.osm.extract.model.Way; |
||||||
|
|
||||||
|
import java.util.Hashtable; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
public class ExtractResult { |
||||||
|
|
||||||
|
private Map<Long, MapEntry> allEntry = new Hashtable<>(); |
||||||
|
private Map<Long, Relation> relations = new Hashtable<>(); |
||||||
|
private Map<Long, Way> ways = new Hashtable<>(); |
||||||
|
private Map<Long, Node> nodes = new Hashtable<>(); |
||||||
|
|
||||||
|
public ExtractResult(Map<Long, MapEntry> allEntry, Map<Long, Relation> relations, Map<Long, Way> ways, Map<Long, Node> nodes) { |
||||||
|
this.allEntry = allEntry; |
||||||
|
this.relations = relations; |
||||||
|
this.ways = ways; |
||||||
|
this.nodes = nodes; |
||||||
|
} |
||||||
|
|
||||||
|
public Map<Long, MapEntry> getAllEntry() { |
||||||
|
return allEntry; |
||||||
|
} |
||||||
|
|
||||||
|
public Map<Long, Relation> getRelations() { |
||||||
|
return relations; |
||||||
|
} |
||||||
|
|
||||||
|
public Map<Long, Way> getWays() { |
||||||
|
return ways; |
||||||
|
} |
||||||
|
|
||||||
|
public Map<Long, Node> getNodes() { |
||||||
|
return nodes; |
||||||
|
} |
||||||
|
} |
||||||
@ -1,4 +1,12 @@ |
|||||||
package org.leolo.map.osm.extract; |
package org.leolo.map.osm.extract; |
||||||
|
|
||||||
|
import java.io.PrintWriter; |
||||||
|
|
||||||
public interface OutputFormat { |
public interface OutputFormat { |
||||||
|
public void writeHeader(PrintWriter output); |
||||||
|
public void writeTailer(PrintWriter output); |
||||||
|
public void writeRelation(PrintWriter output,long id, ExtractResult extractResult); |
||||||
|
public void writeWay(PrintWriter output,long id, ExtractResult extractResult); |
||||||
|
public void writeNode(PrintWriter output,long id, ExtractResult extractResult); |
||||||
|
|
||||||
} |
} |
||||||
|
|||||||
@ -0,0 +1,12 @@ |
|||||||
|
package org.leolo.map.osm.extract; |
||||||
|
|
||||||
|
import java.lang.annotation.ElementType; |
||||||
|
import java.lang.annotation.Retention; |
||||||
|
import java.lang.annotation.RetentionPolicy; |
||||||
|
import java.lang.annotation.Target; |
||||||
|
|
||||||
|
@Target({ElementType.TYPE}) |
||||||
|
@Retention(RetentionPolicy.RUNTIME) |
||||||
|
public @interface SearchProvider { |
||||||
|
String[] searchKey(); |
||||||
|
} |
||||||
@ -0,0 +1,112 @@ |
|||||||
|
package org.leolo.map.osm.extract; |
||||||
|
|
||||||
|
import eu.infomas.annotation.AnnotationDetector; |
||||||
|
import org.apache.logging.log4j.LogManager; |
||||||
|
import org.apache.logging.log4j.Logger; |
||||||
|
import org.leolo.map.osm.extract.model.SearchItem; |
||||||
|
|
||||||
|
import java.io.IOException; |
||||||
|
import java.lang.annotation.Annotation; |
||||||
|
import java.util.*; |
||||||
|
import java.util.function.BiConsumer; |
||||||
|
|
||||||
|
public class SearchProviderManager { |
||||||
|
|
||||||
|
private static SearchProviderManager instance; |
||||||
|
private Logger log = LogManager.getLogger(); |
||||||
|
private Hashtable<String, Class> items = new Hashtable<>(); |
||||||
|
|
||||||
|
public static synchronized SearchProviderManager getInstance(){ |
||||||
|
if(instance==null){ |
||||||
|
instance = new SearchProviderManager(); |
||||||
|
} |
||||||
|
return instance; |
||||||
|
} |
||||||
|
|
||||||
|
private SearchProviderManager(){ |
||||||
|
AnnotationDetector.TypeReporter reporter = new AnnotationDetector.TypeReporter() { |
||||||
|
@Override |
||||||
|
public void reportTypeAnnotation(Class<? extends Annotation> annoClass, String clazz) { |
||||||
|
log.atDebug().log("Class {} has annotation {}", clazz, annoClass.getName()); |
||||||
|
try { |
||||||
|
Class typeClass = Class.forName(clazz); |
||||||
|
if(SearchItem.class.isAssignableFrom(typeClass)){ |
||||||
|
log.atDebug().log("Class {} is an output formatter", clazz); |
||||||
|
SearchProvider of = (SearchProvider) typeClass.getAnnotation(SearchProvider.class); |
||||||
|
for(String format: of.searchKey()){ |
||||||
|
if(items.containsKey(format)){ |
||||||
|
log.atWarn().log("Duplicated search type {}. Shared by (at least) {} and {}", |
||||||
|
format, |
||||||
|
typeClass.getName(), |
||||||
|
items.get(format).getName() |
||||||
|
); |
||||||
|
}else{ |
||||||
|
items.put(format, typeClass); |
||||||
|
log.atInfo().log("Registering class {} for search type {}", typeClass, format); |
||||||
|
} |
||||||
|
} |
||||||
|
}else{ |
||||||
|
log.atError().log("Class {} does not implements OutputFormat but have annotation @OutputFormatter", clazz); |
||||||
|
} |
||||||
|
} catch (ClassNotFoundException e) { |
||||||
|
log.atError().withThrowable(e).log(e.getMessage()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Class<? extends Annotation>[] annotations() { |
||||||
|
return new Class[]{SearchProvider.class}; |
||||||
|
} |
||||||
|
}; |
||||||
|
final AnnotationDetector cf = new AnnotationDetector(reporter); |
||||||
|
try { |
||||||
|
cf.detect(); |
||||||
|
} catch (IOException e) { |
||||||
|
log.atError().withThrowable(e).log(e.getMessage()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public int size() { |
||||||
|
return items.size(); |
||||||
|
} |
||||||
|
|
||||||
|
public boolean isEmpty() { |
||||||
|
return items.isEmpty(); |
||||||
|
} |
||||||
|
|
||||||
|
public Enumeration<String> keys() { |
||||||
|
return items.keys(); |
||||||
|
} |
||||||
|
|
||||||
|
public boolean containsKey(Object key) { |
||||||
|
return items.containsKey(key); |
||||||
|
} |
||||||
|
|
||||||
|
public Class get(Object key) { |
||||||
|
return items.get(key); |
||||||
|
} |
||||||
|
|
||||||
|
public Set<String> keySet() { |
||||||
|
return items.keySet(); |
||||||
|
} |
||||||
|
|
||||||
|
public void forEach(BiConsumer<? super String, ? super Class> action) { |
||||||
|
items.forEach(action); |
||||||
|
} |
||||||
|
|
||||||
|
public int getOutputFormatterCount(){ |
||||||
|
HashSet<Class> set = new HashSet<>(); |
||||||
|
for(Class clazz:items.values()){ |
||||||
|
set.add(clazz); |
||||||
|
} |
||||||
|
return set.size(); |
||||||
|
} |
||||||
|
|
||||||
|
public int getSearchProviderCount(){ |
||||||
|
HashSet<Class> set = new HashSet<>(); |
||||||
|
for(Class clazz:items.values()){ |
||||||
|
set.add(clazz); |
||||||
|
} |
||||||
|
return set.size(); |
||||||
|
} |
||||||
|
} |
||||||
@ -1,8 +1,90 @@ |
|||||||
package org.leolo.map.osm.extract.format; |
package org.leolo.map.osm.extract.format; |
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager; |
||||||
|
import org.apache.logging.log4j.Logger; |
||||||
|
import org.leolo.map.osm.extract.ExtractResult; |
||||||
import org.leolo.map.osm.extract.OutputFormat; |
import org.leolo.map.osm.extract.OutputFormat; |
||||||
import org.leolo.map.osm.extract.OutputFormatter; |
import org.leolo.map.osm.extract.OutputFormatter; |
||||||
|
import org.leolo.map.osm.extract.model.MapEntry; |
||||||
|
import org.leolo.map.osm.extract.model.Node; |
||||||
|
import org.leolo.map.osm.extract.model.Relation; |
||||||
|
import org.leolo.map.osm.extract.model.Way; |
||||||
|
|
||||||
|
import java.io.PrintWriter; |
||||||
|
|
||||||
@OutputFormatter(formatName = {"kml","application/vnd.google-earth.kml+xml"}) |
@OutputFormatter(formatName = {"kml","application/vnd.google-earth.kml+xml"}) |
||||||
public class KMLFormatter implements OutputFormat { |
public class KMLFormatter implements OutputFormat { |
||||||
|
private Logger log = LogManager.getLogger(); |
||||||
|
@Override |
||||||
|
public void writeHeader(PrintWriter output) { |
||||||
|
output.print("<?xml version='1.0'?><kml xmlns='http://www.opengis.net/kml/2.2' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='https://schemas.opengis.net/kml/2.3/ogckml23.xsd'>"); |
||||||
|
output.print("<Document>"); |
||||||
|
output.print("<Style id='sty_0'>"); |
||||||
|
output.print("<LineStyle><color>501400FF</color><width>3</width></LineStyle>"); |
||||||
|
output.print("</Style>"); |
||||||
|
output.print("<Style id='sty_1'><ListStyle><listItemType>checkHideChildren</listItemType></ListStyle></Style>"); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void writeTailer(PrintWriter output) { |
||||||
|
output.print("</Document></kml>"); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void writeRelation(PrintWriter output, long id, ExtractResult extractResult) { |
||||||
|
Relation rel = extractResult.getRelations().get(id); |
||||||
|
output.print(getRelationString(id, extractResult)); |
||||||
|
} |
||||||
|
|
||||||
|
private CharSequence getRelationString(long id, ExtractResult extractResult){ |
||||||
|
Relation rel = extractResult.getRelations().get(id); |
||||||
|
StringBuffer sb = new StringBuffer(); |
||||||
|
sb.append("<Folder id='rel_").append(Long.toHexString(id)).append("'>"); |
||||||
|
sb.append("<styleUrl>#sty_1</styleUrl>"); |
||||||
|
sb.append("<name><![CDATA[").append(rel.getTag("name")).append("<]]></name>"); |
||||||
|
sb.append("<description><![CDATA[<table><tr><th>Tag Name</th><th>Tag Value</th></tr>"); |
||||||
|
rel.tagSet().stream().forEach((tagName)->{ |
||||||
|
StringBuilder tag = new StringBuilder(); |
||||||
|
tag.append("<tr><td>").append(tagName).append("</td><td>").append(rel.getTag(tagName)).append("</td>"); |
||||||
|
sb.append(tag); |
||||||
|
}); |
||||||
|
sb.append("</table>]]></description>"); |
||||||
|
rel.parallelStream().forEach((member)->{ |
||||||
|
MapEntry me = extractResult.getAllEntry().get(member); |
||||||
|
if(me==null){ |
||||||
|
log.atWarn().log("Missing entry {}", id); |
||||||
|
return; |
||||||
|
} |
||||||
|
if(me instanceof Relation){ |
||||||
|
//Calling same function to create nested folder
|
||||||
|
sb.append(getRelationString(member, extractResult)); |
||||||
|
}else if(me instanceof Way){ |
||||||
|
//Handling nameless way
|
||||||
|
StringBuffer wayOut = new StringBuffer(); |
||||||
|
Way way = (Way) me; |
||||||
|
wayOut.append("<Placemark><styleUrl>#sty_0</styleUrl><LineString id='rel_").append(Long.toHexString(id)) |
||||||
|
.append("_w_").append(Long.toHexString(member)).append("'>"); |
||||||
|
wayOut.append("<coordinates>"); |
||||||
|
for(int i=0;i<way.memberCount();i++){ |
||||||
|
Node node = extractResult.getNodes().get(way.getMember(i)); |
||||||
|
wayOut.append(node.getLon()).append(",").append(node.getLat()).append(" "); |
||||||
|
} |
||||||
|
wayOut.append("</coordinates>"); |
||||||
|
wayOut.append("</LineString></Placemark>"); |
||||||
|
sb.append(wayOut); |
||||||
|
} |
||||||
|
}); |
||||||
|
sb.append("</Folder>"); |
||||||
|
return sb; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void writeWay(PrintWriter output, long id, ExtractResult extractResult) { |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void writeNode(PrintWriter output, long id, ExtractResult extractResult) { |
||||||
|
|
||||||
|
} |
||||||
} |
} |
||||||
|
|||||||
@ -0,0 +1,24 @@ |
|||||||
|
package org.leolo.map.osm.extract.format; |
||||||
|
|
||||||
|
import org.leolo.map.osm.extract.SearchProvider; |
||||||
|
import org.leolo.map.osm.extract.model.SearchItem; |
||||||
|
|
||||||
|
@SearchProvider(searchKey = "name") |
||||||
|
public class SimpleStringSearchProvider extends SearchItem { |
||||||
|
|
||||||
|
private String searchKey; |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean matchString(String target) { |
||||||
|
return searchKey.equalsIgnoreCase(target.strip()); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void setSearchKey(String searchKey) { |
||||||
|
this.searchKey = searchKey.strip(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override public String toString(){ |
||||||
|
return "SimpleString["+searchKey+"]"; |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,6 @@ |
|||||||
|
package org.leolo.map.osm.extract.model; |
||||||
|
|
||||||
|
public enum InputType { |
||||||
|
FILE, |
||||||
|
URL; |
||||||
|
} |
||||||
@ -0,0 +1,68 @@ |
|||||||
|
package org.leolo.map.osm.extract.model; |
||||||
|
|
||||||
|
import de.topobyte.osm4j.core.model.iface.OsmEntity; |
||||||
|
import de.topobyte.osm4j.core.model.iface.OsmNode; |
||||||
|
import de.topobyte.osm4j.core.model.iface.OsmRelation; |
||||||
|
import de.topobyte.osm4j.core.model.iface.OsmWay; |
||||||
|
|
||||||
|
import java.util.HashSet; |
||||||
|
import java.util.Set; |
||||||
|
|
||||||
|
public abstract class SearchItem { |
||||||
|
|
||||||
|
private ActionFile af; |
||||||
|
|
||||||
|
private HashSet<String> tagName = new HashSet<>(); |
||||||
|
|
||||||
|
public SearchItem(ActionFile af){ |
||||||
|
this.af = af; |
||||||
|
setTags(); |
||||||
|
} |
||||||
|
|
||||||
|
public SearchItem(){ |
||||||
|
//Empty constructor
|
||||||
|
} |
||||||
|
|
||||||
|
protected final void setActionFile(ActionFile af){ |
||||||
|
this.af = af; |
||||||
|
setTags(); |
||||||
|
} |
||||||
|
|
||||||
|
private void setTags(){ |
||||||
|
tagName.add("name:"+af.getBaseLanguage()); |
||||||
|
for(String lang:af.getOtherLanguage()){ |
||||||
|
tagName.add("name:"+lang); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public abstract boolean matchString(String target); |
||||||
|
public abstract void setSearchKey(String searchKey); |
||||||
|
|
||||||
|
private boolean matchEntity(OsmEntity entity){ |
||||||
|
for(int i=0;i<entity.getNumberOfTags();i++){ |
||||||
|
if("name".equalsIgnoreCase(entity.getTag(i).getKey()) && matchString(entity.getTag(i).getValue())){ |
||||||
|
return true; |
||||||
|
} |
||||||
|
if(af != null){ |
||||||
|
for(String tag:tagName){ |
||||||
|
if(tag.equalsIgnoreCase(entity.getTag(i).getKey()) && matchString(entity.getTag(i).getValue())){ |
||||||
|
return true; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
return false; |
||||||
|
} |
||||||
|
public boolean matchNode(OsmNode node){ |
||||||
|
return matchEntity(node); |
||||||
|
} |
||||||
|
|
||||||
|
public boolean matchWay(OsmWay way){ |
||||||
|
return matchEntity(way); |
||||||
|
} |
||||||
|
|
||||||
|
public boolean matchRelation(OsmRelation relation){ |
||||||
|
return matchEntity(relation); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,92 @@ |
|||||||
|
package org.leolo.map.osm.extract.util; |
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager; |
||||||
|
import org.apache.logging.log4j.Logger; |
||||||
|
|
||||||
|
import java.io.*; |
||||||
|
import java.net.MalformedURLException; |
||||||
|
import java.net.URL; |
||||||
|
|
||||||
|
public abstract class InputFile { |
||||||
|
public abstract long getSize(); |
||||||
|
public abstract InputStream getInputStream() throws IOException; |
||||||
|
|
||||||
|
public long length() { |
||||||
|
return getSize(); |
||||||
|
} |
||||||
|
|
||||||
|
public boolean isValid(){ |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
class FileInputFile extends InputFile{ |
||||||
|
|
||||||
|
private File f; |
||||||
|
|
||||||
|
FileInputFile(File f){ |
||||||
|
this.f = f; |
||||||
|
} |
||||||
|
|
||||||
|
FileInputFile(String f){ |
||||||
|
this.f = new File(f); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public long getSize(){ |
||||||
|
return f.length(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public InputStream getInputStream() throws FileNotFoundException { |
||||||
|
return new FileInputStream(f); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean isValid(){ |
||||||
|
return f.exists() && f.canRead(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
class URLInputFile extends InputFile{ |
||||||
|
|
||||||
|
private Logger log = LogManager.getLogger(); |
||||||
|
private boolean ready = false; |
||||||
|
|
||||||
|
private byte[] data; |
||||||
|
|
||||||
|
public static final int READ_BLOCK_SIZE = 4096; |
||||||
|
|
||||||
|
URLInputFile(String url) throws MalformedURLException, IOException { |
||||||
|
this(new URL(url)); |
||||||
|
} |
||||||
|
URLInputFile(URL url) throws IOException{ |
||||||
|
log.atInfo().log("Connecting to {}", url); |
||||||
|
ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
||||||
|
InputStream is = url.openStream(); |
||||||
|
byte [] buffer = new byte[READ_BLOCK_SIZE]; |
||||||
|
int readSize; |
||||||
|
while((readSize = is.read(buffer))>0){ |
||||||
|
baos.write(buffer, 0, readSize); |
||||||
|
} |
||||||
|
data = baos.toByteArray(); |
||||||
|
is.close(); |
||||||
|
baos.close(); |
||||||
|
ready = true; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public long getSize(){ |
||||||
|
return data.length; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public InputStream getInputStream() throws IOException { |
||||||
|
return new ByteArrayInputStream(data); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean isValid() { |
||||||
|
return ready; |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,27 @@ |
|||||||
|
package org.leolo.map.osm.extract.util; |
||||||
|
|
||||||
|
import org.leolo.map.osm.extract.model.InputType; |
||||||
|
|
||||||
|
import java.io.IOException; |
||||||
|
import java.net.MalformedURLException; |
||||||
|
import java.net.URL; |
||||||
|
import java.util.Locale; |
||||||
|
|
||||||
|
public class InputUtil { |
||||||
|
public static InputType identifyInputType(String str){ |
||||||
|
try { |
||||||
|
URL url = new URL(str); |
||||||
|
} catch (Exception e) { |
||||||
|
return InputType.FILE; |
||||||
|
} |
||||||
|
return InputType.URL; |
||||||
|
} |
||||||
|
|
||||||
|
public static InputFile getInputFile(String path) throws IOException { |
||||||
|
if(identifyInputType(path)==InputType.FILE){ |
||||||
|
return new FileInputFile(path); |
||||||
|
}else{ |
||||||
|
return new URLInputFile(path); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -1,14 +0,0 @@ |
|||||||
import org.junit.jupiter.api.Assertions; |
|
||||||
import org.junit.jupiter.api.Test; |
|
||||||
|
|
||||||
import java.util.ArrayList; |
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*; |
|
||||||
|
|
||||||
public class MainTest { |
|
||||||
|
|
||||||
@Test void test1(){ |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
@ -0,0 +1,50 @@ |
|||||||
|
package org.leolo.map.osm.extract.test; |
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test; |
||||||
|
import org.leolo.map.osm.extract.model.InputType; |
||||||
|
import org.leolo.map.osm.extract.util.InputUtil; |
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*; |
||||||
|
|
||||||
|
public class InputTypeTest { |
||||||
|
|
||||||
|
@Test void testFilePath(){ |
||||||
|
assertEquals(InputUtil.identifyInputType("abc.xml"), InputType.FILE); |
||||||
|
assertEquals(InputUtil.identifyInputType("../abc.xml"), InputType.FILE); |
||||||
|
assertEquals(InputUtil.identifyInputType("./abc.xml"), InputType.FILE); |
||||||
|
assertEquals(InputUtil.identifyInputType("..\\abc.xml"), InputType.FILE); |
||||||
|
assertEquals(InputUtil.identifyInputType("/tmp/abc.xml"), InputType.FILE); |
||||||
|
} |
||||||
|
|
||||||
|
@Test void testUPCPath(){ |
||||||
|
assertEquals(InputUtil.identifyInputType("\\\\somecomputer\\somefolder\\abc.xml"), InputType.FILE); |
||||||
|
} |
||||||
|
|
||||||
|
@Test void testURL(){ |
||||||
|
assertEquals(InputUtil.identifyInputType("http://www.example.com"), InputType.URL); |
||||||
|
assertEquals(InputUtil.identifyInputType("https://www.example.com"), InputType.URL); |
||||||
|
assertEquals(InputUtil.identifyInputType("http://a@www.example.com"), InputType.URL); |
||||||
|
assertEquals(InputUtil.identifyInputType("https://a@www.example.com"), InputType.URL); |
||||||
|
assertEquals(InputUtil.identifyInputType("http://a:1234@www.example.com"), InputType.URL); |
||||||
|
assertEquals(InputUtil.identifyInputType("https://a:1234@www.example.com"), InputType.URL); |
||||||
|
assertEquals(InputUtil.identifyInputType("http://www.example.com:8521"), InputType.URL); |
||||||
|
assertEquals(InputUtil.identifyInputType("https://www.example.com:8521"), InputType.URL); |
||||||
|
assertEquals(InputUtil.identifyInputType("http://a@www.example.com:8521"), InputType.URL); |
||||||
|
assertEquals(InputUtil.identifyInputType("https://a@www.example.com:8521"), InputType.URL); |
||||||
|
assertEquals(InputUtil.identifyInputType("http://a:1234@www.example.com:8521"), InputType.URL); |
||||||
|
assertEquals(InputUtil.identifyInputType("https://a:1234@www.example.com:8521"), InputType.URL); |
||||||
|
assertEquals(InputUtil.identifyInputType("http://www.example.com/abc.xml"), InputType.URL); |
||||||
|
assertEquals(InputUtil.identifyInputType("https://www.example.com/abc.xml"), InputType.URL); |
||||||
|
assertEquals(InputUtil.identifyInputType("http://a@www.example.com/abc.xml"), InputType.URL); |
||||||
|
assertEquals(InputUtil.identifyInputType("https://a@www.example.com/abc.xml"), InputType.URL); |
||||||
|
assertEquals(InputUtil.identifyInputType("http://a:1234@www.example.com/abc.xml"), InputType.URL); |
||||||
|
assertEquals(InputUtil.identifyInputType("https://a:1234@www.example.com/abc.xml"), InputType.URL); |
||||||
|
assertEquals(InputUtil.identifyInputType("http://www.example.com:8521/abc.xml"), InputType.URL); |
||||||
|
assertEquals(InputUtil.identifyInputType("https://www.example.com:8521/abc.xml"), InputType.URL); |
||||||
|
assertEquals(InputUtil.identifyInputType("http://a@www.example.com:8521/abc.xml"), InputType.URL); |
||||||
|
assertEquals(InputUtil.identifyInputType("https://a@www.example.com:8521/abc.xml"), InputType.URL); |
||||||
|
assertEquals(InputUtil.identifyInputType("http://a:1234@www.example.com:8521/abc.xml"), InputType.URL); |
||||||
|
assertEquals(InputUtil.identifyInputType("https://a:1234@www.example.com:8521/abc.xml"), InputType.URL); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,23 @@ |
|||||||
|
package org.leolo.map.osm.extract.test; |
||||||
|
|
||||||
|
import org.junit.jupiter.api.Assertions; |
||||||
|
import org.junit.jupiter.api.Test; |
||||||
|
import org.leolo.map.osm.extract.util.InputFile; |
||||||
|
import org.leolo.map.osm.extract.util.InputUtil; |
||||||
|
|
||||||
|
import java.io.IOException; |
||||||
|
import java.util.ArrayList; |
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*; |
||||||
|
|
||||||
|
public class MainTest { |
||||||
|
|
||||||
|
@Test void test1(){ |
||||||
|
System.out.println("Test executed."); |
||||||
|
} |
||||||
|
|
||||||
|
@Test void downloadFile() throws IOException { |
||||||
|
InputFile inputFile = InputUtil.getInputFile("https://www.leolo.pro/sample"); |
||||||
|
assertEquals(inputFile.length(), 8192); |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue