コード例 #1
0
ファイル: SmartJSO.java プロジェクト: andrewhuang/webscheme
  /**
   * Return Javascript code that can be called on this JSObject to return the attribute to its
   * present state
   */
  public String getRestoreMethod(String attr) {
    attr = attr.intern();

    if (attr == SRC_ATTR) {
      return "src=\"" + jsObject.getMember("src") + "\"";
    }

    if (attr == VALUE_ATTR) {
      String value = getString();
      if (nodeName == OBJECT_NAME) return "setString('" + escapeNewlines(value) + "')";
      // FIX implement SPAN_NAME
      // FIX implement INPUT_NAME (including radio and checkbox)
      if (nodeName == TEXTAREA_NAME) return "value='" + value + "'";
    }

    if (attr == DISABLED_ATTR) {
      if (nodeName == OBJECT_NAME || nodeName == APPLET_NAME) {
        // FIX add setDisabled() method to EmbeddedEditorApplet
      }
      if (nodeName == SPAN_NAME) {
        return ""; // spans are never "enabled" anyway
      }
      if (nodeName == INPUT_NAME) {
        // FIX handle radio and checkboxes
        return "disabled=" + jsObject.getMember("disabled");
      }
      if (nodeName == TEXTAREA_NAME) return "disabled=" + jsObject.getMember("disabled");
    }

    // inert
    return "unimplemented=" + attr;
  }
コード例 #2
0
ファイル: SmartJSO.java プロジェクト: andrewhuang/webscheme
  public void setString(String newval) {
    JSObject firstChild = null; // used in SPAN

    try {
      if (nodeName == OBJECT_NAME || nodeName == APPLET_NAME) {
        Object[] args = {newval};
        jsObject.call("setString", args);
        return;
      }

      if (nodeName == SPAN_NAME) {
        Object[] args = {newval};
        firstChild = (JSObject) jsObject.getMember("firstChild");
        if (firstChild == null) {
          // FIX create the text child node
          System.err.println("FIX: no child for " + jsObject);
        }
        firstChild.setMember("nodeValue", newval);
        return;
      }

      if (nodeName == INPUT_NAME) {
        String inputType = jsObject.getMember("type").toString().intern();
        if (inputType.equals(RADIO_INPUT)) {
          JSObject radioGroup = groupOfRadioInput(jsObject);
          int groupLength = ((Double) radioGroup.getMember("length")).intValue();
          for (int i = 0; i < groupLength; i += 1) {
            JSObject radioInGroup = (JSObject) radioGroup.getSlot(i);
            String radiosVal = (String) radioInGroup.getMember("value");
            if (radiosVal.equals(newval)) radioInGroup.setMember("checked", Boolean.TRUE);
            else radioInGroup.removeMember("checked");
          }
          return;
        } else {
          // default INPUT control
          jsObject.setMember("value", newval);
          return;
        }
      }

      if (nodeName == TEXTAREA_NAME) {
        jsObject.setMember("value", newval);
        return;
      }

    } catch (Exception ex) {
      System.err.println("setString error on " + jsObject);
      ex.printStackTrace();
      return;
    }

    // no matches
    throw new IllegalStateException("setString does not support nodeName " + nodeName);
  }
コード例 #3
0
ファイル: CookieHandler.java プロジェクト: erland/erlandjava
 /**
  * Reads all available cookies
  *
  * @return The complete cookie string
  */
 protected String getCookie() {
   /*
    ** get all cookies for a document
    */
   try {
     JSObject myBrowser = JSObject.getWindow(applet);
     JSObject myDocument = (JSObject) myBrowser.getMember("document");
     String myCookie = (String) myDocument.getMember("cookie");
     if (myCookie != null && myCookie.length() > 0) return myCookie;
   } catch (Exception e) {
     LOG.error("getCookie failed", e);
   }
   return "?";
 }
コード例 #4
0
ファイル: ISPACDocApplet.java プロジェクト: cmorenogg/alsigm
  public static String getCookie() {
    try {
      JSObject myDocument = (JSObject) jsBrowserWindow.getMember("document");
      String myCookie = (String) myDocument.getMember("cookie");
      Log.log("cookie: " + myCookie);

      if (myCookie.length() > 0) {
        return myCookie;
      }

    } catch (Exception e) {
      Log.log("Error getting cookie", e);
    }
    return "";
  }
コード例 #5
0
ファイル: AceEditor.java プロジェクト: dipu-bd/AceFX
 /**
  * Gets a list of all available command and keyboard shortcuts
  *
  * @deprecated for internal usage only.
  * @return list of available commands
  */
 @Deprecated
 public ArrayList<Command> getCommandList() {
   JSObject names = (JSObject) mEditor.getModel().eval("this.commands.byName");
   ArrayList<Command> arr = new ArrayList<>();
   for (String str : Commons.getAllProperties(names)) {
     arr.add(new Command((JSObject) names.getMember(str)));
   }
   return arr;
 }
コード例 #6
0
ファイル: SmartJSO.java プロジェクト: andrewhuang/webscheme
  public String getString() {
    JSObject firstChild = null; // used in SPAN

    System.out.println("  ..getString() on " + this);

    try {
      if (nodeName == OBJECT_NAME || nodeName == APPLET_NAME) {
        Object[] args = {};
        return (String) jsObject.call("getString", args);
      }

      if (nodeName == SPAN_NAME) {
        firstChild = (JSObject) jsObject.getMember("firstChild");
        return firstChild.getMember("nodeValue").toString();
      }

      if (nodeName == INPUT_NAME) {
        String inputType = jsObject.getMember("type").toString().intern();
        if (inputType.equals(RADIO_INPUT)) {
          JSObject radioGroup = groupOfRadioInput(jsObject);
          int groupLength = ((Double) radioGroup.getMember("length")).intValue();
          for (int i = 0; i < groupLength; i += 1) {
            JSObject radioInGroup = (JSObject) radioGroup.getSlot(i);
            Boolean checked = (Boolean) radioInGroup.getMember("checked");
            if (checked.booleanValue()) return (String) radioInGroup.getMember("value");
          }
          return "*noselection*";
        } else {
          // default INPUT control
          return jsObject.getMember("value").toString();
        }
      }

      if (nodeName == TEXTAREA_NAME) {
        return jsObject.getMember("value").toString();
      }

    } catch (Exception ex) {
      System.err.println("getString error on " + jsObject);
      ex.printStackTrace();
      return ERROR_VAL;
    }

    // no matches
    throw new IllegalStateException("getString does not support nodeName " + nodeName);
  }
コード例 #7
0
ファイル: CookieHandler.java プロジェクト: erland/erlandjava
  /**
   * Delete a cookie
   *
   * @param name The name of the cookie
   */
  protected void deleteCookie(String name) {
    setCookie(name, " ");
    /*
     **  delete a cookie, set the expiration in the past
     */
    java.util.Calendar c = java.util.Calendar.getInstance();
    c.add(java.util.Calendar.MONTH, -1);
    String expires = "; expires=" + c.getTime().toString();

    String s1 = name + expires;
    try {
      JSObject myBrowser = JSObject.getWindow(applet);
      JSObject myDocument = (JSObject) myBrowser.getMember("document");
      LOG.debug("del: " + s1);
      myDocument.setMember("cookie", s1);
    } catch (JSException e) {
      LOG.error("deleteCookie " + name + " failed", e);
    }
  }
コード例 #8
0
 @Override
 public void activate() {
   try {
     boolean set = false;
     Object contentWindow = node.getMember("contentWindow");
     if (contentWindow instanceof JSObject) {
       Object document = ((JSObject) contentWindow).getMember("document");
       if (document instanceof JSObject) {
         context.item().frame.set(new ElementServer((JSObject) document, context));
         set = true;
       }
     }
     if (!set) {
       context.item().frame.set(this);
     }
   } catch (Throwable t) {
     LogsServer.instance().exception(t);
   }
 }
コード例 #9
0
ファイル: CookieHandler.java プロジェクト: erland/erlandjava
  /**
   * Write a cookie
   *
   * @param name The name of the cookie
   * @param value The value to write
   */
  protected void setCookie(String name, String value) {
    value = cleanValue(value);
    /*
     **  write a cookie
     **    computes the expiration date, good for 1 month
     */
    java.util.Calendar c = java.util.Calendar.getInstance();
    c.add(java.util.Calendar.YEAR, 1);
    String expires = "; expires=" + c.getTime().toString();

    String s1 = name + "=" + value + expires;
    LOG.debug(s1);
    try {
      JSObject myBrowser = JSObject.getWindow(applet);
      JSObject myDocument = (JSObject) myBrowser.getMember("document");

      myDocument.setMember("cookie", s1);
      LOG.debug("set:" + s1);
    } catch (JSException e) {
      LOG.error("setCookie " + name + "=" + value + " failed", e);
    }
  }
コード例 #10
0
  public void jjsReadJSObject() {
    JSObject jsobjectvalue = (JSObject) window.getMember(jsvar);

    System.out.println(jsobjectvalue);
  }
コード例 #11
0
  public void jjsRead2DArray() {
    Object[][] arrayvalue = (Object[][]) window.getMember(jsvar);

    System.out.println(Arrays.deepToString(arrayvalue));
  }
コード例 #12
0
 public void jjsReadObject() {
   value = window.getMember(jsvar).toString();
   System.out.println(value);
 }
コード例 #13
0
 public void jjsReadBoolean() {
   value = new Boolean(window.getMember(jsvar).toString());
   System.out.println(value);
 }
コード例 #14
0
 public void jjsReadDouble() {
   value = new Double(window.getMember(jsvar).toString());
   System.out.println(value);
 }
コード例 #15
0
ファイル: SmartJSO.java プロジェクト: andrewhuang/webscheme
 static JSObject groupOfRadioInput(JSObject anInput) {
   JSObject form = (JSObject) anInput.getMember("form");
   String groupName = (String) anInput.getMember("name");
   JSObject radioGroup = (JSObject) form.getMember(groupName);
   return radioGroup;
 }
コード例 #16
0
ファイル: SmartJSO.java プロジェクト: andrewhuang/webscheme
 public SmartJSO(JSObject jso) {
   jsObject = jso;
   nodeName = jsObject.getMember("nodeName").toString().intern();
 }
コード例 #17
0
 /** {@inheritDoc} */
 @Override
 public String getAttribute(final String attrName) {
   String val = (String) (node.getMember(attrName));
   return val == null || val.equals("undefined") ? "" : val;
 }
コード例 #18
0
 // methods for testing read from JavaScript variables
 public void jjsReadInt() {
   //        value = new Integer(window.getMember(jsvar).toString());
   int num = ((Number) window.getMember(jsvar)).intValue();
   System.out.println(value);
 }