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