01: /* Copyright 2001 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.channels;
07:
08: import java.util.Enumeration;
09: import java.util.Hashtable;
10:
11: import org.jasig.portal.ChannelRuntimeData;
12: import org.jasig.portal.PortalException;
13: import org.jasig.portal.StandaloneChannelRenderer;
14: import org.jasig.portal.UserProfile;
15: import org.jasig.portal.layout.IUserLayoutStore;
16: import org.jasig.portal.layout.UserLayoutStoreFactory;
17: import org.jasig.portal.utils.DocumentFactory;
18: import org.jasig.portal.utils.XSLT;
19: import org.w3c.dom.Document;
20: import org.w3c.dom.Element;
21: import org.xml.sax.ContentHandler;
22:
23: /**
24: * CSelectSystemProfile channel allows to establish mapping from user-Agent to a system profile.
25: * This channel is meant to be used by a guest user only. Logged in users are expected to use
26: * CUserPreferences profile management screens to achieve the establish user-Agent mappings.
27: *
28: * @author Peter Kharchenko, peterk@interactivebusiness.com
29: * @version $Revision: 35755 $
30: */
31: public class CSelectSystemProfile extends StandaloneChannelRenderer {
32: private static final String sslLocation = "CSelectSystemProfile/CSelectSystemProfile.ssl";
33: IUserLayoutStore ulsdb;
34: private Hashtable systemProfileList;
35:
36: public CSelectSystemProfile() {
37: ulsdb = UserLayoutStoreFactory.getUserLayoutStoreImpl();
38: }
39:
40: public void setRuntimeData(ChannelRuntimeData rd)
41: throws PortalException {
42: super .setRuntimeData(rd);
43: String action = runtimeData.getParameter("action");
44: if (action != null) {
45: String profileId = runtimeData.getParameter("profileId");
46: if (profileId != null && action.equals("map")) {
47: try {
48: ulsdb.setSystemBrowserMapping(this .runtimeData
49: .getBrowserInfo().getUserAgent(), Integer
50: .parseInt(profileId));
51: } catch (Exception e) {
52: throw new PortalException(e);
53: }
54: }
55: }
56: }
57:
58: protected Hashtable getSystemProfileList() throws PortalException {
59: if (systemProfileList == null) {
60: try {
61: systemProfileList = ulsdb.getSystemProfileList();
62: } catch (Exception e) {
63: throw new PortalException(e);
64: }
65: }
66:
67: return systemProfileList;
68: }
69:
70: public void renderXML(ContentHandler out) throws PortalException {
71: Document doc = DocumentFactory.getNewDocument();
72: Element edEl = doc.createElement("profiles");
73: doc.appendChild(edEl);
74: // fill out system-defined profiles
75: Element sEl = doc.createElement("system");
76: for (Enumeration spe = this .getSystemProfileList().elements(); spe
77: .hasMoreElements();) {
78: UserProfile p = (UserProfile) spe.nextElement();
79: Element pEl = doc.createElement("profile");
80: pEl.setAttribute("id", Integer.toString(p.getProfileId()));
81: pEl.setAttribute("name", p.getProfileName());
82: Element dEl = doc.createElement("description");
83: dEl.appendChild(doc.createTextNode(p
84: .getProfileDescription()));
85: pEl.appendChild(dEl);
86: sEl.appendChild(pEl);
87: }
88: edEl.appendChild(sEl);
89:
90: XSLT xslt = XSLT.getTransformer(this , runtimeData.getLocales());
91: xslt.setXML(doc);
92: xslt.setXSL(sslLocation, runtimeData.getBrowserInfo());
93: xslt.setTarget(out);
94: xslt.setStylesheetParameter("baseActionURL", runtimeData
95: .getBaseActionURL());
96: xslt.transform();
97: }
98: }
|