File: GpxWriter10.java

package info (click to toggle)
gpsprune 26.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,824 kB
  • sloc: java: 52,154; sh: 25; makefile: 21; python: 15
file content (116 lines) | stat: -rw-r--r-- 3,692 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package tim.prune.save.xml;

import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;

import tim.prune.data.DataPoint;
import tim.prune.data.Field;
import tim.prune.data.FieldGpx;
import tim.prune.data.FieldXml;
import tim.prune.data.FileInfo;
import tim.prune.data.FileType;
import tim.prune.data.MediaObject;
import tim.prune.gui.ProgressDialog;
import tim.prune.save.SettingsForExport;

/** Responsible for Gpx1.0-specific parts of Gpx writing */
public class GpxWriter10 extends GpxWriter
{
	public GpxWriter10(ProgressDialog inProgress, SettingsForExport inSettings) {
		super(inProgress, inSettings);
	}

	/** @return the default Gpx header without extensions */
	protected String getDefaultGpxHeader()
	{
		return "<gpx version=\"1.0\" creator=\"" + GPX_CREATOR
				+ "\"\n xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
				+ " xmlns=\"http://www.topografix.com/GPX/1/0\""
				+ " xsi:schemaLocation=\"http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd\">";
	}

	/** @return the default schema location string without extensions */
	private String getDefaultSchemaLocation() {
		return "http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd";
	}

	/** @return the default Gpx header with extensions */
	protected String getGpxHeader(FileInfo inInfo)
	{
		HeaderCombiner combiner = new HeaderCombiner(GpxVersion.GPX_1_0);
		for (int i=0; i<inInfo.getNumFiles(); i++) {
			combiner.addSourceInfo(inInfo.getSource(i));
		}

		return "<gpx version=\"1.0\" creator=\"" + GPX_CREATOR
				+ "\"\n xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
				+ " xmlns=\"http://www.topografix.com/GPX/1/0\"\n"
				+ " xsi:schemaLocation=\"" + combiner.getAllLocations(getDefaultSchemaLocation()) + "\"\n"
				+ combiner.getNamespaces() + ">";
	}

	/** Write the name and description in 1.0 format */
	protected void writeMetadata(OutputStreamWriter inWriter, String inName, String inDesc) throws IOException
	{
		// GPX 1.0 doesn't have a metadata tag
		writeNameAndDescription(inWriter, inName, inDesc, "\t");
	}

	/** No, version 1.0 does not support link tags */
	protected boolean versionSupportsPointLinks() {
		return false;
	}

	protected boolean versionSupportsTag(FieldGpx inField) {
		return true;
	}

	/**
	 * Make the media link for a single media item
	 * @param inMedia media item, either photo or audio
	 * @return link for this media
	 */
	protected String makeMediaLink(MediaObject inMedia)
	{
		if (inMedia.getFile() != null)
		{
			// file link
			return "<url>" + inMedia.getFile().getAbsolutePath() + "</url>";
		}
		if (inMedia.getUrl() != null)
		{
			// url link
			return "<url>" + inMedia.getUrl() + "</url>";
		}
		// No link available, must have been loaded from zip file - no link possible
		return "";
	}

	/** Export the extension tags from the given waypoint to the writer */
	protected void exportWaypointExtensions(DataPoint inPoint, Writer inWriter) throws IOException
	{
		for (Field field : inPoint.getFieldList().getFields(FileType.GPX))
		{
			if (field instanceof FieldXml)
			{
				FieldXml xmlField = (FieldXml) field;
				String value = inPoint.getFieldValue(xmlField);
				if (!isEmpty(value))
				{
					// Don't include tag category for Gpx 1.0, just use the tag
					inWriter.write("\t\t\t\t");
					inWriter.write(xmlField.getTag(value));
					inWriter.write("\n");
				}
			}
		}
	}

	/** Export the extension tags from the given trackpoint to the writer */
	protected void exportTrackpointExtensions(DataPoint inPoint, Writer inWriter) throws IOException
	{
		// TODO: Maybe just the same as above?
		exportWaypointExtensions(inPoint, inWriter);
	}
}