Changeset 1027 for trunk/autoquest-plugin-jfc/src/main/java/de/ugoe/cs
- Timestamp:
- 01/02/13 10:09:15 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-plugin-jfc/src/main/java/de/ugoe/cs/autoquest/plugin/jfc/JFCSimplifiedLogParser.java
r1010 r1027 15 15 import java.util.Map; 16 16 import java.util.logging.Level; 17 import java.util.regex.Matcher;18 import java.util.regex.Pattern;19 17 20 18 import javax.xml.parsers.ParserConfigurationException; … … 71 69 */ 72 70 private JFCEventId currentEventId; 73 71 74 72 /** 75 73 * … … 79 77 */ 80 78 private Long currentGUIElementHash; 81 79 82 80 /** 83 81 * … … 87 85 */ 88 86 private Long currentParentHash; 89 87 90 88 /** 91 89 * <p> … … 94 92 */ 95 93 private Long currentEventSource; 96 94 97 95 /** 98 96 * <p> … … 100 98 */ 101 99 private Long currentEventTimestamp = -1l; 102 100 103 101 /** 104 102 * <p> … … 114 112 */ 115 113 private List<Event> currentSequence; 116 114 117 115 /** 118 116 * <p> … … 127 125 * </p> 128 126 */ 129 private GUIElementTree currentGUIElementTree;127 private GUIElementTree<Long> currentGUIElementTree; 130 128 131 129 /** … … 136 134 */ 137 135 private IGUIElement lastGUIElement; 138 136 139 137 /** 140 138 * <p> … … 150 148 */ 151 149 private List<VirtualKey> mPressedKeys = new ArrayList<VirtualKey>(); 152 150 153 151 /** 154 152 * <p> … … 225 223 saxParser = spf.newSAXParser(); 226 224 inputSource = 227 new InputSource(new InputStreamReader(new FileInputStream(file), "UTF-8"));225 new InputSource(new InputStreamReader(new FileInputStream(file), "UTF-8")); 228 226 } 229 227 catch (UnsupportedEncodingException e) { … … 257 255 catch (SAXParseException e) { 258 256 Console.printerrln("Failure parsing file in line " + e.getLineNumber() + 259 ", column " + e.getColumnNumber() + ".");257 ", column " + e.getColumnNumber() + "."); 260 258 Console.logException(e); 261 259 return; … … 303 301 */ 304 302 public void startElement(String uri, String localName, String qName, Attributes atts) 305 throws SAXException{303 throws SAXException{ 306 304 if (qName.equals("sessions")) { 307 305 currentSequence = new LinkedList<Event>(); 308 306 if (currentGUIElementTree == null) 309 currentGUIElementTree = new GUIElementTree();307 currentGUIElementTree = new GUIElementTree<Long>(); 310 308 } 311 309 if (qName.equals("newsession")) { … … 318 316 } 319 317 else if (qName.equals("component")) { 320 321 322 318 currentGUIElementHash = Long.parseLong(atts.getValue("hash"), 16); 319 currentGuiElementSpec = new JFCGUIElementSpec(); 320 currentGuiElementSpec.setElementHash((int) currentGUIElementHash.longValue()); 323 321 } 324 322 else if (qName.equals("event")) { … … 330 328 } 331 329 else if (qName.equals("componentNameChange")) { 332 int sourceHash = (int)Long.parseLong(atts.getValue("hash"), 16);333 334 335 336 337 330 long sourceHash = Long.parseLong(atts.getValue("hash"), 16); 331 String newName = atts.getValue("newName"); 332 // int titleSource = Integer.parseInt(atts.getValue("titleSource")); 333 JFCGUIElement sourceElement = (JFCGUIElement) currentGUIElementTree.find(sourceHash); 334 JFCGUIElementSpec sourceSpec = (JFCGUIElementSpec) sourceElement.getSpecification(); 335 sourceSpec.setName(newName); 338 336 } 339 337 else if (qName.equals("param")) { 340 341 342 343 344 345 346 338 if (currentEventId != null){ 339 if ("source".equals(atts.getValue("name"))){ 340 currentEventSource = Long.parseLong(atts.getValue("value"), 16); 341 } 342 if ("timestamp".equals(atts.getValue("name"))){ 343 currentEventTimestamp = Long.parseLong(atts.getValue("value")); 344 } 347 345 currentEventParameters.put(atts.getValue("name"), atts.getValue("value")); 348 346 } else if(currentGUIElementHash != null){ 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 347 if ("title".equals(atts.getValue("name"))) { 348 currentGuiElementSpec.setName(atts.getValue("value")); 349 } 350 else if ("class".equals(atts.getValue("name"))) { 351 currentGuiElementSpec.setType(atts.getValue("value")); 352 } 353 else if ("icon".equals(atts.getValue("name"))) { 354 currentGuiElementSpec.setIcon(atts.getValue("value")); 355 } 356 else if ("index".equals(atts.getValue("name"))) { 357 currentGuiElementSpec.setIndex(Integer.parseInt(atts.getValue("value"))); 358 } 359 else if ("parent".equals(atts.getValue("name"))) { 360 currentParentHash = Long.parseLong(atts.getValue("value"), 16); 361 } 364 362 } 365 363 } 366 364 else if (qName.equals("ancestor")){ 367 365 currentTypeHierarchy.add(atts.getValue("name")); 368 366 } 369 367 else if (qName.equals("ancestors")){ 370 368 currentTypeHierarchy = new LinkedList<String>(); 371 369 } 372 370 } … … 387 385 } 388 386 else if (qName.equals("ancestors")){ 389 387 currentGuiElementSpec.setTypeHierarchy(currentTypeHierarchy); 390 388 } 391 389 else if (qName.equals("component") && currentGUIElementHash != null) { 392 currentGUIElementTree.add(currentGUIElementHash, currentParentHash, currentGuiElementSpec); 393 // do something with the ancestor list here 394 395 currentGUIElementHash = null; 396 currentParentHash = null; 397 currentTypeHierarchy = null; 390 currentGUIElementTree.add(currentGUIElementHash, currentParentHash, currentGuiElementSpec); 391 392 currentGUIElementHash = null; 393 currentParentHash = null; 394 currentTypeHierarchy = null; 398 395 } 399 396 else if (currentEventId != null) { 400 397 if (qName.equals("event")) { 401 398 402 399 IGUIElement currentGUIElement; 403 400 currentGUIElement = currentGUIElementTree.find(currentEventSource); 404 401 405 402 Event event = new Event 406 (instantiateInteraction(currentEventId, currentEventParameters),407 (currentGUIElement == null ? lastGUIElement : currentGUIElement));403 (instantiateInteraction(currentEventId, currentEventParameters), 404 (currentGUIElement == null ? lastGUIElement : currentGUIElement)); 408 405 event.setTimestamp(currentEventTimestamp); 409 406 JFCGUIElement currentEventTarget = (JFCGUIElement) event.getTarget(); 410 407 currentEventTarget.markAsUsed(); 411 408 412 409 currentSequence.add(event); 413 410 414 411 currentEventParameters = null; 415 412 currentEventId = null; 416 413 currentEventTimestamp = -1l; 417 414 418 415 if (currentGUIElement != null) { 419 416 lastGUIElement = currentGUIElement; 420 417 } 421 418 422 419 currentGUIElement = null; 423 420 } … … 442 439 private IInteraction instantiateInteraction(JFCEventId eventId, 443 440 Map<String, String> eventParameters) 444 throws SAXException445 {441 throws SAXException 442 { 446 443 switch (eventId) 447 444 { … … 467 464 throw new SAXException("unhandled event id " + eventId); 468 465 } 469 }466 } 470 467 471 468 /** … … 485 482 */ 486 483 private IInteraction handleMouseAction(JFCEventId eventId, Map<String, String> eventParameters) 487 throws SAXException488 {484 throws SAXException 485 { 489 486 MouseButtonInteraction.Button button = null; 490 487 … … 532 529 throw new SAXException("unknown event id " + eventId); 533 530 } 534 }531 } 535 532 536 533 /** … … 552 549 */ 553 550 private IInteraction handleKeyAction(JFCEventId eventId, Map<String, String> eventParameters) 554 throws SAXException555 {551 throws SAXException 552 { 556 553 // TODO handle shortcuts 557 554 if (JFCEventId.KEY_PRESSED == eventId) … … 572 569 { 573 570 Console.traceln(Level.SEVERE, "log file has an error, as it contains a key up event on key " + 574 571 key + " for which there is no preceeding key down event"); 575 572 } 576 573 … … 579 576 580 577 throw new SAXException("unknown event id " + eventId); 581 }578 } 582 579 583 580 /** … … 596 593 */ 597 594 private IInteraction handleNewFocus(JFCEventId eventId, Map<String, String> eventParameters) 598 throws SAXException599 {595 throws SAXException 596 { 600 597 if (JFCEventId.FOCUS_GAINED == eventId) 601 598 { … … 606 603 throw new SAXException("unknown event id " + eventId); 607 604 } 608 } 609 610 /** 611 * <p> 612 * for some events in the log file, no GUI element specification is provided. In this case the 613 * GUI element on which the event is executed must be determined based on the 614 * <code>toString</code> parameter of the event. This is achieved through this method. The 615 * <code>toString</code> parameter does not always carry sufficient information for the GUI 616 * elements. For example the title is not necessarily provided. Therefore some of this 617 * information is generated. 618 * </p> 619 * 620 * @param toStringValue 621 * the <code>toString</code> parameter of the event to be parsed for the GUI element 622 * 623 * @return the appropriate GUI Element 624 * 625 * @throws SAXException thrown if the provided value of the <code>toString</code> parameter 626 * can not be parsed 627 */ 628 private void getGUIElementSpecFromToString(String toStringValue) 629 throws SAXException 630 { 631 try 632 { 633 // match the following: <type>[<parameters>] 634 String pattern = "([\\w$\\.]*)\\[(.*)\\]"; 635 Matcher matcher = Pattern.compile(pattern).matcher(toStringValue); 636 637 if (!matcher.find()) 638 { 639 throw new IllegalArgumentException 640 ("could not parse target from toString parameter"); 641 } 642 643 String type = matcher.group(1); 644 645 // match the following: <parameter>|, 646 // where <parameter> := <digitValue>|<value>|<key>"="<value> 647 pattern = "([\\w$@=\\.]*)|,"; 648 649 matcher = Pattern.compile(pattern).matcher(matcher.group(2)); 650 651 float elementHash = -1; 652 653 pattern = "(([\\d]*)|([\\w$]*)|(([\\w$@\\.]*)=([\\w$@\\.]*)))\\z"; 654 Pattern valuePattern = Pattern.compile(pattern); 655 656 while (matcher.find()) { 657 Matcher valueMatcher = valuePattern.matcher(matcher.group(1)); 658 if (valueMatcher.find()) { 659 if ((valueMatcher.group(2) != null) && (!"".equals(valueMatcher.group(2)))) { 660 // found digit value. Those in combination usually denote the position 661 // of the GUI element. So calculate an element has out of them 662 elementHash += Integer.parseInt(valueMatcher.group(2)); 663 } 664 else if ((valueMatcher.group(5) != null) && 665 (!"".equals(valueMatcher.group(5))) && 666 (valueMatcher.group(6) != null) && 667 (!"".equals(valueMatcher.group(6)))) 668 { 669 // found a key value pair. Get some of them and integrate them into the hash 670 String key = valueMatcher.group(5); 671 672 if ("alignmentX".equals(key) || "alignmentY".equals(key)) { 673 elementHash += Float.parseFloat(valueMatcher.group(6)); 674 } 675 } 676 } 677 } 678 679 currentGuiElementSpec.setName("unknown(" + ((int) elementHash) + ")"); 680 currentGuiElementSpec.setType(type); 681 currentGuiElementSpec.setIndex(-1); 682 currentGuiElementSpec.setElementHash((int) elementHash); 683 } 684 catch (Exception e) 685 { 686 throw new SAXException("could not parse target", e); 687 } 688 } 689 605 } 606 690 607 /** 691 608 * <p>
Note: See TracChangeset
for help on using the changeset viewer.