Adding a ContentProvider
The following example adds a ContentProvider to an existing PortalRegistry. The following is the complete code sample: the steps explain each line.
Local ApiObject &MyPortal;
Local ApiObject &MyCPColl, &MyCProvider;
&MyPortal = %Session.GetPortalRegistry();
If NOT &MyPortal.Open(MYRECORD.PORTAL_NAME) Then
/* Do error handling */
End-if;
/* Add a ContentProvider */
&MyCPColl = &MyPortal.ContentProviders;
&MyCProvider = &MyCPColl.InsertItem("HRMS_00");
&MyCProvider.URI = "http://MYMACHINE103100/servlets/iclientservlet/HRMS/";
&MyCProvider.DefaultTemplate = "MYPORTAL_HRMS";
&MyCProvider.Description = "Updated Content Provider for HRMS";
If NOT(&MyPortal.Save()) Then
&ErrorCol = &MySession.PSMessages;
For &I = 1 to &ErrorCol.Count
&Error = &ErrorCol.Item(&I);
/* do error processing */
End-For;
&ErrorCol.DeleteAll();
End-If;To add a ContentProvider:
-
Get a Session object and a PortalRegistry.
Before you can access a PortalRegistry object, you must get a session object. The session controls access to the registry, provides error tracing, enables you to set the runtime environment, and so on. Because you want to use the existing session, use the %Session system variable (instead of the GetSession function.) In addition, you want to get a PortalRegistry. Using the GetPortalRegistry method returns a reference to an unpopulated PortalRegistry object.
&MyPortal = %Session.GetPortalRegistry(); -
Open the PortalRegistry.
After you get a PortalRegistry object, you want to open it, that is, populate it with data. Use the Open method to do this. The Open method returns a Boolean value, and this example uses that value to do error checking to make sure that the PortalRegistry is actually opened. In addition, the name of the PortalRegistry is kept in the record MYRECORD, in the field PORTAL_NAME.
If NOT &MyPortal.Open(MYRECORD.PORTAL_NAME) Then /* Do error handling */ End-if; -
Access the ContentProvider collection.
You can only add a ContentProvider to a ContentProvider collection. So you must access a ContentProvider collection first, using the ContentProviders property on a PortalRegistry.
&MyCPColl = &MyPortal.ContentProviders; -
Add the ContentProvider.
You must use the name of the ContentProvider with the InsertItem method. This example uses HRMS_00. This method does not execute automatically, that is, the ContentProvider isn't actually inserted into the database until the PortalRegistry is saved.
&MyCProvider = &MyCPColl.InsertItem("HRMS_00"); -
Further define the ContentProvider.
The URI of a ContentProvider is used in conjunction with content references to define the location of content. So you should define the URI. If a template isn't found for any of the content references on a page at runtime, the system next tries to use the DefaultTemplate defined for a ContentProvider, so you should define a default template.
&MyCProvider.URI = "http://MYMACHINE103100/servlets/iclientservlet/HRMS/"; &MyCProvider.DefaultTemplate = "MYPORTAL_HRMS"; &MyCProvider.Description = "Updated Content Provider for HRMS"; -
Save the PortalRegistry and check for errors.
Because there is no Save method with a ContentProvider, you must save the PortalRegistry to complete your changes.
You can check if there were any errors using the PSMessages property on the session object.
If NOT(&MyPortal.Save()) Then /* save didn’t complete */ &ErrorCol = &MySession.PSMessages; For &I = 1 to &ErrorCol.Count &Error = &ErrorCol.Item(&I); /* do error processing */ End-For; &ErrorCol.DeleteAll(); End-if;If there are multiple errors, all errors are logged to the PSMessages collection, not just the first occurrence of an error. As you correct each error, delete it from the PSMessages collection.
Note:
If you've called the portal registry API from an Application Engine program, all errors are also logged in the Application Engine error log tables.
See Error Handling.