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