source: trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/guimodel/HTMLDocumentSpec.java @ 2210

Last change on this file since 2210 was 2146, checked in by pharms, 7 years ago
  • refactored GUI model so that hierarchical event target structures can also be used and created by plugins not being strictly for GUIs
File size: 5.4 KB
RevLine 
[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
15package de.ugoe.cs.autoquest.plugin.html.guimodel;
16
[2146]17import de.ugoe.cs.autoquest.eventcore.IEventTargetSpec;
[961]18import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec;
[1876]19import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIView;
[961]20
21/**
22 * <p>
[1276]23 * a GUI element specification of 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 */
[1876]31public class HTMLDocumentSpec extends HTMLGUIElementSpec implements IGUIElementSpec, IGUIView {
[961]32
[1276]33    /**
34     * <p>
35     * default serial version UID
36     * </p>
37     */
[961]38    private static final long serialVersionUID = 1L;
39   
[1276]40    /**
41     * <p>
42     * the server on which the document resists
43     * </p>
44     */
[961]45    private HTMLServerSpec server;
46   
[1276]47    /**
48     * <p>
49     * the path in the URL of the document
50     * </p>
51     */
[1069]52    private String path;
[961]53   
[1276]54    /**
55     * <p>
56     * the query in the URL of the document
57     * </p>
58     */
[1069]59    private String query;
[961]60   
[1276]61    /**
62     * <p>
63     * the title of the document
64     * </p>
65     */
[1069]66    private String title;
67   
[961]68    /**
69     * <p>
[1276]70     * initializes the document with its server, path, query, and title
[961]71     * </p>
72     *
[1276]73     * @param server the server on which the document resists
74     * @param path   the path in the URL of the document
75     * @param query  the query in the URL of the document
76     * @param title  the title of the document
77     *
78     * @throws IllegalArgumentException if the server or path are invalid, i.e. null
[961]79     */
[1069]80    public HTMLDocumentSpec(HTMLServerSpec server, String path, String query, String title) {
[1436]81        super("document", (server != null ? server.hashCode() : 0) +
82              (path != null ? path.hashCode() : 0) + (query != null ? query.hashCode() : 0) +
83              (title != null ? title.hashCode() : 0));
[961]84       
85        if (server == null) {
86            throw new IllegalArgumentException("server must not be null");
87        }
[1069]88        else if (path == null) {
[961]89            throw new IllegalArgumentException("pagePath must not be null");
90        }
91       
92        this.server = server;
[1069]93        this.path = path;
94        this.query = query;
95        this.title = title;
[961]96    }
97
98    /* (non-Javadoc)
99     * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec#getSimilarity(IGUIElementSpec)
100     */
101    @Override
[2146]102    public boolean getSimilarity(IEventTargetSpec other) {
[1069]103        if (other instanceof HTMLDocumentSpec) {
104            HTMLDocumentSpec otherSpec = (HTMLDocumentSpec) other;
[961]105           
106            if (!super.getSimilarity(otherSpec)) {
107                return false;
108            }
109            else if (!server.getSimilarity(otherSpec.server)) {
110                return false;
111            }
[1069]112            else if (!path.equals(otherSpec.path)) {
[961]113                return false;
114            }
[1069]115            else if (query != null ? !query.equals(otherSpec.query) : otherSpec.query != null) {
116                return false;
117            }
[961]118            else {
[1069]119                return (title != null ? title.equals(otherSpec.title) : otherSpec.title == null);
[961]120            }
121        }
122       
123        return false;
124    }
125
[1264]126    /* (non-Javadoc)
[1876]127     * @see java.lang.Object#equals(java.lang.Object)
128     */
129    @Override
130    public boolean equals(Object obj) {
131        if (obj instanceof HTMLDocumentSpec) {
132            return getSimilarity((HTMLDocumentSpec) obj);
133        }
134        else {
135            return false;
136        }
137    }
138
139    /* (non-Javadoc)
[1264]140     * @see java.lang.Object#toString()
141     */
142    @Override
143    public String toString() {
[1876]144        return "Document(" + getPath() + (getQuery() != null ? getQuery() : "") +
145            ", \"" + getTitle() + "\")";
[1264]146    }
147
[1876]148    /* (non-Javadoc)
149     * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIView#isModal()
150     */
151    @Override
152    public boolean isModal() {
153        return true;
154    }
155
[961]156    /**
157     * <p>
[1276]158     * returns the server on which the document resists
[961]159     * </p>
160     *
[1276]161     * @return the server on which the document resists
[961]162     */
163    public HTMLServerSpec getServer() {
164        return server;
165    }
166
167    /**
168     * <p>
[1276]169     * returns the path in the URL of the document
[961]170     * </p>
171     *
[1276]172     * @return the path in the URL of the document
[961]173     */
[1876]174    public String getPath() {
[1069]175        return path;
[961]176    }
177
178    /**
179     * <p>
[1276]180     * returns the query in the URL of the document
[961]181     * </p>
182     *
[1276]183     * @return the query in the URL of the document
[961]184     */
[1876]185    public String getQuery() {
[1069]186        return query;
[961]187    }
188
[1069]189    /**
190     * <p>
[1276]191     * returns the title of the document
[1069]192     * </p>
193     *
[1276]194     * @return the title of the document
[1069]195     */
[1876]196    public String getTitle() {
[1069]197        return title;
198    }
199
[961]200}
Note: See TracBrowser for help on using the repository browser.