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