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

  <!-- NewDocumentTemplatePlugin for DocumentService-->
  <external-component-plugins>
    <target-component>org.exoplatform.services.cms.documents.DocumentService</target-component>
    <component-plugin>
      <name>onlyofficeTemplatePlugin</name>
      <set-method>addDocumentTemplatePlugin</set-method>
      <type>org.exoplatform.onlyoffice.documents.OnlyofficeNewDocumentTemplatePlugin</type>
      <description>The document templates plugin contains a list of avaliable templates</description>
      <init-params>
        <object-param>
          <name>document-templates-configuration</name>
          <object type="org.exoplatform.services.cms.documents.DocumentService$DocumentTemplatesConfig">
            <field name="templates">
              <collection type="java.util.ArrayList">
                <value>
                  <object type="org.exoplatform.services.cms.documents.NewDocumentTemplateConfig">
                    <field name="extension">
                      <string>.docx</string>
                    </field>
                    <field name="path">
                      <string>classpath:files/template.docx</string>
                    </field>
                    <field name="name">
                      <string>MicrosoftOfficeDocument</string>
                    </field>
                    <field name="mimeType">
                      <string>application/vnd.openxmlformats-officedocument.wordprocessingml.document</string>
                    </field>
                  </object>
                </value>
                <value>
                  <object type="org.exoplatform.services.cms.documents.NewDocumentTemplateConfig">
                    <field name="extension">
                      <string>.xlsx</string>
                    </field>
                    <field name="path">
                      <string>classpath:files/template.xlsx</string>
                    </field>
                    <field name="name">
                      <string>MicrosoftOfficeSpreadsheet</string>
                    </field>
                    <field name="mimeType">
                      <string>application/vnd.openxmlformats-officedocument.spreadsheetml.sheet</string>
                    </field>
                  </object>
                </value>
                <value>
                  <object type="org.exoplatform.services.cms.documents.NewDocumentTemplateConfig">
                    <field name="extension">
                      <string>.pptx</string>
                    </field>
                    <field name="path">
                      <string>classpath:files/template.pptx</string>
                    </field>
                    <field name="name">
                      <string>MicrosoftOfficePresentation</string>
                    </field>
                    <field name="mimeType">
                      <string>application/vnd.openxmlformats-officedocument.presentationml.presentation</string>
                    </field>
                  </object>
                </value>
                <value>
                  <object type="org.exoplatform.services.cms.documents.NewDocumentTemplateConfig">
                    <field name="extension">
                      <string>.docxf</string>
                    </field>
                    <field name="path">
                      <string>classpath:files/template.docxf</string>
                    </field>
                    <field name="name">
                      <string>OnlyOfficeDocumentForm</string>
                    </field>
                    <field name="mimeType">
                      <string>application/vnd.openxmlformats-officedocument.wordprocessingml.document</string>
                    </field>
                  </object>
                </value>
                <value>
                  <object type="org.exoplatform.services.cms.documents.NewDocumentTemplateConfig">
                    <field name="extension">
                      <string>.pdf</string>
                    </field>
                    <field name="path">
                      <string>classpath:files/template.pdf</string>
                    </field>
                    <field name="name">
                      <string>OnlyOfficeDocumentFormPdf</string>
                    </field>
                    <field name="mimeType">
                      <string>application/pdf</string>
                    </field>
                  </object>
                </value>
              </collection>
            </field>
          </object>
        </object-param>
      </init-params>
    </component-plugin>
  </external-component-plugins>
  
  <!-- DocumentEditorPlugin for DocumentService-->
  <external-component-plugins>
    <target-component>org.exoplatform.services.cms.documents.DocumentService</target-component>
    <component-plugin>
      <name>onlyofficeEditorPlugin</name>
      <set-method>addDocumentEditorPlugin</set-method>
      <type>org.exoplatform.onlyoffice.documents.OnlyofficeDocumentEditorPlugin</type>
      <description>The document editor plugin</description>
    </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.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>
                <value>
                  <string>application/vnd.openxmlformats-officedocument.wordprocessingml.document.form</string>
                </value>
                <value>
                  <string>application/pdf</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>
          <object type="org.exoplatform.services.cache.impl.infinispan.generic.GenericExoCacheConfig">
            <field name="name">
              <string>onlyoffice.EditorCache</string>
            </field>
            <field name="strategy" profiles="cluster">
              <string>${onlyoffice.EditorCache.strategy:LIRS}</string>
            </field>
            <field name="maxSize">
              <int>${onlyoffice.EditorCache.Capacity:5000}</int>
            </field>
            <field name="liveTime">
              <long>${onlyoffice.EditorCache.TimeToLive:-1}</long>
            </field>
            <field name="cacheMode" profiles="cluster">
              <string>${onlyoffice.EditorCache.cacheMode:replication}</string>
            </field>
          </object>
        </object-param>
        <object-param>
          <name>onlyoffice.ViewerCache</name>
          <object type="org.exoplatform.services.cache.impl.infinispan.generic.GenericExoCacheConfig">
            <field name="name">
              <string>onlyoffice.ViewerCache</string>
            </field>
            <field name="strategy" profiles="cluster">
              <string>${onlyoffice.ViewerCache.strategy:LIRS}</string>
            </field>
            <field name="maxSize">
              <int>${onlyoffice.ViewerCache.Capacity:5000}</int>
            </field>
            <field name="liveTime">
              <long>${onlyoffice.ViewerCache.TimeToLive:-1}</long>
            </field>
            <field name="cacheMode" profiles="cluster">
              <string>${onlyoffice.ViewerCache.cacheMode:replication}</string>
            </field>
          </object>
        </object-param>
        <object-param>
          <name>onlyoffice.EditorStateCache</name>
          <object type="org.exoplatform.services.cache.impl.infinispan.generic.GenericExoCacheConfig">
            <field name="name">
              <string>onlyoffice.EditorStateCache</string>
            </field>
            <field name="strategy" profiles="cluster">
              <string>${onlyoffice.EditorCache.strategy:LIRS}</string>
            </field>
            <field name="maxSize">
              <int>${onlyoffice.EditorCache.Capacity:5000}</int>
            </field>
            <field name="liveTime">
              <long>${onlyoffice.EditorCache.TimeToLive:-1}</long>
            </field>
            <field name="cacheMode" profiles="cluster">
              <string>${onlyoffice.EditorCache.cacheMode:replication}</string>
            </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.onlyoffice.EditorsAdmin</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.onlyoffice.EditorsAdmin</value>
        </values-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>.*/oeditor.*</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>

  <!-- FileViewer plugin to show document preview in Explorer/Stream -->
  <external-component-plugins>
    <target-component>org.exoplatform.webui.ext.UIExtensionManager</target-component>
    <component-plugin>
      <name>File dynamic viewer</name>
      <set-method>registerUIExtensionPlugin</set-method>
      <type>org.exoplatform.webui.ext.UIExtensionPlugin</type>
      <init-params>
        <object-param>
          <name>Office</name>
          <object type="org.exoplatform.webui.ext.UIExtension">
            <field name="type">
              <string>org.exoplatform.ecm.dms.FileViewer</string>
            </field>
            <field name="rank">
              <int>80</int>
            </field>
            <field name="name">
              <string>Office</string>
            </field>
            <field name="category">
              <string>FileViewer</string>
            </field>
            <field name="component">
              <string>org.exoplatform.onlyoffice.webui.OnlyofficeFileViewer</string>
            </field>
            <field name="extendedFilters">
              <collection type="java.util.ArrayList">
                <value>
                  <object type="org.exoplatform.webui.ext.filter.impl.FileFilter">
                    <field name="mimeTypes">
                      <collection type="java.util.ArrayList">
                        <value>
                          <string>application/vnd.openxmlformats-officedocument.wordprocessingml.document</string>
                        </value>
                        <value>
                          <string>application/vnd.openxmlformats-officedocument.spreadsheetml.sheet</string>
                        </value>
                        <value>
                          <string>application/vnd.openxmlformats-officedocument.presentationml.presentation</string>
                        </value>
                        <value>
                          <string>application/vnd.openxmlformats-officedocument.presentationml.template</string>
                        </value>
                        <value>
                          <string>application/vnd.openxmlformats-officedocument.wordprocessingml.document.form</string>
                        </value>
                        <value>
                          <string>application/pdf</string>
                        </value>
                      </collection>
                    </field>
                  </object>
                </value>
              </collection>
            </field>
          </object>
        </object-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>body-end-container</value>
        </value-param>
        <object-param>
          <name>new-document-extension-portlet</name>
          <description>Editor Support 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/NewDocumentExtension</string>
                </field>
              </object>
            </field>
          </object>
        </object-param>
      </init-params>
    </component-plugin>
  </external-component-plugins>
  
</configuration>
