private GuidedDecisionTableGeneratorListener parseAssets(
      final Path path, final ConversionResult result) {

    final List<DataListener> listeners = new ArrayList<DataListener>();
    final GuidedDecisionTableGeneratorListener listener =
        new GuidedDecisionTableGeneratorListener(result);
    listeners.add(listener);

    final ExcelParser parser = new ExcelParser(listeners);
    final InputStream stream = ioService.newInputStream(Paths.convert(path));

    try {
      parser.parseFile(stream);
    } finally {
      try {
        stream.close();
      } catch (IOException ioe) {
        result.addMessage(ioe.getMessage(), ConversionMessageType.ERROR);
      }
    }
    return listener;
  }
Пример #2
0
  @Test
  public void testPropertiesWithWhiteSpaceXLS() {

    final List<DataListener> listeners = new ArrayList<DataListener>();
    final DefaultRuleSheetListener listener = new DefaultRuleSheetListener();
    listeners.add(listener);

    final ExcelParser parser = new ExcelParser(listeners);
    final InputStream is = this.getClass().getResourceAsStream("PropertiesWithWhiteSpace.xls");

    parser.parseFile(is);

    listener.getProperties();

    final String rulesetName =
        listener.getProperties().getSingleProperty(DefaultRuleSheetListener.RULESET_TAG);
    assertNotNull(rulesetName);
    assertEquals("Properties", rulesetName);

    final List<Import> importList =
        RuleSheetParserUtil.getImportList(
            listener.getProperties().getProperty(DefaultRuleSheetListener.IMPORT_TAG));
    assertNotNull(importList);
    assertEquals(1, importList.size());
    assertEquals("java.util.List", importList.get(0).getClassName());

    final List<Global> variableList =
        RuleSheetParserUtil.getVariableList(
            listener.getProperties().getProperty(DefaultRuleSheetListener.VARIABLES_TAG));
    assertNotNull(variableList);
    assertEquals(1, variableList.size());
    assertEquals("java.util.List", variableList.get(0).getClassName());
    assertEquals("list", variableList.get(0).getIdentifier());

    final List<String> functions =
        listener.getProperties().getProperty(DefaultRuleSheetListener.FUNCTIONS_TAG);
    assertNotNull(functions);
    assertEquals(1, functions.size());
    assertEquals("A function", functions.get(0));

    final List<String> queries =
        listener.getProperties().getProperty(DefaultRuleSheetListener.QUERIES_TAG);
    assertNotNull(queries);
    assertEquals(1, queries.size());
    assertEquals("A query", queries.get(0));

    final List<String> declarations =
        listener.getProperties().getProperty(DefaultRuleSheetListener.DECLARES_TAG);
    assertNotNull(declarations);
    assertEquals(1, declarations.size());
    assertEquals("A declared type", declarations.get(0));

    final String sequentialFlag =
        listener.getProperties().getSingleProperty(DefaultRuleSheetListener.SEQUENTIAL_FLAG);
    assertNotNull(sequentialFlag);
    assertEquals("false", sequentialFlag);

    final String escapeQuotesFlag =
        listener.getProperties().getSingleProperty(DefaultRuleSheetListener.ESCAPE_QUOTES_FLAG);
    assertNotNull(escapeQuotesFlag);
    assertEquals("false", escapeQuotesFlag);
  }