LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sw/source/core/swg - SwXMLTextBlocks.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 196 325 60.3 %
Date: 2013-07-09 Functions: 25 33 75.8 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10