LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/framework/source/accelerators - documentacceleratorconfiguration.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 42 50 84.0 %
Date: 2013-07-09 Functions: 17 23 73.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             : #include <i18nlangtag/languagetag.hxx>
      48             : 
      49             : #define SERVICENAME_DOCUMENTACCELERATORCONFIGURATION            DECLARE_ASCII("com.sun.star.ui.DocumentAcceleratorConfiguration")
      50             : #define IMPLEMENTATIONNAME_DOCUMENTACCELERATORCONFIGURATION     DECLARE_ASCII("com.sun.star.comp.framework.DocumentAcceleratorConfiguration")
      51             : 
      52             : namespace framework
      53             : {
      54             : 
      55             : //-----------------------------------------------
      56             : // XInterface, XTypeProvider, XServiceInfo
      57       94826 : DEFINE_XINTERFACE_2(DocumentAcceleratorConfiguration                   ,
      58             :                     XMLBasedAcceleratorConfiguration                           ,
      59             :                     DIRECT_INTERFACE(css::lang::XServiceInfo)          ,
      60             :                     DIRECT_INTERFACE(css::lang::XInitialization))
      61             : //                    DIRECT_INTERFACE(css::ui::XUIConfigurationStorage))
      62             : 
      63           0 : DEFINE_XTYPEPROVIDER_2_WITH_BASECLASS(DocumentAcceleratorConfiguration ,
      64             :                                       XMLBasedAcceleratorConfiguration         ,
      65             :                                       css::lang::XServiceInfo          ,
      66             :                                       css::lang::XInitialization)
      67             : //                                      css::ui::XUIConfigurationStorage)
      68             : 
      69        1638 : DEFINE_XSERVICEINFO_MULTISERVICE_2(DocumentAcceleratorConfiguration                   ,
      70             :                                    ::cppu::OWeakObject                                ,
      71             :                                    SERVICENAME_DOCUMENTACCELERATORCONFIGURATION       ,
      72             :                                    IMPLEMENTATIONNAME_DOCUMENTACCELERATORCONFIGURATION)
      73             : 
      74         614 : DEFINE_INIT_SERVICE(DocumentAcceleratorConfiguration,
      75             :                     {
      76             :                         /*Attention
      77             :                         I think we don't need any mutex or lock here ... because we are called by our own static method impl_createInstance()
      78             :                         to create a new instance of this class by our own supported service factory.
      79             :                         see macro DEFINE_XSERVICEINFO_MULTISERVICE and "impl_initService()" for further information!
      80             :                         */
      81             :                     }
      82             :                    )
      83             : 
      84             : //-----------------------------------------------
      85         614 : DocumentAcceleratorConfiguration::DocumentAcceleratorConfiguration(const css::uno::Reference< css::uno::XComponentContext >& xContext)
      86         614 :     : XMLBasedAcceleratorConfiguration(xContext)
      87             : {
      88         614 : }
      89             : 
      90             : //-----------------------------------------------
      91        1842 : DocumentAcceleratorConfiguration::~DocumentAcceleratorConfiguration()
      92             : {
      93         614 :     m_aPresetHandler.removeStorageListener(this);
      94        1228 : }
      95             : 
      96             : //-----------------------------------------------
      97         614 : void SAL_CALL DocumentAcceleratorConfiguration::initialize(const css::uno::Sequence< css::uno::Any >& lArguments)
      98             :     throw(css::uno::Exception       ,
      99             :           css::uno::RuntimeException)
     100             : {
     101             :     // SAFE -> ----------------------------------
     102         614 :     WriteGuard aWriteLock(m_aLock);
     103             : 
     104        1228 :     css::uno::Reference<css::embed::XStorage> xRoot;
     105         614 :     if (lArguments.getLength() == 1 && (lArguments[0] >>= xRoot))
     106             :     {
     107         614 :         m_xDocumentRoot = xRoot;
     108             :     }
     109             :     else
     110             :     {
     111           0 :         ::comphelper::SequenceAsHashMap lArgs(lArguments);
     112           0 :         m_xDocumentRoot = lArgs.getUnpackedValueOrDefault(
     113             :                             OUString("DocumentRoot"),
     114           0 :                             css::uno::Reference< css::embed::XStorage >());
     115             :     }
     116             : 
     117         614 :     aWriteLock.unlock();
     118             :     // <- SAFE ----------------------------------
     119             : 
     120        1228 :     impl_ts_fillCache();
     121         614 : }
     122             : 
     123             : //-----------------------------------------------
     124           8 : void SAL_CALL DocumentAcceleratorConfiguration::setStorage(const css::uno::Reference< css::embed::XStorage >& xStorage)
     125             :     throw(css::uno::RuntimeException)
     126             : {
     127             :     // Attention! xStorage must be accepted too, if it's NULL !
     128             : 
     129             :     // SAFE -> ----------------------------------
     130           8 :     WriteGuard aWriteLock(m_aLock);
     131           8 :     sal_Bool bForgetOldStorages = m_xDocumentRoot.is();
     132           8 :     m_xDocumentRoot = xStorage;
     133           8 :     aWriteLock.unlock();
     134             :     // <- SAFE ----------------------------------
     135             : 
     136           8 :     if (bForgetOldStorages)
     137           8 :         impl_ts_clearCache();
     138             : 
     139           8 :     if (xStorage.is())
     140           8 :         impl_ts_fillCache();
     141           8 : }
     142             : 
     143             : //-----------------------------------------------
     144           0 : sal_Bool SAL_CALL DocumentAcceleratorConfiguration::hasStorage()
     145             :     throw(css::uno::RuntimeException)
     146             : {
     147             :     // SAFE -> ----------------------------------
     148           0 :     ReadGuard aReadLock(m_aLock);
     149           0 :     return m_xDocumentRoot.is();
     150             :     // <- SAFE ----------------------------------
     151             : }
     152             : 
     153             : //-----------------------------------------------
     154         622 : void DocumentAcceleratorConfiguration::impl_ts_fillCache()
     155             : {
     156             :     // SAFE -> ----------------------------------
     157         622 :     ReadGuard aReadLock(m_aLock);
     158        1244 :     css::uno::Reference< css::embed::XStorage > xDocumentRoot = m_xDocumentRoot;
     159         622 :     aReadLock.unlock();
     160             :     // <- SAFE ----------------------------------
     161             : 
     162             :     // Sometimes we must live without a document root.
     163             :     // E.g. if the document is readonly ...
     164         622 :     if (!xDocumentRoot.is())
     165         622 :         return;
     166             : 
     167             :     // get current office locale ... but dont cache it.
     168             :     // Otherwise we must be listener on the configuration layer
     169             :     // which seems to superflous for this small implementation .-)
     170        1244 :     LanguageTag aLanguageTag( impl_ts_getLocale());
     171             : 
     172             :     // May be the current document does not contain any
     173             :     // accelerator config? Handle it gracefully :-)
     174             :     try
     175             :     {
     176             :         // Note: The used preset class is threadsafe by itself ... and live if we live!
     177             :         // We do not need any mutex here.
     178             : 
     179             :         // open the folder, where the configuration exists
     180             :         m_aPresetHandler.connectToResource(
     181             :             PresetHandler::E_DOCUMENT,
     182             :             PresetHandler::RESOURCETYPE_ACCELERATOR(),
     183             :             OUString(),
     184             :             xDocumentRoot,
     185         622 :             aLanguageTag);
     186             : 
     187         622 :         DocumentAcceleratorConfiguration::reload();
     188         622 :         m_aPresetHandler.addStorageListener(this);
     189             :     }
     190           0 :     catch(const css::uno::Exception&)
     191         622 :     {}
     192             : }
     193             : 
     194             : //-----------------------------------------------
     195           8 : void DocumentAcceleratorConfiguration::impl_ts_clearCache()
     196             : {
     197           8 :     m_aPresetHandler.forgetCachedStorages();
     198           8 : }
     199             : 
     200         402 : } // namespace framework
     201             : 
     202             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10