2000-09-18 16:07:07 +00:00
/*************************************************************************
*
* $ RCSfile : doctempl . cxx , v $
*
2000-12-08 10:35:44 +00:00
* $ Revision : 1.16 $
2000-09-18 16:07:07 +00:00
*
2000-12-08 10:35:44 +00:00
* last change : $ Author : dv $ $ Date : 2000 - 12 - 08 11 : 35 : 44 $
2000-09-18 16:07:07 +00:00
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
*
* - GNU Lesser General Public License Version 2.1
* - Sun Industry Standards Source License Version 1.1
*
* Sun Microsystems Inc . , October , 2000
*
* GNU Lesser General Public License Version 2.1
* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
* Copyright 2000 by Sun Microsystems , Inc .
* 901 San Antonio Road , Palo Alto , CA 94303 , USA
*
* This library is free software ; you can redistribute it and / or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1 , as published by the Free Software Foundation .
*
* This library is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the GNU
* Lesser General Public License for more details .
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library ; if not , write to the Free Software
* Foundation , Inc . , 59 Temple Place , Suite 330 , Boston ,
* MA 02111 - 1307 USA
*
*
* Sun Industry Standards Source License Version 1.1
* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.1 ( the " License " ) ; You may not use this file
* except in compliance with the License . You may obtain a copy of the
* License at http : //www.openoffice.org/license.html.
*
* Software provided under this License is provided on an " AS IS " basis ,
* WITHOUT WARRANTY OF ANY KIND , EITHER EXPRESSED OR IMPLIED , INCLUDING ,
* WITHOUT LIMITATION , WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS ,
* MERCHANTABLE , FIT FOR A PARTICULAR PURPOSE , OR NON - INFRINGING .
* See the License for the specific provisions governing your rights and
* obligations concerning the Software .
*
* The Initial Developer of the Original Code is : Sun Microsystems , Inc .
*
* Copyright : 2000 by Sun Microsystems , Inc .
*
* All Rights Reserved .
*
* Contributor ( s ) : _______________________________________
*
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# include <limits.h>
# ifndef _COM_SUN_STAR_UNO_ANY_H_
# include <com/sun/star/uno/Any.h>
# endif
2000-12-06 10:14:36 +00:00
# ifndef _VOS_THREAD_HXX_
# include <vos/thread.hxx>
# endif
2000-12-01 10:03:15 +00:00
# ifndef _SV_RESARY_HXX
# include <vcl/resary.hxx>
2000-09-18 16:07:07 +00:00
# endif
2000-11-27 07:55:57 +00:00
# ifndef INCLUDED_SVTOOLS_PATHOPTIONS_HXX
2000-11-08 13:25:58 +00:00
# include <svtools/pathoptions.hxx>
2000-11-27 07:55:57 +00:00
# endif
# include <tools/string.hxx>
# ifndef _URLOBJ_HXX
# include <tools/urlobj.hxx>
# endif
2000-12-08 10:35:44 +00:00
# ifndef _EHDL_HXX
# include <svtools/ehdl.hxx>
# endif
# ifndef _SFXECODE_HXX
# include <svtools/sfxecode.hxx>
# endif
2000-11-30 15:43:40 +00:00
# ifndef _COMPHELPER_PROCESSFACTORY_HXX_
# include <comphelper/processfactory.hxx>
# endif
2000-11-27 07:55:57 +00:00
# include <ucbhelper/content.hxx>
# include <com/sun/star/uno/Reference.h>
# ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HPP_
# include <com/sun/star/beans/PropertyAttribute.hpp>
# endif
2000-11-30 15:43:40 +00:00
# ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HDL_
# include <com/sun/star/beans/PropertyValue.hdl>
# endif
2000-11-27 07:55:57 +00:00
# ifndef _COM_SUN_STAR_BEANS_XPROPERTYCONTAINER_HPP_
# include <com/sun/star/beans/XPropertyContainer.hpp>
# endif
2000-11-30 15:43:40 +00:00
# ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
# include <com/sun/star/beans/XPropertySet.hpp>
# endif
2000-11-27 07:55:57 +00:00
# ifndef _COM_SUN_STAR_BEANS_XPROPERTYSETINFO_HPP_
# include <com/sun/star/beans/XPropertySetInfo.hpp>
# endif
2000-11-30 15:43:40 +00:00
# ifdef TF_FILTER
# ifndef _COM_SUN_STAR_DOCUMENT_XTYPEDETECTION_HPP_
# include <com/sun/star/document/XTypeDetection.hpp>
# endif
# else
# ifndef _COM_SUN_STAR_FRAME_XFRAMELOADERQUERY_HPP_
# include <com/sun/star/frame/XFrameLoaderQuery.hpp>
# endif
# endif
2000-11-27 07:55:57 +00:00
# ifndef _COM_SUN_STAR_IO_XINPUTSTREAM_HPP_
# include <com/sun/star/io/XInputStream.hpp>
# endif
# ifndef _COM_SUN_STAR_SDBC_XRESULTSET_HPP_
# include <com/sun/star/sdbc/XResultSet.hpp>
# endif
# ifndef _COM_SUN_STAR_SDBC_XROW_HPP_
# include <com/sun/star/sdbc/XRow.hpp>
# endif
# ifndef _COM_SUN_STAR_UCB_CONTENTINFO_HPP_
# include <com/sun/star/ucb/ContentInfo.hpp>
# endif
2000-11-30 15:43:40 +00:00
# ifndef _COM_SUN_STAR_DOCUMENT_XSTANDALONEDOCUMENTINFO_HPP_
# include <com/sun/star/document/XStandaloneDocumentInfo.hpp>
# endif
2000-11-27 07:55:57 +00:00
# ifndef _COM_SUN_STAR_UCB_INSERTCOMMANDARGUMENT_HPP_
# include <com/sun/star/ucb/InsertCommandArgument.hpp>
# endif
# ifndef _COM_SUN_STAR_UCB_NAMECLASH_HPP_
# include <com/sun/star/ucb/NameClash.hpp>
# endif
# ifndef _COM_SUN_STAR_UCB_TRANSFERINFO_HPP_
# include <com/sun/star/ucb/TransferInfo.hpp>
# endif
# ifndef _COM_SUN_STAR_UCB_XCOMMANDPROCESSOR_HPP_
# include <com/sun/star/ucb/XCommandProcessor.hpp>
# endif
# ifndef _COM_SUN_STAR_UCB_XCONTENT_HPP_
# include <com/sun/star/ucb/XContent.hpp>
# endif
# ifndef _COM_SUN_STAR_UCB_XCONTENTCREATOR_HPP_
# include <com/sun/star/ucb/XContentCreator.hpp>
# endif
# ifndef _COM_SUN_STAR_UCB_XCONTENTACCESS_HPP_
# include <com/sun/star/ucb/XContentAccess.hpp>
# endif
using namespace : : com : : sun : : star : : beans ;
2000-11-30 15:43:40 +00:00
using namespace : : com : : sun : : star : : document ;
using namespace : : com : : sun : : star : : frame ;
2000-11-27 07:55:57 +00:00
using namespace : : com : : sun : : star : : io ;
using namespace : : com : : sun : : star : : lang ;
using namespace : : com : : sun : : star : : sdbc ;
using namespace : : com : : sun : : star : : uno ;
using namespace : : com : : sun : : star : : ucb ;
using namespace rtl ;
using namespace ucb ;
2000-09-18 16:07:07 +00:00
# include "doctempl.hxx"
# include "docfac.hxx"
# include "docfile.hxx"
# include "objsh.hxx"
# include "sfxtypes.hxx"
# include "app.hxx"
# include "sfxresid.hxx"
# include "doc.hrc"
2000-12-08 10:35:44 +00:00
# include "fcontnr.hxx"
2000-09-18 16:07:07 +00:00
//========================================================================
2000-11-27 07:55:57 +00:00
# define HIERARCHIE_ROOT_URL "vnd.sun.star.hier: / "
# define TEMPLATE_ROOT_URL "vnd.sun.star.hier: / templates"
# define TEMPLATE_DIR_NAME "templates"
# define TITLE "Title"
# define IS_FOLDER "IsFolder"
2000-12-07 09:12:29 +00:00
# define PROPERTY_TYPE "TypeDescription"
2000-11-27 07:55:57 +00:00
# define TARGET_URL "TargetURL"
# define TYPE_FOLDER "application / vnd.sun.star.hier-folder"
# define TYPE_LINK "application / vnd.sun.star.hier-link"
# define TYPE_FSYS_FOLDER "application / vnd.sun.staroffice.fsys-folder"
# define TARGET_DIR_URL "TargetDirURL"
# define COMMAND_DELETE "delete"
# define COMMAND_TRANSFER "transfer"
2000-12-06 10:14:36 +00:00
# define STANDARD_FOLDER "standard"
2000-11-30 15:43:40 +00:00
# define SERVICENAME_TYPEDETECTION "com.sun.star.document.TypeDetection"
# define TYPEDETECTION_PARAMETER "FileName"
# define SERVICENAME_OLD_TYPEDETECTION "com.sun.star.frame.FrameLoaderFactory"
# define PARAMETER_OLD_TYPEDETECTION "DeepDetection"
# define SERVICENAME_DOCINFO "com.sun.star.document.StandaloneDocumentInfo"
2000-11-27 07:55:57 +00:00
# define C_DELIM ';'
//========================================================================
class EntryData_Impl
{
2000-12-08 10:35:44 +00:00
SfxObjectShellLock mxObjShell ;
SvStorageRef mxStor ;
2000-11-27 07:55:57 +00:00
OUString maTitle ;
OUString maOwnURL ;
OUString maTargetURL ;
2000-12-07 09:12:29 +00:00
sal_Bool mbInUse : 1 ;
sal_Bool mbNew : 1 ;
2000-12-08 10:35:44 +00:00
sal_Bool mbIsOwner : 1 ;
sal_Bool mbDidConvert : 1 ;
2000-11-27 07:55:57 +00:00
public :
EntryData_Impl ( const OUString & rTitle ) ;
const OUString & GetTitle ( ) const { return maTitle ; }
const OUString & GetTargetURL ( ) const { return maTargetURL ; }
const OUString & GetHierarchyURL ( ) const { return maOwnURL ; }
void SetTitle ( const OUString & rTitle ) { maTitle = rTitle ; }
void SetTargetURL ( const OUString & rTargetURL ) ;
void SetHierarchyURL ( const OUString & rURL ) { maOwnURL = rURL ; }
int Compare ( const OUString & rTitle ) const ;
2000-11-30 15:43:40 +00:00
void SetType ( const OUString & rType ) ;
2000-12-07 09:12:29 +00:00
void ResetFlags ( ) { mbInUse = sal_False ; mbNew = sal_False ; }
void RemoveEntry ( ) ;
void SetInUse ( sal_Bool bInUse ) { mbInUse = bInUse ; }
sal_Bool IsInUse ( ) const { return mbInUse ; }
sal_Bool IsNew ( ) const { return mbNew ; }
2000-12-08 10:35:44 +00:00
SfxObjectShellRef CreateObjectShell ( ) ;
BOOL DeleteObjectShell ( ) ;
2000-11-27 07:55:57 +00:00
} ;
DECLARE_LIST ( EntryList_Impl , EntryData_Impl * ) ;
// ------------------------------------------------------------------------
class RegionData_Impl
{
EntryList_Impl maEntries ;
OUString maTitle ;
OUString maOwnURL ;
OUString maTargetURL ;
Content maTargetContent ;
Content maHierarchyContent ;
2000-12-07 09:12:29 +00:00
sal_Bool mbInUse : 1 ;
sal_Bool mbNew : 1 ;
2000-11-27 07:55:57 +00:00
private :
long GetEntryPos ( const OUString & rTitle ,
sal_Bool & rFound ) const ;
public :
2000-12-07 09:12:29 +00:00
RegionData_Impl ( const OUString & rTitle ) ;
2000-11-27 07:55:57 +00:00
~ RegionData_Impl ( ) ;
2000-11-28 11:58:03 +00:00
EntryData_Impl * GetEntry ( ULONG nIndex ) const ;
2000-12-07 16:01:23 +00:00
EntryData_Impl * GetEntry ( const OUString & rName ) const ;
EntryData_Impl * GetByTargetURL ( const OUString & rName ) const ;
2000-11-27 07:55:57 +00:00
const OUString & GetTitle ( ) const { return maTitle ; }
const OUString & GetTargetURL ( ) const { return maTargetURL ; }
const OUString & GetHierarchyURL ( ) const { return maOwnURL ; }
2000-11-28 11:58:03 +00:00
ULONG GetCount ( ) const ;
2000-11-27 07:55:57 +00:00
void SetTitle ( const OUString & rTitle ) { maTitle = rTitle ; }
void SetTargetURL ( const OUString & rTargetURL ) ;
void SetHierarchyURL ( const OUString & rURL ) { maOwnURL = rURL ; }
void SetTargetContent ( const Content & rTarget ) { maTargetContent = rTarget ; }
void SetHierarchyContent ( const Content & rContent ) { maHierarchyContent = rContent ; }
2000-11-30 15:43:40 +00:00
EntryData_Impl * AddEntry ( Content & rParentFolder ,
2000-11-27 07:55:57 +00:00
const OUString & rTitle ,
const OUString & rTargetURL ) ;
2000-11-28 11:58:03 +00:00
void DeleteEntry ( ULONG nIndex ) ;
2000-11-27 07:55:57 +00:00
int Compare ( const OUString & rTitle ) const
{ return maTitle . compareTo ( rTitle ) ; }
2000-12-06 10:14:36 +00:00
int Compare ( RegionData_Impl * pCompareWith ) const ;
2000-12-07 09:12:29 +00:00
void ResetFlags ( ) ;
void RemoveUnused ( ) ;
void RemoveRegion ( ) ;
void SetInUse ( sal_Bool bInUse ) { mbInUse = bInUse ; }
sal_Bool IsInUse ( ) const { return mbInUse ; }
2000-11-27 07:55:57 +00:00
} ;
DECLARE_LIST ( RegionList_Impl , RegionData_Impl * ) ;
2000-12-01 10:03:15 +00:00
struct NamePair_Impl
{
OUString maShortName ;
OUString maLongName ;
} ;
DECLARE_LIST ( NameList_Impl , NamePair_Impl * ) ;
2000-11-27 07:55:57 +00:00
// ------------------------------------------------------------------------
2000-12-04 09:32:11 +00:00
class SfxDocTemplate_Impl : public SvRefBase
2000-11-27 07:55:57 +00:00
{
2000-11-30 15:43:40 +00:00
Reference < XMultiServiceFactory > mxFactory ;
2000-11-27 07:55:57 +00:00
: : osl : : Mutex maMutex ;
String maDirs ;
RegionList_Impl maRegions ;
2000-12-01 10:03:15 +00:00
NameList_Impl maNames ;
2000-12-06 10:14:36 +00:00
sal_Bool mbConstructed : 1 ;
sal_Bool mbUpdating : 1 ;
2000-11-27 07:55:57 +00:00
private :
sal_Bool InsertOrMarkRegion ( RegionData_Impl * pData ) ;
2000-12-01 10:03:15 +00:00
void ReadFolderList ( ) ;
OUString GetLongName ( const OUString & rShortName ) ;
2000-11-27 07:55:57 +00:00
public :
SfxDocTemplate_Impl ( ) ;
~ SfxDocTemplate_Impl ( ) ;
void Construct ( const String & rDirURLs ) ;
2000-12-06 10:14:36 +00:00
sal_Bool Rescan ( sal_Bool bNow ) ;
2000-11-27 07:55:57 +00:00
void CreateFromHierarchy ( Content & rTemplRoot ) ;
void AddRegion ( const OUString & rTitle ,
const OUString & rTargetURL ,
Content & rContent ) ;
2000-11-28 11:58:03 +00:00
void DeleteRegion ( ULONG nIndex ) ;
2000-11-27 07:55:57 +00:00
2000-11-28 11:58:03 +00:00
ULONG GetRegionCount ( ) const
2000-11-27 07:55:57 +00:00
{ return maRegions . Count ( ) ; }
RegionData_Impl * GetRegion ( const OUString & rName ) const ;
2000-11-28 11:58:03 +00:00
RegionData_Impl * GetRegion ( ULONG nIndex ) const ;
2000-11-27 07:55:57 +00:00
RegionData_Impl * GetRegionByPath ( const String & rPath ) const ;
2000-12-07 09:12:29 +00:00
void GetFolders ( Content & rRoot , Content & rFolder ) ;
2000-11-27 07:55:57 +00:00
void GetTemplates ( Content & rTargetFolder ,
Content & rParentFolder ,
2000-12-07 09:12:29 +00:00
RegionData_Impl * pRegion ) ;
2000-11-27 07:55:57 +00:00
long GetRegionPos ( const OUString & rTitle ,
sal_Bool & rFound ) const ;
sal_Bool GetTemplateRoot ( Content & rTemplRoot , sal_Bool & rNew ) const ;
sal_Bool GetTemplateDir ( USHORT nIndex , Content & rTemplateDir ) const ;
sal_Bool InsertNewRegionToHierarchy (
Content & rRoot ,
const OUString & rTitle ,
const OUString & rTargetURL ,
USHORT nIndex ) ;
sal_Bool InsertNewRegionToFolder (
Content & rRoot ,
const OUString & rTitle ) ;
2000-11-30 15:43:40 +00:00
OUString GetTypeFromURL ( const OUString & rURL ) ;
OUString GetTitleFromURL ( const OUString & rURL ) ;
2000-12-06 10:14:36 +00:00
void AddToStandard ( Content & rRoot ,
Content & rFolder ) ;
2000-12-07 09:12:29 +00:00
sal_Bool DoUpdate ( ) ;
2000-11-27 07:55:57 +00:00
} ;
SfxDocTemplate_Impl * gpTemplateData = 0 ;
String gaEmptyString ;
2000-12-04 09:32:11 +00:00
# ifndef SFX_DECL_DOCTEMPLATES_DEFINED
# define SFX_DECL_DOCTEMPLATES_DEFINED
SV_DECL_REF ( SfxDocTemplate_Impl )
# endif
SV_IMPL_REF ( SfxDocTemplate_Impl )
2000-12-06 10:14:36 +00:00
//------------------------------------------------------------------------
class Updater_Impl : public : : vos : : OThread
{
private :
SfxDocTemplate_ImplRef maDocTemplates ;
public :
Updater_Impl ( SfxDocTemplate_Impl * pTemplates ) ;
~ Updater_Impl ( ) ;
virtual void SAL_CALL run ( ) ;
virtual void SAL_CALL onTerminated ( ) ;
} ;
2000-09-18 16:07:07 +00:00
//------------------------------------------------------------------------
class OpenNotifier_Impl : public SfxListener
{
BOOL bEnd ;
//(dv) CntAnchorRef xAnchor;
//(dv) CntOpenMode eMode;
public :
OpenNotifier_Impl ( /*(dv)const CntAnchorRef& rAnchor, CntOpenMode eOpenMode */ )
: bEnd ( FALSE )
//(dv) , xAnchor( rAnchor )
//(dv) , eMode( eOpenMode )
{
#if 0 //(dv)
StartListening ( * xAnchor ) ;
xAnchor - > Put ( SfxVoidItem ( WID_GETDATA ) ) ;
xAnchor - > MakeVisible ( TRUE ) ;
xAnchor - > MarkAsRoot ( ) ;
xAnchor - > DontThread ( ) ;
xAnchor - > Put ( CntOpenModeItem ( WID_OPEN , eMode ) ) ;
# endif //(dv)
}
virtual void Notify ( SfxBroadcaster & , const SfxHint & ) ;
BOOL IsComplete ( ) const
{ return bEnd ; }
} ;
void OpenNotifier_Impl : : Notify ( SfxBroadcaster & rBC , const SfxHint & rHint )
{
#if 0 //(dv)
if ( rHint . ISA ( CntStatusHint ) )
{
const CntStatusHint & rStatusHint = ( const CntStatusHint & ) rHint ;
USHORT nWhich = rStatusHint . GetRequest ( ) ? rStatusHint . GetRequest ( ) - > Which ( ) : 0 ;
const CntStatus eStatus = rStatusHint . GetStatus ( ) ;
if ( nWhich = = WID_OPEN & & ( eStatus = = CNT_STATUS_DONE | | eStatus = = CNT_STATUS_ERROR ) )
{
bEnd = TRUE ;
EndListening ( * xAnchor ) ;
}
}
# endif //(dv)
}
2000-11-27 07:55:57 +00:00
//========================================================================
//========================================================================
//========================================================================
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
String SfxDocumentTemplates : : GetFullRegionName
(
USHORT nIdx // Index des Bereiches
) const
2000-09-18 16:07:07 +00:00
/* [Beschreibung]
2000-11-27 07:55:57 +00:00
Liefert den logischen Namen eines Bereiches Plus seinem Pfad
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
[ R " uckgabewert] Referenz auf diesen Namen
2000-09-18 16:07:07 +00:00
*/
{
2000-11-27 07:55:57 +00:00
DBG_ASSERT ( pImp , " not initialized " ) ;
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
// First: find the RegionData for the index
String aName ;
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
RegionData_Impl * pData1 = pImp - > GetRegion ( nIdx ) ;
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
if ( pData1 )
2000-12-07 09:12:29 +00:00
aName = pData1 - > GetTitle ( ) ;
2000-11-27 07:55:57 +00:00
/* Second: check if there is another region with the same name.
If there is one , append the path to the region name so it is
distinguishable from the other ones
*/
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
OUString aCompareMe ( aName ) ;
2000-11-28 11:58:03 +00:00
ULONG nCount = pImp - > GetRegionCount ( ) ;
ULONG nIndex = 0 ;
2000-11-27 07:55:57 +00:00
RegionData_Impl * pData2 ;
for ( nIndex = 0 ; nIndex < nCount ; nIndex + + )
2000-09-18 16:07:07 +00:00
{
2000-11-27 07:55:57 +00:00
pData2 = pImp - > GetRegion ( nIndex ) ;
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
if ( ( nIndex ! = nIdx ) & &
2000-12-07 09:12:29 +00:00
( pData2 - > GetTitle ( ) = = aCompareMe ) )
2000-09-18 16:07:07 +00:00
{
2000-11-27 07:55:57 +00:00
INetURLObject aURLObj ( pData2 - > GetTargetURL ( ) ) ;
aURLObj . removeSegment ( ) ;
String aParent = aURLObj . getExternalURL ( ) ;
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
//dv! we should truncate the Parent string ( to a lenght of 10? )
aName + = DEFINE_CONST_UNICODE ( " ( " ) ;
aName + = aParent ;
aName + = DEFINE_CONST_UNICODE ( " ) " ) ;
break ;
}
2000-09-18 16:07:07 +00:00
}
2000-11-27 07:55:57 +00:00
return aName ;
2000-09-18 16:07:07 +00:00
}
//------------------------------------------------------------------------
2000-11-27 07:55:57 +00:00
const String & SfxDocumentTemplates : : GetRegionName
(
USHORT nIdx // Index des Bereiches
) const
2000-09-18 16:07:07 +00:00
/* [Beschreibung]
2000-11-27 07:55:57 +00:00
Liefert den logischen Namen eines Bereiches
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
[ R " uckgabewert]
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
const String & Referenz auf diesen Namen
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
*/
{
static String maTmpString ;
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
RegionData_Impl * pData = pImp - > GetRegion ( nIdx ) ;
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
if ( pData )
2000-12-07 09:12:29 +00:00
maTmpString = pData - > GetTitle ( ) ;
2000-11-27 07:55:57 +00:00
else
maTmpString . Erase ( ) ;
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
return maTmpString ;
2000-09-18 16:07:07 +00:00
}
2000-11-27 07:55:57 +00:00
2000-09-18 16:07:07 +00:00
//------------------------------------------------------------------------
2000-11-27 07:55:57 +00:00
USHORT SfxDocumentTemplates : : GetRegionNo
(
const String & rRegion // Name der Region
) const
2000-09-18 16:07:07 +00:00
/* [Beschreibung]
2000-11-27 07:55:57 +00:00
Liefert den Index f " ur einen logischen Namen eines Bereiches.
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
[ R " uckgabewert]
USHORT Index von ' rRegion ' oder USHRT_MAX falls unbekannt
*/
2000-09-18 16:07:07 +00:00
{
2000-11-27 07:55:57 +00:00
sal_Bool bFound ;
2000-11-28 11:58:03 +00:00
ULONG nIndex = pImp - > GetRegionPos ( rRegion , bFound ) ;
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
if ( bFound )
2000-11-28 11:58:03 +00:00
return ( USHORT ) nIndex ;
2000-11-27 07:55:57 +00:00
else
return USHRT_MAX ;
}
2000-09-18 16:07:07 +00:00
//------------------------------------------------------------------------
2000-11-27 07:55:57 +00:00
USHORT SfxDocumentTemplates : : GetRegionCount ( ) const
2000-09-18 16:07:07 +00:00
/* [Beschreibung]
2000-11-27 07:55:57 +00:00
Liefert die Anzahl der Bereiche
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
[ R " uckgabewert]
USHORT Anzahl der Bereiche
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
*/
2000-09-18 16:07:07 +00:00
{
2000-11-28 11:58:03 +00:00
ULONG nCount = 0 ;
2000-11-27 07:55:57 +00:00
if ( pImp )
nCount = pImp - > GetRegionCount ( ) ;
2000-11-28 11:58:03 +00:00
return ( USHORT ) nCount ;
2000-09-18 16:07:07 +00:00
}
//------------------------------------------------------------------------
2000-11-27 07:55:57 +00:00
USHORT SfxDocumentTemplates : : GetCount
2000-09-18 16:07:07 +00:00
(
2000-11-27 07:55:57 +00:00
const String & rName /* Name des Bereiches, dessen Eintrags-
anzahl ermittelt werden soll */
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
) const
2000-09-18 16:07:07 +00:00
/* [Beschreibung]
2000-11-27 07:55:57 +00:00
Liefert die Anzahl der Eintr " age eines Bereiches
2000-09-18 16:07:07 +00:00
[ R " uckgabewert]
2000-11-27 07:55:57 +00:00
USHORT Anzahl der Eintr " age
2000-09-18 16:07:07 +00:00
*/
{
2000-11-27 07:55:57 +00:00
DBG_ASSERT ( pImp , " not initialized " ) ;
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
RegionData_Impl * pData = pImp - > GetRegion ( rName ) ;
2000-11-28 11:58:03 +00:00
ULONG nCount = 0 ;
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
if ( pData )
nCount = pData - > GetCount ( ) ;
2000-09-18 16:07:07 +00:00
2000-11-28 11:58:03 +00:00
return ( USHORT ) nCount ;
2000-11-27 07:55:57 +00:00
}
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
//------------------------------------------------------------------------
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
BOOL SfxDocumentTemplates : : IsRegionLoaded ( USHORT nIdx ) const
2000-09-18 16:07:07 +00:00
{
2000-11-27 07:55:57 +00:00
RegionData_Impl * pData = pImp - > GetRegion ( nIdx ) ;
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
if ( pData )
return TRUE ;
2000-09-18 16:07:07 +00:00
else
2000-11-27 07:55:57 +00:00
return FALSE ;
2000-09-18 16:07:07 +00:00
}
//------------------------------------------------------------------------
2000-11-27 07:55:57 +00:00
USHORT SfxDocumentTemplates : : GetCount
2000-09-18 16:07:07 +00:00
(
2000-11-27 07:55:57 +00:00
USHORT nRegion /* Index des Bereiches, dessen Eintrags-
anzahl ermittelt werden soll */
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
) const
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
/* [Beschreibung]
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
Liefert die Anzahl der Eintr " age eines Bereiches
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
[ R " uckgabewert] Anzahl der Eintr " age
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
*/
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
{
DBG_ASSERT ( pImp , " not initialized " ) ;
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
RegionData_Impl * pData = pImp - > GetRegion ( nRegion ) ;
2000-11-28 11:58:03 +00:00
ULONG nCount = 0 ;
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
if ( pData )
nCount = pData - > GetCount ( ) ;
2000-09-18 16:07:07 +00:00
2000-11-28 11:58:03 +00:00
return ( USHORT ) nCount ;
2000-09-18 16:07:07 +00:00
}
//------------------------------------------------------------------------
2000-11-27 07:55:57 +00:00
const String & SfxDocumentTemplates : : GetName
(
USHORT nRegion , // Index des Bereiches, in dem der Eintrag liegt
USHORT nIdx // Index des Eintrags
) const
2000-09-18 16:07:07 +00:00
/* [Beschreibung]
2000-11-27 07:55:57 +00:00
Liefert den logischen Namen eines Eintrags eines Bereiches
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
[ R " uckgabewert]
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
const String & Name des Eintrags
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
*/
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
{
DBG_ASSERT ( pImp , " not initialized " ) ;
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
static String maTmpString ;
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
EntryData_Impl * pEntry = NULL ;
RegionData_Impl * pRegion = pImp - > GetRegion ( nRegion ) ;
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
if ( pRegion )
pEntry = pRegion - > GetEntry ( nIdx ) ;
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
if ( pEntry )
maTmpString = pEntry - > GetTitle ( ) ;
else
maTmpString . Erase ( ) ;
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
return maTmpString ;
2000-09-18 16:07:07 +00:00
}
//------------------------------------------------------------------------
2000-11-27 07:55:57 +00:00
String SfxDocumentTemplates : : GetFileName
2000-09-18 16:07:07 +00:00
(
2000-11-27 07:55:57 +00:00
USHORT nRegion , // Index des Bereiches, in dem der Eintrag liegt
USHORT nIdx // Index des Eintrags
) const
2000-09-18 16:07:07 +00:00
/* [Beschreibung]
2000-11-27 07:55:57 +00:00
Liefert den Dateinamen eines Eintrags eines Bereiches
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
[ R " uckgabewert] Dateiname des Eintrags
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
*/
{
DBG_ASSERT ( pImp , " not initialized " ) ;
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
EntryData_Impl * pEntry = NULL ;
RegionData_Impl * pRegion = pImp - > GetRegion ( nRegion ) ;
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
if ( pRegion )
pEntry = pRegion - > GetEntry ( nIdx ) ;
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
if ( pEntry )
2000-09-18 16:07:07 +00:00
{
2000-11-27 07:55:57 +00:00
INetURLObject aURLObj ( pEntry - > GetTargetURL ( ) ) ;
return aURLObj . GetName ( ) ;
2000-09-18 16:07:07 +00:00
}
2000-11-27 07:55:57 +00:00
else
return String ( ) ;
2000-09-18 16:07:07 +00:00
}
//------------------------------------------------------------------------
2000-11-27 07:55:57 +00:00
String SfxDocumentTemplates : : GetPath
2000-09-18 16:07:07 +00:00
(
2000-11-27 07:55:57 +00:00
USHORT nRegion , // Index des Bereiches, in dem der Eintrag liegt
USHORT nIdx // Index des Eintrags
2000-09-18 16:07:07 +00:00
) const
/* [Beschreibung]
2000-11-27 07:55:57 +00:00
Liefert den Dateinamen mit vollst " andigem Pfad zu der einem
Eintrag zugeordneten Datei
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
[ R " uckgabewert]
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
String Dateiname mit vollst " andigem Pfad
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
*/
2000-09-18 16:07:07 +00:00
{
2000-11-27 07:55:57 +00:00
DBG_ASSERT ( pImp , " not initialized " ) ;
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
EntryData_Impl * pEntry = NULL ;
RegionData_Impl * pRegion = pImp - > GetRegion ( nRegion ) ;
if ( pRegion )
pEntry = pRegion - > GetEntry ( nIdx ) ;
if ( pEntry )
return pEntry - > GetTargetURL ( ) ;
else
return String ( ) ;
2000-09-18 16:07:07 +00:00
}
//------------------------------------------------------------------------
2000-11-27 07:55:57 +00:00
String SfxDocumentTemplates : : GetTemplatePath
2000-09-18 16:07:07 +00:00
(
2000-11-27 07:55:57 +00:00
USHORT nRegion , // Index des Bereiches, in dem der Eintrag liegt
const String & rLongName // logischer Name des Eintrags
2000-09-18 16:07:07 +00:00
) const
/* [Beschreibung]
2000-11-27 07:55:57 +00:00
Liefert den Dateinamen mit vollst " andigem Pfad zu der einem
Eintrag zugeordneten Datei
2000-09-18 16:07:07 +00:00
[ R " uckgabewert]
2000-11-27 07:55:57 +00:00
String Dateiname mit vollst " andigem Pfad
2000-09-18 16:07:07 +00:00
*/
{
2000-11-27 07:55:57 +00:00
DBG_ASSERT ( pImp , " not initialized " ) ;
EntryData_Impl * pEntry = NULL ;
RegionData_Impl * pRegion = pImp - > GetRegion ( nRegion ) ;
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
if ( pRegion )
pEntry = pRegion - > GetEntry ( rLongName ) ;
if ( pEntry )
return pEntry - > GetTargetURL ( ) ;
else if ( pRegion )
{
INetURLObject aURLObj ( pRegion - > GetTargetURL ( ) ) ;
aURLObj . insertName ( rLongName ) ;
return aURLObj . getExternalURL ( ) ;
}
else
return String ( ) ;
}
2000-09-18 16:07:07 +00:00
//------------------------------------------------------------------------
2000-11-27 07:55:57 +00:00
String SfxDocumentTemplates : : GetDefaultTemplatePath
2000-09-18 16:07:07 +00:00
(
2000-11-27 07:55:57 +00:00
const String & rLongName
)
2000-09-18 16:07:07 +00:00
/* [Beschreibung]
2000-11-27 07:55:57 +00:00
Liefert den Standardpfad zu Dokumentvorlagen
2000-09-18 16:07:07 +00:00
[ R " uckgabewert]
2000-11-27 07:55:57 +00:00
String Standardpfad zu Dokumentvorlagen
2000-09-18 16:07:07 +00:00
*/
{
2000-11-27 07:55:57 +00:00
DBG_ASSERT ( pImp , " not initialized " ) ;
DBG_ASSERT ( aDirs . GetTokenCount ( cDelim ) , " Keine Bereiche " ) ;
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
String aPath ( aDirs . GetToken ( 0 , cDelim ) ) ;
EntryData_Impl * pEntry = NULL ;
RegionData_Impl * pRegion = pImp - > GetRegion ( aPath ) ;
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
if ( pRegion )
pEntry = pRegion - > GetEntry ( rLongName ) ;
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
if ( pEntry )
return pEntry - > GetTargetURL ( ) ;
else if ( pRegion )
{
INetURLObject aURLObj ( pRegion - > GetTargetURL ( ) ) ;
aURLObj . insertName ( rLongName ) ;
return aURLObj . getExternalURL ( ) ;
}
else
return String ( ) ;
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
/* dv! missing: create the directory, if it doesn't exists
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
DBG_ASSERT ( aDirs . GetTokenCount ( cDelim ) , " Keine Bereiche " ) ;
DirEntry aPath ( aDirs . GetToken ( 0 , cDelim ) ) ;
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
// Verzeichnis anlegen
if ( ! aPath . MakeDir ( ) )
return String ( ) ;
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
MakeFileName_Impl ( aPath , rLongName , TRUE ) ;
SfxTemplateDir * pEntry = new SfxTemplateDir ;
SfxTemplateDirEntryPtr pDirEntry =
new SfxTemplateDirEntry ( String ( ' . ' ) , aPath . GetPath ( ) ) ;
pDirEntry - > SetContent ( new SfxTemplateDir ( aPath . GetPath ( ) ) ) ;
pEntry - > Insert ( pDirEntry , pEntry - > Count ( ) ) ;
pDirs - > Insert ( pEntry , pDirs - > Count ( ) ) ;
return aPath . GetFull ( ) ;
2000-09-18 16:07:07 +00:00
*/
}
//------------------------------------------------------------------------
2000-11-27 07:55:57 +00:00
BOOL SfxDocumentTemplates : : SaveDir
2000-09-18 16:07:07 +00:00
(
2000-11-27 07:55:57 +00:00
// SfxTemplateDir& rDir // das zu speichernde Directory
)
2000-09-18 16:07:07 +00:00
/* [Beschreibung]
2000-11-27 07:55:57 +00:00
Speichert das Directory rDir
2000-09-18 16:07:07 +00:00
[ R " uckgabewert]
2000-11-27 07:55:57 +00:00
BOOL FALSE ,
Schreibfehler
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
TRUE
gespeichert
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
*/
2000-09-18 16:07:07 +00:00
{
2000-11-27 07:55:57 +00:00
return TRUE ;
2000-09-18 16:07:07 +00:00
}
//------------------------------------------------------------------------
2000-11-27 07:55:57 +00:00
void SfxDocumentTemplates : : NewTemplate
2000-09-18 16:07:07 +00:00
(
2000-11-27 07:55:57 +00:00
USHORT nRegion , /* Index des Bereiches, in dem die Vorlage
angelegt werden soll */
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
const String & rLongName , // logischer Name der neuen Vorlage
const String & rFileName // Dateiname der neuen Vorlage
)
2000-09-18 16:07:07 +00:00
/* [Beschreibung]
2000-11-27 07:55:57 +00:00
Eintragen einer neuen Dokumentvorlage in die Verwaltungsstrukturen
Das " Uberschreiben einer Vorlage gleichen Namens wird
verhindert ( ! ! Fehlermeldung )
2000-09-18 16:07:07 +00:00
*/
{
2000-11-27 07:55:57 +00:00
DBG_ASSERT ( pImp , " not initialized " ) ;
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
EntryData_Impl * pEntry ;
RegionData_Impl * pRegion = pImp - > GetRegion ( nRegion ) ;
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
// do nothing if there is no region with that index
if ( ! pRegion )
return ;
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
pEntry = pRegion - > GetEntry ( rLongName ) ;
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
// do nothing if there is already an entry with that name
if ( pEntry )
return ;
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
/* dv! if the filename is only a filename without a path, use the following
code to create a full path
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
INetURLObject aURLObj ( pRegion - > GetTargetURL ( ) ) ;
aURLObj . insertName ( rFileName ) ;
OUString aFullFileName = aURLObj . getExternalURL ( ) ;
2000-09-18 16:07:07 +00:00
*/
2000-11-27 07:55:57 +00:00
Content aContent ;
2000-11-30 15:43:40 +00:00
pEntry = pRegion - > AddEntry ( aContent , rLongName , rFileName ) ;
if ( pEntry )
{
OUString aType = pImp - > GetTypeFromURL ( rFileName ) ;
pEntry - > SetType ( aType ) ;
}
2000-09-18 16:07:07 +00:00
}
//------------------------------------------------------------------------
2000-11-27 07:55:57 +00:00
BOOL SfxDocumentTemplates : : CopyOrMove
2000-09-18 16:07:07 +00:00
(
2000-11-27 07:55:57 +00:00
USHORT nTargetRegion , // Index des Zielbereiches
USHORT nTargetIdx , // Index Zielposition
USHORT nSourceRegion , // Index des Quellbereiches
USHORT nSourceIdx , /* Index der zu kopierenden / zu verschiebenden
Dokumentvorlage */
BOOL bMove // kopieren / verschieben
)
2000-09-18 16:07:07 +00:00
/* [Beschreibung]
2000-11-27 07:55:57 +00:00
Kopieren oder Verschieben einer Dokumentvorlage
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
[ R " uckgabewert]
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
BOOL TRUE
Aktion konnte ausgef " uhrt werden
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
FALSE
Aktion konnte nicht ausgef2uhrt werden
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
[ Querverweise ]
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
< SfxDocumentTemplates : : Move ( USHORT , USHORT , USHORT , USHORT ) >
< SfxDocumentTemplates : : Copy ( USHORT , USHORT , USHORT , USHORT ) >
*/
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
{
/* to perform a copy or move, we need to send a transfer command to
the destination folder with the URL of the source as parameter .
( If the destination content doesn ' t support the transfer command ,
we could try a copy ( and delete ) instead . )
We need two transfers ( one for the real template and one for its
representation in the hierarchy )
. . .
*/
// Don't copy or move any folders
if ( nSourceIdx = = USHRT_MAX )
return FALSE ;
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
if ( nSourceRegion = = nTargetRegion )
{
DBG_ERRORFILE ( " Don't know, what to do! " ) ;
return FALSE ;
#if 0
2000-09-18 16:07:07 +00:00
// Verschieben einer Vorlage innerhalb eines Bereiches
// --> nur Verwaltungsdaten aktualisieren
2000-11-27 07:55:57 +00:00
if ( bMove & & nTargetRegion = = nSourceRegion )
2000-09-18 16:07:07 +00:00
{
if ( nTargetIdx = = USHRT_MAX )
nTargetIdx = 0 ;
const SfxTemplateDirEntryPtr pEntry = rTargetDir [ nSourceIdx ] ;
rTargetDir . Insert ( pEntry , nTargetIdx ) ;
if ( nTargetIdx < nSourceIdx )
+ + nSourceIdx ;
rTargetDir . Remove ( nSourceIdx ) ;
return SaveDir ( rTargetDir ) ;
}
2000-11-27 07:55:57 +00:00
# endif
}
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
RegionData_Impl * pSourceRgn = pImp - > GetRegion ( nSourceRegion ) ;
if ( ! pSourceRgn )
2000-09-18 16:07:07 +00:00
return FALSE ;
2000-11-27 07:55:57 +00:00
EntryData_Impl * pSource = pSourceRgn - > GetEntry ( nSourceIdx ) ;
if ( ! pSource )
return FALSE ;
RegionData_Impl * pTargetRgn = pImp - > GetRegion ( nTargetRegion ) ;
if ( ! pTargetRgn )
return FALSE ;
EntryData_Impl * pTarget = pTargetRgn - > GetEntry ( nTargetIdx ) ;
Reference < XCommandEnvironment > aCmdEnv ;
Content aTarget ;
Content aHierTarget ;
OUString aTitle ;
if ( pTarget )
aTitle = pTarget - > GetTitle ( ) ;
2000-09-18 16:07:07 +00:00
else
2000-11-27 07:55:57 +00:00
aTitle = pSource - > GetTitle ( ) ;
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
try
2000-09-18 16:07:07 +00:00
{
2000-11-27 07:55:57 +00:00
aTarget = Content ( pTargetRgn - > GetTargetURL ( ) , aCmdEnv ) ;
aHierTarget = Content ( pTargetRgn - > GetHierarchyURL ( ) , aCmdEnv ) ;
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
TransferInfo aTransferInfo ;
aTransferInfo . MoveData = bMove ;
aTransferInfo . SourceURL = pSource - > GetTargetURL ( ) ;
aTransferInfo . NewTitle = aTitle ;
aTransferInfo . NameClash = NameClash : : OVERWRITE ;
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
Any aArg = makeAny ( aTransferInfo ) ;
OUString aCmd ( RTL_CONSTASCII_USTRINGPARAM ( COMMAND_TRANSFER ) ) ;
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
aTarget . executeCommand ( aCmd , aArg ) ;
aTransferInfo . SourceURL = pSource - > GetHierarchyURL ( ) ;
aArg = makeAny ( aTransferInfo ) ;
aHierTarget . executeCommand ( aCmd , aArg ) ;
2000-09-18 16:07:07 +00:00
}
2000-11-27 07:55:57 +00:00
catch ( ContentCreationException & )
{ return FALSE ; }
catch ( CommandAbortedException & )
{ return FALSE ; }
2000-12-06 10:14:36 +00:00
catch ( Exception & )
{ return FALSE ; }
2000-11-27 07:55:57 +00:00
// update data structures ...
if ( bMove )
{
pSourceRgn - > DeleteEntry ( nSourceIdx ) ;
}
OUString aNewTargetURL = pTargetRgn - > GetTargetURL ( ) ;
aNewTargetURL + = OUString ( ' / ' ) ;
aNewTargetURL + = aTitle ;
pTargetRgn - > AddEntry ( aTarget , aTitle , aNewTargetURL ) ;
//dv! wenn aktuell das File geoeffnet ist,
// muss es hinterher wieder geoeffnet werden
return TRUE ;
2000-09-18 16:07:07 +00:00
}
//------------------------------------------------------------------------
BOOL SfxDocumentTemplates : : Move
(
USHORT nTargetRegion , // Index des Zielbereiches
USHORT nTargetIdx , // Index Zielposition
USHORT nSourceRegion , // Index des Quellbereiches
2000-12-06 10:14:36 +00:00
USHORT nSourceIdx /* Index der zu kopierenden / zu verschiebenden
2000-09-18 16:07:07 +00:00
Dokumentvorlage */
)
/* [Beschreibung]
Verschieben einer Dokumentvorlage
[ R " uckgabewert]
BOOL TRUE
Aktion konnte ausgef " uhrt werden
FALSE
Aktion konnte nicht ausgef2uhrt werden
[ Querverweise ]
< SfxDocumentTemplates : : CopyOrMove ( USHORT , USHORT , USHORT , USHORT , BOOL ) >
*/
{
2000-11-27 07:55:57 +00:00
return CopyOrMove ( nTargetRegion , nTargetIdx ,
nSourceRegion , nSourceIdx , TRUE ) ;
2000-09-18 16:07:07 +00:00
}
//------------------------------------------------------------------------
BOOL SfxDocumentTemplates : : Copy
(
USHORT nTargetRegion , // Index des Zielbereiches
USHORT nTargetIdx , // Index Zielposition
USHORT nSourceRegion , // Index des Quellbereiches
2000-11-27 07:55:57 +00:00
USHORT nSourceIdx /* Index der zu kopierenden / zu verschiebenden
2000-09-18 16:07:07 +00:00
Dokumentvorlage */
)
/* [Beschreibung]
Kopieren einer Dokumentvorlage
[ R " uckgabewert]
BOOL TRUE
Aktion konnte ausgef " uhrt werden
FALSE
Aktion konnte nicht ausgef " uhrt werden
[ Querverweise ]
< SfxDocumentTemplates : : CopyOrMove ( USHORT , USHORT , USHORT , USHORT , BOOL ) >
*/
{
2000-11-27 07:55:57 +00:00
return CopyOrMove ( nTargetRegion , nTargetIdx ,
nSourceRegion , nSourceIdx , FALSE ) ;
2000-09-18 16:07:07 +00:00
}
//------------------------------------------------------------------------
BOOL SfxDocumentTemplates : : CopyTo
(
USHORT nRegion , /* Bereich der Vorlage, die exportiert werden
soll */
USHORT nIdx , /* Index der Vorlage, die exportiert werden
soll */
const String & rName /* Dateiname, unter dem die Vorlage angelegt
werden soll */
) const
/* [Beschreibung]
Exportieren einer Dokumentvorlage in das Dateisystem
[ R " uckgabewert]
BOOL TRUE
Aktion konnte ausgef " uhrt werden
FALSE
Aktion konnte nicht ausgef " uhrt werden
[ Querverweise ]
< SfxDocumentTemplates : : CopyFrom ( USHORT , USHORT , String & ) >
*/
{
2000-11-28 11:58:03 +00:00
RegionData_Impl * pSourceRgn = pImp - > GetRegion ( nRegion ) ;
if ( ! pSourceRgn )
return FALSE ;
EntryData_Impl * pSource = pSourceRgn - > GetEntry ( nIdx ) ;
if ( ! pSource )
return FALSE ;
INetURLObject aTargetURL ( rName ) ;
OUString aTitle ( aTargetURL . GetName ( ) ) ;
aTargetURL . CutName ( ) ;
2000-12-04 08:28:29 +00:00
OUString aParentURL = aTargetURL . GetMainURL ( ) ;
2000-11-28 11:58:03 +00:00
Reference < XCommandEnvironment > aCmdEnv ;
Content aTarget ;
try
{
aTarget = Content ( aParentURL , aCmdEnv ) ;
TransferInfo aTransferInfo ;
aTransferInfo . MoveData = FALSE ;
aTransferInfo . SourceURL = pSource - > GetTargetURL ( ) ;
aTransferInfo . NewTitle = aTitle ;
aTransferInfo . NameClash = NameClash : : OVERWRITE ;
Any aArg = makeAny ( aTransferInfo ) ;
OUString aCmd ( RTL_CONSTASCII_USTRINGPARAM ( COMMAND_TRANSFER ) ) ;
aTarget . executeCommand ( aCmd , aArg ) ;
}
catch ( ContentCreationException & )
{ return FALSE ; }
catch ( CommandAbortedException & )
{ return FALSE ; }
2000-12-06 10:14:36 +00:00
catch ( Exception & )
{ return FALSE ; }
2000-11-28 11:58:03 +00:00
return TRUE ;
2000-09-18 16:07:07 +00:00
}
//------------------------------------------------------------------------
BOOL SfxDocumentTemplates : : CopyFrom
(
USHORT nRegion , /* Bereich, in den die Vorlage importiert
werden soll */
USHORT nIdx , // Index der neuen Vorlage in diesem Bereich
String & rName /* Dateiname der Vorlage, die importiert
werden soll , als out - Parameter der ( auto -
matisch aus dem Dateinamen generierte )
logische Name der Vorlage */
)
/* [Beschreibung]
Importieren einer Dokumentvorlage aus dem Dateisystem
[ R " uckgabewert] Erfolg (TRUE) oder Mi " serfpTargetDirectory - > GetContent ( ) ) ;
BOOL TRUE
Aktion konnte ausgef " uhrt werden
FALSE
Aktion konnte nicht ausgef " uhrt werden
[ Querverweise ]
< SfxDocumentTemplates : : CopyTo ( USHORT , USHORT , const String & ) >
*/
{
2000-11-28 11:58:03 +00:00
RegionData_Impl * pTargetRgn = pImp - > GetRegion ( nRegion ) ;
if ( ! pTargetRgn )
2000-09-18 16:07:07 +00:00
return FALSE ;
2000-11-28 11:58:03 +00:00
EntryData_Impl * pTarget = pTargetRgn - > GetEntry ( nIdx ) ;
if ( ! pTarget )
return FALSE ;
2000-09-18 16:07:07 +00:00
2000-11-28 11:58:03 +00:00
INetURLObject aSource ( rName ) ;
2000-09-18 16:07:07 +00:00
2000-11-28 11:58:03 +00:00
OUString aTitle ( aSource . GetName ( ) ) ;
Reference < XCommandEnvironment > aCmdEnv ;
Content aTarget ;
2000-09-18 16:07:07 +00:00
2000-11-28 11:58:03 +00:00
try
{
aTarget = Content ( pTargetRgn - > GetTargetURL ( ) , aCmdEnv ) ;
2000-09-18 16:07:07 +00:00
2000-11-28 11:58:03 +00:00
TransferInfo aTransferInfo ;
aTransferInfo . MoveData = FALSE ;
aTransferInfo . SourceURL = rName ;
aTransferInfo . NewTitle = aTitle ;
aTransferInfo . NameClash = NameClash : : OVERWRITE ;
2000-09-18 16:07:07 +00:00
2000-11-28 11:58:03 +00:00
Any aArg = makeAny ( aTransferInfo ) ;
OUString aCmd ( RTL_CONSTASCII_USTRINGPARAM ( COMMAND_TRANSFER ) ) ;
aTarget . executeCommand ( aCmd , aArg ) ;
}
catch ( ContentCreationException & )
{ return FALSE ; }
catch ( CommandAbortedException & )
{ return FALSE ; }
2000-12-06 10:14:36 +00:00
catch ( Exception & )
{ return FALSE ; }
2000-09-18 16:07:07 +00:00
2000-11-28 11:58:03 +00:00
// update data structures ...
2000-11-30 15:43:40 +00:00
EntryData_Impl * pEntry ;
pEntry = pTargetRgn - > AddEntry ( aTarget , aTitle , rName ) ;
if ( pEntry )
{
OUString aType = pImp - > GetTypeFromURL ( rName ) ;
pEntry - > SetType ( aType ) ;
}
2000-09-18 16:07:07 +00:00
2000-11-28 11:58:03 +00:00
return TRUE ;
2000-09-18 16:07:07 +00:00
}
//------------------------------------------------------------------------
BOOL SfxDocumentTemplates : : Delete
(
USHORT nRegion , // Index des Bereiches
USHORT nIdx /* Index des Eintrags oder USHRT_MAX,
wenn ein Verzeichnis gemeint ist . */
)
/* [Beschreibung]
" oschen eines Eintrags oder eines Verzeichnisses
[ R " uckgabewert]
BOOL TRUE
Aktion konnte ausgef " uhrt werden
FALSE
Aktion konnte nicht ausgef " uhrt werden
[ Querverweise ]
< SfxDocumentTemplates : : InsertDir ( const String & , USHORT ) >
< SfxDocumentTemplates : : KillDir ( SfxTemplateDir & ) >
< SfxDocumentTemplates : : SaveDir ( SfxTemplateDir & ) >
*/
{
2000-11-27 07:55:57 +00:00
/* delete the template or folder in the hierarchy and in the
template folder by sending a delete command to the content .
Then remove the data from the lists
*/
sal_Bool bRet = sal_False ;
RegionData_Impl * pRegion = pImp - > GetRegion ( nRegion ) ;
if ( ! pRegion )
return bRet ;
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
OUString aHierURL ;
OUString aTargetURL ;
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
if ( nIdx = = USHRT_MAX )
2000-09-18 16:07:07 +00:00
{
2000-11-27 07:55:57 +00:00
aTargetURL = pRegion - > GetTargetURL ( ) ;
aHierURL = pRegion - > GetHierarchyURL ( ) ;
2000-09-18 16:07:07 +00:00
}
else
{
2000-11-27 07:55:57 +00:00
EntryData_Impl * pEntry = pRegion - > GetEntry ( nIdx ) ;
if ( ! pEntry )
return bRet ;
aTargetURL = pEntry - > GetTargetURL ( ) ;
aHierURL = pEntry - > GetHierarchyURL ( ) ;
2000-09-18 16:07:07 +00:00
}
2000-11-27 07:55:57 +00:00
Reference < XCommandEnvironment > aCmdEnv ;
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
Content aHierCont ;
Content aFolderCont ;
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
try
{
aHierCont = Content ( aHierURL , aCmdEnv ) ;
aFolderCont = Content ( aTargetURL , aCmdEnv ) ;
}
catch ( ContentCreationException & )
{
DBG_ERRORFILE ( " Template or Region doesn't exist! " ) ;
return bRet ;
}
2000-12-06 10:14:36 +00:00
catch ( Exception & )
{ return bRet ; }
2000-11-27 07:55:57 +00:00
try
{
OUString aCmd ( RTL_CONSTASCII_USTRINGPARAM ( COMMAND_DELETE ) ) ;
Any aArg = makeAny ( sal_Bool ( sal_True ) ) ;
aHierCont . executeCommand ( aCmd , aArg ) ;
aFolderCont . executeCommand ( aCmd , aArg ) ;
bRet = sal_True ;
}
catch ( CommandAbortedException & )
{
DBG_ERRORFILE ( " Template or Region doesn't exist! " ) ;
return bRet ;
}
2000-12-06 10:14:36 +00:00
catch ( Exception & )
{ return bRet ; }
2000-11-27 07:55:57 +00:00
if ( bRet )
{
if ( nIdx = = USHRT_MAX )
pImp - > DeleteRegion ( nRegion ) ;
else
pRegion - > DeleteEntry ( nIdx ) ;
}
return bRet ;
}
//------------------------------------------------------------------------
BOOL SfxDocumentTemplates : : InsertDir
(
const String & rText , // der logische Name des neuen Bereiches
USHORT nRegion // Index des Bereiches
)
/* [Beschreibung]
Einf " ugen eines Verzeichnisses
2000-09-18 16:07:07 +00:00
[ R " uckgabewert]
BOOL TRUE
Aktion konnte ausgef " uhrt werden
FALSE
Aktion konnte nicht ausgef " uhrt werden
[ Querverweise ]
< SfxDocumentTemplates : : KillDir ( SfxTemplateDir & ) >
< SfxDocumentTemplates : : SaveDir ( SfxTemplateDir & ) >
*/
{
2000-11-27 07:55:57 +00:00
// create a new entry in hierarchy and another entry in
// the (first?) template direktory, then update
// RegionData_Impl list
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
Content aTemplateRoot ;
Content aTemplateDir ;
sal_Bool bNew ;
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
if ( ! pImp - > GetTemplateRoot ( aTemplateRoot , bNew ) )
return FALSE ;
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
if ( ! pImp - > GetTemplateDir ( 0 , aTemplateDir ) )
return FALSE ;
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
OUString aTitle ( rText ) ;
OUString aTargetURL = aDirs . GetToken ( 0 , C_DELIM ) ;
aTargetURL + = OUString ( ' / ' ) ;
aTargetURL + = aTitle ;
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
if ( pImp - > InsertNewRegionToHierarchy ( aTemplateRoot , aTitle ,
aTargetURL , 0 ) )
{
DBG_ERRORFILE ( " Entry already in hierarchy " ) ;
return FALSE ;
}
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
if ( pImp - > InsertNewRegionToFolder ( aTemplateDir , aTitle ) )
{
DBG_ERRORFILE ( " Entry already in folder " ) ;
return FALSE ;
2000-09-18 16:07:07 +00:00
}
2000-11-27 07:55:57 +00:00
return TRUE ;
2000-09-18 16:07:07 +00:00
}
//------------------------------------------------------------------------
BOOL SfxDocumentTemplates : : SetName
(
const String & rName , // Der zu setzende Name
USHORT nRegion , // Index des Bereiches
USHORT nIdx /* Index des Eintrags oder USHRT_MAX,
wenn ein Verzeichnis gemeint ist . */
)
/* [Beschreibung]
" Andern des Namens eines Eintrags oder eines Verzeichnisses
[ R " uckgabewert]
BOOL TRUE
Aktion konnte ausgef " uhrt werden
FALSE
Aktion konnte nicht ausgef " uhrt werden
*/
{
2000-11-27 07:55:57 +00:00
// find the data entry and rename the entry in the hierarchy as
// well as the corresponding folder or file
RegionData_Impl * pRegion = pImp - > GetRegion ( nRegion ) ;
EntryData_Impl * pEntry = NULL ;
if ( ! pRegion )
return FALSE ;
Content aHierCont ;
Content aFolderCont ;
OUString aTitle ( rName ) ;
OUString aFolderURL = pRegion - > GetTargetURL ( ) ;
2000-11-30 15:43:40 +00:00
OUString aHierURL = pRegion - > GetHierarchyURL ( ) ;
2000-09-18 16:07:07 +00:00
2000-12-07 09:12:29 +00:00
if ( nIdx ! = USHRT_MAX )
2000-09-18 16:07:07 +00:00
{
2000-11-27 07:55:57 +00:00
EntryData_Impl * pEntry = pRegion - > GetEntry ( nIdx ) ;
if ( ! pEntry )
2000-09-18 16:07:07 +00:00
return FALSE ;
2000-11-27 07:55:57 +00:00
aFolderURL = pEntry - > GetTargetURL ( ) ;
aHierURL + = OUString ( ' / ' ) ;
aHierURL + = pEntry - > GetTitle ( ) ;
}
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
Reference < XCommandEnvironment > aCmdEnv ;
OUString aTitleStr ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( TITLE ) ) ) ;
// Create a hierarchy Content with the old title and
// rename it
try
{
aHierCont = Content ( aHierURL , aCmdEnv ) ;
aHierCont . setPropertyValue ( aTitleStr , makeAny ( aTitle ) ) ;
aHierURL = aHierCont . get ( ) - > getIdentifier ( ) - > getContentIdentifier ( ) ;
}
catch ( ContentCreationException & )
{
DBG_ERRORFILE ( " Hierarchy object doesn't exist? " ) ;
return FALSE ;
}
2000-12-06 10:14:36 +00:00
catch ( Exception & )
{ return FALSE ; }
2000-11-27 07:55:57 +00:00
// Create a folder Content with the old title and
// rename it
try
{
aFolderCont = Content ( aFolderURL , aCmdEnv ) ;
2000-12-07 09:12:29 +00:00
aFolderCont . setPropertyValue ( aTitleStr , makeAny ( aTitle ) ) ;
2000-11-27 07:55:57 +00:00
aFolderURL = aFolderCont . get ( ) - > getIdentifier ( ) - > getContentIdentifier ( ) ;
}
catch ( ContentCreationException & )
{
DBG_ERRORFILE ( " Folder object doesn't exist? " ) ;
return FALSE ;
}
2000-12-06 10:14:36 +00:00
catch ( Exception & )
{ return FALSE ; }
2000-11-27 07:55:57 +00:00
// Update the internal data structures
if ( pEntry )
{
2000-12-07 09:12:29 +00:00
pEntry - > SetTitle ( aTitle ) ;
2000-11-27 07:55:57 +00:00
pEntry - > SetTargetURL ( aFolderURL ) ;
pEntry - > SetHierarchyURL ( aHierURL ) ;
}
else
{
pRegion - > SetTitle ( aTitle ) ;
pRegion - > SetTargetURL ( aFolderURL ) ;
pRegion - > SetHierarchyURL ( aHierURL ) ;
}
return TRUE ;
2000-09-18 16:07:07 +00:00
}
//------------------------------------------------------------------------
BOOL SfxDocumentTemplates : : Rescan ( )
/* [Beschreibung]
Abgleich des Verwaltungsdaten mit dem aktuellen Zustand auf der Platte .
Die logischen Namen , zu denen keine Datei mit existiert , werden aus
der Verwaltungsstruktur entfernt ; Dateien , zu denen kein Eintrag
existiert , werden aufgenommen .
[ R " uckgabewert]
BOOL TRUE
Aktion konnte ausgef " uhrt werden
FALSE
Aktion konnte nicht ausgef " uhrt werden
[ Querverweise ]
< SfxTemplateDir : : Scan ( BOOL bDirectory , BOOL bSave ) >
< SfxTemplateDir : : Freshen ( const SfxTemplateDir & rNew ) >
*/
{
2000-12-06 10:14:36 +00:00
if ( pImp . Is ( ) )
{
return pImp - > Rescan ( sal_True ) ;
}
2000-11-27 07:55:57 +00:00
return FALSE ;
2000-12-06 10:14:36 +00:00
2000-11-27 07:55:57 +00:00
#if 0 //dv!
2000-09-18 16:07:07 +00:00
DBG_ASSERT ( pDirs , " not initialized " ) ;
//(mba)/task SfxWaitCursor aWait;
const USHORT nCount = pDirs - > Count ( ) ;
BOOL bOk = TRUE ;
USHORT i ;
for ( i = 0 ; i < nCount ; + + i )
{
SfxTemplateDirEntry * pEntry = ( * pDirs ) [ i ] ;
SfxTemplateDir & rCntnt = pEntry - > GetContent ( ) ;
SfxTemplateDir aNew ( rCntnt . GetPath ( ) ) ;
aNew . Scan ( FALSE ) ;
if ( rCntnt . Freshen ( aNew ) )
bOk | = SaveDir ( rCntnt ) ;
}
USHORT nMax = aDirs . GetTokenCount ( cDelim ) ;
for ( i = 0 ; i < nMax ; i + + )
{
SfxTemplateDir * pOldDir = new SfxTemplateDir (
aDirs . GetToken ( i , cDelim ) , TRUE , FALSE ) ;
SfxTemplateDir * pNewDir = new SfxTemplateDir (
aDirs . GetToken ( i , cDelim ) , TRUE , TRUE ) ;
if ( pOldDir - > Freshen ( * pNewDir ) )
bOk | = SaveDir ( * pOldDir ) ;
delete pNewDir ;
delete pOldDir ;
}
DELETEZ ( pDirs ) ;
DELETEZ ( pDirCount ) ;
Construct ( ) ;
return bOk ;
2000-11-27 07:55:57 +00:00
# endif
2000-09-18 16:07:07 +00:00
}
//------------------------------------------------------------------------
SfxObjectShellRef SfxDocumentTemplates : : CreateObjectShell
(
USHORT nRegion , // Index des Bereiches
USHORT nIdx // Index des Eintrags
)
/* [Beschreibung]
Zugriff auf die DokumentShell eines Eintrags
[ R " uckgabewert]
SfxObjectShellRef Referenz auf die ObjectShell
[ Querverweise ]
< SfxTemplateDirEntry : : CreateObjectShell ( ) >
< SfxDocumentTemplates : : DeleteObjectShell ( USHORT , USHORT ) >
*/
{
2000-12-08 10:35:44 +00:00
if ( ! pImp )
return NULL ;
RegionData_Impl * pRegion = pImp - > GetRegion ( nRegion ) ;
EntryData_Impl * pEntry = NULL ;
if ( pRegion )
pEntry = pRegion - > GetEntry ( nIdx ) ;
if ( pEntry )
return pEntry - > CreateObjectShell ( ) ;
else
return NULL ;
2000-09-18 16:07:07 +00:00
}
//------------------------------------------------------------------------
BOOL SfxDocumentTemplates : : DeleteObjectShell
(
USHORT nRegion , // Index des Bereiches
USHORT nIdx // Index des Eintrags
)
/* [Beschreibung]
Freigeben der ObjectShell eines Eintrags
[ R " uckgabewert]
BOOL TRUE
Aktion konnte ausgef " uhrt werden
FALSE
Aktion konnte nicht ausgef " uhrt werden
[ Querverweise ]
< SfxTemplateDirEntry : : DeleteObjectShell ( ) >
< SfxDocumentTemplates : : CreateObjectShell ( USHORT , USHORT ) >
*/
{
2000-12-08 10:35:44 +00:00
if ( ! pImp )
return NULL ;
RegionData_Impl * pRegion = pImp - > GetRegion ( nRegion ) ;
EntryData_Impl * pEntry = NULL ;
if ( pRegion )
pEntry = pRegion - > GetEntry ( nIdx ) ;
if ( pEntry )
return pEntry - > DeleteObjectShell ( ) ;
else
return TRUE ;
2000-09-18 16:07:07 +00:00
}
//------------------------------------------------------------------------
BOOL SfxDocumentTemplates : : GetFull
(
const String & rRegion , // Der Name des Bereiches
const String & rName , // Der Name der Vorlage
String & rPath // Out: Pfad + Dateiname
)
/* [Beschreibung]
Liefert Pfad + Dateiname zu der durch rRegion und rName bezeichneten
Vorlage
[ R " uckgabewert]
BOOL TRUE
Aktion konnte ausgef " uhrt werden
FALSE
Aktion konnte nicht ausgef " uhrt werden
[ Querverweise ]
< SfxDocumentTemplates : : GetLogicNames ( const String & , String & , String & ) >
*/
{
2000-11-27 07:55:57 +00:00
const EntryData_Impl * pEntry = NULL ;
const USHORT nCount = GetRegionCount ( ) ;
2000-09-18 16:07:07 +00:00
BOOL bFQ = FALSE ;
USHORT nPos = rRegion . Len ( ) ;
2000-11-27 07:55:57 +00:00
2000-09-18 16:07:07 +00:00
while ( - - nPos ! = USHRT_MAX & & rRegion . GetChar ( nPos ) ! = ' ( ' )
;
if ( nPos ! = USHRT_MAX & & rRegion . GetChar ( USHORT ( rRegion . Len ( ) - 1 ) ) = = ' ) ' )
bFQ = TRUE ;
for ( USHORT i = 0 ; i < nCount ; + + i )
{
String aName ;
if ( bFQ )
aName = GetFullRegionName ( i ) ;
else
aName = GetRegionName ( i ) ;
if ( aName = = rRegion )
{
2000-11-27 07:55:57 +00:00
RegionData_Impl * pRegion = pImp - > GetRegion ( i ) ;
if ( pRegion )
pEntry = pRegion - > GetEntry ( rName ) ;
2000-09-18 16:07:07 +00:00
if ( pEntry )
2000-11-27 07:55:57 +00:00
rPath = pEntry - > GetTargetURL ( ) ;
2000-09-18 16:07:07 +00:00
if ( pEntry | | bFQ )
break ;
}
}
return ( pEntry ! = NULL ) ;
}
//------------------------------------------------------------------------
BOOL SfxDocumentTemplates : : GetLogicNames
(
const String & rPath , // vollst"andiger Pfad zu der Vorlage
String & rRegion , // Out: der Bereichsname
String & rName // Out: der Vorlagenname
) const
/* [Beschreibung]
Liefert Pfad und logischen Namen zu der durch rPath bezeichneten
Vorlage
[ R " uckgabewert]
BOOL TRUE
Aktion konnte ausgef " uhrt werden
FALSE
Aktion konnte nicht ausgef " uhrt werden
[ Querverweise ]
< SfxDocumentTemplates : : GetFull ( const String & , const String & , DirEntry & ) >
*/
{
2000-11-27 07:55:57 +00:00
INetURLObject aFullPath ;
2000-09-18 16:07:07 +00:00
2000-11-27 07:55:57 +00:00
aFullPath . SetSmartProtocol ( INET_PROT_FILE ) ;
aFullPath . SetURL ( rPath ) ;
aFullPath . CutLastName ( ) ;
2000-12-04 08:28:29 +00:00
OUString aPathTo = aFullPath . GetMainURL ( ) ;
2000-11-27 07:55:57 +00:00
RegionData_Impl * pData = NULL ;
EntryData_Impl * pEntry = NULL ;
sal_Bool bFound = sal_False ;
2000-11-28 11:58:03 +00:00
ULONG nCount = GetRegionCount ( ) ;
2000-11-27 07:55:57 +00:00
2000-11-28 11:58:03 +00:00
for ( ULONG i = 0 ; ! bFound & & ( i < nCount ) ; i + + )
2000-09-18 16:07:07 +00:00
{
2000-11-27 07:55:57 +00:00
pData = pImp - > GetRegion ( i ) ;
if ( pData - > GetTargetURL ( ) = = aPathTo )
2000-09-18 16:07:07 +00:00
{
2000-11-28 11:58:03 +00:00
ULONG nChildCount = pData - > GetCount ( ) ;
2000-11-27 07:55:57 +00:00
OUString aPath ( rPath ) ;
2000-11-28 11:58:03 +00:00
for ( ULONG j = 0 ; ! bFound & & ( j < nChildCount ) ; j + + )
2000-11-27 07:55:57 +00:00
{
pEntry = pData - > GetEntry ( j ) ;
if ( pEntry - > GetTargetURL ( ) = = aPath )
{
bFound = sal_True ;
}
}
}
2000-09-18 16:07:07 +00:00
}
2000-11-27 07:55:57 +00:00
if ( bFound )
{
2000-12-07 09:12:29 +00:00
rRegion = pData - > GetTitle ( ) ;
2000-11-27 07:55:57 +00:00
rName = pEntry - > GetTitle ( ) ;
}
return bFound ;
2000-09-18 16:07:07 +00:00
}
//------------------------------------------------------------------------
SfxDocumentTemplates : : SfxDocumentTemplates ( )
/* [Beschreibung]
Konstruktor
*/
2000-11-27 07:55:57 +00:00
: pImp ( 0 )
2000-09-18 16:07:07 +00:00
{
2000-11-27 07:55:57 +00:00
aDirs = SvtPathOptions ( ) . GetTemplatePath ( ) ;
cDelim = ' ; ' ; // absichtlich hart verdrahtet
2000-09-18 16:07:07 +00:00
}
//-------------------------------------------------------------------------
void SfxDocumentTemplates : : Construct ( )
// verz"ogerter Aufbau der Verwaltungsdaten
{
2000-12-04 09:32:11 +00:00
if ( ! gpTemplateData )
gpTemplateData = new SfxDocTemplate_Impl ;
pImp = gpTemplateData ;
2000-11-27 07:55:57 +00:00
pImp - > Construct ( aDirs ) ;
2000-09-18 16:07:07 +00:00
}
//------------------------------------------------------------------------
SfxDocumentTemplates : : ~ SfxDocumentTemplates ( )
/* [Beschreibung]
Destruktor
Freigeben der Verwaltungsdaten
*/
{
2000-12-04 09:32:11 +00:00
pImp = NULL ;
2000-09-18 16:07:07 +00:00
}
2000-11-27 07:55:57 +00:00
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
EntryData_Impl : : EntryData_Impl ( const OUString & rTitle )
{
2000-12-08 10:35:44 +00:00
maTitle = rTitle ;
mbInUse = sal_True ;
mbNew = sal_True ;
mbIsOwner = sal_False ;
mbDidConvert = sal_False ;
2000-11-27 07:55:57 +00:00
}
// -----------------------------------------------------------------------
void EntryData_Impl : : SetTargetURL ( const OUString & rTargetURL )
{
maTargetURL = rTargetURL ;
}
// -----------------------------------------------------------------------
int EntryData_Impl : : Compare ( const OUString & rTitle ) const
{
return maTitle . compareTo ( rTitle ) ;
}
2000-11-30 15:43:40 +00:00
// -----------------------------------------------------------------------
void EntryData_Impl : : SetType ( const OUString & rType )
{
Content aContent ;
try
{
Reference < XCommandEnvironment > aCmdEnv ;
aContent = Content ( maOwnURL , aCmdEnv ) ;
Reference < XPropertySetInfo > xPropSet = aContent . getProperties ( ) ;
if ( xPropSet . is ( ) )
{
OUString aPropName ( RTL_CONSTASCII_USTRINGPARAM ( PROPERTY_TYPE ) ) ;
Sequence < OUString > aPropNames ( & aPropName , 1 ) ;
if ( ! xPropSet - > hasPropertyByName ( aPropName ) )
{
Reference < XPropertyContainer > xProperties ( aContent . get ( ) , UNO_QUERY ) ;
if ( xProperties . is ( ) )
{
try
{
xProperties - > addProperty ( aPropName , PropertyAttribute : : MAYBEVOID ,
makeAny ( rType ) ) ;
}
catch ( PropertyExistException & ) { }
catch ( IllegalTypeException & ) { DBG_ERRORFILE ( " IllegalTypeException " ) ; }
catch ( IllegalArgumentException & ) { DBG_ERRORFILE ( " IllegalArgumentException " ) ; }
}
}
Sequence < Any > aPropValues ( 1 ) ;
Any * pPropValues = aPropValues . getArray ( ) ;
pPropValues [ 0 ] = makeAny ( rType ) ;
aContent . setPropertyValues ( aPropNames , aPropValues ) ;
}
}
2000-12-06 10:14:36 +00:00
catch ( CommandAbortedException & ) { }
catch ( RuntimeException & ) { }
catch ( Exception & ) { }
2000-11-30 15:43:40 +00:00
}
2000-12-07 09:12:29 +00:00
// -----------------------------------------------------------------------
void EntryData_Impl : : RemoveEntry ( )
{
Content aEntry ;
try
{
Reference < XCommandEnvironment > aCmdEnv ;
aEntry = Content ( maOwnURL , aCmdEnv ) ;
OUString aCmd ( RTL_CONSTASCII_USTRINGPARAM ( COMMAND_DELETE ) ) ;
Any aArg = makeAny ( sal_Bool ( sal_True ) ) ;
aEntry . executeCommand ( aCmd , aArg ) ;
}
catch ( CommandAbortedException & ) { }
catch ( RuntimeException & ) { }
catch ( Exception & ) { }
}
2000-12-08 10:35:44 +00:00
//------------------------------------------------------------------------
SfxObjectShellRef EntryData_Impl : : CreateObjectShell ( )
{
if ( ! mxObjShell . Is ( ) )
{
mbIsOwner = FALSE ;
BOOL bDum = FALSE ;
SfxApplication * pSfxApp = SFX_APP ( ) ;
mxObjShell = pSfxApp - > DocAlreadyLoaded ( maTargetURL , TRUE , bDum ) ;
if ( ! mxObjShell . Is ( ) )
{
mbIsOwner = TRUE ;
SfxMedium * pMed = new SfxMedium (
maTargetURL , ( STREAM_READ | STREAM_SHARE_DENYWRITE ) , FALSE , 0 ) ;
const SfxFilter * pFilter = NULL ;
if ( pSfxApp - > GetFilterMatcher ( ) . GuessFilter (
* pMed , & pFilter , SFX_FILTER_TEMPLATE , 0 ) | |
pFilter & & ! pFilter - > IsOwnFormat ( ) | |
pFilter & & ! pFilter - > UsesStorage ( ) )
{
SfxErrorContext aEc ( ERRCTX_SFX_LOADTEMPLATE ,
maTargetURL ) ;
delete pMed ;
mbDidConvert = TRUE ;
ULONG lErr ;
if ( mxObjShell . Is ( ) )
if ( lErr = ( pSfxApp - > LoadTemplate (
mxObjShell , maTargetURL ) ! = ERRCODE_NONE ) )
ErrorHandler : : HandleError ( lErr ) ;
}
else
{
const SfxObjectFactory & rFactory =
( ( SfxFactoryFilterContainer * ) pFilter - > GetFilterContainer ( ) )
- > GetFactory ( ) ;
delete pMed ;
mbDidConvert = FALSE ;
mxStor = new SvStorage (
maTargetURL ,
STREAM_READWRITE | STREAM_NOCREATE |
STREAM_SHARE_DENYALL , STORAGE_TRANSACTED ) ;
if ( pFilter )
mxStor - > SetVersion ( pFilter - > GetVersion ( ) ) ;
if ( SVSTREAM_OK = = mxStor - > GetError ( ) )
{
mxObjShell = ( SfxObjectShell * )
rFactory . CreateObject ( SFX_CREATE_MODE_ORGANIZER ) ;
if ( mxObjShell . Is ( ) )
{
mxObjShell - > DoInitNew ( 0 ) ;
if ( ! mxObjShell - > LoadFrom ( mxStor ) )
mxObjShell . Clear ( ) ;
else
{
mxObjShell - > DoHandsOff ( ) ;
mxObjShell - > DoSaveCompleted ( mxStor ) ;
}
}
}
}
}
}
return ( SfxObjectShellRef ) ( SfxObjectShell * ) mxObjShell ;
}
//------------------------------------------------------------------------
BOOL EntryData_Impl : : DeleteObjectShell ( )
{
BOOL bRet = TRUE ;
if ( mxObjShell . Is ( ) )
{
if ( mxObjShell - > IsModified ( ) )
{
//Hier speichern wir auch, falls die Vorlage in Bearbeitung ist...
bRet = FALSE ;
if ( mbIsOwner )
if ( mbDidConvert )
{
bRet = mxObjShell - > PreDoSaveAs_Impl (
maTargetURL ,
mxObjShell - > GetFactory ( ) . GetFilter ( 0 ) - > GetName ( ) , 0 ) ;
}
else
{
if ( mxObjShell - > Save ( ) )
bRet = mxStor - > Commit ( ) ;
else
bRet = FALSE ;
}
}
if ( bRet )
{
mxObjShell . Clear ( ) ;
mxStor . Clear ( ) ;
}
}
return bRet ;
}
2000-11-27 07:55:57 +00:00
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
2000-12-07 09:12:29 +00:00
RegionData_Impl : : RegionData_Impl ( const OUString & rTitle )
2000-11-27 07:55:57 +00:00
{
2000-12-07 09:12:29 +00:00
maTitle = rTitle ;
mbInUse = sal_True ;
mbNew = sal_True ;
2000-11-27 07:55:57 +00:00
}
// -----------------------------------------------------------------------
RegionData_Impl : : ~ RegionData_Impl ( )
{
EntryData_Impl * pData = maEntries . First ( ) ;
while ( pData )
{
delete pData ;
pData = maEntries . Next ( ) ;
}
}
// -----------------------------------------------------------------------
void RegionData_Impl : : SetTargetURL ( const OUString & rTargetURL )
{
if ( ! maTargetContent . get ( ) . is ( ) )
{
try
{
Reference < XCommandEnvironment > aCmdEnv ;
maTargetContent = Content ( rTargetURL , aCmdEnv ) ;
}
2000-12-06 10:14:36 +00:00
catch ( ContentCreationException & ) { }
catch ( Exception & ) { }
2000-11-27 07:55:57 +00:00
}
maTargetURL = rTargetURL ;
if ( ! maTitle . getLength ( ) )
{
INetURLObject aURLObject ( rTargetURL ) ;
maTitle = aURLObject . getName ( ) ;
}
}
// -----------------------------------------------------------------------
long RegionData_Impl : : GetEntryPos ( const OUString & rTitle ,
sal_Bool & rFound ) const
{
// use binary search to find the correct position
// in the maEntries list
int nCompVal = 1 ;
long nStart = 0 ;
long nEnd = maEntries . Count ( ) - 1 ;
long nMid ;
EntryData_Impl * pMid ;
rFound = sal_False ;
while ( nCompVal & & ( nStart < = nEnd ) )
{
nMid = ( nEnd - nStart ) / 2 + nStart ;
pMid = maEntries . GetObject ( nMid ) ;
nCompVal = pMid - > Compare ( rTitle ) ;
if ( nCompVal < 0 ) // pMid < pData
nStart = nMid + 1 ;
else
nEnd = nMid - 1 ;
}
if ( nCompVal = = 0 )
{
rFound = sal_True ;
}
else
{
if ( nCompVal < 0 ) // pMid < pData
nMid + + ;
}
return nMid ;
}
// -----------------------------------------------------------------------
2000-11-30 15:43:40 +00:00
EntryData_Impl * RegionData_Impl : : AddEntry ( Content & rParentFolder ,
const OUString & rTitle ,
const OUString & rTargetURL )
2000-11-27 07:55:57 +00:00
{
Content aLink ;
Reference < XCommandEnvironment > aCmdEnv ;
2000-12-04 08:28:29 +00:00
INetURLObject aLinkObj ( TEMPLATE_ROOT_URL ) ;
aLinkObj . insertName ( maTitle , true ,
INetURLObject : : LAST_SEGMENT , true ,
INetURLObject : : ENCODE_ALL ) ;
aLinkObj . insertName ( rTitle , false ,
INetURLObject : : LAST_SEGMENT , true ,
INetURLObject : : ENCODE_ALL ) ;
OUString aLinkURL = aLinkObj . GetMainURL ( ) ;
// OUString aLinkURL( RTL_CONSTASCII_USTRINGPARAM( TEMPLATE_ROOT_URL ) );
// aLinkURL += OUString( '/' ) + maTitle + OUString( '/' ) + rTitle;
2000-11-27 07:55:57 +00:00
try
{
aLink = Content ( aLinkURL , aCmdEnv ) ;
}
catch ( ContentCreationException & )
{
Sequence < OUString > aNames ( 3 ) ;
OUString * pNames = aNames . getArray ( ) ;
pNames [ 0 ] = OUString ( RTL_CONSTASCII_USTRINGPARAM ( TITLE ) ) ;
pNames [ 1 ] = OUString ( RTL_CONSTASCII_USTRINGPARAM ( IS_FOLDER ) ) ;
pNames [ 2 ] = OUString ( RTL_CONSTASCII_USTRINGPARAM ( TARGET_URL ) ) ;
Sequence < Any > aValues ( 3 ) ;
Any * pValues = aValues . getArray ( ) ;
pValues [ 0 ] = makeAny ( rTitle ) ;
pValues [ 1 ] = makeAny ( sal_Bool ( sal_False ) ) ;
pValues [ 2 ] = makeAny ( rTargetURL ) ;
OUString aType ( RTL_CONSTASCII_USTRINGPARAM ( TYPE_LINK ) ) ;
if ( ! rParentFolder . get ( ) . is ( ) )
{
try
{
rParentFolder = Content ( rTargetURL , aCmdEnv ) ;
}
catch ( ContentCreationException & )
{
2000-11-30 15:43:40 +00:00
return NULL ;
2000-11-27 07:55:57 +00:00
}
}
try
{
rParentFolder . insertNewContent ( aType , aNames , aValues , aLink ) ;
}
catch ( CommandAbortedException & )
{
DBG_ERRORFILE ( " CommandAbortedException " ) ;
2000-11-30 15:43:40 +00:00
return NULL ;
2000-11-27 07:55:57 +00:00
}
}
2000-12-06 10:14:36 +00:00
catch ( Exception & )
{ return NULL ; }
2000-11-27 07:55:57 +00:00
2000-12-07 09:12:29 +00:00
EntryData_Impl * pEntry ;
sal_Bool bFound = sal_False ;
long nPos = GetEntryPos ( rTitle , bFound ) ;
2000-11-27 07:55:57 +00:00
2000-12-07 09:12:29 +00:00
if ( bFound )
2000-11-30 15:43:40 +00:00
{
pEntry = maEntries . GetObject ( nPos ) ;
2000-12-07 09:12:29 +00:00
pEntry - > SetInUse ( sal_True ) ;
}
else
{
pEntry = new EntryData_Impl ( rTitle ) ;
pEntry - > SetTargetURL ( rTargetURL ) ;
pEntry - > SetHierarchyURL ( aLinkURL ) ;
maEntries . Insert ( pEntry , nPos ) ;
2000-11-30 15:43:40 +00:00
}
return pEntry ;
2000-11-27 07:55:57 +00:00
}
// -----------------------------------------------------------------------
2000-11-28 11:58:03 +00:00
ULONG RegionData_Impl : : GetCount ( ) const
2000-11-27 07:55:57 +00:00
{
return maEntries . Count ( ) ;
}
// -----------------------------------------------------------------------
EntryData_Impl * RegionData_Impl : : GetEntry ( const OUString & rName ) const
{
sal_Bool bFound = sal_False ;
long nPos = GetEntryPos ( rName , bFound ) ;
if ( bFound )
return maEntries . GetObject ( nPos ) ;
else
return NULL ;
}
2000-12-07 16:01:23 +00:00
// -----------------------------------------------------------------------
EntryData_Impl * RegionData_Impl : : GetByTargetURL ( const OUString & rName ) const
{
EntryData_Impl * pEntry ;
ULONG nCount = maEntries . Count ( ) ;
for ( ULONG i = 0 ; i < nCount ; i + + )
{
pEntry = maEntries . GetObject ( i ) ;
if ( pEntry & & ( pEntry - > GetTargetURL ( ) = = rName ) )
return pEntry ;
}
return NULL ;
}
2000-11-27 07:55:57 +00:00
// -----------------------------------------------------------------------
2000-11-28 11:58:03 +00:00
EntryData_Impl * RegionData_Impl : : GetEntry ( ULONG nIndex ) const
2000-11-27 07:55:57 +00:00
{
return maEntries . GetObject ( nIndex ) ;
}
// -----------------------------------------------------------------------
2000-11-28 11:58:03 +00:00
void RegionData_Impl : : DeleteEntry ( ULONG nIndex )
2000-11-27 07:55:57 +00:00
{
EntryData_Impl * pEntry = maEntries . GetObject ( nIndex ) ;
if ( pEntry )
{
delete pEntry ;
maEntries . Remove ( ( ULONG ) nIndex ) ;
}
}
// -----------------------------------------------------------------------
2000-12-06 10:14:36 +00:00
int RegionData_Impl : : Compare ( RegionData_Impl * pCompare ) const
2000-11-27 07:55:57 +00:00
{
2000-12-07 09:12:29 +00:00
int nCompare = maTitle . compareTo ( pCompare - > maTitle ) ;
2000-11-27 07:55:57 +00:00
return nCompare ;
}
2000-12-07 09:12:29 +00:00
// -----------------------------------------------------------------------
void RegionData_Impl : : ResetFlags ( )
{
mbInUse = sal_False ;
mbNew = sal_False ;
EntryData_Impl * pData = maEntries . First ( ) ;
while ( pData )
{
pData - > ResetFlags ( ) ;
pData = maEntries . Next ( ) ;
}
}
// -----------------------------------------------------------------------
void RegionData_Impl : : RemoveUnused ( )
{
ULONG nCount = maEntries . Count ( ) ;
EntryData_Impl * pData ;
while ( nCount )
{
pData = maEntries . GetObject ( - - nCount ) ;
if ( ! pData - > IsInUse ( ) )
{
pData - > RemoveEntry ( ) ;
maEntries . Remove ( nCount ) ;
delete pData ;
}
}
}
// -----------------------------------------------------------------------
void RegionData_Impl : : RemoveRegion ( )
{
Content aRegion ;
try
{
Reference < XCommandEnvironment > aCmdEnv ;
aRegion = Content ( maOwnURL , aCmdEnv ) ;
OUString aCmd ( RTL_CONSTASCII_USTRINGPARAM ( COMMAND_DELETE ) ) ;
Any aArg = makeAny ( sal_Bool ( sal_True ) ) ;
aRegion . executeCommand ( aCmd , aArg ) ;
}
catch ( CommandAbortedException & ) { }
catch ( RuntimeException & ) { }
catch ( Exception & ) { }
}
2000-11-27 07:55:57 +00:00
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
SfxDocTemplate_Impl : : SfxDocTemplate_Impl ( )
{
mbConstructed = sal_False ;
2000-12-06 10:14:36 +00:00
mbUpdating = sal_False ;
2000-11-27 07:55:57 +00:00
}
// -----------------------------------------------------------------------
SfxDocTemplate_Impl : : ~ SfxDocTemplate_Impl ( )
{
RegionData_Impl * pRegData = maRegions . First ( ) ;
while ( pRegData )
{
delete pRegData ;
pRegData = maRegions . Next ( ) ;
}
2000-12-04 09:32:11 +00:00
gpTemplateData = NULL ;
2000-11-27 07:55:57 +00:00
}
// -----------------------------------------------------------------------
RegionData_Impl * SfxDocTemplate_Impl : : GetRegion ( const OUString & rName )
const
{
2000-11-28 11:58:03 +00:00
ULONG nCount = maRegions . Count ( ) ;
2000-11-27 07:55:57 +00:00
RegionData_Impl * pData ;
2000-11-28 11:58:03 +00:00
for ( ULONG i = 0 ; i < nCount ; i + + )
2000-11-27 07:55:57 +00:00
{
pData = maRegions . GetObject ( i ) ;
2000-12-07 09:12:29 +00:00
if ( pData - > GetTitle ( ) = = rName )
2000-11-27 07:55:57 +00:00
return pData ;
}
return NULL ;
}
// -----------------------------------------------------------------------
RegionData_Impl * SfxDocTemplate_Impl : : GetRegionByPath (
const String & rName ) const
{
2000-11-28 11:58:03 +00:00
ULONG nCount = maRegions . Count ( ) ;
2000-11-27 07:55:57 +00:00
OUString aCompare ( rName ) ;
RegionData_Impl * pData ;
2000-11-28 11:58:03 +00:00
for ( ULONG i = 0 ; i < nCount ; i + + )
2000-11-27 07:55:57 +00:00
{
pData = maRegions . GetObject ( i ) ;
if ( pData - > GetTargetURL ( ) = = aCompare )
return pData ;
}
return NULL ;
}
// -----------------------------------------------------------------------
2000-11-28 11:58:03 +00:00
RegionData_Impl * SfxDocTemplate_Impl : : GetRegion ( ULONG nIndex ) const
2000-11-27 07:55:57 +00:00
{
return maRegions . GetObject ( nIndex ) ;
}
// -----------------------------------------------------------------------
2000-11-28 11:58:03 +00:00
void SfxDocTemplate_Impl : : DeleteRegion ( ULONG nIndex )
2000-11-27 07:55:57 +00:00
{
RegionData_Impl * pRegion = maRegions . GetObject ( nIndex ) ;
if ( pRegion )
{
delete pRegion ;
maRegions . Remove ( ( ULONG ) nIndex ) ;
}
}
// -----------------------------------------------------------------------
2000-12-06 10:14:36 +00:00
/* AddRegion adds a Region to the RegionList
*/
2000-11-27 07:55:57 +00:00
void SfxDocTemplate_Impl : : AddRegion ( const OUString & rTitle ,
const OUString & rTargetURL ,
Content & rContent )
{
RegionData_Impl * pRegion ;
2000-12-07 09:12:29 +00:00
pRegion = new RegionData_Impl ( rTitle ) ;
2000-11-27 07:55:57 +00:00
pRegion - > SetHierarchyContent ( rContent ) ;
pRegion - > SetTargetURL ( rTargetURL ) ;
pRegion - > SetHierarchyURL ( rContent . get ( ) - > getIdentifier ( ) - > getContentIdentifier ( ) ) ;
2000-12-06 10:14:36 +00:00
if ( InsertOrMarkRegion ( pRegion ) )
{
delete pRegion ;
return ;
}
2000-11-27 07:55:57 +00:00
// now get the content of the region
Reference < XResultSet > xResultSet ;
Sequence < OUString > aProps ( 2 ) ;
OUString * pProps = aProps . getArray ( ) ;
pProps [ 0 ] = OUString : : createFromAscii ( TITLE ) ;
pProps [ 1 ] = OUString : : createFromAscii ( TARGET_URL ) ;
try
{
ResultSetInclude eInclude = INCLUDE_DOCUMENTS_ONLY ;
xResultSet = rContent . createCursor ( aProps , eInclude ) ;
}
catch ( CommandAbortedException & )
{
DBG_ERRORFILE ( " createCursor: CommandAbortedException " ) ;
}
2000-12-06 10:14:36 +00:00
catch ( Exception & ) { }
2000-11-27 07:55:57 +00:00
if ( xResultSet . is ( ) )
{
Reference < XCommandEnvironment > aCmdEnv ;
Reference < XContentAccess > xContentAccess ( xResultSet , UNO_QUERY ) ;
Reference < XRow > xRow ( xResultSet , UNO_QUERY ) ;
try
{
while ( xResultSet - > next ( ) )
{
OUString aTitle ( xRow - > getString ( 1 ) ) ;
OUString aTargetDir ( xRow - > getString ( 2 ) ) ;
pRegion - > AddEntry ( rContent , aTitle , aTargetDir ) ;
}
}
catch ( CommandAbortedException & )
{
DBG_ERRORFILE ( " XContentAccess::next(): CommandAbortedException " ) ;
}
2000-12-06 10:14:36 +00:00
catch ( Exception & ) { }
2000-11-27 07:55:57 +00:00
}
}
// -----------------------------------------------------------------------
void SfxDocTemplate_Impl : : CreateFromHierarchy ( Content & rTemplRoot )
{
Reference < XResultSet > xResultSet ;
2000-12-07 12:32:03 +00:00
Sequence < OUString > aProps ( 2 ) ;
2000-11-27 07:55:57 +00:00
OUString * pProps = aProps . getArray ( ) ;
pProps [ 0 ] = OUString : : createFromAscii ( TITLE ) ;
pProps [ 1 ] = OUString : : createFromAscii ( TARGET_DIR_URL ) ;
try
{
ResultSetInclude eInclude = INCLUDE_FOLDERS_ONLY ;
xResultSet = rTemplRoot . createCursor ( aProps , eInclude ) ;
}
catch ( CommandAbortedException & )
{
DBG_ERRORFILE ( " createCursor: CommandAbortedException " ) ;
}
2000-12-06 10:14:36 +00:00
catch ( Exception & ) { }
2000-11-27 07:55:57 +00:00
if ( xResultSet . is ( ) )
{
Reference < XCommandEnvironment > aCmdEnv ;
Reference < XContentAccess > xContentAccess ( xResultSet , UNO_QUERY ) ;
Reference < XRow > xRow ( xResultSet , UNO_QUERY ) ;
try
{
while ( xResultSet - > next ( ) )
{
OUString aTitle ( xRow - > getString ( 1 ) ) ;
OUString aTargetDir ( xRow - > getString ( 2 ) ) ;
OUString aId = xContentAccess - > queryContentIdentifierString ( ) ;
Content aContent = Content ( aId , aCmdEnv ) ;
2000-12-07 09:12:29 +00:00
AddRegion ( aTitle , aTargetDir , aContent ) ;
2000-11-27 07:55:57 +00:00
}
}
catch ( CommandAbortedException & )
{
DBG_ERRORFILE ( " XContentAccess::next(): CommandAbortedException " ) ;
}
2000-12-06 10:14:36 +00:00
catch ( Exception & ) { }
2000-11-27 07:55:57 +00:00
}
}
// ------------------------------------------------------------------------
void SfxDocTemplate_Impl : : Construct ( const String & rDirs )
{
: : osl : : MutexGuard aGuard ( maMutex ) ;
2000-11-30 15:43:40 +00:00
mxFactory = : : comphelper : : getProcessServiceFactory ( ) ;
2000-11-27 07:55:57 +00:00
if ( mbConstructed )
return ;
Content aTemplRoot ;
sal_Bool bNewRoot ;
2000-12-06 10:14:36 +00:00
maDirs = rDirs ;
2000-11-27 07:55:57 +00:00
if ( ! GetTemplateRoot ( aTemplRoot , bNewRoot ) )
{
DBG_ERRORFILE ( " CreateTemplateHier(): Could not find/create template root " ) ;
return ;
}
2000-12-06 10:14:36 +00:00
mbConstructed = sal_True ;
ReadFolderList ( ) ;
2000-12-08 07:46:50 +00:00
if ( bNewRoot )
Rescan ( sal_False ) ;
else
CreateFromHierarchy ( aTemplRoot ) ;
2000-11-27 07:55:57 +00:00
}
// -----------------------------------------------------------------------
sal_Bool SfxDocTemplate_Impl : : GetTemplateRoot ( Content & rTemplRoot ,
sal_Bool & rNew ) const
{
Reference < XCommandEnvironment > aCmdEnv ;
OUString aTemplRootURL ( RTL_CONSTASCII_USTRINGPARAM ( TEMPLATE_ROOT_URL ) ) ;
sal_Bool bRet = sal_False ;
rNew = sal_False ;
try
{
rTemplRoot = Content ( aTemplRootURL , aCmdEnv ) ;
bRet = sal_True ;
}
catch ( ContentCreationException & )
{
OUString aHierRootURL ( RTL_CONSTASCII_USTRINGPARAM ( HIERARCHIE_ROOT_URL ) ) ;
Sequence < OUString > aNames ( 2 ) ;
OUString * pNames = aNames . getArray ( ) ;
pNames [ 0 ] = OUString ( RTL_CONSTASCII_USTRINGPARAM ( TITLE ) ) ;
pNames [ 1 ] = OUString ( RTL_CONSTASCII_USTRINGPARAM ( IS_FOLDER ) ) ;
Sequence < Any > aValues ( 2 ) ;
Any * pValues = aValues . getArray ( ) ;
pValues [ 0 ] = makeAny ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( TEMPLATE_DIR_NAME ) ) ) ;
pValues [ 1 ] = makeAny ( sal_Bool ( sal_True ) ) ;
try
{
Content aCnt ( aHierRootURL , aCmdEnv ) ;
OUString aType ( RTL_CONSTASCII_USTRINGPARAM ( TYPE_FOLDER ) ) ;
bRet = aCnt . insertNewContent ( aType , aNames , aValues , rTemplRoot ) ;
rNew = sal_True ;
}
catch ( CommandAbortedException & )
{
DBG_ERRORFILE ( " CommandAbortedException " ) ;
}
}
2000-12-06 10:14:36 +00:00
catch ( Exception & ) { }
2000-11-27 07:55:57 +00:00
return bRet ;
}
// -----------------------------------------------------------------------
sal_Bool SfxDocTemplate_Impl : : GetTemplateDir ( USHORT nIndex ,
Content & rTemplateDir ) const
{
Reference < XCommandEnvironment > aCmdEnv ;
INetURLObject aURL ;
sal_Bool bRet = sal_True ;
String aDir = maDirs . GetToken ( nIndex , C_DELIM ) ;
aURL . SetSmartProtocol ( INET_PROT_FILE ) ;
aURL . SetURL ( aDir ) ;
try
{
rTemplateDir = Content ( aURL . GetMainURL ( ) , aCmdEnv ) ;
}
catch ( ContentCreationException & )
{
DBG_ERRORFILE ( " GetTemplateDir(): Template directory doesn't exist " ) ;
bRet = sal_False ;
}
2000-12-06 10:14:36 +00:00
catch ( Exception & )
{ return FALSE ; }
2000-11-27 07:55:57 +00:00
return bRet ;
}
// -----------------------------------------------------------------------
void SfxDocTemplate_Impl : : GetFolders ( Content & rRoot ,
2000-12-07 09:12:29 +00:00
Content & rFolder )
2000-11-27 07:55:57 +00:00
{
Reference < XResultSet > xResultSet ;
Sequence < OUString > aProps ( 1 ) ;
OUString * pProps = aProps . getArray ( ) ;
pProps [ 0 ] = OUString : : createFromAscii ( TITLE ) ;
2000-12-06 10:14:36 +00:00
AddToStandard ( rRoot , rFolder ) ;
2000-11-27 07:55:57 +00:00
try
{
ResultSetInclude eInclude = INCLUDE_FOLDERS_ONLY ;
xResultSet = rFolder . createCursor ( aProps , eInclude ) ;
}
catch ( CommandAbortedException & )
{
DBG_ERRORFILE ( " createCursor: CommandAbortedException " ) ;
}
2000-12-06 10:14:36 +00:00
catch ( Exception & ) { }
2000-11-27 07:55:57 +00:00
if ( xResultSet . is ( ) )
{
Reference < XCommandEnvironment > aCmdEnv ;
Reference < XContentAccess > xContentAccess ( xResultSet , UNO_QUERY ) ;
Reference < XRow > xRow ( xResultSet , UNO_QUERY ) ;
OUString aFolderURL = rFolder . get ( ) - > getIdentifier ( ) - > getContentIdentifier ( ) ;
OUString aRootURL = rRoot . get ( ) - > getIdentifier ( ) - > getContentIdentifier ( ) ;
aRootURL + = OUString ( ' / ' ) ;
Content aFolder ;
Sequence < OUString > aNames ( 2 ) ;
OUString * pNames = aNames . getArray ( ) ;
pNames [ 0 ] = OUString ( RTL_CONSTASCII_USTRINGPARAM ( TITLE ) ) ;
pNames [ 1 ] = OUString ( RTL_CONSTASCII_USTRINGPARAM ( IS_FOLDER ) ) ;
2000-12-07 12:32:03 +00:00
Sequence < OUString > aAdditionalProps ( 1 ) ;
2000-11-27 07:55:57 +00:00
pNames = aAdditionalProps . getArray ( ) ;
pNames [ 0 ] = OUString ( RTL_CONSTASCII_USTRINGPARAM ( TARGET_DIR_URL ) ) ;
Sequence < Any > aValues ( 2 ) ;
Any * pValues = aValues . getArray ( ) ;
OUString aType = OUString ( RTL_CONSTASCII_USTRINGPARAM ( TYPE_FOLDER ) ) ;
try
{
while ( xResultSet - > next ( ) )
{
OUString aTitle ( xRow - > getString ( 1 ) ) ;
if ( aTitle . compareToAscii ( " wizard " ) = = 0 )
continue ;
else if ( aTitle . compareToAscii ( " internal " ) = = 0 )
continue ;
2000-12-01 10:03:15 +00:00
aTitle = GetLongName ( aTitle ) ;
2000-12-04 08:28:29 +00:00
INetURLObject aNewFolderObj ( aRootURL ) ;
2000-12-07 09:12:29 +00:00
aNewFolderObj . insertName ( aTitle , false ,
2000-12-04 08:28:29 +00:00
INetURLObject : : LAST_SEGMENT , true ,
INetURLObject : : ENCODE_ALL ) ;
OUString aNewFolderURL = aNewFolderObj . GetMainURL ( ) ;
2000-11-27 07:55:57 +00:00
OUString aId = xContentAccess - > queryContentIdentifierString ( ) ;
try
{
aFolder = Content ( aNewFolderURL , aCmdEnv ) ;
}
catch ( ContentCreationException & )
{
2000-12-07 09:12:29 +00:00
pValues [ 0 ] = makeAny ( aTitle ) ;
2000-11-27 07:55:57 +00:00
pValues [ 1 ] = makeAny ( sal_Bool ( sal_True ) ) ;
try
{
rRoot . insertNewContent ( aType , aNames , aValues , aFolder ) ;
Reference < XPropertySetInfo > xPropSet = aFolder . getProperties ( ) ;
if ( xPropSet . is ( ) )
{
pNames = aAdditionalProps . getArray ( ) ;
if ( ! xPropSet - > hasPropertyByName ( pNames [ 0 ] ) )
{
Reference < XPropertyContainer > xFolderProp ( aFolder . get ( ) , UNO_QUERY ) ;
if ( xFolderProp . is ( ) )
{
try
{
xFolderProp - > addProperty ( pNames [ 0 ] , PropertyAttribute : : MAYBEVOID ,
makeAny ( aId ) ) ;
}
catch ( PropertyExistException & ) { }
catch ( IllegalTypeException & ) { DBG_ERRORFILE ( " IllegalTypeException " ) ; }
catch ( IllegalArgumentException & ) { DBG_ERRORFILE ( " IllegalArgumentException " ) ; }
}
}
2000-12-07 12:32:03 +00:00
Sequence < Any > aPropValues ( 1 ) ;
2000-11-27 07:55:57 +00:00
Any * pPropValues = aPropValues . getArray ( ) ;
pPropValues [ 0 ] = makeAny ( aId ) ;
aFolder . setPropertyValues ( aAdditionalProps , aPropValues ) ;
}
}
catch ( CommandAbortedException & )
{
DBG_ERRORFILE ( " CommandAbortedException " ) ;
}
}
2000-12-07 09:12:29 +00:00
RegionData_Impl * pRegion = GetRegion ( aTitle ) ;
2000-11-27 07:55:57 +00:00
2000-12-07 09:12:29 +00:00
if ( ! pRegion )
2000-11-27 07:55:57 +00:00
{
2000-12-07 09:12:29 +00:00
pRegion = new RegionData_Impl ( aTitle ) ;
pRegion - > SetTargetURL ( aId ) ;
pRegion - > SetHierarchyURL ( aNewFolderURL ) ;
2000-11-27 07:55:57 +00:00
}
2000-12-07 09:12:29 +00:00
InsertOrMarkRegion ( pRegion ) ;
Content aSubFolder ( xContentAccess - > queryContent ( ) , aCmdEnv ) ;
GetTemplates ( aSubFolder , aFolder , pRegion ) ;
2000-11-27 07:55:57 +00:00
}
}
catch ( CommandAbortedException & )
{
2000-12-04 12:36:58 +00:00
DBG_ERRORFILE ( " GetFolders::next(): CommandAbortedException " ) ;
2000-11-27 07:55:57 +00:00
}
2000-12-06 10:14:36 +00:00
catch ( Exception & ) { }
}
}
// -----------------------------------------------------------------------
void SfxDocTemplate_Impl : : AddToStandard ( Content & rRoot ,
Content & rFolder )
{
OUString aTitle ( RTL_CONSTASCII_USTRINGPARAM ( STANDARD_FOLDER ) ) ;
aTitle = GetLongName ( aTitle ) ;
OUString aRootURL = rRoot . get ( ) - > getIdentifier ( ) - > getContentIdentifier ( ) ;
2000-12-07 09:12:29 +00:00
OUString aFolderURL = rFolder . get ( ) - > getIdentifier ( ) - > getContentIdentifier ( ) ;
2000-12-06 10:14:36 +00:00
INetURLObject aNewFolderObj ( aRootURL ) ;
2000-12-07 09:12:29 +00:00
aNewFolderObj . insertName ( aTitle , false ,
2000-12-06 10:14:36 +00:00
INetURLObject : : LAST_SEGMENT , true ,
INetURLObject : : ENCODE_ALL ) ;
OUString aNewFolderURL = aNewFolderObj . GetMainURL ( ) ;
Content aFolder ;
try
{
Reference < XCommandEnvironment > aCmdEnv ;
aFolder = Content ( aNewFolderURL , aCmdEnv ) ;
}
catch ( ContentCreationException & )
{
2000-12-07 09:12:29 +00:00
OUString aType = OUString ( RTL_CONSTASCII_USTRINGPARAM ( TYPE_FOLDER ) ) ;
Sequence < OUString > aNames ( 2 ) ;
OUString * pNames = aNames . getArray ( ) ;
pNames [ 0 ] = OUString ( RTL_CONSTASCII_USTRINGPARAM ( TITLE ) ) ;
pNames [ 1 ] = OUString ( RTL_CONSTASCII_USTRINGPARAM ( IS_FOLDER ) ) ;
2000-12-07 12:32:03 +00:00
Sequence < OUString > aAdditionalProps ( 1 ) ;
2000-12-07 09:12:29 +00:00
pNames = aAdditionalProps . getArray ( ) ;
pNames [ 0 ] = OUString ( RTL_CONSTASCII_USTRINGPARAM ( TARGET_DIR_URL ) ) ;
Sequence < Any > aValues ( 2 ) ;
Any * pValues = aValues . getArray ( ) ;
2000-12-06 10:14:36 +00:00
pValues [ 0 ] = makeAny ( aTitle ) ;
pValues [ 1 ] = makeAny ( sal_Bool ( sal_True ) ) ;
try
{
rRoot . insertNewContent ( aType , aNames , aValues , aFolder ) ;
Reference < XPropertySetInfo > xPropSet = aFolder . getProperties ( ) ;
if ( xPropSet . is ( ) )
{
pNames = aAdditionalProps . getArray ( ) ;
if ( ! xPropSet - > hasPropertyByName ( pNames [ 0 ] ) )
{
Reference < XPropertyContainer > xFolderProp ( aFolder . get ( ) , UNO_QUERY ) ;
if ( xFolderProp . is ( ) )
{
try
{
xFolderProp - > addProperty ( pNames [ 0 ] , PropertyAttribute : : MAYBEVOID ,
makeAny ( aFolderURL ) ) ;
}
catch ( PropertyExistException & ) { }
catch ( IllegalTypeException & ) { DBG_ERRORFILE ( " IllegalTypeException " ) ; }
catch ( IllegalArgumentException & ) { DBG_ERRORFILE ( " IllegalArgumentException " ) ; }
}
}
2000-12-07 12:32:03 +00:00
Sequence < Any > aPropValues ( 1 ) ;
2000-12-06 10:14:36 +00:00
Any * pPropValues = aPropValues . getArray ( ) ;
pPropValues [ 0 ] = makeAny ( aFolderURL ) ;
aFolder . setPropertyValues ( aAdditionalProps , aPropValues ) ;
}
}
catch ( CommandAbortedException & )
{
DBG_ERRORFILE ( " CommandAbortedException " ) ;
}
}
2000-12-07 09:12:29 +00:00
RegionData_Impl * pRegion = GetRegion ( aTitle ) ;
2000-12-06 10:14:36 +00:00
2000-12-07 09:12:29 +00:00
if ( ! pRegion )
2000-12-06 10:14:36 +00:00
{
2000-12-07 09:12:29 +00:00
pRegion = new RegionData_Impl ( aTitle ) ;
pRegion - > SetTargetURL ( aFolderURL ) ;
pRegion - > SetHierarchyURL ( aNewFolderURL ) ;
InsertOrMarkRegion ( pRegion ) ;
}
else
{
pRegion - > SetInUse ( sal_True ) ;
2000-11-27 07:55:57 +00:00
}
2000-12-07 09:12:29 +00:00
GetTemplates ( rFolder , aFolder , pRegion ) ;
2000-11-27 07:55:57 +00:00
}
// -----------------------------------------------------------------------
void SfxDocTemplate_Impl : : GetTemplates ( Content & rTargetFolder ,
Content & rParentFolder ,
2000-12-07 09:12:29 +00:00
RegionData_Impl * pRegion )
2000-11-27 07:55:57 +00:00
{
Reference < XResultSet > xResultSet ;
Sequence < OUString > aProps ( 1 ) ;
OUString * pProps = aProps . getArray ( ) ;
pProps [ 0 ] = OUString : : createFromAscii ( TITLE ) ;
try
{
ResultSetInclude eInclude = INCLUDE_DOCUMENTS_ONLY ;
xResultSet = rTargetFolder . createCursor ( aProps , eInclude ) ;
}
catch ( CommandAbortedException & )
{
DBG_ERRORFILE ( " createCursor: CommandAbortedException " ) ;
}
2000-12-06 10:14:36 +00:00
catch ( Exception & ) { }
2000-11-27 07:55:57 +00:00
if ( xResultSet . is ( ) )
{
Reference < XContentAccess > xContentAccess ( xResultSet , UNO_QUERY ) ;
Reference < XRow > xRow ( xResultSet , UNO_QUERY ) ;
try
{
while ( xResultSet - > next ( ) )
{
OUString aTitle ( xRow - > getString ( 1 ) ) ;
2000-12-08 07:46:50 +00:00
if ( aTitle . compareToAscii ( " sfx.tlx " ) = = 0 )
continue ;
2000-11-27 07:55:57 +00:00
OUString aId = xContentAccess - > queryContentIdentifierString ( ) ;
2000-12-07 16:01:23 +00:00
EntryData_Impl * pEntry = pRegion - > GetByTargetURL ( aId ) ;
2000-11-30 15:43:40 +00:00
2000-12-07 16:01:23 +00:00
if ( pEntry )
pEntry - > SetInUse ( sal_True ) ;
else
2000-11-30 15:43:40 +00:00
{
2000-12-07 16:01:23 +00:00
OUString aFullTitle = GetTitleFromURL ( aId ) ;
if ( aFullTitle . len ( ) )
aTitle = aFullTitle ;
pEntry = pRegion - > AddEntry ( rParentFolder , aTitle , aId ) ;
if ( pEntry & & pEntry - > IsNew ( ) )
{
OUString aType = GetTypeFromURL ( aId ) ;
pEntry - > SetType ( aType ) ;
}
2000-11-30 15:43:40 +00:00
}
2000-11-27 07:55:57 +00:00
}
}
catch ( CommandAbortedException & )
{
DBG_ERRORFILE ( " XContentAccess::next(): CommandAbortedException " ) ;
}
2000-12-06 10:14:36 +00:00
catch ( Exception & ) { }
2000-11-27 07:55:57 +00:00
}
}
// -----------------------------------------------------------------------
long SfxDocTemplate_Impl : : GetRegionPos ( const OUString & rTitle ,
sal_Bool & rFound ) const
{
int nCompVal = 1 ;
long nStart = 0 ;
long nEnd = maRegions . Count ( ) - 1 ;
long nMid ;
RegionData_Impl * pMid ;
while ( nCompVal & & ( nStart < = nEnd ) )
{
nMid = ( nEnd - nStart ) / 2 + nStart ;
pMid = maRegions . GetObject ( nMid ) ;
nCompVal = pMid - > Compare ( rTitle ) ;
if ( nCompVal < 0 ) // pMid < pData
nStart = nMid + 1 ;
else
nEnd = nMid - 1 ;
}
if ( nCompVal = = 0 )
rFound = TRUE ;
else
{
if ( nCompVal < 0 ) // pMid < pData
nMid + + ;
rFound = sal_False ;
}
return nMid ;
}
// -----------------------------------------------------------------------
2000-12-06 10:14:36 +00:00
sal_Bool SfxDocTemplate_Impl : : InsertOrMarkRegion ( RegionData_Impl * pNew )
2000-11-27 07:55:57 +00:00
{
: : osl : : MutexGuard aGuard ( maMutex ) ;
2000-12-06 10:14:36 +00:00
RegionData_Impl * pData = maRegions . First ( ) ;
sal_Bool bFound ;
sal_Bool bSameName = sal_False ;
while ( pData & & ( pData - > Compare ( pNew ) ! = 0 ) )
pData = maRegions . Next ( ) ;
if ( pData )
{
bFound = sal_True ;
2000-12-07 09:12:29 +00:00
pData - > SetInUse ( sal_True ) ;
2000-12-06 10:14:36 +00:00
}
else
{
bFound = sal_False ;
2000-12-07 09:12:29 +00:00
pNew - > SetInUse ( sal_True ) ;
2000-12-06 10:14:36 +00:00
NamePair_Impl * pPair = maNames . First ( ) ;
if ( pNew - > GetTitle ( ) = = pPair - > maLongName )
maRegions . Insert ( pNew , ( ULONG ) 0 ) ;
else
maRegions . Insert ( pNew , LIST_APPEND ) ;
}
2000-11-27 07:55:57 +00:00
2000-12-06 10:14:36 +00:00
return bFound ;
// don't use binary search here, the region list isn't sorted
// at least, not in the moment
#if 0
int nCompVal = 1 ;
2000-11-27 07:55:57 +00:00
long nStart = 0 ;
long nEnd = maRegions . Count ( ) - 1 ;
long nMid ;
RegionData_Impl * pMid ;
while ( nCompVal & & ( nStart < = nEnd ) )
{
nMid = ( nEnd - nStart ) / 2 + nStart ;
pMid = maRegions . GetObject ( nMid ) ;
2000-12-06 10:14:36 +00:00
nCompVal = pMid - > Compare ( pNew /*, &bSameName */ ) ;
2000-11-27 07:55:57 +00:00
2000-12-06 10:14:36 +00:00
if ( nCompVal < 0 ) // pMid < pNew
2000-11-27 07:55:57 +00:00
nStart = nMid + 1 ;
else
nEnd = nMid - 1 ;
}
if ( nCompVal = = 0 )
{
bFound = TRUE ;
2000-12-07 09:12:29 +00:00
pMid - > SetInUse ( sal_True ) ;
2000-11-27 07:55:57 +00:00
}
else
{
2000-12-06 10:14:36 +00:00
if ( nCompVal < 0 ) // pMid < pNew
2000-11-27 07:55:57 +00:00
nMid + + ;
2000-12-06 10:14:36 +00:00
maRegions . Insert ( pNew , nMid ) ;
2000-11-27 07:55:57 +00:00
bFound = sal_False ;
}
return bFound ;
2000-12-06 10:14:36 +00:00
# endif
2000-11-27 07:55:57 +00:00
}
// -----------------------------------------------------------------------
sal_Bool SfxDocTemplate_Impl : : InsertNewRegionToHierarchy (
Content & rRoot ,
const OUString & rTitle ,
const OUString & rTargetURL ,
USHORT nIndex )
{
Reference < XCommandEnvironment > aCmdEnv ;
OUString aFolderURL = maDirs . GetToken ( nIndex , C_DELIM ) ;
OUString aRootURL = rRoot . get ( ) - > getIdentifier ( ) - > getContentIdentifier ( ) ;
aRootURL + = OUString ( ' / ' ) ;
Sequence < OUString > aNames ( 2 ) ;
Sequence < Any > aValues ( 2 ) ;
OUString * pNames = aNames . getArray ( ) ;
pNames [ 0 ] = OUString ( RTL_CONSTASCII_USTRINGPARAM ( TITLE ) ) ;
pNames [ 1 ] = OUString ( RTL_CONSTASCII_USTRINGPARAM ( IS_FOLDER ) ) ;
2000-12-07 12:32:03 +00:00
Sequence < OUString > aAdditionalProps ( 1 ) ;
2000-11-27 07:55:57 +00:00
pNames = aAdditionalProps . getArray ( ) ;
pNames [ 0 ] = OUString ( RTL_CONSTASCII_USTRINGPARAM ( TARGET_DIR_URL ) ) ;
OUString aType = OUString ( RTL_CONSTASCII_USTRINGPARAM ( TYPE_FOLDER ) ) ;
2000-12-07 09:12:29 +00:00
sal_Bool bExists = sal_False ;
2000-11-27 07:55:57 +00:00
2000-12-07 09:12:29 +00:00
//dv! hier muss ein URLObject benutzt werden
OUString aNewFolderURL = aRootURL + rTitle ;
2000-11-27 07:55:57 +00:00
Content aFolder ;
try
{
aFolder = Content ( aNewFolderURL , aCmdEnv ) ;
bExists = sal_True ;
}
catch ( ContentCreationException & )
{
Any * pValues = aValues . getArray ( ) ;
2000-12-07 09:12:29 +00:00
pValues [ 0 ] = makeAny ( rTitle ) ;
2000-11-27 07:55:57 +00:00
pValues [ 1 ] = makeAny ( sal_Bool ( sal_True ) ) ;
try
{
rRoot . insertNewContent ( aType , aNames , aValues , aFolder ) ;
Reference < XPropertySetInfo > xPropSet = aFolder . getProperties ( ) ;
if ( xPropSet . is ( ) )
{
pNames = aAdditionalProps . getArray ( ) ;
if ( ! xPropSet - > hasPropertyByName ( pNames [ 0 ] ) )
{
Reference < XPropertyContainer > xFolderProp ( aFolder . get ( ) , UNO_QUERY ) ;
if ( xFolderProp . is ( ) )
{
try
{
xFolderProp - > addProperty ( pNames [ 0 ] , PropertyAttribute : : MAYBEVOID ,
makeAny ( rTargetURL ) ) ;
}
catch ( PropertyExistException & ) { }
catch ( IllegalTypeException & ) { DBG_ERRORFILE ( " IllegalTypeException " ) ; }
catch ( IllegalArgumentException & ) { DBG_ERRORFILE ( " IllegalArgumentException " ) ; }
}
}
2000-12-07 12:32:03 +00:00
Sequence < Any > aPropValues ( 1 ) ;
2000-11-27 07:55:57 +00:00
Any * pPropValues = aPropValues . getArray ( ) ;
pPropValues [ 0 ] = makeAny ( rTargetURL ) ;
aFolder . setPropertyValues ( aAdditionalProps , aPropValues ) ;
}
}
catch ( CommandAbortedException & )
{
DBG_ERRORFILE ( " CommandAbortedException " ) ;
}
}
2000-12-06 10:14:36 +00:00
catch ( Exception & )
{ return FALSE ; }
2000-11-27 07:55:57 +00:00
if ( ! bExists )
{
2000-12-07 09:12:29 +00:00
RegionData_Impl * pRegion = new RegionData_Impl ( rTitle ) ;
2000-11-27 07:55:57 +00:00
pRegion - > SetTargetURL ( rTargetURL ) ;
pRegion - > SetHierarchyURL ( aNewFolderURL ) ;
bExists = InsertOrMarkRegion ( pRegion ) ;
if ( bExists )
{
delete pRegion ;
}
}
return bExists ;
}
// -----------------------------------------------------------------------
sal_Bool SfxDocTemplate_Impl : : InsertNewRegionToFolder (
Content & rRoot ,
const OUString & rTitle )
{
Reference < XCommandEnvironment > aCmdEnv ;
Sequence < OUString > aNames ( 2 ) ;
Sequence < Any > aValues ( 2 ) ;
OUString * pNames = aNames . getArray ( ) ;
pNames [ 0 ] = OUString ( RTL_CONSTASCII_USTRINGPARAM ( TITLE ) ) ;
pNames [ 1 ] = OUString ( RTL_CONSTASCII_USTRINGPARAM ( IS_FOLDER ) ) ;
Any * pValues = aValues . getArray ( ) ;
pValues [ 0 ] = makeAny ( rTitle ) ;
pValues [ 1 ] = makeAny ( sal_Bool ( sal_True ) ) ;
OUString aType = OUString ( RTL_CONSTASCII_USTRINGPARAM ( TYPE_FSYS_FOLDER ) ) ;
sal_Bool bExists = sal_False ;
Content aFolder ;
try
{
bExists = ! rRoot . insertNewContent ( aType , aNames , aValues , aFolder ) ;
}
catch ( CommandAbortedException & )
{
bExists = sal_True ;
DBG_ERRORFILE ( " CommandAbortedException " ) ;
}
2000-12-06 10:14:36 +00:00
catch ( Exception & )
{ return FALSE ; }
2000-11-27 07:55:57 +00:00
return bExists ;
}
2000-11-30 15:43:40 +00:00
// -----------------------------------------------------------------------
OUString SfxDocTemplate_Impl : : GetTypeFromURL ( const OUString & rURL )
{
# ifdef TF_FILTER
OUString aService ( RTL_CONSTASCII_USTRINGPARAM ( SERVICENAME_TYPEDETECTION ) ) ;
Reference < XTypeDetection > xTypeDetection ( mxFactory - > createInstance ( aService ) , UNO_QUERY ) ;
OUString aTypeName ;
if ( xTypeDetection . is ( ) = = sal_True )
{
// Build a new media descriptor.
// He will "walking" during all member of our type detection and loading process as an InOut-parameter!
// Every "user" can add or remove information about given document.
Sequence < PropertyValue > aValues ( 1 ) ;
PropertyValue * pValues = aValues . getArray ( ) ;
pValues - > Name = OUString ( RTL_CONSTASCII_USTRINGPARAM ( TYPEDETECTION_PARAMETER ) ) ;
pValues - > Value = makeAny ( rURL ) ;
// Try to get right type name for given descriptor.
// (Allow a deep detection by calling with "sal_True" - If no input stream already exist - every member of our detection process cann add him to the descriptor!)
aTypeName = xTypeDetection - > queryTypeByDescriptor ( aValues , sal_True ) ;
}
return aTypeName ;
# else
OUString aService ( RTL_CONSTASCII_USTRINGPARAM ( SERVICENAME_OLD_TYPEDETECTION ) ) ;
Reference < XFrameLoaderQuery > xTypeDetection ( mxFactory - > createInstance ( aService ) , UNO_QUERY ) ;
OUString aTypeName ;
if ( xTypeDetection . is ( ) = = sal_True )
{
Sequence < PropertyValue > aValues ( 1 ) ;
PropertyValue * pValues = aValues . getArray ( ) ;
pValues - > Name = OUString ( RTL_CONSTASCII_USTRINGPARAM ( PARAMETER_OLD_TYPEDETECTION ) ) ;
pValues - > Value = makeAny ( sal_Bool ( sal_True ) ) ;
aTypeName = xTypeDetection - > searchFilter ( rURL , aValues ) ;
}
return aTypeName ;
# endif
}
// -----------------------------------------------------------------------
OUString SfxDocTemplate_Impl : : GetTitleFromURL ( const OUString & rURL )
{
OUString aTitle ;
OUString aService ( RTL_CONSTASCII_USTRINGPARAM ( SERVICENAME_DOCINFO ) ) ;
Reference < XStandaloneDocumentInfo > xInfo ( mxFactory - > createInstance ( aService ) , UNO_QUERY ) ;
if ( xInfo . is ( ) )
{
try
{
xInfo - > loadFromURL ( rURL ) ;
Reference < XPropertySet > aPropSet ( xInfo , UNO_QUERY ) ;
if ( aPropSet . is ( ) )
{
OUString aPropName ( RTL_CONSTASCII_USTRINGPARAM ( TITLE ) ) ;
Any aValue = aPropSet - > getPropertyValue ( aPropName ) ;
aValue > > = aTitle ;
}
}
catch ( IOException & ) { }
catch ( UnknownPropertyException & ) { }
2000-12-06 10:14:36 +00:00
catch ( Exception & ) { }
2000-11-30 15:43:40 +00:00
}
return aTitle ;
}
2000-12-01 10:03:15 +00:00
// -----------------------------------------------------------------------
void SfxDocTemplate_Impl : : ReadFolderList ( )
{
ResStringArray aShortNames ( SfxResId ( TEMPLATE_SHORT_NAMES_ARY ) ) ;
ResStringArray aLongNames ( SfxResId ( TEMPLATE_LONG_NAMES_ARY ) ) ;
NamePair_Impl * pPair ;
USHORT nCount = Min ( aShortNames . Count ( ) , aLongNames . Count ( ) ) ;
for ( USHORT i = 0 ; i < nCount ; i + + )
{
pPair = new NamePair_Impl ;
pPair - > maShortName = aShortNames . GetString ( i ) ;
pPair - > maLongName = aLongNames . GetString ( i ) ;
maNames . Insert ( pPair , LIST_APPEND ) ;
}
}
// -----------------------------------------------------------------------
OUString SfxDocTemplate_Impl : : GetLongName ( const OUString & rShortName )
{
OUString aRet ;
NamePair_Impl * pPair = maNames . First ( ) ;
while ( pPair )
{
if ( pPair - > maShortName = = rShortName )
{
aRet = pPair - > maLongName ;
break ;
}
else
pPair = maNames . Next ( ) ;
}
if ( ! aRet . len ( ) )
aRet = rShortName ;
return aRet ;
}
2000-12-06 10:14:36 +00:00
// -----------------------------------------------------------------------
sal_Bool SfxDocTemplate_Impl : : Rescan ( sal_Bool bNow )
{
sal_Bool bRet = sal_True ;
if ( bNow )
{
2000-12-07 09:12:29 +00:00
bRet = DoUpdate ( ) ;
2000-12-06 10:14:36 +00:00
}
else
2000-12-07 09:12:29 +00:00
{
Updater_Impl * pThread = new Updater_Impl ( this ) ;
2000-12-06 10:14:36 +00:00
pThread - > create ( ) ;
2000-12-07 09:12:29 +00:00
}
return bRet ;
}
//------------------------------------------------------------------------
sal_Bool SfxDocTemplate_Impl : : DoUpdate ( )
{
sal_Bool bRet = sal_True ;
// First: reset the flags of all regions and their children
RegionData_Impl * pRegion = maRegions . First ( ) ;
while ( pRegion )
{
pRegion - > ResetFlags ( ) ;
pRegion = maRegions . Next ( ) ;
}
// Now scan all the folder in the template search path and mark
// them
Content aTemplRoot ;
sal_Bool bNewRoot ;
if ( ! GetTemplateRoot ( aTemplRoot , bNewRoot ) )
return sal_False ;
ULONG i ;
ULONG nCount = maDirs . GetTokenCount ( C_DELIM ) ;
for ( i = 0 ; i < nCount ; i + + )
{
Content aTemplDir ;
if ( GetTemplateDir ( ( USHORT ) i , aTemplDir ) )
GetFolders ( aTemplRoot , aTemplDir ) ;
}
// Now remove all non existing objects
nCount = GetRegionCount ( ) ;
while ( nCount )
{
pRegion = maRegions . GetObject ( - - nCount ) ;
if ( pRegion - > IsInUse ( ) )
pRegion - > RemoveUnused ( ) ;
else
{
pRegion - > RemoveRegion ( ) ;
maRegions . Remove ( nCount ) ;
delete pRegion ;
}
}
2000-12-06 10:14:36 +00:00
return bRet ;
}
//------------------------------------------------------------------------
//------------------------------------------------------------------------
//------------------------------------------------------------------------
Updater_Impl : : Updater_Impl ( SfxDocTemplate_Impl * pTemplates )
{
maDocTemplates = pTemplates ;
}
//------------------------------------------------------------------------
Updater_Impl : : ~ Updater_Impl ( )
{
maDocTemplates = NULL ;
}
//------------------------------------------------------------------------
void SAL_CALL Updater_Impl : : run ( )
{
2000-12-07 09:12:29 +00:00
maDocTemplates - > DoUpdate ( ) ;
2000-12-06 10:14:36 +00:00
}
//------------------------------------------------------------------------
void SAL_CALL Updater_Impl : : onTerminated ( )
{
delete this ;
}