xref: /aoo42x/main/sfx2/source/doc/doctempl.cxx (revision 940681c7)
1d119d52dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3d119d52dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4d119d52dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5d119d52dSAndrew Rist  * distributed with this work for additional information
6d119d52dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7d119d52dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8d119d52dSAndrew Rist  * "License"); you may not use this file except in compliance
9d119d52dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10d119d52dSAndrew Rist  *
11d119d52dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12d119d52dSAndrew Rist  *
13d119d52dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14d119d52dSAndrew Rist  * software distributed under the License is distributed on an
15d119d52dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16d119d52dSAndrew Rist  * KIND, either express or implied.  See the License for the
17d119d52dSAndrew Rist  * specific language governing permissions and limitations
18d119d52dSAndrew Rist  * under the License.
19d119d52dSAndrew Rist  *
20d119d52dSAndrew Rist  *************************************************************/
21d119d52dSAndrew Rist 
22d119d52dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sfx2.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <limits.h>
28cdf0e10cSrcweir #include <com/sun/star/uno/Any.h>
29cdf0e10cSrcweir #include <vos/mutex.hxx>
30cdf0e10cSrcweir #include <vos/thread.hxx>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #ifndef _SV_RESARY_HXX
33cdf0e10cSrcweir #include <tools/resary.hxx>
34cdf0e10cSrcweir #endif
35cdf0e10cSrcweir #include <vcl/svapp.hxx>
36cdf0e10cSrcweir #include <vcl/settings.hxx>
37cdf0e10cSrcweir #include <unotools/localedatawrapper.hxx>
38cdf0e10cSrcweir #include <unotools/pathoptions.hxx>
39cdf0e10cSrcweir #include <tools/string.hxx>
40cdf0e10cSrcweir #include <tools/urlobj.hxx>
41cdf0e10cSrcweir #include <svtools/ehdl.hxx>
42cdf0e10cSrcweir #include <svtools/sfxecode.hxx>
43cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
44cdf0e10cSrcweir #include <ucbhelper/content.hxx>
45cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
46cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
47cdf0e10cSrcweir #include <com/sun/star/beans/XPropertyContainer.hpp>
48cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
49cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySetInfo.hpp>
50cdf0e10cSrcweir #include <com/sun/star/document/XTypeDetection.hpp>
51cdf0e10cSrcweir #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
52cdf0e10cSrcweir #include <com/sun/star/frame/XComponentLoader.hpp>
53cdf0e10cSrcweir #include <com/sun/star/frame/XDocumentTemplates.hpp>
54cdf0e10cSrcweir #include <com/sun/star/io/XInputStream.hpp>
55cdf0e10cSrcweir #include <com/sun/star/io/XPersist.hpp>
56cdf0e10cSrcweir #include <com/sun/star/lang/XLocalizable.hpp>
57cdf0e10cSrcweir #include <com/sun/star/sdbc/XResultSet.hpp>
58cdf0e10cSrcweir #include <com/sun/star/sdbc/XRow.hpp>
59cdf0e10cSrcweir #include <com/sun/star/ucb/ContentInfo.hpp>
60cdf0e10cSrcweir #include <com/sun/star/ucb/InsertCommandArgument.hpp>
61cdf0e10cSrcweir #include <com/sun/star/ucb/NameClash.hpp>
62cdf0e10cSrcweir #include <com/sun/star/ucb/TransferInfo.hpp>
63cdf0e10cSrcweir #include <com/sun/star/ucb/XCommandProcessor.hpp>
64cdf0e10cSrcweir #include <com/sun/star/ucb/XContent.hpp>
65cdf0e10cSrcweir #include <com/sun/star/ucb/XContentAccess.hpp>
66cdf0e10cSrcweir #include <com/sun/star/ucb/XAnyCompareFactory.hpp>
67cdf0e10cSrcweir #include <com/sun/star/ucb/XAnyCompare.hpp>
68cdf0e10cSrcweir #include <com/sun/star/ucb/NumberedSortingInfo.hpp>
69cdf0e10cSrcweir #include <com/sun/star/embed/ElementModes.hpp>
70cdf0e10cSrcweir #include <com/sun/star/embed/XTransactedObject.hpp>
71cdf0e10cSrcweir 
72cdf0e10cSrcweir #include "sfxurlrelocator.hxx"
73cdf0e10cSrcweir 
74cdf0e10cSrcweir using namespace ::com::sun::star;
75cdf0e10cSrcweir using namespace ::com::sun::star::beans;
76cdf0e10cSrcweir using namespace ::com::sun::star::frame;
77cdf0e10cSrcweir using namespace ::com::sun::star::io;
78cdf0e10cSrcweir using namespace ::com::sun::star::lang;
79cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
80cdf0e10cSrcweir using namespace ::com::sun::star::uno;
81cdf0e10cSrcweir using namespace ::com::sun::star::ucb;
82cdf0e10cSrcweir using namespace ::com::sun::star::document;
83cdf0e10cSrcweir using namespace ::rtl;
84cdf0e10cSrcweir using namespace ::ucbhelper;
85cdf0e10cSrcweir 
86cdf0e10cSrcweir 
87cdf0e10cSrcweir #include <sfx2/doctempl.hxx>
88cdf0e10cSrcweir #include <sfx2/docfac.hxx>
89cdf0e10cSrcweir #include <sfx2/docfile.hxx>
90cdf0e10cSrcweir #include <sfx2/objsh.hxx>
91cdf0e10cSrcweir #include "sfxtypes.hxx"
92cdf0e10cSrcweir #include <sfx2/app.hxx>
93cdf0e10cSrcweir #include "sfx2/sfxresid.hxx"
94cdf0e10cSrcweir #include "doc.hrc"
95cdf0e10cSrcweir #include <sfx2/fcontnr.hxx>
96cdf0e10cSrcweir #include <svtools/templatefoldercache.hxx>
97cdf0e10cSrcweir 
98cdf0e10cSrcweir #include <comphelper/storagehelper.hxx>
99cdf0e10cSrcweir #include <unotools/ucbhelper.hxx>
100cdf0e10cSrcweir 
101cdf0e10cSrcweir //========================================================================
102cdf0e10cSrcweir 
103cdf0e10cSrcweir // #define DONT_USE_HIERARCHY
104cdf0e10cSrcweir 
105cdf0e10cSrcweir #define TITLE                   "Title"
106cdf0e10cSrcweir #define IS_FOLDER               "IsFolder"
107cdf0e10cSrcweir #define PROPERTY_TYPE           "TypeDescription"
108cdf0e10cSrcweir #define TARGET_URL              "TargetURL"
109cdf0e10cSrcweir #define TYPE_FOLDER             "application/vnd.sun.star.hier-folder"
110cdf0e10cSrcweir #define TYPE_LINK               "application/vnd.sun.star.hier-link"
111cdf0e10cSrcweir #define TYPE_FSYS_FOLDER        "application/vnd.sun.staroffice.fsys-folder"
112cdf0e10cSrcweir 
113cdf0e10cSrcweir #define TARGET_DIR_URL          "TargetDirURL"
114cdf0e10cSrcweir #define COMMAND_DELETE          "delete"
115cdf0e10cSrcweir #define COMMAND_TRANSFER        "transfer"
116cdf0e10cSrcweir 
117cdf0e10cSrcweir #define STANDARD_FOLDER         "standard"
118cdf0e10cSrcweir 
119cdf0e10cSrcweir #define SERVICENAME_TYPEDETECTION       "com.sun.star.document.TypeDetection"
120cdf0e10cSrcweir #define TYPEDETECTION_PARAMETER         "FileName"
121cdf0e10cSrcweir //#define SERVICENAME_OLD_TYPEDETECTION   "com.sun.star.frame.FrameLoaderFactory"
122cdf0e10cSrcweir //#define PARAMETER_OLD_TYPEDETECTION     "DeepDetection"
123cdf0e10cSrcweir #define SERVICENAME_DOCINFO             "com.sun.star.document.DocumentProperties"
124cdf0e10cSrcweir #define SERVICENAME_DOCTEMPLATES        "com.sun.star.frame.DocumentTemplates"
125cdf0e10cSrcweir #define SERVICENAME_DESKTOP             "com.sun.star.frame.Desktop"
126cdf0e10cSrcweir 
127cdf0e10cSrcweir //========================================================================
128cdf0e10cSrcweir 
129cdf0e10cSrcweir class RegionData_Impl;
130cdf0e10cSrcweir 
131cdf0e10cSrcweir namespace DocTempl {
132cdf0e10cSrcweir 
133cdf0e10cSrcweir class DocTempl_EntryData_Impl
134cdf0e10cSrcweir {
135cdf0e10cSrcweir     RegionData_Impl*    mpParent;
136cdf0e10cSrcweir 
13786e1cf34SPedro Giffuni     // the following member must be SfxObjectShellLock since it controls that SfxObjectShell lifetime by design
138cdf0e10cSrcweir     // and users of this class expect it to be so.
139cdf0e10cSrcweir     SfxObjectShellLock  mxObjShell;
140cdf0e10cSrcweir 
141cdf0e10cSrcweir     OUString            maTitle;
142cdf0e10cSrcweir     OUString            maOwnURL;
143cdf0e10cSrcweir     OUString            maTargetURL;
144cdf0e10cSrcweir     sal_Bool            mbIsOwner   : 1;
145cdf0e10cSrcweir     sal_Bool            mbDidConvert: 1;
146cdf0e10cSrcweir 
147cdf0e10cSrcweir private:
GetParent() const148cdf0e10cSrcweir     RegionData_Impl*    GetParent() const { return mpParent; }
149cdf0e10cSrcweir 
150cdf0e10cSrcweir public:
151cdf0e10cSrcweir                         DocTempl_EntryData_Impl( RegionData_Impl* pParent,
152cdf0e10cSrcweir                                         const OUString& rTitle );
153cdf0e10cSrcweir 
GetTitle() const154cdf0e10cSrcweir     const OUString&     GetTitle() const { return maTitle; }
155cdf0e10cSrcweir     const OUString&     GetTargetURL();
156cdf0e10cSrcweir     const OUString&     GetHierarchyURL();
157cdf0e10cSrcweir 
SetTitle(const OUString & rTitle)158cdf0e10cSrcweir     void                SetTitle( const OUString& rTitle ) { maTitle = rTitle; }
SetTargetURL(const OUString & rURL)159cdf0e10cSrcweir     void                SetTargetURL( const OUString& rURL ) { maTargetURL = rURL; }
SetHierarchyURL(const OUString & rURL)160cdf0e10cSrcweir     void                SetHierarchyURL( const OUString& rURL) { maOwnURL = rURL; }
161cdf0e10cSrcweir 
162cdf0e10cSrcweir     int                 Compare( const OUString& rTitle ) const;
163cdf0e10cSrcweir 
164cdf0e10cSrcweir     SfxObjectShellRef   CreateObjectShell();
165cdf0e10cSrcweir     sal_Bool                DeleteObjectShell();
166cdf0e10cSrcweir };
167cdf0e10cSrcweir 
168cdf0e10cSrcweir }
169cdf0e10cSrcweir 
170cdf0e10cSrcweir using namespace ::DocTempl;
171cdf0e10cSrcweir 
172cdf0e10cSrcweir // ------------------------------------------------------------------------
173cdf0e10cSrcweir 
174cdf0e10cSrcweir class RegionData_Impl
175cdf0e10cSrcweir {
176cdf0e10cSrcweir     DECLARE_LIST( EntryList_Impl, DocTempl_EntryData_Impl* )
177cdf0e10cSrcweir     const SfxDocTemplate_Impl*  mpParent;
178cdf0e10cSrcweir     EntryList_Impl              maEntries;
179cdf0e10cSrcweir     OUString                    maTitle;
180cdf0e10cSrcweir     OUString                    maOwnURL;
181cdf0e10cSrcweir     OUString                    maTargetURL;
182cdf0e10cSrcweir 
183cdf0e10cSrcweir private:
184cdf0e10cSrcweir     long                        GetEntryPos( const OUString& rTitle,
185cdf0e10cSrcweir                                              sal_Bool& rFound ) const;
GetParent() const186cdf0e10cSrcweir     const SfxDocTemplate_Impl*  GetParent() const { return mpParent; }
187cdf0e10cSrcweir 
188cdf0e10cSrcweir public:
189cdf0e10cSrcweir                         RegionData_Impl( const SfxDocTemplate_Impl* pParent,
190cdf0e10cSrcweir                                          const OUString& rTitle );
191cdf0e10cSrcweir                         ~RegionData_Impl();
192cdf0e10cSrcweir 
SetTargetURL(const OUString & rURL)193cdf0e10cSrcweir     void                SetTargetURL( const OUString& rURL ) { maTargetURL = rURL; }
SetHierarchyURL(const OUString & rURL)194cdf0e10cSrcweir     void                SetHierarchyURL( const OUString& rURL) { maOwnURL = rURL; }
195cdf0e10cSrcweir 
196cdf0e10cSrcweir     DocTempl_EntryData_Impl*     GetEntry( sal_uIntPtr nIndex ) const;
197cdf0e10cSrcweir     DocTempl_EntryData_Impl*     GetEntry( const OUString& rName ) const;
198cdf0e10cSrcweir     DocTempl_EntryData_Impl*     GetByTargetURL( const OUString& rName ) const;
199cdf0e10cSrcweir 
GetTitle() const200cdf0e10cSrcweir     const OUString&     GetTitle() const { return maTitle; }
201cdf0e10cSrcweir     const OUString&     GetTargetURL();
202cdf0e10cSrcweir     const OUString&     GetHierarchyURL();
203cdf0e10cSrcweir 
204cdf0e10cSrcweir     sal_uIntPtr               GetCount() const;
205cdf0e10cSrcweir 
SetTitle(const OUString & rTitle)206cdf0e10cSrcweir     void                SetTitle( const OUString& rTitle ) { maTitle = rTitle; }
207cdf0e10cSrcweir 
208cdf0e10cSrcweir     void                AddEntry( const OUString& rTitle,
209cdf0e10cSrcweir                                   const OUString& rTargetURL,
210cdf0e10cSrcweir                                   sal_uInt16 *pPos = NULL );
211cdf0e10cSrcweir     void                DeleteEntry( sal_uIntPtr nIndex );
212cdf0e10cSrcweir 
Compare(const OUString & rTitle) const213cdf0e10cSrcweir     int                 Compare( const OUString& rTitle ) const
214cdf0e10cSrcweir                             { return maTitle.compareTo( rTitle ); }
215cdf0e10cSrcweir     int                 Compare( RegionData_Impl* pCompareWith ) const;
216cdf0e10cSrcweir };
217cdf0e10cSrcweir 
218cdf0e10cSrcweir DECLARE_LIST( RegionList_Impl, RegionData_Impl* )
219cdf0e10cSrcweir 
220cdf0e10cSrcweir // ------------------------------------------------------------------------
221cdf0e10cSrcweir 
222cdf0e10cSrcweir class SfxDocTemplate_Impl : public SvRefBase
223cdf0e10cSrcweir {
224cdf0e10cSrcweir     uno::Reference< XPersist >               mxInfo;
225cdf0e10cSrcweir     uno::Reference< XDocumentTemplates >     mxTemplates;
226cdf0e10cSrcweir 
227cdf0e10cSrcweir     ::osl::Mutex        maMutex;
228cdf0e10cSrcweir     OUString            maRootURL;
229cdf0e10cSrcweir     OUString            maStandardGroup;
230cdf0e10cSrcweir     RegionList_Impl     maRegions;
231cdf0e10cSrcweir     sal_Bool            mbConstructed;
232cdf0e10cSrcweir 
233cdf0e10cSrcweir     uno::Reference< XAnyCompareFactory > m_rCompareFactory;
234cdf0e10cSrcweir 
235cdf0e10cSrcweir     // the following member is intended to prevent clearing of the global data when it is in use
236cdf0e10cSrcweir     // TODO/LATER: it still does not make the implementation complete thread-safe
237cdf0e10cSrcweir     sal_Int32           mnLockCounter;
238cdf0e10cSrcweir 
239cdf0e10cSrcweir private:
240cdf0e10cSrcweir     void                Clear();
241cdf0e10cSrcweir 
242cdf0e10cSrcweir public:
243cdf0e10cSrcweir                         SfxDocTemplate_Impl();
244cdf0e10cSrcweir                         ~SfxDocTemplate_Impl();
245cdf0e10cSrcweir 
246cdf0e10cSrcweir     void                IncrementLock();
247cdf0e10cSrcweir     void                DecrementLock();
248cdf0e10cSrcweir 
249cdf0e10cSrcweir     sal_Bool            Construct( );
250cdf0e10cSrcweir     void                CreateFromHierarchy( Content &rTemplRoot );
251cdf0e10cSrcweir     void                ReInitFromComponent();
252cdf0e10cSrcweir     void                AddRegion( const OUString& rTitle,
253cdf0e10cSrcweir                                    Content& rContent );
254cdf0e10cSrcweir 
255cdf0e10cSrcweir     void                Rescan();
256cdf0e10cSrcweir 
257cdf0e10cSrcweir     void                DeleteRegion( sal_uIntPtr nIndex );
258cdf0e10cSrcweir 
GetRegionCount() const259cdf0e10cSrcweir     sal_uIntPtr               GetRegionCount() const
260cdf0e10cSrcweir                             { return maRegions.Count(); }
261cdf0e10cSrcweir     RegionData_Impl*    GetRegion( const OUString& rName ) const;
262cdf0e10cSrcweir     RegionData_Impl*    GetRegion( sal_uIntPtr nIndex ) const;
263cdf0e10cSrcweir     void                GetTemplates( Content& rTargetFolder,
264cdf0e10cSrcweir                                       Content& rParentFolder,
265cdf0e10cSrcweir                                       RegionData_Impl* pRegion );
266cdf0e10cSrcweir 
267cdf0e10cSrcweir     long                GetRegionPos( const OUString& rTitle,
268cdf0e10cSrcweir                                       sal_Bool& rFound ) const;
269cdf0e10cSrcweir 
270cdf0e10cSrcweir     sal_Bool            GetTitleFromURL( const OUString& rURL, OUString& aTitle );
271cdf0e10cSrcweir     sal_Bool            InsertRegion( RegionData_Impl *pData, sal_uIntPtr nPos = LIST_APPEND );
GetRootURL() const272cdf0e10cSrcweir     OUString            GetRootURL() const { return maRootURL; }
273cdf0e10cSrcweir 
getDocTemplates()274cdf0e10cSrcweir     uno::Reference< XDocumentTemplates >     getDocTemplates() { return mxTemplates; }
275cdf0e10cSrcweir };
276cdf0e10cSrcweir 
277cdf0e10cSrcweir // ------------------------------------------------------------------------
278cdf0e10cSrcweir 
279cdf0e10cSrcweir class DocTemplLocker_Impl
280cdf0e10cSrcweir {
281cdf0e10cSrcweir     SfxDocTemplate_Impl& m_aDocTempl;
282cdf0e10cSrcweir public:
DocTemplLocker_Impl(SfxDocTemplate_Impl & aDocTempl)283cdf0e10cSrcweir     DocTemplLocker_Impl( SfxDocTemplate_Impl& aDocTempl )
284cdf0e10cSrcweir     : m_aDocTempl( aDocTempl )
285cdf0e10cSrcweir     {
286cdf0e10cSrcweir         m_aDocTempl.IncrementLock();
287cdf0e10cSrcweir     }
288cdf0e10cSrcweir 
~DocTemplLocker_Impl()289cdf0e10cSrcweir     ~DocTemplLocker_Impl()
290cdf0e10cSrcweir     {
291cdf0e10cSrcweir         m_aDocTempl.DecrementLock();
292cdf0e10cSrcweir     }
293cdf0e10cSrcweir };
294cdf0e10cSrcweir 
295cdf0e10cSrcweir // ------------------------------------------------------------------------
296cdf0e10cSrcweir 
297cdf0e10cSrcweir #ifndef SFX_DECL_DOCTEMPLATES_DEFINED
298cdf0e10cSrcweir #define SFX_DECL_DOCTEMPLATES_DEFINED
299cdf0e10cSrcweir SV_DECL_REF(SfxDocTemplate_Impl)
300cdf0e10cSrcweir #endif
301cdf0e10cSrcweir 
302cdf0e10cSrcweir SV_IMPL_REF(SfxDocTemplate_Impl)
303cdf0e10cSrcweir 
304cdf0e10cSrcweir // ------------------------------------------------------------------------
305cdf0e10cSrcweir 
306cdf0e10cSrcweir SfxDocTemplate_Impl *gpTemplateData = 0;
307cdf0e10cSrcweir 
308cdf0e10cSrcweir // -----------------------------------------------------------------------
309cdf0e10cSrcweir 
310cdf0e10cSrcweir static sal_Bool getTextProperty_Impl( Content& rContent,
311cdf0e10cSrcweir                                       const OUString& rPropName,
312cdf0e10cSrcweir                                       OUString& rPropValue );
313cdf0e10cSrcweir 
314cdf0e10cSrcweir //========================================================================
315cdf0e10cSrcweir //========================================================================
316cdf0e10cSrcweir //========================================================================
317cdf0e10cSrcweir 
GetFullRegionName(sal_uInt16 nIdx) const318cdf0e10cSrcweir String SfxDocumentTemplates::GetFullRegionName
319cdf0e10cSrcweir (
320cdf0e10cSrcweir     sal_uInt16 nIdx                     // Index des Bereiches
321cdf0e10cSrcweir )   const
322cdf0e10cSrcweir 
323cdf0e10cSrcweir /*  [Beschreibung]
324cdf0e10cSrcweir 
325cdf0e10cSrcweir     Liefert den logischen Namen eines Bereiches Plus seinem  Pfad
326cdf0e10cSrcweir 
327cdf0e10cSrcweir 
328cdf0e10cSrcweir     [R"uckgabewert]                 Referenz auf diesen Namen
329cdf0e10cSrcweir 
330cdf0e10cSrcweir */
331cdf0e10cSrcweir 
332cdf0e10cSrcweir {
333cdf0e10cSrcweir     // First: find the RegionData for the index
334cdf0e10cSrcweir     String aName;
335cdf0e10cSrcweir 
336cdf0e10cSrcweir     DocTemplLocker_Impl aLocker( *pImp );
337cdf0e10cSrcweir 
338cdf0e10cSrcweir     if ( pImp->Construct() )
339cdf0e10cSrcweir     {
340cdf0e10cSrcweir         RegionData_Impl *pData1 = pImp->GetRegion( nIdx );
341cdf0e10cSrcweir 
342cdf0e10cSrcweir         if ( pData1 )
343cdf0e10cSrcweir             aName = pData1->GetTitle();
344cdf0e10cSrcweir 
345cdf0e10cSrcweir         // --**-- here was some code which appended the path to the
346cdf0e10cSrcweir         //      group if there was more than one with the same name.
347cdf0e10cSrcweir         //      this should not happen anymore
348cdf0e10cSrcweir     }
349cdf0e10cSrcweir 
350cdf0e10cSrcweir     return aName;
351cdf0e10cSrcweir }
352cdf0e10cSrcweir 
353cdf0e10cSrcweir //------------------------------------------------------------------------
354cdf0e10cSrcweir 
GetRegionName(sal_uInt16 nIdx) const355cdf0e10cSrcweir const String& SfxDocumentTemplates::GetRegionName
356cdf0e10cSrcweir (
357cdf0e10cSrcweir     sal_uInt16 nIdx                 // Index des Bereiches
358cdf0e10cSrcweir )   const
359cdf0e10cSrcweir 
360cdf0e10cSrcweir /*  [Beschreibung]
361cdf0e10cSrcweir 
362cdf0e10cSrcweir     Liefert den logischen Namen eines Bereiches
363cdf0e10cSrcweir 
364cdf0e10cSrcweir 
365cdf0e10cSrcweir     [R"uckgabewert]
366cdf0e10cSrcweir 
367cdf0e10cSrcweir     const String&                   Referenz auf diesen Namen
368cdf0e10cSrcweir 
369cdf0e10cSrcweir */
370cdf0e10cSrcweir {
371cdf0e10cSrcweir     static String maTmpString;
372cdf0e10cSrcweir 
373cdf0e10cSrcweir     DocTemplLocker_Impl aLocker( *pImp );
374cdf0e10cSrcweir 
375cdf0e10cSrcweir     if ( pImp->Construct() )
376cdf0e10cSrcweir     {
377cdf0e10cSrcweir         RegionData_Impl *pData = pImp->GetRegion( nIdx );
378cdf0e10cSrcweir 
379cdf0e10cSrcweir         if ( pData )
380cdf0e10cSrcweir             maTmpString = pData->GetTitle();
381cdf0e10cSrcweir         else
382cdf0e10cSrcweir             maTmpString.Erase();
383cdf0e10cSrcweir     }
384cdf0e10cSrcweir     else
385cdf0e10cSrcweir         maTmpString.Erase();
386cdf0e10cSrcweir 
387cdf0e10cSrcweir     return maTmpString;
388cdf0e10cSrcweir }
389cdf0e10cSrcweir 
390cdf0e10cSrcweir 
391cdf0e10cSrcweir //------------------------------------------------------------------------
392cdf0e10cSrcweir 
GetRegionNo(const String & rRegion) const393cdf0e10cSrcweir sal_uInt16 SfxDocumentTemplates::GetRegionNo
394cdf0e10cSrcweir (
395cdf0e10cSrcweir     const String &rRegion       // Name der Region
396cdf0e10cSrcweir )   const
397cdf0e10cSrcweir 
398cdf0e10cSrcweir /*  [Beschreibung]
399cdf0e10cSrcweir 
400cdf0e10cSrcweir     Liefert den Index f"ur einen logischen Namen eines Bereiches.
401cdf0e10cSrcweir 
402cdf0e10cSrcweir 
403cdf0e10cSrcweir     [R"uckgabewert]
404cdf0e10cSrcweir 
405cdf0e10cSrcweir     sal_uInt16          Index von 'rRegion' oder USHRT_MAX falls unbekannt
406cdf0e10cSrcweir 
407cdf0e10cSrcweir */
408cdf0e10cSrcweir {
409cdf0e10cSrcweir     DocTemplLocker_Impl aLocker( *pImp );
410cdf0e10cSrcweir 
411cdf0e10cSrcweir     if ( !pImp->Construct() )
412cdf0e10cSrcweir         return USHRT_MAX;
413cdf0e10cSrcweir 
414cdf0e10cSrcweir     sal_Bool    bFound;
415cdf0e10cSrcweir     sal_uIntPtr       nIndex = pImp->GetRegionPos( rRegion, bFound );
416cdf0e10cSrcweir 
417cdf0e10cSrcweir     if ( bFound )
418cdf0e10cSrcweir         return (sal_uInt16) nIndex;
419cdf0e10cSrcweir     else
420cdf0e10cSrcweir         return USHRT_MAX;
421cdf0e10cSrcweir }
422cdf0e10cSrcweir 
423cdf0e10cSrcweir 
424cdf0e10cSrcweir //------------------------------------------------------------------------
425cdf0e10cSrcweir 
GetRegionCount() const426cdf0e10cSrcweir sal_uInt16 SfxDocumentTemplates::GetRegionCount() const
427cdf0e10cSrcweir 
428cdf0e10cSrcweir /*  [Beschreibung]
429cdf0e10cSrcweir 
430cdf0e10cSrcweir     Liefert die Anzahl der Bereiche
431cdf0e10cSrcweir 
432cdf0e10cSrcweir 
433cdf0e10cSrcweir     [R"uckgabewert]
434cdf0e10cSrcweir 
435cdf0e10cSrcweir     sal_uInt16                  Anzahl der Bereiche
436cdf0e10cSrcweir 
437cdf0e10cSrcweir */
438cdf0e10cSrcweir {
439cdf0e10cSrcweir     DocTemplLocker_Impl aLocker( *pImp );
440cdf0e10cSrcweir 
441cdf0e10cSrcweir     if ( !pImp->Construct() )
442cdf0e10cSrcweir         return 0;
443cdf0e10cSrcweir 
444cdf0e10cSrcweir     sal_uIntPtr nCount = pImp->GetRegionCount();
445cdf0e10cSrcweir 
446cdf0e10cSrcweir     return (sal_uInt16) nCount;
447cdf0e10cSrcweir }
448cdf0e10cSrcweir 
449cdf0e10cSrcweir //------------------------------------------------------------------------
450cdf0e10cSrcweir 
IsRegionLoaded(sal_uInt16 nIdx) const451cdf0e10cSrcweir sal_Bool SfxDocumentTemplates::IsRegionLoaded( sal_uInt16 nIdx ) const
452cdf0e10cSrcweir {
453cdf0e10cSrcweir     DocTemplLocker_Impl aLocker( *pImp );
454cdf0e10cSrcweir 
455cdf0e10cSrcweir     if ( !pImp->Construct() )
456cdf0e10cSrcweir         return sal_False;
457cdf0e10cSrcweir 
458cdf0e10cSrcweir     RegionData_Impl *pData = pImp->GetRegion( nIdx );
459cdf0e10cSrcweir 
460cdf0e10cSrcweir     if ( pData )
461cdf0e10cSrcweir         return sal_True;
462cdf0e10cSrcweir     else
463cdf0e10cSrcweir         return sal_False;
464cdf0e10cSrcweir }
465cdf0e10cSrcweir 
466cdf0e10cSrcweir //------------------------------------------------------------------------
467cdf0e10cSrcweir 
GetCount(const String & rName) const468cdf0e10cSrcweir sal_uInt16 SfxDocumentTemplates::GetCount
469cdf0e10cSrcweir (
470cdf0e10cSrcweir     const String&   rName   /*  Name des Bereiches, dessen Eintrags-
471cdf0e10cSrcweir                                 anzahl ermittelt werden soll */
472cdf0e10cSrcweir 
473cdf0e10cSrcweir )   const
474cdf0e10cSrcweir 
475cdf0e10cSrcweir /*  [Beschreibung]
476cdf0e10cSrcweir 
477cdf0e10cSrcweir     Liefert die Anzahl der Eintr"age eines Bereiches
478cdf0e10cSrcweir 
479cdf0e10cSrcweir 
480cdf0e10cSrcweir     [R"uckgabewert]
481cdf0e10cSrcweir 
482cdf0e10cSrcweir     USHORT                      Anzahl der Eintr"age
483cdf0e10cSrcweir 
484cdf0e10cSrcweir */
485cdf0e10cSrcweir 
486cdf0e10cSrcweir {
487cdf0e10cSrcweir     DocTemplLocker_Impl aLocker( *pImp );
488cdf0e10cSrcweir 
489cdf0e10cSrcweir     if ( !pImp->Construct() )
490cdf0e10cSrcweir         return 0;
491cdf0e10cSrcweir 
492cdf0e10cSrcweir     RegionData_Impl *pData = pImp->GetRegion( rName );
493cdf0e10cSrcweir     sal_uIntPtr            nCount = 0;
494cdf0e10cSrcweir 
495cdf0e10cSrcweir     if ( pData )
496cdf0e10cSrcweir         nCount = pData->GetCount();
497cdf0e10cSrcweir 
498cdf0e10cSrcweir     return (sal_uInt16) nCount;
499cdf0e10cSrcweir }
500cdf0e10cSrcweir 
501cdf0e10cSrcweir //------------------------------------------------------------------------
502cdf0e10cSrcweir 
GetCount(sal_uInt16 nRegion) const503cdf0e10cSrcweir sal_uInt16 SfxDocumentTemplates::GetCount
504cdf0e10cSrcweir (
505cdf0e10cSrcweir     sal_uInt16 nRegion              /*  Index des Bereiches, dessen Eintrags-
506cdf0e10cSrcweir                                     anzahl ermittelt werden soll */
507cdf0e10cSrcweir 
508cdf0e10cSrcweir )   const
509cdf0e10cSrcweir 
510cdf0e10cSrcweir /*  [Beschreibung]
511cdf0e10cSrcweir 
512cdf0e10cSrcweir     Liefert die Anzahl der Eintr"age eines Bereiches
513cdf0e10cSrcweir 
514cdf0e10cSrcweir 
515cdf0e10cSrcweir     [R"uckgabewert]                 Anzahl der Eintr"age
516cdf0e10cSrcweir 
517cdf0e10cSrcweir */
518cdf0e10cSrcweir 
519cdf0e10cSrcweir {
520cdf0e10cSrcweir     DocTemplLocker_Impl aLocker( *pImp );
521cdf0e10cSrcweir 
522cdf0e10cSrcweir     if ( !pImp->Construct() )
523cdf0e10cSrcweir         return 0;
524cdf0e10cSrcweir 
525cdf0e10cSrcweir     RegionData_Impl *pData = pImp->GetRegion( nRegion );
526cdf0e10cSrcweir     sal_uIntPtr            nCount = 0;
527cdf0e10cSrcweir 
528cdf0e10cSrcweir     if ( pData )
529cdf0e10cSrcweir         nCount = pData->GetCount();
530cdf0e10cSrcweir 
531cdf0e10cSrcweir     return (sal_uInt16) nCount;
532cdf0e10cSrcweir }
533cdf0e10cSrcweir 
534cdf0e10cSrcweir //------------------------------------------------------------------------
535cdf0e10cSrcweir 
GetName(sal_uInt16 nRegion,sal_uInt16 nIdx) const536cdf0e10cSrcweir const String& SfxDocumentTemplates::GetName
537cdf0e10cSrcweir (
538cdf0e10cSrcweir     sal_uInt16 nRegion,     //  Index des Bereiches, in dem der Eintrag liegt
539cdf0e10cSrcweir     sal_uInt16 nIdx         //  Index des Eintrags
540cdf0e10cSrcweir )   const
541cdf0e10cSrcweir 
542cdf0e10cSrcweir /*  [Beschreibung]
543cdf0e10cSrcweir 
544cdf0e10cSrcweir     Liefert den logischen Namen eines Eintrags eines Bereiches
545cdf0e10cSrcweir 
546cdf0e10cSrcweir 
547cdf0e10cSrcweir     [R"uckgabewert]
548cdf0e10cSrcweir 
549cdf0e10cSrcweir     const String&           Name des Eintrags
550cdf0e10cSrcweir 
551cdf0e10cSrcweir */
552cdf0e10cSrcweir 
553cdf0e10cSrcweir {
554cdf0e10cSrcweir     DocTemplLocker_Impl aLocker( *pImp );
555cdf0e10cSrcweir 
556cdf0e10cSrcweir     static String maTmpString;
557cdf0e10cSrcweir 
558cdf0e10cSrcweir     if ( pImp->Construct() )
559cdf0e10cSrcweir     {
560cdf0e10cSrcweir         DocTempl_EntryData_Impl  *pEntry = NULL;
561cdf0e10cSrcweir         RegionData_Impl *pRegion = pImp->GetRegion( nRegion );
562cdf0e10cSrcweir 
563cdf0e10cSrcweir         if ( pRegion )
564cdf0e10cSrcweir             pEntry = pRegion->GetEntry( nIdx );
565cdf0e10cSrcweir 
566cdf0e10cSrcweir         if ( pEntry )
567cdf0e10cSrcweir             maTmpString = pEntry->GetTitle();
568cdf0e10cSrcweir         else
569cdf0e10cSrcweir             maTmpString.Erase();
570cdf0e10cSrcweir     }
571cdf0e10cSrcweir     else
572cdf0e10cSrcweir         maTmpString.Erase();
573cdf0e10cSrcweir 
574cdf0e10cSrcweir     return maTmpString;
575cdf0e10cSrcweir }
576cdf0e10cSrcweir 
577cdf0e10cSrcweir //------------------------------------------------------------------------
578cdf0e10cSrcweir 
GetFileName(sal_uInt16 nRegion,sal_uInt16 nIdx) const579cdf0e10cSrcweir String SfxDocumentTemplates::GetFileName
580cdf0e10cSrcweir (
581cdf0e10cSrcweir     sal_uInt16 nRegion,     //  Index des Bereiches, in dem der Eintrag liegt
582cdf0e10cSrcweir     sal_uInt16 nIdx         //  Index des Eintrags
583cdf0e10cSrcweir )   const
584cdf0e10cSrcweir 
585cdf0e10cSrcweir /*  [Beschreibung]
586cdf0e10cSrcweir 
587cdf0e10cSrcweir     Liefert den Dateinamen eines Eintrags eines Bereiches
588cdf0e10cSrcweir 
589cdf0e10cSrcweir     [R"uckgabewert]                 Dateiname des Eintrags
590cdf0e10cSrcweir 
591cdf0e10cSrcweir */
592cdf0e10cSrcweir {
593cdf0e10cSrcweir     DocTemplLocker_Impl aLocker( *pImp );
594cdf0e10cSrcweir 
595cdf0e10cSrcweir     if ( !pImp->Construct() )
596cdf0e10cSrcweir         return String();
597cdf0e10cSrcweir 
598cdf0e10cSrcweir     DocTempl_EntryData_Impl  *pEntry = NULL;
599cdf0e10cSrcweir     RegionData_Impl *pRegion = pImp->GetRegion( nRegion );
600cdf0e10cSrcweir 
601cdf0e10cSrcweir     if ( pRegion )
602cdf0e10cSrcweir         pEntry = pRegion->GetEntry( nIdx );
603cdf0e10cSrcweir 
604cdf0e10cSrcweir     if ( pEntry )
605cdf0e10cSrcweir     {
606cdf0e10cSrcweir         INetURLObject aURLObj( pEntry->GetTargetURL() );
607cdf0e10cSrcweir         return aURLObj.getName( INetURLObject::LAST_SEGMENT, true,
608cdf0e10cSrcweir                                 INetURLObject::DECODE_WITH_CHARSET );
609cdf0e10cSrcweir     }
610cdf0e10cSrcweir     else
611cdf0e10cSrcweir         return String();
612cdf0e10cSrcweir }
613cdf0e10cSrcweir 
614cdf0e10cSrcweir //------------------------------------------------------------------------
615cdf0e10cSrcweir 
GetPath(sal_uInt16 nRegion,sal_uInt16 nIdx) const616cdf0e10cSrcweir String SfxDocumentTemplates::GetPath
617cdf0e10cSrcweir (
618cdf0e10cSrcweir     sal_uInt16  nRegion,    //  Index des Bereiches, in dem der Eintrag liegt
619cdf0e10cSrcweir     sal_uInt16  nIdx        //  Index des Eintrags
620cdf0e10cSrcweir )   const
621cdf0e10cSrcweir 
622cdf0e10cSrcweir /*  [Beschreibung]
623cdf0e10cSrcweir 
624cdf0e10cSrcweir     Liefert den Dateinamen mit vollst"andigem Pfad zu der einem
625cdf0e10cSrcweir     Eintrag zugeordneten Datei
626cdf0e10cSrcweir 
627cdf0e10cSrcweir 
628cdf0e10cSrcweir     [R"uckgabewert]
629cdf0e10cSrcweir 
630cdf0e10cSrcweir     String                  Dateiname mit vollst"andigem Pfad
631cdf0e10cSrcweir 
632cdf0e10cSrcweir */
633cdf0e10cSrcweir {
634cdf0e10cSrcweir     DocTemplLocker_Impl aLocker( *pImp );
635cdf0e10cSrcweir 
636cdf0e10cSrcweir     if ( !pImp->Construct() )
637cdf0e10cSrcweir         return String();
638cdf0e10cSrcweir 
639cdf0e10cSrcweir     DocTempl_EntryData_Impl  *pEntry = NULL;
640cdf0e10cSrcweir     RegionData_Impl *pRegion = pImp->GetRegion( nRegion );
641cdf0e10cSrcweir 
642cdf0e10cSrcweir     if ( pRegion )
643cdf0e10cSrcweir         pEntry = pRegion->GetEntry( nIdx );
644cdf0e10cSrcweir 
645cdf0e10cSrcweir     if ( pEntry )
646cdf0e10cSrcweir         return pEntry->GetTargetURL();
647cdf0e10cSrcweir     else
648cdf0e10cSrcweir         return String();
649cdf0e10cSrcweir }
650cdf0e10cSrcweir 
651cdf0e10cSrcweir //------------------------------------------------------------------------
652cdf0e10cSrcweir 
GetTemplatePath(sal_uInt16 nRegion,const String & rLongName) const653cdf0e10cSrcweir String SfxDocumentTemplates::GetTemplatePath
654cdf0e10cSrcweir (
655cdf0e10cSrcweir     sal_uInt16          nRegion,    //  Index des Bereiches, in dem der Eintrag liegt
656cdf0e10cSrcweir     const String&   rLongName   //  logischer Name des Eintrags
657cdf0e10cSrcweir )   const
658cdf0e10cSrcweir 
659cdf0e10cSrcweir /*  [Beschreibung]
660cdf0e10cSrcweir 
661cdf0e10cSrcweir     Liefert den Dateinamen mit vollst"andigem Pfad zu der einem
662cdf0e10cSrcweir     Eintrag zugeordneten Datei
663cdf0e10cSrcweir 
664cdf0e10cSrcweir 
665cdf0e10cSrcweir     [R"uckgabewert]
666cdf0e10cSrcweir 
667cdf0e10cSrcweir     String                          Dateiname mit vollst"andigem Pfad
668cdf0e10cSrcweir 
669cdf0e10cSrcweir */
670cdf0e10cSrcweir {
671cdf0e10cSrcweir     DocTemplLocker_Impl aLocker( *pImp );
672cdf0e10cSrcweir 
673cdf0e10cSrcweir     if ( !pImp->Construct() )
674cdf0e10cSrcweir         return String();
675cdf0e10cSrcweir 
676cdf0e10cSrcweir     DocTempl_EntryData_Impl  *pEntry = NULL;
677cdf0e10cSrcweir     RegionData_Impl *pRegion = pImp->GetRegion( nRegion );
678cdf0e10cSrcweir 
679cdf0e10cSrcweir     if ( pRegion )
680cdf0e10cSrcweir         pEntry = pRegion->GetEntry( rLongName );
681cdf0e10cSrcweir 
682cdf0e10cSrcweir     if ( pEntry )
683cdf0e10cSrcweir         return pEntry->GetTargetURL();
684cdf0e10cSrcweir     else if ( pRegion )
685cdf0e10cSrcweir     {
686cdf0e10cSrcweir         // a new template is going to be inserted, generate a new URL
687cdf0e10cSrcweir         // TODO/LATER: if the title is localized, use minimized URL in future
688cdf0e10cSrcweir 
689cdf0e10cSrcweir         // --**-- extension handling will become more complicated, because
690cdf0e10cSrcweir         //          every new document type will have it's own extension
691cdf0e10cSrcweir         //          e.g.: .stw or .stc instead of .vor
692cdf0e10cSrcweir         INetURLObject aURLObj( pRegion->GetTargetURL() );
693cdf0e10cSrcweir         aURLObj.insertName( rLongName, false,
694cdf0e10cSrcweir                      INetURLObject::LAST_SEGMENT, true,
695cdf0e10cSrcweir                      INetURLObject::ENCODE_ALL );
696cdf0e10cSrcweir 
697cdf0e10cSrcweir         OUString aExtension = aURLObj.getExtension();
698cdf0e10cSrcweir 
699cdf0e10cSrcweir         if ( ! aExtension.getLength() )
700cdf0e10cSrcweir             aURLObj.setExtension( OUString( RTL_CONSTASCII_USTRINGPARAM( "vor" ) ) );
701cdf0e10cSrcweir 
702cdf0e10cSrcweir         return aURLObj.GetMainURL( INetURLObject::NO_DECODE );
703cdf0e10cSrcweir     }
704cdf0e10cSrcweir     else
705cdf0e10cSrcweir         return String();
706cdf0e10cSrcweir }
707cdf0e10cSrcweir 
708cdf0e10cSrcweir //------------------------------------------------------------------------
709cdf0e10cSrcweir 
GetDefaultTemplatePath(const String & rLongName)710cdf0e10cSrcweir String SfxDocumentTemplates::GetDefaultTemplatePath
711cdf0e10cSrcweir (
712cdf0e10cSrcweir     const String& rLongName
713cdf0e10cSrcweir )
714cdf0e10cSrcweir 
715cdf0e10cSrcweir /*  [Beschreibung]
716cdf0e10cSrcweir 
717cdf0e10cSrcweir     Liefert den Standardpfad zu Dokumentvorlagen
718cdf0e10cSrcweir 
719cdf0e10cSrcweir 
720cdf0e10cSrcweir     [R"uckgabewert]
721cdf0e10cSrcweir 
722cdf0e10cSrcweir     String                  Standardpfad zu Dokumentvorlagen
723cdf0e10cSrcweir 
724cdf0e10cSrcweir */
725cdf0e10cSrcweir {
726cdf0e10cSrcweir     DocTemplLocker_Impl aLocker( *pImp );
727cdf0e10cSrcweir 
728cdf0e10cSrcweir     if ( ! pImp->Construct() )
729cdf0e10cSrcweir         return String();
730cdf0e10cSrcweir 
731cdf0e10cSrcweir     // the first region in the list should always be the standard
732cdf0e10cSrcweir     // group
733cdf0e10cSrcweir     // --**-- perhaps we have to create it ???
734cdf0e10cSrcweir     RegionData_Impl *pRegion = pImp->GetRegion( 0L );
735cdf0e10cSrcweir     DocTempl_EntryData_Impl  *pEntry = NULL;
736cdf0e10cSrcweir 
737cdf0e10cSrcweir     if ( pRegion )
738cdf0e10cSrcweir         pEntry = pRegion->GetEntry( rLongName );
739cdf0e10cSrcweir 
740cdf0e10cSrcweir     if ( pEntry )
741cdf0e10cSrcweir         return pEntry->GetTargetURL();
742cdf0e10cSrcweir     else if ( pRegion )
743cdf0e10cSrcweir     {
744cdf0e10cSrcweir         // a new template is going to be inserted, generate a new URL
745cdf0e10cSrcweir         // TODO/LATER: if the title is localized, use minimized URL in future
746cdf0e10cSrcweir 
747cdf0e10cSrcweir         INetURLObject aURLObj( pRegion->GetTargetURL() );
748cdf0e10cSrcweir         aURLObj.insertName( rLongName, false,
749cdf0e10cSrcweir                      INetURLObject::LAST_SEGMENT, true,
750cdf0e10cSrcweir                      INetURLObject::ENCODE_ALL );
751cdf0e10cSrcweir 
752cdf0e10cSrcweir         OUString aExtension = aURLObj.getExtension();
753cdf0e10cSrcweir 
754cdf0e10cSrcweir         if ( ! aExtension.getLength() )
755cdf0e10cSrcweir             aURLObj.setExtension( OUString( RTL_CONSTASCII_USTRINGPARAM( "vor" ) ) );
756cdf0e10cSrcweir 
757cdf0e10cSrcweir         return aURLObj.GetMainURL( INetURLObject::NO_DECODE );
758cdf0e10cSrcweir     }
759cdf0e10cSrcweir     else
760cdf0e10cSrcweir         return String();
761cdf0e10cSrcweir 
762cdf0e10cSrcweir /* dv! missing: create the directory, if it doesn't exists
763cdf0e10cSrcweir 
764cdf0e10cSrcweir 
765cdf0e10cSrcweir     DBG_ASSERT(aDirs.GetTokenCount(cDelim), "Keine Bereiche");
766cdf0e10cSrcweir     DirEntry aPath(aDirs.GetToken(0, cDelim));
767cdf0e10cSrcweir 
768cdf0e10cSrcweir     // Verzeichnis anlegen
769cdf0e10cSrcweir     if(!aPath.MakeDir())
770cdf0e10cSrcweir         return String();
771cdf0e10cSrcweir 
772cdf0e10cSrcweir     MakeFileName_Impl(aPath, rLongName, sal_True);
773cdf0e10cSrcweir     SfxTemplateDir  *pEntry = new SfxTemplateDir;
774cdf0e10cSrcweir     SfxTemplateDirEntryPtr pDirEntry =
775cdf0e10cSrcweir         new SfxTemplateDirEntry( String( '.' ), aPath.GetPath() );
776cdf0e10cSrcweir     pDirEntry->SetContent(new SfxTemplateDir(aPath.GetPath()));
777cdf0e10cSrcweir     pEntry->Insert(pDirEntry, pEntry->Count());
778cdf0e10cSrcweir     pDirs->Insert(pEntry, pDirs->Count());
779cdf0e10cSrcweir     return aPath.GetFull();
780cdf0e10cSrcweir */
781cdf0e10cSrcweir }
782cdf0e10cSrcweir 
783cdf0e10cSrcweir //------------------------------------------------------------------------
784cdf0e10cSrcweir 
GetTemplateTargetURLFromComponent(const::rtl::OUString & aGroupName,const::rtl::OUString & aTitle)785cdf0e10cSrcweir ::rtl::OUString SfxDocumentTemplates::GetTemplateTargetURLFromComponent( const ::rtl::OUString& aGroupName,
786cdf0e10cSrcweir                                                                          const ::rtl::OUString& aTitle )
787cdf0e10cSrcweir {
788cdf0e10cSrcweir     DocTemplLocker_Impl aLocker( *pImp );
789cdf0e10cSrcweir 
790cdf0e10cSrcweir     INetURLObject aTemplateObj( pImp->GetRootURL() );
791cdf0e10cSrcweir 
792cdf0e10cSrcweir     aTemplateObj.insertName( aGroupName, false,
793cdf0e10cSrcweir                         INetURLObject::LAST_SEGMENT, true,
794cdf0e10cSrcweir                         INetURLObject::ENCODE_ALL );
795cdf0e10cSrcweir 
796cdf0e10cSrcweir     aTemplateObj.insertName( aTitle, false,
797cdf0e10cSrcweir                         INetURLObject::LAST_SEGMENT, true,
798cdf0e10cSrcweir                         INetURLObject::ENCODE_ALL );
799cdf0e10cSrcweir 
800cdf0e10cSrcweir 
801cdf0e10cSrcweir     ::rtl::OUString aResult;
802cdf0e10cSrcweir     Content aTemplate;
803cdf0e10cSrcweir     uno::Reference< XCommandEnvironment > aCmdEnv;
804cdf0e10cSrcweir     if ( Content::create( aTemplateObj.GetMainURL( INetURLObject::NO_DECODE ), aCmdEnv, aTemplate ) )
805cdf0e10cSrcweir     {
806cdf0e10cSrcweir         OUString aPropName( RTL_CONSTASCII_USTRINGPARAM( TARGET_URL ) );
807cdf0e10cSrcweir         getTextProperty_Impl( aTemplate, aPropName, aResult );
808cdf0e10cSrcweir         aResult = SvtPathOptions().SubstituteVariable( aResult );
809cdf0e10cSrcweir     }
810cdf0e10cSrcweir 
811cdf0e10cSrcweir     return aResult;
812cdf0e10cSrcweir }
813cdf0e10cSrcweir 
814cdf0e10cSrcweir //------------------------------------------------------------------------
815cdf0e10cSrcweir 
SaveDir()816cdf0e10cSrcweir sal_Bool SfxDocumentTemplates::SaveDir
817cdf0e10cSrcweir (
818cdf0e10cSrcweir //  SfxTemplateDir& rDir        //  das zu speichernde Directory
819cdf0e10cSrcweir )
820cdf0e10cSrcweir 
821cdf0e10cSrcweir /*  [Beschreibung]
822cdf0e10cSrcweir 
823cdf0e10cSrcweir     Speichert das Directory rDir
824cdf0e10cSrcweir 
825cdf0e10cSrcweir 
826cdf0e10cSrcweir     [R"uckgabewert]
827cdf0e10cSrcweir 
828cdf0e10cSrcweir     sal_Bool                        sal_False,
829cdf0e10cSrcweir                                 Schreibfehler
830cdf0e10cSrcweir 
831cdf0e10cSrcweir                                 sal_True
832cdf0e10cSrcweir                                 gespeichert
833cdf0e10cSrcweir 
834cdf0e10cSrcweir */
835cdf0e10cSrcweir 
836cdf0e10cSrcweir {
837cdf0e10cSrcweir     return sal_True;
838cdf0e10cSrcweir }
839cdf0e10cSrcweir 
840cdf0e10cSrcweir //------------------------------------------------------------------------
841cdf0e10cSrcweir 
NewTemplate(sal_uInt16 nRegion,const String & rLongName,const String & rFileName)842cdf0e10cSrcweir void SfxDocumentTemplates::NewTemplate
843cdf0e10cSrcweir (
844cdf0e10cSrcweir     sal_uInt16          nRegion,    /*  Index des Bereiches, in dem die Vorlage
845cdf0e10cSrcweir                                     angelegt werden soll */
846cdf0e10cSrcweir 
847cdf0e10cSrcweir     const String&   rLongName,  //  logischer Name der neuen Vorlage
848cdf0e10cSrcweir     const String&   rFileName   //  Dateiname der neuen Vorlage
849cdf0e10cSrcweir )
850cdf0e10cSrcweir 
851cdf0e10cSrcweir /*  [Beschreibung]
852cdf0e10cSrcweir 
853cdf0e10cSrcweir     Eintragen einer neuen Dokumentvorlage in die Verwaltungsstrukturen
854cdf0e10cSrcweir     Das "Uberschreiben einer Vorlage gleichen Namens wird
855cdf0e10cSrcweir     verhindert (!! Fehlermeldung)
856cdf0e10cSrcweir 
857cdf0e10cSrcweir */
858cdf0e10cSrcweir 
859cdf0e10cSrcweir {
860cdf0e10cSrcweir     DocTemplLocker_Impl aLocker( *pImp );
861cdf0e10cSrcweir 
862cdf0e10cSrcweir     if ( ! pImp->Construct() )
863cdf0e10cSrcweir         return;
864cdf0e10cSrcweir 
865cdf0e10cSrcweir     DocTempl_EntryData_Impl  *pEntry;
866cdf0e10cSrcweir     RegionData_Impl *pRegion = pImp->GetRegion( nRegion );
867cdf0e10cSrcweir 
868cdf0e10cSrcweir     // do nothing if there is no region with that index
869cdf0e10cSrcweir     if ( !pRegion )
870cdf0e10cSrcweir         return;
871cdf0e10cSrcweir 
872cdf0e10cSrcweir     pEntry = pRegion->GetEntry( rLongName );
873cdf0e10cSrcweir 
874cdf0e10cSrcweir     // do nothing if there is already an entry with that name
875cdf0e10cSrcweir     if ( pEntry )
876cdf0e10cSrcweir         return;
877cdf0e10cSrcweir 
878cdf0e10cSrcweir     uno::Reference< XDocumentTemplates > xTemplates = pImp->getDocTemplates();
879cdf0e10cSrcweir 
880cdf0e10cSrcweir     if ( xTemplates->addTemplate( pRegion->GetTitle(), rLongName, rFileName ) )
881cdf0e10cSrcweir         pRegion->AddEntry( rLongName, rFileName );
882cdf0e10cSrcweir }
883cdf0e10cSrcweir 
884cdf0e10cSrcweir //------------------------------------------------------------------------
885cdf0e10cSrcweir 
CopyOrMove(sal_uInt16 nTargetRegion,sal_uInt16 nTargetIdx,sal_uInt16 nSourceRegion,sal_uInt16 nSourceIdx,sal_Bool bMove)886cdf0e10cSrcweir sal_Bool SfxDocumentTemplates::CopyOrMove
887cdf0e10cSrcweir (
888cdf0e10cSrcweir     sal_uInt16  nTargetRegion,      //  Index des Zielbereiches
889cdf0e10cSrcweir     sal_uInt16  nTargetIdx,         //  Index Zielposition
890cdf0e10cSrcweir     sal_uInt16  nSourceRegion,      //  Index des Quellbereiches
891cdf0e10cSrcweir     sal_uInt16  nSourceIdx,         /*  Index der zu kopierenden / zu verschiebenden
892cdf0e10cSrcweir                                     Dokumentvorlage */
893cdf0e10cSrcweir     sal_Bool    bMove               //  kopieren / verschieben
894cdf0e10cSrcweir )
895cdf0e10cSrcweir 
896cdf0e10cSrcweir /*  [Beschreibung]
897cdf0e10cSrcweir 
898cdf0e10cSrcweir     Kopieren oder Verschieben einer Dokumentvorlage
899cdf0e10cSrcweir 
900cdf0e10cSrcweir     [R"uckgabewert]
901cdf0e10cSrcweir 
902cdf0e10cSrcweir     sal_Bool                            sal_True
903cdf0e10cSrcweir                                     Aktion konnte ausgef"uhrt werden
904cdf0e10cSrcweir 
905cdf0e10cSrcweir                                     sal_False
906cdf0e10cSrcweir                                     Aktion konnte nicht ausgef2uhrt werden
907cdf0e10cSrcweir     [Querverweise]
908cdf0e10cSrcweir 
909cdf0e10cSrcweir     <SfxDocumentTemplates::Move(sal_uInt16,sal_uInt16,sal_uInt16,sal_uInt16)>
910cdf0e10cSrcweir     <SfxDocumentTemplates::Copy(sal_uInt16,sal_uInt16,sal_uInt16,sal_uInt16)>
911cdf0e10cSrcweir */
912cdf0e10cSrcweir 
913cdf0e10cSrcweir {
914cdf0e10cSrcweir     /* to perform a copy or move, we need to send a transfer command to
915cdf0e10cSrcweir        the destination folder with the URL of the source as parameter.
916cdf0e10cSrcweir        ( If the destination content doesn't support the transfer command,
917cdf0e10cSrcweir        we could try a copy ( and delete ) instead. )
918cdf0e10cSrcweir        We need two transfers ( one for the real template and one for its
919cdf0e10cSrcweir        representation in the hierarchy )
920cdf0e10cSrcweir        ...
921cdf0e10cSrcweir     */
922cdf0e10cSrcweir 
923cdf0e10cSrcweir     DocTemplLocker_Impl aLocker( *pImp );
924cdf0e10cSrcweir 
925cdf0e10cSrcweir     if ( !pImp->Construct() )
926cdf0e10cSrcweir         return sal_False;
927cdf0e10cSrcweir 
928cdf0e10cSrcweir     // Don't copy or move any folders
929cdf0e10cSrcweir     if( nSourceIdx == USHRT_MAX )
930cdf0e10cSrcweir         return sal_False ;
931cdf0e10cSrcweir 
932cdf0e10cSrcweir     if ( nSourceRegion == nTargetRegion )
933cdf0e10cSrcweir     {
934cdf0e10cSrcweir         DBG_ERRORFILE( "Don't know, what to do!" );
935cdf0e10cSrcweir         return sal_False;
936cdf0e10cSrcweir #if 0
937cdf0e10cSrcweir     // Verschieben einer Vorlage innerhalb eines Bereiches
938cdf0e10cSrcweir     // --> nur Verwaltungsdaten aktualisieren
939cdf0e10cSrcweir     if ( bMove && nTargetRegion == nSourceRegion )
940cdf0e10cSrcweir     {
941cdf0e10cSrcweir         if(nTargetIdx == USHRT_MAX)
942cdf0e10cSrcweir             nTargetIdx = 0;
943cdf0e10cSrcweir         const SfxTemplateDirEntryPtr pEntry = rTargetDir[nSourceIdx];
944cdf0e10cSrcweir         rTargetDir.Insert(pEntry, nTargetIdx);
945cdf0e10cSrcweir         if(nTargetIdx < nSourceIdx)
946cdf0e10cSrcweir             ++nSourceIdx;
947cdf0e10cSrcweir         rTargetDir.Remove(nSourceIdx);
948cdf0e10cSrcweir         return SaveDir(rTargetDir);
949cdf0e10cSrcweir     }
950cdf0e10cSrcweir #endif
951cdf0e10cSrcweir     }
952cdf0e10cSrcweir 
953cdf0e10cSrcweir     RegionData_Impl *pSourceRgn = pImp->GetRegion( nSourceRegion );
954cdf0e10cSrcweir     if ( !pSourceRgn )
955cdf0e10cSrcweir         return sal_False;
956cdf0e10cSrcweir 
957cdf0e10cSrcweir     DocTempl_EntryData_Impl *pSource = pSourceRgn->GetEntry( nSourceIdx );
958cdf0e10cSrcweir     if ( !pSource )
959cdf0e10cSrcweir         return sal_False;
960cdf0e10cSrcweir 
961cdf0e10cSrcweir     RegionData_Impl *pTargetRgn = pImp->GetRegion( nTargetRegion );
962cdf0e10cSrcweir     if ( !pTargetRgn )
963cdf0e10cSrcweir         return sal_False;
964cdf0e10cSrcweir 
965cdf0e10cSrcweir     OUString aTitle = pSource->GetTitle();
966cdf0e10cSrcweir 
967cdf0e10cSrcweir     uno::Reference< XDocumentTemplates > xTemplates = pImp->getDocTemplates();
968cdf0e10cSrcweir 
969cdf0e10cSrcweir     if ( xTemplates->addTemplate( pTargetRgn->GetTitle(),
970cdf0e10cSrcweir                                   aTitle,
971cdf0e10cSrcweir                                   pSource->GetTargetURL() ) )
972cdf0e10cSrcweir     {
973cdf0e10cSrcweir 
974cdf0e10cSrcweir         INetURLObject aSourceObj( pSource->GetTargetURL() );
975cdf0e10cSrcweir 
976cdf0e10cSrcweir         ::rtl::OUString aNewTargetURL = GetTemplateTargetURLFromComponent( pTargetRgn->GetTitle(), aTitle );
977cdf0e10cSrcweir         if ( !aNewTargetURL.getLength() )
978cdf0e10cSrcweir             return sal_False;
979cdf0e10cSrcweir 
980cdf0e10cSrcweir         if ( bMove )
981cdf0e10cSrcweir         {
982cdf0e10cSrcweir             // --**-- delete the original file
983cdf0e10cSrcweir             sal_Bool bDeleted = xTemplates->removeTemplate( pSourceRgn->GetTitle(),
984cdf0e10cSrcweir                                                             pSource->GetTitle() );
985cdf0e10cSrcweir             if ( bDeleted )
986cdf0e10cSrcweir                 pSourceRgn->DeleteEntry( nSourceIdx );
987cdf0e10cSrcweir             else
988cdf0e10cSrcweir             {
989cdf0e10cSrcweir                 if ( xTemplates->removeTemplate( pTargetRgn->GetTitle(), aTitle ) )
990cdf0e10cSrcweir                     return sal_False; // will trigger tetry with copy instead of move
991cdf0e10cSrcweir 
992cdf0e10cSrcweir                 // if it is not possible to remove just created template ( must be possible! )
993cdf0e10cSrcweir                 // it is better to report success here, since at least the copy has succeeded
994cdf0e10cSrcweir                 // TODO/LATER: solve it more gracefully in future
995cdf0e10cSrcweir             }
996cdf0e10cSrcweir         }
997cdf0e10cSrcweir 
998cdf0e10cSrcweir         pTargetRgn->AddEntry( aTitle, aNewTargetURL, &nTargetIdx );
999cdf0e10cSrcweir 
1000cdf0e10cSrcweir         return sal_True;
1001cdf0e10cSrcweir     }
1002cdf0e10cSrcweir 
1003cdf0e10cSrcweir     // --**-- wenn aktuell das File geoeffnet ist,
1004cdf0e10cSrcweir     // muss es hinterher wieder geoeffnet werden
1005cdf0e10cSrcweir 
1006cdf0e10cSrcweir     return sal_False;
1007cdf0e10cSrcweir }
1008cdf0e10cSrcweir 
1009cdf0e10cSrcweir //------------------------------------------------------------------------
1010cdf0e10cSrcweir 
Move(sal_uInt16 nTargetRegion,sal_uInt16 nTargetIdx,sal_uInt16 nSourceRegion,sal_uInt16 nSourceIdx)1011cdf0e10cSrcweir sal_Bool SfxDocumentTemplates::Move
1012cdf0e10cSrcweir (
1013cdf0e10cSrcweir     sal_uInt16 nTargetRegion,       //  Index des Zielbereiches
1014cdf0e10cSrcweir     sal_uInt16 nTargetIdx,          //  Index Zielposition
1015cdf0e10cSrcweir     sal_uInt16 nSourceRegion,       //  Index des Quellbereiches
1016cdf0e10cSrcweir     sal_uInt16 nSourceIdx           /*  Index der zu kopierenden / zu verschiebenden
1017cdf0e10cSrcweir                                     Dokumentvorlage */
1018cdf0e10cSrcweir )
1019cdf0e10cSrcweir 
1020cdf0e10cSrcweir /*  [Beschreibung]
1021cdf0e10cSrcweir 
1022cdf0e10cSrcweir     Verschieben einer Dokumentvorlage
1023cdf0e10cSrcweir 
1024cdf0e10cSrcweir 
1025cdf0e10cSrcweir     [R"uckgabewert]
1026cdf0e10cSrcweir 
1027cdf0e10cSrcweir     sal_Bool                            sal_True
1028cdf0e10cSrcweir                                     Aktion konnte ausgef"uhrt werden
1029cdf0e10cSrcweir 
1030cdf0e10cSrcweir                                     sal_False
1031cdf0e10cSrcweir                                     Aktion konnte nicht ausgef2uhrt werden
1032cdf0e10cSrcweir 
1033cdf0e10cSrcweir     [Querverweise]
1034cdf0e10cSrcweir 
1035cdf0e10cSrcweir     <SfxDocumentTemplates::CopyOrMove(sal_uInt16,sal_uInt16,sal_uInt16,sal_uInt16,sal_Bool)>
1036cdf0e10cSrcweir */
1037cdf0e10cSrcweir {
1038cdf0e10cSrcweir     DocTemplLocker_Impl aLocker( *pImp );
1039cdf0e10cSrcweir 
1040cdf0e10cSrcweir     return CopyOrMove( nTargetRegion, nTargetIdx,
1041cdf0e10cSrcweir                        nSourceRegion, nSourceIdx, sal_True );
1042cdf0e10cSrcweir }
1043cdf0e10cSrcweir 
1044cdf0e10cSrcweir //------------------------------------------------------------------------
1045cdf0e10cSrcweir 
Copy(sal_uInt16 nTargetRegion,sal_uInt16 nTargetIdx,sal_uInt16 nSourceRegion,sal_uInt16 nSourceIdx)1046cdf0e10cSrcweir sal_Bool SfxDocumentTemplates::Copy
1047cdf0e10cSrcweir (
1048cdf0e10cSrcweir     sal_uInt16 nTargetRegion,       //  Index des Zielbereiches
1049cdf0e10cSrcweir     sal_uInt16 nTargetIdx,          //  Index Zielposition
1050cdf0e10cSrcweir     sal_uInt16 nSourceRegion,       //  Index des Quellbereiches
1051cdf0e10cSrcweir     sal_uInt16 nSourceIdx           /*  Index der zu kopierenden / zu verschiebenden
1052cdf0e10cSrcweir                                     Dokumentvorlage */
1053cdf0e10cSrcweir )
1054cdf0e10cSrcweir 
1055cdf0e10cSrcweir /*  [Beschreibung]
1056cdf0e10cSrcweir 
1057cdf0e10cSrcweir     Kopieren einer Dokumentvorlage
1058cdf0e10cSrcweir 
1059cdf0e10cSrcweir 
1060cdf0e10cSrcweir     [R"uckgabewert]
1061cdf0e10cSrcweir 
1062cdf0e10cSrcweir     sal_Bool                            sal_True
1063cdf0e10cSrcweir                                     Aktion konnte ausgef"uhrt werden
1064cdf0e10cSrcweir 
1065cdf0e10cSrcweir                                     sal_False
1066cdf0e10cSrcweir                                     Aktion konnte nicht ausgef"uhrt werden
1067cdf0e10cSrcweir 
1068cdf0e10cSrcweir     [Querverweise]
1069cdf0e10cSrcweir 
1070cdf0e10cSrcweir     <SfxDocumentTemplates::CopyOrMove(sal_uInt16,sal_uInt16,sal_uInt16,sal_uInt16,sal_Bool)>
1071cdf0e10cSrcweir */
1072cdf0e10cSrcweir 
1073cdf0e10cSrcweir {
1074cdf0e10cSrcweir     DocTemplLocker_Impl aLocker( *pImp );
1075cdf0e10cSrcweir 
1076cdf0e10cSrcweir     return CopyOrMove( nTargetRegion, nTargetIdx,
1077cdf0e10cSrcweir                        nSourceRegion, nSourceIdx, sal_False );
1078cdf0e10cSrcweir }
1079cdf0e10cSrcweir 
1080cdf0e10cSrcweir //------------------------------------------------------------------------
1081cdf0e10cSrcweir 
CopyTo(sal_uInt16 nRegion,sal_uInt16 nIdx,const String & rName) const1082cdf0e10cSrcweir sal_Bool SfxDocumentTemplates::CopyTo
1083cdf0e10cSrcweir (
1084cdf0e10cSrcweir     sal_uInt16          nRegion,    /*  Bereich der Vorlage, die exportiert werden
1085cdf0e10cSrcweir                                     soll  */
1086cdf0e10cSrcweir     sal_uInt16          nIdx,       /*  Index der Vorlage, die exportiert werden
1087cdf0e10cSrcweir                                     soll */
1088cdf0e10cSrcweir     const String&   rName       /*  Dateiname, unter dem die Vorlage angelegt
1089cdf0e10cSrcweir                                     werden soll */
1090cdf0e10cSrcweir )   const
1091cdf0e10cSrcweir 
1092cdf0e10cSrcweir /*  [Beschreibung]
1093cdf0e10cSrcweir 
1094cdf0e10cSrcweir     Exportieren einer Dokumentvorlage in das Dateisystem
1095cdf0e10cSrcweir 
1096cdf0e10cSrcweir 
1097cdf0e10cSrcweir     [R"uckgabewert]
1098cdf0e10cSrcweir 
1099cdf0e10cSrcweir     sal_Bool                            sal_True
1100cdf0e10cSrcweir                                     Aktion konnte ausgef"uhrt werden
1101cdf0e10cSrcweir 
1102cdf0e10cSrcweir                                     sal_False
1103cdf0e10cSrcweir                                     Aktion konnte nicht ausgef"uhrt werden
1104cdf0e10cSrcweir 
1105cdf0e10cSrcweir 
1106cdf0e10cSrcweir     [Querverweise]
1107cdf0e10cSrcweir 
1108cdf0e10cSrcweir     <SfxDocumentTemplates::CopyFrom(sal_uInt16,sal_uInt16,String&)>
1109cdf0e10cSrcweir */
1110cdf0e10cSrcweir 
1111cdf0e10cSrcweir {
1112cdf0e10cSrcweir     DocTemplLocker_Impl aLocker( *pImp );
1113cdf0e10cSrcweir 
1114cdf0e10cSrcweir     if ( ! pImp->Construct() )
1115cdf0e10cSrcweir         return sal_False;
1116cdf0e10cSrcweir 
1117cdf0e10cSrcweir     RegionData_Impl *pSourceRgn = pImp->GetRegion( nRegion );
1118cdf0e10cSrcweir     if ( !pSourceRgn )
1119cdf0e10cSrcweir         return sal_False;
1120cdf0e10cSrcweir 
1121cdf0e10cSrcweir     DocTempl_EntryData_Impl *pSource = pSourceRgn->GetEntry( nIdx );
1122cdf0e10cSrcweir     if ( !pSource )
1123cdf0e10cSrcweir         return sal_False;
1124cdf0e10cSrcweir 
1125cdf0e10cSrcweir     INetURLObject aTargetURL( rName );
1126cdf0e10cSrcweir 
1127cdf0e10cSrcweir     OUString aTitle( aTargetURL.getName( INetURLObject::LAST_SEGMENT, true,
1128cdf0e10cSrcweir                                          INetURLObject::DECODE_WITH_CHARSET ) );
1129cdf0e10cSrcweir     aTargetURL.removeSegment();
1130cdf0e10cSrcweir 
1131cdf0e10cSrcweir     OUString aParentURL = aTargetURL.GetMainURL( INetURLObject::NO_DECODE );
1132cdf0e10cSrcweir 
1133cdf0e10cSrcweir     uno::Reference< XCommandEnvironment > aCmdEnv;
1134cdf0e10cSrcweir     Content aTarget;
1135cdf0e10cSrcweir 
1136cdf0e10cSrcweir     try
1137cdf0e10cSrcweir     {
1138cdf0e10cSrcweir         aTarget = Content( aParentURL, aCmdEnv );
1139cdf0e10cSrcweir 
1140cdf0e10cSrcweir         TransferInfo aTransferInfo;
1141cdf0e10cSrcweir         aTransferInfo.MoveData = sal_False;
1142cdf0e10cSrcweir         aTransferInfo.SourceURL = pSource->GetTargetURL();
1143cdf0e10cSrcweir         aTransferInfo.NewTitle = aTitle;
1144cdf0e10cSrcweir         aTransferInfo.NameClash = NameClash::OVERWRITE;
1145cdf0e10cSrcweir 
1146cdf0e10cSrcweir         Any aArg = makeAny( aTransferInfo );
1147cdf0e10cSrcweir         OUString aCmd( RTL_CONSTASCII_USTRINGPARAM( COMMAND_TRANSFER ) );
1148cdf0e10cSrcweir 
1149cdf0e10cSrcweir         aTarget.executeCommand( aCmd, aArg );
1150cdf0e10cSrcweir     }
1151cdf0e10cSrcweir     catch ( ContentCreationException& )
1152cdf0e10cSrcweir     { return sal_False; }
1153cdf0e10cSrcweir     catch ( Exception& )
1154cdf0e10cSrcweir     { return sal_False; }
1155cdf0e10cSrcweir 
1156cdf0e10cSrcweir     return sal_True;
1157cdf0e10cSrcweir }
1158cdf0e10cSrcweir 
1159cdf0e10cSrcweir //------------------------------------------------------------------------
1160cdf0e10cSrcweir 
CopyFrom(sal_uInt16 nRegion,sal_uInt16 nIdx,String & rName)1161cdf0e10cSrcweir sal_Bool SfxDocumentTemplates::CopyFrom
1162cdf0e10cSrcweir (
1163cdf0e10cSrcweir     sal_uInt16      nRegion,        /*  Bereich, in den die Vorlage importiert
1164cdf0e10cSrcweir                                     werden soll */
1165cdf0e10cSrcweir     sal_uInt16      nIdx,           //  Index der neuen Vorlage in diesem Bereich
1166cdf0e10cSrcweir     String&     rName           /*  Dateiname der Vorlage, die importiert
1167cdf0e10cSrcweir                                     werden soll, als out-Parameter der (auto-
1168cdf0e10cSrcweir                                     matisch aus dem Dateinamen generierte)
1169cdf0e10cSrcweir                                     logische Name der Vorlage */
1170cdf0e10cSrcweir )
1171cdf0e10cSrcweir 
1172cdf0e10cSrcweir /*  [Beschreibung]
1173cdf0e10cSrcweir 
1174cdf0e10cSrcweir     Importieren einer Dokumentvorlage aus dem Dateisystem
1175cdf0e10cSrcweir 
1176cdf0e10cSrcweir 
1177cdf0e10cSrcweir     [R"uckgabewert]                 Erfolg (sal_True) oder Mi"serfpTargetDirectory->GetContent());
1178cdf0e10cSrcweir 
1179cdf0e10cSrcweir     sal_Bool                            sal_True
1180cdf0e10cSrcweir                                     Aktion konnte ausgef"uhrt werden
1181cdf0e10cSrcweir 
1182cdf0e10cSrcweir                                     sal_False
1183cdf0e10cSrcweir                                     Aktion konnte nicht ausgef"uhrt werden
1184cdf0e10cSrcweir 
1185cdf0e10cSrcweir     [Querverweise]
1186cdf0e10cSrcweir 
1187cdf0e10cSrcweir     <SfxDocumentTemplates::CopyTo(sal_uInt16,sal_uInt16,const String&)>
1188cdf0e10cSrcweir */
1189cdf0e10cSrcweir 
1190cdf0e10cSrcweir {
1191cdf0e10cSrcweir     DocTemplLocker_Impl aLocker( *pImp );
1192cdf0e10cSrcweir 
1193cdf0e10cSrcweir     if ( ! pImp->Construct() )
1194cdf0e10cSrcweir         return sal_False;
1195cdf0e10cSrcweir 
1196cdf0e10cSrcweir     RegionData_Impl *pTargetRgn = pImp->GetRegion( nRegion );
1197cdf0e10cSrcweir 
1198cdf0e10cSrcweir     if ( !pTargetRgn )
1199cdf0e10cSrcweir         return sal_False;
1200cdf0e10cSrcweir 
1201cdf0e10cSrcweir     uno::Reference< XDocumentTemplates > xTemplates = pImp->getDocTemplates();
1202cdf0e10cSrcweir     if ( !xTemplates.is() )
1203cdf0e10cSrcweir         return sal_False;
1204cdf0e10cSrcweir 
1205cdf0e10cSrcweir     OUString aTitle;
1206cdf0e10cSrcweir     sal_Bool bTemplateAdded = sal_False;
1207cdf0e10cSrcweir 
1208cdf0e10cSrcweir     if( pImp->GetTitleFromURL( rName, aTitle ) )
1209cdf0e10cSrcweir     {
1210cdf0e10cSrcweir         bTemplateAdded = xTemplates->addTemplate( pTargetRgn->GetTitle(), aTitle, rName );
1211cdf0e10cSrcweir     }
1212cdf0e10cSrcweir     else
1213cdf0e10cSrcweir     {
1214cdf0e10cSrcweir         OUString aService( RTL_CONSTASCII_USTRINGPARAM( SERVICENAME_DESKTOP ) );
1215cdf0e10cSrcweir         uno::Reference< XComponentLoader > xDesktop( ::comphelper::getProcessServiceFactory()->createInstance( aService ),
1216cdf0e10cSrcweir                                                 UNO_QUERY );
1217cdf0e10cSrcweir 
1218cdf0e10cSrcweir         Sequence< PropertyValue > aArgs( 1 );
1219cdf0e10cSrcweir         aArgs[0].Name = ::rtl::OUString::createFromAscii("Hidden");
1220cdf0e10cSrcweir         aArgs[0].Value <<= sal_True;
1221cdf0e10cSrcweir 
1222cdf0e10cSrcweir         INetURLObject   aTemplURL( rName );
1223cdf0e10cSrcweir         uno::Reference< XDocumentPropertiesSupplier > xDocPropsSupplier;
1224cdf0e10cSrcweir         uno::Reference< XStorable > xStorable;
1225cdf0e10cSrcweir         try
1226cdf0e10cSrcweir         {
1227cdf0e10cSrcweir             xStorable = uno::Reference< XStorable >(
1228cdf0e10cSrcweir                 xDesktop->loadComponentFromURL( aTemplURL.GetMainURL(INetURLObject::NO_DECODE),
1229cdf0e10cSrcweir                                                 OUString::createFromAscii( "_blank" ),
1230cdf0e10cSrcweir                                                 0,
1231cdf0e10cSrcweir                                                 aArgs ),
1232cdf0e10cSrcweir                 UNO_QUERY );
1233cdf0e10cSrcweir 
1234cdf0e10cSrcweir             xDocPropsSupplier = uno::Reference< XDocumentPropertiesSupplier >(
1235cdf0e10cSrcweir                 xStorable, UNO_QUERY );
1236cdf0e10cSrcweir         }
1237cdf0e10cSrcweir         catch( Exception& )
1238cdf0e10cSrcweir         {
1239cdf0e10cSrcweir         }
1240cdf0e10cSrcweir 
1241cdf0e10cSrcweir         if( xStorable.is() )
1242cdf0e10cSrcweir         {
1243cdf0e10cSrcweir             // get Title from XDocumentPropertiesSupplier
1244cdf0e10cSrcweir             if( xDocPropsSupplier.is() )
1245cdf0e10cSrcweir             {
1246cdf0e10cSrcweir                 uno::Reference< XDocumentProperties > xDocProps
1247cdf0e10cSrcweir                     = xDocPropsSupplier->getDocumentProperties();
1248cdf0e10cSrcweir                 if (xDocProps.is() ) {
1249cdf0e10cSrcweir                     aTitle = xDocProps->getTitle();
1250cdf0e10cSrcweir                 }
1251cdf0e10cSrcweir             }
1252cdf0e10cSrcweir 
1253cdf0e10cSrcweir             if( ! aTitle.getLength() )
1254cdf0e10cSrcweir             {
1255cdf0e10cSrcweir                 INetURLObject aURL( aTemplURL );
1256cdf0e10cSrcweir                 aURL.CutExtension();
1257cdf0e10cSrcweir                 aTitle = aURL.getName( INetURLObject::LAST_SEGMENT, true,
1258cdf0e10cSrcweir                                         INetURLObject::DECODE_WITH_CHARSET );
1259cdf0e10cSrcweir             }
1260cdf0e10cSrcweir 
1261cdf0e10cSrcweir             // write a template using XStorable interface
1262cdf0e10cSrcweir             bTemplateAdded = xTemplates->storeTemplate( pTargetRgn->GetTitle(), aTitle, xStorable );
1263cdf0e10cSrcweir         }
1264cdf0e10cSrcweir     }
1265cdf0e10cSrcweir 
1266cdf0e10cSrcweir 
1267cdf0e10cSrcweir     if( bTemplateAdded )
1268cdf0e10cSrcweir     {
1269cdf0e10cSrcweir         INetURLObject aTemplObj( pTargetRgn->GetHierarchyURL() );
1270cdf0e10cSrcweir         aTemplObj.insertName( aTitle, false,
1271cdf0e10cSrcweir                               INetURLObject::LAST_SEGMENT, true,
1272cdf0e10cSrcweir                               INetURLObject::ENCODE_ALL );
1273cdf0e10cSrcweir         OUString aTemplURL = aTemplObj.GetMainURL( INetURLObject::NO_DECODE );
1274cdf0e10cSrcweir 
1275cdf0e10cSrcweir         uno::Reference< XCommandEnvironment > aCmdEnv;
1276cdf0e10cSrcweir         Content aTemplCont;
1277cdf0e10cSrcweir 
1278cdf0e10cSrcweir         if( Content::create( aTemplURL, aCmdEnv, aTemplCont ) )
1279cdf0e10cSrcweir         {
1280cdf0e10cSrcweir             OUString aTemplName;
1281cdf0e10cSrcweir             OUString aPropName( RTL_CONSTASCII_USTRINGPARAM( TARGET_URL ) );
1282cdf0e10cSrcweir 
1283cdf0e10cSrcweir             if( getTextProperty_Impl( aTemplCont, aPropName, aTemplName ) )
1284cdf0e10cSrcweir             {
1285cdf0e10cSrcweir                 if ( nIdx == USHRT_MAX )
1286cdf0e10cSrcweir                     nIdx = 0;
1287cdf0e10cSrcweir                 else
1288cdf0e10cSrcweir                     nIdx += 1;
1289cdf0e10cSrcweir 
1290cdf0e10cSrcweir                 pTargetRgn->AddEntry( aTitle, aTemplName, &nIdx );
1291cdf0e10cSrcweir                 rName = aTitle;
1292cdf0e10cSrcweir                 return sal_True;
1293cdf0e10cSrcweir             }
1294cdf0e10cSrcweir             else
1295cdf0e10cSrcweir             {
1296cdf0e10cSrcweir                 DBG_ASSERT( sal_False, "CopyFrom(): The content should contain target URL!" );
1297cdf0e10cSrcweir             }
1298cdf0e10cSrcweir         }
1299cdf0e10cSrcweir         else
1300cdf0e10cSrcweir         {
1301cdf0e10cSrcweir             DBG_ASSERT( sal_False, "CopyFrom(): The content just was created!" );
1302cdf0e10cSrcweir         }
1303cdf0e10cSrcweir     }
1304cdf0e10cSrcweir 
1305cdf0e10cSrcweir     return sal_False;
1306cdf0e10cSrcweir }
1307cdf0e10cSrcweir 
1308cdf0e10cSrcweir //------------------------------------------------------------------------
1309cdf0e10cSrcweir 
Delete(sal_uInt16 nRegion,sal_uInt16 nIdx)1310cdf0e10cSrcweir sal_Bool SfxDocumentTemplates::Delete
1311cdf0e10cSrcweir (
1312cdf0e10cSrcweir     sal_uInt16 nRegion,             //  Index des Bereiches
1313cdf0e10cSrcweir     sal_uInt16 nIdx                 /*  Index des Eintrags oder USHRT_MAX,
1314cdf0e10cSrcweir                                     wenn ein Verzeichnis gemeint ist. */
1315cdf0e10cSrcweir )
1316cdf0e10cSrcweir 
1317cdf0e10cSrcweir /*  [Beschreibung]
1318cdf0e10cSrcweir 
1319cdf0e10cSrcweir     "oschen eines Eintrags oder eines Verzeichnisses
1320cdf0e10cSrcweir 
1321cdf0e10cSrcweir 
1322cdf0e10cSrcweir     [R"uckgabewert]
1323cdf0e10cSrcweir 
1324cdf0e10cSrcweir     sal_Bool                            sal_True
1325cdf0e10cSrcweir                                     Aktion konnte ausgef"uhrt werden
1326cdf0e10cSrcweir 
1327cdf0e10cSrcweir                                     sal_False
1328cdf0e10cSrcweir                                     Aktion konnte nicht ausgef"uhrt werden
1329cdf0e10cSrcweir 
1330cdf0e10cSrcweir 
1331cdf0e10cSrcweir     [Querverweise]
1332cdf0e10cSrcweir 
1333cdf0e10cSrcweir     <SfxDocumentTemplates::InsertDir(const String&,sal_uInt16)>
1334cdf0e10cSrcweir     <SfxDocumentTemplates::KillDir(SfxTemplateDir&)>
1335cdf0e10cSrcweir     <SfxDocumentTemplates::SaveDir(SfxTemplateDir&)>
1336cdf0e10cSrcweir */
1337cdf0e10cSrcweir 
1338cdf0e10cSrcweir {
1339cdf0e10cSrcweir     DocTemplLocker_Impl aLocker( *pImp );
1340cdf0e10cSrcweir 
1341cdf0e10cSrcweir     /* delete the template or folder in the hierarchy and in the
1342cdf0e10cSrcweir        template folder by sending a delete command to the content.
1343cdf0e10cSrcweir        Then remove the data from the lists
1344cdf0e10cSrcweir     */
1345cdf0e10cSrcweir     if ( ! pImp->Construct() )
1346cdf0e10cSrcweir         return sal_False;
1347cdf0e10cSrcweir 
1348cdf0e10cSrcweir     RegionData_Impl *pRegion = pImp->GetRegion( nRegion );
1349cdf0e10cSrcweir 
1350cdf0e10cSrcweir     if ( !pRegion )
1351cdf0e10cSrcweir         return sal_False;
1352cdf0e10cSrcweir 
1353cdf0e10cSrcweir     sal_Bool bRet;
1354cdf0e10cSrcweir     uno::Reference< XDocumentTemplates > xTemplates = pImp->getDocTemplates();
1355cdf0e10cSrcweir 
1356cdf0e10cSrcweir     if ( nIdx == USHRT_MAX )
1357cdf0e10cSrcweir     {
1358cdf0e10cSrcweir         bRet = xTemplates->removeGroup( pRegion->GetTitle() );
1359cdf0e10cSrcweir         if ( bRet )
1360cdf0e10cSrcweir             pImp->DeleteRegion( nRegion );
1361cdf0e10cSrcweir     }
1362cdf0e10cSrcweir     else
1363cdf0e10cSrcweir     {
1364cdf0e10cSrcweir         DocTempl_EntryData_Impl *pEntry = pRegion->GetEntry( nIdx );
1365cdf0e10cSrcweir 
1366cdf0e10cSrcweir         if ( !pEntry )
1367cdf0e10cSrcweir             return sal_False;
1368cdf0e10cSrcweir 
1369cdf0e10cSrcweir         bRet = xTemplates->removeTemplate( pRegion->GetTitle(),
1370cdf0e10cSrcweir                                            pEntry->GetTitle() );
1371cdf0e10cSrcweir         if( bRet )
1372cdf0e10cSrcweir             pRegion->DeleteEntry( nIdx );
1373cdf0e10cSrcweir     }
1374cdf0e10cSrcweir 
1375cdf0e10cSrcweir     return bRet;
1376cdf0e10cSrcweir }
1377cdf0e10cSrcweir 
1378cdf0e10cSrcweir //------------------------------------------------------------------------
1379cdf0e10cSrcweir 
InsertDir(const String & rText,sal_uInt16 nRegion)1380cdf0e10cSrcweir sal_Bool SfxDocumentTemplates::InsertDir
1381cdf0e10cSrcweir (
1382cdf0e10cSrcweir     const String&   rText,      //  der logische Name des neuen Bereiches
1383cdf0e10cSrcweir     sal_uInt16          nRegion     //  Index des Bereiches
1384cdf0e10cSrcweir )
1385cdf0e10cSrcweir 
1386cdf0e10cSrcweir /*  [Beschreibung]
1387cdf0e10cSrcweir 
1388cdf0e10cSrcweir     Einf"ugen eines Verzeichnisses
1389cdf0e10cSrcweir 
1390cdf0e10cSrcweir 
1391cdf0e10cSrcweir     [R"uckgabewert]
1392cdf0e10cSrcweir 
1393cdf0e10cSrcweir     sal_Bool                            sal_True
1394cdf0e10cSrcweir                                     Aktion konnte ausgef"uhrt werden
1395cdf0e10cSrcweir 
1396cdf0e10cSrcweir                                     sal_False
1397cdf0e10cSrcweir                                     Aktion konnte nicht ausgef"uhrt werden
1398cdf0e10cSrcweir 
1399cdf0e10cSrcweir     [Querverweise]
1400cdf0e10cSrcweir 
1401cdf0e10cSrcweir     <SfxDocumentTemplates::KillDir(SfxTemplateDir&)>
1402cdf0e10cSrcweir     <SfxDocumentTemplates::SaveDir(SfxTemplateDir&)>
1403cdf0e10cSrcweir */
1404cdf0e10cSrcweir {
1405cdf0e10cSrcweir     DocTemplLocker_Impl aLocker( *pImp );
1406cdf0e10cSrcweir 
1407cdf0e10cSrcweir     if ( ! pImp->Construct() )
1408cdf0e10cSrcweir         return sal_False;
1409cdf0e10cSrcweir 
1410cdf0e10cSrcweir     RegionData_Impl *pRegion = pImp->GetRegion( rText );
1411cdf0e10cSrcweir 
1412cdf0e10cSrcweir     if ( pRegion )
1413cdf0e10cSrcweir         return sal_False;
1414cdf0e10cSrcweir 
1415cdf0e10cSrcweir     uno::Reference< XDocumentTemplates > xTemplates = pImp->getDocTemplates();
1416cdf0e10cSrcweir 
1417cdf0e10cSrcweir     if ( xTemplates->addGroup( rText ) )
1418cdf0e10cSrcweir     {
1419cdf0e10cSrcweir         RegionData_Impl* pNewRegion = new RegionData_Impl( pImp, rText );
1420cdf0e10cSrcweir 
1421cdf0e10cSrcweir         if ( ! pImp->InsertRegion( pNewRegion, nRegion ) )
1422cdf0e10cSrcweir         {
1423cdf0e10cSrcweir             delete pNewRegion;
1424cdf0e10cSrcweir             return sal_False;
1425cdf0e10cSrcweir         }
1426cdf0e10cSrcweir         return sal_True;
1427cdf0e10cSrcweir     }
1428cdf0e10cSrcweir 
1429cdf0e10cSrcweir     return sal_False;
1430cdf0e10cSrcweir }
1431cdf0e10cSrcweir 
1432cdf0e10cSrcweir //------------------------------------------------------------------------
1433cdf0e10cSrcweir 
SetName(const String & rName,sal_uInt16 nRegion,sal_uInt16 nIdx)1434cdf0e10cSrcweir sal_Bool SfxDocumentTemplates::SetName
1435cdf0e10cSrcweir (
1436cdf0e10cSrcweir     const String&   rName,      //  Der zu setzende Name
1437cdf0e10cSrcweir     sal_uInt16          nRegion,    //  Index des Bereiches
1438cdf0e10cSrcweir     sal_uInt16          nIdx        /*  Index des Eintrags oder USHRT_MAX,
1439cdf0e10cSrcweir                                     wenn ein Verzeichnis gemeint ist. */
1440cdf0e10cSrcweir )
1441cdf0e10cSrcweir 
1442cdf0e10cSrcweir /*  [Beschreibung]
1443cdf0e10cSrcweir 
1444cdf0e10cSrcweir     "Andern des Namens eines Eintrags oder eines Verzeichnisses
1445cdf0e10cSrcweir 
1446cdf0e10cSrcweir 
1447cdf0e10cSrcweir     [R"uckgabewert]
1448cdf0e10cSrcweir 
1449cdf0e10cSrcweir     sal_Bool                            sal_True
1450cdf0e10cSrcweir                                     Aktion konnte ausgef"uhrt werden
1451cdf0e10cSrcweir 
1452cdf0e10cSrcweir                                     sal_False
1453cdf0e10cSrcweir                                     Aktion konnte nicht ausgef"uhrt werden
1454cdf0e10cSrcweir 
1455cdf0e10cSrcweir */
1456cdf0e10cSrcweir 
1457cdf0e10cSrcweir {
1458cdf0e10cSrcweir     DocTemplLocker_Impl aLocker( *pImp );
1459cdf0e10cSrcweir 
1460cdf0e10cSrcweir     if ( ! pImp->Construct() )
1461cdf0e10cSrcweir         return sal_False;
1462cdf0e10cSrcweir 
1463cdf0e10cSrcweir     RegionData_Impl *pRegion = pImp->GetRegion( nRegion );
1464cdf0e10cSrcweir     DocTempl_EntryData_Impl *pEntry = NULL;
1465cdf0e10cSrcweir 
1466cdf0e10cSrcweir     if ( !pRegion )
1467cdf0e10cSrcweir         return sal_False;
1468cdf0e10cSrcweir 
1469cdf0e10cSrcweir     uno::Reference< XDocumentTemplates > xTemplates = pImp->getDocTemplates();
1470cdf0e10cSrcweir     OUString aEmpty;
1471cdf0e10cSrcweir 
1472cdf0e10cSrcweir     if ( nIdx == USHRT_MAX )
1473cdf0e10cSrcweir     {
1474cdf0e10cSrcweir         if ( pRegion->GetTitle() == OUString( rName ) )
1475cdf0e10cSrcweir             return sal_True;
1476cdf0e10cSrcweir 
1477cdf0e10cSrcweir         // we have to rename a region
1478cdf0e10cSrcweir         if ( xTemplates->renameGroup( pRegion->GetTitle(), rName ) )
1479cdf0e10cSrcweir         {
1480cdf0e10cSrcweir             pRegion->SetTitle( rName );
1481cdf0e10cSrcweir             pRegion->SetTargetURL( aEmpty );
1482cdf0e10cSrcweir             pRegion->SetHierarchyURL( aEmpty );
1483cdf0e10cSrcweir             return sal_True;
1484cdf0e10cSrcweir         }
1485cdf0e10cSrcweir     }
1486cdf0e10cSrcweir     else
1487cdf0e10cSrcweir     {
1488cdf0e10cSrcweir         pEntry = pRegion->GetEntry( nIdx );
1489cdf0e10cSrcweir 
1490cdf0e10cSrcweir         if ( !pEntry )
1491cdf0e10cSrcweir             return sal_False;
1492cdf0e10cSrcweir 
1493cdf0e10cSrcweir         if ( pEntry->GetTitle() == OUString( rName ) )
1494cdf0e10cSrcweir             return sal_True;
1495cdf0e10cSrcweir 
1496cdf0e10cSrcweir         if ( xTemplates->renameTemplate( pRegion->GetTitle(),
1497cdf0e10cSrcweir                                          pEntry->GetTitle(),
1498cdf0e10cSrcweir                                          rName ) )
1499cdf0e10cSrcweir         {
1500cdf0e10cSrcweir             pEntry->SetTitle( rName );
1501cdf0e10cSrcweir             pEntry->SetTargetURL( aEmpty );
1502cdf0e10cSrcweir             pEntry->SetHierarchyURL( aEmpty );
1503cdf0e10cSrcweir             return sal_True;
1504cdf0e10cSrcweir         }
1505cdf0e10cSrcweir     }
1506cdf0e10cSrcweir 
1507cdf0e10cSrcweir     return sal_False;
1508cdf0e10cSrcweir }
1509cdf0e10cSrcweir 
1510cdf0e10cSrcweir //------------------------------------------------------------------------
1511cdf0e10cSrcweir 
Rescan()1512cdf0e10cSrcweir sal_Bool SfxDocumentTemplates::Rescan()
1513cdf0e10cSrcweir 
1514cdf0e10cSrcweir /*  [Beschreibung]
1515cdf0e10cSrcweir 
1516cdf0e10cSrcweir     Abgleich des Verwaltungsdaten mit dem aktuellen Zustand auf der Platte.
1517cdf0e10cSrcweir     Die logischen Namen, zu denen keine Datei mit existiert, werden aus
1518cdf0e10cSrcweir     der Verwaltungsstruktur entfernt; Dateien, zu denen kein Eintrag
1519cdf0e10cSrcweir     existiert, werden aufgenommen.
1520cdf0e10cSrcweir 
1521cdf0e10cSrcweir 
1522cdf0e10cSrcweir     [R"uckgabewert]
1523cdf0e10cSrcweir 
1524cdf0e10cSrcweir     sal_Bool                            sal_True
1525cdf0e10cSrcweir                                     Aktion konnte ausgef"uhrt werden
1526cdf0e10cSrcweir 
1527cdf0e10cSrcweir                                     sal_False
1528cdf0e10cSrcweir                                     Aktion konnte nicht ausgef"uhrt werden
1529cdf0e10cSrcweir 
1530cdf0e10cSrcweir 
1531cdf0e10cSrcweir     [Querverweise]
1532cdf0e10cSrcweir 
1533cdf0e10cSrcweir     <SfxTemplateDir::Scan(sal_Bool bDirectory, sal_Bool bSave)>
1534cdf0e10cSrcweir     <SfxTemplateDir::Freshen(const SfxTemplateDir &rNew)>
1535cdf0e10cSrcweir */
1536cdf0e10cSrcweir {
1537cdf0e10cSrcweir     if ( !pImp->Construct() )
1538cdf0e10cSrcweir         return sal_False;
1539cdf0e10cSrcweir 
1540cdf0e10cSrcweir     pImp->Rescan();
1541cdf0e10cSrcweir 
1542cdf0e10cSrcweir     return sal_True;
1543cdf0e10cSrcweir }
1544cdf0e10cSrcweir 
1545cdf0e10cSrcweir //------------------------------------------------------------------------
1546cdf0e10cSrcweir 
CreateObjectShell(sal_uInt16 nRegion,sal_uInt16 nIdx)1547cdf0e10cSrcweir SfxObjectShellRef SfxDocumentTemplates::CreateObjectShell
1548cdf0e10cSrcweir (
1549cdf0e10cSrcweir     sal_uInt16 nRegion,         //  Index des Bereiches
1550cdf0e10cSrcweir     sal_uInt16 nIdx             //  Index des Eintrags
1551cdf0e10cSrcweir )
1552cdf0e10cSrcweir 
1553cdf0e10cSrcweir /*  [Beschreibung]
1554cdf0e10cSrcweir 
1555cdf0e10cSrcweir     Zugriff auf die DokumentShell eines Eintrags
1556cdf0e10cSrcweir 
1557cdf0e10cSrcweir 
1558cdf0e10cSrcweir     [R"uckgabewert]
1559cdf0e10cSrcweir 
1560cdf0e10cSrcweir     SfxObjectShellRef         Referenz auf die ObjectShell
1561cdf0e10cSrcweir 
1562cdf0e10cSrcweir 
1563cdf0e10cSrcweir     [Querverweise]
1564cdf0e10cSrcweir 
1565cdf0e10cSrcweir     <SfxTemplateDirEntry::CreateObjectShell()>
1566cdf0e10cSrcweir     <SfxDocumentTemplates::DeleteObjectShell(sal_uInt16, sal_uInt16)>
1567cdf0e10cSrcweir */
1568cdf0e10cSrcweir 
1569cdf0e10cSrcweir {
1570cdf0e10cSrcweir     DocTemplLocker_Impl aLocker( *pImp );
1571cdf0e10cSrcweir 
1572cdf0e10cSrcweir     if ( !pImp->Construct() )
1573cdf0e10cSrcweir         return NULL;
1574cdf0e10cSrcweir 
1575cdf0e10cSrcweir     RegionData_Impl *pRegion = pImp->GetRegion( nRegion );
1576cdf0e10cSrcweir     DocTempl_EntryData_Impl *pEntry = NULL;
1577cdf0e10cSrcweir 
1578cdf0e10cSrcweir     if ( pRegion )
1579cdf0e10cSrcweir         pEntry = pRegion->GetEntry( nIdx );
1580cdf0e10cSrcweir 
1581cdf0e10cSrcweir     if ( pEntry )
1582cdf0e10cSrcweir         return pEntry->CreateObjectShell();
1583cdf0e10cSrcweir     else
1584cdf0e10cSrcweir         return NULL;
1585cdf0e10cSrcweir }
1586cdf0e10cSrcweir 
1587cdf0e10cSrcweir //------------------------------------------------------------------------
1588cdf0e10cSrcweir 
DeleteObjectShell(sal_uInt16 nRegion,sal_uInt16 nIdx)1589cdf0e10cSrcweir sal_Bool SfxDocumentTemplates::DeleteObjectShell
1590cdf0e10cSrcweir (
1591cdf0e10cSrcweir     sal_uInt16 nRegion,         //  Index des Bereiches
1592cdf0e10cSrcweir     sal_uInt16 nIdx             //  Index des Eintrags
1593cdf0e10cSrcweir )
1594cdf0e10cSrcweir 
1595cdf0e10cSrcweir /*  [Beschreibung]
1596cdf0e10cSrcweir 
1597cdf0e10cSrcweir     Freigeben der ObjectShell eines Eintrags
1598cdf0e10cSrcweir 
1599cdf0e10cSrcweir 
1600cdf0e10cSrcweir     [R"uckgabewert]
1601cdf0e10cSrcweir 
1602cdf0e10cSrcweir     sal_Bool                            sal_True
1603cdf0e10cSrcweir                                     Aktion konnte ausgef"uhrt werden
1604cdf0e10cSrcweir 
1605cdf0e10cSrcweir                                     sal_False
1606cdf0e10cSrcweir                                     Aktion konnte nicht ausgef"uhrt werden
1607cdf0e10cSrcweir 
1608cdf0e10cSrcweir     [Querverweise]
1609cdf0e10cSrcweir 
1610cdf0e10cSrcweir     <SfxTemplateDirEntry::DeleteObjectShell()>
1611cdf0e10cSrcweir     <SfxDocumentTemplates::CreateObjectShell(sal_uInt16, sal_uInt16)>
1612cdf0e10cSrcweir */
1613cdf0e10cSrcweir 
1614cdf0e10cSrcweir {
1615cdf0e10cSrcweir     DocTemplLocker_Impl aLocker( *pImp );
1616cdf0e10cSrcweir 
1617cdf0e10cSrcweir     if ( ! pImp->Construct() )
1618cdf0e10cSrcweir         return sal_True;
1619cdf0e10cSrcweir 
1620cdf0e10cSrcweir     RegionData_Impl *pRegion = pImp->GetRegion( nRegion );
1621cdf0e10cSrcweir     DocTempl_EntryData_Impl *pEntry = NULL;
1622cdf0e10cSrcweir 
1623cdf0e10cSrcweir     if ( pRegion )
1624cdf0e10cSrcweir         pEntry = pRegion->GetEntry( nIdx );
1625cdf0e10cSrcweir 
1626cdf0e10cSrcweir     if ( pEntry )
1627cdf0e10cSrcweir         return pEntry->DeleteObjectShell();
1628cdf0e10cSrcweir     else
1629cdf0e10cSrcweir         return sal_True;
1630cdf0e10cSrcweir }
1631cdf0e10cSrcweir 
1632cdf0e10cSrcweir //------------------------------------------------------------------------
1633cdf0e10cSrcweir 
GetFull(const String & rRegion,const String & rName,String & rPath)1634cdf0e10cSrcweir sal_Bool SfxDocumentTemplates::GetFull
1635cdf0e10cSrcweir (
1636cdf0e10cSrcweir     const String &rRegion,      // Der Name des Bereiches
1637cdf0e10cSrcweir     const String &rName,        // Der Name der Vorlage
1638cdf0e10cSrcweir     String &rPath               // Out: Pfad + Dateiname
1639cdf0e10cSrcweir )
1640cdf0e10cSrcweir 
1641cdf0e10cSrcweir /*  [Beschreibung]
1642cdf0e10cSrcweir 
1643cdf0e10cSrcweir     Liefert Pfad + Dateiname zu der durch rRegion und rName bezeichneten
1644cdf0e10cSrcweir     Vorlage
1645cdf0e10cSrcweir 
1646cdf0e10cSrcweir 
1647cdf0e10cSrcweir     [R"uckgabewert]
1648cdf0e10cSrcweir 
1649cdf0e10cSrcweir     sal_Bool                            sal_True
1650cdf0e10cSrcweir                                     Aktion konnte ausgef"uhrt werden
1651cdf0e10cSrcweir 
1652cdf0e10cSrcweir                                     sal_False
1653cdf0e10cSrcweir                                     Aktion konnte nicht ausgef"uhrt werden
1654cdf0e10cSrcweir 
1655cdf0e10cSrcweir 
1656cdf0e10cSrcweir     [Querverweise]
1657cdf0e10cSrcweir 
1658cdf0e10cSrcweir     <SfxDocumentTemplates::GetLogicNames(const String&,String&,String&)>
1659cdf0e10cSrcweir */
1660cdf0e10cSrcweir 
1661cdf0e10cSrcweir {
1662cdf0e10cSrcweir     DocTemplLocker_Impl aLocker( *pImp );
1663cdf0e10cSrcweir 
1664cdf0e10cSrcweir     // We don't search for empty names!
1665cdf0e10cSrcweir     if ( ! rName.Len() )
1666cdf0e10cSrcweir         return sal_False;
1667cdf0e10cSrcweir 
1668cdf0e10cSrcweir     if ( ! pImp->Construct() )
1669cdf0e10cSrcweir         return sal_False;
1670cdf0e10cSrcweir 
1671cdf0e10cSrcweir     DocTempl_EntryData_Impl* pEntry = NULL;
1672cdf0e10cSrcweir     const sal_uInt16 nCount = GetRegionCount();
1673cdf0e10cSrcweir 
1674cdf0e10cSrcweir     for ( sal_uInt16 i = 0; i < nCount; ++i )
1675cdf0e10cSrcweir     {
1676cdf0e10cSrcweir         RegionData_Impl *pRegion = pImp->GetRegion( i );
1677cdf0e10cSrcweir 
1678cdf0e10cSrcweir         if( pRegion &&
1679cdf0e10cSrcweir             ( !rRegion.Len() || ( rRegion == String( pRegion->GetTitle() ) ) ) )
1680cdf0e10cSrcweir         {
1681cdf0e10cSrcweir             pEntry = pRegion->GetEntry( rName );
1682cdf0e10cSrcweir 
1683cdf0e10cSrcweir             if ( pEntry )
1684cdf0e10cSrcweir             {
1685cdf0e10cSrcweir                 rPath = pEntry->GetTargetURL();
1686cdf0e10cSrcweir                 break;
1687cdf0e10cSrcweir             }
1688cdf0e10cSrcweir         }
1689cdf0e10cSrcweir     }
1690cdf0e10cSrcweir 
1691cdf0e10cSrcweir     return ( pEntry != NULL );
1692cdf0e10cSrcweir }
1693cdf0e10cSrcweir 
1694cdf0e10cSrcweir //------------------------------------------------------------------------
1695cdf0e10cSrcweir 
GetLogicNames(const String & rPath,String & rRegion,String & rName) const1696cdf0e10cSrcweir sal_Bool SfxDocumentTemplates::GetLogicNames
1697cdf0e10cSrcweir (
1698cdf0e10cSrcweir     const String &rPath,            // vollst"andiger Pfad zu der Vorlage
1699cdf0e10cSrcweir     String &rRegion,                // Out: der Bereichsname
1700cdf0e10cSrcweir     String &rName                   // Out: der Vorlagenname
1701cdf0e10cSrcweir ) const
1702cdf0e10cSrcweir 
1703cdf0e10cSrcweir /*  [Beschreibung]
1704cdf0e10cSrcweir 
1705cdf0e10cSrcweir     Liefert Pfad und logischen Namen zu der durch rPath bezeichneten
1706cdf0e10cSrcweir     Vorlage
1707cdf0e10cSrcweir 
1708cdf0e10cSrcweir     [R"uckgabewert]
1709cdf0e10cSrcweir 
1710cdf0e10cSrcweir     sal_Bool                            sal_True
1711cdf0e10cSrcweir                                     Aktion konnte ausgef"uhrt werden
1712cdf0e10cSrcweir 
1713cdf0e10cSrcweir                                     sal_False
1714cdf0e10cSrcweir                                     Aktion konnte nicht ausgef"uhrt werden
1715cdf0e10cSrcweir 
1716cdf0e10cSrcweir 
1717cdf0e10cSrcweir     [Querverweise]
1718cdf0e10cSrcweir 
1719cdf0e10cSrcweir     <SfxDocumentTemplates::GetFull(const String&,const String&,DirEntry&)>
1720cdf0e10cSrcweir */
1721cdf0e10cSrcweir 
1722cdf0e10cSrcweir {
1723cdf0e10cSrcweir     DocTemplLocker_Impl aLocker( *pImp );
1724cdf0e10cSrcweir 
1725cdf0e10cSrcweir     if ( ! pImp->Construct() )
1726cdf0e10cSrcweir         return sal_False;
1727cdf0e10cSrcweir 
1728cdf0e10cSrcweir     INetURLObject aFullPath;
1729cdf0e10cSrcweir 
1730cdf0e10cSrcweir     aFullPath.SetSmartProtocol( INET_PROT_FILE );
1731cdf0e10cSrcweir     aFullPath.SetURL( rPath );
1732cdf0e10cSrcweir     OUString aPath( aFullPath.GetMainURL( INetURLObject::NO_DECODE ) );
1733cdf0e10cSrcweir 
1734cdf0e10cSrcweir     RegionData_Impl *pData = NULL;
1735cdf0e10cSrcweir     DocTempl_EntryData_Impl  *pEntry = NULL;
1736cdf0e10cSrcweir     sal_Bool         bFound = sal_False;
1737cdf0e10cSrcweir 
1738cdf0e10cSrcweir     sal_uIntPtr nCount = GetRegionCount();
1739cdf0e10cSrcweir 
1740cdf0e10cSrcweir     for ( sal_uIntPtr i=0; !bFound && (i<nCount); i++ )
1741cdf0e10cSrcweir     {
1742cdf0e10cSrcweir         pData = pImp->GetRegion( i );
1743cdf0e10cSrcweir         if ( pData )
1744cdf0e10cSrcweir         {
1745cdf0e10cSrcweir             sal_uIntPtr nChildCount = pData->GetCount();
1746cdf0e10cSrcweir 
1747cdf0e10cSrcweir             for ( sal_uIntPtr j=0; !bFound && (j<nChildCount); j++ )
1748cdf0e10cSrcweir             {
1749cdf0e10cSrcweir                 pEntry = pData->GetEntry( j );
1750cdf0e10cSrcweir                 if ( pEntry->GetTargetURL() == aPath )
1751cdf0e10cSrcweir                 {
1752cdf0e10cSrcweir                     bFound = sal_True;
1753cdf0e10cSrcweir                 }
1754cdf0e10cSrcweir             }
1755cdf0e10cSrcweir         }
1756cdf0e10cSrcweir     }
1757cdf0e10cSrcweir 
1758cdf0e10cSrcweir     if ( bFound )
1759cdf0e10cSrcweir     {
1760cdf0e10cSrcweir         rRegion = pData->GetTitle();
1761cdf0e10cSrcweir         rName = pEntry->GetTitle();
1762cdf0e10cSrcweir     }
1763cdf0e10cSrcweir 
1764cdf0e10cSrcweir     return bFound;
1765cdf0e10cSrcweir }
1766cdf0e10cSrcweir 
1767cdf0e10cSrcweir //------------------------------------------------------------------------
1768cdf0e10cSrcweir 
SfxDocumentTemplates()1769cdf0e10cSrcweir SfxDocumentTemplates::SfxDocumentTemplates()
1770cdf0e10cSrcweir 
1771cdf0e10cSrcweir /*  [Beschreibung]
1772cdf0e10cSrcweir 
1773cdf0e10cSrcweir     Konstruktor
1774cdf0e10cSrcweir */
1775cdf0e10cSrcweir {
1776cdf0e10cSrcweir     if ( !gpTemplateData )
1777cdf0e10cSrcweir         gpTemplateData = new SfxDocTemplate_Impl;
1778cdf0e10cSrcweir 
1779cdf0e10cSrcweir     pImp = gpTemplateData;
1780cdf0e10cSrcweir }
1781cdf0e10cSrcweir 
1782cdf0e10cSrcweir //-------------------------------------------------------------------------
1783cdf0e10cSrcweir 
Construct()1784cdf0e10cSrcweir void SfxDocumentTemplates::Construct()
1785cdf0e10cSrcweir 
1786cdf0e10cSrcweir //  verz"ogerter Aufbau der Verwaltungsdaten
1787cdf0e10cSrcweir 
1788cdf0e10cSrcweir {
1789cdf0e10cSrcweir //  pImp->Construct();
1790cdf0e10cSrcweir }
1791cdf0e10cSrcweir 
1792cdf0e10cSrcweir //------------------------------------------------------------------------
1793cdf0e10cSrcweir 
~SfxDocumentTemplates()1794cdf0e10cSrcweir SfxDocumentTemplates::~SfxDocumentTemplates()
1795cdf0e10cSrcweir 
1796cdf0e10cSrcweir /*  [Beschreibung]
1797cdf0e10cSrcweir 
1798cdf0e10cSrcweir     Destruktor
1799cdf0e10cSrcweir     Freigeben der Verwaltungsdaten
1800cdf0e10cSrcweir */
1801cdf0e10cSrcweir 
1802cdf0e10cSrcweir {
1803cdf0e10cSrcweir     pImp = NULL;
1804cdf0e10cSrcweir }
1805cdf0e10cSrcweir 
Update(sal_Bool _bSmart)1806cdf0e10cSrcweir void SfxDocumentTemplates::Update( sal_Bool _bSmart )
1807cdf0e10cSrcweir {
1808cdf0e10cSrcweir     if  (   !_bSmart                                                // don't be smart
1809cdf0e10cSrcweir         ||  ::svt::TemplateFolderCache( sal_True ).needsUpdate()    // update is really necessary
1810cdf0e10cSrcweir         )
1811cdf0e10cSrcweir     {
1812cdf0e10cSrcweir         if ( pImp->Construct() )
1813cdf0e10cSrcweir             pImp->Rescan();
1814cdf0e10cSrcweir     }
1815cdf0e10cSrcweir }
1816cdf0e10cSrcweir 
ReInitFromComponent()1817cdf0e10cSrcweir void SfxDocumentTemplates::ReInitFromComponent()
1818cdf0e10cSrcweir {
1819cdf0e10cSrcweir     pImp->ReInitFromComponent();
1820cdf0e10cSrcweir }
1821cdf0e10cSrcweir 
1822cdf0e10cSrcweir 
HasUserContents(sal_uInt16 nRegion,sal_uInt16 nIdx) const1823cdf0e10cSrcweir sal_Bool SfxDocumentTemplates::HasUserContents( sal_uInt16 nRegion, sal_uInt16 nIdx ) const
1824cdf0e10cSrcweir {
1825cdf0e10cSrcweir     DocTemplLocker_Impl aLocker( *pImp );
1826cdf0e10cSrcweir 
1827cdf0e10cSrcweir     sal_Bool bResult = sal_False;
1828cdf0e10cSrcweir 
1829cdf0e10cSrcweir     RegionData_Impl* pRegion = pImp->GetRegion( nRegion );
1830cdf0e10cSrcweir 
1831cdf0e10cSrcweir     if ( pRegion )
1832cdf0e10cSrcweir     {
1833cdf0e10cSrcweir         ::rtl::OUString aRegionTargetURL = pRegion->GetTargetURL();
1834cdf0e10cSrcweir         if ( aRegionTargetURL.getLength() )
1835cdf0e10cSrcweir         {
1836cdf0e10cSrcweir             sal_uInt16 nLen = 0;
1837cdf0e10cSrcweir             sal_uInt16 nStartInd = 0;
1838cdf0e10cSrcweir 
1839cdf0e10cSrcweir             if( nIdx == USHRT_MAX )
1840cdf0e10cSrcweir             {
1841cdf0e10cSrcweir                 // this is a folder
1842cdf0e10cSrcweir                 // check whether there is at least one editable template
1843cdf0e10cSrcweir                 nLen = ( sal_uInt16 )pRegion->GetCount();
1844cdf0e10cSrcweir                 nStartInd = 0;
1845cdf0e10cSrcweir                 if ( nLen == 0 )
1846cdf0e10cSrcweir                     bResult = sal_True; // the writing part of empty folder with writing URL can be removed
1847cdf0e10cSrcweir             }
1848cdf0e10cSrcweir             else
1849cdf0e10cSrcweir             {
1850cdf0e10cSrcweir                 // this is a template
1851cdf0e10cSrcweir                 // check whether the template is inserted by user
1852cdf0e10cSrcweir                 nLen = 1;
1853cdf0e10cSrcweir                 nStartInd = nIdx;
1854cdf0e10cSrcweir             }
1855cdf0e10cSrcweir 
1856cdf0e10cSrcweir             for ( sal_uInt16 nInd = nStartInd; nInd < nStartInd + nLen; nInd++ )
1857cdf0e10cSrcweir             {
1858cdf0e10cSrcweir                 DocTempl_EntryData_Impl* pEntryData = pRegion->GetEntry( nInd );
1859cdf0e10cSrcweir                 if ( pEntryData )
1860cdf0e10cSrcweir                 {
1861cdf0e10cSrcweir                     ::rtl::OUString aEntryTargetURL = pEntryData->GetTargetURL();
1862cdf0e10cSrcweir                     if ( aEntryTargetURL.getLength()
1863cdf0e10cSrcweir                       && ::utl::UCBContentHelper::IsSubPath( aRegionTargetURL, aEntryTargetURL ) )
1864cdf0e10cSrcweir                     {
1865cdf0e10cSrcweir                         bResult = sal_True;
1866cdf0e10cSrcweir                         break;
1867cdf0e10cSrcweir                     }
1868cdf0e10cSrcweir                 }
1869cdf0e10cSrcweir             }
1870cdf0e10cSrcweir         }
1871cdf0e10cSrcweir     }
1872cdf0e10cSrcweir 
1873cdf0e10cSrcweir     return bResult;
1874cdf0e10cSrcweir }
1875cdf0e10cSrcweir 
1876cdf0e10cSrcweir // -----------------------------------------------------------------------
1877cdf0e10cSrcweir // -----------------------------------------------------------------------
1878cdf0e10cSrcweir // -----------------------------------------------------------------------
DocTempl_EntryData_Impl(RegionData_Impl * pParent,const OUString & rTitle)1879cdf0e10cSrcweir DocTempl_EntryData_Impl::DocTempl_EntryData_Impl( RegionData_Impl* pParent,
1880cdf0e10cSrcweir                                 const OUString& rTitle )
1881cdf0e10cSrcweir {
1882cdf0e10cSrcweir     mpParent    = pParent;
1883cdf0e10cSrcweir     maTitle     = rTitle;
1884cdf0e10cSrcweir     mbIsOwner   = sal_False;
1885cdf0e10cSrcweir     mbDidConvert= sal_False;
1886cdf0e10cSrcweir }
1887cdf0e10cSrcweir 
1888cdf0e10cSrcweir // -----------------------------------------------------------------------
Compare(const OUString & rTitle) const1889cdf0e10cSrcweir int DocTempl_EntryData_Impl::Compare( const OUString& rTitle ) const
1890cdf0e10cSrcweir {
1891cdf0e10cSrcweir     return maTitle.compareTo( rTitle );
1892cdf0e10cSrcweir }
1893cdf0e10cSrcweir 
1894cdf0e10cSrcweir //------------------------------------------------------------------------
CreateObjectShell()1895cdf0e10cSrcweir SfxObjectShellRef DocTempl_EntryData_Impl::CreateObjectShell()
1896cdf0e10cSrcweir {
1897cdf0e10cSrcweir     if( ! mxObjShell.Is() )
1898cdf0e10cSrcweir     {
1899cdf0e10cSrcweir         mbIsOwner = sal_False;
1900cdf0e10cSrcweir         sal_Bool bDum = sal_False;
1901cdf0e10cSrcweir         SfxApplication *pSfxApp = SFX_APP();
1902cdf0e10cSrcweir         String          aTargetURL = GetTargetURL();
1903cdf0e10cSrcweir 
1904cdf0e10cSrcweir         mxObjShell = pSfxApp->DocAlreadyLoaded( aTargetURL, sal_True, bDum );
1905cdf0e10cSrcweir 
1906cdf0e10cSrcweir         if( ! mxObjShell.Is() )
1907cdf0e10cSrcweir         {
1908cdf0e10cSrcweir             mbIsOwner = sal_True;
1909cdf0e10cSrcweir             SfxMedium *pMed=new SfxMedium(
1910cdf0e10cSrcweir                 aTargetURL,(STREAM_STD_READWRITE | STREAM_SHARE_DENYALL),  sal_False, 0 );
1911cdf0e10cSrcweir             const SfxFilter* pFilter = NULL;
1912cdf0e10cSrcweir             pMed->UseInteractionHandler(sal_True);
1913cdf0e10cSrcweir             if( pSfxApp->GetFilterMatcher().GuessFilter(
1914cdf0e10cSrcweir                 *pMed, &pFilter, SFX_FILTER_TEMPLATE, 0 ) ||
1915cdf0e10cSrcweir                 (pFilter && !pFilter->IsOwnFormat()) ||
1916cdf0e10cSrcweir                 (pFilter && !pFilter->UsesStorage()) )
1917cdf0e10cSrcweir             {
1918cdf0e10cSrcweir                 SfxErrorContext aEc( ERRCTX_SFX_LOADTEMPLATE,
1919cdf0e10cSrcweir                                      aTargetURL );
1920cdf0e10cSrcweir                 delete pMed;
1921cdf0e10cSrcweir                 mbDidConvert=sal_True;
1922cdf0e10cSrcweir                 sal_uIntPtr lErr;
1923cdf0e10cSrcweir                 if ( mxObjShell.Is() ) {
1924cdf0e10cSrcweir                     lErr = pSfxApp->LoadTemplate( mxObjShell,aTargetURL);
1925cdf0e10cSrcweir                     if( lErr != ERRCODE_NONE )
1926cdf0e10cSrcweir                         ErrorHandler::HandleError(lErr);
1927cdf0e10cSrcweir                 }
1928cdf0e10cSrcweir 
1929cdf0e10cSrcweir             }
1930cdf0e10cSrcweir             else if (pFilter)
1931cdf0e10cSrcweir             {
1932cdf0e10cSrcweir                 mbDidConvert=sal_False;
1933cdf0e10cSrcweir                 mxObjShell = SfxObjectShell::CreateObject( pFilter->GetServiceName(), SFX_CREATE_MODE_ORGANIZER );
1934cdf0e10cSrcweir                 if ( mxObjShell.Is() )
1935cdf0e10cSrcweir                 {
1936cdf0e10cSrcweir                     mxObjShell->DoInitNew(0);
1937cdf0e10cSrcweir                     // TODO/LATER: make sure that we don't use binary templates!
1938cdf0e10cSrcweir                     if( mxObjShell->LoadFrom( *pMed ) )
1939cdf0e10cSrcweir                     {
1940cdf0e10cSrcweir                         mxObjShell->DoSaveCompleted( pMed );
1941cdf0e10cSrcweir                     }
1942cdf0e10cSrcweir                     else
1943cdf0e10cSrcweir                         mxObjShell.Clear();
1944cdf0e10cSrcweir                 }
1945cdf0e10cSrcweir             }
1946cdf0e10cSrcweir         }
1947cdf0e10cSrcweir     }
1948cdf0e10cSrcweir 
1949cdf0e10cSrcweir     return (SfxObjectShellRef)(SfxObjectShell*) mxObjShell;
1950cdf0e10cSrcweir }
1951cdf0e10cSrcweir 
1952cdf0e10cSrcweir //------------------------------------------------------------------------
DeleteObjectShell()1953cdf0e10cSrcweir sal_Bool DocTempl_EntryData_Impl::DeleteObjectShell()
1954cdf0e10cSrcweir {
1955cdf0e10cSrcweir     sal_Bool bRet = sal_True;
1956cdf0e10cSrcweir 
1957cdf0e10cSrcweir     if ( mxObjShell.Is() )
1958cdf0e10cSrcweir     {
1959cdf0e10cSrcweir         if( mxObjShell->IsModified() )
1960cdf0e10cSrcweir         {
1961cdf0e10cSrcweir             //Hier speichern wir auch, falls die Vorlage in Bearbeitung ist...
1962cdf0e10cSrcweir             bRet = sal_False;
1963cdf0e10cSrcweir 
1964cdf0e10cSrcweir             if ( mbIsOwner )
1965cdf0e10cSrcweir             {
1966cdf0e10cSrcweir                 if( mbDidConvert )
1967cdf0e10cSrcweir                 {
1968cdf0e10cSrcweir                     bRet=mxObjShell->PreDoSaveAs_Impl(
1969cdf0e10cSrcweir                         GetTargetURL(),
1970cdf0e10cSrcweir                         mxObjShell->GetFactory().GetFilterContainer()->GetAnyFilter( SFX_FILTER_EXPORT | SFX_FILTER_IMPORT, SFX_FILTER_INTERNAL )->GetFilterName(), 0 );
1971cdf0e10cSrcweir                 }
1972cdf0e10cSrcweir                 else
1973cdf0e10cSrcweir                 {
1974cdf0e10cSrcweir                     if( mxObjShell->Save() )
1975cdf0e10cSrcweir                     {
1976cdf0e10cSrcweir                         uno::Reference< embed::XTransactedObject > xTransacted( mxObjShell->GetStorage(), uno::UNO_QUERY );
1977cdf0e10cSrcweir                         DBG_ASSERT( xTransacted.is(), "Storage must implement XTransactedObject!\n" );
1978cdf0e10cSrcweir                         if ( xTransacted.is() )
1979cdf0e10cSrcweir                         {
1980cdf0e10cSrcweir                             try
1981cdf0e10cSrcweir                             {
1982cdf0e10cSrcweir                                 xTransacted->commit();
1983cdf0e10cSrcweir                                 bRet = sal_True;
1984cdf0e10cSrcweir                             }
1985cdf0e10cSrcweir                             catch( uno::Exception& )
1986cdf0e10cSrcweir                             {
1987cdf0e10cSrcweir                             }
1988cdf0e10cSrcweir                         }
1989cdf0e10cSrcweir                     }
1990cdf0e10cSrcweir                 }
1991cdf0e10cSrcweir             }
1992cdf0e10cSrcweir         }
1993cdf0e10cSrcweir 
1994cdf0e10cSrcweir         if( bRet )
1995cdf0e10cSrcweir         {
1996cdf0e10cSrcweir             mxObjShell.Clear();
1997cdf0e10cSrcweir         }
1998cdf0e10cSrcweir     }
1999cdf0e10cSrcweir     return bRet;
2000cdf0e10cSrcweir }
2001cdf0e10cSrcweir 
2002cdf0e10cSrcweir // -----------------------------------------------------------------------
GetHierarchyURL()2003cdf0e10cSrcweir const OUString& DocTempl_EntryData_Impl::GetHierarchyURL()
2004cdf0e10cSrcweir {
2005cdf0e10cSrcweir     if ( !maOwnURL.getLength() )
2006cdf0e10cSrcweir     {
2007cdf0e10cSrcweir         INetURLObject aTemplateObj( GetParent()->GetHierarchyURL() );
2008cdf0e10cSrcweir 
2009cdf0e10cSrcweir         aTemplateObj.insertName( GetTitle(), false,
2010cdf0e10cSrcweir                      INetURLObject::LAST_SEGMENT, true,
2011cdf0e10cSrcweir                      INetURLObject::ENCODE_ALL );
2012cdf0e10cSrcweir 
2013cdf0e10cSrcweir         maOwnURL = aTemplateObj.GetMainURL( INetURLObject::NO_DECODE );
2014cdf0e10cSrcweir         DBG_ASSERT( maOwnURL.getLength(), "GetHierarchyURL(): Could not create URL!" );
2015cdf0e10cSrcweir     }
2016cdf0e10cSrcweir 
2017cdf0e10cSrcweir     return maOwnURL;
2018cdf0e10cSrcweir }
2019cdf0e10cSrcweir 
2020cdf0e10cSrcweir // -----------------------------------------------------------------------
GetTargetURL()2021cdf0e10cSrcweir const OUString& DocTempl_EntryData_Impl::GetTargetURL()
2022cdf0e10cSrcweir {
2023cdf0e10cSrcweir     if ( !maTargetURL.getLength() )
2024cdf0e10cSrcweir     {
2025cdf0e10cSrcweir         uno::Reference< XCommandEnvironment > aCmdEnv;
2026cdf0e10cSrcweir         Content aRegion;
2027cdf0e10cSrcweir 
2028cdf0e10cSrcweir         if ( Content::create( GetHierarchyURL(), aCmdEnv, aRegion ) )
2029cdf0e10cSrcweir         {
2030cdf0e10cSrcweir             OUString aPropName( RTL_CONSTASCII_USTRINGPARAM( TARGET_URL ) );
2031cdf0e10cSrcweir 
2032cdf0e10cSrcweir             getTextProperty_Impl( aRegion, aPropName, maTargetURL );
2033cdf0e10cSrcweir         }
2034cdf0e10cSrcweir         else
2035cdf0e10cSrcweir         {
2036cdf0e10cSrcweir             DBG_ERRORFILE( "GetTargetURL(): Could not create hierarchy content!" );
2037cdf0e10cSrcweir         }
2038cdf0e10cSrcweir     }
2039cdf0e10cSrcweir 
2040cdf0e10cSrcweir     return maTargetURL;
2041cdf0e10cSrcweir }
2042cdf0e10cSrcweir 
2043cdf0e10cSrcweir // -----------------------------------------------------------------------
2044cdf0e10cSrcweir // -----------------------------------------------------------------------
2045cdf0e10cSrcweir // -----------------------------------------------------------------------
2046cdf0e10cSrcweir // -----------------------------------------------------------------------
RegionData_Impl(const SfxDocTemplate_Impl * pParent,const OUString & rTitle)2047cdf0e10cSrcweir RegionData_Impl::RegionData_Impl( const SfxDocTemplate_Impl* pParent,
2048cdf0e10cSrcweir                                   const OUString& rTitle )
2049cdf0e10cSrcweir {
2050cdf0e10cSrcweir     maTitle     = rTitle;
2051cdf0e10cSrcweir     mpParent    = pParent;
2052cdf0e10cSrcweir }
2053cdf0e10cSrcweir 
2054cdf0e10cSrcweir // -----------------------------------------------------------------------
~RegionData_Impl()2055cdf0e10cSrcweir RegionData_Impl::~RegionData_Impl()
2056cdf0e10cSrcweir {
2057cdf0e10cSrcweir     DocTempl_EntryData_Impl *pData = maEntries.First();
2058cdf0e10cSrcweir 
2059cdf0e10cSrcweir     while ( pData )
2060cdf0e10cSrcweir     {
2061cdf0e10cSrcweir         delete pData;
2062cdf0e10cSrcweir         pData = maEntries.Next();
2063cdf0e10cSrcweir     }
2064cdf0e10cSrcweir }
2065cdf0e10cSrcweir 
2066cdf0e10cSrcweir // -----------------------------------------------------------------------
GetEntryPos(const OUString & rTitle,sal_Bool & rFound) const2067cdf0e10cSrcweir long RegionData_Impl::GetEntryPos( const OUString& rTitle,
2068cdf0e10cSrcweir                                    sal_Bool& rFound ) const
2069cdf0e10cSrcweir {
2070cdf0e10cSrcweir #if 1   // Don't use binary search today
2071cdf0e10cSrcweir     sal_uIntPtr i;
2072cdf0e10cSrcweir     sal_uIntPtr nCount = maEntries.Count();
2073cdf0e10cSrcweir 
2074cdf0e10cSrcweir     for ( i=0; i<nCount; i++ )
2075cdf0e10cSrcweir     {
2076cdf0e10cSrcweir         DocTempl_EntryData_Impl *pData = maEntries.GetObject( i );
2077cdf0e10cSrcweir 
2078cdf0e10cSrcweir         if ( pData->Compare( rTitle ) == 0 )
2079cdf0e10cSrcweir         {
2080cdf0e10cSrcweir             rFound = sal_True;
2081cdf0e10cSrcweir             return i;
2082cdf0e10cSrcweir         }
2083cdf0e10cSrcweir     }
2084cdf0e10cSrcweir 
2085cdf0e10cSrcweir     rFound = sal_False;
2086cdf0e10cSrcweir     return i;
2087cdf0e10cSrcweir 
2088cdf0e10cSrcweir #else
2089cdf0e10cSrcweir     // use binary search to find the correct position
2090cdf0e10cSrcweir     // in the maEntries list
2091cdf0e10cSrcweir 
2092cdf0e10cSrcweir     int     nCompVal = 1;
2093cdf0e10cSrcweir     long    nStart = 0;
2094cdf0e10cSrcweir     long    nEnd = maEntries.Count() - 1;
2095cdf0e10cSrcweir     long    nMid;
2096cdf0e10cSrcweir 
2097cdf0e10cSrcweir     DocTempl_EntryData_Impl* pMid;
2098cdf0e10cSrcweir 
2099cdf0e10cSrcweir     rFound = sal_False;
2100cdf0e10cSrcweir 
2101cdf0e10cSrcweir     while ( nCompVal && ( nStart <= nEnd ) )
2102cdf0e10cSrcweir     {
2103cdf0e10cSrcweir         nMid = ( nEnd - nStart ) / 2 + nStart;
2104cdf0e10cSrcweir         pMid = maEntries.GetObject( nMid );
2105cdf0e10cSrcweir 
2106cdf0e10cSrcweir         nCompVal = pMid->Compare( rTitle );
2107cdf0e10cSrcweir 
2108cdf0e10cSrcweir         if ( nCompVal < 0 )     // pMid < pData
2109cdf0e10cSrcweir             nStart = nMid + 1;
2110cdf0e10cSrcweir         else
2111cdf0e10cSrcweir             nEnd = nMid - 1;
2112cdf0e10cSrcweir     }
2113cdf0e10cSrcweir 
2114cdf0e10cSrcweir     if ( nCompVal == 0 )
2115cdf0e10cSrcweir     {
2116cdf0e10cSrcweir         rFound = sal_True;
2117cdf0e10cSrcweir     }
2118cdf0e10cSrcweir     else
2119cdf0e10cSrcweir     {
2120cdf0e10cSrcweir         if ( nCompVal < 0 )     // pMid < pData
2121cdf0e10cSrcweir             nMid++;
2122cdf0e10cSrcweir     }
2123cdf0e10cSrcweir 
2124cdf0e10cSrcweir     return nMid;
2125cdf0e10cSrcweir #endif
2126cdf0e10cSrcweir }
2127cdf0e10cSrcweir 
2128cdf0e10cSrcweir // -----------------------------------------------------------------------
AddEntry(const OUString & rTitle,const OUString & rTargetURL,sal_uInt16 * pPos)2129cdf0e10cSrcweir void RegionData_Impl::AddEntry( const OUString& rTitle,
2130cdf0e10cSrcweir                                 const OUString& rTargetURL,
2131cdf0e10cSrcweir                                 sal_uInt16 *pPos )
2132cdf0e10cSrcweir {
2133cdf0e10cSrcweir     INetURLObject aLinkObj( GetHierarchyURL() );
2134cdf0e10cSrcweir     aLinkObj.insertName( rTitle, false,
2135cdf0e10cSrcweir                       INetURLObject::LAST_SEGMENT, true,
2136cdf0e10cSrcweir                       INetURLObject::ENCODE_ALL );
2137cdf0e10cSrcweir     OUString aLinkURL = aLinkObj.GetMainURL( INetURLObject::NO_DECODE );
2138cdf0e10cSrcweir 
2139cdf0e10cSrcweir     DocTempl_EntryData_Impl *pEntry;
2140cdf0e10cSrcweir     sal_Bool        bFound = sal_False;
2141cdf0e10cSrcweir     long            nPos = GetEntryPos( rTitle, bFound );
2142cdf0e10cSrcweir 
2143cdf0e10cSrcweir     if ( bFound )
2144cdf0e10cSrcweir     {
2145cdf0e10cSrcweir         pEntry = maEntries.GetObject( nPos );
2146cdf0e10cSrcweir     }
2147cdf0e10cSrcweir     else
2148cdf0e10cSrcweir     {
2149cdf0e10cSrcweir         if ( pPos )
2150cdf0e10cSrcweir             nPos = *pPos;
2151cdf0e10cSrcweir 
2152cdf0e10cSrcweir         pEntry = new DocTempl_EntryData_Impl( this, rTitle );
2153cdf0e10cSrcweir         pEntry->SetTargetURL( rTargetURL );
2154cdf0e10cSrcweir         pEntry->SetHierarchyURL( aLinkURL );
2155cdf0e10cSrcweir         maEntries.Insert( pEntry, nPos );
2156cdf0e10cSrcweir     }
2157cdf0e10cSrcweir }
2158cdf0e10cSrcweir 
2159cdf0e10cSrcweir // -----------------------------------------------------------------------
GetCount() const2160cdf0e10cSrcweir sal_uIntPtr RegionData_Impl::GetCount() const
2161cdf0e10cSrcweir {
2162cdf0e10cSrcweir     return maEntries.Count();
2163cdf0e10cSrcweir }
2164cdf0e10cSrcweir 
2165cdf0e10cSrcweir // -----------------------------------------------------------------------
GetHierarchyURL()2166cdf0e10cSrcweir const OUString& RegionData_Impl::GetHierarchyURL()
2167cdf0e10cSrcweir {
2168cdf0e10cSrcweir     if ( !maOwnURL.getLength() )
2169cdf0e10cSrcweir     {
2170cdf0e10cSrcweir         INetURLObject aRegionObj( GetParent()->GetRootURL() );
2171cdf0e10cSrcweir 
2172cdf0e10cSrcweir         aRegionObj.insertName( GetTitle(), false,
2173cdf0e10cSrcweir                      INetURLObject::LAST_SEGMENT, true,
2174cdf0e10cSrcweir                      INetURLObject::ENCODE_ALL );
2175cdf0e10cSrcweir 
2176cdf0e10cSrcweir         maOwnURL = aRegionObj.GetMainURL( INetURLObject::NO_DECODE );
2177cdf0e10cSrcweir         DBG_ASSERT( maOwnURL.getLength(), "GetHierarchyURL(): Could not create URL!" );
2178cdf0e10cSrcweir     }
2179cdf0e10cSrcweir 
2180cdf0e10cSrcweir     return maOwnURL;
2181cdf0e10cSrcweir }
2182cdf0e10cSrcweir 
2183cdf0e10cSrcweir // -----------------------------------------------------------------------
GetTargetURL()2184cdf0e10cSrcweir const OUString& RegionData_Impl::GetTargetURL()
2185cdf0e10cSrcweir {
2186cdf0e10cSrcweir     if ( !maTargetURL.getLength() )
2187cdf0e10cSrcweir     {
2188cdf0e10cSrcweir         uno::Reference< XCommandEnvironment > aCmdEnv;
2189cdf0e10cSrcweir         Content aRegion;
2190cdf0e10cSrcweir 
2191cdf0e10cSrcweir         if ( Content::create( GetHierarchyURL(), aCmdEnv, aRegion ) )
2192cdf0e10cSrcweir         {
2193cdf0e10cSrcweir             OUString aPropName( RTL_CONSTASCII_USTRINGPARAM( TARGET_DIR_URL ) );
2194cdf0e10cSrcweir 
2195cdf0e10cSrcweir             getTextProperty_Impl( aRegion, aPropName, maTargetURL );
2196cdf0e10cSrcweir             // --> PB 2004-10-27 #i32656# - the targeturl must be substituted: $(baseinsturl)
2197cdf0e10cSrcweir             maTargetURL = SvtPathOptions().SubstituteVariable( maTargetURL );
2198cdf0e10cSrcweir             // <--
2199cdf0e10cSrcweir         }
2200cdf0e10cSrcweir         else
2201cdf0e10cSrcweir         {
2202cdf0e10cSrcweir             DBG_ERRORFILE( "GetTargetURL(): Could not create hierarchy content!" );
2203cdf0e10cSrcweir         }
2204cdf0e10cSrcweir     }
2205cdf0e10cSrcweir 
2206cdf0e10cSrcweir     return maTargetURL;
2207cdf0e10cSrcweir }
2208cdf0e10cSrcweir 
2209cdf0e10cSrcweir // -----------------------------------------------------------------------
GetEntry(const OUString & rName) const2210cdf0e10cSrcweir DocTempl_EntryData_Impl* RegionData_Impl::GetEntry( const OUString& rName ) const
2211cdf0e10cSrcweir {
2212cdf0e10cSrcweir     sal_Bool    bFound = sal_False;
2213cdf0e10cSrcweir     long        nPos = GetEntryPos( rName, bFound );
2214cdf0e10cSrcweir 
2215cdf0e10cSrcweir     if ( bFound )
2216cdf0e10cSrcweir         return maEntries.GetObject( nPos );
2217cdf0e10cSrcweir     else
2218cdf0e10cSrcweir         return NULL;
2219cdf0e10cSrcweir }
2220cdf0e10cSrcweir 
2221cdf0e10cSrcweir // -----------------------------------------------------------------------
GetByTargetURL(const OUString & rName) const2222cdf0e10cSrcweir DocTempl_EntryData_Impl* RegionData_Impl::GetByTargetURL( const OUString& rName ) const
2223cdf0e10cSrcweir {
2224cdf0e10cSrcweir     DocTempl_EntryData_Impl *pEntry;
2225cdf0e10cSrcweir 
2226cdf0e10cSrcweir     sal_uIntPtr nCount = maEntries.Count();
2227cdf0e10cSrcweir 
2228cdf0e10cSrcweir     for ( sal_uIntPtr i=0; i<nCount; i++ )
2229cdf0e10cSrcweir     {
2230cdf0e10cSrcweir         pEntry = maEntries.GetObject( i );
2231cdf0e10cSrcweir         if ( pEntry && ( pEntry->GetTargetURL() == rName ) )
2232cdf0e10cSrcweir             return pEntry;
2233cdf0e10cSrcweir     }
2234cdf0e10cSrcweir 
2235cdf0e10cSrcweir     return NULL;
2236cdf0e10cSrcweir }
2237cdf0e10cSrcweir 
2238cdf0e10cSrcweir // -----------------------------------------------------------------------
GetEntry(sal_uIntPtr nIndex) const2239cdf0e10cSrcweir DocTempl_EntryData_Impl* RegionData_Impl::GetEntry( sal_uIntPtr nIndex ) const
2240cdf0e10cSrcweir {
2241cdf0e10cSrcweir     return maEntries.GetObject( nIndex );
2242cdf0e10cSrcweir }
2243cdf0e10cSrcweir 
2244cdf0e10cSrcweir // -----------------------------------------------------------------------
DeleteEntry(sal_uIntPtr nIndex)2245cdf0e10cSrcweir void RegionData_Impl::DeleteEntry( sal_uIntPtr nIndex )
2246cdf0e10cSrcweir {
2247cdf0e10cSrcweir     DocTempl_EntryData_Impl *pEntry = maEntries.GetObject( nIndex );
2248cdf0e10cSrcweir 
2249cdf0e10cSrcweir     if ( pEntry )
2250cdf0e10cSrcweir     {
2251cdf0e10cSrcweir         delete pEntry;
2252cdf0e10cSrcweir         maEntries.Remove( (sal_uIntPtr) nIndex );
2253cdf0e10cSrcweir     }
2254cdf0e10cSrcweir }
2255cdf0e10cSrcweir 
2256cdf0e10cSrcweir // -----------------------------------------------------------------------
Compare(RegionData_Impl * pCompare) const2257cdf0e10cSrcweir int RegionData_Impl::Compare( RegionData_Impl* pCompare ) const
2258cdf0e10cSrcweir {
2259cdf0e10cSrcweir     int nCompare = maTitle.compareTo( pCompare->maTitle );
2260cdf0e10cSrcweir 
2261cdf0e10cSrcweir     return nCompare;
2262cdf0e10cSrcweir }
2263cdf0e10cSrcweir 
2264cdf0e10cSrcweir // -----------------------------------------------------------------------
2265cdf0e10cSrcweir // -----------------------------------------------------------------------
2266cdf0e10cSrcweir // -----------------------------------------------------------------------
2267cdf0e10cSrcweir 
SfxDocTemplate_Impl()2268cdf0e10cSrcweir SfxDocTemplate_Impl::SfxDocTemplate_Impl()
2269cdf0e10cSrcweir : mbConstructed( sal_False )
2270cdf0e10cSrcweir , mnLockCounter( 0 )
2271cdf0e10cSrcweir {
2272cdf0e10cSrcweir }
2273cdf0e10cSrcweir 
2274cdf0e10cSrcweir // -----------------------------------------------------------------------
~SfxDocTemplate_Impl()2275cdf0e10cSrcweir SfxDocTemplate_Impl::~SfxDocTemplate_Impl()
2276cdf0e10cSrcweir {
2277cdf0e10cSrcweir     Clear();
2278cdf0e10cSrcweir 
2279cdf0e10cSrcweir     gpTemplateData = NULL;
2280cdf0e10cSrcweir }
2281cdf0e10cSrcweir 
2282cdf0e10cSrcweir // -----------------------------------------------------------------------
IncrementLock()2283cdf0e10cSrcweir void SfxDocTemplate_Impl::IncrementLock()
2284cdf0e10cSrcweir {
2285cdf0e10cSrcweir     ::osl::MutexGuard aGuard( maMutex );
2286cdf0e10cSrcweir     mnLockCounter++;
2287cdf0e10cSrcweir }
2288cdf0e10cSrcweir 
2289cdf0e10cSrcweir // -----------------------------------------------------------------------
DecrementLock()2290cdf0e10cSrcweir void SfxDocTemplate_Impl::DecrementLock()
2291cdf0e10cSrcweir {
2292cdf0e10cSrcweir     ::osl::MutexGuard aGuard( maMutex );
2293cdf0e10cSrcweir     if ( mnLockCounter )
2294cdf0e10cSrcweir         mnLockCounter--;
2295cdf0e10cSrcweir }
2296cdf0e10cSrcweir 
2297cdf0e10cSrcweir // -----------------------------------------------------------------------
GetRegion(sal_uIntPtr nIndex) const2298cdf0e10cSrcweir RegionData_Impl* SfxDocTemplate_Impl::GetRegion( sal_uIntPtr nIndex ) const
2299cdf0e10cSrcweir {
2300cdf0e10cSrcweir     return maRegions.GetObject( nIndex );
2301cdf0e10cSrcweir }
2302cdf0e10cSrcweir 
2303cdf0e10cSrcweir // -----------------------------------------------------------------------
GetRegion(const OUString & rName) const2304cdf0e10cSrcweir RegionData_Impl* SfxDocTemplate_Impl::GetRegion( const OUString& rName )
2305cdf0e10cSrcweir     const
2306cdf0e10cSrcweir {
2307cdf0e10cSrcweir     sal_uIntPtr nCount = maRegions.Count();
2308cdf0e10cSrcweir     RegionData_Impl *pData;
2309cdf0e10cSrcweir 
2310cdf0e10cSrcweir     for ( sal_uIntPtr i=0; i<nCount; i++ )
2311cdf0e10cSrcweir     {
2312cdf0e10cSrcweir         pData = maRegions.GetObject( i );
2313cdf0e10cSrcweir 
2314cdf0e10cSrcweir         if ( pData->GetTitle() == rName )
2315cdf0e10cSrcweir             return pData;
2316cdf0e10cSrcweir     }
2317cdf0e10cSrcweir 
2318cdf0e10cSrcweir     return NULL;
2319cdf0e10cSrcweir }
2320cdf0e10cSrcweir 
2321cdf0e10cSrcweir // -----------------------------------------------------------------------
DeleteRegion(sal_uIntPtr nIndex)2322cdf0e10cSrcweir void SfxDocTemplate_Impl::DeleteRegion( sal_uIntPtr nIndex )
2323cdf0e10cSrcweir {
2324cdf0e10cSrcweir     RegionData_Impl* pRegion = maRegions.GetObject( nIndex );
2325cdf0e10cSrcweir 
2326cdf0e10cSrcweir     if ( pRegion )
2327cdf0e10cSrcweir     {
2328cdf0e10cSrcweir         delete pRegion;
2329cdf0e10cSrcweir         maRegions.Remove( (sal_uIntPtr) nIndex );
2330cdf0e10cSrcweir     }
2331cdf0e10cSrcweir }
2332cdf0e10cSrcweir 
2333cdf0e10cSrcweir // -----------------------------------------------------------------------
2334cdf0e10cSrcweir /*  AddRegion adds a Region to the RegionList
2335cdf0e10cSrcweir */
AddRegion(const OUString & rTitle,Content & rContent)2336cdf0e10cSrcweir void SfxDocTemplate_Impl::AddRegion( const OUString& rTitle,
2337cdf0e10cSrcweir                                      Content& rContent )
2338cdf0e10cSrcweir {
2339cdf0e10cSrcweir     RegionData_Impl* pRegion;
2340cdf0e10cSrcweir     pRegion = new RegionData_Impl( this, rTitle );
2341cdf0e10cSrcweir 
2342cdf0e10cSrcweir     if ( ! InsertRegion( pRegion ) )
2343cdf0e10cSrcweir     {
2344cdf0e10cSrcweir         delete pRegion;
2345cdf0e10cSrcweir         return;
2346cdf0e10cSrcweir     }
2347cdf0e10cSrcweir 
2348cdf0e10cSrcweir     // now get the content of the region
2349cdf0e10cSrcweir     uno::Reference< XResultSet > xResultSet;
2350cdf0e10cSrcweir     Sequence< OUString > aProps(2);
2351cdf0e10cSrcweir     aProps[0] = OUString::createFromAscii( TITLE );
2352cdf0e10cSrcweir     aProps[1] = OUString::createFromAscii( TARGET_URL );
2353cdf0e10cSrcweir 
2354cdf0e10cSrcweir     try
2355cdf0e10cSrcweir     {
2356cdf0e10cSrcweir         ResultSetInclude eInclude = INCLUDE_DOCUMENTS_ONLY;
2357cdf0e10cSrcweir         Sequence< NumberedSortingInfo >     aSortingInfo(1);
2358cdf0e10cSrcweir         aSortingInfo.getArray()->ColumnIndex = 1;
2359cdf0e10cSrcweir         aSortingInfo.getArray()->Ascending = sal_True;
2360cdf0e10cSrcweir         xResultSet = rContent.createSortedCursor( aProps, aSortingInfo, m_rCompareFactory, eInclude );
2361cdf0e10cSrcweir     }
2362cdf0e10cSrcweir     catch ( Exception& ) {}
2363cdf0e10cSrcweir 
2364cdf0e10cSrcweir     if ( xResultSet.is() )
2365cdf0e10cSrcweir     {
2366cdf0e10cSrcweir         uno::Reference< XContentAccess > xContentAccess( xResultSet, UNO_QUERY );
2367cdf0e10cSrcweir         uno::Reference< XRow > xRow( xResultSet, UNO_QUERY );
2368cdf0e10cSrcweir 
2369cdf0e10cSrcweir         try
2370cdf0e10cSrcweir         {
2371cdf0e10cSrcweir             while ( xResultSet->next() )
2372cdf0e10cSrcweir             {
2373cdf0e10cSrcweir                 OUString aTitle( xRow->getString( 1 ) );
2374cdf0e10cSrcweir                 OUString aTargetDir( xRow->getString( 2 ) );
2375cdf0e10cSrcweir 
2376cdf0e10cSrcweir                 pRegion->AddEntry( aTitle, aTargetDir );
2377cdf0e10cSrcweir             }
2378cdf0e10cSrcweir         }
2379cdf0e10cSrcweir         catch ( Exception& ) {}
2380cdf0e10cSrcweir     }
2381cdf0e10cSrcweir }
2382cdf0e10cSrcweir 
2383cdf0e10cSrcweir // -----------------------------------------------------------------------
CreateFromHierarchy(Content & rTemplRoot)2384cdf0e10cSrcweir void SfxDocTemplate_Impl::CreateFromHierarchy( Content &rTemplRoot )
2385cdf0e10cSrcweir {
2386cdf0e10cSrcweir     uno::Reference< XResultSet > xResultSet;
2387cdf0e10cSrcweir     Sequence< OUString > aProps(1);
2388cdf0e10cSrcweir     aProps[0] = OUString::createFromAscii( TITLE );
2389cdf0e10cSrcweir 
2390cdf0e10cSrcweir     try
2391cdf0e10cSrcweir     {
2392cdf0e10cSrcweir         ResultSetInclude eInclude = INCLUDE_FOLDERS_ONLY;
2393cdf0e10cSrcweir         Sequence< NumberedSortingInfo >     aSortingInfo(1);
2394cdf0e10cSrcweir         aSortingInfo.getArray()->ColumnIndex = 1;
2395cdf0e10cSrcweir         aSortingInfo.getArray()->Ascending = sal_True;
2396cdf0e10cSrcweir         xResultSet = rTemplRoot.createSortedCursor( aProps, aSortingInfo, m_rCompareFactory, eInclude );
2397cdf0e10cSrcweir     }
2398cdf0e10cSrcweir     catch ( Exception& ) {}
2399cdf0e10cSrcweir 
2400cdf0e10cSrcweir     if ( xResultSet.is() )
2401cdf0e10cSrcweir     {
2402cdf0e10cSrcweir         uno::Reference< XCommandEnvironment > aCmdEnv;
2403cdf0e10cSrcweir         uno::Reference< XContentAccess > xContentAccess( xResultSet, UNO_QUERY );
2404cdf0e10cSrcweir         uno::Reference< XRow > xRow( xResultSet, UNO_QUERY );
2405cdf0e10cSrcweir 
2406cdf0e10cSrcweir         try
2407cdf0e10cSrcweir         {
2408cdf0e10cSrcweir             while ( xResultSet->next() )
2409cdf0e10cSrcweir             {
2410cdf0e10cSrcweir                 OUString aTitle( xRow->getString( 1 ) );
2411cdf0e10cSrcweir 
2412cdf0e10cSrcweir                 OUString aId = xContentAccess->queryContentIdentifierString();
2413cdf0e10cSrcweir                 Content  aContent = Content( aId, aCmdEnv );
2414cdf0e10cSrcweir 
2415cdf0e10cSrcweir                 AddRegion( aTitle, aContent );
2416cdf0e10cSrcweir             }
2417cdf0e10cSrcweir         }
2418cdf0e10cSrcweir         catch ( Exception& ) {}
2419cdf0e10cSrcweir     }
2420cdf0e10cSrcweir }
2421cdf0e10cSrcweir 
2422cdf0e10cSrcweir // ------------------------------------------------------------------------
Construct()2423cdf0e10cSrcweir sal_Bool SfxDocTemplate_Impl::Construct( )
2424cdf0e10cSrcweir {
2425cdf0e10cSrcweir     ::osl::MutexGuard aGuard( maMutex );
2426cdf0e10cSrcweir 
2427cdf0e10cSrcweir     if ( mbConstructed )
2428cdf0e10cSrcweir         return sal_True;
2429cdf0e10cSrcweir 
2430cdf0e10cSrcweir     uno::Reference< XMultiServiceFactory >   xFactory;
2431cdf0e10cSrcweir     xFactory = ::comphelper::getProcessServiceFactory();
2432cdf0e10cSrcweir 
2433cdf0e10cSrcweir     OUString aService( RTL_CONSTASCII_USTRINGPARAM( SERVICENAME_DOCINFO ) );
2434cdf0e10cSrcweir     uno::Reference< XPersist > xInfo( xFactory->createInstance( aService ), UNO_QUERY );
2435cdf0e10cSrcweir     mxInfo = xInfo;
2436cdf0e10cSrcweir 
2437cdf0e10cSrcweir     aService = OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICENAME_DOCTEMPLATES ) );
2438cdf0e10cSrcweir     uno::Reference< XDocumentTemplates > xTemplates( xFactory->createInstance( aService ), UNO_QUERY );
2439cdf0e10cSrcweir 
2440cdf0e10cSrcweir     if ( xTemplates.is() )
2441cdf0e10cSrcweir         mxTemplates = xTemplates;
2442cdf0e10cSrcweir     else
2443cdf0e10cSrcweir         return sal_False;
2444cdf0e10cSrcweir 
2445cdf0e10cSrcweir     uno::Reference< XLocalizable > xLocalizable( xTemplates, UNO_QUERY );
2446cdf0e10cSrcweir 
2447cdf0e10cSrcweir     Sequence< Any > aCompareArg(1);
2448cdf0e10cSrcweir     *(aCompareArg.getArray()) <<= xLocalizable->getLocale();;
2449cdf0e10cSrcweir     m_rCompareFactory = uno::Reference< XAnyCompareFactory >(
2450cdf0e10cSrcweir                     xFactory->createInstanceWithArguments( OUString::createFromAscii( "com.sun.star.ucb.AnyCompareFactory" ),
2451cdf0e10cSrcweir                                                            aCompareArg ),
2452cdf0e10cSrcweir                     UNO_QUERY );
2453cdf0e10cSrcweir 
2454cdf0e10cSrcweir     uno::Reference < XContent > aRootContent = xTemplates->getContent();
2455cdf0e10cSrcweir     uno::Reference < XCommandEnvironment > aCmdEnv;
2456cdf0e10cSrcweir 
2457cdf0e10cSrcweir     if ( ! aRootContent.is() )
2458cdf0e10cSrcweir         return sal_False;
2459cdf0e10cSrcweir 
2460cdf0e10cSrcweir     mbConstructed = sal_True;
2461cdf0e10cSrcweir     maRootURL = aRootContent->getIdentifier()->getContentIdentifier();
2462cdf0e10cSrcweir 
2463cdf0e10cSrcweir     ResStringArray  aLongNames( SfxResId( TEMPLATE_LONG_NAMES_ARY ) );
2464cdf0e10cSrcweir 
2465cdf0e10cSrcweir     if ( aLongNames.Count() )
2466cdf0e10cSrcweir         maStandardGroup = aLongNames.GetString( 0 );
2467cdf0e10cSrcweir 
2468cdf0e10cSrcweir     Content aTemplRoot( aRootContent, aCmdEnv );
2469cdf0e10cSrcweir     CreateFromHierarchy( aTemplRoot );
2470cdf0e10cSrcweir 
2471cdf0e10cSrcweir     return sal_True;
2472cdf0e10cSrcweir }
2473cdf0e10cSrcweir 
2474cdf0e10cSrcweir // -----------------------------------------------------------------------
ReInitFromComponent()2475cdf0e10cSrcweir void SfxDocTemplate_Impl::ReInitFromComponent()
2476cdf0e10cSrcweir {
2477cdf0e10cSrcweir     uno::Reference< XDocumentTemplates > xTemplates = getDocTemplates();
2478cdf0e10cSrcweir     if ( xTemplates.is() )
2479cdf0e10cSrcweir     {
2480cdf0e10cSrcweir         uno::Reference < XContent > aRootContent = xTemplates->getContent();
2481cdf0e10cSrcweir         uno::Reference < XCommandEnvironment > aCmdEnv;
2482cdf0e10cSrcweir         Content aTemplRoot( aRootContent, aCmdEnv );
2483cdf0e10cSrcweir         Clear();
2484cdf0e10cSrcweir         CreateFromHierarchy( aTemplRoot );
2485cdf0e10cSrcweir     }
2486cdf0e10cSrcweir }
2487cdf0e10cSrcweir 
2488cdf0e10cSrcweir // -----------------------------------------------------------------------
GetTemplates(Content & rTargetFolder,Content &,RegionData_Impl * pRegion)2489cdf0e10cSrcweir void SfxDocTemplate_Impl::GetTemplates( Content& rTargetFolder,
2490cdf0e10cSrcweir                                         Content& /*rParentFolder*/,
2491cdf0e10cSrcweir                                         RegionData_Impl* pRegion )
2492cdf0e10cSrcweir {
2493cdf0e10cSrcweir     uno::Reference< XResultSet > xResultSet;
2494cdf0e10cSrcweir     Sequence< OUString >    aProps(1);
2495cdf0e10cSrcweir 
2496cdf0e10cSrcweir     aProps[0] = OUString::createFromAscii( TITLE );
2497cdf0e10cSrcweir 
2498cdf0e10cSrcweir     try
2499cdf0e10cSrcweir     {
2500cdf0e10cSrcweir         ResultSetInclude eInclude = INCLUDE_DOCUMENTS_ONLY;
2501cdf0e10cSrcweir         Sequence< NumberedSortingInfo >     aSortingInfo(1);
2502cdf0e10cSrcweir         aSortingInfo.getArray()->ColumnIndex = 1;
2503cdf0e10cSrcweir         aSortingInfo.getArray()->Ascending = sal_True;
2504cdf0e10cSrcweir         xResultSet = rTargetFolder.createSortedCursor( aProps, aSortingInfo, m_rCompareFactory, eInclude );
2505cdf0e10cSrcweir     }
2506cdf0e10cSrcweir     catch ( Exception& ) {}
2507cdf0e10cSrcweir 
2508cdf0e10cSrcweir     if ( xResultSet.is() )
2509cdf0e10cSrcweir     {
2510cdf0e10cSrcweir         uno::Reference< XContentAccess > xContentAccess( xResultSet, UNO_QUERY );
2511cdf0e10cSrcweir         uno::Reference< XRow > xRow( xResultSet, UNO_QUERY );
2512cdf0e10cSrcweir 
2513cdf0e10cSrcweir         try
2514cdf0e10cSrcweir         {
2515cdf0e10cSrcweir             while ( xResultSet->next() )
2516cdf0e10cSrcweir             {
2517cdf0e10cSrcweir                 OUString aTitle( xRow->getString(1) );
2518cdf0e10cSrcweir 
2519cdf0e10cSrcweir                 if ( aTitle.compareToAscii( "sfx.tlx" ) == 0 )
2520cdf0e10cSrcweir                     continue;
2521cdf0e10cSrcweir 
2522cdf0e10cSrcweir                 OUString aId = xContentAccess->queryContentIdentifierString();
2523cdf0e10cSrcweir 
2524cdf0e10cSrcweir                 DocTempl_EntryData_Impl* pEntry = pRegion->GetByTargetURL( aId );
2525cdf0e10cSrcweir 
2526cdf0e10cSrcweir                 if ( ! pEntry )
2527cdf0e10cSrcweir                 {
2528cdf0e10cSrcweir                     OUString aFullTitle;
2529cdf0e10cSrcweir                     if( !GetTitleFromURL( aId, aFullTitle ) )
2530cdf0e10cSrcweir                     {
2531cdf0e10cSrcweir                         DBG_ERRORFILE( "GetTemplates(): template of alien format" );
2532cdf0e10cSrcweir                         continue;
2533cdf0e10cSrcweir                     }
2534cdf0e10cSrcweir 
2535cdf0e10cSrcweir                     if ( aFullTitle.getLength() )
2536cdf0e10cSrcweir                         aTitle = aFullTitle;
2537cdf0e10cSrcweir 
2538cdf0e10cSrcweir                     pRegion->AddEntry( aTitle, aId );
2539cdf0e10cSrcweir                 }
2540cdf0e10cSrcweir             }
2541cdf0e10cSrcweir         }
2542cdf0e10cSrcweir         catch ( Exception& ) {}
2543cdf0e10cSrcweir     }
2544cdf0e10cSrcweir }
2545cdf0e10cSrcweir 
2546cdf0e10cSrcweir 
2547cdf0e10cSrcweir // -----------------------------------------------------------------------
GetRegionPos(const OUString & rTitle,sal_Bool & rFound) const2548cdf0e10cSrcweir long SfxDocTemplate_Impl::GetRegionPos( const OUString& rTitle,
2549cdf0e10cSrcweir                                         sal_Bool& rFound ) const
2550cdf0e10cSrcweir {
2551cdf0e10cSrcweir     int     nCompVal = 1;
2552cdf0e10cSrcweir     long    nStart = 0;
2553cdf0e10cSrcweir     long    nEnd = maRegions.Count() - 1;
2554cdf0e10cSrcweir     long    nMid = 0;
2555cdf0e10cSrcweir 
2556cdf0e10cSrcweir     RegionData_Impl* pMid;
2557cdf0e10cSrcweir 
2558cdf0e10cSrcweir     while ( nCompVal && ( nStart <= nEnd ) )
2559cdf0e10cSrcweir     {
2560cdf0e10cSrcweir         nMid = ( nEnd - nStart ) / 2 + nStart;
2561cdf0e10cSrcweir         pMid = maRegions.GetObject( nMid );
2562cdf0e10cSrcweir 
2563cdf0e10cSrcweir         nCompVal = pMid->Compare( rTitle );
2564cdf0e10cSrcweir 
2565cdf0e10cSrcweir         if ( nCompVal < 0 )     // pMid < pData
2566cdf0e10cSrcweir             nStart = nMid + 1;
2567cdf0e10cSrcweir         else
2568cdf0e10cSrcweir             nEnd = nMid - 1;
2569cdf0e10cSrcweir     }
2570cdf0e10cSrcweir 
2571cdf0e10cSrcweir     if ( nCompVal == 0 )
2572cdf0e10cSrcweir         rFound = sal_True;
2573cdf0e10cSrcweir     else
2574cdf0e10cSrcweir     {
2575cdf0e10cSrcweir         if ( nCompVal < 0 )     // pMid < pData
2576cdf0e10cSrcweir             nMid++;
2577cdf0e10cSrcweir 
2578cdf0e10cSrcweir         rFound = sal_False;
2579cdf0e10cSrcweir     }
2580cdf0e10cSrcweir 
2581cdf0e10cSrcweir     return nMid;
2582cdf0e10cSrcweir }
2583cdf0e10cSrcweir 
2584cdf0e10cSrcweir // -----------------------------------------------------------------------
InsertRegion(RegionData_Impl * pNew,sal_uIntPtr nPos)2585cdf0e10cSrcweir sal_Bool SfxDocTemplate_Impl::InsertRegion( RegionData_Impl *pNew,
2586cdf0e10cSrcweir                                             sal_uIntPtr nPos )
2587cdf0e10cSrcweir {
2588cdf0e10cSrcweir     ::osl::MutexGuard   aGuard( maMutex );
2589cdf0e10cSrcweir     RegionData_Impl    *pData = maRegions.First();
2590cdf0e10cSrcweir 
2591cdf0e10cSrcweir     while ( pData && ( pData->Compare( pNew ) != 0 ) )
2592cdf0e10cSrcweir         pData = maRegions.Next();
2593cdf0e10cSrcweir 
2594cdf0e10cSrcweir     if ( ! pData )
2595cdf0e10cSrcweir     {
2596cdf0e10cSrcweir         // compare with the name of the standard group here to insert it
2597cdf0e10cSrcweir         // first
2598cdf0e10cSrcweir 
2599cdf0e10cSrcweir         if ( pNew->GetTitle() == maStandardGroup )
2600cdf0e10cSrcweir             maRegions.Insert( pNew, (sal_uIntPtr) 0 );
2601cdf0e10cSrcweir         else
2602cdf0e10cSrcweir             maRegions.Insert( pNew, nPos );
2603cdf0e10cSrcweir     }
2604cdf0e10cSrcweir 
2605cdf0e10cSrcweir     return ( pData == NULL );
2606cdf0e10cSrcweir }
2607cdf0e10cSrcweir 
2608cdf0e10cSrcweir // -----------------------------------------------------------------------
Rescan()2609cdf0e10cSrcweir void SfxDocTemplate_Impl::Rescan()
2610cdf0e10cSrcweir {
2611cdf0e10cSrcweir     Clear();
2612cdf0e10cSrcweir 
2613cdf0e10cSrcweir     try
2614cdf0e10cSrcweir     {
2615cdf0e10cSrcweir         uno::Reference< XDocumentTemplates > xTemplates = getDocTemplates();
2616cdf0e10cSrcweir         DBG_ASSERT( xTemplates.is(), "SfxDocTemplate_Impl::Rescan:invalid template instance!" );
2617cdf0e10cSrcweir         if ( xTemplates.is() )
2618cdf0e10cSrcweir         {
2619cdf0e10cSrcweir             xTemplates->update();
2620cdf0e10cSrcweir 
2621cdf0e10cSrcweir             uno::Reference < XContent > aRootContent = xTemplates->getContent();
2622cdf0e10cSrcweir             uno::Reference < XCommandEnvironment > aCmdEnv;
2623cdf0e10cSrcweir 
2624cdf0e10cSrcweir             Content aTemplRoot( aRootContent, aCmdEnv );
2625cdf0e10cSrcweir             CreateFromHierarchy( aTemplRoot );
2626cdf0e10cSrcweir         }
2627cdf0e10cSrcweir     }
2628cdf0e10cSrcweir     catch( const Exception& )
2629cdf0e10cSrcweir     {
2630cdf0e10cSrcweir         DBG_ERRORFILE( "SfxDocTemplate_Impl::Rescan: caught an exception while doing the update!" );
2631cdf0e10cSrcweir     }
2632cdf0e10cSrcweir }
2633cdf0e10cSrcweir 
2634cdf0e10cSrcweir // -----------------------------------------------------------------------
GetTitleFromURL(const OUString & rURL,OUString & aTitle)2635cdf0e10cSrcweir sal_Bool SfxDocTemplate_Impl::GetTitleFromURL( const OUString& rURL,
2636cdf0e10cSrcweir                                            OUString& aTitle )
2637cdf0e10cSrcweir {
2638cdf0e10cSrcweir     if ( mxInfo.is() )
2639cdf0e10cSrcweir     {
2640cdf0e10cSrcweir         try
2641cdf0e10cSrcweir         {
2642cdf0e10cSrcweir             mxInfo->read( rURL );
2643cdf0e10cSrcweir         }
2644cdf0e10cSrcweir         catch ( Exception& )
2645cdf0e10cSrcweir         {
2646cdf0e10cSrcweir             // the document is not a StarOffice document
2647cdf0e10cSrcweir             return sal_False;
2648cdf0e10cSrcweir         }
2649cdf0e10cSrcweir 
2650cdf0e10cSrcweir 
2651cdf0e10cSrcweir         try
2652cdf0e10cSrcweir         {
2653cdf0e10cSrcweir             uno::Reference< XPropertySet > aPropSet( mxInfo, UNO_QUERY );
2654cdf0e10cSrcweir             if ( aPropSet.is() )
2655cdf0e10cSrcweir             {
2656cdf0e10cSrcweir                 OUString aPropName( RTL_CONSTASCII_USTRINGPARAM( TITLE ) );
2657cdf0e10cSrcweir                 Any aValue = aPropSet->getPropertyValue( aPropName );
2658cdf0e10cSrcweir                 aValue >>= aTitle;
2659cdf0e10cSrcweir             }
2660cdf0e10cSrcweir         }
2661cdf0e10cSrcweir         catch ( IOException& ) {}
2662cdf0e10cSrcweir         catch ( UnknownPropertyException& ) {}
2663cdf0e10cSrcweir         catch ( Exception& ) {}
2664cdf0e10cSrcweir     }
2665cdf0e10cSrcweir 
2666cdf0e10cSrcweir     if ( ! aTitle.getLength() )
2667cdf0e10cSrcweir     {
2668cdf0e10cSrcweir         INetURLObject aURL( rURL );
2669cdf0e10cSrcweir         aURL.CutExtension();
2670cdf0e10cSrcweir         aTitle = aURL.getName( INetURLObject::LAST_SEGMENT, true,
2671cdf0e10cSrcweir                                INetURLObject::DECODE_WITH_CHARSET );
2672cdf0e10cSrcweir     }
2673cdf0e10cSrcweir 
2674cdf0e10cSrcweir     return sal_True;
2675cdf0e10cSrcweir }
2676cdf0e10cSrcweir 
2677cdf0e10cSrcweir 
2678cdf0e10cSrcweir // -----------------------------------------------------------------------
Clear()2679cdf0e10cSrcweir void SfxDocTemplate_Impl::Clear()
2680cdf0e10cSrcweir {
2681cdf0e10cSrcweir     ::osl::MutexGuard   aGuard( maMutex );
2682cdf0e10cSrcweir     if ( mnLockCounter )
2683cdf0e10cSrcweir         return;
2684cdf0e10cSrcweir 
2685cdf0e10cSrcweir     RegionData_Impl *pRegData = maRegions.First();
2686cdf0e10cSrcweir 
2687cdf0e10cSrcweir     while ( pRegData )
2688cdf0e10cSrcweir     {
2689cdf0e10cSrcweir         delete pRegData;
2690cdf0e10cSrcweir         pRegData = maRegions.Next();
2691cdf0e10cSrcweir     }
2692cdf0e10cSrcweir 
2693cdf0e10cSrcweir     maRegions.Clear();
2694cdf0e10cSrcweir }
2695cdf0e10cSrcweir 
2696cdf0e10cSrcweir // -----------------------------------------------------------------------
2697cdf0e10cSrcweir // -----------------------------------------------------------------------
2698cdf0e10cSrcweir // -----------------------------------------------------------------------
getTextProperty_Impl(Content & rContent,const OUString & rPropName,OUString & rPropValue)2699cdf0e10cSrcweir sal_Bool getTextProperty_Impl( Content& rContent,
2700cdf0e10cSrcweir                                const OUString& rPropName,
2701cdf0e10cSrcweir                                OUString& rPropValue )
2702cdf0e10cSrcweir {
2703cdf0e10cSrcweir     sal_Bool bGotProperty = sal_False;
2704cdf0e10cSrcweir 
2705cdf0e10cSrcweir     // Get the property
2706cdf0e10cSrcweir     try
2707cdf0e10cSrcweir     {
2708cdf0e10cSrcweir         uno::Reference< XPropertySetInfo > aPropInfo = rContent.getProperties();
2709cdf0e10cSrcweir 
2710*940681c7SMatthias Seidel         // check, whether or not the property exists
2711cdf0e10cSrcweir         if ( !aPropInfo.is() || !aPropInfo->hasPropertyByName( rPropName ) )
2712cdf0e10cSrcweir         {
2713cdf0e10cSrcweir             return sal_False;
2714cdf0e10cSrcweir         }
2715cdf0e10cSrcweir 
2716cdf0e10cSrcweir         // now get the property
2717cdf0e10cSrcweir         Any aAnyValue;
2718cdf0e10cSrcweir 
2719cdf0e10cSrcweir         aAnyValue = rContent.getPropertyValue( rPropName );
2720cdf0e10cSrcweir         aAnyValue >>= rPropValue;
2721cdf0e10cSrcweir 
2722cdf0e10cSrcweir         if ( SfxURLRelocator_Impl::propertyCanContainOfficeDir( rPropName ) )
2723cdf0e10cSrcweir         {
2724cdf0e10cSrcweir             SfxURLRelocator_Impl aRelocImpl( ::comphelper::getProcessServiceFactory() );
2725cdf0e10cSrcweir             aRelocImpl.makeAbsoluteURL( rPropValue );
2726cdf0e10cSrcweir         }
2727cdf0e10cSrcweir 
2728cdf0e10cSrcweir         bGotProperty = sal_True;
2729cdf0e10cSrcweir     }
2730cdf0e10cSrcweir     catch ( RuntimeException& ) {}
2731cdf0e10cSrcweir     catch ( Exception& ) {}
2732cdf0e10cSrcweir 
2733cdf0e10cSrcweir     return bGotProperty;
2734cdf0e10cSrcweir }
2735cdf0e10cSrcweir 
2736