Package org.mozilla.javascript

Examples of org.mozilla.javascript.NativeArray


      options.put(key, options, getOption(key));
  }
  // Predefined
  if ( ! "".equals(getOption("predef", ""))) {
      Object[] opts = getOption("predef", "").replaceAll("\\s+", "").split(",");
      options.put("predef", options, new NativeArray(opts));
  }
  // Maximum line length
  if (0 != getOption("maxlen", 0 ))
      options.put("maxlen", options, getOption("maxlen", 0 ));
  // Maximum number of errors
View Full Code Here


  context.evaluateString(scope, "results = JSLINT(contents, opts);", "JSLint", 1, null);
  Scriptable lint = (Scriptable) scope.get("JSLINT", scope);
  // Выходим из контекста
  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

        return pwk;
    }

    public NativeArray jsFunction_getChildren() throws Exception {
        List list = wk.getChildren();
        NativeArray arr =
            (NativeArray)org.mozilla.javascript.Context.getCurrentContext().newObject(getParentScope(),
                                                                                      "Array",
                                                                                      new Object[]{new Integer(list.size())});
        Iterator iter = list.iterator();
        for (int i = 0; iter.hasNext(); i++) {
            WebContinuation child = (WebContinuation)iter.next();
            FOM_WebContinuation cwk = new FOM_WebContinuation(child);
            cwk.enableLogging(logger);
            cwk.setParentScope(getParentScope());
            cwk.setPrototype(getClassPrototype(getParentScope(),
                                               cwk.getClassName()));
            arr.put(i, arr, cwk);
        }
        return arr;
    }
View Full Code Here

        }
       
        // Start the selection-list
        contentHandler.startElement(FormsConstants.INSTANCE_NS, SELECTION_LIST_EL, FormsConstants.INSTANCE_PREFIX_COLON + SELECTION_LIST_EL, XMLUtils.EMPTY_ATTRIBUTES);

        NativeArray array = (NativeArray)result;
        for (int i = 0; i < array.jsGet_length(); i++) {
            Scriptable item = (Scriptable)array.get(i, array);
           
            Object value = item.get("value", item);
            String stringValue = value == null ? "" : this.type.convertToString(value, locale);
            Object label = item.get("label", item);
            if (label == Scriptable.NOT_FOUND)
View Full Code Here

      unitTest.append("API api = new API();\n");

      unitTest.append("ScriptableObject table=");

      final NativeArray actions = (NativeArray) table.get("actions");
      for (final Object a : actions) {
        unitTest.append("api.").append(
            ((ScriptableObject) a).get("method"));

        if (((ScriptableObject) a).get("method") != "createTable") {
          unitTest.append("(table,");
        }
        final NativeArray args = (NativeArray) ((ScriptableObject) a)
            .get("arguments");
        for (final Object argO : args.toArray()) {
          // test.append("\"");
          StringBuilder arg = toString(argO);
          // if string does not start with a quote
          if (!arg.toString().startsWith("\"")) {
            final String replaceAll = arg.toString().replace("\"",
                "\\\"");
            arg = new StringBuilder("\"");
            arg.append(replaceAll);
            arg.append("\"");
          }
          unitTest.append(arg);
          // test.append("\"");
          unitTest.append(",");
        }
        if (args.getIds().length > 0) {
          unitTest.replace(unitTest.length() - 1, unitTest.length(),
              "");
        }
        unitTest.append(");\n");
View Full Code Here

        }
        ScriptableObject table = null;
        try {
          // make sure the player is allowed to join another table
          String tablesStringJson = getOpenAndActiveTables(userName);
          NativeArray tables = (NativeArray) ge
              .execute(tablesStringJson);
          if (tables.size() >= MAX_TABLES) {
            // tell the player they are not allowed to join another
            // table
            json.append("\"messages\":[\"You are already in "
                + MAX_TABLES + " active tables.\"],");
          } else {
            ScriptableObject player = getPlayer(userName);
            final Long mementoId = getMementoId(parameters);
            table = getTable(tableId, mementoId);

            ScriptableObject joinResult = join(table, player,
                armyName);

            if (!(Boolean) joinResult.get("success")) {
              // TODO give joinResult to the user
            }

          }
        } catch (GameEngineException gee) {
          // GameEngineException
          mailUnitTest(createUnitTest(table));
          throw gee;
        }
        //
        json.append("\"id\":");
        json.append(tableId);
      }
        break;

      case CREATE_TABLE: {
        if (userName != null && !userName.equals("")) {

          ScriptableObject player = getPlayer(userName);
          final String maxPlayers = (String) getParameter(
              "maxPlayers", parameters);
          final String armyName = (String) getParameter("armyName",
              parameters);
          final String activations = (String) getParameter(
              "activations", parameters);
          final String startingDisks = (String) getParameter(
              "startingDisks", parameters);
          final String reinforcements = (String) getParameter(
              "reinforcements", parameters);
          final String alignmentRestriction = (String) getParameter(
              "alignmentRestriction", parameters);
          final String maxPoints = (String) getParameter("maxPoints",
              parameters);
          final String scenario = (String) getParameter("scenario",
              parameters);

          ScriptableObject table = null;
          try {
            // make sure the player is allowed to create a new table
            String tablesStringJson = getOpenAndActiveTables(userName);
            NativeArray tables = (NativeArray) ge
                .execute(tablesStringJson);
            if (tables.size() >= 4) {
              // tell the player they are not allowed to create
              // more
              // tables

              json.append("\"messages\":[\"You are already in 4 active tables.\"]");

            } else {
              table = createTable(maxPlayers, maxPoints,
                  activations, startingDisks, reinforcements,
                  alignmentRestriction, scenario);

              ScriptableObject joinResult = join(table, player,
                  armyName);

              Object success = joinResult.get("success");
              if ((Boolean) success) {

                final Long tableId = getId(table);

                json.append("\"id\":");
                json.append(tableId);
              } else {
                json.append(",\"messages\":[");
                // TODO give joinResult to the user
                NativeArray messages = (NativeArray) joinResult
                    .get("messages");
                for (Object message : messages) {
                  json.append("\"" + message + "\",");
                }
                json.append("]");
              }
            }

          } catch (GameEngineException gee) {
            // GameEngineException
            mailUnitTest(createUnitTest(table));
            throw gee;
          }

        }
      }
        break;
      case GET_ALL_TABLES: {
        json.append("\"openTables\":");

        // only get open tables
        String fd = getOpenTables();
        json.append(fd);

        json.append(",\"activeTables\":");

        // only get open tables
        fd = getActiveTables();
        json.append(fd);

        final ScriptableObject player = getPlayer(userName);

        if (player != null) {
          json.append(",\"player\":");
          json.append(stringify(player));
        }
      }
        break;
      case CREATE_DISK: {

        final String name = (String) getParameter("name", parameters);

        if (name == null || name.equals("")) {
          break;
        }

        final String type = (String) getParameter("type", parameters);

        final Integer attack = Integer.parseInt((String) getParameter(
            "attack", parameters));
        final Integer defense = Integer.parseInt((String) getParameter(
            "defense", parameters));
        final Integer toughness = Integer
            .parseInt((String) getParameter("toughness", parameters));
        final Integer movement = Integer
            .parseInt((String) getParameter("movement", parameters));
        final Integer wounds = Integer.parseInt((String) getParameter(
            "wounds", parameters));
        final Boolean flying = getParameter("flying", parameters) == null ? false
            : Boolean.parseBoolean((String) getParameter("flying",
                parameters));
        final Boolean swashbuckler = getParameter("swashbuckler",
            parameters) == null ? false : Boolean
            .parseBoolean((String) getParameter("swashbuckler",
                parameters));
        final Boolean archer = getParameter("archer", parameters) == null ? false
            : Boolean.parseBoolean((String) getParameter("archer",
                parameters));

        final Integer arrows = getParameter("arrows", parameters) == null ? 0
            : Integer.parseInt((String) getParameter("arrows",
                parameters));

        final Integer bolts = getParameter("bolts", parameters) == null ? 0
            : Integer.parseInt((String) getParameter("bolts",
                parameters));

        final Integer fireballs = getParameter("fireballs", parameters) == null ? 0
            : Integer.parseInt((String) getParameter("fireballs",
                parameters));

        final Integer boulders = getParameter("boulders", parameters) == null ? 0
            : Integer.parseInt((String) getParameter("boulders",
                parameters));

        final Integer spellcaster = Integer
            .parseInt((String) getParameter("spellcaster",
                parameters));

        final Integer limit = Integer.parseInt((String) getParameter(
            "limit", parameters));

        String parameter = (String) getParameter("missileImmunity",
            parameters);
        final Boolean missileImmunity = getParameter("missileImmunity",
            parameters) == null ? false : Boolean
            .parseBoolean(parameter);

        final Boolean firstblow = getParameter("firstblow", parameters) == null ? false
            : Boolean.parseBoolean((String) getParameter(
                "firstblow", parameters));

        final Integer cost = Integer.parseInt((String) getParameter(
            "cost", parameters));
        final String faction = (String) getParameter("faction",
            parameters);
        final String alignment = (String) getParameter("alignment",
            parameters);
        final String diameter = (String) getParameter("diameter",
            parameters);
        final String description = (String) getParameter("description",
            parameters);
        final String price = (String) getParameter("price", parameters);

        // name, attack, defense, toughness, movement, wounds, flying,
        // swashbuckler, archer, arrows, bolts, fireballs, boulders,
        // missileImmunity, firstblow, spellcaster, cost, faction,
        // alignment, diameter, description, price
        try {
          createDisk(name, type, attack, defense, toughness,
              movement, wounds, flying, swashbuckler, archer,
              arrows, bolts, fireballs, boulders,
              missileImmunity, firstblow, spellcaster, limit,
              cost, faction, alignment, diameter, description,
              price);

          // redirect to a better place
          response.sendRedirect("/battledisks/disk.jsp#!" + name);
        } catch (GameEngineException gee) {
          // GameEngineException CREATE_DISK
          throw new APIException(gee);
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
        break;
      case LOG_IN: {
        try {
          final ScriptableObject player = getPlayer(userName);
          if (player == null) {
            createPlayer(userName);
          }
          response.sendRedirect("/battledisks/profile.html");
          return null;
        } catch (GameEngineException gee) {
          throw new APIException(gee);
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
        break;
      case PROFILE: {

        try {
          final ScriptableObject player = getPlayer(userName);

          if (player != null) {
            json.append("\"player\":");
            String f = getOpenAndActiveTables(userName);

            NativeArray na = (NativeArray) ge.execute(f);
            player.put("activeTables", player, na);

            json.append(stringify(player));
            json.append(",");
          }
View Full Code Here

    }

    public Object getValue() {
        Object val = getNode();
        if (val instanceof NativeArray) {
            NativeArray arr = (NativeArray)val;
            List list = new LinkedList();
            int len = (int)arr.jsGet_length();
            for (int i = 0; i < len; i++) {
                Object obj = arr.get(i, arr);
                if (obj == Undefined.instance) {
                    obj = null;
                }
                list.add(obj);
            }
View Full Code Here

                value = unwrap(value);
                field.setValue(value);
            } else if (sub instanceof Repeater) {
                Repeater repeater = (Repeater)sub;
                if (value instanceof NativeArray) {
                    NativeArray arr = (NativeArray)value;
                    Object length = getProperty(arr, "length");
                    int len = ((Number)length).intValue();
                    for (int i = repeater.getSize(); i >= len; --i) {
                        repeater.removeRow(i);
                    }
                    for (int i = 0; i < len; i++) {
                        Object elemValue = getProperty(arr, i);
                        if (elemValue instanceof Scriptable) {
                            Scriptable s = (Scriptable)elemValue;
                            Object[] ids = s.getIds();
                            ScriptableWidget wid = wrap(repeater.getRow(i));
                            for (int j = 0; j < ids.length; j++) {
                                String idStr = ids[j].toString();
                                wid.put(idStr, wid, getProperty(s, idStr));
                            }
                        }
                    }
                    return;
                }
            } else if (sub instanceof MultiValueField) {
                MultiValueField field = (MultiValueField)sub;
                Object[] values = null;
                if (value instanceof NativeArray) {
                    NativeArray arr = (NativeArray)value;
                    Object length = getProperty(arr, "length");
                    int len = ((Number)length).intValue();
                    values = new Object[len];
                    for (int i = 0; i < len; i++) {
                        Object elemValue = getProperty(arr, i);
View Full Code Here

          Object resultObject = executeScript( scriptable, scope, script, cx );
          if ( oldStyleOutputs ) {
            if ( resultObject instanceof org.mozilla.javascript.NativeArray ) {
              // we need to convert this to an ArrayList
              NativeArray jsArray = (NativeArray) resultObject;
              int length = (int) jsArray.getLength();
              for ( int i = 0; i < length; i++ ) {
                Object value = jsArray.get( i, scriptable );
                if ( i < outputNames.size() ) {
                  jscriptAction.getOutput( outputNames.get( i ).toString() )
                      .setValue( convertWrappedJavaObject( value ) );
                } else {
                  break;
View Full Code Here

    }

    @Test
    @SuppressWarnings("unchecked")
    public void shouldParseHeterogeneousJsonArray() throws Exception {
        NativeArray actual = (NativeArray) parser
                .parseValue("[ \"hello\" , 3, null, [false] ]");
        assertEquals("hello", actual.get(0, actual));
        assertEquals(3, actual.get(1, actual));
        assertEquals(null, actual.get(2, actual));

        NativeArray innerArr = (NativeArray) actual.get(3, actual);
        assertEquals(false, innerArr.get(0, innerArr));

        assertEquals(4, actual.getLength());
    }
View Full Code Here

TOP

Related Classes of org.mozilla.javascript.NativeArray

Copyright © 2018 www.massapicom. 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.