Ignore:
Timestamp:
06/27/13 09:16:35 (11 years ago)
Author:
pharms
Message:
  • added some documentation
  • corrected handling of unparseable file during compression
Location:
trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html
Files:
3 edited

Legend:

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

    r1093 r1232  
    3333import org.xml.sax.Attributes; 
    3434import org.xml.sax.InputSource; 
     35import org.xml.sax.Locator; 
    3536import org.xml.sax.SAXException; 
    3637import org.xml.sax.SAXParseException; 
     
    116117    /** 
    117118     * <p> 
     119     * the handle to the locator for correctly throwing exceptions with location information 
     120     * </p> 
     121     */ 
     122    private Locator locator; 
     123 
     124    /** 
     125     * <p> 
    118126     * Constructor. Creates a new logParser. 
    119127     * </p> 
     
    134142     * @param filename 
    135143     *            name and path of the log file 
    136      */ 
    137     public void parseFile(String filename) { 
     144     * 
     145     * @throws SAXException in the case, the file could not be parsed 
     146     */ 
     147    public void parseFile(String filename) throws SAXException { 
    138148        if (filename == null) { 
    139149            throw new IllegalArgumentException("filename must not be null"); 
     
    150160     * @param file 
    151161     *            file to be parsed 
    152      */ 
    153     public void parseFile(File file) { 
     162     * 
     163     * @throws SAXException in the case, the file could not be parsed 
     164     */ 
     165    public void parseFile(File file) throws SAXException { 
    154166        if (file == null) { 
    155167            throw new IllegalArgumentException("file must not be null"); 
     
    167179            Console.printerrln("Error parsing file " + file.getName()); 
    168180            Console.logException(e); 
    169             return; 
     181            throw new SAXParseException("Error parsing file " + file.getName(), locator, e); 
    170182        } 
    171183        catch (ParserConfigurationException e) { 
    172184            Console.printerrln("Error parsing file " + file.getName()); 
    173185            Console.logException(e); 
    174             return; 
    175         } 
    176         catch (SAXException e) { 
    177             Console.printerrln("Error parsing file " + file.getName()); 
    178             Console.logException(e); 
     186            throw new SAXParseException("Error parsing file " + file.getName(), locator, e); 
    179187        } 
    180188        catch (FileNotFoundException e) { 
    181189            Console.printerrln("Error parsing file " + file.getName()); 
    182190            Console.logException(e); 
    183         } 
     191            throw new SAXParseException("Error parsing file " + file.getName(), locator, e); 
     192        } 
     193         
    184194        if (inputSource != null) { 
    185195            inputSource.setSystemId("file://" + file.getAbsolutePath()); 
     
    190200                saxParser.parse(inputSource, this); 
    191201            } 
    192             catch (SAXParseException e) { 
    193                 Console.printerrln("Failure parsing file in line " + e.getLineNumber() + 
    194                     ", column " + e.getColumnNumber() + "."); 
    195                 Console.logException(e); 
    196             } 
    197             catch (SAXException e) { 
    198                 Console.printerrln("Error parsing file " + file.getName()); 
    199                 Console.logException(e); 
    200                 return; 
    201             } 
    202202            catch (IOException e) { 
    203203                Console.printerrln("Error parsing file " + file.getName()); 
    204204                Console.logException(e); 
    205                 return; 
     205                throw new SAXParseException("Error parsing file " + file.getName(), locator, e); 
    206206            } 
    207207        } 
     
    228228    public GUIModel getGuiModel() { 
    229229        return guiElementTree.getGUIModel(); 
     230    } 
     231 
     232    /* (non-Javadoc) 
     233     * @see org.xml.sax.helpers.DefaultHandler#setDocumentLocator(org.xml.sax.Locator) 
     234     */ 
     235    @Override 
     236    public void setDocumentLocator(Locator locator) { 
     237        this.locator = locator; 
    230238    } 
    231239 
     
    298306    /** 
    299307     * <p> 
    300      * TODO: comment 
    301      * </p> 
    302      * 
    303      * @param id 
    304      * @param parameters 
    305      * @return 
     308     * called to handle parsed GUI elements 
     309     * </p> 
     310     * 
     311     * @param id         the id of the parsed GUI element 
     312     * @param parameters all parameters parsed for the GUI element 
     313     *  
     314     * @return true, if the GUI element could be handled. In this case this method is not called 
     315     *         again for the same GUI element. Otherwise the method is called later again. This 
     316     *         may be required, if a child GUI element is parsed before the parent GUI element 
    306317     */ 
    307318    protected abstract boolean handleGUIElement(String id, Map<String, String> parameters)  
     
    310321    /** 
    311322     * <p> 
    312      * TODO: comment 
    313      * </p> 
    314      * 
    315      * @param id 
    316      * @param parameters 
    317      * @return 
     323     * called to handle parsed events 
     324     * </p> 
     325     * 
     326     * @param type       the type of the parsed event 
     327     * @param parameters the parameters of the parsed event 
     328     *  
     329     * @return true, if the event could be handled. In this case this method is not called 
     330     *         again for the same event. Otherwise the method is called later again. This 
     331     *         may be required, if e.g. the target of the event, i.e. the GUI element, is not yet 
     332     *         parsed 
    318333     */ 
    319334    protected abstract boolean handleEvent(String type, Map<String, String> parameters) 
     
    322337    /** 
    323338     * <p> 
    324      * TODO: comment 
    325      * </p> 
    326      * 
    327      * @return 
     339     * returns the tree of parsed GUI elements, which consists of the ids of the GUI elements 
     340     * </p> 
     341     * 
     342     * @return as described 
    328343     */ 
    329344    protected GUIElementTree<String> getGUIElementTree() { 
     
    333348    /** 
    334349     * <p> 
    335      * TODO: comment 
     350     * adds an event to the currently parsed sequence of events 
    336351     * </p> 
    337352     * 
     
    344359    /** 
    345360     * <p> 
    346      * TODO: comment 
    347      * </p> 
    348      * 
     361     * this method internally processes GUI elements, that have been parsed but not processed yet. 
     362     * I.e., for such GUI elements, either the method {@link #handleGUIElement(String, Map)} has 
     363     * not been called yet, or it returned false for the previous calls. In this case, the method 
     364     * is called (again). Furthermore, the processing of events is initiated by a call to 
     365     * {@link #processEvents()}. 
     366     * </p> 
    349367     */ 
    350368    private void processGUIElements() throws SAXException { 
     
    374392    /** 
    375393     * <p> 
    376      * TODO: comment 
    377      * </p> 
    378      * 
     394     * this method internally processes events, that have been parsed but not processed yet. 
     395     * I.e., for such events, either the method {@link #handleEvent(String, Map)} has 
     396     * not been called yet, or it returned false for the previous calls. In this case, the method 
     397     * is called (again). 
     398     * </p> 
    379399     */ 
    380400    private void processEvents() throws SAXException { 
     
    410430    /** 
    411431     * <p> 
    412      * TODO document 
     432     * This class is used internally for storing events and GUI elements in lists. 
    413433     * </p> 
    414434     */ 
  • trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/HTMLLogCompressor.java

    r1230 r1232  
    3535/** 
    3636 * <p> 
    37  * TODO comment 
     37 * This class can be used to compress a bunch of HTML log files to one file, that contains only 
     38 * one full GUI model. 
    3839 * </p> 
    3940 *  
    40  * @author Fabian Glaser, Patrick Harms 
     41 * @author Patrick Harms 
    4142 * @version 1.0 
    4243 *  
     
    4546     
    4647    /** 
    47      *  
     48     * <p> 
     49     * The output writer into which the compressed variant of the log files is written 
     50     * </p> 
    4851     */ 
    4952    private PrintWriter outputWriter; 
    5053     
    5154    /** 
     55     * <p> 
    5256     * the GUI elements, that were already logged and need therefore not be logged again into 
    5357     * the same file 
     58     * </p> 
    5459     */ 
    5560    private Set<String> loggedGUIElementIds = new HashSet<String>(); 
    5661 
    5762    /** 
     63     * <p> 
    5864     * the events that were read 
     65     * </p> 
    5966     */ 
    6067    private List<EventEntry> sortedEvents = new LinkedList<EventEntry>(); 
    6168 
    6269    /** 
     70     * <p> 
     71     * called to compress all log files in the provided directory. The method reuses  
     72     * {@link #compressFilesInDirectory(File)}. 
     73     * </p> 
    6374     *  
     75     * @param directory the directory containing the log files to be compressed 
    6476     */ 
    6577    public void compressFilesInDirectory(String directory) { 
     
    7284 
    7385    /** 
     86     * <p> 
     87     * called to compress all log files in the provided directory. The directory if processed 
     88     * recursively. For each directory containing at least one log file the log files are 
     89     * replaced by one large log file containing the GUI model as well as all events contained in 
     90     * the compressed log file. If one log file could not be parsed, it is ignored and not 
     91     * compressed with the other ones. 
     92     * </p> 
    7493     *  
     94     * @param directory the directory containing the log files to be compressed 
    7595     */ 
    7696    public void compressFilesInDirectory(File directory) { 
     
    213233 
    214234    /* (non-Javadoc) 
    215      * @see de.ugoe.cs.autoquest.plugin.html.AbstractDefaultLogParser#handleEvent(java.lang.String, java.util.Map) 
     235     * @see de.ugoe.cs.autoquest.plugin.html.AbstractDefaultLogParser#handleEvent(String,Map) 
    216236     */ 
    217237    @Override 
     
    299319     
    300320    /** 
    301      *  
     321     * <p> 
     322     * this class is used internally for storing events in a sorted list together with the 
     323     * timestamps, being the sort criteria.  
     324     * </p> 
    302325     */ 
    303326    private class EventEntry { 
    304327         
    305328        /** 
    306          *  
     329         * <p> 
     330         * the type of the event 
     331         * </p> 
    307332         */ 
    308333        private String type; 
    309334         
    310335        /** 
    311          *  
     336         * <p> 
     337         * the parameters of the event 
     338         * </p> 
    312339         */ 
    313340        private Map<String, String> parameters; 
    314341         
    315342        /** 
    316          *  
     343         * <p> 
     344         * the timestamp of the event 
     345         * </p> 
    317346         */ 
    318347        private long timestamp; 
     
    320349        /** 
    321350         * <p> 
    322          * TODO: comment 
    323          * </p> 
    324          * 
    325          * @param type 
    326          * @param parameters 
    327          * @param timestamp 
     351         * creates a new event entry with event type, parameters and the timestamp 
     352         * </p> 
    328353         */ 
    329354        private EventEntry(String type, Map<String, String> parameters, long timestamp) { 
     
    334359         
    335360        /** 
    336          *  
     361         * <p> 
     362         * convenience method for dumping the event into the compressed log file 
     363         * </p> 
    337364         */ 
    338365        private void dump() { 
  • trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/HTMLLogParser.java

    r1093 r1232  
    4747     
    4848    /** 
    49      * 
     49     * <p> 
     50     * the pattern used for parsing HTML GUI element paths 
     51     * </p> 
    5052     */ 
    5153    private Pattern htmlElementPattern = 
     
    5355 
    5456    /* (non-Javadoc) 
    55      * @see de.ugoe.cs.autoquest.plugin.html.AbstractDefaultLogParser#handleGUIElement(java.lang.String, java.util.Map) 
     57     * @see de.ugoe.cs.autoquest.plugin.html.AbstractDefaultLogParser#handleGUIElement(String, Map) 
    5658     */ 
    5759    @Override 
     
    149151 
    150152    /* (non-Javadoc) 
    151      * @see de.ugoe.cs.autoquest.plugin.html.AbstractDefaultLogParser#handleEvent(java.lang.String, java.util.Map) 
     153     * @see de.ugoe.cs.autoquest.plugin.html.AbstractDefaultLogParser#handleEvent(String, Map) 
    152154     */ 
    153155    @Override 
     
    201203    /** 
    202204     * <p> 
    203      * TODO: comment 
     205     * used to determine the id of a target denoted by an event. This is only required for older 
     206     * document formats. The new formats use concrete ids. 
    204207     * </p> 
    205      * 
    206      * @param targetDocument 
    207      * @param targetDOMPath 
    208      * @return 
    209208     */ 
    210209    private String determineTargetId(String targetDocument, String targetDOMPath) 
     
    280279     * </p> 
    281280     * 
    282      * @param tagName 
    283      * @return 
     281     * @param tagName the tag name to check 
     282     *  
     283     * @return true, if the tag must be considered, false else 
    284284     */ 
    285285    private boolean tagNameMustBeConsidered(String tagName) { 
     
    289289            !"iframe".equals(tagName) && !"input_hidden".equals(tagName) && 
    290290            !"option".equals(tagName) && !"tt".equals(tagName) && !"br".equals(tagName) && 
    291             !"colgroup".equals(tagName) && !"col".equals(tagName); 
     291            !"colgroup".equals(tagName) && !"col".equals(tagName) && !"hr".equals(tagName) && 
     292            !"param".equals(tagName); 
    292293 
    293294    } 
Note: See TracChangeset for help on using the changeset viewer.