sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1732476 - in /sis/branches/JDK8/core: sis-metadata/src/main/java/org/apache/sis/io/wkt/ sis-referencing/src/main/java/org/apache/sis/referencing/operation/ sis-referencing/src/test/java/org/apache/sis/parameter/ sis-referencing/src/test/ja...
Date Fri, 26 Feb 2016 13:21:59 GMT
Author: desruisseaux
Date: Fri Feb 26 13:21:59 2016
New Revision: 1732476

URL: http://svn.apache.org/viewvc?rev=1732476&view=rev
Log:
If FormattableObject.toString() did not provided a valid WKT, append to the string a warning
giving some indications about the problem.

Modified:
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/FormattableObject.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractCoordinateOperation.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/DefaultParameterDescriptorTest.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/AbstractReferenceSystemTest.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/IndexedResourceBundle.java

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/FormattableObject.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/FormattableObject.java?rev=1732476&r1=1732475&r2=1732476&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/FormattableObject.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/FormattableObject.java
[UTF-8] Fri Feb 26 13:21:59 2016
@@ -108,11 +108,13 @@ public abstract class FormattableObject
 
     /**
      * Returns a <cite>Well Known Text</cite> (WKT) or an alternative text representation
for this object.
-     * If this object can not be represented in a standard way, then this method fallbacks
on a non-standard
-     * representation.
+     * If this object can not be represented in a standard way, then this method may fallback
on non-standard
+     * representation, or leave unformattable elements empty and append warnings after the
WKT.
      *
      * <p>By default this method formats this object according the {@link Convention#WKT2_SIMPLIFIED}
rules,
-     * except that Unicode characters are kept <i>as-is</i> (they are not converted
to ASCII).</p>
+     * except that Unicode characters are kept <i>as-is</i> (they are not converted
to ASCII).
+     * Consequently the WKT is not guaranteed to be ISO 19162 compliant.
+     * For stricter conformance, use {@link #toWKT()} instead.</p>
      *
      * @return The Well Known Text (WKT) or an alternative representation of this object.
      */
@@ -124,6 +126,10 @@ public abstract class FormattableObject
     /**
      * Returns a <cite>Well Known Text</cite> (WKT) for this object using the
specified convention.
      * Unicode characters are kept <i>as-is</i> (they are not converted to ASCII).
+     * The returned string may contain non-standard elements or warnings
+     * if this object can not be formatted according the given convention.
+     *
+     * <p>For stricter conformance to ISO 19162 standard, use {@link #toWKT()} or {@link
WKTFormat} instead.</p>
      *
      * @param  convention The WKT convention to use.
      * @return The Well Known Text (WKT) or a pseudo-WKT representation of this object.
@@ -157,6 +163,7 @@ public abstract class FormattableObject
     /**
      * Returns a WKT for this object using the specified convention.
      * If {@code strict} is true, then an exception is thrown if the WKT is not standard-compliant.
+     * If {@code strict} if false, then warnings are appended after the WKT instead.
      *
      * @param  convention  The convention for choosing WKT element names.
      * @param  colorize    {@code true} for applying syntax coloring, or {@code false} otherwise.
@@ -183,6 +190,7 @@ public abstract class FormattableObject
         if (!strict) {
             formatter.transliterator = Transliterator.IDENTITY;
         }
+        formatter.verifyCharacterValidity = strict;
         final String wkt;
         try {
             formatter.append(this);
@@ -197,6 +205,7 @@ public abstract class FormattableObject
                     throw new UnformattableObjectException(warnings.getMessage(n), warnings.getException(n));
                 }
             }
+            formatter.appendWarnings();
             wkt = formatter.toWKT();
         } finally {
             formatter.clear();

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java?rev=1732476&r1=1732475&r2=1732476&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java
[UTF-8] Fri Feb 26 13:21:59 2016
@@ -61,10 +61,13 @@ import org.apache.sis.util.Debug;
 import org.apache.sis.util.Classes;
 import org.apache.sis.util.Numbers;
 import org.apache.sis.util.Localized;
+import org.apache.sis.util.Exceptions;
 import org.apache.sis.util.Characters;
 import org.apache.sis.util.CharSequences;
 import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.resources.Errors;
+import org.apache.sis.util.resources.Vocabulary;
+import org.apache.sis.internal.util.X364;
 import org.apache.sis.internal.util.Citations;
 import org.apache.sis.internal.util.Constants;
 import org.apache.sis.internal.util.PatchedUnitFormat;
@@ -94,7 +97,7 @@ import org.apache.sis.metadata.iso.exten
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
  * @since   0.4
- * @version 0.6
+ * @version 0.7
  * @module
  *
  * @see <a href="http://docs.opengeospatial.org/is/12-063r5/12-063r5.html">WKT 2 specification</a>
@@ -179,10 +182,18 @@ public class Formatter implements Locali
      * {@link Transliterator#IDENTITY} for preserving non-ASCII characters. The default value
is
      * {@link Transliterator#DEFAULT}, which causes replacements like "é" → "e" in all
elements
      * except {@code REMARKS["…"]}. May also be a user-supplied transliterator.
+     *
+     * @see #getTransliterator()
      */
     Transliterator transliterator;
 
     /**
+     * {@code true} if this {@code Formatter} should verify the validity of characters in
quoted texts.
+     * ISO 19162 restricts quoted texts to ASCII characters with addition of degree symbol
(°).
+     */
+    boolean verifyCharacterValidity = true;
+
+    /**
      * The enclosing WKT element being formatted.
      *
      * @see #getEnclosingElement(int)
@@ -1015,25 +1026,27 @@ public class Formatter implements Locali
         final int base = buffer.appendCodePoint(symbols.getOpeningQuote(0)).length();
         if (type != ElementKind.REMARKS) {
             text = transliterator.filter(text);
-            int startAt = 0; // Index of the last space character.
-            final int length = text.length();
-            for (int i = 0; i < length;) {
-                int c = text.codePointAt(i);
-                int n = Character.charCount(c);
-                if (!Characters.isValidWKT(c)) {
-                    final String illegal = text.substring(i, i+n);
-                    while ((i += n) < length) {
-                        c = text.codePointAt(i);
-                        n = Character.charCount(c);
-                        if (c == ' ' || c == '_') break;
+            if (verifyCharacterValidity) {
+                int startAt = 0;                                        // Index of the last
space character.
+                final int length = text.length();
+                for (int i = 0; i < length;) {
+                    int c = text.codePointAt(i);
+                    int n = Character.charCount(c);
+                    if (!Characters.isValidWKT(c)) {
+                        final String illegal = text.substring(i, i+n);
+                        while ((i += n) < length) {
+                            c = text.codePointAt(i);
+                            n = Character.charCount(c);
+                            if (c == ' ' || c == '_') break;
+                        }
+                        warnings().add(Errors.formatInternational(Errors.Keys.IllegalCharacterForFormat_3,
+                                "Well-Known Text", text.substring(startAt, i), illegal),
null, null);
+                        break;
+                    }
+                    i += n;
+                    if (c == ' ' || c == '_') {
+                        startAt = i;
                     }
-                    warnings().add(Errors.formatInternational(Errors.Keys.IllegalCharacterForFormat_3,
-                            "Well-Known Text", text.substring(startAt, i), illegal), null,
null);
-                    break;
-                }
-                i += n;
-                if (c == ' ' || c == '_') {
-                    startAt = i;
                 }
             }
         }
@@ -1607,6 +1620,35 @@ public class Formatter implements Locali
     }
 
     /**
+     * Appends the warnings after the WKT string. If there is no warnings, then this method
does nothing.
+     * If this method is invoked, then it shall be the last method before {@link #toWKT()}.
+     */
+    final void appendWarnings() {
+        final Warnings warnings = this.warnings;                    // Protect against accidental
changes.
+        if (warnings != null) {
+            final StringBuffer buffer = this.buffer;
+            final String ln = System.lineSeparator();
+            buffer.append(ln).append(ln);
+            if (colors != null) {
+                buffer.append(X364.BACKGROUND_RED.sequence()).append(X364.BOLD.sequence()).append('
');
+            }
+            buffer.append(Vocabulary.getResources(locale).getLabel(Vocabulary.Keys.Warnings));
+            if (colors != null) {
+                buffer.append(' ').append(X364.RESET.sequence()).append(X364.FOREGROUND_RED.sequence());
+            }
+            buffer.append(ln);
+            final int n = warnings.getNumMessages();
+            for (int i=0; i<n; i++) {
+                String message = Exceptions.getLocalizedMessage(warnings.getException(i),
locale);
+                if (message == null) {
+                    message = warnings.getMessage(i);
+                }
+                buffer.append("  • ").append(message).append(ln);
+            }
+        }
+    }
+
+    /**
      * Returns the WKT formatted by this object.
      *
      * @return The WKT formatted by this formatter.

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractCoordinateOperation.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractCoordinateOperation.java?rev=1732476&r1=1732475&r2=1732476&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractCoordinateOperation.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractCoordinateOperation.java
[UTF-8] Fri Feb 26 13:21:59 2016
@@ -29,6 +29,7 @@ import org.opengis.util.InternationalStr
 import org.opengis.metadata.Identifier;
 import org.opengis.metadata.extent.Extent;
 import org.opengis.metadata.quality.PositionalAccuracy;
+import org.opengis.referencing.IdentifiedObject;
 import org.opengis.referencing.crs.GeneralDerivedCRS;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
 import org.opengis.referencing.operation.CoordinateOperation;
@@ -844,7 +845,14 @@ check:      for (int isTarget=0; ; isTar
         append(formatter, getSourceCRS(), WKTKeywords.SourceCRS);
         append(formatter, getTargetCRS(), WKTKeywords.TargetCRS);
         formatter.append(DefaultOperationMethod.castOrCopy(getMethod()));
-        final ParameterValueGroup parameters = getParameterValues();
+        ParameterValueGroup parameters;
+        try {
+            parameters = getParameterValues();
+        } catch (UnsupportedOperationException e) {
+            final IdentifiedObject c = getParameterDescriptors();
+            formatter.setInvalidWKT(c != null ? c : this, e);
+            parameters = null;
+        }
         if (parameters != null) {
             formatter.newLine();
             for (final GeneralParameterValue param : parameters.values()) {

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/DefaultParameterDescriptorTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/DefaultParameterDescriptorTest.java?rev=1732476&r1=1732475&r2=1732476&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/DefaultParameterDescriptorTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/DefaultParameterDescriptorTest.java
[UTF-8] Fri Feb 26 13:21:59 2016
@@ -28,6 +28,7 @@ import org.apache.sis.measure.Measuremen
 import org.apache.sis.metadata.iso.ImmutableIdentifier;
 import org.apache.sis.metadata.iso.citation.Citations;
 import org.apache.sis.internal.util.Constants;
+import org.apache.sis.io.wkt.Convention;
 import org.apache.sis.test.DependsOnMethod;
 import org.apache.sis.test.DependsOn;
 import org.apache.sis.test.TestCase;
@@ -42,7 +43,7 @@ import static org.apache.sis.test.Metada
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
  * @since   0.4
- * @version 0.6
+ * @version 0.7
  * @module
  */
 @DependsOn(org.apache.sis.referencing.AbstractIdentifiedObjectTest.class)
@@ -314,7 +315,7 @@ public final strictfp class DefaultParam
         final DefaultParameterDescriptor<Double> descriptor = create("Real number",
4, 8, 5, SI.METRE);
         assertWktEquals("PARAMETER[“Integer param”, 5]", create("Integer param", 4, 8,
5));
         assertWktEquals("PARAMETER[“Real number”, 5.0, LENGTHUNIT[“metre”, 1]]",
descriptor);
-        assertEquals("Parameter[\"Real number\", 5.0, Unit[\"metre\", 1]]", descriptor.toString());
+        assertWktEquals(Convention.WKT2_SIMPLIFIED, "Parameter[“Real number”, 5.0, Unit[“metre”,
1]]", descriptor);
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/AbstractReferenceSystemTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/AbstractReferenceSystemTest.java?rev=1732476&r1=1732475&r2=1732476&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/AbstractReferenceSystemTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/AbstractReferenceSystemTest.java
[UTF-8] Fri Feb 26 13:21:59 2016
@@ -108,9 +108,8 @@ public final strictfp class AbstractRefe
                 new DefaultTemporalExtent()))); // TODO: needs sis-temporal module for testing
that one.
         final AbstractReferenceSystem object = new AbstractReferenceSystem(properties);
 
-        assertEquals(
-                "ReferenceSystem[\"My “object”.\", AUTHORITY[\"EPSG\", \"4326\"]]",
-                object.toString(Convention.WKT1));
+        assertTrue(object.toString(Convention.WKT1).startsWith(
+                "ReferenceSystem[\"My “object”.\", AUTHORITY[\"EPSG\", \"4326\"]]"));
 
         assertWktEquals(Convention.WKT1,
                 "ReferenceSystem[“My \"object\".”, AUTHORITY[“EPSG”, “4326”]]",

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/IndexedResourceBundle.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/IndexedResourceBundle.java?rev=1732476&r1=1732475&r2=1732476&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/IndexedResourceBundle.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/IndexedResourceBundle.java
[UTF-8] Fri Feb 26 13:21:59 2016
@@ -436,7 +436,7 @@ public class IndexedResourceBundle exten
     private static Class<?> getPublicType(Class<?> c) {
         while (!Modifier.isPublic(c.getModifiers())) {
             for (final Class<?> type : c.getInterfaces()) {
-                if (Modifier.isPublic(type.getModifiers())) {
+                if (Modifier.isPublic(type.getModifiers()) && !type.getName().startsWith("java"))
{
                     return type;
                 }
             }



Mime
View raw message