<?xml version="1.0" encoding="ISO-8859-1"?>
<!--

  Copyright (C) 2019 eXo Platform SAS.

  This is free software; you can redistribute it and/or modify it
  under the terms of the GNU Lesser General Public License as
  published by the Free Software Foundation; either version 2.1 of
  the License, or (at your option) any later version.

  This software is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this software; if not, write to the Free
  Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  02110-1301 USA, or see the FSF site: http://www.fsf.org.

-->
<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">

  <component>
    <key>org.exoplatform.onlyoffice.OnlyofficeEditorService</key>
    <type>org.exoplatform.onlyoffice.OnlyofficeEditorServiceImpl</type>
    <init-params>
      <properties-param>
        <name>editor-configuration</name>
        <property name="documentserver-host" value="${onlyoffice.documentserver.host:127.0.0.1:80}" />
        <property name="documentserver-schema" value="${onlyoffice.documentserver.schema:http}" />
        <property name="documentserver-access-only" value="${onlyoffice.documentserver.accessOnly:true}" />
        <property name="documentserver-allowedhosts" value="${onlyoffice.documentserver.allowedhosts:}" />
        <property name="documentserver-secret" value="${onlyoffice.documentserver.secret:}" />
      </properties-param>
    </init-params>
  </component>
  <component>
    <key>org.exoplatform.onlyoffice.jcr.NodeFinder</key>
    <type>org.exoplatform.onlyoffice.jcr.CMSNodeFinder</type>
  </component>
  <component>
    <type>org.exoplatform.onlyoffice.rest.EditorService</type>
  </component>

  <component>
    <type>org.exoplatform.onlyoffice.cometd.CometdOnlyofficeService</type>
  </component>

  <component>
    <type>org.exoplatform.onlyoffice.documents.NewDocumentService</type>
  </component>
  
  <!-- NewDocumentTypePlugin for NewDocumentService-->
  <external-component-plugins>
    <target-component>org.exoplatform.onlyoffice.documents.NewDocumentService</target-component>
    <component-plugin>
      <name>documentTypePlugin</name>
      <set-method>addTypePlugin</set-method>
      <type>org.exoplatform.onlyoffice.documents.NewDocumentTypePlugin</type>
      <description>The document type plugin contains a list of mimetypes</description>
      <init-params>
        <object-param>
          <name>document-types-configuration</name>
          <object type="org.exoplatform.onlyoffice.documents.NewDocumentService$NewDocumentTypesConfig">
            <field name="types">
              <collection type="java.util.ArrayList">
                <value>
                  <object type="org.exoplatform.onlyoffice.documents.NewDocumentType">
                    <field name="path">
                      <string>classpath:files/template.docx</string>
                    </field>
                    <field name="label">
                      <string>MicrosoftOfficeDocument</string>
                    </field>
                    <field name="mimeType">
                      <string>application/vnd.openxmlformats-officedocument.wordprocessingml.document</string>
                    </field>
                  </object>
                </value>
                <value>
                  <object type="org.exoplatform.onlyoffice.documents.NewDocumentType">
                    <field name="path">
                      <string>classpath:files/template.xlsx</string>
                    </field>
                    <field name="label">
                      <string>MicrosoftOfficeSpreadsheet</string>
                    </field>
                    <field name="mimeType">
                      <string>application/vnd.openxmlformats-officedocument.spreadsheetml.sheet</string>
                    </field>
                  </object>
                </value>
                <value>
                  <object type="org.exoplatform.onlyoffice.documents.NewDocumentType">
                    <field name="path">
                      <string>classpath:files/template.pptx</string>
                    </field>
                    <field name="label">
                      <string>MicrosoftOfficePresentation</string>
                    </field>
                    <field name="mimeType">
                      <string>application/vnd.openxmlformats-officedocument.presentationml.presentation</string>
                    </field>
                  </object>
                </value>
              </collection>
            </field>
          </object>
        </object-param>
      </init-params>
    </component-plugin>
  </external-component-plugins>

  <!-- DocumentTypePlugin for OnlyOfficeEditorService -->
  <external-component-plugins>
    <target-component>org.exoplatform.onlyoffice.OnlyofficeEditorService</target-component>
    <component-plugin>
      <name>documentTypePlugin</name>
      <set-method>addTypePlugin</set-method>
      <type>org.exoplatform.onlyoffice.DocumentTypePlugin</type>
      <description>The document type plugin contains a list of mimetypes</description>
      <init-params>
        <object-param>
          <name>document-types-configuration</name>
          <object type="org.exoplatform.onlyoffice.OnlyofficeEditorServiceImpl$DocumentTypesConfig">
            <field name="mimeTypes">
              <collection type="java.util.ArrayList">
                <value>
                  <string>application/vnd.oasis.opendocument.presentation</string>
                </value>
                <value>
                  <string>application/vnd.oasis.opendocument.spreadsheet</string>
                </value>
                <value>
                  <string>application/vnd.oasis.opendocument.text</string>
                </value>
                <value>
                  <string>application/vnd.openxmlformats-officedocument.presentationml.presentation</string>
                </value>
                <value>
                  <string>application/vnd.openxmlformats-officedocument.spreadsheetml.sheet</string>
                </value>
                <value>
                  <string>application/vnd.openxmlformats-officedocument.wordprocessingml.document</string>
                </value>
              </collection>
            </field>
          </object>
        </object-param>
      </init-params>
    </component-plugin>
  </external-component-plugins>
  
  <!-- Cache configuration -->
  <external-component-plugins>
    <target-component>org.exoplatform.services.cache.CacheService</target-component>
    <component-plugin>
      <name>addExoCacheConfig</name>
      <set-method>addExoCacheConfig</set-method>
      <type>org.exoplatform.services.cache.ExoCacheConfigPlugin</type>
      <description>Cache configuration for Onlyoffice service</description>
      <init-params>
        <object-param>
          <name>onlyoffice.EditorCache</name>
          <description></description>
          <object type="org.exoplatform.services.cache.ExoCacheConfig">
            <field name="name">
              <string>onlyoffice.EditorCache</string>
            </field>
            <field name="maxSize">
              <int>${onlyoffice.EditorCache.Capacity:5000}</int>
            </field>
            <field name="liveTime">
              <long>${onlyoffice.EditorCache.TimeToLive:259200}</long>
            </field>
            <field name="implementation">
              <string>org.exoplatform.services.cache.concurrent.ConcurrentFIFOExoCache</string>
            </field>
          </object>
        </object-param>
        <object-param profiles="cluster">
          <name>onlyoffice.EditorCache</name>
          <description></description>
          <object type="org.exoplatform.services.cache.impl.infinispan.generic.GenericExoCacheConfig">
            <field name="name">
              <string>onlyoffice.EditorCache</string>
            </field>
            <field name="strategy">
              <string>${onlyoffice.EditorCache.strategy:LIRS}</string>
            </field>
            <field name="maxEntries">
              <int>${onlyoffice.EditorCache.Capacity:5000}</int>
            </field>
            <field name="lifespan">
              <long>${onlyoffice.EditorCache.TimeToLive:259200000}</long>
            </field>
            <field name="cacheMode">
              <string>${onlyoffice.EditorCache.cacheMode:replication}</string>
            </field>
          </object>
        </object-param>
        <object-param>
          <name>onlyoffice.EditorStateCache</name>
          <description></description>
          <object type="org.exoplatform.services.cache.ExoCacheConfig">
            <field name="name">
              <string>onlyoffice.EditorStateCache</string>
            </field>
            <field name="maxSize">
              <int>${onlyoffice.EditorCache.Capacity:5000}</int>
            </field>
            <field name="liveTime">
              <long>${onlyoffice.EditorCache.TimeToLive:259200}</long>
            </field>
            <field name="implementation">
              <string>org.exoplatform.services.cache.concurrent.ConcurrentFIFOExoCache</string>
            </field>
          </object>
        </object-param>
        <object-param profiles="cluster">
          <name>onlyoffice.EditorStateCache</name>
          <description></description>
          <object type="org.exoplatform.services.cache.impl.infinispan.generic.GenericExoCacheConfig">
            <field name="name">
              <string>onlyoffice.EditorStateCache</string>
            </field>
            <field name="strategy">
              <string>${onlyoffice.EditorCache.strategy:LIRS}</string>
            </field>
            <field name="maxEntries">
              <int>${onlyoffice.EditorCache.Capacity:5000}</int>
            </field>
            <field name="lifespan">
              <long>${onlyoffice.EditorCache.TimeToLive:259200000}</long>
            </field>
            <field name="cacheMode">
              <string>${onlyoffice.EditorCache.cacheMode:replication}</string>
            </field>
          </object>
        </object-param>
      </init-params>
    </component-plugin>
  </external-component-plugins>

  <!-- ECMS menu action for onlyoffice. -->
  <external-component-plugins>
    <target-component>org.exoplatform.webui.ext.UIExtensionManager</target-component>
    <component-plugin>
      <name>Add Onlyoffice Actions</name>
      <set-method>registerUIExtensionPlugin</set-method>
      <type>org.exoplatform.webui.ext.UIExtensionPlugin</type>
      <init-params>
        <object-param>
          <name>File Activity</name>
          <object type="org.exoplatform.social.webui.activity.UIActivityExtension">
            <field name="type">
              <string>org.exoplatform.social.webui.activity.BaseUIActivity</string>
            </field>
            <field name="name">
              <string>files:spaces</string>
            </field>
            <field name="component">
              <string>org.exoplatform.onlyoffice.webui.FileUIActivity</string>
            </field>
            <field name="activityBuiderClass">
              <string>org.exoplatform.wcm.ext.component.activity.FileUIActivityBuilder</string>
            </field>
          </object>
        </object-param>
        <object-param>
          <name>Share File Activity</name>
          <object type="org.exoplatform.social.webui.activity.UIActivityExtension">
            <field name="type">
              <string>org.exoplatform.social.webui.activity.BaseUIActivity</string>
            </field>
            <field name="name">
              <string>sharefiles:spaces</string>
            </field>
            <field name="component">
              <string>org.exoplatform.onlyoffice.webui.FileUIActivity</string>
            </field>
            <field name="activityBuiderClass">
              <string>org.exoplatform.wcm.ext.component.activity.UISharedFileBuilder</string>
            </field>
          </object>
        </object-param>
        <object-param>
          <name>OnlyofficeOpen</name>
          <object type="org.exoplatform.webui.ext.UIExtension">
            <field name="type">
              <string>org.exoplatform.ecm.dms.UIActionBar</string>
            </field>
            <field name="name">
              <string>OnlyofficeOpen</string>
            </field>
            <field name="rank">
              <int>10</int>
            </field>
            <field name="component">
              <string>org.exoplatform.onlyoffice.webui.OnlyofficeOpenManageComponent</string>
            </field>
          </object>
        </object-param>
        <object-param>
          <name>NewDocument</name>
          <object type="org.exoplatform.webui.ext.UIExtension">
            <field name="type">
              <string>org.exoplatform.ecm.dms.UIActionBar</string>
            </field>
            <field name="name">
              <string>NewDocument</string>
            </field>
            <field name="rank">
              <int>10</int>
            </field>
            <field name="component">
              <string>org.exoplatform.onlyoffice.webui.explorer.NewDocumentManageComponent</string>
            </field>
          </object>
        </object-param>
      </init-params>
    </component-plugin>
  </external-component-plugins>

  <!-- Add Onlyoffice actions to ECMS views -->
  <external-component-plugins>
    <target-component>org.exoplatform.services.cms.views.ManageViewService</target-component>
    <component-plugin>
      <name>customize.view.plugin</name>
      <set-method>setManageViewPlugin</set-method>
      <type>org.exoplatform.onlyoffice.webui.CustomizeViewPlugin</type>
      <description>this plugin customize user view</description>
      <init-params>
        <object-param>
          <name>Admin</name>
          <description>View configuration of Admin</description>
          <object type="org.exoplatform.services.cms.views.ViewConfig">
            <field name="name">
              <string>Admin</string>
            </field>
            <field name="tabList">
              <collection type="java.util.ArrayList">
                <value>
                  <object type="org.exoplatform.services.cms.views.ViewConfig$Tab">
                    <field name="tabName">
                      <string>Admin</string>
                    </field>
                    <field name="buttons">
                      <string>
                        onlyofficeOpen
                      </string>
                    </field>
                  </object>
                </value>
                <value>
                  <object type="org.exoplatform.services.cms.views.ViewConfig$Tab">
                    <field name="tabName">
                      <string>Admin</string>
                    </field>
                    <field name="buttons">
                      <string>
                        newDocument
                      </string>
                    </field>
                  </object>
                </value>
              </collection>
            </field>
          </object>
        </object-param>
        <object-param>
          <name>Icons</name>
          <description>View configuration for user</description>
          <object type="org.exoplatform.services.cms.views.ViewConfig">
            <field name="name">
              <string>Icons</string>
            </field>
            <field name="tabList">
              <collection type="java.util.ArrayList">
                <value>
                  <object type="org.exoplatform.services.cms.views.ViewConfig$Tab">
                    <field name="tabName">
                      <string>Icons</string>
                    </field>
                    <field name="buttons">
                      <string>
                        onlyofficeOpen
                      </string>
                    </field>
                  </object>
                </value>
                <value>
                  <object type="org.exoplatform.services.cms.views.ViewConfig$Tab">
                    <field name="tabName">
                      <string>Icons</string>
                    </field>
                    <field name="buttons">
                      <string>
                        newDocument
                      </string>
                    </field>
                  </object>
                </value>
              </collection>
            </field>
          </object>
        </object-param>
        <object-param>
          <name>List</name>
          <description>View configuration for List</description>
          <object type="org.exoplatform.services.cms.views.ViewConfig">
            <field name="name">
              <string>List</string>
            </field>
            <field name="tabList">
              <collection type="java.util.ArrayList">
                <value>
                  <object type="org.exoplatform.services.cms.views.ViewConfig$Tab">
                    <field name="tabName">
                      <string>List</string>
                    </field>
                    <field name="buttons">
                      <string>
                        onlyofficeOpen
                      </string>
                    </field>
                  </object>
                </value>
                <value>
                  <object type="org.exoplatform.services.cms.views.ViewConfig$Tab">
                    <field name="tabName">
                      <string>List</string>
                    </field>
                    <field name="buttons">
                      <string>
                        newDocument
                      </string>
                    </field>
                  </object>
                </value>
              </collection>
            </field>
          </object>
        </object-param>
        <object-param>
          <name>Web</name>
          <description>View configuration of WCM administrator</description>
          <object type="org.exoplatform.services.cms.views.ViewConfig">
            <field name="name">
              <string>Web</string>
            </field>
            <field name="tabList">
              <collection type="java.util.ArrayList">
                <value>
                  <object type="org.exoplatform.services.cms.views.ViewConfig$Tab">
                    <field name="tabName">
                      <string>Authoring</string>
                    </field>
                    <field name="buttons">
                      <string>
                        onlyofficeOpen
                      </string>
                    </field>
                  </object>
                </value>
                <value>
                  <object type="org.exoplatform.services.cms.views.ViewConfig$Tab">
                    <field name="tabName">
                      <string>Authoring</string>
                    </field>
                    <field name="buttons">
                      <string>
                        newDocument
                      </string>
                    </field>
                  </object>
                </value>
              </collection>
            </field>
          </object>
        </object-param>
        <object-param>
          <name>Categories</name>
          <description>View configuration of WCM contributors</description>
          <object type="org.exoplatform.services.cms.views.ViewConfig">
            <field name="name">
              <string>Categories</string>
            </field>
            <field name="tabList">
              <collection type="java.util.ArrayList">
                <value>
                  <object type="org.exoplatform.services.cms.views.ViewConfig$Tab">
                    <field name="tabName">
                      <string>Collaboration</string>
                    </field>
                    <field name="buttons"><!-- ; onlyofficeClose -->
                      <string>
                        onlyofficeOpen
                      </string>
                    </field>
                  </object>
                </value>
                <value>
                  <object type="org.exoplatform.services.cms.views.ViewConfig$Tab">
                    <field name="tabName">
                      <string>Collaboration</string>
                    </field>
                    <field name="buttons">
                      <string>
                        newDocument
                      </string>
                    </field>
                  </object>
                </value>
              </collection>
            </field>
          </object>
        </object-param>
      </init-params>
    </component-plugin>
  </external-component-plugins>

  <external-component-plugins>
    <target-component>org.exoplatform.services.resources.ResourceBundleService</target-component>
    <component-plugin>
      <name>ResourceBundle Plugin</name>
      <set-method>addResourceBundle</set-method>
      <type>org.exoplatform.services.resources.impl.BaseResourceBundlePlugin</type>
      <init-params>
        <values-param>
          <name>init.resources</name>
          <description>Store the following resources into the db for the first launch</description>
          <value>locale.onlyoffice.Onlyoffice</value>
          <value>locale.onlyoffice.OnlyofficeClient</value>
          <value>locale.navigation.portal.intranet</value>
        </values-param>
        <values-param>
          <name>portal.resource.names</name>
          <description>The properties files of the portal , those file will be merged into one ResoruceBundle properties</description>
          <value>locale.onlyoffice.Onlyoffice</value>
          <value>locale.onlyoffice.OnlyofficeClient</value>
          <value>locale.navigation.portal.intranet</value>
        </values-param>
      </init-params>
    </component-plugin>
  </external-component-plugins>

  <external-component-plugins>
    <target-component>org.exoplatform.commons.addons.AddOnService</target-component>
    <component-plugin>
      <name>addPlugin</name>
      <set-method>addPlugin</set-method>
      <type>org.exoplatform.commons.addons.AddOnPluginImpl</type>
      <description>add application Config</description>
      <init-params>
        <value-param>
          <name>priority</name>
          <value>10</value>
        </value-param>
        <value-param>
          <name>containerName</name>
          <value>bottom-all-container</value>
        </value-param>
        <object-param>
          <name>OnlyofficeStream</name>
          <description>Onlyoffice Document State portlet</description>
          <object type="org.exoplatform.portal.config.serialize.PortletApplication">
            <field name="state">
              <object type="org.exoplatform.portal.config.model.TransientApplicationState">
                <field name="contentId">
                  <string>onlyoffice/OnlyofficeDocumentStatePortlet</string>
                </field>
              </object>
            </field>
          </object>
        </object-param>
      </init-params>
    </component-plugin>
  </external-component-plugins>

  <external-component-plugins>
    <target-component>org.exoplatform.web.filter.ExtensibleFilter</target-component>
    <component-plugin>
      <name>Onlyoffice Editor integration filter plugin</name>
      <set-method>addFilterDefinitions</set-method>
      <type>org.exoplatform.web.filter.FilterDefinitionPlugin</type>
      <init-params>
        <object-param>
          <name>Onlyoffice Editor integration filter</name>
          <object type="org.exoplatform.web.filter.FilterDefinition">
            <field name="filter">
              <object type="org.exoplatform.onlyoffice.webui.OnlyofficeEditorFilter" />
            </field>
            <field name="patterns">
              <collection type="java.util.ArrayList" item-type="java.lang.String">
                <value>
                  <string>/intranet/oeditor.*</string>
                </value>
              </collection>
            </field>
          </object>
        </object-param>
      </init-params>
    </component-plugin>
    <component-plugin>
      <name>Onlyoffice Documents integration filter plugin</name>
      <set-method>addFilterDefinitions</set-method>
      <type>org.exoplatform.web.filter.FilterDefinitionPlugin</type>
      <init-params>
        <object-param>
          <name>Onlyoffice Documents integration filter</name>
          <object type="org.exoplatform.web.filter.FilterDefinition">
            <field name="filter">
              <object type="org.exoplatform.onlyoffice.webui.OnlyofficeDocumentsFilter" />
            </field>
            <field name="patterns">
              <collection type="java.util.ArrayList" item-type="java.lang.String">
                <value>
                  <string>/intranet/documents.*</string>
                </value>
                <value>
                  <string>/g/.*/documents.*</string>
                </value>
              </collection>
            </field>
          </object>
        </object-param>
      </init-params>
    </component-plugin>
  </external-component-plugins>

  <external-component-plugins>
    <target-component>org.exoplatform.services.jcr.RepositoryService</target-component>
    <component-plugin>
      <name>add.namespaces</name>
      <set-method>addPlugin</set-method>
      <type>org.exoplatform.services.jcr.impl.AddNamespacesPlugin</type>
      <init-params>
        <properties-param>
          <name>namespaces</name>
          <property name="eoo" value="http://www.exoplatform.com/jcr/onlyoffice/1.0/" />
        </properties-param>
      </init-params>
    </component-plugin>
    <component-plugin>
      <name>add.gadget.services.nodeType</name>
      <set-method>addPlugin</set-method>
      <type>org.exoplatform.services.jcr.impl.AddNodeTypePlugin</type>
      <init-params>
        <values-param>
          <name>autoCreatedInNewRepository</name>
          <description>Onlyoffice node types configuration file</description>
          <value>jar:/conf/portal/jcr/onlyoffice-nodetypes.xml</value>
        </values-param>
      </init-params>
    </component-plugin>
  </external-component-plugins>

</configuration>