Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include <com/sun/star/embed/ElementModes.hpp>
22 : #include <com/sun/star/embed/XTransactedObject.hpp>
23 : #include <rtl/ustring.hxx>
24 : #include <sot/stg.hxx>
25 : #include <sfx2/docfile.hxx>
26 : #include <tools/urlobj.hxx>
27 : #include <unotools/localfilehelper.hxx>
28 : #include <unotools/ucbstreamhelper.hxx>
29 :
30 : #include <comphelper/storagehelper.hxx>
31 : #include <doc.hxx>
32 : #include <IDocumentUndoRedo.hxx>
33 : #include <docsh.hxx>
34 : #include <pam.hxx>
35 : #include <swblocks.hxx>
36 : #include <ndtxt.hxx>
37 : #include <shellio.hxx>
38 : #include <poolfmt.hxx>
39 : #include <SwXMLTextBlocks.hxx>
40 : #include <SwXMLBlockImport.hxx>
41 : #include <SwXMLBlockExport.hxx>
42 : #include <swerror.h>
43 :
44 : #define STREAM_STGREAD ( STREAM_READ | STREAM_SHARE_DENYWRITE | STREAM_NOCREATE )
45 : #define STREAM_STGWRITE ( STREAM_READ | STREAM_WRITE | STREAM_SHARE_DENYWRITE )
46 :
47 : using namespace ::com::sun::star;
48 :
49 :
50 0 : void SwXMLTextBlocks::InitBlockMode ( const uno::Reference < embed::XStorage >& rStorage )
51 : {
52 0 : xBlkRoot = rStorage;
53 0 : xRoot = 0;
54 0 : }
55 :
56 0 : void SwXMLTextBlocks::ResetBlockMode ( )
57 : {
58 0 : xBlkRoot = 0;
59 0 : xRoot = 0;
60 0 : }
61 :
62 0 : SwXMLTextBlocks::SwXMLTextBlocks( const String& rFile )
63 0 : : SwImpBlocks( rFile ), bAutocorrBlock( sal_False ), nFlags ( 0 )
64 : {
65 0 : SwDocShell* pDocSh = new SwDocShell ( SFX_CREATE_MODE_INTERNAL );
66 0 : if( !pDocSh->DoInitNew( 0 ) )
67 0 : return;
68 0 : bReadOnly = sal_True;
69 0 : pDoc = pDocSh->GetDoc();
70 0 : xDocShellRef = pDocSh;
71 0 : pDoc->SetOle2Link( Link() );
72 0 : pDoc->GetIDocumentUndoRedo().DoUndo(false);
73 0 : pDoc->acquire();
74 0 : uno::Reference< embed::XStorage > refStg;
75 0 : if( !aDateModified.GetDate() || !aTimeModified.GetTime() )
76 0 : Touch(); // falls neu angelegt -> neuen ZeitStempel besorgen
77 : try
78 : {
79 0 : refStg = comphelper::OStorageHelper::GetStorageFromURL( rFile, embed::ElementModes::READWRITE );
80 0 : bReadOnly = sal_False;
81 : }
82 0 : catch(const uno::Exception&)
83 : {
84 : //couldn't open the file - maybe it's readonly
85 : }
86 0 : if( !refStg.is())
87 : {
88 : try
89 : {
90 0 : refStg = comphelper::OStorageHelper::GetStorageFromURL( rFile, embed::ElementModes::READ );
91 : }
92 0 : catch(const uno::Exception&)
93 : {
94 : OSL_FAIL("exception while creating AutoText storage");
95 : }
96 : }
97 0 : InitBlockMode ( refStg );
98 0 : ReadInfo();
99 0 : ResetBlockMode ();
100 0 : bInfoChanged = sal_False;
101 : }
102 :
103 0 : SwXMLTextBlocks::SwXMLTextBlocks( const uno::Reference < embed::XStorage >& rStg, const String& rName )
104 : : SwImpBlocks( rName )
105 : , bAutocorrBlock( sal_True )
106 0 : , nFlags ( 0 )
107 : {
108 0 : SwDocShell* pDocSh = new SwDocShell ( SFX_CREATE_MODE_INTERNAL );
109 0 : if( !pDocSh->DoInitNew( 0 ) )
110 0 : return;
111 0 : bReadOnly = sal_False;
112 0 : pDoc = pDocSh->GetDoc();
113 0 : xDocShellRef = pDocSh;
114 0 : pDoc->SetOle2Link( Link() );
115 0 : pDoc->GetIDocumentUndoRedo().DoUndo(false);
116 0 : pDoc->acquire();
117 :
118 0 : InitBlockMode ( rStg );
119 0 : ReadInfo();
120 0 : bInfoChanged = sal_False;
121 : }
122 :
123 0 : SwXMLTextBlocks::~SwXMLTextBlocks()
124 : {
125 0 : if ( bInfoChanged )
126 0 : WriteInfo();
127 0 : ResetBlockMode ();
128 0 : if(xDocShellRef.Is())
129 0 : xDocShellRef->DoClose();
130 0 : xDocShellRef = 0;
131 0 : if( pDoc && !pDoc->release() )
132 0 : delete pDoc;
133 0 : }
134 :
135 0 : void SwXMLTextBlocks::ClearDoc()
136 : {
137 0 : SwDocShell * pDocShell = pDoc->GetDocShell();
138 0 : pDocShell->InvalidateModel();
139 0 : pDocShell->ReactivateModel();
140 :
141 0 : pDoc->ClearDoc();
142 0 : pDocShell->ClearEmbeddedObjects();
143 0 : }
144 0 : void SwXMLTextBlocks::AddName( const String& rShort, const String& rLong, sal_Bool bOnlyTxt )
145 : {
146 0 : sal_uInt16 nIdx = GetIndex( rShort );
147 0 : SwBlockName* pNew = NULL;
148 0 : if( nIdx != (sal_uInt16) -1 )
149 : {
150 0 : delete aNames[nIdx];
151 0 : aNames.erase( aNames.begin() + nIdx );
152 : }
153 :
154 0 : aPackageName = GeneratePackageName( rShort );
155 0 : pNew = new SwBlockName( rShort, rLong, aPackageName );
156 :
157 0 : pNew->bIsOnlyTxtFlagInit = sal_True;
158 0 : pNew->bIsOnlyTxt = bOnlyTxt;
159 0 : aNames.insert( pNew );
160 0 : bInfoChanged = sal_True;
161 0 : }
162 0 : void SwXMLTextBlocks::AddName( const String& rShort, const String& rLong,
163 : const String& rPackageName, sal_Bool bOnlyTxt )
164 : {
165 0 : sal_uInt16 nIdx = GetIndex( rShort );
166 0 : if( nIdx != (sal_uInt16) -1 )
167 : {
168 0 : delete aNames[nIdx];
169 0 : aNames.erase( aNames.begin() + nIdx );
170 : }
171 0 : SwBlockName* pNew = new SwBlockName( rShort, rLong, rPackageName );
172 0 : pNew->bIsOnlyTxtFlagInit = sal_True;
173 0 : pNew->bIsOnlyTxt = bOnlyTxt;
174 0 : aNames.insert( pNew );
175 0 : bInfoChanged = sal_True;
176 0 : }
177 :
178 0 : sal_uLong SwXMLTextBlocks::Delete( sal_uInt16 n )
179 : {
180 0 : String aPckName (aNames[n]->aPackageName);
181 0 : uno::Reference < container::XNameAccess > xAccess( xBlkRoot, uno::UNO_QUERY );
182 0 : if ( xAccess.is() &&
183 0 : xAccess->hasByName( aPckName ) && xBlkRoot->isStreamElement( aPckName ) )
184 : {
185 : try
186 : {
187 0 : xBlkRoot->removeElement ( aPckName );
188 0 : uno::Reference < embed::XTransactedObject > xTrans( xBlkRoot, uno::UNO_QUERY );
189 0 : if ( xTrans.is() )
190 0 : xTrans->commit();
191 0 : return 0;
192 : }
193 0 : catch (const uno::Exception&)
194 : {
195 0 : return ERR_SWG_WRITE_ERROR;
196 : }
197 : }
198 0 : return 0;
199 : }
200 :
201 0 : sal_uLong SwXMLTextBlocks::Rename( sal_uInt16 nIdx, const String& rNewShort, const String& )
202 : {
203 : OSL_ENSURE( xBlkRoot.is(), "No storage set" );
204 0 : if(!xBlkRoot.is())
205 0 : return 0;
206 0 : rtl::OUString aOldName (aNames[nIdx]->aPackageName);
207 0 : aShort = rNewShort;
208 0 : aPackageName = GeneratePackageName( aShort );
209 :
210 0 : if(aOldName != aPackageName)
211 : {
212 0 : if (IsOnlyTextBlock ( nIdx ) )
213 : {
214 0 : rtl::OUString sExt(".xml");
215 0 : rtl::OUString aOldStreamName( aOldName ); aOldStreamName += sExt;
216 0 : rtl::OUString aNewStreamName( aPackageName ); aNewStreamName += sExt;
217 :
218 0 : xRoot = xBlkRoot->openStorageElement( aOldName, embed::ElementModes::READWRITE );
219 : try
220 : {
221 0 : xRoot->renameElement ( aOldStreamName, aNewStreamName );
222 : }
223 0 : catch(const container::ElementExistException&)
224 : {
225 : SAL_WARN("sw", "Couldn't rename " << aOldStreamName << " to " << aNewStreamName);
226 : }
227 0 : uno::Reference < embed::XTransactedObject > xTrans( xRoot, uno::UNO_QUERY );
228 0 : if ( xTrans.is() )
229 0 : xTrans->commit();
230 0 : xRoot = 0;
231 : }
232 :
233 : try
234 : {
235 0 : xBlkRoot->renameElement ( aOldName, aPackageName );
236 : }
237 0 : catch(const container::ElementExistException&)
238 : {
239 : SAL_WARN("sw", "Couldn't rename " << aOldName << " to " << aPackageName);
240 : }
241 : }
242 0 : uno::Reference < embed::XTransactedObject > xTrans( xBlkRoot, uno::UNO_QUERY );
243 0 : if ( xTrans.is() )
244 0 : xTrans->commit();
245 : // No need to commit xBlkRoot here as SwTextBlocks::Rename calls
246 : // WriteInfo which does the commit
247 0 : return 0;
248 : }
249 :
250 0 : sal_uLong SwXMLTextBlocks::CopyBlock( SwImpBlocks& rDestImp, String& rShort,
251 : const String& rLong)
252 : {
253 0 : sal_uLong nError = 0;
254 0 : OpenFile(sal_True);
255 0 : rDestImp.OpenFile(sal_False);
256 0 : String aGroup( rShort );
257 0 : sal_Bool bTextOnly = IsOnlyTextBlock ( rShort ) ;//pImp->pBlkRoot->IsStream( aGroup );
258 0 : sal_uInt16 nIndex = GetIndex ( rShort );
259 0 : String sDestShortName( GetPackageName (nIndex) );
260 0 : sal_uInt16 nIdx = 0;
261 :
262 : OSL_ENSURE( xBlkRoot.is(), "No storage set" );
263 0 : if(!xBlkRoot.is())
264 0 : return ERR_SWG_WRITE_ERROR;
265 :
266 0 : uno::Reference < container::XNameAccess > xAccess( ((SwXMLTextBlocks&)rDestImp).xBlkRoot, uno::UNO_QUERY );
267 0 : while ( xAccess->hasByName( sDestShortName ) )
268 : {
269 0 : ++nIdx;
270 : //falls wirklich mal einer so verrueckt ist
271 0 : if(USHRT_MAX == nIdx)
272 : {
273 0 : CloseFile();
274 0 : rDestImp.CloseFile();
275 0 : return ERR_SWG_WRITE_ERROR;
276 : }
277 0 : sDestShortName += String::CreateFromInt32( nIdx );
278 : }
279 :
280 : try
281 : {
282 0 : uno::Reference < embed::XStorage > rSourceRoot = xBlkRoot->openStorageElement( aGroup, embed::ElementModes::READ );
283 0 : uno::Reference < embed::XStorage > rDestRoot = ((SwXMLTextBlocks&)rDestImp).xBlkRoot->openStorageElement( sDestShortName, embed::ElementModes::READWRITE );
284 0 : rSourceRoot->copyToStorage( rDestRoot );
285 : }
286 0 : catch (const uno::Exception&)
287 : {
288 0 : nError = ERR_SWG_WRITE_ERROR;
289 : }
290 :
291 0 : if(!nError)
292 : {
293 0 : rShort = sDestShortName;
294 0 : ((SwXMLTextBlocks&)rDestImp).AddName( rShort, rLong, bTextOnly );
295 0 : ((SwXMLTextBlocks&)rDestImp).MakeBlockList();
296 : }
297 0 : CloseFile();
298 0 : rDestImp.CloseFile();
299 0 : return nError;
300 : }
301 :
302 :
303 0 : sal_uLong SwXMLTextBlocks::StartPutBlock( const String& rShort, const String& rPackageName )
304 : {
305 : OSL_ENSURE( xBlkRoot.is(), "No storage set" );
306 0 : if(!xBlkRoot.is())
307 0 : return 0;
308 0 : GetIndex ( rShort );
309 : try
310 : {
311 0 : xRoot = xBlkRoot->openStorageElement( rPackageName, embed::ElementModes::READWRITE );
312 :
313 0 : uno::Reference< beans::XPropertySet > xRootProps( xRoot, uno::UNO_QUERY_THROW );
314 0 : ::rtl::OUString aPropName( RTL_CONSTASCII_USTRINGPARAM("MediaType") );
315 0 : ::rtl::OUString aMime( SotExchange::GetFormatMimeType( SOT_FORMATSTR_ID_STARWRITER_8 ) );
316 0 : xRootProps->setPropertyValue( aPropName, uno::makeAny( aMime ) );
317 : }
318 0 : catch (const uno::Exception&)
319 : {
320 : }
321 0 : return 0;
322 : }
323 0 : sal_uLong SwXMLTextBlocks::BeginPutDoc( const String& rShort, const String& rLong )
324 : {
325 : // In der Basisklasse ablegen!
326 0 : aShort = rShort;
327 0 : aLong = rLong;
328 0 : aPackageName = GeneratePackageName( rShort );
329 0 : SetIsTextOnly( rShort, sal_False);
330 0 : return StartPutBlock (rShort, aPackageName);
331 : }
332 :
333 0 : sal_uLong SwXMLTextBlocks::PutBlock( SwPaM& , const String& )
334 : {
335 0 : sal_uLong nRes = 0;
336 0 : sal_uInt16 nCommitFlags = nFlags & (SWXML_CONVBLOCK|SWXML_NOROOTCOMMIT);
337 :
338 0 : nFlags |= nCommitFlags;
339 :
340 0 : WriterRef xWrt;
341 0 : ::GetXMLWriter ( aEmptyStr, GetBaseURL(), xWrt);
342 0 : SwWriter aWriter (xRoot, *pDoc );
343 :
344 0 : xWrt->bBlock = sal_True;
345 0 : nRes = aWriter.Write ( xWrt );
346 0 : xWrt->bBlock = sal_False;
347 : // Save OLE objects if there are some
348 0 : SwDocShell *pDocSh = pDoc->GetDocShell();
349 :
350 0 : bool bHasChildren = pDocSh && pDocSh->GetEmbeddedObjectContainer().HasEmbeddedObjects();
351 0 : if( !nRes && bHasChildren )
352 : {
353 : // we have to write to the temporary storage first, since the used below functions are optimized
354 : // TODO/LATER: it is only a temporary solution, that should be changed soon, the used methods should be
355 : // called without optimization
356 :
357 0 : sal_Bool bOK = sal_False;
358 :
359 0 : if ( xRoot.is() )
360 : {
361 0 : SfxMedium* pTmpMedium = NULL;
362 : try
363 : {
364 : uno::Reference< embed::XStorage > xTempStorage =
365 0 : ::comphelper::OStorageHelper::GetTemporaryStorage();
366 :
367 0 : xRoot->copyToStorage( xTempStorage );
368 :
369 : // TODO/LATER: no progress bar?!
370 : // TODO/MBA: strange construct
371 0 : pTmpMedium = new SfxMedium( xTempStorage, GetBaseURL() );
372 0 : sal_Bool bTmpOK = pDocSh->SaveAsChildren( *pTmpMedium );
373 0 : if( bTmpOK )
374 0 : bTmpOK = pDocSh->SaveCompletedChildren( sal_False );
375 :
376 0 : xTempStorage->copyToStorage( xRoot );
377 0 : bOK = bTmpOK;
378 : }
379 0 : catch(const uno::Exception&)
380 : {
381 : }
382 :
383 0 : if ( pTmpMedium )
384 0 : DELETEZ( pTmpMedium );
385 : }
386 :
387 0 : if( !bOK )
388 0 : nRes = ERR_SWG_WRITE_ERROR;
389 : }
390 :
391 : try
392 : {
393 0 : uno::Reference < embed::XTransactedObject > xTrans( xRoot, uno::UNO_QUERY );
394 0 : if ( xTrans.is() )
395 0 : xTrans->commit();
396 0 : xRoot = 0;
397 0 : if ( !nCommitFlags )
398 : {
399 0 : uno::Reference < embed::XTransactedObject > xTmpTrans( xBlkRoot, uno::UNO_QUERY );
400 0 : if ( xTmpTrans.is() )
401 0 : xTmpTrans->commit();
402 0 : }
403 : }
404 0 : catch (const uno::Exception&)
405 : {
406 : }
407 :
408 : //TODO/LATER: error handling
409 0 : return 0;
410 : }
411 :
412 0 : sal_uLong SwXMLTextBlocks::PutDoc()
413 : {
414 0 : SwPaM* pPaM = MakePaM();
415 0 : sal_uLong nErr = PutBlock(*pPaM, aLong);
416 0 : delete pPaM;
417 0 : return nErr;
418 : }
419 :
420 0 : sal_uLong SwXMLTextBlocks::GetText( sal_uInt16 nIdx, String& rText )
421 : {
422 0 : return GetBlockText( aNames[ nIdx ]->aShort, rText );
423 : }
424 :
425 0 : sal_uLong SwXMLTextBlocks::GetText( const String& rShort, String& rText )
426 : {
427 0 : return GetBlockText( rShort, rText );
428 : }
429 :
430 :
431 0 : sal_uLong SwXMLTextBlocks::MakeBlockList()
432 : {
433 0 : WriteInfo();
434 0 : return 0;
435 : }
436 :
437 0 : sal_Bool SwXMLTextBlocks::PutMuchEntries( sal_Bool bOn )
438 : {
439 0 : sal_Bool bRet = sal_False;
440 0 : if( bOn )
441 : {
442 0 : if( bInPutMuchBlocks )
443 : {
444 : OSL_ENSURE( !this, "verschachtelte Aufrufe sind nicht erlaubt" );
445 : }
446 0 : else if( !IsFileChanged() )
447 : {
448 0 : bRet = 0 == OpenFile( sal_False );
449 0 : if( bRet )
450 : {
451 0 : nFlags |= SWXML_NOROOTCOMMIT;
452 0 : bInPutMuchBlocks = sal_True;
453 : }
454 : }
455 : }
456 0 : else if( bInPutMuchBlocks )
457 : {
458 0 : nFlags &= ~SWXML_NOROOTCOMMIT;
459 0 : if( xBlkRoot.is() )
460 : {
461 : try
462 : {
463 0 : uno::Reference < embed::XTransactedObject > xTrans( xBlkRoot, uno::UNO_QUERY );
464 0 : if ( xTrans.is() )
465 0 : xTrans->commit();
466 0 : MakeBlockList();
467 0 : CloseFile();
468 0 : Touch();
469 0 : bInPutMuchBlocks = sal_False;
470 0 : bRet = sal_True;
471 : }
472 0 : catch (const uno::Exception&)
473 : {
474 : }
475 : }
476 : }
477 0 : return bRet;
478 : }
479 :
480 0 : sal_uLong SwXMLTextBlocks::OpenFile( sal_Bool bRdOnly )
481 : {
482 0 : if( bAutocorrBlock )
483 0 : return 0;
484 0 : sal_uLong nRet = 0;
485 : try
486 : {
487 : uno::Reference < embed::XStorage > refStg = comphelper::OStorageHelper::GetStorageFromURL( aFile,
488 0 : bRdOnly ? embed::ElementModes::READ : embed::ElementModes::READWRITE );
489 0 : InitBlockMode ( refStg );
490 : }
491 0 : catch (const uno::Exception&)
492 : {
493 : //TODO/LATER: error handling
494 0 : nRet = 1;
495 : }
496 :
497 0 : return nRet;
498 : }
499 :
500 0 : void SwXMLTextBlocks::CloseFile()
501 : {
502 0 : if ( !bAutocorrBlock )
503 : {
504 0 : if (bInfoChanged)
505 0 : WriteInfo();
506 0 : ResetBlockMode();
507 : }
508 0 : }
509 :
510 0 : void SwXMLTextBlocks::SetIsTextOnly( const String& rShort, sal_Bool bNewValue )
511 : {
512 0 : sal_uInt16 nIdx = GetIndex ( rShort );
513 0 : if (nIdx != (sal_uInt16) -1 && nIdx != USHRT_MAX)
514 0 : aNames[nIdx]->bIsOnlyTxt = bNewValue;
515 0 : }
516 :
517 0 : void SwXMLTextBlocks::SetIsTextOnly( sal_uInt16 nIdx, sal_Bool bNewValue )
518 : {
519 0 : aNames[nIdx]->bIsOnlyTxt = bNewValue;
520 0 : }
521 :
522 0 : sal_Bool SwXMLTextBlocks::IsOnlyTextBlock( const String& rShort ) const
523 : {
524 0 : sal_uInt16 nIdx = GetIndex ( rShort );
525 0 : sal_Bool bRet = sal_False;
526 0 : if (nIdx != (sal_uInt16) -1 && nIdx != USHRT_MAX)
527 : {
528 0 : bRet = aNames[nIdx]->bIsOnlyTxt;
529 : }
530 0 : return bRet;
531 : }
532 0 : sal_Bool SwXMLTextBlocks::IsOnlyTextBlock( sal_uInt16 nIdx ) const
533 : {
534 0 : return aNames[nIdx]->bIsOnlyTxt;
535 : }
536 :
537 0 : sal_Bool SwXMLTextBlocks::IsFileUCBStorage( const String & rFileName)
538 : {
539 0 : rtl::OUString aName( rFileName );
540 0 : INetURLObject aObj( aName );
541 0 : if ( aObj.GetProtocol() == INET_PROT_NOT_VALID )
542 : {
543 0 : rtl::OUString aURL;
544 0 : ::utl::LocalFileHelper::ConvertPhysicalNameToURL( aName, aURL );
545 0 : aObj.SetURL( aURL );
546 0 : aName = aObj.GetMainURL( INetURLObject::NO_DECODE );
547 : }
548 :
549 0 : SvStream * pStm = ::utl::UcbStreamHelper::CreateStream( aName, STREAM_STD_READ );
550 0 : sal_Bool bRet = UCBStorage::IsStorageFile( pStm );
551 0 : delete pStm;
552 0 : return bRet;
553 : }
554 :
555 :
556 :
557 0 : short SwXMLTextBlocks::GetFileType ( void ) const
558 : {
559 0 : return SWBLK_XML;
560 : }
561 :
562 0 : rtl::OUString SwXMLTextBlocks::GeneratePackageName ( const String& rShort )
563 : {
564 0 : String aRet = rShort;
565 0 : xub_StrLen nPos = 0;
566 0 : sal_Unicode pDelims[] = { '!', '/', ':', '.', '\\', 0 };
567 0 : rtl::OString sByte(rtl::OUStringToOString(aRet, RTL_TEXTENCODING_UTF7));
568 0 : aRet = rtl::OStringToOUString(sByte, RTL_TEXTENCODING_ASCII_US);
569 0 : while( STRING_NOTFOUND != ( nPos = aRet.SearchChar( pDelims, nPos )))
570 : {
571 0 : aRet.SetChar( nPos, '_' );
572 0 : ++nPos;
573 : }
574 0 : return aRet;
575 : }
576 :
577 0 : sal_uLong SwXMLTextBlocks::PutText( const String& rShort, const String& rName,
578 : const String& rText )
579 : {
580 0 : sal_uLong nRes = 0;
581 0 : aShort = rShort;
582 0 : aLong = rName;
583 0 : aCur = rText;
584 0 : SetIsTextOnly( aShort, sal_True );
585 0 : aPackageName = GeneratePackageName( rShort );
586 0 : ClearDoc();
587 0 : nRes = PutBlockText( rShort, rName, rText, aPackageName );
588 0 : return nRes;
589 : }
590 :
591 0 : void SwXMLTextBlocks::MakeBlockText( const String& rText )
592 : {
593 0 : SwTxtNode* pTxtNode = pDoc->GetNodes()[ pDoc->GetNodes().GetEndOfContent().
594 0 : GetIndex() - 1 ]->GetTxtNode();
595 0 : if( pTxtNode->GetTxtColl() == pDoc->GetDfltTxtFmtColl() )
596 0 : pTxtNode->ChgFmtColl( pDoc->GetTxtCollFromPool( RES_POOLCOLL_STANDARD ));
597 :
598 0 : xub_StrLen nPos = 0;
599 0 : do
600 : {
601 0 : if ( nPos )
602 : {
603 0 : pTxtNode = (SwTxtNode*)pTxtNode->AppendNode( SwPosition( *pTxtNode ) );
604 : }
605 0 : SwIndex aIdx( pTxtNode );
606 0 : String sTemp(rText.GetToken( 0, '\015', nPos ) );
607 0 : pTxtNode->InsertText( sTemp, aIdx );
608 : } while ( STRING_NOTFOUND != nPos );
609 0 : }
610 :
611 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|