Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / desktop / source / deployment / manager / dp_properties.cxx
blob46535e0ee0e1a66d44d218db118fc59dffc47f9f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
22 #include <com/sun/star/lang/IllegalArgumentException.hpp>
23 #include <xmlscript/xml_helper.hxx>
24 #include <ucbhelper/content.hxx>
26 #include <dp_ucb.h>
27 #include <rtl/ustrbuf.hxx>
28 #include "dp_properties.hxx"
30 namespace lang = com::sun::star::lang;
31 namespace ucb = com::sun::star::ucb;
32 namespace uno = com::sun::star::uno;
35 using ::com::sun::star::uno::Reference;
37 #define PROP_SUPPRESS_LICENSE "SUPPRESS_LICENSE"
38 #define PROP_EXTENSION_UPDATE "EXTENSION_UPDATE"
40 namespace dp_manager {
42 //Reading the file
43 ExtensionProperties::ExtensionProperties(
44 OUString const & urlExtension,
45 Reference<ucb::XCommandEnvironment> const & xCmdEnv,
46 Reference<uno::XComponentContext> const & xContext) :
47 m_xCmdEnv(xCmdEnv), m_xContext(xContext)
49 m_propFileUrl = urlExtension + "properties";
51 std::vector< std::pair< OUString, OUString> > props;
52 if (! dp_misc::create_ucb_content(nullptr, m_propFileUrl, nullptr, false))
53 return;
55 ::ucbhelper::Content contentProps(m_propFileUrl, m_xCmdEnv, m_xContext);
56 dp_misc::readProperties(props, contentProps);
58 for (auto const& prop : props)
60 if (prop.first == PROP_SUPPRESS_LICENSE)
61 m_prop_suppress_license = prop.second;
65 //Writing the file
66 ExtensionProperties::ExtensionProperties(
67 OUString const & urlExtension,
68 uno::Sequence<css::beans::NamedValue> const & properties,
69 Reference<ucb::XCommandEnvironment> const & xCmdEnv,
70 Reference<uno::XComponentContext> const & xContext) :
71 m_xCmdEnv(xCmdEnv), m_xContext(xContext)
73 m_propFileUrl = urlExtension + "properties";
75 for (sal_Int32 i = 0; i < properties.getLength(); i++)
77 css::beans::NamedValue const & v = properties[i];
78 if (v.Name == PROP_SUPPRESS_LICENSE)
80 m_prop_suppress_license = getPropertyValue(v);
82 else if (v.Name == PROP_EXTENSION_UPDATE)
84 m_prop_extension_update = getPropertyValue(v);
86 else
88 throw lang::IllegalArgumentException(
89 "Extension Manager: unknown property", nullptr, -1);
94 OUString ExtensionProperties::getPropertyValue(css::beans::NamedValue const & v)
96 OUString value("0");
97 if (! (v.Value >>= value) )
99 throw lang::IllegalArgumentException(
100 "Extension Manager: wrong property value", nullptr, -1);
102 return value;
104 void ExtensionProperties::write()
106 ::ucbhelper::Content contentProps(m_propFileUrl, m_xCmdEnv, m_xContext);
107 OUStringBuffer buf;
109 if (m_prop_suppress_license)
111 buf.append(PROP_SUPPRESS_LICENSE);
112 buf.append("=");
113 buf.append(*m_prop_suppress_license);
116 OString stamp = OUStringToOString(
117 buf.makeStringAndClear(), RTL_TEXTENCODING_UTF8);
118 Reference<css::io::XInputStream> xData(
119 ::xmlscript::createInputStream(
120 reinterpret_cast<sal_Int8 const *>(stamp.getStr()),
121 stamp.getLength() ) );
122 contentProps.writeStream( xData, true /* replace existing */ );
125 bool ExtensionProperties::isSuppressedLicense() const
127 bool ret = false;
128 if (m_prop_suppress_license)
130 if (*m_prop_suppress_license == "1")
131 ret = true;
133 return ret;
136 bool ExtensionProperties::isExtensionUpdate() const
138 bool ret = false;
139 if (m_prop_extension_update)
141 if (*m_prop_extension_update == "1")
142 ret = true;
144 return ret;
147 } // namespace dp_manager
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */