Esempio n. 1
0
  public SingleLineCommand2(RegexConcat pattern) {
    if (pattern == null) {
      throw new IllegalArgumentException();
    }
    if (pattern.getPattern().startsWith("^") == false
        || pattern.getPattern().endsWith("$") == false) {
      throw new IllegalArgumentException("Bad pattern " + pattern.getPattern());
    }

    this.pattern = pattern;
  }
Esempio n. 2
0
 public final CommandControl isValid(BlocLines lines) {
   if (lines.size() != 1) {
     return CommandControl.NOT_OK;
   }
   lines = lines.removeInnerComments();
   if (isCommandForbidden()) {
     return CommandControl.NOT_OK;
   }
   final String line = StringUtils.trin(lines.getFirst499());
   final boolean result = pattern.match(line);
   if (result) {
     actionIfCommandValid();
   }
   return result ? CommandControl.OK : CommandControl.NOT_OK;
 }
Esempio n. 3
0
  public final CommandExecutionResult execute(S system, BlocLines lines) {
    if (lines.size() != 1) {
      throw new IllegalArgumentException();
    }
    lines = lines.removeInnerComments();
    final String line = StringUtils.trin(lines.getFirst499());
    if (isForbidden(line)) {
      return CommandExecutionResult.error("Forbidden line " + line);
    }

    final RegexResult arg = pattern.matcher(line);
    if (arg == null) {
      return CommandExecutionResult.error("Cannot parse line " + line);
    }
    if (system instanceof PSystemError) {
      return CommandExecutionResult.error("PSystemError cannot be cast");
    }
    // System.err.println("lines="+lines);
    // System.err.println("pattern="+pattern.getPattern());
    return executeArg(system, arg);
  }
Esempio n. 4
0
 public String[] getDescription() {
   return new String[] {pattern.getPattern()};
 }