Beispiel #1
0
  public static Object jsFunction_modify(
      Context cx, Scriptable thisObj, Object[] args, Function funObj) throws Exception {
    JSURI js_this = checkInstance(thisObj);
    String type = null;
    HashMap<String, String> params = new HashMap<String, String>();

    if (args.length < 1 || args[0] == Context.getUndefinedValue()) {
      throw Context.reportRuntimeError("Missing append() argument");
    }

    if (args.length >= 2 && args[1] != Context.getUndefinedValue()) {
      type = ESXX.parseMIMEType(Context.toString(args[1]), params);
    }

    return js_this.protocolHandler.modify(cx, thisObj, args[0], type, params);
  }
Beispiel #2
0
  public static Object jsFunction_remove(
      Context cx, Scriptable thisObj, Object[] args, Function funObj) throws Exception {
    JSURI js_this = checkInstance(thisObj);
    String type = null;
    HashMap<String, String> params = new HashMap<String, String>();

    if (args.length >= 1 && args[0] != Context.getUndefinedValue()) {
      type = ESXX.parseMIMEType(Context.toString(args[0]), params);
    }

    return js_this.protocolHandler.remove(cx, thisObj, type, params);
  }
Beispiel #3
0
  public static Object jsConstructor(
      Context cx, java.lang.Object[] args, Function ctorObj, boolean inNewExpr)
      throws URISyntaxException {
    JSURI prop_src_uri = null;
    URI uri = null;
    String uri_string = null;
    String uri_relative = null;
    Scriptable params = null;

    if (args.length < 1 || args[0] == Context.getUndefinedValue()) {
      throw Context.reportRuntimeError("Missing argument");
    }

    // First argument is always the URI
    if (args.length >= 1 && args[0] != Context.getUndefinedValue()) {
      if (args[0] instanceof JSURI) {
        prop_src_uri = (JSURI) args[0];
        uri = prop_src_uri.uri;
      } else if (args[0] instanceof URL) {
        uri = ((URL) args[0]).toURI();
      } else if (args[0] instanceof URI) {
        uri = (URI) args[0];
      } else {
        uri_string = Context.toString(args[0]);
      }
    }

    // Third argument can only by params
    if (args.length >= 3 && args[2] != Context.getUndefinedValue()) {
      params = (Scriptable) args[2];
    }

    // Second argument can be relative URI or params
    if (args.length >= 2 && args[1] != Context.getUndefinedValue()) {
      if (args[1] instanceof Scriptable) {
        if (params != null) {
          throw Context.reportRuntimeError("Expected a String as second argument.");
        }

        params = (Scriptable) args[1];
      } else {
        // args[1] should be resolved against args[0]
        uri_relative = Context.toString(args[1]);
      }
    }

    if (params != null) {
      // Replace {...} patterns in string arguments if params was supplied
      final Scriptable final_params = params;

      StringUtil.ParamResolver resolver =
          new StringUtil.ParamResolver() {
            public String resolveParam(String param) {
              Object obj;

              try {
                obj = final_params.get(Integer.parseInt(param), final_params);
              } catch (NumberFormatException ex) {
                obj = final_params.get(param, final_params);
              }

              try {
                String value = Context.toString(obj);
                return StringUtil.encodeURI(value, false /* == encodeURIComponent() */);
              } catch (URISyntaxException ex) {
                throw new WrappedException(ex);
              }
            }
          };

      uri_string = StringUtil.format(uri_string, resolver);
      uri_relative = StringUtil.format(uri_relative, resolver);
    }

    if (uri_string != null) {
      // Resolve URI against current location, if possible
      JSESXX js_esxx = JSGlobal.getJSESXX(cx, ctorObj);

      if (js_esxx != null) {
        prop_src_uri = js_esxx.jsGet_wd();

        if (prop_src_uri != null) {
          uri = resolveURI(prop_src_uri.uri, uri_string);
        }
      }

      if (uri == null) {
        // Fall back to non-relative
        uri = new URI(uri_string);
      }
    }

    if (uri_relative != null) {
      // Resolve relative part against first URI argument
      uri = resolveURI(uri, uri_relative);
    }

    JSURI rc = new JSURI(uri);

    if (prop_src_uri != null) {
      // Copy local properties from previous JSURI object
      for (Object o : prop_src_uri.getIds()) {
        if (o instanceof String) {
          String key = (String) o;

          rc.put(key, rc, prop_src_uri.get(key, prop_src_uri));
        } else {
          int key = (Integer) o;

          rc.put(key, rc, prop_src_uri.get(key, prop_src_uri));
        }
      }
    }

    return rc;
  }