KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > taglib > string > TextRecordingTag


1 /*
2  * Copyright 1999-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 package org.apache.cocoon.taglib.string;
17
18 import org.apache.cocoon.taglib.VarTransformerTagSupport;
19 import org.xml.sax.SAXException JavaDoc;
20
21 /**
22  * @author <a HREF="mailto:volker.schmitt@basf-it-services.com">Volker Schmitt</a>
23  * @version CVS $Id: TextRecordingTag.java 30932 2004-07-29 17:35:38Z vgritsenko $
24  */

25 public class TextRecordingTag extends VarTransformerTagSupport {
26     StringBuffer JavaDoc bodyContent = new StringBuffer JavaDoc();
27     
28     /*
29      * @see Tag#doEndTag(String, String, String)
30      */

31     public int doEndTag(String JavaDoc namespaceURI, String JavaDoc localName, String JavaDoc qName) throws SAXException JavaDoc {
32         String JavaDoc text = getText();
33
34         if (var != null) {
35             setVariable(var, text);
36         } else {
37             char[] charArray = text.toCharArray();
38             this.xmlConsumer.characters(charArray, 0, charArray.length);
39         }
40
41         return EVAL_PAGE;
42     }
43
44     /**
45      * @return String result of recording
46      */

47     protected final String JavaDoc getText() {
48         return bodyContent.toString();
49     }
50
51     /*
52      * @see ContentHandler#characters(char[], int, int)
53      */

54     public void characters(char[] ch, int start, int length) throws SAXException JavaDoc {
55         bodyContent.append(ch, start, length);
56     }
57
58     /*
59      * @see Recyclable#recycle()
60      */

61     public void recycle() {
62         bodyContent.setLength(0);
63         super.recycle();
64     }
65
66 }
67
Popular Tags