1 16 package org.apache.cocoon.acting; 17 18 import org.apache.bsf.BSFManager; 19 import org.apache.bsf.util.IOUtils; 20 21 import org.apache.avalon.framework.parameters.Parameters; 22 import org.apache.avalon.framework.thread.ThreadSafe; 23 import org.apache.cocoon.ProcessingException; 24 import org.apache.cocoon.environment.ObjectModelHelper; 25 import org.apache.cocoon.environment.Redirector; 26 import org.apache.cocoon.environment.SourceResolver; 27 import org.apache.excalibur.source.Source; 28 29 import java.io.InputStreamReader ; 30 import java.io.Reader ; 31 import java.util.Collections ; 32 import java.util.HashMap ; 33 import java.util.Map ; 34 35 41 42 public class ScriptAction 43 extends ServiceableAction 44 implements ThreadSafe { 45 46 47 public Map act( Redirector redirector, 48 SourceResolver resolver, 49 Map objectModel, 50 String source, 51 Parameters par ) 52 throws Exception { 53 Source src = null; 54 try { 55 String scriptName = source; 58 59 src = resolver.resolveURI(scriptName); 61 String systemID = src.getURI(); 62 63 if (this.getLogger().isDebugEnabled()) { 64 getLogger().debug("script source [" + scriptName + "]"); 65 getLogger().debug("script resolved to [" + systemID + "]"); 66 } 67 68 Reader in = new InputStreamReader (src.getInputStream()); 69 70 72 BSFManager mgr = new BSFManager(); 73 HashMap actionMap = new HashMap (); 74 75 mgr.registerBean("resolver", resolver); 77 mgr.registerBean("objectModel", objectModel); 78 mgr.registerBean("parameters", par); 79 80 mgr.registerBean("actionMap", actionMap); 82 83 85 mgr.registerBean("logger", getLogger()); 86 mgr.registerBean("request", ( ObjectModelHelper.getRequest(objectModel) ) ); 87 mgr.registerBean("scriptaction", this ); 88 mgr.registerBean("manager", this.manager ); 89 90 if (this.getLogger().isDebugEnabled()) { 91 getLogger().debug("BSFManager execution begining"); 92 } 93 94 96 mgr.exec(BSFManager.getLangFromFilename(systemID), systemID, 0, 0, 97 IOUtils.getStringFromReader(in)); 98 99 if (this.getLogger().isDebugEnabled()) { 100 getLogger().debug("BSFManager execution complete"); 101 } 102 103 106 if ( actionMap.containsKey( "scriptaction-continue" )) { 107 return ( Collections.unmodifiableMap(actionMap) ); 108 } else { 109 return (null); 110 } 111 } catch (Exception e) { 112 throw new ProcessingException( 113 "Exception in ScriptAction.act()", e); 114 } finally { 115 resolver.release( src ); 116 } } } | Popular Tags |