01: package com.meterware.httpunit.javascript;
02:
03: /********************************************************************************************************************
04: * $Id: JavaScriptEngineFactory.java,v 1.8 2004/08/08 17:38:18 russgold Exp $
05: *
06: * Copyright (c) 2002, Russell Gold
07: *
08: * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
09: * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
10: * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
11: * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
12: *
13: * The above copyright notice and this permission notice shall be included in all copies or substantial portions
14: * of the Software.
15: *
16: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
17: * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
19: * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20: * DEALINGS IN THE SOFTWARE.
21: *
22: *******************************************************************************************************************/
23: import com.meterware.httpunit.WebResponse;
24: import com.meterware.httpunit.scripting.ScriptingEngineFactory;
25:
26: /**
27: * An implementation of the scripting engine factory which selects a Rhino-based implementation of JavaScript.
28: *
29: * @author <a href="mailto:russgold@httpunit.org">Russell Gold</a>
30: **/
31: public class JavaScriptEngineFactory implements ScriptingEngineFactory {
32:
33: public boolean isEnabled() {
34: try {
35: Class.forName("org.mozilla.javascript.Context");
36: return true;
37: } catch (Exception e) {
38: System.err
39: .println("Rhino classes (js.jar) not found - Javascript disabled");
40: return false;
41: }
42: }
43:
44: public void associate(WebResponse response) {
45: try {
46: JavaScript.run(response);
47: } catch (RuntimeException e) {
48: throw e;
49: } catch (Exception e) {
50: e.printStackTrace();
51: throw new RuntimeException(e.toString());
52: }
53: }
54:
55: public void load(WebResponse response) {
56: try {
57: JavaScript.load(response);
58: } catch (RuntimeException e) {
59: throw e;
60: } catch (Exception e) {
61: e.printStackTrace();
62: throw new RuntimeException(e.toString());
63: }
64: }
65:
66: public void setThrowExceptionsOnError(boolean throwExceptions) {
67: JavaScript.setThrowExceptionsOnError(throwExceptions);
68: }
69:
70: public boolean isThrowExceptionsOnError() {
71: return JavaScript.isThrowExceptionsOnError();
72: }
73:
74: public String[] getErrorMessages() {
75: return JavaScript.getErrorMessages();
76: }
77:
78: public void clearErrorMessages() {
79: JavaScript.clearErrorMessages();
80: }
81: }
|