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