Ignore:
Timestamp:
02/14/13 15:20:07 (11 years ago)
Author:
pharms
Message:
  • support of new HTML logging format
Location:
trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html
Files:
1 added
2 deleted
5 edited
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/HTMLLogParser.java

    r1064 r1069  
    1515package de.ugoe.cs.autoquest.plugin.html; 
    1616 
    17 import java.io.File; 
    18 import java.io.FileInputStream; 
    19 import java.io.FileNotFoundException; 
    20 import java.io.IOException; 
    21 import java.io.InputStreamReader; 
    22 import java.io.UnsupportedEncodingException; 
    23 import java.util.Collection; 
    24 import java.util.HashMap; 
    25 import java.util.LinkedList; 
    2617import java.util.List; 
    2718import java.util.Map; 
    28  
    29 import javax.xml.parsers.ParserConfigurationException; 
    30 import javax.xml.parsers.SAXParser; 
    31 import javax.xml.parsers.SAXParserFactory; 
    32  
    33 import org.xml.sax.Attributes; 
    34 import org.xml.sax.InputSource; 
     19import java.util.regex.Matcher; 
     20import java.util.regex.Pattern; 
     21 
    3522import org.xml.sax.SAXException; 
    36 import org.xml.sax.SAXParseException; 
    37 import org.xml.sax.helpers.DefaultHandler; 
    3823 
    3924import de.ugoe.cs.autoquest.eventcore.Event; 
    4025import de.ugoe.cs.autoquest.eventcore.IEventType; 
    41 import de.ugoe.cs.autoquest.eventcore.guimodel.GUIElementTree; 
    4226import de.ugoe.cs.autoquest.eventcore.guimodel.GUIModel; 
    4327import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement; 
    4428import de.ugoe.cs.autoquest.plugin.html.eventcore.HTMLEventTypeFactory; 
     29import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLDocumentSpec; 
    4530import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLGUIElement; 
    4631import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLGUIElementSpec; 
    4732import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLPageElementSpec; 
    48 import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLPageSpec; 
    4933import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLServerSpec; 
    50 import de.ugoe.cs.util.console.Console; 
    5134 
    5235/** 
    5336 * <p> 
    5437 * This class provides the functionality to parse XML log files generated by the HTMLMonitor of 
    55  * autoquest. The result of parsing a file is a collection of event sequences. 
     38 * AutoQUEST. The result of parsing a file is a collection of event sequences and a GUI model 
    5639 * </p> 
    5740 *  
    58  * @author Fabian Glaser 
     41 * @author Fabian Glaser, Patrick Harms 
    5942 * @version 1.0 
    6043 *  
    6144 */ 
    62 public class HTMLLogParser extends DefaultHandler { 
     45public class HTMLLogParser extends AbstractDefaultLogParser { 
     46     
     47    /** 
     48     * 
     49     */ 
     50    private Pattern htmlElementPattern = 
     51        Pattern.compile("(\\w+)(\\[(\\d+)\\]|\\(htmlId=([\\w-]+)\\))"); 
     52 
     53    /* (non-Javadoc) 
     54     * @see de.ugoe.cs.autoquest.plugin.html.AbstractDefaultLogParser#handleGUIElement(java.lang.String, java.util.Map) 
     55     */ 
     56    @Override 
     57    protected boolean handleGUIElement(String id, Map<String, String> parameters) 
     58        throws SAXException 
     59    { 
     60        HTMLGUIElementSpec specification = null; 
     61         
     62        String parentId = parameters.get("parent"); 
     63        IGUIElement parent = super.getGUIElementTree().find(parentId); 
     64 
     65        if (parameters.containsKey("host")) { 
     66            // this is a server specification 
     67            int port = 80; 
     68            String portStr = parameters.get(port); 
     69             
     70            if (portStr != null) { 
     71                port = Integer.parseInt(portStr); 
     72            } 
     73             
     74            specification = new HTMLServerSpec(parameters.get("host"), port); 
     75        } 
     76        else if (parameters.containsKey("path")) { 
     77            // this is a document specification 
     78             
     79            if (parent != null) { 
     80                if (!(parent.getSpecification() instanceof HTMLServerSpec)) { 
     81                    throw new SAXException 
     82                        ("invalid log: parent GUI element of a document is not of type server"); 
     83                } 
     84                 
     85                specification = new HTMLDocumentSpec 
     86                    ((HTMLServerSpec) parent.getSpecification(), parameters.get("path"), 
     87                     parameters.get("query"), parameters.get("title")); 
     88            } 
     89            else if (parentId == null) { 
     90                throw new SAXException("invalid log: a document has no parent id"); 
     91            } 
     92        } 
     93        else if (parameters.containsKey("tagname")) { 
     94            String tagName = parameters.get("tagname"); 
     95             
     96            if (!tagNameMustBeConsidered(tagName)) { 
     97                return true; 
     98            } 
     99 
     100            if (parent != null) { 
     101                IGUIElement document = parent; 
     102                 
     103                while ((document != null) && 
     104                       (!(document.getSpecification() instanceof HTMLDocumentSpec))) 
     105                { 
     106                    document = document.getParent(); 
     107                } 
     108                 
     109                if (document == null) { 
     110                    throw new SAXException 
     111                        ("invalid log: parent hierarchy of a page element does not contain a " + 
     112                         "document"); 
     113                } 
     114                 
     115                int index = -1; 
     116                String indexStr = parameters.get("index"); 
     117 
     118                if ((indexStr != null) && (!"".equals(indexStr))) { 
     119                    index = Integer.parseInt(indexStr); 
     120                } 
     121 
     122                specification = new HTMLPageElementSpec 
     123                    ((HTMLDocumentSpec) document.getSpecification(), tagName, 
     124                     parameters.get("htmlid"), index); 
     125            } 
     126            else if (parentId == null) { 
     127                throw new SAXException("invalid log: a page element has no parent id"); 
     128            } 
     129        } 
     130        else { 
     131            throw new SAXException("invalid log: unknown GUI element"); 
     132        } 
     133 
     134        if (specification != null) { 
     135            super.getGUIElementTree().add(id, parentId, specification); 
     136            return true; 
     137        } 
     138        else { 
     139            return false; 
     140        } 
     141    } 
     142 
     143    /* (non-Javadoc) 
     144     * @see de.ugoe.cs.autoquest.plugin.html.AbstractDefaultLogParser#handleEvent(java.lang.String, java.util.Map) 
     145     */ 
     146    @Override 
     147    protected boolean handleEvent(String type, Map<String, String> parameters) throws SAXException { 
     148        String targetId = parameters.get("target"); 
     149         
     150        if (targetId == null) { 
     151            String targetDocument = parameters.get("targetDocument"); 
     152            String targetDOMPath = parameters.get("targetDOMPath"); 
     153             
     154            if ((targetDocument == null) || (targetDOMPath == null)) { 
     155                throw new SAXException("event has no target defined"); 
     156            } 
     157             
     158            targetId = determineTargetId(targetDocument, targetDOMPath); 
     159             
     160            if (targetId == null) { 
     161                // the target id can not be determined yet 
     162                return false; 
     163            } 
     164        } 
     165         
     166        IGUIElement target = super.getGUIElementTree().find(targetId); 
     167         
     168        if (target == null) { 
     169            // event not processable yet 
     170            return false; 
     171        } 
     172 
     173        IEventType eventType = 
     174            HTMLEventTypeFactory.getInstance().getEventType(type, parameters, target); 
     175         
     176        Event event = new Event(eventType, target); 
     177 
     178        String timestampStr = parameters.get("timestamp"); 
     179         
     180        if (timestampStr != null) { 
     181            event.setTimestamp(Long.parseLong(timestampStr)); 
     182        } 
     183 
     184        ((HTMLGUIElement) event.getTarget()).markUsed(); 
     185         
     186        super.addToSequence(event); 
     187 
     188        return true; 
     189    } 
     190 
    63191    /** 
    64192     * <p> 
    65      * Constructor. Creates a new HTMLLogParser. 
     193     * TODO: comment 
    66194     * </p> 
    67      */ 
    68     public HTMLLogParser() { 
    69         sequences = new LinkedList<List<Event>>(); 
     195     * 
     196     * @param targetDocument 
     197     * @param targetDOMPath 
     198     * @return 
     199     */ 
     200    private String determineTargetId(String targetDocument, String targetDOMPath) 
     201        throws SAXException 
     202    { 
     203        IGUIElement document = super.getGUIElementTree().find(targetDocument); 
     204         
     205        if (document == null) { 
     206            return null; 
     207        } 
     208         
     209        if (!(document.getSpecification() instanceof HTMLDocumentSpec)) { 
     210            throw new SAXException("an id that should refer to an HTML document refers to" + 
     211                                   "something else"); 
     212        } 
     213         
     214        GUIModel model = super.getGUIElementTree().getGUIModel(); 
     215        IGUIElement child = document; 
     216        String[] pathElements = targetDOMPath.split("/"); 
     217        int pathIndex = 0; 
     218         
     219        HTMLPageElementSpec compareSpec; 
     220        String tagName; 
     221        int index; 
     222        String htmlId; 
     223         
     224        while ((pathIndex < pathElements.length) && (child != null)) { 
     225            if ((pathElements[pathIndex] != null) && (!"".equals(pathElements[pathIndex]))) {            
     226                Matcher matcher = htmlElementPattern.matcher(pathElements[pathIndex]); 
     227                if (!matcher.matches()) { 
     228                    throw new SAXException 
     229                        ("could not parse target DOM path element " + pathElements[pathIndex]); 
     230                } 
     231 
     232                tagName = matcher.group(1); 
     233                String indexStr = matcher.group(3); 
     234                htmlId = matcher.group(4); 
     235 
     236                index = -1; 
     237                if ((indexStr != null) && (!"".equals(indexStr))) { 
     238                    index = Integer.parseInt(indexStr); 
     239                } 
     240 
     241                compareSpec = new HTMLPageElementSpec 
     242                    ((HTMLDocumentSpec) document.getSpecification(), tagName, htmlId, index); 
     243 
     244                List<IGUIElement> children = model.getChildren(child); 
     245                child = null; 
     246 
     247                for (IGUIElement candidate : children) { 
     248                    if (compareSpec.getSimilarity(candidate.getSpecification())) { 
     249                        child = candidate; 
     250                        break; 
     251                    } 
     252                } 
     253            } 
     254             
     255            pathIndex++; 
     256        } 
     257         
     258        if (child != null) { 
     259            return super.getGUIElementTree().find(child); 
     260        } 
     261        else { 
     262            return null; 
     263        } 
    70264    } 
    71265 
    72266    /** 
    73267     * <p> 
    74      * Collection of event sequences that is contained in the parsed log file. 
     268     * checks if tags with the provided name must be handled in the GUI model. As an example, 
     269     * it is not necessary to handle "head" tags and anything included in them.  
    75270     * </p> 
    76      */ 
    77     private Collection<List<Event>> sequences; 
    78  
    79     /** 
    80      * <p> 
    81      * Internal handle to the parsed GUI structure, stored in a GUIElementTree 
    82      * </p> 
    83      */ 
    84     private GUIElementTree<String> currentGUIElementTree; 
    85  
    86     /** 
    87      * <p> 
    88      * Path of the GUI element currently being parsed. 
    89      * </p> 
    90      */ 
    91     private String currentGUIElementPath; 
    92  
    93     /** 
    94      * <p> 
    95      * Path of the parent of the GUI element currently being parsed. 
    96      * </p> 
    97      */ 
    98     private String currentParentPath; 
    99  
    100     /** 
    101      * <p> 
    102      * Source of the GUI element currently being parsed. 
    103      * </p> 
    104      */ 
    105     private String currentEventSource; 
    106  
    107     /** 
    108      * <p> 
    109      * Timestamp of the event currently being parsed. 
    110      * </p> 
    111      */ 
    112     private Long currentEventTimestamp; 
    113  
    114     /** 
    115      * <p> 
    116      * Internal handle to the parameters of the event currently being parsed. 
    117      * </p> 
    118      */ 
    119     private Map<String, String> currentEventParameters; 
    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; 
    127     /** 
    128      * <p> 
    129      * Internal handle to the sequence currently being parsed. 
    130      * </p> 
    131      */ 
    132     private List<Event> currentSequence; 
    133  
    134     /** 
    135      * <p> 
    136      * Internal handle to type of the event currently being parsed. 
    137      * </p> 
    138      */ 
    139     private String currentEventType; 
    140  
    141     /** 
    142      * <p> 
    143      * Class of the GUI element currently being parsed. 
    144      * </p> 
    145      */ 
    146     private String currentGUIElementClass; 
    147  
    148     /** 
    149      * <p> 
    150      * Index of the GUI element currently being parsed. 
    151      * </p> 
    152      */ 
    153     private String currentGUIElementIndex; 
    154  
    155     /** 
    156      * <p> 
    157      * internal handle to the GUI element of the previous event to be potentially reused for the 
    158      * current 
    159      * </p> 
    160      */ 
    161     private IGUIElement lastGUIElement; 
    162  
    163     /** 
    164      * <p> 
    165      * internal handle to the server specification currently being used. 
    166      * </p> 
    167      */ 
    168     private HTMLServerSpec currentServerSpec; 
    169  
    170     /** 
    171      * <p> 
    172      * Parses a log file written by the HTMLMonitor and creates a collection of event sequences. 
    173      * </p> 
    174      *  
    175      * @param filename 
    176      *            name and path of the log file 
    177      */ 
    178     public void parseFile(String filename) { 
    179         if (filename == null) { 
    180             throw new IllegalArgumentException("filename must not be null"); 
    181         } 
    182  
    183         parseFile(new File(filename)); 
    184     } 
    185  
    186     /** 
    187      * <p> 
    188      * Parses a log file written by the HTMLMonitor and creates a collection of event sequences. 
    189      * </p> 
    190      *  
    191      * @param file 
    192      *            file to be parsed 
    193      */ 
    194     public void parseFile(File file) { 
    195         if (file == null) { 
    196             throw new IllegalArgumentException("file must not be null"); 
    197         } 
    198         SAXParserFactory spf = SAXParserFactory.newInstance(); 
    199         spf.setValidating(true); 
    200         SAXParser saxParser = null; 
    201         InputSource inputSource = null; 
    202         try { 
    203             saxParser = spf.newSAXParser(); 
    204             inputSource = 
    205                 new InputSource(new InputStreamReader(new FileInputStream(file), "UTF-8")); 
    206         } 
    207         catch (UnsupportedEncodingException e) { 
    208             Console.printerr("Error parsing file " + file.getName()); 
    209             Console.logException(e); 
    210             return; 
    211         } 
    212         catch (ParserConfigurationException e) { 
    213             Console.printerr("Error parsing file " + file.getName()); 
    214             Console.logException(e); 
    215             return; 
    216         } 
    217         catch (SAXException e) { 
    218             Console.printerr("Error parsing file " + file.getName()); 
    219             Console.logException(e); 
    220         } 
    221         catch (FileNotFoundException e) { 
    222             Console.printerr("Error parsing file " + file.getName()); 
    223             Console.logException(e); 
    224         } 
    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) 
    256      */ 
    257     @Override 
    258     public void startElement(String uri, String localName, String qName, Attributes atts) 
    259         throws SAXException 
    260     { 
    261         if (qName.equals("session")) { 
    262             currentSequence = new LinkedList<Event>(); 
    263             if (currentGUIElementTree == null) 
    264                 currentGUIElementTree = new GUIElementTree<String>(); 
    265         } 
    266         else if (qName.equals("component")) { 
    267             currentGUIElementPath = atts.getValue("path"); 
    268             currentGUIElementParameters = new HashMap<String, String>(); 
    269         } 
    270         else if (qName.equals("event")) { 
    271             currentEventType = atts.getValue("type"); 
    272             currentEventParameters = new HashMap<String, String>(); 
    273         } 
    274         else if (qName.equals("param")) { 
    275             String paramName = atts.getValue("name"); 
    276             if (currentGUIElementPath != null) { 
    277                 if ("parent".equals(paramName)) { 
    278                     currentParentPath = atts.getValue("value"); 
    279                 } 
    280                 if ("class".equals(paramName)) { 
    281                     currentGUIElementClass = atts.getValue("value"); 
    282                 } 
    283                 if ("index".equals(paramName)) { 
    284                     currentGUIElementIndex = atts.getValue("value"); 
    285                 } 
    286                 currentGUIElementParameters.put(paramName, atts.getValue("value")); 
    287             } 
    288             else if (currentEventType != null) { 
    289                 if ("target".equals(paramName)) { 
    290                     currentEventSource = atts.getValue("value"); 
    291                 } 
    292                 if ("timestamp".equals(paramName)) { 
    293                     currentEventTimestamp = Long.parseLong(atts.getValue("value")); 
    294                 } 
    295                 currentEventParameters.put(paramName, atts.getValue("value")); 
    296             } 
    297             else { 
    298                 throw new SAXException("param tag found where it should not be."); 
    299             } 
    300         } 
    301         else { 
    302             throw new SAXException("unknown tag found: " + qName); 
    303         } 
    304  
    305     } 
    306  
    307     /* 
    308      * (non-Javadoc) 
    309      *  
    310      * @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String, java.lang.String, 
    311      * java.lang.String) 
    312      */ 
    313     @Override 
    314     public void endElement(String uri, String localName, String qName) throws SAXException { 
    315         if (qName.equals("session")) { 
    316             if (currentSequence != null && !currentSequence.isEmpty()) { 
    317                 sequences.add(currentSequence); 
    318             } 
    319             currentSequence = null; 
    320         } 
    321         else if (qName.equals("component") && currentGUIElementPath != null) { 
    322             HTMLGUIElementSpec guiElementSpec = 
    323                 getGUIElementSpec(currentGUIElementClass, currentGUIElementParameters); 
    324             currentGUIElementTree.add(currentGUIElementPath, currentParentPath, guiElementSpec); 
    325  
    326             currentParentPath = null; 
    327             currentGUIElementPath = null; 
    328             currentGUIElementParameters = null; 
    329         } 
    330         else if (qName.equals("event")) { 
    331             IGUIElement currentGUIElement; 
    332             currentGUIElement = currentGUIElementTree.find(currentEventSource); 
    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  
    342             event.setTimestamp(currentEventTimestamp); 
    343             HTMLGUIElement currentEventTarget = (HTMLGUIElement) event.getTarget(); 
    344             currentEventTarget.markUsed(); 
    345             currentSequence.add(event); 
    346  
    347             currentEventSource = null; 
    348             currentEventTimestamp = -1l; 
    349             currentEventParameters = null; 
    350             currentEventType = null; 
    351  
    352             if (currentGUIElement != null) { 
    353                 lastGUIElement = currentGUIElement; 
    354             } 
    355  
    356             currentGUIElement = null; 
    357         } 
    358     } 
    359  
    360     /** 
    361      * <p> 
    362      * Returns a collection of event sequences that was obtained from parsing log files. 
    363      * </p> 
    364      *  
     271     * 
     272     * @param tagName 
    365273     * @return 
    366274     */ 
    367     public Collection<List<Event>> getSequences() { 
    368         return sequences; 
    369     } 
    370  
    371     /** 
    372      * <p> 
    373      * Returns the GUI model that is obtained from parsing log files. 
    374      * </p> 
    375      *  
    376      * @return GUIModel 
    377      */ 
    378     public GUIModel getGuiModel() { 
    379         return currentGUIElementTree.getGUIModel(); 
    380     } 
    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     } 
     275    private boolean tagNameMustBeConsidered(String tagName) { 
     276        return 
     277            !"head".equals(tagName) && !"title".equals(tagName) && !"script".equals(tagName) && 
     278            !"style".equals(tagName) && !"link".equals(tagName) && !"meta".equals(tagName) && 
     279            !"iframe".equals(tagName) && !"input_hidden".equals(tagName) && 
     280            !"option".equals(tagName) && !"tt".equals(tagName) && !"br".equals(tagName) && 
     281            !"colgroup".equals(tagName) && !"col".equals(tagName); 
     282 
     283    } 
     284 
    421285} 
  • trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/eventcore/HTMLEventTypeFactory.java

    r1059 r1069  
    2323import de.ugoe.cs.autoquest.eventcore.gui.MouseButtonInteraction; 
    2424import de.ugoe.cs.autoquest.eventcore.gui.MouseClick; 
     25import de.ugoe.cs.autoquest.eventcore.gui.MouseDoubleClick; 
    2526import de.ugoe.cs.autoquest.eventcore.gui.Scroll; 
    2627import de.ugoe.cs.autoquest.eventcore.gui.TextInput; 
     
    7677 
    7778        if ("onscroll".equals(eventName)) { 
    78             int[] coordinates = getCoordinateParameter(eventName, eventParameters); 
     79            int[] coordinates = 
     80                getCoordinateParameter("scrollX", "scrollY", eventName, eventParameters); 
     81             
    7982            result = new Scroll(coordinates[0], coordinates[1]); 
    8083        } 
    8184        else if ("onclick".equals(eventName)) { 
    82             int[] coordinates = getCoordinateParameter(eventName, eventParameters); 
     85            int[] coordinates = getCoordinateParameter("X", "Y", eventName, eventParameters); 
    8386            result = 
    8487                new MouseClick(MouseButtonInteraction.Button.LEFT, coordinates[0], coordinates[1]); 
     88        } 
     89        else if ("ondblclick".equals(eventName)) { 
     90            int[] coordinates = getCoordinateParameter("X", "Y", eventName, eventParameters); 
     91            result = new MouseDoubleClick 
     92                (MouseButtonInteraction.Button.LEFT, coordinates[0], coordinates[1]); 
    8593        } 
    8694        else if ("onchange".equals(eventName)) { 
     
    118126     * @return 
    119127     */ 
    120     private int[] getCoordinateParameter(String eventName, Map<String, String> eventParameters) { 
    121         String xCoord = eventParameters.get("X"); 
     128    private int[] getCoordinateParameter(String              xParamName, 
     129                                         String              yParamName, 
     130                                         String              eventName, 
     131                                         Map<String, String> eventParameters) 
     132    { 
     133        String xCoord = eventParameters.get(xParamName); 
    122134        if (xCoord == null) { 
    123             throw new IllegalArgumentException("eventParameters do not contain X coordinate."); 
     135            throw new IllegalArgumentException 
     136                ("eventParameters do not contain " + xParamName + " coordinate."); 
    124137        } 
    125138 
    126         String yCoord = eventParameters.get("Y"); 
     139        String yCoord = eventParameters.get(yParamName); 
    127140        if (yCoord == null) { 
    128             throw new IllegalArgumentException("eventParameters do not contain Y coordinate."); 
     141            throw new IllegalArgumentException 
     142                ("eventParameters do not contain " + yParamName + " coordinate."); 
    129143        } 
    130144 
     
    134148        } 
    135149        catch (NumberFormatException e) { 
    136             throw new IllegalArgumentException("the coordinates provided" + " of an " + eventName + 
     150            throw new IllegalArgumentException("the coordinates provided by an " + eventName + 
    137151                " event are no numbers"); 
    138152        } 
  • trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/guimodel/HTMLDocument.java

    r1047 r1069  
    2424 * @author Patrick Harms 
    2525 */ 
    26 public class HTMLPage extends HTMLGUIElement implements IDialog { 
     26public class HTMLDocument extends HTMLGUIElement implements IDialog { 
    2727 
    2828    /**  */ 
     
    3737     * @param parent 
    3838     */ 
    39     public HTMLPage(HTMLPageSpec specification, HTMLServer parent) { 
     39    public HTMLDocument(HTMLDocumentSpec specification, HTMLServer parent) { 
    4040        super(specification, parent); 
    4141    } 
     
    4848    @Override 
    4949    public String toString() { 
    50         return "Page(" + getPagePath() + ", \"" + getPageTitle() + "\")"; 
     50        return "Document(" + getPath() + ", \"" + getTitle() + "\")"; 
    5151    } 
    5252 
     
    5858    @Override 
    5959    protected String getElementDescriptor() { 
    60         return "Page"; 
     60        return "Document"; 
    6161    } 
    6262 
     
    6969     */ 
    7070    HTMLServerSpec getServer() { 
    71         return ((HTMLPageSpec) super.getSpecification()).getServer(); 
     71        return ((HTMLDocumentSpec) super.getSpecification()).getServer(); 
    7272    } 
    7373 
     
    7979     * @return 
    8080     */ 
    81     String getPagePath() { 
    82         return ((HTMLPageSpec) super.getSpecification()).getPagePath(); 
     81    String getPath() { 
     82        return ((HTMLDocumentSpec) super.getSpecification()).getPath(); 
    8383    } 
    8484 
     
    9090     * @return 
    9191     */ 
    92     String getPageTitle() { 
    93         return ((HTMLPageSpec) super.getSpecification()).getPageTitle(); 
     92    String getTitle() { 
     93        return ((HTMLDocumentSpec) super.getSpecification()).getTitle(); 
    9494    } 
    9595 
  • trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/guimodel/HTMLDocumentSpec.java

    r1047 r1069  
    1515package de.ugoe.cs.autoquest.plugin.html.guimodel; 
    1616 
    17 import java.net.URL; 
    18  
    1917import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec; 
    2018 
     
    2624 * @author Patrick Harms 
    2725 */ 
    28 public class HTMLPageSpec extends HTMLGUIElementSpec implements IGUIElementSpec { 
     26public class HTMLDocumentSpec extends HTMLGUIElementSpec implements IGUIElementSpec { 
    2927 
    3028    /**  */ 
     
    3533     
    3634    /** */ 
    37     private String pagePath; 
     35    private String path; 
    3836     
    3937    /** */ 
    40     private String pageTitle; 
     38    private String query; 
     39     
     40    /** */ 
     41    private String title; 
    4142     
    4243    /** 
     
    4950     * @param pageTitle 
    5051     */ 
    51     public HTMLPageSpec(HTMLServerSpec server, String pagePath, String pageTitle) { 
    52         super("page"); 
     52    public HTMLDocumentSpec(HTMLServerSpec server, String path, String query, String title) { 
     53        super("document"); 
    5354         
    5455        if (server == null) { 
    5556            throw new IllegalArgumentException("server must not be null"); 
    5657        } 
    57         else if (pagePath == null) { 
     58        else if (path == null) { 
    5859            throw new IllegalArgumentException("pagePath must not be null"); 
    59         } 
    60         else if (pageTitle == null) { 
    61             throw new IllegalArgumentException("pageTitle must not be null"); 
    6260        } 
    6361         
    6462        this.server = server; 
    65         this.pagePath = pagePath; 
    66         this.pageTitle = pageTitle; 
    67     } 
    68  
    69     /** 
    70      * <p> 
    71      * TODO: comment 
    72      * </p> 
    73      * 
    74      * @param server 
    75      * @param pagePath 
    76      * @param pageTitle 
    77      */ 
    78     public HTMLPageSpec(URL pageURL, String pageTitle) { 
    79         super("page"); 
    80          
    81         if (pageURL == null) { 
    82             throw new IllegalArgumentException("pageURL must not be null"); 
    83         } 
    84         else if (pageTitle == null) { 
    85             throw new IllegalArgumentException("pageTitle must not be null"); 
    86         } 
    87          
    88         this.server = new HTMLServerSpec(pageURL); 
    89         this.pagePath = pageURL.getPath(); 
    90         this.pageTitle = pageTitle; 
     63        this.path = path; 
     64        this.query = query; 
     65        this.title = title; 
    9166    } 
    9267 
     
    9671    @Override 
    9772    public boolean getSimilarity(IGUIElementSpec other) { 
    98         if (other instanceof HTMLPageSpec) { 
    99             HTMLPageSpec otherSpec = (HTMLPageSpec) other; 
     73        if (other instanceof HTMLDocumentSpec) { 
     74            HTMLDocumentSpec otherSpec = (HTMLDocumentSpec) other; 
    10075             
    10176            if (!super.getSimilarity(otherSpec)) { 
     
    10580                return false; 
    10681            } 
    107             else if (!pagePath.equals(otherSpec.pagePath)) { 
     82            else if (!path.equals(otherSpec.path)) { 
     83                return false; 
     84            } 
     85            else if (query != null ? !query.equals(otherSpec.query) : otherSpec.query != null) { 
    10886                return false; 
    10987            } 
    11088            else { 
    111                 return pageTitle.equals(otherSpec.pageTitle); 
     89                return (title != null ? title.equals(otherSpec.title) : otherSpec.title == null); 
    11290            } 
    11391        } 
     
    134112     * @return 
    135113     */ 
    136     String getPagePath() { 
    137         return pagePath; 
     114    String getPath() { 
     115        return path; 
    138116    } 
    139117 
     
    145123     * @return 
    146124     */ 
    147     String getPageTitle() { 
    148         return pageTitle; 
     125    String getQuery() { 
     126        return query; 
     127    } 
     128 
     129    /** 
     130     * <p> 
     131     * TODO: comment 
     132     * </p> 
     133     * 
     134     * @return 
     135     */ 
     136    String getTitle() { 
     137        return title; 
    149138    } 
    150139 
  • trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/guimodel/HTMLPageElement.java

    r989 r1069  
    4747     * @param parent 
    4848     */ 
    49     public HTMLPageElement(HTMLPageElementSpec specification, HTMLPage parent) { 
     49    public HTMLPageElement(HTMLPageElementSpec specification, HTMLDocument parent) { 
    5050        super(specification, parent); 
    5151    } 
     
    5858    @Override 
    5959    public String toString() { 
    60         String str = getTag(); 
     60        String str = getTagName(); 
    6161         
    62         if ((getTagId() != null) && (!"".equals(getTagId()))) { 
    63             str += "(id=\"" + getTagId() + "\")"; 
     62        if ((getHtmlId() != null) && (!"".equals(getHtmlId()))) { 
     63            str += "(id=\"" + getHtmlId() + "\")"; 
    6464        } 
    6565        else { 
    66             str += "[" + getTagIndex() + "]"; 
     66            str += "[" + getIndex() + "]"; 
    6767        } 
    6868         
     
    7777    @Override 
    7878    protected String getElementDescriptor() { 
    79         return getTag(); 
     79        return getTagName(); 
    8080    } 
    8181 
     
    8787     * @return 
    8888     */ 
    89     HTMLPageSpec getPage() { 
     89    HTMLDocumentSpec getPage() { 
    9090        return ((HTMLPageElementSpec) super.getSpecification()).getPage(); 
    9191    } 
     
    9898     * @return 
    9999     */ 
    100     String getTag() { 
    101         return ((HTMLPageElementSpec) super.getSpecification()).getTag(); 
     100    String getTagName() { 
     101        return ((HTMLPageElementSpec) super.getSpecification()).getTagName(); 
    102102    } 
    103103 
     
    109109     * @return 
    110110     */ 
    111     String getTagId() { 
    112         return ((HTMLPageElementSpec) super.getSpecification()).getTagId(); 
     111    String getHtmlId() { 
     112        return ((HTMLPageElementSpec) super.getSpecification()).getHtmlId(); 
    113113    } 
    114114 
     
    120120     * @return 
    121121     */ 
    122     int getTagIndex() { 
    123         return ((HTMLPageElementSpec) super.getSpecification()).getTagIndex(); 
     122    int getIndex() { 
     123        return ((HTMLPageElementSpec) super.getSpecification()).getIndex(); 
    124124    } 
    125125 
  • trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/guimodel/HTMLPageElementSpec.java

    r1059 r1069  
    3030     
    3131    /** */ 
    32     private HTMLPageSpec page; 
     32    private HTMLDocumentSpec page; 
    3333     
    3434    /** */ 
    35     private String tag; 
     35    private String tagName; 
    3636     
    3737    /** */ 
    38     private String id; 
     38    private String htmlId; 
    3939     
    4040    /** */ 
     
    5050     * @param id 
    5151     */ 
    52     public HTMLPageElementSpec(HTMLPageSpec page, String tag, String id, int index) { 
    53         super(tag); 
     52    public HTMLPageElementSpec(HTMLDocumentSpec page, String tagName, String htmlId, int index) { 
     53        super(tagName); 
    5454         
    5555        if (page == null) { 
    5656            throw new IllegalArgumentException("page must not be null"); 
    5757        } 
    58         else if (tag == null) { 
     58        else if (tagName == null) { 
    5959            throw new IllegalArgumentException("tag must not be null"); 
    6060        } 
    61         else if ((id == null) && (index < 0)) { 
     61        else if ((htmlId == null) && (index < 0)) { 
    6262            throw new IllegalArgumentException 
    6363                ("either id must not be null or the index must be greater or equal to 0"); 
     
    6565         
    6666        this.page = page; 
    67         this.tag = tag; 
    68         this.id = id; 
     67        this.tagName = tagName; 
     68        this.htmlId = htmlId; 
    6969        this.index = index; 
    7070    } 
     
    8484                return false; 
    8585            } 
    86             else if (!tag.equals(otherSpec.tag)) { 
     86            else if (!tagName.equals(otherSpec.tagName)) { 
    8787                return false; 
    8888            } 
    8989             
    90             if (id != null) { 
    91                 return id.equals(otherSpec.id); 
     90            if (htmlId != null) { 
     91                return htmlId.equals(otherSpec.htmlId); 
    9292            } 
    9393            else if (index >= 0) { 
     
    106106     * @return 
    107107     */ 
    108     public HTMLPageSpec getPage() { 
     108    HTMLDocumentSpec getPage() { 
    109109        return page; 
    110110    } 
     
    117117     * @return 
    118118     */ 
    119     String getTag() { 
    120         return tag; 
     119    String getTagName() { 
     120        return tagName; 
    121121    } 
    122122 
     
    128128     * @return 
    129129     */ 
    130     String getTagId() { 
    131         return id; 
     130    String getHtmlId() { 
     131        return htmlId; 
    132132    } 
    133133 
     
    139139     * @return 
    140140     */ 
    141     int getTagIndex() { 
     141    int getIndex() { 
    142142        return index; 
    143143    } 
  • trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/guimodel/HTMLServerSpec.java

    r1059 r1069  
    1414 
    1515package de.ugoe.cs.autoquest.plugin.html.guimodel; 
    16  
    17 import java.net.URL; 
    1816 
    1917import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec; 
     
    5856        this.host = host; 
    5957        this.port = port; 
    60     } 
    61  
    62     /** 
    63      * <p> 
    64      * TODO: comment 
    65      * </p> 
    66      * 
    67      * @param pageURL 
    68      */ 
    69     public HTMLServerSpec(URL pageURL) { 
    70         super("server"); 
    71  
    72         if (pageURL == null) { 
    73             throw new IllegalArgumentException("page URL must not be null"); 
    74         } 
    75  
    76         this.host = pageURL.getHost(); 
    77         this.port = pageURL.getPort(); 
    7858    } 
    7959 
Note: See TracChangeset for help on using the changeset viewer.