update dev300-m58
[ooovba.git] / sw / source / ui / misc / glosdoc.cxx
bloba34c374291f7191c5a9443b6bc089c1ac4a9c498
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: glosdoc.cxx,v $
10 * $Revision: 1.23 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
34 #include <memory>
36 #include <com/sun/star/container/XNamed.hpp>
38 #define _SVSTDARR_STRINGS
39 #include <unotools/transliterationwrapper.hxx>
41 #include <svtools/svstdarr.hxx>
43 #ifndef __RSC //autogen
44 #include <tools/errinf.hxx>
45 #endif
46 #include <tools/debug.hxx>
47 #include <svtools/urihelper.hxx>
48 #ifndef SVTOOLS_FSTATHELPER_HXX
49 #include <svtools/fstathelper.hxx>
50 #endif
51 #include <svtools/pathoptions.hxx>
52 #include <unotools/tempfile.hxx>
53 #include <swtypes.hxx>
54 #include <errhdl.hxx> // ASSERT
55 #include <uitool.hxx>
56 #include <glosdoc.hxx>
57 #include <shellio.hxx>
58 #include <swunohelper.hxx>
60 #include <unoatxt.hxx>
61 #include <swerror.h>
62 #ifndef _GLOBALS_HRC
63 #include <globals.hrc>
64 #endif
66 using namespace ::com::sun::star;
67 using namespace ::com::sun::star::uno;
70 // PUBLIC METHODES -------------------------------------------------------
71 /* -----------------------------08.02.00 15:54--------------------------------
73 ---------------------------------------------------------------------------*/
74 String lcl_CheckFileName( const String& rNewFilePath,
75 const String& rNewGroupName )
77 String sRet;
78 //group name should contain only A-Z and a-z and spaces
79 for( xub_StrLen i = 0; i < rNewGroupName.Len(); i++ )
81 sal_Unicode cChar = rNewGroupName.GetChar(i);
82 if( (cChar >= 'A' && cChar <= 'Z') ||
83 (cChar >= 'a' && cChar <= 'z') ||
84 (cChar >= '0' && cChar <= '9') ||
85 cChar == '_' || cChar == 0x20 )
87 sRet += cChar;
90 sRet.EraseLeadingChars();
91 sRet.EraseTrailingChars();
93 BOOL bOk = FALSE;
94 if( sRet.Len() )
96 String sTmpDir(rNewFilePath);
97 sTmpDir += INET_PATH_TOKEN;
98 sTmpDir += sRet;
99 sTmpDir += SwGlossaries::GetExtension();
100 bOk = !FStatHelper::IsDocument( sTmpDir );
103 if( !bOk )
105 String rSG = SwGlossaries::GetExtension();
106 //generate generic name
107 utl::TempFile aTemp(
108 String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "group" )),
109 &rSG, &rNewFilePath );
110 aTemp.EnableKillingFile();
112 INetURLObject aTempURL( aTemp.GetURL() );
113 sRet = aTempURL.GetBase();
115 return sRet;
117 /*------------------------------------------------------------------------
118 Beschreibung: Liefert den Namen der Default-Gruppe
119 ------------------------------------------------------------------------*/
122 String SwGlossaries::GetDefName()
124 return String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "standard" ));
127 /*------------------------------------------------------------------------
128 Beschreibung: Liefert die Anzahl der Textbausteingruppen
129 ------------------------------------------------------------------------*/
132 sal_uInt16 SwGlossaries::GetGroupCnt()
134 return GetNameList()->Count();
136 /*------------------------------------------------------------------------
137 Beschreibung: Liefert den Gruppennamen
138 ------------------------------------------------------------------------*/
139 sal_Bool SwGlossaries::FindGroupName(String & rGroup)
141 // enthaelt der Gruppenname keinen Pfad, kann hier ein passender
142 // Gruppeneintrag gesucht werden;
143 sal_uInt16 nCount = GetGroupCnt();
144 sal_uInt16 i;
145 for(i= 0; i < nCount; i++)
147 String sTemp(GetGroupName(i));
148 if(rGroup.Equals( sTemp.GetToken(0, GLOS_DELIM)))
150 rGroup = sTemp;
151 return sal_True;
154 //man darf zweimal suchen, denn bei mehreren Verzeichnissen koennte
155 //der caseinsensitive Name mehrfach auftreten
156 const ::utl::TransliterationWrapper& rSCmp = GetAppCmpStrIgnore();
157 for(i = 0; i < nCount; i++)
159 String sTemp( GetGroupName( i ));
160 sal_uInt16 nPath = (sal_uInt16)sTemp.GetToken(1, GLOS_DELIM).ToInt32();
162 if( !SWUnoHelper::UCB_IsCaseSensitiveFileName( *(*m_pPathArr)[nPath] )
163 && rSCmp.isEqual( rGroup, sTemp.GetToken( 0, GLOS_DELIM) ) )
165 rGroup = sTemp;
166 return sal_True;
169 return sal_False;
171 /* ---------------------------------------------------------------------------
173 ---------------------------------------------------------------------------*/
175 String SwGlossaries::GetGroupName(sal_uInt16 nGroupId)
177 ASSERT(nGroupId < m_pGlosArr->Count(), Textbausteinarray ueberindiziert);
178 return *(*m_pGlosArr)[nGroupId];
180 /* -----------------------------08.02.00 13:04--------------------------------
182 ---------------------------------------------------------------------------*/
183 String SwGlossaries::GetGroupTitle( const String& rGroupName )
185 String sRet;
186 String sGroup(rGroupName);
187 if(STRING_NOTFOUND == sGroup.Search(GLOS_DELIM))
188 FindGroupName(sGroup);
189 SwTextBlocks* pGroup = GetGroupDoc(sGroup, sal_False);
190 if(pGroup)
192 sRet = pGroup->GetName();
193 PutGroupDoc( pGroup );
195 return sRet;
198 /*------------------------------------------------------------------------
199 Beschreibung: Liefert das Textbaustein-Dokument der Gruppe rName
200 ------------------------------------------------------------------------*/
202 SwTextBlocks* SwGlossaries::GetGroupDoc(const String &rName,
203 sal_Bool bCreate) const
205 // gfs. in die Liste der Textbausteine eintragen
206 if(bCreate && m_pGlosArr)
208 const String aName(rName);
209 const sal_uInt16 nCount = m_pGlosArr->Count();
210 sal_uInt16 i;
212 for( i = 0; i < nCount; ++i)
214 const String *pName = (*m_pGlosArr)[i];
215 if(*pName == aName)
216 break;
218 if(i == nCount)
219 { // Baustein nicht in der Liste
220 String *pTmp = new String(aName);
221 m_pGlosArr->Insert(pTmp, m_pGlosArr->Count());
224 return GetGlosDoc( rName, bCreate );
227 /*------------------------------------------------------------------------
228 Beschreibung: Loeschen Textblock
229 ------------------------------------------------------------------------*/
231 void SwGlossaries::PutGroupDoc(SwTextBlocks *pBlock) {
232 delete pBlock;
234 /*------------------------------------------------------------------------
235 Beschreibung: Erzeugt ein neues Dokument mit dem Gruppenname
236 Wird temp. auch als File angelegt, damit die
237 Gruppen auch spaeter (ohne Zugriff) vorhanden sind.
238 ------------------------------------------------------------------------*/
241 sal_Bool SwGlossaries::NewGroupDoc(String& rGroupName, const String& rTitle)
243 sal_uInt16 nNewPath = (sal_uInt16)rGroupName.GetToken(1, GLOS_DELIM).ToInt32();
244 String sNewFilePath(*(*m_pPathArr)[nNewPath]);
245 String sNewGroup = lcl_CheckFileName(sNewFilePath, rGroupName.GetToken(0, GLOS_DELIM));
246 sNewGroup += GLOS_DELIM;
247 sNewGroup += rGroupName.GetToken(1, GLOS_DELIM);
248 SwTextBlocks *pBlock = GetGlosDoc( sNewGroup );
249 if(pBlock)
251 String *pTmp =
252 new String(sNewGroup);
253 SvStrings* pList = GetNameList();
254 pList->Insert(pTmp, pList->Count());
255 pBlock->SetName(rTitle);
256 PutGroupDoc(pBlock);
257 rGroupName = sNewGroup;
258 return sal_True;
260 return sal_False;
262 /* -----------------23.11.98 13:13-------------------
264 * --------------------------------------------------*/
265 sal_Bool SwGlossaries::RenameGroupDoc(
266 const String& rOldGroup, String& rNewGroup, const String& rNewTitle )
268 sal_Bool bRet = sal_False;
269 sal_uInt16 nOldPath = (sal_uInt16)rOldGroup.GetToken(1, GLOS_DELIM).ToInt32();
270 if(nOldPath < m_pPathArr->Count())
272 String sOldFileURL(*(*m_pPathArr)[nOldPath]);
273 sOldFileURL += INET_PATH_TOKEN;
274 sOldFileURL += rOldGroup.GetToken(0, GLOS_DELIM);
275 sOldFileURL += SwGlossaries::GetExtension();
276 BOOL bExist = FStatHelper::IsDocument( sOldFileURL );
277 DBG_ASSERT(bExist, "Gruppe existiert nicht!");
278 if(bExist)
280 sal_uInt16 nNewPath = (sal_uInt16)rNewGroup.GetToken(1, GLOS_DELIM).ToInt32();
281 if( nNewPath < m_pPathArr->Count())
283 String sNewFilePath(*(*m_pPathArr)[nNewPath]);
284 String sNewFileName = lcl_CheckFileName(
285 sNewFilePath, rNewGroup.GetToken(0, GLOS_DELIM));
286 //String aTmp( rNewGroup.GetToken(0, GLOS_DELIM));
287 const sal_uInt16 nFileNameLen = sNewFileName.Len();
288 sNewFileName += SwGlossaries::GetExtension();
289 String sTempNewFilePath(sNewFilePath);
290 sTempNewFilePath += INET_PATH_TOKEN;
291 sTempNewFilePath += sNewFileName ;
292 bExist = FStatHelper::IsDocument( sTempNewFilePath );
293 DBG_ASSERT(!bExist, "Gruppe existiert bereits!");
294 if(!bExist)
296 BOOL bCopyCompleted = SWUnoHelper::UCB_CopyFile(
297 sOldFileURL, sTempNewFilePath, TRUE );
298 if(bCopyCompleted)
300 bRet = sal_True;
301 RemoveFileFromList( rOldGroup );
303 rNewGroup = sNewFileName.Copy(0, nFileNameLen);
304 rNewGroup += GLOS_DELIM;
305 rNewGroup += String::CreateFromInt32(nNewPath);
306 String *pTmp = new String(rNewGroup);
307 if(!m_pGlosArr)
308 GetNameList();
309 else
310 m_pGlosArr->Insert(pTmp, m_pGlosArr->Count());
312 sNewFilePath += INET_PATH_TOKEN;
313 sNewFilePath += sNewFileName ;
314 SwTextBlocks* pNewBlock = new SwTextBlocks( sNewFilePath );
315 pNewBlock->SetName(rNewTitle);
316 delete pNewBlock;
322 return bRet;
325 /*------------------------------------------------------------------------
326 Beschreibung: Loescht eine Textbausteingruppe
327 ------------------------------------------------------------------------*/
330 sal_Bool SwGlossaries::DelGroupDoc(const String &rName)
332 sal_uInt16 nPath = (sal_uInt16)rName.GetToken(1, GLOS_DELIM).ToInt32();
333 if(nPath >= m_pPathArr->Count())
334 return sal_False;
335 String sFileURL(*(*m_pPathArr)[nPath]);
336 String aTmp( rName.GetToken(0, GLOS_DELIM));
337 String aName(aTmp);
338 aName += GLOS_DELIM;
339 aName += String::CreateFromInt32(nPath);
341 aTmp += SwGlossaries::GetExtension();
342 sFileURL += INET_PATH_TOKEN;
343 sFileURL += aTmp;
344 // Auch, wenn das File nicht existiert, muss es aus der Liste
345 // der Textbausteinbereiche entfernt werden
346 // Kein && wegen CFfront
347 BOOL bRemoved = SWUnoHelper::UCB_DeleteFile( sFileURL );
348 DBG_ASSERT(bRemoved, "file has not been removed");
349 RemoveFileFromList( aName );
350 return bRemoved;
352 /*------------------------------------------------------------------------
353 Beschreibung: DTOR
354 ------------------------------------------------------------------------*/
357 SwGlossaries::~SwGlossaries()
359 sal_uInt16 nCount = m_pGlosArr? m_pGlosArr->Count() : 0;
360 sal_uInt16 i;
362 for( i = 0; i < nCount; ++i)
364 String *pTmp = (*m_pGlosArr)[i];
365 delete pTmp;
367 nCount = m_pPathArr? m_pPathArr->Count() : 0;
368 for(i = 0; i < nCount; ++i)
370 String *pTmp = (*m_pPathArr)[i];
371 delete pTmp;
373 delete m_pGlosArr;
374 delete m_pPathArr;
376 InvalidateUNOOjects();
378 /*------------------------------------------------------------------------
379 Beschreibung: Bausteindokument einlesen
380 ------------------------------------------------------------------------*/
383 SwTextBlocks* SwGlossaries::GetGlosDoc( const String &rName, sal_Bool bCreate ) const
385 sal_uInt16 nPath = (sal_uInt16)rName.GetToken(1, GLOS_DELIM).ToInt32();
386 SwTextBlocks *pTmp = 0;
387 if(nPath < m_pPathArr->Count())
389 String sFileURL(*(*m_pPathArr)[nPath]);
390 String aTmp( rName.GetToken(0, GLOS_DELIM));
391 aTmp += SwGlossaries::GetExtension();
392 sFileURL += INET_PATH_TOKEN;
393 sFileURL += aTmp;
395 BOOL bExist = FALSE;
396 if(!bCreate)
397 bExist = FStatHelper::IsDocument( sFileURL );
399 if (bCreate || bExist)
401 pTmp = new SwTextBlocks( sFileURL );
402 sal_Bool bOk = sal_True;
403 if( pTmp->GetError() )
405 ErrorHandler::HandleError( pTmp->GetError() );
406 bOk = !IsError( pTmp->GetError() );
409 if( bOk && !pTmp->GetName().Len() )
410 pTmp->SetName( rName );
414 return pTmp;
417 /*------------------------------------------------------------------------
418 Beschreibung: Zugriff auf die Liste der Name; diese wird gfs. eingelesen
419 ------------------------------------------------------------------------*/
421 SvStrings* SwGlossaries::GetNameList()
423 if( !m_pGlosArr )
425 m_pGlosArr = new SvStrings;
426 String sExt( SwGlossaries::GetExtension() );
427 for( sal_uInt16 i = 0; i < m_pPathArr->Count(); i++ )
429 SvStrings aFiles( 16, 16 );
431 SWUnoHelper::UCB_GetFileListOfFolder( *(*m_pPathArr)[i], aFiles,
432 &sExt );
433 for( USHORT nFiles = 0, nFEnd = aFiles.Count();
434 nFiles < nFEnd; ++nFiles )
436 String* pTitle = aFiles[ nFiles ];
437 String sName( pTitle->Copy( 0, pTitle->Len() - sExt.Len() ));
438 sName += GLOS_DELIM;
439 sName += String::CreateFromInt32( i );
440 m_pGlosArr->Insert( new String(sName), m_pGlosArr->Count() );
442 // don't need any more these pointers
443 delete pTitle;
446 if(!m_pGlosArr->Count())
448 // Der Standard-Baustein steht im ersten Teil des Pfades
449 String *pTmp = new String( SwGlossaries::GetDefName() );
450 (*pTmp) += GLOS_DELIM;
451 (*pTmp) += '0';
452 m_pGlosArr->Insert(pTmp, m_pGlosArr->Count());
455 return m_pGlosArr;
458 /*------------------------------------------------------------------------
459 Beschreibung: CTOR
460 ------------------------------------------------------------------------*/
463 SwGlossaries::SwGlossaries() :
464 m_pPathArr(0),
465 m_pGlosArr(0)
467 m_pPathArr = new SvStrings;
468 UpdateGlosPath(sal_True);
471 /*------------------------------------------------------------------------
472 Beschreibung: Neuen Pfad einstellen und internes Array neu aufbauen
473 ------------------------------------------------------------------------*/
475 /* -----------------21.01.99 15:36-------------------
476 * #61050# Doppelte Pfade fuehren zu Verwirrung - als raus damit
477 * --------------------------------------------------*/
478 sal_Bool lcl_FindSameEntry(const SvStrings& rDirArr, const String& rEntryURL)
480 for(sal_uInt16 i = 0; i < rDirArr.Count(); i++)
481 if(rEntryURL == (*rDirArr.GetObject(i)))
482 return sal_True;
483 return sal_False;
486 void SwGlossaries::UpdateGlosPath(sal_Bool bFull)
488 SvtPathOptions aPathOpt;
489 String aNewPath( aPathOpt.GetAutoTextPath() );
490 sal_Bool bPathChanged = m_aPath != aNewPath;
491 if (bFull || bPathChanged)
493 m_aPath = aNewPath;
494 sal_uInt16 nCount = m_pPathArr? m_pPathArr->Count() : 0;
495 sal_uInt16 i;
497 for( i = nCount; i; --i)
499 String *pTmp = (*m_pPathArr)[i - 1];
500 m_pPathArr->Remove(i - 1);
501 delete pTmp;
503 sal_uInt16 nTokenCount = m_aPath.GetTokenCount(SVT_SEARCHPATH_DELIMITER);
504 SvStrings aDirArr;
505 for( i = 0; i < nTokenCount; i++ )
507 String sPth(m_aPath.GetToken(i, SVT_SEARCHPATH_DELIMITER));
508 sPth = URIHelper::SmartRel2Abs(
509 INetURLObject(), sPth, URIHelper::GetMaybeFileHdl());
511 if(i && lcl_FindSameEntry(aDirArr, sPth))
513 continue;
515 aDirArr.Insert(new String(sPth), aDirArr.Count());
516 if( !FStatHelper::IsFolder( sPth ) )
518 if( m_sErrPath.Len() )
519 m_sErrPath += SVT_SEARCHPATH_DELIMITER;
520 INetURLObject aTemp( sPth );
521 m_sErrPath += String(aTemp.GetFull());
523 else
524 m_pPathArr->Insert(new String(sPth), m_pPathArr->Count());
526 aDirArr.DeleteAndDestroy(0, aDirArr.Count());
528 if(!nTokenCount ||
529 m_sErrPath.Len() && (bPathChanged || m_sOldErrPath != m_sErrPath) )
531 m_sOldErrPath = m_sErrPath;
532 // Falscher Pfad, d.h. AutoText-Verzeichnis existiert nicht
534 ErrorHandler::HandleError( *new StringErrorInfo(
535 ERR_AUTOPATH_ERROR, m_sErrPath,
536 ERRCODE_BUTTON_OK | ERRCODE_MSG_ERROR ));
537 m_bError = sal_True;
539 else
540 m_bError = sal_False;
542 if(m_pGlosArr)
544 for(i = 0; i < m_pGlosArr->Count(); ++i)
546 delete (String *)(*m_pGlosArr)[i];
548 DELETEZ(m_pGlosArr);
549 GetNameList();
554 /*------------------------------------------------------------------------
555 Beschreibung:
556 ------------------------------------------------------------------------*/
559 void SwGlossaries::ShowError()
561 sal_uInt32 nPathError = *new StringErrorInfo(ERR_AUTOPATH_ERROR,
562 m_sErrPath, ERRCODE_BUTTON_OK );
563 ErrorHandler::HandleError( nPathError );
565 /* -----------------------------09.02.00 11:37--------------------------------
567 ---------------------------------------------------------------------------*/
568 String SwGlossaries::GetExtension()
570 return String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( ".bau" ));
575 void SwGlossaries::RemoveFileFromList( const String& rGroup )
577 if(m_pGlosArr)
579 const sal_uInt16 nCount = m_pGlosArr->Count();
580 for(sal_uInt16 i = 0; i < nCount; ++i)
582 String *pTmp = (*m_pGlosArr)[i];
583 if(*pTmp == rGroup)
585 rtl::OUString aUName = rGroup;
587 // tell the UNO AutoTextGroup object that it's not valid anymore
588 for ( UnoAutoTextGroups::iterator aLoop = m_aGlossaryGroups.begin();
589 aLoop != m_aGlossaryGroups.end();
590 ++aLoop
593 Reference< container::XNamed > xNamed( aLoop->get(), UNO_QUERY );
594 if ( xNamed.is() && ( xNamed->getName() == aUName ) )
596 static_cast< SwXAutoTextGroup* >( xNamed.get() )->Invalidate();
597 // note that this static_cast works because we know that the array only
598 // contains SwXAutoTextGroup implementation
599 m_aGlossaryGroups.erase( aLoop );
600 break;
606 // tell all our UNO AutoTextEntry objects that they're not valid anymore
607 for ( UnoAutoTextEntries::iterator aLoop = m_aGlossaryEntries.begin();
608 aLoop != m_aGlossaryEntries.end();
611 Reference< lang::XUnoTunnel > xEntryTunnel( aLoop->get(), UNO_QUERY );
613 SwXAutoTextEntry* pEntry = NULL;
614 if ( xEntryTunnel.is() )
615 pEntry = reinterpret_cast< SwXAutoTextEntry* >(
616 xEntryTunnel->getSomething( SwXAutoTextEntry::getUnoTunnelId() ) );
618 if ( pEntry && ( pEntry->GetGroupName() == rGroup ) )
620 pEntry->Invalidate();
621 aLoop = m_aGlossaryEntries.erase( aLoop );
623 else
624 ++aLoop;
628 m_pGlosArr->Remove(i);
629 delete pTmp;
630 break;
637 String SwGlossaries::GetCompleteGroupName( const rtl::OUString& GroupName )
639 sal_uInt16 nCount = GetGroupCnt();
640 //wenn der Gruppenname intern erzeugt wurde, dann steht auch hier der Pfad drin
641 String sGroup(GroupName);
642 String sGroupName(sGroup.GetToken(0, GLOS_DELIM));
643 String sPath = sGroup.GetToken(1, GLOS_DELIM);
644 sal_Bool bPathLen = sPath.Len() > 0;
645 for ( sal_uInt16 i = 0; i < nCount; i++ )
647 String sGrpName = GetGroupName(i);
648 if(bPathLen ? sGroup == sGrpName : sGroupName == sGrpName.GetToken(0, GLOS_DELIM))
650 return sGrpName;
653 return aEmptyStr;
657 void SwGlossaries::InvalidateUNOOjects()
659 // invalidate all the AutoTextGroup-objects
660 for ( UnoAutoTextGroups::iterator aGroupLoop = m_aGlossaryGroups.begin();
661 aGroupLoop != m_aGlossaryGroups.end();
662 ++aGroupLoop
665 Reference< text::XAutoTextGroup > xGroup( aGroupLoop->get(), UNO_QUERY );
666 if ( xGroup.is() )
667 static_cast< SwXAutoTextGroup* >( xGroup.get() )->Invalidate();
669 UnoAutoTextGroups aTmpg = UnoAutoTextGroups();
670 m_aGlossaryGroups.swap( aTmpg );
672 // invalidate all the AutoTextEntry-objects
673 for ( UnoAutoTextEntries::const_iterator aEntryLoop = m_aGlossaryEntries.begin();
674 aEntryLoop != m_aGlossaryEntries.end();
675 ++aEntryLoop
678 Reference< lang::XUnoTunnel > xEntryTunnel( aEntryLoop->get(), UNO_QUERY );
679 SwXAutoTextEntry* pEntry = NULL;
680 if ( xEntryTunnel.is() )
681 pEntry = reinterpret_cast< SwXAutoTextEntry* >(
682 xEntryTunnel->getSomething( SwXAutoTextEntry::getUnoTunnelId() ) );
684 if ( pEntry )
685 pEntry->Invalidate();
687 UnoAutoTextEntries aTmpe = UnoAutoTextEntries();
688 m_aGlossaryEntries.swap( aTmpe );
691 //-----------------------------------------------------------------------
692 //--- 03.03.2003 14:15:32 -----------------------------------------------
694 Reference< text::XAutoTextGroup > SwGlossaries::GetAutoTextGroup( const ::rtl::OUString& _rGroupName, bool _bCreate )
696 // first, find the name with path-extension
697 String sCompleteGroupName = GetCompleteGroupName( _rGroupName );
699 Reference< text::XAutoTextGroup > xGroup;
701 // look up the group in the cache
702 UnoAutoTextGroups::iterator aSearch = m_aGlossaryGroups.begin();
703 for ( ; aSearch != m_aGlossaryGroups.end(); )
705 Reference< lang::XUnoTunnel > xGroupTunnel( aSearch->get(), UNO_QUERY );
707 SwXAutoTextGroup* pSwGroup = 0;
708 if ( xGroupTunnel.is() )
709 pSwGroup = reinterpret_cast< SwXAutoTextGroup* >( xGroupTunnel->getSomething( SwXAutoTextGroup::getUnoTunnelId() ) );
711 if ( !pSwGroup )
713 // the object is dead in the meantime -> remove from cache
714 aSearch = m_aGlossaryGroups.erase( aSearch );
715 continue;
718 if ( _rGroupName == pSwGroup->getName() )
719 { // the group is already cached
720 if ( sCompleteGroupName.Len() )
721 { // the group still exists -> return it
722 xGroup = pSwGroup;
723 break;
725 else
727 // this group does not exist (anymore) -> release the cached UNO object for it
728 aSearch = m_aGlossaryGroups.erase( aSearch );
729 // so it won't be created below
730 _bCreate = sal_False;
731 break;
735 ++aSearch;
738 if ( !xGroup.is() && _bCreate )
740 xGroup = new SwXAutoTextGroup( sCompleteGroupName, this );
741 // cache it
742 m_aGlossaryGroups.push_back( AutoTextGroupRef( xGroup ) );
745 return xGroup;
748 //-----------------------------------------------------------------------
749 //--- 03.03.2003 13:46:06 -----------------------------------------------
751 Reference< text::XAutoTextEntry > SwGlossaries::GetAutoTextEntry( const String& _rCompleteGroupName, const ::rtl::OUString& _rGroupName, const ::rtl::OUString& _rEntryName,
752 bool _bCreate )
754 //standard must be created
755 sal_Bool bCreate = ( _rCompleteGroupName == GetDefName() );
756 ::std::auto_ptr< SwTextBlocks > pGlosGroup( GetGroupDoc( _rCompleteGroupName, bCreate ) );
758 if ( pGlosGroup.get() && !pGlosGroup->GetError() )
760 sal_uInt16 nIdx = pGlosGroup->GetIndex( _rEntryName );
761 if ( USHRT_MAX == nIdx )
762 throw container::NoSuchElementException();
764 else
765 throw lang::WrappedTargetException();
767 Reference< text::XAutoTextEntry > xReturn;
768 String sGroupName( _rGroupName );
769 String sEntryName( _rEntryName );
771 UnoAutoTextEntries::iterator aSearch( m_aGlossaryEntries.begin() );
772 for ( ; aSearch != m_aGlossaryEntries.end(); )
774 Reference< lang::XUnoTunnel > xEntryTunnel( aSearch->get(), UNO_QUERY );
776 SwXAutoTextEntry* pEntry = NULL;
777 if ( xEntryTunnel.is() )
778 pEntry = reinterpret_cast< SwXAutoTextEntry* >( xEntryTunnel->getSomething( SwXAutoTextEntry::getUnoTunnelId() ) );
779 else
781 // the object is dead in the meantime -> remove from cache
782 aSearch = m_aGlossaryEntries.erase( aSearch );
783 continue;
786 if ( pEntry
787 && ( COMPARE_EQUAL == pEntry->GetGroupName().CompareTo( sGroupName ) )
788 && ( COMPARE_EQUAL == pEntry->GetEntryName().CompareTo( sEntryName ) )
791 xReturn = pEntry;
792 break;
795 ++aSearch;
798 if ( !xReturn.is() && _bCreate )
800 xReturn = new SwXAutoTextEntry( this, sGroupName, sEntryName );
801 // cache it
802 m_aGlossaryEntries.push_back( AutoTextEntryRef( xReturn ) );
805 return xReturn;