001: /**
002: * $Id: PortletResourceMap.java,v 1.3 2006/04/19 06:48:19 mg155852 Exp $
003: * Copyright 2003 Sun Microsystems, Inc. All
004: * rights reserved. Use of this product is subject
005: * to license terms. Federal Acquisitions:
006: * Commercial Software -- Government Users
007: * Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011: * are trademarks or registered trademarks of Sun Microsystems,
012: * Inc. in the United States and other countries.
013: */package com.sun.portal.wsrp.producer;
014:
015: import javax.servlet.ServletContext;
016:
017: import java.util.Map;
018:
019: import com.sun.portal.portletcontainercommon.PortletContainerConstants;
020: import com.sun.portal.wsrp.producer.portletmanagement.impl.PortletManagementManagerImpl;
021:
022: public class PortletResourceMap {
023: public static class PortletEntityIDPrefix {
024: private String appName = null;
025: private String name = null;
026:
027: public PortletEntityIDPrefix(String entityIDPrefix) {
028: if (entityIDPrefix == null) {
029: return;
030: }
031:
032: int sepIndex = entityIDPrefix.indexOf('|');
033: if (sepIndex == -1) {
034: return;
035: }
036:
037: appName = entityIDPrefix.substring(0, sepIndex);
038: name = entityIDPrefix.substring(sepIndex + 1);
039: }
040:
041: public String getAppName() {
042: return appName;
043: }
044:
045: public String getName() {
046: return name;
047: }
048:
049: public String toString() {
050: return "{ appName=" + getAppName() + ", name=" + getName()
051: + " }";
052: }
053: }
054:
055: public static Map get(ServletContext servletContext,
056: String portletName, String entityIDPrefix)
057: throws ProducerException {
058: //String entityIDPrefix = getDPStringProperty(portletName, PDProviderEntryGenerator.ENTITY_ID_PREFIX_NAME);
059: //ISConnection.debug.error("ServiceDescriptionManagerImpl.getPortletResourceMap(): entityIDPrefix=" + entityIDPrefix);
060:
061: PortletEntityIDPrefix peidp = new PortletEntityIDPrefix(
062: entityIDPrefix);
063: //ISConnection.debug.error("ServiceDescriptionManagerImpl.getPortletResourceMap(): peidp=" + peidp.toString());
064:
065: String appName = peidp.getAppName();
066: if (appName == null) {
067: throw new ProducerException(
068: "could not get app name for portletName="
069: + portletName);
070: }
071: appName = "/" + appName;
072:
073: String name = peidp.getName();
074: if (name == null) {
075: throw new ProducerException(
076: "could not get name for portletName=" + portletName);
077: }
078:
079: if (servletContext == null) {
080: return null;
081: }
082: //Obtain appContext for portlet webapp
083: //one portlet webapp can contain multiple portlet
084: ServletContext appContext = servletContext.getContext(appName);
085: if (appContext == null) {
086: throw new ProducerException(
087: "could not get app context for portletName="
088: + portletName + ", appName=" + appName);
089: }
090:
091: //getAttribute will return MetaDataResource associated with all the portlets in the webapp.
092: //Key - portletname
093: //value - another map (containg key as locale string and value as PortletMetaDataResource class.
094: Map resourcesMap = (Map) appContext
095: .getAttribute(PortletContainerConstants.PORTLET_METADATA_RESOURCES);
096: if (resourcesMap == null) {
097: return null;
098: }
099:
100: portletName = PortletManagementManagerImpl
101: .decodeClonedChannelName(portletName);
102: Map portletMap = (Map) resourcesMap.get(portletName);
103: if (portletMap == null) {
104: return null;
105: }
106:
107: return portletMap;
108: }
109: }
|