KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > transformation > helpers > TextRecorder


1 /*
2  * Copyright 1999-2005 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 package org.apache.cocoon.transformation.helpers;
17
18 /**
19  * This class records all character SAX events and creates a string
20  * from them.
21  *
22  * @author <a HREF="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
23  * @version $Id: TextRecorder.java 330528 2005-11-03 11:59:45Z jeremy $
24 */

25 public final class TextRecorder extends NOPRecorder {
26
27     /**
28      * Buffer collecting all character events.
29      */

30     private StringBuffer JavaDoc buffer;
31
32     public TextRecorder() {
33         super();
34         this.buffer = new StringBuffer JavaDoc();
35     }
36
37     public void characters(char ary[], int start, int length) {
38         this.buffer.append(ary, start, length);
39     }
40
41     /**
42      * @return Recorded text so far, trimmed.
43      */

44     public String JavaDoc getText() {
45         return this.buffer.toString().trim();
46     }
47
48     /**
49      * @return Recorded text so far.
50      *
51      * NB. This is a special version of the method used by SQLTransformer
52      * Trimming the String can damage the SQL Syntax under certain circumstances
53      *
54      */

55     public String JavaDoc getAllText() {
56         return this.buffer.toString();
57     }
58 }
59
Popular Tags