Examples of NativeObject


Examples of org.mozilla.javascript.NativeObject

        log.warn("no test files found - exiting");
        System.exit(1);
      }
      for (final File testFile : testFiles){
        log.info("Testing " + testFile.getName());
        final Scriptable scope = new NativeObject();
        scope.setParentScope(GlobalData.getGlobalScope());

        // execute the script, the TestRunner will provide the necessary API
        UserSecurity.doPriviledgedAction(new PrivilegedAction(){
          public Object run() {
            try {
View Full Code Here

Examples of org.mozilla.javascript.NativeObject

    public static final int EXECUTE = 3;
    public static final int APPEND = 4;
    public static final int ACCESS_PERMISSION_LEVEL = 6;
    /** Creates a new instance of ObjectAccessDeniedException */
    public ObjectAccessDeniedException(final Persistable data, final int requestedAction) {
    super(new NativeObject(){
      public Object getDefaultValue(Class typeHint){
            if (requestedAction == BROWSE || requestedAction == LIMITED)
                return "Access denied to " + data + " you do not have any permission";
            if (requestedAction == READ)
                return "Access denied to " + data + " you do not have read permission";
View Full Code Here

Examples of org.mozilla.javascript.NativeObject

        }
       
        return parameters;
  }
  public NativeObject getParametersAndHeadersAsJsObject() {
    NativeObject parameters = Persevere.newObject();
       
        Enumeration headerNames = request.getHeaderNames();
        while (headerNames.hasMoreElements()) {
          String name = (String) headerNames.nextElement();
            parameters.put(name,parameters,request.getHeader(name));
        }
        if (request.getQueryString() != null)
          try {
        // _MUST NOT_ read the body (getInputStream) or call getParameter, because that destroys it for later use
        for (String nameValueStr : request.getQueryString().split("&")) { // parse the query string
          String[] nameValue = nameValueStr.split("=",2);
          if (nameValue.length == 2)
            parameters.put(URLDecoder.decode(nameValue[0],"UTF-8"), parameters, URLDecoder.decode(nameValue[1],"UTF-8"));
        }
          }
          catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
          }
View Full Code Here

Examples of org.mozilla.javascript.NativeObject

          Client connection = new Client("console");
          // give this thread a context/user
          Client.registerThisConnection(connection.getIndividualRequest(null, null));
          context = PersevereContextFactory.getContext();
          global = GlobalData.getGlobalScope();
          consoleScope = new NativeObject();
          // we may want to make this a prototype, so you can create unscoped variables without errors. Downside is it might mislead users as to what they can do in methods
          consoleScope.setParentScope(global);
          ((NativeObject) consoleScope).setGetterOrSetter("help", 0, new PersevereNativeFunction(){

            @Override
View Full Code Here

Examples of org.mozilla.javascript.NativeObject

  public static SMD instance = new SMD();
  static SMDServices servicesInstance;
  private SMD(){           
    setPrototype(ScriptableObject.getClassPrototype(GlobalData.getGlobalScope(),"Object"));

    Scriptable applicationJson = new NativeObject();
    put("representation:application/json", this, applicationJson);
    setAttributes("representation:application/json",ScriptableObject.DONTENUM);
    applicationJson.put("quality", applicationJson, 1.0);
    applicationJson.put("output", applicationJson, new PersevereNativeFunction(){
      @Override
      public Object call(Context cx, Scriptable scope,
          Scriptable thisObj, Object[] args) {
        try {         
          HttpServletResponse response = Client.getCurrentObjectResponse().getHttpResponse();
View Full Code Here

Examples of org.mozilla.javascript.NativeObject

public class ObjectNotFoundException extends EcmaError {
 

  public ObjectNotFoundException(final DataSource source, final String resource) {
    super(new NativeObject(){
      public Object getDefaultValue(Class typeHint){
        return (source == null ? "" : source.getId() + '/') + resource + " not found";
      }
    }, null,0,0,null);
    this.source = source;
View Full Code Here

Examples of org.mozilla.javascript.NativeObject

        }
        if(seqId>=0){
          client.addSequenceId(seqId);
        }
      }
      NativeObject env = new PersistableObject() {
        public Object get(String key, Scriptable start) {
          Object storedValue = super.get(key, start);
          if(storedValue != ScriptableObject.NOT_FOUND)
            return storedValue;
          if ("REQUEST_METHOD".equals(key)) {
            return request.getMethod();
          }
          if ("SERVLET_REQUEST".equals(key)) {
            return request;
          }
          if ("SERVLET_RESPONSE".equals(key)) {
            return response;
          }
          if ("PERSEVERE_REQUEST_HELPER".equals(key)) {
            return rh;
          }
          if ("SERVLET_FILTER_CHAIN".equals(key)) {
            return filterChain;
          }
          if ("SCRIPT_NAME".equals(key)) {
            return request.getServletPath();
          }
          if ("PATH_INFO".equals(key)) {
            String path = request.getRequestURI();
            return path.substring(request.getContextPath().length());
          }
          if ("CONTENT_TYPE".equals(key)) {
            return request.getContentType();
          }
          if ("CONTENT_LENGTH".equals(key)) {
            return request.getContentLength();
          }
          if ("QUERY_STRING".equals(key)) {
            return request.getQueryString();
          }
          if ("SERVER_NAME".equals(key)) {
            return request.getServerName();
          }
          if ("SERVER_PORT".equals(key)) {
            return request.getServerPort();
          }
          if ("SERVER_PROTOCOL".equals(key)) {
            return request.getProtocol();
          }
          if ("jsgi.version".equals(key)) {
            List array = Persevere.newArray();
            array.add(0);
            array.add(1);
            return array;
          }
          if ("jsgi.url_scheme".equals(key)) {
            return request.getScheme();
          }
          if ("jsgi.input".equals(key)) {
            try {
              return request.getInputStream();
            } catch (IOException e) {
              throw new RuntimeException(e);
            }
          }
          if ("jsgi.error".equals(key)) {
            return System.err;
          }
          if ("jsgi.multithread".equals(key)) {
            return true;
          }
          if ("jsgi.multiprocess".equals(key)) {
            return false;
          }
          if ("jsgi.run_once".equals(key)) {
            return false;
          }
          return Undefined.instance;
        }
        public Object getCoreValue(String name){
          return get(name, this);
        }
        @Override
        public Object[] getIds() {
          List list = new ArrayList();
          list.addAll(Arrays.asList(super.getIds()));
          list.addAll(Arrays.asList(new String[]{"REQUEST_METHOD","SCRIPT_NAME","PATH_INFO","CONTENT_TYPE","CONTENT_LENGTH","QUERY_STRING","SERVER_NAME","SERVER_PORT","SERVER_PROTOCOL","jsgi.version","jsgi.url_scheme","jsgi.input","jsgi.error","jsgi.multithread","jsgi.multiprocess","jsgi.run_once"}));
          return list.toArray();
        }

      };
      try {
        ScriptRuntime.setObjectProtoAndParent(env, global);
      } catch (Exception e1) {
      }
      Enumeration headerNames = request.getHeaderNames();
      while(headerNames.hasMoreElements()){
        String headerName = (String) headerNames.nextElement();
        if(!(headerName.equals("Content-Type") || headerName.equals("Content-Length")))
          env.put("HTTP_" + headerName.toUpperCase(), env, request.getHeader(headerName));
      }
      Object result = ((Function) global.get("coreApp", global)).call(PersevereContextFactory.getContext(), global, global,
          new Object[] { env });
      if (result instanceof Scriptable) {
        Object status = ((Scriptable) result).get("status", (Scriptable) result);
View Full Code Here

Examples of org.mozilla.javascript.NativeObject

        return thisObj instanceof Persistable ? ((Persistable)thisObj).getParent() : null;
      }
    },false);
    objectProto.setAttributes("parent",ScriptableObject.DONTENUM);
   
    Scriptable applicationJavascript = new NativeObject();
    objectProto.put("representation:application/javascript", objectProto, applicationJavascript);
    objectProtoMirror.put("representation:application/javascript", objectProtoMirror, applicationJavascript);
    objectProto.setAttributes("representation:application/javascript",ScriptableObject.DONTENUM);
    applicationJavascript.put("quality", applicationJavascript, 0.9);
    applicationJavascript.put("output", applicationJavascript, new PersevereNativeFunction(){
      @Override
      public Object call(Context cx, Scriptable scope,
          Scriptable thisObj, Object[] args) {
        try {
          HttpServletResponse response = Client.getCurrentObjectResponse().getHttpResponse();
          DirtyOutputStreamWriter writer = new DirtyOutputStreamWriter(response.getOutputStream(),"UTF8");
          try{
            new JavaScriptSerializer().serialize(args[0], Client.getCurrentObjectResponse(), writer);
          }
          catch(RuntimeException e){
            if(writer.isDirty)
              writer.write("&&");
            throw e;
          }
          finally{
            writer.flushIfDirty();
          }
          return null;
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

    });
   
    Scriptable applicationJson = new NativeObject();
    objectProto.put("representation:application/json", objectProto, applicationJson);
    objectProtoMirror.put("representation:application/json", objectProtoMirror, applicationJson);
    objectProto.setAttributes("representation:application/json",ScriptableObject.DONTENUM);
    applicationJson.put("quality", applicationJson, 0.8);
    applicationJson.put("output", applicationJson, new PersevereNativeFunction(){
      @Override
      public Object call(Context cx, Scriptable scope,
          Scriptable thisObj, Object[] args) {
        try {
          HttpServletResponse response = Client.getCurrentObjectResponse().getHttpResponse();
View Full Code Here

Examples of org.mozilla.javascript.NativeObject

  context.exit();
  // Get JSLint errors
  NativeArray errors = (NativeArray) lint.get("errors", null);
  List<JSLintIssue> result = new ArrayList<JSLintIssue>();
  for (int i = 0; i < errors.getLength(); i++) {
      NativeObject error = (NativeObject) errors.get(i, null);
      if (null == error) {
    continue;
      }
      // Add error
      result.add(new JSLintIssue(error));
View Full Code Here

Examples of org.mozilla.javascript.NativeObject

            this.content = content;
            this.windowWrapper = ww;
        }

        public Object[] buildArguments() {
            ScriptableObject so = new NativeObject();
            so.put("success", so,
                   (success) ? Boolean.TRUE : Boolean.FALSE);
            if (mime != null) {
                so.put("contentType", so,
                       Context.toObject(mime, windowWrapper));
            }
            if (content != null) {
                so.put("content", so,
                       Context.toObject(content, windowWrapper));
            }
            return new Object [] { so };
        }
View Full Code Here
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.