Managing registered portlets using XML

This recipe explains how to attach applications to a page using the XML configuration of GateIn.

Getting ready

Let's assume that you have defined the page as the previous recipe in the same file:

02portal.war/WEB-INF/conf/portal/portal/financials/page.xml

How to do it...

In order to set specific portlets in a page, you need to declare a portlet-application element for each portlet instance you want to use:

  <page>
    <name>contactus</name>
    <title>Contact us</title>
     <access-permissions>Everyone</access-permissions>
     <edit-permission>*:/platform/administrators</edit-permission>
    <portlet-application>
      <portlet>
        <application-ref>web</application-ref>
        <portlet-ref>ContactUsPortlet</portlet-ref>
        <preferences>
          <preference>
            <name>useAJAX</name>
            <value>false</value>
            <read-only>false</read-only>
          </preference>
        </preferences>
      </portlet>
      <title>Contact us</title>
      <access-permissions>Everyone</access-permissions>
      <show-info-bar>false</show-info-bar>      
    </portlet-application>
  </page>

In this XML definition, we have added a new portlet that contains the ContactUsPortlet previously added in the Application Registry, as we have seen in Chapter 2, Managing Portal Contents Using the GUI. We have assumed that this portlet exists in the Application Registry.

How it works...

A portlet can be declared using a portlet-application element in a page definition; this means that you have to provide the following sub-elements inside the snippet:

  • application-ref: Shows the portlet category as stored in the Application Registry
  • portlet-ref: Shows the portlet reference as stored in the Application Registry
  • preferences: Properties for the current portlet instance

In GateIn, you will find the following default values for the application-ref element:

  • web: This is the Web category
  • exoadmin: This is the Administration category
  • dashboard: This is the Dashboard category

Notice that you can use your own categories, previously created using the Application Registry.

However, this is not the only way to deploy portlets in GateIn, as a standard portlet-container, such as any portlet that would be deployed in WAR, with its WEB-INF/portlet.xml file, can be used in a portal page. The application-ref is then set with the name of the WebApp of the WAR. The portlet-ref is set with the name of the portlet declared in the portlet.xml file.

There's more...

You have so far learned how to attach portlet instances in pages, but if you want to use gadgets, you need to use a different XML element named gadget-application.

This is an example of how to declare a gadget for a page:

<gadget-application>
      <gadget>
        <gadget-ref>ServicesManagement</gadget-ref>
      </gadget>
      <title>Services Management</title>
      <access-permissions>manager:/platform/administrators</access-permissions>
      <show-info-bar>false</show-info-bar>
    </gadget-application>

As you can see in the preceding definition, we already know some of the elements that were introduced for the portlet declaration: title, access-permission, and show-info-bar.

The unique new element introduced here is gadget-ref; this allows defining the identifier of the gadget declared in the Application Registry.

Defining the categories configuration for a portal

If you want to add or change the default settings for application categories related to a specific portal, you can take a look at the following file to understand how to override or define the current XML components:

/02portal.war/WEB-INF/conf/portal/application-registry-configuration.xml

Let's look at the default configuration of GateIn and look at how to use these initialization scripts for your custom portal:

<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.exoplaform.org/xml/ns/kernel_1_2.xsd http://www.exoplaform.org/xml/ns/kernel_1_2.xsd" xmlns="http://www.exoplaform.org/xml/ns/kernel_1_2.xsd">
. . .
<component>
      <key>org.exoplatform.application.registry.ApplicationRegistryService</key>
      <type>org.exoplatform.application.registry.impl.ApplicationRegistryServiceImpl</type>
      <component-plugins>
         <component-plugin>
            <name>new.portal.portlets.registry</name>
            <set-method>initListener</set-method>
            <type>org.exoplatform.application.registry.ApplicationCategoriesPlugins</type>
            <description>this listener init the portlets are registered in PortletRegister</description>
            <init-params>
               <object-param>
                  <name>administration</name>
                  <description>description</description>
                  <object type="org.exoplatform.application.registry.ApplicationCategory">
                     <field name="name">
                        <string>Administration</string>
                     </field>
                     <field name="displayName">
                        <string>Administration</string>
                     </field>
                     <field name="description">
                        <string>application for administration</string>
                     </field>
                     <field name="accessPermissions">
                        <collection type="java.util.ArrayList" item-type="java.lang.String">
                           <value>
                              <string>*:/platform/administrators</string>
                           </value>
                           <value>
                              <string>*:/organization/management/executive-board</string>
                           </value>
                        </collection>
                     </field>
. . .
</configuration>

The preceding snippet shows how GateIn declares the creation of the default Administration category and sets the access permissions and all the applications that must be included.

To define a new category we therefore need to provide:

  • The ApplicationRegistry class that we want to use; if you want, you can use the default one provided by GateIn. To identify a component in the configuration engine, you have to set the key and the type element.
  • A component plugin declared as ApplicationCategoriesPlugin because it is the responsible class for creating categories during the first execution of the portal instance.
  • An init-params element that contains for each category a specific object-param element.
  • Definitions for each category with the following elements:
    • name: This is the node name for the category
    • displayName: The label of the category
    • description: This is the description for the current category
    • accessPermission: The permissions for accessing applications defined for this category
    • applications: The list of all the applications (portlets or gadgets) that we want to initialize under this category

An application must be declared in a category definition in the following way:

<field name="applications">
<collection type="java.util.ArrayList">
<value>
  <object type="org.exoplatform.application.registry.Application">
     
     <field name="applicationName">
    <string>ApplicationRegistryPortlet</string>
     </field>
     
     <field name="categoryName">
       <string>administration</string>
     </field>
     
     <field name="displayName">
       <string>Application Registry</string>
     </field>
     
     <field name="description">
       <string>Application Registry</string>
     </field>
     
     <field name="type">
       <string>portlet</string>
     </field>
     
     <field name="contentId">
       <string>exoadmin/ApplicationRegistryPortlet</string>
     </field>
     
     <field name="accessPermissions">
       <collection type="java.util.ArrayList" item-type="java.lang.String">
         <value>
           <string>*:/platform/administrators</string>
         </value>
         <value>                           <string>*:/organization/management/executive-board</string>
         </value>
       </collection>
     </field>
  </object>
</value>

Finally, let's look at all the needed elements to initialize an application under a category:

  • applicationName: The name of the application instance as registered in the Application Registry
  • categoryName: The name of the category
  • displayName: The default label to use for the current application
  • description: The description for the application
  • type: The type of the implementation; the value could be portlet or gadget
  • contentId: The identifier of the application definition in the portal instance
  • accessPermissions: The permissions to access the current application

See also

  • The Managing the navigation tree using XML recipe
  • The Managing portal pages using XML recipe
  • The Managing portals using XML recipe
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.141.219