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 );
237 OSL_ENSURE(
m_xBlkRoot.is(),
"No storage set" );
243 m_xRoot =
m_xBlkRoot->openStorageElement( rPackageName, embed::ElementModes::READWRITE );
245 uno::Reference< beans::XPropertySet > xRootProps(
m_xRoot, uno::UNO_QUERY_THROW );
247 xRootProps->setPropertyValue(
"MediaType",
uno::Any( aMime ) );
249 catch (
const uno::Exception&)
274 xWrt->m_bBlock =
true;
275 nRes = aWriter.
Write ( xWrt );
276 xWrt->m_bBlock =
false;
281 if( !nRes && bHasChildren )
290 std::unique_ptr<SfxMedium> pTmpMedium;
293 uno::Reference< embed::XStorage > xTempStorage =
296 m_xRoot->copyToStorage( xTempStorage );
305 xTempStorage->copyToStorage(
m_xRoot );
308 catch(
const uno::Exception&)
319 uno::Reference < embed::XTransactedObject > xTrans(
m_xRoot, uno::UNO_QUERY );
325 uno::Reference < embed::XTransactedObject > xTmpTrans(
m_xBlkRoot, uno::UNO_QUERY );
326 if ( xTmpTrans.is() )
330 catch (
const uno::Exception&)
340 std::unique_ptr<SwPaM> pPaM =
MakePaM();
363 OSL_ENSURE(
false,
"Nested calls are not allowed");
382 uno::Reference < embed::XTransactedObject > xTrans(
m_xBlkRoot, uno::UNO_QUERY );
391 catch (
const uno::Exception&)
405 bRdOnly ? embed::ElementModes::READ : embed::ElementModes::READWRITE );
408 catch (
const uno::Exception&)
426 sal_uInt16 nIdx =
GetIndex ( rShort );
427 if (nIdx != USHRT_MAX)
428 m_aNames[nIdx]->m_bIsOnlyText = bNewValue;
433 sal_uInt16 nIdx =
GetIndex ( rShort );
435 if (nIdx != USHRT_MAX)
437 bRet =
m_aNames[nIdx]->m_bIsOnlyText;
443 return m_aNames[nIdx]->m_bIsOnlyText;
448 OUString
aName( rFileName );
450 if ( aObj.
GetProtocol() == INetProtocol::NotValid )
453 osl::FileBase::getFileURLFromSystemPath( aName, aURL );
466 OUStringBuffer
aBuf(OStringToOUString(sByte, RTL_TEXTENCODING_ASCII_US));
467 const sal_Int32 nLen = aBuf.getLength();
483 return aBuf.makeStringAndClear();
487 const OUString& rText )
516 }
while ( -1 != nPos );
Marks a position in the document model.
void InitBlockMode(const css::uno::Reference< css::embed::XStorage > &rStorage)
#define ERR_SWG_WRITE_ERROR
bool SaveCompletedChildren()
static OUString GeneratePackageName(std::u16string_view rShort)
void GetXMLWriter([[maybe_unused]] std::u16string_view, const OUString &rBaseURL, WriterRef &xRet)
rtl::Reference< SwDoc > m_xDoc
bool HasEmbeddedObjects() const
sal_uInt16 GetIndex(const OUString &) const
Get count of Text Blocks.
virtual ~SwXMLTextBlocks() override
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
SfxObjectShellRef m_xDocShellRef
ErrCode Write(WriterRef const &rxWriter, const OUString *=nullptr)
virtual bool IsOnlyTextBlock(const OUString &rShort) const override
css::uno::Reference< css::embed::XStorage > m_xRoot
css::uno::Reference< css::embed::XStorage > m_xBlkRoot
virtual ErrCode Delete(sal_uInt16) override
virtual ErrCode OpenFile(bool bReadOnly=true) override
virtual void CloseFile() override
tools::Time m_aTimeModified
void MakeBlockText(std::u16string_view rText)
static std::unique_ptr< SvStream > CreateStream(const OUString &rFileName, StreamMode eOpenMode, css::uno::Reference< css::awt::XWindow > xParentWin=nullptr)
virtual void ClearDoc() override
Delete the document's content.
ErrCode GetText(std::u16string_view rShort, OUString &)
sal_Int32 GetDate() const
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
SwContentNode * AppendNode(const SwPosition &)
bool IsFileChanged() const
virtual ErrCode PutText(const OUString &, const OUString &, const OUString &) override
void SetIsTextOnly(const OUString &rShort, bool bNewValue)
SwDoc * GetDoc()
returns Doc. But be careful!
virtual ErrCode MakeBlockList() override
static css::uno::Reference< css::embed::XStorage > GetTemporaryStorage(const css::uno::Reference< css::uno::XComponentContext > &rxContext=css::uno::Reference< css::uno::XComponentContext >())
#define TOOLS_WARN_EXCEPTION(area, stream)
const OUString & GetBaseURL() const
virtual bool PutMuchEntries(bool bOn) override
virtual ErrCode PutDoc() override
SwXMLTextBlocks(const OUString &rFile)
Marks a character position inside a document model node.
virtual SwFormatColl * ChgFormatColl(SwFormatColl *) override
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 OUString GetFormatMimeType(SotClipboardFormatId nFormat)
void AddName(const OUString &, const OUString &, const OUString &, bool bOnlyText)
const_iterator begin() const
bool SetURL(std::u16string_view rTheAbsURIRef, EncodeMechanism eMechanism=EncodeMechanism::WasEncoded, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
virtual ErrCode Rename(sal_uInt16, const OUString &) override
std::unique_ptr< SwPaM > MakePaM()
Creating a PaM, that spans the whole document.
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
ErrCode StartPutBlock(const OUString &rShort, const OUString &rPackageName)
OUString InsertText(const OUString &rStr, const SwIndex &rIdx, const SwInsertFlags nMode=SwInsertFlags::DEFAULT)
insert text content
SwTextNode is a paragraph in the document model.
comphelper::EmbeddedObjectContainer & GetEmbeddedObjectContainer() const
ErrCode PutBlockText(const OUString &rShort, std::u16string_view rText, const OUString &rPackageName)
static bool IsStorageFile(SvStream *)
INetProtocol GetProtocol() const
virtual ErrCode BeginPutDoc(const OUString &, const OUString &) override
bool SaveAsChildren(SfxMedium &rMedium)
#define SAL_WARN(area, stream)
ErrCode GetBlockText(std::u16string_view rShort, OUString &rText)
std::pair< const_iterator, bool > insert(Value &&x)
void ClearEmbeddedObjects()
static bool IsFileUCBStorage(const OUString &rFileName)
size_type erase(const Value &x)
SwTextFormatColl * GetTextColl() const