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