Esempio n. 1
0
  @Override
  public LogQueryCommand parse(LogQueryContext context, String commandString) {
    if (commandString.trim().endsWith(","))
      throw new LogQueryParseException("missing-field", commandString.length());

    QueryTokens tokens = QueryTokenizer.tokenize(commandString);
    List<String> fields = new ArrayList<String>();
    String csvPath = tokens.firstArg();

    List<QueryToken> fieldTokens = tokens.subtokens(2, tokens.size());
    for (QueryToken t : fieldTokens) {
      StringTokenizer tok = new StringTokenizer(t.token, ",");
      while (tok.hasMoreTokens()) fields.add(tok.nextToken().trim());
    }

    if (fields.size() == 0)
      throw new LogQueryParseException("missing-field", commandString.length());

    File csvFile = new File(csvPath);
    if (csvFile.exists())
      throw new IllegalStateException("csv file exists: " + csvFile.getAbsolutePath());

    try {
      if (csvFile.getParentFile() != null) csvFile.getParentFile().mkdirs();
      return new OutputCsv(csvFile, fields);
    } catch (IOException e) {
      throw new LogQueryParseException("io-error", -1, e.getMessage());
    }
  }
Esempio n. 2
0
  @Override
  public LogQueryCommand parse(LogQueryContext context, String commandString) {
    // find assignment symbol
    int p = QueryTokenizer.findKeyword(commandString, "=");
    if (p < 0) throw new LogQueryParseException("assign-token-not-found", commandString.length());

    String field = commandString.substring(COMMAND.length(), p).trim();
    String exprToken = commandString.substring(p + 1).trim();

    if (field.isEmpty())
      throw new LogQueryParseException("field-name-not-found", commandString.length());

    if (exprToken.isEmpty())
      throw new LogQueryParseException("expression-not-found", commandString.length());

    Expression expr = ExpressionParser.parse(exprToken);
    return new Eval(field, expr);
  }