2
* Licensed to the Apache Software Foundation (ASF) under one
3
* or more contributor license agreements. See the NOTICE file
4
* distributed with this work for additional information
5
* regarding copyright ownership. The ASF licenses this file
6
* to you under the Apache License, Version 2.0 (the "License");
7
* you may not use this file except in compliance with the License.
8
* You may obtain a copy of the License at
10
* http://www.apache.org/licenses/LICENSE-2.0
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.
19
* $Id: ExtensionHandler.java,v 1.2 2009/12/10 03:18:40 matthewoliver Exp $
21
package org.apache.xalan.extensions;
23
import java.io.IOException;
24
import java.util.Vector;
26
import javax.xml.transform.TransformerException;
28
import org.apache.xalan.templates.ElemTemplateElement;
29
import org.apache.xalan.templates.Stylesheet;
30
import org.apache.xalan.transformer.TransformerImpl;
31
import org.apache.xpath.functions.FuncExtFunction;
34
* Abstract base class for handling an extension namespace for XPath.
35
* Provides functions to test a function's existence and call a function.
36
* Also provides functions for calling an element and testing for
37
* an element's existence.
39
* @author Sanjiva Weerawarana (sanjiva@watson.ibm.com)
42
public abstract class ExtensionHandler
45
/** uri of the extension namespace */
46
protected String m_namespaceUri;
48
/** scripting language of implementation */
49
protected String m_scriptLang;
52
* This method loads a class using the context class loader if we're
53
* running under Java2 or higher.
55
* @param className Name of the class to load
57
static Class getClassForName(String className)
58
throws ClassNotFoundException
60
// Hack for backwards compatibility with XalanJ1 stylesheets
61
if(className.equals("org.apache.xalan.xslt.extensions.Redirect")) {
62
className = "org.apache.xalan.lib.Redirect";
65
return ObjectFactory.findProviderClass(
66
className, ObjectFactory.findClassLoader(), true);
70
* Construct a new extension namespace handler given all the information
73
* @param namespaceUri the extension namespace URI that I'm implementing
74
* @param scriptLang language of code implementing the extension
76
protected ExtensionHandler(String namespaceUri, String scriptLang)
78
m_namespaceUri = namespaceUri;
79
m_scriptLang = scriptLang;
83
* Tests whether a certain function name is known within this namespace.
84
* @param function name of the function being tested
85
* @return true if its known, false if not.
87
public abstract boolean isFunctionAvailable(String function);
90
* Tests whether a certain element name is known within this namespace.
91
* @param element Name of element to check
92
* @return true if its known, false if not.
94
public abstract boolean isElementAvailable(String element);
97
* Process a call to a function.
99
* @param funcName Function name.
100
* @param args The arguments of the function call.
101
* @param methodKey A key that uniquely identifies this class and method call.
102
* @param exprContext The context in which this expression is being executed.
104
* @return the return value of the function evaluation.
106
* @throws TransformerException if parsing trouble
108
public abstract Object callFunction(
109
String funcName, Vector args, Object methodKey,
110
ExpressionContext exprContext) throws TransformerException;
113
* Process a call to a function.
115
* @param extFunction The XPath extension function.
116
* @param args The arguments of the function call.
117
* @param exprContext The context in which this expression is being executed.
119
* @return the return value of the function evaluation.
121
* @throws TransformerException if parsing trouble
123
public abstract Object callFunction(
124
FuncExtFunction extFunction, Vector args,
125
ExpressionContext exprContext) throws TransformerException;
128
* Process a call to this extension namespace via an element. As a side
129
* effect, the results are sent to the TransformerImpl's result tree.
131
* @param localPart Element name's local part.
132
* @param element The extension element being processed.
133
* @param transformer Handle to TransformerImpl.
134
* @param stylesheetTree The compiled stylesheet tree.
135
* @param methodKey A key that uniquely identifies this class and method call.
137
* @throws XSLProcessorException thrown if something goes wrong
138
* while running the extension handler.
139
* @throws MalformedURLException if loading trouble
140
* @throws FileNotFoundException if loading trouble
141
* @throws IOException if loading trouble
142
* @throws TransformerException if parsing trouble
144
public abstract void processElement(
145
String localPart, ElemTemplateElement element, TransformerImpl transformer,
146
Stylesheet stylesheetTree, Object methodKey) throws TransformerException, IOException;