| 1 | /* |
|---|
| 2 | * To change this license header, choose License Headers in Project Properties. |
|---|
| 3 | * To change this template file, choose Tools | Templates |
|---|
| 4 | * and open the template in the editor. |
|---|
| 5 | */ |
|---|
| 6 | package scriptbuilder.structures; |
|---|
| 7 | |
|---|
| 8 | import java.util.ArrayList; |
|---|
| 9 | import java.util.Random; |
|---|
| 10 | import java.util.Stack; |
|---|
| 11 | import java.util.TreeMap; |
|---|
| 12 | import java.util.Vector; |
|---|
| 13 | import java.util.logging.Level; |
|---|
| 14 | import java.util.logging.Logger; |
|---|
| 15 | import org.xml.sax.Attributes; |
|---|
| 16 | import org.xml.sax.SAXParseException; |
|---|
| 17 | import org.xml.sax.helpers.DefaultHandler; |
|---|
| 18 | import scriptbuilder.structures.events.*; |
|---|
| 19 | import scriptbuilder.structures.units.Unit; |
|---|
| 20 | |
|---|
| 21 | /** |
|---|
| 22 | * Script Handler class for the ScriptBuilder. Adapted from the TMCSim script |
|---|
| 23 | * handler written by Matthew Cechini. |
|---|
| 24 | * |
|---|
| 25 | * @author Bryan McGuffin |
|---|
| 26 | * @version 2017/07/03 |
|---|
| 27 | */ |
|---|
| 28 | public class MyScriptHandler extends DefaultHandler |
|---|
| 29 | { |
|---|
| 30 | |
|---|
| 31 | /** |
|---|
| 32 | * Error Logger. |
|---|
| 33 | */ |
|---|
| 34 | private Logger myScriptLogger = Logger.getLogger("scriptbuilder.structures"); |
|---|
| 35 | |
|---|
| 36 | /** |
|---|
| 37 | * The script which XML entities will be entered into. |
|---|
| 38 | */ |
|---|
| 39 | private SimulationScript script; |
|---|
| 40 | |
|---|
| 41 | /** |
|---|
| 42 | * Map containing all parsed values. Keys = XML Element. Values = parsed |
|---|
| 43 | * character data from XML file. |
|---|
| 44 | */ |
|---|
| 45 | private TreeMap<ELEMENT, String> pcData; |
|---|
| 46 | |
|---|
| 47 | /** |
|---|
| 48 | * Current element that we're in. |
|---|
| 49 | */ |
|---|
| 50 | private ELEMENT currentElement; |
|---|
| 51 | |
|---|
| 52 | /** |
|---|
| 53 | * Ordering of elements that we're within. |
|---|
| 54 | */ |
|---|
| 55 | private Stack<ELEMENT> docPosition; |
|---|
| 56 | |
|---|
| 57 | /** |
|---|
| 58 | * Map containing all parsed Incidents. Keys = Incident Log Number. Values = |
|---|
| 59 | * Incident object. |
|---|
| 60 | */ |
|---|
| 61 | private TreeMap<Integer, ScriptIncident> incidentMap; |
|---|
| 62 | |
|---|
| 63 | /** |
|---|
| 64 | * Map containing all Units. Keys = Unit number. Values = Unit object. |
|---|
| 65 | */ |
|---|
| 66 | private ArrayList<Unit> units; |
|---|
| 67 | |
|---|
| 68 | /** |
|---|
| 69 | * Map containing all parsed script events. Keys = XML file level. Values = |
|---|
| 70 | * Event object. |
|---|
| 71 | */ |
|---|
| 72 | private TreeMap<ELEMENT, I_ScriptEvent> eventMap; |
|---|
| 73 | |
|---|
| 74 | /** |
|---|
| 75 | * Buffer used to hold parsed tag content. |
|---|
| 76 | */ |
|---|
| 77 | private StringBuffer parsedValue = new StringBuffer(); |
|---|
| 78 | |
|---|
| 79 | /** |
|---|
| 80 | * ************************************************* |
|---|
| 81 | * ~~~~~~~~Element attribute data.~~~~~~~~ |
|---|
| 82 | * ************************************************** |
|---|
| 83 | */ |
|---|
| 84 | /** |
|---|
| 85 | * Log number for the current ScriptEvent being parsed. |
|---|
| 86 | */ |
|---|
| 87 | private Integer incidentLogNumber = 0; |
|---|
| 88 | |
|---|
| 89 | /** |
|---|
| 90 | * File path for the current audio file. |
|---|
| 91 | */ |
|---|
| 92 | private String audioPath = ""; |
|---|
| 93 | |
|---|
| 94 | /** |
|---|
| 95 | * Length in seconds of the current audio file. |
|---|
| 96 | */ |
|---|
| 97 | private Integer audioLength = 0; |
|---|
| 98 | |
|---|
| 99 | /** |
|---|
| 100 | * Category name for the current cardfile. |
|---|
| 101 | */ |
|---|
| 102 | private String cardfileCategory = ""; |
|---|
| 103 | |
|---|
| 104 | /** |
|---|
| 105 | * File path for the current CHP radio file. |
|---|
| 106 | */ |
|---|
| 107 | private String CHPRadiofile = ""; |
|---|
| 108 | |
|---|
| 109 | /** |
|---|
| 110 | * ID number for the current CMS data. |
|---|
| 111 | */ |
|---|
| 112 | private String CMSID = ""; |
|---|
| 113 | |
|---|
| 114 | /** |
|---|
| 115 | * Type for the current CMS data. |
|---|
| 116 | */ |
|---|
| 117 | private String CMSType = ""; |
|---|
| 118 | |
|---|
| 119 | /** |
|---|
| 120 | * Role played by the instructor for the current dialog line. |
|---|
| 121 | */ |
|---|
| 122 | private String InstructorRole = ""; |
|---|
| 123 | |
|---|
| 124 | /** |
|---|
| 125 | * Role played by the speaker for the current dialog line. |
|---|
| 126 | */ |
|---|
| 127 | private String LineRole = ""; |
|---|
| 128 | |
|---|
| 129 | /** |
|---|
| 130 | * ID number for the current location info. |
|---|
| 131 | */ |
|---|
| 132 | private String LocationInfoID = ""; |
|---|
| 133 | |
|---|
| 134 | /** |
|---|
| 135 | * ID number for the current unit. |
|---|
| 136 | */ |
|---|
| 137 | private String NewUnitNum = ""; |
|---|
| 138 | |
|---|
| 139 | /** |
|---|
| 140 | * ID number for the current Paramics data. |
|---|
| 141 | */ |
|---|
| 142 | private String ParamicsID = ""; |
|---|
| 143 | |
|---|
| 144 | /** |
|---|
| 145 | * Title of the script. |
|---|
| 146 | */ |
|---|
| 147 | private String TMCTitle = ""; |
|---|
| 148 | |
|---|
| 149 | /** |
|---|
| 150 | * Beat for the current Tow data. |
|---|
| 151 | */ |
|---|
| 152 | private String TowBeat = ""; |
|---|
| 153 | |
|---|
| 154 | /** |
|---|
| 155 | * Company name for the current Tow data. |
|---|
| 156 | */ |
|---|
| 157 | private String TowCompany = ""; |
|---|
| 158 | |
|---|
| 159 | /** |
|---|
| 160 | * Confirmation phone number for the current Tow data. |
|---|
| 161 | */ |
|---|
| 162 | private String TowConfNum = ""; |
|---|
| 163 | |
|---|
| 164 | /** |
|---|
| 165 | * Public telephone number for the current Tow data. |
|---|
| 166 | */ |
|---|
| 167 | private String TowPubNum = ""; |
|---|
| 168 | |
|---|
| 169 | /** |
|---|
| 170 | * True/false value for whether the current unit is active. |
|---|
| 171 | */ |
|---|
| 172 | private String UnitActive = ""; |
|---|
| 173 | |
|---|
| 174 | /** |
|---|
| 175 | * True/false value for whether the current unit is the primary unit. |
|---|
| 176 | */ |
|---|
| 177 | private String UnitPrimary = ""; |
|---|
| 178 | |
|---|
| 179 | /** |
|---|
| 180 | * Status of the current unit. |
|---|
| 181 | */ |
|---|
| 182 | private String UnitStatus = ""; |
|---|
| 183 | |
|---|
| 184 | /** |
|---|
| 185 | * ID number for the current unit. |
|---|
| 186 | */ |
|---|
| 187 | private String UnitNum = ""; |
|---|
| 188 | |
|---|
| 189 | /** |
|---|
| 190 | * Street address of the current witness. |
|---|
| 191 | */ |
|---|
| 192 | private String WitnessAddress = ""; |
|---|
| 193 | |
|---|
| 194 | /** |
|---|
| 195 | * Name of the current witness. |
|---|
| 196 | */ |
|---|
| 197 | private String WitnessName = ""; |
|---|
| 198 | |
|---|
| 199 | /** |
|---|
| 200 | * Phone number of the current witness. |
|---|
| 201 | */ |
|---|
| 202 | private String WitnessNum = ""; |
|---|
| 203 | |
|---|
| 204 | /** |
|---|
| 205 | * If true, the current CAD event is not empty. |
|---|
| 206 | */ |
|---|
| 207 | private boolean foundSubEvents = false; |
|---|
| 208 | |
|---|
| 209 | /** |
|---|
| 210 | * The most recent element which contains dialog or other sub-elements. |
|---|
| 211 | */ |
|---|
| 212 | private I_ScriptEvent trackedEvent = null; |
|---|
| 213 | |
|---|
| 214 | /** |
|---|
| 215 | * Incident description for the current ScriptEvent being parsed. |
|---|
| 216 | */ |
|---|
| 217 | private String currentIncidentDesc = ""; |
|---|
| 218 | |
|---|
| 219 | /** |
|---|
| 220 | * Name of the current incident. |
|---|
| 221 | */ |
|---|
| 222 | private String currentIncName = ""; |
|---|
| 223 | |
|---|
| 224 | /** |
|---|
| 225 | * Time index value (in seconds) for the current ScriptEvent being parsed. |
|---|
| 226 | */ |
|---|
| 227 | private long currentEventTime = 0; |
|---|
| 228 | |
|---|
| 229 | /** |
|---|
| 230 | * Number of levels deep we are. Used for debugging. |
|---|
| 231 | */ |
|---|
| 232 | private int sublevels = 0; |
|---|
| 233 | |
|---|
| 234 | /** |
|---|
| 235 | * The incident we are currently editing. |
|---|
| 236 | */ |
|---|
| 237 | private ScriptIncident currInc = null; |
|---|
| 238 | |
|---|
| 239 | private CadData cad = null; |
|---|
| 240 | |
|---|
| 241 | /** |
|---|
| 242 | * Constructor. Initializes incident map. |
|---|
| 243 | * |
|---|
| 244 | * @param scr the script into which the XML file is being read |
|---|
| 245 | */ |
|---|
| 246 | public MyScriptHandler(SimulationScript scr) |
|---|
| 247 | { |
|---|
| 248 | script = scr; |
|---|
| 249 | incidentMap = new TreeMap<Integer, ScriptIncident>(); |
|---|
| 250 | eventMap = new TreeMap<ELEMENT, I_ScriptEvent>(); |
|---|
| 251 | units = new ArrayList<Unit>(); |
|---|
| 252 | pcData = new TreeMap<ELEMENT, String>(); |
|---|
| 253 | docPosition = new Stack<ELEMENT>(); |
|---|
| 254 | } |
|---|
| 255 | |
|---|
| 256 | /** |
|---|
| 257 | * Get the list of incidents that have been parsed from the script file. |
|---|
| 258 | * |
|---|
| 259 | * @return Vector of Incident objects. |
|---|
| 260 | */ |
|---|
| 261 | public Vector<ScriptIncident> getIncidents() |
|---|
| 262 | { |
|---|
| 263 | return new Vector<ScriptIncident>(incidentMap.values()); |
|---|
| 264 | } |
|---|
| 265 | |
|---|
| 266 | /** |
|---|
| 267 | * Get the list of units that have been parsed from the script file. |
|---|
| 268 | * |
|---|
| 269 | * @return Vector of Unit objects. |
|---|
| 270 | */ |
|---|
| 271 | public ArrayList<Unit> getUnits() |
|---|
| 272 | { |
|---|
| 273 | return units; |
|---|
| 274 | } |
|---|
| 275 | |
|---|
| 276 | /** |
|---|
| 277 | * SAX Handler method. Clear incident map and reset the error flag. |
|---|
| 278 | */ |
|---|
| 279 | @Override |
|---|
| 280 | public void startDocument() |
|---|
| 281 | { |
|---|
| 282 | //System.out.println("STUB: Start the document"); |
|---|
| 283 | |
|---|
| 284 | } |
|---|
| 285 | |
|---|
| 286 | /** |
|---|
| 287 | * Clear all existing events, thereby resetting the script. |
|---|
| 288 | */ |
|---|
| 289 | public void reset() |
|---|
| 290 | { |
|---|
| 291 | incidentMap.clear(); |
|---|
| 292 | System.out.println("STUB: Restart the document"); |
|---|
| 293 | } |
|---|
| 294 | |
|---|
| 295 | /** |
|---|
| 296 | * SAX Handler method. Executes at the beginning of each XML element. |
|---|
| 297 | */ |
|---|
| 298 | @Override |
|---|
| 299 | public void startElement(String uri, String localName, String qName, Attributes attributes) |
|---|
| 300 | { |
|---|
| 301 | |
|---|
| 302 | docPosition.push(ELEMENT.byName(qName)); |
|---|
| 303 | |
|---|
| 304 | try |
|---|
| 305 | { |
|---|
| 306 | if (qName.equals(ELEMENT.ACTIVITY_LOG_EVALUATION.tag)) |
|---|
| 307 | { |
|---|
| 308 | eventMap.put(docPosition.peek(), ScriptEvent.factoryByType(ScriptEvent.ScriptEventType.ACTIVITY_LOG_EVAL_EVENT)); |
|---|
| 309 | trackedEvent = eventMap.get(docPosition.peek()); |
|---|
| 310 | } |
|---|
| 311 | else if (qName.equals(ELEMENT.ATMS_EVALUATION.tag)) |
|---|
| 312 | { |
|---|
| 313 | eventMap.put(docPosition.peek(), ScriptEvent.factoryByType(ScriptEvent.ScriptEventType.ATMS_EVAL_EVENT)); |
|---|
| 314 | trackedEvent = eventMap.get(docPosition.peek()); |
|---|
| 315 | } |
|---|
| 316 | else if (qName.equals(ELEMENT.AUDIO.tag)) |
|---|
| 317 | { |
|---|
| 318 | foundSubEvents = true; |
|---|
| 319 | eventMap.put(docPosition.peek(), ScriptEvent.factoryByType(ScriptEvent.ScriptEventType.AUDIO_EVENT)); |
|---|
| 320 | try |
|---|
| 321 | { |
|---|
| 322 | audioLength = Integer.parseInt(attributes.getValue("Length")); |
|---|
| 323 | audioPath = attributes.getValue("Path"); |
|---|
| 324 | } |
|---|
| 325 | catch (Exception e) |
|---|
| 326 | { |
|---|
| 327 | audioLength = 0; |
|---|
| 328 | audioPath = ""; |
|---|
| 329 | } |
|---|
| 330 | } |
|---|
| 331 | else if (qName.equals(ELEMENT.CARDFILE.tag)) |
|---|
| 332 | { |
|---|
| 333 | try |
|---|
| 334 | { |
|---|
| 335 | cardfileCategory = attributes.getValue("Category"); |
|---|
| 336 | } |
|---|
| 337 | catch (Exception e) |
|---|
| 338 | { |
|---|
| 339 | cardfileCategory = ""; |
|---|
| 340 | } |
|---|
| 341 | } |
|---|
| 342 | else if (qName.equals(ELEMENT.CAD_EVALUATION.tag)) |
|---|
| 343 | { |
|---|
| 344 | eventMap.put(docPosition.peek(), ScriptEvent.factoryByType(ScriptEvent.ScriptEventType.CAD_EVAL_EVENT)); |
|---|
| 345 | trackedEvent = eventMap.get(docPosition.peek()); |
|---|
| 346 | } |
|---|
| 347 | else if (qName.equals(ELEMENT.CAD_INCIDENT_EVENT.tag)) |
|---|
| 348 | { |
|---|
| 349 | eventMap.put(docPosition.peek(), ScriptEvent.factoryByType(ScriptEvent.ScriptEventType.CAD_EVENT)); |
|---|
| 350 | } |
|---|
| 351 | else if (qName.equals(ELEMENT.CCTV_INFO.tag)) |
|---|
| 352 | { |
|---|
| 353 | foundSubEvents = true; |
|---|
| 354 | eventMap.put(docPosition.peek(), ScriptEvent.factoryByType(ScriptEvent.ScriptEventType.CCTV_EVENT)); |
|---|
| 355 | } |
|---|
| 356 | else if (qName.equals(ELEMENT.CHP_RADIO.tag)) |
|---|
| 357 | { |
|---|
| 358 | eventMap.put(docPosition.peek(), ScriptEvent.factoryByType(ScriptEvent.ScriptEventType.CHP_RADIO_EVENT)); |
|---|
| 359 | trackedEvent = eventMap.get(docPosition.peek()); |
|---|
| 360 | try |
|---|
| 361 | { |
|---|
| 362 | CHPRadiofile = attributes.getValue("RadioFile"); |
|---|
| 363 | } |
|---|
| 364 | catch (Exception e) |
|---|
| 365 | { |
|---|
| 366 | CHPRadiofile = ""; |
|---|
| 367 | } |
|---|
| 368 | } |
|---|
| 369 | else if (qName.equals(ELEMENT.CMS_EVALUATION.tag)) |
|---|
| 370 | { |
|---|
| 371 | eventMap.put(docPosition.peek(), ScriptEvent.factoryByType(ScriptEvent.ScriptEventType.CMS_EVAL_EVENT)); |
|---|
| 372 | trackedEvent = eventMap.get(docPosition.peek()); |
|---|
| 373 | try |
|---|
| 374 | { |
|---|
| 375 | CMSID = attributes.getValue("cmsID"); |
|---|
| 376 | CMSType = attributes.getValue("type"); |
|---|
| 377 | } |
|---|
| 378 | catch (Exception e) |
|---|
| 379 | { |
|---|
| 380 | CMSID = ""; |
|---|
| 381 | CMSType = ""; |
|---|
| 382 | } |
|---|
| 383 | } |
|---|
| 384 | else if (qName.equals(ELEMENT.FACILITATOR_EVALUATION.tag)) |
|---|
| 385 | { |
|---|
| 386 | eventMap.put(docPosition.peek(), ScriptEvent.factoryByType(ScriptEvent.ScriptEventType.FACILITATOR_EVAL_EVENT)); |
|---|
| 387 | trackedEvent = eventMap.get(docPosition.peek()); |
|---|
| 388 | } |
|---|
| 389 | else if (qName.equals(ELEMENT.INSTRUCTOR.tag)) |
|---|
| 390 | { |
|---|
| 391 | try |
|---|
| 392 | { |
|---|
| 393 | InstructorRole = attributes.getValue("Role"); |
|---|
| 394 | } |
|---|
| 395 | catch (Exception e) |
|---|
| 396 | { |
|---|
| 397 | System.out.println("SERIOUS PARSING ERROR IN \'Role\'"); |
|---|
| 398 | InstructorRole = ""; |
|---|
| 399 | } |
|---|
| 400 | } |
|---|
| 401 | else if (qName.equals(ELEMENT.LINE.tag)) |
|---|
| 402 | { |
|---|
| 403 | try |
|---|
| 404 | { |
|---|
| 405 | LineRole = attributes.getValue("Role"); |
|---|
| 406 | } |
|---|
| 407 | catch (Exception e) |
|---|
| 408 | { |
|---|
| 409 | LineRole = ""; |
|---|
| 410 | } |
|---|
| 411 | } |
|---|
| 412 | else if (qName.equals(ELEMENT.LOCATION_INFO.tag)) |
|---|
| 413 | { |
|---|
| 414 | try |
|---|
| 415 | { |
|---|
| 416 | LocationInfoID = attributes.getValue("ID"); |
|---|
| 417 | } |
|---|
| 418 | catch (Exception e) |
|---|
| 419 | { |
|---|
| 420 | LocationInfoID = ""; |
|---|
| 421 | } |
|---|
| 422 | } |
|---|
| 423 | else if (qName.equals(ELEMENT.MAINTENANCE_RADIO.tag)) |
|---|
| 424 | { |
|---|
| 425 | eventMap.put(docPosition.peek(), ScriptEvent.factoryByType(ScriptEvent.ScriptEventType.MAINTENANCE_RADIO_EVENT)); |
|---|
| 426 | } |
|---|
| 427 | else if (qName.equals(ELEMENT.NEW_UNIT.tag)) |
|---|
| 428 | { |
|---|
| 429 | try |
|---|
| 430 | { |
|---|
| 431 | NewUnitNum = attributes.getValue("UnitNum"); |
|---|
| 432 | } |
|---|
| 433 | catch (Exception e) |
|---|
| 434 | { |
|---|
| 435 | NewUnitNum = ""; |
|---|
| 436 | } |
|---|
| 437 | } |
|---|
| 438 | else if (qName.equals(ELEMENT.PARAMICS.tag)) |
|---|
| 439 | { |
|---|
| 440 | foundSubEvents = true; |
|---|
| 441 | eventMap.put(docPosition.peek(), ScriptEvent.factoryByType(ScriptEvent.ScriptEventType.PARAMICS_EVENT)); |
|---|
| 442 | trackedEvent = eventMap.get(docPosition.peek()); |
|---|
| 443 | try |
|---|
| 444 | { |
|---|
| 445 | ParamicsID = attributes.getValue("LocationID"); |
|---|
| 446 | } |
|---|
| 447 | catch (Exception e) |
|---|
| 448 | { |
|---|
| 449 | ParamicsID = ""; |
|---|
| 450 | } |
|---|
| 451 | } |
|---|
| 452 | else if (qName.equals(ELEMENT.RADIO_EVALUATION.tag)) |
|---|
| 453 | { |
|---|
| 454 | eventMap.put(docPosition.peek(), ScriptEvent.factoryByType(ScriptEvent.ScriptEventType.RADIO_EVAL_EVENT)); |
|---|
| 455 | trackedEvent = eventMap.get(docPosition.peek()); |
|---|
| 456 | } |
|---|
| 457 | else if (qName.equals(ELEMENT.SCRIPT_EVENT.tag)) |
|---|
| 458 | { |
|---|
| 459 | cad = new CadData(); |
|---|
| 460 | } |
|---|
| 461 | |
|---|
| 462 | else if (qName.equals(ELEMENT.TMC_SCRIPT.tag)) |
|---|
| 463 | { |
|---|
| 464 | try |
|---|
| 465 | { |
|---|
| 466 | TMCTitle = attributes.getValue("title"); |
|---|
| 467 | } |
|---|
| 468 | catch (Exception e) |
|---|
| 469 | { |
|---|
| 470 | TMCTitle = ""; |
|---|
| 471 | } |
|---|
| 472 | script.title = TMCTitle; |
|---|
| 473 | |
|---|
| 474 | } |
|---|
| 475 | else if (qName.equals(ELEMENT.TMT_RADIO.tag)) |
|---|
| 476 | { |
|---|
| 477 | eventMap.put(docPosition.peek(), ScriptEvent.factoryByType(ScriptEvent.ScriptEventType.TMT_RADIO_EVENT)); |
|---|
| 478 | } |
|---|
| 479 | else if (qName.equals(ELEMENT.TOW.tag)) |
|---|
| 480 | { |
|---|
| 481 | foundSubEvents = true; |
|---|
| 482 | eventMap.put(docPosition.peek(), ScriptEvent.factoryByType(ScriptEvent.ScriptEventType.TOW_EVENT)); |
|---|
| 483 | try |
|---|
| 484 | { |
|---|
| 485 | TowBeat = attributes.getValue("Beat"); |
|---|
| 486 | TowCompany = attributes.getValue("Company"); |
|---|
| 487 | TowConfNum = attributes.getValue("ConfNum"); |
|---|
| 488 | TowPubNum = attributes.getValue("PubNum"); |
|---|
| 489 | } |
|---|
| 490 | catch (Exception e) |
|---|
| 491 | { |
|---|
| 492 | TowBeat = ""; |
|---|
| 493 | TowCompany = ""; |
|---|
| 494 | TowConfNum = ""; |
|---|
| 495 | TowPubNum = ""; |
|---|
| 496 | } |
|---|
| 497 | } |
|---|
| 498 | else if (qName.equals(ELEMENT.TELEPHONE.tag)) |
|---|
| 499 | { |
|---|
| 500 | eventMap.put(docPosition.peek(), ScriptEvent.factoryByType(ScriptEvent.ScriptEventType.TELEPHONE_EVENT)); |
|---|
| 501 | trackedEvent = eventMap.get(docPosition.peek()); |
|---|
| 502 | } |
|---|
| 503 | else if (qName.equals(ELEMENT.UNIT.tag)) |
|---|
| 504 | { |
|---|
| 505 | foundSubEvents = true; |
|---|
| 506 | eventMap.put(docPosition.peek(), ScriptEvent.factoryByType(ScriptEvent.ScriptEventType.UNIT_EVENT)); |
|---|
| 507 | try |
|---|
| 508 | { |
|---|
| 509 | UnitActive = attributes.getValue("Active"); |
|---|
| 510 | UnitPrimary = attributes.getValue("Primary"); |
|---|
| 511 | UnitStatus = attributes.getValue("Status"); |
|---|
| 512 | UnitNum = attributes.getValue("UnitNum"); |
|---|
| 513 | } |
|---|
| 514 | catch (Exception e) |
|---|
| 515 | { |
|---|
| 516 | UnitActive = ""; |
|---|
| 517 | UnitPrimary = ""; |
|---|
| 518 | UnitStatus = ""; |
|---|
| 519 | UnitNum = "0-0"; |
|---|
| 520 | } |
|---|
| 521 | } |
|---|
| 522 | else if (qName.equals(ELEMENT.WITNESS.tag)) |
|---|
| 523 | { |
|---|
| 524 | foundSubEvents = true; |
|---|
| 525 | eventMap.put(docPosition.peek(), ScriptEvent.factoryByType(ScriptEvent.ScriptEventType.WITNESS_EVENT)); |
|---|
| 526 | try |
|---|
| 527 | { |
|---|
| 528 | WitnessAddress = attributes.getValue("Address"); |
|---|
| 529 | WitnessName = attributes.getValue("Name"); |
|---|
| 530 | WitnessNum = attributes.getValue("PhoneNum"); |
|---|
| 531 | } |
|---|
| 532 | catch (Exception e) |
|---|
| 533 | { |
|---|
| 534 | WitnessAddress = ""; |
|---|
| 535 | WitnessName = ""; |
|---|
| 536 | WitnessNum = ""; |
|---|
| 537 | } |
|---|
| 538 | } |
|---|
| 539 | else if (qName.equals(ELEMENT.INCIDENT.tag)) |
|---|
| 540 | { |
|---|
| 541 | try |
|---|
| 542 | { |
|---|
| 543 | incidentLogNumber = Integer.parseInt(attributes.getValue( |
|---|
| 544 | "LogNum")); |
|---|
| 545 | } |
|---|
| 546 | catch (Exception e) |
|---|
| 547 | { |
|---|
| 548 | myScriptLogger.logp(Level.SEVERE, "ScriptHandler", "startElement", |
|---|
| 549 | "Invalid LogNumber " + attributes.getValue( |
|---|
| 550 | "LogNum"), e); |
|---|
| 551 | incidentLogNumber = 0; |
|---|
| 552 | } |
|---|
| 553 | } |
|---|
| 554 | else if (qName.equals(ELEMENT.UNIT.tag)) |
|---|
| 555 | { |
|---|
| 556 | try |
|---|
| 557 | { |
|---|
| 558 | UnitNum = attributes.getValue("UnitNum"); |
|---|
| 559 | } |
|---|
| 560 | catch (Exception e) |
|---|
| 561 | { |
|---|
| 562 | myScriptLogger.logp(Level.SEVERE, "ScriptHandler", "startElement", |
|---|
| 563 | "Invalid Unit Number " + attributes.getValue( |
|---|
| 564 | "UnitNum"), e); |
|---|
| 565 | UnitNum = "0-0"; |
|---|
| 566 | } |
|---|
| 567 | } |
|---|
| 568 | } |
|---|
| 569 | catch (Exception e) |
|---|
| 570 | { |
|---|
| 571 | myScriptLogger.logp(Level.SEVERE, "ScriptHandler", "startElement", |
|---|
| 572 | "Exception in starting element <" + qName + ">.", e); |
|---|
| 573 | } |
|---|
| 574 | } |
|---|
| 575 | |
|---|
| 576 | /** |
|---|
| 577 | * SAX Handler method. Append read characters to local buffer. |
|---|
| 578 | */ |
|---|
| 579 | @Override |
|---|
| 580 | public void characters(char[] ch, int start, int length) |
|---|
| 581 | { |
|---|
| 582 | String str = new String(ch, start, length).trim(); |
|---|
| 583 | str = str.replace("\t ", ""); |
|---|
| 584 | str = str.replace("\t", ""); |
|---|
| 585 | str = str.replace("\n ", "\n"); |
|---|
| 586 | |
|---|
| 587 | parsedValue.append(str); |
|---|
| 588 | if (pcData.get(docPosition.peek()) == null || pcData.get(docPosition.peek()).equals("")) |
|---|
| 589 | { |
|---|
| 590 | pcData.put(docPosition.peek(), str); |
|---|
| 591 | } |
|---|
| 592 | else |
|---|
| 593 | { |
|---|
| 594 | pcData.put(docPosition.peek(), "" + (pcData.get(docPosition.peek()) |
|---|
| 595 | + "\n" + str)); |
|---|
| 596 | } |
|---|
| 597 | } |
|---|
| 598 | |
|---|
| 599 | /** |
|---|
| 600 | * SAX Handler method. Executes at the close of each XML element. |
|---|
| 601 | */ |
|---|
| 602 | @Override |
|---|
| 603 | public void endElement(String uri, String localName, String qName) |
|---|
| 604 | { |
|---|
| 605 | currentElement = docPosition.pop(); |
|---|
| 606 | I_ScriptEvent newEvent = null; |
|---|
| 607 | try |
|---|
| 608 | { |
|---|
| 609 | if (currentElement == ELEMENT.ATMS_EVALUATION) |
|---|
| 610 | { |
|---|
| 611 | newEvent = eventMap.remove(currentElement); |
|---|
| 612 | |
|---|
| 613 | currInc.addNewEvent(newEvent, (int) currentEventTime); |
|---|
| 614 | } |
|---|
| 615 | else if (currentElement == ELEMENT.ACTIVITY_LOG_EVALUATION) |
|---|
| 616 | { |
|---|
| 617 | newEvent = eventMap.remove(currentElement); |
|---|
| 618 | |
|---|
| 619 | currInc.addNewEvent(newEvent, (int) currentEventTime); |
|---|
| 620 | } |
|---|
| 621 | else if (currentElement == ELEMENT.AGY && docPosition.peek() == ELEMENT.GENERAL) |
|---|
| 622 | { |
|---|
| 623 | cad.Agy = pcData.remove(currentElement); |
|---|
| 624 | } |
|---|
| 625 | else if (currentElement == ELEMENT.ADDRESS && docPosition.peek() == ELEMENT.LOCATION) |
|---|
| 626 | { |
|---|
| 627 | cad.Location_Address = pcData.remove(currentElement); |
|---|
| 628 | } |
|---|
| 629 | else if (currentElement == ELEMENT.AREA && docPosition.peek() == ELEMENT.LOCATION) |
|---|
| 630 | { |
|---|
| 631 | cad.Location_Area = pcData.remove(currentElement); |
|---|
| 632 | } |
|---|
| 633 | else if (currentElement == ELEMENT.BEAT && docPosition.peek() == ELEMENT.LOCATION) |
|---|
| 634 | { |
|---|
| 635 | cad.Location_Beat = pcData.remove(currentElement); |
|---|
| 636 | } |
|---|
| 637 | else if (currentElement == ELEMENT.CITY && docPosition.peek() == ELEMENT.LOCATION) |
|---|
| 638 | { |
|---|
| 639 | cad.Location_City = pcData.remove(currentElement); |
|---|
| 640 | } |
|---|
| 641 | else if (currentElement == ELEMENT.EMS && docPosition.peek() == ELEMENT.LOCATION) |
|---|
| 642 | { |
|---|
| 643 | cad.Location_Ems = pcData.remove(currentElement); |
|---|
| 644 | } |
|---|
| 645 | else if (currentElement == ELEMENT.FIRE && docPosition.peek() == ELEMENT.LOCATION) |
|---|
| 646 | { |
|---|
| 647 | cad.Location_Fire = pcData.remove(currentElement); |
|---|
| 648 | } |
|---|
| 649 | else if (currentElement == ELEMENT.LAW && docPosition.peek() == ELEMENT.LOCATION) |
|---|
| 650 | { |
|---|
| 651 | cad.Location_Law = pcData.remove(currentElement); |
|---|
| 652 | } |
|---|
| 653 | else if (currentElement == ELEMENT.LOC && docPosition.peek() == ELEMENT.LOCATION) |
|---|
| 654 | { |
|---|
| 655 | cad.Location_Loc = pcData.remove(currentElement); |
|---|
| 656 | } |
|---|
| 657 | else if (currentElement == ELEMENT.Type && docPosition.peek() == ELEMENT.HEADER_INFO) |
|---|
| 658 | { |
|---|
| 659 | cad.Header_Type = pcData.remove(currentElement); |
|---|
| 660 | } |
|---|
| 661 | else if (currentElement == ELEMENT.Beat && docPosition.peek() == ELEMENT.HEADER_INFO) |
|---|
| 662 | { |
|---|
| 663 | cad.Header_Beat = pcData.remove(currentElement); |
|---|
| 664 | } |
|---|
| 665 | else if (currentElement == ELEMENT.TruncLoc && docPosition.peek() == ELEMENT.HEADER_INFO) |
|---|
| 666 | { |
|---|
| 667 | cad.Header_TruncLoc = pcData.remove(currentElement); |
|---|
| 668 | } |
|---|
| 669 | else if (currentElement == ELEMENT.FullLoc && docPosition.peek() == ELEMENT.HEADER_INFO) |
|---|
| 670 | { |
|---|
| 671 | cad.Header_FullLoc = pcData.remove(currentElement); |
|---|
| 672 | } |
|---|
| 673 | |
|---|
| 674 | else if (currentElement == ELEMENT.AUDIO) |
|---|
| 675 | { |
|---|
| 676 | newEvent = eventMap.remove(currentElement); |
|---|
| 677 | ((AudioEvent) newEvent).audioLength = audioLength; |
|---|
| 678 | ((AudioEvent) newEvent).audioPath = audioPath; |
|---|
| 679 | ((AudioEvent) newEvent).length = audioLength; |
|---|
| 680 | currInc.addNewEvent(newEvent, (int) currentEventTime); |
|---|
| 681 | } |
|---|
| 682 | else if (currentElement == ELEMENT.CAD_EVALUATION) |
|---|
| 683 | { |
|---|
| 684 | newEvent = eventMap.remove(currentElement); |
|---|
| 685 | |
|---|
| 686 | currInc.addNewEvent(newEvent, (int) currentEventTime); |
|---|
| 687 | } |
|---|
| 688 | else if (currentElement == ELEMENT.CAD_INCIDENT_EVENT) |
|---|
| 689 | { |
|---|
| 690 | newEvent = eventMap.remove(currentElement); |
|---|
| 691 | ((CADEvent) newEvent).detail = pcData.remove(ELEMENT.DETAIL); |
|---|
| 692 | ((CADEvent) newEvent).hasSubEvents = foundSubEvents; |
|---|
| 693 | if (null != ((CADEvent) newEvent).detail) |
|---|
| 694 | { |
|---|
| 695 | if (!(((CADEvent) newEvent).detail.equals(""))) |
|---|
| 696 | { |
|---|
| 697 | currInc.addNewEvent(newEvent, (int) currentEventTime); |
|---|
| 698 | } |
|---|
| 699 | } |
|---|
| 700 | foundSubEvents = false; |
|---|
| 701 | } |
|---|
| 702 | else if (currentElement == ELEMENT.CCTV_INFO) |
|---|
| 703 | { |
|---|
| 704 | newEvent = eventMap.remove(currentElement); |
|---|
| 705 | ((CCTVEvent) newEvent).message = pcData.remove(ELEMENT.CCTV_INFO); |
|---|
| 706 | currInc.addNewEvent(newEvent, (int) currentEventTime); |
|---|
| 707 | } |
|---|
| 708 | else if (currentElement == ELEMENT.CHP_RADIO) |
|---|
| 709 | { |
|---|
| 710 | newEvent = eventMap.remove(currentElement); |
|---|
| 711 | ((CHPRadioEvent) newEvent).radioFile = CHPRadiofile; |
|---|
| 712 | currInc.addNewEvent(newEvent, (int) currentEventTime); |
|---|
| 713 | } |
|---|
| 714 | |
|---|
| 715 | else if (currentElement == ELEMENT.CMS_EVALUATION) |
|---|
| 716 | { |
|---|
| 717 | newEvent = eventMap.remove(currentElement); |
|---|
| 718 | ((CMSEvaluationEvent) newEvent).cmsID = CMSID; |
|---|
| 719 | ((CMSEvaluationEvent) newEvent).cmsType = CMSType; |
|---|
| 720 | if (pcData.get(ELEMENT.LOCATION) != null) |
|---|
| 721 | { |
|---|
| 722 | ((CMSEvaluationEvent) newEvent).location = pcData.remove(ELEMENT.LOCATION); |
|---|
| 723 | } |
|---|
| 724 | |
|---|
| 725 | currInc.addNewEvent(newEvent, (int) currentEventTime); |
|---|
| 726 | } |
|---|
| 727 | else if (currentElement == ELEMENT.CMS_LINE) |
|---|
| 728 | { |
|---|
| 729 | if (trackedEvent instanceof CMSEvaluationEvent) |
|---|
| 730 | { |
|---|
| 731 | ((CMSEvaluationEvent) trackedEvent).message.add(pcData.remove(ELEMENT.CMS_LINE)); |
|---|
| 732 | } |
|---|
| 733 | } |
|---|
| 734 | else if (currentElement == ELEMENT.EXPECTED_ACTION) |
|---|
| 735 | { |
|---|
| 736 | if (trackedEvent instanceof I_EvaluationEvent) |
|---|
| 737 | { |
|---|
| 738 | ((I_EvaluationEvent) trackedEvent).addAction(pcData.remove(ELEMENT.EXPECTED_ACTION)); |
|---|
| 739 | } |
|---|
| 740 | } |
|---|
| 741 | else if (currentElement == ELEMENT.FACILITATOR_EVALUATION) |
|---|
| 742 | { |
|---|
| 743 | newEvent = eventMap.remove(currentElement); |
|---|
| 744 | |
|---|
| 745 | currInc.addNewEvent(newEvent, (int) currentEventTime); |
|---|
| 746 | } |
|---|
| 747 | else if (currentElement == ELEMENT.INSTRUCTOR) |
|---|
| 748 | { |
|---|
| 749 | if (trackedEvent instanceof TelephoneEvent) |
|---|
| 750 | { |
|---|
| 751 | ((TelephoneEvent) trackedEvent).lines.add(pcData.remove(ELEMENT.INSTRUCTOR)); |
|---|
| 752 | ((TelephoneEvent) trackedEvent).roles.add(InstructorRole); |
|---|
| 753 | } |
|---|
| 754 | } |
|---|
| 755 | else if (currentElement == ELEMENT.Lane_number) |
|---|
| 756 | { |
|---|
| 757 | if (trackedEvent instanceof ParamicsEvent) |
|---|
| 758 | { |
|---|
| 759 | ((ParamicsEvent) trackedEvent).laneNums.add(Integer.parseInt(pcData.remove(ELEMENT.Lane_number))); |
|---|
| 760 | } |
|---|
| 761 | } |
|---|
| 762 | else if (currentElement == ELEMENT.LINE) |
|---|
| 763 | { |
|---|
| 764 | if (trackedEvent instanceof CHPRadioEvent) |
|---|
| 765 | { |
|---|
| 766 | ((CHPRadioEvent) trackedEvent).lines.add(pcData.remove(ELEMENT.LINE)); |
|---|
| 767 | ((CHPRadioEvent) trackedEvent).roles.add(LineRole); |
|---|
| 768 | } |
|---|
| 769 | } |
|---|
| 770 | else if (currentElement == ELEMENT.LOCATION_INFO) |
|---|
| 771 | { |
|---|
| 772 | Location_Info locInfo = new Location_Info(); |
|---|
| 773 | |
|---|
| 774 | locInfo.Location_ID = LocationInfoID; |
|---|
| 775 | locInfo.Direction = pcData.remove(ELEMENT.Direction); |
|---|
| 776 | locInfo.Location_type = pcData.remove(ELEMENT.Location_type); |
|---|
| 777 | locInfo.Route = pcData.remove(ELEMENT.Route); |
|---|
| 778 | locInfo.Postmile = pcData.remove(ELEMENT.Postmile); |
|---|
| 779 | cad.locInfo.add(locInfo); |
|---|
| 780 | } |
|---|
| 781 | else if (currentElement == ELEMENT.MAINTENANCE_RADIO) |
|---|
| 782 | { |
|---|
| 783 | newEvent = eventMap.remove(currentElement); |
|---|
| 784 | ((MaintenanceRadioEvent) newEvent).message = pcData.remove(ELEMENT.MAINTENANCE_RADIO); |
|---|
| 785 | currInc.addNewEvent(newEvent, (int) currentEventTime); |
|---|
| 786 | } |
|---|
| 787 | else if (currentElement == ELEMENT.MASTER_INC_NUM) |
|---|
| 788 | { |
|---|
| 789 | cad.Master_Inc_Num = pcData.remove(currentElement); |
|---|
| 790 | } |
|---|
| 791 | else if (currentElement == ELEMENT.P) |
|---|
| 792 | { |
|---|
| 793 | cad.P = pcData.remove(currentElement); |
|---|
| 794 | } |
|---|
| 795 | else if (currentElement == ELEMENT.PARAMICS) |
|---|
| 796 | { |
|---|
| 797 | newEvent = eventMap.remove(currentElement); |
|---|
| 798 | ((ParamicsEvent) newEvent).locationID = ParamicsID; |
|---|
| 799 | |
|---|
| 800 | if (pcData.get(ELEMENT.Status) != null) |
|---|
| 801 | { |
|---|
| 802 | ((ParamicsEvent) newEvent).status = pcData.remove(ELEMENT.Status); |
|---|
| 803 | } |
|---|
| 804 | if (pcData.get(ELEMENT.Incident_type) != null) |
|---|
| 805 | { |
|---|
| 806 | ((ParamicsEvent) newEvent).type = pcData.remove(ELEMENT.Incident_type); |
|---|
| 807 | } |
|---|
| 808 | currInc.addNewEvent(newEvent, (int) currentEventTime); |
|---|
| 809 | } |
|---|
| 810 | else if (currentElement == ELEMENT.RADIO_EVALUATION) |
|---|
| 811 | { |
|---|
| 812 | newEvent = eventMap.remove(currentElement); |
|---|
| 813 | |
|---|
| 814 | currInc.addNewEvent(newEvent, (int) currentEventTime); |
|---|
| 815 | } |
|---|
| 816 | else if (currentElement == ELEMENT.SCRIPT_EVENT) |
|---|
| 817 | { |
|---|
| 818 | currInc.insertCadData(currentEventTime, cad); |
|---|
| 819 | } |
|---|
| 820 | else if (currentElement == ELEMENT.STUDENT) |
|---|
| 821 | { |
|---|
| 822 | if (trackedEvent instanceof TelephoneEvent) |
|---|
| 823 | { |
|---|
| 824 | ((TelephoneEvent) trackedEvent).lines.add(pcData.remove(ELEMENT.STUDENT)); |
|---|
| 825 | ((TelephoneEvent) trackedEvent).roles.add("Student"); |
|---|
| 826 | } |
|---|
| 827 | } |
|---|
| 828 | else if (currentElement == ELEMENT.TEXT && docPosition.peek() == ELEMENT.GENERAL_INFO) |
|---|
| 829 | { |
|---|
| 830 | currInc.description = pcData.remove(ELEMENT.TEXT); |
|---|
| 831 | cad.General_Text = currInc.description; |
|---|
| 832 | } |
|---|
| 833 | else if (currentElement == ELEMENT.TITLE && docPosition.peek() == ELEMENT.GENERAL_INFO) |
|---|
| 834 | { |
|---|
| 835 | cad.General_Title = pcData.remove(ELEMENT.TITLE); |
|---|
| 836 | } |
|---|
| 837 | else if (currentElement == ELEMENT.TMT_RADIO) |
|---|
| 838 | { |
|---|
| 839 | newEvent = eventMap.remove(currentElement); |
|---|
| 840 | ((TMTRadioEvent) newEvent).message = pcData.remove(ELEMENT.TMT_RADIO); |
|---|
| 841 | currInc.addNewEvent(newEvent, (int) currentEventTime); |
|---|
| 842 | } |
|---|
| 843 | else if (currentElement == ELEMENT.TELEPHONE) |
|---|
| 844 | { |
|---|
| 845 | newEvent = eventMap.remove(currentElement); |
|---|
| 846 | currInc.addNewEvent(newEvent, (int) currentEventTime); |
|---|
| 847 | } |
|---|
| 848 | else if (currentElement == ELEMENT.TOW) |
|---|
| 849 | { |
|---|
| 850 | newEvent = eventMap.remove(currentElement); |
|---|
| 851 | ((TowEvent) newEvent).towBeat = TowBeat; |
|---|
| 852 | ((TowEvent) newEvent).towCompany = TowCompany; |
|---|
| 853 | ((TowEvent) newEvent).towConfNum = TowConfNum; |
|---|
| 854 | ((TowEvent) newEvent).towPubNum = TowPubNum; |
|---|
| 855 | currInc.addNewEvent(newEvent, (int) currentEventTime); |
|---|
| 856 | } |
|---|
| 857 | else if (currentElement == ELEMENT.TYPE && docPosition.peek() == ELEMENT.ADDITIONAL_INFO) |
|---|
| 858 | { |
|---|
| 859 | cad.Info_Type = pcData.remove(currentElement); |
|---|
| 860 | } |
|---|
| 861 | else if (currentElement == ELEMENT.TYPE_CODE && docPosition.peek() == ELEMENT.ADDITIONAL_INFO) |
|---|
| 862 | { |
|---|
| 863 | cad.Info_Type_Code = pcData.remove(currentElement); |
|---|
| 864 | } |
|---|
| 865 | else if (currentElement == ELEMENT.UNIT) |
|---|
| 866 | { |
|---|
| 867 | newEvent = eventMap.remove(currentElement); |
|---|
| 868 | ((UnitEvent) newEvent).unitActive = UnitActive; |
|---|
| 869 | ((UnitEvent) newEvent).unitPrimary = UnitPrimary; |
|---|
| 870 | ((UnitEvent) newEvent).unitStatus = UnitStatus; |
|---|
| 871 | ((UnitEvent) newEvent).unitNum = UnitNum; |
|---|
| 872 | currInc.addNewEvent(newEvent, (int) currentEventTime); |
|---|
| 873 | } |
|---|
| 874 | else if (currentElement == ELEMENT.WITNESS) |
|---|
| 875 | { |
|---|
| 876 | newEvent = eventMap.remove(currentElement); |
|---|
| 877 | ((WitnessEvent) newEvent).witnessAddress = WitnessAddress; |
|---|
| 878 | ((WitnessEvent) newEvent).witnessName = WitnessName; |
|---|
| 879 | ((WitnessEvent) newEvent).witnessNum = WitnessNum; |
|---|
| 880 | currInc.addNewEvent(newEvent, (int) currentEventTime); |
|---|
| 881 | } |
|---|
| 882 | |
|---|
| 883 | else if (currentElement == ELEMENT.INCIDENT) |
|---|
| 884 | { |
|---|
| 885 | currentIncName = parsedValue.toString(); |
|---|
| 886 | |
|---|
| 887 | if (incidentMap.get(incidentLogNumber) == null) |
|---|
| 888 | { |
|---|
| 889 | incidentMap.put(incidentLogNumber, |
|---|
| 890 | new ScriptIncident(SimulationScript.incidentColors[Math.abs(new Random().nextInt()) % SimulationScript.incidentColors.length], |
|---|
| 891 | incidentLogNumber, currentIncName, currentIncidentDesc, |
|---|
| 892 | script, (int) currentEventTime)); |
|---|
| 893 | } |
|---|
| 894 | currInc = incidentMap.get(incidentLogNumber); |
|---|
| 895 | |
|---|
| 896 | } |
|---|
| 897 | else if (currentElement == ELEMENT.NEW_UNIT) |
|---|
| 898 | { |
|---|
| 899 | Unit unit = new Unit(); |
|---|
| 900 | unit.UnitNum = NewUnitNum; |
|---|
| 901 | if (pcData.containsKey(ELEMENT.AGY)) |
|---|
| 902 | { |
|---|
| 903 | unit.Agy = pcData.remove(ELEMENT.AGY); |
|---|
| 904 | } |
|---|
| 905 | if (pcData.containsKey(ELEMENT.ALIAS)) |
|---|
| 906 | { |
|---|
| 907 | unit.Alias = pcData.remove(ELEMENT.ALIAS); |
|---|
| 908 | } |
|---|
| 909 | if (pcData.containsKey(ELEMENT.AREA)) |
|---|
| 910 | { |
|---|
| 911 | unit.Area = pcData.remove(ELEMENT.AREA); |
|---|
| 912 | } |
|---|
| 913 | if (pcData.containsKey(ELEMENT.BADGE_NUM)) |
|---|
| 914 | { |
|---|
| 915 | unit.Badge_Num = pcData.remove(ELEMENT.BADGE_NUM); |
|---|
| 916 | } |
|---|
| 917 | if (pcData.containsKey(ELEMENT.CURR_LOC)) |
|---|
| 918 | { |
|---|
| 919 | unit.Curr_Loc = pcData.remove(ELEMENT.CURR_LOC); |
|---|
| 920 | } |
|---|
| 921 | if (pcData.containsKey(ELEMENT.DESTINATION)) |
|---|
| 922 | { |
|---|
| 923 | unit.Destination = pcData.remove(ELEMENT.DESTINATION); |
|---|
| 924 | } |
|---|
| 925 | if (pcData.containsKey(ELEMENT.ID)) |
|---|
| 926 | { |
|---|
| 927 | unit.ID = pcData.remove(ELEMENT.ID); |
|---|
| 928 | } |
|---|
| 929 | if (pcData.containsKey(ELEMENT.MASTER_INC_NUM)) |
|---|
| 930 | { |
|---|
| 931 | unit.Master_Inc_Num = pcData.remove(ELEMENT.MASTER_INC_NUM); |
|---|
| 932 | } |
|---|
| 933 | if (pcData.containsKey(ELEMENT.MISC_INFO)) |
|---|
| 934 | { |
|---|
| 935 | unit.Misc_Info = pcData.remove(ELEMENT.MISC_INFO); |
|---|
| 936 | } |
|---|
| 937 | if (pcData.containsKey(ELEMENT.OOS)) |
|---|
| 938 | { |
|---|
| 939 | unit.OOS = pcData.remove(ELEMENT.OOS); |
|---|
| 940 | } |
|---|
| 941 | if (pcData.containsKey(ELEMENT.OFFICE)) |
|---|
| 942 | { |
|---|
| 943 | unit.Office = pcData.remove(ELEMENT.OFFICE); |
|---|
| 944 | } |
|---|
| 945 | if (pcData.containsKey(ELEMENT.OFFICER)) |
|---|
| 946 | { |
|---|
| 947 | unit.Officer = pcData.remove(ELEMENT.OFFICER); |
|---|
| 948 | } |
|---|
| 949 | if (pcData.containsKey(ELEMENT.P)) |
|---|
| 950 | { |
|---|
| 951 | unit.P = pcData.remove(ELEMENT.P); |
|---|
| 952 | } |
|---|
| 953 | if (pcData.containsKey(ELEMENT.PRIMARY)) |
|---|
| 954 | { |
|---|
| 955 | unit.Primary = pcData.remove(ELEMENT.PRIMARY); |
|---|
| 956 | } |
|---|
| 957 | if (pcData.containsKey(ELEMENT.STACK)) |
|---|
| 958 | { |
|---|
| 959 | unit.Stack = pcData.remove(ELEMENT.STACK); |
|---|
| 960 | } |
|---|
| 961 | if (pcData.containsKey(ELEMENT.STATUS)) |
|---|
| 962 | { |
|---|
| 963 | unit.Status = pcData.remove(ELEMENT.STATUS); |
|---|
| 964 | } |
|---|
| 965 | if (pcData.containsKey(ELEMENT.TIMER)) |
|---|
| 966 | { |
|---|
| 967 | unit.Timer = pcData.remove(ELEMENT.TIMER); |
|---|
| 968 | } |
|---|
| 969 | units.add(unit); |
|---|
| 970 | } |
|---|
| 971 | |
|---|
| 972 | else if (qName.equals(ELEMENT.TIME_INDEX.tag)) |
|---|
| 973 | { |
|---|
| 974 | currentEventTime = timeBytesToSeconds(parsedValue.toString().trim()); |
|---|
| 975 | } |
|---|
| 976 | |
|---|
| 977 | parsedValue.setLength(0); |
|---|
| 978 | eventMap.put(currentElement, null); |
|---|
| 979 | } |
|---|
| 980 | catch (Exception e) |
|---|
| 981 | { |
|---|
| 982 | myScriptLogger.logp(Level.SEVERE, "ScriptHandler", "endElement", |
|---|
| 983 | "Exception in ending element <" + qName + ">.", e); |
|---|
| 984 | } |
|---|
| 985 | /* |
|---|
| 986 | String t = ""; |
|---|
| 987 | sublevels--; |
|---|
| 988 | for (int i = 0; i < sublevels; i++) |
|---|
| 989 | { |
|---|
| 990 | t += "\t"; |
|---|
| 991 | } |
|---|
| 992 | System.out.println(t + "End of element " + qName);*/ |
|---|
| 993 | |
|---|
| 994 | } |
|---|
| 995 | |
|---|
| 996 | /** |
|---|
| 997 | * SAX Handler method. End the document and close it out. |
|---|
| 998 | */ |
|---|
| 999 | @Override |
|---|
| 1000 | public void endDocument() |
|---|
| 1001 | { |
|---|
| 1002 | //System.out.println("STUB: End the document"); |
|---|
| 1003 | } |
|---|
| 1004 | |
|---|
| 1005 | /** |
|---|
| 1006 | * Sax Handler method. Log normal errors. |
|---|
| 1007 | */ |
|---|
| 1008 | @Override |
|---|
| 1009 | public void error(SAXParseException e) |
|---|
| 1010 | { |
|---|
| 1011 | myScriptLogger.logp(Level.SEVERE, "ScriptHandler", "error", |
|---|
| 1012 | "SAX Parsing error.", e); |
|---|
| 1013 | } |
|---|
| 1014 | |
|---|
| 1015 | /** |
|---|
| 1016 | * SAX Handler method. Log fatal errors. |
|---|
| 1017 | */ |
|---|
| 1018 | @Override |
|---|
| 1019 | public void fatalError(SAXParseException e) |
|---|
| 1020 | { |
|---|
| 1021 | myScriptLogger.logp(Level.SEVERE, "ScriptHandler", "fatalError", |
|---|
| 1022 | "SAX Parsing fatal error.", e); |
|---|
| 1023 | } |
|---|
| 1024 | |
|---|
| 1025 | /** |
|---|
| 1026 | * SAX Handler method. Log warnings. |
|---|
| 1027 | */ |
|---|
| 1028 | @Override |
|---|
| 1029 | public void warning(SAXParseException e) |
|---|
| 1030 | { |
|---|
| 1031 | myScriptLogger.logp(Level.SEVERE, "ScriptHandler", "warning", |
|---|
| 1032 | "SAX Parsing warning.", e); |
|---|
| 1033 | } |
|---|
| 1034 | |
|---|
| 1035 | /** |
|---|
| 1036 | * Private method to convert a time object from format HH:MM:SS to a long |
|---|
| 1037 | * value of the corresponding number of seconds. |
|---|
| 1038 | * |
|---|
| 1039 | * @param time String time representation of format HH:MM:SS |
|---|
| 1040 | * @return long Number of seconds |
|---|
| 1041 | * @throws StringIndexOutOfBoundsException if the input parameter is not |
|---|
| 1042 | * valid |
|---|
| 1043 | */ |
|---|
| 1044 | private long timeBytesToSeconds(String time) |
|---|
| 1045 | throws StringIndexOutOfBoundsException |
|---|
| 1046 | { |
|---|
| 1047 | long seconds = 0; |
|---|
| 1048 | |
|---|
| 1049 | seconds = ((long) Character.digit(time.charAt(0), 10) * 36000 |
|---|
| 1050 | + Character.digit(time.charAt(1), 10) * 3600 |
|---|
| 1051 | + Character.digit(time.charAt(3), 10) * 600 |
|---|
| 1052 | + Character.digit(time.charAt(4), 10) * 60 |
|---|
| 1053 | + Character.digit(time.charAt(6), 10) * 10 |
|---|
| 1054 | + Character.digit(time.charAt(7), 10)); |
|---|
| 1055 | |
|---|
| 1056 | return seconds; |
|---|
| 1057 | } |
|---|
| 1058 | } |
|---|