Line 0
Link Here
|
|
|
1 |
/* |
2 |
|
3 |
Licensed to the Apache Software Foundation (ASF) under one or more |
4 |
contributor license agreements. See the NOTICE file distributed with |
5 |
this work for additional information regarding copyright ownership. |
6 |
The ASF licenses this file to You under the Apache License, Version 2.0 |
7 |
(the "License"); you may not use this file except in compliance with |
8 |
the License. You may obtain a copy of the License at |
9 |
|
10 |
http://www.apache.org/licenses/LICENSE-2.0 |
11 |
|
12 |
Unless required by applicable law or agreed to in writing, software |
13 |
distributed under the License is distributed on an "AS IS" BASIS, |
14 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15 |
See the License for the specific language governing permissions and |
16 |
limitations under the License. |
17 |
|
18 |
*/ |
19 |
|
20 |
package org.apache.batik.script.rhino; |
21 |
|
22 |
import org.mozilla.javascript.Context; |
23 |
import org.mozilla.javascript.Function; |
24 |
import org.mozilla.javascript.Scriptable; |
25 |
import org.mozilla.javascript.ScriptableObject; |
26 |
|
27 |
import org.apache.batik.bridge.Location; |
28 |
|
29 |
/** |
30 |
* This class wraps a Location object to expose it to the interpreter. |
31 |
* |
32 |
* @author <a href="mailto:gwadej@anomaly.org">G. Wade Johnson</a> |
33 |
* @version $Id$ |
34 |
*/ |
35 |
public class LocationWrapper extends ScriptableObject { |
36 |
|
37 |
/** |
38 |
* The wrapped Location object. |
39 |
*/ |
40 |
private Location location; |
41 |
|
42 |
/** |
43 |
* Creates a new LocationWrapper |
44 |
* @param context the script context in which we are executing. |
45 |
* @param loc the location object to wrap. |
46 |
*/ |
47 |
public LocationWrapper(org.w3c.dom.Location loc) { |
48 |
super(); |
49 |
location = (Location)loc; |
50 |
String[] names = { "assign", "reload" }; |
51 |
this.defineFunctionProperties(names, LocationWrapper.class, |
52 |
ScriptableObject.DONTENUM); |
53 |
} |
54 |
public String getClassName() { |
55 |
return "Window"; |
56 |
} |
57 |
|
58 |
public String toString() { |
59 |
return location.toString(); |
60 |
} |
61 |
|
62 |
/** |
63 |
* Invocation of this method causes the user agent to navigate to the |
64 |
* supplied location. |
65 |
* |
66 |
* @param url A string containing the URL where the user agent should |
67 |
* navigate to. |
68 |
*/ |
69 |
public static void assign(Context cx, |
70 |
Scriptable thisObj, |
71 |
Object[] args, |
72 |
Function funObj) { |
73 |
if(args.length != 1) { |
74 |
return; |
75 |
} |
76 |
String url = (String)Context.jsToJava(args[0], String.class); |
77 |
LocationWrapper lw = (LocationWrapper)thisObj; |
78 |
Location location = lw.location; |
79 |
location.assign(url); |
80 |
} |
81 |
|
82 |
/** |
83 |
* The user agent reloads the current document. |
84 |
*/ |
85 |
public static void reload(Context cx, |
86 |
Scriptable thisObj, |
87 |
Object[] args, |
88 |
Function funObj) { |
89 |
LocationWrapper lw = (LocationWrapper)thisObj; |
90 |
Location location = lw.location; |
91 |
location.reload(); |
92 |
} |
93 |
|
94 |
} |