Search in sources :

Example 6 with Version

use of org.apache.sis.util.Version in project sis by apache.

the class Writer method writeStartDocument.

/**
 * Writes the XML declaration followed by GPX metadata.
 * This method shall be invoked exactly once before {@code write(Feature)}.
 *
 * @throws Exception if an error occurred while writing to the XML file.
 */
@Override
public void writeStartDocument() throws Exception {
    final String namespace;
    final Version ver;
    switch(version) {
        default:
        case 1:
            ver = StoreProvider.V1_1;
            namespace = Tags.NAMESPACE_V11;
            break;
        case 0:
            ver = StoreProvider.V1_0;
            namespace = Tags.NAMESPACE_V10;
            break;
    }
    super.writeStartDocument();
    writer.setDefaultNamespace(namespace);
    writer.writeStartElement(Tags.GPX);
    writer.writeDefaultNamespace(namespace);
    writer.writeAttribute(Attributes.VERSION, ver.toString());
    if (metadata != null) {
        final String creator = metadata.creator;
        if (creator != null) {
            writer.writeAttribute(Attributes.CREATOR, creator);
        }
        switch(version) {
            default:
            case 1:
                {
                    /*
                     * In GPX 1.1 format, the metadata are stored under a <metadata> node.
                     * This can conveniently be written by JAXB.
                     */
                    marshal(Tags.NAMESPACE_V11, Tags.METADATA, Metadata.class, metadata);
                    break;
                }
            case 0:
                {
                    /*
                     * In GPX 1.0 format, the metadata were written inline in the root <gpx> element.
                     * We need to write them ourself. Not all metadata can be written in that legacy format.
                     */
                    writeSingleValue(Tags.NAME, metadata.name);
                    writeSingleValue(Tags.DESCRIPTION, metadata.description);
                    final Person author = metadata.author;
                    if (author != null) {
                        writeSingleValue(Tags.AUTHOR, author.name);
                        writeSingleValue(Tags.EMAIL, author.email);
                    }
                    writeLinks(metadata.links);
                    writeSingle(Tags.TIME, metadata.time);
                    writeList(Tags.KEYWORDS, metadata.keywords);
                    // Really 1.1 namespace below, not 1.0. See 'marshal(…)' javadoc for explanation.
                    marshal(Tags.NAMESPACE_V11, Tags.BOUNDS, Bounds.class, metadata.bounds);
                }
        }
    }
}
Also used : Version(org.apache.sis.util.Version)

Aggregations

Version (org.apache.sis.util.Version)6 Test (org.junit.Test)2 Marshaller (javax.xml.bind.Marshaller)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 XMLStreamReader (javax.xml.stream.XMLStreamReader)1 ChannelDecoderTest (org.apache.sis.internal.netcdf.impl.ChannelDecoderTest)1 StaxStreamReader (org.apache.sis.internal.storage.xml.stream.StaxStreamReader)1 DataStoreContentException (org.apache.sis.storage.DataStoreContentException)1 ProbeResult (org.apache.sis.storage.ProbeResult)1 StorageConnector (org.apache.sis.storage.StorageConnector)1 MarshallerPool (org.apache.sis.xml.MarshallerPool)1 BrowseGraphic (org.opengis.metadata.identification.BrowseGraphic)1 RepresentativeFraction (org.opengis.metadata.identification.RepresentativeFraction)1