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