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