LCOV - code coverage report
Current view: top level - libreoffice/desktop/source/deployment/manager - dp_properties.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 54 0.0 %
Date: 2012-12-27 Functions: 0 6 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : #include <list>
      26             : 
      27             : #include "dp_ucb.h"
      28             : #include "rtl/ustrbuf.hxx"
      29             : #include "dp_properties.hxx"
      30             : 
      31             : namespace lang  = com::sun::star::lang;
      32             : namespace ucb = com::sun::star::ucb;
      33             : namespace uno = com::sun::star::uno;
      34             : 
      35             : #define OUSTR(s) rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(s))
      36             : 
      37             : using ::com::sun::star::uno::Reference;
      38             : using ::rtl::OUString;
      39             : 
      40             : #define PROP_SUPPRESS_LICENSE "SUPPRESS_LICENSE"
      41             : #define PROP_EXTENSION_UPDATE "EXTENSION_UPDATE"
      42             : 
      43             : namespace dp_manager {
      44             : 
      45             : //Reading the file
      46           0 : ExtensionProperties::ExtensionProperties(
      47             :     OUString const & urlExtension,
      48             :     Reference<ucb::XCommandEnvironment> const & xCmdEnv,
      49             :     Reference<uno::XComponentContext> const & xContext) :
      50           0 :     m_xCmdEnv(xCmdEnv), m_xContext(xContext)
      51             : {
      52           0 :     m_propFileUrl = urlExtension + OUSTR("properties");
      53             : 
      54           0 :     ::std::list< ::std::pair< OUString, OUString> > props;
      55           0 :     if (! dp_misc::create_ucb_content(NULL, m_propFileUrl, 0, false))
      56           0 :         return;
      57             : 
      58           0 :     ::ucbhelper::Content contentProps(m_propFileUrl, m_xCmdEnv, m_xContext);
      59           0 :     dp_misc::readProperties(props, contentProps);
      60             : 
      61             :     typedef ::std::list< ::std::pair< OUString, OUString> >::const_iterator CI;
      62           0 :     for (CI i = props.begin(); i != props.end(); ++i)
      63             :     {
      64           0 :         if (i->first.equals(OUSTR(PROP_SUPPRESS_LICENSE)))
      65           0 :             m_prop_suppress_license = i->second;
      66           0 :     }
      67             : }
      68             : 
      69             : //Writing the file
      70           0 : ExtensionProperties::ExtensionProperties(
      71             :     OUString const & urlExtension,
      72             :     uno::Sequence<css::beans::NamedValue> const & properties,
      73             :     Reference<ucb::XCommandEnvironment> const & xCmdEnv,
      74             :     Reference<uno::XComponentContext> const & xContext) :
      75           0 :     m_xCmdEnv(xCmdEnv), m_xContext(xContext)
      76             : {
      77           0 :     m_propFileUrl = urlExtension + OUSTR("properties");
      78             : 
      79           0 :     for (sal_Int32 i = 0; i < properties.getLength(); i++)
      80             :     {
      81           0 :         css::beans::NamedValue const & v = properties[i];
      82           0 :         if (v.Name.equals(OUSTR(PROP_SUPPRESS_LICENSE)))
      83             :         {
      84           0 :             m_prop_suppress_license = getPropertyValue(v);
      85             :         }
      86           0 :         else if (v.Name.equals(OUSTR(PROP_EXTENSION_UPDATE)))
      87             :         {
      88           0 :             m_prop_extension_update = getPropertyValue(v);
      89             :         }
      90             :         else
      91             :         {
      92             :             throw lang::IllegalArgumentException(
      93           0 :                 OUSTR("Extension Manager: unknown property"), 0, -1);
      94             :         }
      95             :     }
      96           0 : }
      97             : 
      98           0 : OUString ExtensionProperties::getPropertyValue(css::beans::NamedValue const & v)
      99             : {
     100           0 :     OUString value(OUSTR("0"));
     101           0 :     if (v.Value >>= value)
     102             :     {
     103           0 :         if (value.equals(OUSTR("1")))
     104           0 :             value = OUSTR("1");
     105             :     }
     106             :     else
     107             :     {
     108             :         throw lang::IllegalArgumentException(
     109           0 :             OUSTR("Extension Manager: wrong property value"), 0, -1);
     110             :     }
     111           0 :     return value;
     112             : }
     113           0 : void ExtensionProperties::write()
     114             : {
     115           0 :     ::ucbhelper::Content contentProps(m_propFileUrl, m_xCmdEnv, m_xContext);
     116           0 :     ::rtl::OUStringBuffer buf;
     117             : 
     118           0 :     if (m_prop_suppress_license)
     119             :     {
     120           0 :         buf.append(OUSTR(PROP_SUPPRESS_LICENSE));
     121           0 :         buf.append(OUSTR("="));
     122           0 :         buf.append(*m_prop_suppress_license);
     123             :     }
     124             : 
     125             :     ::rtl::OString stamp = ::rtl::OUStringToOString(
     126           0 :         buf.makeStringAndClear(), RTL_TEXTENCODING_UTF8);
     127             :     Reference<css::io::XInputStream> xData(
     128             :         ::xmlscript::createInputStream(
     129             :             ::rtl::ByteSequence(
     130           0 :                 reinterpret_cast<sal_Int8 const *>(stamp.getStr()),
     131           0 :                 stamp.getLength() ) ) );
     132           0 :     contentProps.writeStream( xData, true /* replace existing */ );
     133           0 : }
     134             : 
     135           0 : bool ExtensionProperties::isSuppressedLicense()
     136             : {
     137           0 :     bool ret = false;
     138           0 :     if (m_prop_suppress_license)
     139             :     {
     140           0 :         if (m_prop_suppress_license->equals(OUSTR("1")))
     141           0 :             ret = true;
     142             :     }
     143           0 :     return ret;
     144             : }
     145             : 
     146           0 : bool ExtensionProperties::isExtensionUpdate()
     147             : {
     148           0 :     bool ret = false;
     149           0 :     if (m_prop_extension_update)
     150             :     {
     151           0 :         if (m_prop_extension_update->equals(OUSTR("1")))
     152           0 :             ret = true;
     153             :     }
     154           0 :     return ret;
     155             : }
     156             : 
     157             : } // namespace dp_manager
     158             : 
     159             : 
     160             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10