[961] | 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.guimodel.IGUIElementSpec; |
---|
[1876] | 18 | import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIView; |
---|
[961] | 19 | |
---|
| 20 | /** |
---|
| 21 | * <p> |
---|
[1276] | 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 |
---|
[961] | 26 | * </p> |
---|
| 27 | * |
---|
| 28 | * @author Patrick Harms |
---|
| 29 | */ |
---|
[1876] | 30 | public class HTMLDocumentSpec extends HTMLGUIElementSpec implements IGUIElementSpec, IGUIView { |
---|
[961] | 31 | |
---|
[1276] | 32 | /** |
---|
| 33 | * <p> |
---|
| 34 | * default serial version UID |
---|
| 35 | * </p> |
---|
| 36 | */ |
---|
[961] | 37 | private static final long serialVersionUID = 1L; |
---|
| 38 | |
---|
[1276] | 39 | /** |
---|
| 40 | * <p> |
---|
| 41 | * the server on which the document resists |
---|
| 42 | * </p> |
---|
| 43 | */ |
---|
[961] | 44 | private HTMLServerSpec server; |
---|
| 45 | |
---|
[1276] | 46 | /** |
---|
| 47 | * <p> |
---|
| 48 | * the path in the URL of the document |
---|
| 49 | * </p> |
---|
| 50 | */ |
---|
[1069] | 51 | private String path; |
---|
[961] | 52 | |
---|
[1276] | 53 | /** |
---|
| 54 | * <p> |
---|
| 55 | * the query in the URL of the document |
---|
| 56 | * </p> |
---|
| 57 | */ |
---|
[1069] | 58 | private String query; |
---|
[961] | 59 | |
---|
[1276] | 60 | /** |
---|
| 61 | * <p> |
---|
| 62 | * the title of the document |
---|
| 63 | * </p> |
---|
| 64 | */ |
---|
[1069] | 65 | private String title; |
---|
| 66 | |
---|
[961] | 67 | /** |
---|
| 68 | * <p> |
---|
[1276] | 69 | * initializes the document with its server, path, query, and title |
---|
[961] | 70 | * </p> |
---|
| 71 | * |
---|
[1276] | 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 |
---|
[961] | 78 | */ |
---|
[1069] | 79 | public HTMLDocumentSpec(HTMLServerSpec server, String path, String query, String title) { |
---|
[1436] | 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)); |
---|
[961] | 83 | |
---|
| 84 | if (server == null) { |
---|
| 85 | throw new IllegalArgumentException("server must not be null"); |
---|
| 86 | } |
---|
[1069] | 87 | else if (path == null) { |
---|
[961] | 88 | throw new IllegalArgumentException("pagePath must not be null"); |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | this.server = server; |
---|
[1069] | 92 | this.path = path; |
---|
| 93 | this.query = query; |
---|
| 94 | this.title = title; |
---|
[961] | 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) { |
---|
[1069] | 102 | if (other instanceof HTMLDocumentSpec) { |
---|
| 103 | HTMLDocumentSpec otherSpec = (HTMLDocumentSpec) other; |
---|
[961] | 104 | |
---|
| 105 | if (!super.getSimilarity(otherSpec)) { |
---|
| 106 | return false; |
---|
| 107 | } |
---|
| 108 | else if (!server.getSimilarity(otherSpec.server)) { |
---|
| 109 | return false; |
---|
| 110 | } |
---|
[1069] | 111 | else if (!path.equals(otherSpec.path)) { |
---|
[961] | 112 | return false; |
---|
| 113 | } |
---|
[1069] | 114 | else if (query != null ? !query.equals(otherSpec.query) : otherSpec.query != null) { |
---|
| 115 | return false; |
---|
| 116 | } |
---|
[961] | 117 | else { |
---|
[1069] | 118 | return (title != null ? title.equals(otherSpec.title) : otherSpec.title == null); |
---|
[961] | 119 | } |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | return false; |
---|
| 123 | } |
---|
| 124 | |
---|
[1264] | 125 | /* (non-Javadoc) |
---|
[1876] | 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) |
---|
[1264] | 139 | * @see java.lang.Object#toString() |
---|
| 140 | */ |
---|
| 141 | @Override |
---|
| 142 | public String toString() { |
---|
[1876] | 143 | return "Document(" + getPath() + (getQuery() != null ? getQuery() : "") + |
---|
| 144 | ", \"" + getTitle() + "\")"; |
---|
[1264] | 145 | } |
---|
| 146 | |
---|
[1876] | 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 | |
---|
[961] | 155 | /** |
---|
| 156 | * <p> |
---|
[1276] | 157 | * returns the server on which the document resists |
---|
[961] | 158 | * </p> |
---|
| 159 | * |
---|
[1276] | 160 | * @return the server on which the document resists |
---|
[961] | 161 | */ |
---|
| 162 | public HTMLServerSpec getServer() { |
---|
| 163 | return server; |
---|
| 164 | } |
---|
| 165 | |
---|
| 166 | /** |
---|
| 167 | * <p> |
---|
[1276] | 168 | * returns the path in the URL of the document |
---|
[961] | 169 | * </p> |
---|
| 170 | * |
---|
[1276] | 171 | * @return the path in the URL of the document |
---|
[961] | 172 | */ |
---|
[1876] | 173 | public String getPath() { |
---|
[1069] | 174 | return path; |
---|
[961] | 175 | } |
---|
| 176 | |
---|
| 177 | /** |
---|
| 178 | * <p> |
---|
[1276] | 179 | * returns the query in the URL of the document |
---|
[961] | 180 | * </p> |
---|
| 181 | * |
---|
[1276] | 182 | * @return the query in the URL of the document |
---|
[961] | 183 | */ |
---|
[1876] | 184 | public String getQuery() { |
---|
[1069] | 185 | return query; |
---|
[961] | 186 | } |
---|
| 187 | |
---|
[1069] | 188 | /** |
---|
| 189 | * <p> |
---|
[1276] | 190 | * returns the title of the document |
---|
[1069] | 191 | * </p> |
---|
| 192 | * |
---|
[1276] | 193 | * @return the title of the document |
---|
[1069] | 194 | */ |
---|
[1876] | 195 | public String getTitle() { |
---|
[1069] | 196 | return title; |
---|
| 197 | } |
---|
| 198 | |
---|
[961] | 199 | } |
---|