1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_sw.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <memory> 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include <com/sun/star/container/XNamed.hpp> 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir #define _SVSTDARR_STRINGS 36*cdf0e10cSrcweir #include <unotools/transliterationwrapper.hxx> 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir #include <svl/svstdarr.hxx> 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir #ifndef __RSC //autogen 41*cdf0e10cSrcweir #include <tools/errinf.hxx> 42*cdf0e10cSrcweir #endif 43*cdf0e10cSrcweir #include <tools/debug.hxx> 44*cdf0e10cSrcweir #include <svl/urihelper.hxx> 45*cdf0e10cSrcweir #ifndef SVTOOLS_FSTATHELPER_HXX 46*cdf0e10cSrcweir #include <svl/fstathelper.hxx> 47*cdf0e10cSrcweir #endif 48*cdf0e10cSrcweir #include <unotools/pathoptions.hxx> 49*cdf0e10cSrcweir #include <unotools/tempfile.hxx> 50*cdf0e10cSrcweir #include <swtypes.hxx> 51*cdf0e10cSrcweir #include <errhdl.hxx> // ASSERT 52*cdf0e10cSrcweir #include <uitool.hxx> 53*cdf0e10cSrcweir #include <glosdoc.hxx> 54*cdf0e10cSrcweir #include <shellio.hxx> 55*cdf0e10cSrcweir #include <swunohelper.hxx> 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir #include <unoatxt.hxx> 58*cdf0e10cSrcweir #include <swerror.h> 59*cdf0e10cSrcweir #ifndef _GLOBALS_HRC 60*cdf0e10cSrcweir #include <globals.hrc> 61*cdf0e10cSrcweir #endif 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir using namespace ::com::sun::star; 64*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir // PUBLIC METHODES ------------------------------------------------------- 68*cdf0e10cSrcweir /* -----------------------------08.02.00 15:54-------------------------------- 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir ---------------------------------------------------------------------------*/ 71*cdf0e10cSrcweir String lcl_CheckFileName( const String& rNewFilePath, 72*cdf0e10cSrcweir const String& rNewGroupName ) 73*cdf0e10cSrcweir { 74*cdf0e10cSrcweir String sRet; 75*cdf0e10cSrcweir //group name should contain only A-Z and a-z and spaces 76*cdf0e10cSrcweir for( xub_StrLen i = 0; i < rNewGroupName.Len(); i++ ) 77*cdf0e10cSrcweir { 78*cdf0e10cSrcweir sal_Unicode cChar = rNewGroupName.GetChar(i); 79*cdf0e10cSrcweir if( (cChar >= 'A' && cChar <= 'Z') || 80*cdf0e10cSrcweir (cChar >= 'a' && cChar <= 'z') || 81*cdf0e10cSrcweir (cChar >= '0' && cChar <= '9') || 82*cdf0e10cSrcweir cChar == '_' || cChar == 0x20 ) 83*cdf0e10cSrcweir { 84*cdf0e10cSrcweir sRet += cChar; 85*cdf0e10cSrcweir } 86*cdf0e10cSrcweir } 87*cdf0e10cSrcweir sRet.EraseLeadingChars(); 88*cdf0e10cSrcweir sRet.EraseTrailingChars(); 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir sal_Bool bOk = sal_False; 91*cdf0e10cSrcweir if( sRet.Len() ) 92*cdf0e10cSrcweir { 93*cdf0e10cSrcweir String sTmpDir(rNewFilePath); 94*cdf0e10cSrcweir sTmpDir += INET_PATH_TOKEN; 95*cdf0e10cSrcweir sTmpDir += sRet; 96*cdf0e10cSrcweir sTmpDir += SwGlossaries::GetExtension(); 97*cdf0e10cSrcweir bOk = !FStatHelper::IsDocument( sTmpDir ); 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir if( !bOk ) 101*cdf0e10cSrcweir { 102*cdf0e10cSrcweir String rSG = SwGlossaries::GetExtension(); 103*cdf0e10cSrcweir //generate generic name 104*cdf0e10cSrcweir utl::TempFile aTemp( 105*cdf0e10cSrcweir String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "group" )), 106*cdf0e10cSrcweir &rSG, &rNewFilePath ); 107*cdf0e10cSrcweir aTemp.EnableKillingFile(); 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir INetURLObject aTempURL( aTemp.GetURL() ); 110*cdf0e10cSrcweir sRet = aTempURL.GetBase(); 111*cdf0e10cSrcweir } 112*cdf0e10cSrcweir return sRet; 113*cdf0e10cSrcweir } 114*cdf0e10cSrcweir /*------------------------------------------------------------------------ 115*cdf0e10cSrcweir Beschreibung: Liefert den Namen der Default-Gruppe 116*cdf0e10cSrcweir ------------------------------------------------------------------------*/ 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir String SwGlossaries::GetDefName() 120*cdf0e10cSrcweir { 121*cdf0e10cSrcweir return String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "standard" )); 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir } 124*cdf0e10cSrcweir /*------------------------------------------------------------------------ 125*cdf0e10cSrcweir Beschreibung: Liefert die Anzahl der Textbausteingruppen 126*cdf0e10cSrcweir ------------------------------------------------------------------------*/ 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir sal_uInt16 SwGlossaries::GetGroupCnt() 130*cdf0e10cSrcweir { 131*cdf0e10cSrcweir return GetNameList()->Count(); 132*cdf0e10cSrcweir } 133*cdf0e10cSrcweir /*------------------------------------------------------------------------ 134*cdf0e10cSrcweir Beschreibung: Liefert den Gruppennamen 135*cdf0e10cSrcweir ------------------------------------------------------------------------*/ 136*cdf0e10cSrcweir sal_Bool SwGlossaries::FindGroupName(String & rGroup) 137*cdf0e10cSrcweir { 138*cdf0e10cSrcweir // enthaelt der Gruppenname keinen Pfad, kann hier ein passender 139*cdf0e10cSrcweir // Gruppeneintrag gesucht werden; 140*cdf0e10cSrcweir sal_uInt16 nCount = GetGroupCnt(); 141*cdf0e10cSrcweir sal_uInt16 i; 142*cdf0e10cSrcweir for(i= 0; i < nCount; i++) 143*cdf0e10cSrcweir { 144*cdf0e10cSrcweir String sTemp(GetGroupName(i)); 145*cdf0e10cSrcweir if(rGroup.Equals( sTemp.GetToken(0, GLOS_DELIM))) 146*cdf0e10cSrcweir { 147*cdf0e10cSrcweir rGroup = sTemp; 148*cdf0e10cSrcweir return sal_True; 149*cdf0e10cSrcweir } 150*cdf0e10cSrcweir } 151*cdf0e10cSrcweir //man darf zweimal suchen, denn bei mehreren Verzeichnissen koennte 152*cdf0e10cSrcweir //der caseinsensitive Name mehrfach auftreten 153*cdf0e10cSrcweir const ::utl::TransliterationWrapper& rSCmp = GetAppCmpStrIgnore(); 154*cdf0e10cSrcweir for(i = 0; i < nCount; i++) 155*cdf0e10cSrcweir { 156*cdf0e10cSrcweir String sTemp( GetGroupName( i )); 157*cdf0e10cSrcweir sal_uInt16 nPath = (sal_uInt16)sTemp.GetToken(1, GLOS_DELIM).ToInt32(); 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir if( !SWUnoHelper::UCB_IsCaseSensitiveFileName( *(*m_pPathArr)[nPath] ) 160*cdf0e10cSrcweir && rSCmp.isEqual( rGroup, sTemp.GetToken( 0, GLOS_DELIM) ) ) 161*cdf0e10cSrcweir { 162*cdf0e10cSrcweir rGroup = sTemp; 163*cdf0e10cSrcweir return sal_True; 164*cdf0e10cSrcweir } 165*cdf0e10cSrcweir } 166*cdf0e10cSrcweir return sal_False; 167*cdf0e10cSrcweir } 168*cdf0e10cSrcweir /* --------------------------------------------------------------------------- 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir ---------------------------------------------------------------------------*/ 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir String SwGlossaries::GetGroupName(sal_uInt16 nGroupId) 173*cdf0e10cSrcweir { 174*cdf0e10cSrcweir ASSERT(nGroupId < m_pGlosArr->Count(), Textbausteinarray ueberindiziert); 175*cdf0e10cSrcweir return *(*m_pGlosArr)[nGroupId]; 176*cdf0e10cSrcweir } 177*cdf0e10cSrcweir /* -----------------------------08.02.00 13:04-------------------------------- 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir ---------------------------------------------------------------------------*/ 180*cdf0e10cSrcweir String SwGlossaries::GetGroupTitle( const String& rGroupName ) 181*cdf0e10cSrcweir { 182*cdf0e10cSrcweir String sRet; 183*cdf0e10cSrcweir String sGroup(rGroupName); 184*cdf0e10cSrcweir if(STRING_NOTFOUND == sGroup.Search(GLOS_DELIM)) 185*cdf0e10cSrcweir FindGroupName(sGroup); 186*cdf0e10cSrcweir SwTextBlocks* pGroup = GetGroupDoc(sGroup, sal_False); 187*cdf0e10cSrcweir if(pGroup) 188*cdf0e10cSrcweir { 189*cdf0e10cSrcweir sRet = pGroup->GetName(); 190*cdf0e10cSrcweir PutGroupDoc( pGroup ); 191*cdf0e10cSrcweir } 192*cdf0e10cSrcweir return sRet; 193*cdf0e10cSrcweir } 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir /*------------------------------------------------------------------------ 196*cdf0e10cSrcweir Beschreibung: Liefert das Textbaustein-Dokument der Gruppe rName 197*cdf0e10cSrcweir ------------------------------------------------------------------------*/ 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir SwTextBlocks* SwGlossaries::GetGroupDoc(const String &rName, 200*cdf0e10cSrcweir sal_Bool bCreate) const 201*cdf0e10cSrcweir { 202*cdf0e10cSrcweir // gfs. in die Liste der Textbausteine eintragen 203*cdf0e10cSrcweir if(bCreate && m_pGlosArr) 204*cdf0e10cSrcweir { 205*cdf0e10cSrcweir const String aName(rName); 206*cdf0e10cSrcweir const sal_uInt16 nCount = m_pGlosArr->Count(); 207*cdf0e10cSrcweir sal_uInt16 i; 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir for( i = 0; i < nCount; ++i) 210*cdf0e10cSrcweir { 211*cdf0e10cSrcweir const String *pName = (*m_pGlosArr)[i]; 212*cdf0e10cSrcweir if(*pName == aName) 213*cdf0e10cSrcweir break; 214*cdf0e10cSrcweir } 215*cdf0e10cSrcweir if(i == nCount) 216*cdf0e10cSrcweir { // Baustein nicht in der Liste 217*cdf0e10cSrcweir String *pTmp = new String(aName); 218*cdf0e10cSrcweir m_pGlosArr->Insert(pTmp, m_pGlosArr->Count()); 219*cdf0e10cSrcweir } 220*cdf0e10cSrcweir } 221*cdf0e10cSrcweir return GetGlosDoc( rName, bCreate ); 222*cdf0e10cSrcweir } 223*cdf0e10cSrcweir 224*cdf0e10cSrcweir /*------------------------------------------------------------------------ 225*cdf0e10cSrcweir Beschreibung: Loeschen Textblock 226*cdf0e10cSrcweir ------------------------------------------------------------------------*/ 227*cdf0e10cSrcweir 228*cdf0e10cSrcweir void SwGlossaries::PutGroupDoc(SwTextBlocks *pBlock) { 229*cdf0e10cSrcweir delete pBlock; 230*cdf0e10cSrcweir } 231*cdf0e10cSrcweir /*------------------------------------------------------------------------ 232*cdf0e10cSrcweir Beschreibung: Erzeugt ein neues Dokument mit dem Gruppenname 233*cdf0e10cSrcweir Wird temp. auch als File angelegt, damit die 234*cdf0e10cSrcweir Gruppen auch spaeter (ohne Zugriff) vorhanden sind. 235*cdf0e10cSrcweir ------------------------------------------------------------------------*/ 236*cdf0e10cSrcweir 237*cdf0e10cSrcweir 238*cdf0e10cSrcweir sal_Bool SwGlossaries::NewGroupDoc(String& rGroupName, const String& rTitle) 239*cdf0e10cSrcweir { 240*cdf0e10cSrcweir sal_uInt16 nNewPath = (sal_uInt16)rGroupName.GetToken(1, GLOS_DELIM).ToInt32(); 241*cdf0e10cSrcweir String sNewFilePath(*(*m_pPathArr)[nNewPath]); 242*cdf0e10cSrcweir String sNewGroup = lcl_CheckFileName(sNewFilePath, rGroupName.GetToken(0, GLOS_DELIM)); 243*cdf0e10cSrcweir sNewGroup += GLOS_DELIM; 244*cdf0e10cSrcweir sNewGroup += rGroupName.GetToken(1, GLOS_DELIM); 245*cdf0e10cSrcweir SwTextBlocks *pBlock = GetGlosDoc( sNewGroup ); 246*cdf0e10cSrcweir if(pBlock) 247*cdf0e10cSrcweir { 248*cdf0e10cSrcweir String *pTmp = 249*cdf0e10cSrcweir new String(sNewGroup); 250*cdf0e10cSrcweir SvStrings* pList = GetNameList(); 251*cdf0e10cSrcweir pList->Insert(pTmp, pList->Count()); 252*cdf0e10cSrcweir pBlock->SetName(rTitle); 253*cdf0e10cSrcweir PutGroupDoc(pBlock); 254*cdf0e10cSrcweir rGroupName = sNewGroup; 255*cdf0e10cSrcweir return sal_True; 256*cdf0e10cSrcweir } 257*cdf0e10cSrcweir return sal_False; 258*cdf0e10cSrcweir } 259*cdf0e10cSrcweir /* -----------------23.11.98 13:13------------------- 260*cdf0e10cSrcweir * 261*cdf0e10cSrcweir * --------------------------------------------------*/ 262*cdf0e10cSrcweir sal_Bool SwGlossaries::RenameGroupDoc( 263*cdf0e10cSrcweir const String& rOldGroup, String& rNewGroup, const String& rNewTitle ) 264*cdf0e10cSrcweir { 265*cdf0e10cSrcweir sal_Bool bRet = sal_False; 266*cdf0e10cSrcweir sal_uInt16 nOldPath = (sal_uInt16)rOldGroup.GetToken(1, GLOS_DELIM).ToInt32(); 267*cdf0e10cSrcweir if(nOldPath < m_pPathArr->Count()) 268*cdf0e10cSrcweir { 269*cdf0e10cSrcweir String sOldFileURL(*(*m_pPathArr)[nOldPath]); 270*cdf0e10cSrcweir sOldFileURL += INET_PATH_TOKEN; 271*cdf0e10cSrcweir sOldFileURL += rOldGroup.GetToken(0, GLOS_DELIM); 272*cdf0e10cSrcweir sOldFileURL += SwGlossaries::GetExtension(); 273*cdf0e10cSrcweir sal_Bool bExist = FStatHelper::IsDocument( sOldFileURL ); 274*cdf0e10cSrcweir DBG_ASSERT(bExist, "Gruppe existiert nicht!"); 275*cdf0e10cSrcweir if(bExist) 276*cdf0e10cSrcweir { 277*cdf0e10cSrcweir sal_uInt16 nNewPath = (sal_uInt16)rNewGroup.GetToken(1, GLOS_DELIM).ToInt32(); 278*cdf0e10cSrcweir if( nNewPath < m_pPathArr->Count()) 279*cdf0e10cSrcweir { 280*cdf0e10cSrcweir String sNewFilePath(*(*m_pPathArr)[nNewPath]); 281*cdf0e10cSrcweir String sNewFileName = lcl_CheckFileName( 282*cdf0e10cSrcweir sNewFilePath, rNewGroup.GetToken(0, GLOS_DELIM)); 283*cdf0e10cSrcweir //String aTmp( rNewGroup.GetToken(0, GLOS_DELIM)); 284*cdf0e10cSrcweir const sal_uInt16 nFileNameLen = sNewFileName.Len(); 285*cdf0e10cSrcweir sNewFileName += SwGlossaries::GetExtension(); 286*cdf0e10cSrcweir String sTempNewFilePath(sNewFilePath); 287*cdf0e10cSrcweir sTempNewFilePath += INET_PATH_TOKEN; 288*cdf0e10cSrcweir sTempNewFilePath += sNewFileName ; 289*cdf0e10cSrcweir bExist = FStatHelper::IsDocument( sTempNewFilePath ); 290*cdf0e10cSrcweir DBG_ASSERT(!bExist, "Gruppe existiert bereits!"); 291*cdf0e10cSrcweir if(!bExist) 292*cdf0e10cSrcweir { 293*cdf0e10cSrcweir sal_Bool bCopyCompleted = SWUnoHelper::UCB_CopyFile( 294*cdf0e10cSrcweir sOldFileURL, sTempNewFilePath, sal_True ); 295*cdf0e10cSrcweir if(bCopyCompleted) 296*cdf0e10cSrcweir { 297*cdf0e10cSrcweir bRet = sal_True; 298*cdf0e10cSrcweir RemoveFileFromList( rOldGroup ); 299*cdf0e10cSrcweir 300*cdf0e10cSrcweir rNewGroup = sNewFileName.Copy(0, nFileNameLen); 301*cdf0e10cSrcweir rNewGroup += GLOS_DELIM; 302*cdf0e10cSrcweir rNewGroup += String::CreateFromInt32(nNewPath); 303*cdf0e10cSrcweir String *pTmp = new String(rNewGroup); 304*cdf0e10cSrcweir if(!m_pGlosArr) 305*cdf0e10cSrcweir GetNameList(); 306*cdf0e10cSrcweir else 307*cdf0e10cSrcweir m_pGlosArr->Insert(pTmp, m_pGlosArr->Count()); 308*cdf0e10cSrcweir 309*cdf0e10cSrcweir sNewFilePath += INET_PATH_TOKEN; 310*cdf0e10cSrcweir sNewFilePath += sNewFileName ; 311*cdf0e10cSrcweir SwTextBlocks* pNewBlock = new SwTextBlocks( sNewFilePath ); 312*cdf0e10cSrcweir pNewBlock->SetName(rNewTitle); 313*cdf0e10cSrcweir delete pNewBlock; 314*cdf0e10cSrcweir } 315*cdf0e10cSrcweir } 316*cdf0e10cSrcweir } 317*cdf0e10cSrcweir } 318*cdf0e10cSrcweir } 319*cdf0e10cSrcweir return bRet; 320*cdf0e10cSrcweir } 321*cdf0e10cSrcweir 322*cdf0e10cSrcweir /*------------------------------------------------------------------------ 323*cdf0e10cSrcweir Beschreibung: Loescht eine Textbausteingruppe 324*cdf0e10cSrcweir ------------------------------------------------------------------------*/ 325*cdf0e10cSrcweir 326*cdf0e10cSrcweir 327*cdf0e10cSrcweir sal_Bool SwGlossaries::DelGroupDoc(const String &rName) 328*cdf0e10cSrcweir { 329*cdf0e10cSrcweir sal_uInt16 nPath = (sal_uInt16)rName.GetToken(1, GLOS_DELIM).ToInt32(); 330*cdf0e10cSrcweir if(nPath >= m_pPathArr->Count()) 331*cdf0e10cSrcweir return sal_False; 332*cdf0e10cSrcweir String sFileURL(*(*m_pPathArr)[nPath]); 333*cdf0e10cSrcweir String aTmp( rName.GetToken(0, GLOS_DELIM)); 334*cdf0e10cSrcweir String aName(aTmp); 335*cdf0e10cSrcweir aName += GLOS_DELIM; 336*cdf0e10cSrcweir aName += String::CreateFromInt32(nPath); 337*cdf0e10cSrcweir 338*cdf0e10cSrcweir aTmp += SwGlossaries::GetExtension(); 339*cdf0e10cSrcweir sFileURL += INET_PATH_TOKEN; 340*cdf0e10cSrcweir sFileURL += aTmp; 341*cdf0e10cSrcweir // Auch, wenn das File nicht existiert, muss es aus der Liste 342*cdf0e10cSrcweir // der Textbausteinbereiche entfernt werden 343*cdf0e10cSrcweir // Kein && wegen CFfront 344*cdf0e10cSrcweir sal_Bool bRemoved = SWUnoHelper::UCB_DeleteFile( sFileURL ); 345*cdf0e10cSrcweir DBG_ASSERT(bRemoved, "file has not been removed"); 346*cdf0e10cSrcweir RemoveFileFromList( aName ); 347*cdf0e10cSrcweir return bRemoved; 348*cdf0e10cSrcweir } 349*cdf0e10cSrcweir /*------------------------------------------------------------------------ 350*cdf0e10cSrcweir Beschreibung: DTOR 351*cdf0e10cSrcweir ------------------------------------------------------------------------*/ 352*cdf0e10cSrcweir 353*cdf0e10cSrcweir 354*cdf0e10cSrcweir SwGlossaries::~SwGlossaries() 355*cdf0e10cSrcweir { 356*cdf0e10cSrcweir sal_uInt16 nCount = m_pGlosArr? m_pGlosArr->Count() : 0; 357*cdf0e10cSrcweir sal_uInt16 i; 358*cdf0e10cSrcweir 359*cdf0e10cSrcweir for( i = 0; i < nCount; ++i) 360*cdf0e10cSrcweir { 361*cdf0e10cSrcweir String *pTmp = (*m_pGlosArr)[i]; 362*cdf0e10cSrcweir delete pTmp; 363*cdf0e10cSrcweir } 364*cdf0e10cSrcweir nCount = m_pPathArr? m_pPathArr->Count() : 0; 365*cdf0e10cSrcweir for(i = 0; i < nCount; ++i) 366*cdf0e10cSrcweir { 367*cdf0e10cSrcweir String *pTmp = (*m_pPathArr)[i]; 368*cdf0e10cSrcweir delete pTmp; 369*cdf0e10cSrcweir } 370*cdf0e10cSrcweir delete m_pGlosArr; 371*cdf0e10cSrcweir delete m_pPathArr; 372*cdf0e10cSrcweir 373*cdf0e10cSrcweir InvalidateUNOOjects(); 374*cdf0e10cSrcweir } 375*cdf0e10cSrcweir /*------------------------------------------------------------------------ 376*cdf0e10cSrcweir Beschreibung: Bausteindokument einlesen 377*cdf0e10cSrcweir ------------------------------------------------------------------------*/ 378*cdf0e10cSrcweir 379*cdf0e10cSrcweir 380*cdf0e10cSrcweir SwTextBlocks* SwGlossaries::GetGlosDoc( const String &rName, sal_Bool bCreate ) const 381*cdf0e10cSrcweir { 382*cdf0e10cSrcweir sal_uInt16 nPath = (sal_uInt16)rName.GetToken(1, GLOS_DELIM).ToInt32(); 383*cdf0e10cSrcweir SwTextBlocks *pTmp = 0; 384*cdf0e10cSrcweir if(nPath < m_pPathArr->Count()) 385*cdf0e10cSrcweir { 386*cdf0e10cSrcweir String sFileURL(*(*m_pPathArr)[nPath]); 387*cdf0e10cSrcweir String aTmp( rName.GetToken(0, GLOS_DELIM)); 388*cdf0e10cSrcweir aTmp += SwGlossaries::GetExtension(); 389*cdf0e10cSrcweir sFileURL += INET_PATH_TOKEN; 390*cdf0e10cSrcweir sFileURL += aTmp; 391*cdf0e10cSrcweir 392*cdf0e10cSrcweir sal_Bool bExist = sal_False; 393*cdf0e10cSrcweir if(!bCreate) 394*cdf0e10cSrcweir bExist = FStatHelper::IsDocument( sFileURL ); 395*cdf0e10cSrcweir 396*cdf0e10cSrcweir if (bCreate || bExist) 397*cdf0e10cSrcweir { 398*cdf0e10cSrcweir pTmp = new SwTextBlocks( sFileURL ); 399*cdf0e10cSrcweir sal_Bool bOk = sal_True; 400*cdf0e10cSrcweir if( pTmp->GetError() ) 401*cdf0e10cSrcweir { 402*cdf0e10cSrcweir ErrorHandler::HandleError( pTmp->GetError() ); 403*cdf0e10cSrcweir bOk = !IsError( pTmp->GetError() ); 404*cdf0e10cSrcweir } 405*cdf0e10cSrcweir 406*cdf0e10cSrcweir if( bOk && !pTmp->GetName().Len() ) 407*cdf0e10cSrcweir pTmp->SetName( rName ); 408*cdf0e10cSrcweir } 409*cdf0e10cSrcweir } 410*cdf0e10cSrcweir 411*cdf0e10cSrcweir return pTmp; 412*cdf0e10cSrcweir } 413*cdf0e10cSrcweir 414*cdf0e10cSrcweir /*------------------------------------------------------------------------ 415*cdf0e10cSrcweir Beschreibung: Zugriff auf die Liste der Name; diese wird gfs. eingelesen 416*cdf0e10cSrcweir ------------------------------------------------------------------------*/ 417*cdf0e10cSrcweir 418*cdf0e10cSrcweir SvStrings* SwGlossaries::GetNameList() 419*cdf0e10cSrcweir { 420*cdf0e10cSrcweir if( !m_pGlosArr ) 421*cdf0e10cSrcweir { 422*cdf0e10cSrcweir m_pGlosArr = new SvStrings; 423*cdf0e10cSrcweir String sExt( SwGlossaries::GetExtension() ); 424*cdf0e10cSrcweir for( sal_uInt16 i = 0; i < m_pPathArr->Count(); i++ ) 425*cdf0e10cSrcweir { 426*cdf0e10cSrcweir SvStrings aFiles( 16, 16 ); 427*cdf0e10cSrcweir 428*cdf0e10cSrcweir SWUnoHelper::UCB_GetFileListOfFolder( *(*m_pPathArr)[i], aFiles, 429*cdf0e10cSrcweir &sExt ); 430*cdf0e10cSrcweir for( sal_uInt16 nFiles = 0, nFEnd = aFiles.Count(); 431*cdf0e10cSrcweir nFiles < nFEnd; ++nFiles ) 432*cdf0e10cSrcweir { 433*cdf0e10cSrcweir String* pTitle = aFiles[ nFiles ]; 434*cdf0e10cSrcweir String sName( pTitle->Copy( 0, pTitle->Len() - sExt.Len() )); 435*cdf0e10cSrcweir sName += GLOS_DELIM; 436*cdf0e10cSrcweir sName += String::CreateFromInt32( i ); 437*cdf0e10cSrcweir m_pGlosArr->Insert( new String(sName), m_pGlosArr->Count() ); 438*cdf0e10cSrcweir 439*cdf0e10cSrcweir // don't need any more these pointers 440*cdf0e10cSrcweir delete pTitle; 441*cdf0e10cSrcweir } 442*cdf0e10cSrcweir } 443*cdf0e10cSrcweir if(!m_pGlosArr->Count()) 444*cdf0e10cSrcweir { 445*cdf0e10cSrcweir // Der Standard-Baustein steht im ersten Teil des Pfades 446*cdf0e10cSrcweir String *pTmp = new String( SwGlossaries::GetDefName() ); 447*cdf0e10cSrcweir (*pTmp) += GLOS_DELIM; 448*cdf0e10cSrcweir (*pTmp) += '0'; 449*cdf0e10cSrcweir m_pGlosArr->Insert(pTmp, m_pGlosArr->Count()); 450*cdf0e10cSrcweir } 451*cdf0e10cSrcweir } 452*cdf0e10cSrcweir return m_pGlosArr; 453*cdf0e10cSrcweir } 454*cdf0e10cSrcweir 455*cdf0e10cSrcweir /*------------------------------------------------------------------------ 456*cdf0e10cSrcweir Beschreibung: CTOR 457*cdf0e10cSrcweir ------------------------------------------------------------------------*/ 458*cdf0e10cSrcweir 459*cdf0e10cSrcweir 460*cdf0e10cSrcweir SwGlossaries::SwGlossaries() : 461*cdf0e10cSrcweir m_pPathArr(0), 462*cdf0e10cSrcweir m_pGlosArr(0) 463*cdf0e10cSrcweir { 464*cdf0e10cSrcweir m_pPathArr = new SvStrings; 465*cdf0e10cSrcweir UpdateGlosPath(sal_True); 466*cdf0e10cSrcweir } 467*cdf0e10cSrcweir 468*cdf0e10cSrcweir /*------------------------------------------------------------------------ 469*cdf0e10cSrcweir Beschreibung: Neuen Pfad einstellen und internes Array neu aufbauen 470*cdf0e10cSrcweir ------------------------------------------------------------------------*/ 471*cdf0e10cSrcweir 472*cdf0e10cSrcweir /* -----------------21.01.99 15:36------------------- 473*cdf0e10cSrcweir * #61050# Doppelte Pfade fuehren zu Verwirrung - als raus damit 474*cdf0e10cSrcweir * --------------------------------------------------*/ 475*cdf0e10cSrcweir sal_Bool lcl_FindSameEntry(const SvStrings& rDirArr, const String& rEntryURL) 476*cdf0e10cSrcweir { 477*cdf0e10cSrcweir for(sal_uInt16 i = 0; i < rDirArr.Count(); i++) 478*cdf0e10cSrcweir if(rEntryURL == (*rDirArr.GetObject(i))) 479*cdf0e10cSrcweir return sal_True; 480*cdf0e10cSrcweir return sal_False; 481*cdf0e10cSrcweir } 482*cdf0e10cSrcweir 483*cdf0e10cSrcweir void SwGlossaries::UpdateGlosPath(sal_Bool bFull) 484*cdf0e10cSrcweir { 485*cdf0e10cSrcweir SvtPathOptions aPathOpt; 486*cdf0e10cSrcweir String aNewPath( aPathOpt.GetAutoTextPath() ); 487*cdf0e10cSrcweir sal_Bool bPathChanged = m_aPath != aNewPath; 488*cdf0e10cSrcweir if (bFull || bPathChanged) 489*cdf0e10cSrcweir { 490*cdf0e10cSrcweir m_aPath = aNewPath; 491*cdf0e10cSrcweir sal_uInt16 nCount = m_pPathArr? m_pPathArr->Count() : 0; 492*cdf0e10cSrcweir sal_uInt16 i; 493*cdf0e10cSrcweir 494*cdf0e10cSrcweir for( i = nCount; i; --i) 495*cdf0e10cSrcweir { 496*cdf0e10cSrcweir String *pTmp = (*m_pPathArr)[i - 1]; 497*cdf0e10cSrcweir m_pPathArr->Remove(i - 1); 498*cdf0e10cSrcweir delete pTmp; 499*cdf0e10cSrcweir } 500*cdf0e10cSrcweir sal_uInt16 nTokenCount = m_aPath.GetTokenCount(SVT_SEARCHPATH_DELIMITER); 501*cdf0e10cSrcweir SvStrings aDirArr; 502*cdf0e10cSrcweir for( i = 0; i < nTokenCount; i++ ) 503*cdf0e10cSrcweir { 504*cdf0e10cSrcweir String sPth(m_aPath.GetToken(i, SVT_SEARCHPATH_DELIMITER)); 505*cdf0e10cSrcweir sPth = URIHelper::SmartRel2Abs( 506*cdf0e10cSrcweir INetURLObject(), sPth, URIHelper::GetMaybeFileHdl()); 507*cdf0e10cSrcweir 508*cdf0e10cSrcweir if(i && lcl_FindSameEntry(aDirArr, sPth)) 509*cdf0e10cSrcweir { 510*cdf0e10cSrcweir continue; 511*cdf0e10cSrcweir } 512*cdf0e10cSrcweir aDirArr.Insert(new String(sPth), aDirArr.Count()); 513*cdf0e10cSrcweir if( !FStatHelper::IsFolder( sPth ) ) 514*cdf0e10cSrcweir { 515*cdf0e10cSrcweir if( m_sErrPath.Len() ) 516*cdf0e10cSrcweir m_sErrPath += SVT_SEARCHPATH_DELIMITER; 517*cdf0e10cSrcweir INetURLObject aTemp( sPth ); 518*cdf0e10cSrcweir m_sErrPath += String(aTemp.GetFull()); 519*cdf0e10cSrcweir } 520*cdf0e10cSrcweir else 521*cdf0e10cSrcweir m_pPathArr->Insert(new String(sPth), m_pPathArr->Count()); 522*cdf0e10cSrcweir } 523*cdf0e10cSrcweir aDirArr.DeleteAndDestroy(0, aDirArr.Count()); 524*cdf0e10cSrcweir 525*cdf0e10cSrcweir if(!nTokenCount || 526*cdf0e10cSrcweir (m_sErrPath.Len() && (bPathChanged || m_sOldErrPath != m_sErrPath)) ) 527*cdf0e10cSrcweir { 528*cdf0e10cSrcweir m_sOldErrPath = m_sErrPath; 529*cdf0e10cSrcweir // Falscher Pfad, d.h. AutoText-Verzeichnis existiert nicht 530*cdf0e10cSrcweir 531*cdf0e10cSrcweir ErrorHandler::HandleError( *new StringErrorInfo( 532*cdf0e10cSrcweir ERR_AUTOPATH_ERROR, m_sErrPath, 533*cdf0e10cSrcweir ERRCODE_BUTTON_OK | ERRCODE_MSG_ERROR )); 534*cdf0e10cSrcweir m_bError = sal_True; 535*cdf0e10cSrcweir } 536*cdf0e10cSrcweir else 537*cdf0e10cSrcweir m_bError = sal_False; 538*cdf0e10cSrcweir 539*cdf0e10cSrcweir if(m_pGlosArr) 540*cdf0e10cSrcweir { 541*cdf0e10cSrcweir for(i = 0; i < m_pGlosArr->Count(); ++i) 542*cdf0e10cSrcweir { 543*cdf0e10cSrcweir delete (String *)(*m_pGlosArr)[i]; 544*cdf0e10cSrcweir } 545*cdf0e10cSrcweir DELETEZ(m_pGlosArr); 546*cdf0e10cSrcweir GetNameList(); 547*cdf0e10cSrcweir } 548*cdf0e10cSrcweir } 549*cdf0e10cSrcweir } 550*cdf0e10cSrcweir 551*cdf0e10cSrcweir /*------------------------------------------------------------------------ 552*cdf0e10cSrcweir Beschreibung: 553*cdf0e10cSrcweir ------------------------------------------------------------------------*/ 554*cdf0e10cSrcweir 555*cdf0e10cSrcweir 556*cdf0e10cSrcweir void SwGlossaries::ShowError() 557*cdf0e10cSrcweir { 558*cdf0e10cSrcweir sal_uInt32 nPathError = *new StringErrorInfo(ERR_AUTOPATH_ERROR, 559*cdf0e10cSrcweir m_sErrPath, ERRCODE_BUTTON_OK ); 560*cdf0e10cSrcweir ErrorHandler::HandleError( nPathError ); 561*cdf0e10cSrcweir } 562*cdf0e10cSrcweir /* -----------------------------09.02.00 11:37-------------------------------- 563*cdf0e10cSrcweir 564*cdf0e10cSrcweir ---------------------------------------------------------------------------*/ 565*cdf0e10cSrcweir String SwGlossaries::GetExtension() 566*cdf0e10cSrcweir { 567*cdf0e10cSrcweir return String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( ".bau" )); 568*cdf0e10cSrcweir } 569*cdf0e10cSrcweir 570*cdf0e10cSrcweir 571*cdf0e10cSrcweir 572*cdf0e10cSrcweir void SwGlossaries::RemoveFileFromList( const String& rGroup ) 573*cdf0e10cSrcweir { 574*cdf0e10cSrcweir if(m_pGlosArr) 575*cdf0e10cSrcweir { 576*cdf0e10cSrcweir const sal_uInt16 nCount = m_pGlosArr->Count(); 577*cdf0e10cSrcweir for(sal_uInt16 i = 0; i < nCount; ++i) 578*cdf0e10cSrcweir { 579*cdf0e10cSrcweir String *pTmp = (*m_pGlosArr)[i]; 580*cdf0e10cSrcweir if(*pTmp == rGroup) 581*cdf0e10cSrcweir { 582*cdf0e10cSrcweir rtl::OUString aUName = rGroup; 583*cdf0e10cSrcweir { 584*cdf0e10cSrcweir // tell the UNO AutoTextGroup object that it's not valid anymore 585*cdf0e10cSrcweir for ( UnoAutoTextGroups::iterator aLoop = m_aGlossaryGroups.begin(); 586*cdf0e10cSrcweir aLoop != m_aGlossaryGroups.end(); 587*cdf0e10cSrcweir ++aLoop 588*cdf0e10cSrcweir ) 589*cdf0e10cSrcweir { 590*cdf0e10cSrcweir Reference< container::XNamed > xNamed( aLoop->get(), UNO_QUERY ); 591*cdf0e10cSrcweir if ( xNamed.is() && ( xNamed->getName() == aUName ) ) 592*cdf0e10cSrcweir { 593*cdf0e10cSrcweir static_cast< SwXAutoTextGroup* >( xNamed.get() )->Invalidate(); 594*cdf0e10cSrcweir // note that this static_cast works because we know that the array only 595*cdf0e10cSrcweir // contains SwXAutoTextGroup implementation 596*cdf0e10cSrcweir m_aGlossaryGroups.erase( aLoop ); 597*cdf0e10cSrcweir break; 598*cdf0e10cSrcweir } 599*cdf0e10cSrcweir } 600*cdf0e10cSrcweir } 601*cdf0e10cSrcweir 602*cdf0e10cSrcweir { 603*cdf0e10cSrcweir // tell all our UNO AutoTextEntry objects that they're not valid anymore 604*cdf0e10cSrcweir for ( UnoAutoTextEntries::iterator aLoop = m_aGlossaryEntries.begin(); 605*cdf0e10cSrcweir aLoop != m_aGlossaryEntries.end(); 606*cdf0e10cSrcweir ) 607*cdf0e10cSrcweir { 608*cdf0e10cSrcweir Reference< lang::XUnoTunnel > xEntryTunnel( aLoop->get(), UNO_QUERY ); 609*cdf0e10cSrcweir 610*cdf0e10cSrcweir SwXAutoTextEntry* pEntry = NULL; 611*cdf0e10cSrcweir if ( xEntryTunnel.is() ) 612*cdf0e10cSrcweir pEntry = reinterpret_cast< SwXAutoTextEntry* >( 613*cdf0e10cSrcweir xEntryTunnel->getSomething( SwXAutoTextEntry::getUnoTunnelId() ) ); 614*cdf0e10cSrcweir 615*cdf0e10cSrcweir if ( pEntry && ( pEntry->GetGroupName() == rGroup ) ) 616*cdf0e10cSrcweir { 617*cdf0e10cSrcweir pEntry->Invalidate(); 618*cdf0e10cSrcweir aLoop = m_aGlossaryEntries.erase( aLoop ); 619*cdf0e10cSrcweir } 620*cdf0e10cSrcweir else 621*cdf0e10cSrcweir ++aLoop; 622*cdf0e10cSrcweir } 623*cdf0e10cSrcweir } 624*cdf0e10cSrcweir 625*cdf0e10cSrcweir m_pGlosArr->Remove(i); 626*cdf0e10cSrcweir delete pTmp; 627*cdf0e10cSrcweir break; 628*cdf0e10cSrcweir } 629*cdf0e10cSrcweir } 630*cdf0e10cSrcweir } 631*cdf0e10cSrcweir } 632*cdf0e10cSrcweir 633*cdf0e10cSrcweir 634*cdf0e10cSrcweir String SwGlossaries::GetCompleteGroupName( const rtl::OUString& GroupName ) 635*cdf0e10cSrcweir { 636*cdf0e10cSrcweir sal_uInt16 nCount = GetGroupCnt(); 637*cdf0e10cSrcweir //wenn der Gruppenname intern erzeugt wurde, dann steht auch hier der Pfad drin 638*cdf0e10cSrcweir String sGroup(GroupName); 639*cdf0e10cSrcweir String sGroupName(sGroup.GetToken(0, GLOS_DELIM)); 640*cdf0e10cSrcweir String sPath = sGroup.GetToken(1, GLOS_DELIM); 641*cdf0e10cSrcweir sal_Bool bPathLen = sPath.Len() > 0; 642*cdf0e10cSrcweir for ( sal_uInt16 i = 0; i < nCount; i++ ) 643*cdf0e10cSrcweir { 644*cdf0e10cSrcweir String sGrpName = GetGroupName(i); 645*cdf0e10cSrcweir if(bPathLen ? sGroup == sGrpName : sGroupName == sGrpName.GetToken(0, GLOS_DELIM)) 646*cdf0e10cSrcweir { 647*cdf0e10cSrcweir return sGrpName; 648*cdf0e10cSrcweir } 649*cdf0e10cSrcweir } 650*cdf0e10cSrcweir return aEmptyStr; 651*cdf0e10cSrcweir } 652*cdf0e10cSrcweir 653*cdf0e10cSrcweir 654*cdf0e10cSrcweir void SwGlossaries::InvalidateUNOOjects() 655*cdf0e10cSrcweir { 656*cdf0e10cSrcweir // invalidate all the AutoTextGroup-objects 657*cdf0e10cSrcweir for ( UnoAutoTextGroups::iterator aGroupLoop = m_aGlossaryGroups.begin(); 658*cdf0e10cSrcweir aGroupLoop != m_aGlossaryGroups.end(); 659*cdf0e10cSrcweir ++aGroupLoop 660*cdf0e10cSrcweir ) 661*cdf0e10cSrcweir { 662*cdf0e10cSrcweir Reference< text::XAutoTextGroup > xGroup( aGroupLoop->get(), UNO_QUERY ); 663*cdf0e10cSrcweir if ( xGroup.is() ) 664*cdf0e10cSrcweir static_cast< SwXAutoTextGroup* >( xGroup.get() )->Invalidate(); 665*cdf0e10cSrcweir } 666*cdf0e10cSrcweir UnoAutoTextGroups aTmpg = UnoAutoTextGroups(); 667*cdf0e10cSrcweir m_aGlossaryGroups.swap( aTmpg ); 668*cdf0e10cSrcweir 669*cdf0e10cSrcweir // invalidate all the AutoTextEntry-objects 670*cdf0e10cSrcweir for ( UnoAutoTextEntries::const_iterator aEntryLoop = m_aGlossaryEntries.begin(); 671*cdf0e10cSrcweir aEntryLoop != m_aGlossaryEntries.end(); 672*cdf0e10cSrcweir ++aEntryLoop 673*cdf0e10cSrcweir ) 674*cdf0e10cSrcweir { 675*cdf0e10cSrcweir Reference< lang::XUnoTunnel > xEntryTunnel( aEntryLoop->get(), UNO_QUERY ); 676*cdf0e10cSrcweir SwXAutoTextEntry* pEntry = NULL; 677*cdf0e10cSrcweir if ( xEntryTunnel.is() ) 678*cdf0e10cSrcweir pEntry = reinterpret_cast< SwXAutoTextEntry* >( 679*cdf0e10cSrcweir xEntryTunnel->getSomething( SwXAutoTextEntry::getUnoTunnelId() ) ); 680*cdf0e10cSrcweir 681*cdf0e10cSrcweir if ( pEntry ) 682*cdf0e10cSrcweir pEntry->Invalidate(); 683*cdf0e10cSrcweir } 684*cdf0e10cSrcweir UnoAutoTextEntries aTmpe = UnoAutoTextEntries(); 685*cdf0e10cSrcweir m_aGlossaryEntries.swap( aTmpe ); 686*cdf0e10cSrcweir } 687*cdf0e10cSrcweir 688*cdf0e10cSrcweir //----------------------------------------------------------------------- 689*cdf0e10cSrcweir //--- 03.03.2003 14:15:32 ----------------------------------------------- 690*cdf0e10cSrcweir 691*cdf0e10cSrcweir Reference< text::XAutoTextGroup > SwGlossaries::GetAutoTextGroup( const ::rtl::OUString& _rGroupName, bool _bCreate ) 692*cdf0e10cSrcweir { 693*cdf0e10cSrcweir // first, find the name with path-extension 694*cdf0e10cSrcweir String sCompleteGroupName = GetCompleteGroupName( _rGroupName ); 695*cdf0e10cSrcweir 696*cdf0e10cSrcweir Reference< text::XAutoTextGroup > xGroup; 697*cdf0e10cSrcweir 698*cdf0e10cSrcweir // look up the group in the cache 699*cdf0e10cSrcweir UnoAutoTextGroups::iterator aSearch = m_aGlossaryGroups.begin(); 700*cdf0e10cSrcweir for ( ; aSearch != m_aGlossaryGroups.end(); ) 701*cdf0e10cSrcweir { 702*cdf0e10cSrcweir Reference< lang::XUnoTunnel > xGroupTunnel( aSearch->get(), UNO_QUERY ); 703*cdf0e10cSrcweir 704*cdf0e10cSrcweir SwXAutoTextGroup* pSwGroup = 0; 705*cdf0e10cSrcweir if ( xGroupTunnel.is() ) 706*cdf0e10cSrcweir pSwGroup = reinterpret_cast< SwXAutoTextGroup* >( xGroupTunnel->getSomething( SwXAutoTextGroup::getUnoTunnelId() ) ); 707*cdf0e10cSrcweir 708*cdf0e10cSrcweir if ( !pSwGroup ) 709*cdf0e10cSrcweir { 710*cdf0e10cSrcweir // the object is dead in the meantime -> remove from cache 711*cdf0e10cSrcweir aSearch = m_aGlossaryGroups.erase( aSearch ); 712*cdf0e10cSrcweir continue; 713*cdf0e10cSrcweir } 714*cdf0e10cSrcweir 715*cdf0e10cSrcweir if ( _rGroupName == pSwGroup->getName() ) 716*cdf0e10cSrcweir { // the group is already cached 717*cdf0e10cSrcweir if ( sCompleteGroupName.Len() ) 718*cdf0e10cSrcweir { // the group still exists -> return it 719*cdf0e10cSrcweir xGroup = pSwGroup; 720*cdf0e10cSrcweir break; 721*cdf0e10cSrcweir } 722*cdf0e10cSrcweir else 723*cdf0e10cSrcweir { 724*cdf0e10cSrcweir // this group does not exist (anymore) -> release the cached UNO object for it 725*cdf0e10cSrcweir aSearch = m_aGlossaryGroups.erase( aSearch ); 726*cdf0e10cSrcweir // so it won't be created below 727*cdf0e10cSrcweir _bCreate = sal_False; 728*cdf0e10cSrcweir break; 729*cdf0e10cSrcweir } 730*cdf0e10cSrcweir } 731*cdf0e10cSrcweir 732*cdf0e10cSrcweir ++aSearch; 733*cdf0e10cSrcweir } 734*cdf0e10cSrcweir 735*cdf0e10cSrcweir if ( !xGroup.is() && _bCreate ) 736*cdf0e10cSrcweir { 737*cdf0e10cSrcweir xGroup = new SwXAutoTextGroup( sCompleteGroupName, this ); 738*cdf0e10cSrcweir // cache it 739*cdf0e10cSrcweir m_aGlossaryGroups.push_back( AutoTextGroupRef( xGroup ) ); 740*cdf0e10cSrcweir } 741*cdf0e10cSrcweir 742*cdf0e10cSrcweir return xGroup; 743*cdf0e10cSrcweir } 744*cdf0e10cSrcweir 745*cdf0e10cSrcweir //----------------------------------------------------------------------- 746*cdf0e10cSrcweir //--- 03.03.2003 13:46:06 ----------------------------------------------- 747*cdf0e10cSrcweir 748*cdf0e10cSrcweir Reference< text::XAutoTextEntry > SwGlossaries::GetAutoTextEntry( const String& _rCompleteGroupName, const ::rtl::OUString& _rGroupName, const ::rtl::OUString& _rEntryName, 749*cdf0e10cSrcweir bool _bCreate ) 750*cdf0e10cSrcweir { 751*cdf0e10cSrcweir //standard must be created 752*cdf0e10cSrcweir sal_Bool bCreate = ( _rCompleteGroupName == GetDefName() ); 753*cdf0e10cSrcweir ::std::auto_ptr< SwTextBlocks > pGlosGroup( GetGroupDoc( _rCompleteGroupName, bCreate ) ); 754*cdf0e10cSrcweir 755*cdf0e10cSrcweir if ( pGlosGroup.get() && !pGlosGroup->GetError() ) 756*cdf0e10cSrcweir { 757*cdf0e10cSrcweir sal_uInt16 nIdx = pGlosGroup->GetIndex( _rEntryName ); 758*cdf0e10cSrcweir if ( USHRT_MAX == nIdx ) 759*cdf0e10cSrcweir throw container::NoSuchElementException(); 760*cdf0e10cSrcweir } 761*cdf0e10cSrcweir else 762*cdf0e10cSrcweir throw lang::WrappedTargetException(); 763*cdf0e10cSrcweir 764*cdf0e10cSrcweir Reference< text::XAutoTextEntry > xReturn; 765*cdf0e10cSrcweir String sGroupName( _rGroupName ); 766*cdf0e10cSrcweir String sEntryName( _rEntryName ); 767*cdf0e10cSrcweir 768*cdf0e10cSrcweir UnoAutoTextEntries::iterator aSearch( m_aGlossaryEntries.begin() ); 769*cdf0e10cSrcweir for ( ; aSearch != m_aGlossaryEntries.end(); ) 770*cdf0e10cSrcweir { 771*cdf0e10cSrcweir Reference< lang::XUnoTunnel > xEntryTunnel( aSearch->get(), UNO_QUERY ); 772*cdf0e10cSrcweir 773*cdf0e10cSrcweir SwXAutoTextEntry* pEntry = NULL; 774*cdf0e10cSrcweir if ( xEntryTunnel.is() ) 775*cdf0e10cSrcweir pEntry = reinterpret_cast< SwXAutoTextEntry* >( xEntryTunnel->getSomething( SwXAutoTextEntry::getUnoTunnelId() ) ); 776*cdf0e10cSrcweir else 777*cdf0e10cSrcweir { 778*cdf0e10cSrcweir // the object is dead in the meantime -> remove from cache 779*cdf0e10cSrcweir aSearch = m_aGlossaryEntries.erase( aSearch ); 780*cdf0e10cSrcweir continue; 781*cdf0e10cSrcweir } 782*cdf0e10cSrcweir 783*cdf0e10cSrcweir if ( pEntry 784*cdf0e10cSrcweir && ( COMPARE_EQUAL == pEntry->GetGroupName().CompareTo( sGroupName ) ) 785*cdf0e10cSrcweir && ( COMPARE_EQUAL == pEntry->GetEntryName().CompareTo( sEntryName ) ) 786*cdf0e10cSrcweir ) 787*cdf0e10cSrcweir { 788*cdf0e10cSrcweir xReturn = pEntry; 789*cdf0e10cSrcweir break; 790*cdf0e10cSrcweir } 791*cdf0e10cSrcweir 792*cdf0e10cSrcweir ++aSearch; 793*cdf0e10cSrcweir } 794*cdf0e10cSrcweir 795*cdf0e10cSrcweir if ( !xReturn.is() && _bCreate ) 796*cdf0e10cSrcweir { 797*cdf0e10cSrcweir xReturn = new SwXAutoTextEntry( this, sGroupName, sEntryName ); 798*cdf0e10cSrcweir // cache it 799*cdf0e10cSrcweir m_aGlossaryEntries.push_back( AutoTextEntryRef( xReturn ) ); 800*cdf0e10cSrcweir } 801*cdf0e10cSrcweir 802*cdf0e10cSrcweir return xReturn; 803*cdf0e10cSrcweir } 804*cdf0e10cSrcweir 805*cdf0e10cSrcweir 806*cdf0e10cSrcweir 807