~ubuntu-branches/ubuntu/maverick/libcommons-digester-java/maverick

« back to all changes in this revision

Viewing changes to src/examples/api/document-markup/SetTextSegmentRule.java

  • Committer: Bazaar Package Importer
  • Author(s): Wolfgang Baer
  • Date: 2006-01-15 16:51:19 UTC
  • mfrom: (0.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060115165119-e7cgj3f6o1fmvlg3
Tags: 1.7-2
* Kaffe compiler transition
* Remove Takashi from uploaders to reflect current maintainership

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2004 The Apache Software Foundation.
 
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
 * 
 
8
 *      http://www.apache.org/licenses/LICENSE-2.0
 
9
 * 
 
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.
 
15
 */ 
 
16
 
 
17
import org.apache.commons.beanutils.MethodUtils;
 
18
import org.apache.commons.digester.Rule;
 
19
 
 
20
/**
 
21
 * When a text segment is discovered, it calls a specific method on the top
 
22
 * object on the stack.
 
23
 */
 
24
 
 
25
public class SetTextSegmentRule extends Rule implements TextSegmentHandler {
 
26
 
 
27
 
 
28
    // ----------------------------------------------------------- Constructors
 
29
 
 
30
    public SetTextSegmentRule(String methodName) {
 
31
        this.methodName = methodName;
 
32
    }
 
33
 
 
34
    // ----------------------------------------------------- Instance Variables
 
35
 
 
36
 
 
37
    /**
 
38
     * The method name to call on the parent object.
 
39
     */
 
40
    protected String methodName = null;
 
41
 
 
42
    // --------------------------------------------------------- Public Methods
 
43
 
 
44
    /**
 
45
     * Process the end of this element.
 
46
     */
 
47
    public void textSegment(String text) throws Exception {
 
48
 
 
49
        Object target = digester.peek(0);
 
50
 
 
51
        // Call the specified method
 
52
        Class paramTypes[] = new Class[] {String.class};
 
53
        MethodUtils.invokeMethod(target, methodName,
 
54
            new Object[]{ text }, paramTypes);
 
55
    }
 
56
}