SUMOSAXNeworkfileHandler.java
Go to the documentation of this file.00001 package de.psi.telco.sumoplayer;
00002
00003 import org.xml.sax.Attributes;
00004 import org.xml.sax.SAXException;
00005 import org.xml.sax.helpers.DefaultHandler;
00006
00007 import de.psi.telco.sumoplayer.util.PointImpl;
00008
00015 public class SUMOSAXNeworkfileHandler extends DefaultHandler{
00016
00017
00018 public SUMONetwork network = new SUMONetwork();;
00019
00020
00021 private static int UNKNOWN = 0;
00022 private static int EDGE = 1;
00023 private static int LANE = 2;
00024 private static int CEDGE = 3;
00025 private static int JUNCTION = 4;
00026 private static int OFFSET = 5;
00027 private static int PROJ = 6;
00028 private int currentElementType;
00029
00030
00031 private String sumoEdgeId;
00032 private String sumoLaneId;
00033 private String cEdgeId;
00034 private String junctionId;
00035
00036 public void startElement (String uri, String localName, String qName, Attributes attributes) throws SAXException{
00037 if (qName.equals("edge")){
00038 this.currentElementType = EDGE;
00039 sumoEdgeId = attributes.getValue("id");
00040
00041 }else if (qName.equals("lane")){
00042 this.currentElementType = LANE;
00043 sumoLaneId = attributes.getValue("id");
00044
00045 network.lanes.put(sumoLaneId, new SUMOLane(sumoLaneId));
00046
00047 }else if (qName.equals("cedge")){
00048 this.currentElementType = CEDGE;
00049 cEdgeId = attributes.getValue("id");
00050 }
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064 else if (qName.equals("net-offset")){
00065 this.currentElementType = OFFSET;
00066 }else if (qName.equals("orig-proj")){
00067 this.currentElementType = PROJ;
00068 }
00069
00070 }
00071
00072 public void endElement (String uri, String localName, String qName) throws SAXException{
00073 this.currentElementType = UNKNOWN;
00074 }
00075
00076
00077 public void characters (char ch[], int start, int length){
00078
00079 if (currentElementType == LANE){
00080
00081 char[] chars = new char[length];
00082 for (int i = 0; i<length; i++){
00083 chars[i] = ch[start+i];
00084 }
00085 String data = new String(chars);
00086
00087 String[] coordPairs = data.split(" ");
00088 for (int i = 0 ; i < coordPairs.length; i++){
00089 String[] coordElements = coordPairs[i].split(",");
00090 if (coordElements != null && coordElements.length == 2){
00091 try{
00092 double x = Double.parseDouble(coordElements[0]);
00093 double y = Double.parseDouble(coordElements[1]);
00094
00095 network.lanes.get(sumoLaneId).points.add(new PointImpl(x,y));
00096 }catch(NumberFormatException e){
00097 }
00098 }
00099 }
00100
00101 }else if (currentElementType == OFFSET){
00102 char[] chars = new char[length];
00103 for (int i = 0; i<length; i++){
00104 chars[i] = ch[start+i];
00105 }
00106 String data = new String(chars);
00107 String[] vectorElements = data.split(",");
00108 if (vectorElements.length==2){
00109 network.offset = new PointImpl(Double.parseDouble(vectorElements[0]),Double.parseDouble(vectorElements[1]));
00110 }
00111 }else if (currentElementType == PROJ){
00112 char[] chars = new char[length];
00113 for (int i = 0; i<length; i++){
00114 chars[i] = ch[start+i];
00115 }
00116 network.projString = new String(chars);
00117 }
00118 }
00119 }