Beispiel #1
0
  @Override
  @SuppressWarnings("unchecked")
  protected void evaluationRequest(Script script) {
    super.evaluationRequest(script);

    Object property = null;

    if (getValueOptions() != null) {

      if (getValueOptions().contains("endings")) {
        property = script.getProperty("endings");
      }

      if (property != null) {
        getFileFilter().setAcceptedEndings((ArrayList<String>) property);
      }

      property = null;

      if (getValueOptions().contains("description")) {
        property = script.getProperty("description");
      }

      if (property != null) {
        getFileFilter().setDescription((String) property);
      }
    }
  }
Beispiel #2
0
  /**
   * Process a script against a single input file.
   *
   * @param s script to execute.
   * @param reader input file.
   * @param pw output sink.
   */
  private void processReader(Script s, BufferedReader reader, PrintWriter pw) throws IOException {
    String line;
    String lineCountName = "count";
    s.setProperty(lineCountName, BigInteger.ZERO);
    String autoSplitName = "split";
    s.setProperty("out", pw);

    try {
      InvokerHelper.invokeMethod(s, "begin", null);
    } catch (MissingMethodException mme) {
      // ignore the missing method exception
      // as it means no begin() method is present
    }

    while ((line = reader.readLine()) != null) {
      s.setProperty("line", line);
      s.setProperty(lineCountName, ((BigInteger) s.getProperty(lineCountName)).add(BigInteger.ONE));

      if (autoSplit) {
        s.setProperty(autoSplitName, line.split(splitPattern));
      }

      Object o = s.run();

      if (autoOutput && o != null) {
        pw.println(o);
      }
    }

    try {
      InvokerHelper.invokeMethod(s, "end", null);
    } catch (MissingMethodException mme) {
      // ignore the missing method exception
      // as it means no end() method is present
    }
  }