Ignore:
Timestamp:
06/15/14 08:59:05 (10 years ago)
Author:
hkaulbersch
Message:

Automatic PDF Generation from .fo files now works

File:
1 edited

Legend:

Unmodified
Added
Removed
  • v2/trunk/de.ugoe.cs.swe.bnftools.ebnf/src/de/ugoe/cs/swe/bnftools/generator/EbnfGenerator.xtend

    r70 r72  
    2424import org.eclipse.xtext.generator.IFileSystemAccessExtension 
    2525import java.io.PrintWriter 
     26 
    2627/** 
    2728 * Generates code from your model files on save. 
     
    3031 */ 
    3132class EbnfGenerator implements IGenerator { 
     33 
    3234        //generation of the xsl-file 
    3335        override void doGenerate(Resource resource, IFileSystemAccess fsa) { 
    34                 var String workspacePath =WorkspaceResolver.getWorkspace(); 
     36                var String workspacePath = WorkspaceResolver.getWorkspace(); 
    3537                for (e : resource.allContents.toIterable.filter(EtsiBnf)) { 
    36                         if (e.bnfEntry.size!=0) { 
    37                                  fsa.generateFile(e.name + ".fo", e.compile) 
    38                                   
    39                                  //generate pdf 
    40                                  var uri = (fsa as IFileSystemAccessExtension2).getURI(e.name+".fo"); 
    41                                  var String fullUri = workspacePath+uri.path.substring(10,uri.path.length); 
    42                                 System.out.println(workspacePath+uri.path.substring(10,uri.path.length)); 
     38                        if (e.bnfEntry.size != 0) { 
     39                                fsa.generateFile(e.name + ".fo", e.compile) 
     40 
     41                                //generate pdf 
     42                                var uri = (fsa as IFileSystemAccessExtension2).getURI(e.name + ".fo"); 
     43                                var String fullUri = workspacePath + uri.path.substring(10, uri.path.length); 
     44                                System.out.println(workspacePath + uri.path.substring(10, uri.path.length)); 
    4345                                var File file = new File(fullUri); 
    44                                 System.out.println(file.exists); 
    45 //                               System.out.println(uri.toString()); 
    46                                   
    47                                   
    48 //                               System.out.println(file.exists); 
    49                                  
    50 //                               foToPdf.createPdfFromFo(file,aPath.substring(0,aPath.length-3)); 
     46                                System.out.println(file.exists+ "," + fullUri.substring(0, fullUri.length - 3)); 
     47 
     48                                if (file.exists) { 
     49                                        foToPdf.createPdfFromFo(fullUri.substring(0, fullUri.length - 3)); 
     50                                } 
    5151                        } 
    5252                } 
     
    5454 
    5555        // compile the different entities of the Bnf----------------------------------------------------------------------------- 
    56         def compile(EtsiBnf bnf)  
    57         ''' 
     56        def compile(EtsiBnf bnf) ''' 
    5857        <?xml version="1.0"?> 
    5958        <!-- fop «bnf.name».xml -rtf «bnf.name».rtf --> 
    6059        <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"> 
    61  
     60         
    6261                <fo:layout-master-set> 
    63                         <fo:simple-page-master master-name="A4" page-width="210mm" page-height="297mm"> 
    64                         <fo:region-body region-name="xsl-region-body"  margin="2cm"/> 
    65                 </fo:simple-page-master> 
     62                                <fo:simple-page-master master-name="A4" page-width="210mm" page-height="297mm"> 
     63                                                <fo:region-body region-name="xsl-region-body"  margin="2cm"/> 
     64                                                </fo:simple-page-master> 
    6665                </fo:layout-master-set> 
    6766         
     
    6968                        <fo:flow flow-name="xsl-region-body" font-family="verdana"> 
    7069                                 
    71                                 <fo:block span="all"  text-align="center" text-indent="1em" font-family="Arial" font-size="20pt" font-weight="bold" background-color="#EEEEEE" line-height="20mm">«bnf.name»</fo:block> 
     70                                <fo:block span="all"  text-align="center" text-indent="1em" font-family="Arial" font-size="20pt" font-weight="bold" background-color="#EEEEEE" line-height="20mm">«bnf. 
     71                name»</fo:block> 
    7272                                                 
    73                                 «FOR bnfentry:bnf.bnfEntry» 
     73                                «FOR bnfentry : bnf.bnfEntry» 
    7474                                        «bnfentry.compile» 
    7575                                «ENDFOR» 
     
    7777                </fo:page-sequence> 
    7878        </fo:root>''' 
    79          
    80         def compile(BnfEntry bnfEntry)''' 
    81                 «IF bnfEntry.rule!= null» 
    82                                 «bnfEntry.rule.compile» 
     79 
     80        def compile(BnfEntry bnfEntry) ''' 
     81                «IF bnfEntry.rule != null» 
     82                        «bnfEntry.rule.compile» 
    8383                «ENDIF» 
    8484        ''' 
    85          
    86         def compile(Rule rule)'''<fo:block><fo:inline id="«rule.name»"  color="purple">«IF rule.rulenumber!=0»«rule.rulenumber».        «ENDIF»«rule.name»</fo:inline>  ::=     «rule.definitionList.compile»</fo:block>''' 
    87          
    88         def compile(DefinitionList dList)'''«FOR sDef:dList.singleDefinition»«sDef.compile»«IF !sDef.equals(dList.singleDefinition.last)» | «ENDIF»«ENDFOR»''' 
    89          
    90         def compile(SingleDefinition sDefinition)'''«FOR term:sDefinition.terms»«term.compile»«ENDFOR»''' 
    91          
    92         def compile(Term term)'''«IF term.termAtom!=null»«term.termAtom.compile»«ENDIF»«IF term.termOptionalSequence!=null»«term.termOptionalSequence.compile»«ENDIF»«IF term.termRepeatedSequence!=null»«term.termRepeatedSequence.compile»«ENDIF»«IF term.termGroupedSequence!=null»«term.termGroupedSequence.compile»«ENDIF»''' 
    93          
    94         def compile(GroupedSequence gSequ)'''«FOR d :gSequ.definitionList»«d.compile»«ENDFOR»''' 
    9585 
    96         def compile(RepeatedSequence rSequ)'''{«FOR d:rSequ.definitions»«d.compile»«ENDFOR»}«IF rSequ.morethanonce»+«ENDIF»''' 
    97          
    98         def compile(OptionalSequence oSequ)'''(«FOR d:oSequ.definitionList»«d.compile»«ENDFOR»)''' 
    99          
    100         def compile(Atom atom)''' 
    101         «IF atom.atomRuleReference!= null»«atom.atomRuleReference.compile»«ENDIF»«IF atom.atomStringRule!= null»«atom.atomStringRule.compile»«ENDIF»''' 
    102          
    103         def compile(RuleReference rRef)'''<fo:basic-link internal-destination="«rRef.ruleref.name»" text-decoration="underline" color="blue">«rRef.ruleref.name»</fo:basic-link>        ''' 
    104          
    105         def compile(StringRule sRule)'''«IF sRule.colon!=null»«sRule.colon»«ENDIF»«IF sRule.literal!=null»«sRule.literal»       «ENDIF»''' 
    106          
    107          
     86        def compile(Rule rule) '''<fo:block><fo:inline id="«rule.name»" color="purple">«IF rule.rulenumber != 0»«rule. 
     87                rulenumber».    «ENDIF»«rule.name»</fo:inline>  ::=     «rule.definitionList.compile»</fo:block>''' 
     88 
     89        def compile(DefinitionList dList) '''«FOR sDef : dList.singleDefinition»«sDef.compile»«IF !sDef.equals( 
     90                dList.singleDefinition.last)» | «ENDIF»«ENDFOR»''' 
     91 
     92        def compile(SingleDefinition sDefinition) '''«FOR term : sDefinition.terms»«term.compile»«ENDFOR»''' 
     93 
     94        def compile(Term term) '''«IF term.termAtom != null»«term.termAtom.compile»«ENDIF»«IF term.termOptionalSequence != 
     95                null»«term.termOptionalSequence.compile»«ENDIF»«IF term.termRepeatedSequence != null»«term.termRepeatedSequence. 
     96                compile»«ENDIF»«IF term.termGroupedSequence != null»«term.termGroupedSequence.compile»«ENDIF»''' 
     97 
     98        def compile(GroupedSequence gSequ) '''«FOR d : gSequ.definitionList»«d.compile»«ENDFOR»''' 
     99 
     100        def compile(RepeatedSequence rSequ) '''{«FOR d : rSequ.definitions»«d.compile»«ENDFOR»}«IF rSequ.morethanonce»+«ENDIF»''' 
     101 
     102        def compile(OptionalSequence oSequ) '''(«FOR d : oSequ.definitionList»«d.compile»«ENDFOR»)''' 
     103 
     104        def compile(Atom atom) ''' 
     105        «IF atom.atomRuleReference != null»«atom.atomRuleReference.compile»«ENDIF»«IF atom.atomStringRule != null»«atom. 
     106                atomStringRule.compile»«ENDIF»''' 
     107 
     108        def compile(RuleReference rRef) '''<fo:basic-link internal-destination="«rRef.ruleref.name»" text-decoration="underline" color="blue">«rRef. 
     109                ruleref.name»</fo:basic-link>   ''' 
     110 
     111        def compile(StringRule sRule) '''«IF sRule.colon != null»«sRule.colon»«ENDIF»«IF sRule.literal != null»«sRule. 
     112                literal»        «ENDIF»''' 
     113 
    108114} 
Note: See TracChangeset for help on using the changeset viewer.