[1069] | 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.htmlmonitor; |
---|
| 16 | |
---|
| 17 | /** |
---|
| 18 | * <p> |
---|
| 19 | * represents a document on a web server including its path and query in the URL. |
---|
| 20 | * </p> |
---|
| 21 | * |
---|
| 22 | * @author Patrick Harms |
---|
| 23 | */ |
---|
| 24 | class HtmlDocument extends HtmlGUIElement { |
---|
| 25 | |
---|
| 26 | /** |
---|
| 27 | * the server on which the document resists |
---|
| 28 | */ |
---|
| 29 | private HtmlServer server; |
---|
| 30 | |
---|
| 31 | /** |
---|
| 32 | * the path to the document on the server |
---|
| 33 | */ |
---|
| 34 | private String path; |
---|
| 35 | |
---|
| 36 | /** |
---|
| 37 | * the query on the path that created the document (including the leading questionmark) |
---|
| 38 | */ |
---|
| 39 | private String query; |
---|
| 40 | |
---|
| 41 | /** |
---|
| 42 | * the title of the document, null if none is present |
---|
| 43 | */ |
---|
| 44 | private String title; |
---|
| 45 | |
---|
| 46 | /** |
---|
| 47 | * <p> |
---|
| 48 | * instantiates a new document element |
---|
| 49 | * </p> |
---|
| 50 | * |
---|
| 51 | * @param id the id of the document |
---|
| 52 | * @param server the server on which the document resists |
---|
| 53 | * @param path the path to the document on the server |
---|
| 54 | * @param query the query on the path that created the document (may include the questionmark) |
---|
| 55 | * @param title the title of the document, null if none is present |
---|
| 56 | */ |
---|
| 57 | HtmlDocument(String id, HtmlServer server, String path, String query, String title) { |
---|
| 58 | super(id, server); |
---|
| 59 | |
---|
| 60 | if (server == null) { |
---|
| 61 | throw new IllegalArgumentException("server must not be null"); |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | if (path == null) { |
---|
| 65 | throw new IllegalArgumentException("path must not be null"); |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | this.server = server; |
---|
| 69 | this.path = path; |
---|
| 70 | this.query = query; |
---|
| 71 | this.title = title; |
---|
| 72 | |
---|
| 73 | if ((this.query != null) && (!this.query.startsWith("?"))) { |
---|
| 74 | this.query = "?" + this.query; |
---|
| 75 | } |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | /** |
---|
| 79 | * @return the server on which the document resists |
---|
| 80 | */ |
---|
| 81 | HtmlServer getServer() { |
---|
| 82 | return server; |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | /** |
---|
| 86 | * @return the path to the document on the server |
---|
| 87 | */ |
---|
| 88 | String getPath() { |
---|
| 89 | return path; |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | /** |
---|
| 93 | * @return the query on the path that created the document (including the leading questionmark) |
---|
| 94 | */ |
---|
| 95 | String getQuery() { |
---|
| 96 | return query; |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | /** |
---|
| 100 | * @return the title of the document, null if none is present |
---|
| 101 | */ |
---|
| 102 | String getTitle() { |
---|
| 103 | return title; |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | /* (non-Javadoc) |
---|
[1075] | 107 | * @see java.lang.Object#equals(java.lang.Object) |
---|
[1069] | 108 | */ |
---|
| 109 | @Override |
---|
[1075] | 110 | public boolean equals(Object obj) { |
---|
[1069] | 111 | if (this == obj) { |
---|
| 112 | return true; |
---|
| 113 | } |
---|
| 114 | else if (obj instanceof HtmlDocument) { |
---|
| 115 | return equals((HtmlDocument) obj); |
---|
| 116 | } |
---|
| 117 | else { |
---|
| 118 | return false; |
---|
| 119 | } |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | /* (non-Javadoc) |
---|
| 123 | * @see de.ugoe.cs.autoquest.htmlmonitor.HtmlGUIElement#equals(de.ugoe.cs.autoquest.htmlmonitor.HtmlGUIElement) |
---|
| 124 | */ |
---|
| 125 | public boolean equals(HtmlDocument other) { |
---|
| 126 | if (this == other) { |
---|
| 127 | return true; |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | return (server.equals(other.server) && path.equals(other.path) && |
---|
| 131 | (query != null ? query.equals(other.query) : other.query == null) && |
---|
| 132 | (title != null ? title.equals(other.title) : other.title == null)); |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | /* (non-Javadoc) |
---|
| 136 | * @see java.lang.Object#hashCode() |
---|
| 137 | */ |
---|
| 138 | @Override |
---|
| 139 | public int hashCode() { |
---|
| 140 | return server.hashCode() + path.hashCode() + (query != null ? query.hashCode() : 0) + |
---|
| 141 | (title != null ? title.hashCode() : 0); |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | } |
---|