| 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 | public MyScriptHandler(SimulationScript s) |
|---|
| 245 | { |
|---|
| 246 | script = s; |
|---|
| 247 | incidentMap = new TreeMap<Integer, ScriptIncident>(); |
|---|
| 248 | eventMap = new TreeMap<ELEMENT, I_ScriptEvent>(); |
|---|
| 249 | units = new ArrayList<Unit>(); |
|---|
| 250 | pcData = new TreeMap<ELEMENT, String>(); |
|---|
| 251 | docPosition = new Stack<ELEMENT>(); |
|---|
| 252 | } |
|---|
| 253 | |
|---|
| 254 | /** |
|---|
| 255 | * Get the list of incidents that have been parsed from the script file. |
|---|
| 256 | * |
|---|
| 257 | * @returns Vector of Incident objects. |
|---|
| 258 | */ |
|---|
| 259 | public Vector<ScriptIncident> getIncidents() |
|---|
| 260 | { |
|---|
| 261 | return new Vector<ScriptIncident>(incidentMap.values()); |
|---|
| 262 | } |
|---|
| 263 | |
|---|
| 264 | /** |
|---|
| 265 | * Get the list of units that have been parsed from the script file. |
|---|
| 266 | * |
|---|
| 267 | * @returns Vector of Unit objects. |
|---|
| 268 | */ |
|---|
| 269 | public ArrayList<Unit> getUnits() |
|---|
| 270 | { |
|---|
| 271 | return units; |
|---|
| 272 | } |
|---|
| 273 | |
|---|
| 274 | /** |
|---|
| 275 | * SAX Handler method. Clear incident map and reset the error flag. |
|---|
| 276 | */ |
|---|
| 277 | @Override |
|---|
| 278 | public void startDocument() |
|---|
| 279 | { |
|---|
| 280 | //System.out.println("STUB: Start the document"); |
|---|
| 281 | |
|---|
| 282 | } |
|---|
| 283 | |
|---|
| 284 | /** |
|---|
| 285 | * Clear all existing events, thereby resetting the script. |
|---|
| 286 | */ |
|---|
| 287 | public void reset() |
|---|
| 288 | { |
|---|
| 289 | incidentMap.clear(); |
|---|
| 290 | System.out.println("STUB: Restart the document"); |
|---|
| 291 | } |
|---|
| 292 | |
|---|
| 293 | /** |
|---|
| 294 | * SAX Handler method. Executes at the beginning of each XML element. |
|---|
| 295 | */ |
|---|
| 296 | @Override |
|---|
| 297 | public void startElement(String uri, String localName, String qName, Attributes attributes) |
|---|
| 298 | { |
|---|
| 299 | |
|---|
| 300 | docPosition.push(ELEMENT.byName(qName)); |
|---|
| 301 | |
|---|
| 302 | try |
|---|
| 303 | { |
|---|
| 304 | if (qName.equals(ELEMENT.ACTIVITY_LOG_EVALUATION.tag)) |
|---|
| 305 | { |
|---|
| 306 | eventMap.put(docPosition.peek(), ScriptEvent.factoryByType(ScriptEvent.ScriptEventType.ACTIVITY_LOG_EVAL_EVENT)); |
|---|
| 307 | trackedEvent = eventMap.get(docPosition.peek()); |
|---|
| 308 | } |
|---|
| 309 | else if (qName.equals(ELEMENT.ATMS_EVALUATION.tag)) |
|---|
| 310 | { |
|---|
| 311 | eventMap.put(docPosition.peek(), ScriptEvent.factoryByType(ScriptEvent.ScriptEventType.ATMS_EVAL_EVENT)); |
|---|
| 312 | trackedEvent = eventMap.get(docPosition.peek()); |
|---|
| 313 | } |
|---|
| 314 | else if (qName.equals(ELEMENT.AUDIO.tag)) |
|---|
| 315 | { |
|---|
| 316 | foundSubEvents = true; |
|---|
| 317 | eventMap.put(docPosition.peek(), ScriptEvent.factoryByType(ScriptEvent.ScriptEventType.AUDIO_EVENT)); |
|---|
| 318 | try |
|---|
| 319 | { |
|---|
| 320 | audioLength = Integer.parseInt(attributes.getValue("Length")); |
|---|
| 321 | audioPath = attributes.getValue("Path"); |
|---|
| 322 | } |
|---|
| 323 | catch (Exception e) |
|---|
| 324 | { |
|---|
| 325 | audioLength = 0; |
|---|
| 326 | audioPath = ""; |
|---|
| 327 | } |
|---|
| 328 | } |
|---|
| 329 | else if (qName.equals(ELEMENT.CARDFILE.tag)) |
|---|
| 330 | { |
|---|
| 331 | try |
|---|
| 332 | { |
|---|
| 333 | cardfileCategory = attributes.getValue("Category"); |
|---|
| 334 | } |
|---|
| 335 | catch (Exception e) |
|---|
| 336 | { |
|---|
| 337 | cardfileCategory = ""; |
|---|
| 338 | } |
|---|
| 339 | } |
|---|
| 340 | else if (qName.equals(ELEMENT.CAD_EVALUATION.tag)) |
|---|
| 341 | { |
|---|
| 342 | eventMap.put(docPosition.peek(), ScriptEvent.factoryByType(ScriptEvent.ScriptEventType.CAD_EVAL_EVENT)); |
|---|
| 343 | trackedEvent = eventMap.get(docPosition.peek()); |
|---|
| 344 | } |
|---|
| 345 | else if (qName.equals(ELEMENT.CAD_INCIDENT_EVENT.tag)) |
|---|
| 346 | { |
|---|
| 347 | eventMap.put(docPosition.peek(), ScriptEvent.factoryByType(ScriptEvent.ScriptEventType.CAD_EVENT)); |
|---|
| 348 | } |
|---|
| 349 | else if (qName.equals(ELEMENT.CCTV_INFO.tag)) |
|---|
| 350 | { |
|---|
| 351 | foundSubEvents = true; |
|---|
| 352 | eventMap.put(docPosition.peek(), ScriptEvent.factoryByType(ScriptEvent.ScriptEventType.CCTV_EVENT)); |
|---|
| 353 | } |
|---|
| 354 | else if (qName.equals(ELEMENT.CHP_RADIO.tag)) |
|---|
| 355 | { |
|---|
| 356 | eventMap.put(docPosition.peek(), ScriptEvent.factoryByType(ScriptEvent.ScriptEventType.CHP_RADIO_EVENT)); |
|---|
| 357 | trackedEvent = eventMap.get(docPosition.peek()); |
|---|
| 358 | try |
|---|
| 359 | { |
|---|
| 360 | CHPRadiofile = attributes.getValue("RadioFile"); |
|---|
| 361 | } |
|---|
| 362 | catch (Exception e) |
|---|
| 363 | { |
|---|
| 364 | CHPRadiofile = ""; |
|---|
| 365 | } |
|---|
| 366 | } |
|---|
| 367 | else if (qName.equals(ELEMENT.CMS_EVALUATION.tag)) |
|---|
| 368 | { |
|---|
| 369 | eventMap.put(docPosition.peek(), ScriptEvent.factoryByType(ScriptEvent.ScriptEventType.CMS_EVAL_EVENT)); |
|---|
| 370 | trackedEvent = eventMap.get(docPosition.peek()); |
|---|
| 371 | try |
|---|
| 372 | { |
|---|
| 373 | CMSID = attributes.getValue("cmsID"); |
|---|
| 374 | CMSType = attributes.getValue("type"); |
|---|
| 375 | } |
|---|
| 376 | catch (Exception e) |
|---|
| 377 | { |
|---|
| 378 | CMSID = ""; |
|---|
| 379 | CMSType = ""; |
|---|
| 380 | } |
|---|
| 381 | } |
|---|
| 382 | else if (qName.equals(ELEMENT.FACILITATOR_EVALUATION.tag)) |
|---|
| 383 | { |
|---|
| 384 | eventMap.put(docPosition.peek(), ScriptEvent.factoryByType(ScriptEvent.ScriptEventType.FACILITATOR_EVAL_EVENT)); |
|---|
| 385 | trackedEvent = eventMap.get(docPosition.peek()); |
|---|
| 386 | } |
|---|
| 387 | else if (qName.equals(ELEMENT.INSTRUCTOR.tag)) |
|---|
| 388 | { |
|---|
| 389 | try |
|---|
| 390 | { |
|---|
| 391 | InstructorRole = attributes.getValue("Role"); |
|---|
| 392 | } |
|---|
| 393 | catch (Exception e) |
|---|
| 394 | { |
|---|
| 395 | System.out.println("SERIOUS PARSING ERROR IN \'Role\'"); |
|---|
| 396 | InstructorRole = ""; |
|---|
| 397 | } |
|---|
| 398 | } |
|---|
| 399 | else if (qName.equals(ELEMENT.LINE.tag)) |
|---|
| 400 | { |
|---|
| 401 | try |
|---|
| 402 | { |
|---|
| 403 | LineRole = attributes.getValue("Role"); |
|---|
| 404 | } |
|---|
| 405 | catch (Exception e) |
|---|
| 406 | { |
|---|
| 407 | LineRole = ""; |
|---|
| 408 | } |
|---|
| 409 | } |
|---|
| 410 | else if (qName.equals(ELEMENT.LOCATION_INFO.tag)) |
|---|
| 411 | { |
|---|
| 412 | try |
|---|
| 413 | { |
|---|
| 414 | LocationInfoID = attributes.getValue("ID"); |
|---|
| 415 | } |
|---|
| 416 | catch (Exception e) |
|---|
| 417 | { |
|---|
| 418 | LocationInfoID = ""; |
|---|
| 419 | } |
|---|
| 420 | } |
|---|
| 421 | else if (qName.equals(ELEMENT.MAINTENANCE_RADIO.tag)) |
|---|
| 422 | { |
|---|
| 423 | eventMap.put(docPosition.peek(), ScriptEvent.factoryByType(ScriptEvent.ScriptEventType.MAINTENANCE_RADIO_EVENT)); |
|---|
| 424 | } |
|---|
| 425 | else if (qName.equals(ELEMENT.NEW_UNIT.tag)) |
|---|
| 426 | { |
|---|
| 427 | try |
|---|
| 428 | { |
|---|
| 429 | NewUnitNum = attributes.getValue("UnitNum"); |
|---|
| 430 | } |
|---|
| 431 | catch (Exception e) |
|---|
| 432 | { |
|---|
| 433 | NewUnitNum = ""; |
|---|
| 434 | } |
|---|
| 435 | } |
|---|
| 436 | else if (qName.equals(ELEMENT.PARAMICS.tag)) |
|---|
| 437 | { |
|---|
| 438 | foundSubEvents = true; |
|---|
| 439 | eventMap.put(docPosition.peek(), ScriptEvent.factoryByType(ScriptEvent.ScriptEventType.PARAMICS_EVENT)); |
|---|
| 440 | trackedEvent = eventMap.get(docPosition.peek()); |
|---|
| 441 | try |
|---|
| 442 | { |
|---|
| 443 | ParamicsID = attributes.getValue("LocationID"); |
|---|
| 444 | } |
|---|
| 445 | catch (Exception e) |
|---|
| 446 | { |
|---|
| 447 | ParamicsID = ""; |
|---|
| 448 | } |
|---|
| 449 | } |
|---|
| 450 | else if (qName.equals(ELEMENT.RADIO_EVALUATION.tag)) |
|---|
| 451 | { |
|---|
| 452 | eventMap.put(docPosition.peek(), ScriptEvent.factoryByType(ScriptEvent.ScriptEventType.RADIO_EVAL_EVENT)); |
|---|
| 453 | trackedEvent = eventMap.get(docPosition.peek()); |
|---|
| 454 | } |
|---|
| 455 | else if (qName.equals(ELEMENT.SCRIPT_EVENT.tag)) |
|---|
| 456 | { |
|---|
| 457 | cad = new CadData(); |
|---|
| 458 | } |
|---|
| 459 | |
|---|
| 460 | else if (qName.equals(ELEMENT.TMC_SCRIPT.tag)) |
|---|
| 461 | { |
|---|
| 462 | try |
|---|
| 463 | { |
|---|
| 464 | TMCTitle = attributes.getValue("title"); |
|---|
| 465 | } |
|---|
| 466 | catch (Exception e) |
|---|
| 467 | { |
|---|
| 468 | TMCTitle = ""; |
|---|
| 469 | } |
|---|
| 470 | script.title = TMCTitle; |
|---|
| 471 | |
|---|
| 472 | } |
|---|
| 473 | else if (qName.equals(ELEMENT.TMT_RADIO.tag)) |
|---|
| 474 | { |
|---|
| 475 | eventMap.put(docPosition.peek(), ScriptEvent.factoryByType(ScriptEvent.ScriptEventType.TMT_RADIO_EVENT)); |
|---|
| 476 | } |
|---|
| 477 | else if (qName.equals(ELEMENT.TOW.tag)) |
|---|
| 478 | { |
|---|
| 479 | foundSubEvents = true; |
|---|
| 480 | eventMap.put(docPosition.peek(), ScriptEvent.factoryByType(ScriptEvent.ScriptEventType.TOW_EVENT)); |
|---|
| 481 | try |
|---|
| 482 | { |
|---|
| 483 | TowBeat = attributes.getValue("Beat"); |
|---|
| 484 | TowCompany = attributes.getValue("Company"); |
|---|
| 485 | TowConfNum = attributes.getValue("ConfNum"); |
|---|
| 486 | TowPubNum = attributes.getValue("PubNum"); |
|---|
| 487 | } |
|---|
| 488 | catch (Exception e) |
|---|
| 489 | { |
|---|
| 490 | TowBeat = ""; |
|---|
| 491 | TowCompany = ""; |
|---|
| 492 | TowConfNum = ""; |
|---|
| 493 | TowPubNum = ""; |
|---|
| 494 | } |
|---|
| 495 | } |
|---|
| 496 | else if (qName.equals(ELEMENT.TELEPHONE.tag)) |
|---|
| 497 | { |
|---|
| 498 | eventMap.put(docPosition.peek(), ScriptEvent.factoryByType(ScriptEvent.ScriptEventType.TELEPHONE_EVENT)); |
|---|
| 499 | trackedEvent = eventMap.get(docPosition.peek()); |
|---|
| 500 | } |
|---|
| 501 | else if (qName.equals(ELEMENT.UNIT.tag)) |
|---|
| 502 | { |
|---|
| 503 | foundSubEvents = true; |
|---|
| 504 | eventMap.put(docPosition.peek(), ScriptEvent.factoryByType(ScriptEvent.ScriptEventType.UNIT_EVENT)); |
|---|
| 505 | try |
|---|
| 506 | { |
|---|
| 507 | UnitActive = attributes.getValue("Active"); |
|---|
| 508 | UnitPrimary = attributes.getValue("Primary"); |
|---|
| 509 | UnitStatus = attributes.getValue("Status"); |
|---|
| 510 | UnitNum = attributes.getValue("UnitNum"); |
|---|
| 511 | } |
|---|
| 512 | catch (Exception e) |
|---|
| 513 | { |
|---|
| 514 | UnitActive = ""; |
|---|
| 515 | UnitPrimary = ""; |
|---|
| 516 | UnitStatus = ""; |
|---|
| 517 | UnitNum = "0-0"; |
|---|
| 518 | } |
|---|
| 519 | } |
|---|
| 520 | else if (qName.equals(ELEMENT.WITNESS.tag)) |
|---|
| 521 | { |
|---|
| 522 | foundSubEvents = true; |
|---|
| 523 | eventMap.put(docPosition.peek(), ScriptEvent.factoryByType(ScriptEvent.ScriptEventType.WITNESS_EVENT)); |
|---|
| 524 | try |
|---|
| 525 | { |
|---|
| 526 | WitnessAddress = attributes.getValue("Address"); |
|---|
| 527 | WitnessName = attributes.getValue("Name"); |
|---|
| 528 | WitnessNum = attributes.getValue("PhoneNum"); |
|---|
| 529 | } |
|---|
| 530 | catch (Exception e) |
|---|
| 531 | { |
|---|
| 532 | WitnessAddress = ""; |
|---|
| 533 | WitnessName = ""; |
|---|
| 534 | WitnessNum = ""; |
|---|
| 535 | } |
|---|
| 536 | } |
|---|
| 537 | else if (qName.equals(ELEMENT.INCIDENT.tag)) |
|---|
| 538 | { |
|---|
| 539 | try |
|---|
| 540 | { |
|---|
| 541 | incidentLogNumber = Integer.parseInt(attributes.getValue( |
|---|
| 542 | "LogNum")); |
|---|
| 543 | } |
|---|
| 544 | catch (Exception e) |
|---|
| 545 | { |
|---|
| 546 | myScriptLogger.logp(Level.SEVERE, "ScriptHandler", "startElement", |
|---|
| 547 | "Invalid LogNumber " + attributes.getValue( |
|---|
| 548 | "LogNum"), e); |
|---|
| 549 | incidentLogNumber = 0; |
|---|
| 550 | } |
|---|
| 551 | } |
|---|
| 552 | else if (qName.equals(ELEMENT.UNIT.tag)) |
|---|
| 553 | { |
|---|
| 554 | try |
|---|
| 555 | { |
|---|
| 556 | UnitNum = attributes.getValue("UnitNum"); |
|---|
| 557 | } |
|---|
| 558 | catch (Exception e) |
|---|
| 559 | { |
|---|
| 560 | myScriptLogger.logp(Level.SEVERE, "ScriptHandler", "startElement", |
|---|
| 561 | "Invalid Unit Number " + attributes.getValue( |
|---|
| 562 | "UnitNum"), e); |
|---|
| 563 | UnitNum = "0-0"; |
|---|
| 564 | } |
|---|
| 565 | } |
|---|
| 566 | } |
|---|
| 567 | catch (Exception e) |
|---|
| 568 | { |
|---|
| 569 | myScriptLogger.logp(Level.SEVERE, "ScriptHandler", "startElement", |
|---|
| 570 | "Exception in starting element <" + qName + ">.", e); |
|---|
| 571 | } |
|---|
| 572 | } |
|---|
| 573 | |
|---|
| 574 | /** |
|---|
| 575 | * SAX Handler method. Append read characters to local buffer. |
|---|
| 576 | */ |
|---|
| 577 | @Override |
|---|
| 578 | public void characters(char[] ch, int start, int length) |
|---|
| 579 | { |
|---|
| 580 | String str = new String(ch, start, length).trim(); |
|---|
| 581 | str = str.replace("\t ", ""); |
|---|
| 582 | str = str.replace("\t", ""); |
|---|
| 583 | str = str.replace("\n ", "\n"); |
|---|
| 584 | |
|---|
| 585 | parsedValue.append(str); |
|---|
| 586 | if (pcData.get(docPosition.peek()) == null || pcData.get(docPosition.peek()).equals("")) |
|---|
| 587 | { |
|---|
| 588 | pcData.put(docPosition.peek(), str); |
|---|
| 589 | } |
|---|
| 590 | else |
|---|
| 591 | { |
|---|
| 592 | pcData.put(docPosition.peek(), "" + (pcData.get(docPosition.peek()) |
|---|
| 593 | + "\n" + str)); |
|---|
| 594 | } |
|---|
| 595 | } |
|---|
| 596 | |
|---|
| 597 | /** |
|---|
| 598 | * SAX Handler method. Executes at the close of each XML element. |
|---|
| 599 | */ |
|---|
| 600 | @Override |
|---|
| 601 | public void endElement(String uri, String localName, String qName) |
|---|
| 602 | { |
|---|
| 603 | currentElement = docPosition.pop(); |
|---|
| 604 | I_ScriptEvent newEvent = null; |
|---|
| 605 | try |
|---|
| 606 | { |
|---|
| 607 | if (currentElement == ELEMENT.ATMS_EVALUATION) |
|---|
| 608 | { |
|---|
| 609 | newEvent = eventMap.remove(currentElement); |
|---|
| 610 | |
|---|
| 611 | currInc.addNewEvent(newEvent, (int) currentEventTime); |
|---|
| 612 | } |
|---|
| 613 | else if (currentElement == ELEMENT.ACTIVITY_LOG_EVALUATION) |
|---|
| 614 | { |
|---|
| 615 | newEvent = eventMap.remove(currentElement); |
|---|
| 616 | |
|---|
| 617 | currInc.addNewEvent(newEvent, (int) currentEventTime); |
|---|
| 618 | } |
|---|
| 619 | else if (currentElement == ELEMENT.AGY && docPosition.peek() == ELEMENT.GENERAL) |
|---|
| 620 | { |
|---|
| 621 | cad.Agy = pcData.remove(currentElement); |
|---|
| 622 | } |
|---|
| 623 | else if (currentElement == ELEMENT.ADDRESS && docPosition.peek() == ELEMENT.LOCATION) |
|---|
| 624 | { |
|---|
| 625 | cad.Location_Address = pcData.remove(currentElement); |
|---|
| 626 | } |
|---|
| 627 | else if (currentElement == ELEMENT.AREA && docPosition.peek() == ELEMENT.LOCATION) |
|---|
| 628 | { |
|---|
| 629 | cad.Location_Area = pcData.remove(currentElement); |
|---|
| 630 | } |
|---|
| 631 | else if (currentElement == ELEMENT.BEAT && docPosition.peek() == ELEMENT.LOCATION) |
|---|
| 632 | { |
|---|
| 633 | cad.Location_Beat = pcData.remove(currentElement); |
|---|
| 634 | } |
|---|
| 635 | else if (currentElement == ELEMENT.CITY && docPosition.peek() == ELEMENT.LOCATION) |
|---|
| 636 | { |
|---|
| 637 | cad.Location_City = pcData.remove(currentElement); |
|---|
| 638 | } |
|---|
| 639 | else if (currentElement == ELEMENT.EMS && docPosition.peek() == ELEMENT.LOCATION) |
|---|
| 640 | { |
|---|
| 641 | cad.Location_Ems = pcData.remove(currentElement); |
|---|
| 642 | } |
|---|
| 643 | else if (currentElement == ELEMENT.FIRE && docPosition.peek() == ELEMENT.LOCATION) |
|---|
| 644 | { |
|---|
| 645 | cad.Location_Fire = pcData.remove(currentElement); |
|---|
| 646 | } |
|---|
| 647 | else if (currentElement == ELEMENT.LAW && docPosition.peek() == ELEMENT.LOCATION) |
|---|
| 648 | { |
|---|
| 649 | cad.Location_Law = pcData.remove(currentElement); |
|---|
| 650 | } |
|---|
| 651 | else if (currentElement == ELEMENT.LOC && docPosition.peek() == ELEMENT.LOCATION) |
|---|
| 652 | { |
|---|
| 653 | cad.Location_Loc = pcData.remove(currentElement); |
|---|
| 654 | } |
|---|
| 655 | else if (currentElement == ELEMENT.Type && docPosition.peek() == ELEMENT.HEADER_INFO) |
|---|
| 656 | { |
|---|
| 657 | cad.Header_Type = pcData.remove(currentElement); |
|---|
| 658 | } |
|---|
| 659 | else if (currentElement == ELEMENT.Beat && docPosition.peek() == ELEMENT.HEADER_INFO) |
|---|
| 660 | { |
|---|
| 661 | cad.Header_Beat = pcData.remove(currentElement); |
|---|
| 662 | } |
|---|
| 663 | else if (currentElement == ELEMENT.TruncLoc && docPosition.peek() == ELEMENT.HEADER_INFO) |
|---|
| 664 | { |
|---|
| 665 | cad.Header_TruncLoc = pcData.remove(currentElement); |
|---|
| 666 | } |
|---|
| 667 | else if (currentElement == ELEMENT.FullLoc && docPosition.peek() == ELEMENT.HEADER_INFO) |
|---|
| 668 | { |
|---|
| 669 | cad.Header_FullLoc = pcData.remove(currentElement); |
|---|
| 670 | } |
|---|
| 671 | |
|---|
| 672 | else if (currentElement == ELEMENT.AUDIO) |
|---|
| 673 | { |
|---|
| 674 | newEvent = eventMap.remove(currentElement); |
|---|
| 675 | ((AudioEvent) newEvent).audioLength = audioLength; |
|---|
| 676 | ((AudioEvent) newEvent).audioPath = audioPath; |
|---|
| 677 | ((AudioEvent) newEvent).length = audioLength; |
|---|
| 678 | currInc.addNewEvent(newEvent, (int) currentEventTime); |
|---|
| 679 | } |
|---|
| 680 | else if (currentElement == ELEMENT.CAD_EVALUATION) |
|---|
| 681 | { |
|---|
| 682 | newEvent = eventMap.remove(currentElement); |
|---|
| 683 | |
|---|
| 684 | currInc.addNewEvent(newEvent, (int) currentEventTime); |
|---|
| 685 | } |
|---|
| 686 | else if (currentElement == ELEMENT.CAD_INCIDENT_EVENT) |
|---|
| 687 | { |
|---|
| 688 | newEvent = eventMap.remove(currentElement); |
|---|
| 689 | ((CADEvent) newEvent).detail = pcData.remove(ELEMENT.DETAIL); |
|---|
| 690 | ((CADEvent) newEvent).hasSubEvents = foundSubEvents; |
|---|
| 691 | if (null != ((CADEvent) newEvent).detail) |
|---|
| 692 | { |
|---|
| 693 | if (!(((CADEvent) newEvent).detail.equals(""))) |
|---|
| 694 | { |
|---|
| 695 | currInc.addNewEvent(newEvent, (int) currentEventTime); |
|---|
| 696 | } |
|---|
| 697 | } |
|---|
| 698 | foundSubEvents = false; |
|---|
| 699 | } |
|---|
| 700 | else if (currentElement == ELEMENT.CCTV_INFO) |
|---|
| 701 | { |
|---|
| 702 | newEvent = eventMap.remove(currentElement); |
|---|
| 703 | ((CCTVEvent) newEvent).message = pcData.remove(ELEMENT.CCTV_INFO); |
|---|
| 704 | currInc.addNewEvent(newEvent, (int) currentEventTime); |
|---|
| 705 | } |
|---|
| 706 | else if (currentElement == ELEMENT.CHP_RADIO) |
|---|
| 707 | { |
|---|
| 708 | newEvent = eventMap.remove(currentElement); |
|---|
| 709 | ((CHPRadioEvent) newEvent).radioFile = CHPRadiofile; |
|---|
| 710 | currInc.addNewEvent(newEvent, (int) currentEventTime); |
|---|
| 711 | } |
|---|
| 712 | |
|---|
| 713 | else if (currentElement == ELEMENT.CMS_EVALUATION) |
|---|
| 714 | { |
|---|
| 715 | newEvent = eventMap.remove(currentElement); |
|---|
| 716 | ((CMSEvaluationEvent) newEvent).cmsID = CMSID; |
|---|
| 717 | ((CMSEvaluationEvent) newEvent).cmsType = CMSType; |
|---|
| 718 | if (pcData.get(ELEMENT.LOCATION) != null) |
|---|
| 719 | { |
|---|
| 720 | ((CMSEvaluationEvent) newEvent).location = pcData.remove(ELEMENT.LOCATION); |
|---|
| 721 | } |
|---|
| 722 | |
|---|
| 723 | currInc.addNewEvent(newEvent, (int) currentEventTime); |
|---|
| 724 | } |
|---|
| 725 | else if (currentElement == ELEMENT.CMS_LINE) |
|---|
| 726 | { |
|---|
| 727 | if (trackedEvent instanceof CMSEvaluationEvent) |
|---|
| 728 | { |
|---|
| 729 | ((CMSEvaluationEvent) trackedEvent).message.add(pcData.remove(ELEMENT.CMS_LINE)); |
|---|
| 730 | } |
|---|
| 731 | } |
|---|
| 732 | else if (currentElement == ELEMENT.EXPECTED_ACTION) |
|---|
| 733 | { |
|---|
| 734 | if (trackedEvent instanceof I_EvaluationEvent) |
|---|
| 735 | { |
|---|
| 736 | ((I_EvaluationEvent) trackedEvent).addAction(pcData.remove(ELEMENT.EXPECTED_ACTION)); |
|---|
| 737 | } |
|---|
| 738 | } |
|---|
| 739 | else if (currentElement == ELEMENT.FACILITATOR_EVALUATION) |
|---|
| 740 | { |
|---|
| 741 | newEvent = eventMap.remove(currentElement); |
|---|
| 742 | |
|---|
| 743 | currInc.addNewEvent(newEvent, (int) currentEventTime); |
|---|
| 744 | } |
|---|
| 745 | else if (currentElement == ELEMENT.INSTRUCTOR) |
|---|
| 746 | { |
|---|
| 747 | if (trackedEvent instanceof TelephoneEvent) |
|---|
| 748 | { |
|---|
| 749 | ((TelephoneEvent) trackedEvent).lines.add(pcData.remove(ELEMENT.INSTRUCTOR)); |
|---|
| 750 | ((TelephoneEvent) trackedEvent).roles.add(InstructorRole); |
|---|
| 751 | } |
|---|
| 752 | } |
|---|
| 753 | else if (currentElement == ELEMENT.Lane_number) |
|---|
| 754 | { |
|---|
| 755 | if (trackedEvent instanceof ParamicsEvent) |
|---|
| 756 | { |
|---|
| 757 | ((ParamicsEvent) trackedEvent).laneNums.add(Integer.parseInt(pcData.remove(ELEMENT.Lane_number))); |
|---|
| 758 | } |
|---|
| 759 | } |
|---|
| 760 | else if (currentElement == ELEMENT.LINE) |
|---|
| 761 | { |
|---|
| 762 | if (trackedEvent instanceof CHPRadioEvent) |
|---|
| 763 | { |
|---|
| 764 | ((CHPRadioEvent) trackedEvent).lines.add(pcData.remove(ELEMENT.LINE)); |
|---|
| 765 | ((CHPRadioEvent) trackedEvent).roles.add(LineRole); |
|---|
| 766 | } |
|---|
| 767 | } |
|---|
| 768 | else if (currentElement == ELEMENT.LOCATION_INFO) |
|---|
| 769 | { |
|---|
| 770 | Location_Info locInfo = new Location_Info(); |
|---|
| 771 | |
|---|
| 772 | locInfo.Location_ID = LocationInfoID; |
|---|
| 773 | locInfo.Direction = pcData.remove(ELEMENT.Direction); |
|---|
| 774 | locInfo.Location_type = pcData.remove(ELEMENT.Location_type); |
|---|
| 775 | locInfo.Route = pcData.remove(ELEMENT.Route); |
|---|
| 776 | locInfo.Postmile = pcData.remove(ELEMENT.Postmile); |
|---|
| 777 | cad.locInfo.add(locInfo); |
|---|
| 778 | } |
|---|
| 779 | else if (currentElement == ELEMENT.MAINTENANCE_RADIO) |
|---|
| 780 | { |
|---|
| 781 | newEvent = eventMap.remove(currentElement); |
|---|
| 782 | ((MaintenanceRadioEvent) newEvent).message = pcData.remove(ELEMENT.MAINTENANCE_RADIO); |
|---|
| 783 | currInc.addNewEvent(newEvent, (int) currentEventTime); |
|---|
| 784 | } |
|---|
| 785 | else if (currentElement == ELEMENT.MASTER_INC_NUM) |
|---|
| 786 | { |
|---|
| 787 | cad.Master_Inc_Num = pcData.remove(currentElement); |
|---|
| 788 | } |
|---|
| 789 | else if (currentElement == ELEMENT.P) |
|---|
| 790 | { |
|---|
| 791 | cad.P = pcData.remove(currentElement); |
|---|
| 792 | } |
|---|
| 793 | else if (currentElement == ELEMENT.PARAMICS) |
|---|
| 794 | { |
|---|
| 795 | newEvent = eventMap.remove(currentElement); |
|---|
| 796 | ((ParamicsEvent) newEvent).locationID = ParamicsID; |
|---|
| 797 | |
|---|
| 798 | if (pcData.get(ELEMENT.Status) != null) |
|---|
| 799 | { |
|---|
| 800 | ((ParamicsEvent) newEvent).status = pcData.remove(ELEMENT.Status); |
|---|
| 801 | } |
|---|
| 802 | if (pcData.get(ELEMENT.Incident_type) != null) |
|---|
| 803 | { |
|---|
| 804 | ((ParamicsEvent) newEvent).type = pcData.remove(ELEMENT.Incident_type); |
|---|
| 805 | } |
|---|
| 806 | currInc.addNewEvent(newEvent, (int) currentEventTime); |
|---|
| 807 | } |
|---|
| 808 | else if (currentElement == ELEMENT.RADIO_EVALUATION) |
|---|
| 809 | { |
|---|
| 810 | newEvent = eventMap.remove(currentElement); |
|---|
| 811 | |
|---|
| 812 | currInc.addNewEvent(newEvent, (int) currentEventTime); |
|---|
| 813 | } |
|---|
| 814 | else if (currentElement == ELEMENT.SCRIPT_EVENT) |
|---|
| 815 | { |
|---|
| 816 | currInc.insertCadData(currentEventTime, cad); |
|---|
| 817 | } |
|---|
| 818 | else if (currentElement == ELEMENT.STUDENT) |
|---|
| 819 | { |
|---|
| 820 | if (trackedEvent instanceof TelephoneEvent) |
|---|
| 821 | { |
|---|
| 822 | ((TelephoneEvent) trackedEvent).lines.add(pcData.remove(ELEMENT.STUDENT)); |
|---|
| 823 | ((TelephoneEvent) trackedEvent).roles.add("Student"); |
|---|
| 824 | } |
|---|
| 825 | } |
|---|
| 826 | else if (currentElement == ELEMENT.TEXT && docPosition.peek() == ELEMENT.GENERAL_INFO) |
|---|
| 827 | { |
|---|
| 828 | currInc.description = pcData.remove(ELEMENT.TEXT); |
|---|
| 829 | cad.General_Text = currInc.description; |
|---|
| 830 | } |
|---|
| 831 | else if (currentElement == ELEMENT.TITLE && docPosition.peek() == ELEMENT.GENERAL_INFO) |
|---|
| 832 | { |
|---|
| 833 | cad.General_Title = pcData.remove(ELEMENT.TITLE); |
|---|
| 834 | } |
|---|
| 835 | else if (currentElement == ELEMENT.TMT_RADIO) |
|---|
| 836 | { |
|---|
| 837 | newEvent = eventMap.remove(currentElement); |
|---|
| 838 | ((TMTRadioEvent) newEvent).message = pcData.remove(ELEMENT.TMT_RADIO); |
|---|
| 839 | currInc.addNewEvent(newEvent, (int) currentEventTime); |
|---|
| 840 | } |
|---|
| 841 | else if (currentElement == ELEMENT.TELEPHONE) |
|---|
| 842 | { |
|---|
| 843 | newEvent = eventMap.remove(currentElement); |
|---|
| 844 | currInc.addNewEvent(newEvent, (int) currentEventTime); |
|---|
| 845 | } |
|---|
| 846 | else if (currentElement == ELEMENT.TOW) |
|---|
| 847 | { |
|---|
| 848 | newEvent = eventMap.remove(currentElement); |
|---|
| 849 | ((TowEvent) newEvent).towBeat = TowBeat; |
|---|
| 850 | ((TowEvent) newEvent).towCompany = TowCompany; |
|---|
| 851 | ((TowEvent) newEvent).towConfNum = TowConfNum; |
|---|
| 852 | ((TowEvent) newEvent).towPubNum = TowPubNum; |
|---|
| 853 | currInc.addNewEvent(newEvent, (int) currentEventTime); |
|---|
| 854 | } |
|---|
| 855 | else if (currentElement == ELEMENT.TYPE && docPosition.peek() == ELEMENT.ADDITIONAL_INFO) |
|---|
| 856 | { |
|---|
| 857 | cad.Info_Type = pcData.remove(currentElement); |
|---|
| 858 | } |
|---|
| 859 | else if (currentElement == ELEMENT.TYPE_CODE && docPosition.peek() == ELEMENT.ADDITIONAL_INFO) |
|---|
| 860 | { |
|---|
| 861 | cad.Info_Type_Code = pcData.remove(currentElement); |
|---|
| 862 | } |
|---|
| 863 | else if (currentElement == ELEMENT.UNIT) |
|---|
| 864 | { |
|---|
| 865 | newEvent = eventMap.remove(currentElement); |
|---|
| 866 | ((UnitEvent) newEvent).unitActive = UnitActive; |
|---|
| 867 | ((UnitEvent) newEvent).unitPrimary = UnitPrimary; |
|---|
| 868 | ((UnitEvent) newEvent).unitStatus = UnitStatus; |
|---|
| 869 | ((UnitEvent) newEvent).unitNum = UnitNum; |
|---|
| 870 | currInc.addNewEvent(newEvent, (int) currentEventTime); |
|---|
| 871 | } |
|---|
| 872 | else if (currentElement == ELEMENT.WITNESS) |
|---|
| 873 | { |
|---|
| 874 | newEvent = eventMap.remove(currentElement); |
|---|
| 875 | ((WitnessEvent) newEvent).witnessAddress = WitnessAddress; |
|---|
| 876 | ((WitnessEvent) newEvent).witnessName = WitnessName; |
|---|
| 877 | ((WitnessEvent) newEvent).witnessNum = WitnessNum; |
|---|
| 878 | currInc.addNewEvent(newEvent, (int) currentEventTime); |
|---|
| 879 | } |
|---|
| 880 | |
|---|
| 881 | else if (currentElement == ELEMENT.INCIDENT) |
|---|
| 882 | { |
|---|
| 883 | currentIncName = parsedValue.toString(); |
|---|
| 884 | |
|---|
| 885 | if (incidentMap.get(incidentLogNumber) == null) |
|---|
| 886 | { |
|---|
| 887 | incidentMap.put(incidentLogNumber, |
|---|
| 888 | new ScriptIncident(SimulationScript.incidentColors[Math.abs(new Random().nextInt()) % SimulationScript.incidentColors.length], |
|---|
| 889 | incidentLogNumber, currentIncName, currentIncidentDesc, |
|---|
| 890 | script, (int) currentEventTime)); |
|---|
| 891 | } |
|---|
| 892 | currInc = incidentMap.get(incidentLogNumber); |
|---|
| 893 | |
|---|
| 894 | } |
|---|
| 895 | else if (currentElement == ELEMENT.NEW_UNIT) |
|---|
| 896 | { |
|---|
| 897 | Unit unit = new Unit(); |
|---|
| 898 | unit.UnitNum = NewUnitNum; |
|---|
| 899 | if (pcData.containsKey(ELEMENT.AGY)) |
|---|
| 900 | { |
|---|
| 901 | unit.Agy = pcData.remove(ELEMENT.AGY); |
|---|
| 902 | } |
|---|
| 903 | if (pcData.containsKey(ELEMENT.ALIAS)) |
|---|
| 904 | { |
|---|
| 905 | unit.Alias = pcData.remove(ELEMENT.ALIAS); |
|---|
| 906 | } |
|---|
| 907 | if (pcData.containsKey(ELEMENT.AREA)) |
|---|
| 908 | { |
|---|
| 909 | unit.Area = pcData.remove(ELEMENT.AREA); |
|---|
| 910 | } |
|---|
| 911 | if (pcData.containsKey(ELEMENT.BADGE_NUM)) |
|---|
| 912 | { |
|---|
| 913 | unit.Badge_Num = pcData.remove(ELEMENT.BADGE_NUM); |
|---|
| 914 | } |
|---|
| 915 | if (pcData.containsKey(ELEMENT.CURR_LOC)) |
|---|
| 916 | { |
|---|
| 917 | unit.Curr_Loc = pcData.remove(ELEMENT.CURR_LOC); |
|---|
| 918 | } |
|---|
| 919 | if (pcData.containsKey(ELEMENT.DESTINATION)) |
|---|
| 920 | { |
|---|
| 921 | unit.Destination = pcData.remove(ELEMENT.DESTINATION); |
|---|
| 922 | } |
|---|
| 923 | if (pcData.containsKey(ELEMENT.ID)) |
|---|
| 924 | { |
|---|
| 925 | unit.ID = pcData.remove(ELEMENT.ID); |
|---|
| 926 | } |
|---|
| 927 | if (pcData.containsKey(ELEMENT.MASTER_INC_NUM)) |
|---|
| 928 | { |
|---|
| 929 | unit.Master_Inc_Num = pcData.remove(ELEMENT.MASTER_INC_NUM); |
|---|
| 930 | } |
|---|
| 931 | if (pcData.containsKey(ELEMENT.MISC_INFO)) |
|---|
| 932 | { |
|---|
| 933 | unit.Misc_Info = pcData.remove(ELEMENT.MISC_INFO); |
|---|
| 934 | } |
|---|
| 935 | if (pcData.containsKey(ELEMENT.OOS)) |
|---|
| 936 | { |
|---|
| 937 | unit.OOS = pcData.remove(ELEMENT.OOS); |
|---|
| 938 | } |
|---|
| 939 | if (pcData.containsKey(ELEMENT.OFFICE)) |
|---|
| 940 | { |
|---|
| 941 | unit.Office = pcData.remove(ELEMENT.OFFICE); |
|---|
| 942 | } |
|---|
| 943 | if (pcData.containsKey(ELEMENT.OFFICER)) |
|---|
| 944 | { |
|---|
| 945 | unit.Officer = pcData.remove(ELEMENT.OFFICER); |
|---|
| 946 | } |
|---|
| 947 | if (pcData.containsKey(ELEMENT.P)) |
|---|
| 948 | { |
|---|
| 949 | unit.P = pcData.remove(ELEMENT.P); |
|---|
| 950 | } |
|---|
| 951 | if (pcData.containsKey(ELEMENT.PRIMARY)) |
|---|
| 952 | { |
|---|
| 953 | unit.Primary = pcData.remove(ELEMENT.PRIMARY); |
|---|
| 954 | } |
|---|
| 955 | if (pcData.containsKey(ELEMENT.STACK)) |
|---|
| 956 | { |
|---|
| 957 | unit.Stack = pcData.remove(ELEMENT.STACK); |
|---|
| 958 | } |
|---|
| 959 | if (pcData.containsKey(ELEMENT.STATUS)) |
|---|
| 960 | { |
|---|
| 961 | unit.Status = pcData.remove(ELEMENT.STATUS); |
|---|
| 962 | } |
|---|
| 963 | if (pcData.containsKey(ELEMENT.TIMER)) |
|---|
| 964 | { |
|---|
| 965 | unit.Timer = pcData.remove(ELEMENT.TIMER); |
|---|
| 966 | } |
|---|
| 967 | units.add(unit); |
|---|
| 968 | } |
|---|
| 969 | |
|---|
| 970 | else if (qName.equals(ELEMENT.TIME_INDEX.tag)) |
|---|
| 971 | { |
|---|
| 972 | currentEventTime = timeBytesToSeconds(parsedValue.toString().trim()); |
|---|
| 973 | } |
|---|
| 974 | |
|---|
| 975 | parsedValue.setLength(0); |
|---|
| 976 | eventMap.put(currentElement, null); |
|---|
| 977 | } |
|---|
| 978 | catch (Exception e) |
|---|
| 979 | { |
|---|
| 980 | myScriptLogger.logp(Level.SEVERE, "ScriptHandler", "endElement", |
|---|
| 981 | "Exception in ending element <" + qName + ">.", e); |
|---|
| 982 | } |
|---|
| 983 | /* |
|---|
| 984 | String t = ""; |
|---|
| 985 | sublevels--; |
|---|
| 986 | for (int i = 0; i < sublevels; i++) |
|---|
| 987 | { |
|---|
| 988 | t += "\t"; |
|---|
| 989 | } |
|---|
| 990 | System.out.println(t + "End of element " + qName);*/ |
|---|
| 991 | |
|---|
| 992 | } |
|---|
| 993 | |
|---|
| 994 | /** |
|---|
| 995 | * SAX Handler method. End the document and close it out. |
|---|
| 996 | */ |
|---|
| 997 | @Override |
|---|
| 998 | public void endDocument() |
|---|
| 999 | { |
|---|
| 1000 | //System.out.println("STUB: End the document"); |
|---|
| 1001 | } |
|---|
| 1002 | |
|---|
| 1003 | /** |
|---|
| 1004 | * Sax Handler method. Log normal errors. |
|---|
| 1005 | */ |
|---|
| 1006 | @Override |
|---|
| 1007 | public void error(SAXParseException e) |
|---|
| 1008 | { |
|---|
| 1009 | myScriptLogger.logp(Level.SEVERE, "ScriptHandler", "error", |
|---|
| 1010 | "SAX Parsing error.", e); |
|---|
| 1011 | } |
|---|
| 1012 | |
|---|
| 1013 | /** |
|---|
| 1014 | * SAX Handler method. Log fatal errors. |
|---|
| 1015 | */ |
|---|
| 1016 | @Override |
|---|
| 1017 | public void fatalError(SAXParseException e) |
|---|
| 1018 | { |
|---|
| 1019 | myScriptLogger.logp(Level.SEVERE, "ScriptHandler", "fatalError", |
|---|
| 1020 | "SAX Parsing fatal error.", e); |
|---|
| 1021 | } |
|---|
| 1022 | |
|---|
| 1023 | /** |
|---|
| 1024 | * SAX Handler method. Log warnings. |
|---|
| 1025 | */ |
|---|
| 1026 | @Override |
|---|
| 1027 | public void warning(SAXParseException e) |
|---|
| 1028 | { |
|---|
| 1029 | myScriptLogger.logp(Level.SEVERE, "ScriptHandler", "warning", |
|---|
| 1030 | "SAX Parsing warning.", e); |
|---|
| 1031 | } |
|---|
| 1032 | |
|---|
| 1033 | /** |
|---|
| 1034 | * Private method to convert a time object from format HH:MM:SS to a long |
|---|
| 1035 | * value of the corresponding number of seconds. |
|---|
| 1036 | * |
|---|
| 1037 | * @param time String time representation of format HH:MM:SS |
|---|
| 1038 | * @return long Number of seconds |
|---|
| 1039 | * @throws StringIndexOutOfBoundsException if the input parameter is not |
|---|
| 1040 | * valid |
|---|
| 1041 | */ |
|---|
| 1042 | private long timeBytesToSeconds(String time) |
|---|
| 1043 | throws StringIndexOutOfBoundsException |
|---|
| 1044 | { |
|---|
| 1045 | long seconds = 0; |
|---|
| 1046 | |
|---|
| 1047 | seconds = ((long) Character.digit(time.charAt(0), 10) * 36000 |
|---|
| 1048 | + Character.digit(time.charAt(1), 10) * 3600 |
|---|
| 1049 | + Character.digit(time.charAt(3), 10) * 600 |
|---|
| 1050 | + Character.digit(time.charAt(4), 10) * 60 |
|---|
| 1051 | + Character.digit(time.charAt(6), 10) * 10 |
|---|
| 1052 | + Character.digit(time.charAt(7), 10)); |
|---|
| 1053 | |
|---|
| 1054 | return seconds; |
|---|
| 1055 | } |
|---|
| 1056 | } |
|---|