Changeset 1339


Ignore:
Timestamp:
01/28/14 16:08:11 (10 years ago)
Author:
pharms
Message:
  • added support for parameterizing the parsing of GUI models to ignore ids or indexes
Location:
trunk/autoquest-plugin-html
Files:
4 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/autoquest-plugin-html/.classpath

    r950 r1339  
    1313                </attributes> 
    1414        </classpathentry> 
     15        <classpathentry kind="src" path="src/main/resources"/> 
    1516        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"> 
    1617                <attributes> 
  • trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/HTMLLogParser.java

    r1272 r1339  
    1515package de.ugoe.cs.autoquest.plugin.html; 
    1616 
     17import java.util.Arrays; 
    1718import java.util.List; 
    1819import java.util.Map; 
     
    3132import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLGUIElement; 
    3233import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLGUIElementSpec; 
     34import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLPageElement; 
    3335import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLPageElementSpec; 
    3436import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLServerSpec; 
     
    5355    private Pattern htmlElementPattern = 
    5456        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    } 
    5589 
    5690    /* (non-Javadoc) 
     
    6498         
    6599        String parentId = parameters.get("parent"); 
    66         IGUIElement parent = super.getGUIElementTree().find(parentId); 
     100        HTMLGUIElement parent = (HTMLGUIElement) super.getGUIElementTree().find(parentId); 
    67101 
    68102        if (parameters.containsKey("host")) { 
     
    122156                    index = Integer.parseInt(indexStr); 
    123157                } 
     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                } 
    124173 
    125174                specification = new HTMLPageElementSpec 
    126                     ((HTMLDocumentSpec) document.getSpecification(), tagName, 
    127                      parameters.get("htmlid"), index); 
     175                    ((HTMLDocumentSpec) document.getSpecification(), tagName, htmlId, index); 
    128176                 
    129177            } 
     
    151199    } 
    152200 
     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 
    153336    /* (non-Javadoc) 
    154337     * @see de.ugoe.cs.autoquest.plugin.html.AbstractDefaultLogParser#handleEvent(String, Map) 
     
    159342         
    160343        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             
    161349            String targetDocument = parameters.get("targetDocument"); 
    162350            String targetDOMPath = parameters.get("targetDOMPath"); 
  • trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/commands/CMDcorrectHTMLLogDirs.java

    r1272 r1339  
    1717import java.io.File; 
    1818import java.util.Arrays; 
     19import java.util.HashMap; 
    1920import java.util.List; 
    2021import java.util.logging.Level; 
     
    9091            String serverName = null; 
    9192             
    92             HTMLLogParser parser = new HTMLLogParser(); 
     93            HTMLLogParser parser = new HTMLLogParser(new HashMap<String, List<String>>()); 
    9394            try { 
    9495                parser.parseFile(file); 
  • trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/commands/CMDparseDirHTML.java

    r1220 r1339  
    1818import java.util.Arrays; 
    1919import java.util.Collection; 
     20import java.util.HashMap; 
     21import java.util.LinkedList; 
    2022import java.util.List; 
     23import java.util.Map; 
    2124import java.util.logging.Level; 
     25import java.util.regex.Matcher; 
     26import java.util.regex.Pattern; 
    2227 
    2328import de.ugoe.cs.autoquest.CommandHelpers; 
     
    4853    @Override 
    4954    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>>(); 
    5258 
    5359        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                } 
    5791            } 
    5892        } 
    5993        catch (Exception e) { 
    6094            throw new IllegalArgumentException("illegal parameters provided: " + e); 
     95        } 
     96         
     97        if (sequencesName == null) { 
     98            sequencesName = "sequences"; 
    6199        } 
    62100 
     
    67105        } 
    68106 
    69         HTMLLogParser parser = new HTMLLogParser(); 
     107        HTMLLogParser parser = new HTMLLogParser(parseParams); 
    70108 
    71109        parseFile(folder, parser); 
     
    123161    @Override 
    124162    public String help() { 
    125         return "parseDirHTML <directory> {<sequencesName>}"; 
     163        return "parseDirHTML <directory> {<sequencesName>} {<clearId>} {<clearIndex>}"; 
    126164    } 
    127165 
  • trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/commands/CMDparseHTML.java

    r1179 r1339  
    1616 
    1717import java.util.Collection; 
     18import java.util.HashMap; 
     19import java.util.LinkedList; 
    1820import java.util.List; 
     21import java.util.Map; 
     22import java.util.regex.Matcher; 
     23import java.util.regex.Pattern; 
    1924 
    2025import de.ugoe.cs.autoquest.CommandHelpers; 
     
    4348    @Override 
    4449    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>>(); 
    4753 
    4854        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                } 
    5286            } 
    5387        } 
    5488        catch (Exception e) { 
    55             throw new IllegalArgumentException(); 
     89            throw new IllegalArgumentException("illegal parameters provided: " + e); 
    5690        } 
    5791 
    58         HTMLLogParser parser = new HTMLLogParser(); 
     92        if (sequencesName == null) { 
     93            sequencesName = "sequences"; 
     94        } 
     95 
     96        HTMLLogParser parser = new HTMLLogParser(parseParams); 
    5997 
    6098        try { 
Note: See TracChangeset for help on using the changeset viewer.