Accessing Portal Iviews using PCD API - SCN

58 downloads 5385 Views 440KB Size Report
Accessing Portal Iviews using PCD API Applies to: SAP Portal 7.0+.For more information, ... Adobe flex & Java Dictionary . Accessing Portal Iviews using PCD API
Accessing Portal Iviews using PCD API

Applies to: SAP Portal 7.0+.For more information, visit the Portal and Collaboration homepage.

Summary The article describes the concept and procedure of Accessing Portal Iviews using PCD API Author:

Nilesh Rane

Company: Larsen & Toubro Infotech Limited Created on: 27 March 2010

Author Bio Nilesh Rane is a SAP NetWeaver Consultant in Larsen & Toubro Infotech Limited. He has three years of SAP Portal experience. He has worked extensively in WebDynpro - Java, EPortal, J2EE, SOAP Web Services, Adobe flex & Java Dictionary

SAP COMMUNITY NETWORK © 2010 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com 1

Accessing Portal Iviews using PCD API

Table of Contents Concepts ............................................................................................................................................................. 3 Purpose ........................................................................................................................................................... 3 Portal Content Directory (PCD) ....................................................................................................................... 3 Aspects ............................................................................................................................................................... 4 Developing a Portal Application Project ............................................................................................................. 5 Summary ....................................................................................................................................................... 13 Related Content ................................................................................................................................................ 14 Disclaimer and Liability Notice .......................................................................................................................... 15

SAP COMMUNITY NETWORK © 2010 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com 2

Accessing Portal Iviews using PCD API

Concepts Purpose The Portal Content Directory (PCD) is the main repository for portal content, both delivered with the portal and created by administrators. The PCD contains a hierarchy of folders, each of which can contain semantic objects, such as iViews, pages and roles. We can access these iviews using PCD API and modify attributes of the Portal iView.. Portal Content Directory (PCD) The PCD stores portal objects, and provides an API to enable applications to perform lookups and modify the PCD. The following shows the major components involved when working with the PCD:



Portal Database: Stores portal objects.



Portal Content Directory (PCD): A JNDI provider that provides an API for querying portal objects.



Semantic Object Providers: Each provider defines the logic for returning Java objects when querying a specific portal semantic object. A semantic object is defined by its com.sap.portal.pcd.gl.ObjectClass property.



Portal Content Model (PCM): A set of common interfaces for all portal objects. Administration editors, for example, request PCM interfaces when querying the PCD and other repositories for portal objects. These editors need higher-level interfaces than those provided by the PCD, but do not need the specific interfaces for the different semantic objects

SAP COMMUNITY NETWORK © 2010 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com 3

Accessing Portal Iviews using PCD API

Aspects The aspect of a PCD lookup is an environment variable that specifies the type of object that should be returned when performing a PCD lookup. For example, when looking up a page, you may want to return an IPage object, which contains methods related to a page, such as for adding iViews to the page or setting the layout. Instead, you may want an IAttributeSet, which provides a generic interface that provides access to all the administrative attributes of the page, whether they are defined in the PCD or elsewhere. The aspect is set with the com.sap.portal.directory.Constants.REQUESTED_ASPECT environment variable. It is up to the object provider for the type of object that is requested to read this value and return an appropriate object. The value of the REQUESTED_ASPECT constant is com.sap.portal.jndi.requested_aspect. You can specify it with a string, and thereby not need a reference to jndisupport.jar The following table shows the available aspects, and the interfaces that are returned for each: Aspect

Value of Environment Variable

Object Types Returned

Semantic

PcmConstants.ASPECT_SEMANTICS

IiView IPage ILayout ISystem

Administration

PcmConstants.ASPECT_ADMINISTRATION

IAdminBase From the IAdminBase interface, you can also derive the following interfaces with the getImplementation() method: ICatalogNode IPermission IAttributeSet

Persistence

IPcdAttribute.PERSISTENCY_ASPECT

IPcdContext

If no aspect is specified or an aspect is not recognized by an object factory, the object factory returns the default object. For folders, this is an IPcdContext; for semantic objects, this is the Java semantic object.

SAP COMMUNITY NETWORK © 2010 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com 4

Accessing Portal Iviews using PCD API

Developing a Portal Application Project 

Open NWDS in EPortal Perspective

Select File -> New -> Other -> Portal application -> Create a Portal application Project

SAP COMMUNITY NETWORK © 2010 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com 5

Accessing Portal Iviews using PCD API

Give any meaningful name and click on finish.



Now, create Portal Object inside the project.



Right Click on Project and Select File -> New -> Other-> Portal application -> Portal Application Object.

SAP COMMUNITY NETWORK © 2010 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com 6

Accessing Portal Iviews using PCD API

Select AbstractPortalComponent from the List and click on Next Button.



Enter Object name and select a package and click on Finish button.

SAP COMMUNITY NETWORK © 2010 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com 7

Accessing Portal Iviews using PCD API



Open the class file and type following code in the doContent() method..

IiView iView = null; public void doContent(IPortalComponentRequest request, IPortalComponentResponse response) { Hashtable ht_env = new Hashtable(); //Setting environment variables ht_env.put(Context.INITIAL_CONTEXT_FACTORY,IPcdContext.PCD_INITIAL_CONTEXT_FACTORY ); ht_env.put(Context.SECURITY_PRINCIPAL, request.getUser()); ht_env.put(Constants.REQUESTED_ASPECT, PcmConstants.ASPECT_SEMANTICS); InitialContext iCtx = null; try { iCtx = new InitialContext(ht_env); Object currentObject = iCtx.lookup("portal_content/google"); if (currentObject instanceof IiView) { iView = (IiView) currentObject; }else{ response.write(currentObject.getClass().getName()); response.write("

");

SAP COMMUNITY NETWORK © 2010 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com 8

Accessing Portal Iviews using PCD API

} Enumeration enum = iView.getAttributeIds(); if(enum!=null){ while(enum.hasMoreElements()){ String str = (String)enum.nextElement(); //Displaying all the attributes of the iview response.write("Attribute : " + str + " : " + iView.getAttribute(str) + "
"); } } try { //setting few attributes of the iview //Setting Forced Request Language to German iView.putAttribute("ForcedRequestLanguage","de"); iView.save(); } catch (ValidationException e1) { response.write(e1.getMessage()); } catch (IOException e1) { response.write(e1.getMessage()); } } catch (NamingException e) { response.write(e.getMessage()); } } Similarly you can access page also. IPage myPage =(IPage)iCtx.lookup("pcd:portal_content/MyPage");



Import following jars into the classpath Com.sap.portal.ivs.api_iview_api.jar Com.sap.portal.pcd.glservice_api.jar Gl_api.jar Htmlb.jar Prtjndisupport.jar Tc~epbc~pcm~adminapi~java.jar



Now, we have to create an iview (url iview) on portal. This is target iview. (We are accessing properties of this iview) (Note that for this, you should have content Admin Rights for portal)



Logon To Portal and click on Content Admin tab and open Portal Content Folder

SAP COMMUNITY NETWORK © 2010 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com 9

Accessing Portal Iviews using PCD API



Right click on Portal content and Select New ->iview



Select url iview from template.



Click on Next button. Enter iview name & id and click on Next



Provide url for Google.com and click on Next Button

SAP COMMUNITY NETWORK © 2010 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com 10

Accessing Portal Iviews using PCD API



Check the parameter ForcedRequestLanguage Nothing is selected (By default its English (en)



Click on Finish button.



Now create an iview (Source iview) from your Portal Application



Again follow the same procedure but Now Select Portal Component to create iview.



From the List, Select the Portal Component which you have created.

SAP COMMUNITY NETWORK © 2010 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com 11

Accessing Portal Iviews using PCD API



Select Object from the Portal component



Enter name and id for the iview and click on Finish



Open another session of portal and click on your Application iview. It will show all the attributes of the iview (URL iview google.com).



Now check the attribute which you have set (ForcedRequestLanguage)

SAP COMMUNITY NETWORK © 2010 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com 12

Accessing Portal Iviews using PCD API

Summary Thus, we have understood the how we can access PCD iviews & PCD aspects using PCD API.

SAP COMMUNITY NETWORK © 2010 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com 13

Accessing Portal Iviews using PCD API

Related Content http://help.sap.com/saphelp_nw70/helpdata/en/44/43863b2e641193e10000000a155369/frameset.htm http://help.sap.com/saphelp_nw70/helpdata/en/44/70402d200512d0e10000000a422035/frameset.htm http://help.sap.com/saphelp_nw70/helpdata/en/44/6aaf92f5a23672e10000000a114a6b/frameset.htm http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/6112ecb7-0a01-0010-ef90-941c70c9e401 For more information, visit the Portal and Collaboration homepage.

SAP COMMUNITY NETWORK © 2010 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com 14

Accessing Portal Iviews using PCD API

Disclaimer and Liability Notice This document may discuss sample coding or other information that does not include SAP official interfaces and therefore is not supported by SAP. Changes made based on this information are not supported and can be overwritten during an upgrade. SAP will not be held liable for any damages caused by using or misusing the information, code or methods suggested in this document, and anyone using these methods does so at his/her own risk. SAP offers no guarantees and assumes no responsibility or liability of any type with respect to the content of this technical article or code sample, including any liability resulting from incompatibility between the content within this document and the materials and services offered by SAP. You agree that you will not hold, or seek to hold, SAP responsible or liable with respect to the content of this document.

SAP COMMUNITY NETWORK © 2010 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com 15