1 package de.java2html.options; 2 3 import java.io.IOException ; 4 import java.io.InputStream ; 5 import java.util.Properties ; 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 41 public class JavaSourceConversionOptions { 42 44 private static final String PROPERTIES_FILE_NAME = "java2html.properties"; 49 public final static String TAB_SIZE = IConversionOptionsConstants.TAB_SIZE; 50 51 55 public final static String SHOW_LINE_NUMBERS = IConversionOptionsConstants.SHOW_LINE_NUMBERS; 56 57 61 public final static String SHOW_FILE_NAME = IConversionOptionsConstants.SHOW_FILE_NAME; 62 63 67 public final static String 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 inputStream = JavaSourceConversionOptions.class.getClassLoader().getResourceAsStream( 84 PROPERTIES_FILE_NAME); 85 if (inputStream == null) { 86 return new JavaSourceConversionOptions(); 87 } 88 89 97 98 Properties properties = new Properties (); 99 try { 100 properties.load(inputStream); 101 return new ConversionOptionsPropertiesReader().read(properties); 102 } 103 catch (IOException exception) { 104 throw new IllegalConfigurationException("Error loading configuration file '" + PROPERTIES_FILE_NAME + "' from classpath", exception); } 107 catch (IllegalArgumentException exception) { 108 throw new IllegalConfigurationException("Error loading configuration file '" + PROPERTIES_FILE_NAME + "' from classpath", exception); } 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 126 private boolean showJava2HtmlLink = false; 127 private boolean addLineAnchors = false; 128 private String lineAnchorPrefix = ""; private HorizontalAlignment horizontalAlignment = HorizontalAlignment.LEFT; 130 131 private JavaSourceConversionOptions() { 132 } 134 135 public boolean equals(Object 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 getLineAnchorPrefix() { 210 return lineAnchorPrefix; 211 } 212 213 public void setAddLineAnchors(boolean addLineAnchors) { 214 this.addLineAnchors = addLineAnchors; 215 } 216 217 public void setLineAnchorPrefix(String 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 |