5.2.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 a portlet by configuration.

The registration of portal-managed applications is performed by configuring the ApplicationRegistryService service, so you need a custom-extension. In the following example, you create an extension dedicated to external configuration. If you want to make the hello-portlet.war itself an extension, the configuration is similar.

  1. Follow custom-extension section to create custom-extension-config.jar and custom-extension.war.

  2. Include a new configuration file named WEB-INF/conf/application-registry.xml in the .war:

    
    <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. Modify WEB-INF/conf/configuration.xml 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 custom extension (jar and war) and 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