KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > taglib > test > HelloWorldTag


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.test;
17
18 import org.apache.cocoon.taglib.XMLProducerTagSupport;
19 import org.apache.cocoon.taglib.TagSupport;
20 import org.apache.cocoon.taglib.i18n.LocaleTag;
21 import org.xml.sax.Attributes JavaDoc;
22 import org.xml.sax.SAXException JavaDoc;
23
24 /**
25  * @author <a HREF="mailto:volker.schmitt@basf-it-services.com">Volker Schmitt</a>
26  * @version CVS $Id: HelloWorldTag.java 30932 2004-07-29 17:35:38Z vgritsenko $
27  */

28 public class HelloWorldTag extends XMLProducerTagSupport {
29
30     private static char[] charArrayEN = "Hello World".toCharArray();
31     private static char[] charArrayDE = "Hallo Welt".toCharArray();
32
33     /*
34      * @see Tag#doStartTag(String, String, String, Attributes)
35      */

36     public int doStartTag(String JavaDoc namespaceURI, String JavaDoc localName, String JavaDoc qName, Attributes JavaDoc atts) throws SAXException JavaDoc {
37         LocaleTag localeTag = (LocaleTag) TagSupport.findAncestorWithClass(this, LocaleTag.class);
38         if (localeTag == null) {
39             this.xmlConsumer.characters(charArrayEN, 0, charArrayEN.length);
40         } else {
41             String JavaDoc language = localeTag.getLocale().getLanguage();
42             if ("de".equals(language))
43                 this.xmlConsumer.characters(charArrayDE, 0, charArrayDE.length);
44             else
45                 this.xmlConsumer.characters(charArrayEN, 0, charArrayEN.length);
46         }
47         return EVAL_BODY;
48     }
49
50 }
51
Popular Tags