01: package org.drools.eclipse.dsl.editor;
02:
03: import java.io.Reader;
04:
05: import org.drools.lang.dsl.DSLMappingFile;
06: import org.drools.lang.dsl.DefaultExpander;
07: import org.eclipse.jface.text.IDocument;
08:
09: public class DSLtoDRLDocument extends TransformedDocument {
10:
11: private DSLtoDRLRuleViewer viewer;
12:
13: public DSLtoDRLDocument(IDocument dslDocument,
14: DSLtoDRLRuleViewer viewer) {
15: super (dslDocument);
16: this .viewer = viewer;
17: }
18:
19: protected String transformInput(String content) {
20: DefaultExpander expander = new DefaultExpander();
21: try {
22: Reader reader = DSLAdapter.getDSLContent(content, viewer
23: .getResource());
24: DSLMappingFile mapping = new DSLMappingFile();
25: mapping.parseAndLoad(reader);
26: reader.close();
27: expander.addDSLMapping(mapping.getMapping());
28: return expander.expand(content);
29: } catch (Throwable t) {
30: //viewer.handleError(t);
31: return content;
32: }
33:
34: }
35:
36: }
|