1 16 package org.apache.cocoon.forms.datatype; 17 18 import java.util.Locale ; 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 ; 25 import org.xml.sax.SAXException ; 26 27 32 public class EmptySelectionList implements SelectionList { 33 private String text; 34 private boolean i18n; 35 36 public EmptySelectionList(String text) { 37 this.text = text; 38 this.i18n = false; 39 } 40 41 public EmptySelectionList(String text, boolean i18n) { 42 this.text = text; 43 this.i18n = i18n; 44 } 45 46 public Datatype getDatatype() { 47 return null; 49 } 50 51 public void generateSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException { 52 contentHandler.startElement(FormsConstants.INSTANCE_NS, SELECTION_LIST_EL, FormsConstants.INSTANCE_PREFIX_COLON + SELECTION_LIST_EL, XMLUtils.EMPTY_ATTRIBUTES); 54 55 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 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 contentHandler.endElement(FormsConstants.INSTANCE_NS, LABEL_EL, FormsConstants.INSTANCE_PREFIX_COLON + LABEL_EL); 79 80 contentHandler.endElement(FormsConstants.INSTANCE_NS, ITEM_EL, FormsConstants.INSTANCE_PREFIX_COLON + ITEM_EL); 82 83 contentHandler.endElement(FormsConstants.INSTANCE_NS, SELECTION_LIST_EL, FormsConstants.INSTANCE_PREFIX_COLON + SELECTION_LIST_EL); 85 } 86 } 87 | Popular Tags |