LibreOffice Module desktop (master)  1
dp_dependencies.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <config_folders.h>
21 
22 #include <sal/config.h>
23 
24 #include <com/sun/star/uno/Reference.hxx>
25 #include <com/sun/star/uno/Sequence.hxx>
26 #include <com/sun/star/xml/dom/XElement.hpp>
27 #include <com/sun/star/xml/dom/XNodeList.hpp>
28 #include <osl/diagnose.h>
29 #include <rtl/bootstrap.hxx>
30 #include <rtl/ustring.hxx>
31 #include <sal/types.h>
32 #include <unotools/configmgr.hxx>
33 
34 #include <strings.hrc>
35 #include <dp_shared.hxx>
36 
37 #include <dp_dependencies.hxx>
39 #include <dp_version.hxx>
40 
41 namespace {
42 
43 char const namespaceLibreOffice[] =
44  "http://libreoffice.org/extensions/description/2011";
45 
46 char const namespaceOpenOfficeOrg[] =
47  "http://openoffice.org/extensions/description/2006";
48 
49 char const minimalVersionLibreOffice[] = "LibreOffice-minimal-version";
50 char const maximalVersionLibreOffice[] = "LibreOffice-maximal-version";
51 
52 char const minimalVersionOpenOfficeOrg[] =
53  "OpenOffice.org-minimal-version";
54 
55 char const maximalVersionOpenOfficeOrg[] =
56  "OpenOffice.org-maximal-version";
57 
58 OUString getLibreOfficeMajorMinorMicro() {
60 }
61 
62 OUString getReferenceOpenOfficeOrgMajorMinor() {
63 #ifdef ANDROID
64  // just hardcode the version
65  OUString v("4.1");
66 #else
67  OUString v(
68  "${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE("version")
69  ":Version:ReferenceOOoMajorMinor}");
70  rtl::Bootstrap::expandMacros(v); //TODO: check for failure
71 #endif
72  return v;
73 }
74 
75 bool satisfiesMinimalVersion(
76  OUString const & actual, OUString const & specified)
77 {
78  return dp_misc::compareVersions(actual, specified) != dp_misc::LESS;
79 }
80 
81 bool satisfiesMaximalVersion(
82  OUString const & actual, OUString const & specified)
83 {
84  return dp_misc::compareVersions(actual, specified) != dp_misc::GREATER;
85 }
86 
87 OUString produceErrorText(
88  OUString const & reason, OUString const & version)
89 {
90  return reason.replaceFirst("%VERSION",
91  (version.isEmpty()
92  ? DpResId(RID_DEPLOYMENT_DEPENDENCIES_UNKNOWN)
93  : version));
94 }
95 
96 }
97 
98 namespace dp_misc::Dependencies {
99 
100 css::uno::Sequence< css::uno::Reference< css::xml::dom::XElement > >
102  css::uno::Reference< css::xml::dom::XNodeList > deps(
103  infoset.getDependencies());
104  sal_Int32 n = deps->getLength();
105  css::uno::Sequence< css::uno::Reference< css::xml::dom::XElement > >
106  unsatisfied(n);
107  sal_Int32 unsat = 0;
108  // check first if minimalVersionLibreOffice is specified -- in that case ignore the legacy OOo dependencies
109  bool bIgnoreOoo = false;
110  for (sal_Int32 i = 0; i < n; ++i) {
111  css::uno::Reference< css::xml::dom::XElement > e(
112  deps->item(i), css::uno::UNO_QUERY_THROW);
113  if ( e->getNamespaceURI() == namespaceLibreOffice && e->getTagName() == minimalVersionLibreOffice)
114  {
115  bIgnoreOoo = true;
116  break;
117  }
118  }
119  for (sal_Int32 i = 0; i < n; ++i) {
120  css::uno::Reference< css::xml::dom::XElement > e(
121  deps->item(i), css::uno::UNO_QUERY_THROW);
122  bool sat = false;
123  if ( e->getNamespaceURI() == namespaceOpenOfficeOrg && e->getTagName() == minimalVersionOpenOfficeOrg )
124  {
125  sat = bIgnoreOoo || satisfiesMinimalVersion(
126  getReferenceOpenOfficeOrgMajorMinor(),
127  e->getAttribute("value"));
128  } else if ( e->getNamespaceURI() == namespaceOpenOfficeOrg && e->getTagName() == maximalVersionOpenOfficeOrg )
129  {
130  sat = bIgnoreOoo || satisfiesMaximalVersion(
131  getReferenceOpenOfficeOrgMajorMinor(),
132  e->getAttribute("value"));
133  } else if (e->getNamespaceURI() == namespaceLibreOffice && e->getTagName() == minimalVersionLibreOffice )
134  {
135  sat = satisfiesMinimalVersion(
136  getLibreOfficeMajorMinorMicro(),
137  e->getAttribute("value"));
138  } else if (e->getNamespaceURI() == namespaceLibreOffice && e->getTagName() == maximalVersionLibreOffice )
139  {
140  sat = satisfiesMaximalVersion(getLibreOfficeMajorMinorMicro(), e->getAttribute("value"));
141  } else if (e->hasAttributeNS(namespaceOpenOfficeOrg,
142  minimalVersionOpenOfficeOrg))
143  {
144  sat = satisfiesMinimalVersion(
145  getReferenceOpenOfficeOrgMajorMinor(),
146  e->getAttributeNS(namespaceOpenOfficeOrg,
147  minimalVersionOpenOfficeOrg));
148  }
149  if (!sat) {
150  unsatisfied[unsat++] = e;
151  }
152  }
153  unsatisfied.realloc(unsat);
154  return unsatisfied;
155 }
156 
157 OUString getErrorText(
158  css::uno::Reference< css::xml::dom::XElement > const & dependency)
159 {
160  OSL_ASSERT(dependency.is());
161  if ( dependency->getNamespaceURI() == namespaceOpenOfficeOrg && dependency->getTagName() == minimalVersionOpenOfficeOrg )
162  {
163  return produceErrorText(
164  DpResId(RID_DEPLOYMENT_DEPENDENCIES_OOO_MIN),
165  dependency->getAttribute("value"));
166  } else if (dependency->getNamespaceURI() == namespaceOpenOfficeOrg && dependency->getTagName() == maximalVersionOpenOfficeOrg )
167  {
168  return produceErrorText(
169  DpResId(RID_DEPLOYMENT_DEPENDENCIES_OOO_MAX),
170  dependency->getAttribute("value"));
171  } else if (dependency->getNamespaceURI() == namespaceLibreOffice && dependency->getTagName() == minimalVersionLibreOffice )
172  {
173  return produceErrorText(
174  DpResId(RID_DEPLOYMENT_DEPENDENCIES_LO_MIN),
175  dependency->getAttribute("value"));
176  } else if (dependency->getNamespaceURI() == namespaceLibreOffice && dependency->getTagName() == maximalVersionLibreOffice )
177  {
178  return produceErrorText(
179  DpResId(RID_DEPLOYMENT_DEPENDENCIES_LO_MAX),
180  dependency->getAttribute("value"));
181  } else if (dependency->hasAttributeNS(namespaceOpenOfficeOrg,
182  minimalVersionOpenOfficeOrg))
183  {
184  return produceErrorText(
185  DpResId(RID_DEPLOYMENT_DEPENDENCIES_OOO_MIN),
186  dependency->getAttributeNS(namespaceOpenOfficeOrg,
187  minimalVersionOpenOfficeOrg));
188  } else {
189  return DpResId(RID_DEPLOYMENT_DEPENDENCIES_UNKNOWN);
190  }
191 }
192 
193 }
194 
195 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::xml::dom::XNodeList > getDependencies() const
Return the dependencies.
sal_Int64 n
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC Order compareVersions(OUString const &version1, OUString const &version2)
Definition: dp_version.cxx:41
#define SAL_CONFIGFILE(name)
Dependency handling.
int i
static OUString getAboutBoxProductVersion()
float v
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC css::uno::Sequence< css::uno::Reference< css::xml::dom::XElement > > check(dp_misc::DescriptionInfoset const &infoset)
Check for unsatisfied dependencies.
OUString DpResId(const char *pId)
Definition: dp_shared.hxx:36
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC OUString getErrorText(css::uno::Reference< css::xml::dom::XElement > const &dependency)
Obtain the (human-readable) error message of a failed dependency.
Access to the content of an XML description element.