Ignore:
Timestamp:
2012-03-09T01:06:18+01:00 (13 years ago)
Author:
donvip
Message:

opendata: Initial Neptune files support

Location:
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/OdPlugin.java

    r28000 r28018  
    3030import org.openstreetmap.josm.plugins.opendata.core.gui.OdPreferenceSetting;
    3131import org.openstreetmap.josm.plugins.opendata.core.io.AbstractImporter;
     32import org.openstreetmap.josm.plugins.opendata.core.io.XmlImporter;
    3233import org.openstreetmap.josm.plugins.opendata.core.io.archive.ZipImporter;
    3334import org.openstreetmap.josm.plugins.opendata.core.io.geographic.KmlKmzImporter;
     
    5556                                new CsvImporter(), new OdsImporter(), new XlsImporter(), // Tabular file formats
    5657                                new KmlKmzImporter(), new ShpImporter(), new MifTabImporter(), // Geographic file formats
    57                                 new ZipImporter() // Archive containing any of the others
     58                                new ZipImporter(), // Archive containing any of the others
     59                                new XmlImporter() // Generic importer for XML files (currently used for Neptune files)
    5860                })) {
    59                         ExtensionFileFilter.importers.add(importer);
     61                        ExtensionFileFilter.importers.add(0, importer);
    6062                }
    6163        // Load modules
  • TabularUnified applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/OdConstants.java

    r28001 r28018  
    9898    public static final String ZIP_EXT = "zip";
    9999    public static final String JAR_EXT = "jar";
     100    public static final String XML_EXT = "xml";
    100101   
    101102    /**
     
    115116    public static final ExtensionFileFilter KML_KMZ_FILE_FILTER = new ExtensionFileFilter(KML_EXT+","+KMZ_EXT, KMZ_EXT, tr("KML/KMZ files") + " (*."+KML_EXT+",*."+KMZ_EXT+")");
    116117    public static final ExtensionFileFilter ZIP_FILE_FILTER = new ExtensionFileFilter(ZIP_EXT, ZIP_EXT, tr("Zip Files") + " (*."+ZIP_EXT+")");
     118    public static final ExtensionFileFilter XML_FILE_FILTER = new ExtensionFileFilter(XML_EXT, XML_EXT, tr("OpenData XML files") + " (*."+XML_EXT+")");
    117119   
    118120    /**
  • TabularUnified applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/datasets/AbstractDataSetHandler.java

    r28000 r28018  
    5858
    5959public abstract class AbstractDataSetHandler implements OdConstants {
     60       
    6061        public abstract boolean acceptsFilename(String filename);
     62       
     63        public boolean acceptsFile(File file) {
     64                return acceptsFilename(file.getName());
     65        }
     66       
    6167        public abstract void updateDataSet(DataSet ds);
    6268
  • TabularUnified applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/datasets/fr/FrenchConstants.java

    r28000 r28018  
    2929         */
    3030        public static final String ICON_FR_24 = "fr24.png";
     31       
     32        /**
     33         * NEPTUNE XML Schema
     34         */
     35        public static final String NEPTUNE_XSD = "/neptune/neptune.xsd";
    3136}
  • TabularUnified applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/datasets/fr/FrenchDataSetHandler.java

    r28000 r28018  
    1818import static org.openstreetmap.josm.plugins.opendata.core.io.LambertCC9ZonesProjectionPatterns.lambertCC9Zones;
    1919
     20import java.io.File;
     21import java.io.IOException;
    2022import java.net.MalformedURLException;
    2123import java.net.URL;
     
    2426import java.util.regex.Matcher;
    2527import java.util.regex.Pattern;
     28
     29import javax.xml.XMLConstants;
     30import javax.xml.transform.Source;
     31import javax.xml.transform.stream.StreamSource;
     32import javax.xml.validation.Schema;
     33import javax.xml.validation.SchemaFactory;
     34import javax.xml.validation.Validator;
    2635
    2736import org.geotools.referencing.CRS;
     
    3847import org.openstreetmap.josm.data.projection.UTM.Hemisphere;
    3948import org.openstreetmap.josm.plugins.opendata.core.datasets.SimpleDataSetHandler;
     49import org.xml.sax.SAXException;
    4050
    4151public abstract class FrenchDataSetHandler extends SimpleDataSetHandler implements FrenchConstants {
     
    273283                }
    274284        }
     285       
     286        protected URL getNeptuneSchema() {
     287                return FrenchDataSetHandler.class.getResource(NEPTUNE_XSD);
     288        }
     289
     290        protected final boolean acceptsXmlNeptuneFile(File file) {
     291               
     292                Source xmlFile = new StreamSource(file);
     293               
     294                try {
     295                        SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
     296                        Schema schema = schemaFactory.newSchema(getNeptuneSchema());
     297                        Validator validator = schema.newValidator();
     298                        validator.validate(xmlFile);
     299                        System.out.println(xmlFile.getSystemId() + " is valid");
     300                        return true;
     301                } catch (SAXException e) {
     302                        System.out.println(xmlFile.getSystemId() + " is NOT valid");
     303                        System.out.println("Reason: " + e.getLocalizedMessage());
     304                } catch (IOException e) {
     305                        System.out.println(xmlFile.getSystemId() + " is NOT valid");
     306                        System.out.println("Reason: " + e.getLocalizedMessage());
     307                }
     308               
     309                return false;
     310        }
    275311}
  • TabularUnified applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/AbstractImporter.java

    r28000 r28018  
    4444    }
    4545   
    46     protected final AbstractDataSetHandler findDataSetHandler(String fileName) {
     46    protected final AbstractDataSetHandler findDataSetHandler(File file) {
    4747        for (Module module : ModuleHandler.moduleList) {
    4848                        for (AbstractDataSetHandler dsh : module.getHandlers()) {
    49                                 if (dsh.acceptsFilename(fileName)) {
     49                                if (dsh.acceptsFile(file)) {
    5050                                        return dsh;
    5151                                }
     
    6363                if (file != null) {
    6464                        this.file = file;
    65                         this.handler = findDataSetHandler(file.getName());
     65                        this.handler = findDataSetHandler(file);
    6666                }
    6767                super.importData(file, progressMonitor);
Note: See TracChangeset for help on using the changeset viewer.