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