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 8a881f42c4a704f392934ba23c8b66331e379789
Author: Martin Desruisseaux <martin.desruisse...@geomatys.com>
AuthorDate: Wed May 4 10:37:21 2022 +0200

    Leverage more a simple helper method for getting the filename without 
suffix.
---
 .../main/java/org/apache/sis/internal/storage/csv/Store.java  |  6 +-----
 .../apache/sis/internal/storage/image/WorldFileResource.java  | 11 ++++++++++-
 .../src/main/java/org/apache/sis/storage/DataStore.java       |  2 +-
 .../src/main/java/org/apache/sis/storage/FeatureNaming.java   |  1 +
 4 files changed, 13 insertions(+), 7 deletions(-)

diff --git 
a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/csv/Store.java
 
b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/csv/Store.java
index 7580d9ce41..50fd6de7b7 100644
--- 
a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/csv/Store.java
+++ 
b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/csv/Store.java
@@ -578,11 +578,7 @@ final class Store extends URIDataStore implements 
FeatureSet {
             }
             properties.add(createProperty(name, type, minOccurrence, 
maxOccurrence, characteristics));
         }
-        String name = super.getDisplayName();
-        final int s = name.lastIndexOf('.');
-        if (s > 0) {                            // Exclude 0 because shall not 
be the first character.
-            name = name.substring(0, s);
-        }
+        final String name = 
IOUtilities.filenameWithoutExtension(super.getDisplayName());
         return new 
DefaultFeatureType(Collections.singletonMap(DefaultFeatureType.NAME_KEY, name),
                 false, null, properties.toArray(new 
PropertyType[properties.size()]));
     }
diff --git 
a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/image/WorldFileResource.java
 
b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/image/WorldFileResource.java
index 57dee0fc58..467cce78cc 100644
--- 
a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/image/WorldFileResource.java
+++ 
b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/image/WorldFileResource.java
@@ -44,6 +44,7 @@ import org.apache.sis.storage.event.StoreListeners;
 import org.apache.sis.internal.storage.Resources;
 import org.apache.sis.internal.storage.StoreResource;
 import org.apache.sis.internal.storage.RangeArgument;
+import org.apache.sis.internal.storage.io.IOUtilities;
 import org.apache.sis.internal.coverage.j2d.ImageUtilities;
 import org.apache.sis.internal.util.UnmodifiableArrayList;
 import org.apache.sis.util.resources.Vocabulary;
@@ -179,7 +180,15 @@ class WorldFileResource extends 
AbstractGridCoverageResource implements StoreRes
                     }
                     id = base + n;
                 }
-                identifier = Names.createLocalName(store.getDisplayName(), 
null, id);
+                /*
+                 * Get the filename and omit the extension. The `store.suffix` 
field is null if the input
+                 * source was not a File/Path/URI/URL, in which case we do not 
try to trim the extension.
+                 */
+                String filename = store.getDisplayName();
+                if (store.suffix != null) {
+                    filename = IOUtilities.filenameWithoutExtension(filename);
+                }
+                identifier = Names.createLocalName(filename, null, id);
             }
             return Optional.of(identifier);
         }
diff --git 
a/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStore.java 
b/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStore.java
index 8d5e6e0abb..5731e5f275 100644
--- a/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStore.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStore.java
@@ -263,7 +263,7 @@ public abstract class DataStore implements Resource, 
Localized, AutoCloseable {
      * in identifiers like white spaces.</p>
      *
      * <p>This method should never throw an exception since it may be invoked 
for producing error
-     * messages, in which case throwing an exception here would mask the 
original exception.</p>
+     * messages, in which case throwing an exception here would hide the 
original exception.</p>
      *
      * <p>This method differs from {@link #getIdentifier()} in that it is 
typically a file name
      * known at construction time instead of a property read from metadata.
diff --git 
a/storage/sis-storage/src/main/java/org/apache/sis/storage/FeatureNaming.java 
b/storage/sis-storage/src/main/java/org/apache/sis/storage/FeatureNaming.java
index 69f0668102..82b8f23c9e 100644
--- 
a/storage/sis-storage/src/main/java/org/apache/sis/storage/FeatureNaming.java
+++ 
b/storage/sis-storage/src/main/java/org/apache/sis/storage/FeatureNaming.java
@@ -128,6 +128,7 @@ public class FeatureNaming<E> {
     /**
      * Returns the display name for the given data store, or the localizable 
"unnamed" string
      * if the given data store is null or does not have a display name.
+     * This is used for error message in exceptions.
      */
     private static CharSequence name(final DataStore store) {
         if (store != null) {

Reply via email to