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 #define PROP_SUPPRESS_LICENSE "SUPPRESS_LICENSE"
38 #define PROP_EXTENSION_UPDATE "EXTENSION_UPDATE"
39 
40 namespace dp_manager {
41 
42 //Reading the file
44  OUString const & urlExtension,
45  Reference<ucb::XCommandEnvironment> const & xCmdEnv,
47  m_xCmdEnv(xCmdEnv), m_xContext(xContext)
48 {
49  m_propFileUrl = 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  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)
72 {
73  m_propFileUrl = urlExtension + "properties";
74 
75  for (sal_Int32 i = 0; i < properties.getLength(); i++)
76  {
77  css::beans::NamedValue const & v = properties[i];
78  if (v.Name == PROP_SUPPRESS_LICENSE)
79  {
80  m_prop_suppress_license = getPropertyValue(v);
81  }
82  else if (v.Name == PROP_EXTENSION_UPDATE)
83  {
84  m_prop_extension_update = getPropertyValue(v);
85  }
86  else
87  {
88  throw lang::IllegalArgumentException(
89  "Extension Manager: unknown property", nullptr, -1);
90  }
91  }
92 }
93 
94 OUString ExtensionProperties::getPropertyValue(css::beans::NamedValue const & v)
95 {
96  OUString value("0");
97  if (! (v.Value >>= value) )
98  {
99  throw lang::IllegalArgumentException(
100  "Extension Manager: wrong property value", nullptr, -1);
101  }
102  return value;
103 }
105 {
107  OUStringBuffer buf;
108 
110  {
111  buf.append(PROP_SUPPRESS_LICENSE);
112  buf.append("=");
113  buf.append(*m_prop_suppress_license);
114  }
115 
116  OString stamp = OUStringToOString(
117  buf.makeStringAndClear(), RTL_TEXTENCODING_UTF8);
118  Reference<css::io::XInputStream> xData(
120  reinterpret_cast<sal_Int8 const *>(stamp.getStr()),
121  stamp.getLength() ) );
122  contentProps.writeStream( xData, true /* replace existing */ );
123 }
124 
126 {
127  bool ret = false;
129  {
130  if (*m_prop_suppress_license == "1")
131  ret = true;
132  }
133  return ret;
134 }
135 
137 {
138  bool ret = false;
140  {
141  if (*m_prop_extension_update == "1")
142  ret = true;
143  }
144  return ret;
145 }
146 
147 } // namespace dp_manager
148 
149 
150 /* 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:259
IJScriptValueObject VARIANT value
static OUString getPropertyValue(css::beans::NamedValue const &v)
::boost::optional< OUString > m_prop_suppress_license
const css::uno::Reference< css::uno::XComponentContext > m_xContext
bool getPropertyValue(ValueType &rValue, css::uno::Reference< css::beans::XPropertySet > const &xPropSet, OUString const &propName)
::boost::optional< OUString > m_prop_extension_update
#define PROP_EXTENSION_UPDATE
Reference< io::XInputStream > createInputStream(std::vector< sal_Int8 > const &rInData)
int i
ExtensionProperties(OUString const &urlExtension, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv, css::uno::Reference< css::uno::XComponentContext > const &xContext)
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(const OUString &str, ConnectionSettings const *settings)
float v
static uno::Reference< css::uno::XComponentContext > xContext
Definition: init.cxx:1858
const css::uno::Reference< css::ucb::XCommandEnvironment > m_xCmdEnv
#define PROP_SUPPRESS_LICENSE
void writeStream(const css::uno::Reference< css::io::XInputStream > &rStream, bool bReplaceExisting)
const uno::Reference< uno::XComponentContext > m_xContext