You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2021/09/29 14:36:05 UTC

[sis] 01/02: Add the possibility to download automatically EPSG data if user agrees with EPSG terms of use.

This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git

commit 1e93fa3961a9ac36f3e7f0a267f1b88377c5556c
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Wed Sep 29 15:46:12 2021 +0200

    Add the possibility to download automatically EPSG data if user agrees with EPSG terms of use.
---
 application/sis-javafx/doc/readme.txt              |  6 +-
 application/sis-javafx/pom.xml                     | 12 +++-
 application/sis-javafx/src/main/artifact/bin/sisfx |  2 +-
 .../sis-javafx/src/main/artifact/bin/sisfx.bat     |  2 +-
 .../main/java/org/apache/sis/gui/DataViewer.java   | 17 +++++
 .../apache/sis/internal/gui/BackgroundThreads.java | 26 +++++++
 .../sis/internal/gui/OptionalDataDownloader.java   | 84 ++++++++++++++++++++++
 .../org/apache/sis/internal/gui/Resources.java     | 21 ++++++
 .../apache/sis/internal/gui/Resources.properties   |  4 ++
 .../sis/internal/gui/Resources_fr.properties       |  4 ++
 .../org.apache.sis.setup.InstallationResources     |  3 +
 11 files changed, 173 insertions(+), 8 deletions(-)

diff --git a/application/sis-javafx/doc/readme.txt b/application/sis-javafx/doc/readme.txt
index 279505e..ba6acfb 100644
--- a/application/sis-javafx/doc/readme.txt
+++ b/application/sis-javafx/doc/readme.txt
@@ -12,8 +12,8 @@ NetBeans Ant project, open the following file:
 
 And add the following lines:
 
-    javac.source     = 14
-    javac.target     = 14
+    javac.source     = 17
+    javac.target     = 17
     javac.modulepath = /path/to/my/install/javafx-sdk/lib
-    javafx.options   = --add-modules javafx.graphics,javafx.controls,javafx.fxml
+    javafx.options   = --add-modules javafx.graphics,javafx.controls,javafx.web
     src.javafx.dir   = ${project.root}/application/sis-javafx/src/main/java
diff --git a/application/sis-javafx/pom.xml b/application/sis-javafx/pom.xml
index 995a99f..44ad128 100644
--- a/application/sis-javafx/pom.xml
+++ b/application/sis-javafx/pom.xml
@@ -212,6 +212,12 @@
           <version>${javafx.version}</version>
           <scope>provided</scope>
         </dependency>
+        <dependency>
+          <groupId>org.openjfx</groupId>
+          <artifactId>javafx-web</artifactId>
+          <version>${javafx.version}</version>
+          <scope>provided</scope>
+        </dependency>
       </dependencies>
     </profile>
 
@@ -230,7 +236,7 @@
             <configuration>
               <compilerArgs>
                 <arg>--module-path</arg> <arg>${env.PATH_TO_FX}</arg>
-                <arg>--add-modules</arg> <arg>javafx.graphics,javafx.controls</arg>
+                <arg>--add-modules</arg> <arg>javafx.graphics,javafx.controls,javafx.web</arg>
               </compilerArgs>
             </configuration>
           </plugin>
@@ -238,7 +244,7 @@
             <artifactId>maven-surefire-plugin</artifactId>
             <configuration>
               <argLine>
-                --module-path ${env.PATH_TO_FX} --add-modules javafx.graphics,javafx.controls
+                --module-path ${env.PATH_TO_FX} --add-modules javafx.graphics,javafx.controls,javafx.web
               </argLine>
             </configuration>
           </plugin>
@@ -249,7 +255,7 @@
                 <additionalJOption>--module-path</additionalJOption>
                 <additionalJOption>${env.PATH_TO_FX}</additionalJOption>
                 <additionalJOption>--add-modules</additionalJOption>
-                <additionalJOption>javafx.graphics,javafx.controls</additionalJOption>
+                <additionalJOption>javafx.graphics,javafx.controls,javafx.web</additionalJOption>
               </additionalJOptions>
             </configuration>
           </plugin>
diff --git a/application/sis-javafx/src/main/artifact/bin/sisfx b/application/sis-javafx/src/main/artifact/bin/sisfx
index fe4dfbe..82df3c8 100755
--- a/application/sis-javafx/src/main/artifact/bin/sisfx
+++ b/application/sis-javafx/src/main/artifact/bin/sisfx
@@ -36,7 +36,7 @@ fi
 
 # Execute SIS with any optional JAR that the user may put in the `lib` directory.
 java -splash:"$BASE_DIR/lib/logo.jpg" \
-     --add-modules javafx.graphics,javafx.controls \
+     --add-modules javafx.graphics,javafx.controls,javafx.web \
      --module-path "$PATH_TO_FX" \
      --class-path "$BASE_DIR/lib/*" \
      -Djava.util.logging.config.class="org.apache.sis.internal.setup.LoggingConfiguration" \
diff --git a/application/sis-javafx/src/main/artifact/bin/sisfx.bat b/application/sis-javafx/src/main/artifact/bin/sisfx.bat
index eb1126e..2c12cb0 100644
--- a/application/sis-javafx/src/main/artifact/bin/sisfx.bat
+++ b/application/sis-javafx/src/main/artifact/bin/sisfx.bat
@@ -27,7 +27,7 @@ IF "%PATH_TO_FX%"=="" (
 )
 
 java -splash:"%BASE_DIR%\lib\logo.jpg"^
- --add-modules javafx.graphics,javafx.controls^
+ --add-modules javafx.graphics,javafx.controls,javafx.web^
  --module-path "%PATH_TO_FX%"^
  --class-path "%BASE_DIR%\lib\*"^
  -Djava.util.logging.config.class=org.apache.sis.internal.setup.LoggingConfiguration^
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/DataViewer.java b/application/sis-javafx/src/main/java/org/apache/sis/gui/DataViewer.java
index 08d9bbc..bd0eee2 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/gui/DataViewer.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/DataViewer.java
@@ -65,6 +65,11 @@ import org.apache.sis.util.resources.Vocabulary;
  */
 public class DataViewer extends Application {
     /**
+     * The application being executed, or {@code null} if none.
+     */
+    private static volatile DataViewer running;
+
+    /**
      * Starts the Apache SIS application.
      *
      * @param args  ignored.
@@ -195,6 +200,7 @@ public class DataViewer extends Application {
         if (sp != null) {
             sp.close();
         }
+        running = this;
     }
 
     /**
@@ -300,9 +306,20 @@ public class DataViewer extends Application {
      */
     @Override
     public void stop() throws Exception {
+        running = null;
         LogHandler.register(false);
         BackgroundThreads.stop();
         RecentChoices.saveReferenceSystems();
         super.stop();
     }
+
+    /**
+     * Returns the window in which the application is running, or {@code null} if the application is not running.
+     *
+     * @return the window in which the application is running, or {@code null}.
+     */
+    public static Stage getCurrentStage() {
+        final DataViewer r = running;
+        return (r != null) ? r.window : null;
+    }
 }
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/BackgroundThreads.java b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/BackgroundThreads.java
index bb5ea2e..312292f 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/BackgroundThreads.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/BackgroundThreads.java
@@ -16,14 +16,18 @@
  */
 package org.apache.sis.internal.gui;
 
+import java.util.concurrent.Callable;
 import java.util.concurrent.Executor;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ExecutorService;
+import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ThreadFactory;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.FutureTask;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.atomic.AtomicInteger;
 import javafx.application.Platform;
+import org.apache.sis.gui.DataViewer;
 import org.apache.sis.internal.system.Modules;
 import org.apache.sis.internal.system.Threads;
 import org.apache.sis.util.logging.Logging;
@@ -115,6 +119,28 @@ public final class BackgroundThreads extends AtomicInteger implements ThreadFact
     }
 
     /**
+     * Runs the given task in JavaFX thread and wait for completion before to return.
+     * This method should <em>not</em> be invoked from JavaFX application thread.
+     * This method can be used for showing a dialog box during a background operation.
+     *
+     * @param  <V>   type of result that will be returned.
+     * @param  task  the task to execute in JavaFX thread.
+     * @return the task result, or {@code null} if an error occurred.
+     */
+    public static <V> V runAndWait(final Callable<V> task) {
+        final FutureTask<V> f = new FutureTask<>(task);
+        Platform.runLater(f);
+        try {
+            return f.get();
+        } catch (ExecutionException e) {
+            ExceptionReporter.show(DataViewer.getCurrentStage(), null, null, e.getCause());
+        } catch (InterruptedException e) {
+            interrupted("runAndWait", e);
+        }
+        return null;
+    }
+
+    /**
      * Invoked at application shutdown time for stopping the executor threads after they completed their tasks.
      * This method returns soon but the background threads may continue for some time if they did not finished
      * their task yet.
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/OptionalDataDownloader.java b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/OptionalDataDownloader.java
new file mode 100644
index 0000000..dff857a
--- /dev/null
+++ b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/OptionalDataDownloader.java
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.internal.gui;
+
+import javafx.application.Platform;
+import javafx.scene.control.Alert;
+import javafx.scene.control.ButtonType;
+import javafx.scene.control.DialogPane;
+import javafx.scene.web.WebView;
+import org.apache.sis.gui.DataViewer;
+import org.apache.sis.internal.system.Fallback;
+import org.apache.sis.setup.OptionalInstallations;
+
+
+/**
+ * A provider for data licensed under different terms of use than the Apache license.
+ * This class is automatically instantiated and executed when EPSG data are missing.
+ * It popups a dialog box proposing to the user to download the data, if (s)he accepts
+ * the EPSG terms of use.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @version 1.1
+ * @since   1.1
+ * @module
+ */
+@Fallback
+public final class OptionalDataDownloader extends OptionalInstallations {
+    /**
+     * Creates a new installation scripts provider.
+     */
+    public OptionalDataDownloader() {
+        super("text/html");
+    }
+
+    /**
+     * Asks to the user if (s)he agree to download and install the resource for the given authority.
+     * This method may be invoked twice for the same {@code authority} argument:
+     * first with a null {@code license} argument for asking if the user agrees to download the data,
+     * then with a non-null {@code license} argument for asking if the user agrees with the license terms.
+     */
+    @Override
+    protected boolean askUserAgreement(final String authority, final String license) {
+        if (!Platform.isFxApplicationThread()) {
+            return BackgroundThreads.runAndWait(() -> {
+                return askUserAgreement(authority, license);
+            });
+        }
+        final Resources resources = Resources.forLocale(getLocale());
+        final Alert dialog;
+        dialog = new Alert(Alert.AlertType.CONFIRMATION, null, ButtonType.NO, ButtonType.YES);
+        dialog.initOwner(DataViewer.getCurrentStage());
+        dialog.setTitle(resources.getString(Resources.Keys.GeodeticDataset_1, authority));
+        dialog.setResizable(true);
+        if (license == null) {
+            dialog.getDialogPane().setPrefWidth(600);
+            dialog.setHeaderText(resources.getString(Resources.Keys.DownloadAndInstall_1, authority));
+            dialog.setContentText(resources.getString(Resources.Keys.DownloadDetails_3,
+                    authority, getSpaceRequirement(authority), destinationDirectory));
+        } else {
+            final WebView content = new WebView();
+            content.getEngine().loadContent(license);
+            final DialogPane pane = dialog.getDialogPane();
+            pane.setContent(content);
+            pane.setPrefWidth(800);
+            pane.setPrefHeight(600);
+            dialog.setHeaderText(resources.getString(Resources.Keys.LicenseAgreement));
+        }
+        return dialog.showAndWait().orElse(ButtonType.NO) == ButtonType.YES;
+    }
+}
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources.java b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources.java
index c983d43..dbee944 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources.java
@@ -166,6 +166,17 @@ public final class Resources extends IndexedResourceBundle {
         public static final short DoesNotCoverAOI = 13;
 
         /**
+         * Download and install {0} database?
+         */
+        public static final short DownloadAndInstall_1 = 58;
+
+        /**
+         * This geodetic dataset is required for the support of Coordinate Reference Systems defined by
+         * {0} codes. The database will use {1} Mb in directory {2}.
+         */
+        public static final short DownloadDetails_3 = 59;
+
+        /**
          * An error occurred at the following location:
          */
         public static final short ErrorAt = 53;
@@ -211,6 +222,11 @@ public final class Resources extends IndexedResourceBundle {
         public static final short FullScreen = 22;
 
         /**
+         * {0} geodetic dataset
+         */
+        public static final short GeodeticDataset_1 = 60;
+
+        /**
          * Geospatial data files
          */
         public static final short GeospatialFiles = 23;
@@ -237,6 +253,11 @@ public final class Resources extends IndexedResourceBundle {
         public static final short IsolinesInRange = 57;
 
         /**
+         * Do you accept the license shown below?
+         */
+        public static final short LicenseAgreement = 61;
+
+        /**
          * Loading…
          */
         public static final short Loading = 24;
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources.properties b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources.properties
index 179baf0..1ece0b8 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources.properties
+++ b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources.properties
@@ -42,6 +42,8 @@ CopyFilePath           = Copy file path
 DisplayedSize          = Displayed size
 DisplayStart           = Display start
 DoesNotCoverAOI        = Does not cover the area of interest.
+DownloadAndInstall_1   = Download and install {0} database?
+DownloadDetails_3      = This geodetic dataset is required for the support of Coordinate Reference Systems defined by {0} codes. The database will use {1} Mb in directory {2}.
 ErrorDetails           = Details about error
 ErrorExportingData     = Error exporting data
 ErrorOpeningFile       = Error opening file
@@ -51,11 +53,13 @@ ErrorDataAccess        = Error during data access
 ErrorAt                = An error occurred at the following location:
 Exit                   = Exit
 FullScreen             = Full screen
+GeodeticDataset_1      = {0} geodetic dataset
 GeospatialFiles        = Geospatial data files
 Help                   = Help
 ImageStart             = Image start
 InconsistencyIn_2      = {0} \u2013 inconsistency in `{1}` property
 IsolinesInRange        = Generate isolines at constant interval\nstarting from given minimum.
+LicenseAgreement       = Do you accept the license shown below?
 Loading                = Loading\u2026
 Mercator               = Mercator
 MainWindow             = Main window
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources_fr.properties b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources_fr.properties
index f13048f..2998cd0 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources_fr.properties
+++ b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources_fr.properties
@@ -47,6 +47,8 @@ CopyFilePath           = Copier le chemin du fichier
 DisplayedSize          = Taille affich\u00e9e
 DisplayStart           = D\u00e9but de l\u2019affichage
 DoesNotCoverAOI        = Ne couvre pas la r\u00e9gion d\u2019int\u00e9r\u00eat.
+DownloadAndInstall_1   = T\u00e9l\u00e9charger et installer la base de donn\u00e9es {0}?
+DownloadDetails_3      = Cette base de donn\u00e9es est n\u00e9cessaire pour le support des syst\u00e8mes de r\u00e9f\u00e9rences d\u00e9finis par des codes {0}. La base occupera {1} Mo dans le r\u00e9pertoire {2}.
 ErrorDetails           = D\u00e9tails \u00e0 propos de l\u2019erreur
 ErrorExportingData     = Erreur \u00e0 l\u2019exportation de donn\u00e9es
 ErrorOpeningFile       = Erreur \u00e0 l\u2019ouverture du fichier
@@ -56,11 +58,13 @@ ErrorDataAccess        = Erreur lors de l\u2019acc\u00e8s \u00e0 la donn\u00e9e
 ErrorAt                = Une erreur est survenue \u00e0 l\u2019endroit suivant\u00a0:
 Exit                   = Quitter
 FullScreen             = Plein \u00e9cran
+GeodeticDataset_1      = Base de donn\u00e9es g\u00e9od\u00e9siques {0}
 GeospatialFiles        = Fichiers de donn\u00e9es g\u00e9ospatiales
 Help                   = Aide
 ImageStart             = D\u00e9but de l\u2019image
 InconsistencyIn_2      = {0} \u2013 incoh\u00e9rence dans la propri\u00e9t\u00e9 `{1}`
 IsolinesInRange        = G\u00e9n\u00e8re des isolignes \u00e0 intervalle constant en\ncommen\u00e7ant \u00e0 la valeur minimale sp\u00e9cifi\u00e9e.
+LicenseAgreement       = Acceptez-vous la licence ci-dessous?
 Loading                = Chargement\u2026
 Mercator               = Mercator
 MainWindow             = Fen\u00eatre principale
diff --git a/application/sis-javafx/src/main/resources/META-INF/services/org.apache.sis.setup.InstallationResources b/application/sis-javafx/src/main/resources/META-INF/services/org.apache.sis.setup.InstallationResources
new file mode 100644
index 0000000..0cdb1b8
--- /dev/null
+++ b/application/sis-javafx/src/main/resources/META-INF/services/org.apache.sis.setup.InstallationResources
@@ -0,0 +1,3 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements;
+# and to You under the Apache License, Version 2.0.
+org.apache.sis.internal.gui.OptionalDataDownloader