01: /*
02: * Copyright 2006 Pentaho Corporation. All rights reserved.
03: * This software was developed by Pentaho Corporation and is provided under the terms
04: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
05: * this file except in compliance with the license. If you need a copy of the license,
06: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
07: * BI Platform. The Initial Developer is Pentaho Corporation.
08: *
09: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
10: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
11: * the license for the specific language governing your rights and limitations.
12: *
13: * @created Feb 01, 2006
14: * @author Michael D'Amour
15: */
16:
17: package org.pentaho.jfreereport.wizard.utility;
18:
19: import java.util.Locale;
20:
21: import org.pentaho.core.system.PentahoSystem;
22: import org.pentaho.core.system.StandaloneApplicationContext;
23: import org.pentaho.messages.util.LocaleHelper;
24: import org.pentaho.util.logging.ILogger;
25:
26: public class PentahoUtility {
27:
28: private static boolean started = false;
29: private static String solutionRoot = null;
30: private static String baseURL = null;
31:
32: public static void startup() {
33: startup(solutionRoot, baseURL);
34: }
35:
36: public static void setSolutionRoot(String solutionRoot) {
37: PentahoUtility.solutionRoot = solutionRoot;
38: }
39:
40: public static String getSolutionRoot() {
41: return solutionRoot;
42: }
43:
44: public static void startup(String solutionRootPath, String baseURL) {
45:
46: // PentahoSystem.setUserDetailsRoleListService(new UserDetailsRoleListService());
47:
48: LocaleHelper.setLocale(Locale.getDefault());
49:
50: if (!started) {
51:
52: PentahoSystem.loggingLevel = ILogger.ERROR;
53:
54: if (PentahoSystem.getApplicationContext() == null) {
55:
56: StandaloneApplicationContext applicationContext = new StandaloneApplicationContext(
57: solutionRootPath, ""); //$NON-NLS-1$
58:
59: // set the base url assuming there is a running server on port 8080
60: applicationContext.setBaseUrl(baseURL);
61:
62: // Setup simple-jndi for datasources
63: System
64: .setProperty(
65: "java.naming.factory.initial", "org.osjava.sj.SimpleContextFactory"); //$NON-NLS-1$ //$NON-NLS-2$
66: System
67: .setProperty(
68: "org.osjava.sj.root", solutionRootPath + "/system/simple-jndi"); //$NON-NLS-1$ //$NON-NLS-2$
69: System.setProperty("org.osjava.sj.delimiter", "/"); //$NON-NLS-1$ //$NON-NLS-2$
70: PentahoSystem.init(applicationContext);
71: started = true;
72: }
73: }
74: }
75:
76: public static void shutdown() {
77: try {
78: PentahoSystem.shutdown();
79: started = false;
80: } catch (Exception ex) {
81: ex.printStackTrace();
82: }
83: }
84:
85: public static String getBaseURL() {
86: return baseURL;
87: }
88:
89: public static void setBaseURL(String baseURL) {
90: PentahoUtility.baseURL = baseURL;
91: }
92:
93: }
|