1 16 package org.apache.cocoon.components.cron; 17 18 import org.apache.avalon.framework.CascadingRuntimeException; 19 import org.apache.avalon.framework.configuration.Configurable; 20 import org.apache.avalon.framework.configuration.Configuration; 21 import org.apache.avalon.framework.configuration.ConfigurationException; 22 import org.apache.avalon.framework.parameters.Parameters; 23 24 import org.apache.excalibur.source.Source; 25 import org.apache.excalibur.source.SourceResolver; 26 27 import java.io.InputStream ; 28 import java.io.InputStreamReader ; 29 import java.util.Map ; 30 31 45 public class CocoonPipelineCronJob extends ServiceableCronJob 46 implements Configurable, ConfigurableCronJob { 47 48 public static final String PIPELINE_PARAM = "pipeline"; 49 50 private String configuredPipeline; 51 private String pipeline; 52 53 public void execute(String name) { 54 55 if (getLogger ().isDebugEnabled ()) { 56 getLogger().debug ("CocoonPipelineCronJob: " + name + ", calling pipeline: " + pipeline); 57 } 58 59 SourceResolver resolver = null; 60 Source src = null; 61 try { 62 resolver = (SourceResolver)this.manager.lookup (SourceResolver.ROLE); 63 src = resolver.resolveURI ("cocoon://" + pipeline); 64 65 InputStream is = src.getInputStream(); 66 InputStreamReader reader = new InputStreamReader (is); 67 StringBuffer sb = new StringBuffer (); 68 char[] b = new char[8192]; 69 int n; 70 while((n = reader.read (b)) > 0) { 71 sb.append (b, 0, n); 72 } 73 reader.close (); 74 if (getLogger ().isInfoEnabled ()) { 75 getLogger ().info ("CocoonPipelineCronJob: " + name + ", called pipeline: " + 76 pipeline + ", and received following content:\n" + sb.toString() ); 77 } 78 } catch(Exception e) { 79 throw new CascadingRuntimeException ("CocoonPipelineCronJob: " + name + ", raised an exception: ", e); 80 } finally { 81 if (resolver != null) { 82 resolver.release (src); 83 this.manager.release (resolver); 84 resolver = null; 85 src = null; 86 } 87 } 88 } 89 90 public void configure(final Configuration config) throws ConfigurationException { 91 this.configuredPipeline = config.getChild(PIPELINE_PARAM).getValue(null); 92 } 93 94 97 public void setup(Parameters params, Map objects) { 98 if (null != params) { 99 pipeline = params.getParameter(PIPELINE_PARAM, configuredPipeline); 100 } else { 101 pipeline = configuredPipeline; 102 } 103 } 104 } 105 | Popular Tags |