Skip to Content
author's profile photo
Former Member

Accessing profiles of other components

Hi,

Is there any way of accessing the profile of another component from a component? The two components are in the same namespace.

rgds

kiran

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

1 Answer

  • author's profile photo
    Former Member
    Sep 30, 2005 at 04:00 PM

    This is how you do it,

    Give the component's path (including pcd..) of the component whose profile u need to access..like this:

    IPortalComponentContext context = request.getComponentContext("pcd:/portal_content/xxxx/iview");

    IPortalComponentProfile profile = context.getProfile();

    String thisColor = profile.getProperty("color");

    Let me know if u need more.

    Regards,

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      (Or) Try this:

      <b>iviewPath</b>: if u can pass the iviewpath dynamically using EPCM bag or cookies to this application then u cud find the title.

      try {
      		   Context initialContext = getEnvironment(request);
      		   IPcdContext targetObject = (IPcdContext)initialContext.lookup(<b>iviewPath</b>);
      		
      			Object object = targetObject.getAttributes("").get("com.sap.portal.pcm.Title");
      			//Object object1 = targetObject.getAttributes("").get("com.sap.portal.pcm.Description");
      			if(object instanceof IPcdAttribute){
      				IPcdAttribute att = (IPcdAttribute)object;
      				objtitle = att.get(request.getLocale());
      			}
      		/*	
      			if(object1 instanceof IPcdAttribute){
      				IPcdAttribute att = (IPcdAttribute)object1;
      				objdesc = att.get(request.getLocale());
      			}
              */
      			
      	   } catch (NamingException e) {
      			   e.printStackTrace();
      	   } 
      }
      
      	public InitialContext getEnvironment(IPortalComponentRequest request) {
      			InitialContext initialContext = null;
      			try{
      				IUser principalObj = null;
      			
      				principalObj = this.getServiceUser("pcd_service");
      				Hashtable env = new Hashtable();
      				env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sapportals.portal.pcd.gl.PcdInitialContextFactory");
      					if(principalObj!=null){
      						env.put(Context.SECURITY_PRINCIPAL,principalObj);			
      					}
      				env.put("com.sap.portal.jndi.requested_aspect","com.sap.portal.pcd.gl.PersistencyAspect");
      				env.put("java.naming.factory.object","_IPcdContext_");
      				initialContext = new InitialContext(env);
      			}catch(NamingException e){
      			}
      			return initialContext;
      		}
      
      	
      		public IUser getServiceUser(String username) {
      		IUser serviceUser = null;
      		IUserManagementEngine ume = 
      				(IUserManagementEngine)PortalRuntime
      				.getRuntimeResources()
      				.getService(IUserManagementEngine.KEY);
      			
      		IServiceUserFactory sufactory = ume.getServiceUserFactory();	
      	
      		try {
      			serviceUser = sufactory.getServiceUser(username);
      		} catch (UMException e) {
      		
      			e.printStackTrace();
      		}
      	
      		
      			return serviceUser;
      		}

      <b>PS: Please award points for helpful answers</b>