Ignore:
Timestamp:
2012-03-19T00:23:49+01:00 (12 years ago)
Author:
donvip
Message:

opendata: large code reorganization, ask for license agreement before downloading, from embedded HTML/RTF files for ODbL and LO/OL

Location:
applications/editors/josm/plugins/opendata
Files:
25 added
39 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/opendata/modules/be.bruxelles/src/org/openstreetmap/josm/plugins/opendata/modules/be/bruxelles/datasets/BruxellesDataSetHandler.java

    r28000 r28113  
    1818import java.net.MalformedURLException;
    1919import java.net.URL;
    20 import java.util.Locale;
    2120
    22 import org.openstreetmap.josm.Main;
    2321import org.openstreetmap.josm.data.projection.Projection;
    2422import org.openstreetmap.josm.plugins.opendata.core.datasets.be.BelgianDataSetHandler;
     23import org.openstreetmap.josm.plugins.opendata.core.util.OdUtils;
    2524import org.openstreetmap.josm.plugins.opendata.modules.be.bruxelles.BruxellesConstants;
    2625
     
    7069        public URL getLocalPortalURL() {
    7170                String basePortal = null;
    72                 String lang = Main.pref.get("language");
    73                 if (lang == null || lang.isEmpty()) {
    74                         lang = Locale.getDefault().toString();
    75                 }
     71                String lang = OdUtils.getJosmLanguage();
    7672                       
    7773                if (lang.startsWith("fr")) {
  • applications/editors/josm/plugins/opendata/modules/be.bruxelles/src/org/openstreetmap/josm/plugins/opendata/modules/be/bruxelles/datasets/culture/BDHandler.java

    r28000 r28113  
    77public class BDHandler extends BruxellesDataSetHandler {
    88
     9        public BDHandler() {
     10                getCsvHandler().setSeparator(",");
     11        }
     12       
    913        @Override
    1014        public boolean acceptsFilename(String filename) {
     
    1923                }
    2024        }
    21 
    22         /* (non-Javadoc)
    23          * @see org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler#getCsvSeparator()
    24          */
    25         @Override
    26         public String getCsvSeparator() {
    27                 return ",";
    28         }
    2925}
  • applications/editors/josm/plugins/opendata/modules/be.datagovbe/src/org/openstreetmap/josm/plugins/opendata/modules/be/datagovbe/datasets/DataGovDataSetHandler.java

    r28000 r28113  
    1515//    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    1616package org.openstreetmap.josm.plugins.opendata.modules.be.datagovbe.datasets;
    17 
    18 import java.net.URL;
    1917
    2018import org.openstreetmap.josm.data.projection.Projection;
     
    5856                return SOURCE_DATAGOVBE;
    5957        }
    60 
    61         /* (non-Javadoc)
    62          * @see org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler#getLocalPortalURL()
    63          */
    64         @Override
    65         public URL getLocalPortalURL() {
    66                 return null;
    67         }
    6858}
  • applications/editors/josm/plugins/opendata/modules/fr.cg41/src/org/openstreetmap/josm/plugins/opendata/modules/fr/cg41/datasets/Cg41DataSetHandler.java

    r28000 r28113  
    22
    33import java.net.MalformedURLException;
    4 import java.net.URL;
    54
    65import org.openstreetmap.josm.data.osm.Tag;
     
    98
    109public abstract class Cg41DataSetHandler extends FrenchDataSetHandler implements Cg41Constants {
    11        
    12         private int portalId;
    1310       
    1411        public Cg41DataSetHandler(int portalId, String nationalPath) {
     
    3633
    3734        private final void init(int portalId, String nationalPath) {
    38                 this.portalId = portalId;
    3935                setNationalPortalPath(nationalPath);
     36                try {
     37                        if (portalId > 0) {
     38                                setLocalPortalURL(PORTAL_CG41 + portalId);
     39                        }
     40                } catch (MalformedURLException e) {
     41                        e.printStackTrace();
     42                }
     43
    4044        }
    4145
     
    6367                return ICON_CG41_16;
    6468        }
    65 
    66         public final URL getLocalPortalURL() {
    67                 try {
    68                         if (portalId > 0) {
    69                                 return new URL(PORTAL_CG41 + portalId);
    70                         }
    71                 } catch (MalformedURLException e) {
    72                         e.printStackTrace();
    73                 }
    74                 return null;
    75         }
    7669}
  • applications/editors/josm/plugins/opendata/modules/fr.datagouvfr/src/org/openstreetmap/josm/plugins/opendata/modules/fr/datagouvfr/datasets/DataGouvDataSetHandler.java

    r28054 r28113  
    1717
    1818import java.net.MalformedURLException;
    19 import java.net.URL;
    2019
    2120import org.openstreetmap.josm.data.projection.Projection;
    2221import org.openstreetmap.josm.plugins.opendata.core.datasets.fr.FrenchDataSetHandler;
     22import org.openstreetmap.josm.plugins.opendata.core.licenses.License;
    2323import org.openstreetmap.josm.plugins.opendata.modules.fr.datagouvfr.DataGouvFrConstants;
    2424
     
    5050                setNationalPortalPath(portalPath);
    5151                setSingleProjection(singleProjection);
     52                setLicense(License.LOOL);
    5253        }
    5354
     
    5859        public String getSource() {
    5960                return SOURCE_DATAGOUVFR;
    60         }
    61 
    62         /* (non-Javadoc)
    63          * @see org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler#getLocalPortalURL()
    64          */
    65         @Override
    66         public URL getLocalPortalURL() {
    67                 return null;
    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;
    8161        }
    8262       
  • applications/editors/josm/plugins/opendata/modules/fr.datagouvfr/src/org/openstreetmap/josm/plugins/opendata/modules/fr/datagouvfr/datasets/administration/GeoFlaHandler.java

    r28050 r28113  
    3737                super();
    3838                setName("GEOFLA®");
    39         }
    40 
    41         /* (non-Javadoc)
    42          * @see org.openstreetmap.josm.plugins.opendata.portals.fr.datagouvfr.datasets.DataGouvDataSetHandler#getLocalPortalURL()
    43          */
    44         @Override
    45         public URL getLocalPortalURL() {
     39                getShpHandler().setPreferMultipolygonToSimpleWay(true);
    4640                try {
    47                         return new URL("http://professionnels.ign.fr/ficheProduitCMS.do?idDoc=6185461");
     41                        setLocalPortalURL("http://professionnels.ign.fr/ficheProduitCMS.do?idDoc=6185461");
    4842                } catch (MalformedURLException e) {
    49                         System.err.println(e.getMessage());
    50                         return null;
     43                        e.printStackTrace();
    5144                }
    5245        }
     
    7972        protected boolean isArrondissementFile(String filename) {
    8073                return acceptsShpFilename(filename, "ARRONDISSEMENT") || acceptsShpFilename(filename, "LIMITE_ARRONDISSEMENT");
    81         }
    82 
    83         @Override
    84         public boolean preferMultipolygonToSimpleWay() {
    85                 return true;
    8674        }
    8775
  • applications/editors/josm/plugins/opendata/modules/fr.datagouvfr/src/org/openstreetmap/josm/plugins/opendata/modules/fr/datagouvfr/datasets/culture/BibliothequesHandler.java

    r28054 r28113  
    1616package org.openstreetmap.josm.plugins.opendata.modules.fr.datagouvfr.datasets.culture;
    1717
    18 import java.nio.charset.Charset;
    19 
    2018import org.openstreetmap.josm.data.osm.DataSet;
    2119import org.openstreetmap.josm.data.osm.Node;
     
    2826                setName("Bibliothèques municipales");
    2927                setDownloadFileName("lieux de lecture_geoloc.txt");
     28                getCsvHandler().setCharset(ISO8859_15);
    3029        }
    3130
     
    4140                }
    4241        }
    43 
    44         /* (non-Javadoc)
    45          * @see org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler#getCsvCharset()
    46          */
    47         @Override
    48         public Charset getCsvCharset() {
    49                 return Charset.forName(ISO8859_15);
    50         }
    5142}
  • applications/editors/josm/plugins/opendata/modules/fr.datagouvfr/src/org/openstreetmap/josm/plugins/opendata/modules/fr/datagouvfr/datasets/diplomatie/EtabAEFEHandler.java

    r28054 r28113  
    2626                setName("Établissements du réseau d'enseignement de l'AEFE");
    2727                setDownloadFileName("ETALAB_MAEE_Extraction_LDAP_geoloc_AEFE_2011-10-13.csv");
     28                getCsvHandler().setSeparator(",");
    2829        }
    2930
     
    4445                }
    4546        }
    46 
    47         /* (non-Javadoc)
    48          * @see org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler#getCsvSeparator()
    49          */
    50         @Override
    51         public String getCsvSeparator() {
    52                 return ",";
    53         }
    5447}
  • applications/editors/josm/plugins/opendata/modules/fr.datagouvfr/src/org/openstreetmap/josm/plugins/opendata/modules/fr/datagouvfr/datasets/ecologie/AssainissementHandler.java

    r28050 r28113  
    3030                super("assainissement-collectif-30381843");
    3131                setName("Assainissement collectif");
     32                getSpreadSheetHandler().setSheetNumber(1);
    3233        }
    3334
     
    4041        public void updateDataSet(DataSet ds) {
    4142                // TODO Auto-generated method stub
    42         }
    43 
    44         /* (non-Javadoc)
    45          * @see org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler#getSheetNumber()
    46          */
    47         @Override
    48         public int getSheetNumber() {
    49                 return 1;
    5043        }
    5144
  • applications/editors/josm/plugins/opendata/modules/fr.datagouvfr/src/org/openstreetmap/josm/plugins/opendata/modules/fr/datagouvfr/datasets/education/Etab1er2ndDegreHandler.java

    r28054 r28113  
    1616package org.openstreetmap.josm.plugins.opendata.modules.fr.datagouvfr.datasets.education;
    1717
    18 import java.nio.charset.Charset;
    19 
    2018import org.openstreetmap.josm.data.coor.EastNorth;
    2119import org.openstreetmap.josm.data.coor.LatLon;
    2220import org.openstreetmap.josm.data.osm.DataSet;
    2321import org.openstreetmap.josm.data.osm.Node;
     22import org.openstreetmap.josm.plugins.opendata.core.io.tabular.DefaultCsvHandler;
    2423import org.openstreetmap.josm.plugins.opendata.modules.fr.datagouvfr.datasets.DataGouvDataSetHandler;
    2524
    2625public class Etab1er2ndDegreHandler extends DataGouvDataSetHandler {
    2726
     27        private class EtabCsvHandler extends DefaultCsvHandler {
     28               
     29                public EtabCsvHandler() {
     30                        setCharset(ISO8859_15);
     31                        setHandlesProjection(true);
     32                }
     33               
     34                @Override
     35                public LatLon getCoor(EastNorth en, String[] fields) {
     36                        return getLatLonByDptCode(en, fields[0].substring(0, 3), false);
     37                }
     38        }
     39       
    2840        public Etab1er2ndDegreHandler() {
    2941                super("Géolocalisation-des-établissements-d'enseignement-du-premier-degré-et-du-second-degré-du-ministère-d-30378093");
    3042                setName("Établissements d'enseignement du premier degré et du second degré");
    3143                setDownloadFileName("MENJVA_etab_geoloc.csv");
     44                setCsvHandler(new EtabCsvHandler());
    3245        }
    3346       
     
    5366                }
    5467        }
    55 
    56         /* (non-Javadoc)
    57          * @see org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler#handlesCsvProjection()
    58          */
    59         @Override
    60         public boolean handlesSpreadSheetProjection() {
    61                 return true;
    62         }
    63 
    64         /* (non-Javadoc)
    65          * @see org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler#getCsvCoor(org.openstreetmap.josm.data.coor.EastNorth, java.lang.String[])
    66          */
    67         @Override
    68         public LatLon getSpreadSheetCoor(EastNorth en, String[] fields) {
    69                 return getLatLonByDptCode(en, fields[0].substring(0, 3), false);
    70         }
    71 
    72         /* (non-Javadoc)
    73          * @see org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler#getCsvCharset()
    74          */
    75         @Override
    76         public Charset getCsvCharset() {
    77                 return Charset.forName(ISO8859_15);
    78         }
    7968}
  • applications/editors/josm/plugins/opendata/modules/fr.datagouvfr/src/org/openstreetmap/josm/plugins/opendata/modules/fr/datagouvfr/datasets/education/EtabSupHandler.java

    r28054 r28113  
    2424public class EtabSupHandler extends DataGouvDataSetHandler {
    2525
     26        private class EtabSupCsvHandler extends InternalCsvHandler {
     27                @Override
     28                public LatLon getCoor(EastNorth en, String[] fields) {
     29                        // X/Y sont inversees dans le fichier
     30                        return wgs84.eastNorth2latlon(new EastNorth(en.north(), en.east()));
     31                }
     32        }
     33       
    2634        public EtabSupHandler() {
    2735                super("Etablissements-d'enseignement-supérieur-30382046", wgs84);
    2836                setName("Établissements d'enseignement supérieur");
    2937                setDownloadFileName("livraison ETALAB 28 11 2011.xls");
     38                setCsvHandler(new EtabSupCsvHandler());
    3039        }
    3140
     
    4251                }
    4352        }
    44 
    45         /* (non-Javadoc)
    46          * @see org.openstreetmap.josm.plugins.opendata.portals.fr.datagouvfr.datasets.DataGouvDataSetHandler#getSpreadSheetCoor(org.openstreetmap.josm.data.coor.EastNorth, java.lang.String[])
    47          */
    48         @Override
    49         public LatLon getSpreadSheetCoor(EastNorth en, String[] fields) {
    50                 // X/Y sont inversees dans le fichier
    51                 return wgs84.eastNorth2latlon(new EastNorth(en.north(), en.east()));
    52         }
    5353}
  • applications/editors/josm/plugins/opendata/modules/fr.datagouvfr/src/org/openstreetmap/josm/plugins/opendata/modules/fr/datagouvfr/datasets/hydrologie/EauxDeSurfaceHandler.java

    r28055 r28113  
    2929
    3030import org.openstreetmap.josm.data.osm.DataSet;
     31import org.openstreetmap.josm.plugins.opendata.core.io.archive.DefaultZipHandler;
    3132import org.openstreetmap.josm.plugins.opendata.modules.fr.datagouvfr.datasets.DataGouvDataSetHandler;
    3233import org.openstreetmap.josm.tools.Pair;
     
    6566        public EauxDeSurfaceHandler() {
    6667                setName("Eaux de surface");
     68                setZipHandler(new InternalZipHandler());
    6769        }
    6870       
     
    123125                return new Pair<String, URL>(a.name, new URL("http://www.rapportage.eaufrance.fr/sites/default/files/SIG/FR"+a.code+"_SW.zip"));
    124126        }
    125 
    126         /* (non-Javadoc)
    127          * @see org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler#notifyTempFileWritten(java.io.File)
    128          */
    129         @Override
    130         public void notifyTempFileWritten(File file) {
    131                 if (file.getName().matches(SHP_PATTERN.replace("(.*)", "F")+"\\.prj")) { // Adour-Garonne .prj files cannot be parsed because they do not contain quotes...
    132                         try {
    133                                 BufferedReader reader = new BufferedReader(new FileReader(file));
    134                                 String line = reader.readLine();
    135                                 reader.close();
    136                                 if (!line.contains("\"")) {
    137                                         for (String term : new String[]{"GCS_ETRS_1989", "D_ETRS_1989", "GRS_1980", "Greenwich", "Degree"}) {
    138                                                 line = line.replace(term, "\""+term+"\"");
     127       
     128        private class InternalZipHandler extends DefaultZipHandler {
     129                @Override
     130                public void notifyTempFileWritten(File file) {
     131                        if (file.getName().matches(SHP_PATTERN.replace("(.*)", "F")+"\\.prj")) { // Adour-Garonne .prj files cannot be parsed because they do not contain quotes...
     132                                try {
     133                                        BufferedReader reader = new BufferedReader(new FileReader(file));
     134                                        String line = reader.readLine();
     135                                        reader.close();
     136                                        if (!line.contains("\"")) {
     137                                                for (String term : new String[]{"GCS_ETRS_1989", "D_ETRS_1989", "GRS_1980", "Greenwich", "Degree"}) {
     138                                                        line = line.replace(term, "\""+term+"\"");
     139                                                }
     140                                                BufferedWriter writer = new BufferedWriter(new FileWriter(file));
     141                                                writer.write(line);
     142                                                writer.close();
    139143                                        }
    140                                         BufferedWriter writer = new BufferedWriter(new FileWriter(file));
    141                                         writer.write(line);
    142                                         writer.close();
     144                                } catch (Exception e) {
     145                                        e.printStackTrace();
    143146                                }
    144                         } catch (Exception e) {
    145                                 e.printStackTrace();
    146147                        }
    147148                }
  • applications/editors/josm/plugins/opendata/modules/fr.datagouvfr/src/org/openstreetmap/josm/plugins/opendata/modules/fr/datagouvfr/datasets/transport/PassageNiveauHandler.java

    r28054 r28113  
    1616package org.openstreetmap.josm.plugins.opendata.modules.fr.datagouvfr.datasets.transport;
    1717
    18 import java.nio.charset.Charset;
    19 
    2018import org.openstreetmap.josm.data.osm.DataSet;
    2119import org.openstreetmap.josm.data.osm.Node;
     
    2826                setName("Passages à niveau");
    2927                setDownloadFileName("passage_a_niveau.csv");
     28                getCsvHandler().setCharset(ISO8859_15);
    3029        }
    3130
     
    4140                }
    4241        }
    43 
    44         /* (non-Javadoc)
    45          * @see org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler#getCsvCharset()
    46          */
    47         @Override
    48         public Charset getCsvCharset() {
    49                 return Charset.forName(ISO8859_15);
    50         }
    5142}
  • applications/editors/josm/plugins/opendata/modules/fr.lemans/src/org/openstreetmap/josm/plugins/opendata/modules/fr/lemans/datasets/LeMansDataSetHandler.java

    r28091 r28113  
    2323import org.openstreetmap.josm.data.osm.Tag;
    2424import org.openstreetmap.josm.plugins.opendata.core.datasets.fr.FrenchDataSetHandler;
     25import org.openstreetmap.josm.plugins.opendata.core.licenses.License;
    2526import org.openstreetmap.josm.plugins.opendata.modules.fr.lemans.LeMansConstants;
    2627import org.openstreetmap.josm.tools.Pair;
    2728
    2829public abstract class LeMansDataSetHandler extends FrenchDataSetHandler implements LeMansConstants {
    29        
    30         private String uuid;
    3130       
    3231        private String kmzUuid;
     
    5857
    5958        private final void init(String uuid) {
    60                 this.uuid = uuid;
     59                try {
     60                        setLicense(License.ODbL);
     61                        if (uuid != null && !uuid.isEmpty()) {
     62                                setLocalPortalURL(PORTAL + "page.do?t=2&uuid=" + uuid);
     63                        }
     64                } catch (MalformedURLException e) {
     65                        e.printStackTrace();
     66                }
    6167        }
    6268               
     
    7379                return SOURCE_LE_MANS;
    7480        }
    75 
    76         public final URL getLocalPortalURL() {
    77                 try {
    78                         if (uuid != null && !uuid.isEmpty()) {
    79                                 return new URL(PORTAL + "page.do?t=2&uuid=" + uuid);
    80                         }
    81                 } catch (MalformedURLException e) {
    82                         e.printStackTrace();
    83                 }
    84                 return null;
    85         }
    8681       
    8782        /* (non-Javadoc)
    8883         * @see org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler#getLicenseURL()
    8984         */
    90         @Override
     85        /*@Override
    9186        public URL getLicenseURL() {
    9287                try {
     
    9691                }
    9792                return null;
    98         }
    99        
     93        }*/
     94
    10095        /* (non-Javadoc)
    10196         * @see org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler#getDataURLs()
  • applications/editors/josm/plugins/opendata/modules/fr.paris/src/org/openstreetmap/josm/plugins/opendata/modules/fr/paris/datasets/ParisDataSetHandler.java

    r28044 r28113  
    2222import org.openstreetmap.josm.plugins.opendata.core.datasets.fr.FrenchDataSetHandler;
    2323import org.openstreetmap.josm.plugins.opendata.modules.fr.paris.ParisConstants;
     24import org.openstreetmap.josm.plugins.opendata.modules.fr.paris.ParisLicense;
    2425
    2526public abstract class ParisDataSetHandler extends FrenchDataSetHandler implements ParisConstants {
     
    5354        private final void init(int documentId) {
    5455                this.documentId = documentId;
     56                setLicense(new ParisLicense());
     57                try {
     58                        if (documentId > 0) {
     59                                setLocalPortalURL(PORTAL + "jsp/site/Portal.jsp?document_id="+documentId + "&portlet_id="+portletId);
     60                        }
     61                } catch (MalformedURLException e) {
     62                        e.printStackTrace();
     63                }
    5564        }
    5665
     
    6978        public String getLocalPortalIconName() {
    7079                return ICON_PARIS_24;
    71         }
    72 
    73         public final URL getLocalPortalURL() {
    74                 try {
    75                         if (documentId > 0) {
    76                                 return new URL(PORTAL + "jsp/site/Portal.jsp?document_id="+documentId + "&portlet_id="+portletId);
    77                         }
    78                 } catch (MalformedURLException e) {
    79                         e.printStackTrace();
    80                 }
    81                 return null;
    8280        }
    8381       
  • applications/editors/josm/plugins/opendata/modules/fr.paris/src/org/openstreetmap/josm/plugins/opendata/modules/fr/paris/datasets/urbanisme/SanisettesHandler.java

    r28044 r28113  
    3232                super(93);
    3333                setName("Sanisettes");
     34                getShpHandler().setCheckNodeProximity(true);
    3435        }
    3536
     
    116117                return PORTAL+"hn/sanisettes.zip";
    117118        }
    118 
    119         /* (non-Javadoc)
    120          * @see org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler#checkShpNodeProximity()
    121          */
    122         @Override
    123         public boolean checkShpNodeProximity() {
    124                 return true;
    125         }
    126119}
  • applications/editors/josm/plugins/opendata/modules/fr.sncf/src/org/openstreetmap/josm/plugins/opendata/modules/fr/sncf/datasets/EquipementsHandler.java

    r28044 r28113  
     1//    JOSM opendata plugin.
     2//    Copyright (C) 2011-2012 Don-vip
     3//
     4//    This program is free software: you can redistribute it and/or modify
     5//    it under the terms of the GNU General Public License as published by
     6//    the Free Software Foundation, either version 3 of the License, or
     7//    (at your option) any later version.
     8//
     9//    This program is distributed in the hope that it will be useful,
     10//    but WITHOUT ANY WARRANTY; without even the implied warranty of
     11//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12//    GNU General Public License for more details.
     13//
     14//    You should have received a copy of the GNU General Public License
     15//    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    116package org.openstreetmap.josm.plugins.opendata.modules.fr.sncf.datasets;
    217
     
    823public class EquipementsHandler extends SncfDataSetHandler {
    924
     25        private class LambertIICsvHandler extends InternalCsvHandler {
     26                @Override
     27                public LatLon getCoor(EastNorth en, String[] fields) {
     28                        // Lambert II coordinates offset by 2000000 (see http://fr.wikipedia.org/wiki/Projection_conique_conforme_de_Lambert#Projections_officielles_en_France_métropolitaine)
     29                        return super.getCoor(new EastNorth(en.getX(), en.getY()-2000000), fields);
     30                }
     31        }
     32       
    1033        public EquipementsHandler() {
    1134                super("equipementsgares");
     35                setCsvHandler(new LambertIICsvHandler());
    1236                setSingleProjection(lambert4Zones[1]); // Lambert II
    1337        }
     
    2549                }
    2650        }
    27 
    28         /* (non-Javadoc)
    29          * @see org.openstreetmap.josm.plugins.opendata.core.datasets.fr.FrenchDataSetHandler#getSpreadSheetCoor(org.openstreetmap.josm.data.coor.EastNorth, java.lang.String[])
    30          */
    31         @Override
    32         public LatLon getSpreadSheetCoor(EastNorth en, String[] fields) {
    33                 // Lambert II coordinates offset by 2000000 (see http://fr.wikipedia.org/wiki/Projection_conique_conforme_de_Lambert#Projections_officielles_en_France_métropolitaine)
    34                 return super.getSpreadSheetCoor(new EastNorth(en.getX(), en.getY()-2000000), fields);
    35         }
    3651}
  • applications/editors/josm/plugins/opendata/modules/fr.sncf/src/org/openstreetmap/josm/plugins/opendata/modules/fr/sncf/datasets/SncfDataSetHandler.java

    r28044 r28113  
     1//    JOSM opendata plugin.
     2//    Copyright (C) 2011-2012 Don-vip
     3//
     4//    This program is free software: you can redistribute it and/or modify
     5//    it under the terms of the GNU General Public License as published by
     6//    the Free Software Foundation, either version 3 of the License, or
     7//    (at your option) any later version.
     8//
     9//    This program is distributed in the hope that it will be useful,
     10//    but WITHOUT ANY WARRANTY; without even the implied warranty of
     11//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12//    GNU General Public License for more details.
     13//
     14//    You should have received a copy of the GNU General Public License
     15//    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    116package org.openstreetmap.josm.plugins.opendata.modules.fr.sncf.datasets;
    217
    318import java.net.MalformedURLException;
    4 import java.net.URL;
    519
    620import org.openstreetmap.josm.data.osm.Tag;
    721import org.openstreetmap.josm.plugins.opendata.core.datasets.fr.FrenchDataSetHandler;
    822import org.openstreetmap.josm.plugins.opendata.modules.fr.sncf.SncfConstants;
     23import org.openstreetmap.josm.plugins.opendata.modules.fr.sncf.SncfLicense;
    924
    1025public abstract class SncfDataSetHandler extends FrenchDataSetHandler implements SncfConstants {
    11        
    12         private String portalId;
    1326       
    1427        public SncfDataSetHandler(String portalId) {
     
    4558       
    4659        private final void init(String portalId) {
    47                 this.portalId = portalId;
     60                setLicense(new SncfLicense());
     61                if (portalId != null && !portalId.isEmpty()) {
     62                        try {
     63                                setLocalPortalURL(PORTAL + portalId);
     64                        } catch (MalformedURLException e) {
     65                                e.printStackTrace();
     66                        }
     67                }
    4868        }
    4969
     
    7191                return ICON_16;
    7292        }
    73 
    74         public final URL getLocalPortalURL() {
    75                 try {
    76                         if (portalId != null) {
    77                                 return new URL(PORTAL + portalId);
    78                         }
    79                 } catch (MalformedURLException e) {
    80                         e.printStackTrace();
    81                 }
    82                 return null;
    83         }
    84 
    85         /* (non-Javadoc)
    86          * @see org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler#getLicenseURL()
    87          */
    88         @Override
    89         public URL getLicenseURL() {
    90                 try {
    91                         return new URL("http://test.data-sncf.com/licence");
    92                 } catch (MalformedURLException e) {
    93                         e.printStackTrace();
    94                 }
    95                 return null;
    96         }
    9793}
  • applications/editors/josm/plugins/opendata/modules/fr.toulouse/src/org/openstreetmap/josm/plugins/opendata/modules/fr/toulouse/ToulouseConstants.java

    r28044 r28113  
    3535         * Portal
    3636         */
    37         public static final String PORTAL = "http://data.grandtoulouse.fr/les-donnees/-/opendata/card/";
     37        public static final String PORTAL = "http://data.grandtoulouse.fr";
    3838
    3939        /**
  • applications/editors/josm/plugins/opendata/modules/fr.toulouse/src/org/openstreetmap/josm/plugins/opendata/modules/fr/toulouse/datasets/ToulouseDataSetHandler.java

    r28044 r28113  
     1//    JOSM opendata plugin.
     2//    Copyright (C) 2011-2012 Don-vip
     3//
     4//    This program is free software: you can redistribute it and/or modify
     5//    it under the terms of the GNU General Public License as published by
     6//    the Free Software Foundation, either version 3 of the License, or
     7//    (at your option) any later version.
     8//
     9//    This program is distributed in the hope that it will be useful,
     10//    but WITHOUT ANY WARRANTY; without even the implied warranty of
     11//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12//    GNU General Public License for more details.
     13//
     14//    You should have received a copy of the GNU General Public License
     15//    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    116package org.openstreetmap.josm.plugins.opendata.modules.fr.toulouse.datasets;
    217
    318import java.net.MalformedURLException;
    4 import java.net.URL;
    519
    620import org.openstreetmap.josm.data.osm.Tag;
    721import org.openstreetmap.josm.plugins.opendata.core.datasets.fr.FrenchDataSetHandler;
    822import org.openstreetmap.josm.plugins.opendata.modules.fr.toulouse.ToulouseConstants;
     23import org.openstreetmap.josm.plugins.opendata.modules.fr.toulouse.ToulouseLicense;
    924
    1025public abstract class ToulouseDataSetHandler extends FrenchDataSetHandler implements ToulouseConstants {
    11        
    12         private int portalId;
    13         private String wikiPage;
    1426       
    1527        public ToulouseDataSetHandler(int portalId) {
     
    4658       
    4759        private final void init(int portalId) {
    48                 this.portalId = portalId;
     60                try {
     61                        setLicense(new ToulouseLicense());
     62                        if (portalId > 0) {
     63                                String url = PORTAL + "/les-donnees/-/opendata/card/" + portalId + "--";
     64                                setLocalPortalURL(url);
     65                                //setLicenseURL(url+"/license");
     66                                setDataURL(url+"/resource/document");
     67                        }
     68                } catch (MalformedURLException e) {
     69                        e.printStackTrace();
     70                }
    4971        }
    5072
     
    7294                return ICON_CROIX_16;
    7395        }
    74 
    75         public final URL getLocalPortalURL() {
    76                 try {
    77                         if (portalId > 0) {
    78                                 return new URL(PORTAL + portalId + "--");
    79                         }
    80                 } catch (MalformedURLException e) {
    81                         e.printStackTrace();
    82                 }
    83                 return null;
    84         }
    85        
    86         /* (non-Javadoc)
    87          * @see org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler#getLicenseURL()
    88          */
    89         @Override
    90         public URL getLicenseURL() {
    91                 try {
    92                         return new URL(getLocalPortalURL().toString()+"/license");
    93                 } catch (MalformedURLException e) {
    94                         e.printStackTrace();
    95                 }
    96                 return null;
    97         }
    98 
    99         /* (non-Javadoc)
    100          * @see org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler#getDataURL()
    101          */
    102         @Override
    103         public URL getDataURL() {
    104                 try {
    105                         return new URL(getLocalPortalURL().toString()+"/resource/document");
    106                 } catch (MalformedURLException e) {
    107                         e.printStackTrace();
    108                 }
    109                 return null;
    110         }
    111 
    112         /* (non-Javadoc)
    113          * @see org.openstreetmap.josm.plugins.fr.opendata.datasets.AbstractDataSetHandler#getWikiURL()
    114          */
    115         @Override
    116         public URL getWikiURL() {
    117                 try {
    118                         if (wikiPage != null && !wikiPage.isEmpty()) {
    119                                 return new URL(WIKI + "/" + wikiPage);
    120                         }
    121                 } catch (MalformedURLException e) {
    122                         e.printStackTrace();
    123                 }
    124                 return null;
    125         }
    12696       
    12797        protected final void setWikiPage(String wikiPage) {
    128                 this.wikiPage = wikiPage.replace(" ", "_");
    129                 setName(wikiPage.replace("_", " "));
     98                if (wikiPage != null && !wikiPage.isEmpty()) {
     99                        setName(wikiPage.replace("_", " "));
     100                        try {
     101                                setWikiURL(WIKI + "/" + wikiPage.replace(" ", "_"));
     102                        } catch (MalformedURLException e) {
     103                                e.printStackTrace();
     104                        }
     105                }
    130106        }
    131107}
  • applications/editors/josm/plugins/opendata/modules/fr.toulouse/src/org/openstreetmap/josm/plugins/opendata/modules/fr/toulouse/datasets/transport/ChantiersPonctuelsHandler.java

    r28096 r28113  
    1616package org.openstreetmap.josm.plugins.opendata.modules.fr.toulouse.datasets.transport;
    1717
    18 import java.nio.charset.Charset;
    1918
    2019public class ChantiersPonctuelsHandler extends ChantiersHandler {
     
    2221        public ChantiersPonctuelsHandler() {
    2322                super(14071, "Chantiers en cours (ponctuel)");
     23                getCsvHandler().setCharset(ISO8859_15);
    2424        }
    2525
     
    2828                return acceptsCsvKmzTabFilename(filename, "Chantiers_Ponctuels");
    2929        }
    30        
    31         /* (non-Javadoc)
    32          * @see org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler#getCsvCharset()
    33          */
    34         @Override
    35         public Charset getCsvCharset() {
    36                 return Charset.forName(ISO8859_15);
    37         }
    3830}
  • applications/editors/josm/plugins/opendata/modules/fr.toulouse/src/org/openstreetmap/josm/plugins/opendata/modules/fr/toulouse/datasets/transport/PistesCyclablesHandler.java

    r28044 r28113  
    1616package org.openstreetmap.josm.plugins.opendata.modules.fr.toulouse.datasets.transport;
    1717
    18 import static org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler.OaQueryType.NODE;
    19 import static org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler.OaQueryType.WAY;
    20 import static org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler.OaRecurseType.NODE_RELATION;
    21 import static org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler.OaRecurseType.RELATION_WAY;
    22 import static org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler.OaRecurseType.WAY_NODE;
    23 import static org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler.OaRecurseType.WAY_RELATION;
    24 
    2518import java.util.Arrays;
    2619import java.util.Collection;
     
    3124import org.openstreetmap.josm.data.osm.IPrimitive;
    3225import org.openstreetmap.josm.data.osm.Way;
     26import org.openstreetmap.josm.plugins.opendata.core.io.OverpassApi;
    3327import org.openstreetmap.josm.plugins.opendata.modules.fr.toulouse.datasets.ToulouseDataSetHandler;
     28
     29import static org.openstreetmap.josm.plugins.opendata.core.io.OverpassApi.OaQueryType.*;
     30import static org.openstreetmap.josm.plugins.opendata.core.io.OverpassApi.OaRecurseType.*;
    3431
    3532public class PistesCyclablesHandler extends ToulouseDataSetHandler {
     
    6562        @Override
    6663        protected String getOverpassApiQueries(String bbox, String... conditions) {
    67                 return oaQuery(bbox, NODE, conditions) + "\n" +
    68                                 oaRecurse(NODE_RELATION, RELATION_WAY, WAY_NODE) + "\n" +
    69                                 oaQuery(bbox, WAY, conditions) + "\n" +
    70                                 oaRecurse(WAY_NODE, "nodes") + "\n" +
    71                                 oaRecurse(WAY_RELATION);
     64                return OverpassApi.query(bbox, NODE, conditions) + "\n" +
     65                                OverpassApi.recurse(NODE_RELATION, RELATION_WAY, WAY_NODE) + "\n" +
     66                                OverpassApi.query(bbox, WAY, conditions) + "\n" +
     67                                OverpassApi.recurse(WAY_NODE, "nodes") + "\n" +
     68                                OverpassApi.recurse(WAY_RELATION);
    7269        }
    7370
  • applications/editors/josm/plugins/opendata/modules/fr.toulouse/src/org/openstreetmap/josm/plugins/opendata/modules/fr/toulouse/datasets/transport/ReseauTisseoHandler.java

    r28054 r28113  
    3434                setName("Réseau Tisséo (Métro, Bus, Tram)");
    3535                setCategory(CAT_TRANSPORT);
    36                 setSkipXsdValidationInZipReading(true);
     36                getZipHandler().setSkipXsdValidation(true);
    3737        }
    3838
  • applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/OdConstants.java

    r28091 r28113  
    8787        public static final String ICON_EMPTY_24 = "empty24.png";
    8888
     89        public static final String ICON_LOOL_48 = "lool48.png";
     90
    8991    /**
    9092     * File extensions.
     
    156158     * Resources
    157159     */
    158     public static final String DICTIONARY_FR = "/org/openstreetmap/josm/plugins/opendata/core/resources/dictionary.fr.csv";
     160    public static final String RESOURCE_PATH = "/org/openstreetmap/josm/plugins/opendata/core/resources/";
     161    public static final String DICTIONARY_FR = RESOURCE_PATH+"dictionary.fr.csv";
    159162}
  • applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/actions/DownloadDataTask.java

    r28054 r28113  
    1616package org.openstreetmap.josm.plugins.opendata.core.actions;
    1717
     18import static org.openstreetmap.josm.tools.I18n.tr;
     19
    1820import java.io.File;
     21import java.io.IOException;
    1922import java.util.concurrent.Future;
    2023import java.util.regex.Pattern;
     24
     25import javax.swing.JOptionPane;
    2126
    2227import org.openstreetmap.josm.Main;
     
    2530import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    2631import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    27 import org.openstreetmap.josm.io.AbstractReader;
    2832import org.openstreetmap.josm.plugins.opendata.core.OdConstants;
    2933import org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler;
    3034import org.openstreetmap.josm.plugins.opendata.core.datasets.DataSetUpdater;
     35import org.openstreetmap.josm.plugins.opendata.core.gui.AskLicenseAgreementDialog;
    3136import org.openstreetmap.josm.plugins.opendata.core.io.NetworkReader;
    3237import org.openstreetmap.josm.plugins.opendata.core.layers.OdDataLayer;
     38import org.openstreetmap.josm.plugins.opendata.core.licenses.License;
    3339import org.openstreetmap.josm.plugins.opendata.core.modules.Module;
    3440import org.openstreetmap.josm.plugins.opendata.core.modules.ModuleHandler;
     
    3743
    3844        private AbstractDataSetHandler handler;
     45       
     46        //private static final PdfEditorKit pdfEditorKit = new PdfEditorKit();
    3947       
    4048        @Override
     
    4553        @Override
    4654        public Future<?> loadUrl(boolean newLayer, String url, ProgressMonitor progressMonitor) {
    47                 Class<? extends AbstractReader> readerClass = null; // TODO
    48         downloadTask = new InternDownloadTasK(newLayer, new NetworkReader(url, handler, readerClass), progressMonitor);
     55        downloadTask = new InternalDownloadTasK(newLayer, new NetworkReader(url, handler), progressMonitor);
    4956        currentBounds = null;
    50         // Extract .osm filename from URL to set the new layer name
    51         //Matcher matcher = Pattern.compile("http://.*/(.*\\.osm)").matcher(url);
    52         //newLayerName = matcher.matches() ? matcher.group(1) : null;
    53         return Main.worker.submit(downloadTask);
     57        if (handler == null || !handler.hasLicenseToBeAccepted() || askLicenseAgreement(handler.getLicense())) {
     58                return Main.worker.submit(downloadTask);
     59        } else {
     60                return null;
     61        }
    5462        }
    5563
     
    7381        }
    7482       
    75         protected class InternDownloadTasK extends DownloadTask {
     83        protected class InternalDownloadTasK extends DownloadTask {
    7684
    77                 public InternDownloadTasK(boolean newLayer, NetworkReader reader, ProgressMonitor progressMonitor) {
     85                public InternalDownloadTasK(boolean newLayer, NetworkReader reader, ProgressMonitor progressMonitor) {
    7886                        super(newLayer, reader, progressMonitor);
    7987                }
     
    99107                }
    100108        }
     109       
     110    /**
     111     * returns true if the user accepts the license, false if they refuse
     112     */
     113    protected final boolean askLicenseAgreement(License license) {
     114        if (license == null || (license.getURL() == null && license.getSummaryURL() == null)) {
     115                return true;
     116        }
     117        try {
     118                return new AskLicenseAgreementDialog(license).showDialog().getValue() == 1;
     119               
     120                } catch (IOException e) {
     121            JOptionPane.showMessageDialog(Main.parent, tr("License URL not available: {0}", license.toString()));
     122            return false;
     123                }
     124    }
    101125}
  • applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/datasets/AbstractDataSetHandler.java

    r28091 r28113  
    1919import java.net.MalformedURLException;
    2020import java.net.URL;
    21 import java.nio.charset.Charset;
    2221import java.util.ArrayList;
    2322import java.util.Collection;
     
    2524import java.util.regex.Pattern;
    2625
    27 import org.geotools.referencing.CRS;
    28 import org.geotools.referencing.crs.AbstractDerivedCRS;
    29 import org.geotools.referencing.datum.DefaultEllipsoid;
    30 import org.geotools.referencing.operation.projection.LambertConformal;
    31 import org.geotools.referencing.operation.projection.LambertConformal1SP;
    32 import org.geotools.referencing.operation.projection.LambertConformal2SP;
    33 import org.geotools.referencing.operation.projection.MapProjection.AbstractProvider;
    34 import org.opengis.parameter.ParameterDescriptor;
    35 import org.opengis.parameter.ParameterValueGroup;
    36 import org.opengis.referencing.FactoryException;
    37 import org.opengis.referencing.crs.CoordinateReferenceSystem;
    38 import org.opengis.referencing.crs.GeographicCRS;
    39 import org.opengis.referencing.datum.GeodeticDatum;
    40 import org.opengis.referencing.operation.MathTransform;
    41 import org.openstreetmap.josm.Main;
    4226import org.openstreetmap.josm.data.Bounds;
    43 import org.openstreetmap.josm.data.coor.EastNorth;
    4427import org.openstreetmap.josm.data.coor.LatLon;
    4528import org.openstreetmap.josm.data.osm.DataSet;
    4629import org.openstreetmap.josm.data.osm.IPrimitive;
    4730import org.openstreetmap.josm.data.osm.OsmPrimitive;
    48 import org.openstreetmap.josm.data.projection.AbstractProjection;
    49 import org.openstreetmap.josm.data.projection.Ellipsoid;
    50 import org.openstreetmap.josm.data.projection.Projection;
    51 import org.openstreetmap.josm.data.projection.Projections;
    52 import org.openstreetmap.josm.data.projection.proj.LambertConformalConic;
    53 import org.openstreetmap.josm.data.projection.proj.LambertConformalConic.Parameters;
    54 import org.openstreetmap.josm.data.projection.proj.LambertConformalConic.Parameters1SP;
    55 import org.openstreetmap.josm.data.projection.proj.LambertConformalConic.Parameters2SP;
    5631import org.openstreetmap.josm.gui.preferences.SourceEditor.ExtendedSourceEntry;
    5732import org.openstreetmap.josm.io.AbstractReader;
    5833import org.openstreetmap.josm.plugins.opendata.core.OdConstants;
     34import org.openstreetmap.josm.plugins.opendata.core.io.archive.DefaultZipHandler;
     35import org.openstreetmap.josm.plugins.opendata.core.io.archive.ZipHandler;
     36import org.openstreetmap.josm.plugins.opendata.core.io.geographic.DefaultShpHandler;
     37import org.openstreetmap.josm.plugins.opendata.core.io.geographic.ShpHandler;
     38import org.openstreetmap.josm.plugins.opendata.core.io.tabular.CsvHandler;
     39import org.openstreetmap.josm.plugins.opendata.core.io.tabular.DefaultCsvHandler;
     40import org.openstreetmap.josm.plugins.opendata.core.io.tabular.SpreadSheetHandler;
     41import org.openstreetmap.josm.plugins.opendata.core.licenses.License;
    5942import org.openstreetmap.josm.plugins.opendata.core.util.NamesFrUtils;
    6043import org.openstreetmap.josm.tools.Pair;
     
    9982        private String sourceDate;
    10083        private File associatedFile;
    101         private URL dataURL;
    10284
    10385        public AbstractDataSetHandler() {
     86                setShpHandler(new DefaultShpHandler());
     87                setZipHandler(new DefaultZipHandler());
     88                setCsvHandler(new DefaultCsvHandler());
    10489        }
    10590       
     
    178163        }
    179164       
    180         public URL getWikiURL() {return null;}
    181        
    182         public URL getLocalPortalURL() {return null;}
    183        
    184         public URL getNationalPortalURL() {return null;}
    185 
    186         public URL getLicenseURL() {return null;}
    187 
    188         public URL getDataURL() {return dataURL;}
    189        
    190         public final void setDataURL(String url) throws MalformedURLException {
    191                 this.dataURL = new URL(url);
    192         }
    193        
    194         public final void setDataURL(URL url) {
    195                 this.dataURL = url;
     165        // -------------------- License --------------------
     166       
     167        private License license;
     168       
     169        public License getLicense() {
     170                return license;
     171        }
     172
     173        public final void setLicense(License license) {
     174                this.license = license;
     175        }
     176
     177        // --------------------- URLs ---------------------
     178       
     179        private URL dataURL;
     180        private URL wikiURL;
     181        private URL localPortalURL;
     182        private URL nationalPortalURL;
     183       
     184        public URL getDataURL() {
     185                return dataURL;
     186        }
     187
     188        public final void setDataURL(URL dataURL) {
     189                this.dataURL = dataURL;
     190        }
     191
     192        public final void setDataURL(String dataURL) throws MalformedURLException {
     193                setDataURL(new URL(dataURL));
     194        }
     195
     196        public URL getWikiURL() {
     197                return wikiURL;
     198        }
     199
     200        public final void setWikiURL(URL wikiURL) {
     201                this.wikiURL = wikiURL;
     202        }
     203
     204        public final void setWikiURL(String wikiURL) throws MalformedURLException {
     205                setWikiURL(new URL(wikiURL));
     206        }
     207
     208        public URL getLocalPortalURL() {
     209                return localPortalURL;
     210        }
     211
     212        public final void setLocalPortalURL(URL localPortalURL) {
     213                this.localPortalURL = localPortalURL;
     214        }
     215
     216        public final void setLocalPortalURL(String localPortalURL) throws MalformedURLException {
     217                setLocalPortalURL(new URL(localPortalURL));
     218        }
     219
     220        public URL getNationalPortalURL() {
     221                return nationalPortalURL;
     222        }
     223
     224        public final void setNationalPortalURL(URL nationalPortalURL) {
     225                this.nationalPortalURL = nationalPortalURL;
     226        }
     227
     228        public final void setNationalPortalURL(String nationalPortalURL) throws MalformedURLException {
     229                setNationalPortalURL(new URL(nationalPortalURL));
    196230        }
    197231
     
    199233
    200234        public AbstractReader getReaderForUrl(String url) {return null;}
     235       
     236        private boolean hasLicenseToBeAccepted = true;
     237
     238        public final boolean hasLicenseToBeAccepted() {
     239                return hasLicenseToBeAccepted;
     240        }
     241
     242        public final void setHasLicenseToBeAccepted(boolean hasLicenseToBeAccepted) {
     243                this.hasLicenseToBeAccepted = hasLicenseToBeAccepted;
     244        }
    201245
    202246        public final DataSetCategory getCategory() {
     
    226270        }
    227271
    228         public enum OaQueryType {
    229                 NODE ("node"),
    230                 WAY ("way"),
    231                 RELATION ("relation");
    232                 @Override
    233                 public String toString() { return this.value; }
    234                 private OaQueryType(final String value) { this.value = value; }
    235                 private final String value;
    236         }
    237 
    238         public enum OaRecurseType {
    239                 RELATION_RELATION ("relation-relation"),
    240                 RELATION_BACKWARDS ("relation-backwards"),
    241                 RELATION_WAY ("relation-way"),
    242                 RELATION_NODE ("relation-node"),
    243                 WAY_NODE ("way-node"),
    244                 WAY_RELATION ("way-relation"),
    245                 NODE_RELATION ("node-relation"),
    246                 NODE_WAY ("node-way");
    247                 @Override
    248                 public String toString() { return this.value; }
    249                 private OaRecurseType(final String value) { this.value = value; }
    250                 private final String value;
    251         }
    252272
    253273        protected String getOverpassApiRequest(String bbox) {return null;}
    254        
    255         protected final String oaUnion(String ... queries) {
    256                 String result = "<union>\n";
    257                 for (String query : queries) {
    258                         if (query != null) {
    259                                 result += query + "\n";
    260                         }
    261                 }
    262                 result += "</union>";
    263                 return result;
    264         }
    265        
    266         protected final String oaQuery(String bbox, OaQueryType type, String ... conditions) {
    267                 String result = "<query type=\""+type+"\" >\n";
    268                 if (bbox != null) {
    269                         result += "<bbox-query "+bbox+"/>\n";
    270                 }
    271                 for (String condition : conditions) {
    272                         if (condition != null) {
    273                                 result += condition + "\n";
    274                         }
    275                 }
    276                 result += "</query>";
    277                 return result;
    278         }
    279 
    280         protected final String oaRecurse(OaRecurseType type, String into) {
    281                 return "<recurse type=\""+type+"\" into=\""+into+"\"/>\n";
    282         }
    283 
    284         protected final String oaRecurse(OaRecurseType ... types) {
    285                 String result = "";
    286                 for (OaRecurseType type : types) {
    287                         result += "<recurse type=\""+type+"\"/>\n";
    288                 }
    289                 return result;
    290         }
    291        
    292         protected final String oaPrint() {
    293                 return "<print mode=\"meta\"/>";
    294         }
    295        
    296         protected final String oaHasKey(String key) {
    297                 return oaHasKey(key, null);
    298         }
    299 
    300         protected final String oaHasKey(String key, String value) {
    301                 return "<has-kv k=\""+key+"\" "+(value != null && !value.isEmpty() ? "v=\""+value+"\"" : "")+" />";
    302         }
    303274
    304275        public boolean equals(IPrimitive p1, IPrimitive p2) {return false;}
     
    405376        }
    406377       
    407         public boolean handlesSpreadSheetProjection() {
    408                 return false;
    409         }
    410        
    411         public List<Projection> getSpreadSheetProjections() {
    412                 return null;
    413         }
    414 
    415         public LatLon getSpreadSheetCoor(EastNorth en, String[] fields) {
    416                 return null;
    417         }
    418        
    419         public Charset getCsvCharset() {
    420                 return null;
    421         }
    422        
    423         public String getCsvSeparator() {
    424                 return null;
    425         }
    426        
    427         public int getSheetNumber() {
    428                 return -1;
    429         }
    430        
    431378        public ExtendedSourceEntry getMapPaintStyle() {
    432379                return null;
     
    446393                                fileNameWithoutExtension+"."+MAPCSS_EXT);
    447394        }
    448        
    449         public boolean preferMultipolygonToSimpleWay() {
    450                 return false;
    451         }
    452        
     395               
    453396        public final void setAssociatedFile(File associatedFile) {
    454397                this.associatedFile = associatedFile;
     
    457400        public final File getAssociatedFile() {
    458401                return this.associatedFile;
    459         }
    460        
    461         private static final List<Pair<org.opengis.referencing.datum.Ellipsoid, Ellipsoid>>
    462                 ellipsoids = new ArrayList<Pair<org.opengis.referencing.datum.Ellipsoid, Ellipsoid>>();
    463         static {
    464                 ellipsoids.add(new Pair<org.opengis.referencing.datum.Ellipsoid, Ellipsoid>(DefaultEllipsoid.GRS80, Ellipsoid.GRS80));
    465                 ellipsoids.add(new Pair<org.opengis.referencing.datum.Ellipsoid, Ellipsoid>(DefaultEllipsoid.WGS84, Ellipsoid.WGS84));
    466         }
    467        
    468         private static final Double get(ParameterValueGroup values, ParameterDescriptor desc) {
    469                 return (Double) values.parameter(desc.getName().getCode()).getValue();
    470         }
    471        
    472         private static final boolean equals(Double a, Double b) {
    473                 boolean res = Math.abs(a - b) <= Main.pref.getDouble(PREF_CRS_COMPARISON_TOLERANCE, DEFAULT_CRS_COMPARISON_TOLERANCE);
    474                 if (Main.pref.getBoolean(PREF_CRS_COMPARISON_DEBUG, false)) {
    475                         System.out.println("Comparing "+a+" and "+b+" -> "+res);
    476                 }
    477                 return res;
    478         }
    479        
    480         public MathTransform findMathTransform(CoordinateReferenceSystem sourceCRS, CoordinateReferenceSystem targetCRS, boolean lenient) throws FactoryException {
    481                 if (sourceCRS instanceof GeographicCRS && sourceCRS.getName().getCode().equalsIgnoreCase("GCS_ETRS_1989")) {
    482                         return CRS.findMathTransform(CRS.decode("EPSG:4258"), targetCRS, lenient);
    483                 } else if (sourceCRS instanceof AbstractDerivedCRS && sourceCRS.getName().getCode().equalsIgnoreCase("Lambert_Conformal_Conic")) {
    484                         List<MathTransform> result = new ArrayList<MathTransform>();
    485                         AbstractDerivedCRS crs = (AbstractDerivedCRS) sourceCRS;
    486                         MathTransform transform = crs.getConversionFromBase().getMathTransform();
    487                         if (transform instanceof LambertConformal && crs.getDatum() instanceof GeodeticDatum) {
    488                                 LambertConformal lambert = (LambertConformal) transform;
    489                                 GeodeticDatum geo = (GeodeticDatum) crs.getDatum();
    490                                 for (Projection p : Projections.getProjections()) {
    491                                         if (p instanceof AbstractProjection) {
    492                                                 AbstractProjection ap = (AbstractProjection) p;
    493                                                 if (ap.getProj() instanceof LambertConformalConic) {
    494                                                         for (Pair<org.opengis.referencing.datum.Ellipsoid, Ellipsoid> pair : ellipsoids) {
    495                                                                 if (pair.a.equals(geo.getEllipsoid()) && pair.b.equals(ap.getEllipsoid())) {
    496                                                                         boolean ok = true;
    497                                                                         ParameterValueGroup values = lambert.getParameterValues();
    498                                                                         Parameters params = ((LambertConformalConic) ap.getProj()).getParameters();
    499                                                                        
    500                                                                         ok = ok ? equals(get(values, AbstractProvider.LATITUDE_OF_ORIGIN), params.latitudeOrigin) : ok;
    501                                                                         ok = ok ? equals(get(values, AbstractProvider.CENTRAL_MERIDIAN), ap.getCentralMeridian()) : ok;
    502                                                                         ok = ok ? equals(get(values, AbstractProvider.SCALE_FACTOR), ap.getScaleFactor()) : ok;
    503                                                                         ok = ok ? equals(get(values, AbstractProvider.FALSE_EASTING), ap.getFalseEasting()) : ok;
    504                                                                         ok = ok ? equals(get(values, AbstractProvider.FALSE_NORTHING), ap.getFalseNorthing()) : ok;
    505                                                                        
    506                                                                         if (lambert instanceof LambertConformal2SP && params instanceof Parameters2SP) {
    507                                                                                 Parameters2SP param = (Parameters2SP) params;
    508                                                                                 ok = ok ? equals(Math.min(get(values, AbstractProvider.STANDARD_PARALLEL_1),get(values, AbstractProvider.STANDARD_PARALLEL_2)),
    509                                                                                                                  Math.min(param.standardParallel1, param.standardParallel2)) : ok;
    510                                                                                 ok = ok ? equals(Math.max(get(values, AbstractProvider.STANDARD_PARALLEL_1), get(values, AbstractProvider.STANDARD_PARALLEL_2)),
    511                                                                                                          Math.max(param.standardParallel1, param.standardParallel2)) : ok;
    512                                                                                
    513                                                                         } else if (!(lambert instanceof LambertConformal1SP && params instanceof Parameters1SP)) {
    514                                                                                 ok = false;
    515                                                                         }
    516 
    517                                                                         if (ok) {
    518                                                                                 try {
    519                                                                                         result.add(CRS.findMathTransform(CRS.decode(p.toCode()), targetCRS, lenient));
    520                                                                                 } catch (FactoryException e) {
    521                                                                                         System.err.println(e.getMessage());
    522                                                                                 }
    523                                                                         }
    524                                                                 }
    525                                                         }
    526                                                 }
    527                                         }
    528                                 }
    529                         }
    530                         if (!result.isEmpty()) {
    531                                 if (result.size() > 1) {
    532                                         System.err.println("Found multiple projections !"); // TODO: something
    533                                 }
    534                                 return result.get(0);
    535                         }
    536                 }
    537                 return null;
    538         }
    539 
    540         public boolean checkShpNodeProximity() {
    541                 return false;
    542402        }
    543403       
     
    555415                return false;
    556416        }
    557 
    558         private boolean setSkipXsdValidationInZipReading = false;
    559        
    560         public final void setSkipXsdValidationInZipReading(boolean skip) {
    561                 setSkipXsdValidationInZipReading = skip;
    562         }
    563        
    564         public boolean skipXsdValidationInZipReading() {
    565                 return setSkipXsdValidationInZipReading;
    566         }
    567 
    568         public void notifyTempFileWritten(File file) {
    569                 // Do nothing, let handler overload this method if they need it
     417       
     418        // --------- Shapefile handling ---------
     419       
     420        private ShpHandler shpHandler;
     421
     422        public final void setShpHandler(ShpHandler handler) {
     423                shpHandler = handler;
     424        }
     425       
     426        public final ShpHandler getShpHandler() {
     427                return shpHandler;
     428        }
     429
     430        // ------------ Zip handling ------------
     431       
     432        private ZipHandler zipHandler;
     433
     434        public final void setZipHandler(ZipHandler handler) {
     435                zipHandler = handler;
     436        }
     437       
     438        public ZipHandler getZipHandler() {
     439                return zipHandler;
     440        }
     441       
     442        // ------ Spreadsheet handling ----------
     443
     444        private SpreadSheetHandler ssHandler;
     445
     446        public final void setSpreadSheetHandler(SpreadSheetHandler handler) {
     447                ssHandler = handler;
     448        }
     449       
     450        public final SpreadSheetHandler getSpreadSheetHandler() {
     451                return ssHandler;
     452        }
     453
     454        public final void setCsvHandler(CsvHandler handler) {
     455                setSpreadSheetHandler(handler);
     456        }
     457       
     458        public final CsvHandler getCsvHandler() {
     459                if (ssHandler instanceof CsvHandler) {
     460                        return (CsvHandler) ssHandler;
     461                } else {
     462                        return null;
     463                }
    570464        }
    571465}
  • applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/datasets/SimpleDataSetHandler.java

    r28000 r28113  
     1//    JOSM opendata plugin.
     2//    Copyright (C) 2011-2012 Don-vip
     3//
     4//    This program is free software: you can redistribute it and/or modify
     5//    it under the terms of the GNU General Public License as published by
     6//    the Free Software Foundation, either version 3 of the License, or
     7//    (at your option) any later version.
     8//
     9//    This program is distributed in the hope that it will be useful,
     10//    but WITHOUT ANY WARRANTY; without even the implied warranty of
     11//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12//    GNU General Public License for more details.
     13//
     14//    You should have received a copy of the GNU General Public License
     15//    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    116package org.openstreetmap.josm.plugins.opendata.core.datasets;
    2 
    3 import static org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler.OaQueryType.NODE;
    4 import static org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler.OaQueryType.WAY;
    5 import static org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler.OaQueryType.RELATION;
    6 import static org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler.OaRecurseType.NODE_RELATION;
    7 import static org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler.OaRecurseType.RELATION_WAY;
    8 import static org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler.OaRecurseType.WAY_NODE;
    9 import static org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler.OaRecurseType.WAY_RELATION;
    1017
    1118import java.util.ArrayList;
     
    1724import org.openstreetmap.josm.data.osm.Tag;
    1825import org.openstreetmap.josm.data.projection.Projection;
     26import org.openstreetmap.josm.plugins.opendata.core.io.OverpassApi;
     27
     28import static org.openstreetmap.josm.plugins.opendata.core.io.OverpassApi.OaQueryType.*;
     29import static org.openstreetmap.josm.plugins.opendata.core.io.OverpassApi.OaRecurseType.*;
    1930
    2031public abstract class SimpleDataSetHandler extends AbstractDataSetHandler {
     
    155166                List<String> conditions = new ArrayList<String>();
    156167                for (Tag tag : this.relevantTags) {
    157                         conditions.add(oaHasKey(tag.getKey(), tag.getValue()));
     168                        conditions.add(OverpassApi.hasKey(tag.getKey(), tag.getValue()));
    158169                }
    159170                return conditions.toArray(new String[0]);
     
    162173        protected String getOverpassApiQueries(String bbox, String ... conditions) {
    163174                String[] mpconditions = new String[conditions.length+1];
    164                 mpconditions[0] = oaHasKey("type", "multipolygon");
     175                mpconditions[0] = OverpassApi.hasKey("type", "multipolygon");
    165176                for (int i=0; i<conditions.length; i++) {
    166177                        mpconditions[i+1] = conditions[i];
    167178                }
    168                 return oaQuery(bbox, NODE, conditions) + "\n" + // Nodes
    169                                 oaRecurse(NODE_RELATION, RELATION_WAY, WAY_NODE) + "\n" +
    170                                 oaQuery(bbox, WAY, conditions) + "\n" + // Full ways and their full relations
    171                                 oaRecurse(WAY_NODE, "nodes") + "\n" +
    172                                 oaRecurse(WAY_RELATION, RELATION_WAY, WAY_NODE) + "\n" +
    173                                 oaQuery(bbox, RELATION, mpconditions) + "\n" + // Full multipolygons
    174                                 oaRecurse(RELATION_WAY, WAY_NODE);
     179                return OverpassApi.query(bbox, NODE, conditions) + "\n" + // Nodes
     180                        OverpassApi.recurse(NODE_RELATION, RELATION_WAY, WAY_NODE) + "\n" +
     181                        OverpassApi.query(bbox, WAY, conditions) + "\n" + // Full ways and their full relations
     182                        OverpassApi.recurse(WAY_NODE, "nodes") + "\n" +
     183                        OverpassApi.recurse(WAY_RELATION, RELATION_WAY, WAY_NODE) + "\n" +
     184                        OverpassApi.query(bbox, RELATION, mpconditions) + "\n" + // Full multipolygons
     185                        OverpassApi.recurse(RELATION_WAY, WAY_NODE);
    175186        }
    176187       
     
    183194                if (this.relevantUnion) {
    184195                        for (Tag tag : this.relevantTags) {
    185                                 result += getOverpassApiQueries(bbox, oaHasKey(tag.getKey(), tag.getValue()));
    186                         }
    187                         result = oaUnion(result);
     196                                result += getOverpassApiQueries(bbox, OverpassApi.hasKey(tag.getKey(), tag.getValue()));
     197                        }
     198                        result = OverpassApi.union(result);
    188199                } else {
    189                         result = oaUnion(getOverpassApiQueries(bbox, getOverpassApiConditions()));
    190                 }
    191                 return result + oaPrint();
     200                        result = OverpassApi.union(getOverpassApiQueries(bbox, getOverpassApiConditions()));
     201                }
     202                return result + OverpassApi.print();
    192203        }
    193204
  • applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/datasets/be/BelgianDataSetHandler.java

    r28000 r28113  
    1818import java.net.MalformedURLException;
    1919import java.net.URL;
    20 import java.util.Arrays;
    21 import java.util.List;
    2220import java.util.Locale;
    2321
     
    2826import org.openstreetmap.josm.data.projection.Projection;
    2927import org.openstreetmap.josm.plugins.opendata.core.datasets.SimpleDataSetHandler;
     28import org.openstreetmap.josm.plugins.opendata.core.io.tabular.DefaultCsvHandler;
    3029
    3130public abstract class BelgianDataSetHandler extends SimpleDataSetHandler implements BelgianConstants {
     
    4544                lambert2008
    4645        };
     46       
     47        protected class InternalCsvHandler extends DefaultCsvHandler {
     48                /*@Override
     49                public List<Projection> getSpreadSheetProjections() {
     50                        if (singleProjection != null) {
     51                                return Arrays.asList(new Projection[]{singleProjection});
     52                        } else {
     53                                return Arrays.asList(projections);
     54                        }
     55                }*/
     56               
     57                @Override
     58                public LatLon getCoor(EastNorth en, String[] fields) {
     59                        if (singleProjection != null) {
     60                                return singleProjection.eastNorth2latlon(en);
     61                        } else {
     62                                return super.getCoor(en, fields);
     63                        }
     64                }
     65        }
    4766
    4867        public BelgianDataSetHandler() {
    49                
     68                init();
    5069        }
    5170
    5271        public BelgianDataSetHandler(String relevantTag) {
    5372                super(relevantTag);
     73                init();
    5474        }
    5575
    5676        public BelgianDataSetHandler(boolean relevantUnion, String[] relevantTags) {
    5777                super(relevantUnion, relevantTags);
     78                init();
    5879        }
    5980
    6081        public BelgianDataSetHandler(boolean relevantUnion, Tag[] relevantTags) {
    6182                super(relevantUnion, relevantTags);
     83                init();
    6284        }
    6385       
     86        private void init() {
     87                setCsvHandler(new InternalCsvHandler());
     88        }
     89
    6490        protected final void setNationalPortalPath(String nationalPortalPathDe, String nationalPortalPathEn, String nationalPortalPathFr, String nationalPortalPathNl) {
    6591                this.nationalPortalPathDe = nationalPortalPathDe;
     
    7197        protected final void setSingleProjection(Projection singleProjection) {
    7298                this.singleProjection = singleProjection;
     99                getCsvHandler().setHandlesProjection(singleProjection != null);
    73100        }
    74101
     
    116143                return ICON_BE_24;
    117144        }
    118        
    119         /* (non-Javadoc)
    120          * @see org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler#handlesCsvProjection()
    121          */
    122         @Override
    123         public boolean handlesSpreadSheetProjection() {
    124                 return singleProjection != null ? true : super.handlesSpreadSheetProjection();
    125         }
    126        
    127         /* (non-Javadoc)
    128          * @see org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler#getCsvProjections()
    129          */
    130         @Override
    131         public List<Projection> getSpreadSheetProjections() {
    132                 if (singleProjection != null) {
    133                         return Arrays.asList(new Projection[]{singleProjection});
    134                 } else {
    135                         return Arrays.asList(projections);
    136                 }
    137         }
    138        
    139         /* (non-Javadoc)
    140          * @see org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler#getCsvCoor(org.openstreetmap.josm.data.coor.EastNorth, java.lang.String[])
    141          */
    142         @Override
    143         public LatLon getSpreadSheetCoor(EastNorth en, String[] fields) {
    144                 if (singleProjection != null) {
    145                         return singleProjection.eastNorth2latlon(en);
    146                 } else {
    147                         return super.getSpreadSheetCoor(en, fields);
    148                 }
    149         }
    150145}
  • applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/datasets/fr/FrenchDataSetHandler.java

    r28050 r28113  
    2121import java.net.URL;
    2222import java.util.Arrays;
    23 import java.util.List;
    2423import java.util.regex.Matcher;
    2524import java.util.regex.Pattern;
    2625
    27 import org.geotools.referencing.CRS;
    28 import org.opengis.referencing.FactoryException;
    29 import org.opengis.referencing.crs.CoordinateReferenceSystem;
    30 import org.opengis.referencing.operation.MathTransform;
    3126import org.openstreetmap.josm.data.coor.EastNorth;
    3227import org.openstreetmap.josm.data.coor.LatLon;
     
    3833import org.openstreetmap.josm.data.projection.UTM.Hemisphere;
    3934import org.openstreetmap.josm.plugins.opendata.core.datasets.SimpleDataSetHandler;
     35import org.openstreetmap.josm.plugins.opendata.core.io.tabular.DefaultCsvHandler;
    4036
    4137public abstract class FrenchDataSetHandler extends SimpleDataSetHandler implements FrenchConstants {
     
    6662                utm40, // Reunion
    6763        };
     64       
     65        protected class InternalCsvHandler extends DefaultCsvHandler {
     66                /*@Override
     67                public List<Projection> getSpreadSheetProjections() {
     68                        if (singleProjection != null) {
     69                                return Arrays.asList(new Projection[]{singleProjection});
     70                        } else {
     71                                return Arrays.asList(projections);
     72                        }
     73                }*/
     74               
     75                @Override
     76                public LatLon getCoor(EastNorth en, String[] fields) {
     77                        if (singleProjection != null) {
     78                                return singleProjection.eastNorth2latlon(en);
     79                        } else {
     80                                return super.getCoor(en, fields);
     81                        }
     82                }
     83
     84                @Override
     85                public boolean handlesProjection() {
     86                        return singleProjection != null;
     87                }
     88        }
    6889
    6990        public FrenchDataSetHandler() {
    70                
     91                init();
    7192        }
    7293
    7394        public FrenchDataSetHandler(String relevantTag) {
    7495                super(relevantTag);
     96                init();
    7597        }
    7698
    7799        public FrenchDataSetHandler(boolean relevantUnion, String[] relevantTags) {
    78100                super(relevantUnion, relevantTags);
     101                init();
    79102        }
    80103
    81104        public FrenchDataSetHandler(boolean relevantUnion, Tag[] relevantTags) {
    82105                super(relevantUnion, relevantTags);
    83         }
    84        
     106                init();
     107        }
     108       
     109        private void init() {
     110                setShpHandler(new FrenchShpHandler());
     111                setCsvHandler(new InternalCsvHandler());
     112        }
     113
    85114        protected final void setNationalPortalPath(String nationalPortalPath) {
    86115                this.nationalPortalPath = nationalPortalPath;
     
    120149        public String getNationalPortalIconName() {
    121150                return ICON_FR_24;
    122         }
    123        
    124         /* (non-Javadoc)
    125          * @see org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler#handlesCsvProjection()
    126          */
    127         @Override
    128         public boolean handlesSpreadSheetProjection() {
    129                 return singleProjection != null ? true : super.handlesSpreadSheetProjection();
    130         }
    131        
    132         /* (non-Javadoc)
    133          * @see org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler#getCsvProjections()
    134          */
    135         @Override
    136         public List<Projection> getSpreadSheetProjections() {
    137                 if (singleProjection != null) {
    138                         return Arrays.asList(new Projection[]{singleProjection});
    139                 } else {
    140                         return Arrays.asList(projections);
    141                 }
    142         }
    143        
    144         /* (non-Javadoc)
    145          * @see org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler#getCsvCoor(org.openstreetmap.josm.data.coor.EastNorth, java.lang.String[])
    146          */
    147         @Override
    148         public LatLon getSpreadSheetCoor(EastNorth en, String[] fields) {
    149                 if (singleProjection != null) {
    150                         return singleProjection.eastNorth2latlon(en);
    151                 } else {
    152                         return super.getSpreadSheetCoor(en, fields);
    153                 }
    154151        }
    155152       
     
    258255                return "";
    259256        }
    260 
    261         /* (non-Javadoc)
    262          * @see org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler#findMathTransform(org.opengis.referencing.crs.CoordinateReferenceSystem, org.opengis.referencing.crs.CoordinateReferenceSystem, boolean)
    263          */
    264         @Override
    265         public MathTransform findMathTransform(CoordinateReferenceSystem sourceCRS, CoordinateReferenceSystem targetCRS, boolean lenient)
    266                         throws FactoryException {
    267                 if (sourceCRS.getName().getCode().equalsIgnoreCase("RGM04")) {
    268                         return CRS.findMathTransform(CRS.decode("EPSG:4471"), targetCRS, lenient);
    269                 } else if (sourceCRS.getName().getCode().equalsIgnoreCase("RGFG95_UTM_Zone_22N")) {
    270                         return CRS.findMathTransform(CRS.decode("EPSG:2972"), targetCRS, lenient);
    271                 } else {
    272                         return super.findMathTransform(sourceCRS, targetCRS, lenient);
    273                 }
    274         }
    275257}
  • applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/NetworkReader.java

    r28088 r28113  
    5050        private String filename;
    5151       
    52     public NetworkReader(String url, AbstractDataSetHandler handler, Class<? extends AbstractReader> readerClass) {
     52    public NetworkReader(String url, AbstractDataSetHandler handler) {
    5353        CheckParameterUtil.ensureParameterNotNull(url, "url");
    54         //CheckParameterUtil.ensureParameterNotNull(readerClass, "readerClass");
    5554        this.url = url;
    56         this.readerClass = readerClass;
    5755        this.handler = handler;
     56        this.readerClass = null;
    5857    }
    5958   
  • applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/archive/ZipReader.java

    r28055 r28113  
    5050        private final ZipInputStream zis;
    5151        private final AbstractDataSetHandler handler;
     52        private final ZipHandler zipHandler;
    5253       
    5354        private File file;
     
    5657        this.zis = in instanceof ZipInputStream ? (ZipInputStream) in : new ZipInputStream(in);
    5758        this.handler = handler;
     59        this.zipHandler = handler != null ? handler.getZipHandler() : null;
    5860    }
    5961
     
    116118                                        fos.close();
    117119                                        // Allow handler to perform specific treatments (for example, fix invalid .prj files)
    118                                         if (handler != null) {
    119                                                 handler.notifyTempFileWritten(file);
     120                                        if (zipHandler != null) {
     121                                                zipHandler.notifyTempFileWritten(file);
    120122                                        }
    121123                                        // Set last modification date
     
    135137                                        }
    136138                                        // Special treatment for XML files (check supported XSD), unless handler explicitely skip it
    137                                         if (XML_FILE_FILTER.accept(file) && ((handler != null && handler.skipXsdValidationInZipReading())
     139                                        if (XML_FILE_FILTER.accept(file) && ((zipHandler != null && zipHandler.skipXsdValidation())
    138140                                                        || OdPlugin.getInstance().xmlImporter.acceptFile(file))) {
    139141                                                candidates.add(file);
  • applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/ShpReader.java

    r28044 r28113  
    8484public class ShpReader extends AbstractReader implements OdConstants {
    8585
    86         private final AbstractDataSetHandler handler;
     86        private final ShpHandler handler;
    8787       
    8888        private final CoordinateReferenceSystem wgs84;
     
    9393        private MathTransform transform;
    9494       
    95         public ShpReader(AbstractDataSetHandler handler) throws NoSuchAuthorityCodeException, FactoryException {
     95        public ShpReader(ShpHandler handler) throws NoSuchAuthorityCodeException, FactoryException {
    9696                this.handler = handler;
    9797                this.wgs84 = CRS.decode("EPSG:4326");
     
    105105                }
    106106                try {
    107                         return new ShpReader(handler).parse(file, instance);
     107                        return new ShpReader(handler != null ? handler.getShpHandler() : null).parse(file, instance);
    108108                } catch (IOException e) {
    109109                        throw e;
     
    373373        private Node getNode(Point p, String key) {
    374374                Node n = nodes.get(key);
    375                 if (n == null && handler != null && handler.checkShpNodeProximity()) {
     375                if (n == null && handler != null && handler.checkNodeProximity()) {
    376376                        LatLon ll = new LatLon(p.getY(), p.getX());
    377377                        for (Node node : nodes.values()) {
  • applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/TabReader.java

    r28000 r28113  
    3434import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    3535import org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler;
     36import org.openstreetmap.josm.plugins.opendata.core.io.tabular.SpreadSheetHandler;
    3637import org.openstreetmap.josm.plugins.opendata.core.io.tabular.SpreadSheetReader;
    3738
     
    7677
    7778                private final DbaseFileReader dbfReader;
    78                 public TabOsmReader(AbstractDataSetHandler handler, TabFiles tabFiles) throws IOException {
     79                public TabOsmReader(SpreadSheetHandler handler, TabFiles tabFiles) throws IOException {
    7980                        super(handler);
    8081                        this.dbfReader = new DbaseFileReader(tabFiles, false, datCharset, null);
     
    111112        try {
    112113                File dataFile = getDataFile(file, ".dat");
    113                 ds.mergeFrom(new TabOsmReader(handler, new TabFiles(file, dataFile)).
     114                ds.mergeFrom(new TabOsmReader(handler != null ? handler.getSpreadSheetHandler() : null, new TabFiles(file, dataFile)).
    114115                                doParse(columns.toArray(new String[0]), instance));
    115116        } catch (IOException e) {
  • applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/tabular/CsvReader.java

    r28033 r28113  
    3535        private String line;
    3636
    37         public CsvReader(AbstractDataSetHandler handler) {
     37        public CsvReader(CsvHandler handler) {
    3838                this(handler, ";");
    3939        }
    4040
    41         public CsvReader(AbstractDataSetHandler handler, String defaultSep) {
     41        public CsvReader(CsvHandler handler, String defaultSep) {
    4242                super(handler);
    43                 this.charset = handler != null && handler.getCsvCharset() != null ? handler.getCsvCharset() : Charset.forName(UTF8);
    44                 this.sep = handler != null && handler.getCsvSeparator() != null ? handler.getCsvSeparator() : defaultSep;
     43                this.charset = handler != null && handler.getCharset() != null ? handler.getCharset() : Charset.forName(UTF8);
     44                this.sep = handler != null && handler.getSeparator() != null ? handler.getSeparator() : defaultSep;
    4545        }
    4646       
    4747        public static DataSet parseDataSet(InputStream in, AbstractDataSetHandler handler, ProgressMonitor instance) throws IOException {
    48                 CsvReader csvReader = new CsvReader(handler);
     48                CsvHandler csvHandler = null;
     49                if (handler.getSpreadSheetHandler() instanceof CsvHandler) {
     50                        csvHandler = (CsvHandler) handler.getSpreadSheetHandler();
     51                }
     52                CsvReader csvReader = new CsvReader(csvHandler);
    4953                try {
    5054                        return csvReader.parse(in, instance);
    5155                } catch (IllegalArgumentException e) {
    52                         if (handler == null) {
     56                        if (csvHandler == null || (csvHandler.getSeparator() != null && csvHandler.getSeparator().equals(";"))) {
    5357                                // If default sep has been used, try comma
    5458                                System.out.println(e.getMessage());
    55                                 CsvReader newReader = new CsvReader(handler, ",");
     59                                CsvReader newReader = new CsvReader(csvHandler, ",");
    5660                                newReader.initResources(in, instance);
    5761                                newReader.line = csvReader.line;
  • applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/tabular/OdsReader.java

    r28000 r28113  
    3838        private static final String SEP = "TextP:\\[";
    3939       
    40         public OdsReader(AbstractDataSetHandler handler) {
     40        public OdsReader(SpreadSheetHandler handler) {
    4141                super(handler);
    4242        }
     
    4444        public static DataSet parseDataSet(InputStream in,
    4545                        AbstractDataSetHandler handler, ProgressMonitor instance) throws IOException {
    46                 return new OdsReader(handler).parse(in, instance);
     46                return new OdsReader(handler != null ? handler.getSpreadSheetHandler() : null).parse(in, instance);
    4747        }
    4848
  • applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/tabular/SpreadSheetReader.java

    r28000 r28113  
    3737import org.openstreetmap.josm.io.AbstractReader;
    3838import org.openstreetmap.josm.plugins.opendata.core.OdConstants;
    39 import org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler;
    4039import org.openstreetmap.josm.plugins.opendata.core.io.ProjectionChooser;
    4140import org.openstreetmap.josm.plugins.opendata.core.io.ProjectionPatterns;
     
    5352        }
    5453
    55         protected final AbstractDataSetHandler handler;
    56 
    57         public SpreadSheetReader(AbstractDataSetHandler handler) {
     54        protected final SpreadSheetHandler handler;
     55
     56        public SpreadSheetReader(SpreadSheetHandler handler) {
    5857                this.handler = handler;
    5958        }
     
    122121                }
    123122
    124                 final boolean handlerOK = handler != null && handler.handlesSpreadSheetProjection();
     123                final boolean handlerOK = handler != null && handler.handlesProjection();
    125124
    126125                if (proj != null) {
     
    168167                        }
    169168                        if (en.isValid()) {
    170                                 n.setCoor(proj != null && !handlerOK ? proj.eastNorth2latlon(en) : handler.getSpreadSheetCoor(en, fields));
     169                                n.setCoor(proj != null && !handlerOK ? proj.eastNorth2latlon(en) : handler.getCoor(en, fields));
    171170                        } else {
    172171                                System.err.println("Warning: Skipping line "+lineNumber+" because no valid coordinates have been found.");
  • applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/tabular/XlsReader.java

    r28000 r28113  
    3838        private int rowIndex;
    3939       
    40         public XlsReader(AbstractDataSetHandler handler) {
     40        public XlsReader(SpreadSheetHandler handler) {
    4141                super(handler);
    4242        }
     
    4444        public static DataSet parseDataSet(InputStream in,
    4545                        AbstractDataSetHandler handler, ProgressMonitor instance) throws IOException {
    46                 return new XlsReader(handler).parse(in, instance);
     46                return new XlsReader(handler != null ? handler.getSpreadSheetHandler() : null).parse(in, instance);
    4747        }
    4848
  • applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/layers/OdDataLayer.java

    r28022 r28113  
    3838import org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler;
    3939import org.openstreetmap.josm.plugins.opendata.core.io.OsmDownloader;
     40import org.openstreetmap.josm.plugins.opendata.core.licenses.License;
    4041import org.openstreetmap.josm.plugins.opendata.core.util.OdUtils;
    4142
     
    155156                                        tr("View National Portal page"), tr("Launch browser to the national portal page of the selected data set")));
    156157                }
    157                 if (this.handler.getLicenseURL() != null) {
    158                         if (this.handler.getLicenseURL().getProtocol().startsWith("http")) {
    159                                 result.add(new OpenLinkAction(this.handler.getLicenseURL(), ICON_AGREEMENT_24,
     158                if (this.handler.getLicense() != null) {
     159                        License lic = this.handler.getLicense();
     160                        if (lic.getURL() != null && lic.getURL().getProtocol().startsWith("http")) {
     161                                result.add(new OpenLinkAction(lic.getURL(), ICON_AGREEMENT_24,
    160162                                                tr("View License"), tr("Launch browser to the license page of the selected data set")));
     163                        } else {
     164                                // TODO: view embedded licenses
     165                        }
     166                        if (lic.getSummaryURL() != null && lic.getSummaryURL().getProtocol().startsWith("http")) {
     167                                result.add(new OpenLinkAction(lic.getSummaryURL(), ICON_AGREEMENT_24,
     168                                                tr("View License (summary)"), tr("Launch browser to the summary license page of the selected data set")));
    161169                        } else {
    162170                                // TODO: view embedded licenses
  • applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/util/OdUtils.java

    r28022 r28113  
    1818import java.util.ArrayList;
    1919import java.util.List;
     20import java.util.Locale;
    2021
    2122import javax.swing.ImageIcon;
    2223
    2324import org.apache.commons.lang3.StringUtils;
     25import org.openstreetmap.josm.Main;
    2426import org.openstreetmap.josm.data.osm.OsmPrimitive;
    2527import org.openstreetmap.josm.data.osm.Relation;
     
    5658       
    5759        public static final ImageIcon getImageIcon(String iconName) {
    58                 return new ImageProvider(iconName).setAdditionalClassLoaders(ModuleHandler.getResourceClassLoaders()).get();
     60                return getImageIcon(iconName, false);
     61        }
     62       
     63        public static final ImageIcon getImageIcon(String iconName, boolean optional) {
     64                return new ImageProvider(iconName).setOptional(optional).setAdditionalClassLoaders(ModuleHandler.getResourceClassLoaders()).get();
     65        }
     66       
     67        public static final String getJosmLanguage() {
     68                String lang = Main.pref.get("language");
     69                if (lang == null || lang.isEmpty()) {
     70                        lang = Locale.getDefault().toString();
     71                }
     72                return lang;
    5973        }
    6074}
Note: See TracChangeset for help on using the changeset viewer.