use of org.apache.sis.util.Version in project sis by apache.
the class DefaultVerticalDatumTest method testGML31.
/**
* Tests (un)marshalling of an older version, GML 3.1.
*
* @throws JAXBException if an error occurred during unmarshalling.
*
* @see <a href="http://issues.apache.org/jira/browse/SIS-160">SIS-160: Need XSLT between GML 3.1 and 3.2</a>
*/
@Test
public void testGML31() throws JAXBException {
final Version version = new Version("3.1");
final MarshallerPool pool = getMarshallerPool();
final Unmarshaller unmarshaller = pool.acquireUnmarshaller();
unmarshaller.setProperty(XML.GML_VERSION, version);
final DefaultVerticalDatum datum = (DefaultVerticalDatum) unmarshaller.unmarshal(getClass().getResource(GML31_FILE));
pool.recycle(unmarshaller);
/*
* Following attribute exists in GML 3.1 only.
*/
assertEquals("vertDatumType", VerticalDatumType.GEOIDAL, datum.getVerticalDatumType());
/*
* The name, anchor definition and domain of validity are lost because
* those property does not have the same XML element name (SIS-160).
* Below is all we have.
*/
assertEquals("remarks", "Approximates geoid.", datum.getRemarks().toString());
assertEquals("scope", "Hydrography.", datum.getScope().toString());
/*
* Test marshaling. We can not yet compare with the original XML file
* because of all the information lost. This may be fixed in a future
* SIS version (SIS-160).
*/
final Marshaller marshaller = pool.acquireMarshaller();
marshaller.setProperty(XML.GML_VERSION, version);
final String xml = marshal(marshaller, datum);
pool.recycle(marshaller);
assertXmlEquals("<gml:VerticalDatum xmlns:gml=\"" + LegacyNamespaces.GML + "\">\n" + " <gml:remarks>Approximates geoid.</gml:remarks>\n" + " <gml:scope>Hydrography.</gml:scope>\n" + " <gml:verticalDatumType>geoidal</gml:verticalDatumType>\n" + "</gml:VerticalDatum>", xml, "xmlns:*");
}
use of org.apache.sis.util.Version in project sis by apache.
the class Reader method initialize.
/**
* Reads the metadata. This method should be invoked exactly once after construction.
* This work is performed outside the constructor for allowing {@link #close()} method
* invocation no matter if this {@code initialize(boolean)} method fails.
*
* @param readMetadata if {@code false}, skip the reading of metadata elements.
* @return the GPX file version, or {@code null} if no version information was found.
* @throws DataStoreException if the root element is not the expected one.
* @throws XMLStreamException if an error occurred while reading the XML file.
* @throws JAXBException if an error occurred while parsing GPX 1.1 metadata.
* @throws ClassCastException if an object unmarshalled by JAXB was not of the expected type.
* @throws URISyntaxException if an error occurred while parsing URI in GPX 1.0 metadata.
* @throws DateTimeParseException if a text can not be parsed as a date.
* @throws EOFException if the file seems to be truncated.
*/
public Version initialize(final boolean readMetadata) throws DataStoreException, XMLStreamException, JAXBException, URISyntaxException, EOFException {
/*
* Skip comments, characters, entity declarations, etc. until we find the root element.
* If that root is anything other than <gpx>, we consider that this is not a GPX file.
*/
moveToRootElement(Reader::isGPX, Tags.GPX);
/*
* If a version attribute is found on the <gpx> element, use that value for detecting the GPX version.
* If a version is specified, we require major.minor version 1.0 or 1.1 but accept any bug-fix versions
* (e.g. 1.1.x). If no version attribute was found, try to infer the version from the namespace URL.
*/
namespace = reader.getNamespaceURI();
String ver = reader.getAttributeValue(null, Attributes.VERSION);
Version version = null;
if (ver != null) {
version = new Version(ver);
if (version.compareTo(StoreProvider.V1_0, 2) < 0 || version.compareTo(StoreProvider.V1_1, 2) > 0) {
throw new DataStoreContentException(errors().getString(Errors.Keys.UnsupportedFormatVersion_2, owner.getFormatName(), version));
}
} else if (namespace != null) {
switch(namespace) {
case Tags.NAMESPACE_V10:
version = StoreProvider.V1_0;
break;
case Tags.NAMESPACE_V11:
version = StoreProvider.V1_1;
break;
}
}
/*
* Read metadata immediately, from current position until the beginning of way points, tracks or routes.
* The metadata can appear in two forms:
*
* - In GPX 1.0, they are declared directly in the <gpx> body.
* Those elements are parsed in the switch statement below.
*
* - In GPX 1.1, they are declared in a <metadata> sub-element and their structure is a little bit
* more elaborated than what it was in the previous version. We will use JAXB for parsing them.
*/
parse: while (reader.hasNext()) {
switch(next()) {
case START_ELEMENT:
{
/*
* GPX 1.0 and 1.1 metadata should not be mixed. However the following code will work even
* if GPX 1.0 metadata like <name> or <author> appear after the GPX 1.1 <metadata> element.
* If both kind of metadata are specified, the latest value overwrites the values before it.
*/
if (isGPX()) {
final String name = reader.getLocalName();
if (readMetadata) {
switch(name) {
// GPX 1.1 metadata
case Tags.METADATA:
metadata = unmarshal(Metadata.class);
break;
// GPX 1.0 metadata
case Tags.NAME:
metadata().name = getElementText();
break;
case Tags.DESCRIPTION:
metadata().description = getElementText();
break;
case Tags.AUTHOR:
author().name = getElementText();
break;
case Tags.EMAIL:
author().email = getElementText();
break;
case Tags.URL:
link().uri = getElementAsURI();
break;
case Tags.URL_NAME:
link().text = getElementText();
break;
case Tags.TIME:
metadata().time = getElementAsDate();
break;
case Tags.KEYWORDS:
metadata().keywords = getElementAsList();
break;
case Tags.BOUNDS:
metadata().bounds = unmarshal(Bounds.class);
break;
// stop metadata parsing.
case Tags.WAY_POINT:
case Tags.TRACKS:
case Tags.ROUTES:
break parse;
case Tags.GPX:
throw new DataStoreContentException(nestedElement(Tags.GPX));
}
} else {
/*
* If the caller asked to skip metadata, just look for the end of metadata elements.
*/
switch(name) {
case Tags.METADATA:
skipUntilEnd(reader.getName());
break;
case Tags.WAY_POINT:
case Tags.TRACKS:
case Tags.ROUTES:
break parse;
case Tags.GPX:
throw new DataStoreContentException(nestedElement(Tags.GPX));
}
}
}
break;
}
case END_ELEMENT:
{
/*
* Reminder: calling next() after getElementText(), getElementAsFoo() and unmarshal(…) methods
* moves the reader after the END_ELEMENT event. Consequently there is only the enclosing <gpx>
* tag to check here.
*/
if (isEndGPX()) {
break parse;
}
break;
}
}
}
if (readMetadata) {
metadata().store = (Store) owner;
}
return version;
}
use of org.apache.sis.util.Version in project sis by apache.
the class DefaultBrowseGraphicTest method roundtrip.
/**
* Verifies that marshalling the given metadata produces the expected XML document,
* then verifies that unmarshalling that document gives back the original metadata object.
* If {@link #legacy} is {@code true}, then this method will use ISO 19139:2007 schema.
*/
private void roundtrip(final BrowseGraphic browse, String expected) throws JAXBException {
final String actual;
final Version version;
if (legacy) {
expected = toLegacyXML(expected);
version = VERSION_2007;
} else {
version = VERSION_2014;
}
actual = marshal(browse, version);
assertXmlEquals(expected, actual, "xmlns:*");
assertEquals(browse, unmarshal(BrowseGraphic.class, actual));
}
use of org.apache.sis.util.Version in project sis by apache.
the class DefaultRepresentativeFractionTest method roundtrip.
/**
* Verifies that marshalling the given metadata produces the expected XML document,
* then verifies that unmarshalling that document gives back the original metadata object.
* If {@link #legacy} is {@code true}, then this method will use ISO 19139:2007 schema.
*/
private void roundtrip(final RepresentativeFraction browse, String expected) throws JAXBException {
final String actual;
final Version version;
if (legacy) {
expected = toLegacyXML(expected);
version = VERSION_2007;
} else {
version = VERSION_2014;
}
actual = marshal(browse, version);
assertXmlEquals(expected, actual, "xmlns:*");
assertEquals(browse, unmarshal(RepresentativeFraction.class, actual));
}
use of org.apache.sis.util.Version in project sis by apache.
the class NetcdfStoreProviderTest method testProbeContentFromStream.
/**
* Tests {@link NetcdfStoreProvider#probeContent(StorageConnector)} for an input stream which shall
* be recognized as a classic netCDF file.
*
* @throws DataStoreException if a logical error occurred.
*/
@Test
public void testProbeContentFromStream() throws DataStoreException {
final StorageConnector c = new StorageConnector(IOTestCase.getResourceAsStream(NCEP));
final NetcdfStoreProvider provider = new NetcdfStoreProvider();
final ProbeResult probe = provider.probeContent(c);
assertTrue("isSupported", probe.isSupported());
assertEquals("getMimeType", NetcdfStoreProvider.MIME_TYPE, probe.getMimeType());
assertEquals("getVersion", new Version("1"), probe.getVersion());
c.closeAllExcept(null);
}
Aggregations