|
Lines 28-33
Link Here
|
| 28 |
import org.eclipse.rwt.internal.theme.*; |
28 |
import org.eclipse.rwt.internal.theme.*; |
| 29 |
import org.eclipse.rwt.internal.theme.css.CssFileReader; |
29 |
import org.eclipse.rwt.internal.theme.css.CssFileReader; |
| 30 |
import org.eclipse.rwt.internal.theme.css.StyleSheet; |
30 |
import org.eclipse.rwt.internal.theme.css.StyleSheet; |
|
|
31 |
import org.eclipse.rwt.internal.util.ClassInstantiationException; |
| 32 |
import org.eclipse.rwt.internal.util.ClassUtil; |
| 31 |
import org.eclipse.rwt.lifecycle.PhaseListener; |
33 |
import org.eclipse.rwt.lifecycle.PhaseListener; |
| 32 |
import org.eclipse.rwt.resources.IResource; |
34 |
import org.eclipse.rwt.resources.IResource; |
| 33 |
import org.eclipse.rwt.resources.IResourceManagerFactory; |
35 |
import org.eclipse.rwt.resources.IResourceManagerFactory; |
|
Lines 40-61
Link Here
|
| 40 |
public final class RWTServletContextListener implements ServletContextListener { |
42 |
public final class RWTServletContextListener implements ServletContextListener { |
| 41 |
|
43 |
|
| 42 |
private static final String PREFIX = "org.eclipse.rwt."; |
44 |
private static final String PREFIX = "org.eclipse.rwt."; |
| 43 |
public static final String ENTRY_POINTS_PARAM |
45 |
public static final String ENTRY_POINTS_PARAM = PREFIX + "entryPoints"; |
| 44 |
= PREFIX + "entryPoints"; |
46 |
public static final String THEMES_PARAM = PREFIX + "themes"; |
| 45 |
public static final String THEMES_PARAM |
47 |
public static final String RESOURCE_MANAGER_FACTORY_PARAM = PREFIX + "resourceManagerFactory"; |
| 46 |
= PREFIX + "themes"; |
48 |
public static final String SETTING_STORE_FACTORY_PARAM = PREFIX + "settingStoreFactory"; |
| 47 |
public static final String RESOURCE_MANAGER_FACTORY_PARAM |
49 |
public static final String ADAPTER_FACTORIES_PARAM = PREFIX + "adapterFactories"; |
| 48 |
= PREFIX + "resourceManagerFactory"; |
50 |
public static final String PHASE_LISTENERS_PARAM = PREFIX + "phaseListeners"; |
| 49 |
public static final String SETTING_STORE_FACTORY_PARAM |
51 |
public static final String RESOURCES_PARAM = PREFIX + "resources"; |
| 50 |
= PREFIX + "settingStoreFactory"; |
52 |
public static final String BRANDINGS_PARAM = PREFIX + "brandings"; |
| 51 |
public static final String ADAPTER_FACTORIES_PARAM |
|
|
| 52 |
= PREFIX + "adapterFactories"; |
| 53 |
public static final String PHASE_LISTENERS_PARAM |
| 54 |
= PREFIX + "phaseListeners"; |
| 55 |
public static final String RESOURCES_PARAM |
| 56 |
= PREFIX + "resources"; |
| 57 |
public static final String BRANDINGS_PARAM |
| 58 |
= PREFIX + "brandings"; |
| 59 |
|
53 |
|
| 60 |
private static final String SEPARATOR = ","; |
54 |
private static final String SEPARATOR = ","; |
| 61 |
|
55 |
|
|
Lines 68-73
Link Here
|
| 68 |
private static final String REGISTERED_BRANDINGS |
62 |
private static final String REGISTERED_BRANDINGS |
| 69 |
= RWTServletContextListener.class.getName() + "registeredBrandings"; |
63 |
= RWTServletContextListener.class.getName() + "registeredBrandings"; |
| 70 |
|
64 |
|
|
|
65 |
private static final ClassLoader CLASS_LOADER = RWTServletContextListener.class.getClassLoader(); |
| 71 |
|
66 |
|
| 72 |
public static class ContextDestroyer implements Runnable { |
67 |
public static class ContextDestroyer implements Runnable { |
| 73 |
protected final ServletContext servletContext; |
68 |
protected final ServletContext servletContext; |
|
Lines 206-220
Link Here
|
| 206 |
public static void registerResourceManagerFactory( |
201 |
public static void registerResourceManagerFactory( |
| 207 |
final ServletContext context ) |
202 |
final ServletContext context ) |
| 208 |
{ |
203 |
{ |
| 209 |
String factoryName |
204 |
String factoryName = context.getInitParameter( RESOURCE_MANAGER_FACTORY_PARAM ); |
| 210 |
= context.getInitParameter( RESOURCE_MANAGER_FACTORY_PARAM ); |
|
|
| 211 |
if( factoryName != null ) { |
205 |
if( factoryName != null ) { |
| 212 |
try { |
206 |
try { |
| 213 |
Class clazz = Class.forName( factoryName ); |
207 |
IResourceManagerFactory factory |
| 214 |
IResourceManagerFactory factory; |
208 |
= ( IResourceManagerFactory )ClassUtil.newInstance( CLASS_LOADER, factoryName ); |
| 215 |
factory = ( IResourceManagerFactory )clazz.newInstance(); |
|
|
| 216 |
ResourceManager.register( factory ); |
209 |
ResourceManager.register( factory ); |
| 217 |
} catch( final Exception ex ) { |
210 |
} catch( ClassInstantiationException ex ) { |
| 218 |
String text = "Failed to register resource manager factory ''{0}''."; |
211 |
String text = "Failed to register resource manager factory ''{0}''."; |
| 219 |
String msg = MessageFormat.format( text, new Object[] { factoryName } ); |
212 |
String msg = MessageFormat.format( text, new Object[] { factoryName } ); |
| 220 |
context.log( msg, ex ); |
213 |
context.log( msg, ex ); |
|
Lines 235-248
Link Here
|
| 235 |
= context.getInitParameter( SETTING_STORE_FACTORY_PARAM ); |
228 |
= context.getInitParameter( SETTING_STORE_FACTORY_PARAM ); |
| 236 |
if( factoryName != null ) { |
229 |
if( factoryName != null ) { |
| 237 |
try { |
230 |
try { |
| 238 |
Class clazz = Class.forName( factoryName ); |
231 |
ISettingStoreFactory factory |
| 239 |
ISettingStoreFactory factory; |
232 |
= ( ISettingStoreFactory )ClassUtil.newInstance( CLASS_LOADER, factoryName ); |
| 240 |
factory = ( ISettingStoreFactory )clazz.newInstance(); |
|
|
| 241 |
SettingStoreManager.register( factory ); |
233 |
SettingStoreManager.register( factory ); |
| 242 |
} catch( final Exception ex ) { |
234 |
} catch( ClassInstantiationException cie ) { |
| 243 |
String text = "Failed to register setting store factory ''{0}''."; |
235 |
String text = "Failed to register setting store factory ''{0}''."; |
| 244 |
String msg = MessageFormat.format( text, new Object[] { factoryName } ); |
236 |
String msg = MessageFormat.format( text, new Object[] { factoryName } ); |
| 245 |
context.log( msg, ex ); |
237 |
context.log( msg, cie ); |
| 246 |
} |
238 |
} |
| 247 |
} else { |
239 |
} else { |
| 248 |
SettingStoreManager.register( new RWTFileSettingStoreFactory() ); |
240 |
SettingStoreManager.register( new RWTFileSettingStoreFactory() ); |
|
Lines 297-309
Link Here
|
| 297 |
for( int i = 0; i < listenerNames.length; i++ ) { |
289 |
for( int i = 0; i < listenerNames.length; i++ ) { |
| 298 |
String className = listenerNames[ i ].trim(); |
290 |
String className = listenerNames[ i ].trim(); |
| 299 |
try { |
291 |
try { |
| 300 |
Class clazz = Class.forName( className ); |
292 |
PhaseListener listener = ( PhaseListener )ClassUtil.newInstance( CLASS_LOADER, className ); |
| 301 |
PhaseListener listener = ( PhaseListener )clazz.newInstance(); |
|
|
| 302 |
phaseListeners.add( listener ); |
293 |
phaseListeners.add( listener ); |
| 303 |
} catch( final Throwable thr ) { |
294 |
} catch( ClassInstantiationException cie ) { |
| 304 |
String text = "Failed to register phase listener ''{0}''."; |
295 |
String text = "Failed to register phase listener ''{0}''."; |
| 305 |
String msg = MessageFormat.format( text, new Object[] { className } ); |
296 |
String msg = MessageFormat.format( text, new Object[] { className } ); |
| 306 |
context.log( msg, thr ); |
297 |
context.log( msg, cie ); |
| 307 |
} |
298 |
} |
| 308 |
} |
299 |
} |
| 309 |
} else { |
300 |
} else { |
|
Lines 345-357
Link Here
|
| 345 |
for( int i = 0; i < resourceClassNames.length; i++ ) { |
336 |
for( int i = 0; i < resourceClassNames.length; i++ ) { |
| 346 |
String className = resourceClassNames[ i ].trim(); |
337 |
String className = resourceClassNames[ i ].trim(); |
| 347 |
try { |
338 |
try { |
| 348 |
Class clazz = Class.forName( className ); |
339 |
IResource resource = ( IResource )ClassUtil.newInstance( CLASS_LOADER, className ); |
| 349 |
IResource resource = ( IResource )clazz.newInstance(); |
|
|
| 350 |
resources.add( resource ); |
340 |
resources.add( resource ); |
| 351 |
} catch( final Throwable thr ) { |
341 |
} catch( ClassInstantiationException cie ) { |
| 352 |
String text = "Failed to register resource ''{0}''."; |
342 |
String text = "Failed to register resource ''{0}''."; |
| 353 |
String msg = MessageFormat.format( text, new Object[] { className } ); |
343 |
String msg = MessageFormat.format( text, new Object[] { className } ); |
| 354 |
context.log( msg, thr ); |
344 |
context.log( msg, cie ); |
| 355 |
} |
345 |
} |
| 356 |
} |
346 |
} |
| 357 |
} |
347 |
} |
|
Lines 393-405
Link Here
|
| 393 |
String fileName = parts[ 1 ]; |
383 |
String fileName = parts[ 1 ]; |
| 394 |
try { |
384 |
try { |
| 395 |
String themeName = "Unnamed Theme: " + themeId; |
385 |
String themeName = "Unnamed Theme: " + themeId; |
| 396 |
StyleSheet styleSheet |
386 |
StyleSheet styleSheet = CssFileReader.readStyleSheet( fileName, loader ); |
| 397 |
= CssFileReader.readStyleSheet( fileName, loader ); |
|
|
| 398 |
Theme theme = new Theme( themeId, themeName, styleSheet ); |
387 |
Theme theme = new Theme( themeId, themeName, styleSheet ); |
| 399 |
manager.registerTheme( theme ); |
388 |
manager.registerTheme( theme ); |
| 400 |
} catch( Exception e ) { |
389 |
} catch( Exception e ) { |
| 401 |
String text = "Failed to register custom theme ''{0}'' " |
390 |
String text = "Failed to register custom theme ''{0}'' from resource ''{1}''"; |
| 402 |
+ "from resource ''{1}''"; |
|
|
| 403 |
Object[] args = new Object[] { themeId, fileName }; |
391 |
Object[] args = new Object[] { themeId, fileName }; |
| 404 |
String msg = MessageFormat.format( text, args ); |
392 |
String msg = MessageFormat.format( text, args ); |
| 405 |
context.log( msg, e ); |
393 |
context.log( msg, e ); |
|
Lines 438-451
Link Here
|
| 438 |
for( int i = 0; i < brandings.length; i++ ) { |
426 |
for( int i = 0; i < brandings.length; i++ ) { |
| 439 |
String className = brandings[ i ].trim(); |
427 |
String className = brandings[ i ].trim(); |
| 440 |
try { |
428 |
try { |
| 441 |
Object newInstance = Class.forName( className ).newInstance(); |
429 |
AbstractBranding branding |
| 442 |
AbstractBranding branding = ( AbstractBranding )newInstance; |
430 |
= ( AbstractBranding )ClassUtil.newInstance( CLASS_LOADER, className ); |
| 443 |
BrandingManager.register( branding ); |
431 |
BrandingManager.register( branding ); |
| 444 |
registeredBrandings.add( branding ); |
432 |
registeredBrandings.add( branding ); |
| 445 |
} catch( Exception e ) { |
433 |
} catch( ClassInstantiationException cie ) { |
| 446 |
String text = "Failed to register branding ''{0}''."; |
434 |
String text = "Failed to register branding ''{0}''."; |
| 447 |
String msg = MessageFormat.format( text, new Object[] { className } ); |
435 |
String msg = MessageFormat.format( text, new Object[] { className } ); |
| 448 |
servletContext.log( msg, e ); |
436 |
servletContext.log( msg, cie ); |
| 449 |
} |
437 |
} |
| 450 |
} |
438 |
} |
| 451 |
setRegisteredBrandings( servletContext, registeredBrandings ); |
439 |
setRegisteredBrandings( servletContext, registeredBrandings ); |