2000-09-18 16:07:07 +00:00
/*************************************************************************
*
* $ RCSfile : doctempl . cxx , v $
*
2000-11-30 15:43:40 +00:00
* $ Revision : 1.6 $
2000-09-18 16:07:07 +00:00
*
2000-11-30 15:43:40 +00:00
* last change : $ Author : dv $ $ Date : 2000 - 11 - 30 16 : 43 : 40 $
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>
# if ! defined( MAC ) && ! defined( UNX )
# include <io.h>
# endif
# ifndef _COM_SUN_STAR_UNO_ANY_H_
# include <com/sun/star/uno/Any.h>
# endif
# ifndef _SYSTEM_HXX //autogen
# include <vcl/system.hxx>
# endif
# ifndef _MSGBOX_HXX //autogen
# include <vcl/msgbox.hxx>
# endif
# ifndef _SVSTOR_HXX //autogen
# include <so3/svstor.hxx>
# endif
# ifndef _SFXECODE_HXX
# include <svtools/sfxecode.hxx>
# endif
# ifndef _EHDL_HXX
# include <svtools/ehdl.hxx>
# 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-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"
2000-11-27 07:55:57 +00:00
# include "inimgr.hxx"
2000-09-18 16:07:07 +00:00
# include "sfxresid.hxx"
# include "docfilt.hxx"
# include "fltfnc.hxx"
# include "doc.hrc"
# include "ucbhelp.hxx"
# include "openflag.hxx"
2000-11-27 07:55:57 +00:00
# include "ucbhelp.hxx"
2000-09-18 16:07:07 +00:00
//========================================================================
const char __FAR_DATA pHeader [ ] = " Sfx Document Template Directory " ;
const char __FAR_DATA pFileFileName [ ] = " sfx.tpl " ;
const char __FAR_DATA pDirFileName [ ] = " sfx.tlx " ;
const char pMGName [ ] = " mg.bad " ;
const char cDefWildcard = ' * ' ;
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-11-30 15:43:40 +00:00
# define PROPERTY_TYPE "TypeDecription"
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 PARENT_DIR_URL "ParentDirURL"
# define REAL_NAME "RealName"
# define COMMAND_DELETE "delete"
# define COMMAND_TRANSFER "transfer"
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
{
OUString maTitle ;
OUString maOwnURL ;
OUString maTargetURL ;
sal_Bool mbChecked ;
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-11-27 07:55:57 +00:00
} ;
DECLARE_LIST ( EntryList_Impl , EntryData_Impl * ) ;
// ------------------------------------------------------------------------
class RegionData_Impl
{
EntryList_Impl maEntries ;
OUString maTitle ;
OUString maRealTitle ;
OUString maOwnURL ;
OUString maTargetURL ;
Content maTargetContent ;
Content maHierarchyContent ;
sal_Bool mbChecked ;
private :
long GetEntryPos ( const OUString & rTitle ,
sal_Bool & rFound ) const ;
public :
RegionData_Impl ( const OUString & rTitle ,
const OUString & rRealTitle ) ;
~ RegionData_Impl ( ) ;
EntryData_Impl * GetEntry ( const OUString & rName ) const ;
2000-11-28 11:58:03 +00:00
EntryData_Impl * GetEntry ( ULONG nIndex ) const ;
2000-11-27 07:55:57 +00:00
const OUString & GetTitle ( ) const { return maTitle ; }
const OUString & GetRealTitle ( ) const { return maRealTitle ; }
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 SetRealTitle ( const OUString & rTitle ) { maRealTitle = 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
void SetChecked ( sal_Bool bChecked ) { mbChecked = bChecked ; }
int Compare ( const OUString & rTitle ) const
{ return maTitle . compareTo ( rTitle ) ; }
int Compare ( RegionData_Impl * pCompareWith ,
sal_Bool * pbNamesAreEqual = NULL ) const ;
} ;
DECLARE_LIST ( RegionList_Impl , RegionData_Impl * ) ;
// ------------------------------------------------------------------------
class SfxDocTemplate_Impl
{
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 ;
long mnRefCount ;
sal_Bool mbConstructed ;
private :
sal_Bool InsertOrMarkRegion ( RegionData_Impl * pData ) ;
public :
SfxDocTemplate_Impl ( ) ;
~ SfxDocTemplate_Impl ( ) ;
void Construct ( const String & rDirURLs ) ;
sal_Bool Rescan ( ) ;
void CreateFromHierarchy ( Content & rTemplRoot ) ;
void AddRegion ( const OUString & rTitle ,
const OUString & rRealTitle ,
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 ;
void GetFolders ( Content & rRoot , Content & rFolder , ULONG nIndex ) ;
void GetTemplates ( Content & rTargetFolder ,
Content & rParentFolder ,
RegionData_Impl * pRegion ,
const OUString & rParentURL ) ;
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-11-27 07:55:57 +00:00
} ;
SfxDocTemplate_Impl * gpTemplateData = 0 ;
String gaEmptyString ;
// ------------------------------------------------------------------------
2000-09-18 16:07:07 +00:00
# define VERSION 4
// Wird nur noch gebraucht, um die Datein beim Scannen zu "uberspringen
// LongNameList_Impl needs this function, too!
const String FileName_Impl ( BOOL bDir )
{
return bDir ? String : : CreateFromAscii ( pDirFileName ) :
String : : CreateFromAscii ( pFileFileName ) ;
}
// ------------------------------------------------------------------------
class LongNameList_Impl : public List
{
List * mpNames ;
public :
LongNameList_Impl ( const String & rDirName ) ;
~ LongNameList_Impl ( ) ;
String GetLongName ( const String & rShortName ) const ;
BOOL ReadHeader ( SvStream & rStream ) const ;
} ;
//------------------------------------------------------------------------
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
#if 0
//dv!
2000-11-28 11:58:03 +00:00
void MakeFileName_Impl ( const String & rLongName , BOOL bDir )
2000-09-18 16:07:07 +00:00
{
String aFName ( rLongName ) ;
if ( ! bDir )
aFName + = DEFINE_CONST_UNICODE ( " .vor " ) ;
rEntry . MakeShortName ( aFName , FSYS_KIND_NONE ) ;
}
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
#if 0
//dv!
2000-09-18 16:07:07 +00:00
SfxObjectShellRef SfxTemplateDirEntry : : CreateObjectShell ( )
/* [Beschreibung]
Anlegen einer DokumentShell zu diesem Entry ; das Entry beinhaltet
den Dateinamen .
[ R " uckgabewert]
SfxObjectShellRef Referenz auf die DokumentShell
[ Querverweise ]
< SfxTemplateDirEntry : : DeleteObjectShell ( ) >
*/
{
if ( ! xObjShell . Is ( ) )
{
bIsOwner = FALSE ;
BOOL bDum = FALSE ;
SfxApplication * pSfxApp = SFX_APP ( ) ;
xObjShell = pSfxApp - > DocAlreadyLoaded ( GetFull ( ) . GetFull ( ) , TRUE , bDum ) ;
if ( ! xObjShell . Is ( ) )
{
bIsOwner = TRUE ;
SfxMedium * pMed = new SfxMedium (
2000-10-17 12:39:45 +00:00
GetFull ( ) . GetFull ( ) , ( STREAM_READ | STREAM_SHARE_DENYWRITE ) , FALSE , 0 ) ;
2000-09-18 16:07:07 +00:00
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 ,
GetFull ( ) . GetFull (
FSYS_STYLE_HOST , FALSE , 20 ) ) ;
delete pMed ;
bDidConvert = TRUE ;
ULONG lErr ;
if ( xObjShell . Is ( ) )
if ( lErr = ( pSfxApp - > LoadTemplate (
xObjShell , GetFull ( ) . GetFull ( ) ) ! = ERRCODE_NONE ) )
ErrorHandler : : HandleError ( lErr ) ;
}
else
{
const SfxObjectFactory & rFactory =
( ( SfxFactoryFilterContainer * ) pFilter - > GetFilterContainer ( ) )
- > GetFactory ( ) ;
delete pMed ;
bDidConvert = FALSE ;
xStor = new SvStorage (
GetFull ( ) . GetFull ( ) ,
STREAM_READWRITE | STREAM_NOCREATE |
STREAM_SHARE_DENYALL , STORAGE_TRANSACTED ) ;
if ( pFilter )
xStor - > SetVersion ( pFilter - > GetVersion ( ) ) ;
if ( SVSTREAM_OK = = xStor - > GetError ( ) )
{
xObjShell = ( SfxObjectShell * )
rFactory . CreateObject ( SFX_CREATE_MODE_ORGANIZER ) ;
if ( xObjShell . Is ( ) )
{
xObjShell - > DoInitNew ( 0 ) ;
if ( ! xObjShell - > LoadFrom ( xStor ) )
xObjShell . Clear ( ) ;
else
{
xObjShell - > DoHandsOff ( ) ;
xObjShell - > DoSaveCompleted ( xStor ) ;
}
}
}
}
}
}
return ( SfxObjectShellRef ) ( SfxObjectShell * ) xObjShell ;
}
//------------------------------------------------------------------------
BOOL SfxTemplateDirEntry : : DeleteObjectShell ( )
/* [Beschreibung]
" oschen der DokumentShell dieses Entrys, sofern eine DokumentShell
angelegt wurde
[ R " uckgabewert]
BOOL FALSE : es ist ein Fehler beim Speichern aufgetreten ;
TRUE : das Dokument wurde gespeichert
[ Querverweise ]
< SfxTemplateDirEntry : : CreateObjectShell ( ) >
*/
{
BOOL bRet = TRUE ;
if ( xObjShell . Is ( ) )
{
if ( xObjShell - > IsModified ( ) )
{
//Hier speichern wir auch, falls die Vorlage in Bearbeitung ist...
bRet = FALSE ;
if ( bIsOwner )
if ( bDidConvert )
{
bRet = xObjShell - > PreDoSaveAs_Impl (
GetFull ( ) . GetFull ( ) ,
xObjShell - > GetFactory ( ) . GetFilter ( 0 ) - > GetName ( ) , 0 ) ;
}
else
{
if ( xObjShell - > Save ( ) )
bRet = xStor - > Commit ( ) ;
else
bRet = FALSE ;
}
}
if ( bRet )
{
xObjShell . Clear ( ) ;
xStor . Clear ( ) ;
}
}
return bRet ;
}
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
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 )
aName = pData1 - > GetRealTitle ( ) ;
/* 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 ) & &
( pData2 - > GetRealTitle ( ) = = 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 )
maTmpString = pData - > GetRealTitle ( ) ;
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 ; }
catch ( . . . )
{ return FALSE ; }
// 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
USHORT nSourceIdx /* Index der zu kopierenden / z uverschiebenden
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 ( ) ;
OUString aParentURL = aTargetURL . GetFull ( ) ;
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 ; }
catch ( . . . )
{ return FALSE ; }
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 ; }
catch ( . . . )
{ 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 ;
}
catch ( . . . )
{
DBG_ERRORFILE ( " Any Other Exception! " ) ;
return bRet ;
}
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 ;
}
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 aRealTitle ( 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-11-27 07:55:57 +00:00
sal_Bool bSetRealTitle ( sal_False ) ;
if ( nIdx = = USHRT_MAX )
2000-09-18 16:07:07 +00:00
{
2000-11-27 07:55:57 +00:00
sal_Int32 nStart = pRegion - > GetRealTitle ( ) . getLength ( ) ;
aTitle + = pRegion - > GetTitle ( ) . copy ( nStart ) ;
bSetRealTitle = sal_True ;
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 )
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 ) ) ;
if ( bSetRealTitle )
{
OUString aPropName ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( REAL_NAME ) ) ) ;
aHierCont . setPropertyValue ( aPropName , makeAny ( aRealTitle ) ) ;
}
aHierURL = aHierCont . get ( ) - > getIdentifier ( ) - > getContentIdentifier ( ) ;
}
catch ( ContentCreationException & )
{
DBG_ERRORFILE ( " Hierarchy object doesn't exist? " ) ;
return FALSE ;
}
catch ( . . . )
{
DBG_ERRORFILE ( " Any other exception " ) ;
return FALSE ;
}
// Create a folder Content with the old title and
// rename it
try
{
aFolderCont = Content ( aFolderURL , aCmdEnv ) ;
aFolderCont . setPropertyValue ( aTitleStr , makeAny ( aRealTitle ) ) ;
aFolderURL = aFolderCont . get ( ) - > getIdentifier ( ) - > getContentIdentifier ( ) ;
}
catch ( ContentCreationException & )
{
DBG_ERRORFILE ( " Folder object doesn't exist? " ) ;
return FALSE ;
}
catch ( . . . )
{
DBG_ERRORFILE ( " Any other exception " ) ;
return FALSE ;
2000-09-18 16:07:07 +00:00
}
2000-11-27 07:55:57 +00:00
// Update the internal data structures
if ( pEntry )
{
pEntry - > SetTitle ( aRealTitle ) ;
pEntry - > SetTargetURL ( aFolderURL ) ;
pEntry - > SetHierarchyURL ( aHierURL ) ;
}
else
{
pRegion - > SetTitle ( aTitle ) ;
pRegion - > SetRealTitle ( aRealTitle ) ;
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-11-27 07:55:57 +00:00
return FALSE ;
#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-11-27 07:55:57 +00:00
return NULL ;
#if 0 //dv!
2000-09-18 16:07:07 +00:00
DBG_ASSERT ( pDirs , " not initialized " ) ;
return ( * pDirs ) [ nRegion ] - > GetContent ( ) [ nIdx ] - > CreateObjectShell ( ) ;
2000-11-27 07:55:57 +00:00
# endif
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-11-27 07:55:57 +00:00
#if 0
2000-09-18 16:07:07 +00:00
DBG_ASSERT ( pDirs , " not initialized " ) ;
return ( * pDirs ) [ nRegion ] - > GetContent ( ) [ nIdx ] - > DeleteObjectShell ( ) ;
2000-11-27 07:55:57 +00:00
# endif
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 ( ) ;
OUString aPathTo = aFullPath . GetFull ( ) ;
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 )
{
rRegion = pData - > GetRealTitle ( ) ;
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-11-27 07:55:57 +00:00
if ( ! pImp )
pImp = new SfxDocTemplate_Impl ;
pImp - > Construct ( aDirs ) ;
2000-09-18 16:07:07 +00:00
}
//------------------------------------------------------------------------
SfxDocumentTemplates : : ~ SfxDocumentTemplates ( )
/* [Beschreibung]
Destruktor
Freigeben der Verwaltungsdaten
*/
{
2000-11-28 11:58:03 +00:00
delete pImp ;
2000-09-18 16:07:07 +00:00
}
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
struct LongNameListRec
{
String maShortName ;
String maLongName ;
LongNameListRec ( const String & rShort ,
const String & rLong )
: maShortName ( rShort )
, maLongName ( rLong )
{ }
} ;
// ------------------------------------------------------------------------
LongNameList_Impl : : LongNameList_Impl ( const String & rDirName )
{
String aName = rDirName ;
aName . Append ( FileName_Impl ( TRUE ) ) ;
mpNames = 0 ;
SfxMedium aMedium ( aName , STREAM_STD_READ , TRUE ) ;
SvStream * pStream = aMedium . GetInStream ( ) ;
if ( pStream )
{
char cDir ;
USHORT nCount , i ;
ByteString aLongName ; // logischer Name des Benutzers
ByteString aFileName ; // Dateiname (ohne Pfad)
LongNameListRec * pNew ;
if ( ! ReadHeader ( * pStream ) )
return ;
* pStream > > cDir ;
* pStream > > nCount ;
mpNames = new List ( nCount , 10 ) ;
CharSet eCharSet = pStream - > GetStreamCharSet ( ) ;
for ( i = 0 ; i < nCount ; + + i )
{
pStream - > ReadByteString ( aLongName ) ;
pStream - > ReadByteString ( aFileName ) ;
pNew = new LongNameListRec ( String ( aFileName , eCharSet ) ,
String ( aLongName , eCharSet ) ) ;
mpNames - > Insert ( pNew ) ;
}
}
}
// ------------------------------------------------------------------------
LongNameList_Impl : : ~ LongNameList_Impl ( )
{
if ( mpNames )
{
LongNameListRec * pData = ( LongNameListRec * ) mpNames - > First ( ) ;
while ( pData )
{
delete pData ;
pData = ( LongNameListRec * ) mpNames - > Next ( ) ;
}
delete mpNames ;
}
}
// ------------------------------------------------------------------------
String LongNameList_Impl : : GetLongName ( const String & rShortName ) const
{
String aLongName ;
LongNameListRec * pData ;
if ( mpNames )
pData = ( LongNameListRec * ) mpNames - > First ( ) ;
else
pData = NULL ;
while ( pData )
{
if ( pData - > maShortName = = rShortName )
{
aLongName = pData - > maLongName ;
break ;
}
else
pData = ( LongNameListRec * ) mpNames - > Next ( ) ;
}
return aLongName ;
}
// ------------------------------------------------------------------------
BOOL LongNameList_Impl : : ReadHeader ( SvStream & rStream ) const
{
ByteString aHeader ;
USHORT nUS = strlen ( pHeader ) ;
USHORT nVersion ;
CharSet eCharSet ;
char c ;
rStream . Read ( aHeader . AllocBuffer ( nUS ) , nUS ) ;
rStream > > c > > nVersion > > nUS ;
// CharSet einlesen und am Stream setzen
eCharSet = ( CharSet ) nUS ;
rStream . SetStreamCharSet ( eCharSet ) ;
if ( aHeader ! = pHeader )
return FALSE ;
if ( nVersion ! = VERSION )
return FALSE ;
return TRUE ;
}
2000-11-27 07:55:57 +00:00
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
EntryData_Impl : : EntryData_Impl ( const OUString & rTitle )
{
maTitle = rTitle ;
mbChecked = sal_False ;
}
// -----------------------------------------------------------------------
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 ) ;
}
}
catch ( . . . )
{
}
}
2000-11-27 07:55:57 +00:00
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
RegionData_Impl : : RegionData_Impl ( const OUString & rTitle ,
const OUString & rRealTitle )
{
maTitle = rTitle ;
maRealTitle = rRealTitle ;
mbChecked = sal_False ;
}
// -----------------------------------------------------------------------
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 ) ;
}
catch ( ContentCreationException & )
{ }
catch ( . . . )
{ DBG_ERRORFILE ( " Any other exception " ) ; }
}
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 ;
OUString aLinkURL ( RTL_CONSTASCII_USTRINGPARAM ( TEMPLATE_ROOT_URL ) ) ;
aLinkURL + = OUString ( ' / ' ) + maTitle + OUString ( ' / ' ) + rTitle ;
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
}
catch ( . . . )
{
DBG_ERRORFILE ( " Any other exception " ) ;
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
}
catch ( . . . )
{
DBG_ERRORFILE ( " Any other exception " ) ;
2000-11-30 15:43:40 +00:00
return NULL ;
2000-11-27 07:55:57 +00:00
}
}
EntryData_Impl * pEntry = new EntryData_Impl ( rTitle ) ;
pEntry - > SetTargetURL ( rTargetURL ) ;
pEntry - > SetHierarchyURL ( aLinkURL ) ;
sal_Bool bFound = sal_False ;
long nPos = GetEntryPos ( pEntry - > GetTitle ( ) , bFound ) ;
if ( ! bFound )
maEntries . Insert ( pEntry , nPos ) ;
2000-11-30 15:43:40 +00:00
else
{
delete pEntry ;
pEntry = maEntries . GetObject ( nPos ) ;
}
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-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 ) ;
}
}
// -----------------------------------------------------------------------
int RegionData_Impl : : Compare ( RegionData_Impl * pCompare ,
sal_Bool * pbNamesAreEqual ) const
{
int nCompare = maRealTitle . compareTo ( pCompare - > maRealTitle ) ;
if ( nCompare = = 0 )
{
if ( pbNamesAreEqual )
* pbNamesAreEqual = sal_True ;
nCompare = maTargetURL . compareTo ( pCompare - > maTargetURL ) ;
}
return nCompare ;
}
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
SfxDocTemplate_Impl : : SfxDocTemplate_Impl ( )
{
mnRefCount = 0 ;
mbConstructed = sal_False ;
}
// -----------------------------------------------------------------------
SfxDocTemplate_Impl : : ~ SfxDocTemplate_Impl ( )
{
RegionData_Impl * pRegData = maRegions . First ( ) ;
while ( pRegData )
{
delete pRegData ;
pRegData = maRegions . Next ( ) ;
}
}
// -----------------------------------------------------------------------
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 ) ;
if ( pData - > GetRealTitle ( ) = = rName )
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 ) ;
}
}
// -----------------------------------------------------------------------
void SfxDocTemplate_Impl : : AddRegion ( const OUString & rTitle ,
const OUString & rRealTitle ,
const OUString & rTargetURL ,
Content & rContent )
{
RegionData_Impl * pRegion ;
pRegion = new RegionData_Impl ( rTitle , rRealTitle ) ;
pRegion - > SetHierarchyContent ( rContent ) ;
pRegion - > SetTargetURL ( rTargetURL ) ;
pRegion - > SetHierarchyURL ( rContent . get ( ) - > getIdentifier ( ) - > getContentIdentifier ( ) ) ;
InsertOrMarkRegion ( pRegion ) ;
// 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 " ) ;
}
catch ( . . . )
{
DBG_ERRORFILE ( " createCursor: Any other exception " ) ;
}
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 " ) ;
}
catch ( . . . )
{
DBG_ERRORFILE ( " XContentAccess::next(): Any other exception " ) ;
}
}
}
// -----------------------------------------------------------------------
void SfxDocTemplate_Impl : : CreateFromHierarchy ( Content & rTemplRoot )
{
Reference < XResultSet > xResultSet ;
Sequence < OUString > aProps ( 4 ) ;
OUString * pProps = aProps . getArray ( ) ;
pProps [ 0 ] = OUString : : createFromAscii ( TITLE ) ;
pProps [ 1 ] = OUString : : createFromAscii ( TARGET_DIR_URL ) ;
pProps [ 2 ] = OUString : : createFromAscii ( PARENT_DIR_URL ) ;
pProps [ 3 ] = OUString : : createFromAscii ( REAL_NAME ) ;
try
{
ResultSetInclude eInclude = INCLUDE_FOLDERS_ONLY ;
xResultSet = rTemplRoot . createCursor ( aProps , eInclude ) ;
}
catch ( CommandAbortedException & )
{
DBG_ERRORFILE ( " createCursor: CommandAbortedException " ) ;
}
catch ( . . . )
{
DBG_ERRORFILE ( " createCursor: Any other exception " ) ;
}
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 aParentDir ( xRow - > getString ( 3 ) ) ;
OUString aRealTitle ( xRow - > getString ( 4 ) ) ;
OUString aId = xContentAccess - > queryContentIdentifierString ( ) ;
Content aContent = Content ( aId , aCmdEnv ) ;
AddRegion ( aTitle , aRealTitle , aTargetDir , aContent ) ;
}
}
catch ( CommandAbortedException & )
{
DBG_ERRORFILE ( " XContentAccess::next(): CommandAbortedException " ) ;
}
catch ( . . . )
{
DBG_ERRORFILE ( " XContentAccess::next(): Any other exception " ) ;
}
}
}
// ------------------------------------------------------------------------
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 ;
else
mbConstructed = sal_True ;
maDirs = rDirs ;
Content aTemplRoot ;
sal_Bool bNewRoot ;
if ( ! GetTemplateRoot ( aTemplRoot , bNewRoot ) )
{
DBG_ERRORFILE ( " CreateTemplateHier(): Could not find/create template root " ) ;
return ;
}
if ( bNewRoot )
{
2000-11-28 11:58:03 +00:00
USHORT i ;
USHORT nCount = rDirs . GetTokenCount ( C_DELIM ) ;
2000-11-27 07:55:57 +00:00
for ( i = 0 ; i < nCount ; i + + )
{
Content aTemplDir ;
if ( GetTemplateDir ( i , aTemplDir ) )
GetFolders ( aTemplRoot , aTemplDir , i ) ;
}
}
else
CreateFromHierarchy ( aTemplRoot ) ;
}
// -----------------------------------------------------------------------
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 " ) ;
}
catch ( . . . )
{
DBG_ERRORFILE ( " Any other exception " ) ;
}
}
catch ( . . . )
{
DBG_ERRORFILE ( " Any other exception " ) ;
}
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 ;
}
catch ( . . . )
{
DBG_ERRORFILE ( " Any other exception " ) ;
bRet = sal_False ;
}
return bRet ;
}
// -----------------------------------------------------------------------
void SfxDocTemplate_Impl : : GetFolders ( Content & rRoot ,
Content & rFolder ,
ULONG nIndex )
{
Reference < XResultSet > xResultSet ;
Sequence < OUString > aProps ( 1 ) ;
OUString * pProps = aProps . getArray ( ) ;
pProps [ 0 ] = OUString : : createFromAscii ( TITLE ) ;
try
{
ResultSetInclude eInclude = INCLUDE_FOLDERS_ONLY ;
xResultSet = rFolder . createCursor ( aProps , eInclude ) ;
}
catch ( CommandAbortedException & )
{
DBG_ERRORFILE ( " createCursor: CommandAbortedException " ) ;
}
catch ( . . . )
{
DBG_ERRORFILE ( " createCursor: Any other exception " ) ;
}
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 ( ' / ' ) ;
OUString aIndex ( ' . ' ) ;
aIndex + = OUString : : valueOf ( ( sal_Int32 ) nIndex ) ;
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 ) ) ;
Sequence < OUString > aAdditionalProps ( 3 ) ;
pNames = aAdditionalProps . getArray ( ) ;
pNames [ 0 ] = OUString ( RTL_CONSTASCII_USTRINGPARAM ( TARGET_DIR_URL ) ) ;
pNames [ 1 ] = OUString ( RTL_CONSTASCII_USTRINGPARAM ( PARENT_DIR_URL ) ) ;
pNames [ 2 ] = OUString ( RTL_CONSTASCII_USTRINGPARAM ( REAL_NAME ) ) ;
Sequence < Any > aValues ( 2 ) ;
Any * pValues = aValues . getArray ( ) ;
OUString aType = OUString ( RTL_CONSTASCII_USTRINGPARAM ( TYPE_FOLDER ) ) ;
try
{
while ( xResultSet - > next ( ) )
{
sal_Bool bWasInList ;
OUString aTitle ( xRow - > getString ( 1 ) ) ;
if ( aTitle . compareToAscii ( " wizard " ) = = 0 )
continue ;
else if ( aTitle . compareToAscii ( " internal " ) = = 0 )
continue ;
OUString aURLTitle = aTitle + aIndex ;
OUString aNewFolderURL = aRootURL + aURLTitle ;
OUString aId = xContentAccess - > queryContentIdentifierString ( ) ;
try
{
aFolder = Content ( aNewFolderURL , aCmdEnv ) ;
}
catch ( ContentCreationException & )
{
pValues [ 0 ] = makeAny ( aURLTitle ) ;
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 ) ) ;
xFolderProp - > addProperty ( pNames [ 1 ] , PropertyAttribute : : MAYBEVOID ,
makeAny ( aId ) ) ;
xFolderProp - > addProperty ( pNames [ 2 ] , PropertyAttribute : : MAYBEVOID ,
makeAny ( aTitle ) ) ;
}
catch ( PropertyExistException & ) { }
catch ( IllegalTypeException & ) { DBG_ERRORFILE ( " IllegalTypeException " ) ; }
catch ( IllegalArgumentException & ) { DBG_ERRORFILE ( " IllegalArgumentException " ) ; }
}
}
Sequence < Any > aPropValues ( 3 ) ;
Any * pPropValues = aPropValues . getArray ( ) ;
pPropValues [ 0 ] = makeAny ( aId ) ;
pPropValues [ 1 ] = makeAny ( aFolderURL ) ;
pPropValues [ 2 ] = makeAny ( aTitle ) ;
aFolder . setPropertyValues ( aAdditionalProps , aPropValues ) ;
}
}
catch ( CommandAbortedException & )
{
DBG_ERRORFILE ( " CommandAbortedException " ) ;
}
catch ( . . . )
{
DBG_ERRORFILE ( " Any other exception " ) ;
}
}
RegionData_Impl * pRegion = new RegionData_Impl ( aURLTitle , aTitle ) ;
pRegion - > SetTargetURL ( aId ) ;
pRegion - > SetHierarchyURL ( aNewFolderURL ) ;
bWasInList = InsertOrMarkRegion ( pRegion ) ;
Content aSubFolder ( xContentAccess - > queryContent ( ) , aCmdEnv ) ;
GetTemplates ( aSubFolder , aFolder , pRegion , aNewFolderURL ) ;
if ( bWasInList )
{
delete pRegion ;
}
}
}
catch ( CommandAbortedException & )
{
DBG_ERRORFILE ( " XContentAccess::next(): CommandAbortedException " ) ;
}
catch ( . . . )
{
DBG_ERRORFILE ( " XContentAccess::next(): Any other exception " ) ;
}
}
}
// -----------------------------------------------------------------------
void SfxDocTemplate_Impl : : GetTemplates ( Content & rTargetFolder ,
Content & rParentFolder ,
RegionData_Impl * pRegion ,
const OUString & rParentURL )
{
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 " ) ;
}
catch ( . . . )
{
DBG_ERRORFILE ( " createCursor: Any other exception " ) ;
}
if ( xResultSet . is ( ) )
{
Reference < XContentAccess > xContentAccess ( xResultSet , UNO_QUERY ) ;
Reference < XRow > xRow ( xResultSet , UNO_QUERY ) ;
try
{
while ( xResultSet - > next ( ) )
{
OUString aTitle ( xRow - > getString ( 1 ) ) ;
OUString aId = xContentAccess - > queryContentIdentifierString ( ) ;
2000-11-30 15:43:40 +00:00
OUString aFullTitle = GetTitleFromURL ( aId ) ;
2000-11-27 07:55:57 +00:00
2000-11-30 15:43:40 +00:00
if ( aFullTitle . len ( ) )
aTitle = aFullTitle ;
EntryData_Impl * pEntry ;
pEntry = pRegion - > AddEntry ( rParentFolder , aTitle , aId ) ;
if ( pEntry )
{
OUString aType = GetTypeFromURL ( aId ) ;
pEntry - > SetType ( aType ) ;
}
2000-11-27 07:55:57 +00:00
}
}
catch ( CommandAbortedException & )
{
DBG_ERRORFILE ( " XContentAccess::next(): CommandAbortedException " ) ;
}
catch ( . . . )
{
DBG_ERRORFILE ( " XContentAccess::next(): Any other exception " ) ;
}
}
}
// -----------------------------------------------------------------------
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 ;
}
// -----------------------------------------------------------------------
sal_Bool SfxDocTemplate_Impl : : InsertOrMarkRegion ( RegionData_Impl * pData )
{
: : osl : : MutexGuard aGuard ( maMutex ) ;
int nCompVal = 1 ;
long nStart = 0 ;
long nEnd = maRegions . Count ( ) - 1 ;
long nMid ;
RegionData_Impl * pMid ;
sal_Bool bFound ;
sal_Bool bSameName = sal_False ;
while ( nCompVal & & ( nStart < = nEnd ) )
{
nMid = ( nEnd - nStart ) / 2 + nStart ;
pMid = maRegions . GetObject ( nMid ) ;
nCompVal = pMid - > Compare ( pData , & bSameName ) ;
if ( nCompVal < 0 ) // pMid < pData
nStart = nMid + 1 ;
else
nEnd = nMid - 1 ;
}
if ( nCompVal = = 0 )
{
bFound = TRUE ;
pMid - > SetChecked ( sal_True ) ;
}
else
{
if ( nCompVal < 0 ) // pMid < pData
nMid + + ;
maRegions . Insert ( pData , nMid ) ;
bFound = sal_False ;
}
return bFound ;
}
// -----------------------------------------------------------------------
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 ( ' / ' ) ;
OUString aIndex ( ' . ' ) ;
aIndex + = OUString : : valueOf ( ( sal_Int32 ) nIndex ) ;
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 ) ) ;
Sequence < OUString > aAdditionalProps ( 3 ) ;
pNames = aAdditionalProps . getArray ( ) ;
pNames [ 0 ] = OUString ( RTL_CONSTASCII_USTRINGPARAM ( TARGET_DIR_URL ) ) ;
pNames [ 1 ] = OUString ( RTL_CONSTASCII_USTRINGPARAM ( PARENT_DIR_URL ) ) ;
pNames [ 2 ] = OUString ( RTL_CONSTASCII_USTRINGPARAM ( REAL_NAME ) ) ;
OUString aType = OUString ( RTL_CONSTASCII_USTRINGPARAM ( TYPE_FOLDER ) ) ;
sal_Bool bExists = sal_False ;
OUString aURLTitle = rTitle + aIndex ;
OUString aNewFolderURL = aRootURL + aURLTitle ;
Content aFolder ;
try
{
aFolder = Content ( aNewFolderURL , aCmdEnv ) ;
bExists = sal_True ;
}
catch ( ContentCreationException & )
{
Any * pValues = aValues . getArray ( ) ;
pValues [ 0 ] = makeAny ( aURLTitle ) ;
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 ) ) ;
xFolderProp - > addProperty ( pNames [ 1 ] , PropertyAttribute : : MAYBEVOID ,
makeAny ( aFolderURL ) ) ;
xFolderProp - > addProperty ( pNames [ 2 ] , PropertyAttribute : : MAYBEVOID ,
makeAny ( rTitle ) ) ;
}
catch ( PropertyExistException & ) { }
catch ( IllegalTypeException & ) { DBG_ERRORFILE ( " IllegalTypeException " ) ; }
catch ( IllegalArgumentException & ) { DBG_ERRORFILE ( " IllegalArgumentException " ) ; }
}
}
Sequence < Any > aPropValues ( 3 ) ;
Any * pPropValues = aPropValues . getArray ( ) ;
pPropValues [ 0 ] = makeAny ( rTargetURL ) ;
pPropValues [ 1 ] = makeAny ( aFolderURL ) ;
pPropValues [ 2 ] = makeAny ( rTitle ) ;
aFolder . setPropertyValues ( aAdditionalProps , aPropValues ) ;
}
}
catch ( CommandAbortedException & )
{
DBG_ERRORFILE ( " CommandAbortedException " ) ;
}
catch ( . . . )
{
DBG_ERRORFILE ( " Any other exception " ) ;
}
}
if ( ! bExists )
{
RegionData_Impl * pRegion = new RegionData_Impl ( aURLTitle , rTitle ) ;
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 " ) ;
}
catch ( . . . )
{
bExists = sal_True ;
DBG_ERRORFILE ( " Any other exception " ) ;
}
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 & ) { }
}
return aTitle ;
}