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);
}
}
}
}
Aggregations