1 48 49 package org.jpublish.action.bsf; 50 51 import com.anthonyeden.lib.config.Configuration; 52 import com.anthonyeden.lib.util.MessageUtilities; 53 import org.apache.bsf.BSFException; 54 import org.apache.bsf.BSFManager; 55 import org.apache.commons.logging.Log; 56 import org.apache.commons.logging.LogFactory; 57 import org.jpublish.JPublishEngine; 58 import org.jpublish.JPublishRuntimeException; 59 import org.jpublish.RequestContext; 60 import org.jpublish.action.AbstractScriptHandler; 61 62 67 68 public class BSFScriptHandler extends AbstractScriptHandler { 69 70 private static Log log = LogFactory.getLog(BSFScriptHandler.class); 71 72 private BSFManager bsfManager = new BSFManager(); 73 74 81 82 public void set(String name, Object value, Class c) { 83 try { 84 bsfManager.declareBean(name, value, c); 85 } catch (BSFException e) { 86 Object [] args = {name, file.getName()}; 87 throw new JPublishRuntimeException(MessageUtilities.getMessage(getClass(), JPublishEngine.MESSAGE_PACKAGE, 88 "failedToDeclareObject", args), e); 89 } 90 } 91 92 100 101 public void execute(String name, String scriptText, 102 RequestContext requestContext, Configuration configuration) { 103 try { 104 if (log.isDebugEnabled()) { 105 log.debug("Executing script: " + name); 106 } 107 String scriptLanguage = bsfManager.getLangFromFilename(name); 108 bsfManager.exec(scriptLanguage, name, 0, 0, scriptText); 109 } catch (BSFException e) { 110 Object [] args = {name, e.getMessage()}; 111 throw new JPublishRuntimeException(MessageUtilities.getMessage(getClass(), JPublishEngine.MESSAGE_PACKAGE, 112 "scriptExecutionError", args), e); 113 } 114 } 115 116 } 117 | Popular Tags |