Changeset 1339
- Timestamp:
- 01/28/14 16:08:11 (11 years ago)
- Location:
- trunk/autoquest-plugin-html
- Files:
-
- 4 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-plugin-html/.classpath
r950 r1339 13 13 </attributes> 14 14 </classpathentry> 15 <classpathentry kind="src" path="src/main/resources"/> 15 16 <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"> 16 17 <attributes> -
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"); -
trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/commands/CMDcorrectHTMLLogDirs.java
r1272 r1339 17 17 import java.io.File; 18 18 import java.util.Arrays; 19 import java.util.HashMap; 19 20 import java.util.List; 20 21 import java.util.logging.Level; … … 90 91 String serverName = null; 91 92 92 HTMLLogParser parser = new HTMLLogParser( );93 HTMLLogParser parser = new HTMLLogParser(new HashMap<String, List<String>>()); 93 94 try { 94 95 parser.parseFile(file); -
trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/commands/CMDparseDirHTML.java
r1220 r1339 18 18 import java.util.Arrays; 19 19 import java.util.Collection; 20 import java.util.HashMap; 21 import java.util.LinkedList; 20 22 import java.util.List; 23 import java.util.Map; 21 24 import java.util.logging.Level; 25 import java.util.regex.Matcher; 26 import java.util.regex.Pattern; 22 27 23 28 import de.ugoe.cs.autoquest.CommandHelpers; … … 48 53 @Override 49 54 public void run(List<Object> parameters) { 50 String path; 51 String sequencesName = "sequences"; 55 String path = null; 56 String sequencesName = null; 57 Map<String, List<String>> parseParams = new HashMap<String, List<String>>(); 52 58 53 59 try { 54 path = (String) parameters.get(0); 55 if (parameters.size() >= 2) { 56 sequencesName = (String) parameters.get(1); 60 for (int i = 0; i < parameters.size(); i++) { 61 String param = (String) parameters.get(i); 62 if (!param.startsWith("-")) { 63 if (path == null) { 64 path = param; 65 } 66 else if (sequencesName == null) { 67 sequencesName = param; 68 } 69 } 70 else { 71 Pattern parseParamPattern = Pattern.compile("-(\\w*)=([\\w=\\[\\]\\(\\)/]*)"); 72 Matcher matcher = parseParamPattern.matcher(param); 73 74 if (matcher.matches()) { 75 String key = matcher.group(1); 76 List<String> values = parseParams.get(key); 77 78 if (values == null) { 79 values = new LinkedList<String>(); 80 parseParams.put(key, values); 81 } 82 83 values.add(matcher.group(2)); 84 } 85 else { 86 String message = "parse parameter does not follow format: -<key>=<value>"; 87 Console.printerrln(message); 88 throw new IllegalArgumentException(message); 89 } 90 } 57 91 } 58 92 } 59 93 catch (Exception e) { 60 94 throw new IllegalArgumentException("illegal parameters provided: " + e); 95 } 96 97 if (sequencesName == null) { 98 sequencesName = "sequences"; 61 99 } 62 100 … … 67 105 } 68 106 69 HTMLLogParser parser = new HTMLLogParser( );107 HTMLLogParser parser = new HTMLLogParser(parseParams); 70 108 71 109 parseFile(folder, parser); … … 123 161 @Override 124 162 public String help() { 125 return "parseDirHTML <directory> {<sequencesName>} ";163 return "parseDirHTML <directory> {<sequencesName>} {<clearId>} {<clearIndex>}"; 126 164 } 127 165 -
trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/commands/CMDparseHTML.java
r1179 r1339 16 16 17 17 import java.util.Collection; 18 import java.util.HashMap; 19 import java.util.LinkedList; 18 20 import java.util.List; 21 import java.util.Map; 22 import java.util.regex.Matcher; 23 import java.util.regex.Pattern; 19 24 20 25 import de.ugoe.cs.autoquest.CommandHelpers; … … 43 48 @Override 44 49 public void run(List<Object> parameters) { 45 String filename; 46 String sequencesName = "sequences"; 50 String filename = null; 51 String sequencesName = null; 52 Map<String, List<String>> parseParams = new HashMap<String, List<String>>(); 47 53 48 54 try { 49 filename = (String) parameters.get(0); 50 if (parameters.size() >= 2) { 51 sequencesName = (String) parameters.get(1); 55 for (int i = 0; i < parameters.size(); i++) { 56 String param = (String) parameters.get(i); 57 if (!param.startsWith("-")) { 58 if (filename == null) { 59 filename = param; 60 } 61 else if (sequencesName == null) { 62 sequencesName = param; 63 } 64 } 65 else { 66 Pattern parseParamPattern = Pattern.compile("-(\\w*)=([\\w=\\[\\]\\(\\)/]*)"); 67 Matcher matcher = parseParamPattern.matcher(param); 68 69 if (matcher.matches()) { 70 String key = matcher.group(1); 71 List<String> values = parseParams.get(key); 72 73 if (values == null) { 74 values = new LinkedList<String>(); 75 parseParams.put(key, values); 76 } 77 78 values.add(matcher.group(2)); 79 } 80 else { 81 String message = "parse parameter does not follow format: -<key>=<value>"; 82 Console.printerrln(message); 83 throw new IllegalArgumentException(message); 84 } 85 } 52 86 } 53 87 } 54 88 catch (Exception e) { 55 throw new IllegalArgumentException( );89 throw new IllegalArgumentException("illegal parameters provided: " + e); 56 90 } 57 91 58 HTMLLogParser parser = new HTMLLogParser(); 92 if (sequencesName == null) { 93 sequencesName = "sequences"; 94 } 95 96 HTMLLogParser parser = new HTMLLogParser(parseParams); 59 97 60 98 try {
Note: See TracChangeset
for help on using the changeset viewer.