Portal Scripting Interface and project support
With the Portal Scripting Interface, we can create Jacl or Jython scripts to automate the management of projects.
Use the Project bean with the Portal Scripting Interface, we can perform the following actions on projects:
- List all available projects
- Create and delete projects
- Retrieve information about a specific project
- Retrieve locale-specific attributes for projects
- Approve projects
- Publish projects
- Set active project
To run commands with the Project bean, we can use the Portal bean to set a project as the context for subsequent commands.
List projects
To retrieve a list of projects, use the listall method. This method returns the names of the projects.
- Jacl syntax: $Project listall
- Jython syntax: Project.listall()
- Jacl example:
wsadmin>$Project listall "TestProject1"
- Jython example:
wsadmin>Project.listall() '"TestProject2" "TestProject1"'
Create projects
To create a project, use the create method.
- Jacl syntax: $Project create "project_name"
- Jython syntax: Project.create("project_name")
- Jacl example:
wsadmin>$Project create "TestProject1" TestProject1
- Jython example:
Project.create("TestProject1") 'TestProject1'
If you create a project with the Portal Scripting Interface, the project is not listed with the recent projects in the project menu.
Delete projects
To delete a project, use the delete method.
- Jacl syntax: $Project delete "project_name"
- Jython syntax: Project.delete("project_name")
- Jacl example:
- wsadmin>$Project delete "TestProject1"
- Jython example:
- wsadmin>Project.delete("TestProject1")
Retrieve project details
Retrieve project details with the details method. This method returns the following information about the project: the Universally Unique Identifier (UUID), state, name, and title.
- Jacl syntax: $Project details "project_name"
- Jython syntax: Project.details("project_name")
- Jacl example:
$Project details "TestProject1" uuid : bb571f0c-2143-4bcc-ba42-358a64d75116 state: ACTIVE name : TestProject1 title: TestProject1 items: testpage1 (draft / new)
- Jython example:
wsadmin>print Project.details("TestProject1") uuid : 255f129d-cc46-4d83-823d-80f9a28d13f5 state: ACTIVE name : TestProject1 title: TestProject1 items: testpage1 (draft / new)
Retrieve translated attributes
If any project attributes are translated, such as the title or description, we can retrieve those attributes with the nlsget method. Specify the attribute with one of the following parameters:
- Title: title or t
- Description: description, descr, or d
- Jacl syntax: $Project nlsget "project_name" attribute_parameter [locale]
- Jython syntax: Project.nlsget("project_name","attribute_parameter"[,"locale"])
- Jacl example:
wsadmin>$Project nlsget "TestProject1" descr en This is the description for TestProject1.
- Jython example:
wsadmin>print Project.nlsget("TestProject1", "descr", "en") This is the description for TestProject1.If you do not specify a value for the locale parameter, the currently selected locale is used.
Approve projects
To approve the drafts in a project, use the approve method. This method approves all draft items in the project at the same time. Before we can publish a project, all items in the project must be approved.
- Jacl syntax: $Project approve "project_name"
- Jython syntax: Project.approve("project_name")
- Jacl example:
wsadmin>$Project approve "TestProject1" wsadmin>$Project details "TestProject1" uuid : bb571f0c-2143-4bcc-ba42-358a64d75116 state: PENDING name : TestProject1 title: TestProject1 items: testpage1 (draft / new / publish pending)
- Jython example:
wsadmin>Project.approve("TestProject1") wsadmin>print Project.details("TestProject1") uuid : 255f129d-cc46-4d83-823d-80f9a28d13f5 state: PENDING name : TestProject1 title: TestProject1 items: testpage1 (draft / new / publish pending)
Publish projects
To publish a project, use the publish method. Before we can publish a project, all items in the project must be approved.
- Jacl syntax: $Project publish "project_name"
- Jython syntax: Project.publish("project_name")
- Jacl example:
wsadmin>$Project publish "TestProject1" wsadmin>$Project details "TestProject1" uuid : bb571f0c-2143-4bcc-ba42-358a64d75116 state: PUBLISHED name : TestProject1 title: TestProject1 items: testpage1 (published)
- Jython example:
wsadmin>Project.publish("TestProject1") wsadmin>print Project.details("TestProject1") uuid : 255f129d-cc46-4d83-823d-80f9a28d13f5 state: PUBLISHED name : TestProject1 title: TestProject1 items: testpage1 (published)
Set active project
For commands to run within a project, use the setproject method of the Portal bean to specify the project. When invoking the setproject method, you identify the active project with the name of the project. If you invoke the setproject method without specifying a project name, the active project is cleared. When set the project during a session, the project is active immediately.
To set the active project, establish a user session with the portal using the login command of the Portal bean.
- Jacl syntax: $Project setproject "project_name"
- Jython syntax: Portal.setproject("project_name")
- Jacl example:
- wsadmin>$Portal setproject "TestProject1"
- Jython example:
- wsadmin>Portal.setproject("TestProject1")
Examples
These examples demonstrate a typical command sequence to create a page within a specific project. Each example script performs the following operations:
- Establishes a user session.
- Creates a project (myproject).
- Retrieves the details for the myproject project.
- Sets the active project to the myproject project.
- Locates the Home page in the portal.
- Creates the testpage1 page as a child page of the Home page. This operation takes place within the context of the active project.
- Clears the active project.
- Terminates the user session.
- Jacl example:
$Portal login set myproject [$Project create "My new project" $Project details $myproject $Portal setproject $myproject $Content find any un ibm.portal.Home select $Content create page testpage1 html shared public $Portal setproject $Portal logout
- Jython example:
Portal.login() myproject = Project.create("My new project") Project.details(myproject) Portal.setproject(myproject) Content.find("any", "un", "ibm.portal.Home", "select") Content.create("page","testpage1","html", "shared", "public") Portal.setproject() Portal.logout()
Parent: Administer managed pages