private Map<String, Object> convertLocationToMap(Location location) { Map<String, Object> map = Maps.newHashMap(); map.put("href", location.getHref()); map.put("protocol", location.getProtocol()); map.put("host", location.getHost()); map.put("hostname", location.getHostname()); map.put("port", location.getPort()); map.put("pathname", location.getPathname()); map.put("search", location.getSearch()); map.put("hash", location.getHash()); map.put("href", location.getHref()); return map; }
/** * Returns the pathname portion of the location URL. * @return the pathname portion of the location URL * @see <a href="http://msdn.microsoft.com/en-us/library/ms534332.aspx">MSDN Documentation</a> */ public String jsxGet_pathname() { if (WebClient.URL_ABOUT_BLANK == getUrl()) { if (getBrowserVersion().isFirefox()) { return ""; } return "/blank"; } return getUrl().getPath(); }
/** * Sets the search portion of the location URL (the portion following the '?'). * @param search the new search portion of the location URL * @throws Exception if an error occurs * @see <a href="http://msdn.microsoft.com/en-us/library/ms534620.aspx">MSDN Documentation</a> */ public void jsxSet_search(final String search) throws Exception { setUrl(UrlUtils.getUrlWithNewQuery(getUrl(), search)); }
history_.setPrototype(getPrototype(history_.getClass())); location_ = new Location(); location_.setParentScope(this); location_.setPrototype(getPrototype(location_.getClass())); location_.initialize(this);
final HtmlPage page = (HtmlPage) getWindow(getStartingScope()).getWebWindow().getEnclosedPage(); final PostponedAction action = new PostponedAction() {
final boolean encodeHash = getBrowserVersion().hasFeature(JS_LOCATION_HREF_HASH_IS_ENCODED); final String hash = getHash(encodeHash); if (hash != null) { url = UrlUtils.getUrlWithNewRef(url, hash);
/** * Returns the search portion of the location URL (the portion following the '?'). * @return the search portion of the location URL * @see <a href="http://msdn.microsoft.com/en-us/library/ms534620.aspx">MSDN Documentation</a> */ public String jsxGet_search() { final String search = getUrl().getQuery(); if (search == null) { return ""; } return "?" + search; }
/** * Returns the hash portion of the location URL (the portion following the '#'). * @return the hash portion of the location URL * @see <a href="http://msdn.microsoft.com/en-us/library/ms533775.aspx">MSDN Documentation</a> */ @JsxGetter public String getHash() { final boolean decodeHash = getBrowserVersion().hasFeature(JS_LOCATION_HASH_IS_DECODED); String hash = hash_; if (hash_ != null && (decodeHash || hash_.equals(getUrl().getRef()))) { hash = decodeHash(hash); } if (StringUtils.isEmpty(hash)) { if (getBrowserVersion().hasFeature(JS_LOCATION_HASH_RETURNS_HASH_FOR_EMPTY_DEFINED) && getHref().endsWith("#")) { return "#"; } } else if (getBrowserVersion().hasFeature(JS_LOCATION_HASH_HASH_IS_ENCODED)) { return "#" + UrlUtils.encodeHash(hash); } else { return "#" + hash; } return ""; }
/** * Sets the hash portion of the location URL (the portion following the '#'). * * @param oldURL the old URL * @param hash the new hash portion of the location URL */ public void setHash(final String oldURL, String hash) { // IMPORTANT: This method must not call setUrl(), because // we must not hit the server just to change the hash! if (hash != null && !hash.isEmpty() && hash.charAt(0) == '#') { hash = hash.substring(1); } final boolean hasChanged = hash != null && !hash.equals(hash_); hash_ = hash; final String newURL = getHref(); if (hasChanged) { final Window w = getWindow(); final Event event; if (getBrowserVersion().hasFeature(EVENT_TYPE_HASHCHANGEEVENT)) { event = new HashChangeEvent(w, Event.TYPE_HASH_CHANGE, oldURL, newURL); } else { event = new Event(w, Event.TYPE_HASH_CHANGE); event.initEvent(Event.TYPE_HASH_CHANGE, false, false); } w.executeEventLocally(event); } }
public void execute() throws Exception { if (newLocation.startsWith(JAVASCRIPT_PREFIX)) { final String script = newLocation.substring(11); page.executeJavaScriptIfPossible(script, "new location value", 1); return; } try { final URL url = page.getFullyQualifiedUrl(newLocation); final URL oldUrl = page.getWebResponse().getRequestSettings().getUrl(); if (url.sameFile(oldUrl) && !StringUtils.equals(url.getRef(), oldUrl.getRef())) { // If we're just setting or modifying the hash, avoid a server hit. jsxSet_hash(newLocation); return; } final WebWindow webWindow = getWindow().getWebWindow(); webWindow.getWebClient().getPage(webWindow, new WebRequestSettings(url)); } catch (final MalformedURLException e) { LOG.error("jsxSet_location('" + newLocation + "') Got MalformedURLException", e); throw e; } catch (final IOException e) { LOG.error("jsxSet_location('" + newLocation + "') Got IOException", e); throw e; } } };
/** * Returns the hash portion of the location URL (the portion following the '#'). * @return the hash portion of the location URL * @see <a href="http://msdn.microsoft.com/en-us/library/ms533775.aspx">MSDN Documentation</a> */ public String jsxGet_hash() { final String hash = getHash(false); if (hash != null) { return "#" + hash; } return ""; }
/** * Sets the hash portion of the location URL (the portion following the '#'). * * @param hash the new hash portion of the location URL * @see <a href="http://msdn.microsoft.com/en-us/library/ms533775.aspx">MSDN Documentation</a> */ public void jsxSet_hash(String hash) { // IMPORTANT: This method must not call setUrl(), because // we must not hit the server just to change the hash! try { if (hash != null) { if (hash.startsWith("#")) { hash = hash.substring(1); } final boolean decodeHash = !getBrowserVersion().isIE(); if (decodeHash) { hash = URIUtil.decode(hash); } hash_ = hash; } else { hash_ = null; } } catch (final URIException e) { LOG.error(e.getMessage(), e); } }
history_.setPrototype(getPrototype(history_.getClass())); location_ = new Location(); location_.setParentScope(this); location_.setPrototype(getPrototype(location_.getClass())); location_.initialize(this);
final HtmlPage page = (HtmlPage) getWindow(getStartingScope()).getWebWindow().getEnclosedPage(); final PostponedAction action = new PostponedAction() {
final boolean encodeHash = getBrowserVersion().hasFeature(JS_LOCATION_HREF_HASH_IS_ENCODED); final String hash = getHash(encodeHash); if (hash != null) { url = UrlUtils.getUrlWithNewRef(url, hash);
/** * Returns the protocol portion of the location URL, including the trailing ':'. * @return the protocol portion of the location URL, including the trailing ':' * @see <a href="http://msdn.microsoft.com/en-us/library/ms534353.aspx">MSDN Documentation</a> */ public String jsxGet_protocol() { return getUrl().getProtocol() + ":"; }
/** * Returns the hash portion of the location URL (the portion following the '#'). * @return the hash portion of the location URL * @see <a href="http://msdn.microsoft.com/en-us/library/ms533775.aspx">MSDN Documentation</a> */ @JsxGetter public String getHash() { final boolean decodeHash = getBrowserVersion().hasFeature(JS_LOCATION_HASH_IS_DECODED); String hash = hash_; if (hash_ != null && (decodeHash || hash_.equals(getUrl().getRef()))) { hash = decodeHash(hash); } if (StringUtils.isEmpty(hash)) { if (getBrowserVersion().hasFeature(JS_LOCATION_HASH_RETURNS_HASH_FOR_EMPTY_DEFINED) && getHref().endsWith("#")) { return "#"; } } else if (getBrowserVersion().hasFeature(JS_LOCATION_HASH_HASH_IS_ENCODED)) { return "#" + UrlUtils.encodeHash(hash); } else { return "#" + hash; } return ""; }
/** * Sets the hash portion of the location URL (the portion following the '#'). * * @param oldURL the old URL * @param hash the new hash portion of the location URL */ public void setHash(final String oldURL, String hash) { // IMPORTANT: This method must not call setUrl(), because // we must not hit the server just to change the hash! if (hash != null && !hash.isEmpty() && hash.charAt(0) == '#') { hash = hash.substring(1); } final boolean hasChanged = hash != null && !hash.equals(hash_); hash_ = hash; final String newURL = getHref(); if (hasChanged) { final Window w = getWindow(); final Event event; if (getBrowserVersion().hasFeature(EVENT_TYPE_HASHCHANGEEVENT)) { event = new HashChangeEvent(w, Event.TYPE_HASH_CHANGE, oldURL, newURL); } else { event = new Event(w, Event.TYPE_HASH_CHANGE); event.initEvent(Event.TYPE_HASH_CHANGE, false, false); } w.executeEventLocally(event); } }
public void execute() throws Exception { if (newLocation.startsWith(JAVASCRIPT_PREFIX)) { final String script = newLocation.substring(11); page.executeJavaScriptIfPossible(script, "new location value", 1); return; } try { final URL url = page.getFullyQualifiedUrl(newLocation); final URL oldUrl = page.getWebResponse().getRequestSettings().getUrl(); if (url.sameFile(oldUrl) && !StringUtils.equals(url.getRef(), oldUrl.getRef())) { // If we're just setting or modifying the hash, avoid a server hit. jsxSet_hash(newLocation); return; } final WebWindow webWindow = getWindow().getWebWindow(); webWindow.getWebClient().getPage(webWindow, new WebRequestSettings(url)); } catch (final MalformedURLException e) { LOG.error("jsxSet_location('" + newLocation + "') Got MalformedURLException", e); throw e; } catch (final IOException e) { LOG.error("jsxSet_location('" + newLocation + "') Got IOException", e); throw e; } } };