Use new fare API format

This commit is contained in:
Doug Keen 2016-10-28 07:05:40 -07:00
parent a1db2cf90b
commit 83b739737e

View File

@ -4,43 +4,31 @@ import org.xml.sax.Attributes;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler; import org.xml.sax.helpers.DefaultHandler;
import java.util.HashMap;
import java.util.Map;
public class FareContentHandler extends DefaultHandler { public class FareContentHandler extends DefaultHandler {
public FareContentHandler() { public FareContentHandler() {
super(); super();
} }
private String currentValue;
private boolean isParsingTag;
private String fare; private String fare;
public String getFare() { public String getFare() {
return fare; return fare;
} }
@Override
public void characters(char[] ch, int start, int length)
throws SAXException {
if (isParsingTag) {
currentValue = new String(ch, start, length);
}
}
@Override @Override
public void startElement(String uri, String localName, String qName, public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException { Attributes attributes) throws SAXException {
if (localName.equals("fare")) { if (localName.equals("fare")) {
isParsingTag = true; Map<String, String> attributeMap = new HashMap<>();
for (int i = attributes.getLength() - 1; i >= 0; i--) {
attributeMap.put(attributes.getLocalName(i), attributes.getValue(i));
}
if (attributeMap.containsKey("class") && attributeMap.get("class").equals("cash")) {
fare = "$" + attributeMap.get("amount");
} }
} }
@Override
public void endElement(String uri, String localName, String qName)
throws SAXException {
if (localName.equals("fare") && currentValue != null) {
fare = "$" + currentValue;
} }
isParsingTag = false;
currentValue = null;
}
} }