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