1
22
23 package com.liferay.util.bridges.ruby;
24
25 import com.liferay.portal.kernel.log.Log;
26 import com.liferay.portal.kernel.log.LogFactoryUtil;
27 import com.liferay.util.bridges.bsf.BaseBSFPortlet;
28
29 import org.apache.bsf.BSFException;
30
31 import org.jruby.RubyException;
32 import org.jruby.exceptions.RaiseException;
33
34
40 public class RubyPortlet extends BaseBSFPortlet {
41
42 protected String getFileParam() {
43 return _FILE_PARAM;
44 }
45
46 protected String getScriptingEngineClassName() {
47 return _SCRIPTING_ENGINE_CLASS_NAME;
48 }
49
50 protected String getScriptingEngineExtension() {
51 return _SCRIPTING_ENGINE_EXTENSION;
52 }
53
54 protected String getScriptingEngineLanguage() {
55 return _SCRIPTING_ENGINE_LANGUAGE;
56 }
57
58 protected void logBSFException(BSFException bsfe, String path) {
59 String message =
60 "The script at " + path + " or one of the global files has errors.";
61
62 Throwable t = bsfe.getTargetException();
63
64 if (t instanceof RaiseException) {
65 RubyException re = ((RaiseException)t).getException();
66
67 message +=
68 re.message + " (" + re.getMetaClass().toString() + ")";
69
70 _log.error(message);
71
72 if (_log.isDebugEnabled()) {
73 _log.debug(t, t);
74 }
75 }
76 else {
77 _log.error(message, t);
78 }
79 }
80
81 private static final String _FILE_PARAM = "rubyFile";
82
83 private static final String _SCRIPTING_ENGINE_CLASS_NAME =
84 "org.jruby.javasupport.bsf.JRubyEngine";
85
86 private static final String _SCRIPTING_ENGINE_EXTENSION = "rb";
87
88 private static final String _SCRIPTING_ENGINE_LANGUAGE = "ruby";
89
90 private static Log _log = LogFactoryUtil.getLog(RubyPortlet.class);
91
92 }