1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed;
18
19 import java.util.Locale;
20
21 import org.apache.jetspeed.administration.PortalConfiguration;
22 import org.apache.jetspeed.components.ComponentManager;
23 import org.apache.jetspeed.engine.Engine;
24 import org.apache.jetspeed.exception.JetspeedException;
25 import org.apache.jetspeed.request.RequestContext;
26
27 /***
28 * Jetspeed environment
29 * <br/>
30 * Provides an easy way to access the current running environment
31 * of jetspeed.
32 *
33 * @author <a href="mailto:david@bluesunrise.com">David Sean Taylor</a>
34 * @version $Id: Jetspeed.java 552657 2007-07-03 03:57:47Z taylor $
35 */
36 public class Jetspeed
37 {
38 private static Engine engine = null;
39 /***
40 * Shuts down the currently running instance of the portal
41 * Engine.
42 * @throws JetspeedException
43 */
44 public static void shutdown() throws JetspeedException
45 {
46 if (engine != null)
47 engine.shutdown();
48 }
49
50 public static Engine getEngine()
51 {
52 return engine;
53 }
54
55 public static PortalContext getContext()
56 {
57 if (engine == null)
58 {
59 throw new NullPointerException("The engine is null, have you called createEngine() yet?");
60 }
61 return engine.getContext();
62 }
63
64 /***
65 * Given a application relative path, returns the real path relative to the application root
66 *
67 */
68 public static String getRealPath(String path)
69 {
70 if (engine == null)
71 {
72 return null;
73 }
74 return engine.getRealPath(path);
75 }
76
77 /***
78 * Delegtes to the current Engine to retreive the RequestContext
79 * appropriate for the current thread.
80 *
81 * @see org.apache.jetspeed.engine.Engine#getCurrentRequestContext()
82 *
83 * @return The RequestContext for this current Thread.
84 */
85 public static RequestContext getCurrentRequestContext()
86 {
87 if (engine != null)
88 return engine.getCurrentRequestContext();
89 return null;
90 }
91
92
93
94 public static Locale getDefaultLocale()
95 {
96 return Locale.getDefault();
97 }
98
99 public static ComponentManager getComponentManager()
100 {
101 if (engine == null)
102 return null;
103 return engine.getComponentManager();
104 }
105
106 public static void setEngine(Engine engine)
107 {
108 Jetspeed.engine = engine;
109 }
110
111 public static PortalConfiguration getConfiguration()
112 {
113 ComponentManager manager = getComponentManager();
114 if (manager != null)
115 return (PortalConfiguration)manager.getComponent("PortalConfiguration");
116 return null;
117 }
118
119 }