2
* Copyright 2004 The Apache Software Foundation.
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
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
17
import org.apache.commons.beanutils.MethodUtils;
18
import org.apache.commons.digester.Rule;
21
* When a text segment is discovered, it calls a specific method on the top
22
* object on the stack.
25
public class SetTextSegmentRule extends Rule implements TextSegmentHandler {
28
// ----------------------------------------------------------- Constructors
30
public SetTextSegmentRule(String methodName) {
31
this.methodName = methodName;
34
// ----------------------------------------------------- Instance Variables
38
* The method name to call on the parent object.
40
protected String methodName = null;
42
// --------------------------------------------------------- Public Methods
45
* Process the end of this element.
47
public void textSegment(String text) throws Exception {
49
Object target = digester.peek(0);
51
// Call the specified method
52
Class paramTypes[] = new Class[] {String.class};
53
MethodUtils.invokeMethod(target, methodName,
54
new Object[]{ text }, paramTypes);