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.IDialog; |
---|
18 | import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement; |
---|
19 | |
---|
20 | /** |
---|
21 | * <p> |
---|
22 | * a GUI element representing 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 |
---|
26 | * </p> |
---|
27 | * |
---|
28 | * @author Patrick Harms |
---|
29 | */ |
---|
30 | public class HTMLDocument extends HTMLGUIElement implements IDialog { |
---|
31 | |
---|
32 | /** |
---|
33 | * <p> |
---|
34 | * default serial version UID |
---|
35 | * </p> |
---|
36 | */ |
---|
37 | private static final long serialVersionUID = 1L; |
---|
38 | |
---|
39 | /** |
---|
40 | * <p> |
---|
41 | * instantiates the document with it specification and its parent, which is always a server |
---|
42 | * </p> |
---|
43 | * |
---|
44 | * @param specification the specification of the document |
---|
45 | * @param parent the server on which the document resists |
---|
46 | */ |
---|
47 | public HTMLDocument(HTMLDocumentSpec specification, HTMLServer parent) { |
---|
48 | super(specification, parent); |
---|
49 | } |
---|
50 | |
---|
51 | /** |
---|
52 | * <p> |
---|
53 | * returns the path in the URL of the document |
---|
54 | * </p> |
---|
55 | * |
---|
56 | * @return the path in the URL of the document |
---|
57 | */ |
---|
58 | public String getPath() { |
---|
59 | return ((HTMLDocumentSpec) super.getSpecification()).getPath(); |
---|
60 | } |
---|
61 | |
---|
62 | /* |
---|
63 | * (non-Javadoc) |
---|
64 | * |
---|
65 | * @see de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLGUIElement#getElementDescriptor() |
---|
66 | */ |
---|
67 | @Override |
---|
68 | protected String getElementDescriptor() { |
---|
69 | return "Document"; |
---|
70 | } |
---|
71 | |
---|
72 | /* (non-Javadoc) |
---|
73 | * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement#getDistanceTo(IGUIElement) |
---|
74 | */ |
---|
75 | @Override |
---|
76 | public double getDistanceTo(IGUIElement otherElement) { |
---|
77 | if (otherElement instanceof HTMLServer) { |
---|
78 | // use the implementation provided by the server |
---|
79 | return otherElement.getDistanceTo(this); |
---|
80 | } |
---|
81 | else if (otherElement instanceof HTMLDocument) { |
---|
82 | if (this.getSpecification().getSimilarity(otherElement.getSpecification())) { |
---|
83 | return DISTANCE_NONE; |
---|
84 | } |
---|
85 | else { |
---|
86 | // use the implementation provided by the server to check if the document resists |
---|
87 | // at least on the same server |
---|
88 | return getServer().getDistanceTo(otherElement); |
---|
89 | } |
---|
90 | } |
---|
91 | else if (otherElement instanceof HTMLPageElement) { |
---|
92 | HTMLDocumentSpec documentSpec = |
---|
93 | ((HTMLPageElementSpec) otherElement.getSpecification()).getPage(); |
---|
94 | |
---|
95 | if (this.getSpecification().getSimilarity(documentSpec)) { |
---|
96 | return DISTANCE_SAME_DOCUMENT; |
---|
97 | } |
---|
98 | else { |
---|
99 | // use the implementation provided by the server to check if the document resists |
---|
100 | // at least on the same server |
---|
101 | return getServer().getDistanceTo(otherElement); |
---|
102 | } |
---|
103 | } |
---|
104 | |
---|
105 | return DISTANCE_DISTINCT_SERVER; |
---|
106 | } |
---|
107 | |
---|
108 | /** |
---|
109 | * <p> |
---|
110 | * returns the server on which the document resists |
---|
111 | * </p> |
---|
112 | * |
---|
113 | * @return the server on which the document resists |
---|
114 | */ |
---|
115 | HTMLServer getServer() { |
---|
116 | return (HTMLServer) super.getParent(); |
---|
117 | } |
---|
118 | |
---|
119 | /** |
---|
120 | * <p> |
---|
121 | * returns the title of the document |
---|
122 | * </p> |
---|
123 | * |
---|
124 | * @return the title of the document |
---|
125 | */ |
---|
126 | String getTitle() { |
---|
127 | return ((HTMLDocumentSpec) super.getSpecification()).getTitle(); |
---|
128 | } |
---|
129 | |
---|
130 | } |
---|