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 : : #include <sfx2/docfilt.hxx>
30 : : #include <sot/storage.hxx>
31 : : #include <tools/urlobj.hxx>
32 : : #include <svl/fstathelper.hxx>
33 : : #include <svl/macitem.hxx>
34 : : #include <unotools/charclass.hxx>
35 : : #include <frmfmt.hxx>
36 : : #include <doc.hxx>
37 : : #include <docary.hxx>
38 : : #include <pam.hxx>
39 : : #include <shellio.hxx>
40 : : #include <swblocks.hxx>
41 : : #include <ndtxt.hxx>
42 : : #include <mdiexp.hxx> // Progress
43 : : #include <SwXMLTextBlocks.hxx>
44 : : #include <docsh.hxx>
45 : : #include <swunohelper.hxx>
46 : :
47 : : #include <statstr.hrc>
48 : : #include <swerror.h>
49 : :
50 : : //////////////////////////////////////////////////////////////////////////
51 : :
52 : : // Hash-Code errechnen (muss nicht eindeutig sein)
53 : :
54 : :
55 : 356 : sal_uInt16 SwImpBlocks::Hash( const String& r )
56 : : {
57 : 356 : sal_uInt16 n = 0;
58 : 356 : xub_StrLen nLen = r.Len();
59 [ + - ]: 356 : if( nLen > 8 )
60 : 356 : nLen = 8;
61 : 356 : const sal_Unicode* p = r.GetBuffer();
62 [ + + ]: 3204 : while( nLen-- )
63 : 2848 : n = ( n << 1 ) + *p++;
64 : 356 : return n;
65 : : }
66 : :
67 : :
68 : 0 : SwBlockName::SwBlockName( const String& rShort, const String& rLong, long n )
69 : : : nPos( n ), aShort( rShort ), aLong( rLong ), aPackageName (rShort),
70 [ # # ][ # # ]: 0 : bIsOnlyTxtFlagInit( sal_False ), bIsOnlyTxt( sal_False )
71 : : {
72 : 0 : nHashS = SwImpBlocks::Hash( rShort );
73 : 0 : nHashL = SwImpBlocks::Hash( rLong );
74 : 0 : }
75 : 82 : SwBlockName::SwBlockName( const String& rShort, const String& rLong, const String& rPackageName)
76 : : : nPos( 0 ), aShort( rShort ), aLong( rLong ), aPackageName (rPackageName),
77 [ + - ][ + - ]: 82 : bIsOnlyTxtFlagInit( sal_False ), bIsOnlyTxt( sal_False )
78 : : {
79 : 82 : nHashS = SwImpBlocks::Hash( rShort );
80 : 82 : nHashL = SwImpBlocks::Hash( rLong );
81 : 82 : }
82 : :
83 : :
84 : : // Ist die angegebene Datei ein Storage oder gibt es sie nicht?
85 : :
86 : 118 : short SwImpBlocks::GetFileType( const String& rFile )
87 : : {
88 [ + - ][ + + ]: 118 : if( !FStatHelper::IsDocument( rFile ) )
89 : 4 : return SWBLK_NO_FILE;
90 [ + - ]: 114 : if( SwXMLTextBlocks::IsFileUCBStorage( rFile ) )
91 : 114 : return SWBLK_XML;
92 [ # # ]: 0 : if( SvStorage::IsStorageFile( rFile ) )
93 : 0 : return SWBLK_SW3;
94 : : //otherwise return NONE
95 : 118 : return SWBLK_NONE;
96 : : }
97 : :
98 : :
99 : 118 : SwImpBlocks::SwImpBlocks( const String& rFile, sal_Bool )
100 : : : aFile( rFile ),
101 : : aDateModified( Date::EMPTY ),
102 : : aTimeModified( Time::EMPTY ),
103 : : pDoc( 0 ), nCur( (sal_uInt16)-1 ),
104 [ + - ][ + - ]: 118 : bReadOnly( sal_True ), bInPutMuchBlocks( sal_False )
[ + - ][ + - ]
[ + - ][ + - ]
105 : : {
106 : : FStatHelper::GetModifiedDateTimeOfFile( rFile,
107 [ + - ][ + - ]: 118 : &aDateModified, &aTimeModified );
108 [ + - ][ + - ]: 118 : INetURLObject aObj(rFile);
109 [ + - ][ + - ]: 118 : aObj.setExtension( aEmptyStr );
110 [ + - ][ + - ]: 118 : aName = aObj.GetBase();
[ + - ]
111 : 118 : }
112 : :
113 : :
114 [ + - ][ + - ]: 116 : SwImpBlocks::~SwImpBlocks()
[ + - ][ + - ]
[ + - ]
115 : : {
116 [ + - ]: 116 : aNames.DeleteAndDestroyAll();
117 [ - + ]: 116 : }
118 : :
119 : : // Loeschen des Inhaltes des Dokuments
120 : 0 : void SwImpBlocks::ClearDoc()
121 : : {
122 : 0 : pDoc->ClearDoc();
123 : 0 : }
124 : :
125 : 0 : sal_uLong SwImpBlocks::GetDocForConversion( sal_uInt16 n )
126 : : {
127 : 0 : return GetDoc( n );
128 : : }
129 : :
130 : : // Erzeugen eines PaMs, der das ganze Dokument umfasst
131 : 2 : SwPaM* SwImpBlocks::MakePaM()
132 : : {
133 [ + - ]: 2 : SwPaM* pPam = new SwPaM( pDoc->GetNodes().GetEndOfContent() );
134 : 2 : pPam->Move( fnMoveBackward, fnGoDoc );
135 : 2 : pPam->SetMark();
136 : 2 : pPam->Move( fnMoveForward, fnGoDoc );
137 : 2 : pPam->Exchange();
138 : 2 : return pPam;
139 : : }
140 : :
141 : :
142 : 88 : sal_uInt16 SwImpBlocks::GetCount() const
143 : : {
144 : 88 : return aNames.size();
145 : : }
146 : :
147 : : // Case Insensitive
148 : 190 : sal_uInt16 SwImpBlocks::GetIndex( const String& rShort ) const
149 : : {
150 [ + - ][ + - ]: 190 : String s( GetAppCharClass().uppercase( rShort ) );
[ + - ][ + - ]
151 : 190 : sal_uInt16 nHash = Hash( s );
152 [ + + ]: 216 : for( sal_uInt16 i = 0; i < aNames.size(); i++ )
153 : : {
154 [ + - ]: 84 : const SwBlockName* pName = aNames[ i ];
155 [ + - ][ + + ]: 168 : if( pName->nHashS == nHash
[ + + ]
156 [ + - ]: 84 : && pName->aShort == s )
157 : 58 : return i;
158 : : }
159 [ + - ]: 190 : return (sal_uInt16) -1;
160 : : }
161 : :
162 : :
163 : 2 : sal_uInt16 SwImpBlocks::GetLongIndex( const String& rLong ) const
164 : : {
165 : 2 : sal_uInt16 nHash = Hash( rLong );
166 [ + + ]: 4 : for( sal_uInt16 i = 0; i < aNames.size(); i++ )
167 : : {
168 : 2 : const SwBlockName* pName = aNames[ i ];
169 [ - + ]: 2 : if( pName->nHashL == nHash
[ - + # # ]
170 : 0 : && pName->aLong == rLong )
171 : 0 : return i;
172 : : }
173 : 2 : return (sal_uInt16) -1;
174 : : }
175 : :
176 : :
177 : 38 : const String& SwImpBlocks::GetShortName( sal_uInt16 n ) const
178 : : {
179 [ + - ]: 38 : if( n < aNames.size() )
180 : 38 : return aNames[n]->aShort;
181 : 38 : return aEmptyStr;
182 : : }
183 : :
184 : :
185 : 30 : const String& SwImpBlocks::GetLongName( sal_uInt16 n ) const
186 : : {
187 [ + - ]: 30 : if( n < aNames.size() )
188 : 30 : return aNames[n]->aLong;
189 : 30 : return aEmptyStr;
190 : : }
191 : :
192 : 28 : rtl::OUString SwImpBlocks::GetPackageName( sal_uInt16 n ) const
193 : : {
194 [ + - ]: 28 : if( n < aNames.size() )
195 : 28 : return aNames[n]->aPackageName;
196 : 28 : return rtl::OUString();
197 : : }
198 : :
199 : 0 : void SwImpBlocks::AddName( const String& rShort, const String& rLong,
200 : : sal_Bool bOnlyTxt )
201 : : {
202 [ # # ]: 0 : sal_uInt16 nIdx = GetIndex( rShort );
203 [ # # ]: 0 : if( nIdx != (sal_uInt16) -1 )
204 : : {
205 [ # # ][ # # ]: 0 : delete aNames[nIdx];
[ # # ]
206 [ # # ][ # # ]: 0 : aNames.erase( aNames.begin() + nIdx );
207 : : }
208 [ # # ][ # # ]: 0 : SwBlockName* pNew = new SwBlockName( rShort, rLong, 0L );
209 : 0 : pNew->bIsOnlyTxtFlagInit = sal_True;
210 : 0 : pNew->bIsOnlyTxt = bOnlyTxt;
211 [ # # ]: 0 : aNames.insert( pNew );
212 : 0 : }
213 : :
214 : :
215 : :
216 : 34 : sal_Bool SwImpBlocks::IsFileChanged() const
217 : : {
218 : 34 : Date aTempDateModified( aDateModified );
219 [ + - ]: 34 : Time aTempTimeModified( aTimeModified );
220 : : return FStatHelper::GetModifiedDateTimeOfFile( aFile,
221 [ + - ][ + - ]: 68 : &aTempDateModified, &aTempTimeModified ) &&
[ + - ][ # # ]
222 : 34 : ( aDateModified != aTempDateModified ||
223 [ + - + - ]: 102 : aTimeModified != aTempTimeModified );
[ - + ]
224 : : }
225 : :
226 : :
227 : 30 : void SwImpBlocks::Touch()
228 : : {
229 : : FStatHelper::GetModifiedDateTimeOfFile( aFile,
230 [ + - ]: 30 : &aDateModified, &aTimeModified );
231 : 30 : }
232 : :
233 : 0 : sal_Bool SwImpBlocks::IsOnlyTextBlock( const String& ) const
234 : : {
235 : 0 : return sal_False;
236 : : }
237 : :
238 : 0 : sal_uLong SwImpBlocks::GetMacroTable( sal_uInt16, SvxMacroTableDtor&, sal_Bool )
239 : : {
240 : 0 : return 0;
241 : : }
242 : :
243 : 0 : sal_uLong SwImpBlocks::SetMacroTable( sal_uInt16 ,
244 : : const SvxMacroTableDtor& , sal_Bool )
245 : : {
246 : 0 : return 0;
247 : : }
248 : :
249 : 0 : sal_Bool SwImpBlocks::PutMuchEntries( sal_Bool )
250 : : {
251 : 0 : return sal_False;
252 : : }
253 : :
254 : : ////////////////////////////////////////////////////////////////////////////
255 : :
256 : :
257 : 118 : SwTextBlocks::SwTextBlocks( const String& rFile )
258 : 118 : : pImp( 0 ), nErr( 0 )
259 : : {
260 [ + - ][ + - ]: 118 : INetURLObject aObj(rFile);
261 [ + - ][ + - ]: 118 : String sFileName = aObj.GetMainURL( INetURLObject::NO_DECODE );
262 [ + + - ]: 118 : switch( SwImpBlocks::GetFileType( rFile ) )
[ + - ]
263 : : {
264 [ + - ][ + - ]: 114 : case SWBLK_XML: pImp = new SwXMLTextBlocks( sFileName ); break;
265 [ + - ][ + - ]: 4 : case SWBLK_NO_FILE: pImp = new SwXMLTextBlocks( sFileName ); break;
266 : : }
267 [ - + ]: 118 : if( !pImp )
268 [ + - ][ + - ]: 118 : nErr = ERR_SWG_FILE_FORMAT_ERROR;
269 : 118 : }
270 : :
271 : 116 : SwTextBlocks::~SwTextBlocks()
272 : : {
273 [ + - ]: 116 : delete pImp;
274 : 116 : }
275 : :
276 : 118 : const String& SwTextBlocks::GetName()
277 : : {
278 [ + - ]: 118 : return pImp ? pImp->aName : aEmptyStr;
279 : : }
280 : :
281 : :
282 : 8 : void SwTextBlocks::SetName( const String& r )
283 : : {
284 [ + - ]: 8 : if( pImp )
285 : 8 : pImp->SetName( r );
286 : 8 : }
287 : :
288 : :
289 : 0 : sal_Bool SwTextBlocks::IsOld() const
290 : : {
291 [ # # ]: 0 : if (pImp)
292 : : {
293 : 0 : short nType = pImp->GetFileType();
294 [ # # ][ # # ]: 0 : if (SWBLK_SW3 == nType || SWBLK_SW2 == nType )
295 : 0 : return sal_True;
296 : : }
297 : 0 : return sal_False;
298 : : }
299 : :
300 : :
301 : 54 : sal_uInt16 SwTextBlocks::GetCount() const
302 : : {
303 [ + - ]: 54 : return pImp ? pImp->GetCount() : 0;
304 : : }
305 : :
306 : :
307 : 62 : sal_uInt16 SwTextBlocks::GetIndex( const String& r ) const
308 : : {
309 [ + - ]: 62 : return pImp ? pImp->GetIndex( r ) : (sal_uInt16) -1;
310 : : }
311 : :
312 : :
313 : 2 : sal_uInt16 SwTextBlocks::GetLongIndex( const String& r ) const
314 : : {
315 [ + - ]: 2 : return pImp ? (sal_uInt16)(pImp->GetLongIndex( r )) : (sal_uInt16) -1;
316 : : }
317 : :
318 : :
319 : 18 : const String& SwTextBlocks::GetShortName( sal_uInt16 n ) const
320 : : {
321 [ + - ]: 18 : if( pImp )
322 : 18 : return pImp->GetShortName( n );
323 : 18 : return aEmptyStr;
324 : : }
325 : :
326 : :
327 : 10 : const String& SwTextBlocks::GetLongName( sal_uInt16 n ) const
328 : : {
329 [ + - ]: 10 : if( pImp )
330 : 10 : return pImp->GetLongName( n );
331 : 10 : return aEmptyStr;
332 : : }
333 : :
334 : :
335 : 10 : sal_Bool SwTextBlocks::Delete( sal_uInt16 n )
336 : : {
337 [ + - ][ + - ]: 10 : if( pImp && !pImp->bInPutMuchBlocks )
338 : : {
339 [ - + ]: 10 : if( pImp->IsFileChanged() )
340 : 0 : nErr = ERR_TXTBLOCK_NEWFILE_ERROR;
341 [ + - ]: 10 : else if( 0 == (nErr = pImp->OpenFile( sal_False ) ))
342 : : {
343 : 10 : nErr = pImp->Delete( n );
344 [ + - ]: 10 : if( !nErr )
345 : : {
346 [ + - ]: 10 : delete pImp->aNames[n];
347 [ + - ][ + - ]: 10 : pImp->aNames.erase( pImp->aNames.begin() + n );
348 : : }
349 [ - + ]: 10 : if( n == pImp->nCur )
350 : 0 : pImp->nCur = (sal_uInt16) -1;
351 [ + - ]: 10 : if( !nErr )
352 : 10 : nErr = pImp->MakeBlockList();
353 : : }
354 : 10 : pImp->CloseFile();
355 : 10 : pImp->Touch();
356 : :
357 : 10 : return sal_Bool( nErr == 0 );
358 : : }
359 : 10 : return sal_False;
360 : : }
361 : :
362 : :
363 : 2 : sal_uInt16 SwTextBlocks::Rename( sal_uInt16 n, const String* s, const String* l )
364 : : {
365 : 2 : sal_uInt16 nIdx = (sal_uInt16)-1;
366 [ + - ][ + - ]: 2 : if( pImp && !pImp->bInPutMuchBlocks )
367 : : {
368 : 2 : pImp->nCur = nIdx;
369 [ + - ][ + - ]: 2 : String aNew, aLong;
370 [ + - ]: 2 : if( s )
371 [ + - ][ + - ]: 2 : aNew = aLong = *s;
372 [ + - ]: 2 : if( l )
373 [ + - ]: 2 : aLong = *l;
374 [ - + ]: 2 : if( !aNew.Len() )
375 : : {
376 : : OSL_ENSURE( !this, "Kein Kurzname in Rename angegeben" );
377 : 0 : nErr = ERR_SWG_INTERNAL_ERROR; return (sal_uInt16) -1;
378 : : }
379 : :
380 [ + - ][ - + ]: 2 : if( pImp->IsFileChanged() )
381 : 0 : nErr = ERR_TXTBLOCK_NEWFILE_ERROR;
382 [ + - ][ + - ]: 2 : else if( 0 == ( nErr = pImp->OpenFile( sal_False )))
383 : : {
384 : : // Vorher den neuen Eintrag in die Liste setzen!
385 [ + - ][ + - ]: 2 : aNew = GetAppCharClass().uppercase( aNew );
[ + - ][ + - ]
386 [ + - ]: 2 : nErr = pImp->Rename( n, aNew, aLong );
387 [ + - ]: 2 : if( !nErr )
388 : : {
389 [ + - ]: 2 : sal_Bool bOnlyTxt = pImp->aNames[ n ]->bIsOnlyTxt;
390 [ + - ][ + - ]: 2 : delete pImp->aNames[n];
[ + - ]
391 [ + - ][ + - ]: 2 : pImp->aNames.erase( pImp->aNames.begin() + n );
392 [ + - ]: 2 : pImp->AddName( aNew, aLong, bOnlyTxt );
393 [ + - ]: 2 : nErr = pImp->MakeBlockList();
394 : : }
395 : : }
396 [ + - ]: 2 : pImp->CloseFile();
397 [ + - ]: 2 : pImp->Touch();
398 [ + - ]: 2 : if( !nErr )
399 [ + - ][ + - ]: 2 : nIdx = pImp->GetIndex( aNew );
[ - + ][ + - ]
[ + - ]
400 : : }
401 : 2 : return nIdx;
402 : : }
403 : :
404 : 0 : sal_uLong SwTextBlocks::CopyBlock( SwTextBlocks& rSource, String& rSrcShort,
405 : : const String& rLong )
406 : : {
407 : 0 : sal_Bool bIsOld = sal_False;
408 [ # # ]: 0 : if (rSource.pImp)
409 : : {
410 : 0 : short nType = rSource.pImp->GetFileType();
411 [ # # ][ # # ]: 0 : if (SWBLK_SW2 == nType || SWBLK_SW3 == nType )
412 : 0 : bIsOld = sal_True;
413 : : }
414 [ # # ]: 0 : if( bIsOld ) //rSource.IsOld() )
415 : 0 : nErr = ERR_SWG_OLD_GLOSSARY;
416 [ # # ]: 0 : else if( pImp->bInPutMuchBlocks )
417 : 0 : nErr = ERR_SWG_INTERNAL_ERROR;
418 : : else
419 : 0 : nErr = pImp->CopyBlock(*rSource.pImp, rSrcShort, rLong);
420 : 0 : return nErr;
421 : : }
422 : :
423 : 8 : sal_Bool SwTextBlocks::BeginGetDoc( sal_uInt16 n )
424 : : {
425 [ + - ][ + - ]: 8 : if( pImp && !pImp->bInPutMuchBlocks )
426 : : {
427 : : // diese Optimierierung darf es nicht mehr geben. OLE-Objecte muessen auf
428 : : // ihre SubStorages zugreifem koennen!
429 : : // if( n == pImp->nCur )
430 : : // return sal_True;
431 : :
432 [ - + ]: 8 : if( pImp->IsFileChanged() )
433 : 0 : nErr = ERR_TXTBLOCK_NEWFILE_ERROR;
434 [ + - ]: 8 : else if( 0 == ( nErr = pImp->OpenFile( sal_True )))
435 : : {
436 : 8 : pImp->ClearDoc();
437 : 8 : nErr = pImp->GetDoc( n );
438 [ - + ]: 8 : if( nErr )
439 : 0 : pImp->nCur = (sal_uInt16)-1;
440 : : else
441 : 8 : pImp->nCur = n;
442 : : }
443 : 8 : return sal_Bool( nErr == 0 );
444 : : }
445 : 8 : return sal_False;
446 : : }
447 : :
448 : :
449 : 8 : void SwTextBlocks::EndGetDoc()
450 : : {
451 [ + - ][ + - ]: 8 : if( pImp && !pImp->bInPutMuchBlocks )
452 : 8 : pImp->CloseFile();
453 : 8 : }
454 : :
455 : :
456 : 2 : sal_Bool SwTextBlocks::BeginPutDoc( const String& s, const String& l )
457 : : {
458 [ + - ]: 2 : if( pImp )
459 : : {
460 : 2 : sal_Bool bOk = pImp->bInPutMuchBlocks;
461 [ + - ]: 2 : if( !bOk )
462 : : {
463 [ - + ]: 2 : if( pImp->IsFileChanged() )
464 : 0 : nErr = ERR_TXTBLOCK_NEWFILE_ERROR;
465 : : else
466 : 2 : nErr = pImp->OpenFile( sal_False );
467 : 2 : bOk = 0 == nErr;
468 : : }
469 [ + - ]: 2 : if( bOk )
470 : : {
471 [ + - ][ + - ]: 2 : String aNew = GetAppCharClass().uppercase(s);
[ + - ][ + - ]
472 [ + - ][ + - ]: 2 : nErr = pImp->BeginPutDoc( aNew, l );
473 : : }
474 [ - + ]: 2 : if( nErr )
475 : 0 : pImp->CloseFile();
476 : : }
477 : 2 : return 0 == nErr;
478 : : }
479 : :
480 : :
481 : 2 : sal_uInt16 SwTextBlocks::PutDoc()
482 : : {
483 : 2 : sal_uInt16 nIdx = (sal_uInt16)-1;
484 [ + - ]: 2 : if( pImp )
485 : : {
486 : 2 : nErr = pImp->PutDoc();
487 [ + - ]: 2 : if( !nErr )
488 : : {
489 : 2 : pImp->nCur = GetIndex( pImp->aShort );
490 [ - + ]: 2 : if( pImp->nCur != (sal_uInt16) -1 )
491 : 0 : pImp->aNames[ pImp->nCur ]->aLong = pImp->aLong;
492 : : else
493 : : {
494 : 2 : pImp->AddName( pImp->aShort, pImp->aLong );
495 : 2 : pImp->nCur = pImp->GetIndex( pImp->aShort );
496 : : }
497 [ + - ]: 2 : if( !pImp->bInPutMuchBlocks )
498 : 2 : nErr = pImp->MakeBlockList();
499 : : }
500 [ + - ]: 2 : if( !pImp->bInPutMuchBlocks )
501 : : {
502 : 2 : pImp->CloseFile();
503 : 2 : pImp->Touch();
504 : : }
505 : 2 : nIdx = pImp->nCur;
506 : : }
507 : 2 : return nIdx;
508 : : }
509 : :
510 : 12 : sal_uInt16 SwTextBlocks::PutText( const String& rShort, const String& rName,
511 : : const String& rTxt )
512 : : {
513 : 12 : sal_uInt16 nIdx = (sal_uInt16) -1;
514 [ + - ]: 12 : if( pImp )
515 : : {
516 : 12 : sal_Bool bOk = pImp->bInPutMuchBlocks;
517 [ + - ]: 12 : if( !bOk )
518 : : {
519 [ - + ]: 12 : if( pImp->IsFileChanged() )
520 : 0 : nErr = ERR_TXTBLOCK_NEWFILE_ERROR;
521 : : else
522 : 12 : nErr = pImp->OpenFile( sal_False );
523 : 12 : bOk = 0 == nErr;
524 : : }
525 [ + - ]: 12 : if( bOk )
526 : : {
527 [ + - ][ + - ]: 12 : String aNew = GetAppCharClass().uppercase( rShort );
[ + - ][ + - ]
528 [ + - ]: 12 : nErr = pImp->PutText( aNew, rName, rTxt );
529 : 12 : pImp->nCur = (sal_uInt16) -1;
530 [ + - ]: 12 : if( !nErr )
531 : : {
532 [ + - ]: 12 : nIdx = GetIndex( pImp->aShort );
533 [ + + ]: 12 : if( nIdx != (sal_uInt16) -1 )
534 [ + - ][ + - ]: 2 : pImp->aNames[ nIdx ]->aLong = rName;
535 : : else
536 : : {
537 [ + - ]: 10 : pImp->AddName( pImp->aShort, rName, sal_True );
538 [ + - ]: 10 : nIdx = pImp->GetIndex( pImp->aShort );
539 : : }
540 [ + - ]: 12 : if( !pImp->bInPutMuchBlocks )
541 [ + - ]: 12 : nErr = pImp->MakeBlockList();
542 [ + - ]: 12 : }
543 : : }
544 [ + - ]: 12 : if( !pImp->bInPutMuchBlocks )
545 : : {
546 : 12 : pImp->CloseFile();
547 : 12 : pImp->Touch();
548 : : }
549 : : }
550 : 12 : return nIdx;
551 : : }
552 : :
553 : :
554 : 22 : SwDoc* SwTextBlocks::GetDoc()
555 : : {
556 [ + - ]: 22 : if( pImp )
557 : 22 : return pImp->pDoc;
558 : 22 : return 0;
559 : : }
560 : :
561 : :
562 : 2 : void SwTextBlocks::ClearDoc()
563 : : {
564 [ + - ]: 2 : if( pImp )
565 : 2 : pImp->ClearDoc();
566 : 2 : pImp->nCur = (sal_uInt16) -1;
567 : 2 : }
568 : :
569 : :
570 : 0 : const String& SwTextBlocks::GetFileName() const
571 : : {
572 : 0 : return pImp->GetFileName();
573 : : }
574 : :
575 : :
576 : 0 : sal_Bool SwTextBlocks::IsReadOnly() const
577 : : {
578 : 0 : return pImp->bReadOnly;
579 : : }
580 : :
581 : 8 : sal_Bool SwTextBlocks::IsOnlyTextBlock( sal_uInt16 nIdx ) const
582 : : {
583 : 8 : sal_Bool bRet = sal_False;
584 [ + - ][ + - ]: 8 : if( pImp && !pImp->bInPutMuchBlocks )
585 : : {
586 : 8 : SwBlockName* pBlkNm = const_cast<SwBlockName*>( pImp->aNames[ nIdx ] );
587 [ - + ][ - + : 8 : if( !pBlkNm->bIsOnlyTxtFlagInit &&
# # # # ]
588 : 0 : !pImp->IsFileChanged() && !pImp->OpenFile( sal_True ) )
589 : : {
590 : 0 : pBlkNm->bIsOnlyTxt = pImp->IsOnlyTextBlock( pBlkNm->aShort );
591 : 0 : pBlkNm->bIsOnlyTxtFlagInit = sal_True;
592 : 0 : pImp->CloseFile();
593 : : }
594 : 8 : bRet = pBlkNm->bIsOnlyTxt;
595 : : }
596 : 8 : return bRet;
597 : : }
598 : :
599 : 4 : sal_Bool SwTextBlocks::IsOnlyTextBlock( const String& rShort ) const
600 : : {
601 : 4 : sal_uInt16 nIdx = pImp->GetIndex( rShort );
602 [ + + ]: 4 : if( USHRT_MAX != nIdx )
603 : : {
604 [ + - ]: 2 : if( pImp->aNames[ nIdx ]->bIsOnlyTxtFlagInit )
605 : 2 : return pImp->aNames[ nIdx ]->bIsOnlyTxt;
606 : 0 : return IsOnlyTextBlock( nIdx );
607 : : }
608 : :
609 : : OSL_ENSURE( !this, "ungueltiger Name" );
610 : 4 : return sal_False;
611 : : }
612 : :
613 : 2 : sal_Bool SwTextBlocks::GetMacroTable( sal_uInt16 nIdx, SvxMacroTableDtor& rMacroTbl )
614 : : {
615 : 2 : sal_Bool bRet = sal_True;
616 [ + - ][ + - ]: 2 : if ( pImp && !pImp->bInPutMuchBlocks )
617 : 2 : bRet = ( 0 == pImp->GetMacroTable( nIdx, rMacroTbl ) );
618 : 2 : return bRet;
619 : : }
620 : :
621 : 0 : sal_Bool SwTextBlocks::SetMacroTable( sal_uInt16 nIdx,
622 : : const SvxMacroTableDtor& rMacroTbl )
623 : : {
624 : 0 : sal_Bool bRet = sal_True;
625 [ # # ][ # # ]: 0 : if ( pImp && !pImp->bInPutMuchBlocks )
626 : 0 : bRet = ( 0 == pImp->SetMacroTable( nIdx, rMacroTbl ) );
627 : 0 : return bRet;
628 : : }
629 : :
630 : 0 : sal_Bool SwTextBlocks::StartPutMuchBlockEntries()
631 : : {
632 : 0 : sal_Bool bRet = sal_False;
633 [ # # ][ # # ]: 0 : if( !IsOld() && pImp )
[ # # ]
634 : 0 : bRet = pImp->PutMuchEntries( sal_True );
635 : 0 : return bRet;
636 : : }
637 : :
638 : 0 : void SwTextBlocks::EndPutMuchBlockEntries()
639 : : {
640 [ # # ]: 0 : if( pImp )
641 : 0 : pImp->PutMuchEntries( sal_False );
642 : 0 : }
643 : :
644 : 0 : String SwTextBlocks::GetBaseURL() const
645 : : {
646 : 0 : String sRet;
647 [ # # ]: 0 : if(pImp)
648 [ # # ]: 0 : sRet = pImp->GetBaseURL();
649 : 0 : return sRet;
650 : : }
651 : :
652 : 14 : void SwTextBlocks::SetBaseURL( const String& rURL )
653 : : {
654 [ + - ]: 14 : if(pImp)
655 : 14 : pImp->SetBaseURL(rURL);
656 : 14 : }
657 : :
658 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|