|
Lines 1-5
Link Here
|
| 1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2002, 2007 Innoopract Informationssysteme GmbH. |
2 |
* Copyright (c) 2002, 2010 Innoopract Informationssysteme GmbH. |
| 3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
|
Lines 7-296
Link Here
|
| 7 |
* |
7 |
* |
| 8 |
* Contributors: |
8 |
* Contributors: |
| 9 |
* Innoopract Informationssysteme GmbH - initial API and implementation |
9 |
* Innoopract Informationssysteme GmbH - initial API and implementation |
|
|
10 |
* EclipseSource - ongoing implementation |
| 10 |
******************************************************************************/ |
11 |
******************************************************************************/ |
| 11 |
package org.eclipse.rwt.internal; |
12 |
package org.eclipse.rwt.internal; |
| 12 |
|
13 |
|
| 13 |
import java.io.*; |
|
|
| 14 |
import java.net.URL; |
| 15 |
import java.net.URLConnection; |
| 16 |
import java.util.HashMap; |
14 |
import java.util.HashMap; |
| 17 |
import java.util.Map; |
15 |
import java.util.Map; |
| 18 |
|
16 |
|
| 19 |
import javax.xml.parsers.*; |
17 |
import javax.xml.parsers.FactoryConfigurationError; |
| 20 |
|
18 |
|
| 21 |
import org.w3c.dom.*; |
|
|
| 22 |
import org.xml.sax.*; |
| 23 |
|
19 |
|
| 24 |
|
20 |
/** |
| 25 |
/** |
21 |
* This is a helping class that reads configuration values from system |
| 26 |
* This is a helping class for the W4TApplication to read |
22 |
* properties. |
| 27 |
* the initialisations, which are stored in w4t.xml in the conf/ |
|
|
| 28 |
* directory of the web applications root. |
| 29 |
*/ |
23 |
*/ |
| 30 |
public class ConfigurationReader { |
24 |
public class ConfigurationReader { |
| 31 |
|
|
|
| 32 |
private static final String W4_TOOLKIT_SCHEMA = "w4t.xsd"; |
| 33 |
private static final String JAXP_SCHEMA_LANGUAGE |
| 34 |
= "http://java.sun.com/xml/jaxp/properties/schemaLanguage"; |
| 35 |
private static final String W3C_XML_SCHEMA |
| 36 |
= "http://www.w3.org/2001/XMLSchema"; |
| 37 |
|
| 38 |
|
25 |
|
| 39 |
private static Document document = null; |
|
|
| 40 |
private static IConfiguration configuration = null; |
26 |
private static IConfiguration configuration = null; |
| 41 |
private static final Map values = new HashMap(); |
27 |
private static final Map values = new HashMap(); |
| 42 |
private static File configurationFile = null; |
|
|
| 43 |
private static IEngineConfig engineConfig = null; |
28 |
private static IEngineConfig engineConfig = null; |
| 44 |
|
29 |
|
| 45 |
private static final class ConfigurationImpl implements IConfiguration { |
30 |
private static final class ConfigurationImpl implements IConfiguration { |
| 46 |
|
31 |
|
| 47 |
private IInitialization initialization = null; |
|
|
| 48 |
private IFileUpload fileUpload = null; |
| 49 |
|
| 50 |
public IInitialization getInitialization() { |
| 51 |
if( initialization == null ) { |
| 52 |
initialization = new InitializationImpl(); |
| 53 |
} |
| 54 |
return initialization; |
| 55 |
} |
| 56 |
|
| 57 |
public IFileUpload getFileUpload() { |
| 58 |
if( fileUpload == null ) { |
| 59 |
fileUpload = new FileUploadImpl(); |
| 60 |
} |
| 61 |
return fileUpload; |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
private static final class InitializationImpl implements IInitialization { |
| 66 |
|
| 67 |
public String getStartUpForm() { |
| 68 |
// do not use Startup.class.getName() since in name space mode |
| 69 |
// that class must be loaded in session scope |
| 70 |
return getConfigValue( "startUpForm", "com.w4t.administration.Startup" ); |
| 71 |
} |
| 72 |
|
| 73 |
public String getLifeCycle() { |
32 |
public String getLifeCycle() { |
| 74 |
String defaultValue = IInitialization.LIFE_CYCLE_DEFAULT; |
33 |
String defaultValue = IConfiguration.LIFE_CYCLE_DEFAULT; |
| 75 |
return getConfigValue( IInitialization.PARAM_LIFE_CYCLE, defaultValue ); |
34 |
return getConfigValue( IConfiguration.PARAM_LIFE_CYCLE, defaultValue ); |
| 76 |
} |
|
|
| 77 |
|
| 78 |
public String getErrorPage() { |
| 79 |
// do not use DefaultErrorForm.class.getName() since in name space mode |
| 80 |
// that class must be loaded in session scope |
| 81 |
String defaultValue = "com.w4t.administration.DefaultErrorForm"; |
| 82 |
return getConfigValue( "errorPage", defaultValue ); |
| 83 |
} |
| 84 |
|
| 85 |
public String getAdministrationStartupForm() { |
| 86 |
// do not use Startup.class.getName() since in name space mode |
| 87 |
// that class must be loaded in session scope |
| 88 |
String defaultValue = "com.w4t.administration.Startup"; |
| 89 |
return getConfigValue( "administrationStartupForm", defaultValue ); |
| 90 |
} |
35 |
} |
| 91 |
|
36 |
|
| 92 |
public String getMessagePage() { |
|
|
| 93 |
// do not use DefaultMessageForm.class.getName() since in name space mode |
| 94 |
// that class must be loaded in session scope |
| 95 |
String defaultValue = "com.w4t.administration.DefaultMessageForm"; |
| 96 |
return getConfigValue( "messagePage", defaultValue ); |
| 97 |
} |
| 98 |
|
| 99 |
public String getWorkDirectory() { |
| 100 |
return getConfigValue( "workDirectory", "WEB-INF/classes/" ); |
| 101 |
} |
| 102 |
|
| 103 |
public long getClosingTimeout() { |
| 104 |
String value = getConfigValue( "closingTimeout", "3600000" ); |
| 105 |
long result = Long.parseLong( value ); |
| 106 |
return ( result < 60000 ) ? 60000 : result; |
| 107 |
} |
| 108 |
|
| 109 |
public long getSkimmerFrequenzy() { |
| 110 |
String value = getConfigValue( "skimmerFrequency", "60000" ); |
| 111 |
return Long.parseLong( value ); |
| 112 |
} |
| 113 |
|
| 114 |
public boolean isDirectMonitoringAccess() { |
| 115 |
String value = getConfigValue( "directMonitoringAccess", "true" ); |
| 116 |
return Boolean.valueOf( value ).booleanValue(); |
| 117 |
} |
| 118 |
|
| 119 |
public boolean isCompression() { |
37 |
public boolean isCompression() { |
| 120 |
String value = getConfigValue( "org.eclipse.rwt.compression", "false" ); |
38 |
String value = getConfigValue( IConfiguration.PARAM_COMPRESSION, |
|
|
39 |
"false" ); |
| 121 |
return Boolean.valueOf( value ).booleanValue(); |
40 |
return Boolean.valueOf( value ).booleanValue(); |
| 122 |
} |
41 |
} |
| 123 |
|
42 |
|
| 124 |
public boolean isProcessTime() { |
|
|
| 125 |
String value = getConfigValue( "processTime", "false" ); |
| 126 |
return Boolean.valueOf( value ).booleanValue(); |
| 127 |
} |
| 128 |
|
| 129 |
public String getNoscriptSubmitters() { |
| 130 |
String defaultValue = IInitialization.NOSCRIPT_SUBMITTERS_CREATE; |
| 131 |
return getConfigValue( "noscriptSubmitters", defaultValue ); |
| 132 |
} |
| 133 |
|
| 134 |
public String getResources() { |
43 |
public String getResources() { |
| 135 |
String defaultValue = IInitialization.RESOURCES_DELIVER_FROM_DISK; |
44 |
String defaultValue = IConfiguration.RESOURCES_DELIVER_FROM_DISK; |
| 136 |
return getConfigValue( "resources", defaultValue ); |
45 |
return getConfigValue( "resources", defaultValue ); |
| 137 |
} |
46 |
} |
| 138 |
|
|
|
| 139 |
public long getMaxSessionUnboundToForceGC() { |
| 140 |
String tagName = "maxSessionUnboundToForceGC"; |
| 141 |
String value = getConfigValue( tagName, "0" ); |
| 142 |
return Long.parseLong( value ); |
| 143 |
} |
| 144 |
|
| 145 |
public String getHandleMissingI18NResource() { |
| 146 |
String defaultValue = IInitialization.HANDLE_MISSING_I18N_RESOURCE_EMPTY; |
| 147 |
return getConfigValue( "handleMissingI18NResource", defaultValue ); |
| 148 |
} |
| 149 |
} |
47 |
} |
| 150 |
|
48 |
|
| 151 |
private static final class FileUploadImpl implements IFileUpload { |
|
|
| 152 |
|
| 153 |
public long getMaxUploadSize() { |
| 154 |
String value = getConfigValue( "maxUploadSize", "4194304" ); |
| 155 |
return Long.parseLong( value ); |
| 156 |
} |
| 157 |
|
| 158 |
public int getMaxMemorySize() { |
| 159 |
String value = getConfigValue( "maxMemorySize", "524288" ); |
| 160 |
return Integer.parseInt( value ); |
| 161 |
} |
| 162 |
} |
| 163 |
|
| 164 |
public static IConfiguration getConfiguration() { |
49 |
public static IConfiguration getConfiguration() { |
| 165 |
if( configuration == null ) { |
50 |
if( configuration == null ) { |
| 166 |
configuration = new ConfigurationImpl(); |
51 |
configuration = new ConfigurationImpl(); |
| 167 |
} |
52 |
} |
| 168 |
return configuration; |
53 |
return configuration; |
| 169 |
} |
54 |
} |
| 170 |
|
|
|
| 171 |
public static void setConfigurationFile( final File configurationFile ) |
| 172 |
throws FactoryConfigurationError, |
| 173 |
ParserConfigurationException, |
| 174 |
SAXException, |
| 175 |
IOException |
| 176 |
{ |
| 177 |
reset(); |
| 178 |
if( configurationFile != null ) { |
| 179 |
if( !configurationFile.exists() ) { |
| 180 |
String msg = "Parameter 'configurationFile [" |
| 181 |
+ configurationFile.toString() |
| 182 |
+ "]' does not exist."; |
| 183 |
throw new IllegalArgumentException( msg ); |
| 184 |
} |
| 185 |
if( configurationFile.isDirectory() ) { |
| 186 |
String msg = "Parameter 'configurationFile' must not be a directory."; |
| 187 |
throw new IllegalArgumentException( msg ); |
| 188 |
} |
| 189 |
ConfigurationReader.configurationFile = configurationFile; |
| 190 |
} |
| 191 |
if( configurationFile != null ) { |
| 192 |
parseConfiguration(); |
| 193 |
} |
| 194 |
} |
| 195 |
|
55 |
|
| 196 |
public static IEngineConfig getEngineConfig() { |
56 |
public static IEngineConfig getEngineConfig() { |
| 197 |
return engineConfig; |
57 |
return engineConfig; |
| 198 |
} |
58 |
} |
| 199 |
|
59 |
|
| 200 |
public static void setEngineConfig( final IEngineConfig engineConfig ) |
60 |
public static void setEngineConfig( final IEngineConfig engineConfig ) |
| 201 |
throws FactoryConfigurationError, |
61 |
throws FactoryConfigurationError |
| 202 |
ParserConfigurationException, |
|
|
| 203 |
SAXException, |
| 204 |
IOException |
| 205 |
{ |
62 |
{ |
| 206 |
ConfigurationReader.engineConfig = engineConfig; |
63 |
ConfigurationReader.engineConfig = engineConfig; |
| 207 |
setConfigurationFile( engineConfig.getConfigFile() ); |
|
|
| 208 |
} |
64 |
} |
| 209 |
|
|
|
| 210 |
|
| 211 |
////////////////// |
| 212 |
// helping methods |
| 213 |
|
65 |
|
| 214 |
private static void reset() { |
66 |
public static void reset() { |
| 215 |
values.clear(); |
67 |
values.clear(); |
| 216 |
document = null; |
|
|
| 217 |
configuration = null; |
68 |
configuration = null; |
| 218 |
configurationFile = null; |
|
|
| 219 |
} |
69 |
} |
| 220 |
|
70 |
|
| 221 |
private static void parseConfiguration() |
71 |
////////////////// |
| 222 |
throws FactoryConfigurationError, |
72 |
// helping methods |
| 223 |
ParserConfigurationException, |
73 |
|
| 224 |
SAXException, |
|
|
| 225 |
IOException |
| 226 |
{ |
| 227 |
if( configurationFile != null ) { |
| 228 |
InputStream is = new FileInputStream( configurationFile ); |
| 229 |
try { |
| 230 |
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); |
| 231 |
factory.setNamespaceAware( true ); |
| 232 |
ClassLoader loader = ConfigurationReader.class.getClassLoader(); |
| 233 |
final URL schema = loader.getResource( W4_TOOLKIT_SCHEMA ); |
| 234 |
factory.setValidating( schema != null ); |
| 235 |
try { |
| 236 |
factory.setAttribute( JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA ); |
| 237 |
} catch( final IllegalArgumentException iae ) { |
| 238 |
// XML-Processing does not support JAXP 1.2 or greater |
| 239 |
factory.setNamespaceAware( false ); |
| 240 |
factory.setValidating( false ); |
| 241 |
} |
| 242 |
DocumentBuilder builder = factory.newDocumentBuilder(); |
| 243 |
builder.setEntityResolver( new EntityResolver() { |
| 244 |
public InputSource resolveEntity( final String publicID, |
| 245 |
final String systemID ) |
| 246 |
throws IOException, SAXException |
| 247 |
{ |
| 248 |
InputSource result = null; |
| 249 |
if( schema != null && systemID.endsWith( W4_TOOLKIT_SCHEMA ) ) { |
| 250 |
URLConnection connection = schema.openConnection(); |
| 251 |
connection.setUseCaches( false ); |
| 252 |
result = new InputSource( connection.getInputStream() ); |
| 253 |
} |
| 254 |
return result; |
| 255 |
} |
| 256 |
} ); |
| 257 |
|
| 258 |
// TODO: more sophisticated ErrorHandler implementation... |
| 259 |
builder.setErrorHandler( new ErrorHandler() { |
| 260 |
|
| 261 |
public void error( final SAXParseException spe ) |
| 262 |
throws SAXException |
| 263 |
{ |
| 264 |
System.out.println( "Error parsing W4 Toolkit configuration:" ); |
| 265 |
System.out.println( configurationFile.toString() ); |
| 266 |
System.out.println( spe.getMessage() ); |
| 267 |
} |
| 268 |
|
| 269 |
public void fatalError( final SAXParseException spe ) |
| 270 |
throws SAXException |
| 271 |
{ |
| 272 |
String msg = "Fatal error parsing W4 Toolkit configuration:"; |
| 273 |
System.out.println( msg ); |
| 274 |
System.out.println( configurationFile.toString() ); |
| 275 |
System.out.println( spe.getMessage() ); |
| 276 |
} |
| 277 |
|
| 278 |
public void warning( final SAXParseException spe ) |
| 279 |
throws SAXException |
| 280 |
{ |
| 281 |
System.out.println( "Warning parsing W4 Toolkit configuration:" ); |
| 282 |
System.out.println( configurationFile.toString() ); |
| 283 |
System.out.println( spe.getMessage() ); |
| 284 |
} |
| 285 |
|
| 286 |
} ); |
| 287 |
document = builder.parse( is ); |
| 288 |
} finally { |
| 289 |
is.close(); |
| 290 |
} |
| 291 |
} |
| 292 |
} |
| 293 |
|
| 294 |
private static String getConfigValue( final String tagName, |
74 |
private static String getConfigValue( final String tagName, |
| 295 |
final String defaultValue ) |
75 |
final String defaultValue ) |
| 296 |
{ |
76 |
{ |
|
Lines 298-315
Link Here
|
| 298 |
String result = ""; |
78 |
String result = ""; |
| 299 |
if( System.getProperty( tagName ) != null ) { |
79 |
if( System.getProperty( tagName ) != null ) { |
| 300 |
result = System.getProperty( tagName ); |
80 |
result = System.getProperty( tagName ); |
| 301 |
} else if( document != null ) { |
|
|
| 302 |
NodeList nodeList = document.getElementsByTagName( tagName ); |
| 303 |
Node item = nodeList.item( 0 ); |
| 304 |
if( item != null ) { |
| 305 |
Node firstChild = item.getFirstChild(); |
| 306 |
if( firstChild != null ) { |
| 307 |
String nodeValue = firstChild.getNodeValue(); |
| 308 |
result = nodeValue.trim(); |
| 309 |
} |
| 310 |
} else { |
| 311 |
result = defaultValue; |
| 312 |
} |
| 313 |
} else { |
81 |
} else { |
| 314 |
result = defaultValue; |
82 |
result = defaultValue; |
| 315 |
} |
83 |
} |