01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.forms.datatype.convertor;
18:
19: import java.util.Locale;
20:
21: import org.apache.cocoon.forms.datatype.convertor.ConversionResult;
22: import org.apache.cocoon.forms.datatype.convertor.Convertor;
23: import org.xml.sax.ContentHandler;
24: import org.xml.sax.SAXException;
25:
26: /**
27: * The CharConvertor converts a String to a Character object and viceversa.
28: *
29: * <p>Converting from char to String, returns a String only containing the input character
30: * Converting from String to char, returns a Character object created with the first char of the input String</p>
31: *
32: */
33: public class CharConvertor implements Convertor {
34:
35: public ConversionResult convertFromString(String value,
36: Locale locale, Convertor.FormatCache formatCache) {
37: Character c = new Character(value.charAt(0));
38: return new ConversionResult(c);
39: }
40:
41: public String convertToString(Object value, Locale locale,
42: Convertor.FormatCache formatCache) {
43: Character c = (Character) value;
44: if (c.charValue() == 0)
45: return "";
46: return c.toString();
47: }
48:
49: public Class getTypeClass() {
50: return Character.class;
51: }
52:
53: public void generateSaxFragment(ContentHandler contentHandler,
54: Locale locale) throws SAXException {
55: // intentionally empty
56: }
57: }
|