Ignore:
Timestamp:
02/14/13 15:20:07 (11 years ago)
Author:
pharms
Message:
  • support of new HTML logging format
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/autoquest-htmlmonitor/src/main/java/de/ugoe/cs/autoquest/htmlmonitor/HtmlPageElement.java

    r1022 r1069  
    1515package de.ugoe.cs.autoquest.htmlmonitor; 
    1616 
    17 import java.util.ArrayList; 
    18 import java.util.List; 
    19  
    2017/** 
    2118 * <p> 
    22  * represents an element of an HTML GUI. This can be a server, which is usually the root of a 
    23  * GUI structure, a web page, or a tag within a web page. 
     19 * represents an element of an HTML GUI, i.e. a tag within a web page. 
    2420 * </p> 
    2521 *  
    2622 * @author Patrick Harms 
    2723 */ 
    28 class HtmlPageElement { 
    29  
    30     /** 
    31      * path to the parent of this page element or null, if this is the root element 
    32      */ 
    33     private String parentPath; 
    34      
    35     /** 
    36      * the name of the tag represented by this page element. May also be the name of the server 
    37      * or the page. 
     24class HtmlPageElement extends HtmlGUIElement { 
     25 
     26    /** 
     27     * the document to which the represented tag belongs 
     28     */ 
     29    private HtmlDocument document; 
     30     
     31    /** 
     32     * the parent page element; if null, the document is considered the parent 
     33     */ 
     34    private HtmlPageElement parent; 
     35     
     36    /** 
     37     * the name of the tag represented by this page element. 
    3838     */ 
    3939    private String tagName; 
    4040     
    4141    /** 
    42      * the id of the page element. May also be the name of the server including port number or the 
    43      * URL of the page 
    44      */ 
    45     private String id; 
    46      
    47     /** 
    48      * the title of the page if a page is represented through this element 
    49      */ 
    50     private String title; 
     42     * the id of the page element inside the DOM. 
     43     */ 
     44    private String htmlId; 
    5145     
    5246    /** 
     
    5751     
    5852    /** 
    59      * the children of this element 
    60      */ 
    61     private List<HtmlPageElement> children; 
    62  
    63     /** 
    6453     * <p> 
    6554     * instantiates a new element representing a tag in an HTML page 
    6655     * </p> 
    6756     * 
    68      * @param parentPath the path through the DOM to the parent node of the represented tag  
    69      * @param tagName    the name of the represented tag 
    70      * @param id         the id of the tag in the DOM 
    71      * @param index      the index of the represented tag regarding all tags with the same tag name 
    72      *                   in the list of children of the parent tag 
    73      */ 
    74     HtmlPageElement(String parentPath, String tagName, String id, Integer index) { 
    75         this.parentPath = parentPath; 
     57     * @param id       the id of the page element 
     58     * @param document the document to which the represented tag belongs 
     59     * @param parent   the parent page element; if null, the document is considered the parent 
     60     * @param tagName  the name of the represented tag 
     61     * @param htmlId   the id of the tag in the DOM 
     62     * @param index    the index of the represented tag regarding all tags with the same 
     63     *                 tag name in the list of children of the parent tag 
     64     */ 
     65    HtmlPageElement(String          id, 
     66                    HtmlDocument    document, 
     67                    HtmlPageElement parent, 
     68                    String          tagName, 
     69                    String          htmlId, 
     70                    Integer         index) 
     71    { 
     72        super(id, parent == null ? document : parent); 
     73         
     74        if (document == null) { 
     75            throw new IllegalArgumentException("document must not be null"); 
     76        } 
     77 
     78        if (tagName == null) { 
     79            throw new IllegalArgumentException("tagName must not be null"); 
     80        } 
     81         
     82        if ((htmlId == null) && (index == null)) { 
     83            throw new IllegalArgumentException("either one of htmlId and index must not be null"); 
     84        } 
     85         
     86        this.document = document; 
     87        this.parent = parent; 
    7688        this.tagName = tagName; 
    77         this.id = id; 
     89        this.htmlId = htmlId; 
    7890        this.index = index; 
    7991    } 
     
    8193    /** 
    8294     * <p> 
    83      * instantiates a new element representing an HTML page 
     95     * returns the document to which the represented tag belongs 
    8496     * </p> 
    8597     * 
    86      * @param parentPath the path through the DOM to the parent node of the represented tag which is 
    87      *                   usually a server 
    88      * @param tagName    the name of the represented tag which is the path of the web page 
    89      * @param title      the title of the web page 
    90      * @param id         the id of the web page which is its path 
    91      * @param index      usually 0 
    92      */ 
    93     HtmlPageElement(String parentPath, String tagName, String id, String title, Integer index) { 
    94         this(parentPath, tagName, id, index); 
    95         this.title = title; 
    96     } 
    97  
    98     /** 
    99      * <p> 
    100      * returns the name of the tag represented by this page element. May also be the name of the 
    101      * server or the page. 
     98     * @return the document 
     99     */ 
     100    HtmlDocument getDocument() { 
     101        return document; 
     102    } 
     103 
     104    /** 
     105     * <p> 
     106     * returns the name of the tag represented by this page element. 
    102107     * </p> 
    103108     *  
     
    110115    /** 
    111116     * <p> 
    112      * returns the id of the page element. May also be the name of the server including port 
    113      * number or the URL of the page 
     117     * returns the id of the page element. 
    114118     * </p> 
    115119     *  
    116120     * @return the id 
    117121     */ 
    118     String getId() { 
    119         return id; 
    120     } 
    121  
    122     /** 
    123      * <p> 
    124      * returns the title of the page if a page is represented through this element 
    125      * </p> 
    126      *  
    127      * @return the title 
    128      */ 
    129     String getTitle() { 
    130         return title; 
     122    String getHtmlId() { 
     123        return htmlId; 
    131124    } 
    132125 
     
    141134    Integer getIndex() { 
    142135        return index; 
    143     } 
    144  
    145     /** 
    146      * <p> 
    147      * returns the children of this element if any, null else 
    148      * </p> 
    149      *  
    150      * @return the children 
    151      */ 
    152     List<HtmlPageElement> getChildren() { 
    153         return children; 
    154     } 
    155  
    156  
    157     /** 
    158      * adds a child to this element 
    159      *  
    160      * @param child the child to be added 
    161      */ 
    162     void addChild(HtmlPageElement child) { 
    163         if (child != null) { 
    164             if (children == null) { 
    165                 children = new ArrayList<HtmlPageElement>(); 
    166             } 
    167              
    168             children.add(child); 
    169         } 
    170     } 
    171  
    172     /** 
    173      * <p> 
    174      * returns the path to the parent of this page element or null, if this is the root element 
    175      * </p> 
    176      * 
    177      * @return as described 
    178      */ 
    179     String getParentPath() { 
    180         return parentPath; 
    181136    } 
    182137 
     
    190145     * @return as described 
    191146     */ 
    192     String getPath() { 
     147    String getDOMPath() { 
    193148        StringBuffer result = new StringBuffer(); 
    194         if (parentPath != null) { 
    195             result.append(parentPath); 
     149        if (parent != null) { 
     150            result.append(parent.getDOMPath()); 
    196151        } 
    197152 
     
    199154        result.append(tagName); 
    200155         
    201         if ((id != null) && (!"".equals(id))) { 
    202             result.append("(id="); 
    203             result.append(id); 
     156        if ((htmlId != null) && (!"".equals(htmlId))) { 
     157            result.append("(htmlId="); 
     158            result.append(htmlId); 
    204159            result.append(")"); 
    205160        } 
     
    213168    } 
    214169 
     170    /* (non-Javadoc) 
     171     * @see de.ugoe.cs.autoquest.htmlmonitor.HtmlGUIElement#equals(de.ugoe.cs.autoquest.htmlmonitor.HtmlGUIElement) 
     172     */ 
     173    @Override 
     174    public boolean equals(HtmlGUIElement obj) { 
     175        if (this == obj) { 
     176            return true; 
     177        } 
     178        else if (obj instanceof HtmlPageElement) { 
     179            return equals((HtmlPageElement) obj); 
     180        } 
     181        else { 
     182            return false; 
     183        } 
     184    } 
     185 
     186    /* (non-Javadoc) 
     187     * @see de.ugoe.cs.autoquest.htmlmonitor.HtmlGUIElement#equals(de.ugoe.cs.autoquest.htmlmonitor.HtmlGUIElement) 
     188     */ 
     189    public boolean equals(HtmlPageElement other) { 
     190        if (this == other) { 
     191            return true; 
     192        } 
     193 
     194        return (document.equals(other.document) && tagName.equals(other.tagName) && 
     195                (parent != null ? parent.equals(other.parent) : other.parent == null) && 
     196                (htmlId != null ? htmlId.equals(other.htmlId) : other.htmlId == null) && 
     197                (index != null ? index.equals(other.index) : other.index == null)); 
     198    } 
     199 
     200    /* (non-Javadoc) 
     201     * @see java.lang.Object#hashCode() 
     202     */ 
     203    @Override 
     204    public int hashCode() { 
     205        return document.hashCode() + tagName.hashCode() + (parent != null ? parent.hashCode() : 0) + 
     206            (htmlId != null ? htmlId.hashCode() : 0) + (index != null ? index : 0); 
     207    } 
     208 
    215209} 
Note: See TracChangeset for help on using the changeset viewer.