20#include <com/sun/star/embed/ElementModes.hpp>
21#include <com/sun/star/embed/XTransactedObject.hpp>
22#include <com/sun/star/embed/XStorage.hpp>
23#include <com/sun/star/container/ElementExistException.hpp>
24#include <com/sun/star/beans/XPropertySet.hpp>
25#include <osl/file.hxx>
26#include <rtl/ustring.hxx>
74 m_xDoc->GetIDocumentUndoRedo().DoUndo(
false);
75 uno::Reference< embed::XStorage > refStg;
84 catch(
const uno::Exception&)
94 catch(
const uno::Exception&)
116 m_xDoc->GetIDocumentUndoRedo().DoUndo(
false);
150 const OUString& rPackageName,
bool bOnlyText )
152 sal_uInt16 nIdx =
GetIndex( rShort );
153 if (nIdx != USHRT_MAX)
157 std::unique_ptr<SwBlockName> pNew(
new SwBlockName( rShort, rLong, rPackageName ));
158 pNew->m_bIsOnlyTextFlagInit =
true;
159 pNew->m_bIsOnlyText = bOnlyText;
173 uno::Reference < embed::XTransactedObject > xTrans(
m_xBlkRoot, uno::UNO_QUERY );
178 catch (
const uno::Exception&)
188 OSL_ENSURE(
m_xBlkRoot.is(),
"No storage set" );
199 OUString sExt(
".xml");
200 OUString aOldStreamName = aOldName + sExt;
203 m_xRoot =
m_xBlkRoot->openStorageElement( aOldName, embed::ElementModes::READWRITE );
206 m_xRoot->renameElement ( aOldStreamName, aNewStreamName );
208 catch(
const container::ElementExistException&)
210 SAL_WARN(
"sw",
"Couldn't rename " << aOldStreamName <<
" to " << aNewStreamName);
212 uno::Reference < embed::XTransactedObject > xTrans(
m_xRoot, uno::UNO_QUERY );
222 catch(
const container::ElementExistException&)
227 uno::Reference < embed::XTransactedObject > xTrans(
m_xBlkRoot, uno::UNO_QUERY );
236 const OUString& rLong)
241 const OUString aGroup( rShort );
245 OUString sDestShortName( sPackageName );
248 OSL_ENSURE(
m_xBlkRoot.is(),
"No storage set" );
253 while ( xAccess->hasByName( sDestShortName ) )
257 if(USHRT_MAX == nIdx)
263 sDestShortName = sPackageName + OUString::number( nIdx );
268 uno::Reference < embed::XStorage > rSourceRoot =
m_xBlkRoot->openStorageElement( aGroup, embed::ElementModes::READ );
269 uno::Reference < embed::XStorage > rDestRoot =
static_cast<SwXMLTextBlocks&
>(rDestImp).
m_xBlkRoot->openStorageElement( sDestShortName, embed::ElementModes::READWRITE );
270 rSourceRoot->copyToStorage( rDestRoot );
272 catch (
const uno::Exception&)
279 rShort = sDestShortName;
290 OSL_ENSURE(
m_xBlkRoot.is(),
"No storage set" );
296 m_xRoot =
m_xBlkRoot->openStorageElement( rPackageName, embed::ElementModes::READWRITE );
298 uno::Reference< beans::XPropertySet > xRootProps(
m_xRoot, uno::UNO_QUERY_THROW );
300 xRootProps->setPropertyValue(
"MediaType",
uno::Any( aMime ) );
302 catch (
const uno::Exception&)
327 xWrt->m_bBlock =
true;
328 nRes = aWriter.
Write ( xWrt );
329 xWrt->m_bBlock =
false;
334 if( !nRes && bHasChildren )
343 std::unique_ptr<SfxMedium> pTmpMedium;
346 uno::Reference< embed::XStorage > xTempStorage =
349 m_xRoot->copyToStorage( xTempStorage );
358 xTempStorage->copyToStorage(
m_xRoot );
361 catch(
const uno::Exception&)
372 uno::Reference < embed::XTransactedObject > xTrans(
m_xRoot, uno::UNO_QUERY );
378 uno::Reference < embed::XTransactedObject > xTmpTrans(
m_xBlkRoot, uno::UNO_QUERY );
379 if ( xTmpTrans.is() )
383 catch (
const uno::Exception&)
393 std::unique_ptr<SwPaM> pPaM =
MakePaM();
416 OSL_ENSURE(
false,
"Nested calls are not allowed");
435 uno::Reference < embed::XTransactedObject > xTrans(
m_xBlkRoot, uno::UNO_QUERY );
444 catch (
const uno::Exception&)
458 bRdOnly ? embed::ElementModes::READ : embed::ElementModes::READWRITE );
461 catch (
const uno::Exception&)
479 sal_uInt16 nIdx =
GetIndex ( rShort );
480 if (nIdx != USHRT_MAX)
481 m_aNames[nIdx]->m_bIsOnlyText = bNewValue;
486 sal_uInt16 nIdx =
GetIndex ( rShort );
488 if (nIdx != USHRT_MAX)
490 bRet =
m_aNames[nIdx]->m_bIsOnlyText;
496 return m_aNames[nIdx]->m_bIsOnlyText;
501 OUString
aName( rFileName );
503 if ( aObj.
GetProtocol() == INetProtocol::NotValid )
506 osl::FileBase::getFileURLFromSystemPath(
aName,
aURL );
519 OUStringBuffer
aBuf(OStringToOUString(sByte, RTL_TEXTENCODING_ASCII_US));
520 const sal_Int32 nLen =
aBuf.getLength();
536 return aBuf.makeStringAndClear();
540 const OUString& rText )
569 }
while ( -1 !=
nPos );
sal_Int32 GetDate() const
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
INetProtocol GetProtocol() const
bool SetURL(std::u16string_view rTheAbsURIRef, EncodeMechanism eMechanism=EncodeMechanism::WasEncoded, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
comphelper::EmbeddedObjectContainer & GetEmbeddedObjectContainer() const
bool SaveCompletedChildren()
bool SaveAsChildren(SfxMedium &rMedium)
void ClearEmbeddedObjects()
static OUString GetFormatMimeType(SotClipboardFormatId nFormat)
Marks a character position inside a document model content node (SwContentNode)
SwDoc * GetDoc()
returns Doc. But be careful!
const OUString & GetBaseURL() const
OUString GetPackageName(sal_uInt16) const
Return longname for index.
sal_uInt16 GetIndex(const OUString &) const
Get count of Text Blocks.
virtual ErrCode OpenFile(bool bReadOnly=true)=0
bool IsFileChanged() const
std::unique_ptr< SwPaM > MakePaM()
Creating a PaM, that spans the whole document.
tools::Time m_aTimeModified
rtl::Reference< SwDoc > m_xDoc
virtual void CloseFile()=0
SwTextNode is a paragraph in the document model.
SwContentNode * AppendNode(const SwPosition &)
virtual SwFormatColl * ChgFormatColl(SwFormatColl *) override
OUString InsertText(const OUString &rStr, const SwContentIndex &rIdx, const SwInsertFlags nMode=SwInsertFlags::DEFAULT)
insert text content
SwTextFormatColl * GetTextColl() const
ErrCode Write(WriterRef const &rxWriter, const OUString *=nullptr)
virtual ErrCode CopyBlock(SwImpBlocks &rImp, OUString &rShort, const OUString &rLong) override
void SetIsTextOnly(const OUString &rShort, bool bNewValue)
virtual bool PutMuchEntries(bool bOn) override
virtual ErrCode MakeBlockList() override
void InitBlockMode(const css::uno::Reference< css::embed::XStorage > &rStorage)
virtual bool IsOnlyTextBlock(const OUString &rShort) const override
SwXMLTextBlocks(const OUString &rFile)
virtual ErrCode PutText(const OUString &, const OUString &, const OUString &) override
css::uno::Reference< css::embed::XStorage > m_xBlkRoot
void MakeBlockText(std::u16string_view rText)
static OUString GeneratePackageName(std::u16string_view rShort)
SfxObjectShellRef m_xDocShellRef
virtual void ClearDoc() override
Delete the document's content.
ErrCode GetBlockText(std::u16string_view rShort, OUString &rText)
virtual ErrCode Rename(sal_uInt16, const OUString &) override
static bool IsFileUCBStorage(const OUString &rFileName)
virtual ErrCode PutDoc() override
virtual ErrCode Delete(sal_uInt16) override
ErrCode GetText(std::u16string_view rShort, OUString &)
ErrCode StartPutBlock(const OUString &rShort, const OUString &rPackageName)
ErrCode PutBlockText(const OUString &rShort, std::u16string_view rText, const OUString &rPackageName)
virtual void CloseFile() override
void AddName(const OUString &, const OUString &, const OUString &, bool bOnlyText)
css::uno::Reference< css::embed::XStorage > m_xRoot
virtual ~SwXMLTextBlocks() override
virtual ErrCode OpenFile(bool bReadOnly=true) override
virtual ErrCode BeginPutDoc(const OUString &, const OUString &) override
static bool IsStorageFile(SvStream *)
bool HasEmbeddedObjects() const
static css::uno::Reference< css::embed::XStorage > GetStorageFromURL(const OUString &aURL, sal_Int32 nStorageMode, const css::uno::Reference< css::uno::XComponentContext > &rxContext=css::uno::Reference< css::uno::XComponentContext >())
static css::uno::Reference< css::embed::XStorage > GetTemporaryStorage(const css::uno::Reference< css::uno::XComponentContext > &rxContext=css::uno::Reference< css::uno::XComponentContext >())
const_iterator begin() const
size_type erase(const Value &x)
std::pair< const_iterator, bool > insert(Value &&x)
static std::unique_ptr< SvStream > CreateStream(const OUString &rFileName, StreamMode eOpenMode, css::uno::Reference< css::awt::XWindow > xParentWin=nullptr)
#define TOOLS_WARN_EXCEPTION(area, stream)
#define SAL_WARN(area, stream)
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
@ RES_POOLCOLL_STANDARD
Standard.
Marks a position in the document model.
#define ERR_SWG_WRITE_ERROR
void GetXMLWriter(std::u16string_view, const OUString &rBaseURL, WriterRef &xRet)