001: /* Copyright 2003 The JA-SIG Collaborative. All rights reserved.
002: * See license distributed with this file and
003: * available online at http://www.uportal.org/license.html
004: */
005:
006: package org.jasig.portal.layout.channels;
007:
008: import java.io.IOException;
009: import java.io.InputStream;
010:
011: import org.jasig.portal.ChannelRuntimeData;
012: import org.jasig.portal.IPrivileged;
013: import org.jasig.portal.IUserPreferencesManager;
014: import org.jasig.portal.PortalControlStructures;
015: import org.jasig.portal.PortalException;
016: import org.jasig.portal.PortalSessionManager;
017: import org.jasig.portal.UserPreferences;
018: import org.jasig.portal.channels.BaseChannel;
019: import org.jasig.portal.layout.IUserLayoutStore;
020: import org.jasig.portal.layout.UserLayoutStoreFactory;
021: import org.jasig.portal.properties.PropertiesManager;
022: import org.apache.commons.logging.Log;
023: import org.apache.commons.logging.LogFactory;
024: import org.jasig.portal.utils.XSLT;
025: import org.xml.sax.ContentHandler;
026:
027: /**
028: * A channel for selecting skins.
029: *
030: * The path to the available skins is configured by the portal.properties
031: * property "org.jasig.portal.layout.channels.CSkinSelector.skins_path" as
032: * mediated by PropertiesManager. If that property is not configured, the path
033: * "media/org/jasig/portal/layout/tab-column/xhtml-theme" is used.
034: *
035: * @author Michael Ivanov, mvi@immagic.com
036: * @version $Revision: 36794 $
037: */
038: public class CSkinSelector extends BaseChannel implements IPrivileged {
039:
040: private static final Log log = LogFactory
041: .getLog(CSkinSelector.class);
042:
043: private static final String SKINS_PATH = PropertiesManager
044: .getProperty(CSkinSelector.class.getName() + ".skins_path",
045: "media/org/jasig/portal/layout/tab-column/xhtml-theme");
046:
047: private static final String sslLocation = "/org/jasig/portal/channels/CSkinSelector/CSkinSelector.ssl";
048: private PortalControlStructures controlStructures;
049: private IUserPreferencesManager upm;
050: private static IUserLayoutStore store = UserLayoutStoreFactory
051: .getUserLayoutStoreImpl();
052:
053: public CSkinSelector() {
054: super ();
055: }
056:
057: /**
058: * Passes portal control structure to the channel.
059: * @see PortalControlStructures
060: */
061: public void setPortalControlStructures(PortalControlStructures pcs)
062: throws PortalException {
063: controlStructures = pcs;
064: if (upm == null)
065: upm = controlStructures.getUserPreferencesManager();
066: }
067:
068: public void setRuntimeData(ChannelRuntimeData rd)
069: throws PortalException {
070: runtimeData = rd;
071: String action = runtimeData.getParameter("action");
072: if (action != null) {
073: if (runtimeData.getParameter("submitSave") != null) {
074: String skinName = runtimeData.getParameter("skinName");
075: UserPreferences userPrefs = upm.getUserPreferences();
076: userPrefs.getThemeStylesheetUserPreferences()
077: .putParameterValue("skin", skinName);
078: saveUserPreferences(userPrefs);
079: }
080: }
081: }
082:
083: private void saveUserPreferences(UserPreferences userPrefs)
084: throws PortalException {
085: try {
086: store.putUserPreferences(staticData.getPerson(), userPrefs);
087: } catch (Exception e) {
088: throw new PortalException(e);
089: }
090: }
091:
092: public void renderXML(ContentHandler out) throws PortalException {
093:
094: InputStream xmlStream = null;
095: try {
096: xmlStream = PortalSessionManager
097: .getResourceAsStream(SKINS_PATH + "/skinList.xml");
098: UserPreferences userPrefs = upm.getUserPreferences();
099: String currentSkin = userPrefs
100: .getThemeStylesheetUserPreferences()
101: .getParameterValue("skin");
102:
103: XSLT xslt = XSLT.getTransformer(this , runtimeData
104: .getLocales());
105: xslt.setXML(xmlStream);
106: xslt.setXSL(sslLocation, "skinSelector", runtimeData
107: .getBrowserInfo());
108: xslt.setTarget(out);
109: xslt.setStylesheetParameter("skinsPath", SKINS_PATH);
110: xslt.setStylesheetParameter("baseActionURL", runtimeData
111: .getBaseActionURL());
112: if (currentSkin != null)
113: xslt.setStylesheetParameter("currentSkin", currentSkin);
114: xslt.transform();
115: } finally {
116: try {
117: if (xmlStream != null)
118: xmlStream.close();
119: } catch (IOException ioe) {
120: log
121: .error("CSkinSelector:renderXML():: Can not close InputStream "
122: + ioe);
123: }
124: }
125: }
126:
127: }
|