Portal Scripting Interface and content associations
With the Portal Scripting Interface, you can create scripts to automate the management of content associations. Using the ContentMapping bean with the Portal Scripting Interface, you can add, modify, and remove content associations.
Retrieve content associations
To retrieve content association 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, you might have a web content page with the unique name my.test.page
. Using the find method of the Content bean, you
can determine the object ID of the my.test.page
page.
- Jacl example:
-
$set the_page [$Content find page uniquename "my.test.page"] $ContentMapping select $the_page
- Jython 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 method and the get methods to access the content associations. The list method returns a list of content association IDs. The IDs can identify either the resource ID of a folder or the content path of the folder, depending on how the page is mapped. You can use the content association 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 content-id $mid]" puts " default? [$ContentMapping get isdefault $mid]" puts " scope: [$ContentMapping get scope $mid]" }
- 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('content-id', mid) print " default? "+ContentMapping.get('isdefault', mid) print " scope: "+ContentMapping.get('scope', mid)
The get method can return the default association for the selected web content page. The list method can retrieve a list of scopes that are defined for the associations 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 associations
Use the add method to add new content associations to a web content page. You can assign a content association by specifying the content path of the folder or the ID of folder. If you identify the folder by content path, the association is internally transformed to actually point to the ID of the folder. As a result, if you rename the folder later, the association still points 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_id
- Jython 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 associations
- remove
- Removes an individual content association, as specified either by the resource ID of the folder or the content path of the folder.
- delete
- Removes all content associations for the web content page.
The following examples demonstrate how to remove the content associations for two web content pages. The content associations of the first page are removed individually with the remove method, and the content associations 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 delete
- Jython 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 associations
- Default flag
- Delegation mode
- Mapping scope
When calling the set method, pass in the ID of the content association that you want to update.
my.test.page
. Several settings are
specified for the first content association:- The default flag is set to make this content association the default content association for the web content page.
- The association scope is specified as
_scp_
. - Page-based access control is turned off by setting the delegation mode to false.
- 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,'')