1 | // Copyright 2012 Georg-August-Universität Göttingen, Germany |
---|
2 | // |
---|
3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
---|
4 | // you may not use this file except in compliance with the License. |
---|
5 | // You may obtain a copy of the License at |
---|
6 | // |
---|
7 | // http://www.apache.org/licenses/LICENSE-2.0 |
---|
8 | // |
---|
9 | // Unless required by applicable law or agreed to in writing, software |
---|
10 | // distributed under the License is distributed on an "AS IS" BASIS, |
---|
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
12 | // See the License for the specific language governing permissions and |
---|
13 | // limitations under the License. |
---|
14 | |
---|
15 | package de.ugoe.cs.autoquest.plugin.genericevents; |
---|
16 | |
---|
17 | import java.util.Map; |
---|
18 | |
---|
19 | import org.xml.sax.SAXException; |
---|
20 | |
---|
21 | import de.ugoe.cs.autoquest.eventcore.Event; |
---|
22 | import de.ugoe.cs.autoquest.eventcore.EventTargetModelException; |
---|
23 | import de.ugoe.cs.autoquest.eventcore.IEventType; |
---|
24 | import de.ugoe.cs.autoquest.eventcore.StringEventType; |
---|
25 | import de.ugoe.cs.autoquest.plugin.genericevents.eventCore.GenericEventTarget; |
---|
26 | import de.ugoe.cs.autoquest.plugin.genericevents.eventCore.GenericEventTargetSpec; |
---|
27 | |
---|
28 | /** |
---|
29 | * <p> |
---|
30 | * This class provides the functionality to parse XML log files generated by the generic event |
---|
31 | * monitor of AutoQUEST. The result of parsing a file is a collection of event sequences and a |
---|
32 | * target model. |
---|
33 | * </p> |
---|
34 | * |
---|
35 | * @author Patrick Harms |
---|
36 | * @version 1.0 |
---|
37 | * |
---|
38 | */ |
---|
39 | public class GenericEventLogParser extends AbstractDefaultLogParser { |
---|
40 | |
---|
41 | /* (non-Javadoc) |
---|
42 | * @see de.ugoe.cs.autoquest.plugin.html.AbstractDefaultLogParser#handleGUIElement(String, Map) |
---|
43 | */ |
---|
44 | @Override |
---|
45 | protected boolean handleTarget(String id, Map<String, String> parameters) |
---|
46 | throws SAXException |
---|
47 | { |
---|
48 | String parentId = parameters.get("parent"); |
---|
49 | |
---|
50 | GenericEventTargetSpec specification = new GenericEventTargetSpec(id, parameters); |
---|
51 | |
---|
52 | try { |
---|
53 | super.getTargetTree().add(id, parentId, specification); |
---|
54 | } |
---|
55 | catch (EventTargetModelException e) { |
---|
56 | throw new SAXException("could not handle generic event target with id " + |
---|
57 | id + ": " + e.getMessage(), e); |
---|
58 | } |
---|
59 | |
---|
60 | return true; |
---|
61 | } |
---|
62 | |
---|
63 | /* (non-Javadoc) |
---|
64 | * @see de.ugoe.cs.autoquest.plugin.html.AbstractDefaultLogParser#handleEvent(String, Map) |
---|
65 | */ |
---|
66 | @Override |
---|
67 | protected boolean handleEvent(String type, Map<String, String> parameters) throws SAXException { |
---|
68 | String targetId = parameters.get("targetId"); |
---|
69 | |
---|
70 | if (targetId == null) { |
---|
71 | throw new SAXException("event does not have a target id"); |
---|
72 | } |
---|
73 | |
---|
74 | GenericEventTarget target = super.getTargetTree().find(targetId); |
---|
75 | |
---|
76 | IEventType eventType = new StringEventType(type); |
---|
77 | |
---|
78 | if (eventType != null) { |
---|
79 | Event event = new Event(eventType, target); |
---|
80 | |
---|
81 | String timestampStr = parameters.get("timestamp"); |
---|
82 | |
---|
83 | if (timestampStr != null) { |
---|
84 | event.setTimestamp(Long.parseLong(timestampStr)); |
---|
85 | } |
---|
86 | |
---|
87 | super.addToSequence(event); |
---|
88 | } |
---|
89 | // else ignore unknown event type |
---|
90 | |
---|
91 | return true; |
---|
92 | } |
---|
93 | |
---|
94 | } |
---|