001: /*
002: * Copyright 2004-2005 Sun Microsystems, Inc. All
003: * rights reserved. Use of this product is subject
004: * to license terms. Federal Acquisitions:
005: * Commercial Software -- Government Users
006: * Subject to Standard License Terms and
007: * Conditions.
008: *
009: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
010: * are trademarks or registered trademarks of Sun Microsystems,
011: * Inc. in the United States and other countries.
012: */
013: package com.sun.portal.providers.portletwindow;
014:
015: import com.sun.portal.desktop.context.DesktopContextThreadLocalizer;
016: import com.sun.portal.desktop.dp.DPRoot;
017: import com.sun.portal.desktop.RequestThreadLocalizer;
018: import com.sun.portal.providers.ProviderException;
019: import com.sun.portal.providers.context.ProviderContext;
020: import com.sun.portal.providers.context.ProviderContextException;
021: import com.sun.portal.providers.context.LocalePropertiesFilter;
022:
023: import javax.servlet.http.HttpServletRequest;
024: import java.util.Iterator;
025: import java.util.Map;
026: import java.util.Set;
027: import java.util.TreeSet;
028: import java.util.Locale;
029: import java.util.List;
030:
031: public class PortletWindowProviderUtils {
032: /**
033: * Gets the entityID.
034: *
035: * EntityID is represented as <web application name>|<portlet
036: * name>|<channel name>|<web application name>|<portlet name>.
037: * It is stored in the display profile during deployment time.
038: */
039: static public String getEntityID(HttpServletRequest request,
040: String channelName, ProviderContext pc)
041: throws ProviderException {
042: try {
043: String entityIdPrefix = pc.getStringProperty(channelName,
044: "entityIDPrefix");
045: return entityIdPrefix + "|" + channelName;
046: } catch (ProviderContextException pe) {
047: throw new ProviderException(
048: "PortletWindowProviderUtils.getEntityID():"
049: + " couldn't get entityIDPrefix for chanel "
050: + channelName, pe);
051: }
052:
053: }
054:
055: //This method returns the entityIDs of all the portlet channels.
056: public static Set getEntityIDs() {
057: Set entityIDs = new TreeSet();
058: DPRoot dpRoot = DesktopContextThreadLocalizer.get().getDPRoot();
059: Set channels = dpRoot.getChannelNames();
060:
061: Iterator iter = channels.iterator();
062: while (iter.hasNext()) {
063: String chName = (String) iter.next();
064: com.sun.portal.desktop.dp.DPChannel dpc = dpRoot
065: .getChannel(chName);
066: com.sun.portal.desktop.dp.DPProvider dpro = dpc
067: .getProvider();
068: if (dpro != null) {
069: String clPr = dpro.getClassName();
070: if (clPr
071: .equals("com.sun.portal.providers.portletwindow.PortletWindowProvider")) {
072: String entityIDPrefix = (String) dpc
073: .getProperties()
074: .getString("entityIDPrefix").getValue();
075: entityIDs.add(entityIDPrefix + "|" + chName);
076: }
077: }
078: }
079: return entityIDs;
080: }
081:
082: /**
083: * Gets the roleMap property for a channel. It is stored in the
084: * display profile during deployment time.
085:
086: */
087: static public Map getRoleMap(HttpServletRequest req,
088: String channelName, ProviderContext pc)
089: throws ProviderContextException, ProviderException {
090: if (pc.existsCollectionProperty(channelName, "roleMap")) {
091: return pc.getCollectionProperty(channelName, "roleMap");
092: }
093: return null;
094:
095: }
096:
097: /**
098: * Gets the userInfoMap property for a channel. It is stored in
099: * the display profile during deployment time.
100: */
101: static public Map getUserInfoMap(HttpServletRequest req,
102: String channelName, ProviderContext pc)
103: throws ProviderContextException, ProviderException {
104: if (pc.existsCollectionProperty(channelName, "userInfoMap")) {
105: return pc.getCollectionProperty(channelName, "userInfoMap");
106: }
107: return null;
108: }
109:
110: static public String getTitle(ProviderContext pc, String channel,
111: boolean exact) throws ProviderException {
112: String title = null;
113: Locale locale = pc.getLocale();
114: if (locale == null)
115: locale = RequestThreadLocalizer.getRequest().getLocale();
116: try {
117: List pflist = LocalePropertiesFilter
118: .getLocalePropertiesFilters(locale, true);
119: title = pc.getStringProperty(channel, "title", pflist,
120: exact);
121: } catch (ProviderContextException pce) {
122: throw new ProviderException(
123: "PortletWindowProviderUtils.getTitle():"
124: + " couldn't get title for chanel "
125: + channel, pce);
126: }
127: return title;
128: }
129: }
|