View Javadoc
1   package eu.simuline.m2latex.core;
2   
3   import java.io.File;
4   
5   /**
6    * The enumeration of all supported (creational) targets. 
7    * These are targets where tex files are converted into a target format 
8    * and the resulting document is included in the target folder for delivery.  
9    * Additional targets are <code>clr</code>, <code>grp</code> and <code>chk</code>. 
10   * None of them are creational. 
11   *
12   *
13   * Created: Fri Oct  7 13:32:21 2016
14   *
15   * @author <a href="mailto:rei3ner@arcor.de">Ernst Reissner</a>
16   * @version 1.0
17   */
18  public enum Target {
19  
20     /**
21       * standalone
22       *
23       */
24      rtf() {
25  	private final String RTF_OUTPUT_FILES = "^T$T\\.rtf$";
26  	// may throw BuildFailureException TEX01 
27  	public void processSource(LatexProcessor latexProcessor, 
28  				  File texFile) throws BuildFailureException {
29  	    latexProcessor.processLatex2rtf(texFile);
30  	}
31  
32  	public String getPatternOutputFiles(Settings settings) {
33  	    return RTF_OUTPUT_FILES;
34  	}
35  
36      },
37      /**
38       * standalone. 
39       */
40      dvi() {
41  	// FIXME: how does this fit with preprocessing?? 
42  	private final String LATEX_OUTPUT_FILES = 
43  	    "^(T$T\\.dvi|.+(\\.(ptx|eps|jpg|png)|\\d+\\.mps))$";
44  	// may throw BuildFailureException TEX01 
45  	public void processSource(LatexProcessor latexProcessor, 
46  				  File texFile) throws BuildFailureException {
47  	    latexProcessor.processLatex2dvi(texFile);
48  	}
49  
50  	public String getPatternOutputFiles(Settings settings) {
51  	    return LATEX_OUTPUT_FILES;
52  	}
53      },
54      /**
55       * standalone. 
56       */
57      pdf() {
58  	private final String LATEX_OUTPUT_FILES = "^T$T\\.pdf$";
59  	// may throw BuildFailureException TEX01 
60  	public void processSource(LatexProcessor latexProcessor, 
61  				  File texFile) throws BuildFailureException {
62  	    latexProcessor.processLatex2pdf(texFile);
63  	}
64  
65  	public String getPatternOutputFiles(Settings settings) {
66  	    return LATEX_OUTPUT_FILES;
67  	}
68      },
69      /**
70       * Based on {@link #pdf}
71       *
72       */
73      html() {
74  	// may throw BuildFailureException TEX01 
75  	public void processSource(LatexProcessor latexProcessor, 
76  				  File texFile) throws BuildFailureException {
77  	    latexProcessor.processLatex2html(texFile);
78  	}
79  
80  	public String getPatternOutputFiles(Settings settings) {
81  	    return settings.getPatternT4htOutputFiles();
82  	}
83      },
84      /**
85       * Based on {@link #pdf}
86       *
87       */
88      odt() {
89  	private final String OOFFICE_OUTPUT_FILES = 
90  	    "^T$T\\.(odt|fodt|uot|uot)$";
91  	// may throw BuildFailureException TEX01 
92  	public void processSource(LatexProcessor latexProcessor, 
93  				  File texFile) throws BuildFailureException {
94  	    latexProcessor.processLatex2odt(texFile);
95  	}
96  
97  	public String getPatternOutputFiles(Settings settings) {
98  	    return OOFFICE_OUTPUT_FILES;
99  	}
100     },
101     /**
102      * Based on {@link #odt}
103      *
104      */
105     docx() {
106 	private final String MSWORD_OUTPUT_FILES = 
107 	    "^T$T\\.(doc(|6|.95|.x|.x7)|rtf)$";
108 	// may throw BuildFailureException TEX01 
109 	public void processSource(LatexProcessor latexProcessor, 
110 				  File texFile) throws BuildFailureException {
111 	    latexProcessor.processLatex2docx(texFile);
112 	}
113 
114 	public String getPatternOutputFiles(Settings settings) {
115 	    return MSWORD_OUTPUT_FILES;
116 	}
117     },
118     /**
119      * Based on {@link #pdf}
120      */
121     txt() {
122 	private final String TXT_OUTPUT_FILES = "^T$T\\.txt$";
123 	// may throw BuildFailureException TEX01 
124 	public void processSource(LatexProcessor latexProcessor, 
125 				  File texFile) throws BuildFailureException {
126 	    latexProcessor.processLatex2txt(texFile);
127 	}
128 
129 	public String getPatternOutputFiles(Settings settings) {
130 	    return TXT_OUTPUT_FILES;
131 	}
132     };
133 
134     /**
135      * Processes the latex main file <code>texFile</code> 
136      * delegating to <code>latexProcessor</code>. 
137      * Logging: FIXME: may be incomplete 
138      * <ul>
139      * <li> EEX01, EEX02, EEX03, WEX04, WEX05 if running a command 
140      *      to transform <code>texFile</code> failed. 
141      * </ul>
142      *
143      * @param latexProcessor
144      *    the processor to process <code>texFile</code> 
145      * @param texFile
146      *    the latex main file to be processed. 
147      * @throws BuildFailureException
148      *    TEX01 if invocation of a command 
149      *    to transform <code>texFile</code> failed. 
150      */
151     public abstract void processSource(LatexProcessor latexProcessor, 
152     				       File texFile) 
153     throws BuildFailureException;
154 
155     /**
156      * Returns the pattern of the output files. 
157      * For example if creating pdf, 
158      * this is just <code>^T$T\.pdf$</code>, 
159      * where <code>T$T</code> represents the name of the latex main file 
160      * without suffix. 
161      * For target {@link #html}, this is much more complicated, 
162      * because a lot of files are created in general, 
163      * not only <code>^T$T\.h?tml?$</code>. 
164      *
165      * @param settings
166      *    the settings required to determine the pattern. 
167      *    This depends on the settings for {@link #html} only. 
168      */
169     public abstract String getPatternOutputFiles(Settings settings);
170 
171 }
172