source: trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/guimodel/HTMLPageElementSpec.java @ 1264

Last change on this file since 1264 was 1264, checked in by pharms, 11 years ago
  • improved logging
File size: 3.7 KB
Line 
1//   Copyright 2012 Georg-August-Universität Göttingen, Germany
2//
3//   Licensed under the Apache License, Version 2.0 (the "License");
4//   you may not use this file except in compliance with the License.
5//   You may obtain a copy of the License at
6//
7//       http://www.apache.org/licenses/LICENSE-2.0
8//
9//   Unless required by applicable law or agreed to in writing, software
10//   distributed under the License is distributed on an "AS IS" BASIS,
11//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//   See the License for the specific language governing permissions and
13//   limitations under the License.
14
15package de.ugoe.cs.autoquest.plugin.html.guimodel;
16
17import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec;
18
19/**
20 * <p>
21 * TODO comment
22 * </p>
23 *
24 * @author Patrick Harms
25 */
26public class HTMLPageElementSpec extends HTMLGUIElementSpec implements IGUIElementSpec {
27
28    /**  */
29    private static final long serialVersionUID = 1L;
30   
31    /** */
32    private HTMLDocumentSpec page;
33   
34    /** */
35    private String tagName;
36   
37    /** */
38    private String htmlId;
39   
40    /** */
41    private int index;
42
43    /**
44     * <p>
45     * TODO: comment
46     * </p>
47     *
48     * @param type
49     * @param index
50     * @param id
51     */
52    public HTMLPageElementSpec(HTMLDocumentSpec page, String tagName, String htmlId, int index) {
53        super(tagName);
54       
55        if (page == null) {
56            throw new IllegalArgumentException("page must not be null");
57        }
58        else if (tagName == null) {
59            throw new IllegalArgumentException("tag must not be null");
60        }
61        else if ((htmlId == null) && (index < 0)) {
62            throw new IllegalArgumentException
63                ("either id must not be null or the index must be greater or equal to 0");
64        }
65       
66        this.page = page;
67        this.tagName = tagName;
68        this.htmlId = htmlId;
69        this.index = index;
70    }
71
72    /* (non-Javadoc)
73     * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec#getSimilarity(IGUIElementSpec)
74     */
75    @Override
76    public boolean getSimilarity(IGUIElementSpec other) {
77        if (other instanceof HTMLPageElementSpec) {
78            HTMLPageElementSpec otherSpec = (HTMLPageElementSpec) other;
79           
80            if (!super.getSimilarity(otherSpec)) {
81                return false;
82            }
83            /*else if (!page.getSimilarity(otherSpec.page)) {
84                return false;
85            }*/
86            else if (!tagName.equals(otherSpec.tagName)) {
87                return false;
88            }
89           
90            if (htmlId != null) {
91                return htmlId.equals(otherSpec.htmlId);
92            }
93            else if (index >= 0) {
94                return index == otherSpec.index;
95            }
96        }
97       
98        return false;
99    }
100
101    /* (non-Javadoc)
102     * @see java.lang.Object#toString()
103     */
104    @Override
105    public String toString() {
106        String str = getTagName();
107       
108        if ((getHtmlId() != null) && (!"".equals(getHtmlId()))) {
109            str += "(id=\"" + getHtmlId() + "\")";
110        }
111        else {
112            str += "[" + getIndex() + "]";
113        }
114       
115        return str;
116    }
117
118    /**
119     * <p>
120     * TODO: comment
121     * </p>
122     *
123     * @return
124     */
125    HTMLDocumentSpec getPage() {
126        return page;
127    }
128
129    /**
130     * <p>
131     * TODO: comment
132     * </p>
133     *
134     * @return
135     */
136    String getTagName() {
137        return tagName;
138    }
139
140    /**
141     * <p>
142     * TODO: comment
143     * </p>
144     *
145     * @return
146     */
147    String getHtmlId() {
148        return htmlId;
149    }
150
151    /**
152     * <p>
153     * TODO: comment
154     * </p>
155     *
156     * @return
157     */
158    int getIndex() {
159        return index;
160    }
161
162}
Note: See TracBrowser for help on using the repository browser.