001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.woody.datatype;
018:
019: import java.util.Locale;
020:
021: import org.apache.cocoon.transformation.I18nTransformer;
022: import org.apache.cocoon.woody.Constants;
023: import org.apache.cocoon.xml.AttributesImpl;
024: import org.xml.sax.ContentHandler;
025: import org.xml.sax.SAXException;
026:
027: /**
028: *
029: * @author <a href="http://www.apache.org/~sylvain/">Sylvain Wallez</a>
030: * @version CVS $Id: EmptySelectionList.java 433543 2006-08-22 06:22:54Z crossley $
031: */
032: public class EmptySelectionList implements SelectionList {
033: private String text;
034: private boolean i18n;
035:
036: public EmptySelectionList(String text) {
037: this .text = text;
038: this .i18n = false;
039: }
040:
041: public EmptySelectionList(String text, boolean i18n) {
042: this .text = text;
043: this .i18n = i18n;
044: }
045:
046: public Datatype getDatatype() {
047: // Cannot return anything meaningful
048: return null;
049: }
050:
051: public void generateSaxFragment(ContentHandler contentHandler,
052: Locale locale) throws SAXException {
053: // Start wi:selection list
054: contentHandler.startElement(Constants.WI_NS, SELECTION_LIST_EL,
055: Constants.WI_PREFIX_COLON + SELECTION_LIST_EL,
056: Constants.EMPTY_ATTRS);
057:
058: // Start wi:item
059: AttributesImpl itemAttrs = new AttributesImpl();
060: itemAttrs.addCDATAAttribute("value", "");
061: contentHandler.startElement(Constants.WI_NS, ITEM_EL,
062: Constants.WI_PREFIX_COLON + ITEM_EL, itemAttrs);
063:
064: // Start wi:label
065: contentHandler.startElement(Constants.WI_NS, LABEL_EL,
066: Constants.WI_PREFIX_COLON + LABEL_EL,
067: Constants.EMPTY_ATTRS);
068: if (this .text != null) {
069:
070: if (i18n) {
071: contentHandler.startPrefixMapping("i18n",
072: I18nTransformer.I18N_NAMESPACE_URI);
073:
074: contentHandler.startElement(
075: I18nTransformer.I18N_NAMESPACE_URI,
076: I18nTransformer.I18N_TEXT_ELEMENT, "i18n:"
077: + I18nTransformer.I18N_TEXT_ELEMENT,
078: Constants.EMPTY_ATTRS);
079: contentHandler.characters(this .text.toCharArray(), 0,
080: this .text.length());
081: contentHandler.endElement(
082: I18nTransformer.I18N_NAMESPACE_URI,
083: I18nTransformer.I18N_TEXT_ELEMENT, "i18n:"
084: + I18nTransformer.I18N_TEXT_ELEMENT);
085:
086: contentHandler.endPrefixMapping("i18n");
087: } else {
088: contentHandler.characters(this .text.toCharArray(), 0,
089: this .text.length());
090: }
091: }
092:
093: // End wi:label
094: contentHandler.endElement(Constants.WI_NS, LABEL_EL,
095: Constants.WI_PREFIX_COLON + LABEL_EL);
096:
097: // End wi:item
098: contentHandler.endElement(Constants.WI_NS, ITEM_EL,
099: Constants.WI_PREFIX_COLON + ITEM_EL);
100:
101: // End wi:selection-list
102: contentHandler.endElement(Constants.WI_NS, SELECTION_LIST_EL,
103: Constants.WI_PREFIX_COLON + SELECTION_LIST_EL);
104: }
105: }
|