01: /* Copyright 2003 The JA-SIG Collaborative. All rights reserved.
02: * See license distributed with this file and
03: * available online at http://www.uportal.org/license.html
04: */
05:
06: package org.jasig.portal.layout.channels.locales;
07:
08: import java.util.Locale;
09:
10: import org.jasig.portal.ChannelRuntimeData;
11: import org.jasig.portal.IPrivileged;
12: import org.jasig.portal.IUserPreferencesManager;
13: import org.jasig.portal.PortalControlStructures;
14: import org.jasig.portal.PortalException;
15: import org.jasig.portal.channels.BaseChannel;
16: import org.jasig.portal.i18n.LocaleManager;
17: import org.jasig.portal.utils.XSLT;
18: import org.xml.sax.ContentHandler;
19:
20: /**
21: * Lets a user select his/her locale preference. The UI, for now, is
22: * limited. The user can only select one locale choice. The underlying
23: * APIs and data structures actually allow an "ordering" of locales, so
24: * this channel can be enhanced to allow the user to sort a list of locales.
25: * @author Ken Weiner, kweiner@unicon.net
26: * @version $Revision: 34761 $
27: */
28: public class CUserLocalesSelector extends BaseChannel implements
29: IPrivileged {
30:
31: private IUserPreferencesManager upm = null;
32: private LocaleManager lm = null;
33: private Locale userLocale = null;
34: private static final String sslUri = "userLocales.ssl";
35:
36: public void setPortalControlStructures(PortalControlStructures pcs)
37: throws PortalException {
38: upm = pcs.getUserPreferencesManager();
39: lm = upm.getUserPreferences().getProfile().getLocaleManager();
40: Locale[] userLocales = lm.getUserLocales();
41: if (userLocales != null && userLocales.length > 0) {
42: userLocale = userLocales[0];
43: }
44: }
45:
46: public void setRuntimeData(ChannelRuntimeData runtimeData)
47: throws PortalException {
48: this .runtimeData = runtimeData;
49: String localeString = runtimeData.getParameter("locale");
50: if (localeString != null) {
51: userLocale = LocaleManager.parseLocale(localeString);
52: try {
53: lm.persistUserLocales(new Locale[] { userLocale });
54: upm.getUserLayoutManager().loadUserLayout();
55: runtimeData.setLocales(lm.getLocales());
56: } catch (Exception e) {
57: throw new PortalException(e);
58: }
59: }
60: }
61:
62: public void renderXML(ContentHandler out) throws PortalException {
63: Locale[] locales = runtimeData.getLocales();
64: XSLT xslt = XSLT.getTransformer(this , locales);
65: xslt.setXML(LocaleManager.xmlValueOf(locales, userLocale));
66: xslt.setXSL(sslUri, runtimeData.getBrowserInfo());
67: xslt.setTarget(out);
68: xslt.setStylesheetParameter("baseActionURL", runtimeData
69: .getBaseActionURL());
70: xslt.transform();
71: }
72:
73: }
|