5.1.2.2. Registering a portlet by configuration

In the previous section, you registered the hello-portlet to an application category and add it to a page through UI. In this section, you learn how to register this portlet by configuration.

The registration of portal-managed applications is performed by configuring the ApplicationRegistryService service, so you need a portal extension. In the following example, you are going to make the hello-portlet as an extension containing service configuration. The source code is available here.

  1. Make your hello-portlet a portal extension by adding META-INF/exo-conf/configuration.xml file:

    
    <configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xsi:schemaLocation="http://www.exoplatform.org/xml/ns/kernel_1_2.xsd http://www.exoplatform.org/xml/ns/kernel_1_2.xsd"
        xmlns="http://www.exoplatform.org/xml/ns/kernel_1_2.xsd">
        <external-component-plugins>
            <target-component>org.exoplatform.container.definition.PortalContainerConfig</target-component>
            <component-plugin>
                <name>Add PortalContainer Definitions</name>
                <set-method>registerChangePlugin</set-method>
                <type>org.exoplatform.container.definition.PortalContainerDefinitionChangePlugin</type>
                <priority>101</priority>
                <init-params>
                    <values-param>
                        <name>apply.specific</name>
                        <value>portal</value>
                    </values-param>
                    <object-param>
                        <name>addDependencies</name>
                        <object type="org.exoplatform.container.definition.PortalContainerDefinitionChange$AddDependencies">
                            <field name="dependencies">
                                <collection type="java.util.ArrayList">
                                    <value><string>hello-portlet</string></value>
                                </collection>
                            </field>
                        </object>
                    </object-param>
                </init-params>
            </component-plugin>
        </external-component-plugins>
    </configuration>
  2. Add a new configuration file named WEB-INF/conf/application-registry.xml:

    
    <configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.exoplatform.org/xml/ns/kernel_1_2.xsd http://www.exoplatform.org/xml/ns/kernel_1_2.xsd"
        xmlns="http://www.exoplatform.org/xml/ns/kernel_1_2.xsd">
        <external-component-plugins>
            <target-component>org.exoplatform.application.registry.ApplicationRegistryService</target-component>
            <component-plugin>
                <name>acme.apps</name>
                <set-method>initListener</set-method>
                <type>org.exoplatform.application.registry.ApplicationCategoriesPlugins</type>
                <description></description>
                <init-params>
                    <object-param>
                        <name>ACME Apps</name>
                        <description></description>
                        <object type="org.exoplatform.application.registry.ApplicationCategory">
                            <field name="name"><string>ACMEApps</string></field>
                            <field name="displayName"><string>ACME applications</string></field>
                            <field name="description"><string>ACME applications</string></field>
                            <field name="accessPermissions">
                                <collection type="java.util.ArrayList" item-type="java.lang.String">
                                    <value><string>*:/platform/users</string></value>
                                </collection>
                            </field>
                            <field name="applications">
                                <collection type="java.util.ArrayList">
                                    <value>
                                        <object type="org.exoplatform.application.registry.Application">
                                            <field name="applicationName"><string>Hello</string></field>
                                            <field name="categoryName"><string>ACMEApps</string></field>
                                            <field name="displayName"><string>Hello</string></field>
                                            <field name="type"><string>portlet</string></field>
                                            <field name="description"><string>Hello Portlet</string></field>
                                            <field name="contentId"><string>hello-portlet/Hello</string></field>
                                            <field name="accessPermissions">
                                                <collection type="java.util.ArrayList" item-type="java.lang.String">
                                                    <value><string>*:/platform/administrators</string></value>
                                                </collection>
                                            </field>
                                        </object>
                                    </value>
                                </collection>
                            </field>
                        </object>
                    </object-param>
                </init-params>
            </component-plugin>
        </external-component-plugins>
    </configuration>
    • accessPermissions: Set this to Everyone if you want to make the category/portlet public.

    • contentId: The hello-portlet/Hello pattern is the package name (declared in web.xml) and the portlet name (declared in portlet.xml).

  3. Add the WEB-INF/conf/configuration.xml file to import the new configuration file:

    
    <configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.exoplatform.org/xml/ns/kernel_1_2.xsd http://www.exoplatform.org/xml/ns/kernel_1_2.xsd"
        xmlns="http://www.exoplatform.org/xml/ns/kernel_1_2.xsd">
        <import>war:/conf/application-registry.xml</import>
    </configuration>

After deploying the hello-portlet.war, you can test that the portlet is registered under the ACME applications category:

Copyright ©. All rights reserved. eXo Platform SAS
blog comments powered byDisqus