Search in sources :

Example 11 with DSLTokenizedMappingFile

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);
    }
}
Also used : ValidationMessage(org.guvnor.common.services.shared.validation.model.ValidationMessage) ArrayList(java.util.ArrayList) StringReader(java.io.StringReader) IOException(java.io.IOException) DSLTokenizedMappingFile(org.drools.compiler.lang.dsl.DSLTokenizedMappingFile)

Example 12 with DSLTokenizedMappingFile

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;
}
Also used : Path(org.uberfire.java.nio.file.Path) Path(org.uberfire.java.nio.file.Path) ArrayList(java.util.ArrayList) IOException(java.io.IOException) DSLMappingFile(org.drools.compiler.lang.dsl.DSLMappingFile) StringReader(java.io.StringReader) DSLTokenizedMappingFile(org.drools.compiler.lang.dsl.DSLTokenizedMappingFile)

Example 13 with DSLTokenizedMappingFile

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;
}
Also used : Path(org.uberfire.java.nio.file.Path) Path(org.uberfire.java.nio.file.Path) ArrayList(java.util.ArrayList) IOException(java.io.IOException) DSLMappingFile(org.drools.compiler.lang.dsl.DSLMappingFile) StringReader(java.io.StringReader) DSLTokenizedMappingFile(org.drools.compiler.lang.dsl.DSLTokenizedMappingFile)

Example 14 with DSLTokenizedMappingFile

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;
    }
}
Also used : XmlPackageReader(org.drools.compiler.compiler.xml.XmlPackageReader) Reader(java.io.Reader) XmlChangeSetReader(org.drools.core.xml.XmlChangeSetReader) StringReader(java.io.StringReader) DSLTokenizedMappingFile(org.drools.compiler.lang.dsl.DSLTokenizedMappingFile)

Example 15 with DSLTokenizedMappingFile

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 ");
    }
}
Also used : StringReader(java.io.StringReader) StringReader(java.io.StringReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) DSLMappingEntry(org.drools.compiler.lang.dsl.DSLMappingEntry) IOException(java.io.IOException) DSLTokenizedMappingFile(org.drools.compiler.lang.dsl.DSLTokenizedMappingFile) Test(org.junit.Test)

Aggregations

DSLTokenizedMappingFile (org.drools.compiler.lang.dsl.DSLTokenizedMappingFile)25 StringReader (java.io.StringReader)24 IOException (java.io.IOException)20 Test (org.junit.Test)15 Reader (java.io.Reader)14 InputStreamReader (java.io.InputStreamReader)13 DSLMappingEntry (org.drools.compiler.lang.dsl.DSLMappingEntry)11 ArrayList (java.util.ArrayList)9 DSLMappingFile (org.drools.compiler.lang.dsl.DSLMappingFile)7 DefaultExpander (org.drools.compiler.lang.dsl.DefaultExpander)7 Path (org.uberfire.java.nio.file.Path)5 Expander (org.drools.compiler.lang.Expander)2 DSLSentence (org.drools.workbench.models.datamodel.rule.DSLSentence)2 Iterator (java.util.Iterator)1 XmlPackageReader (org.drools.compiler.compiler.xml.XmlPackageReader)1 DSLMapping (org.drools.compiler.lang.dsl.DSLMapping)1 DefaultExpanderResolver (org.drools.compiler.lang.dsl.DefaultExpanderResolver)1 XmlChangeSetReader (org.drools.core.xml.XmlChangeSetReader)1 DSLVariableValue (org.drools.workbench.models.datamodel.rule.DSLVariableValue)1 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)1