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