KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > woody > datatype > EmptySelectionList


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.woody.datatype;
17
18 import java.util.Locale JavaDoc;
19
20 import org.apache.cocoon.transformation.I18nTransformer;
21 import org.apache.cocoon.woody.Constants;
22 import org.apache.cocoon.xml.AttributesImpl;
23 import org.xml.sax.ContentHandler JavaDoc;
24 import org.xml.sax.SAXException JavaDoc;
25
26 /**
27  *
28  * @author <a HREF="http://www.apache.org/~sylvain/">Sylvain Wallez</a>
29  * @version CVS $Id: EmptySelectionList.java 30932 2004-07-29 17:35:38Z vgritsenko $
30  */

31 public class EmptySelectionList implements SelectionList {
32     private String JavaDoc text;
33     private boolean i18n;
34     
35     public EmptySelectionList(String JavaDoc text) {
36         this.text = text;
37         this.i18n = false;
38     }
39     
40     public EmptySelectionList(String JavaDoc text, boolean i18n) {
41         this.text = text;
42         this.i18n = i18n;
43     }
44
45     public Datatype getDatatype() {
46         // Cannot return anything meaningful
47
return null;
48     }
49
50     public void generateSaxFragment(ContentHandler JavaDoc contentHandler, Locale JavaDoc locale) throws SAXException JavaDoc {
51         // Start wi:selection list
52
contentHandler.startElement(Constants.WI_NS, SELECTION_LIST_EL, Constants.WI_PREFIX_COLON + SELECTION_LIST_EL, Constants.EMPTY_ATTRS);
53
54         // Start wi:item
55
AttributesImpl itemAttrs = new AttributesImpl();
56         itemAttrs.addCDATAAttribute("value", "");
57         contentHandler.startElement(Constants.WI_NS, ITEM_EL, Constants.WI_PREFIX_COLON + ITEM_EL, itemAttrs);
58
59         // Start wi:label
60
contentHandler.startElement(Constants.WI_NS, LABEL_EL, Constants.WI_PREFIX_COLON + LABEL_EL, Constants.EMPTY_ATTRS);
61         if (this.text != null) {
62
63             if (i18n) {
64                 contentHandler.startPrefixMapping("i18n", I18nTransformer.I18N_NAMESPACE_URI);
65         
66                 contentHandler.startElement(I18nTransformer.I18N_NAMESPACE_URI, I18nTransformer.I18N_TEXT_ELEMENT, "i18n:" + I18nTransformer.I18N_TEXT_ELEMENT, Constants.EMPTY_ATTRS);
67                 contentHandler.characters(this.text.toCharArray(), 0, this.text.length());
68                 contentHandler.endElement(I18nTransformer.I18N_NAMESPACE_URI, I18nTransformer.I18N_TEXT_ELEMENT, "i18n:" + I18nTransformer.I18N_TEXT_ELEMENT);
69     
70                 contentHandler.endPrefixMapping("i18n");
71             } else {
72                 contentHandler.characters(this.text.toCharArray(), 0, this.text.length());
73             }
74         }
75         
76         // End wi:label
77
contentHandler.endElement(Constants.WI_NS, LABEL_EL, Constants.WI_PREFIX_COLON + LABEL_EL);
78         
79         // End wi:item
80
contentHandler.endElement(Constants.WI_NS, ITEM_EL, Constants.WI_PREFIX_COLON + ITEM_EL);
81         
82         // End wi:selection-list
83
contentHandler.endElement(Constants.WI_NS, SELECTION_LIST_EL, Constants.WI_PREFIX_COLON + SELECTION_LIST_EL);
84     }
85 }
86
Popular Tags