Package com.aicontest.visualizer.js.dom

Source Code of com.aicontest.visualizer.js.dom.Location

package com.aicontest.visualizer.js.dom;

import java.awt.Desktop;
import java.net.URI;

import netscape.javascript.JSObject;

import com.aicontest.visualizer.Visualizer;

public class Location {

  private Visualizer webWrapper;

  public Location(Visualizer webWrapper) {
    this.webWrapper = webWrapper;
  }

  private JSObject getJSLocation() {
    JSObject jsRoot = webWrapper.getJsRoot();
    if (jsRoot != null) {
      JSObject document = (JSObject) jsRoot.getMember("document");
      return (JSObject) document.getMember("location");
    }
    return null;
  }

  public String getHref() {
    JSObject jsLoc = getJSLocation();
    if (jsLoc == null) {
      return "";
    }
    return jsLoc.getMember("href").toString();
  }

  public void setHref(String href) {
    JSObject jsLoc = getJSLocation();
    if (jsLoc == null)
      try {
        Desktop.getDesktop().browse(URI.create(href));
      } catch (Exception e) {
        e.printStackTrace();
      }
    else
      jsLoc.setMember("href", href);
  }
}
TOP

Related Classes of com.aicontest.visualizer.js.dom.Location

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.