| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package javax.faces.convert; |
| 17 | |
|
| 18 | |
import javax.faces.component.UIComponent; |
| 19 | |
import javax.faces.context.FacesContext; |
| 20 | |
import javax.faces.internal.ConvertUtil; |
| 21 | |
import javax.faces.internal.FacesMessageUtil; |
| 22 | |
|
| 23 | |
import org.seasar.framework.util.AssertionUtil; |
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
public class CharacterConverter implements Converter { |
| 29 | |
|
| 30 | |
public static final String CONVERTER_ID = "javax.faces.Character"; |
| 31 | |
|
| 32 | 2 | public static final String CONVERSION_OBJECT_ID = CharacterConverter.class |
| 33 | |
.getName() |
| 34 | |
+ ".CONVERSION"; |
| 35 | |
|
| 36 | 1 | public static final String CONVERSION_STRING_ID = CharacterConverter.class |
| 37 | |
.getName() |
| 38 | |
+ ".CONVERSION_STRING"; |
| 39 | |
|
| 40 | 12 | public CharacterConverter() { |
| 41 | 12 | } |
| 42 | |
|
| 43 | |
public Object getAsObject(FacesContext context, UIComponent component, |
| 44 | |
String value) throws ConverterException { |
| 45 | 5 | AssertionUtil.assertNotNull("FacesContext", context); |
| 46 | 4 | AssertionUtil.assertNotNull("UIComponent", component); |
| 47 | 3 | if (value == null) { |
| 48 | 1 | return null; |
| 49 | |
} |
| 50 | 2 | value = value.trim(); |
| 51 | 2 | if (value.length() < 1) { |
| 52 | 1 | Object[] args = ConvertUtil.createExceptionMessageArgs(component, |
| 53 | |
value); |
| 54 | 1 | throw new ConverterException(FacesMessageUtil.getMessage(context, |
| 55 | |
getObjectMessageId(), args)); |
| 56 | |
} |
| 57 | |
try { |
| 58 | 1 | return new Character(value.charAt(0)); |
| 59 | 0 | } catch (Exception e) { |
| 60 | 0 | Object[] args = ConvertUtil.createExceptionMessageArgs(component, |
| 61 | |
value); |
| 62 | 0 | throw new ConverterException(FacesMessageUtil.getMessage(context, |
| 63 | |
getObjectMessageId(), args), e); |
| 64 | |
} |
| 65 | |
} |
| 66 | |
|
| 67 | |
public String getAsString(FacesContext context, UIComponent component, |
| 68 | |
Object value) throws ConverterException { |
| 69 | 7 | AssertionUtil.assertNotNull("FacesContext", context); |
| 70 | 6 | AssertionUtil.assertNotNull("UIComponent", component); |
| 71 | 5 | if (value == null) { |
| 72 | 1 | return ""; |
| 73 | |
} |
| 74 | |
try { |
| 75 | 4 | return (value instanceof String) ? (String) value |
| 76 | |
: ((Character) value).toString(); |
| 77 | 1 | } catch (Exception e) { |
| 78 | 1 | Object[] args = ConvertUtil.createExceptionMessageArgs(component, |
| 79 | |
value); |
| 80 | 1 | throw new ConverterException(FacesMessageUtil.getMessage(context, |
| 81 | |
getStringMessageId(), args), e); |
| 82 | |
} |
| 83 | |
} |
| 84 | |
|
| 85 | |
protected String getObjectMessageId() { |
| 86 | 1 | return CONVERSION_OBJECT_ID; |
| 87 | |
} |
| 88 | |
|
| 89 | |
protected String getStringMessageId() { |
| 90 | 1 | return CONVERSION_STRING_ID; |
| 91 | |
} |
| 92 | |
|
| 93 | |
} |