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 2023/01/17 17:56:28 UTC
[sis] 01/01: Handle characters for the "File reference" column of EPSG database that are illegal according URI syntax.
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 186c01efb99922d744fc6c925b58c940b6e7ab04
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Tue Jan 17 18:55:34 2023 +0100
Handle characters for the "File reference" column of EPSG database that are illegal according URI syntax.
---
.../sis/referencing/factory/sql/EPSGDataAccess.java | 13 +++++++++----
.../apache/sis/util/resources/IndexedResourceBundle.java | 15 +++++++++------
2 files changed, 18 insertions(+), 10 deletions(-)
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGDataAccess.java b/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGDataAccess.java
index 46658ed855..aa33a6cbf6 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGDataAccess.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGDataAccess.java
@@ -2728,8 +2728,12 @@ next: while (r.next()) {
String reference;
if (Double.isNaN(value)) {
/*
- * If no numeric values were provided in the database, then the values should be
- * in some external file. It may be a file in the $SIS_DATA/DatumChanges directory.
+ * If no numeric value was provided in the database, then the values should be in
+ * an external file. It may be a file in the "$SIS_DATA/DatumChanges" directory.
+ * The reference file should be relative and _not_ encoded for valid URI syntax.
+ * The encoding will be applied by invoking an `URI` multi-argument constructor.
+ * Note that we must use a multi-arguments constructor, not URI(String), because
+ * the latter assumes an encoded string (which is not the case in EPSG database).
*/
reference = getString(operation, result, 3);
} else {
@@ -2744,13 +2748,14 @@ next: while (r.next()) {
}
try {
if (reference != null) {
- param.setValue(reference);
+ param.setValue(new URI(null, reference, null)); // See above comment.
} else if (unit != null) {
param.setValue(value, unit);
} else {
param.setValue(value);
}
- } catch (RuntimeException exception) { // Catch InvalidParameterValueException, ArithmeticException and others.
+ } catch (RuntimeException | URISyntaxException exception) {
+ // Catch InvalidParameterValueException, ArithmeticException and others.
throw new FactoryDataException(error().getString(Errors.Keys.CanNotSetParameterValue_1, name), exception);
}
}
diff --git a/core/sis-utility/src/main/java/org/apache/sis/util/resources/IndexedResourceBundle.java b/core/sis-utility/src/main/java/org/apache/sis/util/resources/IndexedResourceBundle.java
index ef618c53a4..03c87279d1 100644
--- a/core/sis-utility/src/main/java/org/apache/sis/util/resources/IndexedResourceBundle.java
+++ b/core/sis-utility/src/main/java/org/apache/sis/util/resources/IndexedResourceBundle.java
@@ -16,6 +16,7 @@
*/
package org.apache.sis.util.resources;
+import java.net.URI;
import java.net.URL;
import java.io.BufferedInputStream;
import java.io.DataInputStream;
@@ -424,12 +425,8 @@ public class IndexedResourceBundle extends ResourceBundle implements Localized {
text = ((InternationalString) element).toString(getLocale());
}
replacement = CharSequences.shortSentence(text, MAX_STRING_LENGTH);
- } else if (element instanceof Throwable) {
- String message = Exceptions.getLocalizedMessage((Throwable) element, getLocale());
- if (message == null) {
- message = Classes.getShortClassName(element);
- }
- replacement = message;
+ } else if (element instanceof URI) {
+ replacement = ((URI) element).getPath(); // For decoding encoded characters.
} else if (element instanceof Class<?>) {
replacement = Classes.getShortName(getPublicType((Class<?>) element));
} else if (element instanceof ControlledVocabulary) {
@@ -443,6 +440,12 @@ public class IndexedResourceBundle extends ResourceBundle implements Localized {
replacement = s;
} else if (element.getClass().isArray()) {
replacement = Utilities.deepToString(element);
+ } else if (element instanceof Throwable) {
+ String message = Exceptions.getLocalizedMessage((Throwable) element, getLocale());
+ if (message == null) {
+ message = Classes.getShortClassName(element);
+ }
+ replacement = message;
}
/*
* No need to check for Numbers or Dates instances, since they are