Changeset 1339 for trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/HTMLLogParser.java
- Timestamp:
- 01/28/14 16:08:11 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/HTMLLogParser.java
r1272 r1339 15 15 package de.ugoe.cs.autoquest.plugin.html; 16 16 17 import java.util.Arrays; 17 18 import java.util.List; 18 19 import java.util.Map; … … 31 32 import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLGUIElement; 32 33 import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLGUIElementSpec; 34 import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLPageElement; 33 35 import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLPageElementSpec; 34 36 import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLServerSpec; … … 53 55 private Pattern htmlElementPattern = 54 56 Pattern.compile("(\\w+)(\\[(\\d+)\\]|\\(htmlId=([\\w-]+)\\))"); 57 58 /** 59 * <p> 60 * the pattern used for parsing parsing parameters 61 * </p> 62 */ 63 private Pattern htmlElementSpecPattern = 64 Pattern.compile("(\\w+)(\\[(\\d+)\\]|\\(htmlId=([\\w-]+)\\))?"); 65 66 /** 67 * <p> 68 * parameters to influence parsing 69 * </p> 70 */ 71 private Map<String, List<String>> parseParams; 72 73 /** 74 * <p> 75 * TODO: comment 76 * </p> 77 * 78 * @param parseParams 79 */ 80 public HTMLLogParser(Map<String, List<String>> parseParams) { 81 this.parseParams = parseParams; 82 83 for (String paramKey : parseParams.keySet()) { 84 if (!"clearId".equals(paramKey) && !"clearIndex".equals(paramKey)) { 85 throw new IllegalArgumentException("unknown parse parameter key " + paramKey); 86 } 87 } 88 } 55 89 56 90 /* (non-Javadoc) … … 64 98 65 99 String parentId = parameters.get("parent"); 66 IGUIElement parent =super.getGUIElementTree().find(parentId);100 HTMLGUIElement parent = (HTMLGUIElement) super.getGUIElementTree().find(parentId); 67 101 68 102 if (parameters.containsKey("host")) { … … 122 156 index = Integer.parseInt(indexStr); 123 157 } 158 159 String htmlId = parameters.get("htmlid"); 160 161 if (clearIndex(tagName, index, htmlId, parent)) { 162 index = -1; 163 } 164 165 if (clearHTMLId(tagName, index, htmlId, parent)) { 166 htmlId = null; 167 } 168 169 if ((htmlId == null) && (index == -1)) { 170 // set at least a default index, if all is to be ignored. 171 index = 0; 172 } 124 173 125 174 specification = new HTMLPageElementSpec 126 ((HTMLDocumentSpec) document.getSpecification(), tagName, 127 parameters.get("htmlid"), index); 175 ((HTMLDocumentSpec) document.getSpecification(), tagName, htmlId, index); 128 176 129 177 } … … 151 199 } 152 200 201 /** 202 * <p> 203 * TODO: comment 204 * </p> 205 * 206 * @param tagName 207 * @param parent 208 * @return 209 */ 210 private boolean clearIndex(String tagName, int index, String id, HTMLGUIElement parent) { 211 return clearSomething("clearIndex", tagName, index, id, parent); 212 } 213 214 /** 215 * <p> 216 * TODO: comment 217 * </p> 218 * 219 * @param tagName 220 * @param parent 221 * @return 222 */ 223 private boolean clearHTMLId(String tagName, int index, String id, HTMLGUIElement parent) { 224 return clearSomething("clearId", tagName, index, id, parent); 225 } 226 227 /** 228 * <p> 229 * TODO: comment 230 * </p> 231 * 232 * @param tagName 233 * @param parent 234 * @return 235 */ 236 private boolean clearSomething(String parseParamId, 237 String tagName, 238 int index, 239 String id, 240 HTMLGUIElement parent) 241 { 242 if (parseParams.containsKey(parseParamId)) { 243 for (String spec : parseParams.get(parseParamId)) { 244 // determine the specification parts 245 if (spec.startsWith("/")) { 246 throw new IllegalArgumentException("can not handle absolute specifications"); 247 } 248 else if (spec.endsWith("/")) { 249 throw new IllegalArgumentException("specifications may not end with a /"); 250 } 251 252 String[] tagSpecs = spec.split("/"); 253 254 if (tagMatchesTagSpec(tagName, index, id, parent, tagSpecs)) { 255 return true; 256 } 257 } 258 } 259 260 return false; 261 } 262 263 /** 264 * <p> 265 * TODO: comment 266 * </p> 267 * 268 * @param tagName 269 * @param parent 270 * @param spec 271 * @return 272 */ 273 private boolean tagMatchesTagSpec(String tagName, 274 int index, 275 String id, 276 HTMLGUIElement parent, 277 String[] tagSpecs) 278 { 279 280 if (tagSpecs.length > 0) { 281 Matcher matcher = htmlElementSpecPattern.matcher(tagSpecs[tagSpecs.length - 1]); 282 283 if (!matcher.matches()) { 284 throw new IllegalArgumentException 285 ("illegal tag specification " + tagSpecs[tagSpecs.length - 1]); 286 } 287 288 if (!tagName.equals(matcher.group(1))) { 289 return false; 290 } 291 292 String idCondition = matcher.group(4); 293 294 if (idCondition != null) { 295 if (!idCondition.equals(id)) { 296 return false; 297 } 298 } 299 300 String indexCondition = matcher.group(3); 301 302 if (indexCondition != null) { 303 try { 304 if (index != Integer.parseInt(indexCondition)) { 305 return false; 306 } 307 } 308 catch (NumberFormatException e) { 309 throw new IllegalArgumentException 310 ("illegal tag index specification " + indexCondition, e); 311 } 312 } 313 314 if (tagSpecs.length > 1) { 315 if (parent instanceof HTMLPageElement) { 316 return tagMatchesTagSpec(((HTMLPageElement) parent).getTagName(), 317 ((HTMLPageElement) parent).getIndex(), 318 ((HTMLPageElement) parent).getHtmlId(), 319 (HTMLGUIElement) parent.getParent(), 320 Arrays.copyOfRange(tagSpecs, 0, tagSpecs.length - 1)); 321 } 322 else { 323 throw new IllegalArgumentException 324 ("specification matches documents or servers. This is not supported yet."); 325 } 326 } 327 else { 328 return true; 329 } 330 } 331 else { 332 return true; 333 } 334 } 335 153 336 /* (non-Javadoc) 154 337 * @see de.ugoe.cs.autoquest.plugin.html.AbstractDefaultLogParser#handleEvent(String, Map) … … 159 342 160 343 if (targetId == null) { 344 if (parseParams.size() != 0) { 345 throw new SAXException 346 ("old log file versions can not be parsed with parse parameters"); 347 } 348 161 349 String targetDocument = parameters.get("targetDocument"); 162 350 String targetDOMPath = parameters.get("targetDOMPath");
Note: See TracChangeset
for help on using the changeset viewer.