Portal Scripting Interface and content mappings
With the Portal Scripting Interface, you can create scripts that you can use to automate the management of content mappings between Web content pages and folders in Web content system. Using the ContentMapping bean with the Portal Scripting Interface, you can add, modify, and remove content mappings.Before a script can work with content mappings through the ContentMapping bean, establish a user session with the portal using the login command of the Portal bean. The user identity must have sufficient permissions to administer the Web content pages and Web content library folders referenced by the script.
Retrieve content mappings
To retrieve content mapping information, use the select method to specify the object ID of the Web content page. You can often derive the object ID for a resource from another bean and use that as input for the select method. For example, to retrieve the content mappings for a Web content page with the unique name my.test.page, you can use the find method of the Content bean to determine the object ID of the Web content page.Jacl example:
$set the_page [$Content find page uniquename "my.test.page"] $ContentMapping select $the_pageJython example:
the_page = Content.find('page','uniquename','my.test.page') ContentMapping.select(the_page)After you have the object ID of the Web content page, you can use the list and get methods to access the content mappings. The list method returns a list of content mapping IDs, which can be either the resource ID of a folder or the content path of the folder, depending on how the Web content page is mapped. You can use the content mapping IDs returned by the list method as arguments for the get method.
Jacl example:
$set the_page [$Content find page uniquename "my.test.page"] $ContentMapping select $the_page foreach mid [$ContentMapping list mappings] { puts " Mapping $mid info:" puts " content id: [$ContentMapping get $mid content-id]" puts " default? [$ContentMapping get $mid isdefault]" puts " scope: [$ContentMapping get $mid scope]" }Jython example:
var the_page = Content.find('page','uniquename','my.test.page') ContentMapping.select(the_page) for mid in ContentMapping.list('mappings').split(): print " Mapping "+mid+" info:" print " content id: "+ContentMapping get(mid,'content-id') print " default? "+ContentMapping get(mid,'isdefault') print " scope: "+ContentMapping get(mid,'scope')In addition the get method can return the default mapping for the selected Web content page, and the list method can retrieve a list of scopes defined for the mappings of the Web content page.
Jacl example:
$set the_page [$Content find page uniquename "my.test.page"] $ContentMapping select $the_page puts "available scopes: [$ContentMapping list scopes]" puts "default mapping: [$ContentMapping get defaultmapping]" puts "portal resource OID: [$ContentMapping get oid]"Jython example:
var the_page = Content.find('page','uniquename','my.test.page') ContentMapping.select(the_page) print "available scopes: "+ContentMapping.list('scopes') print "default mapping: "+ContentMapping.get('defaultmapping') print "portal resource OID: "+ContentMapping.get('oid')
Add content mappings
Use the add method to add new content mappings to a Web content page. You can assign a content mapping by specifying the content path of the folder or the ID of folder. If you identify the folder by content path, the mapping will be internally transformed to actually point to the ID of the folder. As a result, if you rename the folder later on, the mapping will still point to the same folder.Jacl example:
$ContentMapping select [$ContentNode find page uniquename "my.sample.page"] $ContentMapping add content-path "/test1/mapping" set the_content_id .... ## obtain ID of content to be mapped $ContentMapping add id $the_content_idJython example:
ContentMapping.select(Content.find('all','un','my.sample.page')) ContentMapping.add('content-path','/test1/mapping') var the_content_id = ... ## obtain ID of content to be mapped ContentMapping.add('id',the_content_id)
Remove content mappings
The ContentMapping bean provides two methods you can use to remove content mappings from a Web content page:
- remove: Removes an individual content mapping, as specified either by the resource ID of the folder or the content path of the folder.
- delete: Removes all content mappings for the Web content page.
The following examples demonstrate how to remove the content mappings for two Web content pages. The content mappings of the first page are removed individually with the remove method, and the content mappings of the second page are removed with the delete method.
Jacl Example:
$set the_first_page [$Content find page uniquename "my.test.page"] $ContentMapping select $the_first_page foreach mid [$ContentMapping list mappings] { $ContentMapping remove $mid } $set another_page [$Content find page uniquename "my.second.test.page"] $ContentMapping select $another_page $ContentMapping deleteJython Example:
var the_page = Content.find('page','uniquename','my.test.page') ContentMapping.select(the_first_page) for mid in ContentMapping.list('mappings').split(): ContentMapping.remove(mid) var another_page = Content.find('page','uniquename','my.second.test.page') ContentMapping.select(another_page) ContentMapping.delete()
Modify content mappings
To modify content mappings, use the set method of the ContentMapping bean. You can change the following attributes:
- Default flag
- Delegation mode
- Mapping scope
When calling the set method, pass in the ID of the content mapping that you want to update.
The following example updates two content mappings for the Web content page identified by the unique name my.test.page. For the first content mapping, the default flag is set to make this the default content mapping for the Web content page, the mapping scope is specified as _scp_, and page-based access control is turned off by setting the delegation mode to false. For the second content mapping, the mapping scope is removed by specifying an empty string.
Jacl Example:
$ContentMapping select [$ContentNode find page uniquename "my.sample.page"] set first_m_id [lindex [$ContentMapping list mappings] 0] $ContentMapping set scope $first_m_id "_scp_" $ContentMapping set default $first_m_id true $ContentMapping set delegation $first_m_id false set second_m_id [lindex [$ContentMapping list mappings] 1] $ContentMapping set scope $second_m_id ""Jython Example:
ContentMapping.select(Content.find('all','un','my.sample.page')) var first_m_id = ContentMapping.list('mappings').split() [0] ContentMapping.set('scope',first_m_id,'_scp_') ContentMapping.set('default',first_m_id,'true') ContentMapping.set('delegation',first_m_id,'false') var second_m_id = ContentMapping.list('mappings').split() [1] ContentMapping.set('scope',second_m_id,'')
Content mappings
Related reference
December 14, 2011
Apr 1, 2011 1:26:17 PM
});