001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jetspeed;
018:
019: import java.util.Locale;
020:
021: import org.apache.jetspeed.administration.PortalConfiguration;
022: import org.apache.jetspeed.components.ComponentManager;
023: import org.apache.jetspeed.engine.Engine;
024: import org.apache.jetspeed.exception.JetspeedException;
025: import org.apache.jetspeed.request.RequestContext;
026:
027: /**
028: * Jetspeed environment
029: * <br/>
030: * Provides an easy way to access the current running environment
031: * of jetspeed.
032: *
033: * @author <a href="mailto:david@bluesunrise.com">David Sean Taylor</a>
034: * @version $Id: Jetspeed.java 552657 2007-07-03 03:57:47Z taylor $
035: */
036: public class Jetspeed {
037: private static Engine engine = null;
038:
039: /**
040: * Shuts down the currently running instance of the portal
041: * Engine.
042: * @throws JetspeedException
043: */
044: public static void shutdown() throws JetspeedException {
045: if (engine != null)
046: engine.shutdown();
047: }
048:
049: public static Engine getEngine() {
050: return engine;
051: }
052:
053: public static PortalContext getContext() {
054: if (engine == null) {
055: throw new NullPointerException(
056: "The engine is null, have you called createEngine() yet?");
057: }
058: return engine.getContext();
059: }
060:
061: /**
062: * Given a application relative path, returns the real path relative to the application root
063: *
064: */
065: public static String getRealPath(String path) {
066: if (engine == null) {
067: return null;
068: }
069: return engine.getRealPath(path);
070: }
071:
072: /**
073: * Delegtes to the current Engine to retreive the RequestContext
074: * appropriate for the current thread.
075: *
076: * @see org.apache.jetspeed.engine.Engine#getCurrentRequestContext()
077: *
078: * @return The RequestContext for this current Thread.
079: */
080: public static RequestContext getCurrentRequestContext() {
081: if (engine != null)
082: return engine.getCurrentRequestContext();
083: return null;
084: }
085:
086: // TODO We need to get this from the Engine and the engine should get it from the configuration.
087:
088: public static Locale getDefaultLocale() {
089: return Locale.getDefault();
090: }
091:
092: public static ComponentManager getComponentManager() {
093: if (engine == null)
094: return null;
095: return engine.getComponentManager();
096: }
097:
098: public static void setEngine(Engine engine) {
099: Jetspeed.engine = engine;
100: }
101:
102: public static PortalConfiguration getConfiguration() {
103: ComponentManager manager = getComponentManager();
104: if (manager != null)
105: return (PortalConfiguration) manager
106: .getComponent("PortalConfiguration");
107: return null;
108: }
109:
110: }
|