Line data Source code
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 "tools/resid.hxx"
34 : #include "unotools/configmgr.hxx"
35 :
36 : #include "deployment.hrc"
37 : #include "dp_resource.h"
38 :
39 : #include "dp_dependencies.hxx"
40 : #include "dp_descriptioninfoset.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 0 : OUString getLibreOfficeMajorMinorMicro() {
60 0 : return utl::ConfigManager::getAboutBoxProductVersion();
61 : }
62 :
63 0 : OUString getReferenceOpenOfficeOrgMajorMinor() {
64 : OUString v(
65 : "${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE("version")
66 0 : ":Version:ReferenceOOoMajorMinor}");
67 0 : rtl::Bootstrap::expandMacros(v); //TODO: check for failure
68 0 : return v;
69 : }
70 :
71 0 : bool satisfiesMinimalVersion(
72 : OUString const & actual, OUString const & specified)
73 : {
74 0 : return dp_misc::compareVersions(actual, specified) != dp_misc::LESS;
75 : }
76 :
77 0 : bool satisfiesMaximalVersion(
78 : OUString const & actual, OUString const & specified)
79 : {
80 0 : return dp_misc::compareVersions(actual, specified) != dp_misc::GREATER;
81 : }
82 :
83 0 : OUString produceErrorText(
84 : OUString const & reason, OUString const & version)
85 : {
86 : return reason.replaceFirst("%VERSION",
87 0 : (version.isEmpty()
88 : ? dp_misc::getResId(RID_DEPLOYMENT_DEPENDENCIES_UNKNOWN).toString()
89 0 : : 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 > >
99 0 : check(dp_misc::DescriptionInfoset const & infoset) {
100 : css::uno::Reference< css::xml::dom::XNodeList > deps(
101 0 : infoset.getDependencies());
102 0 : sal_Int32 n = deps->getLength();
103 : css::uno::Sequence< css::uno::Reference< css::xml::dom::XElement > >
104 0 : unsatisfied(n);
105 0 : sal_Int32 unsat = 0;
106 0 : for (sal_Int32 i = 0; i < n; ++i) {
107 : css::uno::Reference< css::xml::dom::XElement > e(
108 0 : deps->item(i), css::uno::UNO_QUERY_THROW);
109 0 : bool sat = false;
110 0 : if ( e->getNamespaceURI() == namespaceOpenOfficeOrg && e->getTagName() == minimalVersionOpenOfficeOrg )
111 : {
112 : sat = satisfiesMinimalVersion(
113 : getReferenceOpenOfficeOrgMajorMinor(),
114 0 : e->getAttribute("value"));
115 0 : } else if ( e->getNamespaceURI() == namespaceOpenOfficeOrg && e->getTagName() == maximalVersionOpenOfficeOrg )
116 : {
117 : sat = satisfiesMaximalVersion(
118 : getReferenceOpenOfficeOrgMajorMinor(),
119 0 : e->getAttribute("value"));
120 0 : } else if (e->getNamespaceURI() == namespaceLibreOffice && e->getTagName() == minimalVersionLibreOffice )
121 : {
122 : sat = satisfiesMinimalVersion(
123 : getLibreOfficeMajorMinorMicro(),
124 0 : e->getAttribute("value"));
125 0 : } else if (e->hasAttributeNS(namespaceOpenOfficeOrg,
126 0 : minimalVersionOpenOfficeOrg))
127 : {
128 : sat = satisfiesMinimalVersion(
129 : getReferenceOpenOfficeOrgMajorMinor(),
130 0 : e->getAttributeNS(namespaceOpenOfficeOrg,
131 0 : minimalVersionOpenOfficeOrg));
132 : }
133 0 : if (!sat) {
134 0 : unsatisfied[unsat++] = e;
135 : }
136 0 : }
137 0 : unsatisfied.realloc(unsat);
138 0 : return unsatisfied;
139 : }
140 :
141 0 : OUString getErrorText(
142 : css::uno::Reference< css::xml::dom::XElement > const & dependency)
143 : {
144 : OSL_ASSERT(dependency.is());
145 0 : if ( dependency->getNamespaceURI() == namespaceOpenOfficeOrg && dependency->getTagName() == minimalVersionOpenOfficeOrg )
146 : {
147 : return produceErrorText(
148 : dp_misc::getResId(RID_DEPLOYMENT_DEPENDENCIES_OOO_MIN).toString(),
149 0 : dependency->getAttribute("value"));
150 0 : } else if (dependency->getNamespaceURI() == namespaceOpenOfficeOrg && dependency->getTagName() == maximalVersionOpenOfficeOrg )
151 : {
152 : return produceErrorText(
153 : dp_misc::getResId(RID_DEPLOYMENT_DEPENDENCIES_OOO_MAX).toString(),
154 0 : dependency->getAttribute("value"));
155 0 : } else if (dependency->getNamespaceURI() == namespaceLibreOffice && dependency->getTagName() == minimalVersionLibreOffice )
156 : {
157 : return produceErrorText(
158 : dp_misc::getResId(RID_DEPLOYMENT_DEPENDENCIES_LO_MIN).toString(),
159 0 : dependency->getAttribute("value"));
160 0 : } else if (dependency->hasAttributeNS(namespaceOpenOfficeOrg,
161 0 : minimalVersionOpenOfficeOrg))
162 : {
163 : return produceErrorText(
164 : dp_misc::getResId(RID_DEPLOYMENT_DEPENDENCIES_OOO_MIN).toString(),
165 0 : dependency->getAttributeNS(namespaceOpenOfficeOrg,
166 0 : minimalVersionOpenOfficeOrg));
167 : } else {
168 0 : return dp_misc::getResId(RID_DEPLOYMENT_DEPENDENCIES_UNKNOWN).toString();
169 : }
170 : }
171 :
172 : }
173 :
174 : }
175 :
176 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|