Author: desruisseaux
Date: Mon Feb 19 21:21:06 2018
New Revision: 1824814
URL: http://svn.apache.org/viewvc?rev=1824814&view=rev
Log:
Fix a corner case in the reordering of elements (MD_DataIdentification.extent
to be inserted between environmentalDescription and supplementalInformation).
Modified:
sis/branches/ISO-19115-3/core/sis-referencing/src/test/java/org/apache/sis/test/integration/MetadataTest.java
sis/branches/ISO-19115-3/core/sis-referencing/src/test/resources/org/apache/sis/test/integration/Metadata.xml
sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/TransformingWriter.java
sis/branches/ISO-19115-3/core/sis-utility/src/main/resources/org/apache/sis/xml/ImportNames.lst
Modified:
sis/branches/ISO-19115-3/core/sis-referencing/src/test/java/org/apache/sis/test/integration/MetadataTest.java
URL:
http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-referencing/src/test/java/org/apache/sis/test/integration/MetadataTest.java?rev=1824814&r1=1824813&r2=1824814&view=diff
==============================================================================
---
sis/branches/ISO-19115-3/core/sis-referencing/src/test/java/org/apache/sis/test/integration/MetadataTest.java
[UTF-8] (original)
+++
sis/branches/ISO-19115-3/core/sis-referencing/src/test/java/org/apache/sis/test/integration/MetadataTest.java
[UTF-8] Mon Feb 19 21:21:06 2018
@@ -304,6 +304,13 @@ public strictfp class MetadataTest exten
new DefaultVerticalExtent(Double.NaN, Double.NaN,
vcrs),
temporal)));
}
+ /*
+ * Data identification / Environmental description and
Supplemental information.
+ */
+ {
+ identification.setEnvironmentDescription (new
SimpleInternationalString("Possibly cloudy."));
+ identification.setSupplementalInformation(new
SimpleInternationalString("This metadata has been modified with dummy
values."));
+ }
metadata.setIdentificationInfo(singleton(identification));
}
/*
Modified:
sis/branches/ISO-19115-3/core/sis-referencing/src/test/resources/org/apache/sis/test/integration/Metadata.xml
URL:
http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-referencing/src/test/resources/org/apache/sis/test/integration/Metadata.xml?rev=1824814&r1=1824813&r2=1824814&view=diff
==============================================================================
---
sis/branches/ISO-19115-3/core/sis-referencing/src/test/resources/org/apache/sis/test/integration/Metadata.xml
(original)
+++
sis/branches/ISO-19115-3/core/sis-referencing/src/test/resources/org/apache/sis/test/integration/Metadata.xml
Mon Feb 19 21:21:06 2018
@@ -353,6 +353,9 @@
<gmd:topicCategory>
<gmd:MD_TopicCategoryCode>oceans</gmd:MD_TopicCategoryCode>
</gmd:topicCategory>
+ <gmd:environmentDescription>
+ <gco:CharacterString>Possibly cloudy.</gco:CharacterString>
+ </gmd:environmentDescription>
<gmd:extent>
<gmd:EX_Extent>
<gmd:geographicElement>
@@ -412,6 +415,9 @@
</gmd:verticalElement>
</gmd:EX_Extent>
</gmd:extent>
+ <gmd:supplementalInformation>
+ <gco:CharacterString>This metadata has been modified with dummy
values.</gco:CharacterString>
+ </gmd:supplementalInformation>
</gmd:MD_DataIdentification>
</gmd:identificationInfo>
<gmd:contentInfo>
Modified:
sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/TransformingWriter.java
URL:
http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/TransformingWriter.java?rev=1824814&r1=1824813&r2=1824814&view=diff
==============================================================================
---
sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/TransformingWriter.java
[UTF-8] (original)
+++
sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/TransformingWriter.java
[UTF-8] Mon Feb 19 21:21:06 2018
@@ -175,9 +175,11 @@ final class TransformingWriter extends T
* to newer standards. This is a FIFO (First-In-First-Out) queue.
Namespaces are the exported ones
* (the ones after conversions from JAXB to the XML document to write).
*
+ * <p>Elements are instance of {@link XMLEvent} or {@link NewDeferred}.</p>
+ *
* @see #ELEMENTS_TO_REORDER
*/
- private final Queue<XMLEvent> deferred;
+ private final Queue<Object> deferred;
/**
* If non-null, elements to skip before we can write the {@linkplain
#deferred} events.
@@ -354,7 +356,7 @@ final class TransformingWriter extends T
if (originalName.equals(subtreeRootName)) {
subtreeNesting--; // May reach 0
but be followed by another element to skip.
} else if (subtreeNesting == 0) {
- writeDeferred(); // About to
exit the parent element containing deferred element.
+ writeDeferred(null); // About to
exit the parent element containing deferred element.
}
}
close(originalName); // Must be
invoked only after 'convert(QName)'
@@ -393,7 +395,13 @@ final class TransformingWriter extends T
isDeferring = true;
}
} else if (subtreeNesting == 0) {
- if (toSkip.contains(originalName)) {
+ /*
+ * If the current element should not be skipped
(toSkip.contains(…) = false), then
+ * we need to write all deferred elements. Usually
'writeDeferred(…) returns false,
+ * so the block inside the 'if' is executed only if
'toSkip.contains(…)' is true.
+ * But in few cases, we still need to be in "skipping"
state after 'writeDeferred'.
+ */
+ if (toSkip.contains(originalName) ||
writeDeferred(originalName)) {
/*
* Found an element to skip. That element will be
written immediately (except if
* it is another element which needs reordering), and
the elements currently in
@@ -404,9 +412,11 @@ final class TransformingWriter extends T
*/
subtreeRootName = originalName;
subtreeNesting = 1;
- isDeferring =
ELEMENTS_TO_REORDER.containsKey(originalName);
- } else {
- writeDeferred(); // End
of deferring.
+ final Set<QName> interleaved =
ELEMENTS_TO_REORDER.get(originalName);
+ if (interleaved != null) {
+ isDeferring = true;
+ deferred.add(new NewDeferred(interleaved));
+ }
}
} else if (originalName.equals(subtreeRootName)) {
subtreeNesting++;
@@ -423,17 +433,58 @@ final class TransformingWriter extends T
}
/**
+ * A sentinel value in the {@link TransformingWriter#deferred} queue
meaning that after reaching this point,
+ * we need to reevaluate if the remaining elements should be written
immediately of deferred again.
+ * This happen when some elements to move are interleaved. For example in
{@code MD_DataIdentification}:
+ *
+ * <ol>
+ * <li>{@code topicCategory} needs to move before {@code
environmentDescription}</li>
+ * <li>{@code extent} needs to move before {@code
supplementalInformation}</li>
+ * <li>{@code graphicOverviews}</li>
+ * <li>{@code resourceFormats}</li>
+ * <li><i>etc.</i>
+ * <li>{@code environmentDescription}</li>
+ * <li>{@code supplementalInformation}</li>
+ * </ol>
+ *
+ * This class is for handling the {@code extent} case in such scenario.
+ */
+ private static final class NewDeferred {
+ /** The value to assign to {@link TransformingWriter#deferred} after
we reach this point. */
+ final Set<QName> toSkip;
+
+ /** Creates a new sentinel value for a reevaluation point. */
+ NewDeferred(final Set<QName> toSkip) {
+ this.toSkip = toSkip;
+ }
+ }
+
+ /**
* Writes immediately all elements that were deferred. This happen because
the next {@link StartElement}
* to write should be after the deferred element, or because we are about
to exit the parent element that
* contains the deferred element, or because {@link #flush()} has been
invoked.
*
+ * @param element the {@link StartElement} element name, or {@code null}
for other events.
+ * @return {@code true} if the given element starts a new subtree to skip.
+ *
* @see #ELEMENTS_TO_REORDER
*/
- private void writeDeferred() throws XMLStreamException {
+ private boolean writeDeferred(final QName element) throws
XMLStreamException {
subtreeRootName = null;
toSkip = null;
- XMLEvent v;
- while ((v = deferred.poll()) != null) out.add(v);
+ Object v;
+ while ((v = deferred.poll()) != null) {
+ if (!(v instanceof NewDeferred)) {
+ out.add((XMLEvent) v);
+ } else if (element != null) {
+ final Set<QName> s = ((NewDeferred) v).toSkip;
+ if (s.contains(element)) {
+ toSkip = s;
+ return true;
+ }
+ }
+ }
+ return false;
}
/**
@@ -552,7 +603,7 @@ final class TransformingWriter extends T
*/
@Override
public void flush() throws XMLStreamException {
- writeDeferred();
+ writeDeferred(null);
out.flush();
}
Modified:
sis/branches/ISO-19115-3/core/sis-utility/src/main/resources/org/apache/sis/xml/ImportNames.lst
URL:
http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-utility/src/main/resources/org/apache/sis/xml/ImportNames.lst?rev=1824814&r1=1824813&r2=1824814&view=diff
==============================================================================
---
sis/branches/ISO-19115-3/core/sis-utility/src/main/resources/org/apache/sis/xml/ImportNames.lst
[UTF-8] (original)
+++
sis/branches/ISO-19115-3/core/sis-utility/src/main/resources/org/apache/sis/xml/ImportNames.lst
[UTF-8] Mon Feb 19 21:21:06 2018
@@ -580,8 +580,6 @@ http://standards.iso.org/iso/19115/-3/mr
DS_AssociationTypeCode
DS_InitiativeTypeCode
MD_AggregateInformation !other namespace
- associationType
- initiativeType
metadataReference
name
MD_AssociatedResource