KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > web > ui > repo > converter > MimeTypeConverter


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.repo.converter;
18
19 import javax.faces.component.UIComponent;
20 import javax.faces.context.FacesContext;
21 import javax.faces.convert.Converter;
22
23 import org.alfresco.service.cmr.repository.MimetypeService;
24 import org.alfresco.web.bean.repository.Repository;
25
26 /**
27  * Converter class to convert an XML date representation into a Date
28  *
29  * @author gavinc
30  */

31 public class MimeTypeConverter implements Converter
32 {
33    /**
34     * <p>The standard converter id for this converter.</p>
35     */

36    public static final String JavaDoc CONVERTER_ID = "org.alfresco.faces.MimeTypeConverter";
37
38    /**
39     * @see javax.faces.convert.Converter#getAsObject(javax.faces.context.FacesContext, javax.faces.component.UIComponent, java.lang.String)
40     */

41    public Object JavaDoc getAsObject(FacesContext context, UIComponent component, String JavaDoc value)
42    {
43       return value;
44    }
45
46    /**
47     * @see javax.faces.convert.Converter#getAsString(javax.faces.context.FacesContext, javax.faces.component.UIComponent, java.lang.Object)
48     */

49    public String JavaDoc getAsString(FacesContext context, UIComponent component, Object JavaDoc value)
50    {
51       String JavaDoc result = null;
52       
53       if (value instanceof String JavaDoc)
54       {
55          MimetypeService mimetypeService = Repository.getServiceRegistry(context).getMimetypeService();
56          result = mimetypeService.getDisplaysByMimetype().get(value.toString());
57       }
58       else if (value != null)
59       {
60          result = value.toString();
61       }
62       
63       return result;
64    }
65 }
66
Popular Tags