Skript

Beispiel: Javaklassengenerierung für eine DTD
Sven Eric Panitz
TFH Berlin
Version Mar 5, 2004
The source of this paper is an XML-file. The sources are processed by the XQuery processor quip, XSLT scripts and LATEX  in order to produce the different formats of the paper.

Contents

1  Example
    1.1  Ausgangs-DTD
    1.2  Konvertierung nach LATEX

1  Example

1.1  Ausgangs-DTD

play
<!DOCTYPE PLAY SYSTEM "play.dtd" [
<!ELEMENT PLAY     
   (TITLE, FM, PERSONAE, SCNDESCR, PLAYSUBT, INDUCT?
   ,PROLOGUE?, ACT+, EPILOGUE?)>
<!ELEMENT TITLE    (#PCDATA)>
<!ELEMENT FM       (P+)>
<!ELEMENT P        (#PCDATA)>
<!ELEMENT PERSONAE (TITLE, (PERSONA | PGROUP)+)>
<!ELEMENT PGROUP   (PERSONA+, GRPDESCR)>
<!ELEMENT PERSONA  (#PCDATA)>
<!ELEMENT GRPDESCR (#PCDATA)>
<!ELEMENT SCNDESCR (#PCDATA)>
<!ELEMENT PLAYSUBT (#PCDATA)>
<!ELEMENT INDUCT   
   (TITLE, SUBTITLE*, (SCENE+|(SPEECH|STAGEDIR|SUBHEAD)+))>
<!ELEMENT ACT      
   (TITLE, SUBTITLE*, PROLOGUE?, SCENE+, EPILOGUE?)>
<!ELEMENT SCENE    
   (TITLE, SUBTITLE*, (SPEECH | STAGEDIR | SUBHEAD)+)>
<!ELEMENT PROLOGUE (TITLE, SUBTITLE*, (STAGEDIR | SPEECH)+)>
<!ELEMENT EPILOGUE (TITLE, SUBTITLE*, (STAGEDIR | SPEECH)+)>
<!ELEMENT SPEECH   (SPEAKER+, (LINE | STAGEDIR | SUBHEAD)+)>
<!ELEMENT SPEAKER  (#PCDATA)>
<!ELEMENT LINE     (#PCDATA | STAGEDIR)*>
<!ELEMENT STAGEDIR (#PCDATA)>
<!ELEMENT SUBTITLE (#PCDATA)>
<!ELEMENT SUBHEAD  (#PCDATA)>]>

1.2  Konvertierung nach LATEX

PLAYToLaTeXVisitor
package examples.theatre;

import de.tfhberlin.crempel.util.Visitor;

import java.util.List;
import de.tfhberlin.crempel.util.Maybe;
import java.io.*;

public  class PLAYToLaTeXVisitor 
                 extends PLAYVisitor<StringWriter>{
  StringWriter out=new StringWriter();

  public StringWriter eval(PLAY pl){
    final TITLE title=pl.getTheTITLE();
    final FM fm=pl.getTheFM();
    final PERSONAE personae=pl.getThePERSONAE();
    final SCNDESCR scndesc =pl.getTheSCNDESCR();
    final PLAYSUBT playsubt=pl.getThePLAYSUBT();
    final Maybe<INDUCT> induct = pl.getTheMaybe_INDUCT_();
    final Maybe<PROLOGUE> prologue= pl.getTheMaybe_PROLOGUE_();
    final List<ACT> acts=pl.getTheList_ACT_();
    final Maybe<EPILOGUE> epilogue = pl.getTheMaybe_EPILOGUE_();

    out.write("\\documentclass[10pt,a4paper]{article}\n");
    out.write("\\usepackage[english]{babel}\n");
    out.write("\\begin{document}\n");
    out.write("\\title{"+title.getPcdata()+"}\n");
    for (ACT act:acts){
      act.visit(new ACTToLaTeXVisitor(out));
    }
    out.write("\\end{document}\n");

    return out;
  }

  public static void main(String [] args) throws Exception{
    final String arg= args[0];
    PLAY play 
     = (PLAY)de.tfhberlin.crempel.test.MainParser.pFile
          ("examples.theatre.PLAYParser",arg);
    StringWriter tex = play.visit(new PLAYToLaTeXVisitor());
    Writer out 
      = new FileWriter(
                 arg.substring(0,arg.lastIndexOf('.'))+".tex");
    out.write(tex.toString());
    out.close();
  }
}

ACTToLaTeXVisitor
package examples.theatre;

import de.tfhberlin.crempel.util.Visitor;

import java.util.List;
import de.tfhberlin.crempel.util.Maybe;
import java.io.*;

public class ACTToLaTeXVisitor extends ACTVisitor<StringWriter>{
  StringWriter out;
  public ACTToLaTeXVisitor(StringWriter o){out=o;}
  public StringWriter eval(ACT act){
    final TITLE title = act.getTheTITLE();;
    final List<SUBTITLE> subtitles = act.getTheList_SUBTITLE_();
    final Maybe<PROLOGUE> prologue=act.getTheMaybe_PROLOGUE_();
    final List<SCENE> scenes=act.getTheList_SCENE_();
    final Maybe<EPILOGUE> epilogues=act.getTheMaybe_EPILOGUE_();

    out.write("\\section*{"+title.getPcdata()+"}\n");
    for (SCENE scene:scenes){
      scene.visit(new SceneToLaTeXVisitor(out));
    }
    return out;
  }}

SceneToLaTeXVisitor
package examples.theatre;

import de.tfhberlin.crempel.util.Visitor;

import java.util.List;
import de.tfhberlin.crempel.util.Maybe;
import java.io.*;

public  class SceneToLaTeXVisitor extends SCENEVisitor<StringWriter>{
  StringWriter out;
  public SceneToLaTeXVisitor(StringWriter o){out=o;}

  public StringWriter eval(SCENE sc){
    final TITLE title=sc.getTheTITLE();
    final List<SUBTITLE> subtitles=sc.getTheList_SUBTITLE_();
    final List<Choice_SPEECH_STAGEDIR_SUBHEAD> spDirSubheads
     =sc.getTheList_Choice_SPEECH_STAGEDIR_SUBHEAD_();
    out.write("\\subsection*{"+title.getPcdata()+"}\n");
    for (Choice_SPEECH_STAGEDIR_SUBHEAD spDirSubhead:spDirSubheads)
      spDirSubhead.visit(new SpeechStageDirSubheadToLaTeX(out));
    return out;
  }}

SpeechStageDirSubheadToLaTeX
package examples.theatre;

import de.tfhberlin.crempel.util.Visitor;
import java.io.*;
import java.util.List;
import de.tfhberlin.crempel.util.Maybe;

public  class SpeechStageDirSubheadToLaTeX 
 extends Choice_SPEECH_STAGEDIR_SUBHEADVisitor<StringWriter>{

  StringWriter out;
  public SpeechStageDirSubheadToLaTeX(StringWriter o){out=o;}

  public StringWriter eval
                    (CChoice_SPEECH_STAGEDIR_SUBHEADSPEECH sp){
    SPEECH speech = sp.getTheSPEECH();
    out.write("\\begin{description}\n");
    out.write("\\item[");
    for (SPEAKER speaker:speech.getTheList_SPEAKER_()){
      out.write(" "+speaker.getPcdata());
    }
    out.write("]");
    List<Choice_LINE_STAGEDIR_SUBHEAD> lineStagedirSubheads
      = speech.getTheList_Choice_LINE_STAGEDIR_SUBHEAD_();

    for (Choice_LINE_STAGEDIR_SUBHEAD lineStagedirSubhead
        :lineStagedirSubheads){
      lineStagedirSubhead.visit(new LineStageDirSubheadToLaTeX(out));
    }
    

    out.write("\\end{description}\n");
    return out;
  }
  public StringWriter eval
                 (CChoice_SPEECH_STAGEDIR_SUBHEADSTAGEDIR st){
    STAGEDIR stageDir = st.getTheSTAGEDIR(); ;
    return out;
  }
  public StringWriter eval
                 (CChoice_SPEECH_STAGEDIR_SUBHEADSUBHEAD subH){
    SUBHEAD subhead = subH.getTheSUBHEAD(); ;
    return out;
  }
  public StringWriter eval(Choice_SPEECH_STAGEDIR_SUBHEAD xs){
    throw new RuntimeException(xs.getClass().toString());
  }}


LineStageDirSubheadToLaTeX
package examples.theatre;

import de.tfhberlin.crempel.util.Visitor;
import java.io.*;
import java.util.List;
import de.tfhberlin.crempel.util.Maybe;

public  class LineStageDirSubheadToLaTeX 
 extends Choice_LINE_STAGEDIR_SUBHEADVisitor<StringWriter>{

  StringWriter out;
  public LineStageDirSubheadToLaTeX(StringWriter o){out=o;}

  public StringWriter eval(CChoice_LINE_STAGEDIR_SUBHEADLINE sp){
    LINE line = sp.getTheLINE();
    for (Choice_String_STAGEDIR stringStageDir:line.getXs()){
      if (stringStageDir instanceof CChoice_String_STAGEDIRString){
        out.write
         (((CChoice_String_STAGEDIRString) stringStageDir)
                                     .getTheString());
        out.write("\\\\");
      }
    }
    return out;
  }
  public StringWriter eval
             (CChoice_LINE_STAGEDIR_SUBHEADSTAGEDIR st){
    STAGEDIR stageDir = st.getTheSTAGEDIR(); ;
    return out;
  }
  public StringWriter eval
             (CChoice_LINE_STAGEDIR_SUBHEADSUBHEAD subH){
    SUBHEAD subhead = subH.getTheSUBHEAD(); ;
    return out;
  }
}




File translated from TEX by TTH, version 3.20.
On 5 Mar 2004, 11:35.