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 2019/02/14 15:11:32 UTC
[sis] 01/02: Ignore blank strings in some netCDF attributes.
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 ab396495f8f820db4a96365e3fc22c4ebcc73033
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Thu Feb 14 15:24:50 2019 +0100
Ignore blank strings in some netCDF attributes.
---
.../main/java/org/apache/sis/internal/netcdf/Variable.java | 13 +++++++++----
.../org/apache/sis/internal/netcdf/impl/VariableInfo.java | 14 +++++++++-----
.../java/org/apache/sis/storage/netcdf/MetadataReader.java | 2 +-
3 files changed, 19 insertions(+), 10 deletions(-)
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Variable.java b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Variable.java
index 7cada80..5595ff1 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Variable.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Variable.java
@@ -427,15 +427,20 @@ public abstract class Variable extends NamedElement {
}
/**
- * Returns the value of the given attribute as a string. This is a convenience method
- * for {@link #getAttributeValues(String, boolean)} when a singleton value is expected.
+ * Returns the value of the given attribute as a non-blank string and leading/trailing spaces removed.
+ * This is a convenience method for {@link #getAttributeValues(String, boolean)} when a singleton value
+ * is expected and blank strings ignored.
*
* @param attributeName the name of the attribute for which to get the value.
- * @return the singleton attribute value, or {@code null} if none or ambiguous.
+ * @return the singleton attribute value, or {@code null} if none, empty, blank or ambiguous.
*/
public String getAttributeAsString(final String attributeName) {
final Object value = getAttributeValue(attributeName, false);
- return (value != null) ? value.toString() : null;
+ if (value != null) {
+ final String text = value.toString().trim();
+ if (!text.isEmpty()) return text;
+ }
+ return null;
}
/**
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java
index 44d29c1..ac2af88 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java
@@ -376,9 +376,9 @@ final class VariableInfo extends Variable implements Comparable<VariableInfo> {
@Override
public String getDescription() {
for (final String attributeName : DESCRIPTION_ATTRIBUTES) {
- final Object value = getAttributeValue(attributeName);
- if (value instanceof String) {
- return (String) value;
+ final String value = getAttributeAsString(attributeName);
+ if (value != null) {
+ return value;
}
}
return null;
@@ -580,12 +580,16 @@ final class VariableInfo extends Variable implements Comparable<VariableInfo> {
}
/**
- * Returns the value of the given attribute as a string, or {@code null} if none.
+ * Returns the value of the given attribute as a non-blank string, or {@code null} if none.
*/
@Override
public String getAttributeAsString(final String attributeName) {
final Object value = getAttributeValue(attributeName);
- return (value instanceof String) ? (String) value : null;
+ if (value instanceof String) {
+ final String text = ((String) value).trim();
+ if (!text.isEmpty()) return text;
+ }
+ return null;
}
/**
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java b/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java
index b0abc0b..0eb9714 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java
@@ -947,7 +947,7 @@ split: while ((start = CharSequences.skipLeadingWhitespaces(value, start, lengt
final NameFactory f = decoder.nameFactory;
setBandIdentifier(f.createMemberName(null, name, f.createTypeName(null, variable.getDataTypeName())));
}
- final String id = trim(variable.getAttributeAsString(CF.STANDARD_NAME));
+ final String id = variable.getAttributeAsString(CF.STANDARD_NAME);
if (id != null && !id.equals(name)) {
addBandName(variable.getAttributeAsString(ACDD.standard_name_vocabulary), id);
}