// {{{ literalBeanShellReplace() method
  private static String literalBeanShellReplace(View view, JEditBuffer buffer, CharSequence found)
      throws Exception {
    replaceNS.setVariable("buffer", buffer);
    replaceNS.setVariable("_0", found);
    Object obj = BeanShell.runCachedBlock(replaceMethod, view, replaceNS);

    replaceNS.setVariable("_0", null, false);
    // Not really necessary because it is already cleared in the end of
    // BeanShell.runCachedBlock()
    replaceNS.setVariable("buffer", null, false);

    if (obj == null) return "";
    else return obj.toString();
  } // }}}
 public static Object doConversion(Object value, String function, String oper, Object... params) {
   try {
     if (!ProfileManager.transportsLoaded() || nullOrEmpty(function)) return value;
     NameSpace tmp = new NameSpace(BeanShell.getNameSpace(), "transport");
     tmp.setVariable("value", value);
     tmp.setVariable("oper", oper);
     Element el = selectElement(ProfileManager.transports, "//FUNCTION[@name='" + function + "']");
     if (el == null) {
       BerichtsheftPlugin.consoleMessage("berichtsheft.doConversion.message.1", function);
       return value;
     }
     String script = param(el.getTextContent(), 0, params);
     return BeanShell.eval(null, tmp, script);
   } catch (Exception e) {
     BerichtsheftPlugin.consoleMessage("berichtsheft.doConversion.message.2", function, value);
     return null;
   }
 }
  // {{{ regexpBeanShellReplace() method
  private static String regexpBeanShellReplace(
      View view, JEditBuffer buffer, SearchMatcher.Match occur) throws Exception {
    replaceNS.setVariable("buffer", buffer, false);
    for (int i = 0; i < occur.substitutions.length; i++) {
      replaceNS.setVariable("_" + i, occur.substitutions[i]);
    }

    Object obj = BeanShell.runCachedBlock(replaceMethod, view, replaceNS);

    for (int i = 0; i < occur.substitutions.length; i++) {
      replaceNS.setVariable("_" + i, null, false);
    }
    // Not really necessary because it is already cleared in the end of
    // BeanShell.runCachedBlock()
    replaceNS.setVariable("buffer", null, false);

    if (obj == null) return "";
    else return obj.toString();
  } // }}}
Beispiel #4
0
  // {{{ isSelected() method
  public boolean isSelected(Component comp) {
    if (isSelected == null) return false;

    NameSpace global = BeanShell.getNameSpace();

    try {
      View view = GUIUtilities.getView(comp);

      // undocumented hack to allow browser actions to work.
      // XXX - clean up in 4.3
      global.setVariable("_comp", comp);

      return Boolean.TRUE.equals(
          BeanShell.runCachedBlock(
              isSelected.get(),
              view,
              new NameSpace(BeanShell.getNameSpace(), "BeanShellAction.isSelected()")));
    } catch (Throwable e) {
      Log.log(Log.ERROR, this, e);

      // dialogs f**k things up if a menu is visible, etc!
      // new BeanShellErrorDialog(view,e);

      // so that in the future we don't see streams of
      // exceptions
      isSelected = null;

      return false;
    } finally {
      try {
        global.setVariable("_comp", null);
      } catch (UtilEvalError err) {
        Log.log(Log.ERROR, this, err);
      }
    }
  } // }}}