Changeset 1069 for trunk/autoquest-htmlmonitor/src/main/java/de/ugoe/cs/autoquest/htmlmonitor/HtmlPageElement.java
- Timestamp:
- 02/14/13 15:20:07 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-htmlmonitor/src/main/java/de/ugoe/cs/autoquest/htmlmonitor/HtmlPageElement.java
r1022 r1069 15 15 package de.ugoe.cs.autoquest.htmlmonitor; 16 16 17 import java.util.ArrayList;18 import java.util.List;19 20 17 /** 21 18 * <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. 24 20 * </p> 25 21 * 26 22 * @author Patrick Harms 27 23 */ 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. 24 class 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. 38 38 */ 39 39 private String tagName; 40 40 41 41 /** 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; 51 45 52 46 /** … … 57 51 58 52 /** 59 * the children of this element60 */61 private List<HtmlPageElement> children;62 63 /**64 53 * <p> 65 54 * instantiates a new element representing a tag in an HTML page 66 55 * </p> 67 56 * 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; 76 88 this.tagName = tagName; 77 this. id = id;89 this.htmlId = htmlId; 78 90 this.index = index; 79 91 } … … 81 93 /** 82 94 * <p> 83 * instantiates a new element representing an HTML page95 * returns the document to which the represented tag belongs 84 96 * </p> 85 97 * 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. 102 107 * </p> 103 108 * … … 110 115 /** 111 116 * <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. 114 118 * </p> 115 119 * 116 120 * @return the id 117 121 */ 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; 131 124 } 132 125 … … 141 134 Integer getIndex() { 142 135 return index; 143 }144 145 /**146 * <p>147 * returns the children of this element if any, null else148 * </p>149 *150 * @return the children151 */152 List<HtmlPageElement> getChildren() {153 return children;154 }155 156 157 /**158 * adds a child to this element159 *160 * @param child the child to be added161 */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 element175 * </p>176 *177 * @return as described178 */179 String getParentPath() {180 return parentPath;181 136 } 182 137 … … 190 145 * @return as described 191 146 */ 192 String get Path() {147 String getDOMPath() { 193 148 StringBuffer result = new StringBuffer(); 194 if (parent Path!= null) {195 result.append(parent Path);149 if (parent != null) { 150 result.append(parent.getDOMPath()); 196 151 } 197 152 … … 199 154 result.append(tagName); 200 155 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); 204 159 result.append(")"); 205 160 } … … 213 168 } 214 169 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 215 209 }
Note: See TracChangeset
for help on using the changeset viewer.