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

Last change on this file since 1876 was 1876, checked in by pharms, 9 years ago
  • added support for views in GUIs
File size: 5.4 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;
18import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIView;
19
20/**
21 * <p>
22 * a GUI element specification of an HTML document, i.e., a page on an HTML server. This is the
23 * element for a GUI model of an HTML web site being always and only the children of servers. It
24 * is identified through the server on which it resists, its path, a potential query, and a title.
25 * Its children are HTML page elements
26 * </p>
27 *
28 * @author Patrick Harms
29 */
30public class HTMLDocumentSpec extends HTMLGUIElementSpec implements IGUIElementSpec, IGUIView {
31
32    /**
33     * <p>
34     * default serial version UID
35     * </p>
36     */
37    private static final long serialVersionUID = 1L;
38   
39    /**
40     * <p>
41     * the server on which the document resists
42     * </p>
43     */
44    private HTMLServerSpec server;
45   
46    /**
47     * <p>
48     * the path in the URL of the document
49     * </p>
50     */
51    private String path;
52   
53    /**
54     * <p>
55     * the query in the URL of the document
56     * </p>
57     */
58    private String query;
59   
60    /**
61     * <p>
62     * the title of the document
63     * </p>
64     */
65    private String title;
66   
67    /**
68     * <p>
69     * initializes the document with its server, path, query, and title
70     * </p>
71     *
72     * @param server the server on which the document resists
73     * @param path   the path in the URL of the document
74     * @param query  the query in the URL of the document
75     * @param title  the title of the document
76     *
77     * @throws IllegalArgumentException if the server or path are invalid, i.e. null
78     */
79    public HTMLDocumentSpec(HTMLServerSpec server, String path, String query, String title) {
80        super("document", (server != null ? server.hashCode() : 0) +
81              (path != null ? path.hashCode() : 0) + (query != null ? query.hashCode() : 0) +
82              (title != null ? title.hashCode() : 0));
83       
84        if (server == null) {
85            throw new IllegalArgumentException("server must not be null");
86        }
87        else if (path == null) {
88            throw new IllegalArgumentException("pagePath must not be null");
89        }
90       
91        this.server = server;
92        this.path = path;
93        this.query = query;
94        this.title = title;
95    }
96
97    /* (non-Javadoc)
98     * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec#getSimilarity(IGUIElementSpec)
99     */
100    @Override
101    public boolean getSimilarity(IGUIElementSpec other) {
102        if (other instanceof HTMLDocumentSpec) {
103            HTMLDocumentSpec otherSpec = (HTMLDocumentSpec) other;
104           
105            if (!super.getSimilarity(otherSpec)) {
106                return false;
107            }
108            else if (!server.getSimilarity(otherSpec.server)) {
109                return false;
110            }
111            else if (!path.equals(otherSpec.path)) {
112                return false;
113            }
114            else if (query != null ? !query.equals(otherSpec.query) : otherSpec.query != null) {
115                return false;
116            }
117            else {
118                return (title != null ? title.equals(otherSpec.title) : otherSpec.title == null);
119            }
120        }
121       
122        return false;
123    }
124
125    /* (non-Javadoc)
126     * @see java.lang.Object#equals(java.lang.Object)
127     */
128    @Override
129    public boolean equals(Object obj) {
130        if (obj instanceof HTMLDocumentSpec) {
131            return getSimilarity((HTMLDocumentSpec) obj);
132        }
133        else {
134            return false;
135        }
136    }
137
138    /* (non-Javadoc)
139     * @see java.lang.Object#toString()
140     */
141    @Override
142    public String toString() {
143        return "Document(" + getPath() + (getQuery() != null ? getQuery() : "") +
144            ", \"" + getTitle() + "\")";
145    }
146
147    /* (non-Javadoc)
148     * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIView#isModal()
149     */
150    @Override
151    public boolean isModal() {
152        return true;
153    }
154
155    /**
156     * <p>
157     * returns the server on which the document resists
158     * </p>
159     *
160     * @return the server on which the document resists
161     */
162    public HTMLServerSpec getServer() {
163        return server;
164    }
165
166    /**
167     * <p>
168     * returns the path in the URL of the document
169     * </p>
170     *
171     * @return the path in the URL of the document
172     */
173    public String getPath() {
174        return path;
175    }
176
177    /**
178     * <p>
179     * returns the query in the URL of the document
180     * </p>
181     *
182     * @return the query in the URL of the document
183     */
184    public String getQuery() {
185        return query;
186    }
187
188    /**
189     * <p>
190     * returns the title of the document
191     * </p>
192     *
193     * @return the title of the document
194     */
195    public String getTitle() {
196        return title;
197    }
198
199}
Note: See TracBrowser for help on using the repository browser.