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 | * the hash code of this document |
---|
48 | */ |
---|
49 | private int hashCode; |
---|
50 | |
---|
51 | /** |
---|
52 | * <p> |
---|
53 | * instantiates a new document element |
---|
54 | * </p> |
---|
55 | * |
---|
56 | * @param id the id of the document |
---|
57 | * @param server the server on which the document resists |
---|
58 | * @param path the path to the document on the server |
---|
59 | * @param query the query on the path that created the document (may include the questionmark) |
---|
60 | * @param title the title of the document, null if none is present |
---|
61 | */ |
---|
62 | HtmlDocument(String id, HtmlServer server, String path, String query, String title) { |
---|
63 | super(id, server); |
---|
64 | |
---|
65 | if (server == null) { |
---|
66 | throw new IllegalArgumentException("server must not be null"); |
---|
67 | } |
---|
68 | |
---|
69 | if (path == null) { |
---|
70 | throw new IllegalArgumentException("path must not be null"); |
---|
71 | } |
---|
72 | |
---|
73 | this.server = server; |
---|
74 | this.path = path; |
---|
75 | this.query = query; |
---|
76 | this.title = title; |
---|
77 | |
---|
78 | if ((this.query != null) && (!this.query.startsWith("?"))) { |
---|
79 | this.query = "?" + this.query; |
---|
80 | } |
---|
81 | |
---|
82 | this.hashCode = this.server.hashCode() + this.path.hashCode() + |
---|
83 | (this.query != null ? this.query.hashCode() : 0) + |
---|
84 | (this.title != null ? this.title.hashCode() : 0); |
---|
85 | } |
---|
86 | |
---|
87 | /** |
---|
88 | * @return the server on which the document resists |
---|
89 | */ |
---|
90 | HtmlServer getServer() { |
---|
91 | return server; |
---|
92 | } |
---|
93 | |
---|
94 | /** |
---|
95 | * @return the path to the document on the server |
---|
96 | */ |
---|
97 | String getPath() { |
---|
98 | return path; |
---|
99 | } |
---|
100 | |
---|
101 | /** |
---|
102 | * @return the query on the path that created the document (including the leading questionmark) |
---|
103 | */ |
---|
104 | String getQuery() { |
---|
105 | return query; |
---|
106 | } |
---|
107 | |
---|
108 | /** |
---|
109 | * @return the title of the document, null if none is present |
---|
110 | */ |
---|
111 | String getTitle() { |
---|
112 | return title; |
---|
113 | } |
---|
114 | |
---|
115 | /* (non-Javadoc) |
---|
116 | * @see java.lang.Object#equals(java.lang.Object) |
---|
117 | */ |
---|
118 | @Override |
---|
119 | public boolean equals(Object obj) { |
---|
120 | if (this == obj) { |
---|
121 | return true; |
---|
122 | } |
---|
123 | else if (obj instanceof HtmlDocument) { |
---|
124 | return equals((HtmlDocument) obj); |
---|
125 | } |
---|
126 | else { |
---|
127 | return false; |
---|
128 | } |
---|
129 | } |
---|
130 | |
---|
131 | /* (non-Javadoc) |
---|
132 | * @see de.ugoe.cs.autoquest.htmlmonitor.HtmlGUIElement#equals(de.ugoe.cs.autoquest.htmlmonitor.HtmlGUIElement) |
---|
133 | */ |
---|
134 | public boolean equals(HtmlDocument other) { |
---|
135 | if (this == other) { |
---|
136 | return true; |
---|
137 | } |
---|
138 | |
---|
139 | return (server.equals(other.server) && path.equals(other.path) && |
---|
140 | (query != null ? query.equals(other.query) : other.query == null) && |
---|
141 | (title != null ? title.equals(other.title) : other.title == null)); |
---|
142 | } |
---|
143 | |
---|
144 | /* (non-Javadoc) |
---|
145 | * @see java.lang.Object#hashCode() |
---|
146 | */ |
---|
147 | @Override |
---|
148 | public int hashCode() { |
---|
149 | return hashCode; |
---|
150 | } |
---|
151 | |
---|
152 | } |
---|