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