Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <memory>
31 : :
32 : : #include <com/sun/star/container/XNamed.hpp>
33 : :
34 : : #include <unotools/transliterationwrapper.hxx>
35 : :
36 : :
37 : : #ifndef __RSC //autogen
38 : : #include <tools/errinf.hxx>
39 : : #endif
40 : : #include <osl/diagnose.h>
41 : : #include <svl/urihelper.hxx>
42 : : #include <svl/fstathelper.hxx>
43 : : #include <unotools/pathoptions.hxx>
44 : : #include <unotools/tempfile.hxx>
45 : : #include <comphelper/string.hxx>
46 : : #include <swtypes.hxx>
47 : : #include <uitool.hxx>
48 : : #include <glosdoc.hxx>
49 : : #include <shellio.hxx>
50 : : #include <swunohelper.hxx>
51 : :
52 : : #include <unoatxt.hxx>
53 : : #include <swerror.h>
54 : : #include <globals.hrc>
55 : :
56 : : using namespace ::com::sun::star;
57 : : using namespace ::com::sun::star::uno;
58 : :
59 : : // PUBLIC METHODES -------------------------------------------------------
60 : 8 : String lcl_CheckFileName( const String& rNewFilePath,
61 : : const String& rNewGroupName )
62 : : {
63 : 8 : String sRet;
64 : : //group name should contain only A-Z and a-z and spaces
65 [ + + ]: 110 : for( xub_StrLen i = 0; i < rNewGroupName.Len(); i++ )
66 : : {
67 : 102 : sal_Unicode cChar = rNewGroupName.GetChar(i);
68 [ - + ][ # # ]: 102 : if (comphelper::string::isalnumAscii(cChar) ||
[ # # ][ + - ]
[ + - ]
69 : : cChar == '_' || cChar == 0x20)
70 : : {
71 [ + - ]: 102 : sRet += cChar;
72 : : }
73 : : }
74 [ + - ][ + - ]: 8 : sRet = comphelper::string::strip(sRet, ' ');
[ + - ]
75 : :
76 : 8 : sal_Bool bOk = sal_False;
77 [ + - ]: 8 : if( sRet.Len() )
78 : : {
79 [ + - ]: 8 : String sTmpDir(rNewFilePath);
80 [ + - ]: 8 : sTmpDir += INET_PATH_TOKEN;
81 [ + - ]: 8 : sTmpDir += sRet;
82 [ + - ][ + - ]: 8 : sTmpDir += SwGlossaries::GetExtension();
[ + - ]
83 [ + - ][ + - ]: 8 : bOk = !FStatHelper::IsDocument( sTmpDir );
[ + - ]
84 : : }
85 : :
86 [ - + ]: 8 : if( !bOk )
87 : : {
88 [ # # ]: 0 : String rSG = SwGlossaries::GetExtension();
89 : : //generate generic name
90 : : utl::TempFile aTemp(rtl::OUString("group"),
91 [ # # ][ # # ]: 0 : &rSG, &rNewFilePath );
[ # # ]
92 : 0 : aTemp.EnableKillingFile();
93 : :
94 [ # # ][ # # ]: 0 : INetURLObject aTempURL( aTemp.GetURL() );
[ # # ][ # # ]
95 [ # # ][ # # ]: 0 : sRet = aTempURL.GetBase();
[ # # ][ # # ]
[ # # ]
96 : : }
97 : 8 : return sRet;
98 : : }
99 : :
100 : : /*------------------------------------------------------------------------
101 : : Description: supplies the default group's name
102 : : ------------------------------------------------------------------------*/
103 : 16 : String SwGlossaries::GetDefName()
104 : : {
105 [ + - ]: 16 : return rtl::OUString("standard");
106 : :
107 : : }
108 : :
109 : : /*------------------------------------------------------------------------
110 : : Description: supplies the number of text block groups
111 : : ------------------------------------------------------------------------*/
112 : 60 : sal_uInt16 SwGlossaries::GetGroupCnt()
113 : : {
114 : 60 : return static_cast<sal_uInt16>(GetNameList().size());
115 : : }
116 : :
117 : : /*------------------------------------------------------------------------
118 : : Description: supplies the group's name
119 : : ------------------------------------------------------------------------*/
120 : 0 : sal_Bool SwGlossaries::FindGroupName(String & rGroup)
121 : : {
122 : : // if the group name doesn't contain a path, a suitable group entry
123 : : // can the searched for here;
124 : 0 : sal_uInt16 nCount = GetGroupCnt();
125 : : sal_uInt16 i;
126 [ # # ]: 0 : for(i= 0; i < nCount; i++)
127 : : {
128 [ # # ]: 0 : String sTemp(GetGroupName(i));
129 [ # # ][ # # ]: 0 : if(rGroup.Equals( sTemp.GetToken(0, GLOS_DELIM)))
[ # # ][ # # ]
130 : : {
131 [ # # ]: 0 : rGroup = sTemp;
132 : 0 : return sal_True;
133 : : }
134 [ # # ][ # # ]: 0 : }
135 : : // you can search two times because for more directories the case sensitive
136 : : // name could occur multiple times
137 : 0 : const ::utl::TransliterationWrapper& rSCmp = GetAppCmpStrIgnore();
138 [ # # ]: 0 : for(i = 0; i < nCount; i++)
139 : : {
140 [ # # ]: 0 : String sTemp( GetGroupName( i ));
141 [ # # ][ # # ]: 0 : sal_uInt16 nPath = (sal_uInt16)sTemp.GetToken(1, GLOS_DELIM).ToInt32();
[ # # ]
142 : :
143 [ # # ][ # # ]: 0 : if (!SWUnoHelper::UCB_IsCaseSensitiveFileName( m_PathArr[nPath] )
[ # # ][ # # ]
[ # # ]
144 [ # # ][ # # ]: 0 : && rSCmp.isEqual( rGroup, sTemp.GetToken( 0, GLOS_DELIM) ) )
[ # # ][ # # ]
[ # # ]
145 : : {
146 [ # # ]: 0 : rGroup = sTemp;
147 : 0 : return sal_True;
148 : : }
149 [ # # ][ # # ]: 0 : }
150 : 0 : return sal_False;
151 : : }
152 : :
153 : 182 : String SwGlossaries::GetGroupName(sal_uInt16 nGroupId)
154 : : {
155 : : OSL_ENSURE(static_cast<size_t>(nGroupId) < m_GlosArr.size(),
156 : : "SwGlossaries::GetGroupName: index out of bounds");
157 : 182 : return m_GlosArr[nGroupId];
158 : : }
159 : :
160 : 4 : String SwGlossaries::GetGroupTitle( const String& rGroupName )
161 : : {
162 [ + - ]: 4 : String sRet;
163 [ + - ]: 4 : String sGroup(rGroupName);
164 [ + - ][ - + ]: 4 : if(STRING_NOTFOUND == sGroup.Search(GLOS_DELIM))
165 [ # # ]: 0 : FindGroupName(sGroup);
166 [ + - ]: 4 : SwTextBlocks* pGroup = GetGroupDoc(sGroup, sal_False);
167 [ + - ]: 4 : if(pGroup)
168 : : {
169 [ + - ][ + - ]: 4 : sRet = pGroup->GetName();
170 [ + - ]: 4 : PutGroupDoc( pGroup );
171 : : }
172 [ + - ]: 4 : return sRet;
173 : : }
174 : :
175 : : /*------------------------------------------------------------------------
176 : : Description: supplies the group rName's text block document
177 : : ------------------------------------------------------------------------*/
178 : 110 : SwTextBlocks* SwGlossaries::GetGroupDoc(const String &rName,
179 : : sal_Bool bCreate)
180 : : {
181 : : // insert to the list of text blocks if applicable
182 [ - + ][ # # ]: 110 : if(bCreate && !m_GlosArr.empty())
[ - + ]
183 : : {
184 [ # # ]: 0 : std::vector<String>::const_iterator it(m_GlosArr.begin());
185 [ # # ][ # # ]: 0 : for (; it != m_GlosArr.end(); ++it)
[ # # ]
186 : : {
187 [ # # ][ # # ]: 0 : if (*it == rName)
[ # # ]
188 : 0 : break;
189 : : }
190 [ # # ][ # # ]: 0 : if (it == m_GlosArr.end())
191 : : { // block not in the list
192 [ # # ]: 0 : m_GlosArr.push_back(rName);
193 : : }
194 : : }
195 : 110 : return GetGlosDoc( rName, bCreate );
196 : : }
197 : :
198 : : /*------------------------------------------------------------------------
199 : : Description: delete a text block
200 : : ------------------------------------------------------------------------*/
201 : 18 : void SwGlossaries::PutGroupDoc(SwTextBlocks *pBlock) {
202 [ + - ]: 18 : delete pBlock;
203 : 18 : }
204 : :
205 : : /*------------------------------------------------------------------------
206 : : Description: Creates a new document with the group name. temporarly
207 : : also created as file so that groups remain there later
208 : : (without access).
209 : : ------------------------------------------------------------------------*/
210 : 4 : sal_Bool SwGlossaries::NewGroupDoc(String& rGroupName, const String& rTitle)
211 : : {
212 [ + - ][ + - ]: 4 : sal_uInt16 nNewPath = (sal_uInt16)rGroupName.GetToken(1, GLOS_DELIM).ToInt32();
[ + - ]
213 [ - + ]: 4 : if (static_cast<size_t>(nNewPath) >= m_PathArr.size())
214 : 0 : return sal_False;
215 [ + - ][ + - ]: 4 : String sNewFilePath(m_PathArr[nNewPath]);
216 [ + - ][ + - ]: 4 : String sNewGroup = lcl_CheckFileName(sNewFilePath, rGroupName.GetToken(0, GLOS_DELIM));
[ + - ]
217 [ + - ]: 4 : sNewGroup += GLOS_DELIM;
218 [ + - ][ + - ]: 4 : sNewGroup += rGroupName.GetToken(1, GLOS_DELIM);
[ + - ]
219 [ + - ]: 4 : SwTextBlocks *pBlock = GetGlosDoc( sNewGroup );
220 [ + - ]: 4 : if(pBlock)
221 : : {
222 [ + - ][ + - ]: 4 : GetNameList().push_back(sNewGroup);
223 [ + - ]: 4 : pBlock->SetName(rTitle);
224 [ + - ]: 4 : PutGroupDoc(pBlock);
225 [ + - ]: 4 : rGroupName = sNewGroup;
226 : 4 : return sal_True;
227 : : }
228 [ + - ][ + - ]: 4 : return sal_False;
229 : : }
230 : :
231 : 4 : sal_Bool SwGlossaries::RenameGroupDoc(
232 : : const String& rOldGroup, String& rNewGroup, const String& rNewTitle )
233 : : {
234 : 4 : sal_Bool bRet = sal_False;
235 [ + - ]: 4 : sal_uInt16 nOldPath = (sal_uInt16)rOldGroup.GetToken(1, GLOS_DELIM).ToInt32();
236 [ + - ]: 4 : if (static_cast<size_t>(nOldPath) < m_PathArr.size())
237 : : {
238 [ + - ][ + - ]: 4 : String sOldFileURL(m_PathArr[nOldPath]);
239 [ + - ]: 4 : sOldFileURL += INET_PATH_TOKEN;
240 [ + - ][ + - ]: 4 : sOldFileURL += rOldGroup.GetToken(0, GLOS_DELIM);
[ + - ]
241 [ + - ][ + - ]: 4 : sOldFileURL += SwGlossaries::GetExtension();
[ + - ]
242 [ + - ][ + - ]: 4 : sal_Bool bExist = FStatHelper::IsDocument( sOldFileURL );
243 : : OSL_ENSURE(bExist, "group doesn't exist!");
244 [ + - ]: 4 : if(bExist)
245 : : {
246 [ + - ][ + - ]: 4 : sal_uInt16 nNewPath = (sal_uInt16)rNewGroup.GetToken(1, GLOS_DELIM).ToInt32();
[ + - ]
247 [ + - ]: 4 : if (static_cast<size_t>(nNewPath) < m_PathArr.size())
248 : : {
249 [ + - ][ + - ]: 4 : String sNewFilePath(m_PathArr[nNewPath]);
250 : : String sNewFileName = lcl_CheckFileName(
251 [ + - ][ + - ]: 4 : sNewFilePath, rNewGroup.GetToken(0, GLOS_DELIM));
[ + - ]
252 : 4 : const sal_uInt16 nFileNameLen = sNewFileName.Len();
253 [ + - ][ + - ]: 4 : sNewFileName += SwGlossaries::GetExtension();
[ + - ]
254 [ + - ]: 4 : String sTempNewFilePath(sNewFilePath);
255 [ + - ]: 4 : sTempNewFilePath += INET_PATH_TOKEN;
256 [ + - ]: 4 : sTempNewFilePath += sNewFileName ;
257 [ + - ][ + - ]: 4 : bExist = FStatHelper::IsDocument( sTempNewFilePath );
258 : : OSL_ENSURE(!bExist, "group already exists!");
259 [ + - ]: 4 : if(!bExist)
260 : : {
261 : : sal_Bool bCopyCompleted = SWUnoHelper::UCB_CopyFile(
262 [ + - ]: 4 : sOldFileURL, sTempNewFilePath, sal_True );
263 [ + - ]: 4 : if(bCopyCompleted)
264 : : {
265 : 4 : bRet = sal_True;
266 [ + - ]: 4 : RemoveFileFromList( rOldGroup );
267 : :
268 [ + - ][ + - ]: 4 : rNewGroup = sNewFileName.Copy(0, nFileNameLen);
[ + - ]
269 [ + - ]: 4 : rNewGroup += GLOS_DELIM;
270 [ + - ][ + - ]: 4 : rNewGroup += String::CreateFromInt32(nNewPath);
[ + - ]
271 [ - + ]: 4 : if (m_GlosArr.empty())
272 : : {
273 [ # # ]: 0 : GetNameList();
274 : : }
275 : : else
276 : : {
277 [ + - ]: 4 : m_GlosArr.push_back(rNewGroup);
278 : : }
279 : :
280 [ + - ]: 4 : sNewFilePath += INET_PATH_TOKEN;
281 [ + - ]: 4 : sNewFilePath += sNewFileName ;
282 [ + - ][ + - ]: 4 : SwTextBlocks* pNewBlock = new SwTextBlocks( sNewFilePath );
283 [ + - ]: 4 : pNewBlock->SetName(rNewTitle);
284 [ + - ][ + - ]: 4 : delete pNewBlock;
285 : : }
286 [ + - ][ + - ]: 4 : }
[ + - ]
287 : : }
288 [ + - ]: 4 : }
289 : : }
290 : 4 : return bRet;
291 : : }
292 : :
293 : : /*------------------------------------------------------------------------
294 : : Description: Deletes a text block group
295 : : ------------------------------------------------------------------------*/
296 : 2 : sal_Bool SwGlossaries::DelGroupDoc(const String &rName)
297 : : {
298 [ + - ][ + - ]: 2 : sal_uInt16 nPath = (sal_uInt16)rName.GetToken(1, GLOS_DELIM).ToInt32();
[ + - ]
299 [ - + ]: 2 : if (static_cast<size_t>(nPath) >= m_PathArr.size())
300 : 0 : return sal_False;
301 [ + - ][ + - ]: 2 : String sFileURL(m_PathArr[nPath]);
302 [ + - ]: 2 : String aTmp( rName.GetToken(0, GLOS_DELIM));
303 [ + - ]: 2 : String aName(aTmp);
304 [ + - ]: 2 : aName += GLOS_DELIM;
305 [ + - ][ + - ]: 2 : aName += String::CreateFromInt32(nPath);
[ + - ]
306 : :
307 [ + - ][ + - ]: 2 : aTmp += SwGlossaries::GetExtension();
[ + - ]
308 [ + - ]: 2 : sFileURL += INET_PATH_TOKEN;
309 [ + - ]: 2 : sFileURL += aTmp;
310 : : // Even if the file doesn't exist it hast to be deleted from
311 : : // the list of text block regions
312 : : // no && because of CFfront
313 [ + - ]: 2 : sal_Bool bRemoved = SWUnoHelper::UCB_DeleteFile( sFileURL );
314 : : OSL_ENSURE(bRemoved, "file has not been removed");
315 [ + - ]: 2 : RemoveFileFromList( aName );
316 [ + - ][ + - ]: 2 : return bRemoved;
[ + - ]
317 : : }
318 : :
319 [ + - ][ + - ]: 2 : SwGlossaries::~SwGlossaries()
[ + - ]
320 : : {
321 [ + - ]: 2 : InvalidateUNOOjects();
322 : 2 : }
323 : :
324 : : /*------------------------------------------------------------------------
325 : : Description: read a block document
326 : : ------------------------------------------------------------------------*/
327 : 114 : SwTextBlocks* SwGlossaries::GetGlosDoc( const String &rName, sal_Bool bCreate ) const
328 : : {
329 [ + - ]: 114 : sal_uInt16 nPath = (sal_uInt16)rName.GetToken(1, GLOS_DELIM).ToInt32();
330 : 114 : SwTextBlocks *pTmp = 0;
331 [ + - ]: 114 : if (static_cast<size_t>(nPath) < m_PathArr.size())
332 : : {
333 [ + - ][ + - ]: 114 : String sFileURL(m_PathArr[nPath]);
334 [ + - ]: 114 : String aTmp( rName.GetToken(0, GLOS_DELIM));
335 [ + - ][ + - ]: 114 : aTmp += SwGlossaries::GetExtension();
[ + - ]
336 [ + - ]: 114 : sFileURL += INET_PATH_TOKEN;
337 [ + - ]: 114 : sFileURL += aTmp;
338 : :
339 : 114 : sal_Bool bExist = sal_False;
340 [ + + ]: 114 : if(!bCreate)
341 [ + - ][ + - ]: 110 : bExist = FStatHelper::IsDocument( sFileURL );
342 : :
343 [ + + ][ + - ]: 114 : if (bCreate || bExist)
344 : : {
345 [ + - ][ + - ]: 114 : pTmp = new SwTextBlocks( sFileURL );
346 : 114 : sal_Bool bOk = sal_True;
347 [ - + ]: 114 : if( pTmp->GetError() )
348 : : {
349 [ # # ]: 0 : ErrorHandler::HandleError( pTmp->GetError() );
350 : 0 : bOk = !IsError( pTmp->GetError() );
351 : : }
352 : :
353 [ + - ][ + - ]: 114 : if( bOk && !pTmp->GetName().Len() )
[ - + ][ - + ]
354 [ # # ]: 0 : pTmp->SetName( rName );
355 [ + - ][ + - ]: 114 : }
356 : : }
357 : :
358 : 114 : return pTmp;
359 : : }
360 : :
361 : : /*------------------------------------------------------------------------
362 : : Description: access to the list of names; read in if applicable
363 : : ------------------------------------------------------------------------*/
364 : 64 : std::vector<String> & SwGlossaries::GetNameList()
365 : : {
366 [ + + ]: 64 : if (m_GlosArr.empty())
367 : : {
368 [ + - ]: 2 : String sExt( SwGlossaries::GetExtension() );
369 [ + + ]: 6 : for (size_t i = 0; i < m_PathArr.size(); ++i)
370 : : {
371 [ + - ]: 4 : std::vector<String*> aFiles;
372 : :
373 [ + - ][ + - ]: 4 : SWUnoHelper::UCB_GetFileListOfFolder(m_PathArr[i], aFiles, &sExt);
374 [ + - ]: 24 : for( std::vector<String*>::const_iterator filesIt(aFiles.begin());
[ + - + - ]
[ + + ]
375 : 12 : filesIt != aFiles.end(); ++filesIt)
376 : : {
377 [ + - ]: 8 : String *pTitle = *filesIt;
378 [ + - ]: 8 : String sName( pTitle->Copy( 0, pTitle->Len() - sExt.Len() ));
379 [ + - ]: 8 : sName += GLOS_DELIM;
380 [ + - ][ + - ]: 8 : sName += String::CreateFromInt32( static_cast<sal_Int16>(i) );
[ + - ]
381 [ + - ]: 8 : m_GlosArr.push_back(sName);
382 : :
383 : : // don't need any more these pointers
384 [ + - ][ + - ]: 8 : delete pTitle;
385 [ + - ]: 8 : }
386 : 4 : }
387 [ - + ]: 2 : if (m_GlosArr.empty())
388 : : {
389 : : // the standard block is inside of the path's first part
390 [ # # ]: 0 : String tmp( SwGlossaries::GetDefName() );
391 [ # # ]: 0 : tmp += GLOS_DELIM;
392 [ # # ]: 0 : tmp += '0';
393 [ # # ][ # # ]: 0 : m_GlosArr.push_back( tmp );
394 [ + - ]: 2 : }
395 : : }
396 : 64 : return m_GlosArr;
397 : : }
398 : :
399 [ + - ][ + - ]: 2 : SwGlossaries::SwGlossaries()
[ + - ][ + - ]
[ + - ][ + - ]
400 : : {
401 [ + - ]: 2 : UpdateGlosPath(sal_True);
402 : 2 : }
403 : :
404 : : /*------------------------------------------------------------------------
405 : : Description: set new path and recreate internal array
406 : : ------------------------------------------------------------------------*/
407 : :
408 : : /* --------------------------------------------------
409 : : * #61050# double paths cause irritation - get rid of it
410 : : * --------------------------------------------------*/
411 : 2 : sal_Bool lcl_FindSameEntry(const std::vector<String*>& rDirArr, const String& rEntryURL)
412 : : {
413 [ + - ][ + - ]: 4 : for(std::vector<String*>::const_iterator it(rDirArr.begin()); it != rDirArr.end(); ++it)
[ + + ]
414 [ + - ][ + - ]: 2 : if( **it == rEntryURL )
[ - + ]
415 : 0 : return sal_True;
416 : 2 : return sal_False;
417 : : }
418 : :
419 : 2 : void SwGlossaries::UpdateGlosPath(sal_Bool bFull)
420 : : {
421 [ + - ]: 2 : SvtPathOptions aPathOpt;
422 [ + - ][ + - ]: 2 : String aNewPath( aPathOpt.GetAutoTextPath() );
423 [ + - ]: 2 : sal_Bool bPathChanged = m_aPath != aNewPath;
424 [ - + ][ # # ]: 2 : if (bFull || bPathChanged)
425 : : {
426 [ + - ]: 2 : m_aPath = aNewPath;
427 : :
428 : 2 : m_PathArr.clear();
429 : :
430 [ + - ][ + - ]: 2 : sal_uInt16 nTokenCount = comphelper::string::getTokenCount(m_aPath, SVT_SEARCHPATH_DELIMITER);
431 [ + - ]: 2 : std::vector<String*> aDirArr;
432 [ + + ]: 6 : for( sal_uInt16 i = 0; i < nTokenCount; i++ )
433 : : {
434 [ + - ]: 4 : String sPth(m_aPath.GetToken(i, SVT_SEARCHPATH_DELIMITER));
435 : : sPth = URIHelper::SmartRel2Abs(
436 [ + - ][ + - ]: 4 : INetURLObject(), sPth, URIHelper::GetMaybeFileHdl());
[ + - ][ + - ]
[ + - ][ + - ]
437 : :
438 [ + - ][ - + ]: 4 : if(i && lcl_FindSameEntry(aDirArr, sPth))
[ - + ][ + + ]
439 : : {
440 : 0 : continue;
441 : : }
442 [ + - ][ + - ]: 4 : aDirArr.push_back(new String(sPth));
[ + - ]
443 [ + - ][ + - ]: 4 : if( !FStatHelper::IsFolder( sPth ) )
[ - + ]
444 : : {
445 [ # # ]: 0 : if( m_sErrPath.Len() )
446 [ # # ]: 0 : m_sErrPath += SVT_SEARCHPATH_DELIMITER;
447 [ # # ][ # # ]: 0 : INetURLObject aTemp( sPth );
448 [ # # ][ # # ]: 0 : m_sErrPath += String(aTemp.GetFull());
[ # # ][ # # ]
[ # # ]
449 : : }
450 : : else
451 [ + - ]: 4 : m_PathArr.push_back(sPth);
452 [ + - ][ + - ]: 4 : }
453 [ + - ][ + - ]: 6 : for(std::vector<String*>::const_iterator it(aDirArr.begin()); it != aDirArr.end(); ++it)
[ + - ][ + + ]
454 [ + - ][ + - ]: 4 : delete *it;
[ + - ]
455 : :
456 [ + - - + ]: 4 : if(!nTokenCount ||
[ # # ][ # # ]
[ - + ]
457 [ # # ]: 2 : (m_sErrPath.Len() && (bPathChanged || m_sOldErrPath != m_sErrPath)) )
458 : : {
459 [ # # ]: 0 : m_sOldErrPath = m_sErrPath;
460 : : // wrong path, that means AutoText directory doesn't exist
461 : :
462 : : ErrorHandler::HandleError( *new StringErrorInfo(
463 : : ERR_AUTOPATH_ERROR, m_sErrPath,
464 [ # # ][ # # ]: 0 : ERRCODE_BUTTON_OK | ERRCODE_MSG_ERROR ));
[ # # ][ # # ]
465 : 0 : m_bError = sal_True;
466 : : }
467 : : else
468 : 2 : m_bError = sal_False;
469 : :
470 [ - + ]: 2 : if (!m_GlosArr.empty())
471 : : {
472 : 0 : m_GlosArr.clear();
473 [ # # ]: 0 : GetNameList();
474 : 2 : }
475 [ + - ][ + - ]: 2 : }
476 : 2 : }
477 : :
478 : 0 : void SwGlossaries::ShowError()
479 : : {
480 : : sal_uInt32 nPathError = *new StringErrorInfo(ERR_AUTOPATH_ERROR,
481 [ # # ]: 0 : m_sErrPath, ERRCODE_BUTTON_OK );
482 : 0 : ErrorHandler::HandleError( nPathError );
483 : 0 : }
484 : :
485 : 134 : String SwGlossaries::GetExtension()
486 : : {
487 [ + - ]: 134 : return rtl::OUString(".bau");
488 : : }
489 : :
490 : 6 : void SwGlossaries::RemoveFileFromList( const String& rGroup )
491 : : {
492 [ + - ]: 6 : if (!m_GlosArr.empty())
493 : : {
494 [ + - + - ]: 66 : for (std::vector<String>::iterator it(m_GlosArr.begin());
[ + - ]
495 : 30 : it != m_GlosArr.end(); ++it)
496 : : {
497 [ + - ][ + - ]: 30 : if (*it == rGroup)
[ + + ]
498 : : {
499 [ + - ]: 6 : rtl::OUString aUName = rGroup;
500 : : {
501 : : // tell the UNO AutoTextGroup object that it's not valid anymore
502 [ + - ][ + + ]: 60 : for ( UnoAutoTextGroups::iterator aLoop = m_aGlossaryGroups.begin();
503 : 28 : aLoop != m_aGlossaryGroups.end();
504 : : ++aLoop
505 : : )
506 : : {
507 [ + - ][ + - ]: 26 : Reference< container::XNamed > xNamed( aLoop->get(), UNO_QUERY );
508 [ + - ][ + - ]: 26 : if ( xNamed.is() && ( xNamed->getName() == aUName ) )
[ + + ][ + - ]
[ + + # # ]
[ + - ]
509 : : {
510 [ + - ][ + - ]: 4 : static_cast< SwXAutoTextGroup* >( xNamed.get() )->Invalidate();
[ + - ]
511 : : // note that this static_cast works because we know that the array only
512 : : // contains SwXAutoTextGroup implementation
513 [ + - ]: 26 : m_aGlossaryGroups.erase( aLoop );
514 : : break;
515 : : }
516 [ + + ]: 26 : }
517 : : }
518 : :
519 : : {
520 : : // tell all our UNO AutoTextEntry objects that they're not valid anymore
521 [ + - ][ + + ]: 20 : for ( UnoAutoTextEntries::iterator aLoop = m_aGlossaryEntries.begin();
522 : 14 : aLoop != m_aGlossaryEntries.end();
523 : : )
524 : : {
525 [ + - ][ + - ]: 8 : Reference< lang::XUnoTunnel > xEntryTunnel( aLoop->get(), UNO_QUERY );
526 : :
527 : 8 : SwXAutoTextEntry* pEntry = NULL;
528 [ + - ]: 8 : if ( xEntryTunnel.is() )
529 : : pEntry = reinterpret_cast< SwXAutoTextEntry* >(
530 [ + - ][ + - ]: 8 : xEntryTunnel->getSomething( SwXAutoTextEntry::getUnoTunnelId() ) );
[ + - ]
531 : :
532 [ + - ][ + - ]: 8 : if ( pEntry && ( pEntry->GetGroupName() == rGroup ) )
[ + + ][ + + ]
533 : : {
534 : 4 : pEntry->Invalidate();
535 [ + - ]: 4 : aLoop = m_aGlossaryEntries.erase( aLoop );
536 : : }
537 : : else
538 : 4 : ++aLoop;
539 : 8 : }
540 : : }
541 : :
542 [ + - ]: 6 : m_GlosArr.erase(it);
543 : 6 : break;
544 : : }
545 : : }
546 : : }
547 : 6 : }
548 : :
549 : 46 : String SwGlossaries::GetCompleteGroupName( const rtl::OUString& GroupName )
550 : : {
551 [ + - ]: 46 : sal_uInt16 nCount = GetGroupCnt();
552 : : // when the group name was created internally the path is here as well
553 [ + - ]: 46 : String sGroup(GroupName);
554 [ + - ]: 46 : String sGroupName(sGroup.GetToken(0, GLOS_DELIM));
555 [ + - ]: 46 : String sPath = sGroup.GetToken(1, GLOS_DELIM);
556 : 46 : sal_Bool bPathLen = sPath.Len() > 0;
557 [ + + ]: 206 : for ( sal_uInt16 i = 0; i < nCount; i++ )
558 : : {
559 [ + - ]: 160 : String sGrpName = GetGroupName(i);
560 [ + + ][ + - ]: 160 : if(bPathLen ? sGroup == sGrpName : sGroupName == sGrpName.GetToken(0, GLOS_DELIM))
[ + - ][ + - ]
[ + + ][ + - ]
[ + + # # ]
561 : : {
562 [ + - ]: 160 : return sGrpName;
563 : : }
564 [ + - ][ + + ]: 160 : }
565 [ + - ][ + - ]: 46 : return aEmptyStr;
[ + - ][ + - ]
566 : : }
567 : :
568 : 2 : void SwGlossaries::InvalidateUNOOjects()
569 : : {
570 : : // invalidate all the AutoTextGroup-objects
571 [ + - ][ + + ]: 20 : for ( UnoAutoTextGroups::iterator aGroupLoop = m_aGlossaryGroups.begin();
572 : 10 : aGroupLoop != m_aGlossaryGroups.end();
573 : : ++aGroupLoop
574 : : )
575 : : {
576 [ + - ][ + - ]: 8 : Reference< text::XAutoTextGroup > xGroup( aGroupLoop->get(), UNO_QUERY );
577 [ + - ]: 8 : if ( xGroup.is() )
578 [ + - ][ + - ]: 8 : static_cast< SwXAutoTextGroup* >( xGroup.get() )->Invalidate();
[ + - ]
579 : 8 : }
580 [ + - ]: 2 : UnoAutoTextGroups aTmpg = UnoAutoTextGroups();
581 : 2 : m_aGlossaryGroups.swap( aTmpg );
582 : :
583 : : // invalidate all the AutoTextEntry-objects
584 [ + - ][ + + ]: 8 : for ( UnoAutoTextEntries::const_iterator aEntryLoop = m_aGlossaryEntries.begin();
[ + - ]
585 : 4 : aEntryLoop != m_aGlossaryEntries.end();
586 : : ++aEntryLoop
587 : : )
588 : : {
589 [ + - ][ + - ]: 2 : Reference< lang::XUnoTunnel > xEntryTunnel( aEntryLoop->get(), UNO_QUERY );
590 : 2 : SwXAutoTextEntry* pEntry = NULL;
591 [ + - ]: 2 : if ( xEntryTunnel.is() )
592 : : pEntry = reinterpret_cast< SwXAutoTextEntry* >(
593 [ + - ][ + - ]: 2 : xEntryTunnel->getSomething( SwXAutoTextEntry::getUnoTunnelId() ) );
[ + - ]
594 : :
595 [ + - ]: 2 : if ( pEntry )
596 : 2 : pEntry->Invalidate();
597 : 2 : }
598 [ + - ]: 2 : UnoAutoTextEntries aTmpe = UnoAutoTextEntries();
599 : 2 : m_aGlossaryEntries.swap( aTmpe );
600 : 2 : }
601 : :
602 : 16 : Reference< text::XAutoTextGroup > SwGlossaries::GetAutoTextGroup( const ::rtl::OUString& _rGroupName, bool _bCreate )
603 : : {
604 : : // first, find the name with path-extension
605 [ + - ]: 16 : String sCompleteGroupName = GetCompleteGroupName( _rGroupName );
606 : :
607 : 16 : Reference< text::XAutoTextGroup > xGroup;
608 : :
609 : : // look up the group in the cache
610 : 16 : UnoAutoTextGroups::iterator aSearch = m_aGlossaryGroups.begin();
611 [ + - ][ + + ]: 50 : for ( ; aSearch != m_aGlossaryGroups.end(); )
612 : : {
613 [ + - ][ + - ]: 38 : Reference< lang::XUnoTunnel > xGroupTunnel( aSearch->get(), UNO_QUERY );
614 : :
615 : 38 : SwXAutoTextGroup* pSwGroup = 0;
616 [ + - ]: 38 : if ( xGroupTunnel.is() )
617 [ + - ][ + - ]: 38 : pSwGroup = reinterpret_cast< SwXAutoTextGroup* >( xGroupTunnel->getSomething( SwXAutoTextGroup::getUnoTunnelId() ) );
[ + - ]
618 : :
619 [ - + ]: 38 : if ( !pSwGroup )
620 : : {
621 : : // the object is dead in the meantime -> remove from cache
622 [ # # ]: 0 : aSearch = m_aGlossaryGroups.erase( aSearch );
623 : 0 : continue;
624 : : }
625 : :
626 [ + - ][ + + ]: 38 : if ( _rGroupName == pSwGroup->getName() )
627 : : { // the group is already cached
628 [ + - ]: 4 : if ( sCompleteGroupName.Len() )
629 : : { // the group still exists -> return it
630 [ + - ][ + - ]: 4 : xGroup = pSwGroup;
631 : : break;
632 : : }
633 : : else
634 : : {
635 : : // this group does not exist (anymore) -> release the cached UNO object for it
636 [ # # ]: 0 : aSearch = m_aGlossaryGroups.erase( aSearch );
637 : : // so it won't be created below
638 : 0 : _bCreate = sal_False;
639 : : break;
640 : : }
641 : : }
642 : :
643 [ + - + ]: 72 : ++aSearch;
644 : 38 : }
645 : :
646 [ + + ][ + - ]: 16 : if ( !xGroup.is() && _bCreate )
[ + + ]
647 : : {
648 [ + - ][ + - ]: 12 : xGroup = new SwXAutoTextGroup( sCompleteGroupName, this );
[ + - ][ + - ]
649 : : // cache it
650 [ + - ][ + - ]: 12 : m_aGlossaryGroups.push_back( AutoTextGroupRef( xGroup ) );
[ + - ]
651 : : }
652 : :
653 [ + - ]: 16 : return xGroup;
654 : : }
655 : :
656 : 14 : Reference< text::XAutoTextEntry > SwGlossaries::GetAutoTextEntry( const String& _rCompleteGroupName, const ::rtl::OUString& _rGroupName, const ::rtl::OUString& _rEntryName,
657 : : bool _bCreate )
658 : : {
659 : : //standard must be created
660 [ + - ][ + - ]: 14 : sal_Bool bCreate = ( _rCompleteGroupName == GetDefName() );
[ + - ]
661 [ + - ]: 14 : ::std::auto_ptr< SwTextBlocks > pGlosGroup( GetGroupDoc( _rCompleteGroupName, bCreate ) );
662 : :
663 [ + - ][ + - ]: 14 : if ( pGlosGroup.get() && !pGlosGroup->GetError() )
[ + - ]
664 : : {
665 [ + - ][ + - ]: 14 : sal_uInt16 nIdx = pGlosGroup->GetIndex( _rEntryName );
[ + - ]
666 [ + + ]: 14 : if ( USHRT_MAX == nIdx )
667 [ + - ]: 2 : throw container::NoSuchElementException();
668 : : }
669 : : else
670 [ # # ]: 0 : throw lang::WrappedTargetException();
671 : :
672 : 12 : Reference< text::XAutoTextEntry > xReturn;
673 [ + - ]: 12 : String sGroupName( _rGroupName );
674 [ + - ]: 12 : String sEntryName( _rEntryName );
675 : :
676 : 12 : UnoAutoTextEntries::iterator aSearch( m_aGlossaryEntries.begin() );
677 [ + - ][ + + ]: 22 : for ( ; aSearch != m_aGlossaryEntries.end(); )
678 : : {
679 [ + - ][ + - ]: 16 : Reference< lang::XUnoTunnel > xEntryTunnel( aSearch->get(), UNO_QUERY );
680 : :
681 : 16 : SwXAutoTextEntry* pEntry = NULL;
682 [ + - ]: 16 : if ( xEntryTunnel.is() )
683 [ + - ][ + - ]: 16 : pEntry = reinterpret_cast< SwXAutoTextEntry* >( xEntryTunnel->getSomething( SwXAutoTextEntry::getUnoTunnelId() ) );
[ + - ]
684 : : else
685 : : {
686 : : // the object is dead in the meantime -> remove from cache
687 [ # # ]: 0 : aSearch = m_aGlossaryEntries.erase( aSearch );
688 : 0 : continue;
689 : : }
690 : :
691 [ + - ][ + + ]: 40 : if ( pEntry
[ + + ][ + + ]
692 [ + - ]: 16 : && ( COMPARE_EQUAL == pEntry->GetGroupName().CompareTo( sGroupName ) )
693 [ + - ]: 8 : && ( COMPARE_EQUAL == pEntry->GetEntryName().CompareTo( sEntryName ) )
694 : : )
695 : : {
696 [ + - ][ + - ]: 6 : xReturn = pEntry;
697 : : break;
698 : : }
699 : :
700 [ + - + ]: 26 : ++aSearch;
701 : 16 : }
702 : :
703 [ + + ][ + - ]: 12 : if ( !xReturn.is() && _bCreate )
[ + + ]
704 : : {
705 [ + - ][ + - ]: 6 : xReturn = new SwXAutoTextEntry( this, sGroupName, sEntryName );
[ + - ]
706 : : // cache it
707 [ + - ][ + - ]: 6 : m_aGlossaryEntries.push_back( AutoTextEntryRef( xReturn ) );
[ + - ]
708 : : }
709 : :
710 [ + - ][ + - ]: 14 : return xReturn;
[ + - ]
711 : : }
712 : :
713 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|