use of org.drools.compiler.lang.dsl.DSLTokenizedMappingFile in project drools-wb by kiegroup.
the class DSLTextEditorServiceImpl method doValidation.
private List<ValidationMessage> doValidation(final String content) {
final List<ValidationMessage> validationMessages = new ArrayList<ValidationMessage>();
final DSLTokenizedMappingFile dslLoader = new DSLTokenizedMappingFile();
try {
if (!dslLoader.parseAndLoad(new StringReader(content))) {
validationMessages.addAll(makeValidationMessages(dslLoader));
}
return validationMessages;
} catch (IOException e) {
throw ExceptionUtilities.handleException(e);
}
}
use of org.drools.compiler.lang.dsl.DSLTokenizedMappingFile in project drools-wb by kiegroup.
the class GuidedRuleDSLRSourceService method getDSLMappingFiles.
private List<DSLMappingFile> getDSLMappingFiles(final Path path) {
final List<DSLMappingFile> dsls = new ArrayList<DSLMappingFile>();
final org.uberfire.backend.vfs.Path vfsPath = Paths.convert(path);
final org.uberfire.backend.vfs.Path packagePath = moduleService.resolvePackage(vfsPath).getPackageMainResourcesPath();
final org.uberfire.java.nio.file.Path nioPackagePath = Paths.convert(packagePath);
final Collection<Path> dslPaths = fileDiscoveryService.discoverFiles(nioPackagePath, FILTER_DSLS);
for (final org.uberfire.java.nio.file.Path dslPath : dslPaths) {
final String dslDefinition = ioService.readAllString(dslPath);
final DSLTokenizedMappingFile dslFile = new DSLTokenizedMappingFile();
try {
if (dslFile.parseAndLoad(new StringReader(dslDefinition))) {
dsls.add(dslFile);
} else {
logger.error("Unable to parse DSL definition: " + dslDefinition);
}
} catch (IOException ioe) {
logger.error(ioe.getMessage());
}
}
return dsls;
}
use of org.drools.compiler.lang.dsl.DSLTokenizedMappingFile in project drools-wb by kiegroup.
the class GuidedRuleTemplateSourceService method getDSLMappingFiles.
private List<DSLMappingFile> getDSLMappingFiles(final Path path) {
final List<DSLMappingFile> dsls = new ArrayList<DSLMappingFile>();
final org.uberfire.backend.vfs.Path vfsPath = Paths.convert(path);
final org.uberfire.backend.vfs.Path packagePath = moduleService.resolvePackage(vfsPath).getPackageMainResourcesPath();
final org.uberfire.java.nio.file.Path nioPackagePath = Paths.convert(packagePath);
final Collection<Path> dslPaths = fileDiscoveryService.discoverFiles(nioPackagePath, FILTER_DSLS);
for (final org.uberfire.java.nio.file.Path dslPath : dslPaths) {
final String dslDefinition = ioService.readAllString(dslPath);
final DSLTokenizedMappingFile dslFile = new DSLTokenizedMappingFile();
try {
if (dslFile.parseAndLoad(new StringReader(dslDefinition))) {
dsls.add(dslFile);
} else {
logger.error("Unable to parse DSL definition: " + dslDefinition);
}
} catch (IOException ioe) {
logger.error(ioe.getMessage());
}
}
return dsls;
}
use of org.drools.compiler.lang.dsl.DSLTokenizedMappingFile in project drools by kiegroup.
the class KnowledgeBuilderImpl method addDsl.
public void addDsl(Resource resource) throws IOException {
this.resource = resource;
DSLTokenizedMappingFile file = new DSLTokenizedMappingFile();
Reader reader = null;
try {
reader = resource.getReader();
if (!file.parseAndLoad(reader)) {
this.results.addAll(file.getErrors());
}
if (this.dslFiles == null) {
this.dslFiles = new ArrayList<DSLTokenizedMappingFile>();
}
this.dslFiles.add(file);
} finally {
if (reader != null) {
reader.close();
}
this.resource = null;
}
}
use of org.drools.compiler.lang.dsl.DSLTokenizedMappingFile in project drools by kiegroup.
the class DSLTokenizedMappingFileTest method testParseFileWithBrackets.
@Test
public void testParseFileWithBrackets() {
String file = "[when]ATTRIBUTE \"{attr}\" IS IN [{list}]=Attribute( {attr} in ({list}) )";
try {
final Reader reader = new StringReader(file);
this.file = new DSLTokenizedMappingFile();
final boolean parsingResult = this.file.parseAndLoad(reader);
reader.close();
assertTrue(this.file.getErrors().toString(), parsingResult);
assertTrue(this.file.getErrors().isEmpty());
assertEquals(1, this.file.getMapping().getEntries().size());
DSLMappingEntry entry = (DSLMappingEntry) this.file.getMapping().getEntries().get(0);
assertEquals(DSLMappingEntry.CONDITION, entry.getSection());
assertEquals(DSLMappingEntry.EMPTY_METADATA, entry.getMetaData());
assertEquals(lookbehind + "ATTRIBUTE\\s+\"(.*?)\"\\s+IS\\s+IN\\s+[(.*?)](?=\\W|$)", entry.getKeyPattern().toString());
// Attribute( {attr} in ({list}) )
assertEquals("Attribute( {attr} in ({list}) )", entry.getValuePattern());
} catch (final IOException e) {
e.printStackTrace();
fail("Should not raise exception ");
}
}
Aggregations