// Copyright 2012 Georg-August-Universität Göttingen, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package de.ugoe.cs.autoquest.plugin.html.guimodel; import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec; import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIView; /** *

* a GUI element specification of an HTML document, i.e., a page on an HTML server. This is the * element for a GUI model of an HTML web site being always and only the children of servers. It * is identified through the server on which it resists, its path, a potential query, and a title. * Its children are HTML page elements *

* * @author Patrick Harms */ public class HTMLDocumentSpec extends HTMLGUIElementSpec implements IGUIElementSpec, IGUIView { /** *

* default serial version UID *

*/ private static final long serialVersionUID = 1L; /** *

* the server on which the document resists *

*/ private HTMLServerSpec server; /** *

* the path in the URL of the document *

*/ private String path; /** *

* the query in the URL of the document *

*/ private String query; /** *

* the title of the document *

*/ private String title; /** *

* initializes the document with its server, path, query, and title *

* * @param server the server on which the document resists * @param path the path in the URL of the document * @param query the query in the URL of the document * @param title the title of the document * * @throws IllegalArgumentException if the server or path are invalid, i.e. null */ public HTMLDocumentSpec(HTMLServerSpec server, String path, String query, String title) { super("document", (server != null ? server.hashCode() : 0) + (path != null ? path.hashCode() : 0) + (query != null ? query.hashCode() : 0) + (title != null ? title.hashCode() : 0)); if (server == null) { throw new IllegalArgumentException("server must not be null"); } else if (path == null) { throw new IllegalArgumentException("pagePath must not be null"); } this.server = server; this.path = path; this.query = query; this.title = title; } /* (non-Javadoc) * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec#getSimilarity(IGUIElementSpec) */ @Override public boolean getSimilarity(IGUIElementSpec other) { if (other instanceof HTMLDocumentSpec) { HTMLDocumentSpec otherSpec = (HTMLDocumentSpec) other; if (!super.getSimilarity(otherSpec)) { return false; } else if (!server.getSimilarity(otherSpec.server)) { return false; } else if (!path.equals(otherSpec.path)) { return false; } else if (query != null ? !query.equals(otherSpec.query) : otherSpec.query != null) { return false; } else { return (title != null ? title.equals(otherSpec.title) : otherSpec.title == null); } } return false; } /* (non-Javadoc) * @see java.lang.Object#equals(java.lang.Object) */ @Override public boolean equals(Object obj) { if (obj instanceof HTMLDocumentSpec) { return getSimilarity((HTMLDocumentSpec) obj); } else { return false; } } /* (non-Javadoc) * @see java.lang.Object#toString() */ @Override public String toString() { return "Document(" + getPath() + (getQuery() != null ? getQuery() : "") + ", \"" + getTitle() + "\")"; } /* (non-Javadoc) * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIView#isModal() */ @Override public boolean isModal() { return true; } /** *

* returns the server on which the document resists *

* * @return the server on which the document resists */ public HTMLServerSpec getServer() { return server; } /** *

* returns the path in the URL of the document *

* * @return the path in the URL of the document */ public String getPath() { return path; } /** *

* returns the query in the URL of the document *

* * @return the query in the URL of the document */ public String getQuery() { return query; } /** *

* returns the title of the document *

* * @return the title of the document */ public String getTitle() { return title; } }