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 2016/07/26 16:35:12 UTC
svn commit: r1754157 - in /sis/branches/JDK8:
core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/constraint/
core/sis-metadata/src/test/java/org/apache/sis/test/
storage/sis-storage/src/main/java/org/apache/sis/internal/storage/
storage/sis-st...
Author: desruisseaux
Date: Tue Jul 26 16:35:12 2016
New Revision: 1754157
URL: http://svn.apache.org/viewvc?rev=1754157&view=rev
Log:
Complete the MetadataBuilder.parseLegalNotice(String) helper method.
Added:
sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/MetadataBuilderTest.java (with props)
Modified:
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/constraint/DefaultConstraints.java
sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/test/MetadataAssert.java
sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MetadataBuilder.java
sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/test/suite/StorageTestSuite.java
Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/constraint/DefaultConstraints.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/constraint/DefaultConstraints.java?rev=1754157&r1=1754156&r2=1754157&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/constraint/DefaultConstraints.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/constraint/DefaultConstraints.java [UTF-8] Tue Jul 26 16:35:12 2016
@@ -95,7 +95,7 @@ public class DefaultConstraints extends
private Collection<Citation> references;
/**
- * Citation for the limitation of constraint.
+ * Information concerning the parties to whom the resource can or cannot be released.
*/
private Releasability releasability;
@@ -277,7 +277,7 @@ public class DefaultConstraints extends
/**
* Returns information concerning the parties to whom the resource can or cannot be released.
*
- * @return Information concerning the parties to whom the resource, or {@code null} if none.
+ * @return Information concerning the parties to whom the resource can or cannot be released, or {@code null} if none.
*
* @since 0.5
*/
@@ -290,7 +290,7 @@ public class DefaultConstraints extends
/**
* Sets the information concerning the parties to whom the resource.
*
- * @param newValue The new information concerning the parties to whom the resource.
+ * @param newValue The new information concerning the parties to whom the resource can or cannot be released.
*
* @since 0.5
*/
Modified: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/test/MetadataAssert.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/test/MetadataAssert.java?rev=1754157&r1=1754156&r2=1754157&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/test/MetadataAssert.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/test/MetadataAssert.java [UTF-8] Tue Jul 26 16:35:12 2016
@@ -19,6 +19,7 @@ package org.apache.sis.test;
import java.util.Locale;
import org.opengis.util.InternationalString;
import org.opengis.metadata.citation.Citation;
+import org.opengis.metadata.citation.Responsibility;
import org.opengis.referencing.IdentifiedObject;
import org.apache.sis.io.wkt.Symbols;
import org.apache.sis.io.wkt.WKTFormat;
@@ -31,7 +32,7 @@ import org.apache.sis.io.wkt.Convention;
*
* @author Martin Desruisseaux (Geomatys)
* @since 0.4
- * @version 0.6
+ * @version 0.8
* @module
*/
public strictfp class MetadataAssert extends Assert {
@@ -56,9 +57,9 @@ public strictfp class MetadataAssert ext
/**
* Asserts that the English title of the given citation is equals to the expected string.
*
- * @param message The message to report in case of test failure.
- * @param expected The expected English title.
- * @param citation The citation to test.
+ * @param message the message to report in case of test failure.
+ * @param expected the expected English title.
+ * @param citation the citation to test.
*
* @since 0.6
*
@@ -72,12 +73,30 @@ public strictfp class MetadataAssert ext
}
/**
+ * Asserts that the given citation has only one responsible party,
+ * and its English name is equals to the expected string.
+ *
+ * @param message the message to report in case of test failure.
+ * @param expected the expected English responsibly party name.
+ * @param citation the citation to test.
+ *
+ * @since 0.8
+ */
+ public static void assertPartyNameEquals(final String message, final String expected, final Citation citation) {
+ assertNotNull(message, citation);
+ final Responsibility r = TestUtilities.getSingleton(citation.getCitedResponsibleParties());
+ final InternationalString name = TestUtilities.getSingleton(r.getParties()).getName();
+ assertNotNull(message, name);
+ assertEquals(message, expected, name.toString(Locale.US));
+ }
+
+ /**
* Asserts that the WKT 2 of the given object is equal to the expected one.
* This method expected the {@code \u201c\u2026\u201d} quotation marks instead of {@code "\u2026"}
* for easier readability of {@link String} constants in Java code.
*
- * @param expected The expected text, or {@code null} if {@code object} is expected to be null.
- * @param object The object to format in <cite>Well Known Text</cite> format, or {@code null}.
+ * @param expected the expected text, or {@code null} if {@code object} is expected to be null.
+ * @param object the object to format in <cite>Well Known Text</cite> format, or {@code null}.
*/
public static void assertWktEquals(final String expected, final Object object) {
assertWktEquals(Convention.WKT2, expected, object);
@@ -88,9 +107,9 @@ public strictfp class MetadataAssert ext
* This method expected the {@code \u201c\u2026\u201d} quotation marks instead of {@code "\u2026"} for easier readability of
* {@link String} constants in Java code.
*
- * @param convention The WKT convention to use.
- * @param expected The expected text, or {@code null} if {@code object} is expected to be null.
- * @param object The object to format in <cite>Well Known Text</cite> format, or {@code null}.
+ * @param convention the WKT convention to use.
+ * @param expected the expected text, or {@code null} if {@code object} is expected to be null.
+ * @param object the object to format in <cite>Well Known Text</cite> format, or {@code null}.
*/
public static void assertWktEquals(final Convention convention, final String expected, final Object object) {
if (expected == null) {
@@ -112,9 +131,9 @@ public strictfp class MetadataAssert ext
* This method is like {@link #assertWktEquals(String, Object)}, but the use of regular expression allows some
* tolerance for example on numerical parameter values that may be subject to a limited form of rounding errors.
*
- * @param convention The WKT convention to use.
- * @param expected The expected regular expression, or {@code null} if {@code object} is expected to be null.
- * @param object The object to format in <cite>Well Known Text</cite> format, or {@code null}.
+ * @param convention the WKT convention to use.
+ * @param expected the expected regular expression, or {@code null} if {@code object} is expected to be null.
+ * @param object the object to format in <cite>Well Known Text</cite> format, or {@code null}.
*
* @since 0.6
*/
Modified: sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MetadataBuilder.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MetadataBuilder.java?rev=1754157&r1=1754156&r2=1754157&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MetadataBuilder.java [UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MetadataBuilder.java [UTF-8] Tue Jul 26 16:35:12 2016
@@ -16,19 +16,22 @@
*/
package org.apache.sis.internal.storage;
+import java.util.Date;
import java.util.Collection;
+import java.util.Collections;
import java.nio.charset.Charset;
+import org.opengis.metadata.citation.Role;
+import org.opengis.metadata.citation.DateType;
import org.opengis.metadata.constraint.Restriction;
import org.opengis.referencing.ReferenceSystem;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.operation.TransformException;
import org.apache.sis.geometry.AbstractEnvelope;
import org.apache.sis.metadata.iso.DefaultMetadata;
-import org.apache.sis.metadata.iso.citation.AbstractParty;
import org.apache.sis.metadata.iso.extent.DefaultExtent;
+import org.apache.sis.metadata.iso.citation.AbstractParty;
import org.apache.sis.metadata.iso.citation.DefaultCitation;
-import org.apache.sis.metadata.iso.citation.DefaultIndividual;
-import org.apache.sis.metadata.iso.citation.DefaultOrganisation;
+import org.apache.sis.metadata.iso.citation.DefaultCitationDate;
import org.apache.sis.metadata.iso.citation.DefaultResponsibility;
import org.apache.sis.metadata.iso.constraint.DefaultLegalConstraints;
import org.apache.sis.metadata.iso.identification.DefaultDataIdentification;
@@ -36,6 +39,9 @@ import org.apache.sis.util.CharSequences
import org.apache.sis.util.Utilities;
import org.apache.sis.util.iso.Types;
+// Branch-dependent imports
+import java.time.LocalDate;
+
/**
* Helper methods for the metadata created by {@code DataStore} implementations.
@@ -48,19 +54,6 @@ import org.apache.sis.util.iso.Types;
*/
public class MetadataBuilder {
/**
- * Elements to ignore in the legal notice to be parsed by {@link #parseLegalNotice(String)}.
- * Some of those elements are implied by the metadata were the legal notice will be stored.
- */
- private static final String[] IGNORABLE_NOTICE = {
- "(C)", "�", "All rights reserved"
- };
-
- /**
- * {@code true} for creating responsible parties as organization, or {@code false} for creating them as individual.
- */
- private boolean authorIsOrganization;
-
- /**
* The metadata created by this reader, or {@code null} if none.
*/
private DefaultMetadata metadata;
@@ -200,11 +193,14 @@ public class MetadataBuilder {
/**
* Creates the person or organization information object if it does not already exists, then return it.
*
+ * <p><b>Limitation:</b> current implementation creates an {@code AbstractParty} instead than one of the subtypes.
+ * This is not valid, but we currently have no way to know if the party is an individual or an organization.</p>
+ *
* @return the person or organization information (never {@code null}).
*/
private AbstractParty party() {
if (party == null) {
- party = authorIsOrganization ? new DefaultOrganisation() : new DefaultIndividual();
+ party = new AbstractParty(); // See limitation in above javadoc.
}
return party;
}
@@ -294,69 +290,214 @@ public class MetadataBuilder {
}
/**
- * Parses the legal notice. The method expects a string of the form
- * \u201cCopyright, John Smith, 1992. All rights reserved.\u201d
- *
- * @param notice the legal notice, or {@code null} if none.
+ * Elements to omit in the legal notice to be parsed by {@link MetadataBuilder#parseLegalNotice(String)}.
+ * Some of those elements are implied by the metadata were the legal notice will be stored.
*/
- public final void parseLegalNotice(final String notice) {
- if (notice != null) {
- int year = 0; // The copyright year, or 0 if none.
- Restriction restriction = null; // The kind of restriction (copyright, licence, etc.).
+ private static final class LegalSymbols {
+ /**
+ * Symbols associated to restrictions.
+ */
+ private static final LegalSymbols[] VALUES = {
+ new LegalSymbols(Restriction.COPYRIGHT, "COPYRIGHT", "(C)", "�", "All rights reserved"),
+ new LegalSymbols(Restriction.TRADEMARK, "TRADEMARK", "(TM)", "\u2122", "(R)", "�")
+ };
+
+ /**
+ * The restriction to use if an item in the {@linkplain #symbols} list is found.
+ */
+ private final Restriction restriction;
+
+ /**
+ * Symbols to use as an indication that the {@linkplain #restriction} applies.
+ */
+ private final String[] symbols;
+
+ /**
+ * Creates a new enumeration value for the given symbol.
+ */
+ private LegalSymbols(final Restriction restriction, final String... symbols) {
+ this.restriction = restriction;
+ this.symbols = symbols;
+ }
+
+ /**
+ * Returns {@code true} if the given character is a space or a punctuation of category "other".
+ * The punctuation characters include coma, dot, semi-colon, <i>etc.</i> but do not include
+ * parenthesis or connecting punctuation.
+ *
+ * @param c the Unicode code point of the character to test.
+ */
+ private static boolean isSpaceOrPunctuation(final int c) {
+ switch (Character.getType(c)) {
+ case Character.LINE_SEPARATOR:
+ case Character.SPACE_SEPARATOR:
+ case Character.PARAGRAPH_SEPARATOR:
+ case Character.OTHER_PUNCTUATION: return true;
+ default: return false;
+ }
+ }
+
+ /**
+ * Implementation of {@link MetadataBuilder#parseLegalNotice(String)}, provided here for reducing
+ * the amount of class loading in the common case where there is no legal notice to parse.
+ */
+ static void parse(final String notice, final DefaultLegalConstraints constraints) {
final int length = notice.length();
- final StringBuilder name = new StringBuilder(length); // Everything which is not one of the above or an ignored text.
- int start = CharSequences.skipLeadingWhitespaces(notice, 0, length);
-parse: for (int i = start; i < length;) {
+ final StringBuilder buffer = new StringBuilder(length);
+ int year = 0; // The copyright year, or 0 if none.
+ int quoteLevel = 0; // Incremented on ( [ � characters, decremented on ) ] � characters.
+ boolean isCopyright = false; // Whether the word parsed by previous iteration was "Copyright" or "(C)".
+ boolean wasSeparator = true; // Whether the caracter parsed by the previous iteration was a word separator.
+ boolean wasPunctuation = true; // Whether the previous character was a punctuation of Unicode category "other".
+ boolean skipNextChars = true; // Whether the next spaces and some punction characters should be ignored.
+parse: for (int i = 0; i < length;) {
final int c = notice.codePointAt(i);
final int n = Character.charCount(c);
- if (!Character.isLetterOrDigit(c)) {
+ int quoteChange = 0;
+ boolean isSeparator = false;
+ boolean isPunctuation;
+ switch (Character.getType(c)) {
+ case Character.INITIAL_QUOTE_PUNCTUATION:
+ case Character.START_PUNCTUATION: {
+ quoteChange = +1; // ( [ � etc.
+ skipNextChars = false;
+ isPunctuation = false;
+ break;
+ }
+ case Character.FINAL_QUOTE_PUNCTUATION:
+ case Character.END_PUNCTUATION: {
+ quoteChange = -1; // ) ] � etc.
+ skipNextChars = false;
+ isPunctuation = false;
+ break;
+ }
+ default: { // Letter, digit, hyphen, etc.
+ skipNextChars = false;
+ isPunctuation = false;
+ break;
+ }
+ case Character.OTHER_PUNCTUATION: { // , . : ; / " etc. but not -.
+ isPunctuation = true;
+ isSeparator = true;
+ break;
+ }
+ case Character.LINE_SEPARATOR:
+ case Character.SPACE_SEPARATOR:
+ case Character.PARAGRAPH_SEPARATOR: {
+ isPunctuation = wasPunctuation;
+ isSeparator = true;
+ break;
+ }
+ }
+ if (wasSeparator && !isSeparator && quoteLevel == 0) {
/*
- * Ignore text like "(C)" or "All rights reserved". Some of those statements
- * are implied by the metadata were the legal notice will be stored.
+ * Found the beginning of a new word. Ignore textes like "(C)" or "All rights reserved".
+ * Some of those textes are implied by the metadata where the legal notice will be stored.
*/
- for (final String ignorable : IGNORABLE_NOTICE) {
- if (notice.regionMatches(true, start, ignorable, 0, ignorable.length())) {
- start = i = CharSequences.skipLeadingWhitespaces(notice, i + ignorable.length(), length);
- continue parse;
+ for (final LegalSymbols r : VALUES) {
+ for (final String symbol : r.symbols) {
+ if (notice.regionMatches(true, i, symbol, 0, symbol.length())) {
+ final int after = i + symbol.length();
+ if (after >= length || isSpaceOrPunctuation(notice.codePointAt(after))) {
+ isCopyright |= Restriction.COPYRIGHT.equals(r.restriction);
+ constraints.getUseConstraints().add(r.restriction);
+ wasPunctuation = true; // Pretend that "Copyright" was followed by a coma.
+ skipNextChars = true; // Ignore spaces and punctuations until the next word.
+ i = after; // Skip the "Copyright" (or other) word.
+ continue parse;
+ }
+ }
}
}
/*
- * Convert text like "Copyright" or "Licence" into one of the Restriction enumerated values.
+ * If a copyright notice is followed by digits, assume that those digits are the copyright year.
+ * We require the year to be surrounded by punctuations in order to reduce the risk of confusion
+ * with postal addresses. So this block should accept "John, 1992." but not "1992 Nowhere road".
*/
- if (restriction == null) {
- restriction = Types.forCodeName(Restriction.class, notice.substring(start, i), false);
- if (restriction != null) {
- constraints().getAccessConstraints().add(restriction);
- start = i = CharSequences.skipLeadingWhitespaces(notice, i, length);
- continue;
+ if (isCopyright && wasPunctuation && year == 0 && c >= '0' && c <= '9') {
+ int endOfDigits = i + n; // After the last digit in sequence.
+ while (endOfDigits < length) {
+ final int d = notice.codePointAt(endOfDigits);
+ if (d < '0' || d > '9') break;
+ endOfDigits++; // No need to use Character.charCount(s) here.
}
- } else {
- /*
- * After we determined that the string begins by "Copyright" or another recognized string
- * and is not one of the ignorable statements, store the remaining either in the buffer
- * or as the copyright year.
- */
- if (year == 0 && Character.isDigit(notice.charAt(start))
- && Character.isDigit(notice.codePointBefore(i)))
- {
- try {
- year = Integer.parseInt(notice.substring(start, i));
- if (year >= 1800 && year <= 9999) { // Those limits are arbitrary.
- start = i; // Accept as a copyright year.
- i += n;
- continue;
- } else {
- year = 0; // Reject - not a copyright year.
- }
- } catch (NumberFormatException ex) { // Ignore - not an integer.
+ // Verify if the digits are followed by a punctuation.
+ final int endOfToken = CharSequences.skipLeadingWhitespaces(notice, endOfDigits, length);
+ if (endOfToken >= length || isSpaceOrPunctuation(notice.codePointAt(endOfToken))) try {
+ year = Integer.parseInt(notice.substring(i, endOfDigits));
+ if (year >= 1800 && year <= 9999) { // Those limits are arbitrary.
+ skipNextChars = true;
+ i = endOfToken;
+ continue;
}
+ year = 0; // Reject as not a copyright year.
+ } catch (NumberFormatException e) {
+ // Not an integer - ignore, will be handled as text.
}
- name.append(notice, start, i);
}
}
+ /*
+ * End of the block that was executed at the beginning of each new word.
+ * Following is executed for every characters, except if the above block
+ * skipped a portion of the input string.
+ */
+ wasPunctuation = isPunctuation;
+ wasSeparator = isSeparator;
+ quoteLevel += quoteChange;
+ if (!skipNextChars && !Character.isIdentifierIgnorable(c)) {
+ buffer.appendCodePoint(c);
+ }
i += n;
}
- // TODO: store year and name.
+ /*
+ * End of parsing. Omit trailing spaces and some punctuations if any, then store the result.
+ */
+ int i = buffer.length();
+ while (i > 0) {
+ final int c = buffer.codePointBefore(i);
+ if (!isSpaceOrPunctuation(c)) break;
+ i -= Character.charCount(c);
+ }
+ final DefaultCitation c = new DefaultCitation(notice);
+ if (year != 0) {
+ final Date date = new Date(LocalDate.of(year, 1, 1).toEpochDay() * (24*60*60*1000L));
+ c.setDates(Collections.singleton(new DefaultCitationDate(date, DateType.IN_FORCE)));
+ }
+ if (i != 0) {
+ buffer.setLength(i);
+ c.setCitedResponsibleParties(Collections.singleton(new DefaultResponsibility(Role.OWNER, null,
+ new AbstractParty(buffer, null)))); // Same limitation than MetadataBuilder.party().
+ }
+ constraints.getReferences().add(c);
+ }
+ }
+
+ /**
+ * Parses the legal notice. The method expects a string of the form
+ * \u201cCopyright, John Smith, 1992. All rights reserved.\u201d
+ * The result of above example will be:
+ *
+ * {@preformat text
+ * Metadata
+ * ��\u2514\u2500Identification info
+ * ������\u2514\u2500Resource constraints
+ * ����������\u251c\u2500Use constraints\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026 Copyright
+ * ����������\u2514\u2500Reference
+ * ��������������\u251c\u2500Title\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026 Copyright (C), John Smith, 1992. All rights reserved.
+ * ��������������\u251c\u2500Date
+ * ��������������\u2502���\u251c\u2500Date\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026 1992-01-01
+ * ��������������\u2502���\u2514\u2500Date type\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026 In force
+ * ��������������\u2514\u2500Cited responsible party
+ * ������������������\u251c\u2500Party
+ * ������������������\u2502���\u2514\u2500Name\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026 John Smith
+ * ������������������\u2514\u2500Role\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026 Owner
+ * }
+ *
+ * @param notice the legal notice, or {@code null} if none.
+ */
+ public final void parseLegalNotice(final String notice) {
+ if (notice != null) {
+ LegalSymbols.parse(notice, constraints());
}
}
}
Added: sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/MetadataBuilderTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/MetadataBuilderTest.java?rev=1754157&view=auto
==============================================================================
--- sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/MetadataBuilderTest.java (added)
+++ sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/MetadataBuilderTest.java [UTF-8] Tue Jul 26 16:35:12 2016
@@ -0,0 +1,83 @@
+/*
+ * 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.storage;
+
+import org.opengis.metadata.constraint.LegalConstraints;
+import org.opengis.metadata.constraint.Restriction;
+import org.opengis.metadata.citation.Citation;
+import org.apache.sis.test.TestCase;
+import org.junit.Test;
+
+import static org.apache.sis.test.MetadataAssert.*;
+import static org.apache.sis.test.TestUtilities.date;
+import static org.apache.sis.test.TestUtilities.getSingleton;
+
+
+/**
+ * Tests {@link MetadataBuilder}.
+ *
+ * @author Martin Desruisseaux (Geomatys)
+ * @since 0.8
+ * @version 0.8
+ * @module
+ */
+public final strictfp class MetadataBuilderTest extends TestCase {
+ /**
+ * Tests {@link MetadataBuilder#parseLegalNotice(String)}.
+ * The expected result of this parsing is:
+ *
+ * {@preformat text
+ * Metadata
+ * ��\u2514\u2500Identification info
+ * ������\u2514\u2500Resource constraints
+ * ����������\u251c\u2500Use constraints\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026 Copyright
+ * ����������\u2514\u2500Reference
+ * ��������������\u251c\u2500Title\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026 Copyright (C), John Smith, 1992. All rights reserved.
+ * ��������������\u251c\u2500Date
+ * ��������������\u2502���\u251c\u2500Date\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026 1992-01-01
+ * ��������������\u2502���\u2514\u2500Date type\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026 In force
+ * ��������������\u2514\u2500Cited responsible party
+ * ������������������\u251c\u2500Party
+ * ������������������\u2502���\u2514\u2500Name\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026 John Smith
+ * ������������������\u2514\u2500Role\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026 Owner
+ * }
+ */
+ @Test
+ public void testParseLegalNotice() {
+ verifyCopyrightParsing("Copyright (C), John Smith, 1992. All rights reserved.");
+ verifyCopyrightParsing("(C) 1992, John Smith. All rights reserved.");
+ }
+
+ /**
+ * Verifies the metadata that contains the result of parsing a copyright statement.
+ * Should contains the "John Smith" name and 1992 year.
+ *
+ * @param notice the copyright statement to parse.
+ */
+ private static void verifyCopyrightParsing(final String notice) {
+ final MetadataBuilder builder = new MetadataBuilder();
+ builder.parseLegalNotice(notice);
+ final LegalConstraints constraints = (LegalConstraints) getSingleton(getSingleton(
+ builder.result().getIdentificationInfo()).getResourceConstraints());
+
+ assertEquals("useConstraints", Restriction.COPYRIGHT, getSingleton(constraints.getUseConstraints()));
+ final Citation ref = getSingleton(constraints.getReferences());
+ assertTitleEquals("reference.title", notice, ref);
+ assertPartyNameEquals("reference.citedResponsibleParty", "John Smith", ref);
+ assertEquals("date", date("1992-01-01 00:00:00"), getSingleton(ref.getDates()).getDate());
+ }
+}
Propchange: sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/MetadataBuilderTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/MetadataBuilderTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain;charset=UTF-8
Modified: sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/test/suite/StorageTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/test/suite/StorageTestSuite.java?rev=1754157&r1=1754156&r2=1754157&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/test/suite/StorageTestSuite.java [UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-storage/src/test/java/org/apache/sis/test/suite/StorageTestSuite.java [UTF-8] Tue Jul 26 16:35:12 2016
@@ -37,6 +37,7 @@ import org.junit.BeforeClass;
org.apache.sis.internal.storage.ChannelImageInputStreamTest.class,
org.apache.sis.internal.storage.ChannelImageOutputStreamTest.class,
org.apache.sis.internal.storage.HyperRectangleReaderTest.class,
+ org.apache.sis.internal.storage.MetadataBuilderTest.class,
org.apache.sis.storage.ProbeResultTest.class,
org.apache.sis.storage.StorageConnectorTest.class,
org.apache.sis.internal.storage.xml.MimeTypeDetectorTest.class,