- Timestamp:
- 02/05/13 14:17:26 (12 years ago)
- Location:
- trunk
- Files:
-
- 3 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/NewHTMLLogParser.java
r1051 r1059 38 38 39 39 import de.ugoe.cs.autoquest.eventcore.Event; 40 import de.ugoe.cs.autoquest.eventcore.IEventType; 40 41 import de.ugoe.cs.autoquest.eventcore.guimodel.GUIElementTree; 41 42 import de.ugoe.cs.autoquest.eventcore.guimodel.GUIModel; … … 44 45 import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLGUIElement; 45 46 import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLGUIElementSpec; 47 import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLPageElementSpec; 48 import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLPageSpec; 49 import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLServerSpec; 46 50 import de.ugoe.cs.util.console.Console; 47 51 … … 72 76 */ 73 77 private Collection<List<Event>> sequences; 74 78 75 79 /** 76 80 * <p> … … 79 83 */ 80 84 private GUIElementTree<String> currentGUIElementTree; 81 85 82 86 /** 83 87 * <p> … … 86 90 */ 87 91 private String currentGUIElementPath; 88 92 89 93 /** 90 94 * <p> … … 93 97 */ 94 98 private String currentParentPath; 95 99 96 100 /** 97 101 * <p> … … 100 104 */ 101 105 private String currentEventSource; 102 106 103 107 /** 104 108 * <p> … … 107 111 */ 108 112 private Long currentEventTimestamp; 109 113 110 114 /** 111 115 * <p> … … 114 118 */ 115 119 private Map<String, String> currentEventParameters; 116 120 121 /** 122 * <p> 123 * Internal handle to the parameters of the GUI element currently being parsed. 124 * </p> 125 */ 126 private Map<String, String> currentGUIElementParameters; 117 127 /** 118 128 * <p> … … 121 131 */ 122 132 private List<Event> currentSequence; 123 133 124 134 /** 125 135 * <p> … … 128 138 */ 129 139 private String currentEventType; 130 140 131 141 /** 132 142 * <p> … … 135 145 */ 136 146 private String currentGUIElementClass; 137 147 138 148 /** 139 149 * <p> … … 142 152 */ 143 153 private String currentGUIElementIndex; 144 145 /** 146 * Internal handle to the specification of the GUI element currently being parsed. 147 */ 148 private HTMLGUIElementSpec currentGUIElementSpec; 149 154 150 155 /** 151 156 * <p> … … 155 160 */ 156 161 private IGUIElement lastGUIElement; 157 162 163 /** 164 * <p> 165 * internal handle to the server specification currently being used. 166 * </p> 167 */ 168 private HTMLServerSpec currentServerSpec; 169 158 170 /** 159 171 * <p> … … 162 174 * 163 175 * @param filename 164 * name and path of the log file176 * name and path of the log file 165 177 */ 166 178 public void parseFile(String filename) { 167 if (filename == null) {179 if (filename == null) { 168 180 throw new IllegalArgumentException("filename must not be null"); 169 181 } 170 182 171 183 parseFile(new File(filename)); 172 184 } 185 173 186 /** 174 187 * <p> 175 188 * Parses a log file written by the HTMLMonitor and creates a collection of event sequences. 176 189 * </p> 190 * 177 191 * @param file 178 * file to be parsed192 * file to be parsed 179 193 */ 180 194 public void parseFile(File file) { 181 if (file == null) {195 if (file == null) { 182 196 throw new IllegalArgumentException("file must not be null"); 183 197 } … … 186 200 SAXParser saxParser = null; 187 201 InputSource inputSource = null; 188 try {202 try { 189 203 saxParser = spf.newSAXParser(); 190 204 inputSource = 191 192 } 193 catch (UnsupportedEncodingException e) {205 new InputSource(new InputStreamReader(new FileInputStream(file), "UTF-8")); 206 } 207 catch (UnsupportedEncodingException e) { 194 208 Console.printerr("Error parsing file " + file.getName()); 195 209 Console.logException(e); 196 210 return; 197 211 } 198 catch (ParserConfigurationException e) {212 catch (ParserConfigurationException e) { 199 213 Console.printerr("Error parsing file " + file.getName()); 200 214 Console.logException(e); 201 215 return; 202 216 } 203 catch (SAXException e) {217 catch (SAXException e) { 204 218 Console.printerr("Error parsing file " + file.getName()); 205 219 Console.logException(e); 206 220 } 207 catch (FileNotFoundException e) {221 catch (FileNotFoundException e) { 208 222 Console.printerr("Error parsing file " + file.getName()); 209 223 Console.logException(e); 210 224 } 211 if (inputSource != null){ 212 inputSource.setSystemId("file://" + file.getAbsolutePath()); 213 try{ 214 if (saxParser == null){ 215 throw new RuntimeException("SaxParser creation failed"); 216 } 217 saxParser.parse(inputSource, this); 218 } 219 catch (SAXParseException e){ 220 Console.printerrln("Failure parsing file in line " + e.getLineNumber() + 221 ", column " + e.getColumnNumber() + "."); 222 Console.logException(e); 223 } 224 catch (SAXException e){ 225 Console.printerr("Error parsing file " + file.getName()); 226 Console.logException(e); 227 return; 228 } 229 catch (IOException e){ 230 Console.printerr("Error parsing file " + file.getName()); 231 Console.logException(e); 232 return; 233 } 234 } 235 } 236 237 /* (non-Javadoc) 238 * @see org.xml.sax.helpers.DefaultHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes) 225 if (inputSource != null) { 226 inputSource.setSystemId("file://" + file.getAbsolutePath()); 227 try { 228 if (saxParser == null) { 229 throw new RuntimeException("SaxParser creation failed"); 230 } 231 saxParser.parse(inputSource, this); 232 } 233 catch (SAXParseException e) { 234 Console.printerrln("Failure parsing file in line " + e.getLineNumber() + 235 ", column " + e.getColumnNumber() + "."); 236 Console.logException(e); 237 } 238 catch (SAXException e) { 239 Console.printerr("Error parsing file " + file.getName()); 240 Console.logException(e); 241 return; 242 } 243 catch (IOException e) { 244 Console.printerr("Error parsing file " + file.getName()); 245 Console.logException(e); 246 return; 247 } 248 } 249 } 250 251 /* 252 * (non-Javadoc) 253 * 254 * @see org.xml.sax.helpers.DefaultHandler#startElement(java.lang.String, java.lang.String, 255 * java.lang.String, org.xml.sax.Attributes) 239 256 */ 240 257 @Override … … 243 260 { 244 261 if (qName.equals("session")) { 245 246 247 262 currentSequence = new LinkedList<Event>(); 263 if (currentGUIElementTree == null) 264 currentGUIElementTree = new GUIElementTree<String>(); 248 265 } 249 266 else if (qName.equals("component")) { 250 267 currentGUIElementPath = atts.getValue("path"); 268 currentGUIElementParameters = new HashMap<String, String>(); 251 269 } 252 270 else if (qName.equals("event")) { … … 254 272 currentEventParameters = new HashMap<String, String>(); 255 273 } 256 else if (qName.equals("param")) {274 else if (qName.equals("param")) { 257 275 String paramName = atts.getValue("name"); 258 if (currentGUIElementPath != null) {259 if ("parent".equals(paramName)) {276 if (currentGUIElementPath != null) { 277 if ("parent".equals(paramName)) { 260 278 currentParentPath = atts.getValue("value"); 261 279 } 262 if ("class".equals(paramName)) {280 if ("class".equals(paramName)) { 263 281 currentGUIElementClass = atts.getValue("value"); 264 282 } 265 if ("index".equals(paramName)) {283 if ("index".equals(paramName)) { 266 284 currentGUIElementIndex = atts.getValue("value"); 267 285 } 268 } 269 else if (currentEventType != null){ 270 if ("target".equals(paramName)){ 286 currentGUIElementParameters.put(paramName, atts.getValue("value")); 287 } 288 else if (currentEventType != null) { 289 if ("target".equals(paramName)) { 271 290 currentEventSource = atts.getValue("value"); 272 291 } 273 if ("timestamp".equals(paramName)) {292 if ("timestamp".equals(paramName)) { 274 293 currentEventTimestamp = Long.parseLong(atts.getValue("value")); 275 294 } 276 295 currentEventParameters.put(paramName, atts.getValue("value")); 277 296 } 278 else {297 else { 279 298 throw new SAXException("param tag found where it should not be."); 280 299 } 281 300 } 282 else {301 else { 283 302 throw new SAXException("unknown tag found: " + qName); 284 303 } … … 286 305 } 287 306 288 /* (non-Javadoc) 289 * @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String, java.lang.String, java.lang.String) 307 /* 308 * (non-Javadoc) 309 * 310 * @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String, java.lang.String, 311 * java.lang.String) 290 312 */ 291 313 @Override 292 314 public void endElement(String uri, String localName, String qName) throws SAXException { 293 315 if (qName.equals("session")) { 294 if (currentSequence != null && !currentSequence.isEmpty()) {316 if (currentSequence != null && !currentSequence.isEmpty()) { 295 317 sequences.add(currentSequence); 296 318 } … … 298 320 } 299 321 else if (qName.equals("component") && currentGUIElementPath != null) { 300 HTMLGUIElementSpec guiElementSpec = new HTMLGUIElementSpec(currentGUIElementClass); 322 HTMLGUIElementSpec guiElementSpec = 323 getGUIElementSpec(currentGUIElementClass, currentGUIElementParameters); 301 324 currentGUIElementTree.add(currentGUIElementPath, currentParentPath, guiElementSpec); 302 325 303 326 currentParentPath = null; 304 327 currentGUIElementPath = null; 328 currentGUIElementParameters = null; 305 329 } 306 330 else if (qName.equals("event")) { 307 331 IGUIElement currentGUIElement; 308 332 currentGUIElement = currentGUIElementTree.find(currentEventSource); 309 310 Event event = new Event(HTMLEventTypeFactory. 311 getInstance().getEventType(currentEventType, currentEventParameters), 312 (currentGUIElement == null ? lastGUIElement : currentGUIElement)); 313 333 334 IEventType eventType = 335 HTMLEventTypeFactory.getInstance().getEventType(currentEventType, 336 currentEventParameters, 337 currentGUIElement); 338 Event event = 339 new Event(eventType, (currentGUIElement == null ? lastGUIElement 340 : currentGUIElement)); 341 314 342 event.setTimestamp(currentEventTimestamp); 315 343 HTMLGUIElement currentEventTarget = (HTMLGUIElement) event.getTarget(); 316 344 currentEventTarget.markUsed(); 317 345 currentSequence.add(event); 318 346 319 347 currentEventSource = null; 320 348 currentEventTimestamp = -1l; 321 349 currentEventParameters = null; 322 350 currentEventType = null; 323 324 if (currentGUIElement != null) {351 352 if (currentGUIElement != null) { 325 353 lastGUIElement = currentGUIElement; 326 354 } 327 355 328 356 currentGUIElement = null; 329 357 } 330 358 } 331 359 332 360 /** 333 361 * <p> 334 362 * Returns a collection of event sequences that was obtained from parsing log files. 335 363 * </p> 364 * 336 365 * @return 337 366 */ 338 public Collection<List<Event>> getSequences() {367 public Collection<List<Event>> getSequences() { 339 368 return sequences; 340 369 } 341 370 342 371 /** 343 372 * <p> … … 347 376 * @return GUIModel 348 377 */ 349 public GUIModel getGuiModel() {378 public GUIModel getGuiModel() { 350 379 return currentGUIElementTree.getGUIModel(); 351 380 } 352 381 382 /** 383 * Returns the HTMLGUIElementSpecification for a GUI Element described 384 * by its class name and its parameters. 385 * @param guiElementClass 386 * @param guiElementParameters 387 * @return 388 */ 389 private HTMLGUIElementSpec getGUIElementSpec(String guiElementClass, 390 Map<String, String> guiElementParameters) 391 { 392 HTMLGUIElementSpec specification = null; 393 if ("server".equals(guiElementClass)) { 394 // TODO: add correct port handling 395 specification = new HTMLServerSpec(guiElementParameters.get("htmlId"), 0); 396 currentServerSpec = (HTMLServerSpec) specification; 397 } 398 399 else { 400 String id = guiElementParameters.get("htmlId"); 401 if (id == null) { 402 HTMLPageElementSpec parentSpec = 403 (HTMLPageElementSpec) currentGUIElementTree.find(currentParentPath) 404 .getSpecification(); 405 id = parentSpec.getPage().getPagePath(); 406 } 407 408 int index = -1; 409 String indexStr = guiElementParameters.get("index"); 410 411 if ((indexStr != null) && (!"".equals(indexStr))) { 412 index = Integer.parseInt(indexStr); 413 } 414 String title = guiElementParameters.get("title"); 415 HTMLPageSpec page = new HTMLPageSpec(currentServerSpec, id, title); 416 specification = new HTMLPageElementSpec(page, guiElementClass, id, index); 417 } 418 419 return specification; 420 } 353 421 } -
trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/eventcore/HTMLEventTypeFactory.java
r1054 r1059 24 24 import de.ugoe.cs.autoquest.eventcore.gui.MouseClick; 25 25 import de.ugoe.cs.autoquest.eventcore.gui.Scroll; 26 import de.ugoe.cs.autoquest.eventcore.gui.TextInput; 27 import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement; 28 import de.ugoe.cs.autoquest.eventcore.guimodel.ITextArea; 29 import de.ugoe.cs.autoquest.eventcore.guimodel.ITextField; 26 30 import de.ugoe.cs.util.console.Console; 27 31 … … 32 36 * 33 37 * @author Patrick Harms 38 * @author Fabian Glaser 34 39 */ 35 40 public class HTMLEventTypeFactory { … … 66 71 * @return 67 72 */ 68 public IEventType getEventType(String eventName, Map<String, String> eventParameters) { 73 public IEventType getEventType(String eventName, Map<String, String> eventParameters, 74 IGUIElement guiElement) { 69 75 IInteraction result = null; 70 76 … … 79 85 } 80 86 else if ("onchange".equals(eventName)) { 81 // TODO: Implement "onchange" event handling 82 Console.traceln(Level.FINE, "Unhandled event of type \"" + eventName + "\""); 87 String value = eventParameters.get("selectedValue"); 88 89 if ((guiElement instanceof ITextArea) || (guiElement instanceof ITextField)) { 90 result = new TextInput(value, null); 91 } 92 else { 93 throw new IllegalArgumentException("can not handle onchange events on GUI " + 94 "elements of type " + guiElement.getClass()); 95 } 83 96 } 84 97 else if ("onfocus".equals(eventName)) { … … 125 138 } 126 139 } 140 141 142 127 143 } -
trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/guimodel/HTMLPageElementSpec.java
r961 r1059 106 106 * @return 107 107 */ 108 HTMLPageSpec getPage() {108 public HTMLPageSpec getPage() { 109 109 return page; 110 110 } -
trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/guimodel/HTMLPageSpec.java
r961 r1059 58 58 throw new IllegalArgumentException("pagePath must not be null"); 59 59 } 60 else if (pageTitle == null) {61 throw new IllegalArgumentException("pageTitle must not be null");62 }60 // else if (pageTitle == null) { 61 // throw new IllegalArgumentException("pageTitle must not be null"); 62 // } 63 63 64 64 this.server = server; … … 134 134 * @return 135 135 */ 136 String getPagePath() {136 public String getPagePath() { 137 137 return pagePath; 138 138 } -
trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/guimodel/HTMLServerSpec.java
r961 r1059 45 45 * @param port 46 46 */ 47 HTMLServerSpec(String host, int port) {47 public HTMLServerSpec(String host, int port) { 48 48 super("server"); 49 49 … … 67 67 * @param pageURL 68 68 */ 69 HTMLServerSpec(URL pageURL) {69 public HTMLServerSpec(URL pageURL) { 70 70 super("server"); 71 71
Note: See TracChangeset
for help on using the changeset viewer.