LCOV - code coverage report
Current view: top level - sfx2/source/doc - doctemplates.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 488 1288 37.9 %
Date: 2012-08-25 Functions: 65 121 53.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 485 2577 18.8 %

           Branch data     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 "doctemplates.hxx"
      22                 :            : #include <osl/mutex.hxx>
      23                 :            : #include <tools/debug.hxx>
      24                 :            : #include <tools/diagnose_ex.h>
      25                 :            : #include <tools/urlobj.hxx>
      26                 :            : #include <rtl/ustring.hxx>
      27                 :            : #include <rtl/ustrbuf.hxx>
      28                 :            : #include <tools/resary.hxx>
      29                 :            : #include <vcl/svapp.hxx>
      30                 :            : #include <vcl/wrkwin.hxx>
      31                 :            : #include <unotools/pathoptions.hxx>
      32                 :            : #include <comphelper/componentcontext.hxx>
      33                 :            : #include <comphelper/processfactory.hxx>
      34                 :            : #include <comphelper/sequenceashashmap.hxx>
      35                 :            : #include <comphelper/string.hxx>
      36                 :            : #include <com/sun/star/beans/PropertyAttribute.hpp>
      37                 :            : #include <com/sun/star/beans/XPropertySet.hpp>
      38                 :            : #include <com/sun/star/beans/XPropertySetInfo.hpp>
      39                 :            : #include <com/sun/star/beans/XPropertyContainer.hpp>
      40                 :            : #include <com/sun/star/beans/StringPair.hpp>
      41                 :            : #include <com/sun/star/util/XMacroExpander.hpp>
      42                 :            : #include <com/sun/star/container/XContainerQuery.hpp>
      43                 :            : #include <com/sun/star/document/XTypeDetection.hpp>
      44                 :            : #include <com/sun/star/document/XStandaloneDocumentInfo.hpp>
      45                 :            : #include <com/sun/star/sdbc/XResultSet.hpp>
      46                 :            : #include <com/sun/star/sdbc/XRow.hpp>
      47                 :            : #include <com/sun/star/ucb/NameClash.hpp>
      48                 :            : #include <com/sun/star/ucb/NameClashException.hpp>
      49                 :            : #include <com/sun/star/ucb/TransferInfo.hpp>
      50                 :            : #include <com/sun/star/ucb/XCommandEnvironment.hpp>
      51                 :            : #include <com/sun/star/ucb/XContentAccess.hpp>
      52                 :            : #include <com/sun/star/frame/XModuleManager.hpp>
      53                 :            : #include <com/sun/star/uno/Exception.hpp>
      54                 :            : 
      55                 :            : #include <svtools/templatefoldercache.hxx>
      56                 :            : #include <unotools/configmgr.hxx>
      57                 :            : #include <unotools/ucbhelper.hxx>
      58                 :            : 
      59                 :            : #include "sfx2/sfxresid.hxx"
      60                 :            : #include "sfxurlrelocator.hxx"
      61                 :            : #include "doctemplateslocal.hxx"
      62                 :            : #include <sfx2/docfac.hxx>
      63                 :            : #include <sfx2/docfile.hxx>
      64                 :            : #include "doc.hrc"
      65                 :            : 
      66                 :            : #include <vector>
      67                 :            : 
      68                 :            : //-----------------------------------------------------------------------------
      69                 :            : 
      70                 :            : //=============================================================================
      71                 :            : 
      72                 :            : #define TEMPLATE_SERVICE_NAME               "com.sun.star.frame.DocumentTemplates"
      73                 :            : #define TEMPLATE_IMPLEMENTATION_NAME        "com.sun.star.comp.sfx2.DocumentTemplates"
      74                 :            : 
      75                 :            : #define SERVICENAME_TYPEDETECTION           "com.sun.star.document.TypeDetection"
      76                 :            : #define SERVICENAME_DOCINFO                 "com.sun.star.document.StandaloneDocumentInfo"
      77                 :            : 
      78                 :            : #define TEMPLATE_ROOT_URL       "vnd.sun.star.hier:/templates"
      79                 :            : #define TITLE                   "Title"
      80                 :            : #define IS_FOLDER               "IsFolder"
      81                 :            : #define IS_DOCUMENT             "IsDocument"
      82                 :            : #define TARGET_URL              "TargetURL"
      83                 :            : #define TEMPLATE_VERSION        "TemplateComponentVersion"
      84                 :            : #define TEMPLATE_VERSION_VALUE  "2"
      85                 :            : #define TYPE_FOLDER             "application/vnd.sun.star.hier-folder"
      86                 :            : #define TYPE_LINK               "application/vnd.sun.star.hier-link"
      87                 :            : #define TYPE_FSYS_FOLDER        "application/vnd.sun.staroffice.fsys-folder"
      88                 :            : #define TYPE_FSYS_FILE          "application/vnd.sun.staroffice.fsys-file"
      89                 :            : 
      90                 :            : #define PROPERTY_DIRLIST        "DirectoryList"
      91                 :            : #define PROPERTY_NEEDSUPDATE    "NeedsUpdate"
      92                 :            : #define PROPERTY_TYPE           "TypeDescription"
      93                 :            : 
      94                 :            : #define TARGET_DIR_URL          "TargetDirURL"
      95                 :            : #define COMMAND_DELETE          "delete"
      96                 :            : #define COMMAND_TRANSFER        "transfer"
      97                 :            : 
      98                 :            : #define STANDARD_FOLDER         "standard"
      99                 :            : 
     100                 :            : #define C_DELIM                 ';'
     101                 :            : 
     102                 :            : //=============================================================================
     103                 :            : 
     104                 :            : using namespace ::com::sun::star;
     105                 :            : using namespace ::com::sun::star::beans;
     106                 :            : using namespace ::com::sun::star::document;
     107                 :            : using namespace ::com::sun::star::io;
     108                 :            : using namespace ::com::sun::star::lang;
     109                 :            : using namespace ::com::sun::star::sdbc;
     110                 :            : using namespace ::com::sun::star::ucb;
     111                 :            : using namespace ::com::sun::star::uno;
     112                 :            : using namespace ::com::sun::star::container;
     113                 :            : using namespace ::com::sun::star::util;
     114                 :            : 
     115                 :            : using namespace ::rtl;
     116                 :            : using namespace ::ucbhelper;
     117                 :            : using namespace ::comphelper;
     118                 :            : 
     119                 :            : using ::std::vector;
     120                 :            : 
     121                 :            : //=============================================================================
     122                 :            : 
     123                 :            : class WaitWindow_Impl : public WorkWindow
     124                 :            : {
     125                 :            :     Rectangle   _aRect;
     126                 :            :     sal_uInt16      _nTextStyle;
     127                 :            :     String      _aText;
     128                 :            : 
     129                 :            :     public:
     130                 :            :                      WaitWindow_Impl();
     131                 :            :                     ~WaitWindow_Impl();
     132                 :            :     virtual void     Paint( const Rectangle& rRect );
     133                 :            : };
     134                 :            : 
     135                 :            : #define X_OFFSET 15
     136                 :            : #define Y_OFFSET 15
     137                 :            : 
     138                 :            : //=============================================================================
     139                 :            : 
     140                 :         44 : struct NamePair_Impl
     141                 :            : {
     142                 :            :     OUString maShortName;
     143                 :            :     OUString maLongName;
     144                 :            : };
     145                 :            : 
     146                 :            : class Updater_Impl;
     147                 :            : class DocTemplates_EntryData_Impl;
     148                 :            : class GroupData_Impl;
     149                 :            : 
     150                 :            : typedef vector< NamePair_Impl* > NameList_Impl;
     151                 :            : typedef vector< GroupData_Impl* > GroupList_Impl;
     152                 :            : 
     153                 :            : //=============================================================================
     154                 :            : #include <com/sun/star/task/XInteractionHandler.hpp>
     155                 :            : #include <com/sun/star/ucb/XProgressHandler.hpp>
     156                 :            : 
     157         [ -  + ]:         22 : class TplTaskEnvironment : public ::cppu::WeakImplHelper1< ucb::XCommandEnvironment >
     158                 :            : {
     159                 :            :     uno::Reference< task::XInteractionHandler >               m_xInteractionHandler;
     160                 :            :     uno::Reference< ucb::XProgressHandler >                   m_xProgressHandler;
     161                 :            : 
     162                 :            : public:
     163                 :         14 :     TplTaskEnvironment( const uno::Reference< task::XInteractionHandler>& rxInteractionHandler )
     164                 :         14 :                                 : m_xInteractionHandler( rxInteractionHandler )
     165                 :         14 :                             {}
     166                 :            : 
     167                 :          0 :     virtual uno::Reference<task::XInteractionHandler> SAL_CALL getInteractionHandler() throw (uno::RuntimeException)
     168                 :          0 :     { return m_xInteractionHandler; }
     169                 :            : 
     170                 :          0 :     virtual uno::Reference<ucb::XProgressHandler> SAL_CALL    getProgressHandler() throw (uno::RuntimeException)
     171                 :          0 :     { return m_xProgressHandler; }
     172                 :            : };
     173                 :            : 
     174                 :            : class SfxDocTplService_Impl
     175                 :            : {
     176                 :            :     uno::Reference< XMultiServiceFactory >           mxFactory;
     177                 :            :     uno::Reference< XCommandEnvironment >            maCmdEnv;
     178                 :            :     uno::Reference< XStandaloneDocumentInfo >        mxInfo;
     179                 :            :     uno::Reference< XTypeDetection >                 mxType;
     180                 :            : 
     181                 :            :     ::osl::Mutex                maMutex;
     182                 :            :     Sequence< OUString >        maTemplateDirs;
     183                 :            :     OUString                    maRootURL;
     184                 :            :     NameList_Impl               maNames;
     185                 :            :     Locale                      maLocale;
     186                 :            :     Content                     maRootContent;
     187                 :            :     Updater_Impl*               mpUpdater;
     188                 :            :     sal_Bool                    mbIsInitialized : 1;
     189                 :            :     sal_Bool                    mbLocaleSet     : 1;
     190                 :            : 
     191                 :            :     SfxURLRelocator_Impl        maRelocator;
     192                 :            : 
     193                 :            :     void                        init_Impl();
     194                 :            :     void                        getDefaultLocale();
     195                 :            :     void                        getDirList();
     196                 :            :     void                        readFolderList();
     197                 :            :     sal_Bool                    needsUpdate();
     198                 :            :     OUString                    getLongName( const OUString& rShortName );
     199                 :            :     sal_Bool                    setTitleForURL( const OUString& rURL, const OUString& aTitle );
     200                 :            :     sal_Bool                    getTitleFromURL( const OUString& rURL, OUString& aTitle, OUString& aType, sal_Bool& bDocHasTitle );
     201                 :            : 
     202                 :            :     sal_Bool                    addEntry( Content& rParentFolder,
     203                 :            :                                           const OUString& rTitle,
     204                 :            :                                           const OUString& rTargetURL,
     205                 :            :                                           const OUString& rType );
     206                 :            : 
     207                 :            :     sal_Bool                    createFolder( const OUString& rNewFolderURL,
     208                 :            :                                               sal_Bool  bCreateParent,
     209                 :            :                                               sal_Bool  bFsysFolder,
     210                 :            :                                               Content   &rNewFolder );
     211                 :            : 
     212                 :            :     sal_Bool                    CreateNewUniqueFolderWithPrefix( const ::rtl::OUString& aPath,
     213                 :            :                                                                 const ::rtl::OUString& aPrefix,
     214                 :            :                                                                 ::rtl::OUString& aNewFolderName,
     215                 :            :                                                                 ::rtl::OUString& aNewFolderURL,
     216                 :            :                                                                 Content& aNewFolder );
     217                 :            :     ::rtl::OUString             CreateNewUniqueFileWithPrefix( const ::rtl::OUString& aPath,
     218                 :            :                                                                 const ::rtl::OUString& aPrefix,
     219                 :            :                                                                 const ::rtl::OUString& aExt );
     220                 :            : 
     221                 :            :     uno::Sequence< beans::StringPair > ReadUINamesForTemplateDir_Impl( const ::rtl::OUString& aUserPath );
     222                 :            :     sal_Bool                    UpdateUINamesForTemplateDir_Impl( const ::rtl::OUString& aUserPath,
     223                 :            :                                                                   const ::rtl::OUString& aGroupName,
     224                 :            :                                                                   const ::rtl::OUString& aNewFolderName );
     225                 :            :     sal_Bool                    ReplaceUINamesForTemplateDir_Impl( const ::rtl::OUString& aUserPath,
     226                 :            :                                                                   const ::rtl::OUString& aFsysGroupName,
     227                 :            :                                                                   const ::rtl::OUString& aOldGroupName,
     228                 :            :                                                                   const ::rtl::OUString& aNewGroupName );
     229                 :            :     sal_Bool                    RemoveUINamesForTemplateDir_Impl( const ::rtl::OUString& aUserPath,
     230                 :            :                                                                   const ::rtl::OUString& aGroupName );
     231                 :            :     sal_Bool                    WriteUINamesForTemplateDir_Impl( const ::rtl::OUString& aUserPath,
     232                 :            :                                                                 const uno::Sequence< beans::StringPair >& aUINames );
     233                 :            : 
     234                 :            :     ::rtl::OUString             CreateNewGroupFsys( const ::rtl::OUString& rGroupName, Content& aGroup );
     235                 :            : 
     236                 :            :     sal_Bool                    removeContent( Content& rContent );
     237                 :            :     sal_Bool                    removeContent( const OUString& rContentURL );
     238                 :            : 
     239                 :            :     sal_Bool                    setProperty( Content& rContent,
     240                 :            :                                              const OUString& rPropName,
     241                 :            :                                              const Any& rPropValue );
     242                 :            :     sal_Bool                    getProperty( Content& rContent,
     243                 :            :                                              const OUString& rPropName,
     244                 :            :                                              Any& rPropValue );
     245                 :            : 
     246                 :            :     void                        createFromContent( GroupList_Impl& rList,
     247                 :            :                                                    Content &rContent,
     248                 :            :                                                    sal_Bool bHierarchy,
     249                 :            :                                                    sal_Bool bWriteableContent = sal_False );
     250                 :            :     void                        addHierGroup( GroupList_Impl& rList,
     251                 :            :                                               const OUString& rTitle,
     252                 :            :                                               const OUString& rOwnURL );
     253                 :            :     void                        addFsysGroup( GroupList_Impl& rList,
     254                 :            :                                               const OUString& rTitle,
     255                 :            :                                               const OUString& rUITitle,
     256                 :            :                                               const OUString& rOwnURL,
     257                 :            :                                               sal_Bool bWriteableGroup = sal_False );
     258                 :            :     void                        removeFromHierarchy( DocTemplates_EntryData_Impl *pData );
     259                 :            :     void                        addToHierarchy( GroupData_Impl *pGroup,
     260                 :            :                                                 DocTemplates_EntryData_Impl *pData );
     261                 :            : 
     262                 :            :     void                        removeFromHierarchy( GroupData_Impl *pGroup );
     263                 :            :     void                        addGroupToHierarchy( GroupData_Impl *pGroup );
     264                 :            : 
     265                 :            :     void                        updateData( DocTemplates_EntryData_Impl *pData );
     266                 :            : 
     267                 :            : public:
     268                 :            :                                  SfxDocTplService_Impl( uno::Reference< XMultiServiceFactory > xFactory );
     269                 :            :                                 ~SfxDocTplService_Impl();
     270                 :            : 
     271         [ +  - ]:         14 :     sal_Bool                    init() { if ( !mbIsInitialized ) init_Impl(); return mbIsInitialized; }
     272                 :          2 :     Content                     getContent() const { return maRootContent; }
     273                 :            : 
     274                 :            :     void                        setLocale( const Locale & rLocale );
     275                 :            :     Locale                      getLocale();
     276                 :            : 
     277                 :            :     sal_Bool                    storeTemplate( const OUString& rGroupName,
     278                 :            :                                                const OUString& rTemplateName,
     279                 :            :                                                const uno::Reference< XSTORABLE >& rStorable );
     280                 :            : 
     281                 :            :     sal_Bool                    addTemplate( const OUString& rGroupName,
     282                 :            :                                              const OUString& rTemplateName,
     283                 :            :                                              const OUString& rSourceURL );
     284                 :            :     sal_Bool                    removeTemplate( const OUString& rGroupName,
     285                 :            :                                                 const OUString& rTemplateName );
     286                 :            :     sal_Bool                    renameTemplate( const OUString& rGroupName,
     287                 :            :                                                 const OUString& rOldName,
     288                 :            :                                                 const OUString& rNewName );
     289                 :            : 
     290                 :            :     sal_Bool                    addGroup( const OUString& rGroupName );
     291                 :            :     sal_Bool                    removeGroup( const OUString& rGroupName );
     292                 :            :     sal_Bool                    renameGroup( const OUString& rOldName,
     293                 :            :                                              const OUString& rNewName );
     294                 :            : 
     295                 :            :     void                        update( sal_Bool bUpdateNow );
     296                 :            :     void                        doUpdate();
     297                 :          0 :     void                        finished() { mpUpdater = NULL; }
     298                 :            : };
     299                 :            : 
     300                 :            : //=============================================================================
     301                 :            : 
     302                 :            : class Updater_Impl : public ::osl::Thread
     303                 :            : {
     304                 :            : private:
     305                 :            :     SfxDocTplService_Impl   *mpDocTemplates;
     306                 :            : 
     307                 :            : public:
     308                 :            :                              Updater_Impl( SfxDocTplService_Impl* pTemplates );
     309                 :            :                             ~Updater_Impl();
     310                 :            : 
     311                 :            :     virtual void SAL_CALL   run();
     312                 :            :     virtual void SAL_CALL   onTerminated();
     313                 :            : };
     314                 :            : 
     315                 :            : //=============================================================================
     316                 :            : 
     317                 :         20 : class DocTemplates_EntryData_Impl
     318                 :            : {
     319                 :            :     OUString            maTitle;
     320                 :            :     OUString            maType;
     321                 :            :     OUString            maTargetURL;
     322                 :            :     OUString            maHierarchyURL;
     323                 :            : 
     324                 :            :     sal_Bool            mbInHierarchy   : 1;
     325                 :            :     sal_Bool            mbInUse         : 1;
     326                 :            :     sal_Bool            mbUpdateType    : 1;
     327                 :            :     sal_Bool            mbUpdateLink    : 1;
     328                 :            : 
     329                 :            : public:
     330                 :            :                         DocTemplates_EntryData_Impl( const OUString& rTitle );
     331                 :            : 
     332                 :          0 :     void                setInUse() { mbInUse = sal_True; }
     333                 :          0 :     void                setHierarchy( sal_Bool bInHierarchy ) { mbInHierarchy = bInHierarchy; }
     334                 :          0 :     void                setUpdateLink( sal_Bool bUpdateLink ) { mbUpdateLink = bUpdateLink; }
     335                 :          0 :     void                setUpdateType( sal_Bool bUpdateType ) { mbUpdateType = bUpdateType; }
     336                 :            : 
     337                 :          0 :     sal_Bool            getInUse() const { return mbInUse; }
     338                 :          0 :     sal_Bool            getInHierarchy() const { return mbInHierarchy; }
     339                 :          0 :     sal_Bool            getUpdateLink() const { return mbUpdateLink; }
     340                 :          0 :     sal_Bool            getUpdateType() const { return mbUpdateType; }
     341                 :            : 
     342                 :          0 :     const OUString&     getHierarchyURL() const { return maHierarchyURL; }
     343                 :         20 :     const OUString&     getTargetURL() const { return maTargetURL; }
     344                 :        130 :     const OUString&     getTitle() const { return maTitle; }
     345                 :         20 :     const OUString&     getType() const { return maType; }
     346                 :            : 
     347                 :          0 :     void                setHierarchyURL( const OUString& rURL ) { maHierarchyURL = rURL; }
     348                 :         20 :     void                setTargetURL( const OUString& rURL ) { maTargetURL = rURL; }
     349                 :         20 :     void                setType( const OUString& rType ) { maType = rType; }
     350                 :            : };
     351                 :            : 
     352                 :            : //=============================================================================
     353                 :            : 
     354                 :            : class GroupData_Impl
     355                 :            : {
     356                 :            :     vector< DocTemplates_EntryData_Impl* > maEntries;
     357                 :            :     OUString            maTitle;
     358                 :            :     OUString            maHierarchyURL;
     359                 :            :     OUString            maTargetURL;
     360                 :            :     sal_Bool            mbInUse         : 1;
     361                 :            :     sal_Bool            mbInHierarchy   : 1;
     362                 :            : 
     363                 :            : public:
     364                 :            :                         GroupData_Impl( const OUString& rTitle );
     365                 :            :                         ~GroupData_Impl();
     366                 :            : 
     367                 :         12 :     void                setInUse() { mbInUse = sal_True; }
     368                 :          0 :     void                setHierarchy( sal_Bool bInHierarchy ) { mbInHierarchy = bInHierarchy; }
     369                 :          6 :     void                setHierarchyURL( const OUString& rURL ) { maHierarchyURL = rURL; }
     370                 :          2 :     void                setTargetURL( const OUString& rURL ) { maTargetURL = rURL; }
     371                 :            : 
     372                 :          6 :     sal_Bool            getInUse() const { return mbInUse; }
     373                 :          6 :     sal_Bool            getInHierarchy() const { return mbInHierarchy; }
     374                 :         40 :     const OUString&     getHierarchyURL() const { return maHierarchyURL; }
     375                 :          6 :     const OUString&     getTargetURL() const { return maTargetURL; }
     376                 :         18 :     const OUString&     getTitle() const { return maTitle; }
     377                 :            : 
     378                 :            :     DocTemplates_EntryData_Impl*     addEntry( const OUString& rTitle,
     379                 :            :                                   const OUString& rTargetURL,
     380                 :            :                                   const OUString& rType,
     381                 :            :                                   const OUString& rHierURL );
     382                 :          6 :     size_t                          count() { return maEntries.size(); }
     383                 :         20 :     DocTemplates_EntryData_Impl*    getEntry( size_t nPos ) { return maEntries[ nPos ]; }
     384                 :            : };
     385                 :            : 
     386                 :            : //-----------------------------------------------------------------------------
     387                 :            : // private SfxDocTplService_Impl
     388                 :            : //-----------------------------------------------------------------------------
     389                 :         14 : void SfxDocTplService_Impl::init_Impl()
     390                 :            : {
     391         [ +  - ]:         14 :     uno::Reference< lang::XMultiServiceFactory > xFactory = ::comphelper::getProcessServiceFactory();
     392         [ +  - ]:         14 :     if ( xFactory.is() )
     393                 :            :     {
     394 [ +  - ][ +  - ]:         14 :         uno::Reference < task::XInteractionHandler > xInteractionHandler( xFactory->createInstance( DEFINE_CONST_UNICODE("com.sun.star.task.InteractionHandler") ), uno::UNO_QUERY );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     395 [ +  - ][ +  - ]:         14 :         maCmdEnv = new TplTaskEnvironment( xInteractionHandler );
                 [ +  - ]
     396                 :            :     }
     397                 :            : 
     398         [ +  - ]:         14 :     ::osl::ClearableMutexGuard aGuard( maMutex );
     399                 :         14 :     sal_Bool bIsInitialized = sal_False;
     400                 :         14 :     sal_Bool bNeedsUpdate   = sal_False;
     401                 :            : 
     402         [ -  + ]:         14 :     if ( !mbLocaleSet )
     403         [ #  # ]:          0 :         getDefaultLocale();
     404                 :            : 
     405                 :            :     // convert locale to string
     406                 :         14 :     OUString aLang = maLocale.Language;
     407                 :         14 :     aLang += OUString( '-' );
     408                 :         14 :     aLang += maLocale.Country;
     409                 :            : 
     410                 :            :     // set maRootContent to the root of the templates hierarchy. Create the
     411                 :            :     // entry if necessary
     412                 :            : 
     413                 :         14 :     maRootURL = OUString( TEMPLATE_ROOT_URL  );
     414                 :         14 :     maRootURL += OUString( '/' );
     415                 :         14 :     maRootURL += aLang;
     416                 :            : 
     417                 :         14 :     ::rtl::OUString aTemplVersPropName( TEMPLATE_VERSION  );
     418                 :         14 :     ::rtl::OUString aTemplVers( TEMPLATE_VERSION_VALUE  );
     419 [ -  + ][ +  - ]:         14 :     if ( Content::create( maRootURL, maCmdEnv, maRootContent ) )
     420                 :            :     {
     421                 :          0 :         uno::Any aValue;
     422                 :          0 :         ::rtl::OUString aPropValue;
     423   [ #  #  #  #  :          0 :         if ( getProperty( maRootContent, aTemplVersPropName, aValue )
           #  # ][ #  # ]
                 [ #  # ]
     424                 :          0 :           && ( aValue >>= aPropValue )
     425                 :          0 :           && aPropValue.equals( aTemplVers ) )
     426                 :            :         {
     427                 :          0 :             bIsInitialized = sal_True;
     428                 :            :         }
     429                 :            :         else
     430         [ #  # ]:          0 :             removeContent( maRootContent );
     431                 :            :     }
     432                 :            : 
     433         [ +  - ]:         14 :     if ( !bIsInitialized )
     434                 :            :     {
     435 [ +  - ][ +  + ]:         30 :         if ( createFolder( maRootURL, sal_True, sal_False, maRootContent )
         [ +  - ][ +  + ]
     436 [ +  - ][ +  - ]:         16 :           && setProperty( maRootContent, aTemplVersPropName, uno::makeAny( aTemplVers ) ) )
         [ +  + ][ #  # ]
     437                 :          2 :             bIsInitialized = sal_True;
     438                 :            : 
     439                 :         14 :         bNeedsUpdate = sal_True;
     440                 :            :     }
     441                 :            : 
     442         [ +  + ]:         14 :     if ( bIsInitialized )
     443                 :            :     {
     444                 :          2 :         OUString aService( SERVICENAME_DOCINFO  );
     445                 :            :         try {
     446                 :            :             mxInfo = uno::Reference< XStandaloneDocumentInfo > (
     447 [ +  - ][ +  - ]:          2 :                 mxFactory->createInstance( aService ), UNO_QUERY );
         [ +  - ][ #  # ]
                 [ +  - ]
     448         [ #  # ]:          0 :         } catch (uno::RuntimeException &) {
     449                 :            :             OSL_FAIL("SfxDocTplService_Impl::init_Impl: "
     450                 :            :                 "cannot create DocumentProperties service");
     451                 :            :         }
     452                 :            : 
     453                 :          2 :         aService = OUString( SERVICENAME_TYPEDETECTION  );
     454 [ +  - ][ +  - ]:          2 :         mxType = uno::Reference< XTypeDetection > ( mxFactory->createInstance( aService ), UNO_QUERY );
         [ +  - ][ +  - ]
     455                 :            : 
     456         [ +  - ]:          2 :         getDirList();
     457         [ +  - ]:          2 :         readFolderList();
     458                 :            : 
     459         [ +  - ]:          2 :         if ( bNeedsUpdate )
     460                 :            :         {
     461         [ +  - ]:          2 :             aGuard.clear();
     462         [ +  - ]:          2 :             SolarMutexClearableGuard aSolarGuard;
     463                 :            : 
     464 [ +  - ][ +  - ]:          2 :             WaitWindow_Impl* pWin = new WaitWindow_Impl();
     465                 :            : 
     466         [ +  - ]:          2 :             aSolarGuard.clear();
     467         [ +  - ]:          2 :             ::osl::ClearableMutexGuard anotherGuard( maMutex );
     468                 :            : 
     469         [ +  - ]:          2 :             update( sal_True );
     470                 :            : 
     471         [ +  - ]:          2 :             anotherGuard.clear();
     472         [ +  - ]:          2 :             SolarMutexGuard aSecondSolarGuard;
     473                 :            : 
     474 [ +  - ][ +  - ]:          2 :             delete pWin;
         [ +  - ][ +  - ]
                 [ +  - ]
     475                 :            :         }
     476 [ #  # ][ #  # ]:          0 :         else if ( needsUpdate() )
     477                 :            :             // the UI should be shown only on the first update
     478         [ #  # ]:          2 :             update( sal_True );
     479                 :            :     }
     480                 :            :     else
     481                 :            :     {
     482                 :            :         SAL_WARN( "sfx2.doc", "init_Impl(): Could not create root" );
     483                 :            :     }
     484                 :            : 
     485         [ +  - ]:         14 :     mbIsInitialized = bIsInitialized;
     486                 :         14 : }
     487                 :            : 
     488                 :            : //-----------------------------------------------------------------------------
     489                 :         14 : void SfxDocTplService_Impl::getDefaultLocale()
     490                 :            : {
     491         [ +  - ]:         14 :     if ( !mbLocaleSet )
     492                 :            :     {
     493         [ +  - ]:         14 :         ::osl::MutexGuard aGuard( maMutex );
     494         [ +  - ]:         14 :         if ( !mbLocaleSet )
     495                 :            :         {
     496         [ +  - ]:         14 :             rtl::OUString aLocale( utl::ConfigManager::getLocale() );
     497         [ +  + ]:         14 :             if ( !aLocale.isEmpty() )
     498                 :            :             {
     499                 :          2 :                 sal_Int32 nPos = aLocale.indexOf( sal_Unicode( '-' ) );
     500         [ +  - ]:          2 :                 if ( nPos != -1 )
     501                 :            :                 {
     502                 :          2 :                     maLocale.Language = aLocale.copy( 0, nPos );
     503                 :          2 :                     nPos = aLocale.indexOf( sal_Unicode( '_' ), nPos + 1 );
     504         [ -  + ]:          2 :                     if ( nPos != -1 )
     505                 :            :                     {
     506                 :            :                         maLocale.Country
     507                 :          0 :                             = aLocale.copy( maLocale.Language.getLength() + 1,
     508                 :          0 :                                             nPos - maLocale.Language.getLength() - 1 );
     509                 :            :                         maLocale.Variant
     510                 :          0 :                             = aLocale.copy( nPos + 1 );
     511                 :            :                     }
     512                 :            :                     else
     513                 :            :                     {
     514                 :            :                         maLocale.Country
     515                 :          2 :                             = aLocale.copy( maLocale.Language.getLength() + 1 );
     516                 :            :                     }
     517                 :            :                 }
     518                 :            : 
     519                 :            :             }
     520                 :            : 
     521                 :         14 :             mbLocaleSet = sal_True;
     522         [ +  - ]:         14 :         }
     523                 :            :     }
     524                 :         14 : }
     525                 :            : 
     526                 :            : // -----------------------------------------------------------------------
     527                 :          2 : void SfxDocTplService_Impl::readFolderList()
     528                 :            : {
     529         [ +  - ]:          2 :     SolarMutexGuard aGuard;
     530                 :            : 
     531 [ +  - ][ +  - ]:          2 :     ResStringArray  aShortNames( SfxResId( TEMPLATE_SHORT_NAMES_ARY ) );
     532 [ +  - ][ +  - ]:          2 :     ResStringArray  aLongNames( SfxResId( TEMPLATE_LONG_NAMES_ARY ) );
     533                 :            : 
     534                 :            :     NamePair_Impl*  pPair;
     535                 :            : 
     536                 :          2 :     sal_uInt16 nCount = (sal_uInt16)( Min( aShortNames.Count(), aLongNames.Count() ) );
     537                 :            : 
     538         [ +  + ]:         24 :     for ( sal_uInt16 i=0; i<nCount; i++ )
     539                 :            :     {
     540         [ +  - ]:         22 :         pPair = new NamePair_Impl;
     541         [ +  - ]:         22 :         pPair->maShortName  = aShortNames.GetString( i );
     542         [ +  - ]:         22 :         pPair->maLongName   = aLongNames.GetString( i );
     543                 :            : 
     544         [ +  - ]:         22 :         maNames.push_back( pPair );
     545 [ +  - ][ +  - ]:          2 :     }
                 [ +  - ]
     546                 :          2 : }
     547                 :            : 
     548                 :            : // -----------------------------------------------------------------------
     549                 :         12 : OUString SfxDocTplService_Impl::getLongName( const OUString& rShortName )
     550                 :            : {
     551                 :         12 :     OUString         aRet;
     552                 :            : 
     553         [ +  + ]:         48 :     for ( size_t i = 0, n = maNames.size(); i < n; ++i )
     554                 :            :     {
     555                 :         46 :         NamePair_Impl* pPair = maNames[ i ];
     556         [ +  + ]:         46 :         if ( pPair->maShortName == rShortName )
     557                 :            :         {
     558                 :         10 :             aRet = pPair->maLongName;
     559                 :         10 :             break;
     560                 :            :         }
     561                 :            :     }
     562                 :            : 
     563         [ +  + ]:         12 :     if ( aRet.isEmpty() )
     564                 :          2 :         aRet = rShortName;
     565                 :            : 
     566                 :         12 :     return aRet;
     567                 :            : }
     568                 :            : 
     569                 :            : //-----------------------------------------------------------------------------
     570                 :          2 : void SfxDocTplService_Impl::getDirList()
     571                 :            : {
     572                 :          2 :     OUString aPropName( PROPERTY_DIRLIST  );
     573                 :          2 :     Any      aValue;
     574                 :            : 
     575                 :            :     // Get the template dir list
     576                 :            :     // TODO/LATER: let use service, register listener
     577         [ +  - ]:          2 :     INetURLObject   aURL;
     578 [ +  - ][ +  - ]:          2 :     String          aDirs = SvtPathOptions().GetTemplatePath();
         [ +  - ][ +  - ]
     579 [ +  - ][ +  - ]:          2 :     sal_uInt16  nCount = comphelper::string::getTokenCount(aDirs, C_DELIM);
     580                 :            : 
     581 [ +  - ][ +  - ]:          2 :     maTemplateDirs = Sequence< OUString >( nCount );
                 [ +  - ]
     582                 :            : 
     583                 :          2 :     uno::Reference< XComponentContext > xCtx;
     584                 :          2 :     uno::Reference< util::XMacroExpander > xExpander;
     585         [ +  - ]:          2 :     uno::Reference< XPropertySet > xPropSet( mxFactory, UNO_QUERY );
     586                 :            :     const rtl::OUString aPrefix(
     587                 :          2 :         "vnd.sun.star.expand:"  );
     588                 :            : 
     589         [ +  - ]:          2 :     if ( xPropSet.is() )
     590                 :            :     {
     591         [ +  - ]:          2 :         xPropSet->getPropertyValue(
     592                 :            :             rtl::OUString(
     593                 :          2 :                 "DefaultContext"  ) )
     594 [ +  - ][ +  - ]:          2 :             >>= xCtx;
     595                 :            :     }
     596                 :            : 
     597         [ +  - ]:          2 :     if ( xCtx.is() )
     598                 :            :     {
     599         [ +  - ]:          2 :         xCtx->getValueByName(
     600                 :          2 :             rtl::OUString( "/singletons/com.sun.star.util.theMacroExpander"  ) )
     601 [ +  - ][ +  - ]:          2 :             >>= xExpander;
     602                 :            : 
     603                 :            :         OSL_ENSURE( xExpander.is(),
     604                 :            :                     "Unable to obtain macro expander singleton!" );
     605                 :            :     }
     606                 :            : 
     607         [ +  + ]:         10 :     for ( sal_uInt16 i=0; i<nCount; i++ )
     608                 :            :     {
     609                 :          8 :         aURL.SetSmartProtocol( INET_PROT_FILE );
     610 [ +  - ][ +  - ]:          8 :         aURL.SetURL( aDirs.GetToken( i, C_DELIM ) );
         [ +  - ][ +  - ]
     611 [ +  - ][ +  - ]:          8 :         maTemplateDirs[i] = aURL.GetMainURL( INetURLObject::NO_DECODE );
     612                 :            : 
     613         [ +  - ]:          8 :         sal_Int32 nIndex = maTemplateDirs[i].indexOf( aPrefix );
     614 [ +  - ][ +  + ]:          8 :         if ( nIndex != -1 && xExpander.is() )
                 [ +  + ]
     615                 :            :         {
     616   [ +  -  +  - ]:          4 :             maTemplateDirs[i] = maTemplateDirs[i].replaceAt(nIndex,
     617                 :            :                                                             aPrefix.getLength(),
     618                 :          6 :                                                             rtl::OUString());
     619 [ +  - ][ +  - ]:          2 :             maTemplateDirs[i] = xExpander->expandMacros( maTemplateDirs[i] );
         [ +  - ][ +  - ]
     620                 :            :         }
     621                 :            :     }
     622                 :            : 
     623         [ +  - ]:          2 :     aValue <<= maTemplateDirs;
     624                 :            : 
     625                 :            :     // Store the template dir list
     626 [ +  - ][ +  - ]:          2 :     setProperty( maRootContent, aPropName, aValue );
                 [ +  - ]
     627                 :          2 : }
     628                 :            : 
     629                 :            : //-----------------------------------------------------------------------------
     630                 :          0 : sal_Bool SfxDocTplService_Impl::needsUpdate()
     631                 :            : {
     632                 :          0 :     OUString aPropName( PROPERTY_NEEDSUPDATE  );
     633                 :          0 :     sal_Bool bHasProperty = sal_False;
     634                 :          0 :     sal_Bool bNeedsUpdate = sal_True;
     635                 :          0 :     Any      aValue;
     636                 :            : 
     637                 :            :     // Get the template dir list
     638         [ #  # ]:          0 :     bHasProperty = getProperty( maRootContent, aPropName, aValue );
     639                 :            : 
     640         [ #  # ]:          0 :     if ( bHasProperty )
     641                 :          0 :         aValue >>= bNeedsUpdate;
     642                 :            : 
     643                 :            :     // the old template component also checks this state, but it is initialized from this component
     644                 :            :     // so if this componend was already updated the old component does not need such an update
     645         [ #  # ]:          0 :     ::svt::TemplateFolderCache aTempCache;
     646         [ #  # ]:          0 :     if ( !bNeedsUpdate )
     647         [ #  # ]:          0 :         bNeedsUpdate = aTempCache.needsUpdate();
     648                 :            : 
     649         [ #  # ]:          0 :     if ( bNeedsUpdate )
     650         [ #  # ]:          0 :         aTempCache.storeState();
     651                 :            : 
     652         [ #  # ]:          0 :     return bNeedsUpdate;
     653                 :            : }
     654                 :            : 
     655                 :            : // -----------------------------------------------------------------------
     656                 :          0 : sal_Bool SfxDocTplService_Impl::setTitleForURL( const OUString& rURL, const OUString& aTitle )
     657                 :            : {
     658                 :          0 :     sal_Bool bResult = sal_False;
     659         [ #  # ]:          0 :     if ( mxInfo.is() )
     660                 :            :     {
     661                 :            :         try
     662                 :            :         {
     663 [ #  # ][ #  # ]:          0 :             mxInfo->loadFromURL( rURL );
     664         [ #  # ]:          0 :             uno::Reference< XPropertySet > xPropSet( mxInfo, UNO_QUERY_THROW );
     665                 :          0 :             OUString aPropName( TITLE  );
     666 [ #  # ][ #  # ]:          0 :             xPropSet->setPropertyValue( aPropName, uno::makeAny( aTitle ) );
                 [ #  # ]
     667 [ #  # ][ #  # ]:          0 :             mxInfo->storeIntoURL( rURL );
     668         [ #  # ]:          0 :             bResult = sal_True;
     669                 :            :         }
     670                 :          0 :         catch ( Exception& )
     671                 :            :         {
     672                 :            :         }
     673                 :            :     }
     674                 :            : 
     675                 :          0 :     return bResult;
     676                 :            : }
     677                 :            : 
     678                 :            : // -----------------------------------------------------------------------
     679                 :         20 : sal_Bool SfxDocTplService_Impl::getTitleFromURL( const OUString& rURL, OUString& aTitle, OUString& aType, sal_Bool& bDocHasTitle )
     680                 :            : {
     681                 :         20 :     bDocHasTitle = sal_False;
     682                 :            : 
     683         [ +  - ]:         20 :     if ( mxInfo.is() )
     684                 :            :     {
     685                 :            :         try
     686                 :            :         {
     687 [ +  - ][ +  - ]:         20 :             mxInfo->loadFromURL( rURL );
     688                 :            :         }
     689                 :          0 :         catch ( Exception& )
     690                 :            :         {
     691                 :            :             // the document is not a StarOffice document
     692                 :          0 :             return sal_False;
     693                 :            :         }
     694                 :            : 
     695                 :            :         try
     696                 :            :         {
     697         [ +  - ]:         20 :             uno::Reference< XPropertySet > aPropSet( mxInfo, UNO_QUERY );
     698         [ +  - ]:         20 :             if ( aPropSet.is() )
     699                 :            :             {
     700                 :         20 :                 OUString aPropName( TITLE  );
     701 [ +  - ][ +  - ]:         20 :                 Any aValue = aPropSet->getPropertyValue( aPropName );
     702                 :         20 :                 aValue >>= aTitle;
     703                 :            : 
     704                 :         20 :                 aPropName = OUString( "MIMEType"  );
     705 [ +  - ][ +  - ]:         20 :                 aValue = aPropSet->getPropertyValue( aPropName );
     706                 :         20 :                 aValue >>= aType;
     707      [ #  #  # ]:         20 :             }
     708                 :            :         }
     709                 :          0 :         catch ( UnknownPropertyException& ) {}
     710                 :          0 :         catch ( Exception& ) {}
     711                 :            :     }
     712                 :            : 
     713 [ +  - ][ +  - ]:         20 :     if ( aType.isEmpty() && mxType.is() )
                 [ +  - ]
     714                 :            :     {
     715 [ +  - ][ +  - ]:         20 :         ::rtl::OUString aDocType = mxType->queryTypeByURL( rURL );
     716         [ +  - ]:         20 :         if ( !aDocType.isEmpty() )
     717                 :            :             try
     718                 :            :             {
     719         [ +  - ]:         20 :                 uno::Reference< container::XNameAccess > xTypeDetection( mxType, uno::UNO_QUERY_THROW );
     720 [ +  - ][ +  - ]:         20 :                 SequenceAsHashMap aTypeProps( xTypeDetection->getByName( aDocType ) );
                 [ +  - ]
     721                 :            :                 aType = aTypeProps.getUnpackedValueOrDefault(
     722                 :            :                             ::rtl::OUString("MediaType"),
     723 [ +  - ][ #  # ]:         20 :                             ::rtl::OUString() );
                 [ +  - ]
     724                 :            :             }
     725         [ #  # ]:          0 :             catch( uno::Exception& )
     726                 :         20 :             {}
     727                 :            :     }
     728                 :            : 
     729         [ -  + ]:         20 :     if ( aTitle.isEmpty() )
     730                 :            :     {
     731         [ #  # ]:          0 :         INetURLObject aURL( rURL );
     732         [ #  # ]:          0 :         aURL.CutExtension();
     733                 :            :         aTitle = aURL.getName( INetURLObject::LAST_SEGMENT, true,
     734 [ #  # ][ #  # ]:          0 :                                INetURLObject::DECODE_WITH_CHARSET );
     735                 :            :     }
     736                 :            :     else
     737                 :         20 :         bDocHasTitle = sal_True;
     738                 :            : 
     739         [ #  # ]:         20 :     return sal_True;
     740                 :            : }
     741                 :            : 
     742                 :            : // -----------------------------------------------------------------------
     743                 :         20 : sal_Bool SfxDocTplService_Impl::addEntry( Content& rParentFolder,
     744                 :            :                                           const OUString& rTitle,
     745                 :            :                                           const OUString& rTargetURL,
     746                 :            :                                           const OUString& rType )
     747                 :            : {
     748                 :         20 :     sal_Bool bAddedEntry = sal_False;
     749                 :            : 
     750 [ +  - ][ +  - ]:         20 :     INetURLObject aLinkObj( rParentFolder.getURL() );
     751                 :            :     aLinkObj.insertName( rTitle, false,
     752                 :            :                       INetURLObject::LAST_SEGMENT, true,
     753         [ +  - ]:         20 :                       INetURLObject::ENCODE_ALL );
     754         [ +  - ]:         20 :     OUString aLinkURL = aLinkObj.GetMainURL( INetURLObject::NO_DECODE );
     755                 :            : 
     756         [ +  - ]:         20 :     Content aLink;
     757                 :            : 
     758 [ +  - ][ +  - ]:         20 :     if ( ! Content::create( aLinkURL, maCmdEnv, aLink ) )
     759                 :            :     {
     760         [ +  - ]:         20 :         Sequence< OUString > aNames(3);
     761         [ +  - ]:         20 :         aNames[0] = OUString( TITLE  );
     762         [ +  - ]:         20 :         aNames[1] = OUString( IS_FOLDER  );
     763         [ +  - ]:         20 :         aNames[2] = OUString( TARGET_URL  );
     764                 :            : 
     765         [ +  - ]:         20 :         Sequence< Any > aValues(3);
     766 [ +  - ][ +  - ]:         20 :         aValues[0] = makeAny( rTitle );
     767 [ +  - ][ +  - ]:         20 :         aValues[1] = makeAny( sal_Bool( sal_False ) );
     768 [ +  - ][ +  - ]:         20 :         aValues[2] = makeAny( rTargetURL );
     769                 :            : 
     770                 :         20 :         OUString aType( TYPE_LINK  );
     771                 :         20 :         OUString aAdditionalProp( PROPERTY_TYPE  );
     772                 :            : 
     773                 :            :         try
     774                 :            :         {
     775         [ +  - ]:         20 :             rParentFolder.insertNewContent( aType, aNames, aValues, aLink );
     776 [ +  - ][ +  - ]:         20 :             setProperty( aLink, aAdditionalProp, makeAny( rType ) );
                 [ #  # ]
     777                 :         20 :             bAddedEntry = sal_True;
     778                 :            :         }
     779         [ #  # ]:          0 :         catch( Exception& )
     780 [ +  - ][ +  - ]:         20 :         {}
     781                 :            :     }
     782 [ +  - ][ +  - ]:         20 :     return bAddedEntry;
     783                 :            : }
     784                 :            : 
     785                 :            : // -----------------------------------------------------------------------
     786                 :         36 : sal_Bool SfxDocTplService_Impl::createFolder( const OUString& rNewFolderURL,
     787                 :            :                                               sal_Bool  bCreateParent,
     788                 :            :                                               sal_Bool  bFsysFolder,
     789                 :            :                                               Content   &rNewFolder )
     790                 :            : {
     791         [ +  - ]:         36 :     Content         aParent;
     792                 :         36 :     sal_Bool        bCreatedFolder = sal_False;
     793         [ +  - ]:         36 :     INetURLObject   aParentURL( rNewFolderURL );
     794                 :            :     OUString        aFolderName = aParentURL.getName( INetURLObject::LAST_SEGMENT, true,
     795         [ +  - ]:         36 :                                                       INetURLObject::DECODE_WITH_CHARSET );
     796                 :            : 
     797                 :            :     // compute the parent folder url from the new folder url
     798                 :            :     // and remove the final slash, because Content::create doesn't
     799                 :            :     // like it
     800         [ +  - ]:         36 :     aParentURL.removeSegment();
     801 [ +  - ][ +  + ]:         36 :     if ( aParentURL.getSegmentCount() >= 1 )
     802         [ +  - ]:         22 :         aParentURL.removeFinalSlash();
     803                 :            : 
     804                 :            :     // if the parent exists, we can continue with the creation of the
     805                 :            :     // new folder, we have to create the parent otherwise ( as long as
     806                 :            :     // bCreateParent is set to true )
     807 [ +  - ][ +  - ]:         36 :     if ( Content::create( aParentURL.GetMainURL( INetURLObject::NO_DECODE ), maCmdEnv, aParent ) )
                 [ +  + ]
     808                 :            :     {
     809                 :            :         try
     810                 :            :         {
     811         [ +  - ]:         10 :             Sequence< OUString > aNames(2);
     812         [ +  - ]:         10 :             aNames[0] = OUString( TITLE  );
     813         [ +  - ]:         10 :             aNames[1] = OUString( IS_FOLDER  );
     814                 :            : 
     815         [ +  - ]:         10 :             Sequence< Any > aValues(2);
     816 [ +  - ][ +  - ]:         10 :             aValues[0] = makeAny( aFolderName );
     817 [ +  - ][ +  - ]:         10 :             aValues[1] = makeAny( sal_Bool( sal_True ) );
     818                 :            : 
     819                 :         10 :             OUString aType;
     820                 :            : 
     821         [ -  + ]:         10 :             if ( bFsysFolder )
     822                 :          0 :                 aType = OUString( TYPE_FSYS_FOLDER  );
     823                 :            :             else
     824                 :         10 :                 aType = OUString( TYPE_FOLDER  );
     825                 :            : 
     826         [ +  - ]:         10 :             aParent.insertNewContent( aType, aNames, aValues, rNewFolder );
     827 [ +  - ][ +  - ]:         10 :             bCreatedFolder = sal_True;
              [ #  #  # ]
     828                 :            :         }
     829         [ #  # ]:          0 :         catch( RuntimeException& )
     830                 :            :         {
     831                 :            :             SAL_WARN( "sfx2.doc", "createFolder(): got runtime exception" );
     832                 :            :         }
     833         [ #  # ]:          0 :         catch( Exception& )
     834                 :            :         {
     835                 :            :             SAL_WARN( "sfx2.doc", "createFolder(): Could not create new folder" );
     836                 :            :         }
     837                 :            :     }
     838         [ +  - ]:         26 :     else if ( bCreateParent )
     839                 :            :     {
     840                 :            :         // if the parent doesn't exists and bCreateParent is set to true,
     841                 :            :         // we try to create the parent and if this was successful, we
     842                 :            :         // try to create the new folder again ( but this time, we set
     843                 :            :         // bCreateParent to false to avoid endless recusions )
     844 [ +  - ][ +  + ]:         66 :         if ( ( aParentURL.getSegmentCount() >= 1 ) &&
         [ +  + ][ +  + ]
     845 [ +  - ][ +  - ]:         40 :                createFolder( aParentURL.GetMainURL( INetURLObject::NO_DECODE ), bCreateParent, bFsysFolder, aParent ) )
         [ +  + ][ #  # ]
     846                 :            :         {
     847         [ +  - ]:          2 :             bCreatedFolder = createFolder( rNewFolderURL, sal_False, bFsysFolder, rNewFolder );
     848                 :            :         }
     849                 :            :     }
     850                 :            : 
     851 [ +  - ][ +  - ]:         36 :     return bCreatedFolder;
     852                 :            : }
     853                 :            : 
     854                 :            : // -----------------------------------------------------------------------
     855                 :          0 : sal_Bool SfxDocTplService_Impl::CreateNewUniqueFolderWithPrefix( const ::rtl::OUString& aPath,
     856                 :            :                                                                 const ::rtl::OUString& aPrefix,
     857                 :            :                                                                 ::rtl::OUString& aNewFolderName,
     858                 :            :                                                                 ::rtl::OUString& aNewFolderURL,
     859                 :            :                                                                 Content& aNewFolder )
     860                 :            : {
     861                 :          0 :     sal_Bool bCreated = sal_False;
     862         [ #  # ]:          0 :     INetURLObject aDirPath( aPath );
     863                 :            : 
     864         [ #  # ]:          0 :     Content aParent;
     865                 :          0 :     uno::Reference< XCommandEnvironment > aQuietEnv;
     866 [ #  # ][ #  # ]:          0 :        if ( Content::create( aDirPath.GetMainURL( INetURLObject::NO_DECODE ), aQuietEnv, aParent ) )
                 [ #  # ]
     867                 :            :        {
     868         [ #  # ]:          0 :         for ( sal_Int32 nInd = 0; nInd < 32000; nInd++ )
     869                 :            :         {
     870                 :          0 :             ::rtl::OUString aTryName = aPrefix;
     871         [ #  # ]:          0 :             if ( nInd )
     872                 :          0 :                 aTryName += ::rtl::OUString::valueOf( nInd );
     873                 :            : 
     874                 :            :             try
     875                 :            :             {
     876         [ #  # ]:          0 :                 Sequence< OUString > aNames(2);
     877         [ #  # ]:          0 :                 aNames[0] = OUString( TITLE  );
     878         [ #  # ]:          0 :                 aNames[1] = OUString( IS_FOLDER  );
     879                 :            : 
     880         [ #  # ]:          0 :                 Sequence< Any > aValues(2);
     881 [ #  # ][ #  # ]:          0 :                 aValues[0] = makeAny( aTryName );
     882 [ #  # ][ #  # ]:          0 :                 aValues[1] = makeAny( sal_Bool( sal_True ) );
     883                 :            : 
     884                 :          0 :                 OUString aType( TYPE_FSYS_FOLDER  );
     885                 :            : 
     886 [ #  # ][ #  # ]:          0 :                 bCreated = aParent.insertNewContent( aType, aNames, aValues, aNewFolder );
                 [ #  # ]
     887                 :            :             }
     888         [ #  # ]:          0 :             catch( ucb::NameClashException& )
     889                 :            :             {
     890                 :            :                 // if there is already an element, retry
     891                 :            :             }
     892   [ #  #  #  #  :          0 :             catch( Exception& )
                #  #  # ]
     893                 :            :             {
     894         [ #  # ]:          0 :                 INetURLObject aObjPath( aDirPath );
     895                 :            :                 aObjPath.insertName( aTryName, false,
     896                 :            :                       INetURLObject::LAST_SEGMENT, true,
     897         [ #  # ]:          0 :                       INetURLObject::ENCODE_ALL );
     898                 :            :                 // if there is already an element, retry
     899                 :            :                 // if there was another error, do not try any more
     900   [ #  #  #  #  :          0 :                 if ( !::utl::UCBContentHelper::Exists( aObjPath.GetMainURL( INetURLObject::NO_DECODE ) ) )
                   #  # ]
     901   [ #  #  #  # ]:          0 :                     break;
     902                 :            :             }
     903                 :            : 
     904         [ #  # ]:          0 :             if ( bCreated )
     905                 :            :             {
     906                 :          0 :                 aNewFolderName = aTryName;
     907 [ #  # ][ #  # ]:          0 :                 aNewFolderURL = aNewFolder.get()->getIdentifier()->getContentIdentifier();
         [ #  # ][ #  # ]
                 [ #  # ]
     908                 :            :                 break;
     909                 :            :             }
     910         [ #  # ]:          0 :         }
     911                 :            :     }
     912                 :            : 
     913 [ #  # ][ #  # ]:          0 :     return bCreated;
     914                 :            : }
     915                 :            : 
     916                 :            : // -----------------------------------------------------------------------
     917                 :          0 : ::rtl::OUString SfxDocTplService_Impl::CreateNewUniqueFileWithPrefix( const ::rtl::OUString& aPath,
     918                 :            :                                                                         const ::rtl::OUString& aPrefix,
     919                 :            :                                                                         const ::rtl::OUString& aExt )
     920                 :            : {
     921                 :          0 :     ::rtl::OUString aNewFileURL;
     922         [ #  # ]:          0 :     INetURLObject aDirPath( aPath );
     923                 :            : 
     924         [ #  # ]:          0 :        Content aParent;
     925                 :            : 
     926                 :          0 :     uno::Reference< XCommandEnvironment > aQuietEnv;
     927 [ #  # ][ #  # ]:          0 :     if ( Content::create( aDirPath.GetMainURL( INetURLObject::NO_DECODE ), aQuietEnv, aParent ) )
                 [ #  # ]
     928                 :            :        {
     929         [ #  # ]:          0 :         for ( sal_Int32 nInd = 0; nInd < 32000; nInd++ )
     930                 :            :         {
     931         [ #  # ]:          0 :             Content aNewFile;
     932                 :          0 :             sal_Bool bCreated = sal_False;
     933                 :          0 :             ::rtl::OUString aTryName = aPrefix;
     934         [ #  # ]:          0 :             if ( nInd )
     935                 :          0 :                 aTryName += ::rtl::OUString::valueOf( nInd );
     936         [ #  # ]:          0 :             if ( aExt.toChar() != '.' )
     937                 :          0 :                 aTryName += ::rtl::OUString( "."  );
     938                 :          0 :             aTryName += aExt;
     939                 :            : 
     940                 :            :             try
     941                 :            :             {
     942         [ #  # ]:          0 :                 Sequence< OUString > aNames(2);
     943         [ #  # ]:          0 :                 aNames[0] = OUString( TITLE  );
     944         [ #  # ]:          0 :                 aNames[1] = OUString( IS_DOCUMENT  );
     945                 :            : 
     946         [ #  # ]:          0 :                 Sequence< Any > aValues(2);
     947 [ #  # ][ #  # ]:          0 :                 aValues[0] = makeAny( aTryName );
     948 [ #  # ][ #  # ]:          0 :                 aValues[1] = makeAny( sal_Bool( sal_True ) );
     949                 :            : 
     950                 :          0 :                 OUString aType( TYPE_FSYS_FILE  );
     951                 :            : 
     952 [ #  # ][ #  # ]:          0 :                 bCreated = aParent.insertNewContent( aType, aNames, aValues, aNewFile );
                 [ #  # ]
     953                 :            :             }
     954         [ #  # ]:          0 :             catch( ucb::NameClashException& )
     955                 :            :             {
     956                 :            :                 // if there is already an element, retry
     957                 :            :             }
     958   [ #  #  #  #  :          0 :             catch( Exception& )
                #  #  # ]
     959                 :            :             {
     960         [ #  # ]:          0 :                 INetURLObject aObjPath( aPath );
     961                 :            :                 aObjPath.insertName( aTryName, false,
     962                 :            :                       INetURLObject::LAST_SEGMENT, true,
     963         [ #  # ]:          0 :                       INetURLObject::ENCODE_ALL );
     964                 :            :                 // if there is already an element, retry
     965                 :            :                 // if there was another error, do not try any more
     966   [ #  #  #  #  :          0 :                 if ( !::utl::UCBContentHelper::Exists( aObjPath.GetMainURL( INetURLObject::NO_DECODE ) ) )
                   #  # ]
     967   [ #  #  #  # ]:          0 :                     break;
     968                 :            :             }
     969                 :            : 
     970         [ #  # ]:          0 :             if ( bCreated )
     971                 :            :             {
     972 [ #  # ][ #  # ]:          0 :                 aNewFileURL = aNewFile.get()->getIdentifier()->getContentIdentifier();
         [ #  # ][ #  # ]
                 [ #  # ]
     973                 :            :                 break;
     974                 :            :             }
     975 [ #  # ][ #  # ]:          0 :         }
                 [ #  # ]
     976                 :            :     }
     977                 :            : 
     978 [ #  # ][ #  # ]:          0 :     return aNewFileURL;
     979                 :            : }
     980                 :            : 
     981                 :            : // -----------------------------------------------------------------------
     982                 :          0 : sal_Bool SfxDocTplService_Impl::removeContent( Content& rContent )
     983                 :            : {
     984                 :          0 :     sal_Bool bRemoved = sal_False;
     985                 :            :     try
     986                 :            :     {
     987                 :          0 :         OUString aCmd( COMMAND_DELETE  );
     988         [ #  # ]:          0 :         Any aArg = makeAny( sal_Bool( sal_True ) );
     989                 :            : 
     990         [ #  # ]:          0 :         rContent.executeCommand( aCmd, aArg );
     991      [ #  #  # ]:          0 :         bRemoved = sal_True;
     992                 :            :     }
     993                 :          0 :     catch ( RuntimeException& ) {}
     994                 :          0 :     catch ( Exception& ) {}
     995                 :            : 
     996                 :          0 :     return bRemoved;
     997                 :            : }
     998                 :            : 
     999                 :            : // -----------------------------------------------------------------------
    1000                 :          0 : sal_Bool SfxDocTplService_Impl::removeContent( const OUString& rContentURL )
    1001                 :            : {
    1002         [ #  # ]:          0 :     Content aContent;
    1003                 :            : 
    1004 [ #  # ][ #  # ]:          0 :     if ( Content::create( rContentURL, maCmdEnv, aContent ) )
    1005         [ #  # ]:          0 :         return removeContent( aContent );
    1006                 :            :     else
    1007         [ #  # ]:          0 :         return sal_False;
    1008                 :            : }
    1009                 :            : 
    1010                 :            : // -----------------------------------------------------------------------
    1011                 :         34 : sal_Bool SfxDocTplService_Impl::setProperty( Content& rContent,
    1012                 :            :                                              const OUString& rPropName,
    1013                 :            :                                              const Any& rPropValue )
    1014                 :            : {
    1015                 :         34 :     sal_Bool bPropertySet = sal_False;
    1016                 :            : 
    1017                 :            :     // Store the property
    1018                 :            :     try
    1019                 :            :     {
    1020                 :         34 :         Any aPropValue( rPropValue );
    1021         [ +  - ]:         34 :         uno::Reference< XPropertySetInfo > aPropInfo = rContent.getProperties();
    1022                 :            : 
    1023                 :            :         // check, whether or not the property exists, create it, when not
    1024 [ +  - ][ +  - ]:         34 :         if ( !aPropInfo.is() || !aPropInfo->hasPropertyByName( rPropName ) )
         [ +  - ][ +  + ]
                 [ +  + ]
    1025                 :            :         {
    1026 [ +  - ][ +  - ]:         32 :             uno::Reference< XPropertyContainer > xProperties( rContent.get(), UNO_QUERY );
           [ #  #  #  # ]
    1027         [ +  - ]:         32 :             if ( xProperties.is() )
    1028                 :            :             {
    1029                 :            :                 try
    1030                 :            :                 {
    1031 [ +  - ][ +  - ]:         32 :                     xProperties->addProperty( rPropName, PropertyAttribute::MAYBEVOID, rPropValue );
    1032                 :            :                 }
    1033         [ #  # ]:          0 :                 catch( PropertyExistException& ) {}
    1034         [ #  # ]:          0 :                 catch( IllegalTypeException& ) {
    1035                 :            :                     SAL_WARN( "sfx2.doc", "IllegalTypeException" );
    1036                 :            :                 }
    1037         [ #  # ]:          0 :                 catch( IllegalArgumentException& ) {
    1038                 :            :                     SAL_WARN( "sfx2.doc", "IllegalArgumentException" );
    1039                 :            :                 }
    1040                 :         32 :             }
    1041                 :            :         }
    1042                 :            : 
    1043                 :            :         // To ensure a reloctable office installation, the path to the
    1044                 :            :         // office installtion directory must never be stored directly.
    1045 [ +  - ][ +  + ]:         34 :         if ( SfxURLRelocator_Impl::propertyCanContainOfficeDir( rPropName ) )
    1046                 :            :         {
    1047                 :          8 :             OUString aValue;
    1048         [ +  + ]:          8 :             if ( rPropValue >>= aValue )
    1049                 :            :             {
    1050         [ +  - ]:          6 :                 maRelocator.makeRelocatableURL( aValue );
    1051         [ +  - ]:          6 :                 aPropValue = makeAny( aValue );
    1052                 :            :             }
    1053                 :            :             else
    1054                 :            :             {
    1055         [ +  - ]:          2 :                 Sequence< OUString > aValues;
    1056 [ +  - ][ +  - ]:          2 :                 if ( rPropValue >>= aValues )
    1057                 :            :                 {
    1058         [ +  + ]:         10 :                     for ( sal_Int32 n = 0; n < aValues.getLength(); n++ )
    1059                 :            :                     {
    1060 [ +  - ][ +  - ]:          8 :                         maRelocator.makeRelocatableURL( aValues[ n ] );
    1061                 :            :                     }
    1062         [ +  - ]:          2 :                     aPropValue = makeAny( aValues );
    1063                 :            :                 }
    1064                 :            :                 else
    1065                 :            :                 {
    1066                 :            :                     OSL_FAIL( "Unsupported property value type" );
    1067         [ +  - ]:          2 :                 }
    1068                 :          8 :             }
    1069                 :            :         }
    1070                 :            : 
    1071                 :            :         // now set the property
    1072                 :            : 
    1073         [ +  - ]:         34 :         rContent.setPropertyValue( rPropName, aPropValue );
    1074      [ #  #  # ]:         34 :         bPropertySet = sal_True;
    1075                 :            :     }
    1076                 :          0 :     catch ( RuntimeException& ) {}
    1077                 :          0 :     catch ( Exception& ) {}
    1078                 :            : 
    1079                 :         34 :     return bPropertySet;
    1080                 :            : }
    1081                 :            : 
    1082                 :            : // -----------------------------------------------------------------------
    1083                 :          0 : sal_Bool SfxDocTplService_Impl::getProperty( Content& rContent,
    1084                 :            :                                              const OUString& rPropName,
    1085                 :            :                                              Any& rPropValue )
    1086                 :            : {
    1087                 :          0 :     sal_Bool bGotProperty = sal_False;
    1088                 :            : 
    1089                 :            :     // Get the property
    1090                 :            :     try
    1091                 :            :     {
    1092         [ #  # ]:          0 :         uno::Reference< XPropertySetInfo > aPropInfo = rContent.getProperties();
    1093                 :            : 
    1094                 :            :         // check, whether or not the property exists
    1095 [ #  # ][ #  # ]:          0 :         if ( !aPropInfo.is() || !aPropInfo->hasPropertyByName( rPropName ) )
         [ #  # ][ #  # ]
                 [ #  # ]
    1096                 :            :         {
    1097                 :          0 :             return sal_False;
    1098                 :            :         }
    1099                 :            : 
    1100                 :            :         // now get the property
    1101                 :            : 
    1102         [ #  # ]:          0 :         rPropValue = rContent.getPropertyValue( rPropName );
    1103                 :            : 
    1104                 :            :         // To ensure a reloctable office installation, the path to the
    1105                 :            :         // office installtion directory must never be stored directly.
    1106 [ #  # ][ #  # ]:          0 :         if ( SfxURLRelocator_Impl::propertyCanContainOfficeDir( rPropName ) )
    1107                 :            :         {
    1108                 :          0 :             OUString aValue;
    1109         [ #  # ]:          0 :             if ( rPropValue >>= aValue )
    1110                 :            :             {
    1111         [ #  # ]:          0 :                 maRelocator.makeAbsoluteURL( aValue );
    1112         [ #  # ]:          0 :                 rPropValue = makeAny( aValue );
    1113                 :            :             }
    1114                 :            :             else
    1115                 :            :             {
    1116         [ #  # ]:          0 :                 Sequence< OUString > aValues;
    1117 [ #  # ][ #  # ]:          0 :                 if ( rPropValue >>= aValues )
    1118                 :            :                 {
    1119         [ #  # ]:          0 :                     for ( sal_Int32 n = 0; n < aValues.getLength(); n++ )
    1120                 :            :                     {
    1121 [ #  # ][ #  # ]:          0 :                         maRelocator.makeAbsoluteURL( aValues[ n ] );
    1122                 :            :                     }
    1123         [ #  # ]:          0 :                     rPropValue = makeAny( aValues );
    1124                 :            :                 }
    1125                 :            :                 else
    1126                 :            :                 {
    1127                 :            :                     OSL_FAIL( "Unsupported property value type" );
    1128         [ #  # ]:          0 :                 }
    1129                 :          0 :             }
    1130                 :            :         }
    1131                 :            : 
    1132         [ #  # ]:          0 :         bGotProperty = sal_True;
              [ #  #  # ]
    1133                 :            :     }
    1134                 :          0 :     catch ( RuntimeException& ) {}
    1135                 :          0 :     catch ( Exception& ) {}
    1136                 :            : 
    1137                 :          0 :     return bGotProperty;
    1138                 :            : }
    1139                 :            : 
    1140                 :            : // -----------------------------------------------------------------------
    1141                 :            : // static
    1142                 :         34 : bool SfxURLRelocator_Impl::propertyCanContainOfficeDir(
    1143                 :            :                                         const rtl::OUString & rPropName )
    1144                 :            : {
    1145                 :            :     // Note: TargetURL is handled by UCB itself (because it is a property
    1146                 :            :     //       with a predefined semantic). Additional Core properties introduced
    1147                 :            :     //       be a client app must be handled by the client app itself, because
    1148                 :            :     //       the UCB does not know the semantics of those properties.
    1149 [ +  + ][ +  + ]:         34 :     return ( rPropName == TARGET_DIR_URL || rPropName == PROPERTY_DIRLIST );
    1150                 :            : }
    1151                 :            : 
    1152                 :            : //-----------------------------------------------------------------------------
    1153                 :            : // public SfxDocTplService_Impl
    1154                 :            : //-----------------------------------------------------------------------------
    1155                 :            : 
    1156                 :         14 : SfxDocTplService_Impl::SfxDocTplService_Impl( uno::Reference< XMultiServiceFactory > xFactory )
    1157 [ +  - ][ +  - ]:         14 : : maRelocator( xFactory )
         [ +  - ][ +  - ]
                 [ +  - ]
    1158                 :            : {
    1159         [ +  - ]:         14 :     mxFactory       = xFactory;
    1160                 :         14 :     mpUpdater       = NULL;
    1161                 :         14 :     mbIsInitialized = sal_False;
    1162                 :         14 :     mbLocaleSet     = sal_False;
    1163                 :         14 : }
    1164                 :            : 
    1165                 :            : //-----------------------------------------------------------------------------
    1166 [ +  - ][ +  - ]:         11 : SfxDocTplService_Impl::~SfxDocTplService_Impl()
         [ +  - ][ +  - ]
    1167                 :            : {
    1168         [ +  - ]:         11 :     ::osl::MutexGuard aGuard( maMutex );
    1169                 :            : 
    1170         [ -  + ]:         11 :     if ( mpUpdater )
    1171                 :            :     {
    1172         [ #  # ]:          0 :         mpUpdater->terminate();
    1173         [ #  # ]:          0 :         mpUpdater->join();
    1174 [ #  # ][ #  # ]:          0 :         delete mpUpdater;
    1175                 :            :     }
    1176                 :            : 
    1177         [ +  + ]:         33 :     for ( size_t i = 0, n = maNames.size(); i < n; ++i )
    1178         [ +  - ]:         22 :         delete maNames[ i ];
    1179         [ +  - ]:         11 :     maNames.clear();
    1180                 :         11 : }
    1181                 :            : 
    1182                 :            : //-----------------------------------------------------------------------------
    1183                 :         14 : Locale SfxDocTplService_Impl::getLocale()
    1184                 :            : {
    1185         [ +  - ]:         14 :     ::osl::MutexGuard aGuard( maMutex );
    1186                 :            : 
    1187         [ +  - ]:         14 :     if ( !mbLocaleSet )
    1188         [ +  - ]:         14 :         getDefaultLocale();
    1189                 :            : 
    1190         [ +  - ]:         14 :     return maLocale;
    1191                 :            : }
    1192                 :            : 
    1193                 :            : //-----------------------------------------------------------------------------
    1194                 :          0 : void SfxDocTplService_Impl::setLocale( const Locale &rLocale )
    1195                 :            : {
    1196         [ #  # ]:          0 :     ::osl::MutexGuard aGuard( maMutex );
    1197                 :            : 
    1198   [ #  #  #  #  :          0 :     if ( mbLocaleSet &&
           #  # ][ #  # ]
    1199                 :          0 :          ( maLocale.Language != rLocale.Language ) &&
    1200                 :          0 :          ( maLocale.Country != rLocale.Country ) )
    1201                 :          0 :         mbIsInitialized = sal_False;
    1202                 :            : 
    1203                 :          0 :     maLocale    = rLocale;
    1204         [ #  # ]:          0 :     mbLocaleSet = sal_True;
    1205                 :          0 : }
    1206                 :            : 
    1207                 :            : //-----------------------------------------------------------------------------
    1208                 :          2 : void SfxDocTplService_Impl::update( sal_Bool bUpdateNow )
    1209                 :            : {
    1210         [ +  - ]:          2 :     ::osl::MutexGuard aGuard( maMutex );
    1211                 :            : 
    1212         [ +  - ]:          2 :     if ( bUpdateNow )
    1213         [ +  - ]:          2 :         doUpdate();
    1214                 :            :     else
    1215                 :            :     {
    1216         [ #  # ]:          0 :         mpUpdater = new Updater_Impl( this );
    1217         [ #  # ]:          0 :         mpUpdater->create();
    1218         [ +  - ]:          2 :     }
    1219                 :          2 : }
    1220                 :            : 
    1221                 :            : //-----------------------------------------------------------------------------
    1222                 :          2 : void SfxDocTplService_Impl::doUpdate()
    1223                 :            : {
    1224         [ +  - ]:          2 :     ::osl::MutexGuard aGuard( maMutex );
    1225                 :            : 
    1226                 :          2 :     OUString aPropName( PROPERTY_NEEDSUPDATE  );
    1227                 :          2 :     Any      aValue;
    1228                 :            : 
    1229         [ +  - ]:          2 :     aValue <<= sal_True;
    1230         [ +  - ]:          2 :     setProperty( maRootContent, aPropName, aValue );
    1231                 :            : 
    1232         [ +  - ]:          2 :     GroupList_Impl  aGroupList;
    1233                 :            : 
    1234                 :            :     // get the entries from the hierarchy
    1235         [ +  - ]:          2 :     createFromContent( aGroupList, maRootContent, sal_True );
    1236                 :            : 
    1237                 :            :     // get the entries from the template directories
    1238                 :          2 :     sal_Int32   nCountDir = maTemplateDirs.getLength();
    1239         [ +  - ]:          2 :     OUString*   pDirs = maTemplateDirs.getArray();
    1240         [ +  - ]:          2 :     Content     aDirContent;
    1241                 :            : 
    1242                 :            :     // the last directory in the list must be writable
    1243                 :          2 :     sal_Bool bWriteableDirectory = sal_True;
    1244                 :            : 
    1245                 :            :     // the target folder might not exist, for this reason no interaction handler should be used
    1246                 :          2 :     uno::Reference< XCommandEnvironment > aQuietEnv;
    1247                 :            : 
    1248         [ +  + ]:         10 :     while ( nCountDir )
    1249                 :            :     {
    1250                 :          8 :         nCountDir--;
    1251 [ +  - ][ +  - ]:          8 :         if ( Content::create( pDirs[ nCountDir ], aQuietEnv, aDirContent ) )
    1252                 :            :         {
    1253         [ +  - ]:          8 :             createFromContent( aGroupList, aDirContent, sal_False, bWriteableDirectory );
    1254                 :            :         }
    1255                 :            : 
    1256                 :          8 :         bWriteableDirectory = sal_False;
    1257                 :            :     }
    1258                 :            : 
    1259                 :            :     // now check the list
    1260         [ +  + ]:          8 :     for( size_t j = 0, n = aGroupList.size(); j < n; ++j )
    1261                 :            :     {
    1262                 :          6 :         GroupData_Impl *pGroup = aGroupList[ j ];
    1263         [ +  - ]:          6 :         if ( pGroup->getInUse() )
    1264                 :            :         {
    1265         [ -  + ]:          6 :             if ( pGroup->getInHierarchy() )
    1266                 :            :             {
    1267         [ #  # ]:          0 :                 Content aGroup;
    1268 [ #  # ][ #  # ]:          0 :                 if ( Content::create( pGroup->getHierarchyURL(), maCmdEnv, aGroup ) )
    1269                 :            :                     setProperty( aGroup,
    1270                 :            :                                  OUString( TARGET_DIR_URL  ),
    1271 [ #  # ][ #  # ]:          0 :                                  makeAny( pGroup->getTargetURL() ) );
    1272                 :            : 
    1273                 :          0 :                 size_t nCount = pGroup->count();
    1274         [ #  # ]:          0 :                 for ( size_t i=0; i<nCount; i++ )
    1275                 :            :                 {
    1276         [ #  # ]:          0 :                     DocTemplates_EntryData_Impl *pData = pGroup->getEntry( i );
    1277         [ #  # ]:          0 :                     if ( ! pData->getInUse() )
    1278                 :            :                     {
    1279         [ #  # ]:          0 :                         if ( pData->getInHierarchy() )
    1280         [ #  # ]:          0 :                             removeFromHierarchy( pData ); // delete entry in hierarchy
    1281                 :            :                         else
    1282         [ #  # ]:          0 :                             addToHierarchy( pGroup, pData ); // add entry to hierarchy
    1283                 :            :                     }
    1284   [ #  #  #  # ]:          0 :                     else if ( pData->getUpdateType() ||
                 [ #  # ]
    1285                 :          0 :                               pData->getUpdateLink() )
    1286                 :            :                     {
    1287         [ #  # ]:          0 :                         updateData( pData );
    1288                 :            :                     }
    1289         [ #  # ]:          0 :                 }
    1290                 :            :             }
    1291                 :            :             else
    1292                 :            :             {
    1293         [ +  - ]:          6 :                 addGroupToHierarchy( pGroup ); // add group to hierarchy
    1294                 :            :             }
    1295                 :            :         }
    1296                 :            :         else
    1297         [ #  # ]:          0 :             removeFromHierarchy( pGroup ); // delete group from hierarchy
    1298                 :            : 
    1299 [ +  - ][ +  - ]:          6 :         delete pGroup;
    1300                 :            :     }
    1301                 :          2 :     aGroupList.clear();
    1302                 :            : 
    1303         [ +  - ]:          2 :     aValue <<= sal_False;
    1304 [ +  - ][ +  - ]:          2 :     setProperty( maRootContent, aPropName, aValue );
                 [ +  - ]
    1305                 :          2 : }
    1306                 :            : 
    1307                 :            : //-----------------------------------------------------------------------------
    1308                 :          8 : uno::Sequence< beans::StringPair > SfxDocTplService_Impl::ReadUINamesForTemplateDir_Impl( const ::rtl::OUString& aUserPath )
    1309                 :            : {
    1310         [ +  - ]:          8 :     INetURLObject aLocObj( aUserPath );
    1311                 :            :     aLocObj.insertName( ::rtl::OUString( "groupuinames.xml"  ), false,
    1312                 :            :                       INetURLObject::LAST_SEGMENT, true,
    1313         [ +  - ]:          8 :                       INetURLObject::ENCODE_ALL );
    1314         [ +  - ]:          8 :     Content aLocContent;
    1315                 :            : 
    1316                 :            :     // TODO/LATER: Use hashmap in future
    1317         [ +  - ]:          8 :     uno::Sequence< beans::StringPair > aUINames;
    1318 [ +  - ][ +  - ]:          8 :     if ( Content::create( aLocObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference < ucb::XCommandEnvironment >(), aLocContent ) )
                 [ +  - ]
    1319                 :            :     {
    1320                 :            :         try
    1321                 :            :         {
    1322         [ -  + ]:          8 :             uno::Reference< io::XInputStream > xLocStream = aLocContent.openStream();
    1323         [ #  # ]:          0 :             if ( xLocStream.is() )
    1324 [ #  # ][ #  # ]:          8 :                 aUINames = DocTemplLocaleHelper::ReadGroupLocalizationSequence( xLocStream, mxFactory );
         [ #  # ][ -  + ]
    1325                 :            :         }
    1326         [ +  - ]:          8 :         catch( uno::Exception& )
    1327                 :            :         {}
    1328                 :            :     }
    1329                 :            : 
    1330 [ +  - ][ +  - ]:          8 :     return aUINames;
    1331                 :            : }
    1332                 :            : 
    1333                 :            : //-----------------------------------------------------------------------------
    1334                 :          0 : sal_Bool SfxDocTplService_Impl::UpdateUINamesForTemplateDir_Impl( const ::rtl::OUString& aUserPath,
    1335                 :            :                                                                   const ::rtl::OUString& aGroupName,
    1336                 :            :                                                                   const ::rtl::OUString& aNewFolderName )
    1337                 :            : {
    1338         [ #  # ]:          0 :     uno::Sequence< beans::StringPair > aUINames = ReadUINamesForTemplateDir_Impl( aUserPath );
    1339                 :          0 :     sal_Int32 nLen = aUINames.getLength();
    1340                 :            : 
    1341                 :            :     // it is possible that the name is used already, but it should be checked before
    1342         [ #  # ]:          0 :     for ( sal_Int32 nInd = 0; nInd < nLen; nInd++ )
    1343 [ #  # ][ #  # ]:          0 :         if ( aUINames[nInd].First.equals( aNewFolderName ) )
    1344                 :          0 :             return sal_False;
    1345                 :            : 
    1346         [ #  # ]:          0 :     aUINames.realloc( ++nLen );
    1347         [ #  # ]:          0 :     aUINames[nLen-1].First = aNewFolderName;
    1348         [ #  # ]:          0 :     aUINames[nLen-1].Second = aGroupName;
    1349                 :            : 
    1350 [ #  # ][ #  # ]:          0 :     return WriteUINamesForTemplateDir_Impl( aUserPath, aUINames );
    1351                 :            : }
    1352                 :            : 
    1353                 :            : //-----------------------------------------------------------------------------
    1354                 :          0 : sal_Bool SfxDocTplService_Impl::ReplaceUINamesForTemplateDir_Impl( const ::rtl::OUString& aUserPath,
    1355                 :            :                                                                   const ::rtl::OUString& aDefaultFsysGroupName,
    1356                 :            :                                                                   const ::rtl::OUString& aOldGroupName,
    1357                 :            :                                                                   const ::rtl::OUString& aNewGroupName )
    1358                 :            : {
    1359         [ #  # ]:          0 :     uno::Sequence< beans::StringPair > aUINames = ReadUINamesForTemplateDir_Impl( aUserPath );
    1360                 :          0 :     sal_Int32 nLen = aUINames.getLength();
    1361                 :            : 
    1362                 :          0 :     sal_Bool bChanged = sal_False;
    1363         [ #  # ]:          0 :     for ( sal_Int32 nInd = 0; nInd < nLen; nInd++ )
    1364 [ #  # ][ #  # ]:          0 :         if ( aUINames[nInd].Second.equals( aOldGroupName ) )
    1365                 :            :         {
    1366         [ #  # ]:          0 :             aUINames[nInd].Second = aNewGroupName;
    1367                 :          0 :             bChanged = sal_True;
    1368                 :            :         }
    1369                 :            : 
    1370         [ #  # ]:          0 :     if ( !bChanged )
    1371                 :            :     {
    1372         [ #  # ]:          0 :         aUINames.realloc( ++nLen );
    1373         [ #  # ]:          0 :         aUINames[nLen-1].First = aDefaultFsysGroupName;
    1374         [ #  # ]:          0 :         aUINames[nLen-1].Second = aNewGroupName;
    1375                 :            :     }
    1376 [ #  # ][ #  # ]:          0 :     return WriteUINamesForTemplateDir_Impl( aUserPath, aUINames );
    1377                 :            : }
    1378                 :            : 
    1379                 :            : //-----------------------------------------------------------------------------
    1380                 :          0 : sal_Bool SfxDocTplService_Impl::RemoveUINamesForTemplateDir_Impl( const ::rtl::OUString& aUserPath,
    1381                 :            :                                                                   const ::rtl::OUString& aGroupName )
    1382                 :            : {
    1383         [ #  # ]:          0 :     uno::Sequence< beans::StringPair > aUINames = ReadUINamesForTemplateDir_Impl( aUserPath );
    1384                 :          0 :     sal_Int32 nLen = aUINames.getLength();
    1385         [ #  # ]:          0 :     uno::Sequence< beans::StringPair > aNewUINames( nLen );
    1386                 :          0 :     sal_Int32 nNewLen = 0;
    1387                 :            : 
    1388                 :          0 :     sal_Bool bChanged = sal_False;
    1389         [ #  # ]:          0 :     for ( sal_Int32 nInd = 0; nInd < nLen; nInd++ )
    1390 [ #  # ][ #  # ]:          0 :         if ( aUINames[nInd].Second.equals( aGroupName ) )
    1391                 :          0 :             bChanged = sal_True;
    1392                 :            :         else
    1393                 :            :         {
    1394                 :          0 :             nNewLen++;
    1395 [ #  # ][ #  # ]:          0 :             aNewUINames[nNewLen-1].First = aUINames[nInd].First;
    1396 [ #  # ][ #  # ]:          0 :             aNewUINames[nNewLen-1].Second = aUINames[nInd].Second;
    1397                 :            :         }
    1398                 :            : 
    1399         [ #  # ]:          0 :     aNewUINames.realloc( nNewLen );
    1400                 :            : 
    1401 [ #  # ][ #  # ]:          0 :     return bChanged ? WriteUINamesForTemplateDir_Impl( aUserPath, aNewUINames ) : sal_True;
         [ #  # ][ #  # ]
    1402                 :            : }
    1403                 :            : 
    1404                 :            : 
    1405                 :            : //-----------------------------------------------------------------------------
    1406                 :          0 : sal_Bool SfxDocTplService_Impl::WriteUINamesForTemplateDir_Impl( const ::rtl::OUString& aUserPath,
    1407                 :            :                                                                 const uno::Sequence< beans::StringPair >& aUINames )
    1408                 :            : {
    1409                 :          0 :     sal_Bool bResult = sal_False;
    1410                 :            :     try {
    1411                 :            :         uno::Reference< beans::XPropertySet > xTempFile(
    1412         [ #  # ]:          0 :                 mxFactory->createInstance( ::rtl::OUString("com.sun.star.io.TempFile") ),
    1413 [ #  # ][ #  # ]:          0 :                 uno::UNO_QUERY_THROW );
    1414                 :            : 
    1415                 :          0 :         ::rtl::OUString aTempURL;
    1416 [ #  # ][ #  # ]:          0 :         uno::Any aUrl = xTempFile->getPropertyValue( ::rtl::OUString("Uri") );
    1417                 :          0 :         aUrl >>= aTempURL;
    1418                 :            : 
    1419         [ #  # ]:          0 :         uno::Reference< io::XStream > xStream( xTempFile, uno::UNO_QUERY_THROW );
    1420 [ #  # ][ #  # ]:          0 :         uno::Reference< io::XOutputStream > xOutStream = xStream->getOutputStream();
    1421         [ #  # ]:          0 :         if ( !xOutStream.is() )
    1422         [ #  # ]:          0 :             throw uno::RuntimeException();
    1423                 :            : 
    1424 [ #  # ][ #  # ]:          0 :         DocTemplLocaleHelper::WriteGroupLocalizationSequence( xOutStream, aUINames, mxFactory );
    1425                 :            :         try {
    1426                 :            :             // the SAX writer might close the stream
    1427 [ #  # ][ #  # ]:          0 :             xOutStream->closeOutput();
    1428         [ #  # ]:          0 :         } catch( uno::Exception& )
    1429                 :            :         {}
    1430                 :            : 
    1431         [ #  # ]:          0 :         Content aTargetContent( aUserPath, maCmdEnv );
    1432         [ #  # ]:          0 :         Content aSourceContent( aTempURL, maCmdEnv );
    1433                 :            :         aTargetContent.transferContent( aSourceContent,
    1434                 :            :                                         InsertOperation_COPY,
    1435                 :            :                                         ::rtl::OUString( "groupuinames.xml"  ),
    1436         [ #  # ]:          0 :                                         ucb::NameClash::OVERWRITE );
    1437 [ #  # ][ #  # ]:          0 :         bResult = sal_True;
                 [ #  # ]
    1438                 :            :     }
    1439                 :          0 :     catch ( uno::Exception& )
    1440                 :            :     {
    1441                 :            :     }
    1442                 :            : 
    1443                 :          0 :     return bResult;
    1444                 :            : }
    1445                 :            : 
    1446                 :            : //-----------------------------------------------------------------------------
    1447                 :          0 : ::rtl::OUString SfxDocTplService_Impl::CreateNewGroupFsys( const ::rtl::OUString& rGroupName, Content& aGroup )
    1448                 :            : {
    1449                 :          0 :     ::rtl::OUString aResultURL;
    1450                 :            : 
    1451         [ #  # ]:          0 :     if ( maTemplateDirs.getLength() )
    1452                 :            :     {
    1453         [ #  # ]:          0 :         ::rtl::OUString aTargetPath = maTemplateDirs[ maTemplateDirs.getLength() - 1 ];
    1454                 :            : 
    1455                 :            :         // create a new folder with the given name
    1456         [ #  # ]:          0 :         Content aNewFolder;
    1457                 :          0 :         ::rtl::OUString aNewFolderName;
    1458                 :            : 
    1459                 :            :         // the Fsys name instead of GroupName should be used, the groupuinames must be added also
    1460 [ #  # ][ #  # ]:          0 :         if ( !CreateNewUniqueFolderWithPrefix( aTargetPath,
                 [ #  # ]
    1461                 :            :                                                 rGroupName,
    1462                 :            :                                                 aNewFolderName,
    1463                 :            :                                                 aResultURL,
    1464         [ #  # ]:          0 :                                                 aNewFolder )
    1465                 :            :           && !CreateNewUniqueFolderWithPrefix( aTargetPath,
    1466                 :            :                                                 ::rtl::OUString( "UserGroup"  ),
    1467                 :            :                                                 aNewFolderName,
    1468                 :            :                                                 aResultURL,
    1469 [ #  # ][ #  # ]:          0 :                                                 aNewFolder ) )
                 [ #  # ]
           [ #  #  #  # ]
    1470                 :            : 
    1471                 :          0 :             return ::rtl::OUString();
    1472                 :            : 
    1473 [ #  # ][ #  # ]:          0 :         if ( !UpdateUINamesForTemplateDir_Impl( aTargetPath, rGroupName, aNewFolderName ) )
    1474                 :            :         {
    1475                 :            :             // we could not create the groupuinames for the folder, so we delete the group in the
    1476                 :            :             // the folder and return
    1477         [ #  # ]:          0 :             removeContent( aNewFolder );
    1478                 :          0 :             return ::rtl::OUString();
    1479                 :            :         }
    1480                 :            : 
    1481                 :            :         // Now set the target url for this group and we are done
    1482                 :          0 :         OUString aPropName( TARGET_DIR_URL  );
    1483         [ #  # ]:          0 :         Any aValue = makeAny( aResultURL );
    1484                 :            : 
    1485 [ #  # ][ #  # ]:          0 :         if ( ! setProperty( aGroup, aPropName, aValue ) )
    1486                 :            :         {
    1487         [ #  # ]:          0 :             removeContent( aNewFolder );
    1488                 :          0 :             return ::rtl::OUString();
    1489 [ #  # ][ #  # ]:          0 :         }
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1490                 :            :     }
    1491                 :            : 
    1492                 :          0 :     return aResultURL;
    1493                 :            : }
    1494                 :            : 
    1495                 :            : //-----------------------------------------------------------------------------
    1496                 :          0 : sal_Bool SfxDocTplService_Impl::addGroup( const OUString& rGroupName )
    1497                 :            : {
    1498         [ #  # ]:          0 :     ::osl::MutexGuard aGuard( maMutex );
    1499                 :            : 
    1500                 :            :     // Check, whether or not there is a group with this name
    1501         [ #  # ]:          0 :     Content      aNewGroup;
    1502                 :          0 :     OUString        aNewGroupURL;
    1503         [ #  # ]:          0 :     INetURLObject   aNewGroupObj( maRootURL );
    1504                 :            : 
    1505                 :            :     aNewGroupObj.insertName( rGroupName, false,
    1506                 :            :                       INetURLObject::LAST_SEGMENT, true,
    1507         [ #  # ]:          0 :                       INetURLObject::ENCODE_ALL );
    1508                 :            : 
    1509         [ #  # ]:          0 :     aNewGroupURL = aNewGroupObj.GetMainURL( INetURLObject::NO_DECODE );
    1510                 :            : 
    1511 [ #  # ][ #  # ]:          0 :     if ( Content::create( aNewGroupURL, maCmdEnv, aNewGroup ) ||
         [ #  # ][ #  # ]
    1512         [ #  # ]:          0 :          ! createFolder( aNewGroupURL, sal_False, sal_False, aNewGroup ) )
    1513                 :            :     {
    1514                 :            :         // if there already was a group with this name or the new group
    1515                 :            :         // could not be created, we return here
    1516                 :          0 :         return sal_False;
    1517                 :            :     }
    1518                 :            : 
    1519                 :            :     // Get the user template path entry ( new group will always
    1520                 :            :     // be added in the user template path )
    1521                 :            :     sal_Int32   nIndex;
    1522                 :          0 :     OUString    aUserPath;
    1523                 :            : 
    1524                 :          0 :     nIndex = maTemplateDirs.getLength();
    1525         [ #  # ]:          0 :     if ( nIndex )
    1526                 :          0 :         nIndex--;
    1527                 :            :     else
    1528                 :          0 :         return sal_False;   // We don't know where to add the group
    1529                 :            : 
    1530         [ #  # ]:          0 :     aUserPath = maTemplateDirs[ nIndex ];
    1531                 :            : 
    1532                 :            :     // create a new folder with the given name
    1533         [ #  # ]:          0 :     Content      aNewFolder;
    1534                 :          0 :     OUString        aNewFolderName;
    1535                 :          0 :     OUString        aNewFolderURL;
    1536                 :            : 
    1537                 :            :     // the Fsys name instead of GroupName should be used, the groupuinames must be added also
    1538 [ #  # ][ #  # ]:          0 :     if ( !CreateNewUniqueFolderWithPrefix( aUserPath,
                 [ #  # ]
    1539                 :            :                                             rGroupName,
    1540                 :            :                                             aNewFolderName,
    1541                 :            :                                             aNewFolderURL,
    1542         [ #  # ]:          0 :                                             aNewFolder )
    1543                 :            :       && !CreateNewUniqueFolderWithPrefix( aUserPath,
    1544                 :            :                                             ::rtl::OUString( "UserGroup"  ),
    1545                 :            :                                             aNewFolderName,
    1546                 :            :                                             aNewFolderURL,
    1547 [ #  # ][ #  # ]:          0 :                                             aNewFolder ) )
                 [ #  # ]
           [ #  #  #  # ]
    1548                 :            :     {
    1549                 :            :         // we could not create the folder, so we delete the group in the
    1550                 :            :         // hierarchy and return
    1551         [ #  # ]:          0 :         removeContent( aNewGroup );
    1552                 :          0 :         return sal_False;
    1553                 :            :     }
    1554                 :            : 
    1555 [ #  # ][ #  # ]:          0 :     if ( !UpdateUINamesForTemplateDir_Impl( aUserPath, rGroupName, aNewFolderName ) )
    1556                 :            :     {
    1557                 :            :         // we could not create the groupuinames for the folder, so we delete the group in the
    1558                 :            :         // hierarchy, the folder and return
    1559         [ #  # ]:          0 :         removeContent( aNewGroup );
    1560         [ #  # ]:          0 :         removeContent( aNewFolder );
    1561                 :          0 :         return sal_False;
    1562                 :            :     }
    1563                 :            : 
    1564                 :            :     // Now set the target url for this group and we are done
    1565                 :          0 :     OUString aPropName( TARGET_DIR_URL  );
    1566         [ #  # ]:          0 :     Any aValue = makeAny( aNewFolderURL );
    1567                 :            : 
    1568 [ #  # ][ #  # ]:          0 :     if ( ! setProperty( aNewGroup, aPropName, aValue ) )
    1569                 :            :     {
    1570         [ #  # ]:          0 :         removeContent( aNewGroup );
    1571         [ #  # ]:          0 :         removeContent( aNewFolder );
    1572                 :          0 :         return sal_False;
    1573                 :            :     }
    1574                 :            : 
    1575 [ #  # ][ #  # ]:          0 :     return sal_True;
         [ #  # ][ #  # ]
    1576                 :            : }
    1577                 :            : 
    1578                 :            : //-----------------------------------------------------------------------------
    1579                 :          0 : sal_Bool SfxDocTplService_Impl::removeGroup( const OUString& rGroupName )
    1580                 :            : {
    1581                 :            :     // remove all the elements that have the prefix aTargetURL
    1582                 :            :     // if the group does not have other elements remove it
    1583                 :            : 
    1584         [ #  # ]:          0 :     ::osl::MutexGuard aGuard( maMutex );
    1585                 :            : 
    1586                 :          0 :     sal_Bool bResult = sal_False;
    1587                 :            : 
    1588                 :            :     // create the group url
    1589         [ #  # ]:          0 :     INetURLObject aGroupObj( maRootURL );
    1590                 :            :     aGroupObj.insertName( rGroupName, false,
    1591                 :            :                       INetURLObject::LAST_SEGMENT, true,
    1592         [ #  # ]:          0 :                       INetURLObject::ENCODE_ALL );
    1593                 :            : 
    1594                 :            :     // Get the target url
    1595         [ #  # ]:          0 :     Content  aGroup;
    1596         [ #  # ]:          0 :     OUString    aGroupURL = aGroupObj.GetMainURL( INetURLObject::NO_DECODE );
    1597                 :            : 
    1598 [ #  # ][ #  # ]:          0 :     if ( Content::create( aGroupURL, maCmdEnv, aGroup ) )
    1599                 :            :     {
    1600                 :          0 :         OUString    aPropName( TARGET_DIR_URL  );
    1601                 :          0 :         Any      aValue;
    1602                 :            : 
    1603                 :          0 :         OUString    aGroupTargetURL;
    1604 [ #  # ][ #  # ]:          0 :         if ( getProperty( aGroup, aPropName, aValue ) )
    1605                 :          0 :             aValue >>= aGroupTargetURL;
    1606                 :            : 
    1607         [ #  # ]:          0 :         if ( aGroupTargetURL.isEmpty() )
    1608                 :          0 :             return sal_False; // nothing is allowed to be removed
    1609                 :            : 
    1610         [ #  # ]:          0 :         if ( !maTemplateDirs.getLength() )
    1611                 :          0 :             return sal_False;
    1612         [ #  # ]:          0 :         ::rtl::OUString aGeneralTempPath = maTemplateDirs[ maTemplateDirs.getLength() - 1 ];
    1613                 :            : 
    1614                 :            :         // check that the fs location is in writeble folder and this is not a "My templates" folder
    1615         [ #  # ]:          0 :         INetURLObject aGroupParentFolder( aGroupTargetURL );
    1616 [ #  # ][ #  # ]:          0 :         if ( !aGroupParentFolder.removeSegment()
         [ #  # ][ #  # ]
    1617                 :            :           || !::utl::UCBContentHelper::IsSubPath( aGeneralTempPath,
    1618 [ #  # ][ #  # ]:          0 :                                                       aGroupParentFolder.GetMainURL( INetURLObject::NO_DECODE ) ) )
         [ #  # ][ #  # ]
    1619                 :          0 :             return sal_False;
    1620                 :            : 
    1621                 :            :         // now get the content of the Group
    1622                 :          0 :         uno::Reference< XResultSet > xResultSet;
    1623         [ #  # ]:          0 :         Sequence< OUString > aProps( 1 );
    1624                 :            : 
    1625         [ #  # ]:          0 :         aProps[0] = OUString(TARGET_URL );
    1626                 :            : 
    1627                 :            :         try
    1628                 :            :         {
    1629                 :          0 :             sal_Bool bHasNonRemovable = sal_False;
    1630                 :          0 :             sal_Bool bHasShared = sal_False;
    1631                 :            : 
    1632                 :          0 :             ResultSetInclude eInclude = INCLUDE_DOCUMENTS_ONLY;
    1633 [ #  # ][ #  # ]:          0 :             xResultSet = aGroup.createCursor( aProps, eInclude );
    1634                 :            : 
    1635         [ #  # ]:          0 :             if ( xResultSet.is() )
    1636                 :            :             {
    1637         [ #  # ]:          0 :                 uno::Reference< XContentAccess > xContentAccess( xResultSet, UNO_QUERY_THROW );
    1638         [ #  # ]:          0 :                 uno::Reference< XRow > xRow( xResultSet, UNO_QUERY_THROW );
    1639                 :            : 
    1640 [ #  # ][ #  # ]:          0 :                 while ( xResultSet->next() )
                 [ #  # ]
    1641                 :            :                 {
    1642 [ #  # ][ #  # ]:          0 :                     OUString aTemplTargetURL( xRow->getString( 1 ) );
    1643 [ #  # ][ #  # ]:          0 :                     OUString aHierURL = xContentAccess->queryContentIdentifierString();
    1644                 :            : 
    1645 [ #  # ][ #  # ]:          0 :                     if ( ::utl::UCBContentHelper::IsSubPath( aGroupTargetURL, aTemplTargetURL ) )
    1646                 :            :                     {
    1647                 :            :                         // this is a user template, and it can be removed
    1648 [ #  # ][ #  # ]:          0 :                         if ( removeContent( aTemplTargetURL ) )
    1649         [ #  # ]:          0 :                             removeContent( aHierURL );
    1650                 :            :                         else
    1651                 :          0 :                             bHasNonRemovable = sal_True;
    1652                 :            :                     }
    1653                 :            :                     else
    1654                 :          0 :                         bHasShared = sal_True;
    1655                 :          0 :                 }
    1656                 :            : 
    1657 [ #  # ][ #  # ]:          0 :                 if ( !bHasNonRemovable && !bHasShared )
    1658                 :            :                 {
    1659 [ #  # ][ #  # ]:          0 :                     if ( removeContent( aGroupTargetURL )
         [ #  # ][ #  # ]
    1660         [ #  # ]:          0 :                       || !::utl::UCBContentHelper::Exists( aGroupTargetURL ) )
    1661                 :            :                     {
    1662         [ #  # ]:          0 :                         removeContent( aGroupURL );
    1663         [ #  # ]:          0 :                         RemoveUINamesForTemplateDir_Impl( aGeneralTempPath, rGroupName );
    1664                 :          0 :                         bResult = sal_True; // the operation is successful only if the whole group is removed
    1665                 :            :                     }
    1666                 :            :                 }
    1667         [ #  # ]:          0 :                 else if ( !bHasNonRemovable )
    1668                 :            :                 {
    1669 [ #  # ][ #  # ]:          0 :                     if ( removeContent( aGroupTargetURL )
         [ #  # ][ #  # ]
    1670         [ #  # ]:          0 :                       || !::utl::UCBContentHelper::Exists( aGroupTargetURL ) )
    1671                 :            :                     {
    1672         [ #  # ]:          0 :                         RemoveUINamesForTemplateDir_Impl( aGeneralTempPath, rGroupName );
    1673 [ #  # ][ #  # ]:          0 :                         setProperty( aGroup, aPropName, uno::makeAny( ::rtl::OUString() ) );
    1674                 :            :                     }
    1675         [ #  # ]:          0 :                 }
    1676                 :            :             }
    1677                 :            :         }
    1678 [ #  # ][ #  # ]:          0 :         catch ( Exception& ) {}
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1679                 :            :     }
    1680                 :            : 
    1681 [ #  # ][ #  # ]:          0 :     return bResult;
                 [ #  # ]
    1682                 :            : }
    1683                 :            : 
    1684                 :            : //-----------------------------------------------------------------------------
    1685                 :          0 : sal_Bool SfxDocTplService_Impl::renameGroup( const OUString& rOldName,
    1686                 :            :                                              const OUString& rNewName )
    1687                 :            : {
    1688         [ #  # ]:          0 :     ::osl::MutexGuard aGuard( maMutex );
    1689                 :            : 
    1690                 :            :     // create the group url
    1691         [ #  # ]:          0 :     Content         aGroup;
    1692         [ #  # ]:          0 :     INetURLObject   aGroupObj( maRootURL );
    1693                 :            :                     aGroupObj.insertName( rNewName, false,
    1694                 :            :                                           INetURLObject::LAST_SEGMENT, true,
    1695         [ #  # ]:          0 :                                           INetURLObject::ENCODE_ALL );
    1696         [ #  # ]:          0 :     OUString        aGroupURL = aGroupObj.GetMainURL( INetURLObject::NO_DECODE );
    1697                 :            : 
    1698                 :            :     // Check, if there is a group with the new name, return false
    1699                 :            :     // if there is one.
    1700 [ #  # ][ #  # ]:          0 :     if ( Content::create( aGroupURL, maCmdEnv, aGroup ) )
    1701                 :          0 :         return sal_False;
    1702                 :            : 
    1703         [ #  # ]:          0 :     aGroupObj.removeSegment();
    1704                 :            :     aGroupObj.insertName( rOldName, false,
    1705                 :            :                       INetURLObject::LAST_SEGMENT, true,
    1706         [ #  # ]:          0 :                       INetURLObject::ENCODE_ALL );
    1707         [ #  # ]:          0 :     aGroupURL = aGroupObj.GetMainURL( INetURLObject::NO_DECODE );
    1708                 :            : 
    1709                 :            :     // When there is no group with the old name, we can't rename it
    1710 [ #  # ][ #  # ]:          0 :     if ( ! Content::create( aGroupURL, maCmdEnv, aGroup ) )
    1711                 :          0 :         return sal_False;
    1712                 :            : 
    1713                 :          0 :     OUString aGroupTargetURL;
    1714                 :            :     // there is no need to check whether target dir url is in target path, since if the target path is changed
    1715                 :            :     // the target dir url should be already generated new
    1716                 :          0 :     OUString    aPropName( TARGET_DIR_URL  );
    1717                 :          0 :     Any      aValue;
    1718 [ #  # ][ #  # ]:          0 :     if ( getProperty( aGroup, aPropName, aValue ) )
    1719                 :          0 :         aValue >>= aGroupTargetURL;
    1720                 :            : 
    1721         [ #  # ]:          0 :     if ( aGroupTargetURL.isEmpty() )
    1722                 :          0 :         return sal_False;
    1723                 :            : 
    1724         [ #  # ]:          0 :     if ( !maTemplateDirs.getLength() )
    1725                 :          0 :         return sal_False;
    1726         [ #  # ]:          0 :     ::rtl::OUString aGeneralTempPath = maTemplateDirs[ maTemplateDirs.getLength() - 1 ];
    1727                 :            : 
    1728                 :            :     // check that the fs location is in writeble folder and this is not a "My templates" folder
    1729         [ #  # ]:          0 :     INetURLObject aGroupParentFolder( aGroupTargetURL );
    1730 [ #  # ][ #  # ]:          0 :     if ( !aGroupParentFolder.removeSegment()
         [ #  # ][ #  # ]
    1731                 :            :       || !::utl::UCBContentHelper::IsSubPath( aGeneralTempPath,
    1732 [ #  # ][ #  # ]:          0 :                                                   aGroupParentFolder.GetMainURL( INetURLObject::NO_DECODE ) ) )
         [ #  # ][ #  # ]
    1733                 :          0 :         return sal_False;
    1734                 :            : 
    1735                 :            :     // check that the group can be renamed ( all the contents must be in target location )
    1736                 :          0 :     sal_Bool bCanBeRenamed = sal_False;
    1737                 :            :        try
    1738                 :            :        {
    1739                 :          0 :         uno::Reference< XResultSet > xResultSet;
    1740         [ #  # ]:          0 :         Sequence< OUString > aProps( 1 );
    1741                 :            : 
    1742         [ #  # ]:          0 :         aProps[0] = OUString(TARGET_URL );
    1743                 :          0 :         ResultSetInclude eInclude = INCLUDE_DOCUMENTS_ONLY;
    1744 [ #  # ][ #  # ]:          0 :         xResultSet = aGroup.createCursor( aProps, eInclude );
    1745                 :            : 
    1746         [ #  # ]:          0 :         if ( xResultSet.is() )
    1747                 :            :         {
    1748         [ #  # ]:          0 :                uno::Reference< XContentAccess > xContentAccess( xResultSet, UNO_QUERY_THROW );
    1749         [ #  # ]:          0 :                uno::Reference< XRow > xRow( xResultSet, UNO_QUERY_THROW );
    1750                 :            : 
    1751 [ #  # ][ #  # ]:          0 :                while ( xResultSet->next() )
                 [ #  # ]
    1752                 :            :                {
    1753 [ #  # ][ #  # ]:          0 :                    OUString aTemplTargetURL( xRow->getString( 1 ) );
    1754                 :            : 
    1755 [ #  # ][ #  # ]:          0 :                 if ( !::utl::UCBContentHelper::IsSubPath( aGroupTargetURL, aTemplTargetURL ) )
    1756         [ #  # ]:          0 :                     throw uno::Exception();
    1757                 :          0 :             }
    1758                 :            : 
    1759                 :          0 :             bCanBeRenamed = sal_True;
    1760 [ #  # ][ #  # ]:          0 :         }
    1761                 :            :     }
    1762         [ #  # ]:          0 :     catch ( Exception& ) {}
    1763                 :            : 
    1764         [ #  # ]:          0 :     if ( bCanBeRenamed )
    1765                 :            :     {
    1766         [ #  # ]:          0 :         INetURLObject aGroupTargetObj( aGroupTargetURL );
    1767         [ #  # ]:          0 :         ::rtl::OUString aFsysName = aGroupTargetObj.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
    1768                 :            : 
    1769 [ #  # ][ #  # ]:          0 :         if ( aGroupTargetObj.removeSegment()
         [ #  # ][ #  # ]
    1770                 :            :           && ReplaceUINamesForTemplateDir_Impl( aGroupTargetObj.GetMainURL( INetURLObject::NO_DECODE ),
    1771                 :            :                                                   aFsysName,
    1772                 :            :                                                 rOldName,
    1773 [ #  # ][ #  # ]:          0 :                                                 rNewName ) )
         [ #  # ][ #  # ]
    1774                 :            :         {
    1775                 :            :             // rename the group in the hierarchy
    1776                 :          0 :             OUString aTitleProp( TITLE  );
    1777                 :          0 :             Any aTitleValue;
    1778         [ #  # ]:          0 :             aTitleValue <<= rNewName;
    1779                 :            : 
    1780         [ #  # ]:          0 :             return setProperty( aGroup, aTitleProp, aTitleValue );
    1781 [ #  # ][ #  # ]:          0 :         }
                 [ #  # ]
    1782                 :            :     }
    1783                 :            : 
    1784 [ #  # ][ #  # ]:          0 :     return sal_False;
         [ #  # ][ #  # ]
    1785                 :            : }
    1786                 :            : 
    1787                 :            : //-----------------------------------------------------------------------------
    1788                 :          0 : sal_Bool SfxDocTplService_Impl::storeTemplate( const OUString& rGroupName,
    1789                 :            :                                                const OUString& rTemplateName,
    1790                 :            :                                                const uno::Reference< XSTORABLE >& rStorable )
    1791                 :            : {
    1792         [ #  # ]:          0 :     ::osl::MutexGuard aGuard( maMutex );
    1793                 :            : 
    1794                 :            :     // Check, whether or not there is a group with this name
    1795                 :            :     // Return false, if there is no group with the given name
    1796 [ #  # ][ #  # ]:          0 :     Content         aGroup, aTemplate, aTargetGroup, aTemplateToRemove;
         [ #  # ][ #  # ]
    1797                 :          0 :     OUString        aGroupURL, aTemplateURL, aTemplateToRemoveTargetURL;
    1798         [ #  # ]:          0 :     INetURLObject   aGroupObj( maRootURL );
    1799                 :          0 :     sal_Bool        bRemoveOldTemplateContent = sal_False;
    1800                 :          0 :     ::rtl::OUString sDocServiceName;
    1801                 :            : 
    1802                 :            :     aGroupObj.insertName( rGroupName, false,
    1803                 :            :                       INetURLObject::LAST_SEGMENT, true,
    1804         [ #  # ]:          0 :                       INetURLObject::ENCODE_ALL );
    1805         [ #  # ]:          0 :     aGroupURL = aGroupObj.GetMainURL( INetURLObject::NO_DECODE );
    1806                 :            : 
    1807 [ #  # ][ #  # ]:          0 :     if ( ! Content::create( aGroupURL, maCmdEnv, aGroup ) )
    1808                 :          0 :         return sal_False;
    1809                 :            : 
    1810                 :          0 :     ::rtl::OUString aGroupTargetURL;
    1811                 :          0 :     ::rtl::OUString aPropName( TARGET_DIR_URL  );
    1812                 :          0 :     Any      aValue;
    1813 [ #  # ][ #  # ]:          0 :     if ( getProperty( aGroup, aPropName, aValue ) )
    1814                 :          0 :         aValue >>= aGroupTargetURL;
    1815                 :            : 
    1816                 :            : 
    1817                 :            :     // Check, if there's a template with the given name in this group
    1818                 :            :     // the target template should be overwritten if it is imported by user
    1819                 :            :     // in case the template is installed by office installation of by an add-in
    1820                 :            :     // it can not be replaced
    1821                 :            :     aGroupObj.insertName( rTemplateName, false,
    1822                 :            :                       INetURLObject::LAST_SEGMENT, true,
    1823         [ #  # ]:          0 :                       INetURLObject::ENCODE_ALL );
    1824         [ #  # ]:          0 :     aTemplateURL = aGroupObj.GetMainURL( INetURLObject::NO_DECODE );
    1825                 :            : 
    1826 [ #  # ][ #  # ]:          0 :     if ( Content::create( aTemplateURL, maCmdEnv, aTemplateToRemove ) )
    1827                 :            :     {
    1828                 :          0 :         OUString    aTargetTemplPropName( TARGET_URL  );
    1829                 :            : 
    1830                 :          0 :         bRemoveOldTemplateContent = sal_True;
    1831 [ #  # ][ #  # ]:          0 :         if ( getProperty( aTemplateToRemove, aTargetTemplPropName, aValue ) )
    1832                 :          0 :             aValue >>= aTemplateToRemoveTargetURL;
    1833                 :            : 
    1834         [ #  # ]:          0 :         if ( aGroupTargetURL.isEmpty() || !maTemplateDirs.getLength()
           [ #  #  #  # ]
         [ #  # ][ #  # ]
    1835 [ #  # ][ #  # ]:          0 :           || (!aTemplateToRemoveTargetURL.isEmpty() && !::utl::UCBContentHelper::IsSubPath( maTemplateDirs[ maTemplateDirs.getLength() - 1 ], aTemplateToRemoveTargetURL )) )
    1836         [ #  # ]:          0 :             return sal_False; // it is not allowed to remove the template
    1837                 :            :     }
    1838                 :            : 
    1839                 :            :     try
    1840                 :            :     {
    1841         [ #  # ]:          0 :         uno::Reference< lang::XMultiServiceFactory > xFactory = ::comphelper::getProcessServiceFactory();
    1842         [ #  # ]:          0 :         if ( !xFactory.is() )
    1843         [ #  # ]:          0 :             throw uno::RuntimeException();
    1844                 :            : 
    1845                 :            :         // get document service name
    1846                 :            :         uno::Reference< frame::XModuleManager > xModuleManager(
    1847         [ #  # ]:          0 :             xFactory->createInstance(
    1848                 :          0 :                     ::rtl::OUString("com.sun.star.frame.ModuleManager") ),
    1849 [ #  # ][ #  # ]:          0 :             uno::UNO_QUERY_THROW );
    1850 [ #  # ][ #  # ]:          0 :         sDocServiceName = xModuleManager->identify( uno::Reference< uno::XInterface >( rStorable, uno::UNO_QUERY ) );
                 [ #  # ]
    1851         [ #  # ]:          0 :         if ( sDocServiceName.isEmpty() )
    1852         [ #  # ]:          0 :             throw uno::RuntimeException();
    1853                 :            : 
    1854                 :            :         // get the actual filter name
    1855                 :          0 :         ::rtl::OUString aFilterName;
    1856                 :            : 
    1857                 :            :         uno::Reference< lang::XMultiServiceFactory > xConfigProvider(
    1858         [ #  # ]:          0 :                 xFactory->createInstance(
    1859                 :          0 :                     ::rtl::OUString("com.sun.star.configuration.ConfigurationProvider") ),
    1860 [ #  # ][ #  # ]:          0 :                 uno::UNO_QUERY_THROW );
    1861                 :            : 
    1862         [ #  # ]:          0 :         uno::Sequence< uno::Any > aArgs( 1 );
    1863                 :          0 :         beans::PropertyValue aPathProp;
    1864                 :          0 :         aPathProp.Name = ::rtl::OUString("nodepath");
    1865         [ #  # ]:          0 :         aPathProp.Value <<= ::rtl::OUString( "/org.openoffice.Setup/Office/Factories/"  );
    1866 [ #  # ][ #  # ]:          0 :         aArgs[0] <<= aPathProp;
    1867                 :            : 
    1868                 :            :         uno::Reference< container::XNameAccess > xSOFConfig(
    1869         [ #  # ]:          0 :             xConfigProvider->createInstanceWithArguments(
    1870                 :            :                                     ::rtl::OUString("com.sun.star.configuration.ConfigurationAccess"),
    1871                 :          0 :                                     aArgs ),
    1872 [ #  # ][ #  # ]:          0 :             uno::UNO_QUERY_THROW );
    1873                 :            : 
    1874                 :          0 :         uno::Reference< container::XNameAccess > xApplConfig;
    1875 [ #  # ][ #  # ]:          0 :         xSOFConfig->getByName( sDocServiceName ) >>= xApplConfig;
                 [ #  # ]
    1876         [ #  # ]:          0 :         if ( !xApplConfig.is() )
    1877         [ #  # ]:          0 :             throw uno::RuntimeException();
    1878                 :            : 
    1879 [ #  # ][ #  # ]:          0 :         xApplConfig->getByName( ::rtl::OUString( "ooSetupFactoryActualTemplateFilter"  ) ) >>= aFilterName;
    1880         [ #  # ]:          0 :         if ( aFilterName.isEmpty() )
    1881         [ #  # ]:          0 :             throw uno::RuntimeException();
    1882                 :            : 
    1883                 :            :         // find the related type name
    1884                 :          0 :         ::rtl::OUString aTypeName;
    1885                 :            :         uno::Reference< container::XNameAccess > xFilterFactory(
    1886         [ #  # ]:          0 :             xFactory->createInstance( ::rtl::OUString("com.sun.star.document.FilterFactory") ),
    1887 [ #  # ][ #  # ]:          0 :             uno::UNO_QUERY_THROW );
    1888                 :            : 
    1889         [ #  # ]:          0 :         uno::Sequence< beans::PropertyValue > aFilterData;
    1890 [ #  # ][ #  # ]:          0 :         xFilterFactory->getByName( aFilterName ) >>= aFilterData;
                 [ #  # ]
    1891         [ #  # ]:          0 :         for ( sal_Int32 nInd = 0; nInd < aFilterData.getLength(); nInd++ )
    1892 [ #  # ][ #  # ]:          0 :             if ( aFilterData[nInd].Name == "Type" )
    1893         [ #  # ]:          0 :                 aFilterData[nInd].Value >>= aTypeName;
    1894                 :            : 
    1895         [ #  # ]:          0 :         if ( aTypeName.isEmpty() )
    1896         [ #  # ]:          0 :             throw uno::RuntimeException();
    1897                 :            : 
    1898                 :            :         // find the mediatype and extension
    1899                 :            :         uno::Reference< container::XNameAccess > xTypeDetection =
    1900                 :          0 :             mxType.is() ?
    1901                 :            :                 uno::Reference< container::XNameAccess >( mxType, uno::UNO_QUERY_THROW ) :
    1902                 :            :                 uno::Reference< container::XNameAccess >(
    1903         [ #  # ]:          0 :                     xFactory->createInstance( ::rtl::OUString("com.sun.star.document.TypeDetection") ),
    1904 [ #  # ][ #  # ]:          0 :                     uno::UNO_QUERY_THROW );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
           [ #  #  #  #  
           #  # ][ #  # ]
    1905                 :            : 
    1906 [ #  # ][ #  # ]:          0 :         SequenceAsHashMap aTypeProps( xTypeDetection->getByName( aTypeName ) );
                 [ #  # ]
    1907                 :            :         uno::Sequence< ::rtl::OUString > aAllExt =
    1908 [ #  # ][ #  # ]:          0 :             aTypeProps.getUnpackedValueOrDefault( ::rtl::OUString("Extensions"), Sequence< ::rtl::OUString >() );
                 [ #  # ]
    1909         [ #  # ]:          0 :         if ( !aAllExt.getLength() )
    1910         [ #  # ]:          0 :             throw uno::RuntimeException();
    1911                 :            : 
    1912         [ #  # ]:          0 :         ::rtl::OUString aMediaType = aTypeProps.getUnpackedValueOrDefault( ::rtl::OUString("MediaType"), ::rtl::OUString() );
    1913         [ #  # ]:          0 :         ::rtl::OUString aExt = aAllExt[0];
    1914                 :            : 
    1915 [ #  # ][ #  # ]:          0 :         if ( aMediaType.isEmpty() || aExt.isEmpty() )
                 [ #  # ]
    1916         [ #  # ]:          0 :             throw uno::RuntimeException();
    1917                 :            : 
    1918                 :            :         // construct destination url
    1919         [ #  # ]:          0 :         if ( aGroupTargetURL.isEmpty() )
    1920                 :            :         {
    1921         [ #  # ]:          0 :             aGroupTargetURL = CreateNewGroupFsys( rGroupName, aGroup );
    1922                 :            : 
    1923         [ #  # ]:          0 :             if ( aGroupTargetURL.isEmpty() )
    1924         [ #  # ]:          0 :                 throw uno::RuntimeException();
    1925                 :            :         }
    1926                 :            : 
    1927         [ #  # ]:          0 :         ::rtl::OUString aNewTemplateTargetURL = CreateNewUniqueFileWithPrefix( aGroupTargetURL, rTemplateName, aExt );
    1928         [ #  # ]:          0 :         if ( aNewTemplateTargetURL.isEmpty() )
    1929                 :            :         {
    1930         [ #  # ]:          0 :             aNewTemplateTargetURL = CreateNewUniqueFileWithPrefix( aGroupTargetURL, ::rtl::OUString( "UserTemplate"  ), aExt );
    1931                 :            : 
    1932         [ #  # ]:          0 :             if ( aNewTemplateTargetURL.isEmpty() )
    1933         [ #  # ]:          0 :                 throw uno::RuntimeException();
    1934                 :            :         }
    1935                 :            : 
    1936                 :            :         // store template
    1937         [ #  # ]:          0 :         uno::Sequence< PropertyValue > aStoreArgs( 2 );
    1938         [ #  # ]:          0 :         aStoreArgs[0].Name = ::rtl::OUString("FilterName");
    1939 [ #  # ][ #  # ]:          0 :         aStoreArgs[0].Value <<= aFilterName;
    1940         [ #  # ]:          0 :         aStoreArgs[1].Name = ::rtl::OUString("DocumentTitle");
    1941 [ #  # ][ #  # ]:          0 :         aStoreArgs[1].Value <<= rTemplateName;
    1942                 :            : 
    1943 [ #  # ][ #  # ]:          0 :         ::rtl::OUString aCurrentDocumentURL = rStorable->getLocation();
    1944 [ #  # ][ #  # ]:          0 :         if( !::utl::UCBContentHelper::EqualURLs( aNewTemplateTargetURL, rStorable->getLocation() ))
         [ #  # ][ #  # ]
    1945 [ #  # ][ #  # ]:          0 :             rStorable->storeToURL( aNewTemplateTargetURL, aStoreArgs );
    1946                 :            :         else
    1947 [ #  # ][ #  # ]:          0 :             rStorable->store();
    1948                 :            : 
    1949                 :            :         // the storing was successful, now the old template with the same name can be removed if it existed
    1950         [ #  # ]:          0 :         if ( !aTemplateToRemoveTargetURL.isEmpty() )
    1951                 :            :         {
    1952         [ #  # ]:          0 :             removeContent( aTemplateToRemoveTargetURL );
    1953                 :            : 
    1954                 :            :             /*
    1955                 :            :              * pb: #i79496#
    1956                 :            :              * if the old template was the standard template
    1957                 :            :              * it is necessary to change the standard template with the new file name
    1958                 :            :              */
    1959 [ #  # ][ #  # ]:          0 :             String sStdTmplFile = SfxObjectFactory::GetStandardTemplate( sDocServiceName );
                 [ #  # ]
    1960 [ #  # ][ #  # ]:          0 :             if ( INetURLObject( sStdTmplFile ) == INetURLObject( aTemplateToRemoveTargetURL ) )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1961                 :            :             {
    1962 [ #  # ][ #  # ]:          0 :                 SfxObjectFactory::SetStandardTemplate( sDocServiceName, aNewTemplateTargetURL );
         [ #  # ][ #  # ]
                 [ #  # ]
    1963         [ #  # ]:          0 :             }
    1964                 :            :         }
    1965                 :            : 
    1966         [ #  # ]:          0 :         if ( bRemoveOldTemplateContent )
    1967         [ #  # ]:          0 :             removeContent( aTemplateToRemove );
    1968                 :            : 
    1969                 :            :         // add the template to hierarchy
    1970 [ #  # ][ #  # ]:          0 :         return addEntry( aGroup, rTemplateName, aNewTemplateTargetURL, aMediaType );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1971                 :            :     }
    1972         [ #  # ]:          0 :     catch( Exception& )
    1973                 :            :     {
    1974                 :            :         // the template was not stored
    1975                 :          0 :         return sal_False;
    1976 [ #  # ][ #  # ]:          0 :     }
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1977                 :            : }
    1978                 :            : 
    1979                 :            : //-----------------------------------------------------------------------------
    1980                 :          0 : sal_Bool SfxDocTplService_Impl::addTemplate( const OUString& rGroupName,
    1981                 :            :                                              const OUString& rTemplateName,
    1982                 :            :                                              const OUString& rSourceURL )
    1983                 :            : {
    1984         [ #  # ]:          0 :     ::osl::MutexGuard aGuard( maMutex );
    1985                 :            : 
    1986                 :            :     // Check, whether or not there is a group with this name
    1987                 :            :     // Return false, if there is no group with the given name
    1988 [ #  # ][ #  # ]:          0 :     Content         aGroup, aTemplate, aTargetGroup;
                 [ #  # ]
    1989                 :          0 :     OUString        aGroupURL, aTemplateURL;
    1990         [ #  # ]:          0 :     INetURLObject   aGroupObj( maRootURL );
    1991                 :            : 
    1992                 :            :     aGroupObj.insertName( rGroupName, false,
    1993                 :            :                       INetURLObject::LAST_SEGMENT, true,
    1994         [ #  # ]:          0 :                       INetURLObject::ENCODE_ALL );
    1995         [ #  # ]:          0 :     aGroupURL = aGroupObj.GetMainURL( INetURLObject::NO_DECODE );
    1996                 :            : 
    1997 [ #  # ][ #  # ]:          0 :     if ( ! Content::create( aGroupURL, maCmdEnv, aGroup ) )
    1998                 :          0 :         return sal_False;
    1999                 :            : 
    2000                 :            :     // Check, if there's a template with the given name in this group
    2001                 :            :     // Return false, if there already is a template
    2002                 :            :     aGroupObj.insertName( rTemplateName, false,
    2003                 :            :                       INetURLObject::LAST_SEGMENT, true,
    2004         [ #  # ]:          0 :                       INetURLObject::ENCODE_ALL );
    2005         [ #  # ]:          0 :     aTemplateURL = aGroupObj.GetMainURL( INetURLObject::NO_DECODE );
    2006                 :            : 
    2007 [ #  # ][ #  # ]:          0 :     if ( Content::create( aTemplateURL, maCmdEnv, aTemplate ) )
    2008                 :          0 :         return sal_False;
    2009                 :            : 
    2010                 :            :     // get the target url of the group
    2011                 :          0 :     OUString    aTargetURL;
    2012                 :          0 :     OUString    aPropName( TARGET_DIR_URL  );
    2013                 :          0 :     Any         aValue;
    2014                 :            : 
    2015 [ #  # ][ #  # ]:          0 :     if ( getProperty( aGroup, aPropName, aValue ) )
    2016                 :          0 :         aValue >>= aTargetURL;
    2017                 :            : 
    2018         [ #  # ]:          0 :     if ( aTargetURL.isEmpty() )
    2019                 :            :     {
    2020         [ #  # ]:          0 :         aTargetURL = CreateNewGroupFsys( rGroupName, aGroup );
    2021                 :            : 
    2022         [ #  # ]:          0 :         if ( aTargetURL.isEmpty() )
    2023                 :          0 :             return sal_False;
    2024                 :            :     }
    2025                 :            : 
    2026                 :            :     // Get the content type
    2027                 :          0 :     OUString aTitle, aType, aTargetURL2, aFullName;
    2028                 :            : 
    2029                 :            :     // only StarOffice documents are acceptable
    2030                 :          0 :     sal_Bool bDocHasTitle = sal_False;
    2031 [ #  # ][ #  # ]:          0 :     if( !getTitleFromURL( rSourceURL, aTitle, aType, bDocHasTitle ) )
    2032                 :          0 :         return sal_False;
    2033                 :            : 
    2034         [ #  # ]:          0 :     INetURLObject   aSourceObj( rSourceURL );
    2035         [ #  # ]:          0 :     if ( rTemplateName.equals( aTitle ) )
    2036                 :            :     {
    2037                 :            :         // addTemplate will sometimes be called just to add an entry in the
    2038                 :            :         // hierarchy; the target URL and the source URL will be the same in
    2039                 :            :         // this scenario
    2040                 :            :         // TODO/LATER: get rid of this old hack
    2041                 :            : 
    2042         [ #  # ]:          0 :         INetURLObject   aTargetObj( aTargetURL );
    2043                 :            : 
    2044                 :            :         aTargetObj.insertName( rTemplateName, false,
    2045                 :            :                       INetURLObject::LAST_SEGMENT, true,
    2046         [ #  # ]:          0 :                       INetURLObject::ENCODE_ALL );
    2047 [ #  # ][ #  # ]:          0 :         aTargetObj.setExtension( aSourceObj.getExtension() );
    2048                 :            : 
    2049         [ #  # ]:          0 :         aTargetURL2 = aTargetObj.GetMainURL( INetURLObject::NO_DECODE );
    2050                 :            : 
    2051         [ #  # ]:          0 :         if ( aTargetURL2 == rSourceURL )
    2052 [ #  # ][ #  # ]:          0 :             return addEntry( aGroup, rTemplateName, aTargetURL2, aType );
                 [ #  # ]
    2053                 :            :     }
    2054                 :            : 
    2055                 :            :     // copy the template into the new group (targeturl)
    2056                 :            : 
    2057         [ #  # ]:          0 :     INetURLObject aTmpURL( aSourceObj );
    2058         [ #  # ]:          0 :     aTmpURL.CutExtension();
    2059         [ #  # ]:          0 :     ::rtl::OUString aPattern = aTmpURL.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
    2060                 :            : 
    2061 [ #  # ][ #  # ]:          0 :     ::rtl::OUString aNewTemplateTargetURL = CreateNewUniqueFileWithPrefix( aTargetURL, aPattern, aSourceObj.getExtension() );
    2062         [ #  # ]:          0 :     INetURLObject aNewTemplateTargetObj( aNewTemplateTargetURL );
    2063         [ #  # ]:          0 :     ::rtl::OUString aNewTemplateTargetName = aNewTemplateTargetObj.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
    2064 [ #  # ][ #  # ]:          0 :     if ( aNewTemplateTargetURL.isEmpty() || aNewTemplateTargetName.isEmpty() )
                 [ #  # ]
    2065                 :          0 :         return sal_False;
    2066                 :            : 
    2067                 :            :     // get access to source file
    2068         [ #  # ]:          0 :     Content aSourceContent;
    2069                 :          0 :     uno::Reference < ucb::XCommandEnvironment > xEnv;
    2070         [ #  # ]:          0 :     INetURLObject   aSourceURL( rSourceURL );
    2071 [ #  # ][ #  # ]:          0 :     if( ! Content::create( aSourceURL.GetMainURL( INetURLObject::NO_DECODE ), xEnv, aSourceContent ) )
                 [ #  # ]
    2072                 :          0 :         return sal_False;
    2073                 :            : 
    2074 [ #  # ][ #  # ]:          0 :     if( ! Content::create( aTargetURL, xEnv, aTargetGroup ) )
    2075                 :          0 :         return sal_False;
    2076                 :            : 
    2077                 :            :     // transfer source file
    2078                 :            :     try
    2079                 :            :     {
    2080         [ #  # ]:          0 :         if( ! aTargetGroup.transferContent( aSourceContent,
    2081                 :            :                                                 InsertOperation_COPY,
    2082                 :            :                                                 aNewTemplateTargetName,
    2083         [ #  # ]:          0 :                                                 NameClash::OVERWRITE ) )
    2084                 :          0 :             return sal_False;
    2085                 :            : 
    2086                 :            :         // allow to edit the added template
    2087         [ #  # ]:          0 :         Content aResultContent;
    2088 [ #  # ][ #  # ]:          0 :         if ( Content::create( aNewTemplateTargetURL, xEnv, aResultContent ) )
    2089                 :            :         {
    2090                 :          0 :             ::rtl::OUString aPropertyName( "IsReadOnly"  );
    2091                 :          0 :             uno::Any aProperty;
    2092                 :          0 :             sal_Bool bReadOnly = sal_False;
    2093 [ #  # ][ #  # ]:          0 :             if ( getProperty( aResultContent, aPropertyName, aProperty ) && ( aProperty >>= bReadOnly ) && bReadOnly )
         [ #  # ][ #  # ]
                 [ #  # ]
    2094 [ #  # ][ #  # ]:          0 :                 setProperty( aResultContent, aPropertyName, uno::makeAny( (sal_Bool)sal_False ) );
    2095   [ #  #  #  #  :          0 :         }
                      # ]
    2096                 :            :     }
    2097         [ #  # ]:          0 :     catch ( ContentCreationException& )
    2098                 :          0 :     { return sal_False; }
    2099         [ #  # ]:          0 :     catch ( Exception& )
    2100                 :          0 :     { return sal_False; }
    2101                 :            : 
    2102                 :            : 
    2103                 :            :     // either the document has title and it is the same as requested, or we have to set it
    2104 [ #  # ][ #  # ]:          0 :     sal_Bool bCorrectTitle = ( bDocHasTitle && aTitle.equals( rTemplateName ) );
    2105         [ #  # ]:          0 :     if ( !bCorrectTitle )
    2106                 :            :     {
    2107         [ #  # ]:          0 :         if ( !bDocHasTitle )
    2108                 :            :         {
    2109         [ #  # ]:          0 :             INetURLObject aNewTmpObj( aNewTemplateTargetObj );
    2110         [ #  # ]:          0 :             aNewTmpObj.CutExtension();
    2111 [ #  # ][ #  # ]:          0 :             bCorrectTitle = ( aNewTmpObj.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET ).equals( rTemplateName ) );
    2112                 :            :         }
    2113                 :            : 
    2114         [ #  # ]:          0 :         if ( !bCorrectTitle )
    2115         [ #  # ]:          0 :             bCorrectTitle = setTitleForURL( aNewTemplateTargetURL, rTemplateName );
    2116                 :            :     }
    2117                 :            : 
    2118         [ #  # ]:          0 :     if ( bCorrectTitle )
    2119                 :            :     {
    2120                 :            :         // create a new entry in the hierarchy
    2121         [ #  # ]:          0 :         return addEntry( aGroup, rTemplateName, aNewTemplateTargetURL, aType );
    2122                 :            :     }
    2123                 :            : 
    2124                 :            :     // TODO/LATER: The user could be notified here that the renaming has failed
    2125                 :            :     // create a new entry in the hierarchy
    2126         [ #  # ]:          0 :     addEntry( aGroup, aTitle, aNewTemplateTargetURL, aType );
    2127 [ #  # ][ #  # ]:          0 :     return sal_False;
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    2128                 :            : }
    2129                 :            : 
    2130                 :            : //-----------------------------------------------------------------------------
    2131                 :          0 : sal_Bool SfxDocTplService_Impl::removeTemplate( const OUString& rGroupName,
    2132                 :            :                                                 const OUString& rTemplateName )
    2133                 :            : {
    2134         [ #  # ]:          0 :     ::osl::MutexGuard aGuard( maMutex );
    2135                 :            : 
    2136                 :            :     // Check, whether or not there is a group with this name
    2137                 :            :     // Return false, if there is no group with the given name
    2138 [ #  # ][ #  # ]:          0 :     Content         aGroup, aTemplate;
    2139                 :          0 :     OUString        aGroupURL, aTemplateURL;
    2140         [ #  # ]:          0 :     INetURLObject   aGroupObj( maRootURL );
    2141                 :            : 
    2142                 :            :     aGroupObj.insertName( rGroupName, false,
    2143                 :            :                       INetURLObject::LAST_SEGMENT, true,
    2144         [ #  # ]:          0 :                       INetURLObject::ENCODE_ALL );
    2145         [ #  # ]:          0 :     aGroupURL = aGroupObj.GetMainURL( INetURLObject::NO_DECODE );
    2146                 :            : 
    2147 [ #  # ][ #  # ]:          0 :     if ( ! Content::create( aGroupURL, maCmdEnv, aGroup ) )
    2148                 :          0 :         return sal_False;
    2149                 :            : 
    2150                 :            :     // Check, if there's a template with the given name in this group
    2151                 :            :     // Return false, if there is no template
    2152                 :            :     aGroupObj.insertName( rTemplateName, false,
    2153                 :            :                       INetURLObject::LAST_SEGMENT, true,
    2154         [ #  # ]:          0 :                       INetURLObject::ENCODE_ALL );
    2155         [ #  # ]:          0 :     aTemplateURL = aGroupObj.GetMainURL( INetURLObject::NO_DECODE );
    2156                 :            : 
    2157 [ #  # ][ #  # ]:          0 :     if ( !Content::create( aTemplateURL, maCmdEnv, aTemplate ) )
    2158                 :          0 :         return sal_False;
    2159                 :            : 
    2160                 :            :     // get the target URL from the template
    2161                 :          0 :     OUString    aTargetURL;
    2162                 :          0 :     OUString    aPropName( TARGET_URL  );
    2163                 :          0 :     Any         aValue;
    2164                 :            : 
    2165 [ #  # ][ #  # ]:          0 :     if ( getProperty( aTemplate, aPropName, aValue ) )
    2166                 :          0 :         aValue >>= aTargetURL;
    2167                 :            : 
    2168                 :            :     // delete the target template
    2169         [ #  # ]:          0 :     if ( !aTargetURL.isEmpty() )
    2170                 :            :     {
    2171 [ #  # ][ #  # ]:          0 :         if ( !maTemplateDirs.getLength()
                 [ #  # ]
    2172 [ #  # ][ #  # ]:          0 :           || !::utl::UCBContentHelper::IsSubPath( maTemplateDirs[ maTemplateDirs.getLength() - 1 ], aTargetURL ) )
    2173                 :          0 :             return sal_False;
    2174                 :            : 
    2175         [ #  # ]:          0 :         removeContent( aTargetURL );
    2176                 :            :     }
    2177                 :            : 
    2178                 :            :     // delete the template entry
    2179 [ #  # ][ #  # ]:          0 :     return removeContent( aTemplate );
         [ #  # ][ #  # ]
                 [ #  # ]
    2180                 :            : }
    2181                 :            : 
    2182                 :            : //-----------------------------------------------------------------------------
    2183                 :          0 : sal_Bool SfxDocTplService_Impl::renameTemplate( const OUString& rGroupName,
    2184                 :            :                                                 const OUString& rOldName,
    2185                 :            :                                                 const OUString& rNewName )
    2186                 :            : {
    2187         [ #  # ]:          0 :     ::osl::MutexGuard aGuard( maMutex );
    2188                 :            : 
    2189                 :            :     // Check, whether or not there is a group with this name
    2190                 :            :     // Return false, if there is no group with the given name
    2191 [ #  # ][ #  # ]:          0 :     Content         aGroup, aTemplate;
    2192                 :          0 :     OUString        aGroupURL, aTemplateURL;
    2193         [ #  # ]:          0 :     INetURLObject   aGroupObj( maRootURL );
    2194                 :            : 
    2195                 :            :     aGroupObj.insertName( rGroupName, false,
    2196                 :            :                       INetURLObject::LAST_SEGMENT, true,
    2197         [ #  # ]:          0 :                       INetURLObject::ENCODE_ALL );
    2198         [ #  # ]:          0 :     aGroupURL = aGroupObj.GetMainURL( INetURLObject::NO_DECODE );
    2199                 :            : 
    2200 [ #  # ][ #  # ]:          0 :     if ( ! Content::create( aGroupURL, maCmdEnv, aGroup ) )
    2201                 :          0 :         return sal_False;
    2202                 :            : 
    2203                 :            :     // Check, if there's a template with the new name in this group
    2204                 :            :     // Return false, if there is one
    2205                 :            :     aGroupObj.insertName( rNewName, false,
    2206                 :            :                       INetURLObject::LAST_SEGMENT, true,
    2207         [ #  # ]:          0 :                       INetURLObject::ENCODE_ALL );
    2208         [ #  # ]:          0 :     aTemplateURL = aGroupObj.GetMainURL( INetURLObject::NO_DECODE );
    2209                 :            : 
    2210 [ #  # ][ #  # ]:          0 :     if ( Content::create( aTemplateURL, maCmdEnv, aTemplate ) )
    2211                 :          0 :         return sal_False;
    2212                 :            : 
    2213                 :            :     // Check, if there's a template with the old name in this group
    2214                 :            :     // Return false, if there is no template
    2215         [ #  # ]:          0 :     aGroupObj.removeSegment();
    2216                 :            :     aGroupObj.insertName( rOldName, false,
    2217                 :            :                       INetURLObject::LAST_SEGMENT, true,
    2218         [ #  # ]:          0 :                       INetURLObject::ENCODE_ALL );
    2219         [ #  # ]:          0 :     aTemplateURL = aGroupObj.GetMainURL( INetURLObject::NO_DECODE );
    2220                 :            : 
    2221 [ #  # ][ #  # ]:          0 :     if ( !Content::create( aTemplateURL, maCmdEnv, aTemplate ) )
    2222                 :          0 :         return sal_False;
    2223                 :            : 
    2224                 :          0 :     OUString    aTemplateTargetURL;
    2225                 :          0 :     OUString    aTargetProp( TARGET_URL  );
    2226                 :          0 :     Any         aTargetValue;
    2227                 :            : 
    2228 [ #  # ][ #  # ]:          0 :     if ( getProperty( aTemplate, aTargetProp, aTargetValue ) )
    2229                 :          0 :         aTargetValue >>= aTemplateTargetURL;
    2230                 :            : 
    2231 [ #  # ][ #  # ]:          0 :     if ( !setTitleForURL( aTemplateTargetURL, rNewName ) )
    2232                 :          0 :         return sal_False;
    2233                 :            : 
    2234                 :            :     // rename the template entry in the cache
    2235                 :          0 :     OUString    aTitleProp( TITLE  );
    2236                 :          0 :     Any         aTitleValue;
    2237         [ #  # ]:          0 :     aTitleValue <<= rNewName;
    2238                 :            : 
    2239 [ #  # ][ #  # ]:          0 :     return setProperty( aTemplate, aTitleProp, aTitleValue );
         [ #  # ][ #  # ]
                 [ #  # ]
    2240                 :            : }
    2241                 :            : 
    2242                 :            : //-----------------------------------------------------------------------------
    2243                 :            : 
    2244 [ +  - ][ +  - ]:        576 : SFX_IMPL_XSERVICEINFO( SfxDocTplService, TEMPLATE_SERVICE_NAME, TEMPLATE_IMPLEMENTATION_NAME )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    2245 [ +  - ][ +  - ]:          8 : SFX_IMPL_SINGLEFACTORY( SfxDocTplService )
    2246                 :            : 
    2247                 :            : //-----------------------------------------------------------------------------
    2248                 :         14 : SfxDocTplService::SfxDocTplService( const uno::Reference< XMultiServiceFactory >& xFactory )
    2249                 :            : {
    2250 [ +  - ][ +  - ]:         14 :     pImp = new SfxDocTplService_Impl( xFactory );
    2251                 :         14 : }
    2252                 :            : 
    2253                 :            : //-----------------------------------------------------------------------------
    2254                 :            : 
    2255                 :         11 : SfxDocTplService::~SfxDocTplService()
    2256                 :            : {
    2257 [ +  - ][ +  - ]:         11 :     delete pImp;
    2258         [ -  + ]:         22 : }
    2259                 :            : 
    2260                 :            : //-----------------------------------------------------------------------------
    2261                 :            : //--- XLocalizable ---
    2262                 :            : //-----------------------------------------------------------------------------
    2263                 :            : 
    2264                 :         14 : Locale SAL_CALL SfxDocTplService::getLocale()
    2265                 :            :     throw( RUNTIMEEXCEPTION )
    2266                 :            : {
    2267                 :         14 :     return pImp->getLocale();
    2268                 :            : }
    2269                 :            : 
    2270                 :            : //-----------------------------------------------------------------------------
    2271                 :            : 
    2272                 :          0 : void SAL_CALL SfxDocTplService::setLocale( const Locale & rLocale )
    2273                 :            :     throw( RUNTIMEEXCEPTION )
    2274                 :            : {
    2275                 :          0 :     pImp->setLocale( rLocale );
    2276                 :          0 : }
    2277                 :            : 
    2278                 :            : //-----------------------------------------------------------------------------
    2279                 :            : //--- XDocumentTemplates ---
    2280                 :            : //-----------------------------------------------------------------------------
    2281                 :         14 : uno::Reference< XCONTENT > SAL_CALL SfxDocTplService::getContent()
    2282                 :            :     throw( RUNTIMEEXCEPTION )
    2283                 :            : {
    2284         [ +  + ]:         14 :     if ( pImp->init() )
    2285         [ +  - ]:          2 :         return pImp->getContent().get();
    2286                 :            :     else
    2287                 :         14 :         return NULL;
    2288                 :            : }
    2289                 :            : 
    2290                 :            : //-----------------------------------------------------------------------------
    2291                 :          0 : sal_Bool SAL_CALL SfxDocTplService::storeTemplate( const OUString& GroupName,
    2292                 :            :                                                    const OUString& TemplateName,
    2293                 :            :                                                    const uno::Reference< XSTORABLE >& Storable )
    2294                 :            :     throw( RUNTIMEEXCEPTION )
    2295                 :            : {
    2296         [ #  # ]:          0 :     if ( pImp->init() )
    2297                 :          0 :         return pImp->storeTemplate( GroupName, TemplateName, Storable );
    2298                 :            :     else
    2299                 :          0 :         return sal_False;
    2300                 :            : }
    2301                 :            : 
    2302                 :            : //-----------------------------------------------------------------------------
    2303                 :          0 : sal_Bool SAL_CALL SfxDocTplService::addTemplate( const OUString& rGroupName,
    2304                 :            :                                                  const OUString& rTemplateName,
    2305                 :            :                                                  const OUString& rSourceURL )
    2306                 :            :     throw( RUNTIMEEXCEPTION )
    2307                 :            : {
    2308         [ #  # ]:          0 :     if ( pImp->init() )
    2309                 :          0 :         return pImp->addTemplate( rGroupName, rTemplateName, rSourceURL );
    2310                 :            :     else
    2311                 :          0 :         return sal_False;
    2312                 :            : }
    2313                 :            : 
    2314                 :            : //-----------------------------------------------------------------------------
    2315                 :          0 : sal_Bool SAL_CALL SfxDocTplService::removeTemplate( const OUString& rGroupName,
    2316                 :            :                                                     const OUString& rTemplateName )
    2317                 :            :     throw( RUNTIMEEXCEPTION )
    2318                 :            : {
    2319         [ #  # ]:          0 :     if ( pImp->init() )
    2320                 :          0 :         return pImp->removeTemplate( rGroupName, rTemplateName );
    2321                 :            :     else
    2322                 :          0 :         return sal_False;
    2323                 :            : }
    2324                 :            : 
    2325                 :            : //-----------------------------------------------------------------------------
    2326                 :          0 : sal_Bool SAL_CALL SfxDocTplService::renameTemplate( const OUString& rGroupName,
    2327                 :            :                                                     const OUString& rOldName,
    2328                 :            :                                                     const OUString& rNewName )
    2329                 :            :     throw( RUNTIMEEXCEPTION )
    2330                 :            : {
    2331         [ #  # ]:          0 :     if ( rOldName == rNewName )
    2332                 :          0 :         return sal_True;
    2333                 :            : 
    2334         [ #  # ]:          0 :     if ( pImp->init() )
    2335                 :          0 :         return pImp->renameTemplate( rGroupName, rOldName, rNewName );
    2336                 :            :     else
    2337                 :          0 :         return sal_False;
    2338                 :            : }
    2339                 :            : 
    2340                 :            : //-----------------------------------------------------------------------------
    2341                 :          0 : sal_Bool SAL_CALL SfxDocTplService::addGroup( const OUString& rGroupName )
    2342                 :            :     throw( RUNTIMEEXCEPTION )
    2343                 :            : {
    2344         [ #  # ]:          0 :     if ( pImp->init() )
    2345                 :          0 :         return pImp->addGroup( rGroupName );
    2346                 :            :     else
    2347                 :          0 :         return sal_False;
    2348                 :            : }
    2349                 :            : 
    2350                 :            : //-----------------------------------------------------------------------------
    2351                 :          0 : sal_Bool SAL_CALL SfxDocTplService::removeGroup( const OUString& rGroupName )
    2352                 :            :     throw( RUNTIMEEXCEPTION )
    2353                 :            : {
    2354         [ #  # ]:          0 :     if ( pImp->init() )
    2355                 :          0 :         return pImp->removeGroup( rGroupName );
    2356                 :            :     else
    2357                 :          0 :         return sal_False;
    2358                 :            : }
    2359                 :            : 
    2360                 :            : //-----------------------------------------------------------------------------
    2361                 :          0 : sal_Bool SAL_CALL SfxDocTplService::renameGroup( const OUString& rOldName,
    2362                 :            :                                                  const OUString& rNewName )
    2363                 :            :     throw( RUNTIMEEXCEPTION )
    2364                 :            : {
    2365         [ #  # ]:          0 :     if ( rOldName == rNewName )
    2366                 :          0 :         return sal_True;
    2367                 :            : 
    2368         [ #  # ]:          0 :     if ( pImp->init() )
    2369                 :          0 :         return pImp->renameGroup( rOldName, rNewName );
    2370                 :            :     else
    2371                 :          0 :         return sal_False;
    2372                 :            : }
    2373                 :            : 
    2374                 :            : //-----------------------------------------------------------------------------
    2375                 :          0 : void SAL_CALL SfxDocTplService::update()
    2376                 :            :     throw( RUNTIMEEXCEPTION )
    2377                 :            : {
    2378         [ #  # ]:          0 :     if ( pImp->init() )
    2379                 :          0 :         pImp->update( sal_True );
    2380                 :          0 : }
    2381                 :            : 
    2382                 :            : //------------------------------------------------------------------------
    2383                 :            : 
    2384                 :          0 : Updater_Impl::Updater_Impl( SfxDocTplService_Impl* pTemplates )
    2385                 :            : {
    2386                 :          0 :     mpDocTemplates = pTemplates;
    2387                 :          0 : }
    2388                 :            : 
    2389                 :            : //------------------------------------------------------------------------
    2390                 :          0 : Updater_Impl::~Updater_Impl()
    2391                 :            : {
    2392         [ #  # ]:          0 : }
    2393                 :            : 
    2394                 :            : //------------------------------------------------------------------------
    2395                 :          0 : void SAL_CALL Updater_Impl::run()
    2396                 :            : {
    2397                 :          0 :     mpDocTemplates->doUpdate();
    2398                 :          0 : }
    2399                 :            : 
    2400                 :            : //------------------------------------------------------------------------
    2401                 :          0 : void SAL_CALL Updater_Impl::onTerminated()
    2402                 :            : {
    2403                 :          0 :     mpDocTemplates->finished();
    2404         [ #  # ]:          0 :     delete this;
    2405                 :          0 : }
    2406                 :            : 
    2407                 :            : //-----------------------------------------------------------------------------
    2408                 :          2 : WaitWindow_Impl::WaitWindow_Impl()
    2409 [ +  - ][ +  - ]:          2 :     : WorkWindow( NULL, WB_BORDER | WB_3DLOOK )
    2410                 :            : {
    2411         [ +  - ]:          2 :     Rectangle aRect = Rectangle( 0, 0, 300, 30000 );
    2412                 :          2 :     _nTextStyle = TEXT_DRAW_CENTER | TEXT_DRAW_VCENTER | TEXT_DRAW_WORDBREAK | TEXT_DRAW_MULTILINE;
    2413 [ +  - ][ +  - ]:          2 :     _aText = SfxResId( RID_CNT_STR_WAITING ).toString();
                 [ +  - ]
    2414         [ +  - ]:          2 :     _aRect = GetTextRect( aRect, _aText, _nTextStyle );
    2415                 :          2 :     aRect = _aRect;
    2416                 :          2 :     aRect.Right() += 2*X_OFFSET;
    2417                 :          2 :     aRect.Bottom() += 2*Y_OFFSET;
    2418                 :          2 :     _aRect.SetPos( Point( X_OFFSET, Y_OFFSET ) );
    2419 [ +  - ][ +  - ]:          2 :     SetOutputSizePixel( aRect.GetSize() );
    2420         [ +  - ]:          2 :     Show();
    2421         [ +  - ]:          2 :     Update();
    2422         [ +  - ]:          2 :     Flush();
    2423                 :          2 : }
    2424                 :            : 
    2425                 :            : //-----------------------------------------------------------------------------
    2426         [ +  - ]:          2 : WaitWindow_Impl::~WaitWindow_Impl()
    2427                 :            : {
    2428         [ +  - ]:          2 :     Hide();
    2429         [ -  + ]:          4 : }
    2430                 :            : 
    2431                 :            : //-----------------------------------------------------------------------------
    2432                 :          2 : void WaitWindow_Impl::Paint( const Rectangle& /*rRect*/ )
    2433                 :            : {
    2434                 :          2 :     DrawText( _aRect, _aText, _nTextStyle );
    2435                 :          2 : }
    2436                 :            : 
    2437                 :            : //-----------------------------------------------------------------------------
    2438                 :          0 : void SfxDocTplService_Impl::addHierGroup( GroupList_Impl& rList,
    2439                 :            :                                           const OUString& rTitle,
    2440                 :            :                                           const OUString& rOwnURL )
    2441                 :            : {
    2442                 :            :     // now get the content of the Group
    2443         [ #  # ]:          0 :     Content                 aContent;
    2444                 :          0 :     uno::Reference< XResultSet > xResultSet;
    2445         [ #  # ]:          0 :     Sequence< OUString >    aProps(3);
    2446                 :            : 
    2447         [ #  # ]:          0 :     aProps[0] = OUString(TITLE );
    2448         [ #  # ]:          0 :     aProps[1] = OUString(TARGET_URL );
    2449         [ #  # ]:          0 :     aProps[2] = OUString(PROPERTY_TYPE );
    2450                 :            : 
    2451                 :            :     try
    2452                 :            :     {
    2453 [ #  # ][ #  # ]:          0 :         aContent = Content( rOwnURL, maCmdEnv );
                 [ #  # ]
    2454                 :          0 :         ResultSetInclude eInclude = INCLUDE_DOCUMENTS_ONLY;
    2455 [ #  # ][ #  # ]:          0 :         xResultSet = aContent.createCursor( aProps, eInclude );
              [ #  #  # ]
    2456                 :            :     }
    2457         [ #  # ]:          0 :     catch ( ContentCreationException& )
    2458                 :            :     {
    2459                 :            :         SAL_WARN( "sfx2.doc", "addHierGroup: ContentCreationException" );
    2460                 :            :     }
    2461         [ #  # ]:          0 :     catch ( Exception& ) {}
    2462                 :            : 
    2463         [ #  # ]:          0 :     if ( xResultSet.is() )
    2464                 :            :     {
    2465 [ #  # ][ #  # ]:          0 :         GroupData_Impl *pGroup = new GroupData_Impl( rTitle );
    2466                 :          0 :         pGroup->setHierarchy( sal_True );
    2467                 :          0 :         pGroup->setHierarchyURL( rOwnURL );
    2468         [ #  # ]:          0 :         rList.push_back( pGroup );
    2469                 :            : 
    2470         [ #  # ]:          0 :         uno::Reference< XContentAccess > xContentAccess( xResultSet, UNO_QUERY );
    2471         [ #  # ]:          0 :         uno::Reference< XRow > xRow( xResultSet, UNO_QUERY );
    2472                 :            : 
    2473                 :            :         try
    2474                 :            :         {
    2475 [ #  # ][ #  # ]:          0 :             while ( xResultSet->next() )
                 [ #  # ]
    2476                 :            :             {
    2477                 :          0 :                 sal_Bool             bUpdateType = sal_False;
    2478                 :            :                 DocTemplates_EntryData_Impl  *pData;
    2479                 :            : 
    2480 [ #  # ][ #  # ]:          0 :                 OUString aTitle( xRow->getString( 1 ) );
    2481 [ #  # ][ #  # ]:          0 :                 OUString aTargetDir( xRow->getString( 2 ) );
    2482 [ #  # ][ #  # ]:          0 :                 OUString aType( xRow->getString( 3 ) );
    2483 [ #  # ][ #  # ]:          0 :                 OUString aHierURL = xContentAccess->queryContentIdentifierString();
    2484                 :            : 
    2485         [ #  # ]:          0 :                 if ( aType.isEmpty() )
    2486                 :            :                 {
    2487                 :          0 :                     OUString aTmpTitle;
    2488                 :            : 
    2489                 :          0 :                     sal_Bool bDocHasTitle = sal_False;
    2490 [ #  # ][ #  # ]:          0 :                     if( !getTitleFromURL( aTargetDir, aTmpTitle, aType, bDocHasTitle ) )
    2491                 :            :                     {
    2492                 :            :                         SAL_WARN( "sfx2.doc", "addHierGroup(): template of alien format" );
    2493                 :          0 :                         continue;
    2494                 :            :                     }
    2495                 :            : 
    2496         [ #  # ]:          0 :                     if ( !aType.isEmpty() )
    2497         [ #  # ]:          0 :                         bUpdateType = sal_True;
    2498                 :            :                 }
    2499                 :            : 
    2500         [ #  # ]:          0 :                 pData = pGroup->addEntry( aTitle, aTargetDir, aType, aHierURL );
    2501         [ #  # ]:          0 :                 pData->setUpdateType( bUpdateType );
    2502 [ #  # ][ #  # ]:          0 :             }
         [ #  # ][ #  # ]
    2503                 :            :         }
    2504         [ #  # ]:          0 :         catch ( Exception& ) {}
    2505 [ #  # ][ #  # ]:          0 :     }
    2506                 :          0 : }
    2507                 :            : 
    2508                 :            : //-----------------------------------------------------------------------------
    2509                 :         16 : void SfxDocTplService_Impl::addFsysGroup( GroupList_Impl& rList,
    2510                 :            :                                           const OUString& rTitle,
    2511                 :            :                                           const OUString& rUITitle,
    2512                 :            :                                           const OUString& rOwnURL,
    2513                 :            :                                           sal_Bool bWriteableGroup )
    2514                 :            : {
    2515                 :         16 :     ::rtl::OUString aTitle;
    2516                 :            : 
    2517         [ +  + ]:         16 :     if ( rUITitle.isEmpty() )
    2518                 :            :     {
    2519                 :            :         // reserved FS names that should not be used
    2520         [ +  + ]:          8 :         if ( rTitle.compareToAscii( "wizard" ) == 0 )
    2521                 :            :             return;
    2522         [ +  + ]:          6 :         else if ( rTitle.compareToAscii( "internal" ) == 0 )
    2523                 :            :             return;
    2524                 :            : 
    2525         [ +  - ]:          4 :         aTitle = getLongName( rTitle );
    2526                 :            :     }
    2527                 :            :     else
    2528                 :          8 :         aTitle = rUITitle;
    2529                 :            : 
    2530         [ -  + ]:         12 :     if ( aTitle.isEmpty() )
    2531                 :            :         return;
    2532                 :            : 
    2533                 :         12 :     GroupData_Impl* pGroup = NULL;
    2534         [ +  + ]:         18 :     for ( size_t i = 0, n = rList.size(); i < n; ++i )
    2535                 :            :     {
    2536         [ +  + ]:         12 :         if ( rList[ i ]->getTitle() == aTitle )
    2537                 :            :         {
    2538                 :          6 :             pGroup = rList[ i ];
    2539                 :          6 :             break;
    2540                 :            :         }
    2541                 :            :     }
    2542                 :            : 
    2543         [ +  + ]:         12 :     if ( !pGroup )
    2544                 :            :     {
    2545 [ +  - ][ +  - ]:          6 :         pGroup = new GroupData_Impl( aTitle );
    2546         [ +  - ]:          6 :         rList.push_back( pGroup );
    2547                 :            :     }
    2548                 :            : 
    2549         [ +  + ]:         12 :     if ( bWriteableGroup )
    2550                 :          2 :         pGroup->setTargetURL( rOwnURL );
    2551                 :            : 
    2552                 :         12 :     pGroup->setInUse();
    2553                 :            : 
    2554                 :            :     // now get the content of the Group
    2555         [ +  - ]:         12 :     Content                 aContent;
    2556                 :         12 :     uno::Reference< XResultSet > xResultSet;
    2557         [ +  - ]:         12 :     Sequence< OUString >    aProps(1);
    2558         [ +  - ]:         12 :     aProps[0] = OUString(TITLE );
    2559                 :            : 
    2560                 :            :     try
    2561                 :            :     {
    2562                 :            :         // this method is only used during checking of the available template-folders
    2563                 :            :         // that should happen quietly
    2564                 :         12 :         uno::Reference< XCommandEnvironment > aQuietEnv;
    2565 [ +  - ][ +  - ]:         12 :         aContent = Content( rOwnURL, aQuietEnv );
                 [ +  - ]
    2566                 :         12 :         ResultSetInclude eInclude = INCLUDE_DOCUMENTS_ONLY;
    2567 [ +  - ][ +  - ]:         12 :         xResultSet = aContent.createCursor( aProps, eInclude );
                 [ #  # ]
    2568                 :            :     }
    2569         [ #  # ]:          0 :     catch ( Exception& ) {}
    2570                 :            : 
    2571         [ +  - ]:         12 :     if ( xResultSet.is() )
    2572                 :            :     {
    2573         [ +  - ]:         12 :         uno::Reference< XContentAccess > xContentAccess( xResultSet, UNO_QUERY );
    2574         [ +  - ]:         12 :         uno::Reference< XRow > xRow( xResultSet, UNO_QUERY );
    2575                 :            : 
    2576                 :            :         try
    2577                 :            :         {
    2578 [ +  - ][ +  - ]:         32 :             while ( xResultSet->next() )
                 [ +  + ]
    2579                 :            :             {
    2580 [ +  - ][ +  - ]:         20 :                 OUString aChildTitle( xRow->getString( 1 ) );
    2581 [ +  - ][ +  - ]:         20 :                 OUString aTargetURL = xContentAccess->queryContentIdentifierString();
    2582                 :         20 :                 OUString aType;
    2583                 :         20 :                 OUString aHierURL;
    2584                 :            : 
    2585 [ -  + ][ -  + ]:         20 :                 if ( aChildTitle.compareToAscii( "sfx.tlx" ) == 0 || aChildTitle == "groupuinames.xml" )
                 [ +  - ]
    2586                 :          0 :                     continue;
    2587                 :            : 
    2588                 :            :                 // only StarOffice templates are accepted
    2589                 :         20 :                 sal_Bool bDocHasTitle = sal_False;
    2590 [ +  - ][ -  + ]:         20 :                 if( !getTitleFromURL( aTargetURL, aChildTitle, aType, bDocHasTitle ) )
    2591                 :          0 :                     continue;
    2592                 :            : 
    2593 [ +  - ][ -  + ]:         40 :                 pGroup->addEntry( aChildTitle, aTargetURL, aType, aHierURL );
    2594 [ -  + ][ -  + ]:         40 :             }
         [ +  - ][ #  # ]
    2595                 :            :         }
    2596         [ #  # ]:         12 :         catch ( Exception& ) {}
    2597 [ +  - ][ +  - ]:         16 :     }
                 [ +  + ]
    2598                 :            : }
    2599                 :            : 
    2600                 :            : // -----------------------------------------------------------------------
    2601                 :         10 : void SfxDocTplService_Impl::createFromContent( GroupList_Impl& rList,
    2602                 :            :                                                Content &rContent,
    2603                 :            :                                                sal_Bool bHierarchy,
    2604                 :            :                                                sal_Bool bWriteableContent )
    2605                 :            : {
    2606 [ +  - ][ +  - ]:         10 :     OUString aTargetURL = rContent.get()->getIdentifier()->getContentIdentifier();
         [ +  - ][ +  - ]
                 [ +  - ]
    2607                 :            : 
    2608                 :            :     // when scanning the file system, we have to add the 'standard' group, too
    2609         [ +  + ]:         10 :     if ( ! bHierarchy )
    2610                 :            :     {
    2611         [ +  - ]:          8 :         OUString aUIStdTitle = getLongName( OUString( STANDARD_FOLDER  ) );
    2612         [ +  - ]:          8 :         addFsysGroup( rList, ::rtl::OUString(), aUIStdTitle, aTargetURL, bWriteableContent );
    2613                 :            :     }
    2614                 :            : 
    2615                 :            :     // search for predefined UI names
    2616         [ +  - ]:         10 :     INetURLObject aLayerObj( aTargetURL );
    2617                 :            : 
    2618                 :            :     // TODO/LATER: Use hashmap in future
    2619         [ +  - ]:         10 :     uno::Sequence< beans::StringPair > aUINames;
    2620         [ +  + ]:         10 :     if ( !bHierarchy )
    2621 [ +  - ][ +  - ]:          8 :         aUINames = ReadUINamesForTemplateDir_Impl( aLayerObj.GetMainURL( INetURLObject::NO_DECODE ) );
         [ +  - ][ +  - ]
    2622                 :            : 
    2623                 :         10 :     uno::Reference< XResultSet > xResultSet;
    2624         [ +  - ]:         10 :     Sequence< OUString > aProps(1);
    2625         [ +  - ]:         10 :     aProps[0] = OUString(TITLE );
    2626                 :            : 
    2627                 :            :     try
    2628                 :            :     {
    2629                 :         10 :         ResultSetInclude eInclude = INCLUDE_FOLDERS_ONLY;
    2630 [ +  - ][ #  # ]:         10 :         xResultSet = rContent.createCursor( aProps, eInclude );
                 [ +  - ]
    2631                 :            :     }
    2632         [ #  # ]:          0 :     catch ( Exception& ) {}
    2633                 :            : 
    2634         [ +  - ]:         10 :     if ( xResultSet.is() )
    2635                 :            :     {
    2636         [ +  - ]:         10 :         uno::Reference< XContentAccess > xContentAccess( xResultSet, UNO_QUERY );
    2637         [ +  - ]:         10 :         uno::Reference< XRow > xRow( xResultSet, UNO_QUERY );
    2638                 :            : 
    2639                 :            :         try
    2640                 :            :         {
    2641 [ +  - ][ +  - ]:         18 :             while ( xResultSet->next() )
                 [ +  + ]
    2642                 :            :             {
    2643                 :            :                 // TODO/LATER: clarify the encoding of the Title
    2644 [ +  - ][ +  - ]:          8 :                 OUString aTitle( xRow->getString( 1 ) );
    2645 [ +  - ][ +  - ]:          8 :                 OUString aTargetSubfolderURL( xContentAccess->queryContentIdentifierString() );
    2646                 :            : 
    2647         [ -  + ]:          8 :                 if ( bHierarchy )
    2648         [ #  # ]:          0 :                     addHierGroup( rList, aTitle, aTargetSubfolderURL );
    2649                 :            :                 else
    2650                 :            :                 {
    2651                 :          8 :                     ::rtl::OUString aUITitle;
    2652         [ -  + ]:          8 :                     for ( sal_Int32 nInd = 0; nInd < aUINames.getLength(); nInd++ )
    2653 [ #  # ][ #  # ]:          0 :                         if ( aUINames[nInd].First.equals( aTitle ) )
    2654                 :            :                         {
    2655         [ #  # ]:          0 :                             aUITitle = aUINames[nInd].Second;
    2656                 :          0 :                             break;
    2657                 :            :                         }
    2658                 :            : 
    2659         [ +  - ]:          8 :                     addFsysGroup( rList, aTitle, aUITitle, aTargetSubfolderURL, bWriteableContent );
    2660                 :            :                 }
    2661         [ #  # ]:          8 :             }
    2662                 :            :         }
    2663         [ #  # ]:         10 :         catch ( Exception& ) {}
    2664 [ +  - ][ +  - ]:         10 :     }
                 [ +  - ]
    2665                 :         10 : }
    2666                 :            : 
    2667                 :            : //-----------------------------------------------------------------------------
    2668                 :          0 : void SfxDocTplService_Impl::removeFromHierarchy( DocTemplates_EntryData_Impl *pData )
    2669                 :            : {
    2670         [ #  # ]:          0 :     Content aTemplate;
    2671                 :            : 
    2672 [ #  # ][ #  # ]:          0 :     if ( Content::create( pData->getHierarchyURL(), maCmdEnv, aTemplate ) )
    2673                 :            :     {
    2674         [ #  # ]:          0 :         removeContent( aTemplate );
    2675         [ #  # ]:          0 :     }
    2676                 :          0 : }
    2677                 :            : 
    2678                 :            : //-----------------------------------------------------------------------------
    2679                 :         20 : void SfxDocTplService_Impl::addToHierarchy( GroupData_Impl *pGroup,
    2680                 :            :                                             DocTemplates_EntryData_Impl *pData )
    2681                 :            : {
    2682 [ +  - ][ +  - ]:         20 :     Content aGroup, aTemplate;
    2683                 :            : 
    2684 [ +  - ][ -  + ]:         20 :     if ( ! Content::create( pGroup->getHierarchyURL(), maCmdEnv, aGroup ) )
    2685                 :            :         return;
    2686                 :            : 
    2687                 :            :     // Check, if there's a template with the given name in this group
    2688                 :            :     // Return if there is already a template
    2689         [ +  - ]:         20 :     INetURLObject aGroupObj( pGroup->getHierarchyURL() );
    2690                 :            : 
    2691                 :         20 :     aGroupObj.insertName( pData->getTitle(), false,
    2692                 :            :                       INetURLObject::LAST_SEGMENT, true,
    2693         [ +  - ]:         20 :                       INetURLObject::ENCODE_ALL );
    2694                 :            : 
    2695         [ +  - ]:         20 :     OUString aTemplateURL = aGroupObj.GetMainURL( INetURLObject::NO_DECODE );
    2696                 :            : 
    2697 [ +  - ][ -  + ]:         20 :     if ( Content::create( aTemplateURL, maCmdEnv, aTemplate ) )
    2698                 :            :         return;
    2699                 :            : 
    2700                 :         20 :     addEntry( aGroup, pData->getTitle(),
    2701                 :         20 :               pData->getTargetURL(),
    2702 [ +  - ][ -  + ]:         40 :               pData->getType() );
         [ +  - ][ -  + ]
         [ +  - ][ -  + ]
         [ +  - ][ +  - ]
    2703                 :            : }
    2704                 :            : 
    2705                 :            : //-----------------------------------------------------------------------------
    2706                 :          0 : void SfxDocTplService_Impl::updateData( DocTemplates_EntryData_Impl *pData )
    2707                 :            : {
    2708         [ #  # ]:          0 :     Content aTemplate;
    2709                 :            : 
    2710 [ #  # ][ #  # ]:          0 :     if ( ! Content::create( pData->getHierarchyURL(), maCmdEnv, aTemplate ) )
    2711                 :          0 :         return;
    2712                 :            : 
    2713                 :          0 :     OUString aPropName;
    2714                 :            : 
    2715         [ #  # ]:          0 :     if ( pData->getUpdateType() )
    2716                 :            :     {
    2717                 :          0 :         aPropName = OUString( PROPERTY_TYPE  );
    2718 [ #  # ][ #  # ]:          0 :         setProperty( aTemplate, aPropName, makeAny( pData->getType() ) );
    2719                 :            :     }
    2720                 :            : 
    2721         [ #  # ]:          0 :     if ( pData->getUpdateLink() )
    2722                 :            :     {
    2723                 :          0 :         aPropName = OUString( TARGET_URL  );
    2724 [ #  # ][ #  # ]:          0 :         setProperty( aTemplate, aPropName, makeAny( pData->getTargetURL() ) );
    2725 [ #  # ][ #  # ]:          0 :     }
    2726                 :            : }
    2727                 :            : 
    2728                 :            : //-----------------------------------------------------------------------------
    2729                 :          6 : void SfxDocTplService_Impl::addGroupToHierarchy( GroupData_Impl *pGroup )
    2730                 :            : {
    2731                 :          6 :     OUString aAdditionalProp( TARGET_DIR_URL  );
    2732         [ +  - ]:          6 :     Content aGroup;
    2733                 :            : 
    2734         [ +  - ]:          6 :     INetURLObject aNewGroupObj( maRootURL );
    2735                 :          6 :     aNewGroupObj.insertName( pGroup->getTitle(), false,
    2736                 :            :           INetURLObject::LAST_SEGMENT, true,
    2737         [ +  - ]:          6 :           INetURLObject::ENCODE_ALL );
    2738                 :            : 
    2739         [ +  - ]:          6 :     OUString aNewGroupURL = aNewGroupObj.GetMainURL( INetURLObject::NO_DECODE );
    2740                 :            : 
    2741 [ +  - ][ +  - ]:          6 :     if ( createFolder( aNewGroupURL, sal_False, sal_False, aGroup ) )
    2742                 :            :     {
    2743 [ +  - ][ +  - ]:          6 :         setProperty( aGroup, aAdditionalProp, makeAny( pGroup->getTargetURL() ) );
    2744                 :          6 :         pGroup->setHierarchyURL( aNewGroupURL );
    2745                 :            : 
    2746                 :          6 :         sal_uIntPtr nCount = pGroup->count();
    2747         [ +  + ]:         26 :         for ( sal_uIntPtr i=0; i<nCount; i++ )
    2748                 :            :         {
    2749         [ +  - ]:         20 :             DocTemplates_EntryData_Impl *pData = pGroup->getEntry( i );
    2750         [ +  - ]:         20 :             addToHierarchy( pGroup, pData ); // add entry to hierarchy
    2751                 :            :         }
    2752 [ +  - ][ +  - ]:          6 :     }
    2753                 :          6 : }
    2754                 :            : 
    2755                 :            : //-----------------------------------------------------------------------------
    2756                 :          0 : void SfxDocTplService_Impl::removeFromHierarchy( GroupData_Impl *pGroup )
    2757                 :            : {
    2758         [ #  # ]:          0 :     Content aGroup;
    2759                 :            : 
    2760 [ #  # ][ #  # ]:          0 :     if ( Content::create( pGroup->getHierarchyURL(), maCmdEnv, aGroup ) )
    2761                 :            :     {
    2762         [ #  # ]:          0 :         removeContent( aGroup );
    2763         [ #  # ]:          0 :     }
    2764                 :          0 : }
    2765                 :            : 
    2766                 :            : // -----------------------------------------------------------------------
    2767                 :          6 : GroupData_Impl::GroupData_Impl( const OUString& rTitle )
    2768                 :            : {
    2769                 :          6 :     maTitle = rTitle;
    2770                 :          6 :     mbInUse = sal_False;
    2771                 :          6 :     mbInHierarchy = sal_False;
    2772                 :          6 : }
    2773                 :            : 
    2774                 :            : // -----------------------------------------------------------------------
    2775                 :          6 : GroupData_Impl::~GroupData_Impl()
    2776                 :            : {
    2777         [ +  + ]:         26 :     for ( size_t i = 0, n = maEntries.size(); i < n; ++i )
    2778         [ +  - ]:         20 :         delete maEntries[ i ];
    2779                 :          6 :     maEntries.clear();
    2780                 :          6 : }
    2781                 :            : 
    2782                 :            : // -----------------------------------------------------------------------
    2783                 :         20 : DocTemplates_EntryData_Impl* GroupData_Impl::addEntry( const OUString& rTitle,
    2784                 :            :                                           const OUString& rTargetURL,
    2785                 :            :                                           const OUString& rType,
    2786                 :            :                                           const OUString& rHierURL )
    2787                 :            : {
    2788                 :         20 :     DocTemplates_EntryData_Impl* pData = NULL;
    2789                 :         20 :     bool EntryFound = false;
    2790                 :            : 
    2791         [ +  + ]:        110 :     for ( size_t i = 0, n = maEntries.size(); i < n; ++i )
    2792                 :            :     {
    2793                 :         90 :         pData = maEntries[ i ];
    2794         [ -  + ]:         90 :         if ( pData->getTitle() == rTitle )
    2795                 :            :         {
    2796                 :          0 :             EntryFound = true;
    2797                 :          0 :             break;
    2798                 :            :         }
    2799                 :            :     }
    2800                 :            : 
    2801         [ +  - ]:         20 :     if ( !EntryFound )
    2802                 :            :     {
    2803         [ +  - ]:         20 :         pData = new DocTemplates_EntryData_Impl( rTitle );
    2804                 :         20 :         pData->setTargetURL( rTargetURL );
    2805                 :         20 :         pData->setType( rType );
    2806         [ -  + ]:         20 :         if ( !rHierURL.isEmpty() )
    2807                 :            :         {
    2808                 :          0 :             pData->setHierarchyURL( rHierURL );
    2809                 :          0 :             pData->setHierarchy( sal_True );
    2810                 :            :         }
    2811         [ +  - ]:         20 :         maEntries.push_back( pData );
    2812                 :            :     }
    2813                 :            :     else
    2814                 :            :     {
    2815         [ #  # ]:          0 :         if ( !rHierURL.isEmpty() )
    2816                 :            :         {
    2817                 :          0 :             pData->setHierarchyURL( rHierURL );
    2818                 :          0 :             pData->setHierarchy( sal_True );
    2819                 :            :         }
    2820                 :            : 
    2821         [ #  # ]:          0 :         if ( pData->getInHierarchy() )
    2822                 :          0 :             pData->setInUse();
    2823                 :            : 
    2824         [ #  # ]:          0 :         if ( rTargetURL != pData->getTargetURL() )
    2825                 :            :         {
    2826                 :          0 :             pData->setTargetURL( rTargetURL );
    2827                 :          0 :             pData->setUpdateLink( sal_True );
    2828                 :            :         }
    2829                 :            :     }
    2830                 :            : 
    2831                 :         20 :     return pData;
    2832                 :            : }
    2833                 :            : 
    2834                 :            : // -----------------------------------------------------------------------
    2835                 :         20 : DocTemplates_EntryData_Impl::DocTemplates_EntryData_Impl( const OUString& rTitle )
    2836                 :            : {
    2837                 :         20 :     maTitle         = rTitle;
    2838                 :         20 :     mbInUse         = sal_False;
    2839                 :         20 :     mbInHierarchy   = sal_False;
    2840                 :         20 :     mbUpdateType    = sal_False;
    2841                 :         20 :     mbUpdateLink    = sal_False;
    2842                 :         20 : }
    2843                 :            : 
    2844                 :            : // -----------------------------------------------------------------------
    2845                 :         14 : SfxURLRelocator_Impl::SfxURLRelocator_Impl( uno::Reference< XMultiServiceFactory > xFactory )
    2846                 :         14 : : mxFactory( xFactory )
    2847                 :            : {
    2848                 :         14 : }
    2849                 :            : 
    2850                 :            : // -----------------------------------------------------------------------
    2851                 :         11 : SfxURLRelocator_Impl::~SfxURLRelocator_Impl()
    2852                 :            : {
    2853                 :         11 : }
    2854                 :            : 
    2855                 :            : // -----------------------------------------------------------------------
    2856                 :         10 : void SfxURLRelocator_Impl::initOfficeInstDirs()
    2857                 :            : {
    2858         [ +  + ]:         10 :     if ( !mxOfficeInstDirs.is() )
    2859                 :            :     {
    2860         [ +  - ]:          2 :         osl::MutexGuard aGuard( maMutex );
    2861         [ +  - ]:          2 :         if ( !mxOfficeInstDirs.is() )
    2862                 :            :         {
    2863                 :            :             OSL_ENSURE( mxFactory.is(), "No service manager!" );
    2864                 :            : 
    2865                 :          2 :             uno::Reference< XComponentContext > xCtx;
    2866         [ +  - ]:          2 :             uno::Reference< XPropertySet > xPropSet( mxFactory, UNO_QUERY );
    2867         [ +  - ]:          2 :             if ( xPropSet.is() )
    2868                 :            :             {
    2869         [ +  - ]:          2 :                 xPropSet->getPropertyValue(
    2870                 :            :                     rtl::OUString(
    2871                 :          2 :                         "DefaultContext"  ) )
    2872 [ +  - ][ +  - ]:          2 :                 >>= xCtx;
    2873                 :            :             }
    2874                 :            : 
    2875                 :            :             OSL_ENSURE( xCtx.is(),
    2876                 :            :                         "Unable to obtain component context from "
    2877                 :            :                         "service manager!" );
    2878                 :            : 
    2879         [ +  - ]:          2 :             if ( xCtx.is() )
    2880                 :            :             {
    2881         [ +  - ]:          2 :                 xCtx->getValueByName(
    2882                 :            :                     rtl::OUString(
    2883                 :            :                         "/singletons/"
    2884                 :          2 :                         "com.sun.star.util.theOfficeInstallationDirectories"  ) )
    2885 [ +  - ][ +  - ]:          2 :                 >>= mxOfficeInstDirs;
    2886                 :            :             }
    2887                 :            : 
    2888                 :            :             OSL_ENSURE( mxOfficeInstDirs.is(),
    2889                 :            :                         "Unable to obtain office installation directory "
    2890                 :          2 :                         "singleton!" );
    2891         [ +  - ]:          2 :         }
    2892                 :            :     }
    2893                 :         10 : }
    2894                 :            : 
    2895                 :            : // -----------------------------------------------------------------------
    2896                 :         10 : void SfxURLRelocator_Impl::implExpandURL( ::rtl::OUString& io_url )
    2897                 :            : {
    2898         [ +  - ]:         10 :     const INetURLObject aParser( io_url );
    2899         [ +  - ]:         10 :     if ( aParser.GetProtocol() != INET_PROT_VND_SUN_STAR_EXPAND )
    2900                 :         10 :         return;
    2901                 :            : 
    2902         [ #  # ]:          0 :     io_url = aParser.GetURLPath( INetURLObject::DECODE_WITH_CHARSET );
    2903                 :            :     try
    2904                 :            :     {
    2905         [ #  # ]:          0 :         if ( !mxMacroExpander.is() )
    2906                 :            :         {
    2907         [ #  # ]:          0 :             ::comphelper::ComponentContext aContext( mxFactory );
    2908 [ #  # ][ #  # ]:          0 :             mxMacroExpander.set( aContext.getSingleton( "com.sun.star.util.theMacroExpander" ), UNO_QUERY_THROW );
         [ #  # ][ #  # ]
    2909                 :            :         }
    2910 [ #  # ][ #  # ]:          0 :         io_url = mxMacroExpander->expandMacros( io_url );
    2911                 :            :     }
    2912         [ #  # ]:          0 :     catch( const Exception& )
    2913                 :            :     {
    2914                 :            :         DBG_UNHANDLED_EXCEPTION();
    2915 [ +  - ][ -  + ]:         10 :     }
    2916                 :            : }
    2917                 :            : 
    2918                 :            : // -----------------------------------------------------------------------
    2919                 :         14 : void SfxURLRelocator_Impl::makeRelocatableURL( rtl::OUString & rURL )
    2920                 :            : {
    2921         [ +  + ]:         14 :     if ( !rURL.isEmpty() )
    2922                 :            :     {
    2923                 :         10 :         initOfficeInstDirs();
    2924                 :         10 :         implExpandURL( rURL );
    2925                 :         10 :         rURL = mxOfficeInstDirs->makeRelocatableURL( rURL );
    2926                 :            :     }
    2927                 :         14 : }
    2928                 :            : 
    2929                 :            : // -----------------------------------------------------------------------
    2930                 :          0 : void SfxURLRelocator_Impl::makeAbsoluteURL( rtl::OUString & rURL )
    2931                 :            : {
    2932         [ #  # ]:          0 :     if ( !rURL.isEmpty() )
    2933                 :            :     {
    2934                 :          0 :         initOfficeInstDirs();
    2935                 :          0 :         implExpandURL( rURL );
    2936                 :          0 :         rURL = mxOfficeInstDirs->makeAbsoluteURL( rURL );
    2937                 :            :     }
    2938                 :          0 : }
    2939                 :            : 
    2940                 :            : 
    2941                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10