1 16 package org.pentaho.plugin.kettle; 17 18 import java.io.File ; 19 import java.io.FileInputStream ; 20 import java.io.InputStream ; 21 import java.io.IOException ; 22 import java.util.Map ; 23 import java.util.Properties ; 24 25 import org.pentaho.core.session.IPentahoSession; 26 import org.pentaho.core.system.IPentahoSystemListener; 27 import org.pentaho.core.system.PentahoSystem; 28 import org.pentaho.messages.Messages; 29 import org.pentaho.util.logging.Logger; 30 31 import be.ibridge.kettle.trans.StepLoader; 32 import be.ibridge.kettle.core.LocalVariables; 33 import be.ibridge.kettle.job.JobEntryLoader; 34 35 36 public class KettleSystemListener implements IPentahoSystemListener { 37 38 public boolean startup(IPentahoSession session) { 39 40 try { 41 42 43 StepLoader stloader = StepLoader.getInstance(); 44 environmentInit(); 45 if (!stloader.read()) { 46 Logger.error(KettleSystemListener.class.getName(), Messages.getErrorString("KettleSystemListener.ERROR_0001_STEP_LOAD_FAILED")); } 48 49 JobEntryLoader jeLoader = JobEntryLoader.getInstance(); 50 if (!jeLoader.read()) { 51 Logger.error(KettleSystemListener.class.getName(), Messages.getString("KettleSystemListener.ERROR_0002_JOB_ENTRY_LOAD_FAILED")); } 53 54 55 } catch (Exception ex) { 56 Logger.error(KettleSystemListener.class.getName(), Messages.getErrorString("KettleSystemListener.ERROR_0001_STEP_LOAD_FAILED"), ex); 58 } 59 60 return true; 61 } 62 63 64 65 public static Map readProperties() { 66 67 Properties props = new Properties (); 68 String kettlePropsFilename = PentahoSystem.getApplicationContext().getSolutionPath("system"+File.separator+"kettle"+File.separator+"kettle.properties"); 70 InputStream is = null; 71 try { 72 File propsFile = new File ( kettlePropsFilename ); 73 if( !propsFile.exists() ) { 74 return props; 75 } 76 is = new FileInputStream (propsFile); 77 props.load(is); 78 } catch (IOException ioe) { 79 Logger.error(KettleSystemListener.class.getName(), Messages.getString("KettleSystemListener.ERROR_0003_PROPERTY_FILE_READ_FAILED") + ioe.getMessage(), ioe); } 81 finally { 82 if (is != null) 83 try 84 { 85 is.close(); 86 } 87 catch (IOException e) 88 { 89 } 91 } 92 93 props.put( "pentaho.solutionpath", PentahoSystem.getApplicationContext().getFileOutputPath( "" ) ); return props; 95 96 } 97 98 99 100 public static void environmentInit() 101 102 { 103 104 Map kettleProperties = readProperties(); 105 106 System.getProperties().putAll(kettleProperties); 107 108 LocalVariables local = LocalVariables.getInstance(); 109 110 local.createKettleVariables(Thread.currentThread().getName(), null, false); 111 112 113 114 } 115 116 117 118 119 public void shutdown() { 120 } 122 123 } 124 | Popular Tags |