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 static char const namespaceLibreOffice[] =
44  "http://libreoffice.org/extensions/description/2011";
45 
46 static char const namespaceOpenOfficeOrg[] =
47  "http://openoffice.org/extensions/description/2006";
48 
49 static char const minimalVersionLibreOffice[] = "LibreOffice-minimal-version";
50 
51 static char const minimalVersionOpenOfficeOrg[] =
52  "OpenOffice.org-minimal-version";
53 
54 static char const maximalVersionOpenOfficeOrg[] =
55  "OpenOffice.org-maximal-version";
56 
57 OUString getLibreOfficeMajorMinorMicro() {
59 }
60 
61 OUString getReferenceOpenOfficeOrgMajorMinor() {
62 #ifdef ANDROID
63  // just hardcode the version
64  OUString v("4.1");
65 #else
66  OUString v(
67  "${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE("version")
68  ":Version:ReferenceOOoMajorMinor}");
69  rtl::Bootstrap::expandMacros(v); //TODO: check for failure
70 #endif
71  return v;
72 }
73 
74 bool satisfiesMinimalVersion(
75  OUString const & actual, OUString const & specified)
76 {
77  return dp_misc::compareVersions(actual, specified) != dp_misc::LESS;
78 }
79 
80 bool satisfiesMaximalVersion(
81  OUString const & actual, OUString const & specified)
82 {
83  return dp_misc::compareVersions(actual, specified) != dp_misc::GREATER;
84 }
85 
86 OUString produceErrorText(
87  OUString const & reason, OUString const & version)
88 {
89  return reason.replaceFirst("%VERSION",
90  (version.isEmpty()
91  ? DpResId(RID_DEPLOYMENT_DEPENDENCIES_UNKNOWN)
92  : version));
93 }
94 
95 }
96 
97 namespace dp_misc::Dependencies {
98 
99 css::uno::Sequence< css::uno::Reference< css::xml::dom::XElement > >
101  css::uno::Reference< css::xml::dom::XNodeList > deps(
102  infoset.getDependencies());
103  sal_Int32 n = deps->getLength();
104  css::uno::Sequence< css::uno::Reference< css::xml::dom::XElement > >
105  unsatisfied(n);
106  sal_Int32 unsat = 0;
107  // check first if minimalVersionLibreOffice is specified -- in that case ignore the legacy OOo dependencies
108  bool bIgnoreOoo = false;
109  for (sal_Int32 i = 0; i < n; ++i) {
110  css::uno::Reference< css::xml::dom::XElement > e(
111  deps->item(i), css::uno::UNO_QUERY_THROW);
112  if ( e->getNamespaceURI() == namespaceLibreOffice && e->getTagName() == minimalVersionLibreOffice)
113  {
114  bIgnoreOoo = true;
115  break;
116  }
117  }
118  for (sal_Int32 i = 0; i < n; ++i) {
119  css::uno::Reference< css::xml::dom::XElement > e(
120  deps->item(i), css::uno::UNO_QUERY_THROW);
121  bool sat = false;
122  if ( e->getNamespaceURI() == namespaceOpenOfficeOrg && e->getTagName() == minimalVersionOpenOfficeOrg )
123  {
124  sat = bIgnoreOoo || satisfiesMinimalVersion(
125  getReferenceOpenOfficeOrgMajorMinor(),
126  e->getAttribute("value"));
127  } else if ( e->getNamespaceURI() == namespaceOpenOfficeOrg && e->getTagName() == maximalVersionOpenOfficeOrg )
128  {
129  sat = bIgnoreOoo || satisfiesMaximalVersion(
130  getReferenceOpenOfficeOrgMajorMinor(),
131  e->getAttribute("value"));
132  } else if (e->getNamespaceURI() == namespaceLibreOffice && e->getTagName() == minimalVersionLibreOffice )
133  {
134  sat = satisfiesMinimalVersion(
135  getLibreOfficeMajorMinorMicro(),
136  e->getAttribute("value"));
137  } else if (e->hasAttributeNS(namespaceOpenOfficeOrg,
138  minimalVersionOpenOfficeOrg))
139  {
140  sat = satisfiesMinimalVersion(
141  getReferenceOpenOfficeOrgMajorMinor(),
142  e->getAttributeNS(namespaceOpenOfficeOrg,
143  minimalVersionOpenOfficeOrg));
144  }
145  if (!sat) {
146  unsatisfied[unsat++] = e;
147  }
148  }
149  unsatisfied.realloc(unsat);
150  return unsatisfied;
151 }
152 
153 OUString getErrorText(
154  css::uno::Reference< css::xml::dom::XElement > const & dependency)
155 {
156  OSL_ASSERT(dependency.is());
157  if ( dependency->getNamespaceURI() == namespaceOpenOfficeOrg && dependency->getTagName() == minimalVersionOpenOfficeOrg )
158  {
159  return produceErrorText(
160  DpResId(RID_DEPLOYMENT_DEPENDENCIES_OOO_MIN),
161  dependency->getAttribute("value"));
162  } else if (dependency->getNamespaceURI() == namespaceOpenOfficeOrg && dependency->getTagName() == maximalVersionOpenOfficeOrg )
163  {
164  return produceErrorText(
165  DpResId(RID_DEPLOYMENT_DEPENDENCIES_OOO_MAX),
166  dependency->getAttribute("value"));
167  } else if (dependency->getNamespaceURI() == namespaceLibreOffice && dependency->getTagName() == minimalVersionLibreOffice )
168  {
169  return produceErrorText(
170  DpResId(RID_DEPLOYMENT_DEPENDENCIES_LO_MIN),
171  dependency->getAttribute("value"));
172  } else if (dependency->hasAttributeNS(namespaceOpenOfficeOrg,
173  minimalVersionOpenOfficeOrg))
174  {
175  return produceErrorText(
176  DpResId(RID_DEPLOYMENT_DEPENDENCIES_OOO_MIN),
177  dependency->getAttributeNS(namespaceOpenOfficeOrg,
178  minimalVersionOpenOfficeOrg));
179  } else {
180  return DpResId(RID_DEPLOYMENT_DEPENDENCIES_UNKNOWN);
181  }
182 }
183 
184 }
185 
186 /* 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:37
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.