001: /*
002: * Copyright 2006 Pentaho Corporation. All rights reserved.
003: * This software was developed by Pentaho Corporation and is provided under the terms
004: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
005: * this file except in compliance with the license. If you need a copy of the license,
006: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
007: * BI Platform. The Initial Developer is Pentaho Corporation.
008: *
009: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
011: * the license for the specific language governing your rights and limitations.
012: *
013: * Created Jan 9, 2006
014: * @author mbatchel
015: */
016: package org.pentaho.plugin.olap;
017:
018: import java.io.File;
019: import java.io.IOException;
020: import java.io.InputStream;
021:
022: import mondrian.olap.MondrianProperties;
023:
024: import org.pentaho.core.repository.ISolutionRepository;
025: import org.pentaho.core.session.IPentahoSession;
026: import org.pentaho.core.system.IPentahoSystemListener;
027: import org.pentaho.core.system.PentahoSystem;
028: import org.pentaho.messages.Messages;
029: import org.pentaho.util.logging.Logger;
030:
031: public class MondrianSystemListener implements IPentahoSystemListener {
032:
033: public boolean startup(IPentahoSession session) {
034: try {
035: System
036: .setProperty(
037: "pentaho.olap.xmladatasources", "system/olap/datasources.xml"); //$NON-NLS-1$ //$NON-NLS-2$
038: } catch (Exception ex) {
039: Logger
040: .error(
041: MondrianSystemListener.class.getName(),
042: Messages
043: .getErrorString("MondrianSystemListener.ERROR_0001_PROPERTY_SET_FAILED"), ex); //$NON-NLS-1$
044: }
045:
046: loadMondrianProperties(session);
047:
048: return true;
049: }
050:
051: /**
052: * on pentaho system startup, load the mondrian.properties file
053: * from system/mondrian/mondrian.properties
054: */
055: public void loadMondrianProperties(IPentahoSession session) {
056: /* Load the mondrian.properties file */
057: String mondrianPropsFilename = "system" + File.separator + "mondrian" + File.separator + "mondrian.properties"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
058: InputStream is = null;
059: try {
060: ISolutionRepository repository = PentahoSystem
061: .getSolutionRepository(session);
062: if (repository.resourceExists(mondrianPropsFilename)) {
063: is = repository.getResourceInputStream(
064: mondrianPropsFilename, false);
065: MondrianProperties.instance().load(is);
066: Logger
067: .debug(
068: MondrianSystemListener.class.getName(),
069: Messages
070: .getString(
071: "MondrianSystemListener.PROPERTY_FILE_LOADED", mondrianPropsFilename)); //$NON-NLS-1$
072: } else {
073: Logger
074: .warn(
075: MondrianSystemListener.class.getName(),
076: Messages
077: .getString(
078: "MondrianSystemListener.PROPERTY_FILE_NOT_FOUND", mondrianPropsFilename)); //$NON-NLS-1$
079: }
080: } catch (IOException ioe) {
081: Logger
082: .error(
083: MondrianSystemListener.class.getName(),
084: Messages
085: .getString(
086: "MondrianSystemListener.ERROR_0002_PROPERTY_FILE_READ_FAILED", ioe.getMessage()), ioe); //$NON-NLS-1$
087: } finally {
088: try {
089: if (is != null)
090: is.close();
091: } catch (IOException e) {
092: // ignore
093: }
094: }
095: }
096:
097: public void shutdown() {
098: // Nothing required
099: }
100: }
|