1 /*
2 * Copyright (c) 2002-2026 Gargoyle Software Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 * https://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 package org.htmlunit.javascript.host;
16
17 import org.htmlunit.corejs.javascript.Context;
18 import org.htmlunit.corejs.javascript.NativeFunction;
19 import org.htmlunit.corejs.javascript.VarScope;
20 import org.htmlunit.xpath.xml.utils.PrefixResolver;
21
22 /**
23 * A special {@link PrefixResolver} for {@link NativeFunction}s.
24 *
25 * @author Chuck Dumont
26 * @author Ronald Brill
27 */
28 public class NativeFunctionPrefixResolver implements PrefixResolver {
29
30 private final NativeFunction resolverFn_;
31 private final VarScope scope_;
32
33 /**
34 * Constructor.
35 *
36 * @param resolverFn the {@link NativeFunction} this resolver is for
37 * @param scope the scope
38 */
39 public NativeFunctionPrefixResolver(final NativeFunction resolverFn, final VarScope scope) {
40 resolverFn_ = resolverFn;
41 scope_ = scope;
42 }
43
44 /**
45 * {@inheritDoc}
46 */
47 @Override
48 public String getNamespaceForPrefix(final String prefix) {
49 final Object result = Context.call(null, resolverFn_, scope_, null, new Object[]{prefix});
50 return result == null ? null : result.toString();
51 }
52
53 /**
54 * {@inheritDoc}
55 */
56 @Override
57 public String getNamespaceForPrefix(final String prefix, final org.w3c.dom.Node node) {
58 throw new UnsupportedOperationException();
59 }
60
61 /**
62 * {@inheritDoc}
63 */
64 @Override
65 public boolean handlesNullPrefixes() {
66 return false;
67 }
68 }