1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.util.bridges.ruby;
16  
17  import com.liferay.portal.kernel.log.Log;
18  import com.liferay.portal.kernel.log.LogFactoryUtil;
19  import com.liferay.util.bridges.bsf.BaseBSFPortlet;
20  
21  import org.apache.bsf.BSFException;
22  
23  import org.jruby.RubyException;
24  import org.jruby.exceptions.RaiseException;
25  
26  /**
27   * <a href="RubyPortlet.java.html"><b><i>View Source</i></b></a>
28   *
29   * @author Jorge Ferrer
30   */
31  public class RubyPortlet extends BaseBSFPortlet {
32  
33      protected String getFileParam() {
34          return _FILE_PARAM;
35      }
36  
37      protected String getScriptingEngineClassName() {
38          return _SCRIPTING_ENGINE_CLASS_NAME;
39      }
40  
41      protected String getScriptingEngineExtension() {
42          return _SCRIPTING_ENGINE_EXTENSION;
43      }
44  
45      protected String getScriptingEngineLanguage() {
46          return _SCRIPTING_ENGINE_LANGUAGE;
47      }
48  
49      protected void logBSFException(BSFException bsfe, String path) {
50          String message =
51              "The script at " + path + " or one of the global files has errors.";
52  
53          Throwable t = bsfe.getTargetException();
54  
55          if (t instanceof RaiseException) {
56              RubyException re = ((RaiseException)t).getException();
57  
58              message +=
59                  re.message + " (" + re.getMetaClass().toString() + ")";
60  
61              _log.error(message);
62  
63              if (_log.isDebugEnabled()) {
64                  _log.debug(t, t);
65              }
66          }
67          else {
68              _log.error(message, t);
69          }
70      }
71  
72      private static final String _FILE_PARAM = "rubyFile";
73  
74      private static final String _SCRIPTING_ENGINE_CLASS_NAME =
75          "org.jruby.javasupport.bsf.JRubyEngine";
76  
77      private static final String _SCRIPTING_ENGINE_EXTENSION = "rb";
78  
79      private static final String _SCRIPTING_ENGINE_LANGUAGE = "ruby";
80  
81      private static Log _log = LogFactoryUtil.getLog(RubyPortlet.class);
82  
83  }