Changeset 29706 in osm for applications/editors/josm/plugins/opendata
- Timestamp:
- 2013-06-26T22:14:50+02:00 (12 years ago)
- Location:
- applications/editors/josm/plugins/opendata
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/opendata/build.xml
r29694 r29706 1 1 <?xml version="1.0" encoding="utf-8"?> 2 2 <project name="opendata" default="dist" basedir="."> 3 <property name="plugin.main.version" value=" 5874"/>3 <property name="plugin.main.version" value="6031"/> 4 4 <property name="plugin.author" value="Don-vip"/> 5 5 <property name="plugin.class" value="org.openstreetmap.josm.plugins.opendata.OdPlugin"/> -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/actions/DownloadDataTask.java
r28696 r29706 73 73 } 74 74 } 75 for (String ext : new String[]{ZIP_EXT, CSV_EXT, KML_EXT, KMZ_EXT, XLS_EXT, ODS_EXT, SHP_EXT, MIF_EXT, TAB_EXT}) {75 for (String ext : NetworkReader.FILE_AND_ARCHIVE_READERS.keySet()) { 76 76 if (Pattern.compile(".*\\."+ext, Pattern.CASE_INSENSITIVE).matcher(url).matches()) { 77 77 return true; … … 81 81 } 82 82 83 protected class InternalDownloadTasK extends DownloadTask { 83 @Override 84 public String[] getPatterns() { 85 String pattern = ""; 86 for (String ext : NetworkReader.FILE_AND_ARCHIVE_READERS.keySet()) { 87 if (!pattern.isEmpty()) { 88 pattern += "|"; 89 } 90 pattern += "."+ext; 91 } 92 return new String[]{".*(" + pattern + ")"}; 93 } 94 95 @Override 96 public String getTitle() { 97 return tr("Download open data"); 98 } 99 100 protected class InternalDownloadTasK extends DownloadTask { 84 101 85 102 public InternalDownloadTasK(boolean newLayer, NetworkReader reader, ProgressMonitor progressMonitor) { -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/NetworkReader.java
r29686 r29706 20 20 import java.io.File; 21 21 import java.io.InputStream; 22 import java.util.HashMap; 23 import java.util.Map; 22 24 import java.util.regex.Matcher; 23 25 import java.util.regex.Pattern; … … 53 55 private File file; 54 56 private String filename; 55 57 58 /** 59 * File readers 60 */ 61 public static final Map<String, Class<? extends AbstractReader>> FILE_READERS = new HashMap<String, Class<? extends AbstractReader>>(); 62 static { 63 FILE_READERS.put(CSV_EXT, CsvReader.class); 64 FILE_READERS.put(KML_EXT, KmlReader.class); 65 FILE_READERS.put(KMZ_EXT, KmzReader.class); 66 FILE_READERS.put(GML_EXT, GmlReader.class); 67 FILE_READERS.put(XLS_EXT, XlsReader.class); 68 FILE_READERS.put(ODS_EXT, OdsReader.class); 69 FILE_READERS.put(SHP_EXT, ShpReader.class); 70 FILE_READERS.put(MIF_EXT, MifReader.class); 71 FILE_READERS.put(TAB_EXT, TabReader.class); 72 } 73 74 public static final Map<String, Class<? extends AbstractReader>> FILE_AND_ARCHIVE_READERS = new HashMap<String, Class<? extends AbstractReader>>(FILE_READERS); 75 static { 76 FILE_AND_ARCHIVE_READERS.put(ZIP_EXT, ZipReader.class); 77 FILE_AND_ARCHIVE_READERS.put(SEVENZIP_EXT, SevenZipReader.class); 78 } 79 56 80 public NetworkReader(String url, AbstractDataSetHandler handler, boolean promptUser) { 57 81 CheckParameterUtil.ensureParameterNotNull(url, "url"); … … 76 100 if (m.matches()) { 77 101 filename = m.group(1); 78 return findReaderByExtension(filename .toLowerCase());102 return findReaderByExtension(filename); 79 103 } 80 104 } … … 105 129 106 130 private Class<? extends AbstractReader> findReaderByExtension(String filename) { 107 filename = filename.replace("\"", ""); 108 if (filename.endsWith("."+XLS_EXT)) { 109 return XlsReader.class; 110 } else if (filename.endsWith("."+CSV_EXT)) { 111 return CsvReader.class; 112 } else if (filename.endsWith("."+ODS_EXT)) { 113 return OdsReader.class; 114 } else if (filename.endsWith("."+KML_EXT)) { 115 return KmlReader.class; 116 } else if (filename.endsWith("."+KMZ_EXT)) { 117 return KmzReader.class; 118 } else if (filename.endsWith("."+MIF_EXT)) { 119 return MifReader.class; 120 } else if (filename.endsWith("."+SHP_EXT)) { 121 return ShpReader.class; 122 } else if (filename.endsWith("."+TAB_EXT)) { 123 return TabReader.class; 124 } else if (filename.endsWith("."+GML_EXT)) { 125 return GmlReader.class; 126 } else if (filename.endsWith("."+ZIP_EXT)) { 127 return ZipReader.class; 128 } else if (filename.endsWith("."+SEVENZIP_EXT)) { 129 return SevenZipReader.class; 130 } else { 131 return null; 132 } 131 filename = filename.replace("\"", "").toLowerCase(); 132 for (String ext : FILE_AND_ARCHIVE_READERS.keySet()) { 133 if (filename.endsWith("."+ext)) { 134 return FILE_AND_ARCHIVE_READERS.get(ext); 135 } 136 } 137 return null; 133 138 } 134 139 … … 146 151 } 147 152 if (readerClass == null) { 148 readerClass = findReaderByExtension(url .toLowerCase());153 readerClass = findReaderByExtension(url); 149 154 } 150 155 if (readerClass == null) { … … 153 158 if (readerClass == null) { 154 159 throw new OsmTransferException("Cannot find appropriate reader !");//TODO handler job ? 155 } else if (findReaderByExtension(url .toLowerCase()) != null) {160 } else if (findReaderByExtension(url) != null) { 156 161 filename = url.substring(url.lastIndexOf('/')+1); 157 162 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/archive/ArchiveReader.java
r29680 r29706 36 36 import org.openstreetmap.josm.plugins.opendata.core.gui.DialogPrompter; 37 37 import org.openstreetmap.josm.plugins.opendata.core.io.NeptuneReader; 38 import org.openstreetmap.josm.plugins.opendata.core.io.NetworkReader; 38 39 import org.openstreetmap.josm.plugins.opendata.core.io.geographic.GmlReader; 39 40 import org.openstreetmap.josm.plugins.opendata.core.io.geographic.KmlReader; … … 96 97 } 97 98 98 if (file == null) { 99 return null; 100 } else if (!file.exists()) { 101 Main.warn("File does not exist: "+file.getPath()); 102 return null; 103 } else { 104 DataSet from = null; 105 FileInputStream in = new FileInputStream(file); 106 ProgressMonitor instance = null; 107 if (progressMonitor != null) { 108 instance = progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false); 109 } 110 if (file.getName().toLowerCase().endsWith(CSV_EXT)) { 111 from = CsvReader.parseDataSet(in, handler, instance); 112 } else if (file.getName().toLowerCase().endsWith(KML_EXT)) { 113 from = KmlReader.parseDataSet(in, instance); 114 } else if (file.getName().toLowerCase().endsWith(KMZ_EXT)) { 115 from = KmzReader.parseDataSet(in, instance); 116 } else if (file.getName().toLowerCase().endsWith(XLS_EXT)) { 117 from = XlsReader.parseDataSet(in, handler, instance); 118 } else if (file.getName().toLowerCase().endsWith(ODS_EXT)) { 119 from = OdsReader.parseDataSet(in, handler, instance); 120 } else if (file.getName().toLowerCase().endsWith(SHP_EXT)) { 121 from = ShpReader.parseDataSet(in, file, handler, instance); 122 } else if (file.getName().toLowerCase().endsWith(MIF_EXT)) { 123 from = MifReader.parseDataSet(in, file, handler, instance); 124 } else if (file.getName().toLowerCase().endsWith(TAB_EXT)) { 125 from = TabReader.parseDataSet(in, file, handler, instance); 126 } else if (file.getName().toLowerCase().endsWith(GML_EXT)) { 127 from = GmlReader.parseDataSet(in, handler, instance); 128 } else if (file.getName().toLowerCase().endsWith(XML_EXT)) { 129 if (OdPlugin.getInstance().xmlImporter.acceptFile(file)) { 130 from = NeptuneReader.parseDataSet(in, handler, instance); 131 } else { 132 System.err.println("Unsupported XML file: "+file.getName()); 133 } 134 135 } else { 136 System.err.println("Unsupported file extension: "+file.getName()); 137 } 138 if (from != null) { 139 ds = from; 140 } 99 DataSet from = getDataForFile(progressMonitor); 100 if (from != null) { 101 ds = from; 141 102 } 142 103 } catch (IllegalArgumentException e) { … … 152 113 } 153 114 115 protected DataSet getDataForFile(final ProgressMonitor progressMonitor) 116 throws FileNotFoundException, IOException, XMLStreamException, FactoryConfigurationError, JAXBException { 117 if (file == null) { 118 return null; 119 } else if (!file.exists()) { 120 Main.warn("File does not exist: "+file.getPath()); 121 return null; 122 } else { 123 DataSet from = null; 124 FileInputStream in = new FileInputStream(file); 125 ProgressMonitor instance = null; 126 if (progressMonitor != null) { 127 instance = progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false); 128 } 129 if (file.getName().toLowerCase().endsWith(CSV_EXT)) { 130 from = CsvReader.parseDataSet(in, handler, instance); 131 } else if (file.getName().toLowerCase().endsWith(KML_EXT)) { 132 from = KmlReader.parseDataSet(in, instance); 133 } else if (file.getName().toLowerCase().endsWith(KMZ_EXT)) { 134 from = KmzReader.parseDataSet(in, instance); 135 } else if (file.getName().toLowerCase().endsWith(XLS_EXT)) { 136 from = XlsReader.parseDataSet(in, handler, instance); 137 } else if (file.getName().toLowerCase().endsWith(ODS_EXT)) { 138 from = OdsReader.parseDataSet(in, handler, instance); 139 } else if (file.getName().toLowerCase().endsWith(SHP_EXT)) { 140 from = ShpReader.parseDataSet(in, file, handler, instance); 141 } else if (file.getName().toLowerCase().endsWith(MIF_EXT)) { 142 from = MifReader.parseDataSet(in, file, handler, instance); 143 } else if (file.getName().toLowerCase().endsWith(TAB_EXT)) { 144 from = TabReader.parseDataSet(in, file, handler, instance); 145 } else if (file.getName().toLowerCase().endsWith(GML_EXT)) { 146 from = GmlReader.parseDataSet(in, handler, instance); 147 } else if (file.getName().toLowerCase().endsWith(XML_EXT)) { 148 if (OdPlugin.getInstance().xmlImporter.acceptFile(file)) { 149 from = NeptuneReader.parseDataSet(in, handler, instance); 150 } else { 151 System.err.println("Unsupported XML file: "+file.getName()); 152 } 153 154 } else { 155 System.err.println("Unsupported file extension: "+file.getName()); 156 } 157 return from; 158 } 159 } 160 154 161 protected final void lookForCandidate(String entryName, final List<File> candidates, File file) { 155 162 // Test file name to see if it may contain useful data 156 for (String ext : new String[] { 157 CSV_EXT, KML_EXT, KMZ_EXT, XLS_EXT, ODS_EXT, SHP_EXT, MIF_EXT, TAB_EXT, GML_EXT 158 }) { 163 for (String ext : NetworkReader.FILE_READERS.keySet()) { 159 164 if (entryName.toLowerCase().endsWith("."+ext)) { 160 165 candidates.add(file);
Note:
See TracChangeset
for help on using the changeset viewer.