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

Generated by: LCOV version 1.10