Changeset 28050 in osm for applications/editors/josm/plugins/opendata
- Timestamp:
- 2012-03-11T21:59:38+01:00 (13 years ago)
- Location:
- applications/editors/josm/plugins/opendata
- Files:
-
- 1 added
- 22 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/opendata/modules/fr.datagouvfr/build.xml
r28000 r28050 60 60 <target name="compile" depends="init"> 61 61 <echo message="compiling sources for ${module.jar} ... "/> 62 <javac srcdir="${module.src.dir}" debug="true" destdir="${module.build.dir}" includeAntRuntime="false"> 62 <javac srcdir="${module.src.dir}" debug="true" destdir="${module.build.dir}" includeAntRuntime="false" encoding="UTF-8" > 63 63 <classpath> 64 64 <pathelement location="${josm}"/> -
applications/editors/josm/plugins/opendata/modules/fr.datagouvfr/src/org/openstreetmap/josm/plugins/opendata/modules/fr/datagouvfr/datasets/DataGouvDataSetHandler.java
r28000 r28050 16 16 package org.openstreetmap.josm.plugins.opendata.modules.fr.datagouvfr.datasets; 17 17 18 import java.net.MalformedURLException; 18 19 import java.net.URL; 19 20 … … 66 67 return null; 67 68 } 69 70 /* (non-Javadoc) 71 * @see org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler#getLicenseURL() 72 */ 73 @Override 74 public URL getLicenseURL() { 75 try { 76 return new URL(FRENCH_PORTAL+"Licence-Ouverte-Open-Licence"); 77 } catch (MalformedURLException e) { 78 e.printStackTrace(); 79 } 80 return null; 81 } 82 83 protected final void setDataGouvFrUrl(String suffix) { 84 try { 85 setDataURL(FRENCH_PORTAL+"var/download/"+suffix); 86 } catch (MalformedURLException e) { 87 e.printStackTrace(); 88 } 89 } 68 90 } -
applications/editors/josm/plugins/opendata/modules/fr.datagouvfr/src/org/openstreetmap/josm/plugins/opendata/modules/fr/datagouvfr/datasets/administration/GeoFlaHandler.java
r28000 r28050 18 18 import java.net.MalformedURLException; 19 19 import java.net.URL; 20 import java.util.ArrayList; 21 import java.util.List; 20 22 21 23 import org.apache.commons.lang3.text.WordUtils; … … 28 30 import org.openstreetmap.josm.data.osm.RelationMember; 29 31 import org.openstreetmap.josm.plugins.opendata.modules.fr.datagouvfr.datasets.DataGouvDataSetHandler; 32 import org.openstreetmap.josm.tools.Pair; 30 33 31 34 public class GeoFlaHandler extends DataGouvDataSetHandler { … … 33 36 public GeoFlaHandler() { 34 37 super(); 38 setName("GEOFLA®"); 35 39 } 36 40 … … 201 205 return null; 202 206 } 207 208 private Pair<String, URL> getGeoflaURL(String name, String urlSuffix) throws MalformedURLException { 209 return new Pair<String, URL>(name, new URL("http://professionnels.ign.fr/DISPLAY/000/"+urlSuffix)); 210 } 211 212 /* (non-Javadoc) 213 * @see org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler#getDataURLs() 214 */ 215 @Override 216 public List<Pair<String, URL>> getDataURLs() { 217 List<Pair<String, URL>> result = new ArrayList<Pair<String,URL>>(); 218 try { 219 result.add(getGeoflaURL("Départements France métropolitaine et Corse", "528/175/5281750/GEOFLADept_FR_Corse_AV_L93.zip")); 220 result.add(getGeoflaURL("Départements France entière", "528/175/5281754/FR_DOM_Mayotte_shp_WGS84.zip")); 221 // FIXME: tar.gz files 222 /*result.add(getGeoflaURL("Communes France métropolitaine", "531/266/5312664/GEOFLA_1-1_SHP_LAMB93_FR-ED111.tar.gz")); 223 result.add(getGeoflaURL("Communes Guadeloupe", "531/265/5312650/GEOFLA_1-1_SHP_UTM20W84_GP-ED111.tar.gz")); 224 result.add(getGeoflaURL("Communes Martinique", "531/265/5312653/GEOFLA_1-1_SHP_UTM20W84_MQ-ED111.tar.gz")); 225 result.add(getGeoflaURL("Communes Guyane", "531/265/5312657/GEOFLA_1-1_SHP_UTM22RGFG95_GF-ED111.tar.gz")); 226 result.add(getGeoflaURL("Communes Réunion", "531/266/5312660/GEOFLA_1-1_SHP_RGR92UTM40S_RE-ED111.tar.gz")); 227 result.add(getGeoflaURL("Communes Mayotte", "531/275/5312753/GEOFLA_1-1_SHP_RGM04UTM38S_YT-ED111.tar.gz"));*/ 228 } catch (MalformedURLException e) { 229 e.printStackTrace(); 230 } 231 return result; 232 } 203 233 } -
applications/editors/josm/plugins/opendata/modules/fr.datagouvfr/src/org/openstreetmap/josm/plugins/opendata/modules/fr/datagouvfr/datasets/agriculture/RegistreParcellaireHandler.java
r28000 r28050 16 16 package org.openstreetmap.josm.plugins.opendata.modules.fr.datagouvfr.datasets.agriculture; 17 17 18 import java.net.MalformedURLException; 19 import java.net.URL; 20 import java.util.ArrayList; 21 import java.util.List; 22 18 23 import org.openstreetmap.josm.data.osm.DataSet; 19 24 import org.openstreetmap.josm.data.osm.OsmPrimitive; 20 25 import org.openstreetmap.josm.gui.preferences.SourceEditor.ExtendedSourceEntry; 26 import org.openstreetmap.josm.plugins.opendata.core.datasets.fr.FrenchDepartment; 21 27 import org.openstreetmap.josm.plugins.opendata.modules.fr.datagouvfr.datasets.DataGouvDataSetHandler; 28 import org.openstreetmap.josm.tools.Pair; 22 29 23 30 public class RegistreParcellaireHandler extends DataGouvDataSetHandler { … … 55 62 public RegistreParcellaireHandler() { 56 63 super(); 64 setName("Registre Parcellaire Graphique"); 57 65 } 58 66 … … 124 132 } 125 133 } 134 135 private Pair<String, URL> getRpgURL(String number, String name) throws MalformedURLException { 136 return new Pair<String, URL>(number+" - "+name, new URL("http://www.data.gouv.fr/var/download/ign/RPG_2010_"+number+".ZIP")); 137 } 138 139 /* (non-Javadoc) 140 * @see org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler#getDataURLs() 141 */ 142 @Override 143 public List<Pair<String, URL>> getDataURLs() { 144 List<Pair<String, URL>> result = new ArrayList<Pair<String,URL>>(); 145 try { 146 for (FrenchDepartment dpt : FrenchDepartment.allDepartments) { 147 result.add(getRpgURL(dpt.getCode(), dpt.getName())); 148 } 149 } catch (MalformedURLException e) { 150 e.printStackTrace(); 151 } 152 return result; 153 } 126 154 } -
applications/editors/josm/plugins/opendata/modules/fr.datagouvfr/src/org/openstreetmap/josm/plugins/opendata/modules/fr/datagouvfr/datasets/culture/BibliothequesHandler.java
r28000 r28050 19 19 20 20 import org.openstreetmap.josm.data.osm.DataSet; 21 import org.openstreetmap.josm.data.osm.Node; 21 22 import org.openstreetmap.josm.plugins.opendata.modules.fr.datagouvfr.datasets.DataGouvDataSetHandler; 22 23 … … 25 26 public BibliothequesHandler() { 26 27 super("Adresses-des-bibliothèques-municipales-30382179", lambert93); 28 setName("Bibliothèques municipales"); 29 setDataGouvFrUrl("lieux de lecture_geoloc.txt"); 27 30 } 28 31 … … 34 37 @Override 35 38 public void updateDataSet(DataSet ds) { 36 // TODO Auto-generated method stub 37 39 for (Node n : ds.getNodes()) { 40 n.put("amenity", "library"); 41 } 38 42 } 39 43 -
applications/editors/josm/plugins/opendata/modules/fr.datagouvfr/src/org/openstreetmap/josm/plugins/opendata/modules/fr/datagouvfr/datasets/diplomatie/EtabAEFEHandler.java
r28000 r28050 24 24 public EtabAEFEHandler() { 25 25 super("Géolocalisation-des-établissements-du-réseau-d'enseignement-de-l'AEFE-30382449", wgs84); 26 setName("Établissements du réseau d'enseignement de l'AEFE"); 27 setDataGouvFrUrl("ETALAB_MAEE_Extraction_LDAP_geoloc_AEFE_2011-10-13.csv"); 26 28 } 27 29 28 30 @Override 29 31 public boolean acceptsFilename(String filename) { 30 return acceptsCsvFilename(filename, "ETALAB_MAEE_Extraction_LDAP_geoloc_AEFE_20..-..-..\\.csv-fr"); 32 return acceptsCsvFilename(filename, "ETALAB_MAEE_Extraction_LDAP_geoloc_AEFE_20..-..-..(\\.csv-fr)?"); 31 33 } 32 34 -
applications/editors/josm/plugins/opendata/modules/fr.datagouvfr/src/org/openstreetmap/josm/plugins/opendata/modules/fr/datagouvfr/datasets/ecologie/AssainissementHandler.java
r28000 r28050 16 16 package org.openstreetmap.josm.plugins.opendata.modules.fr.datagouvfr.datasets.ecologie; 17 17 18 import java.net.MalformedURLException; 19 import java.net.URL; 20 import java.util.ArrayList; 21 import java.util.List; 22 18 23 import org.openstreetmap.josm.data.osm.DataSet; 19 24 import org.openstreetmap.josm.plugins.opendata.modules.fr.datagouvfr.datasets.DataGouvDataSetHandler; 25 import org.openstreetmap.josm.tools.Pair; 20 26 21 27 public class AssainissementHandler extends DataGouvDataSetHandler { … … 23 29 public AssainissementHandler() { 24 30 super("assainissement-collectif-30381843"); 31 setName("Assainissement collectif"); 25 32 } 26 33 … … 42 49 return 1; 43 50 } 51 52 /* (non-Javadoc) 53 * @see org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler#getDataURLs() 54 */ 55 @Override 56 public List<Pair<String, URL>> getDataURLs() { 57 List<Pair<String, URL>> result = new ArrayList<Pair<String,URL>>(); 58 try { 59 result.add(new Pair<String, URL>("Données 2009", new URL("http://www.assainissement.developpement-durable.gouv.fr/telecharger2.php"))); 60 // FIXME problem with 2010 file (blank cells ?) 61 //result.add(new Pair<String, URL>("Données 2010", new URL("http://www.assainissement.developpement-durable.gouv.fr/telecharger2_2010.php"))); 62 } catch (MalformedURLException e) { 63 e.printStackTrace(); 64 } 65 return result; 66 } 44 67 } -
applications/editors/josm/plugins/opendata/modules/fr.datagouvfr/src/org/openstreetmap/josm/plugins/opendata/modules/fr/datagouvfr/datasets/education/Etab1er2ndDegreHandler.java
r28000 r28050 28 28 public Etab1er2ndDegreHandler() { 29 29 super("Géolocalisation-des-établissements-d'enseignement-du-premier-degré-et-du-second-degré-du-ministère-d-30378093"); 30 setName("Établissements d'enseignement du premier degré et du second degré"); 31 setDataGouvFrUrl("MENJVA_etab_geoloc.csv"); 30 32 } 31 33 32 34 @Override 33 35 public boolean acceptsFilename(String filename) { 34 return acceptsCsvFilename(filename, "MENJVA_etab_geoloc .csv-fr");36 return acceptsCsvFilename(filename, "MENJVA_etab_geoloc(\\.csv-fr)?"); 35 37 } 36 38 -
applications/editors/josm/plugins/opendata/modules/fr.datagouvfr/src/org/openstreetmap/josm/plugins/opendata/modules/fr/datagouvfr/datasets/education/EtabSupHandler.java
r28000 r28050 26 26 public EtabSupHandler() { 27 27 super("Etablissements-d'enseignement-supérieur-30382046", wgs84); 28 setName("Établissements d'enseignement supérieur"); 29 setDataGouvFrUrl("livraison ETALAB 28 11 2011.xls"); 28 30 } 29 31 30 32 @Override 31 33 public boolean acceptsFilename(String filename) { 32 return acceptsXlsFilename(filename, "livraison ETALAB .. .. 20..\\.xls-fr"); 34 return acceptsXlsFilename(filename, "livraison ETALAB .. .. 20..(\\.xls-fr)?"); 33 35 } 34 36 -
applications/editors/josm/plugins/opendata/modules/fr.datagouvfr/src/org/openstreetmap/josm/plugins/opendata/modules/fr/datagouvfr/datasets/hydrologie/ROEHandler.java
r28000 r28050 16 16 package org.openstreetmap.josm.plugins.opendata.modules.fr.datagouvfr.datasets.hydrologie; 17 17 18 import java.net.MalformedURLException; 19 18 20 import org.openstreetmap.josm.data.osm.DataSet; 19 21 import org.openstreetmap.josm.data.osm.Node; … … 24 26 public ROEHandler() { 25 27 super("référentiel-des-obstacles-à-l'écoulement-30381987"); 28 setName("Référentiel des Obstacles à l’Écoulement"); 29 try { 30 setDataURL("http://www.eaufrance.fr/docs/ROE/donnee_obstacles_ecoulement_v3.zip"); 31 } catch (MalformedURLException e) { 32 e.printStackTrace(); 33 } 26 34 } 27 35 -
applications/editors/josm/plugins/opendata/modules/fr.datagouvfr/src/org/openstreetmap/josm/plugins/opendata/modules/fr/datagouvfr/datasets/transport/PassageNiveauHandler.java
r28000 r28050 26 26 public PassageNiveauHandler() { 27 27 super("Passages-à-niveau-30383135"); 28 setName("Passages à niveau"); 29 setDataGouvFrUrl("passage_a_niveau.csv"); 28 30 } 29 31 30 32 @Override 31 33 public boolean acceptsFilename(String filename) { 32 return acceptsCsvFilename(filename, "passage_a_niveau .csv-fr");34 return acceptsCsvFilename(filename, "passage_a_niveau(\\.csv-fr)?"); 33 35 } 34 36 -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/OdPlugin.java
r28044 r28050 19 19 import static org.openstreetmap.josm.tools.I18n.marktr; 20 20 21 import java.awt.Toolkit; 21 22 import java.awt.event.KeyEvent; 22 23 import java.io.File; 24 import java.net.URL; 23 25 import java.util.Arrays; 24 26 import java.util.HashMap; … … 27 29 28 30 import javax.swing.JMenu; 31 import javax.swing.JMenuItem; 29 32 30 33 import org.openstreetmap.josm.Main; … … 32 35 import org.openstreetmap.josm.gui.MainMenu; 33 36 import org.openstreetmap.josm.gui.MapFrame; 37 import org.openstreetmap.josm.gui.MenuScroller; 34 38 import org.openstreetmap.josm.gui.preferences.PreferenceSetting; 35 39 import org.openstreetmap.josm.plugins.Plugin; … … 55 59 import org.openstreetmap.josm.plugins.opendata.core.modules.ModuleHandler; 56 60 import org.openstreetmap.josm.plugins.opendata.core.modules.ModuleInformation; 61 import org.openstreetmap.josm.tools.Pair; 57 62 58 63 public final class OdPlugin extends Plugin implements OdConstants { … … 93 98 } 94 99 100 private JMenu getModuleMenu(Module module) { 101 String moduleName = module.getDisplayedName(); 102 if (moduleName == null || moduleName.isEmpty()) { 103 moduleName = module.getModuleInformation().getName(); 104 } 105 JMenu moduleMenu = new JMenu(moduleName); 106 moduleMenu.setIcon(module.getModuleInformation().getScaledIcon()); 107 return moduleMenu; 108 } 109 95 110 private void buildMenu() { 111 int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height; 96 112 for (Module module : ModuleHandler.moduleList) { 97 113 Map<DataSetCategory, JMenu> catMenus = new HashMap<DataSetCategory, JMenu>(); 98 114 JMenu moduleMenu = null; 99 115 for (AbstractDataSetHandler handler: module.getHandlers()) { 100 if (handler.getDataURL() != null) { 116 if (handler.getDataURL() != null || (handler.getDataURLs() != null && !handler.getDataURLs().isEmpty())) { 101 117 if (moduleMenu == null) { 102 String moduleName = module.getDisplayedName(); 103 if (moduleName == null || moduleName.isEmpty()) { 104 moduleName = module.getModuleInformation().getName(); 105 } 106 moduleMenu = new JMenu(moduleName); 107 moduleMenu.setIcon(module.getModuleInformation().getScaledIcon()); 118 moduleMenu = getModuleMenu(module); 108 119 } 109 120 DataSetCategory cat = handler.getCategory(); … … 118 129 endMenu = moduleMenu; 119 130 } 120 endMenu.add(new DownloadDataAction(handler)); 131 String handlerName = handler.getName(); 132 if (handlerName == null || handlerName.isEmpty()) { 133 handlerName = handler.getClass().getName(); 134 } 135 if (handler.getDataURL() != null) { 136 endMenu.add(new DownloadDataAction(handlerName, handler.getDataURL())); 137 } else if (handler.getDataURLs() != null) { 138 JMenu handlerMenu = new JMenu(handlerName); 139 JMenuItem item = null; 140 for (Pair<String, URL> pair : handler.getDataURLs()) { 141 if (pair != null && pair.a != null && pair.b != null) { 142 item = handlerMenu.add(new DownloadDataAction(pair.a, pair.b)); 143 } 144 } 145 if (item != null) { 146 MenuScroller.setScrollerFor(handlerMenu, (screenHeight / item.getPreferredSize().height)-3); 147 endMenu.add(handlerMenu); 148 } 149 } 121 150 } 122 151 } 123 152 if (moduleMenu != null) { 153 //MenuScroller.setScrollerFor(moduleMenu, screenHeight / moduleMenu.getItem(0).getPreferredSize().height); 124 154 menu.add(moduleMenu); 125 155 } 126 156 } 127 157 menu.addSeparator(); 128 MainMenu.add(menu, new OpenPreferencesActions()); 158 /*JMenuItem itemIcon =*/ MainMenu.add(menu, new OpenPreferencesActions()); 159 //MenuScroller.setScrollerFor(menu, screenHeight / itemIcon.getPreferredSize().height); 129 160 } 130 161 -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/OdConstants.java
r28033 r28050 126 126 public static final String Y_STRING = "Y|LAT|LATI|LATITUDE|NORTHING"; 127 127 128 // The list of all ProjectionPatterns (filled at each constr cutor call)128 // The list of all ProjectionPatterns (filled at each constructor call) 129 129 public static final Collection<ProjectionPatterns> PROJECTIONS = new ArrayList<ProjectionPatterns>(); 130 130 -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/actions/DownloadDataAction.java
r28044 r28050 17 17 18 18 import java.awt.event.ActionEvent; 19 import java.net.URL; 19 20 20 21 import javax.swing.Action; … … 22 23 import org.openstreetmap.josm.Main; 23 24 import org.openstreetmap.josm.actions.JosmAction; 24 import org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler;25 25 import org.openstreetmap.josm.tools.CheckParameterUtil; 26 26 27 27 public class DownloadDataAction extends JosmAction { 28 28 29 private final AbstractDataSetHandler handler;29 private final URL url; 30 30 31 public DownloadDataAction(AbstractDataSetHandler handler) { 32 CheckParameterUtil.ensureParameterNotNull(handler, "handler"); 33 this.handler = handler; 34 String name = handler.getName(); 35 if (name == null || name.isEmpty()) { 36 name = handler.getClass().getName(); 37 } 31 public DownloadDataAction(String name, URL url) { 32 super(false); 33 CheckParameterUtil.ensureParameterNotNull(name, "name"); 34 CheckParameterUtil.ensureParameterNotNull(url, "url"); 38 35 putValue(Action.NAME, name); 36 putValue("toolbar", "opendata_download_"+name.toLowerCase().replace(" ", "_")); 37 this.url = url; 39 38 } 40 39 41 40 @Override 42 41 public void actionPerformed(ActionEvent e) { 43 Main.main.menu.openLocation.openUrl(true, handler.getDataURL().toString());42 Main.main.menu.openLocation.openUrl(true, url.toString()); 44 43 } 45 44 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/actions/DownloadDataTask.java
r28044 r28050 56 56 for (Module module : ModuleHandler.moduleList) { 57 57 for (AbstractDataSetHandler handler : module.getHandlers()) { 58 if (handler != null && handler.getDataURL() != null && url.equals(handler.getDataURL().toString())) {58 if (handler.acceptsUrl(url)) { 59 59 this.handler = handler; 60 60 return true; … … 77 77 protected OsmDataLayer createNewLayer(String layerName) { 78 78 File associatedFile = ((NetworkReader)reader).getReadFile(); 79 String filename = ((NetworkReader)reader).getReadFileName(); 79 80 if (layerName == null || layerName.isEmpty()) { 80 layerName = associatedFile == null ? OsmDataLayer.createNewName() : associatedFile.getName(); 81 if (associatedFile != null) { 82 layerName = associatedFile.getName(); 83 } else if (filename != null && !filename.isEmpty()) { 84 layerName = filename; 85 } else { 86 layerName = OsmDataLayer.createNewName(); 87 } 81 88 } 82 89 DataSetUpdater.updateDataSet(dataSet, handler, associatedFile); -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/actions/OpenPreferencesActions.java
r28044 r28050 30 30 31 31 public OpenPreferencesActions() { 32 super(false); 32 33 putValue(NAME, tr("Preferences")); 33 34 putValue(SMALL_ICON, ImageProvider.get("dialogs", ICON_CORE_24)); 35 putValue("toolbar", "opendata_open_preferences"); 34 36 } 35 37 -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/datasets/AbstractDataSetHandler.java
r28044 r28050 17 17 18 18 import java.io.File; 19 import java.net.MalformedURLException; 19 20 import java.net.URL; 20 21 import java.nio.charset.Charset; … … 97 98 private String sourceDate; 98 99 private File associatedFile; 100 private URL dataURL; 99 101 100 102 public AbstractDataSetHandler() { … … 179 181 public URL getLicenseURL() {return null;} 180 182 181 public URL getDataURL() {return null;} 182 183 public URL getDataURL() {return dataURL;} 184 185 public final void setDataURL(String url) throws MalformedURLException { 186 this.dataURL = new URL(url); 187 } 188 189 public final void setDataURL(URL url) { 190 this.dataURL = url; 191 } 192 193 public List<Pair<String,URL>> getDataURLs() {return null;} 194 183 195 public AbstractReader getReaderForUrl(String url) {return null;} 184 196 … … 522 534 return false; 523 535 } 536 537 public boolean acceptsUrl(String url) { 538 if (getDataURL() != null && url.equals(getDataURL().toString())) { 539 return true; 540 } 541 if (getDataURLs() != null) { 542 for (Pair<String, URL> pair : getDataURLs()) { 543 if (pair.b != null && url.equals(pair.b.toString())) { 544 return true; 545 } 546 } 547 } 548 return false; 549 } 524 550 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/datasets/fr/FrenchConstants.java
r28018 r28050 23 23 * Portal 24 24 */ 25 public static final String FRENCH_PORTAL = "http://www.data.gouv.fr/ donnees/view/";25 public static final String FRENCH_PORTAL = "http://www.data.gouv.fr/"; 26 26 27 27 /** -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/datasets/fr/FrenchDataSetHandler.java
r28031 r28050 98 98 try { 99 99 if (nationalPortalPath != null && !nationalPortalPath.isEmpty()) { 100 return new URL(FRENCH_PORTAL + nationalPortalPath); 100 return new URL(FRENCH_PORTAL + "donnees/view/" + nationalPortalPath); 101 101 } 102 102 } catch (MalformedURLException e) { -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/NetworkReader.java
r28044 r28050 20 20 import java.io.File; 21 21 import java.io.InputStream; 22 import java.util.regex.Matcher; 23 import java.util.regex.Pattern; 22 24 23 25 import org.openstreetmap.josm.data.osm.DataSet; … … 26 28 import org.openstreetmap.josm.io.OsmServerReader; 27 29 import org.openstreetmap.josm.io.OsmTransferException; 30 import org.openstreetmap.josm.plugins.opendata.core.OdConstants; 28 31 import org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler; 29 32 import org.openstreetmap.josm.plugins.opendata.core.io.archive.ZipReader; … … 38 41 import org.openstreetmap.josm.tools.CheckParameterUtil; 39 42 40 public class NetworkReader extends OsmServerReader { 43 public class NetworkReader extends OsmServerReader implements OdConstants { 41 44 42 45 private final String url; … … 45 48 46 49 private File file; 50 private String filename; 47 51 48 52 public NetworkReader(String url, AbstractDataSetHandler handler, Class<? extends AbstractReader> readerClass) { … … 58 62 } 59 63 64 public final String getReadFileName() { 65 return filename; 66 } 67 68 private Class<? extends AbstractReader> findReaderByAttachment() { 69 String cdisp = this.activeConnection.getHeaderField("Content-disposition"); 70 if (cdisp != null) { 71 Matcher m = Pattern.compile("attachment; filename=(.*)").matcher(cdisp); 72 if (m.matches()) { 73 filename = m.group(1); 74 return findReaderByExtension(filename.toLowerCase()); 75 } 76 } 77 return null; 78 } 79 80 private Class<? extends AbstractReader> findReaderByContentType() { 81 String contentType = this.activeConnection.getContentType(); 82 if (contentType.startsWith("application/zip")) { 83 return ZipReader.class; 84 } else if (contentType.startsWith("application/vnd.ms-excel")) { 85 return XlsReader.class; 86 } else if (contentType.startsWith("application/octet-stream")) { 87 //return OdsReader.class;//FIXME, can be anything 88 } else if (contentType.startsWith("text/plain")) {//TODO: extract charset 89 return CsvReader.class; 90 } else if (contentType.startsWith("tdyn/html")) { 91 //return CsvReader.class;//FIXME, can also be .tar.gz 92 } else { 93 System.err.println("Unsupported content type: "+contentType); 94 } 95 return null; 96 } 97 98 private Class<? extends AbstractReader> findReaderByExtension(String filename) { 99 if (filename.endsWith("."+XLS_EXT)) { 100 return XlsReader.class; 101 } else if (filename.endsWith("."+CSV_EXT)) { 102 return CsvReader.class; 103 } else if (filename.endsWith("."+ODS_EXT)) { 104 return OdsReader.class; 105 } else if (filename.endsWith("."+KML_EXT)) { 106 return KmlReader.class; 107 } else if (filename.endsWith("."+KMZ_EXT)) { 108 return KmzReader.class; 109 } else if (filename.endsWith("."+MIF_EXT)) { 110 return MifReader.class; 111 } else if (filename.endsWith("."+SHP_EXT)) { 112 return ShpReader.class; 113 } else if (filename.endsWith("."+TAB_EXT)) { 114 return TabReader.class; 115 } else if (filename.endsWith("."+ZIP_EXT)) { 116 return ZipReader.class; 117 } else { 118 return null; 119 } 120 } 121 60 122 @Override 61 123 public DataSet parseOsm(ProgressMonitor progressMonitor) throws OsmTransferException { … … 69 131 ProgressMonitor instance = progressMonitor.createSubTaskMonitor(1, false); 70 132 if (readerClass == null) { 71 String contentType = this.activeConnection.getContentType(); 72 if (contentType.startsWith("application/zip")) { 73 readerClass = ZipReader.class; 74 } else { 75 throw new IllegalArgumentException("Unsupported content type: "+contentType); 133 readerClass = findReaderByAttachment(); 134 } 135 if (readerClass == null) { 136 readerClass = findReaderByContentType(); 137 } 138 if (readerClass == null) { 139 readerClass = findReaderByExtension(url.toLowerCase()); 140 if (readerClass != null) { 141 filename = url.substring(url.lastIndexOf('/')); 76 142 } 143 } 144 if (readerClass == null) { 145 throw new OsmTransferException("Cannot find appropriate reader !");//TODO handler job ? 77 146 } 78 147 if (readerClass.equals(ZipReader.class)) { -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/ProjectionPatterns.java
r28000 r28050 63 63 64 64 public static final Pattern getCoordinatePattern(String coor, String proj) { 65 return Pattern.compile("(?:.*(?:"+coor+").*(?:"+proj+").*)|(?:.*("+proj+").*(?:"+coor+").*)", Pattern.CASE_INSENSITIVE); 65 if (proj != null && !proj.isEmpty()) { 66 return Pattern.compile("(?:.*(?:"+coor+").*(?:"+proj+").*)|(?:.*("+proj+").*(?:"+coor+").*)", Pattern.CASE_INSENSITIVE); 67 } else { 68 return Pattern.compile(coor, Pattern.CASE_INSENSITIVE); 69 } 66 70 } 67 71 } -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/archive/ZipReader.java
r28044 r28050 96 96 while ((entry = zis.getNextEntry()) != null) { 97 97 File file = new File(temp + File.separator + entry.getName()); 98 File parent = file.getParentFile(); 99 if (parent != null && !parent.exists()) { 100 parent.mkdirs(); 101 } 98 102 if (file.exists() && !file.delete()) { 99 103 throw new IOException("Could not delete temp file/dir: " + file.getAbsolutePath());
Note:
See TracChangeset
for help on using the changeset viewer.