use of org.drools.template.parser.DefaultTemplateContainer in project drools by kiegroup.
the class ExternalSpreadsheetCompiler method compile.
public String compile(final InputStream xlsStream, final String worksheetName, final InputStream templateStream, int startRow, int startCol) {
TemplateContainer tc = new DefaultTemplateContainer(templateStream);
closeStream(templateStream);
return compile(xlsStream, worksheetName, new TemplateDataListener(startRow, startCol, tc));
}
use of org.drools.template.parser.DefaultTemplateContainer in project drools by kiegroup.
the class DataProviderCompiler method compile.
/**
* Generates DRL from a data provider for the spreadsheet data and templates.
*
* @param dataProvider the data provider for the spreadsheet data
* @param templateStream the InputStream for reading the templates
* @return the generated DRL text as a String
*/
public String compile(final DataProvider dataProvider, final InputStream templateStream, boolean replaceOptionals) {
DefaultTemplateContainer tc = new DefaultTemplateContainer(templateStream, replaceOptionals);
closeStream(templateStream);
return compile(dataProvider, new TemplateDataListener(tc));
}
use of org.drools.template.parser.DefaultTemplateContainer in project drools by kiegroup.
the class ObjectDataCompiler method compile.
/**
* Compile templates, substituting from a collection of maps or objects
* into the given template.
*
* @param objs objs the collection of maps or objects
* @param templateStream the template as a stream
* @return the expanded rules as a string
*/
public String compile(final Collection<?> objs, final InputStream templateStream) {
TemplateContainer tc = new DefaultTemplateContainer(templateStream);
closeStream(templateStream);
return compile(new ObjectDataProvider(tc, objs), new TemplateDataListener(tc));
}
use of org.drools.template.parser.DefaultTemplateContainer in project drools by kiegroup.
the class ResultSetGenerator method compile.
/**
* Generates DRL from a data provider for the spreadsheet data and templates.
*
* @param rs the resultset for the table data
* @param templateStream the InputStream for reading the templates
* @return the generated DRL text as a String
*/
public String compile(final ResultSet rs, final InputStream templateStream) {
TemplateContainer tc = new DefaultTemplateContainer(templateStream);
closeStream(templateStream);
return compile(rs, new TemplateDataListener(tc));
}
use of org.drools.template.parser.DefaultTemplateContainer in project drools by kiegroup.
the class DataProviderCompilerTest method testCompilerMaps.
@Test
public void testCompilerMaps() throws Exception {
Collection<Map<String, Object>> maps = new ArrayList<Map<String, Object>>();
final ObjectDataCompiler converter = new ObjectDataCompiler();
InputStream templateStream = this.getClass().getResourceAsStream("/templates/rule_template_1.drl");
TemplateContainer tc = new DefaultTemplateContainer(templateStream);
Column[] columns = tc.getColumns();
for (String[] row : rows) {
Map<String, Object> map = new HashMap<String, Object>();
for (int icol = 0; icol < columns.length; icol++) {
Object value = row[icol];
if (value != null) {
map.put(columns[icol].getName(), value);
}
}
maps.add(map);
}
templateStream = this.getClass().getResourceAsStream("/templates/rule_template_1.drl");
final String drl = converter.compile(maps, templateStream);
Assertions.assertThat(EXPECTED_RULES.toString()).isEqualToIgnoringWhitespace(drl);
}
Aggregations