01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.transformation.helpers;
18:
19: /**
20: * This class records all character SAX events and creates a string
21: * from them.
22: *
23: * @author <a href="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
24: * @version $Id: TextRecorder.java 433543 2006-08-22 06:22:54Z crossley $
25: */
26: public final class TextRecorder extends NOPRecorder {
27:
28: /**
29: * Buffer collecting all character events.
30: */
31: private StringBuffer buffer;
32:
33: public TextRecorder() {
34: super ();
35: this .buffer = new StringBuffer();
36: }
37:
38: public void characters(char ary[], int start, int length) {
39: this .buffer.append(ary, start, length);
40: }
41:
42: /**
43: * @return Recorded text so far, trimmed.
44: */
45: public String getText() {
46: return this .buffer.toString().trim();
47: }
48:
49: /**
50: * @return Recorded text so far.
51: *
52: * NB. This is a special version of the method used by SQLTransformer
53: * Trimming the String can damage the SQL Syntax under certain circumstances
54: *
55: */
56: public String getAllText() {
57: return this.buffer.toString();
58: }
59: }
|