1 16 package org.apache.cocoon.woody.datatype; 17 18 import java.util.Locale ; 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 ; 24 import org.xml.sax.SAXException ; 25 26 31 public class EmptySelectionList implements SelectionList { 32 private String text; 33 private boolean i18n; 34 35 public EmptySelectionList(String text) { 36 this.text = text; 37 this.i18n = false; 38 } 39 40 public EmptySelectionList(String text, boolean i18n) { 41 this.text = text; 42 this.i18n = i18n; 43 } 44 45 public Datatype getDatatype() { 46 return null; 48 } 49 50 public void generateSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException { 51 contentHandler.startElement(Constants.WI_NS, SELECTION_LIST_EL, Constants.WI_PREFIX_COLON + SELECTION_LIST_EL, Constants.EMPTY_ATTRS); 53 54 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 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 contentHandler.endElement(Constants.WI_NS, LABEL_EL, Constants.WI_PREFIX_COLON + LABEL_EL); 78 79 contentHandler.endElement(Constants.WI_NS, ITEM_EL, Constants.WI_PREFIX_COLON + ITEM_EL); 81 82 contentHandler.endElement(Constants.WI_NS, SELECTION_LIST_EL, Constants.WI_PREFIX_COLON + SELECTION_LIST_EL); 84 } 85 } 86 | Popular Tags |