| RubyPortlet.java |
1 /**
2 * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
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 /**
35 * <a href="RubyPortlet.java.html"><b><i>View Source</i></b></a>
36 *
37 * @author Jorge Ferrer
38 *
39 */
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 }