merge the formfield patch from ooo-build
[ooovba.git] / desktop / source / deployment / misc / dp_dependencies.cxx
blobb509315da6dc14b1c800b358a78f5f3723505668
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_desktop.hxx"
31 #include "sal/config.h"
33 #include "com/sun/star/uno/Reference.hxx"
34 #include "com/sun/star/uno/Sequence.hxx"
35 #include "com/sun/star/xml/dom/XElement.hpp"
36 #include "com/sun/star/xml/dom/XNode.hpp"
37 #include "com/sun/star/xml/dom/XNodeList.hpp"
38 #include "rtl/bootstrap.hxx"
39 #include "rtl/string.h"
40 #include "rtl/ustring.h"
41 #include "rtl/ustring.hxx"
42 #include "sal/types.h"
43 #include "tools/string.hxx"
45 #include "deployment.hrc"
46 #include "dp_resource.h"
48 #include "dp_dependencies.hxx"
49 #include "dp_descriptioninfoset.hxx"
50 #include "dp_version.hxx"
52 namespace {
54 namespace css = ::com::sun::star;
56 static char const xmlNamespace[] =
57 "http://openoffice.org/extensions/description/2006";
59 ::dp_misc::Order compareWithVersion(::rtl::OUString const & version) {
60 ::rtl::OUString v(
61 RTL_CONSTASCII_USTRINGPARAM(
62 "${$OOO_BASE_DIR/program/" SAL_CONFIGFILE("version")
63 ":Version:OOOPackageVersion}"));
64 ::rtl::Bootstrap::expandMacros(v);
65 return ::dp_misc::compareVersions(v, version);
68 bool satisfiesMinimalVersion(::rtl::OUString const & version) {
69 return compareWithVersion(version) != ::dp_misc::LESS;
74 namespace dp_misc {
76 namespace Dependencies {
78 css::uno::Sequence< css::uno::Reference< css::xml::dom::XElement > >
79 check(::dp_misc::DescriptionInfoset const & infoset) {
80 css::uno::Reference< css::xml::dom::XNodeList > deps(
81 infoset.getDependencies());
82 ::sal_Int32 n = deps->getLength();
83 css::uno::Sequence< css::uno::Reference< css::xml::dom::XElement > >
84 unsatisfied(n);
85 ::sal_Int32 unsat = 0;
86 for (::sal_Int32 i = 0; i < n; ++i) {
87 static char const minimalVersion[] = "OpenOffice.org-minimal-version";
88 css::uno::Reference< css::xml::dom::XElement > e(
89 deps->item(i), css::uno::UNO_QUERY_THROW);
90 bool sat = false;
91 if (e->getNamespaceURI().equalsAsciiL(
92 RTL_CONSTASCII_STRINGPARAM(xmlNamespace))
93 && e->getTagName().equalsAsciiL(
94 RTL_CONSTASCII_STRINGPARAM(minimalVersion)))
96 sat = satisfiesMinimalVersion(
97 e->getAttribute(
98 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("value"))));
99 } else if (e->getNamespaceURI().equalsAsciiL(
100 RTL_CONSTASCII_STRINGPARAM(xmlNamespace))
101 && e->getTagName().equalsAsciiL(
102 RTL_CONSTASCII_STRINGPARAM(
103 "OpenOffice.org-maximal-version")))
105 sat =
106 compareWithVersion(
107 e->getAttribute(
108 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("value"))))
109 != ::dp_misc::GREATER;
110 } else if (e->hasAttributeNS(
111 ::rtl::OUString(
112 RTL_CONSTASCII_USTRINGPARAM(xmlNamespace)),
113 ::rtl::OUString(
114 RTL_CONSTASCII_USTRINGPARAM(minimalVersion))))
116 sat = satisfiesMinimalVersion(
117 e->getAttributeNS(
118 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(xmlNamespace)),
119 ::rtl::OUString(
120 RTL_CONSTASCII_USTRINGPARAM(minimalVersion))));
122 if (!sat) {
123 unsatisfied[unsat++] = e;
126 unsatisfied.realloc(unsat);
127 return unsatisfied;
130 ::rtl::OUString
131 name(css::uno::Reference< css::xml::dom::XElement > const & dependency) {
132 ::rtl::OUString n(
133 dependency->getAttributeNS(
134 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(xmlNamespace)),
135 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("name"))));
136 return n.getLength() == 0
137 ? ::rtl::OUString(
138 ::String(::dp_misc::getResId(RID_DEPLYOMENT_DEPENDENCIES_UNKNOWN)))
139 : n;
142 ::rtl::OUString getErrorText( css::uno::Reference< css::xml::dom::XElement > const & dependency )
144 ::rtl::OUString sReason;
145 ::rtl::OUString sValue;
146 ::rtl::OUString sVersion(RTL_CONSTASCII_USTRINGPARAM("%VERSION"));
148 if ( dependency->getNamespaceURI().equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( xmlNamespace ) )
149 && dependency->getTagName().equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "OpenOffice.org-minimal-version" ) ) )
151 sValue = dependency->getAttribute( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "value" ) ) );
152 sReason = ::rtl::OUString( ::String(::dp_misc::getResId(RID_DEPLYOMENT_DEPENDENCIES_MIN)) );
154 else if ( dependency->getNamespaceURI().equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( xmlNamespace ) )
155 && dependency->getTagName().equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "OpenOffice.org-maximal-version" ) ) )
157 sValue = dependency->getAttribute( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("value") ) );
158 sReason = ::rtl::OUString( ::String(::dp_misc::getResId(RID_DEPLYOMENT_DEPENDENCIES_MAX)) );
160 else if ( dependency->hasAttributeNS( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( xmlNamespace ) ),
161 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OpenOffice.org-minimal-version" ))))
163 sValue = dependency->getAttributeNS( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( xmlNamespace ) ),
164 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OpenOffice.org-minimal-version" ) ) );
165 sReason = ::rtl::OUString( ::String(::dp_misc::getResId(RID_DEPLYOMENT_DEPENDENCIES_MIN)) );
167 else
168 return ::rtl::OUString( ::String(::dp_misc::getResId(RID_DEPLYOMENT_DEPENDENCIES_UNKNOWN)) );
170 if ( sValue.getLength() == 0 )
171 sValue = ::rtl::OUString( ::String(::dp_misc::getResId(RID_DEPLYOMENT_DEPENDENCIES_UNKNOWN)) );
173 sal_Int32 nPos = sReason.indexOf( sVersion );
174 if ( nPos >= 0 )
175 sReason = sReason.replaceAt( nPos, sVersion.getLength(), sValue );
176 return sReason;