use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.
the class History method replaceState.
/**
* Replaces a state.
* @param object the state object
* @param title the title
* @param url an optional URL
*/
@JsxFunction
public void replaceState(final Object object, final String title, final String url) {
final WebWindow w = getWindow().getWebWindow();
try {
URL newStateUrl = null;
final HtmlPage page = (HtmlPage) w.getEnclosedPage();
if (StringUtils.isNotBlank(url)) {
newStateUrl = page.getFullyQualifiedUrl(url);
}
w.getHistory().replaceState(object, newStateUrl);
} catch (final MalformedURLException e) {
Context.throwAsScriptRuntimeEx(e);
}
}
use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.
the class History method pushState.
/**
* Pushes a state.
* @param object the state object
* @param title the title
* @param url an optional URL
*/
@JsxFunction
public void pushState(final Object object, final String title, final String url) {
final WebWindow w = getWindow().getWebWindow();
try {
URL newStateUrl = null;
final HtmlPage page = (HtmlPage) w.getEnclosedPage();
if (StringUtils.isNotBlank(url)) {
newStateUrl = page.getFullyQualifiedUrl(url);
}
w.getHistory().pushState(object, newStateUrl);
} catch (final IOException e) {
Context.throwAsScriptRuntimeEx(e);
}
}
use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.
the class Location method reload.
/**
* Reloads the current page, possibly forcing retrieval from the server even if
* the browser cache contains the latest version of the document.
* @param force if {@code true}, force reload from server; otherwise, may reload from cache
* @throws IOException if there is a problem reloading the page
* @see <a href="http://msdn.microsoft.com/en-us/library/ms536342.aspx">MSDN Documentation</a>
*/
@JsxFunction
public void reload(final boolean force) throws IOException {
final WebWindow webWindow = window_.getWebWindow();
final HtmlPage htmlPage = (HtmlPage) webWindow.getEnclosedPage();
final WebRequest request = htmlPage.getWebResponse().getWebRequest();
if (webWindow.getWebClient().getBrowserVersion().hasFeature(JS_LOCATION_RELOAD_REFERRER)) {
request.setRefererlHeader(htmlPage.getUrl());
}
webWindow.getWebClient().download(webWindow, "", request, true, false, false, "JS location.reload");
}
use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.
the class Console method error.
/**
* This method performs logging to the console at {@code error} level.
* @param cx the JavaScript context
* @param thisObj the scriptable
* @param args the arguments passed into the method
* @param funObj the function
*/
@JsxFunction
public static void error(final Context cx, final Scriptable thisObj, final Object[] args, final Function funObj) {
final WebConsole webConsole = toWebConsole(thisObj);
final Formatter oldFormatter = webConsole.getFormatter();
webConsole.setFormatter(FORMATTER_);
webConsole.error(args);
webConsole.setFormatter(oldFormatter);
}
use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.
the class Console method dir.
/**
* Implementation of console {@code dir} function. This method does not enter recursively
* in the passed object, nor prints the details of objects or functions.
* @param o the object to be printed
*/
@JsxFunction
public void dir(final Object o) {
if (o instanceof ScriptableObject) {
final ScriptableObject obj = (ScriptableObject) o;
final Object[] ids = obj.getIds();
if (ids != null && ids.length > 0) {
final StringBuilder sb = new StringBuilder();
for (final Object id : ids) {
final Object value = obj.get(id);
if (value instanceof Delegator) {
sb.append(id).append(": ").append(((Delegator) value).getClassName()).append('\n');
} else if (value instanceof HtmlUnitScriptable) {
sb.append(id).append(": ").append(((HtmlUnitScriptable) value).getClassName()).append('\n');
} else if (value instanceof BaseFunction) {
sb.append(id).append(": function ").append(((BaseFunction) value).getFunctionName()).append("()\n");
} else {
sb.append(id).append(": ").append(value).append('\n');
}
}
getWebConsole().info(sb.toString());
}
}
}
Aggregations