KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > forms > 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.forms.datatype;
17
18 import java.util.Locale JavaDoc;
19
20 import org.apache.cocoon.forms.FormsConstants;
21 import org.apache.cocoon.transformation.I18nTransformer;
22 import org.apache.cocoon.xml.AttributesImpl;
23 import org.apache.cocoon.xml.XMLUtils;
24 import org.xml.sax.ContentHandler JavaDoc;
25 import org.xml.sax.SAXException JavaDoc;
26
27 /**
28  *
29  * @author <a HREF="http://www.apache.org/~sylvain/">Sylvain Wallez</a>
30  * @version $Id: EmptySelectionList.java 326838 2005-10-20 06:26:53Z sylvain $
31  */

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