[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 | |
---|
[1012] | 17 | import de.ugoe.cs.autoquest.eventcore.guimodel.IDialog; |
---|
[1490] | 18 | import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement; |
---|
[961] | 19 | |
---|
| 20 | /** |
---|
| 21 | * <p> |
---|
[1276] | 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 |
---|
[961] | 26 | * </p> |
---|
| 27 | * |
---|
| 28 | * @author Patrick Harms |
---|
| 29 | */ |
---|
[1069] | 30 | public class HTMLDocument extends HTMLGUIElement implements IDialog { |
---|
[961] | 31 | |
---|
[1276] | 32 | /** |
---|
| 33 | * <p> |
---|
| 34 | * default serial version UID |
---|
| 35 | * </p> |
---|
| 36 | */ |
---|
[961] | 37 | private static final long serialVersionUID = 1L; |
---|
| 38 | |
---|
| 39 | /** |
---|
| 40 | * <p> |
---|
[1276] | 41 | * instantiates the document with it specification and its parent, which is always a server |
---|
[961] | 42 | * </p> |
---|
| 43 | * |
---|
[1276] | 44 | * @param specification the specification of the document |
---|
| 45 | * @param parent the server on which the document resists |
---|
[961] | 46 | */ |
---|
[1069] | 47 | public HTMLDocument(HTMLDocumentSpec specification, HTMLServer parent) { |
---|
[961] | 48 | super(specification, parent); |
---|
| 49 | } |
---|
| 50 | |
---|
[1264] | 51 | /** |
---|
| 52 | * <p> |
---|
[1276] | 53 | * returns the path in the URL of the document |
---|
[1264] | 54 | * </p> |
---|
| 55 | * |
---|
[1276] | 56 | * @return the path in the URL of the document |
---|
[961] | 57 | */ |
---|
[1264] | 58 | public String getPath() { |
---|
| 59 | return ((HTMLDocumentSpec) super.getSpecification()).getPath(); |
---|
[961] | 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() { |
---|
[1069] | 69 | return "Document"; |
---|
[961] | 70 | } |
---|
| 71 | |
---|
[1490] | 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 | |
---|
[961] | 108 | /** |
---|
| 109 | * <p> |
---|
[1276] | 110 | * returns the server on which the document resists |
---|
[961] | 111 | * </p> |
---|
| 112 | * |
---|
[1276] | 113 | * @return the server on which the document resists |
---|
[961] | 114 | */ |
---|
[1276] | 115 | HTMLServer getServer() { |
---|
| 116 | return (HTMLServer) super.getParent(); |
---|
[961] | 117 | } |
---|
| 118 | |
---|
| 119 | /** |
---|
| 120 | * <p> |
---|
[1276] | 121 | * returns the title of the document |
---|
[961] | 122 | * </p> |
---|
| 123 | * |
---|
[1276] | 124 | * @return the title of the document |
---|
[961] | 125 | */ |
---|
[1069] | 126 | String getTitle() { |
---|
| 127 | return ((HTMLDocumentSpec) super.getSpecification()).getTitle(); |
---|
[961] | 128 | } |
---|
| 129 | |
---|
| 130 | } |
---|