Commits

Anonymous committed 8c988d7

jsc341: i117327: add extra extension dependency check

  • Participants
  • Parent commits 7dbaa61

Comments (0)

Files changed (7)

File desktop/source/deployment/inc/dp_descriptioninfoset.hxx

     SAL_DLLPRIVATE ::rtl::OUString 
         getNodeValueFromExpression(::rtl::OUString const & expression) const;
 
+    /** Check the extensions blacklist if additional extension meta data (e.g. dependencies)
+        are defined for this extension and have to be taken into account.
+    */
+    SAL_DLLPRIVATE void
+        checkBlacklist() const;
+    
+    /** Helper method to compare the versions with the current version 
+     */
+    SAL_DLLPRIVATE bool
+        checkBlacklistVersion(::rtl::OUString currentversion,
+                              ::com::sun::star::uno::Sequence< ::rtl::OUString > const & versions) const;
+    
+    ::com::sun::star::uno::Reference<
+        ::com::sun::star::uno::XComponentContext > m_context;
     ::com::sun::star::uno::Reference<
         ::com::sun::star::xml::dom::XNode > m_element;
     ::com::sun::star::uno::Reference<

File desktop/source/deployment/misc/dp_descriptioninfoset.cxx

 #include "sal/config.h"
 
 #include "comphelper/sequence.hxx"
+#include "comphelper/seqstream.hxx"
 #include "comphelper/makesequence.hxx"
 #include "comphelper/processfactory.hxx"
 #include "boost/optional.hpp"
+#include "com/sun/star/container/XNameAccess.hpp"
 #include "com/sun/star/beans/Optional.hpp"
+#include "com/sun/star/beans/PropertyValue.hpp"
+#include "com/sun/star/beans/XPropertySet.hpp"
+#include "com/sun/star/io/SequenceInputStream.hpp"
 #include "com/sun/star/lang/XMultiComponentFactory.hpp"
 #include "com/sun/star/lang/Locale.hpp"
 #include "com/sun/star/uno/Reference.hxx"
 DescriptionInfoset::DescriptionInfoset(
     css::uno::Reference< css::uno::XComponentContext > const & context,
     css::uno::Reference< css::xml::dom::XNode > const & element):
+    m_context(context),
     m_element(element)
 {
     css::uno::Reference< css::lang::XMultiComponentFactory > manager(
     return n.is() ? getNodeValue(n) : ::rtl::OUString();
 }
 
+void DescriptionInfoset::checkBlacklist() const
+{
+    if (m_element.is()) {
+        boost::optional< OUString > id(getIdentifier());
+        if (!id)
+            return; // nothing to check
+        OUString currentversion(getVersion());
+        if (currentversion.getLength() == 0)
+            return;  // nothing to check
+
+        css::uno::Reference< css::lang::XMultiComponentFactory > manager(
+            m_context->getServiceManager(), css::uno::UNO_QUERY_THROW);
+        css::uno::Reference< css::lang::XMultiServiceFactory> provider(
+            manager->createInstanceWithContext(
+                ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.configuration.ConfigurationProvider")), m_context),
+                css::uno::UNO_QUERY_THROW);
+
+        css::uno::Sequence< css::uno::Any > args = css::uno::Sequence< css::uno::Any >(1);
+        css::beans::PropertyValue prop;
+        prop.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("nodepath"));
+        prop.Value <<= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Office.ExtensionDependencies/Extensions"));
+        args[0] <<= prop;
+
+        css::uno::Reference< css::container::XNameAccess > blacklist(
+            provider->createInstanceWithArguments(
+                ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.configuration.ConfigurationAccess")), args),
+                css::uno::UNO_QUERY_THROW);
+
+        // check first if a blacklist entry is available
+        if (blacklist.is() && blacklist->hasByName(*id)) {
+            css::uno::Reference< css::beans::XPropertySet > extProps(
+                blacklist->getByName(*id), css::uno::UNO_QUERY_THROW);
+
+            css::uno::Any anyValue = extProps->getPropertyValue(
+                ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Versions")));
+            
+            css::uno::Sequence< ::rtl::OUString > blversions;
+            anyValue >>= blversions;
+
+            // check if the current version requires further dependency checks from the blacklist
+            if (checkBlacklistVersion(currentversion, blversions)) {
+                anyValue = extProps->getPropertyValue(
+                    ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Dependencies")));
+                ::rtl::OUString udeps;
+                anyValue >>= udeps;
+
+                if (udeps.getLength() == 0)
+                    return; // nothing todo
+                
+                ::rtl::OString xmlDependencies = ::rtl::OUStringToOString(udeps, RTL_TEXTENCODING_UNICODE);
+                
+                css::uno::Reference< css::xml::dom::XDocumentBuilder> docbuilder(
+                    manager->createInstanceWithContext(
+                        ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.xml.dom.DocumentBuilder")), m_context),
+                    css::uno::UNO_QUERY_THROW);
+
+                css::uno::Sequence< sal_Int8 > byteSeq((const sal_Int8*)xmlDependencies.getStr(), xmlDependencies.getLength());
+
+                css::uno::Reference< css::io::XInputStream> inputstream( css::io::SequenceInputStream::createStreamFromSequence(m_context, byteSeq), 
+                                                                         css::uno::UNO_QUERY_THROW);
+                
+                css::uno::Reference< css::xml::dom::XDocument > xDocument(docbuilder->parse(inputstream));
+                css::uno::Reference< css::xml::dom::XElement > xElement(xDocument->getDocumentElement());
+                css::uno::Reference< css::xml::dom::XNodeList > xDeps(xElement->getChildNodes());
+                sal_Int32 nLen = xDeps->getLength();
+
+                // get dependency node of current description info to merge the new dependencies from the blacklist
+                css::uno::Reference< css::xml::dom::XNode > xCurrentDeps(
+                    m_xpath->selectSingleNode(m_element, ::rtl::OUString(
+                                                  RTL_CONSTASCII_USTRINGPARAM("desc:dependencies"))));
+
+                css::uno::Reference< css::xml::dom::XDocument > xCurrentDescInfo(xCurrentDeps->getOwnerDocument());
+                
+                for (sal_Int32 i=0; i<nLen; i++) {
+                    css::uno::Reference< css::xml::dom::XNode > xNode(xDeps->item(i));
+                    css::uno::Reference< css::xml::dom::XElement > xDep(xNode, css::uno::UNO_QUERY);
+                    if (xDep.is()) {
+                        // found valid blacklist dependency, import the node first and append it to the existing dependency node
+                        css::uno::Reference< css::xml::dom::XNode > importedNode = xCurrentDescInfo->importNode(xNode, true);
+                        xCurrentDeps->appendChild(importedNode);
+                    }
+                }
+            }
+        }
+    }
+}
+
+bool DescriptionInfoset::checkBlacklistVersion(
+    ::rtl::OUString currentversion,
+    ::com::sun::star::uno::Sequence< ::rtl::OUString > const & versions) const
+{
+    sal_Int32 nLen = versions.getLength();
+    for (sal_Int32 i=0; i<nLen; i++) {
+        if (currentversion.equals(versions[i]))
+            return true;
+    }
+
+    return false;
+}
 
 ::rtl::OUString DescriptionInfoset::getVersion() const 
 {
         aToken = aToken.trim();
         if (aToken.getLength())
             vec.push_back(aToken);
-     
+        
     }
     while (nIndex >= 0);
 
 DescriptionInfoset::getDependencies() const {
     if (m_element.is()) {
         try {
+            // check the extension blacklist first and expand the dependencies if applicable
+            checkBlacklist();
+            
             return m_xpath->selectNodeList(m_element, ::rtl::OUString(
                         RTL_CONSTASCII_USTRINGPARAM("desc:dependencies/*")));
         } catch (css::xml::xpath::XPathException &) {

File officecfg/registry/data/org/openoffice/Office/ExtensionDependencies.xcu

+<?xml version='1.0' encoding='UTF-8'?>
+<oor:component-data xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema"
+    oor:name="ExtensionDependencies" oor:package="org.openoffice.Office">
+    <node oor:name="Extensions">
+        <node oor:name="org.openoffice.bi.OracleBIConnector" oor:op="replace">
+            <prop oor:name="Versions">
+                <value>
+                    <it>1.0</it>
+                </value>
+            </prop>
+            <prop oor:name="Dependencies">
+                <value>&lt;dependencies xmlns=&quot;http://openoffice.org/extensions/description/2006&quot;&gt;&lt;OpenOffice.org-maximal-version d:name=&quot;OpenOffice.org 3.3&quot; value="3.3"/&gt;&lt;/dependencies&gt;</value>
+            </prop>
+        </node>
+    </node>
+</oor:component-data>

File officecfg/registry/data/org/openoffice/Office/makefile.mk

     Compatibility.xcu \
     DataAccess.xcu \
     Embedding.xcu \
+    ExtensionDependencies.xcu \
     ExtensionManager.xcu \
-	Impress.xcu	\
+    Impress.xcu	\
     Jobs.xcu \
     Labels.xcu \
     Linguistic.xcu \

File officecfg/registry/schema/org/openoffice/Office/ExtensionDependencies.xcs

+<!DOCTYPE oor:component-schema SYSTEM "../../../../component-schema.dtd">
+<oor:component-schema oor:name="ExtensionDependencies" oor:package="org.openoffice.Office" xml:lang="en-US" xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+    <info>
+	<author>JSC</author>
+        <desc>Contains a list of extensions with additonal dependencies to overrule missing dependencies in extensions
+              or to control specific extensions in general.</desc>
+    </info>
+    <templates>
+        <group oor:name="Extension">
+            <info><desc>Describes the additonal meta data for an extension whereas the node name have to be the extension identifier.</desc></info>
+            <prop oor:name="Versions" oor:type="oor:string-list" oor:localized="false">
+                <info><desc>Specifies a list of extension versions for which the extra dependecies should be active.</desc></info>
+            </prop>
+            <prop oor:name="Platforms" oor:type="oor:string-list" oor:localized="false">
+                <info><desc>Specifies a list of platforms for which the extra dependencies mechanism is active.</desc></info>
+            </prop>
+            <prop oor:name="Dependencies" oor:type="xs:string" oor:localized="false">
+                <info><desc>Specifies a list of additonal dependencies.</desc></info>
+            </prop>
+	</group>
+    </templates>
+    <component>
+        <set oor:name="Extensions" oor:node-type="Extension">
+            <info><desc>Specifies the list of extensions with extra dependecies.</desc></info>
+        </set>
+    </component>
+</oor:component-schema>

File officecfg/registry/schema/org/openoffice/Office/makefile.mk

     Draw.xcs \
     Events.xcs \
     Embedding.xcs \
+    ExtensionDependencies.xcs \
     ExtensionManager.xcs \
     Impress.xcs \
     Java.xcs \

File postprocess/packregistry/makefile.mk

     $(MY_XCS)/Office/Embedding.xcs \
     $(MY_XCS)/Office/Events.xcs \
     $(MY_XCS)/Office/ExtendedColorScheme.xcs \
+    $(MY_XCS)/Office/ExtensionDependencies.xcs \
     $(MY_XCS)/Office/ExtensionManager.xcs \
     $(MY_XCS)/Office/FormWizard.xcs \
     $(MY_XCS)/Office/Histories.xcs \
     $(MY_XCU)/Office/Common.xcu \
     $(MY_XCU)/Office/DataAccess.xcu \
     $(MY_XCU)/Office/Embedding.xcu \
+    $(MY_XCU)/Office/ExtensionDependencies.xcu \
     $(MY_XCU)/Office/ExtensionManager.xcu \
     $(MY_XCU)/Office/FormWizard.xcu \
     $(MY_XCU)/Office/Histories.xcu \