Ticket #21638: opendata_ckan_data.gv.at_v2.patch

File opendata_ckan_data.gv.at_v2.patch, 150.6 KB (added by Woazboat, 2 years ago)
  • plugins/jackan/.classpath

     
     1<?xml version="1.0" encoding="UTF-8"?>
     2<classpath>
     3        <classpathentry kind="src" path="src"/>
     4        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
     5        <classpathentry combineaccessrules="false" kind="src" path="/JOSM"/>
     6        <classpathentry exported="true" kind="con" path="org.apache.ivyde.eclipse.cpcontainer.IVYDE_CONTAINER/?project=JOSM-jackan&amp;ivyXmlPath=ivy.xml&amp;confs=*"/>
     7        <classpathentry kind="output" path="bin"/>
     8</classpath>
  • plugins/jackan/.project

     
     1<?xml version="1.0" encoding="UTF-8"?>
     2<projectDescription>
     3        <name>JOSM-jackan</name>
     4        <comment></comment>
     5        <projects>
     6        </projects>
     7        <buildSpec>
     8                <buildCommand>
     9                        <name>org.eclipse.jdt.core.javabuilder</name>
     10                        <arguments>
     11                        </arguments>
     12                </buildCommand>
     13                <buildCommand>
     14                        <name>org.sonarlint.eclipse.core.sonarlintBuilder</name>
     15                        <arguments>
     16                        </arguments>
     17                </buildCommand>
     18                <buildCommand>
     19                        <name>net.sf.eclipsecs.core.CheckstyleBuilder</name>
     20                        <arguments>
     21                        </arguments>
     22                </buildCommand>
     23        </buildSpec>
     24        <natures>
     25                <nature>org.eclipse.jdt.core.javanature</nature>
     26                <nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
     27                <nature>org.apache.ivyde.eclipse.ivynature</nature>
     28        </natures>
     29</projectDescription>
  • plugins/jackan/build.xml

     
     1<?xml version="1.0" encoding="utf-8"?>
     2<project name="jackan" default="dist" basedir=".">
     3    <!-- enter the SVN commit message -->
     4    <property name="commit.message" value="Commit message"/>
     5    <!-- enter the *lowest* JOSM version this plugin is currently compatible with -->
     6    <property name="plugin.main.version" value="10580"/>
     7   
     8    <property name="plugin.author" value="Woazboat"/>
     9    <property name="plugin.class" value="org.openstreetmap.josm.plugins.jackan.JackanPlugin"/>
     10    <property name="plugin.description" value="Provides a CKAN client. Not meant to be installed directly by users, but rather as a dependency for other plugins."/>
     11    <property name="plugin.icon" value="images/jackan.png"/>
     12    <!-- <property name="plugin.canloadatruntime" value="true"/> -->
     13    <!--<property name="plugin.link" value="..."/>-->
     14    <!--<property name="plugin.early" value="..."/>-->
     15    <!-- <property name="plugin.requires" value=""/> -->
     16    <property name="plugin.stage" value="10"/>
     17
     18    <!-- ** include targets that all plugins have in common ** -->
     19    <import file="../build-common.xml"/>
     20
     21    <target name="pre-compile" depends="fetch_dependencies">
     22        <!-- include fetch_dependencies task -->
     23    </target>
     24</project>
  • plugins/jackan/ivy.xml

    Cannot display: file marked as a binary type.
    svn:mime-type = application/octet-stream
    
    Property changes on: plugins/jackan/images/jackan.png
    ___________________________________________________________________
    Added: svn:mime-type
    ## -0,0 +1 ##
    +application/octet-stream
    \ No newline at end of property
     
     1<ivy-module version="2.0" xmlns:m="http://ant.apache.org/ivy/maven">
     2        <info organisation="org.openstreetmap.josm.plugins" module="jackan" revision="1.0" />
     3        <configurations defaultconf="default" defaultconfmapping="default->default">
     4                <conf name="default" />
     5        </configurations>
     6        <dependencies>
     7                <dependency org="eu.trentorise.opendata" name="jackan" rev="0.4.2" />
     8        </dependencies>
     9</ivy-module>
  • plugins/jackan/ivy_settings.xml

     
     1<ivysettings>
     2    <version-matchers usedefaults="true">
     3        <maven-tsnap-vm/>
     4    </version-matchers>
     5    <settings defaultResolver="central"/>
     6    <resolvers>
     7        <ibiblio name="central" m2compatible="true"/>
     8        <ibiblio name="josm-nexus" root="https://josm.openstreetmap.de/nexus/content/repositories/releases/" m2compatible="true" />
     9    </resolvers>
     10    <modules>
     11        <module organisation="org.openstreetmap.jmapviewer" resolver="josm-nexus"/>
     12        <module organisation="org.openstreetmap.josm" resolver="josm-nexus"/>
     13    </modules>
     14</ivysettings>
  • plugins/jackan/src/org/openstreetmap/josm/plugins/jackan/JackanPlugin.java

     
     1package org.openstreetmap.josm.plugins.jackan;
     2
     3import org.openstreetmap.josm.plugins.Plugin;
     4import org.openstreetmap.josm.plugins.PluginInformation;
     5
     6public class JackanPlugin extends Plugin {
     7    public JackanPlugin(PluginInformation info) {
     8        super(info);
     9    }
     10}
  • plugins/opendata/.classpath

     
    44        <classpathentry including="images/" kind="src" path=""/>
    55        <classpathentry excluding="org/odftoolkit/odfdom/JarManifest.java|org/odftoolkit/simple/JarManifest.java|org/odftoolkit/simple/|org/jopendocument/dom/spreadsheet/SheetTest.java|org/jopendocument/dom/ChildCreatorTest.java|org/jopendocument/dom/ODSingleXMLDocumentTest.java|org/jopendocument/dom/OOXMLTest.java|org/jopendocument/dom/template/|org/jopendocument/sample/|org/jopendocument/util/cache/ICacheTest.java|org/jopendocument/panel/|org/jopendocument/tools/|org/jopendocument/print/|org/jopendocument/renderer/|org/jopendocument/util/BenchmarkUtilities.java|org/jopendocument/util/ImageUtilities.java|org/jopendocument/util/PrintUtilities.java|org/odftoolkit/odfdom/|org/jopendocument/util/CompareUtils.java|org/jopendocument/util/DummyGraphics2D.java|org/jopendocument/util/DummyFontMetrics.java|org/jopendocument/dom/spreadsheet/CalcNode.java|org/jopendocument/io/StyleTableProperties.java|org/jopendocument/util/ReflectUtils.java|org/jopendocument/util/cache/CacheWatcher.java|org/jopendocument/util/cache/CacheWatcherFactory.java|org/jopendocument/util/cache/ICache.java|org/jopendocument/util/cache/|org/jopendocument/util/cc/ExnTransformer.java|org/jopendocument/model/chart/ChartChart.java|org/jopendocument/model/ConfigConfigItem.java|org/jopendocument/dom/text/Heading.java|org/odftoolkit/" kind="src" path="includes"/>
    66        <classpathentry kind="src" path="resources"/>
     7        <classpathentry kind="src" path="modules/at.gv.data/src"/>
     8        <classpathentry kind="src" path="modules/at.gv.data/resources"/>
    79        <classpathentry kind="src" path="modules/fr.datagouvfr/src"/>
    810        <classpathentry kind="src" path="modules/fr.datagouvfr/resources"/>
    911        <classpathentry kind="src" path="modules/fr.paris/src"/>
     
    2426        <classpathentry combineaccessrules="false" kind="src" path="/JOSM-utilsplugin2"/>
    2527        <classpathentry combineaccessrules="false" kind="src" path="/JOSM-GeoTools"/>
    2628        <classpathentry combineaccessrules="false" kind="src" path="/JOSM-jts"/>
     29        <classpathentry combineaccessrules="false" kind="src" path="/JOSM-jackan"/>
    2730        <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
    2831        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
    2932                <attributes>
  • plugins/opendata/build.xml

     
    77    <property name="plugin.icon" value="images/dialogs/o24.png"/>
    88    <property name="plugin.canloadatruntime" value="true"/>
    99    <property name="plugin.link" value="https://wiki.openstreetmap.org/wiki/JOSM/Plugins/OpenData"/>
    10     <property name="plugin.requires" value="apache-commons;jaxb;jts;ejml;geotools;utilsplugin2"/>
     10    <property name="plugin.requires" value="apache-commons;jaxb;jts;ejml;geotools;jackan;utilsplugin2"/>
    1111
    1212    <!-- ** include targets that all plugins have in common ** -->
    1313    <import file="../build-common.xml"/>
     
    1818        <include name="jts.jar"/>
    1919        <include name="ejml.jar"/>
    2020        <include name="geotools.jar"/>
     21        <include name="jackan.jar"/>
    2122        <include name="opendata.jar"/>
    2223    </fileset>
    2324
     
    2526    <property name="jts" location="${plugin.dist.dir}/jts.jar"/>
    2627    <property name="ejml" location="${plugin.dist.dir}/ejml.jar"/>
    2728    <property name="geotools" location="${plugin.dist.dir}/geotools.jar"/>
     29    <property name="jackan" location="${plugin.dist.dir}/jackan.jar"/>
    2830   
    2931    <!--
    3032    **********************************************************
  • plugins/opendata/modules/at.gv.data/README

    Cannot display: file marked as a binary type.
    svn:mime-type = application/octet-stream
    
    Property changes on: plugins/opendata/images/at24.png
    ___________________________________________________________________
    Added: svn:mime-type
    ## -0,0 +1 ##
    +application/octet-stream
    \ No newline at end of property
     
     1README
     2======
     3
     4Readme of data.gv.at module for JOSM Open Data plugin
     5
     6    * Author: Woazboat
     7    * License: GPL v3 (see gpl-3.0.txt)
     8
     9-------------------------------- DOCUMENTATION --------------------------------
     10
     11See https://wiki.openstreetmap.org/wiki/JOSM/Plugins/OpenData
  • plugins/opendata/modules/at.gv.data/build.xml

     
     1<?xml version="1.0" encoding="utf-8"?>
     2<project name="at.gv.data" default="dist" basedir=".">
     3    <!-- enter the SVN commit message -->
     4    <property name="commit.message" value="Commit message"/>
     5    <!-- should not be necessary to change the following properties -->
     6    <property name="josm" location="../../../../core/dist/josm-custom.jar"/>
     7    <property name="plugin.dist.dir" value="../../../../dist"/>
     8    <property name="opendata" location="${plugin.dist.dir}/opendata.jar"/>
     9    <property name="apachecommons" location="${plugin.dist.dir}/apache-commons.jar"/>
     10    <property name="jackan" location="${plugin.dist.dir}/jackan.jar"/>
     11    <property name="module.build.dir" value="build"/>
     12    <property name="module.src.dir" value="src"/>
     13    <property name="ant.build.javac.source" value="1.8"/>
     14    <property name="ant.build.javac.target" value="1.8"/>
     15    <!-- this is the directory where the module jar is copied to -->
     16    <property name="module.dist.dir" value="../../dist"/>
     17    <property name="module.jar" value="${module.dist.dir}/${ant.project.name}.jar"/>
     18    <!-- conditions -->
     19    <condition property="resources.exist">
     20        <available file="resources" type="dir" />
     21    </condition>
     22    <condition property="images.exist">
     23        <available file="images" type="dir" />
     24    </condition>
     25    <!--
     26    **********************************************************
     27    ** init - initializes the build
     28    **********************************************************
     29    -->
     30    <target name="init">
     31        <mkdir dir="${module.build.dir}"/>
     32        <mkdir dir="${module.build.dir}/META-INF"/>
     33    </target>
     34    <!--
     35    **********************************************************
     36    ** compile - compiles the source tree
     37    **********************************************************
     38    -->
     39    <target name="compile" depends="init">
     40        <echo message="compiling sources for ${module.jar} ... "/>
     41        <javac srcdir="${module.src.dir}" debug="true" destdir="${module.build.dir}" includeAntRuntime="false" encoding="UTF-8" >
     42            <classpath>
     43                <pathelement location="${josm}"/>
     44                <pathelement location="${opendata}"/>
     45                <pathelement location="${apachecommons}"/>
     46                <pathelement location="${jackan}"/>
     47            </classpath>
     48            <compilerarg value="-Xlint:deprecation"/>
     49            <compilerarg value="-Xlint:unchecked"/>
     50        </javac>
     51    </target>
     52    <!--
     53    **********************************************************
     54    ** copy-resources - copies resources dir to build dir
     55    **********************************************************
     56    -->
     57    <target name="copy-resources" if="resources.exist">
     58        <copy todir="${module.build.dir}">
     59            <fileset dir="resources" />
     60        </copy>
     61    </target>
     62    <!--
     63    **********************************************************
     64    ** copy-images - copies images dir to build dir
     65    **********************************************************
     66    -->
     67    <target name="copy-images" if="images.exist">
     68        <copy todir="${module.build.dir}/images">
     69            <fileset dir="images" />
     70        </copy>
     71    </target>
     72    <!--
     73    **********************************************************
     74    ** dist - creates the module jar
     75    **********************************************************
     76    -->
     77    <target name="dist" depends="compile,revision,copy-resources, copy-images">
     78        <echo message="creating ${ant.project.name}.jar ... "/>
     79        <copy todir="${module.build.dir}">
     80            <fileset dir=".">
     81                <include name="README"/>
     82                <include name="gpl-3.0.txt"/>
     83            </fileset>
     84        </copy>
     85        <jar destfile="${module.jar}" basedir="${module.build.dir}" manifestencoding="UTF-8">
     86            <!--
     87            ************************************************
     88            ** configure these properties. Most of them will
     89            ** be copied to the module manifest file.
     90            **
     91            ************************************************
     92            -->
     93            <manifest>
     94                <attribute name="Author" value="Woazboat"/>
     95                <attribute name="Module-Class" value="org.openstreetmap.josm.plugins.opendata.modules.at.gv.data.DataGvAtModule"/>
     96                <attribute name="Module-Date" value="${version.entry.commit.date}"/>
     97                <attribute name="Module-Description" value="data.gv.at"/>
     98                <attribute name="Module-Icon" value="images/at24.png"/>
     99                <!-- <attribute name="Module-Link" value="https://wiki.openstreetmap.org/wiki/JOSM/Plugins/OpenData"/> -->
     100                <attribute name="Module-Version" value="${version.entry.commit.revision}"/>
     101            </manifest>
     102        </jar>
     103    </target>
     104    <!--
     105    **********************************************************
     106    ** revision - extracts the current revision number for the
     107    **    file build.number and stores it in the XML property
     108    **    version.*
     109    **********************************************************
     110    -->
     111    <target name="revision">
     112        <exec append="false" output="REVISION" executable="svn" failifexecutionfails="false">
     113            <env key="LANG" value="C"/>
     114            <arg value="info"/>
     115            <arg value="--xml"/>
     116            <arg value="."/>
     117        </exec>
     118        <xmlproperty file="REVISION" prefix="version" keepRoot="false" collapseAttributes="true"/>
     119        <delete file="REVISION"/>
     120    </target>
     121    <!--
     122    **********************************************************
     123    ** clean - clean up the build environment
     124    **********************************************************
     125    -->
     126    <target name="clean">
     127        <delete dir="${module.build.dir}"/>
     128        <delete file="${module.jar}"/>
     129    </target>
     130    <!--
     131    **********************************************************
     132    ** install - install the module in your local JOSM installation
     133    **********************************************************
     134    -->
     135    <target name="install" depends="dist">
     136        <property environment="env"/>
     137        <condition property="josm.plugins.dir" value="${env.APPDATA}/JOSM/plugins" else="${user.home}/.josm/plugins">
     138            <and>
     139                <os family="windows"/>
     140            </and>
     141        </condition>
     142        <copy file="${module.jar}" todir="${josm.plugins.dir}/opendata/modules" overwrite="yes"/>
     143    </target>
     144    <!--
     145    ************************** Publishing the module ***********************************
     146    -->
     147    <!-- commits the source tree for this module -->
     148    <target name="commit-current">
     149        <echo>Commiting the module source with message '${commit.message}' ...</echo>
     150        <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false">
     151            <env key="LANG" value="C"/>
     152            <arg value="commit"/>
     153            <arg value="-m '${commit.message}'"/>
     154            <arg value="."/>
     155        </exec>
     156    </target>
     157    <!-- updates (svn up) the source tree for this module -->
     158    <target name="update-current">
     159        <echo>Updating module source ...</echo>
     160        <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false">
     161            <env key="LANG" value="C"/>
     162            <arg value="up"/>
     163            <arg value="."/>
     164        </exec>
     165        <echo>Updating ${module.jar} ...</echo>
     166        <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false">
     167            <env key="LANG" value="C"/>
     168            <arg value="up"/>
     169            <arg value="../dist/${module.jar}"/>
     170        </exec>
     171    </target>
     172    <!-- commits the module.jar -->
     173    <target name="commit-dist">
     174        <echo>
     175    ***** Properties of published ${module.jar} *****
     176    Commit message    : '${commit.message}'                   
     177    Module-Version    : ${version.entry.commit.revision}
     178    ***** / Properties of published ${module.jar} *****                   
     179                       
     180    Now committing ${module.jar} ...
     181    </echo>
     182        <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false">
     183            <env key="LANG" value="C"/>
     184            <arg value="-m '${commit.message}'"/>
     185            <arg value="commit"/>
     186            <arg value="${module.jar}"/>
     187        </exec>
     188    </target>
     189    <!-- make sure svn is present as a command line tool -->
     190    <target name="ensure-svn-present">
     191        <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false" failonerror="false" resultproperty="svn.exit.code">
     192            <env key="LANG" value="C"/>
     193            <arg value="--version"/>
     194        </exec>
     195        <fail message="Fatal: command 'svn --version' failed. Please make sure svn is installed on your system.">
     196            <!-- return code not set at all? Most likely svn isn't installed -->
     197            <condition>
     198                <not>
     199                    <isset property="svn.exit.code"/>
     200                </not>
     201            </condition>
     202        </fail>
     203        <fail message="Fatal: command 'svn --version' failed. Please make sure a working copy of svn is installed on your system.">
     204            <!-- error code from SVN? Most likely svn is not what we are looking on this system -->
     205            <condition>
     206                <isfailure code="${svn.exit.code}"/>
     207            </condition>
     208        </fail>
     209    </target>
     210    <target name="publish" depends="ensure-svn-present,commit-current,update-current,clean,dist,commit-dist">
     211    </target>
     212</project>
  • plugins/opendata/modules/at.gv.data/gpl-3.0.txt

     
     1                    GNU GENERAL PUBLIC LICENSE
     2                       Version 3, 29 June 2007
     3
     4 Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
     5 Everyone is permitted to copy and distribute verbatim copies
     6 of this license document, but changing it is not allowed.
     7
     8                            Preamble
     9
     10  The GNU General Public License is a free, copyleft license for
     11software and other kinds of works.
     12
     13  The licenses for most software and other practical works are designed
     14to take away your freedom to share and change the works.  By contrast,
     15the GNU General Public License is intended to guarantee your freedom to
     16share and change all versions of a program--to make sure it remains free
     17software for all its users.  We, the Free Software Foundation, use the
     18GNU General Public License for most of our software; it applies also to
     19any other work released this way by its authors.  You can apply it to
     20your programs, too.
     21
     22  When we speak of free software, we are referring to freedom, not
     23price.  Our General Public Licenses are designed to make sure that you
     24have the freedom to distribute copies of free software (and charge for
     25them if you wish), that you receive source code or can get it if you
     26want it, that you can change the software or use pieces of it in new
     27free programs, and that you know you can do these things.
     28
     29  To protect your rights, we need to prevent others from denying you
     30these rights or asking you to surrender the rights.  Therefore, you have
     31certain responsibilities if you distribute copies of the software, or if
     32you modify it: responsibilities to respect the freedom of others.
     33
     34  For example, if you distribute copies of such a program, whether
     35gratis or for a fee, you must pass on to the recipients the same
     36freedoms that you received.  You must make sure that they, too, receive
     37or can get the source code.  And you must show them these terms so they
     38know their rights.
     39
     40  Developers that use the GNU GPL protect your rights with two steps:
     41(1) assert copyright on the software, and (2) offer you this License
     42giving you legal permission to copy, distribute and/or modify it.
     43
     44  For the developers' and authors' protection, the GPL clearly explains
     45that there is no warranty for this free software.  For both users' and
     46authors' sake, the GPL requires that modified versions be marked as
     47changed, so that their problems will not be attributed erroneously to
     48authors of previous versions.
     49
     50  Some devices are designed to deny users access to install or run
     51modified versions of the software inside them, although the manufacturer
     52can do so.  This is fundamentally incompatible with the aim of
     53protecting users' freedom to change the software.  The systematic
     54pattern of such abuse occurs in the area of products for individuals to
     55use, which is precisely where it is most unacceptable.  Therefore, we
     56have designed this version of the GPL to prohibit the practice for those
     57products.  If such problems arise substantially in other domains, we
     58stand ready to extend this provision to those domains in future versions
     59of the GPL, as needed to protect the freedom of users.
     60
     61  Finally, every program is threatened constantly by software patents.
     62States should not allow patents to restrict development and use of
     63software on general-purpose computers, but in those that do, we wish to
     64avoid the special danger that patents applied to a free program could
     65make it effectively proprietary.  To prevent this, the GPL assures that
     66patents cannot be used to render the program non-free.
     67
     68  The precise terms and conditions for copying, distribution and
     69modification follow.
     70
     71                       TERMS AND CONDITIONS
     72
     73  0. Definitions.
     74
     75  "This License" refers to version 3 of the GNU General Public License.
     76
     77  "Copyright" also means copyright-like laws that apply to other kinds of
     78works, such as semiconductor masks.
     79
     80  "The Program" refers to any copyrightable work licensed under this
     81License.  Each licensee is addressed as "you".  "Licensees" and
     82"recipients" may be individuals or organizations.
     83
     84  To "modify" a work means to copy from or adapt all or part of the work
     85in a fashion requiring copyright permission, other than the making of an
     86exact copy.  The resulting work is called a "modified version" of the
     87earlier work or a work "based on" the earlier work.
     88
     89  A "covered work" means either the unmodified Program or a work based
     90on the Program.
     91
     92  To "propagate" a work means to do anything with it that, without
     93permission, would make you directly or secondarily liable for
     94infringement under applicable copyright law, except executing it on a
     95computer or modifying a private copy.  Propagation includes copying,
     96distribution (with or without modification), making available to the
     97public, and in some countries other activities as well.
     98
     99  To "convey" a work means any kind of propagation that enables other
     100parties to make or receive copies.  Mere interaction with a user through
     101a computer network, with no transfer of a copy, is not conveying.
     102
     103  An interactive user interface displays "Appropriate Legal Notices"
     104to the extent that it includes a convenient and prominently visible
     105feature that (1) displays an appropriate copyright notice, and (2)
     106tells the user that there is no warranty for the work (except to the
     107extent that warranties are provided), that licensees may convey the
     108work under this License, and how to view a copy of this License.  If
     109the interface presents a list of user commands or options, such as a
     110menu, a prominent item in the list meets this criterion.
     111
     112  1. Source Code.
     113
     114  The "source code" for a work means the preferred form of the work
     115for making modifications to it.  "Object code" means any non-source
     116form of a work.
     117
     118  A "Standard Interface" means an interface that either is an official
     119standard defined by a recognized standards body, or, in the case of
     120interfaces specified for a particular programming language, one that
     121is widely used among developers working in that language.
     122
     123  The "System Libraries" of an executable work include anything, other
     124than the work as a whole, that (a) is included in the normal form of
     125packaging a Major Component, but which is not part of that Major
     126Component, and (b) serves only to enable use of the work with that
     127Major Component, or to implement a Standard Interface for which an
     128implementation is available to the public in source code form.  A
     129"Major Component", in this context, means a major essential component
     130(kernel, window system, and so on) of the specific operating system
     131(if any) on which the executable work runs, or a compiler used to
     132produce the work, or an object code interpreter used to run it.
     133
     134  The "Corresponding Source" for a work in object code form means all
     135the source code needed to generate, install, and (for an executable
     136work) run the object code and to modify the work, including scripts to
     137control those activities.  However, it does not include the work's
     138System Libraries, or general-purpose tools or generally available free
     139programs which are used unmodified in performing those activities but
     140which are not part of the work.  For example, Corresponding Source
     141includes interface definition files associated with source files for
     142the work, and the source code for shared libraries and dynamically
     143linked subprograms that the work is specifically designed to require,
     144such as by intimate data communication or control flow between those
     145subprograms and other parts of the work.
     146
     147  The Corresponding Source need not include anything that users
     148can regenerate automatically from other parts of the Corresponding
     149Source.
     150
     151  The Corresponding Source for a work in source code form is that
     152same work.
     153
     154  2. Basic Permissions.
     155
     156  All rights granted under this License are granted for the term of
     157copyright on the Program, and are irrevocable provided the stated
     158conditions are met.  This License explicitly affirms your unlimited
     159permission to run the unmodified Program.  The output from running a
     160covered work is covered by this License only if the output, given its
     161content, constitutes a covered work.  This License acknowledges your
     162rights of fair use or other equivalent, as provided by copyright law.
     163
     164  You may make, run and propagate covered works that you do not
     165convey, without conditions so long as your license otherwise remains
     166in force.  You may convey covered works to others for the sole purpose
     167of having them make modifications exclusively for you, or provide you
     168with facilities for running those works, provided that you comply with
     169the terms of this License in conveying all material for which you do
     170not control copyright.  Those thus making or running the covered works
     171for you must do so exclusively on your behalf, under your direction
     172and control, on terms that prohibit them from making any copies of
     173your copyrighted material outside their relationship with you.
     174
     175  Conveying under any other circumstances is permitted solely under
     176the conditions stated below.  Sublicensing is not allowed; section 10
     177makes it unnecessary.
     178
     179  3. Protecting Users' Legal Rights From Anti-Circumvention Law.
     180
     181  No covered work shall be deemed part of an effective technological
     182measure under any applicable law fulfilling obligations under article
     18311 of the WIPO copyright treaty adopted on 20 December 1996, or
     184similar laws prohibiting or restricting circumvention of such
     185measures.
     186
     187  When you convey a covered work, you waive any legal power to forbid
     188circumvention of technological measures to the extent such circumvention
     189is effected by exercising rights under this License with respect to
     190the covered work, and you disclaim any intention to limit operation or
     191modification of the work as a means of enforcing, against the work's
     192users, your or third parties' legal rights to forbid circumvention of
     193technological measures.
     194
     195  4. Conveying Verbatim Copies.
     196
     197  You may convey verbatim copies of the Program's source code as you
     198receive it, in any medium, provided that you conspicuously and
     199appropriately publish on each copy an appropriate copyright notice;
     200keep intact all notices stating that this License and any
     201non-permissive terms added in accord with section 7 apply to the code;
     202keep intact all notices of the absence of any warranty; and give all
     203recipients a copy of this License along with the Program.
     204
     205  You may charge any price or no price for each copy that you convey,
     206and you may offer support or warranty protection for a fee.
     207
     208  5. Conveying Modified Source Versions.
     209
     210  You may convey a work based on the Program, or the modifications to
     211produce it from the Program, in the form of source code under the
     212terms of section 4, provided that you also meet all of these conditions:
     213
     214    a) The work must carry prominent notices stating that you modified
     215    it, and giving a relevant date.
     216
     217    b) The work must carry prominent notices stating that it is
     218    released under this License and any conditions added under section
     219    7.  This requirement modifies the requirement in section 4 to
     220    "keep intact all notices".
     221
     222    c) You must license the entire work, as a whole, under this
     223    License to anyone who comes into possession of a copy.  This
     224    License will therefore apply, along with any applicable section 7
     225    additional terms, to the whole of the work, and all its parts,
     226    regardless of how they are packaged.  This License gives no
     227    permission to license the work in any other way, but it does not
     228    invalidate such permission if you have separately received it.
     229
     230    d) If the work has interactive user interfaces, each must display
     231    Appropriate Legal Notices; however, if the Program has interactive
     232    interfaces that do not display Appropriate Legal Notices, your
     233    work need not make them do so.
     234
     235  A compilation of a covered work with other separate and independent
     236works, which are not by their nature extensions of the covered work,
     237and which are not combined with it such as to form a larger program,
     238in or on a volume of a storage or distribution medium, is called an
     239"aggregate" if the compilation and its resulting copyright are not
     240used to limit the access or legal rights of the compilation's users
     241beyond what the individual works permit.  Inclusion of a covered work
     242in an aggregate does not cause this License to apply to the other
     243parts of the aggregate.
     244
     245  6. Conveying Non-Source Forms.
     246
     247  You may convey a covered work in object code form under the terms
     248of sections 4 and 5, provided that you also convey the
     249machine-readable Corresponding Source under the terms of this License,
     250in one of these ways:
     251
     252    a) Convey the object code in, or embodied in, a physical product
     253    (including a physical distribution medium), accompanied by the
     254    Corresponding Source fixed on a durable physical medium
     255    customarily used for software interchange.
     256
     257    b) Convey the object code in, or embodied in, a physical product
     258    (including a physical distribution medium), accompanied by a
     259    written offer, valid for at least three years and valid for as
     260    long as you offer spare parts or customer support for that product
     261    model, to give anyone who possesses the object code either (1) a
     262    copy of the Corresponding Source for all the software in the
     263    product that is covered by this License, on a durable physical
     264    medium customarily used for software interchange, for a price no
     265    more than your reasonable cost of physically performing this
     266    conveying of source, or (2) access to copy the
     267    Corresponding Source from a network server at no charge.
     268
     269    c) Convey individual copies of the object code with a copy of the
     270    written offer to provide the Corresponding Source.  This
     271    alternative is allowed only occasionally and noncommercially, and
     272    only if you received the object code with such an offer, in accord
     273    with subsection 6b.
     274
     275    d) Convey the object code by offering access from a designated
     276    place (gratis or for a charge), and offer equivalent access to the
     277    Corresponding Source in the same way through the same place at no
     278    further charge.  You need not require recipients to copy the
     279    Corresponding Source along with the object code.  If the place to
     280    copy the object code is a network server, the Corresponding Source
     281    may be on a different server (operated by you or a third party)
     282    that supports equivalent copying facilities, provided you maintain
     283    clear directions next to the object code saying where to find the
     284    Corresponding Source.  Regardless of what server hosts the
     285    Corresponding Source, you remain obligated to ensure that it is
     286    available for as long as needed to satisfy these requirements.
     287
     288    e) Convey the object code using peer-to-peer transmission, provided
     289    you inform other peers where the object code and Corresponding
     290    Source of the work are being offered to the general public at no
     291    charge under subsection 6d.
     292
     293  A separable portion of the object code, whose source code is excluded
     294from the Corresponding Source as a System Library, need not be
     295included in conveying the object code work.
     296
     297  A "User Product" is either (1) a "consumer product", which means any
     298tangible personal property which is normally used for personal, family,
     299or household purposes, or (2) anything designed or sold for incorporation
     300into a dwelling.  In determining whether a product is a consumer product,
     301doubtful cases shall be resolved in favor of coverage.  For a particular
     302product received by a particular user, "normally used" refers to a
     303typical or common use of that class of product, regardless of the status
     304of the particular user or of the way in which the particular user
     305actually uses, or expects or is expected to use, the product.  A product
     306is a consumer product regardless of whether the product has substantial
     307commercial, industrial or non-consumer uses, unless such uses represent
     308the only significant mode of use of the product.
     309
     310  "Installation Information" for a User Product means any methods,
     311procedures, authorization keys, or other information required to install
     312and execute modified versions of a covered work in that User Product from
     313a modified version of its Corresponding Source.  The information must
     314suffice to ensure that the continued functioning of the modified object
     315code is in no case prevented or interfered with solely because
     316modification has been made.
     317
     318  If you convey an object code work under this section in, or with, or
     319specifically for use in, a User Product, and the conveying occurs as
     320part of a transaction in which the right of possession and use of the
     321User Product is transferred to the recipient in perpetuity or for a
     322fixed term (regardless of how the transaction is characterized), the
     323Corresponding Source conveyed under this section must be accompanied
     324by the Installation Information.  But this requirement does not apply
     325if neither you nor any third party retains the ability to install
     326modified object code on the User Product (for example, the work has
     327been installed in ROM).
     328
     329  The requirement to provide Installation Information does not include a
     330requirement to continue to provide support service, warranty, or updates
     331for a work that has been modified or installed by the recipient, or for
     332the User Product in which it has been modified or installed.  Access to a
     333network may be denied when the modification itself materially and
     334adversely affects the operation of the network or violates the rules and
     335protocols for communication across the network.
     336
     337  Corresponding Source conveyed, and Installation Information provided,
     338in accord with this section must be in a format that is publicly
     339documented (and with an implementation available to the public in
     340source code form), and must require no special password or key for
     341unpacking, reading or copying.
     342
     343  7. Additional Terms.
     344
     345  "Additional permissions" are terms that supplement the terms of this
     346License by making exceptions from one or more of its conditions.
     347Additional permissions that are applicable to the entire Program shall
     348be treated as though they were included in this License, to the extent
     349that they are valid under applicable law.  If additional permissions
     350apply only to part of the Program, that part may be used separately
     351under those permissions, but the entire Program remains governed by
     352this License without regard to the additional permissions.
     353
     354  When you convey a copy of a covered work, you may at your option
     355remove any additional permissions from that copy, or from any part of
     356it.  (Additional permissions may be written to require their own
     357removal in certain cases when you modify the work.)  You may place
     358additional permissions on material, added by you to a covered work,
     359for which you have or can give appropriate copyright permission.
     360
     361  Notwithstanding any other provision of this License, for material you
     362add to a covered work, you may (if authorized by the copyright holders of
     363that material) supplement the terms of this License with terms:
     364
     365    a) Disclaiming warranty or limiting liability differently from the
     366    terms of sections 15 and 16 of this License; or
     367
     368    b) Requiring preservation of specified reasonable legal notices or
     369    author attributions in that material or in the Appropriate Legal
     370    Notices displayed by works containing it; or
     371
     372    c) Prohibiting misrepresentation of the origin of that material, or
     373    requiring that modified versions of such material be marked in
     374    reasonable ways as different from the original version; or
     375
     376    d) Limiting the use for publicity purposes of names of licensors or
     377    authors of the material; or
     378
     379    e) Declining to grant rights under trademark law for use of some
     380    trade names, trademarks, or service marks; or
     381
     382    f) Requiring indemnification of licensors and authors of that
     383    material by anyone who conveys the material (or modified versions of
     384    it) with contractual assumptions of liability to the recipient, for
     385    any liability that these contractual assumptions directly impose on
     386    those licensors and authors.
     387
     388  All other non-permissive additional terms are considered "further
     389restrictions" within the meaning of section 10.  If the Program as you
     390received it, or any part of it, contains a notice stating that it is
     391governed by this License along with a term that is a further
     392restriction, you may remove that term.  If a license document contains
     393a further restriction but permits relicensing or conveying under this
     394License, you may add to a covered work material governed by the terms
     395of that license document, provided that the further restriction does
     396not survive such relicensing or conveying.
     397
     398  If you add terms to a covered work in accord with this section, you
     399must place, in the relevant source files, a statement of the
     400additional terms that apply to those files, or a notice indicating
     401where to find the applicable terms.
     402
     403  Additional terms, permissive or non-permissive, may be stated in the
     404form of a separately written license, or stated as exceptions;
     405the above requirements apply either way.
     406
     407  8. Termination.
     408
     409  You may not propagate or modify a covered work except as expressly
     410provided under this License.  Any attempt otherwise to propagate or
     411modify it is void, and will automatically terminate your rights under
     412this License (including any patent licenses granted under the third
     413paragraph of section 11).
     414
     415  However, if you cease all violation of this License, then your
     416license from a particular copyright holder is reinstated (a)
     417provisionally, unless and until the copyright holder explicitly and
     418finally terminates your license, and (b) permanently, if the copyright
     419holder fails to notify you of the violation by some reasonable means
     420prior to 60 days after the cessation.
     421
     422  Moreover, your license from a particular copyright holder is
     423reinstated permanently if the copyright holder notifies you of the
     424violation by some reasonable means, this is the first time you have
     425received notice of violation of this License (for any work) from that
     426copyright holder, and you cure the violation prior to 30 days after
     427your receipt of the notice.
     428
     429  Termination of your rights under this section does not terminate the
     430licenses of parties who have received copies or rights from you under
     431this License.  If your rights have been terminated and not permanently
     432reinstated, you do not qualify to receive new licenses for the same
     433material under section 10.
     434
     435  9. Acceptance Not Required for Having Copies.
     436
     437  You are not required to accept this License in order to receive or
     438run a copy of the Program.  Ancillary propagation of a covered work
     439occurring solely as a consequence of using peer-to-peer transmission
     440to receive a copy likewise does not require acceptance.  However,
     441nothing other than this License grants you permission to propagate or
     442modify any covered work.  These actions infringe copyright if you do
     443not accept this License.  Therefore, by modifying or propagating a
     444covered work, you indicate your acceptance of this License to do so.
     445
     446  10. Automatic Licensing of Downstream Recipients.
     447
     448  Each time you convey a covered work, the recipient automatically
     449receives a license from the original licensors, to run, modify and
     450propagate that work, subject to this License.  You are not responsible
     451for enforcing compliance by third parties with this License.
     452
     453  An "entity transaction" is a transaction transferring control of an
     454organization, or substantially all assets of one, or subdividing an
     455organization, or merging organizations.  If propagation of a covered
     456work results from an entity transaction, each party to that
     457transaction who receives a copy of the work also receives whatever
     458licenses to the work the party's predecessor in interest had or could
     459give under the previous paragraph, plus a right to possession of the
     460Corresponding Source of the work from the predecessor in interest, if
     461the predecessor has it or can get it with reasonable efforts.
     462
     463  You may not impose any further restrictions on the exercise of the
     464rights granted or affirmed under this License.  For example, you may
     465not impose a license fee, royalty, or other charge for exercise of
     466rights granted under this License, and you may not initiate litigation
     467(including a cross-claim or counterclaim in a lawsuit) alleging that
     468any patent claim is infringed by making, using, selling, offering for
     469sale, or importing the Program or any portion of it.
     470
     471  11. Patents.
     472
     473  A "contributor" is a copyright holder who authorizes use under this
     474License of the Program or a work on which the Program is based.  The
     475work thus licensed is called the contributor's "contributor version".
     476
     477  A contributor's "essential patent claims" are all patent claims
     478owned or controlled by the contributor, whether already acquired or
     479hereafter acquired, that would be infringed by some manner, permitted
     480by this License, of making, using, or selling its contributor version,
     481but do not include claims that would be infringed only as a
     482consequence of further modification of the contributor version.  For
     483purposes of this definition, "control" includes the right to grant
     484patent sublicenses in a manner consistent with the requirements of
     485this License.
     486
     487  Each contributor grants you a non-exclusive, worldwide, royalty-free
     488patent license under the contributor's essential patent claims, to
     489make, use, sell, offer for sale, import and otherwise run, modify and
     490propagate the contents of its contributor version.
     491
     492  In the following three paragraphs, a "patent license" is any express
     493agreement or commitment, however denominated, not to enforce a patent
     494(such as an express permission to practice a patent or covenant not to
     495sue for patent infringement).  To "grant" such a patent license to a
     496party means to make such an agreement or commitment not to enforce a
     497patent against the party.
     498
     499  If you convey a covered work, knowingly relying on a patent license,
     500and the Corresponding Source of the work is not available for anyone
     501to copy, free of charge and under the terms of this License, through a
     502publicly available network server or other readily accessible means,
     503then you must either (1) cause the Corresponding Source to be so
     504available, or (2) arrange to deprive yourself of the benefit of the
     505patent license for this particular work, or (3) arrange, in a manner
     506consistent with the requirements of this License, to extend the patent
     507license to downstream recipients.  "Knowingly relying" means you have
     508actual knowledge that, but for the patent license, your conveying the
     509covered work in a country, or your recipient's use of the covered work
     510in a country, would infringe one or more identifiable patents in that
     511country that you have reason to believe are valid.
     512
     513  If, pursuant to or in connection with a single transaction or
     514arrangement, you convey, or propagate by procuring conveyance of, a
     515covered work, and grant a patent license to some of the parties
     516receiving the covered work authorizing them to use, propagate, modify
     517or convey a specific copy of the covered work, then the patent license
     518you grant is automatically extended to all recipients of the covered
     519work and works based on it.
     520
     521  A patent license is "discriminatory" if it does not include within
     522the scope of its coverage, prohibits the exercise of, or is
     523conditioned on the non-exercise of one or more of the rights that are
     524specifically granted under this License.  You may not convey a covered
     525work if you are a party to an arrangement with a third party that is
     526in the business of distributing software, under which you make payment
     527to the third party based on the extent of your activity of conveying
     528the work, and under which the third party grants, to any of the
     529parties who would receive the covered work from you, a discriminatory
     530patent license (a) in connection with copies of the covered work
     531conveyed by you (or copies made from those copies), or (b) primarily
     532for and in connection with specific products or compilations that
     533contain the covered work, unless you entered into that arrangement,
     534or that patent license was granted, prior to 28 March 2007.
     535
     536  Nothing in this License shall be construed as excluding or limiting
     537any implied license or other defenses to infringement that may
     538otherwise be available to you under applicable patent law.
     539
     540  12. No Surrender of Others' Freedom.
     541
     542  If conditions are imposed on you (whether by court order, agreement or
     543otherwise) that contradict the conditions of this License, they do not
     544excuse you from the conditions of this License.  If you cannot convey a
     545covered work so as to satisfy simultaneously your obligations under this
     546License and any other pertinent obligations, then as a consequence you may
     547not convey it at all.  For example, if you agree to terms that obligate you
     548to collect a royalty for further conveying from those to whom you convey
     549the Program, the only way you could satisfy both those terms and this
     550License would be to refrain entirely from conveying the Program.
     551
     552  13. Use with the GNU Affero General Public License.
     553
     554  Notwithstanding any other provision of this License, you have
     555permission to link or combine any covered work with a work licensed
     556under version 3 of the GNU Affero General Public License into a single
     557combined work, and to convey the resulting work.  The terms of this
     558License will continue to apply to the part which is the covered work,
     559but the special requirements of the GNU Affero General Public License,
     560section 13, concerning interaction through a network will apply to the
     561combination as such.
     562
     563  14. Revised Versions of this License.
     564
     565  The Free Software Foundation may publish revised and/or new versions of
     566the GNU General Public License from time to time.  Such new versions will
     567be similar in spirit to the present version, but may differ in detail to
     568address new problems or concerns.
     569
     570  Each version is given a distinguishing version number.  If the
     571Program specifies that a certain numbered version of the GNU General
     572Public License "or any later version" applies to it, you have the
     573option of following the terms and conditions either of that numbered
     574version or of any later version published by the Free Software
     575Foundation.  If the Program does not specify a version number of the
     576GNU General Public License, you may choose any version ever published
     577by the Free Software Foundation.
     578
     579  If the Program specifies that a proxy can decide which future
     580versions of the GNU General Public License can be used, that proxy's
     581public statement of acceptance of a version permanently authorizes you
     582to choose that version for the Program.
     583
     584  Later license versions may give you additional or different
     585permissions.  However, no additional obligations are imposed on any
     586author or copyright holder as a result of your choosing to follow a
     587later version.
     588
     589  15. Disclaimer of Warranty.
     590
     591  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
     592APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
     593HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
     594OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
     595THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     596PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
     597IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
     598ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
     599
     600  16. Limitation of Liability.
     601
     602  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
     603WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
     604THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
     605GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
     606USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
     607DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
     608PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
     609EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
     610SUCH DAMAGES.
     611
     612  17. Interpretation of Sections 15 and 16.
     613
     614  If the disclaimer of warranty and limitation of liability provided
     615above cannot be given local legal effect according to their terms,
     616reviewing courts shall apply local law that most closely approximates
     617an absolute waiver of all civil liability in connection with the
     618Program, unless a warranty or assumption of liability accompanies a
     619copy of the Program in return for a fee.
     620
     621                     END OF TERMS AND CONDITIONS
     622
     623            How to Apply These Terms to Your New Programs
     624
     625  If you develop a new program, and you want it to be of the greatest
     626possible use to the public, the best way to achieve this is to make it
     627free software which everyone can redistribute and change under these terms.
     628
     629  To do so, attach the following notices to the program.  It is safest
     630to attach them to the start of each source file to most effectively
     631state the exclusion of warranty; and each file should have at least
     632the "copyright" line and a pointer to where the full notice is found.
     633
     634    <one line to give the program's name and a brief idea of what it does.>
     635    Copyright (C) <year>  <name of author>
     636
     637    This program is free software: you can redistribute it and/or modify
     638    it under the terms of the GNU General Public License as published by
     639    the Free Software Foundation, either version 3 of the License, or
     640    (at your option) any later version.
     641
     642    This program is distributed in the hope that it will be useful,
     643    but WITHOUT ANY WARRANTY; without even the implied warranty of
     644    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     645    GNU General Public License for more details.
     646
     647    You should have received a copy of the GNU General Public License
     648    along with this program.  If not, see <http://www.gnu.org/licenses/>.
     649
     650Also add information on how to contact you by electronic and paper mail.
     651
     652  If the program does terminal interaction, make it output a short
     653notice like this when it starts in an interactive mode:
     654
     655    <program>  Copyright (C) <year>  <name of author>
     656    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
     657    This is free software, and you are welcome to redistribute it
     658    under certain conditions; type `show c' for details.
     659
     660The hypothetical commands `show w' and `show c' should show the appropriate
     661parts of the General Public License.  Of course, your program's commands
     662might be different; for a GUI interface, you would use an "about box".
     663
     664  You should also get your employer (if you work as a programmer) or school,
     665if any, to sign a "copyright disclaimer" for the program, if necessary.
     666For more information on this, and how to apply and follow the GNU GPL, see
     667<http://www.gnu.org/licenses/>.
     668
     669  The GNU General Public License does not permit incorporating your program
     670into proprietary programs.  If your program is a subroutine library, you
     671may consider it more useful to permit linking proprietary applications with
     672the library.  If this is what you want to do, use the GNU Lesser General
     673Public License instead of this License.  But first, please read
     674<http://www.gnu.org/philosophy/why-not-lgpl.html>.
  • plugins/opendata/modules/at.gv.data/src/org/openstreetmap/josm/plugins/opendata/modules/at/gv/data/DataGvAtConstants.java

     
     1package org.openstreetmap.josm.plugins.opendata.modules.at.gv.data;
     2
     3import org.openstreetmap.josm.plugins.opendata.core.datasets.at.AustrianConstants;
     4
     5public interface DataGvAtConstants extends AustrianConstants {
     6    public static final String DATAGVAT_URL = "https://data.gv.at/";
     7    public static final String DATAGVAT_CKAN_URL = "https://www.data.gv.at/katalog/";
     8
     9    public static final String SOURCE_DATAGVAT = "data.gv.at";
     10}
  • plugins/opendata/modules/at.gv.data/src/org/openstreetmap/josm/plugins/opendata/modules/at/gv/data/DataGvAtModule.java

     
     1package org.openstreetmap.josm.plugins.opendata.modules.at.gv.data;
     2
     3import java.util.Arrays;
     4import java.util.List;
     5
     6import javax.swing.JMenu;
     7import javax.swing.JMenuItem;
     8import javax.swing.JSeparator;
     9
     10import org.openstreetmap.josm.plugins.opendata.core.actions.DatasetSearchAction;
     11import org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler;
     12import org.openstreetmap.josm.plugins.opendata.core.modules.AbstractModule;
     13import org.openstreetmap.josm.plugins.opendata.core.modules.ModuleInformation;
     14import org.openstreetmap.josm.plugins.opendata.core.platforms.CkanDataPlatform;
     15import org.openstreetmap.josm.plugins.opendata.modules.at.gv.data.datasets.handlers.CastlesPalacesStyriaHandler;
     16import org.openstreetmap.josm.plugins.opendata.modules.at.gv.data.datasets.handlers.DefibrillatorsViennaHandler;
     17import org.openstreetmap.josm.plugins.opendata.modules.at.gv.data.datasets.handlers.DrinkingFountainsViennaHandler;
     18import org.openstreetmap.josm.tools.Logging;
     19
     20
     21public class DataGvAtModule extends AbstractModule {
     22
     23    private CkanDataPlatform platform;
     24
     25    public DataGvAtModule(ModuleInformation info) {
     26        super(info);
     27
     28        platform = new CkanDataPlatform(this, DataGvAtConstants.DATAGVAT_CKAN_URL, "data.gv.at");
     29
     30        addHandlerClass(DefibrillatorsViennaHandler.class);
     31        addHandlerClass(DrinkingFountainsViennaHandler.class);
     32        addHandlerClass(CastlesPalacesStyriaHandler.class);
     33    }
     34
     35    @Override
     36    public JMenuItem getModuleMenu() {
     37        Logging.debug("Creating menu for opendata module {0}", getDisplayedName());
     38
     39        JMenuItem baseMenuItem = super.getModuleMenu();
     40        if (baseMenuItem == null) {
     41            baseMenuItem = super.getBaseModuleMenu();
     42        }
     43
     44        if (baseMenuItem instanceof JMenu) {
     45            JMenu baseMenu = (JMenu)baseMenuItem;
     46
     47            baseMenu.add(new JMenuItem(new DatasetSearchAction(platform)), 0);
     48            if (baseMenu.getItemCount() > 1) {
     49                baseMenu.add(new JSeparator(), 1);
     50            }
     51
     52            return baseMenu;
     53        }
     54
     55        return baseMenuItem;
     56    }
     57
     58    @Override
     59    public AbstractDataSetHandler findDataSetHandlerForUrl(String url) {
     60        AbstractDataSetHandler handler = super.findDataSetHandlerForUrl(url);
     61        if (handler != null) {
     62            return handler;
     63        }
     64
     65        handler = platform.findDataSetHandlerForUrl(url);
     66        if (handler != null) {
     67            return handler;
     68        }
     69
     70        return null;
     71    }
     72
     73    @Override
     74    public List<String> getAcceptedPatterns() {
     75        return Arrays.asList(platform.getResourceRegex());
     76    }
     77}
  • plugins/opendata/modules/at.gv.data/src/org/openstreetmap/josm/plugins/opendata/modules/at/gv/data/datasets/DataGvAtDataSetHandler.java

     
     1package org.openstreetmap.josm.plugins.opendata.modules.at.gv.data.datasets;
     2
     3import org.openstreetmap.josm.plugins.opendata.core.datasets.CkanDataSetHandler;
     4import org.openstreetmap.josm.plugins.opendata.modules.at.gv.data.DataGvAtConstants;
     5
     6public abstract class DataGvAtDataSetHandler extends CkanDataSetHandler implements DataGvAtConstants {
     7
     8    public DataGvAtDataSetHandler(String dataset) {
     9        super(DATAGVAT_CKAN_URL, dataset);
     10    }
     11
     12    public DataGvAtDataSetHandler(String dataset, String name) {
     13        super(DATAGVAT_CKAN_URL, dataset, name);
     14    }
     15
     16    @Override
     17    public String getSource() {
     18        return SOURCE_DATAGVAT;
     19    }
     20
     21    @Override
     22    public String getLocalPortalIconName() {
     23        return ICON_AT_24;
     24    }
     25
     26    @Override
     27    public String getNationalPortalIconName() {
     28        return ICON_AT_24;
     29    }
     30}
  • plugins/opendata/modules/at.gv.data/src/org/openstreetmap/josm/plugins/opendata/modules/at/gv/data/datasets/handlers/CastlesPalacesStyriaHandler.java

     
     1package org.openstreetmap.josm.plugins.opendata.modules.at.gv.data.datasets.handlers;
     2
     3import java.util.Arrays;
     4import java.util.List;
     5
     6import org.openstreetmap.josm.data.osm.DataSet;
     7import org.openstreetmap.josm.data.osm.Node;
     8import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
     9import org.openstreetmap.josm.plugins.opendata.modules.at.gv.data.datasets.DataGvAtDataSetHandler;
     10import org.openstreetmap.josm.tools.OsmPrimitiveImageProvider;
     11
     12public class CastlesPalacesStyriaHandler extends DataGvAtDataSetHandler {
     13
     14    private final List<String> ignored_descr = Arrays.asList("Burg", "Schloss", "Schlössl", "Ruine", "Ansitz", "Burgruine", "Schlossruine");
     15
     16    public CastlesPalacesStyriaHandler() {
     17        super("baa510c0-396b-11e2-81c1-0800200c9a66",
     18              "Burgen und Schlösser in der Steiermark");
     19        OsmPrimitiveImageProvider.getResource("historic", "castle", OsmPrimitiveType.NODE)
     20            .ifPresent(i -> setMenuIcon(i.getImageIcon()));
     21    }
     22
     23    @Override
     24    public void updateDataSet(DataSet ds) {
     25        for (Node n : ds.getNodes()) {
     26
     27            String castle_type = n.get("KATEGORIE");
     28            String descr = n.get("Beschr_kur");
     29            String visible = n.get("Sichtbarke");
     30            String name = n.get("OBJEKTNAME");
     31            boolean levelled = descr != null && (descr.contains("abgekommen") || descr.contains("abgegangen"));
     32
     33            n.put("name", name);
     34            if (descr != null && !ignored_descr.contains(descr) && !descr.equals(name)) {
     35                n.put("description", descr);
     36            }
     37
     38            if (visible != null && visible.equals("sichtbar")) {
     39                if (castle_type != null && !castle_type.isEmpty()) {
     40                    switch (castle_type) {
     41                        case "Burg":
     42                            if (!levelled) {
     43                                n.put("historic", "castle");
     44                                n.put("castle_type", "defensive");
     45                            } else {
     46                                n.put("historic", "archaeological_site");
     47                                n.put("site_type", "fortification");
     48                            }
     49                            break;
     50                        case "Schloss":
     51                            if (!levelled) {
     52                                n.put("historic", "castle");
     53                                n.put("castle_type", "stately");
     54                            }
     55                            break;
     56                        case "Ruine":
     57                            n.put("historic", "ruins");
     58                            if (descr != null && descr.contains("Burgruine")) {
     59                                n.put("ruins", "castle");
     60                            }
     61                            break;
     62                        case "Burgstall":
     63                        case "Befestigungsanlage":
     64                            n.put("historic", "archaeological_site");
     65                            n.put("site_type", "fortification");
     66                            break;
     67                        case "Ansitz":
     68                            if (!levelled) {
     69                                n.put("historic", "castle");
     70                                n.put("castle_type", "manor");
     71                            }
     72                            break;
     73                    }
     74                }
     75            }
     76        }
     77    }
     78}
  • plugins/opendata/modules/at.gv.data/src/org/openstreetmap/josm/plugins/opendata/modules/at/gv/data/datasets/handlers/DefibrillatorsViennaHandler.java

     
     1package org.openstreetmap.josm.plugins.opendata.modules.at.gv.data.datasets.handlers;
     2
     3import java.util.Arrays;
     4import java.util.List;
     5import java.util.stream.Collectors;
     6
     7import org.openstreetmap.josm.command.DeleteCommand;
     8import org.openstreetmap.josm.data.osm.DataSet;
     9import org.openstreetmap.josm.data.osm.Node;
     10import org.openstreetmap.josm.data.osm.OsmPrimitive;
     11import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
     12import org.openstreetmap.josm.plugins.opendata.modules.at.gv.data.datasets.DataGvAtDataSetHandler;
     13import org.openstreetmap.josm.tools.OsmPrimitiveImageProvider;
     14
     15public class DefibrillatorsViennaHandler extends DataGvAtDataSetHandler {
     16    private final List<String> ignored_loc_hints = Arrays.asList(
     17        "Anbringung ist zu erheben",
     18        "Anbringung ist zu validieren",
     19        "folgt zu einem späteren Zeitpunkt",
     20        "noch zu verifizieren",
     21        "zu verifizieren",
     22        "xx",
     23        "nn",
     24        "-");
     25
     26    public DefibrillatorsViennaHandler() {
     27        super("96196887-5a20-4e93-a302-72f306f32c9d",
     28              "Defibrillatoren Wien");
     29        OsmPrimitiveImageProvider.getResource("emergency", "defibrillator", OsmPrimitiveType.NODE)
     30            .ifPresent(i -> setMenuIcon(i.getImageIcon()));
     31    }
     32
     33    @Override
     34    public void updateDataSet(DataSet ds) {
     35        List<OsmPrimitive> testEntries = ds.allPrimitives().stream()
     36            .filter(p -> p.hasTag("INFO") && p.get("INFO").contains("Testeintrag"))
     37            .collect(Collectors.toList());
     38        DeleteCommand.delete(testEntries, true, true);
     39
     40        for (Node n : ds.getNodes()) {
     41            String location_hint = n.get("INFO");
     42            String time_hint = n.get("HINWEIS");
     43
     44            n.put("emergency", "defibrillator");
     45            replace(n, "OBJECTID", "ref:at:ogd");
     46
     47            if (location_hint != null && !location_hint.isEmpty() &&
     48                !ignored_loc_hints.contains(location_hint)) {
     49                replace(n, "INFO", "defibrillator:location");
     50            }
     51
     52            if (time_hint != null && !time_hint.isEmpty()) {
     53                String opening_hours_time = "";
     54                String opening_hours_comment = time_hint;
     55                if (time_hint.startsWith("immer")) {
     56                    opening_hours_time = "24/7";
     57                    opening_hours_comment = time_hint.replaceFirst("immer(?:<br>)?", "");
     58                }
     59
     60                StringBuilder oh_v = new StringBuilder();
     61                oh_v.append(opening_hours_time);
     62                if (!opening_hours_comment.isEmpty()) {
     63                    if (!oh_v.toString().isEmpty()) {
     64                        oh_v.append(" ");
     65                    }
     66                    oh_v.append("\"")
     67                        .append(opening_hours_comment.replace("\"", ""))
     68                        .append("\"");
     69                }
     70                n.put("opening_hours", oh_v.toString());
     71            }
     72        }
     73    }
     74}
  • plugins/opendata/modules/at.gv.data/src/org/openstreetmap/josm/plugins/opendata/modules/at/gv/data/datasets/handlers/DrinkingFountainsViennaHandler.java

     
     1package org.openstreetmap.josm.plugins.opendata.modules.at.gv.data.datasets.handlers;
     2
     3import java.util.Arrays;
     4import java.util.List;
     5
     6import org.openstreetmap.josm.data.osm.DataSet;
     7import org.openstreetmap.josm.data.osm.Node;
     8import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
     9import org.openstreetmap.josm.plugins.opendata.modules.at.gv.data.datasets.DataGvAtDataSetHandler;
     10import org.openstreetmap.josm.tools.OsmPrimitiveImageProvider;
     11
     12public class DrinkingFountainsViennaHandler extends DataGvAtDataSetHandler {
     13
     14    private final List<String> drinking_water_types = Arrays.asList(
     15        "Trinkbrunnen", "Trinkhydrant", "Trinkbrunnen mit Tränke", "Auslaufbrunnen");
     16
     17    private final List<String> for_dogs = Arrays.asList(
     18        "Hundetrinkbrunnen", "Trinkbrunnen mit Tränke");
     19
     20    private final List<String> fountains = Arrays.asList(
     21        "Zierbrunnen", "Bodenfontäne");
     22
     23    public DrinkingFountainsViennaHandler() {
     24        super("2ed52078-7e55-40ea-8036-0d89118a06f4",
     25              "Trink-/Brunnen Wien");
     26        OsmPrimitiveImageProvider.getResource("amenity", "drinking_water", OsmPrimitiveType.NODE)
     27            .ifPresent(i -> setMenuIcon(i.getImageIcon()));
     28    }
     29
     30    @Override
     31    public void updateDataSet(DataSet ds) {
     32        for (Node n : ds.getNodes()) {
     33            String fountain_type = n.get("BASIS_TYP_");
     34
     35            replace(n, "OBJECTID", "ref:at:ogd");
     36
     37            if (drinking_water_types.contains(fountain_type)) {
     38                n.put("amenity", "drinking_water");
     39                if (for_dogs.contains(fountain_type)) {
     40                    n.put("dog", "yes");
     41                }
     42            }
     43
     44            if (fountains.contains(fountain_type)) {
     45                n.put("amenity", "fountain");
     46            }
     47
     48            if ("Bodenfontäne".equals(fountain_type)) {
     49                n.put("fountain", "splash_pad");
     50            }
     51
     52            if ("Spielbrunnen".equals(fountain_type)) {
     53                n.put("playground", "water");
     54            }
     55        }
     56    }
     57}
  • plugins/opendata/modules/build.xml

     
    66            <ant antfile="build.xml" target="@{target}" dir="fr.datagouvfr"/>
    77            <ant antfile="build.xml" target="@{target}" dir="fr.paris"/>
    88            <ant antfile="build.xml" target="@{target}" dir="fr.toulouse"/>
     9            <ant antfile="build.xml" target="@{target}" dir="at.gv.data"/>
    910        </sequential>
    1011    </macrodef>
    1112    <target name="dist">
  • plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/OdPlugin.java

     
    33
    44import java.awt.Image;
    55import java.io.File;
    6 import java.net.URL;
    76import java.util.Arrays;
    8 import java.util.HashMap;
    97import java.util.List;
    10 import java.util.Map;
     8import java.util.stream.Collectors;
    119
    1210import javax.swing.ImageIcon;
    1311import javax.swing.JMenu;
     
    1816import org.openstreetmap.josm.gui.MainFrame;
    1917import org.openstreetmap.josm.gui.MainMenu;
    2018import org.openstreetmap.josm.gui.MapFrame;
    21 import org.openstreetmap.josm.gui.MenuScroller;
    2219import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
    2320import org.openstreetmap.josm.gui.util.GuiHelper;
    2421import org.openstreetmap.josm.io.session.SessionReader;
     
    2522import org.openstreetmap.josm.io.session.SessionWriter;
    2623import org.openstreetmap.josm.plugins.Plugin;
    2724import org.openstreetmap.josm.plugins.PluginInformation;
    28 import org.openstreetmap.josm.plugins.opendata.core.actions.DownloadDataAction;
    2925import org.openstreetmap.josm.plugins.opendata.core.actions.DownloadDataTask;
    3026import org.openstreetmap.josm.plugins.opendata.core.actions.OpenPreferencesActions;
    31 import org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler;
    32 import org.openstreetmap.josm.plugins.opendata.core.datasets.DataSetCategory;
    3327import org.openstreetmap.josm.plugins.opendata.core.gui.OdDialog;
    3428import org.openstreetmap.josm.plugins.opendata.core.gui.OdPreferenceSetting;
    3529import org.openstreetmap.josm.plugins.opendata.core.io.AbstractImporter;
     
    4640import org.openstreetmap.josm.plugins.opendata.core.io.tabular.OdsImporter;
    4741import org.openstreetmap.josm.plugins.opendata.core.io.tabular.XlsImporter;
    4842import org.openstreetmap.josm.plugins.opendata.core.layers.OdDataLayer;
    49 import org.openstreetmap.josm.plugins.opendata.core.modules.Module;
    5043import org.openstreetmap.josm.plugins.opendata.core.modules.ModuleHandler;
    5144import org.openstreetmap.josm.plugins.opendata.core.modules.ModuleInformation;
    5245import org.openstreetmap.josm.plugins.opendata.core.util.OdUtils;
    53 import org.openstreetmap.josm.tools.Pair;
    5446import org.openstreetmap.josm.tools.ResourceProvider;
    5547
    5648/**
     
    10799        return instance;
    108100    }
    109101
    110     private JMenu getModuleMenu(Module module) {
    111         String moduleName = module.getDisplayedName();
    112         if (moduleName == null || moduleName.isEmpty()) {
    113             moduleName = module.getModuleInformation().getName();
    114         }
    115         JMenu moduleMenu = new JMenu(moduleName);
    116         moduleMenu.setIcon(module.getModuleInformation().getScaledIcon());
    117         return moduleMenu;
    118     }
     102    private void buildMenu() {
     103        List<JMenuItem> moduleMenus =  ModuleHandler.moduleList.stream()
     104            .map(m -> m.getModuleMenu()).filter(mm -> mm != null)
     105            .collect(Collectors.toList());
    119106
    120     private void buildMenu() {
    121         for (Module module : ModuleHandler.moduleList) {
    122             Map<DataSetCategory, JMenu> catMenus = new HashMap<>();
    123             JMenu moduleMenu = null;
    124             for (AbstractDataSetHandler handler: module.getNewlyInstanciatedHandlers()) {
    125                 URL dataURL = handler.getDataURL();
    126                 List<Pair<String, URL>> dataURLs = handler.getDataURLs();
    127                 if (dataURL != null || (dataURLs != null && !dataURLs.isEmpty())) {
    128                     if (moduleMenu == null) {
    129                         moduleMenu = getModuleMenu(module);
    130                     }
    131                     DataSetCategory cat = handler.getCategory();
    132                     JMenu endMenu = null;
    133                     if (cat != null) {
    134                         if ((endMenu = catMenus.get(cat)) == null) {
    135                             catMenus.put(cat, endMenu = new JMenu(cat.getName()));
    136                             setMenuItemIcon(cat.getIcon(), endMenu);
    137                             moduleMenu.add(endMenu);
    138                         }
    139                     }
    140                     if (endMenu == null) {
    141                         endMenu = moduleMenu;
    142                     }
    143                     String handlerName = handler.getName();
    144                     if (handlerName == null || handlerName.isEmpty()) {
    145                         handlerName = handler.getClass().getName();
    146                     }
    147                     JMenuItem handlerItem = null;
    148                     if (dataURL != null) {
    149                         handlerItem = endMenu.add(new DownloadDataAction(module, handlerName, dataURL));
    150                     } else if (dataURLs != null) {
    151                         JMenu handlerMenu = new JMenu(handlerName);
    152                         JMenuItem item = null;
    153                         for (Pair<String, URL> pair : dataURLs) {
    154                             if (pair != null && pair.a != null && pair.b != null) {
    155                                 item = handlerMenu.add(new DownloadDataAction(module, pair.a, pair.b));
    156                             }
    157                         }
    158                         if (item != null) {
    159                             MenuScroller.setScrollerFor(handlerMenu);
    160                             handlerItem = endMenu.add(handlerMenu);
    161                         }
    162                     }
    163                     if (handlerItem != null) {
    164                         setMenuItemIcon(handler.getMenuIcon(), handlerItem);
    165                     }
    166                 }
    167             }
    168             if (moduleMenu != null) {
    169                 menu.add(moduleMenu);
    170             }
     107        if (!moduleMenus.isEmpty()) {
     108            menu.addSeparator();
     109            moduleMenus.forEach(mm -> menu.add(mm));
    171110        }
    172111        menu.addSeparator();
    173112        MainMenu.add(menu, new OpenPreferencesActions());
    174113    }
    175114
    176     private void setMenuItemIcon(ImageIcon icon, JMenuItem menuItem) {
     115    public static void setMenuItemIcon(ImageIcon icon, JMenuItem menuItem) {
    177116        if (icon != null) {
    178117            if (icon.getIconHeight() != 16 || icon.getIconWidth() != 16) {
    179118                icon = new ImageIcon(icon.getImage().getScaledInstance(16, 16, Image.SCALE_DEFAULT));
  • plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/actions/DatasetSearchAction.java

     
     1package org.openstreetmap.josm.plugins.opendata.core.actions;
     2
     3import static org.openstreetmap.josm.tools.I18n.tr;
     4
     5import java.awt.event.ActionEvent;
     6import java.awt.event.KeyEvent;
     7
     8import org.openstreetmap.josm.actions.JosmAction;
     9import org.openstreetmap.josm.plugins.opendata.core.gui.DatasetSearchDialog;
     10import org.openstreetmap.josm.plugins.opendata.core.platforms.AbstractDataPlatform;
     11import org.openstreetmap.josm.tools.Shortcut;
     12
     13public class DatasetSearchAction extends JosmAction {
     14
     15    private AbstractDataPlatform platform;
     16
     17    public DatasetSearchAction(AbstractDataPlatform platform) {
     18        super(tr("Search datasets on {0}", platform.getName()), "dialogs/search", tr("Search for available datasets on {0}", platform.getName()),
     19            Shortcut.registerShortcut("opendata:searchDataset_" + platform.getName(), tr("Search for available datasets on {0}", platform.getName()), KeyEvent.CHAR_UNDEFINED, Shortcut.NONE),
     20            true, false);
     21        this.platform = platform;
     22    }
     23
     24    @Override
     25    public void actionPerformed(ActionEvent arg0) {
     26        final DatasetSearchDialog dlg = new DatasetSearchDialog(platform);
     27        dlg.showDialog();
     28    }
     29}
  • plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/actions/DownloadDataAction.java

     
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.plugins.opendata.core.actions;
    33
     4import static org.openstreetmap.josm.tools.I18n.tr;
     5
    46import java.awt.event.ActionEvent;
    57import java.net.URL;
    68
     
    1012import org.openstreetmap.josm.gui.MainApplication;
    1113import org.openstreetmap.josm.plugins.opendata.core.modules.Module;
    1214import org.openstreetmap.josm.tools.CheckParameterUtil;
     15import org.openstreetmap.josm.tools.Logging;
    1316
    1417public class DownloadDataAction extends JosmAction {
    1518
    1619    private final URL url;
    1720
     21    public DownloadDataAction(String name, URL url) {
     22        this(null, name, url);
     23    }
     24
    1825    public DownloadDataAction(Module module, String name, URL url) {
    19         super(false);
     26        super(name, "download", tr("Download data"), null, false,
     27            module != null ? ("opendata_download_"+module.getDisplayedName()+"_"+name).toLowerCase().replace(" ", "_") : null, false);
    2028        CheckParameterUtil.ensureParameterNotNull(name, "name");
    2129        CheckParameterUtil.ensureParameterNotNull(url, "url");
    22         putValue(Action.NAME, name);
    23         putValue("toolbar", ("opendata_download_"+module.getDisplayedName()+"_"+name).toLowerCase().replace(" ", "_"));
    2430        this.url = url;
    2531    }
    2632
    2733    @Override
    2834    public void actionPerformed(ActionEvent e) {
     35        download(url);
     36    }
     37
     38    public static void download(URL url) {
     39        Logging.debug("Downloading opendata dataset {0}", url.toString());
    2940        MainApplication.getMenu().openLocation.openUrl(true, url.toString());
    3041    }
    3142}
  • plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/actions/DownloadDataTask.java

     
    55
    66import java.io.File;
    77import java.io.IOException;
     8import java.util.ArrayList;
     9import java.util.List;
    810import java.util.Optional;
     11import java.util.concurrent.CancellationException;
     12import java.util.concurrent.CompletableFuture;
    913import java.util.concurrent.Future;
     14import java.util.concurrent.FutureTask;
    1015import java.util.regex.Pattern;
    1116
    1217import javax.swing.JOptionPane;
     
    1722import org.openstreetmap.josm.gui.MainApplication;
    1823import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1924import org.openstreetmap.josm.gui.progress.ProgressMonitor;
     25import org.openstreetmap.josm.io.OsmTransferCanceledException;
     26import org.openstreetmap.josm.io.OsmTransferException;
    2027import org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler;
    2128import org.openstreetmap.josm.plugins.opendata.core.datasets.DataSetUpdater;
    2229import org.openstreetmap.josm.plugins.opendata.core.gui.AskLicenseAgreementDialog;
    2330import org.openstreetmap.josm.plugins.opendata.core.io.NetworkReader;
     31import org.openstreetmap.josm.plugins.opendata.core.io.UnsupportedDataException;
    2432import org.openstreetmap.josm.plugins.opendata.core.layers.OdDataLayer;
    2533import org.openstreetmap.josm.plugins.opendata.core.licenses.License;
    2634import org.openstreetmap.josm.plugins.opendata.core.modules.Module;
    2735import org.openstreetmap.josm.plugins.opendata.core.modules.ModuleHandler;
     36import org.openstreetmap.josm.tools.Logging;
    2837
    2938public class DownloadDataTask extends DownloadOsmTask {
    3039
     
    3241
    3342    @Override
    3443    public Future<?> loadUrl(DownloadParams settings, String url, ProgressMonitor progressMonitor) {
     44        url = modifyUrlBeforeLoad(url);
     45        if (url == null) {
     46            CompletableFuture<?> f = CompletableFuture.completedFuture(null);
     47            f.completeExceptionally(new CancellationException("Download not supported by dataset handler"));
     48            return f;
     49        }
    3550        downloadTask = new InternalDownloadTask(settings, new NetworkReader(url, handler, true), progressMonitor, zoomAfterDownload);
    3651        currentBounds = null;
    3752        if (handler == null || !handler.hasLicenseToBeAccepted() || askLicenseAgreement(handler.getLicense())) {
    3853            return MainApplication.worker.submit(downloadTask);
    3954        } else {
    40             return null;
     55            CompletableFuture<?> f = CompletableFuture.completedFuture(null);
     56            f.completeExceptionally(new CancellationException("License not accepted"));
     57            return f;
    4158        }
    4259    }
    4360
    4461    @Override
    45     public boolean acceptsUrl(String url) {
    46         this.handler = null;
     62    protected String modifyUrlBeforeLoad(String url) {
     63        if (handler != null) {
     64            return handler.modifyUrlBeforeLoad(url);
     65        } else {
     66            return url;
     67        }
     68    }
     69
     70    public AbstractDataSetHandler findDataSetHandlerForUrl(String url) {
    4771        for (Module module : ModuleHandler.moduleList) {
    48             for (AbstractDataSetHandler handler : module.getNewlyInstanciatedHandlers()) {
    49                 if (handler.acceptsUrl(url)) {
    50                     this.handler = handler;
    51                     return true;
    52                 }
     72            AbstractDataSetHandler handler = module.findDataSetHandlerForUrl(url);
     73            if (handler != null) {
     74                return handler;
    5375            }
    5476        }
     77
     78        return null;
     79    }
     80
     81    @Override
     82    public boolean acceptsUrl(String url) {
     83        this.handler = findDataSetHandlerForUrl(url);
     84        if (handler != null) {
     85            return true;
     86        }
     87
    5588        for (String ext : NetworkReader.FILE_AND_ARCHIVE_READERS.keySet()) {
    5689            if (Pattern.compile(".*\\."+ext, Pattern.CASE_INSENSITIVE).matcher(url).matches()) {
    5790                return true;
     
    6295
    6396    @Override
    6497    public String[] getPatterns() {
    65         StringBuilder pattern = new StringBuilder();
     98        List<String> acceptedPatterns = new ArrayList<>();
     99        StringBuilder fileExtPattern = new StringBuilder();
    66100        for (String ext : NetworkReader.FILE_AND_ARCHIVE_READERS.keySet()) {
    67             if (pattern.length() > 0) {
    68                 pattern.append('|');
     101            if (fileExtPattern.length() > 0) {
     102                fileExtPattern.append('|');
    69103            }
    70             pattern.append('.').append(ext);
     104            fileExtPattern.append('.').append(ext);
    71105        }
    72         return new String[]{".*(" + pattern + ")"};
     106        acceptedPatterns.add(".*(" + fileExtPattern + ")");
     107
     108        for (Module module : ModuleHandler.moduleList) {
     109            List<String> modulePatterns = module.getAcceptedPatterns();
     110            acceptedPatterns.addAll(modulePatterns);
     111        }
     112
     113        return acceptedPatterns.stream().toArray(String[]::new);
    73114    }
    74115
    75116    @Override
     
    77118        return tr("Download open data");
    78119    }
    79120
     121    /**
     122     * returns true if the user accepts the license, false if they refuse
     123     */
     124    protected final boolean askLicenseAgreement(License license) {
     125        if (license == null || (license.getURL() == null && license.getSummaryURL() == null)) {
     126            return true;
     127        }
     128        try {
     129            return new AskLicenseAgreementDialog(license).showDialog().getValue() == 1;
     130        } catch (IOException e) {
     131            JOptionPane.showMessageDialog(MainApplication.getMainFrame(), tr("License URL not available: {0}", license.toString()));
     132            return false;
     133        }
     134    }
     135
    80136    protected class InternalDownloadTask extends DownloadTask {
    81137
    82138        public InternalDownloadTask(DownloadParams settings, NetworkReader reader, ProgressMonitor progressMonitor, boolean zoomAfterDownload) {
     
    100156            DataSetUpdater.updateDataSet(dataSet, handler, associatedFile);
    101157            return new OdDataLayer(dataSet, layerName, associatedFile, handler);
    102158        }
    103     }
    104159
    105     /**
    106      * returns true if the user accepts the license, false if they refuse
    107      */
    108     protected final boolean askLicenseAgreement(License license) {
    109         if (license == null || (license.getURL() == null && license.getSummaryURL() == null)) {
    110             return true;
     160        @Override
     161        public void realRun() {
     162            try {
     163                if (isCanceled())
     164                    return;
     165                dataSet = parseDataSet();
     166            } catch (OsmTransferException e) {
     167                if (isCanceled()) {
     168                    Logging.info(tr("Ignoring exception because download has been canceled. Exception was: {0}", e.toString()));
     169                    return;
     170                }
     171                if (e instanceof OsmTransferCanceledException) {
     172                    setCanceled(true);
     173                    return;
     174                } else if (e instanceof UnsupportedDataException) {
     175                    // Only show error message instead of full backtrace + bug report window
     176                    rememberErrorMessage(e.getMessage());
     177                } else {
     178                    rememberException(e);
     179                }
     180                DownloadDataTask.this.setFailed(true);
     181            }
    111182        }
    112         try {
    113             return new AskLicenseAgreementDialog(license).showDialog().getValue() == 1;
    114         } catch (IOException e) {
    115             JOptionPane.showMessageDialog(MainApplication.getMainFrame(), tr("License URL not available: {0}", license.toString()));
    116             return false;
    117         }
    118183    }
    119184}
  • plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/datasets/AbstractDataSetHandler.java

     
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.plugins.opendata.core.datasets;
    33
     4import static org.openstreetmap.josm.tools.I18n.tr;
     5
    46import java.io.File;
     7import java.io.UnsupportedEncodingException;
    58import java.net.MalformedURLException;
    69import java.net.URL;
     10import java.net.URLEncoder;
    711import java.util.ArrayList;
    812import java.util.Collection;
     13import java.util.Collections;
    914import java.util.List;
     15import java.util.Objects;
    1016import java.util.regex.Pattern;
     17import java.util.stream.Collectors;
    1118
     19import javax.swing.Action;
    1220import javax.swing.ImageIcon;
     21import javax.swing.JComponent;
     22import javax.swing.JMenu;
     23import javax.swing.JMenuItem;
     24import javax.swing.JSeparator;
    1325
    1426import org.openstreetmap.josm.actions.JosmAction;
    1527import org.openstreetmap.josm.data.Bounds;
     
    1931import org.openstreetmap.josm.data.osm.OsmPrimitive;
    2032import org.openstreetmap.josm.data.preferences.sources.ExtendedSourceEntry;
    2133import org.openstreetmap.josm.data.preferences.sources.SourceType;
     34import org.openstreetmap.josm.gui.MenuScroller;
    2235import org.openstreetmap.josm.io.AbstractReader;
     36import org.openstreetmap.josm.plugins.opendata.core.modules.Module;
     37import org.openstreetmap.josm.plugins.opendata.OdPlugin;
    2338import org.openstreetmap.josm.plugins.opendata.core.OdConstants;
     39import org.openstreetmap.josm.plugins.opendata.core.actions.DownloadDataAction;
     40import org.openstreetmap.josm.plugins.opendata.core.actions.OpenLinkAction;
     41import org.openstreetmap.josm.plugins.opendata.core.actions.ViewLicenseAction;
     42import org.openstreetmap.josm.plugins.opendata.core.gui.ViewLicenseDialog;
    2443import org.openstreetmap.josm.plugins.opendata.core.io.archive.ArchiveHandler;
    2544import org.openstreetmap.josm.plugins.opendata.core.io.archive.DefaultArchiveHandler;
    2645import org.openstreetmap.josm.plugins.opendata.core.io.geographic.DefaultGmlHandler;
     
    3453import org.openstreetmap.josm.plugins.opendata.core.licenses.License;
    3554import org.openstreetmap.josm.plugins.opendata.core.util.NamesFrUtils;
    3655import org.openstreetmap.josm.plugins.opendata.core.util.OdUtils;
     56import org.openstreetmap.josm.tools.Logging;
    3757import org.openstreetmap.josm.tools.Pair;
     58import org.openstreetmap.josm.tools.Utils;
    3859
    3960public abstract class AbstractDataSetHandler {
    4061
     
    7293    }
    7394
    7495    private String name;
     96    private String geoToponym;
     97    private String maintainer;
     98    private String maintainerEmail;
     99    private String description;
    75100    private DataSetCategory category;
    76101    private String sourceDate;
    77102    private File associatedFile;
     
    176201
    177202    // --------------------- URLs ---------------------
    178203
     204    private List<Pair<String, URL>> dataURLs = new ArrayList<>();
    179205    private URL dataURL;
    180206    private URL wikiURL;
    181207    private URL localPortalURL;
     
    185211        return dataURL;
    186212    }
    187213
     214    public List<Pair<String, URL>> getDataURLs() {
     215        return dataURLs;
     216    }
     217
    188218    public final void setDataURL(URL dataURL) {
    189219        this.dataURL = dataURL;
    190220    }
     
    193223        setDataURL(new URL(dataURL));
    194224    }
    195225
     226    public final void addDataURL(String title, URL dataURL) {
     227        dataURLs.add(new Pair<>(title, dataURL));
     228    }
     229
     230    public final void addDataURL(String title, String dataURL) throws MalformedURLException {
     231        addDataURL(title, new URL(dataURL));
     232    }
     233
     234    public String modifyUrlBeforeLoad(String url) {
     235        return url;
     236    }
     237
    196238    public URL getWikiURL() {
    197239        return wikiURL;
    198240    }
     
    229271        setNationalPortalURL(new URL(nationalPortalURL));
    230272    }
    231273
    232     public List<Pair<String, URL>> getDataURLs() {
    233         return null;
    234     }
    235274
    236275    public AbstractReader getReaderForUrl(String url) {
    237276        return null;
     
    238277    }
    239278
    240279    private boolean hasLicenseToBeAccepted = true;
     280    private String dataVersion;
    241281
    242282    public final boolean hasLicenseToBeAccepted() {
    243283        return hasLicenseToBeAccepted;
     
    377417        this.name = name;
    378418    }
    379419
     420    public final String getDescription() {
     421        return description;
     422    }
     423
     424    public final void setDescription(String description) {
     425        this.description = description;
     426    }
     427
     428    public final String getDataVersion() {
     429        return dataVersion;
     430    }
     431
     432    public final void setDataVersion(String dataVersion) {
     433        this.dataVersion = dataVersion;
     434    }
     435
     436    public final void setMaintainer(String maintainer) {
     437        this.maintainer = maintainer;
     438    }
     439
     440    public final String getMaintainer() {
     441        return maintainer;
     442    }
     443
     444    public final void setMaintainerEmail(String maintainerEmail) {
     445        this.maintainerEmail = maintainerEmail;
     446    }
     447
     448    public final String getMaintainerEmail() {
     449        return maintainerEmail;
     450    }
     451
     452    public void setGeographicToponym(String geoToponym) {
     453        this.geoToponym = geoToponym;
     454    }
     455
     456    public String getGeographicToponym() {
     457        return geoToponym;
     458    }
     459
    380460    public String getLocalPortalIconName() {
    381461        return OdConstants.ICON_CORE_24;
    382462    }
     
    534614    public void notifyActive() {
    535615        // To be overriden when the handler has specific treatments to perform when its layer becomes active
    536616    }
     617
     618    // Menu
     619
     620    /**
     621     * Get a list of download actions for the resources handled by this dataset
     622     *
     623     * @return a list of {@link DownloadDataAction} that can be used to download the resources for this dataset
     624     */
     625    public List<JComponent> getDownloadActionMenuItems() {
     626        return getDownloadActionMenuItems(null);
     627    }
     628
     629    /**
     630     * Get a list of download actions for the resources handled by this dataset
     631     * @param module
     632     * @return a list of {@link DownloadDataAction} that can be used to download the resources for this dataset
     633     */
     634    public List<JComponent> getDownloadActionMenuItems(Module module) {
     635        List<JComponent> items = new ArrayList<>();
     636
     637        String handlerName = getName();
     638        if (handlerName == null || handlerName.isEmpty()) {
     639            handlerName = getClass().getName();
     640        }
     641
     642        URL dataURL = getDataURL();
     643        List<Pair<String, URL>> dataURLs = getDataURLs();
     644
     645        if (dataURL != null) {
     646            items.add(new JMenuItem(new DownloadDataAction(module, handlerName, dataURL)));
     647        }
     648        if (dataURLs != null) {
     649            if (items.size() > 0 && dataURLs.size() > 0) {
     650                items.add(new JSeparator());
     651            }
     652            for (Pair<String, URL> pair : dataURLs) {
     653                if (pair != null && pair.a != null && pair.b != null) {
     654                    items.add(new JMenuItem(new DownloadDataAction(module, pair.a, pair.b)));
     655                }
     656            }
     657        }
     658
     659        return items;
     660    }
     661
     662    /**
     663     * Build the menu representing the dataset in the opendata module mennu
     664     *
     665     * @param module
     666     * @return {@link JMenuItem} or {@link JMenu} to be displayed in the opendata module menu
     667     */
     668    public JMenuItem getHandlerMenu(Module module) {
     669        JMenuItem menuItem = null;
     670
     671        String handlerName = getName();
     672        if (handlerName == null || handlerName.isEmpty()) {
     673            handlerName = getClass().getName();
     674        }
     675
     676        URL dataURL = getDataURL();
     677        List<Pair<String, URL>> dataURLs = getDataURLs();
     678
     679        if (dataURL != null) {
     680            menuItem = new JMenuItem(new DownloadDataAction(module, handlerName, dataURL));
     681        } else if (dataURLs != null) {
     682            JMenu handlerMenu = new JMenu(handlerName);
     683            for (Pair<String, URL> pair : dataURLs) {
     684                if (pair != null && pair.a != null && pair.b != null) {
     685                    handlerMenu.add(new DownloadDataAction(module, pair.a, pair.b));
     686                }
     687            }
     688
     689            if (handlerMenu.getItemCount() > 0) {
     690                MenuScroller.setScrollerFor(handlerMenu);
     691                menuItem = handlerMenu;
     692            }
     693        }
     694
     695        if (menuItem != null) {
     696            OdPlugin.setMenuItemIcon(getMenuIcon(), menuItem);
     697        }
     698       
     699        return menuItem;
     700    }
     701
     702    /**
     703     * Get the supported actions for this dataset (e.g. view license, view on open data platform)
     704     *
     705     * @return A list of actions for this dataset
     706     */
     707    public List<Action> getMenuActions() {
     708        List<Action> actions = new ArrayList<>();
     709
     710        if (getWikiURL() != null) {
     711            actions.add(new OpenLinkAction(getWikiURL(), OdConstants.ICON_OSM_24,
     712                    tr("View OSM Wiki page"), tr("Launch browser to the OSM Wiki page of the selected data set")));
     713        }
     714        if (getLocalPortalURL() != null) {
     715            actions.add(new OpenLinkAction(getLocalPortalURL(), getLocalPortalIconName(),
     716                    tr("View Local Portal page"), tr("Launch browser to the local portal page of the selected data set")));
     717        }
     718        if (getNationalPortalURL() != null) {
     719            actions.add(new OpenLinkAction(getNationalPortalURL(), getNationalPortalIconName(),
     720                    tr("View National Portal page"), tr("Launch browser to the national portal page of the selected data set")));
     721        }
     722        if (getLicense() != null) {
     723            License lic = getLicense();
     724            if (lic.getURL() != null && lic.getURL().getProtocol().startsWith("http")) {
     725                actions.add(new OpenLinkAction(lic.getURL(), OdConstants.ICON_AGREEMENT_24,
     726                        tr("View License"), tr("Launch browser to the license page of the selected data set")));
     727            }
     728            if (lic.getSummaryURL() != null && lic.getSummaryURL().getProtocol().startsWith("http")) {
     729                actions.add(new OpenLinkAction(lic.getSummaryURL(), OdConstants.ICON_AGREEMENT_24,
     730                        tr("View License (summary)"), tr("Launch browser to the summary license page of the selected data set")));
     731            }
     732            if ((lic.getURL() != null && !lic.getURL().getProtocol().startsWith("http")) ||
     733                    (lic.getSummaryURL() != null && !lic.getSummaryURL().getProtocol().startsWith("http"))) {
     734                actions.add(new ViewLicenseAction(lic, tr("View License"), tr("View the license of the selected data set")));
     735            }
     736        }
     737
     738        return actions;
     739    }
     740
     741    /**
     742     * Get a list of {@link JMenuItem}that should be displayed in the popup menu for this dataset
     743     * (e.g. in the dataset search list)
     744     *
     745     * @return A list of menu items/separators/... to be displayed in the popup menu for this dataset
     746     */
     747    public List<JComponent> getPopupMenuItems() {
     748        List<JComponent> items = new ArrayList<>();
     749        items.addAll(getMenuActions().stream().map(a -> new JMenuItem(a)).collect(Collectors.toList()));
     750       
     751        List<JComponent> downloadActionItems = getDownloadActionMenuItems();
     752        if (downloadActionItems.size() > 0 && items.size() > 0) {
     753            items.add(new JSeparator());
     754            items.addAll(downloadActionItems);
     755        }
     756        return items;
     757    }
     758
     759    /**
     760     * Returns the text representing the dataset in a gui component.
     761     * Can be overridden to customize the text
     762     *
     763     * @return text representing the dataset
     764     */
     765    public String getComponentText() {
     766        StringBuilder t = new StringBuilder();
     767        String toponym = getGeographicToponym();
     768
     769        t.append("<html><strong>")
     770            .append(getName())
     771            .append("</strong> <span color='gray'><i>")
     772            // .append(" <span color='gray'><i>")
     773            .append(Objects.toString(toponym, ""))
     774            // .append("</i></span>")
     775            .append("</i></span></html>");
     776
     777        return t.toString();
     778    }
     779
     780    /**
     781     * Returns the text representing an open data dataset in a gui tooltip.
     782     * Can be overridden to customize the text
     783     *
     784     * @return tooltip text for the dataset
     785     */
     786    public String getToolTipText() {
     787        StringBuilder tt = new StringBuilder();
     788        List<Pair<String, String>> infoList = new ArrayList<>();
     789
     790        tt.append("<html><strong>")
     791            .append(Utils.escapeReservedCharactersHTML(getName()))
     792            .append("</strong><br><br>");
     793        String description = getDescription();
     794        if (description != null && !description.isEmpty()) {
     795            tt.append("<p>").append(Utils.escapeReservedCharactersHTML(getDescription()))
     796            .append("</p><br>");
     797        }
     798       
     799        infoList.add(new Pair<>("Maintainer", getMaintainer()));
     800        infoList.add(new Pair<>("Geographic area", getGeographicToponym()));
     801        infoList.add(new Pair<>("Source", getSource()));
     802        infoList.add(new Pair<>("Source date", getSourceDate()));
     803        infoList.add(new Pair<>("Data version", getDataVersion()));
     804        infoList.stream().filter(i -> i.b != null && !i.b.isEmpty())
     805            .forEachOrdered(i -> tt.append(Utils.escapeReservedCharactersHTML(i.a)).append(": ")
     806            .append(Utils.escapeReservedCharactersHTML(i.b)).append("<br>"));
     807
     808            List<Pair<String, URL>> urls = getDataURLs();
     809            if (!urls.isEmpty()) {
     810                tt.append("<br>Resources:<br><ul>");
     811                urls.stream().forEachOrdered(u -> {
     812                    try {
     813                        tt.append("<li>").append(Utils.escapeReservedCharactersHTML(u.a))
     814                            .append(" (<a href=\"").append(URLEncoder.encode(u.b.toString(), "UTF-8")).append("\">")
     815                            .append(Utils.escapeReservedCharactersHTML(u.b.toString()))
     816                            .append("</a>)</li>");
     817                    } catch (UnsupportedEncodingException e) {
     818                        Logging.error(e);
     819                    }
     820                });
     821            }
     822
     823        tt.append("</html>");
     824        return tt.toString();
     825    }
    537826}
  • plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/datasets/CkanDataSetHandler.java

     
     1package org.openstreetmap.josm.plugins.opendata.core.datasets;
     2
     3import static org.openstreetmap.josm.tools.I18n.tr;
     4
     5import java.awt.Component;
     6import java.awt.GridBagLayout;
     7import java.net.InetAddress;
     8import java.net.MalformedURLException;
     9import java.net.URI;
     10import java.net.URISyntaxException;
     11import java.net.URL;
     12import java.util.ArrayList;
     13import java.util.Arrays;
     14import java.util.Collections;
     15import java.util.List;
     16import java.util.Map;
     17import java.util.Objects;
     18import java.util.Set;
     19import java.util.regex.Matcher;
     20import java.util.regex.Pattern;
     21import java.util.stream.Collectors;
     22
     23import javax.swing.BorderFactory;
     24import javax.swing.DefaultListCellRenderer;
     25import javax.swing.JComboBox;
     26import javax.swing.JLabel;
     27import javax.swing.JList;
     28import javax.swing.JPanel;
     29
     30import org.openstreetmap.josm.data.osm.DataSet;
     31import org.openstreetmap.josm.gui.ExtendedDialog;
     32import org.openstreetmap.josm.gui.MainApplication;
     33import org.openstreetmap.josm.plugins.opendata.core.gui.DialogPrompter;
     34import org.openstreetmap.josm.plugins.opendata.core.gui.CkanResourceCandidateChooser;
     35import org.openstreetmap.josm.plugins.opendata.core.gui.CkanResourceListCellRenderer;
     36import org.openstreetmap.josm.plugins.opendata.core.licenses.License;
     37import org.openstreetmap.josm.plugins.opendata.core.platforms.CkanDataPlatform;
     38import org.openstreetmap.josm.tools.GBC;
     39import org.openstreetmap.josm.tools.Logging;
     40import org.openstreetmap.josm.tools.Pair;
     41
     42import eu.trentorise.opendata.jackan.CkanClient;
     43import eu.trentorise.opendata.jackan.exceptions.CkanNotFoundException;
     44import eu.trentorise.opendata.jackan.model.CkanDataset;
     45import eu.trentorise.opendata.jackan.model.CkanResource;
     46
     47public class CkanDataSetHandler extends AbstractDataSetHandler {
     48    private CkanClient ckanClient = null;
     49    private String ckanDatasetId = null;
     50    private CkanDataset ckanDataset = null;
     51
     52    public CkanDataSetHandler(CkanClient ckanClient, CkanDataset dataset) {
     53        this.ckanClient = ckanClient;
     54        initFromCkanDataset(dataset);
     55    }
     56
     57    public CkanDataSetHandler(String ckanCatalogUrl, CkanDataset dataset) {
     58        this(new CkanClient(ckanCatalogUrl), dataset);
     59    }
     60
     61    public CkanDataSetHandler(String ckanCatalogUrl, String datasetId) {
     62        ckanClient = new CkanClient(ckanCatalogUrl);
     63        CkanDataset ckanDataset = fetchCkanDataset();
     64
     65        initFromCkanDataset(ckanDataset);
     66    }
     67
     68    public CkanDataSetHandler(String ckanCatalogUrl, String datasetId, String name) {
     69        // Lazily fetch ckan dataset from server when required
     70        ckanClient = new CkanClient(ckanCatalogUrl);
     71        setCkanDatasetId(datasetId);
     72        setName(name);
     73        try {
     74            String datasetUrl = CkanClient.makeDatasetUrl(ckanClient.getCatalogUrl(), getCkanDatasetId());
     75            setDataURL(datasetUrl);
     76            setNationalPortalURL(datasetUrl);
     77        } catch (MalformedURLException e) {
     78            Logging.error(e);
     79        }
     80    }
     81
     82    private CkanDataset fetchCkanDataset() {
     83        return ckanClient.getDataset(getCkanDatasetId());
     84    }
     85
     86    private void initFromCkanDataset(CkanDataset dataset) {
     87        initFromCkanDataset(dataset, false);
     88    }
     89
     90    private void initFromCkanDataset(CkanDataset dataset, boolean overrideProperties) {
     91        setCkanDataset(dataset);
     92
     93        String title = dataset.getTitle();
     94        String ckanName = dataset.getName();
     95        String ckanLicenseUrl = dataset.getLicenseUrl();
     96        Map<String, Object> ckanOthers = dataset.getOthers();
     97
     98        if (getCkanDatasetId() == null || overrideProperties) {
     99            setCkanDatasetId(dataset.getId());
     100        }
     101
     102        if (getName() == null || overrideProperties) {
     103            setName(title != null && !title.isEmpty() ? title : ckanName);
     104        }
     105
     106        if (getDescription() == null || overrideProperties) {
     107            String description = dataset.getNotes();
     108            if (description != null) {
     109                setDescription(description);
     110            }
     111        }
     112
     113        if (getDataVersion() == null || overrideProperties) {
     114            String version = dataset.getVersion();
     115            if (version != null) {
     116                setDataVersion(version);
     117            }
     118        }
     119
     120        if (getGeographicToponym() == null || overrideProperties) {
     121            Object geoToponym = ckanOthers.get("geographic_toponym");
     122            if (geoToponym instanceof String) {
     123                setGeographicToponym((String)geoToponym);
     124            }
     125        }
     126
     127        if (getMaintainer() == null || overrideProperties) {
     128            String maintainer = dataset.getMaintainer();
     129            if (maintainer != null) {
     130                setMaintainer(maintainer);
     131            }
     132        }
     133
     134        if (getLicense() == null || overrideProperties) {
     135            if (ckanLicenseUrl != null && !ckanLicenseUrl.isEmpty()) {
     136                try {
     137                    setLicense(new License(ckanLicenseUrl));
     138                } catch (MalformedURLException e) {
     139                    Logging.error(e);
     140                }
     141            }
     142        }
     143
     144        try {
     145            String datasetUrl = CkanClient.makeDatasetUrl(ckanClient.getCatalogUrl(), dataset.getId());
     146            if (getDataURL() == null || overrideProperties) {
     147                setDataURL(datasetUrl);
     148            }
     149            if (getNationalPortalURL() == null || overrideProperties) {
     150                setNationalPortalURL(datasetUrl);
     151            }
     152        } catch (MalformedURLException e) {
     153            Logging.error(e);
     154        }
     155
     156        List<Pair<String, URL>> dataUrls = getDataURLs();
     157        for (CkanResource r : getCkanResources()) {
     158            String ckanResourceUrl = getResourceUrl(ckanClient.getCatalogUrl(), dataset.getId(), r.getId());
     159            Logging.debug("Dataset has CKAN resource, name: {0}, format: {1}, mimetype: {2}, size: {3}, url: {4}, dataset resource url: {5}", r.getName(), r.getFormat(), r.getMimetype(), r.getSize(), r.getUrl(), ckanResourceUrl);
     160            try {
     161                URL resourceUrl = new URL(ckanResourceUrl);
     162                if (!dataUrls.stream().anyMatch(p -> p.b == resourceUrl) || overrideProperties) {
     163                    addDataURL(r.getName(), resourceUrl);
     164                }
     165            } catch (MalformedURLException e) {
     166                Logging.error(e);
     167            }
     168        }
     169    }
     170
     171    private void setCkanDataset(CkanDataset ckanDataset) {
     172        this.ckanDataset = ckanDataset;
     173    }
     174
     175    private CkanDataset getCkanDataset() throws CkanNotFoundException {
     176        if (ckanDataset == null) {
     177            Logging.debug("Lazily fetching ckan dataset {0} from server {1}", getCkanDatasetId(), ckanClient.getCatalogUrl());
     178            CkanDataset ckanDataset = fetchCkanDataset();
     179            setCkanDataset(ckanDataset);
     180            initFromCkanDataset(ckanDataset, false);
     181        }
     182
     183        return this.ckanDataset;
     184    }
     185
     186    private void setCkanDatasetId(String ckanDatasetId) {
     187        this.ckanDatasetId = ckanDatasetId;
     188    }
     189
     190    public String getCkanDatasetId() {
     191        return this.ckanDatasetId;
     192    }
     193
     194    public List<CkanResource> getCkanResources() {
     195        return getCkanDataset().getResources();
     196    }
     197
     198    private static String getResourceUrl(String ckanCatalogUrl, String datasetId, String resourceId) {
     199        // CkanClient.makeResourceUrl doesn't provide the correct output
     200        return CkanClient.makeDatasetUrl(ckanCatalogUrl, datasetId) + "/resource/" + resourceId;
     201    }
     202
     203    @Override
     204    public boolean acceptsUrl(String url) {
     205        Pair<String, String> ids = CkanDataPlatform.getIdsFromUrl(ckanClient.getCatalogUrl(), url);
     206        return ids != null && ids.a != null && ids.a.equals(getCkanDatasetId());
     207    }
     208
     209    @Override
     210    public boolean acceptsFilename(String filename) {
     211        return false;
     212    }
     213
     214    @Override
     215    public String modifyUrlBeforeLoad(String url) {
     216        Pair<String, String> datasetResourceId = CkanDataPlatform.getIdsFromUrl(ckanClient.getCatalogUrl(), url);
     217        String datasetId = datasetResourceId != null ? datasetResourceId.a : null;
     218        String resourceId = datasetResourceId != null ? datasetResourceId.b : null;
     219
     220        if (datasetId != null) {
     221            if (!datasetId.equals(getCkanDatasetId()) && !datasetId.equals(getCkanDataset().getName())) {
     222                Logging.warn("Ckan dataset {0} handler invoked for different dataset {1}", getCkanDatasetId(), url);
     223            }
     224
     225            if (resourceId == null) {
     226                List<CkanResource> resources = getCkanResources();
     227                if (resources.size() > 0) {
     228                    if (resources.size() == 1) {
     229                        resourceId = resources.get(0).getId();
     230                    } else {
     231                        DialogPrompter<CkanResourceCandidateChooser> prompt = new DialogPrompter<CkanResourceCandidateChooser>() {
     232                            @Override
     233                            protected CkanResourceCandidateChooser buildDialog() {
     234                                return new CkanResourceCandidateChooser(MainApplication.getMainFrame(), resources);
     235                            }
     236                        };
     237                        if (prompt.promptInEdt().getValue() == 1) {
     238                            resourceId = prompt.getDialog().getSelectedResource().getId();
     239                        } else {
     240                            return null;
     241                        }
     242                    }
     243                } else {
     244                    return null;
     245                }
     246            }
     247
     248            if (resourceId != null) {
     249                final String lookupId = resourceId;
     250                String cResourceUrl = getCkanResources().stream().filter(r -> lookupId.equals(r.getId()))
     251                    .findAny().map(r -> r.getUrl()).orElse(null);
     252
     253                if (cResourceUrl == null) {
     254                    try {
     255                        Logging.debug("CKAN Resource {0} not in local dataset {1} info cache, querying server for information",
     256                            resourceId, getCkanDatasetId());
     257                        CkanResource cRes = ckanClient.getResource(resourceId);
     258                        cResourceUrl = cRes.getUrl();
     259                    } catch (CkanNotFoundException e) {
     260                        Logging.info("Dataset {0} not found on open data platform {1}", resourceId, getName());
     261                    } catch (Exception e) {
     262                        Logging.warn(e);
     263                    }
     264                }
     265
     266                if (cResourceUrl != null) {
     267                    try {
     268                        URI rUri = new URI(cResourceUrl.replace(" ", "%20")); // space replacement = partial workaround for invalid url encoding in upstream
     269                        final List<String> allowedSchemes = Arrays.asList("http", "https", "ftp");
     270
     271                        if (!allowedSchemes.stream().anyMatch(s -> s.equals(rUri.getScheme()))) {
     272                            Logging.warn("Invalid CKAN resource URL received from server (only http/https/ftp allowed): {0}", cResourceUrl);
     273                            return url;
     274                        }
     275
     276                        InetAddress inetAddress = InetAddress.getByName(rUri.getHost());
     277                        if (inetAddress.isAnyLocalAddress() || inetAddress.isLoopbackAddress() || inetAddress.isLinkLocalAddress() || inetAddress.isSiteLocalAddress()){
     278                            Logging.warn("Invalid CKAN resource URL received from server (local address): {0} = {1}", cResourceUrl, inetAddress);
     279                            return url;
     280                        }
     281
     282                        Logging.debug("Modifying location download url {0} to CKAN resource target url {1}", url, rUri);
     283
     284                        return rUri.toString();
     285                    } catch (Exception e) {
     286                        Logging.warn("Received invalid resource url {0} from CKAN server: {1}", cResourceUrl, e);
     287                    }
     288                }
     289            }
     290        }
     291
     292        return url;
     293    }
     294
     295    @Override
     296    public void updateDataSet(DataSet ds) {
     297        // default: leave data unmodified
     298    }
     299}
  • plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/gui/CkanResourceCandidateChooser.java

     
     1package org.openstreetmap.josm.plugins.opendata.core.gui;
     2
     3import static org.openstreetmap.josm.tools.I18n.tr;
     4
     5import java.awt.Component;
     6import java.awt.GridBagLayout;
     7import java.util.List;
     8
     9import javax.swing.BorderFactory;
     10import javax.swing.JComboBox;
     11import javax.swing.JLabel;
     12import javax.swing.JPanel;
     13
     14import org.openstreetmap.josm.gui.ExtendedDialog;
     15import org.openstreetmap.josm.tools.GBC;
     16
     17import eu.trentorise.opendata.jackan.model.CkanResource;
     18
     19public class CkanResourceCandidateChooser extends ExtendedDialog {
     20    /**
     21     * This is the panel holding all candidate resources
     22     */
     23    private final JPanel projPanel = new JPanel(new GridBagLayout());
     24
     25    private final JComboBox<CkanResource> resourceCombo;
     26
     27    public CkanResourceCandidateChooser(Component parent, List<CkanResource> resourceCandidates) {
     28        this(parent, tr("Resource to load"), new String[] {tr("OK"), tr("Cancel")}, resourceCandidates);
     29    }
     30
     31    protected CkanResourceCandidateChooser(Component parent, String title, String[] buttonTexts, List<CkanResource> resourceCandidates) {
     32        super(parent, title, buttonTexts);
     33        this.resourceCombo = new JComboBox<>(resourceCandidates.toArray(new CkanResource[0]));
     34        this.resourceCombo.setRenderer(new CkanResourceListCellRenderer());
     35        addGui(resourceCandidates);
     36    }
     37
     38    public void addGui(List<CkanResource> candidates) {
     39        projPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
     40        projPanel.setLayout(new GridBagLayout());
     41        projPanel.add(new JLabel(tr("Resource to load")), GBC.std().insets(5, 5, 0, 5));
     42        projPanel.add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL));
     43        projPanel.add(resourceCombo, GBC.eop().fill(GBC.HORIZONTAL).insets(0, 5, 5, 5));
     44        setContent(projPanel);
     45    }
     46
     47    public CkanResource getSelectedResource() {
     48        return (CkanResource) resourceCombo.getSelectedItem();
     49    }
     50}
  • plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/gui/CkanResourceListCellRenderer.java

     
     1package org.openstreetmap.josm.plugins.opendata.core.gui;
     2
     3import java.awt.Component;
     4
     5import javax.swing.DefaultListCellRenderer;
     6import javax.swing.JList;
     7
     8import eu.trentorise.opendata.jackan.model.CkanResource;
     9
     10public class CkanResourceListCellRenderer extends DefaultListCellRenderer {
     11
     12    @Override
     13    public Component getListCellRendererComponent(JList<?> list, Object value,
     14            int index, boolean isSelected, boolean cellHasFocus) {
     15        super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
     16        if (value instanceof CkanResource) {
     17            CkanResource r = (CkanResource)value;
     18            StringBuilder t = new StringBuilder();
     19
     20            String id = r.getId();
     21            String name = r.getName();
     22            String description = r.getDescription();
     23            String format = r.getFormat();
     24            Boolean haveFormat = format != null && !format.isEmpty();
     25            String mimetype = r.getMimetype();
     26
     27            t.append("<html><strong>")
     28             .append(haveInfo(name)        ? name :
     29                     haveInfo(description) ? description :
     30                                             id)
     31             .append("</strong> <span color='gray'>");
     32
     33            if (haveInfo(format) || haveInfo(mimetype)) {
     34                t.append("[");
     35                if (haveInfo(format)) {
     36                    t.append(format);
     37                    if (haveInfo(mimetype)) {
     38                        t.append(" | ");
     39                    }
     40                }
     41                if (haveInfo(mimetype)) {
     42                    t.append(mimetype);
     43                }
     44                t.append("]");
     45            }
     46
     47            t.append("</span></html>");
     48            setText(t.toString());
     49        }
     50        return this;
     51    }
     52
     53    private boolean haveInfo(String info) {
     54        return info != null && !info.isEmpty();
     55    }
     56}
  • plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/gui/DatasetListCellRenderer.java

     
     1package org.openstreetmap.josm.plugins.opendata.core.gui;
     2
     3import static org.openstreetmap.josm.tools.I18n.tr;
     4
     5import java.awt.Component;
     6import java.io.UnsupportedEncodingException;
     7import java.net.URL;
     8import java.net.URLEncoder;
     9import java.util.ArrayList;
     10import java.util.LinkedHashMap;
     11import java.util.List;
     12import java.util.Map;
     13
     14import javax.swing.DefaultListCellRenderer;
     15import javax.swing.JLabel;
     16import javax.swing.JList;
     17import javax.swing.ListCellRenderer;
     18
     19import org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler;
     20import org.openstreetmap.josm.tools.Logging;
     21import org.openstreetmap.josm.tools.Pair;
     22import org.openstreetmap.josm.tools.Utils;
     23
     24public class DatasetListCellRenderer extends DefaultListCellRenderer {
     25
     26    @Override
     27    public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
     28        final AbstractDataSetHandler entry = (AbstractDataSetHandler) value;
     29        Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
     30        return renderer(c, entry, false);
     31    }
     32
     33    /**
     34     * Internal method that stuffs information into the rendering component
     35     * provided that it's a kind of JLabel.
     36     * @param def the rendering component
     37     * @param value the AbstractDataSetHandler to render
     38     * @param fast whether the icons should be loaded fast since many items are being displayed
     39     * @return the modified rendering component
     40     */
     41    private Component renderer(Component def, AbstractDataSetHandler value, boolean fast) {
     42        if (value != null && def instanceof JLabel) {
     43            ((JLabel) def).setText(getComponentText(value));
     44            ((JLabel) def).setToolTipText(getComponentToolTipText(value));
     45        }
     46        return def;
     47    }
     48
     49    /**
     50     * Returns the text representing an open data dataset in a component.
     51     * Can be overridden to customize the text
     52     * @param dataset AbstractDataSetHandler
     53     * @return text representing the dataset
     54     */
     55    protected String getComponentText(AbstractDataSetHandler dataset) {
     56        return dataset.getComponentText();
     57    }
     58
     59    /**
     60     * Returns the text representing an open data dataset in a tooltip.
     61     * Can be overridden to customize the text
     62     * @param dataset AbstractDataSetHandler
     63     * @return tooltip text for the dataset
     64     */
     65    protected String getComponentToolTipText(AbstractDataSetHandler dataset) {
     66        return dataset.getToolTipText();
     67    }
     68}
  • plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/gui/DatasetSearchDialog.java

     
     1package org.openstreetmap.josm.plugins.opendata.core.gui;
     2
     3import static org.openstreetmap.josm.tools.I18n.tr;
     4
     5import java.awt.event.ActionEvent;
     6import java.awt.event.MouseEvent;
     7import java.net.URL;
     8import java.util.ArrayList;
     9import java.util.Collection;
     10import java.util.Collections;
     11import java.util.List;
     12import java.awt.Dimension;
     13import java.awt.GridBagLayout;
     14
     15import javax.swing.Action;
     16import javax.swing.JLabel;
     17import javax.swing.JPanel;
     18import javax.swing.JPopupMenu;
     19
     20import org.openstreetmap.josm.gui.ExtendedDialog;
     21import org.openstreetmap.josm.gui.MainApplication;
     22import org.openstreetmap.josm.gui.widgets.ListPopupMenu;
     23import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;
     24import org.openstreetmap.josm.plugins.opendata.core.actions.DownloadDataAction;
     25import org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler;
     26import org.openstreetmap.josm.plugins.opendata.core.platforms.AbstractDataPlatform;
     27import org.openstreetmap.josm.tools.GBC;
     28
     29import org.openstreetmap.josm.plugins.opendata.core.modules.Module;
     30
     31public class DatasetSearchDialog extends ExtendedDialog {
     32    private final JPanel panel = new JPanel(new GridBagLayout());
     33    private final PopupDatasetSearchPanel datasetSearchBox;
     34
     35    public DatasetSearchDialog(AbstractDataPlatform platform) {
     36        super(MainApplication.getMainFrame(), tr("Search datasets"),
     37            new String[] {tr("Open"), tr("Cancel")}, true);
     38
     39        this.datasetSearchBox = new PopupDatasetSearchPanel(platform);
     40        this.datasetSearchBox.setDblClickListener(e -> buttonAction(0, null));
     41
     42        panel.add(new JLabel(tr("Search for datasets on {0}", platform.getName())), GBC.eol().fill(GBC.HORIZONTAL));
     43        panel.add(datasetSearchBox, GBC.eop().fill(GBC.BOTH));
     44        setButtonIcons("download", "cancel");
     45        setDefaultButton(1);
     46        setContent(panel, false);
     47        setPreferredSize(new Dimension(800, 400));
     48    }
     49
     50    @Override
     51    protected void buttonAction(int buttonIndex, ActionEvent evt) {
     52        super.buttonAction(buttonIndex, evt);
     53        if (buttonIndex != 0) {
     54            return;
     55        }
     56        final AbstractDataSetHandler selected = datasetSearchBox.getSelectedItem();
     57        if (selected == null) {
     58            return;
     59        }
     60
     61        URL url = selected.getDataURL();
     62        if (url != null) {
     63            DownloadDataAction.download(url);
     64        }
     65    }
     66
     67    class PopupDatasetSearchPanel extends DatasetSearchPanel {
     68
     69        private PopupMenuHandler popupHandler;
     70
     71        public PopupDatasetSearchPanel(AbstractDataPlatform platform) {
     72            super(platform);
     73
     74            popupHandler = new PopupMenuHandler();
     75            lsResult.addMouseListener(popupHandler);
     76        }
     77
     78        class PopupMenuHandler extends PopupMenuLauncher {
     79            @Override
     80            public void showMenu(MouseEvent evt) {
     81                menu = new DatasetSearchListPopup(lsResult.getSelectedValuesList());
     82                super.showMenu(evt);
     83            }
     84        }
     85    }
     86
     87    class DatasetSearchListPopup extends JPopupMenu {
     88        public DatasetSearchListPopup(List<AbstractDataSetHandler> selectedDatasets) {
     89            if (selectedDatasets.size() == 1) {
     90                AbstractDataSetHandler dataset = selectedDatasets.get(0);
     91                dataset.getPopupMenuItems().stream().forEachOrdered(mi -> add(mi));
     92            }
     93        }
     94    }
     95}
  • plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/gui/DatasetSearchPanel.java

     
     1package org.openstreetmap.josm.plugins.opendata.core.gui;
     2
     3import java.awt.Component;
     4import java.util.Collections;
     5import java.util.List;
     6import java.util.concurrent.Executors;
     7import java.util.concurrent.TimeUnit;
     8import java.util.stream.Collectors;
     9
     10import javax.swing.JList;
     11
     12import org.openstreetmap.josm.gui.util.GuiHelper;
     13import org.openstreetmap.josm.gui.widgets.SearchTextResultListPanel;
     14import org.openstreetmap.josm.tools.Utils;
     15import org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler;
     16import org.openstreetmap.josm.plugins.opendata.core.platforms.AbstractDataPlatform;
     17import org.openstreetmap.josm.plugins.opendata.core.util.Debouncer;
     18
     19public class DatasetSearchPanel extends SearchTextResultListPanel<AbstractDataSetHandler> {
     20
     21    private AbstractDataPlatform platform;
     22
     23    protected final Debouncer debouncer = new Debouncer(
     24            Executors.newSingleThreadScheduledExecutor(Utils.newThreadFactory("ckan-search-%d", Thread.NORM_PRIORITY)));
     25
     26    public DatasetSearchPanel(AbstractDataPlatform platform) {
     27        super();
     28        this.platform = platform;
     29        lsResult.setCellRenderer(new DatasetListCellRenderer());
     30    }
     31
     32    @Override
     33    protected void filterItems() {
     34        final String query = edSearchText.getText();
     35        debouncer.debounce(getClass(), () -> {
     36            final List<AbstractDataSetHandler> entries = query == null || query.isEmpty()
     37                            ? Collections.emptyList()
     38                            : platform.searchDatasets(query).collect(Collectors.toList());
     39            GuiHelper.runInEDT(() -> lsResultModel.setItems(entries));
     40        }, 300, TimeUnit.MILLISECONDS);
     41    }
     42
     43    public AbstractDataSetHandler getSelectedItem() {
     44        synchronized (lsResultModel) {
     45            final int idx = lsResult.getSelectedIndex();
     46            final AbstractDataSetHandler selected = idx < lsResultModel.getSize() && idx >= 0 ? lsResultModel.getElementAt(idx) : null;
     47
     48            if (selected != null) {
     49                return selected;
     50            } else if (!lsResultModel.isEmpty()) {
     51                return lsResultModel.getElementAt(0);
     52            } else {
     53                return null;
     54            }
     55        }
     56    }
     57}
  • plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/NetworkReader.java

     
    157157                readerClass = findReaderByContentType();
    158158            }
    159159            if (readerClass == null) {
    160                 throw new OsmTransferException("Cannot find appropriate reader !"); //TODO handler job ?
     160                UnsupportedDataException e = new UnsupportedDataException(tr("Unsupported data type"));
     161                e.setUrl(url);
     162                throw e; //TODO handler job ?
    161163            } else if (findReaderByExtension(url) != null) {
    162164                filename = url.substring(url.lastIndexOf('/')+1);
    163165            }
  • plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/UnsupportedDataException.java

     
     1package org.openstreetmap.josm.plugins.opendata.core.io;
     2
     3import org.openstreetmap.josm.io.OsmTransferException;
     4
     5public class UnsupportedDataException extends OsmTransferException {
     6
     7    public UnsupportedDataException() {
     8    }
     9
     10    public UnsupportedDataException(String message) {
     11        super(message);
     12    }
     13
     14    public UnsupportedDataException(Throwable cause) {
     15        super(cause);
     16    }
     17
     18    public UnsupportedDataException(String message, Throwable cause) {
     19        super(message, cause);
     20    }
     21}
  • plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/layers/OdDataLayer.java

     
    124124            result.add(entry);
    125125        }
    126126        if (this.handler != null) {
    127             if (this.handler.getWikiURL() != null || this.handler.getLocalPortalURL() != null || this.handler.getNationalPortalURL() != null) {
     127            List<Action> handlerActions = this.handler.getMenuActions();
     128            if (!handlerActions.isEmpty()) {
    128129                result.add(SeparatorLayerAction.INSTANCE);
    129             }
    130             if (this.handler.getWikiURL() != null) {
    131                 result.add(new OpenLinkAction(this.handler.getWikiURL(), OdConstants.ICON_OSM_24,
    132                         tr("View OSM Wiki page"), tr("Launch browser to the OSM Wiki page of the selected data set")));
    133             }
    134             if (this.handler.getLocalPortalURL() != null) {
    135                 result.add(new OpenLinkAction(this.handler.getLocalPortalURL(), this.handler.getLocalPortalIconName(),
    136                         tr("View Local Portal page"), tr("Launch browser to the local portal page of the selected data set")));
    137             }
    138             if (this.handler.getNationalPortalURL() != null) {
    139                 result.add(new OpenLinkAction(this.handler.getNationalPortalURL(), this.handler.getNationalPortalIconName(),
    140                         tr("View National Portal page"), tr("Launch browser to the national portal page of the selected data set")));
    141             }
    142             if (this.handler.getLicense() != null) {
    143                 License lic = this.handler.getLicense();
    144                 if (lic.getURL() != null && lic.getURL().getProtocol().startsWith("http")) {
    145                     result.add(new OpenLinkAction(lic.getURL(), OdConstants.ICON_AGREEMENT_24,
    146                             tr("View License"), tr("Launch browser to the license page of the selected data set")));
     130                for (Action entry : handlerActions) {
     131                    result.add(entry);
    147132                }
    148                 if (lic.getSummaryURL() != null && lic.getSummaryURL().getProtocol().startsWith("http")) {
    149                     result.add(new OpenLinkAction(lic.getSummaryURL(), OdConstants.ICON_AGREEMENT_24,
    150                             tr("View License (summary)"), tr("Launch browser to the summary license page of the selected data set")));
    151                 }
    152                 if ((lic.getURL() != null && !lic.getURL().getProtocol().startsWith("http")) ||
    153                         (lic.getSummaryURL() != null && !lic.getSummaryURL().getProtocol().startsWith("http"))) {
    154                     result.add(new ViewLicenseAction(lic, tr("View License"), tr("View the license of the selected data set")));
    155                 }
    156133            }
    157134        }
    158135        return result.toArray(new Action[0]);
  • plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/licenses/License.java

     
    1111
    1212import org.openstreetmap.josm.plugins.opendata.core.util.OdUtils;
    1313
    14 public abstract class License {
     14public class License {
    1515
    1616    public static final ODbL ODbL = new ODbL();
    1717    public static final LOOL LOOL = new LOOL();
     
    2121
    2222    private Icon icon;
    2323
     24    public License() {
     25    }
     26
     27    public License(String licenseUrl) throws MalformedURLException {
     28        setURL(licenseUrl);
     29    }
     30
     31    public License(String licenseUrl, String language) throws MalformedURLException {
     32        setURL(licenseUrl, language);
     33    }
     34
     35    public License(Map<String, URL> languageToLicenceMap) {
     36        urls.putAll(languageToLicenceMap);
     37    }
     38
     39    public License(Map<String, URL> licenseUrls, Map<String, URL> summaryUrls) {
     40        urls.putAll(licenseUrls);
     41        summaryURLs.putAll(summaryUrls);
     42    }
     43
    2444    private static URL getURL(Map<String, URL> map) {
    2545        // Find URL for current language
    2646        String lang = OdUtils.getJosmLanguage();
  • plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/modules/AbstractModule.java

     
    77import java.io.InputStream;
    88import java.util.ArrayList;
    99import java.util.Collection;
     10import java.util.Collections;
     11import java.util.HashMap;
    1012import java.util.List;
     13import java.util.Map;
    1114
     15import javax.swing.JMenu;
     16import javax.swing.JMenuItem;
     17
    1218import org.openstreetmap.josm.data.preferences.sources.ExtendedSourceEntry;
    1319import org.openstreetmap.josm.data.preferences.sources.SourceEntry;
    1420import org.openstreetmap.josm.data.preferences.sources.SourceProvider;
     
    1521import org.openstreetmap.josm.plugins.opendata.OdPlugin;
    1622import org.openstreetmap.josm.plugins.opendata.core.OdConstants;
    1723import org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler;
     24import org.openstreetmap.josm.plugins.opendata.core.datasets.DataSetCategory;
    1825import org.openstreetmap.josm.tools.Logging;
    1926
    2027public abstract class AbstractModule implements Module {
     
    3542    }
    3643
    3744    @Override
     45    public void addHandlerClass(Class<? extends AbstractDataSetHandler> handlerClass) {
     46        handlers.add(handlerClass);
     47    }
     48
     49    @Override
    3850    public List<Class<? extends AbstractDataSetHandler>> getHandlers() {
    3951        return handlers;
    4052    }
    4153
    4254    @Override
     55    public AbstractDataSetHandler findDataSetHandlerForUrl(String url) {
     56        for (AbstractDataSetHandler handler : getNewlyInstanciatedHandlers()) {
     57            if (handler.acceptsUrl(url)) {
     58                return handler;
     59            }
     60        }
     61
     62        return null;
     63    }
     64
     65    @Override
    4366    public String getDisplayedName() {
    4467        return info.name;
    4568    }
     
    120143        }
    121144        return instanciatedHandlers;
    122145    }
     146
     147    @Override
     148    public JMenuItem getModuleMenu() {
     149        JMenu moduleMenu = null;
     150        Map<DataSetCategory, JMenu> catMenus = new HashMap<>();
     151
     152        String moduleName = getDisplayedName();
     153        if (moduleName == null || moduleName.isEmpty()) {
     154            moduleName = getModuleInformation().getName();
     155        }
     156       
     157        for (AbstractDataSetHandler handler : getNewlyInstanciatedHandlers()) {
     158            JMenuItem handlerMenuItem = handler.getHandlerMenu(this);
     159            if (handlerMenuItem != null) {
     160                if (moduleMenu == null) {
     161                    moduleMenu = getBaseModuleMenu();
     162                    // moduleMenu = new JMenu(moduleName);
     163                    // moduleMenu.setIcon(getModuleInformation().getScaledIcon());
     164                }
     165
     166                JMenu targetMenu = moduleMenu;
     167                DataSetCategory cat = handler.getCategory();
     168                if (cat != null) {
     169                    JMenu categoryMenu = catMenus.get(cat);
     170                    if (categoryMenu == null) {
     171                        categoryMenu = new JMenu(cat.getName());
     172                        OdPlugin.setMenuItemIcon(cat.getIcon(), categoryMenu);
     173                        catMenus.put(cat, categoryMenu);
     174                        moduleMenu.add(categoryMenu);
     175                    }
     176                    targetMenu = categoryMenu;
     177                }
     178               
     179                targetMenu.add(handlerMenuItem);
     180            }
     181        }
     182       
     183        return moduleMenu;
     184    }
     185
     186    protected JMenu getBaseModuleMenu() {
     187        String moduleName = getDisplayedName();
     188        if (moduleName == null || moduleName.isEmpty()) {
     189            moduleName = getModuleInformation().getName();
     190        }
     191        JMenu baseModuleMenu = new JMenu(moduleName);
     192        baseModuleMenu.setIcon(getModuleInformation().getScaledIcon());
     193        return baseModuleMenu;
     194    }
     195
     196    @Override
     197    public List<String> getAcceptedPatterns() {
     198        return Collections.emptyList();
     199    }
    123200}
  • plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/modules/Module.java

     
    33
    44import java.util.List;
    55
     6import javax.swing.JMenuItem;
     7
    68import org.openstreetmap.josm.data.preferences.sources.SourceProvider;
    79import org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler;
    810
     
    1012
    1113    String getDisplayedName();
    1214
     15    void addHandlerClass(Class<? extends AbstractDataSetHandler> handlerClass);
     16
    1317    List<Class<? extends AbstractDataSetHandler>> getHandlers();
    1418
     19    AbstractDataSetHandler findDataSetHandlerForUrl(String url);
     20
    1521    List<AbstractDataSetHandler> getNewlyInstanciatedHandlers();
    1622
    1723    SourceProvider getMapPaintStyleSourceProvider();
     
    1925    SourceProvider getPresetSourceProvider();
    2026
    2127    ModuleInformation getModuleInformation();
     28
     29    JMenuItem getModuleMenu();
     30
     31    List<String> getAcceptedPatterns();
    2232}
  • plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/platforms/AbstractDataPlatform.java

     
     1package org.openstreetmap.josm.plugins.opendata.core.platforms;
     2
     3import java.util.stream.Stream;
     4
     5import org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler;
     6import org.openstreetmap.josm.plugins.opendata.core.modules.Module;
     7
     8public abstract class AbstractDataPlatform {
     9
     10    private String name;
     11    private Module module;
     12
     13    public AbstractDataPlatform(Module module, String name) {
     14        this.module = module;
     15        this.name = name;
     16    }
     17
     18    public void setName(String name) {
     19        this.name = name;
     20    }
     21   
     22    public String getName() {
     23        return name;
     24    }
     25
     26    public Module getModule() {
     27        return module;
     28    }
     29
     30    public abstract Stream<AbstractDataSetHandler> searchDatasets(String searchString);
     31
     32    public AbstractDataSetHandler findDataSetHandlerForUrl(String url) {
     33        return null;
     34    }
     35}
  • plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/platforms/CkanDataPlatform.java

     
     1package org.openstreetmap.josm.plugins.opendata.core.platforms;
     2
     3import java.net.URI;
     4import java.util.ArrayList;
     5import java.util.HashMap;
     6import java.util.List;
     7import java.util.Map;
     8import java.util.Optional;
     9import java.util.regex.Matcher;
     10import java.util.regex.Pattern;
     11import java.util.stream.Collectors;
     12import java.util.stream.Stream;
     13
     14import org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler;
     15import org.openstreetmap.josm.plugins.opendata.core.datasets.CkanDataSetHandler;
     16import org.openstreetmap.josm.plugins.opendata.core.modules.Module;
     17import org.openstreetmap.josm.tools.Logging;
     18import org.openstreetmap.josm.tools.Pair;
     19
     20import eu.trentorise.opendata.jackan.CkanClient;
     21import eu.trentorise.opendata.jackan.exceptions.CkanNotFoundException;
     22import eu.trentorise.opendata.jackan.SearchResults;
     23import eu.trentorise.opendata.jackan.model.CkanDataset;
     24import eu.trentorise.opendata.jackan.model.CkanResource;
     25
     26public class CkanDataPlatform extends AbstractDataPlatform {
     27
     28    protected CkanClient client;
     29
     30    public CkanDataPlatform(Module module, String ckanApiUrl) {
     31        this(module, ckanApiUrl, null);
     32    }
     33
     34    public CkanDataPlatform(Module module, String ckanApiUrl, String platformName) {
     35        super(module, platformName);
     36        client = new CkanClient(ckanApiUrl);
     37    }
     38
     39    @Override
     40    public String getName() {
     41        String platformName = super.getName();
     42        return platformName != null && !platformName.isEmpty() ? platformName : client.getCatalogUrl();
     43    }
     44
     45    public Optional<CkanDataset> getDataset(String datasetId) {
     46        try {
     47            return Optional.of(client.getDataset(datasetId));
     48        } catch (Exception e) {
     49            Logging.info("Ckan dataset {0} not found on platform {1}", datasetId, getName());
     50            return Optional.empty();
     51        }
     52    }
     53
     54    public Optional<CkanResource> getResource(String resourceId) {
     55        try {
     56            return Optional.of(client.getResource(resourceId));
     57        } catch (Exception e) {
     58            Logging.info("Ckan resource {0} not found on platform {1}", resourceId, getName());
     59            return Optional.empty();
     60        }
     61    }
     62
     63    @Override
     64    public Stream<AbstractDataSetHandler> searchDatasets(String searchString) {
     65        Logging.debug("Searching for ''{0}'' on {1}", searchString, getName());
     66        SearchResults<CkanDataset> searchResults = client.searchDatasets(searchString, 50, 0);
     67        List<CkanDataSetHandler> dataSetHandlers = searchResults.getResults().stream()
     68            .map(cd -> new CkanDataSetHandler(client.getCatalogUrl(), cd)).collect(Collectors.toList());
     69        Logging.debug("Search for ''{0}'' on {1} yielded {2} items (out of {3})",
     70            searchString, getName(), dataSetHandlers.size(), searchResults.getCount());
     71       
     72        return dataSetHandlers.stream().map(h -> (AbstractDataSetHandler)h);
     73    }
     74
     75    public String getResourceRegex() {
     76        return getResourceRegex(client.getCatalogUrl());
     77    }
     78
     79    public static String getResourceRegex(String ckanCatalogUrl) {
     80        if (ckanCatalogUrl != null) {
     81            return "^" + Pattern.quote(ckanCatalogUrl) + "/dataset/(?<dataset>[^/]+)/?(?:resource/(?<resource>[^/]+)/?)?$";
     82        } else {
     83            return "^https?://.*/dataset/(?<dataset>[^/]+)/?(?:resource/(?<resource>[^/]+)/?)?$";
     84        }
     85    }
     86
     87    public Pair<String, String> getIdsFromUrl(String url) {
     88        return getIdsFromUrl(client.getCatalogUrl(), url);
     89    }
     90
     91    public static Pair<String, String> getIdsFromUrl(String ckanCatalogUrl, String url) {
     92        Pattern ckanResourceRegex = Pattern.compile(getResourceRegex(ckanCatalogUrl));
     93        Matcher m = ckanResourceRegex.matcher(url);
     94        if (m.find()) {
     95            return new Pair<>(m.group("dataset"), m.group("resource"));
     96        }
     97
     98        return null;
     99    }
     100
     101    @Override
     102    public AbstractDataSetHandler findDataSetHandlerForUrl(String url) {
     103        Pair<String, String> datasetResourceId = getIdsFromUrl(url);
     104        String datasetId = datasetResourceId != null ? datasetResourceId.a : null;
     105        if (datasetId != null) {
     106            try {
     107                CkanDataset cDs = client.getDataset(datasetResourceId.a);
     108                Logging.info("Creating new handler for dataset {0} on open data platform {1}", datasetResourceId.a, getName());
     109                return new CkanDataSetHandler(client, cDs);
     110            } catch (CkanNotFoundException e) {
     111                Logging.info("Dataset {0} not found on open data platform {1}", datasetResourceId.a, getName());
     112            } catch (Exception e) {
     113                Logging.warn(e);
     114            }
     115        }
     116
     117        return null;
     118    }
     119}
  • plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/util/Debouncer.java

     
     1// License: GPL. For details, see LICENSE file.
     2package org.openstreetmap.josm.plugins.opendata.core.util;
     3
     4import java.util.concurrent.ConcurrentHashMap;
     5import java.util.concurrent.Future;
     6import java.util.concurrent.ScheduledExecutorService;
     7import java.util.concurrent.TimeUnit;
     8
     9// Taken from wikipedia plugin
     10// TODO: move this to common code
     11public class Debouncer {
     12    private final ScheduledExecutorService scheduler;
     13    private final ConcurrentHashMap<Object, Future<?>> delayedMap = new ConcurrentHashMap<>();
     14
     15    public Debouncer(ScheduledExecutorService scheduler) {
     16        this.scheduler = scheduler;
     17    }
     18
     19    /**
     20     * Debounces {@code callable} by {@code delay}, i.e., schedules it to be executed after {@code delay},
     21     * or cancels its execution if the method is called with the same key within the {@code delay} again.
     22     * @param key key
     23     * @param runnable runnable to be scheduled
     24     * @param delay delay value
     25     * @param unit delay time unit
     26     */
     27    public void debounce(final Object key, final Runnable runnable, long delay, TimeUnit unit) {
     28        final Future<?> prev = delayedMap.put(key, scheduler.schedule(() -> {
     29            try {
     30                runnable.run();
     31            } finally {
     32                delayedMap.remove(key);
     33            }
     34        }, delay, unit));
     35        if (prev != null) {
     36            prev.cancel(true);
     37        }
     38    }
     39
     40    public void shutdown() {
     41        scheduler.shutdownNow();
     42    }
     43}