1 package org.opentrafficsim.road.network.factory.opendrive;
2
3 import java.io.Serializable;
4
5 import org.djunits.unit.AngleUnit;
6 import org.djunits.unit.LengthUnit;
7 import org.djunits.value.vdouble.scalar.Angle;
8 import org.djunits.value.vdouble.scalar.Length;
9 import org.opentrafficsim.core.network.NetworkException;
10 import org.w3c.dom.NamedNodeMap;
11 import org.w3c.dom.Node;
12 import org.xml.sax.SAXException;
13
14
15
16
17
18
19
20
21
22
23 public class HeaderTag implements Serializable
24 {
25
26 private static final long serialVersionUID = 20150723L;
27
28
29 @SuppressWarnings("checkstyle:visibilitymodifier")
30 String name = null;
31
32
33 @SuppressWarnings("checkstyle:visibilitymodifier")
34 int revMajor = 0;
35
36
37 @SuppressWarnings("checkstyle:visibilitymodifier")
38 int revMinor = 0;
39
40
41 @SuppressWarnings("checkstyle:visibilitymodifier")
42 String version = null;
43
44
45 @SuppressWarnings("checkstyle:visibilitymodifier")
46 String date = null;
47
48
49 @SuppressWarnings("checkstyle:visibilitymodifier")
50 Length north = null;
51
52
53 @SuppressWarnings("checkstyle:visibilitymodifier")
54 Length south = null;
55
56
57 @SuppressWarnings("checkstyle:visibilitymodifier")
58 Length east = null;
59
60
61 @SuppressWarnings("checkstyle:visibilitymodifier")
62 Length west = null;
63
64
65 @SuppressWarnings("checkstyle:visibilitymodifier")
66 String vendor = null;
67
68
69 @SuppressWarnings("checkstyle:visibilitymodifier")
70 Length originLat = null;
71
72
73 @SuppressWarnings("checkstyle:visibilitymodifier")
74 Length originLong = null;
75
76
77 @SuppressWarnings("checkstyle:visibilitymodifier")
78 Angle originHdg = null;
79
80
81
82
83
84
85
86
87 @SuppressWarnings("checkstyle:needbraces")
88 static void parseHeader(final Node node, final OpenDriveNetworkLaneParser parser) throws SAXException, NetworkException
89 {
90 NamedNodeMap attributes = node.getAttributes();
91 HeaderTag headerTag = new HeaderTag();
92
93 Node name = attributes.getNamedItem("name");
94 if (name == null)
95 throw new SAXException("Header: missing attribute name");
96 headerTag.name = name.getNodeValue().trim();
97
98 Node revMajor = attributes.getNamedItem("revMajor");
99 if (revMajor == null)
100 throw new SAXException("Header: missing attribute revMajor");
101 headerTag.revMajor = Integer.parseInt(revMajor.getNodeValue().trim());
102
103 Node revMinor = attributes.getNamedItem("revMinor");
104 if (revMinor == null)
105 throw new SAXException("Header: missing attribute revMinor");
106 headerTag.revMinor = Integer.parseInt(revMinor.getNodeValue().trim());
107
108 Node version = attributes.getNamedItem("version");
109 if (version == null)
110 throw new SAXException("Header: missing attribute version");
111 headerTag.version = version.getNodeValue().trim();
112
113 Node date = attributes.getNamedItem("date");
114 if (date == null)
115 throw new SAXException("Header: missing attribute date");
116 headerTag.date = date.getNodeValue().trim();
117
118 Node vendor = attributes.getNamedItem("vendor");
119 if (vendor == null)
120 throw new SAXException("Header: missing attribute vendor");
121 headerTag.vendor = vendor.getNodeValue().trim();
122
123 Node north = attributes.getNamedItem("north");
124 if (north == null)
125 throw new SAXException("Header: missing attribute north");
126 headerTag.north = new Length(Double.parseDouble(north.getNodeValue().trim()), LengthUnit.METER);
127
128 Node south = attributes.getNamedItem("south");
129 if (south == null)
130 throw new SAXException("Header: missing attribute south");
131 headerTag.south = new Length(Double.parseDouble(south.getNodeValue().trim()), LengthUnit.METER);
132
133 Node east = attributes.getNamedItem("east");
134 if (east == null)
135 throw new SAXException("Header: missing attribute east");
136 headerTag.east = new Length(Double.parseDouble(east.getNodeValue().trim()), LengthUnit.METER);
137
138 Node west = attributes.getNamedItem("west");
139 if (west == null)
140 throw new SAXException("Header: missing attribute west");
141 headerTag.west = new Length(Double.parseDouble(west.getNodeValue().trim()), LengthUnit.METER);
142
143 Node originLat = attributes.getNamedItem("originLat");
144 if (originLat == null)
145 throw new SAXException("Header: missing attribute originLat");
146 headerTag.originLat = new Length(Double.parseDouble(originLat.getNodeValue().trim()), LengthUnit.METER);
147
148 Node originLong = attributes.getNamedItem("originLong");
149 if (originLong == null)
150 throw new SAXException("Header: missing attribute originLong");
151 headerTag.originLong = new Length(Double.parseDouble(originLong.getNodeValue().trim()), LengthUnit.METER);
152
153 Node originHdg = attributes.getNamedItem("originHdg");
154 if (originHdg == null)
155 throw new SAXException("Header: missing attribute originHdg");
156 headerTag.originHdg = new Angle(Double.parseDouble(originHdg.getNodeValue().trim()), AngleUnit.DEGREE);
157
158 parser.headerTag = headerTag;
159 }
160
161
162
163
164 public Length getOriginLat()
165 {
166 return this.originLat;
167 }
168
169
170
171
172 public Length getOriginLong()
173 {
174 return this.originLong;
175 }
176
177
178 @Override
179 public final String toString()
180 {
181 return "HeaderTag [name=" + this.name + ", revMajor=" + this.revMajor + ", revMinor=" + this.revMinor + ", version="
182 + this.version + ", date=" + this.date + ", north=" + this.north + ", south=" + this.south + ", east="
183 + this.east + ", west=" + this.west + ", vendor=" + this.vendor + ", originLat=" + this.originLat
184 + ", originLong=" + this.originLong + ", originHdg=" + this.originHdg + "]";
185 }
186 }