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