LibreOffice Module desktop (master) 1
dp_properties.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
21#include <com/sun/star/ucb/XCommandEnvironment.hpp>
22#include <com/sun/star/lang/IllegalArgumentException.hpp>
24#include <ucbhelper/content.hxx>
25
26#include <dp_ucb.h>
27#include "dp_properties.hxx"
28
29namespace lang = com::sun::star::lang;
30namespace ucb = com::sun::star::ucb;
31namespace uno = com::sun::star::uno;
32
33
34using ::com::sun::star::uno::Reference;
35
36constexpr OUStringLiteral PROP_SUPPRESS_LICENSE = u"SUPPRESS_LICENSE";
37constexpr OUStringLiteral PROP_EXTENSION_UPDATE = u"EXTENSION_UPDATE";
38
39namespace dp_manager {
40
41//Reading the file
43 std::u16string_view urlExtension,
44 Reference<ucb::XCommandEnvironment> const & xCmdEnv,
45 Reference<uno::XComponentContext> const & xContext) :
46 m_xCmdEnv(xCmdEnv), m_xContext(xContext)
47{
48 m_propFileUrl = OUString::Concat(urlExtension) + "properties";
49
50 std::vector< std::pair< OUString, OUString> > props;
51 if (! dp_misc::create_ucb_content(nullptr, m_propFileUrl, nullptr, false))
52 return;
53
54 ::ucbhelper::Content contentProps(m_propFileUrl, m_xCmdEnv, m_xContext);
55 dp_misc::readProperties(props, contentProps);
56
57 for (auto const& prop : props)
58 {
59 if (prop.first == PROP_SUPPRESS_LICENSE)
60 m_prop_suppress_license = prop.second;
61 }
62}
63
64//Writing the file
66 std::u16string_view urlExtension,
68 Reference<ucb::XCommandEnvironment> const & xCmdEnv,
69 Reference<uno::XComponentContext> const & xContext) :
70 m_xCmdEnv(xCmdEnv), m_xContext(xContext)
71{
72 m_propFileUrl = OUString::Concat(urlExtension) + "properties";
73
74 for (css::beans::NamedValue const & v : properties)
75 {
76 if (v.Name == PROP_SUPPRESS_LICENSE)
77 {
78 m_prop_suppress_license = getPropertyValue(v);
79 }
80 else if (v.Name == PROP_EXTENSION_UPDATE)
81 {
82 m_prop_extension_update = getPropertyValue(v);
83 }
84 else
85 {
86 throw lang::IllegalArgumentException(
87 "Extension Manager: unknown property", nullptr, -1);
88 }
89 }
90}
91
92OUString ExtensionProperties::getPropertyValue(css::beans::NamedValue const & v)
93{
94 OUString value("0");
95 if (! (v.Value >>= value) )
96 {
97 throw lang::IllegalArgumentException(
98 "Extension Manager: wrong property value", nullptr, -1);
99 }
100 return value;
101}
103{
105 OUString buf;
106
108 {
109 buf = OUString::Concat(PROP_SUPPRESS_LICENSE) + "=" + *m_prop_suppress_license;
110 }
111
112 OString stamp = OUStringToOString(buf, RTL_TEXTENCODING_UTF8);
113 Reference<css::io::XInputStream> xData(
114 ::xmlscript::createInputStream(
115 reinterpret_cast<sal_Int8 const *>(stamp.getStr()),
116 stamp.getLength() ) );
117 contentProps.writeStream( xData, true /* replace existing */ );
118}
119
121{
122 bool ret = false;
124 {
125 if (*m_prop_suppress_license == "1")
126 ret = true;
127 }
128 return ret;
129}
130
132{
133 bool ret = false;
135 {
136 if (*m_prop_extension_update == "1")
137 ret = true;
138 }
139 return ret;
140}
141
142} // namespace dp_manager
143
144
145/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const css::uno::Reference< css::uno::XComponentContext > m_xContext
::std::optional< OUString > m_prop_extension_update
const css::uno::Reference< css::ucb::XCommandEnvironment > m_xCmdEnv
::std::optional< OUString > m_prop_suppress_license
static OUString getPropertyValue(css::beans::NamedValue const &v)
ExtensionProperties(std::u16string_view urlExtension, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv, css::uno::Reference< css::uno::XComponentContext > const &xContext)
void writeStream(const css::uno::Reference< css::io::XInputStream > &rStream, bool bReplaceExisting)
Any value
uno::Reference< uno::XComponentContext > m_xContext
constexpr OUStringLiteral PROP_EXTENSION_UPDATE
constexpr OUStringLiteral PROP_SUPPRESS_LICENSE
float v
float u
static uno::Reference< css::uno::XComponentContext > xContext
Definition: init.cxx:2642
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC bool readProperties(std::vector< std::pair< OUString, OUString > > &out_result, ::ucbhelper::Content &ucb_content)
Definition: dp_ucb.cxx:256
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC bool create_ucb_content(::ucbhelper::Content *ucb_content, OUString const &url, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv, bool throw_exc=true)
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
dictionary props
bool getPropertyValue(ValueType &rValue, css::uno::Reference< css::beans::XPropertySet > const &xPropSet, OUString const &propName)
signed char sal_Int8