示例#1
0
  @Override
  public Object childEvaluate(Parser parser, String functionName, List<Object> parameters)
      throws ParserException {

    Object numArgs = parser.getVariable("macro.args.num");
    int argCount = 0;

    if (numArgs instanceof BigDecimal) {
      argCount = ((BigDecimal) numArgs).intValue();
    }

    if (functionName.equals("argCount")) {
      return BigDecimal.valueOf(argCount);
    }

    if (parameters.size() != 1 || !(parameters.get(0) instanceof BigDecimal)) {
      throw new ParserException(I18N.getText("macro.function.args.incorrectParam", "arg"));
    }

    int argNo = ((BigDecimal) parameters.get(0)).intValue();

    if (argCount == 0 && argNo == 0) {
      return parser.getVariable("macro.args");
    }

    if (argNo < 0 || argNo >= argCount) {
      throw new ParserException(
          I18N.getText("macro.function.args.outOfRange", "arg", argNo, argCount - 1));
    }

    return parser.getVariable("macro.args." + argNo);
  }
示例#2
0
  /**
   * Gets the label of the token
   *
   * @param parser The parser that called the Object.
   * @param args The arguments passed.
   * @return the name of the token.
   * @throws ParserException when an error occurs.
   */
  private Object getLabel(Parser parser, List<Object> args) throws ParserException {
    Token token;

    if (args.size() == 1) {
      if (!MapTool.getParser().isMacroTrusted()) {
        throw new ParserException(I18N.getText("macro.function.general.noPermOther", "getLabel"));
      }

      token = FindTokenFunctions.findToken(args.get(0).toString(), null);
      if (token == null) {
        throw new ParserException(
            I18N.getText(
                "macro.function.general.unknownToken", "getLabel", args.get(0).toString()));
      }
    } else if (args.isEmpty()) {
      MapToolVariableResolver res = (MapToolVariableResolver) parser.getVariableResolver();
      token = res.getTokenInContext();
      if (token == null) {
        throw new ParserException(
            I18N.getText("macro.function.general.noImpersonated", "getLabel"));
      }
    } else {
      throw new ParserException(
          I18N.getText("macro.function.general.tooManyParam", "getLabel", 1, args.size()));
    }
    return getLabel(token);
  }
示例#3
0
  /**
   * Sets the label of the token.
   *
   * @param parser The parser that called the Object.
   * @param args The arguments passed.
   * @return the new name of the token.
   * @throws ParserException when an error occurs.
   */
  private Object setLabel(Parser parser, List<Object> args) throws ParserException {
    Token token;

    if (args.size() == 2) {
      if (!MapTool.getParser().isMacroTrusted()) {
        throw new ParserException(I18N.getText("macro.function.general.noPermOther", "setLabel"));
      }
      token = FindTokenFunctions.findToken(args.get(1).toString(), null);
      if (token == null) {
        throw new ParserException(
            I18N.getText(
                "macro.function.general.unknownToken", "setLabel", args.get(1).toString()));
      }
    } else if (args.size() == 1) {
      MapToolVariableResolver res = (MapToolVariableResolver) parser.getVariableResolver();
      token = res.getTokenInContext();
      if (token == null) {
        throw new ParserException(
            I18N.getText("macro.function.general.noImpersonated", "setLabel"));
      }
    } else if (args.isEmpty()) {
      throw new ParserException(
          I18N.getText("macro.function.general.notEnoughParam", "setLabel", 1, args.size()));
    } else {
      throw new ParserException(
          I18N.getText("macro.function.general.tooManyParam", "setLabel", 2, args.size()));
    }
    setLabel(token, args.get(0).toString());
    Zone zone = MapTool.getFrame().getCurrentZoneRenderer().getZone();
    MapTool.serverCommand().putToken(zone.getId(), token);
    zone.putToken(token);
    return args.get(0);
  }