KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > java2html > options > JavaSourceConversionOptions


1 package de.java2html.options;
2
3 import java.io.IOException JavaDoc;
4 import java.io.InputStream JavaDoc;
5 import java.util.Properties JavaDoc;
6
7 import de.java2html.properties.ConversionOptionsPropertiesReader;
8 import de.java2html.util.Ensure;
9 import de.java2html.util.IllegalConfigurationException;
10 import de.java2html.util.IoUtilities;
11
12 /**
13  * Conversion options for customizing the output result. You can adjust the
14  * output style of a {@link de.java2html.converter.AbstractJavaSourceConverter}by
15  * changing the attributes of this object. The color and font style are defined
16  * by the {@link de.java2html.options.JavaSourceStyleTable} associated with
17  * this options.
18  *
19  * @see #setStyleTable(JavaSourceStyleTable)
20  * @see #getStyleTable()
21  * @see de.java2html.converter.AbstractJavaSourceConverter
22  *
23  * @author <a HREF="mailto:markus@jave.de">Markus Gebhard</a>
24  *
25  * <code>Copyright (C) Markus Gebhard 2000-2003
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.</code>
40  */

41 public class JavaSourceConversionOptions {
42   //Attribute names for persistence (e.g. in the eclipse plugin
43

44   private static final String JavaDoc PROPERTIES_FILE_NAME = "java2html.properties"; //$NON-NLS-1$
45
/**
46    * @deprecated As of Dec 21, 2003 (Markus Gebhard), replaced by
47    * {@link IConversionOptionsConstants#TAB_SIZE}
48    */

49   public final static String JavaDoc TAB_SIZE = IConversionOptionsConstants.TAB_SIZE;
50
51   /**
52    * @deprecated As of Dec 21, 2003 (Markus Gebhard), replaced by
53    * {@link IConversionOptionsConstants#SHOW_LINE_NUMBERS}
54    */

55   public final static String JavaDoc SHOW_LINE_NUMBERS = IConversionOptionsConstants.SHOW_LINE_NUMBERS;
56
57   /**
58    * @deprecated As of Dec 21, 2003 (Markus Gebhard), replaced by
59    * {@link IConversionOptionsConstants#SHOW_FILE_NAME}
60    */

61   public final static String JavaDoc SHOW_FILE_NAME = IConversionOptionsConstants.SHOW_FILE_NAME;
62
63   /**
64    * @deprecated As of Dec 21, 2003 (Markus Gebhard), replaced by
65    * {@link IConversionOptionsConstants#SHOW_TABLE_BORDER}
66    */

67   public final static String JavaDoc SHOW_TABLE_BORDER = IConversionOptionsConstants.SHOW_TABLE_BORDER;
68
69   private static JavaSourceConversionOptions defaultOptions;
70
71   public static JavaSourceConversionOptions getRawDefault() {
72     return new JavaSourceConversionOptions();
73   }
74
75   public static JavaSourceConversionOptions getDefault() throws IllegalConfigurationException {
76     if (defaultOptions == null) {
77       defaultOptions = createDefaultOptions();
78     }
79     return defaultOptions.getClone();
80   }
81
82   private static JavaSourceConversionOptions createDefaultOptions() throws IllegalConfigurationException {
83     InputStream JavaDoc inputStream = JavaSourceConversionOptions.class.getClassLoader().getResourceAsStream(
84         PROPERTIES_FILE_NAME);
85     if (inputStream == null) {
86       return new JavaSourceConversionOptions();
87     }
88
89     /* TODO: ClassLoader.getSystemResourceAsStream(PROPERTIES_FILE_NAME)
90      instead of
91      Java2HtmlConversionOptions.class.getClassLoader().getResourceAsStream(PROPERTIES_FILE_NAME);
92      Will have to find out how I can make this compatible when using Java WebStart.
93      As far as I know using ClassLoader.getSystemResourceAsStream() will propbably not find
94      resources that are defined in the JNLP file. Maybe I should use
95      ClassLoader.getSystemResourceAsStream as fallback if there is no file found using the other
96      classloader... */

97
98     Properties JavaDoc properties = new Properties JavaDoc();
99     try {
100       properties.load(inputStream);
101       return new ConversionOptionsPropertiesReader().read(properties);
102     }
103     catch (IOException JavaDoc exception) {
104       throw new IllegalConfigurationException("Error loading configuration file '" //$NON-NLS-1$
105
+ PROPERTIES_FILE_NAME + "' from classpath", exception); //$NON-NLS-1$
106
}
107     catch (IllegalArgumentException JavaDoc exception) {
108       throw new IllegalConfigurationException("Error loading configuration file '" //$NON-NLS-1$
109
+ PROPERTIES_FILE_NAME + "' from classpath", exception); //$NON-NLS-1$
110
}
111     finally {
112       IoUtilities.close(inputStream);
113     }
114   }
115
116   private JavaSourceStyleTable styleTable = JavaSourceStyleTable.getDefault();
117   private int tabSize = 2;
118   private boolean showLineNumbers = false;
119   private boolean showFileName = false;
120   private boolean showTableBorder = false;
121
122   /**
123    * Flag indication whether html output contains a link to the
124    * Java2Html-Homepage or not.
125    */

126   private boolean showJava2HtmlLink = false;
127   private boolean addLineAnchors = false;
128   private String JavaDoc lineAnchorPrefix = ""; //$NON-NLS-1$
129
private HorizontalAlignment horizontalAlignment = HorizontalAlignment.LEFT;
130
131   private JavaSourceConversionOptions() {
132     //nothing to do
133
}
134
135   public boolean equals(Object JavaDoc obj) {
136     if (!(obj instanceof JavaSourceConversionOptions)) {
137       return false;
138     }
139     JavaSourceConversionOptions other = (JavaSourceConversionOptions) obj;
140     return (other.tabSize == tabSize
141         && other.styleTable.equals(styleTable)
142         && other.showFileName == showFileName
143         && other.showJava2HtmlLink == showJava2HtmlLink
144         && other.showLineNumbers == showLineNumbers
145         && other.showTableBorder == showTableBorder && other.horizontalAlignment == horizontalAlignment);
146   }
147
148   public int hashCode() {
149     return styleTable.hashCode() + tabSize;
150   }
151
152   public JavaSourceConversionOptions getClone() {
153     JavaSourceConversionOptions options = new JavaSourceConversionOptions();
154     options.styleTable = styleTable.getClone();
155     options.tabSize = tabSize;
156     options.showLineNumbers = showLineNumbers;
157     options.showFileName = showFileName;
158     options.showJava2HtmlLink = showJava2HtmlLink;
159     options.showTableBorder = showTableBorder;
160     options.horizontalAlignment = horizontalAlignment;
161     return options;
162   }
163
164   public void setStyleTable(JavaSourceStyleTable styleTable) {
165     Ensure.ensureArgumentNotNull(styleTable);
166     this.styleTable = styleTable;
167   }
168
169   public JavaSourceStyleTable getStyleTable() {
170     return styleTable;
171   }
172
173   public int getTabSize() {
174     return tabSize;
175   }
176
177   public void setTabSize(int tabSize) {
178     this.tabSize = tabSize;
179   }
180
181   public boolean isShowLineNumbers() {
182     return showLineNumbers;
183   }
184
185   public void setShowLineNumbers(boolean showLineNumbers) {
186     this.showLineNumbers = showLineNumbers;
187   }
188
189   public boolean isShowFileName() {
190     return showFileName;
191   }
192
193   public boolean isShowTableBorder() {
194     return showTableBorder;
195   }
196
197   public void setShowFileName(boolean showFileName) {
198     this.showFileName = showFileName;
199   }
200
201   public void setShowTableBorder(boolean showTableBorder) {
202     this.showTableBorder = showTableBorder;
203   }
204
205   public boolean isAddLineAnchors() {
206     return addLineAnchors;
207   }
208
209   public String JavaDoc getLineAnchorPrefix() {
210     return lineAnchorPrefix;
211   }
212
213   public void setAddLineAnchors(boolean addLineAnchors) {
214     this.addLineAnchors = addLineAnchors;
215   }
216
217   public void setLineAnchorPrefix(String JavaDoc lineAnchorPrefix) {
218     this.lineAnchorPrefix = lineAnchorPrefix;
219   }
220
221   public HorizontalAlignment getHorizontalAlignment() {
222     return horizontalAlignment;
223   }
224
225   public void setHorizontalAlignment(HorizontalAlignment horizontalAlignment) {
226     Ensure.ensureArgumentNotNull(horizontalAlignment);
227     this.horizontalAlignment = horizontalAlignment;
228   }
229
230   public boolean isShowJava2HtmlLink() {
231     return showJava2HtmlLink;
232   }
233
234   public void setShowJava2HtmlLink(boolean isShowJava2HtmlLink) {
235     this.showJava2HtmlLink = isShowJava2HtmlLink;
236   }
237 }
Popular Tags