KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > web > ui > common > converter > BooleanLabelConverter


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.web.ui.common.converter;
18
19 import java.util.ResourceBundle JavaDoc;
20
21 import javax.faces.component.UIComponent;
22 import javax.faces.context.FacesContext;
23 import javax.faces.convert.Converter;
24 import javax.faces.convert.ConverterException;
25
26 import org.alfresco.web.app.Application;
27
28 /**
29  * Converter class to convert a Boolean value (including null) into a human readable form.
30  *
31  * @author Kevin Roast
32  */

33 public class BooleanLabelConverter implements Converter
34 {
35    /**
36     * <p>The standard converter id for this converter.</p>
37     */

38    public static final String JavaDoc CONVERTER_ID = "org.alfresco.faces.BooleanLabelConverter";
39    
40    private static final String JavaDoc MSG_YES = "yes";
41    private static final String JavaDoc MSG_NO = "no";
42    
43    /**
44     * @see javax.faces.convert.Converter#getAsObject(javax.faces.context.FacesContext, javax.faces.component.UIComponent, java.lang.String)
45     */

46    public Object JavaDoc getAsObject(FacesContext context, UIComponent component, String JavaDoc value)
47          throws ConverterException
48    {
49       return Boolean.valueOf(value);
50    }
51
52    /**
53     * @see javax.faces.convert.Converter#getAsString(javax.faces.context.FacesContext, javax.faces.component.UIComponent, java.lang.Object)
54     */

55    public String JavaDoc getAsString(FacesContext context, UIComponent component, Object JavaDoc value)
56          throws ConverterException
57    {
58       ResourceBundle JavaDoc bundle = Application.getBundle(context);
59       
60       String JavaDoc result = bundle.getString(MSG_NO);
61       
62       if (value instanceof Boolean JavaDoc)
63       {
64          result = ((Boolean JavaDoc)value).booleanValue() ? bundle.getString(MSG_YES) : bundle.getString(MSG_NO);
65       }
66       
67       return result;
68    }
69 }
70
Popular Tags