MATSIM
Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
org.matsim.counts.CountsReaderMatsimV1 Class Reference
Inheritance diagram for org.matsim.counts.CountsReaderMatsimV1:
Inheritance graph
[legend]

Public Member Functions

 CountsReaderMatsimV1 (final Counts counts)
 
 CountsReaderMatsimV1 (final CoordinateTransformation coordinateTransformation, final Counts counts)
 
void startTag (final String name, final Attributes atts, final Stack< String > context)
 
void endTag (final String name, final String content, final Stack< String > context)
 
abstract void startTag (String name, Attributes atts, Stack< String > context)
 
final void setValidating (final boolean validateXml)
 
final void setNamespaceAware (final boolean awareness)
 
final void setLocalDtdDirectory (final String localDtdDirectory)
 
final void readFile (final String filename) throws UncheckedIOException
 
final void readURL (final URL url) throws UncheckedIOException
 
final void readStream (InputStream stream) throws UncheckedIOException
 
final void parse (final URL url) throws UncheckedIOException
 
final void parse (final InputStream stream) throws UncheckedIOException
 
final void parse (final InputSource input) throws UncheckedIOException
 
final String getDoctype ()
 
final InputSource resolveEntity (final String publicId, final String systemId)
 
void characters (final char[] ch, final int start, final int length) throws SAXException
 
final void startElement (final String uri, final String localName, final String qName, Attributes atts)
 
final void endElement (final String uri, final String localName, final String qName) throws SAXException
 
final void error (final SAXParseException ex) throws SAXException
 
final void fatalError (final SAXParseException ex) throws SAXException
 
final void warning (final SAXParseException ex) throws SAXException
 

Static Public Member Functions

static double parseDouble (String value) throws NumberFormatException
 

Protected Member Functions

void setDoctype (final String doctype)
 

Private Member Functions

void startCounts (final Attributes meta)
 
void startCount (final Attributes meta)
 
void startVolume (final Attributes meta)
 

Private Attributes

final CoordinateTransformation coordinateTransformation
 
final Counts counts
 
Count currcount = null
 

Static Private Attributes

static final String COUNTS = "counts"
 
static final String COUNT = "count"
 
static final String VOLUME = "volume"
 
static final Logger log = LogManager.getLogger(CountsReaderMatsimV1.class)
 

Detailed Description

A reader for counts-files of MATSim according to counts_v1.xsd.

Author
mrieser

Definition at line 40 of file CountsReaderMatsimV1.java.

Constructor & Destructor Documentation

◆ CountsReaderMatsimV1() [1/2]

org.matsim.counts.CountsReaderMatsimV1.CountsReaderMatsimV1 ( final Counts  counts)

Definition at line 53 of file CountsReaderMatsimV1.java.

References org.matsim.counts.CountsReaderMatsimV1.counts.

53  {
54  this( new IdentityTransformation(), counts );
55  }

◆ CountsReaderMatsimV1() [2/2]

org.matsim.counts.CountsReaderMatsimV1.CountsReaderMatsimV1 ( final CoordinateTransformation  coordinateTransformation,
final Counts  counts 
)

Member Function Documentation

◆ startTag() [1/2]

void org.matsim.counts.CountsReaderMatsimV1.startTag ( final String  name,
final Attributes  atts,
final Stack< String >  context 
)

Definition at line 66 of file CountsReaderMatsimV1.java.

References org.matsim.counts.CountsReaderMatsimV1.startCount(), org.matsim.counts.CountsReaderMatsimV1.startCounts(), and org.matsim.counts.CountsReaderMatsimV1.startVolume().

66  {
67  if (VOLUME.equals(name)) {
68  startVolume(atts);
69  } else if (COUNT.equals(name)) {
70  startCount(atts);
71  } else if (COUNTS.equals(name)) {
72  startCounts(atts);
73  }
74  }
Here is the call graph for this function:

◆ endTag()

void org.matsim.counts.CountsReaderMatsimV1.endTag ( final String  name,
final String  content,
final Stack< String >  context 
)

Definition at line 77 of file CountsReaderMatsimV1.java.

77  {
78 
79  }

◆ startCounts()

void org.matsim.counts.CountsReaderMatsimV1.startCounts ( final Attributes  meta)
private

Definition at line 81 of file CountsReaderMatsimV1.java.

References org.matsim.counts.Counts< T extends Identifiable< T >.setDescription(), org.matsim.counts.Counts< T extends Identifiable< T >.setName(), and org.matsim.counts.Counts< T extends Identifiable< T >.setYear().

Referenced by org.matsim.counts.CountsReaderMatsimV1.startTag().

81  {
82  this.counts.setName(meta.getValue("name"));
83  this.counts.setDescription(meta.getValue("desc"));
84  this.counts.setYear(Integer.parseInt(meta.getValue("year")));
85  }
void setName(String name)
Definition: Counts.java:53
void setDescription(String description)
Definition: Counts.java:61
void setYear(int year)
Definition: Counts.java:77
Here is the call graph for this function:

◆ startCount()

void org.matsim.counts.CountsReaderMatsimV1.startCount ( final Attributes  meta)
private

Definition at line 87 of file CountsReaderMatsimV1.java.

References org.matsim.api.core.v01.Id< T >.create(), org.matsim.counts.Counts< T extends Identifiable< T >.createAndAddCount(), org.matsim.counts.Count< T >.setCoord(), and org.matsim.core.utils.geometry.CoordinateTransformation.transform().

Referenced by org.matsim.counts.CountsReaderMatsimV1.startTag().

87  {
88  String locId = meta.getValue("loc_id");
89  this.currcount = this.counts.createAndAddCount(Id.create(locId, Link.class), meta.getValue("cs_id"));
90  String x = meta.getValue("x");
91  String y = meta.getValue("y");
92  if (x != null && y != null) {
93  this.currcount.setCoord(
95  new Coord(
96  Double.parseDouble(x),
97  Double.parseDouble(y))));
98  }
99  }
final CoordinateTransformation coordinateTransformation
void setCoord(final Coord coord)
Definition: Count.java:147
final Count< T > createAndAddCount(final Id< T > linkId, final String stationName)
Old API.
Definition: Counts.java:114
Here is the call graph for this function:

◆ startVolume()

void org.matsim.counts.CountsReaderMatsimV1.startVolume ( final Attributes  meta)
private

Definition at line 101 of file CountsReaderMatsimV1.java.

References org.matsim.counts.Count< T >.createVolume().

Referenced by org.matsim.counts.CountsReaderMatsimV1.startTag().

101  {
102  if (this.currcount != null) {
103  this.currcount.createVolume(Integer.parseInt(meta.getValue("h")), Double.parseDouble(meta.getValue("val")));
104  }
105  }
final Volume createVolume(final int h, final double val)
Definition: Count.java:76
Here is the call graph for this function:

◆ startTag() [2/2]

abstract void org.matsim.core.utils.io.MatsimXmlParser.startTag ( String  name,
Attributes  atts,
Stack< String >  context 
)
abstractinherited

◆ setValidating()

final void org.matsim.core.utils.io.MatsimXmlParser.setValidating ( final boolean  validateXml)
inherited

Sets, if this parser should validate the read XML or not. Not validating is sometimes useful during development or during some tests with format-extensions that are not yet part of the DTD, but it is strongly discouraged not to validate during production use.

Parameters
validateXmlWhether the parsed XML should be validated or not.

Definition at line 117 of file MatsimXmlParser.java.

Referenced by org.matsim.core.events.EventsConverterXML.EventsConverterXML(), and org.matsim.core.events.EventsReaderXMLv1.EventsReaderXMLv1().

117  {
118  this.isValidating = validateXml;
119  }

◆ setNamespaceAware()

final void org.matsim.core.utils.io.MatsimXmlParser.setNamespaceAware ( final boolean  awareness)
inherited

Specifies that the parser produced by this code will provide support for XML namespaces. By default the value of this is set to false.

Parameters
awarenesstrue if the parser produced by this code will provide support for XML namespaces; false otherwise.
See also
javax.xml.parsers.SAXParserFactory::setNamespaceAware(boolean)

Definition at line 128 of file MatsimXmlParser.java.

128  {
129  this.isNamespaceAware = awareness;
130  }

◆ setLocalDtdDirectory()

final void org.matsim.core.utils.io.MatsimXmlParser.setLocalDtdDirectory ( final String  localDtdDirectory)
inherited

Sets the directory where to look for DTD and XSD files if they are not found at the location specified in the XML.

Parameters
localDtdDirectory

Definition at line 138 of file MatsimXmlParser.java.

138  {
139  this.localDtdBase = localDtdDirectory;
140  }

◆ readFile()

final void org.matsim.core.utils.io.MatsimXmlParser.readFile ( final String  filename) throws UncheckedIOException
inherited

Parses the specified file. The file can be gzip-compressed and is decompressed on-the-fly while parsing. A gzip-compressed file must have the ending ".gz" to be correctly recognized. The passed filename may or may not contain the ending ".gz". If no uncompressed file is found with the specified name, the ending ".gz" will be added to the filename and a compressed file will be searched for and read if found.

Parameters
filenameThe filename of the file to read, optionally ending with ".gz" to force reading a gzip-compressed file.
Exceptions
UncheckedIOException

Implements org.matsim.core.api.internal.MatsimReader.

Definition at line 152 of file MatsimXmlParser.java.

References org.matsim.core.utils.io.IOUtils.getBufferedReader(), and org.matsim.core.utils.io.MatsimXmlParser.parse().

Referenced by org.matsim.utils.gis.matsim2esri.plans.SelectedPlans2ESRIShape.main(), org.matsim.core.utils.io.OsmNetworkReader.parse(), org.matsim.vehicles.MatsimVehicleReader.readFile(), org.matsim.pt.transitSchedule.api.TransitScheduleReader.readFile(), org.matsim.core.events.MatsimEventsReader.readFile(), org.matsim.core.population.io.StreamingPopulationReader.readFile(), org.matsim.core.network.NetworkUtils.readNetwork(), org.matsim.core.population.PopulationUtils.readPopulation(), org.matsim.core.network.algorithms.intersectionSimplifier.RunIntersectionSimplifier.run(), and org.matsim.run.gui.ScheduleValidatorWindow.run().

152  {
153  log.info("starting to parse xml from file " + filename + " ...");
154  this.theSource = filename;
155  parse(new InputSource(IOUtils.getBufferedReader(filename)));
156  }
Here is the call graph for this function:

◆ readURL()

final void org.matsim.core.utils.io.MatsimXmlParser.readURL ( final URL  url) throws UncheckedIOException
inherited

Implements org.matsim.core.api.internal.MatsimReader.

Definition at line 159 of file MatsimXmlParser.java.

References org.matsim.core.utils.io.MatsimXmlParser.parse().

Referenced by org.matsim.vehicles.MatsimVehicleReader.readURL(), and org.matsim.core.events.MatsimEventsReader.readURL().

159  {
160  parse( url ) ;
161  }
Here is the call graph for this function:

◆ readStream()

final void org.matsim.core.utils.io.MatsimXmlParser.readStream ( InputStream  stream) throws UncheckedIOException
inherited

Definition at line 163 of file MatsimXmlParser.java.

References org.matsim.core.utils.io.MatsimXmlParser.parse().

163  {
164  parse(stream);
165  }
Here is the call graph for this function:

◆ parse() [1/3]

final void org.matsim.core.utils.io.MatsimXmlParser.parse ( final URL  url) throws UncheckedIOException
inherited

◆ parse() [2/3]

final void org.matsim.core.utils.io.MatsimXmlParser.parse ( final InputStream  stream) throws UncheckedIOException
inherited

Definition at line 175 of file MatsimXmlParser.java.

References org.matsim.core.utils.io.MatsimXmlParser.parse().

175  {
176  this.theSource = "stream";
177  parse(new InputSource(stream));
178  }
Here is the call graph for this function:

◆ parse() [3/3]

final void org.matsim.core.utils.io.MatsimXmlParser.parse ( final InputSource  input) throws UncheckedIOException
inherited

Definition at line 180 of file MatsimXmlParser.java.

References org.matsim.core.utils.io.MatsimXmlParser.ValidationType.DTD_ONLY, and org.matsim.core.utils.io.MatsimXmlParser.ValidationType.NO_VALIDATION.

180  {
181  try {
182  boolean validating = this.isValidating && this.validationType != ValidationType.NO_VALIDATION;
183  boolean useWstxParser = !validating || this.validationType == ValidationType.DTD_ONLY;
184 
185  if (useWstxParser) {
186  // use Woodstox-library as XML parser when no validation or only DTD-validation is required, as it is much faster than the default (xerces)
187 
188  WstxSAXParserFactory factory = new WstxSAXParserFactory();
189  factory.setValidating(validating);
190  factory.setNamespaceAware(this.isNamespaceAware);
191  factory.setFeature("http://xml.org/sax/features/external-general-entities", false); // prevent XEE attack: https://en.wikipedia.org/wiki/XML_external_entity_attack
192 
193  if (validating) {
194  factory.setFeature("http://xml.org/sax/features/validation", true); // required to enable DTD validation in Woodstox
195  SAXParser parser = factory.newSAXParser();
196  XMLReader reader = parser.getXMLReader();
197  reader.setContentHandler(this);
198  reader.setErrorHandler(this);
199  reader.setEntityResolver(this);
200  reader.parse(input);
201  } else {
202  SAXParser parser = factory.newSAXParser();
203  parser.parse(input, this);
204  }
205 
206  } else {
207  // use the default (Xerces) SAX parser, it is slower than Woodstox, but supports XSD validation
208 
209  SAXParserFactory factory = SAXParserFactory.newInstance();
210  factory.setValidating(validating);
211  factory.setNamespaceAware(this.isNamespaceAware);
212  factory.setFeature("http://xml.org/sax/features/external-general-entities", false); // prevent XEE attack: https://en.wikipedia.org/wiki/XML_external_entity_attack
213 
214  if (validating) {
215  // enable optional support for XML Schemas
216  factory.setFeature("http://apache.org/xml/features/validation/schema", true);
217  SAXParser parser = factory.newSAXParser();
218  XMLReader reader = parser.getXMLReader();
219  reader.setContentHandler(this);
220  reader.setErrorHandler(this);
221  reader.setEntityResolver(this);
222  reader.parse(input);
223  } else {
224  SAXParser parser = factory.newSAXParser();
225  parser.parse(input, this);
226  }
227  }
228  } catch (IOException e) {
229  throw new UncheckedIOException(e);
230  } catch (SAXException | ParserConfigurationException e) {
231  throw new UncheckedIOException(new IOException(e));
232  }
233  }

◆ getDoctype()

final String org.matsim.core.utils.io.MatsimXmlParser.getDoctype ( )
inherited

Definition at line 235 of file MatsimXmlParser.java.

References org.matsim.core.utils.io.MatsimXmlParser.doctype.

235  {
236  return this.doctype;
237  }

◆ setDoctype()

void org.matsim.core.utils.io.MatsimXmlParser.setDoctype ( final String  doctype)
protectedinherited

Definition at line 239 of file MatsimXmlParser.java.

References org.matsim.core.utils.io.MatsimXmlParser.doctype.

Referenced by org.matsim.core.utils.io.MatsimXmlParser.resolveEntity().

239  {
240  // implementation of this method is what reacts to the different version of the file formats, so we cannot make it final. kai, jul'16
241 
242  this.doctype = doctype;
243  }

◆ resolveEntity()

final InputSource org.matsim.core.utils.io.MatsimXmlParser.resolveEntity ( final String  publicId,
final String  systemId 
)
inherited

Definition at line 248 of file MatsimXmlParser.java.

References org.matsim.core.utils.io.MatsimXmlParser.findDtdInClasspath(), org.matsim.core.utils.io.MatsimXmlParser.findDtdInDefaultLocation(), org.matsim.core.utils.io.MatsimXmlParser.findDtdInLocalFilesystem(), org.matsim.core.utils.io.MatsimXmlParser.findDtdInRemoteLocation(), and org.matsim.core.utils.io.MatsimXmlParser.setDoctype().

248  {
249  // ConfigReader* did override this. Not sure if it did that for good reasons. kai, jul'16
250 
251  // extract the last part of the systemId
252  int index = systemId.replace('\\', '/').lastIndexOf('/');
253  String shortSystemId = systemId.substring(index + 1);
254 
255  if (this.doctype == null) {
256  // this is the first systemId we have to resolve, assume it's the doctype
257  // I haven't found any other way to determine the doctype of the currently read file
258  setDoctype(shortSystemId);
259  }
260 
261  InputSource source;
262  if (this.preferLocalDtds) {
263  source = findDtdInLocalFilesystem(shortSystemId);
264  if (source == null) {
265  source = findDtdInClasspath(shortSystemId);
266  }
267  if (source == null) {
268  source = findDtdInDefaultLocation(shortSystemId);
269  }
270  if (source == null) {
271  source = findDtdInRemoteLocation(systemId);
272  }
273  } else {
274  source = findDtdInRemoteLocation(systemId);
275  if (source == null) {
276  source = findDtdInLocalFilesystem(shortSystemId);
277  }
278  if (source == null) {
279  source = findDtdInClasspath(shortSystemId);
280  }
281  if (source == null) {
282  source = findDtdInDefaultLocation(shortSystemId);
283  }
284  }
285 
286  if (source == null) {
287  // We could neither get the remote nor the local version of the dtd, show a warning
288  log.warn("Could neither get the DTD from the web nor a local one. " + systemId);
289  } else {
290  source.setSystemId(systemId);
291  }
292  return source;
293  }
static InputSource findDtdInDefaultLocation(final String shortSystemId)
static InputSource findDtdInRemoteLocation(final String fullSystemId)
InputSource findDtdInLocalFilesystem(final String shortSystemId)
InputSource findDtdInClasspath(final String shortSystemId)
Here is the call graph for this function:

◆ characters()

void org.matsim.core.utils.io.MatsimXmlParser.characters ( final char []  ch,
final int  start,
final int  length 
) throws SAXException
inherited

Definition at line 352 of file MatsimXmlParser.java.

352  {
353  // has to be non-final since otherwise the events parser does not work. Probably ok (this here is just a default implementation). kai, jul'16
354 
355  StringBuffer buffer = this.buffers.peek();
356  if (buffer != null) {
357  buffer.append(ch, start, length);
358  }
359  }

◆ startElement()

final void org.matsim.core.utils.io.MatsimXmlParser.startElement ( final String  uri,
final String  localName,
final String  qName,
Attributes  atts 
)
inherited

Definition at line 362 of file MatsimXmlParser.java.

References org.matsim.core.utils.io.MatsimXmlParser.startTag().

362  {
363  // I have not good intuition if making this one non-final might be ok. kai, jul'16
364 
365  String tag = (uri.length() == 0) ? qName : localName;
366  this.buffers.push(new StringBuffer());
367  this.startTag(tag, atts, this.theContext);
368  this.theContext.push(tag);
369  }
abstract void startTag(String name, Attributes atts, Stack< String > context)
Here is the call graph for this function:

◆ endElement()

final void org.matsim.core.utils.io.MatsimXmlParser.endElement ( final String  uri,
final String  localName,
final String  qName 
) throws SAXException
inherited

Definition at line 372 of file MatsimXmlParser.java.

References org.matsim.core.utils.io.MatsimXmlParser.endTag(), and org.matsim.core.utils.io.MatsimXmlParser.theContext.

372  {
373  // I have not good intuition if making this one non-final might be ok. kai, jul'16
374 
375  String tag = (uri.length() == 0) ? qName : localName;
376  this.theContext.pop();
377  StringBuffer buffer = this.buffers.pop();
378  this.endTag(tag, buffer.toString(), this.theContext);
379  }
abstract void endTag(String name, String content, Stack< String > context)
Here is the call graph for this function:

◆ error()

final void org.matsim.core.utils.io.MatsimXmlParser.error ( final SAXParseException  ex) throws SAXException
inherited

Definition at line 384 of file MatsimXmlParser.java.

References org.matsim.core.utils.io.MatsimXmlParser.getInputSource().

384  {
385  if (this.theContext.isEmpty()) {
386  System.err.println("Missing DOCTYPE.");
387  }
388  System.err.println("XML-ERROR: " + getInputSource(ex) + ", line " + ex.getLineNumber() + ", column " + ex.getColumnNumber() + ":");
389  System.err.println(ex.toString());
390  throw ex;
391  }
String getInputSource(final SAXParseException ex)
Here is the call graph for this function:

◆ fatalError()

final void org.matsim.core.utils.io.MatsimXmlParser.fatalError ( final SAXParseException  ex) throws SAXException
inherited

Definition at line 394 of file MatsimXmlParser.java.

References org.matsim.core.utils.io.MatsimXmlParser.getInputSource().

394  {
395  System.err.println("XML-FATAL: " + getInputSource(ex) + ", line " + ex.getLineNumber() + ", column " + ex.getColumnNumber() + ":");
396  System.err.println(ex.toString());
397  throw ex;
398  }
String getInputSource(final SAXParseException ex)
Here is the call graph for this function:

◆ warning()

final void org.matsim.core.utils.io.MatsimXmlParser.warning ( final SAXParseException  ex) throws SAXException
inherited

Definition at line 401 of file MatsimXmlParser.java.

References org.matsim.core.utils.io.MatsimXmlParser.getInputSource().

401  {
402  System.err.println("XML-WARNING: " + getInputSource(ex) + ", line " + ex.getLineNumber() + ", column " + ex.getColumnNumber() + ":");
403  System.err.println(ex.getMessage());
404  }
String getInputSource(final SAXParseException ex)
Here is the call graph for this function:

◆ parseDouble()

static double org.matsim.core.utils.io.MatsimXmlParser.parseDouble ( String  value) throws NumberFormatException
staticinherited

Parses a String into a double, taking into account the special encoding for Infinity according to the xsd-specifications for the xs:double data type

Definition at line 426 of file MatsimXmlParser.java.

426  {
427  if ("INF".equals(value)) {
428  return Double.POSITIVE_INFINITY;
429  }
430  if ("-INF".equals(value)) {
431  return Double.NEGATIVE_INFINITY;
432  }
433  if ("NaN".equals(value)) {
434  return Double.NaN;
435  }
436  return Double.parseDouble(value);
437  }

Member Data Documentation

◆ COUNTS

final String org.matsim.counts.CountsReaderMatsimV1.COUNTS = "counts"
staticprivate

Definition at line 42 of file CountsReaderMatsimV1.java.

◆ COUNT

final String org.matsim.counts.CountsReaderMatsimV1.COUNT = "count"
staticprivate

Definition at line 43 of file CountsReaderMatsimV1.java.

◆ VOLUME

final String org.matsim.counts.CountsReaderMatsimV1.VOLUME = "volume"
staticprivate

Definition at line 44 of file CountsReaderMatsimV1.java.

◆ coordinateTransformation

final CoordinateTransformation org.matsim.counts.CountsReaderMatsimV1.coordinateTransformation
private

◆ counts

final Counts org.matsim.counts.CountsReaderMatsimV1.counts
private

◆ currcount

Count org.matsim.counts.CountsReaderMatsimV1.currcount = null
private

Definition at line 49 of file CountsReaderMatsimV1.java.

◆ log

final Logger org.matsim.counts.CountsReaderMatsimV1.log = LogManager.getLogger(CountsReaderMatsimV1.class)
staticprivate

Definition at line 51 of file CountsReaderMatsimV1.java.


The documentation for this class was generated from the following file: