Package org.openstreetmap.josm.tools
Class XmlObjectParser
- java.lang.Object
-
- org.openstreetmap.josm.tools.XmlObjectParser
-
- All Implemented Interfaces:
java.lang.Iterable<java.lang.Object>
public class XmlObjectParser extends java.lang.Object implements java.lang.Iterable<java.lang.Object>
An helper class that reads from a XML stream into specific objects.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classXmlObjectParser.AddNamespaceFilterprivate static classXmlObjectParser.Entryprivate classXmlObjectParser.Parser
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringlangThe language prefix to useprivate java.util.Map<java.lang.String,XmlObjectParser.Entry>mappingprivate org.xml.sax.helpers.DefaultHandlerparserprivate java.util.List<java.lang.Object>queueThe queue of already parsed items from the parsing thread.private java.util.Iterator<java.lang.Object>queueIterator
-
Constructor Summary
Constructors Constructor Description XmlObjectParser()Constructs a newXmlObjectParser.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanhasNext()Check if there is a next parsed object availablejava.util.Iterator<java.lang.Object>iterator()voidmap(java.lang.String tagName, java.lang.Class<?> klass)Add a new tag name to class type mappingvoidmapBoth(java.lang.String tagName, java.lang.Class<?> klass)voidmapOnStart(java.lang.String tagName, java.lang.Class<?> klass)java.lang.Objectnext()Get the next element that was parsedjava.lang.Iterable<java.lang.Object>start(java.io.Reader in)Starts parsing from the given input reader, without validation.private java.lang.Iterable<java.lang.Object>start(java.io.Reader in, org.xml.sax.ContentHandler contentHandler)java.lang.Iterable<java.lang.Object>startWithValidation(java.io.Reader in, java.lang.String namespace, java.lang.String schemaSource)Starts parsing from the given input reader, with XSD validation.
-
-
-
Field Detail
-
lang
public static final java.lang.String lang
The language prefix to use
-
mapping
private final java.util.Map<java.lang.String,XmlObjectParser.Entry> mapping
-
parser
private final org.xml.sax.helpers.DefaultHandler parser
-
queue
private final java.util.List<java.lang.Object> queue
The queue of already parsed items from the parsing thread.
-
queueIterator
private java.util.Iterator<java.lang.Object> queueIterator
-
-
Constructor Detail
-
XmlObjectParser
public XmlObjectParser()
Constructs a newXmlObjectParser.
-
-
Method Detail
-
start
private java.lang.Iterable<java.lang.Object> start(java.io.Reader in, org.xml.sax.ContentHandler contentHandler) throws org.xml.sax.SAXException, java.io.IOException
- Throws:
org.xml.sax.SAXExceptionjava.io.IOException
-
start
public java.lang.Iterable<java.lang.Object> start(java.io.Reader in) throws org.xml.sax.SAXException
Starts parsing from the given input reader, without validation.- Parameters:
in- The input reader- Returns:
- iterable collection of objects
- Throws:
org.xml.sax.SAXException- if any XML or I/O error occurs
-
startWithValidation
public java.lang.Iterable<java.lang.Object> startWithValidation(java.io.Reader in, java.lang.String namespace, java.lang.String schemaSource) throws org.xml.sax.SAXException
Starts parsing from the given input reader, with XSD validation.- Parameters:
in- The input readernamespace- default namespaceschemaSource- XSD schema- Returns:
- iterable collection of objects
- Throws:
org.xml.sax.SAXException- if any XML or I/O error occurs
-
map
public void map(java.lang.String tagName, java.lang.Class<?> klass)
Add a new tag name to class type mapping- Parameters:
tagName- The tag name that should be converted to that classklass- The class the XML elements should be converted to.
-
mapOnStart
public void mapOnStart(java.lang.String tagName, java.lang.Class<?> klass)
-
mapBoth
public void mapBoth(java.lang.String tagName, java.lang.Class<?> klass)
-
next
public java.lang.Object next()
Get the next element that was parsed- Returns:
- The next object
-
hasNext
public boolean hasNext()
Check if there is a next parsed object available- Returns:
trueif there is a next object
-
iterator
public java.util.Iterator<java.lang.Object> iterator()
- Specified by:
iteratorin interfacejava.lang.Iterable<java.lang.Object>
-
-