KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > module > admininterface > dialogs > LanguageSelect


1 /**
2  *
3  * Magnolia and its source-code is licensed under the LGPL.
4  * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5  * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6  * you are required to provide proper attribution to obinary.
7  * If you reproduce or distribute the document without making any substantive modifications to its content,
8  * please use the following attribution line:
9  *
10  * Copyright 1993-2005 obinary Ltd. (http://www.obinary.com) All rights reserved.
11  *
12  */

13 package info.magnolia.module.admininterface.dialogs;
14
15 import info.magnolia.cms.core.Content;
16 import info.magnolia.cms.gui.control.SelectOption;
17 import info.magnolia.cms.gui.dialog.DialogSelect;
18 import info.magnolia.cms.i18n.MessagesManager;
19 import info.magnolia.context.MgnlContext;
20
21 import java.util.ArrayList JavaDoc;
22 import java.util.Collection JavaDoc;
23 import java.util.Collections JavaDoc;
24 import java.util.Comparator JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.List JavaDoc;
27 import java.util.Locale JavaDoc;
28
29 import javax.jcr.RepositoryException;
30 import javax.servlet.http.HttpServletRequest JavaDoc;
31 import javax.servlet.http.HttpServletResponse JavaDoc;
32
33 import org.apache.commons.lang.StringUtils;
34
35
36 /**
37  * Select one of the supported lanuge
38  * @author Philipp Bracher
39  * @version $Revision: 6341 $ ($Author: philipp $)
40  */

41 public class LanguageSelect extends DialogSelect {
42
43     /**
44      * @see info.magnolia.cms.gui.dialog.DialogSelect#init(javax.servlet.http.HttpServletRequest,
45      * javax.servlet.http.HttpServletResponse, info.magnolia.cms.core.Content, info.magnolia.cms.core.Content)
46      */

47     public void init(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response, Content websiteNode, Content configNode)
48         throws RepositoryException {
49         super.init(request, response, websiteNode, configNode);
50
51         List JavaDoc options = new ArrayList JavaDoc();
52
53         Collection JavaDoc col = MessagesManager.getAvailableLocales();
54
55         for (Iterator JavaDoc iter = col.iterator(); iter.hasNext();) {
56             Locale JavaDoc locale = (Locale JavaDoc) iter.next();
57             String JavaDoc code = locale.getLanguage();
58             if (StringUtils.isNotEmpty(locale.getCountry())) {
59                 code += "_" + locale.getCountry(); //$NON-NLS-1$
60
}
61             String JavaDoc name = locale.getDisplayName(MgnlContext.getLocale());
62             SelectOption option = new SelectOption(name, code);
63             options.add(option);
64         }
65
66         // sort them
67
Collections.sort(options, new Comparator JavaDoc() {
68
69             public int compare(Object JavaDoc arg0, Object JavaDoc arg1) {
70                 try {
71                     String JavaDoc name0 = ((SelectOption) arg0).getLabel();
72                     String JavaDoc name1 = ((SelectOption) arg1).getLabel();
73                     return name0.compareTo(name1);
74                 }
75                 catch (Exception JavaDoc e) {
76                     return 0;
77                 }
78             }
79         });
80
81         this.setOptions(options);
82     }
83 }
84
Popular Tags