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.kettle;
017:
018: import java.io.File;
019: import java.io.IOException;
020: import java.io.InputStream;
021: import java.util.Map;
022: import java.util.Properties;
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.di.core.util.EnvUtil;
029: import org.pentaho.di.job.JobEntryLoader;
030: import org.pentaho.di.trans.StepLoader;
031: import org.pentaho.messages.Messages;
032: import org.pentaho.util.logging.Logger;
033:
034: public class KettleSystemListener implements IPentahoSystemListener {
035:
036: public boolean startup(IPentahoSession session) {
037: /* Load the plugins etc. */
038: environmentInit(session);
039: try {
040: StepLoader.init();
041: } catch (Throwable t) {
042: t.printStackTrace();
043: Logger
044: .error(
045: KettleSystemListener.class.getName(),
046: Messages
047: .getErrorString("KettleSystemListener.ERROR_0001_STEP_LOAD_FAILED")); //$NON-NLS-1$
048: }
049:
050: try {
051: JobEntryLoader.init();
052: } catch (Throwable t) {
053: t.printStackTrace();
054: Logger
055: .error(
056: KettleSystemListener.class.getName(),
057: Messages
058: .getString("KettleSystemListener.ERROR_0002_JOB_ENTRY_LOAD_FAILED")); //$NON-NLS-1$
059: }
060:
061: return true;
062: }
063:
064: public static Map readProperties(IPentahoSession session) {
065:
066: Properties props = new Properties();
067: String kettlePropsFilename = "system" + File.separator + "kettle" + File.separator + "kettle.properties"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
068:
069: InputStream is = null;
070: try {
071: ISolutionRepository repository = PentahoSystem
072: .getSolutionRepository(session);
073:
074: if (!repository.resourceExists(kettlePropsFilename)) {
075: return props;
076: }
077: is = repository.getResourceInputStream(kettlePropsFilename,
078: false);
079: props.load(is);
080: } catch (IOException ioe) {
081: Logger
082: .error(
083: KettleSystemListener.class.getName(),
084: Messages
085: .getString("KettleSystemListener.ERROR_0003_PROPERTY_FILE_READ_FAILED") + ioe.getMessage(), ioe); //$NON-NLS-1$
086: } finally {
087: if (is != null)
088: try {
089: is.close();
090: } catch (IOException e) {
091: // ignore
092: }
093: }
094:
095: props
096: .put(
097: "pentaho.solutionpath", PentahoSystem.getApplicationContext().getFileOutputPath("")); //$NON-NLS-1$ //$NON-NLS-2$
098: return props;
099:
100: }
101:
102: public static void environmentInit(IPentahoSession session) {
103: EnvUtil.environmentInit();
104: }
105:
106: public void shutdown() {
107: // Nothing required
108: }
109:
110: }
|