Ticket #21638: opendata_ckan_data.gv.at_v2.patch
File opendata_ckan_data.gv.at_v2.patch, 150.6 KB (added by , 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&ivyXmlPath=ivy.xml&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
1 package org.openstreetmap.josm.plugins.jackan; 2 3 import org.openstreetmap.josm.plugins.Plugin; 4 import org.openstreetmap.josm.plugins.PluginInformation; 5 6 public class JackanPlugin extends Plugin { 7 public JackanPlugin(PluginInformation info) { 8 super(info); 9 } 10 } -
plugins/opendata/.classpath
4 4 <classpathentry including="images/" kind="src" path=""/> 5 5 <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"/> 6 6 <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"/> 7 9 <classpathentry kind="src" path="modules/fr.datagouvfr/src"/> 8 10 <classpathentry kind="src" path="modules/fr.datagouvfr/resources"/> 9 11 <classpathentry kind="src" path="modules/fr.paris/src"/> … … 24 26 <classpathentry combineaccessrules="false" kind="src" path="/JOSM-utilsplugin2"/> 25 27 <classpathentry combineaccessrules="false" kind="src" path="/JOSM-GeoTools"/> 26 28 <classpathentry combineaccessrules="false" kind="src" path="/JOSM-jts"/> 29 <classpathentry combineaccessrules="false" kind="src" path="/JOSM-jackan"/> 27 30 <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> 28 31 <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"> 29 32 <attributes> -
plugins/opendata/build.xml
7 7 <property name="plugin.icon" value="images/dialogs/o24.png"/> 8 8 <property name="plugin.canloadatruntime" value="true"/> 9 9 <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"/> 11 11 12 12 <!-- ** include targets that all plugins have in common ** --> 13 13 <import file="../build-common.xml"/> … … 18 18 <include name="jts.jar"/> 19 19 <include name="ejml.jar"/> 20 20 <include name="geotools.jar"/> 21 <include name="jackan.jar"/> 21 22 <include name="opendata.jar"/> 22 23 </fileset> 23 24 … … 25 26 <property name="jts" location="${plugin.dist.dir}/jts.jar"/> 26 27 <property name="ejml" location="${plugin.dist.dir}/ejml.jar"/> 27 28 <property name="geotools" location="${plugin.dist.dir}/geotools.jar"/> 29 <property name="jackan" location="${plugin.dist.dir}/jackan.jar"/> 28 30 29 31 <!-- 30 32 ********************************************************** -
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
1 README 2 ====== 3 4 Readme 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 11 See 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 11 software and other kinds of works. 12 13 The licenses for most software and other practical works are designed 14 to take away your freedom to share and change the works. By contrast, 15 the GNU General Public License is intended to guarantee your freedom to 16 share and change all versions of a program--to make sure it remains free 17 software for all its users. We, the Free Software Foundation, use the 18 GNU General Public License for most of our software; it applies also to 19 any other work released this way by its authors. You can apply it to 20 your programs, too. 21 22 When we speak of free software, we are referring to freedom, not 23 price. Our General Public Licenses are designed to make sure that you 24 have the freedom to distribute copies of free software (and charge for 25 them if you wish), that you receive source code or can get it if you 26 want it, that you can change the software or use pieces of it in new 27 free programs, and that you know you can do these things. 28 29 To protect your rights, we need to prevent others from denying you 30 these rights or asking you to surrender the rights. Therefore, you have 31 certain responsibilities if you distribute copies of the software, or if 32 you modify it: responsibilities to respect the freedom of others. 33 34 For example, if you distribute copies of such a program, whether 35 gratis or for a fee, you must pass on to the recipients the same 36 freedoms that you received. You must make sure that they, too, receive 37 or can get the source code. And you must show them these terms so they 38 know 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 42 giving you legal permission to copy, distribute and/or modify it. 43 44 For the developers' and authors' protection, the GPL clearly explains 45 that there is no warranty for this free software. For both users' and 46 authors' sake, the GPL requires that modified versions be marked as 47 changed, so that their problems will not be attributed erroneously to 48 authors of previous versions. 49 50 Some devices are designed to deny users access to install or run 51 modified versions of the software inside them, although the manufacturer 52 can do so. This is fundamentally incompatible with the aim of 53 protecting users' freedom to change the software. The systematic 54 pattern of such abuse occurs in the area of products for individuals to 55 use, which is precisely where it is most unacceptable. Therefore, we 56 have designed this version of the GPL to prohibit the practice for those 57 products. If such problems arise substantially in other domains, we 58 stand ready to extend this provision to those domains in future versions 59 of the GPL, as needed to protect the freedom of users. 60 61 Finally, every program is threatened constantly by software patents. 62 States should not allow patents to restrict development and use of 63 software on general-purpose computers, but in those that do, we wish to 64 avoid the special danger that patents applied to a free program could 65 make it effectively proprietary. To prevent this, the GPL assures that 66 patents cannot be used to render the program non-free. 67 68 The precise terms and conditions for copying, distribution and 69 modification 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 78 works, such as semiconductor masks. 79 80 "The Program" refers to any copyrightable work licensed under this 81 License. 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 85 in a fashion requiring copyright permission, other than the making of an 86 exact copy. The resulting work is called a "modified version" of the 87 earlier work or a work "based on" the earlier work. 88 89 A "covered work" means either the unmodified Program or a work based 90 on the Program. 91 92 To "propagate" a work means to do anything with it that, without 93 permission, would make you directly or secondarily liable for 94 infringement under applicable copyright law, except executing it on a 95 computer or modifying a private copy. Propagation includes copying, 96 distribution (with or without modification), making available to the 97 public, and in some countries other activities as well. 98 99 To "convey" a work means any kind of propagation that enables other 100 parties to make or receive copies. Mere interaction with a user through 101 a computer network, with no transfer of a copy, is not conveying. 102 103 An interactive user interface displays "Appropriate Legal Notices" 104 to the extent that it includes a convenient and prominently visible 105 feature that (1) displays an appropriate copyright notice, and (2) 106 tells the user that there is no warranty for the work (except to the 107 extent that warranties are provided), that licensees may convey the 108 work under this License, and how to view a copy of this License. If 109 the interface presents a list of user commands or options, such as a 110 menu, 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 115 for making modifications to it. "Object code" means any non-source 116 form of a work. 117 118 A "Standard Interface" means an interface that either is an official 119 standard defined by a recognized standards body, or, in the case of 120 interfaces specified for a particular programming language, one that 121 is widely used among developers working in that language. 122 123 The "System Libraries" of an executable work include anything, other 124 than the work as a whole, that (a) is included in the normal form of 125 packaging a Major Component, but which is not part of that Major 126 Component, and (b) serves only to enable use of the work with that 127 Major Component, or to implement a Standard Interface for which an 128 implementation 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 132 produce 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 135 the source code needed to generate, install, and (for an executable 136 work) run the object code and to modify the work, including scripts to 137 control those activities. However, it does not include the work's 138 System Libraries, or general-purpose tools or generally available free 139 programs which are used unmodified in performing those activities but 140 which are not part of the work. For example, Corresponding Source 141 includes interface definition files associated with source files for 142 the work, and the source code for shared libraries and dynamically 143 linked subprograms that the work is specifically designed to require, 144 such as by intimate data communication or control flow between those 145 subprograms and other parts of the work. 146 147 The Corresponding Source need not include anything that users 148 can regenerate automatically from other parts of the Corresponding 149 Source. 150 151 The Corresponding Source for a work in source code form is that 152 same work. 153 154 2. Basic Permissions. 155 156 All rights granted under this License are granted for the term of 157 copyright on the Program, and are irrevocable provided the stated 158 conditions are met. This License explicitly affirms your unlimited 159 permission to run the unmodified Program. The output from running a 160 covered work is covered by this License only if the output, given its 161 content, constitutes a covered work. This License acknowledges your 162 rights 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 165 convey, without conditions so long as your license otherwise remains 166 in force. You may convey covered works to others for the sole purpose 167 of having them make modifications exclusively for you, or provide you 168 with facilities for running those works, provided that you comply with 169 the terms of this License in conveying all material for which you do 170 not control copyright. Those thus making or running the covered works 171 for you must do so exclusively on your behalf, under your direction 172 and control, on terms that prohibit them from making any copies of 173 your copyrighted material outside their relationship with you. 174 175 Conveying under any other circumstances is permitted solely under 176 the conditions stated below. Sublicensing is not allowed; section 10 177 makes 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 182 measure under any applicable law fulfilling obligations under article 183 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 similar laws prohibiting or restricting circumvention of such 185 measures. 186 187 When you convey a covered work, you waive any legal power to forbid 188 circumvention of technological measures to the extent such circumvention 189 is effected by exercising rights under this License with respect to 190 the covered work, and you disclaim any intention to limit operation or 191 modification of the work as a means of enforcing, against the work's 192 users, your or third parties' legal rights to forbid circumvention of 193 technological measures. 194 195 4. Conveying Verbatim Copies. 196 197 You may convey verbatim copies of the Program's source code as you 198 receive it, in any medium, provided that you conspicuously and 199 appropriately publish on each copy an appropriate copyright notice; 200 keep intact all notices stating that this License and any 201 non-permissive terms added in accord with section 7 apply to the code; 202 keep intact all notices of the absence of any warranty; and give all 203 recipients 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, 206 and 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 211 produce it from the Program, in the form of source code under the 212 terms 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 236 works, which are not by their nature extensions of the covered work, 237 and which are not combined with it such as to form a larger program, 238 in or on a volume of a storage or distribution medium, is called an 239 "aggregate" if the compilation and its resulting copyright are not 240 used to limit the access or legal rights of the compilation's users 241 beyond what the individual works permit. Inclusion of a covered work 242 in an aggregate does not cause this License to apply to the other 243 parts 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 248 of sections 4 and 5, provided that you also convey the 249 machine-readable Corresponding Source under the terms of this License, 250 in 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 294 from the Corresponding Source as a System Library, need not be 295 included in conveying the object code work. 296 297 A "User Product" is either (1) a "consumer product", which means any 298 tangible personal property which is normally used for personal, family, 299 or household purposes, or (2) anything designed or sold for incorporation 300 into a dwelling. In determining whether a product is a consumer product, 301 doubtful cases shall be resolved in favor of coverage. For a particular 302 product received by a particular user, "normally used" refers to a 303 typical or common use of that class of product, regardless of the status 304 of the particular user or of the way in which the particular user 305 actually uses, or expects or is expected to use, the product. A product 306 is a consumer product regardless of whether the product has substantial 307 commercial, industrial or non-consumer uses, unless such uses represent 308 the only significant mode of use of the product. 309 310 "Installation Information" for a User Product means any methods, 311 procedures, authorization keys, or other information required to install 312 and execute modified versions of a covered work in that User Product from 313 a modified version of its Corresponding Source. The information must 314 suffice to ensure that the continued functioning of the modified object 315 code is in no case prevented or interfered with solely because 316 modification has been made. 317 318 If you convey an object code work under this section in, or with, or 319 specifically for use in, a User Product, and the conveying occurs as 320 part of a transaction in which the right of possession and use of the 321 User Product is transferred to the recipient in perpetuity or for a 322 fixed term (regardless of how the transaction is characterized), the 323 Corresponding Source conveyed under this section must be accompanied 324 by the Installation Information. But this requirement does not apply 325 if neither you nor any third party retains the ability to install 326 modified object code on the User Product (for example, the work has 327 been installed in ROM). 328 329 The requirement to provide Installation Information does not include a 330 requirement to continue to provide support service, warranty, or updates 331 for a work that has been modified or installed by the recipient, or for 332 the User Product in which it has been modified or installed. Access to a 333 network may be denied when the modification itself materially and 334 adversely affects the operation of the network or violates the rules and 335 protocols for communication across the network. 336 337 Corresponding Source conveyed, and Installation Information provided, 338 in accord with this section must be in a format that is publicly 339 documented (and with an implementation available to the public in 340 source code form), and must require no special password or key for 341 unpacking, reading or copying. 342 343 7. Additional Terms. 344 345 "Additional permissions" are terms that supplement the terms of this 346 License by making exceptions from one or more of its conditions. 347 Additional permissions that are applicable to the entire Program shall 348 be treated as though they were included in this License, to the extent 349 that they are valid under applicable law. If additional permissions 350 apply only to part of the Program, that part may be used separately 351 under those permissions, but the entire Program remains governed by 352 this License without regard to the additional permissions. 353 354 When you convey a copy of a covered work, you may at your option 355 remove any additional permissions from that copy, or from any part of 356 it. (Additional permissions may be written to require their own 357 removal in certain cases when you modify the work.) You may place 358 additional permissions on material, added by you to a covered work, 359 for which you have or can give appropriate copyright permission. 360 361 Notwithstanding any other provision of this License, for material you 362 add to a covered work, you may (if authorized by the copyright holders of 363 that 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 389 restrictions" within the meaning of section 10. If the Program as you 390 received it, or any part of it, contains a notice stating that it is 391 governed by this License along with a term that is a further 392 restriction, you may remove that term. If a license document contains 393 a further restriction but permits relicensing or conveying under this 394 License, you may add to a covered work material governed by the terms 395 of that license document, provided that the further restriction does 396 not survive such relicensing or conveying. 397 398 If you add terms to a covered work in accord with this section, you 399 must place, in the relevant source files, a statement of the 400 additional terms that apply to those files, or a notice indicating 401 where to find the applicable terms. 402 403 Additional terms, permissive or non-permissive, may be stated in the 404 form of a separately written license, or stated as exceptions; 405 the above requirements apply either way. 406 407 8. Termination. 408 409 You may not propagate or modify a covered work except as expressly 410 provided under this License. Any attempt otherwise to propagate or 411 modify it is void, and will automatically terminate your rights under 412 this License (including any patent licenses granted under the third 413 paragraph of section 11). 414 415 However, if you cease all violation of this License, then your 416 license from a particular copyright holder is reinstated (a) 417 provisionally, unless and until the copyright holder explicitly and 418 finally terminates your license, and (b) permanently, if the copyright 419 holder fails to notify you of the violation by some reasonable means 420 prior to 60 days after the cessation. 421 422 Moreover, your license from a particular copyright holder is 423 reinstated permanently if the copyright holder notifies you of the 424 violation by some reasonable means, this is the first time you have 425 received notice of violation of this License (for any work) from that 426 copyright holder, and you cure the violation prior to 30 days after 427 your receipt of the notice. 428 429 Termination of your rights under this section does not terminate the 430 licenses of parties who have received copies or rights from you under 431 this License. If your rights have been terminated and not permanently 432 reinstated, you do not qualify to receive new licenses for the same 433 material 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 438 run a copy of the Program. Ancillary propagation of a covered work 439 occurring solely as a consequence of using peer-to-peer transmission 440 to receive a copy likewise does not require acceptance. However, 441 nothing other than this License grants you permission to propagate or 442 modify any covered work. These actions infringe copyright if you do 443 not accept this License. Therefore, by modifying or propagating a 444 covered 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 449 receives a license from the original licensors, to run, modify and 450 propagate that work, subject to this License. You are not responsible 451 for enforcing compliance by third parties with this License. 452 453 An "entity transaction" is a transaction transferring control of an 454 organization, or substantially all assets of one, or subdividing an 455 organization, or merging organizations. If propagation of a covered 456 work results from an entity transaction, each party to that 457 transaction who receives a copy of the work also receives whatever 458 licenses to the work the party's predecessor in interest had or could 459 give under the previous paragraph, plus a right to possession of the 460 Corresponding Source of the work from the predecessor in interest, if 461 the predecessor has it or can get it with reasonable efforts. 462 463 You may not impose any further restrictions on the exercise of the 464 rights granted or affirmed under this License. For example, you may 465 not impose a license fee, royalty, or other charge for exercise of 466 rights granted under this License, and you may not initiate litigation 467 (including a cross-claim or counterclaim in a lawsuit) alleging that 468 any patent claim is infringed by making, using, selling, offering for 469 sale, 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 474 License of the Program or a work on which the Program is based. The 475 work thus licensed is called the contributor's "contributor version". 476 477 A contributor's "essential patent claims" are all patent claims 478 owned or controlled by the contributor, whether already acquired or 479 hereafter acquired, that would be infringed by some manner, permitted 480 by this License, of making, using, or selling its contributor version, 481 but do not include claims that would be infringed only as a 482 consequence of further modification of the contributor version. For 483 purposes of this definition, "control" includes the right to grant 484 patent sublicenses in a manner consistent with the requirements of 485 this License. 486 487 Each contributor grants you a non-exclusive, worldwide, royalty-free 488 patent license under the contributor's essential patent claims, to 489 make, use, sell, offer for sale, import and otherwise run, modify and 490 propagate the contents of its contributor version. 491 492 In the following three paragraphs, a "patent license" is any express 493 agreement or commitment, however denominated, not to enforce a patent 494 (such as an express permission to practice a patent or covenant not to 495 sue for patent infringement). To "grant" such a patent license to a 496 party means to make such an agreement or commitment not to enforce a 497 patent against the party. 498 499 If you convey a covered work, knowingly relying on a patent license, 500 and the Corresponding Source of the work is not available for anyone 501 to copy, free of charge and under the terms of this License, through a 502 publicly available network server or other readily accessible means, 503 then you must either (1) cause the Corresponding Source to be so 504 available, or (2) arrange to deprive yourself of the benefit of the 505 patent license for this particular work, or (3) arrange, in a manner 506 consistent with the requirements of this License, to extend the patent 507 license to downstream recipients. "Knowingly relying" means you have 508 actual knowledge that, but for the patent license, your conveying the 509 covered work in a country, or your recipient's use of the covered work 510 in a country, would infringe one or more identifiable patents in that 511 country that you have reason to believe are valid. 512 513 If, pursuant to or in connection with a single transaction or 514 arrangement, you convey, or propagate by procuring conveyance of, a 515 covered work, and grant a patent license to some of the parties 516 receiving the covered work authorizing them to use, propagate, modify 517 or convey a specific copy of the covered work, then the patent license 518 you grant is automatically extended to all recipients of the covered 519 work and works based on it. 520 521 A patent license is "discriminatory" if it does not include within 522 the scope of its coverage, prohibits the exercise of, or is 523 conditioned on the non-exercise of one or more of the rights that are 524 specifically granted under this License. You may not convey a covered 525 work if you are a party to an arrangement with a third party that is 526 in the business of distributing software, under which you make payment 527 to the third party based on the extent of your activity of conveying 528 the work, and under which the third party grants, to any of the 529 parties who would receive the covered work from you, a discriminatory 530 patent license (a) in connection with copies of the covered work 531 conveyed by you (or copies made from those copies), or (b) primarily 532 for and in connection with specific products or compilations that 533 contain the covered work, unless you entered into that arrangement, 534 or that patent license was granted, prior to 28 March 2007. 535 536 Nothing in this License shall be construed as excluding or limiting 537 any implied license or other defenses to infringement that may 538 otherwise 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 543 otherwise) that contradict the conditions of this License, they do not 544 excuse you from the conditions of this License. If you cannot convey a 545 covered work so as to satisfy simultaneously your obligations under this 546 License and any other pertinent obligations, then as a consequence you may 547 not convey it at all. For example, if you agree to terms that obligate you 548 to collect a royalty for further conveying from those to whom you convey 549 the Program, the only way you could satisfy both those terms and this 550 License 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 555 permission to link or combine any covered work with a work licensed 556 under version 3 of the GNU Affero General Public License into a single 557 combined work, and to convey the resulting work. The terms of this 558 License will continue to apply to the part which is the covered work, 559 but the special requirements of the GNU Affero General Public License, 560 section 13, concerning interaction through a network will apply to the 561 combination as such. 562 563 14. Revised Versions of this License. 564 565 The Free Software Foundation may publish revised and/or new versions of 566 the GNU General Public License from time to time. Such new versions will 567 be similar in spirit to the present version, but may differ in detail to 568 address new problems or concerns. 569 570 Each version is given a distinguishing version number. If the 571 Program specifies that a certain numbered version of the GNU General 572 Public License "or any later version" applies to it, you have the 573 option of following the terms and conditions either of that numbered 574 version or of any later version published by the Free Software 575 Foundation. If the Program does not specify a version number of the 576 GNU General Public License, you may choose any version ever published 577 by the Free Software Foundation. 578 579 If the Program specifies that a proxy can decide which future 580 versions of the GNU General Public License can be used, that proxy's 581 public statement of acceptance of a version permanently authorizes you 582 to choose that version for the Program. 583 584 Later license versions may give you additional or different 585 permissions. However, no additional obligations are imposed on any 586 author or copyright holder as a result of your choosing to follow a 587 later version. 588 589 15. Disclaimer of Warranty. 590 591 THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 ALL 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 603 WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 SUCH DAMAGES. 611 612 17. Interpretation of Sections 15 and 16. 613 614 If the disclaimer of warranty and limitation of liability provided 615 above cannot be given local legal effect according to their terms, 616 reviewing courts shall apply local law that most closely approximates 617 an absolute waiver of all civil liability in connection with the 618 Program, unless a warranty or assumption of liability accompanies a 619 copy 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 626 possible use to the public, the best way to achieve this is to make it 627 free 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 630 to attach them to the start of each source file to most effectively 631 state the exclusion of warranty; and each file should have at least 632 the "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 650 Also 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 653 notice 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 660 The hypothetical commands `show w' and `show c' should show the appropriate 661 parts of the General Public License. Of course, your program's commands 662 might 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, 665 if any, to sign a "copyright disclaimer" for the program, if necessary. 666 For 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 670 into proprietary programs. If your program is a subroutine library, you 671 may consider it more useful to permit linking proprietary applications with 672 the library. If this is what you want to do, use the GNU Lesser General 673 Public 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
1 package org.openstreetmap.josm.plugins.opendata.modules.at.gv.data; 2 3 import org.openstreetmap.josm.plugins.opendata.core.datasets.at.AustrianConstants; 4 5 public 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
1 package org.openstreetmap.josm.plugins.opendata.modules.at.gv.data; 2 3 import java.util.Arrays; 4 import java.util.List; 5 6 import javax.swing.JMenu; 7 import javax.swing.JMenuItem; 8 import javax.swing.JSeparator; 9 10 import org.openstreetmap.josm.plugins.opendata.core.actions.DatasetSearchAction; 11 import org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler; 12 import org.openstreetmap.josm.plugins.opendata.core.modules.AbstractModule; 13 import org.openstreetmap.josm.plugins.opendata.core.modules.ModuleInformation; 14 import org.openstreetmap.josm.plugins.opendata.core.platforms.CkanDataPlatform; 15 import org.openstreetmap.josm.plugins.opendata.modules.at.gv.data.datasets.handlers.CastlesPalacesStyriaHandler; 16 import org.openstreetmap.josm.plugins.opendata.modules.at.gv.data.datasets.handlers.DefibrillatorsViennaHandler; 17 import org.openstreetmap.josm.plugins.opendata.modules.at.gv.data.datasets.handlers.DrinkingFountainsViennaHandler; 18 import org.openstreetmap.josm.tools.Logging; 19 20 21 public 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
1 package org.openstreetmap.josm.plugins.opendata.modules.at.gv.data.datasets; 2 3 import org.openstreetmap.josm.plugins.opendata.core.datasets.CkanDataSetHandler; 4 import org.openstreetmap.josm.plugins.opendata.modules.at.gv.data.DataGvAtConstants; 5 6 public 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
1 package org.openstreetmap.josm.plugins.opendata.modules.at.gv.data.datasets.handlers; 2 3 import java.util.Arrays; 4 import java.util.List; 5 6 import org.openstreetmap.josm.data.osm.DataSet; 7 import org.openstreetmap.josm.data.osm.Node; 8 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 9 import org.openstreetmap.josm.plugins.opendata.modules.at.gv.data.datasets.DataGvAtDataSetHandler; 10 import org.openstreetmap.josm.tools.OsmPrimitiveImageProvider; 11 12 public 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
1 package org.openstreetmap.josm.plugins.opendata.modules.at.gv.data.datasets.handlers; 2 3 import java.util.Arrays; 4 import java.util.List; 5 import java.util.stream.Collectors; 6 7 import org.openstreetmap.josm.command.DeleteCommand; 8 import org.openstreetmap.josm.data.osm.DataSet; 9 import org.openstreetmap.josm.data.osm.Node; 10 import org.openstreetmap.josm.data.osm.OsmPrimitive; 11 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 12 import org.openstreetmap.josm.plugins.opendata.modules.at.gv.data.datasets.DataGvAtDataSetHandler; 13 import org.openstreetmap.josm.tools.OsmPrimitiveImageProvider; 14 15 public 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
1 package org.openstreetmap.josm.plugins.opendata.modules.at.gv.data.datasets.handlers; 2 3 import java.util.Arrays; 4 import java.util.List; 5 6 import org.openstreetmap.josm.data.osm.DataSet; 7 import org.openstreetmap.josm.data.osm.Node; 8 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 9 import org.openstreetmap.josm.plugins.opendata.modules.at.gv.data.datasets.DataGvAtDataSetHandler; 10 import org.openstreetmap.josm.tools.OsmPrimitiveImageProvider; 11 12 public 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
6 6 <ant antfile="build.xml" target="@{target}" dir="fr.datagouvfr"/> 7 7 <ant antfile="build.xml" target="@{target}" dir="fr.paris"/> 8 8 <ant antfile="build.xml" target="@{target}" dir="fr.toulouse"/> 9 <ant antfile="build.xml" target="@{target}" dir="at.gv.data"/> 9 10 </sequential> 10 11 </macrodef> 11 12 <target name="dist"> -
plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/OdPlugin.java
3 3 4 4 import java.awt.Image; 5 5 import java.io.File; 6 import java.net.URL;7 6 import java.util.Arrays; 8 import java.util.HashMap;9 7 import java.util.List; 10 import java.util. Map;8 import java.util.stream.Collectors; 11 9 12 10 import javax.swing.ImageIcon; 13 11 import javax.swing.JMenu; … … 18 16 import org.openstreetmap.josm.gui.MainFrame; 19 17 import org.openstreetmap.josm.gui.MainMenu; 20 18 import org.openstreetmap.josm.gui.MapFrame; 21 import org.openstreetmap.josm.gui.MenuScroller;22 19 import org.openstreetmap.josm.gui.preferences.PreferenceSetting; 23 20 import org.openstreetmap.josm.gui.util.GuiHelper; 24 21 import org.openstreetmap.josm.io.session.SessionReader; … … 25 22 import org.openstreetmap.josm.io.session.SessionWriter; 26 23 import org.openstreetmap.josm.plugins.Plugin; 27 24 import org.openstreetmap.josm.plugins.PluginInformation; 28 import org.openstreetmap.josm.plugins.opendata.core.actions.DownloadDataAction;29 25 import org.openstreetmap.josm.plugins.opendata.core.actions.DownloadDataTask; 30 26 import 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;33 27 import org.openstreetmap.josm.plugins.opendata.core.gui.OdDialog; 34 28 import org.openstreetmap.josm.plugins.opendata.core.gui.OdPreferenceSetting; 35 29 import org.openstreetmap.josm.plugins.opendata.core.io.AbstractImporter; … … 46 40 import org.openstreetmap.josm.plugins.opendata.core.io.tabular.OdsImporter; 47 41 import org.openstreetmap.josm.plugins.opendata.core.io.tabular.XlsImporter; 48 42 import org.openstreetmap.josm.plugins.opendata.core.layers.OdDataLayer; 49 import org.openstreetmap.josm.plugins.opendata.core.modules.Module;50 43 import org.openstreetmap.josm.plugins.opendata.core.modules.ModuleHandler; 51 44 import org.openstreetmap.josm.plugins.opendata.core.modules.ModuleInformation; 52 45 import org.openstreetmap.josm.plugins.opendata.core.util.OdUtils; 53 import org.openstreetmap.josm.tools.Pair;54 46 import org.openstreetmap.josm.tools.ResourceProvider; 55 47 56 48 /** … … 107 99 return instance; 108 100 } 109 101 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()); 119 106 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)); 171 110 } 172 111 menu.addSeparator(); 173 112 MainMenu.add(menu, new OpenPreferencesActions()); 174 113 } 175 114 176 p rivatevoid setMenuItemIcon(ImageIcon icon, JMenuItem menuItem) {115 public static void setMenuItemIcon(ImageIcon icon, JMenuItem menuItem) { 177 116 if (icon != null) { 178 117 if (icon.getIconHeight() != 16 || icon.getIconWidth() != 16) { 179 118 icon = new ImageIcon(icon.getImage().getScaledInstance(16, 16, Image.SCALE_DEFAULT)); -
plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/actions/DatasetSearchAction.java
1 package org.openstreetmap.josm.plugins.opendata.core.actions; 2 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 5 import java.awt.event.ActionEvent; 6 import java.awt.event.KeyEvent; 7 8 import org.openstreetmap.josm.actions.JosmAction; 9 import org.openstreetmap.josm.plugins.opendata.core.gui.DatasetSearchDialog; 10 import org.openstreetmap.josm.plugins.opendata.core.platforms.AbstractDataPlatform; 11 import org.openstreetmap.josm.tools.Shortcut; 12 13 public 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
1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.opendata.core.actions; 3 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 4 6 import java.awt.event.ActionEvent; 5 7 import java.net.URL; 6 8 … … 10 12 import org.openstreetmap.josm.gui.MainApplication; 11 13 import org.openstreetmap.josm.plugins.opendata.core.modules.Module; 12 14 import org.openstreetmap.josm.tools.CheckParameterUtil; 15 import org.openstreetmap.josm.tools.Logging; 13 16 14 17 public class DownloadDataAction extends JosmAction { 15 18 16 19 private final URL url; 17 20 21 public DownloadDataAction(String name, URL url) { 22 this(null, name, url); 23 } 24 18 25 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); 20 28 CheckParameterUtil.ensureParameterNotNull(name, "name"); 21 29 CheckParameterUtil.ensureParameterNotNull(url, "url"); 22 putValue(Action.NAME, name);23 putValue("toolbar", ("opendata_download_"+module.getDisplayedName()+"_"+name).toLowerCase().replace(" ", "_"));24 30 this.url = url; 25 31 } 26 32 27 33 @Override 28 34 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()); 29 40 MainApplication.getMenu().openLocation.openUrl(true, url.toString()); 30 41 } 31 42 } -
plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/actions/DownloadDataTask.java
5 5 6 6 import java.io.File; 7 7 import java.io.IOException; 8 import java.util.ArrayList; 9 import java.util.List; 8 10 import java.util.Optional; 11 import java.util.concurrent.CancellationException; 12 import java.util.concurrent.CompletableFuture; 9 13 import java.util.concurrent.Future; 14 import java.util.concurrent.FutureTask; 10 15 import java.util.regex.Pattern; 11 16 12 17 import javax.swing.JOptionPane; … … 17 22 import org.openstreetmap.josm.gui.MainApplication; 18 23 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 19 24 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 25 import org.openstreetmap.josm.io.OsmTransferCanceledException; 26 import org.openstreetmap.josm.io.OsmTransferException; 20 27 import org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler; 21 28 import org.openstreetmap.josm.plugins.opendata.core.datasets.DataSetUpdater; 22 29 import org.openstreetmap.josm.plugins.opendata.core.gui.AskLicenseAgreementDialog; 23 30 import org.openstreetmap.josm.plugins.opendata.core.io.NetworkReader; 31 import org.openstreetmap.josm.plugins.opendata.core.io.UnsupportedDataException; 24 32 import org.openstreetmap.josm.plugins.opendata.core.layers.OdDataLayer; 25 33 import org.openstreetmap.josm.plugins.opendata.core.licenses.License; 26 34 import org.openstreetmap.josm.plugins.opendata.core.modules.Module; 27 35 import org.openstreetmap.josm.plugins.opendata.core.modules.ModuleHandler; 36 import org.openstreetmap.josm.tools.Logging; 28 37 29 38 public class DownloadDataTask extends DownloadOsmTask { 30 39 … … 32 41 33 42 @Override 34 43 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 } 35 50 downloadTask = new InternalDownloadTask(settings, new NetworkReader(url, handler, true), progressMonitor, zoomAfterDownload); 36 51 currentBounds = null; 37 52 if (handler == null || !handler.hasLicenseToBeAccepted() || askLicenseAgreement(handler.getLicense())) { 38 53 return MainApplication.worker.submit(downloadTask); 39 54 } else { 40 return null; 55 CompletableFuture<?> f = CompletableFuture.completedFuture(null); 56 f.completeExceptionally(new CancellationException("License not accepted")); 57 return f; 41 58 } 42 59 } 43 60 44 61 @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) { 47 71 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; 53 75 } 54 76 } 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 55 88 for (String ext : NetworkReader.FILE_AND_ARCHIVE_READERS.keySet()) { 56 89 if (Pattern.compile(".*\\."+ext, Pattern.CASE_INSENSITIVE).matcher(url).matches()) { 57 90 return true; … … 62 95 63 96 @Override 64 97 public String[] getPatterns() { 65 StringBuilder pattern = new StringBuilder(); 98 List<String> acceptedPatterns = new ArrayList<>(); 99 StringBuilder fileExtPattern = new StringBuilder(); 66 100 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('|'); 69 103 } 70 pattern.append('.').append(ext);104 fileExtPattern.append('.').append(ext); 71 105 } 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); 73 114 } 74 115 75 116 @Override … … 77 118 return tr("Download open data"); 78 119 } 79 120 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 80 136 protected class InternalDownloadTask extends DownloadTask { 81 137 82 138 public InternalDownloadTask(DownloadParams settings, NetworkReader reader, ProgressMonitor progressMonitor, boolean zoomAfterDownload) { … … 100 156 DataSetUpdater.updateDataSet(dataSet, handler, associatedFile); 101 157 return new OdDataLayer(dataSet, layerName, associatedFile, handler); 102 158 } 103 }104 159 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 } 111 182 } 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 }118 183 } 119 184 } -
plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/datasets/AbstractDataSetHandler.java
1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.opendata.core.datasets; 3 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 4 6 import java.io.File; 7 import java.io.UnsupportedEncodingException; 5 8 import java.net.MalformedURLException; 6 9 import java.net.URL; 10 import java.net.URLEncoder; 7 11 import java.util.ArrayList; 8 12 import java.util.Collection; 13 import java.util.Collections; 9 14 import java.util.List; 15 import java.util.Objects; 10 16 import java.util.regex.Pattern; 17 import java.util.stream.Collectors; 11 18 19 import javax.swing.Action; 12 20 import javax.swing.ImageIcon; 21 import javax.swing.JComponent; 22 import javax.swing.JMenu; 23 import javax.swing.JMenuItem; 24 import javax.swing.JSeparator; 13 25 14 26 import org.openstreetmap.josm.actions.JosmAction; 15 27 import org.openstreetmap.josm.data.Bounds; … … 19 31 import org.openstreetmap.josm.data.osm.OsmPrimitive; 20 32 import org.openstreetmap.josm.data.preferences.sources.ExtendedSourceEntry; 21 33 import org.openstreetmap.josm.data.preferences.sources.SourceType; 34 import org.openstreetmap.josm.gui.MenuScroller; 22 35 import org.openstreetmap.josm.io.AbstractReader; 36 import org.openstreetmap.josm.plugins.opendata.core.modules.Module; 37 import org.openstreetmap.josm.plugins.opendata.OdPlugin; 23 38 import org.openstreetmap.josm.plugins.opendata.core.OdConstants; 39 import org.openstreetmap.josm.plugins.opendata.core.actions.DownloadDataAction; 40 import org.openstreetmap.josm.plugins.opendata.core.actions.OpenLinkAction; 41 import org.openstreetmap.josm.plugins.opendata.core.actions.ViewLicenseAction; 42 import org.openstreetmap.josm.plugins.opendata.core.gui.ViewLicenseDialog; 24 43 import org.openstreetmap.josm.plugins.opendata.core.io.archive.ArchiveHandler; 25 44 import org.openstreetmap.josm.plugins.opendata.core.io.archive.DefaultArchiveHandler; 26 45 import org.openstreetmap.josm.plugins.opendata.core.io.geographic.DefaultGmlHandler; … … 34 53 import org.openstreetmap.josm.plugins.opendata.core.licenses.License; 35 54 import org.openstreetmap.josm.plugins.opendata.core.util.NamesFrUtils; 36 55 import org.openstreetmap.josm.plugins.opendata.core.util.OdUtils; 56 import org.openstreetmap.josm.tools.Logging; 37 57 import org.openstreetmap.josm.tools.Pair; 58 import org.openstreetmap.josm.tools.Utils; 38 59 39 60 public abstract class AbstractDataSetHandler { 40 61 … … 72 93 } 73 94 74 95 private String name; 96 private String geoToponym; 97 private String maintainer; 98 private String maintainerEmail; 99 private String description; 75 100 private DataSetCategory category; 76 101 private String sourceDate; 77 102 private File associatedFile; … … 176 201 177 202 // --------------------- URLs --------------------- 178 203 204 private List<Pair<String, URL>> dataURLs = new ArrayList<>(); 179 205 private URL dataURL; 180 206 private URL wikiURL; 181 207 private URL localPortalURL; … … 185 211 return dataURL; 186 212 } 187 213 214 public List<Pair<String, URL>> getDataURLs() { 215 return dataURLs; 216 } 217 188 218 public final void setDataURL(URL dataURL) { 189 219 this.dataURL = dataURL; 190 220 } … … 193 223 setDataURL(new URL(dataURL)); 194 224 } 195 225 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 196 238 public URL getWikiURL() { 197 239 return wikiURL; 198 240 } … … 229 271 setNationalPortalURL(new URL(nationalPortalURL)); 230 272 } 231 273 232 public List<Pair<String, URL>> getDataURLs() {233 return null;234 }235 274 236 275 public AbstractReader getReaderForUrl(String url) { 237 276 return null; … … 238 277 } 239 278 240 279 private boolean hasLicenseToBeAccepted = true; 280 private String dataVersion; 241 281 242 282 public final boolean hasLicenseToBeAccepted() { 243 283 return hasLicenseToBeAccepted; … … 377 417 this.name = name; 378 418 } 379 419 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 380 460 public String getLocalPortalIconName() { 381 461 return OdConstants.ICON_CORE_24; 382 462 } … … 534 614 public void notifyActive() { 535 615 // To be overriden when the handler has specific treatments to perform when its layer becomes active 536 616 } 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 } 537 826 } -
plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/datasets/CkanDataSetHandler.java
1 package org.openstreetmap.josm.plugins.opendata.core.datasets; 2 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 5 import java.awt.Component; 6 import java.awt.GridBagLayout; 7 import java.net.InetAddress; 8 import java.net.MalformedURLException; 9 import java.net.URI; 10 import java.net.URISyntaxException; 11 import java.net.URL; 12 import java.util.ArrayList; 13 import java.util.Arrays; 14 import java.util.Collections; 15 import java.util.List; 16 import java.util.Map; 17 import java.util.Objects; 18 import java.util.Set; 19 import java.util.regex.Matcher; 20 import java.util.regex.Pattern; 21 import java.util.stream.Collectors; 22 23 import javax.swing.BorderFactory; 24 import javax.swing.DefaultListCellRenderer; 25 import javax.swing.JComboBox; 26 import javax.swing.JLabel; 27 import javax.swing.JList; 28 import javax.swing.JPanel; 29 30 import org.openstreetmap.josm.data.osm.DataSet; 31 import org.openstreetmap.josm.gui.ExtendedDialog; 32 import org.openstreetmap.josm.gui.MainApplication; 33 import org.openstreetmap.josm.plugins.opendata.core.gui.DialogPrompter; 34 import org.openstreetmap.josm.plugins.opendata.core.gui.CkanResourceCandidateChooser; 35 import org.openstreetmap.josm.plugins.opendata.core.gui.CkanResourceListCellRenderer; 36 import org.openstreetmap.josm.plugins.opendata.core.licenses.License; 37 import org.openstreetmap.josm.plugins.opendata.core.platforms.CkanDataPlatform; 38 import org.openstreetmap.josm.tools.GBC; 39 import org.openstreetmap.josm.tools.Logging; 40 import org.openstreetmap.josm.tools.Pair; 41 42 import eu.trentorise.opendata.jackan.CkanClient; 43 import eu.trentorise.opendata.jackan.exceptions.CkanNotFoundException; 44 import eu.trentorise.opendata.jackan.model.CkanDataset; 45 import eu.trentorise.opendata.jackan.model.CkanResource; 46 47 public 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
1 package org.openstreetmap.josm.plugins.opendata.core.gui; 2 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 5 import java.awt.Component; 6 import java.awt.GridBagLayout; 7 import java.util.List; 8 9 import javax.swing.BorderFactory; 10 import javax.swing.JComboBox; 11 import javax.swing.JLabel; 12 import javax.swing.JPanel; 13 14 import org.openstreetmap.josm.gui.ExtendedDialog; 15 import org.openstreetmap.josm.tools.GBC; 16 17 import eu.trentorise.opendata.jackan.model.CkanResource; 18 19 public 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
1 package org.openstreetmap.josm.plugins.opendata.core.gui; 2 3 import java.awt.Component; 4 5 import javax.swing.DefaultListCellRenderer; 6 import javax.swing.JList; 7 8 import eu.trentorise.opendata.jackan.model.CkanResource; 9 10 public 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
1 package org.openstreetmap.josm.plugins.opendata.core.gui; 2 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 5 import java.awt.Component; 6 import java.io.UnsupportedEncodingException; 7 import java.net.URL; 8 import java.net.URLEncoder; 9 import java.util.ArrayList; 10 import java.util.LinkedHashMap; 11 import java.util.List; 12 import java.util.Map; 13 14 import javax.swing.DefaultListCellRenderer; 15 import javax.swing.JLabel; 16 import javax.swing.JList; 17 import javax.swing.ListCellRenderer; 18 19 import org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler; 20 import org.openstreetmap.josm.tools.Logging; 21 import org.openstreetmap.josm.tools.Pair; 22 import org.openstreetmap.josm.tools.Utils; 23 24 public 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
1 package org.openstreetmap.josm.plugins.opendata.core.gui; 2 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 5 import java.awt.event.ActionEvent; 6 import java.awt.event.MouseEvent; 7 import java.net.URL; 8 import java.util.ArrayList; 9 import java.util.Collection; 10 import java.util.Collections; 11 import java.util.List; 12 import java.awt.Dimension; 13 import java.awt.GridBagLayout; 14 15 import javax.swing.Action; 16 import javax.swing.JLabel; 17 import javax.swing.JPanel; 18 import javax.swing.JPopupMenu; 19 20 import org.openstreetmap.josm.gui.ExtendedDialog; 21 import org.openstreetmap.josm.gui.MainApplication; 22 import org.openstreetmap.josm.gui.widgets.ListPopupMenu; 23 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher; 24 import org.openstreetmap.josm.plugins.opendata.core.actions.DownloadDataAction; 25 import org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler; 26 import org.openstreetmap.josm.plugins.opendata.core.platforms.AbstractDataPlatform; 27 import org.openstreetmap.josm.tools.GBC; 28 29 import org.openstreetmap.josm.plugins.opendata.core.modules.Module; 30 31 public 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
1 package org.openstreetmap.josm.plugins.opendata.core.gui; 2 3 import java.awt.Component; 4 import java.util.Collections; 5 import java.util.List; 6 import java.util.concurrent.Executors; 7 import java.util.concurrent.TimeUnit; 8 import java.util.stream.Collectors; 9 10 import javax.swing.JList; 11 12 import org.openstreetmap.josm.gui.util.GuiHelper; 13 import org.openstreetmap.josm.gui.widgets.SearchTextResultListPanel; 14 import org.openstreetmap.josm.tools.Utils; 15 import org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler; 16 import org.openstreetmap.josm.plugins.opendata.core.platforms.AbstractDataPlatform; 17 import org.openstreetmap.josm.plugins.opendata.core.util.Debouncer; 18 19 public 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
157 157 readerClass = findReaderByContentType(); 158 158 } 159 159 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 ? 161 163 } else if (findReaderByExtension(url) != null) { 162 164 filename = url.substring(url.lastIndexOf('/')+1); 163 165 } -
plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/UnsupportedDataException.java
1 package org.openstreetmap.josm.plugins.opendata.core.io; 2 3 import org.openstreetmap.josm.io.OsmTransferException; 4 5 public 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
124 124 result.add(entry); 125 125 } 126 126 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()) { 128 129 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); 147 132 } 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 }156 133 } 157 134 } 158 135 return result.toArray(new Action[0]); -
plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/licenses/License.java
11 11 12 12 import org.openstreetmap.josm.plugins.opendata.core.util.OdUtils; 13 13 14 public abstractclass License {14 public class License { 15 15 16 16 public static final ODbL ODbL = new ODbL(); 17 17 public static final LOOL LOOL = new LOOL(); … … 21 21 22 22 private Icon icon; 23 23 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 24 44 private static URL getURL(Map<String, URL> map) { 25 45 // Find URL for current language 26 46 String lang = OdUtils.getJosmLanguage(); -
plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/modules/AbstractModule.java
7 7 import java.io.InputStream; 8 8 import java.util.ArrayList; 9 9 import java.util.Collection; 10 import java.util.Collections; 11 import java.util.HashMap; 10 12 import java.util.List; 13 import java.util.Map; 11 14 15 import javax.swing.JMenu; 16 import javax.swing.JMenuItem; 17 12 18 import org.openstreetmap.josm.data.preferences.sources.ExtendedSourceEntry; 13 19 import org.openstreetmap.josm.data.preferences.sources.SourceEntry; 14 20 import org.openstreetmap.josm.data.preferences.sources.SourceProvider; … … 15 21 import org.openstreetmap.josm.plugins.opendata.OdPlugin; 16 22 import org.openstreetmap.josm.plugins.opendata.core.OdConstants; 17 23 import org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler; 24 import org.openstreetmap.josm.plugins.opendata.core.datasets.DataSetCategory; 18 25 import org.openstreetmap.josm.tools.Logging; 19 26 20 27 public abstract class AbstractModule implements Module { … … 35 42 } 36 43 37 44 @Override 45 public void addHandlerClass(Class<? extends AbstractDataSetHandler> handlerClass) { 46 handlers.add(handlerClass); 47 } 48 49 @Override 38 50 public List<Class<? extends AbstractDataSetHandler>> getHandlers() { 39 51 return handlers; 40 52 } 41 53 42 54 @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 43 66 public String getDisplayedName() { 44 67 return info.name; 45 68 } … … 120 143 } 121 144 return instanciatedHandlers; 122 145 } 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 } 123 200 } -
plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/modules/Module.java
3 3 4 4 import java.util.List; 5 5 6 import javax.swing.JMenuItem; 7 6 8 import org.openstreetmap.josm.data.preferences.sources.SourceProvider; 7 9 import org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler; 8 10 … … 10 12 11 13 String getDisplayedName(); 12 14 15 void addHandlerClass(Class<? extends AbstractDataSetHandler> handlerClass); 16 13 17 List<Class<? extends AbstractDataSetHandler>> getHandlers(); 14 18 19 AbstractDataSetHandler findDataSetHandlerForUrl(String url); 20 15 21 List<AbstractDataSetHandler> getNewlyInstanciatedHandlers(); 16 22 17 23 SourceProvider getMapPaintStyleSourceProvider(); … … 19 25 SourceProvider getPresetSourceProvider(); 20 26 21 27 ModuleInformation getModuleInformation(); 28 29 JMenuItem getModuleMenu(); 30 31 List<String> getAcceptedPatterns(); 22 32 } -
plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/platforms/AbstractDataPlatform.java
1 package org.openstreetmap.josm.plugins.opendata.core.platforms; 2 3 import java.util.stream.Stream; 4 5 import org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler; 6 import org.openstreetmap.josm.plugins.opendata.core.modules.Module; 7 8 public 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
1 package org.openstreetmap.josm.plugins.opendata.core.platforms; 2 3 import java.net.URI; 4 import java.util.ArrayList; 5 import java.util.HashMap; 6 import java.util.List; 7 import java.util.Map; 8 import java.util.Optional; 9 import java.util.regex.Matcher; 10 import java.util.regex.Pattern; 11 import java.util.stream.Collectors; 12 import java.util.stream.Stream; 13 14 import org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler; 15 import org.openstreetmap.josm.plugins.opendata.core.datasets.CkanDataSetHandler; 16 import org.openstreetmap.josm.plugins.opendata.core.modules.Module; 17 import org.openstreetmap.josm.tools.Logging; 18 import org.openstreetmap.josm.tools.Pair; 19 20 import eu.trentorise.opendata.jackan.CkanClient; 21 import eu.trentorise.opendata.jackan.exceptions.CkanNotFoundException; 22 import eu.trentorise.opendata.jackan.SearchResults; 23 import eu.trentorise.opendata.jackan.model.CkanDataset; 24 import eu.trentorise.opendata.jackan.model.CkanResource; 25 26 public 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. 2 package org.openstreetmap.josm.plugins.opendata.core.util; 3 4 import java.util.concurrent.ConcurrentHashMap; 5 import java.util.concurrent.Future; 6 import java.util.concurrent.ScheduledExecutorService; 7 import java.util.concurrent.TimeUnit; 8 9 // Taken from wikipedia plugin 10 // TODO: move this to common code 11 public 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 }