LCOV - code coverage report
Current view: top level - libreoffice/framework/source/accelerators - documentacceleratorconfiguration.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 27 45 60.0 %
Date: 2012-12-17 Functions: 13 21 61.9 %
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             : #include <accelerators/documentacceleratorconfiguration.hxx>
      21             : 
      22             : #include <xml/acceleratorconfigurationreader.hxx>
      23             : 
      24             : #include <xml/acceleratorconfigurationwriter.hxx>
      25             : 
      26             : #include <xml/saxnamespacefilter.hxx>
      27             : 
      28             : #include <threadhelp/readguard.hxx>
      29             : #include <threadhelp/writeguard.hxx>
      30             : 
      31             : #include <acceleratorconst.h>
      32             : #include <services.h>
      33             : 
      34             : #include <com/sun/star/io/XActiveDataSource.hpp>
      35             : 
      36             : #include <com/sun/star/io/XSeekable.hpp>
      37             : 
      38             : #include <com/sun/star/io/XTruncate.hpp>
      39             : 
      40             : #include <com/sun/star/embed/ElementModes.hpp>
      41             : 
      42             : #include <com/sun/star/xml/sax/InputSource.hpp>
      43             : 
      44             : #include <com/sun/star/xml/sax/XParser.hpp>
      45             : 
      46             : #include <comphelper/sequenceashashmap.hxx>
      47             : 
      48             : 
      49             : namespace framework
      50             : {
      51             : 
      52             : //-----------------------------------------------
      53             : // XInterface, XTypeProvider, XServiceInfo
      54         300 : DEFINE_XINTERFACE_2(DocumentAcceleratorConfiguration                   ,
      55             :                     XMLBasedAcceleratorConfiguration                           ,
      56             :                     DIRECT_INTERFACE(css::lang::XServiceInfo)          ,
      57             :                     DIRECT_INTERFACE(css::lang::XInitialization))
      58             : //                    DIRECT_INTERFACE(css::ui::XUIConfigurationStorage))
      59             : 
      60           0 : DEFINE_XTYPEPROVIDER_2_WITH_BASECLASS(DocumentAcceleratorConfiguration ,
      61             :                                       XMLBasedAcceleratorConfiguration         ,
      62             :                                       css::lang::XServiceInfo          ,
      63             :                                       css::lang::XInitialization)
      64             : //                                      css::ui::XUIConfigurationStorage)
      65             : 
      66         522 : DEFINE_XSERVICEINFO_MULTISERVICE(DocumentAcceleratorConfiguration                   ,
      67             :                                  ::cppu::OWeakObject                                ,
      68             :                                  SERVICENAME_DOCUMENTACCELERATORCONFIGURATION       ,
      69             :                                  IMPLEMENTATIONNAME_DOCUMENTACCELERATORCONFIGURATION)
      70             : 
      71           2 : DEFINE_INIT_SERVICE(DocumentAcceleratorConfiguration,
      72             :                     {
      73             :                         /*Attention
      74             :                         I think we don't need any mutex or lock here ... because we are called by our own static method impl_createInstance()
      75             :                         to create a new instance of this class by our own supported service factory.
      76             :                         see macro DEFINE_XSERVICEINFO_MULTISERVICE and "impl_initService()" for further informations!
      77             :                         */
      78             :                     }
      79             :                    )
      80             : 
      81             : //-----------------------------------------------
      82           2 : DocumentAcceleratorConfiguration::DocumentAcceleratorConfiguration(const css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR)
      83           2 :     : XMLBasedAcceleratorConfiguration(xSMGR)
      84             : {
      85           2 : }
      86             : 
      87             : //-----------------------------------------------
      88           6 : DocumentAcceleratorConfiguration::~DocumentAcceleratorConfiguration()
      89             : {
      90           2 :     m_aPresetHandler.removeStorageListener(this);
      91           4 : }
      92             : 
      93             : //-----------------------------------------------
      94           2 : void SAL_CALL DocumentAcceleratorConfiguration::initialize(const css::uno::Sequence< css::uno::Any >& lArguments)
      95             :     throw(css::uno::Exception       ,
      96             :           css::uno::RuntimeException)
      97             : {
      98             :     // SAFE -> ----------------------------------
      99           2 :     WriteGuard aWriteLock(m_aLock);
     100             : 
     101           2 :     ::comphelper::SequenceAsHashMap lArgs(lArguments);
     102             :     m_xDocumentRoot = lArgs.getUnpackedValueOrDefault(
     103             :                         ::rtl::OUString("DocumentRoot"),
     104           2 :                         css::uno::Reference< css::embed::XStorage >());
     105             : 
     106           2 :     aWriteLock.unlock();
     107             :     // <- SAFE ----------------------------------
     108             : 
     109           2 :     impl_ts_fillCache();
     110           2 : }
     111             : 
     112             : //-----------------------------------------------
     113           0 : void SAL_CALL DocumentAcceleratorConfiguration::setStorage(const css::uno::Reference< css::embed::XStorage >& xStorage)
     114             :     throw(css::uno::RuntimeException)
     115             : {
     116             :     // Attention! xStorage must be accepted too, if it's NULL !
     117             : 
     118             :     // SAFE -> ----------------------------------
     119           0 :     WriteGuard aWriteLock(m_aLock);
     120           0 :     sal_Bool bForgetOldStorages = m_xDocumentRoot.is();
     121           0 :     m_xDocumentRoot = xStorage;
     122           0 :     aWriteLock.unlock();
     123             :     // <- SAFE ----------------------------------
     124             : 
     125           0 :     if (bForgetOldStorages)
     126           0 :         impl_ts_clearCache();
     127             : 
     128           0 :     if (xStorage.is())
     129           0 :         impl_ts_fillCache();
     130           0 : }
     131             : 
     132             : //-----------------------------------------------
     133           0 : sal_Bool SAL_CALL DocumentAcceleratorConfiguration::hasStorage()
     134             :     throw(css::uno::RuntimeException)
     135             : {
     136             :     // SAFE -> ----------------------------------
     137           0 :     ReadGuard aReadLock(m_aLock);
     138           0 :     return m_xDocumentRoot.is();
     139             :     // <- SAFE ----------------------------------
     140             : }
     141             : 
     142             : //-----------------------------------------------
     143           2 : void DocumentAcceleratorConfiguration::impl_ts_fillCache()
     144             : {
     145             :     // SAFE -> ----------------------------------
     146           2 :     ReadGuard aReadLock(m_aLock);
     147           2 :     css::uno::Reference< css::embed::XStorage > xDocumentRoot = m_xDocumentRoot;
     148           2 :     aReadLock.unlock();
     149             :     // <- SAFE ----------------------------------
     150             : 
     151             :     // Sometimes we must live without a document root.
     152             :     // E.g. if the document is readonly ...
     153           2 :     if (!xDocumentRoot.is())
     154           2 :         return;
     155             : 
     156             :     // get current office locale ... but dont cache it.
     157             :     // Otherwise we must be listener on the configuration layer
     158             :     // which seems to superflous for this small implementation .-)
     159           2 :     ::comphelper::Locale aLocale = impl_ts_getLocale();
     160             : 
     161             :     // May be the current document does not contain any
     162             :     // accelerator config? Handle it gracefully :-)
     163             :     try
     164             :     {
     165             :         // Note: The used preset class is threadsafe by itself ... and live if we live!
     166             :         // We do not need any mutex here.
     167             : 
     168             :         // open the folder, where the configuration exists
     169             :         m_aPresetHandler.connectToResource(
     170             :             PresetHandler::E_DOCUMENT,
     171             :             PresetHandler::RESOURCETYPE_ACCELERATOR(),
     172             :             ::rtl::OUString(),
     173             :             xDocumentRoot,
     174           2 :             aLocale);
     175             : 
     176           2 :         DocumentAcceleratorConfiguration::reload();
     177           2 :         m_aPresetHandler.addStorageListener(this);
     178             :     }
     179           0 :     catch(const css::uno::Exception&)
     180           2 :     {}
     181             : }
     182             : 
     183             : //-----------------------------------------------
     184           0 : void DocumentAcceleratorConfiguration::impl_ts_clearCache()
     185             : {
     186           0 :     m_aPresetHandler.forgetCachedStorages();
     187           0 : }
     188             : 
     189             : } // namespace framework
     190             : 
     191             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10