3.2. Creating a new site

In this tutorial you create your own site using a custom-extension.

The custom extension requires a jar and a war, so make sure you follow the link above to create and deploy the jar. Below are steps to create the war. Notice the webapp name is site-extension to configure it properly in the jar.

  1. Create the webapp site-extension.war:

    • The portal folder name indicates that the site is of portal type.

    • The site1 folder name will attend in the URL of the created site. If you change it here, you need to change it everywhere in the later configuration.

  2. Edit web.xml:

    
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="3.0" metadata-complete="true"
      xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
      <display-name>site-extension</display-name>
      <listener>
        <listener-class>org.exoplatform.container.web.PortalContainerConfigOwner</listener-class>
      </listener>
    </web-app>
  3. Edit configuration.xml to import site definition configuration:

    
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <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/sites-definition.xml</import>
    </configuration>
  4. Edit sites-definition.xml to declare your site(s) to the portal:

    
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <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.portal.config.UserPortalConfigService</target-component>
        <component-plugin>
          <name>new.portal.config.user.listener</name>
          <set-method>initListener</set-method>
          <type>org.exoplatform.portal.config.NewPortalConfigListener</type>
          <description></description>
          <init-params>
            <value-param>
              <name>override</name>
              <description></description>
              <value>true</value>
            </value-param>
            <object-param>
              <name>portal.configuration</name>
              <description></description>
              <object type="org.exoplatform.portal.config.NewPortalConfig">
                <field name="predefinedOwner">
                  <collection type="java.util.HashSet">
                  <!-- You can declare many sites here -->
                  <value><string>site1</string></value>
                  <!--<value><string>site2</string></value>-->
                  </collection>
                </field>
                <field name="ownerType">
                  <string>portal</string>
                </field>
                <field name="templateLocation">
                  <string>war:/conf/sites</string>
                </field>
                <field name="importMode">
                  <string>merge</string>
                </field>
              </object>
            </object-param>
          </init-params>
        </component-plugin>
      </external-component-plugins>
    </configuration>
  5. Edit site1/portal.xml:

    
    <portal-config>
      <portal-name>site1</portal-name>
      <locale>en</locale>
      <access-permissions>*:/platform/users</access-permissions>
      <edit-permission>*:/platform/administrators</edit-permission>
      <properties>
        <entry key="sessionAlive">never</entry>
        <entry key="showPortletInfo">1</entry>
      </properties>
      <portal-layout>
        <page-body> </page-body>
      </portal-layout>
    </portal-config>
    • <locale>: Defines the default language of your site.

    • <access-permissions>: Specifies which membership(s) can access your site. Use comma to separate values.

    • <edit-permission>: Specifies which membership can edit your site. Single value only.

    • <properties>: See Keep session alive and Show info bar by default for details.

    • <portal-layout>: This is the simplest layout that contains only the <page-body>. You will write more complete layout later.

  6. Edit site1/navigation.xml. In this example, only the homepage is defined:

    
    <node-navigation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.gatein.org/xml/ns/gatein_objects_1_2 http://www.gatein.org/xml/ns/gatein_objects_1_2"
      xmlns="http://www.gatein.org/xml/ns/gatein_objects_1_2">
      <priority>1</priority>
      <page-nodes>
        <node>
          <uri>home</uri>
          <name>home</name>
          <label>Home Page</label>
          <page-reference>portal::site1::homepage</page-reference>
        </node>
      </page-nodes>
    </node-navigation>
    • <page-reference>: Assigns the node to a page. The format is {site-type}::{site-name}::{page-name}.

  7. Edit site1/pages.xml. In this example, only one page (homepage) is created. The page contains GettingStartedPortlet that is a built-in portlet.

    
    <page-set xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.gatein.org/xml/ns/gatein_objects_1_2 http://www.gatein.org/xml/ns/gatein_objects_1_2"
      xmlns="http://www.gatein.org/xml/ns/gatein_objects_1_2">
      <page>
        <name>homepage</name>
        <title>Home Page</title>
        <access-permissions>*:/platform/users</access-permissions>
        <edit-permission>*:/platform/administrators</edit-permission>
        <portlet-application>
          <portlet>
            <application-ref>homepage-portlets</application-ref>
            <portlet-ref>GettingStartedPortlet</portlet-ref>
          </portlet>
          <title>Getting Started</title>
          <access-permissions>*:/platform/users</access-permissions>
          <show-info-bar>false</show-info-bar>
          <show-application-state>false</show-application-state>
          <show-application-mode>false</show-application-mode>
        </portlet-application>
      </page>
    </page-set>
  8. Deploy your extension, then test your site at http://mycompany.com:8080/portal/site1/.

Note

Note that the override value-param should be set to true. This will be explained in the next section.

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