KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > java2html > converter > AbstractJavaSourceConverter


1 package de.java2html.converter;
2
3 import java.io.BufferedWriter JavaDoc;
4 import java.io.IOException JavaDoc;
5 import java.io.Writer JavaDoc;
6
7 import de.java2html.javasource.JavaSource;
8 import de.java2html.options.JavaSourceConversionOptions;
9 import de.java2html.util.Ensure;
10
11 /**
12  * Abstract superclass for all converters for converting a {@link de.java2html.javasource.JavaSource}
13  * object to anything else.
14  *
15  * For questions, suggestions, bug-reports, enhancement-requests etc.
16  * I may be contacted at:
17  * <a HREF="mailto:markus@jave.de">markus@jave.de</a>
18  *
19  * The Java2html home page is located at:
20  * <a HREF="http://www.java2html.de">http://www.java2html.de</a>
21  *
22  * @author <a HREF="mailto:markus@jave.de">Markus Gebhard</a>
23  * @version 2.0, 05/07/02
24  *
25  * Copyright (C) Markus Gebhard 2000-2002
26  *
27  * This program is free software; you can redistribute it and/or
28  * modify it under the terms of the GNU General Public License
29  * as published by the Free Software Foundation; either version 2
30  * of the License, or (at your option) any later version.
31  *
32  * This program is distributed in the hope that it will be useful,
33  * but WITHOUT ANY WARRANTY; without even the implied warranty of
34  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35  * GNU General Public License for more details.
36  *
37  * You should have received a copy of the GNU General Public License
38  * along with this program; if not, write to the Free Software
39  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
40  */

41 public abstract class AbstractJavaSourceConverter implements IJavaSourceConverter {
42
43   private final ConverterMetaData metaData;
44
45   public AbstractJavaSourceConverter(ConverterMetaData metaData) {
46     Ensure.ensureArgumentNotNull(metaData);
47     this.metaData = metaData;
48   }
49
50   /**
51    * Is called to convert the object 'source' to the destination
52    * format. The result is stored in 'result' and can be retrieved
53    * by calling getResult().
54    */

55   public final void convert(JavaSource source, JavaSourceConversionOptions options, Writer JavaDoc writer)
56       throws IOException JavaDoc {
57     BufferedWriter JavaDoc bw = null;
58     try {
59       bw = new BufferedWriter JavaDoc(writer);
60       convert(source, options, bw);
61       bw.flush();
62     }
63     catch (IOException JavaDoc e) {
64       throw e;
65     }
66   }
67
68   public abstract void convert(JavaSource source, JavaSourceConversionOptions options, BufferedWriter JavaDoc writer)
69       throws IOException JavaDoc;
70
71   /**
72    * Returns a header for the result document.
73    * This one will be placed before the first block of converted
74    * code.
75    * Subclasses can return an empty String (&quot;&quot;) if there is none neccessary.
76    * @param title
77    */

78   public abstract String JavaDoc getDocumentHeader(JavaSourceConversionOptions options, String JavaDoc title);
79
80   /**
81    * Returns a footer for the result document.
82    * This one will be placed behind the last block of converted
83    * code.
84    * Subclasses can return an empty String (&quot;&quot;) if there is none neccessary.
85    */

86   public abstract String JavaDoc getDocumentFooter(JavaSourceConversionOptions options);
87
88   /**
89    * Returns the code that has to be placed between two blocks
90    * of converted code.
91    * Subclasses can return an empty String (&quot;&quot;) if there is none neccessary.
92    */

93   public abstract String JavaDoc getBlockSeparator(JavaSourceConversionOptions options);
94
95   public void writeDocumentHeader(Writer JavaDoc writer, JavaSourceConversionOptions options, String JavaDoc title)
96       throws IOException JavaDoc {
97     writer.write(getDocumentHeader(options, title));
98   }
99
100   public void writeDocumentFooter(Writer JavaDoc writer, JavaSourceConversionOptions options) throws IOException JavaDoc {
101     writer.write(getDocumentFooter(options));
102   }
103
104   public void writeBlockSeparator(Writer JavaDoc writer, JavaSourceConversionOptions options) throws IOException JavaDoc {
105     writer.write(getBlockSeparator(options));
106   }
107
108   public final String JavaDoc getDefaultFileExtension() {
109     return metaData.getDefaultFileExtension();
110   }
111   
112   public final ConverterMetaData getMetaData() {
113     return metaData;
114   }
115 }
Popular Tags