summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/test/style/xstyleloader.hxx1
-rw-r--r--offapi/com/sun/star/style/XStyleLoader.idl3
-rw-r--r--sc/inc/tablink.hxx9
-rw-r--r--sc/qa/extras/scstylefamiliesobj.cxx1
-rw-r--r--sc/source/ui/docshell/tablink.cxx5
-rw-r--r--sc/source/ui/unoobj/styleuno.cxx22
-rw-r--r--sw/PythonTest_sw_python.mk1
-rw-r--r--sw/inc/docsh.hxx3
-rw-r--r--sw/inc/shellio.hxx7
-rw-r--r--sw/qa/python/testdocuments/xstyleloader.odtbin0 -> 9181 bytes
-rw-r--r--sw/qa/python/xstyleloader.py56
-rw-r--r--sw/source/core/unocore/unostyle.cxx24
-rw-r--r--sw/source/uibase/app/docsh2.cxx5
-rw-r--r--test/source/style/xstyleloader.cxx30
14 files changed, 154 insertions, 13 deletions
diff --git a/include/test/style/xstyleloader.hxx b/include/test/style/xstyleloader.hxx
index 4077d30327d0..ca34a72cf4b3 100644
--- a/include/test/style/xstyleloader.hxx
+++ b/include/test/style/xstyleloader.hxx
@@ -32,6 +32,7 @@ public:
// XStyleLoader
void testLoadStylesFromURL();
+ void testLoadStylesFromStream();
// XStyleLoader2
void testLoadStylesFromDocument();
diff --git a/offapi/com/sun/star/style/XStyleLoader.idl b/offapi/com/sun/star/style/XStyleLoader.idl
index a695b79dde21..2899f23d61b2 100644
--- a/offapi/com/sun/star/style/XStyleLoader.idl
+++ b/offapi/com/sun/star/style/XStyleLoader.idl
@@ -38,8 +38,10 @@ published interface XStyleLoader: com::sun::star::uno::XInterface
defined in this document are loaded.</p>
@param URL
The directory and the filename from document with the styles
+ You can also load from stream. Use "private:stream" as the URL and the InputStream parameter below.
@param aOptions
Specifies which of the Style families the method should load.
+
The <code>sequence<PropertyValue></code> has the following, optional items:
<ul>
<li> boolean LoadCellStyles </li>
@@ -48,6 +50,7 @@ published interface XStyleLoader: com::sun::star::uno::XInterface
<li> boolean LoadPageStyles </li>
<li> boolean LoadNumberingStyles </li>
<li> boolean OverwriteStyles</li>
+ <li> com::sun::star::io::XInputStream InputStream (since LibreOffice 6.5)</li>
</ul>
<p>As the default, all supported style families are loaded and existing styles are overwritten.</p>
*/
diff --git a/sc/inc/tablink.hxx b/sc/inc/tablink.hxx
index 7038bd345fae..eb5e2f665696 100644
--- a/sc/inc/tablink.hxx
+++ b/sc/inc/tablink.hxx
@@ -82,10 +82,11 @@ private:
SfxMedium* pMedium;
public:
- ScDocumentLoader( const OUString& rFileName,
- OUString& rFilterName, OUString& rOptions,
- sal_uInt32 nRekCnt = 0, weld::Window* pInteractionParent = nullptr );
- ~ScDocumentLoader();
+ ScDocumentLoader(const OUString& rFileName, OUString& rFilterName, OUString& rOptions,
+ sal_uInt32 nRekCnt = 0, weld::Window* pInteractionParent = nullptr,
+ css::uno::Reference<css::io::XInputStream> xInputStream
+ = css::uno::Reference<css::io::XInputStream>());
+ ~ScDocumentLoader();
ScDocument* GetDocument();
ScDocShell* GetDocShell() { return pDocShell; }
bool IsError() const;
diff --git a/sc/qa/extras/scstylefamiliesobj.cxx b/sc/qa/extras/scstylefamiliesobj.cxx
index 26cbce051de5..991334d192b7 100644
--- a/sc/qa/extras/scstylefamiliesobj.cxx
+++ b/sc/qa/extras/scstylefamiliesobj.cxx
@@ -70,6 +70,7 @@ public:
// XStyleLoader
CPPUNIT_TEST(testLoadStylesFromDocument);
+ CPPUNIT_TEST(testLoadStylesFromStream);
CPPUNIT_TEST(testLoadStylesFromURL);
CPPUNIT_TEST_SUITE_END();
diff --git a/sc/source/ui/docshell/tablink.cxx b/sc/source/ui/docshell/tablink.cxx
index 6d43206f4c0a..9ef612caa161 100644
--- a/sc/source/ui/docshell/tablink.cxx
+++ b/sc/source/ui/docshell/tablink.cxx
@@ -514,7 +514,8 @@ SfxMedium* ScDocumentLoader::CreateMedium( const OUString& rFileName, std::share
ScDocumentLoader::ScDocumentLoader(const OUString& rFileName,
OUString& rFilterName, OUString& rOptions,
- sal_uInt32 nRekCnt, weld::Window* pInteractionParent)
+ sal_uInt32 nRekCnt, weld::Window* pInteractionParent,
+ css::uno::Reference<css::io::XInputStream> xInputStream)
: pDocShell(nullptr)
, pMedium(nullptr)
{
@@ -524,6 +525,8 @@ ScDocumentLoader::ScDocumentLoader(const OUString& rFileName,
std::shared_ptr<const SfxFilter> pFilter = ScDocShell::Factory().GetFilterContainer()->GetFilter4FilterName( rFilterName );
pMedium = CreateMedium(rFileName, pFilter, rOptions, pInteractionParent);
+ if (xInputStream.is())
+ pMedium->setStreamToLoadFrom(xInputStream, true);
if ( pMedium->GetError() != ERRCODE_NONE )
return ;
diff --git a/sc/source/ui/unoobj/styleuno.cxx b/sc/source/ui/unoobj/styleuno.cxx
index aed15b31427e..452c5dc3d345 100644
--- a/sc/source/ui/unoobj/styleuno.cxx
+++ b/sc/source/ui/unoobj/styleuno.cxx
@@ -529,7 +529,27 @@ void SAL_CALL ScStyleFamiliesObj::loadStylesFromURL( const OUString& aURL,
OUString aFilter; // empty - detect
OUString aFiltOpt;
- ScDocumentLoader aLoader( aURL, aFilter, aFiltOpt );
+ uno::Reference<io::XInputStream> xInputStream;
+ if (aURL == "private:stream")
+ {
+ for (const auto& rProp : aOptions)
+ {
+ if (rProp.Name == "InputStream")
+ {
+ rProp.Value >>= xInputStream;
+ if (!xInputStream.is())
+ {
+ throw lang::IllegalArgumentException(
+ "Parameter 'InputStream' could not be converted "
+ "to type 'com::sun::star::io::XInputStream'",
+ nullptr, 0);
+ }
+ break;
+ }
+ }
+ }
+
+ ScDocumentLoader aLoader( aURL, aFilter, aFiltOpt, 0, nullptr, xInputStream );
ScDocShell* pSource = aLoader.GetDocShell();
diff --git a/sw/PythonTest_sw_python.mk b/sw/PythonTest_sw_python.mk
index 6e699f5caa1d..b1c96a5c26ab 100644
--- a/sw/PythonTest_sw_python.mk
+++ b/sw/PythonTest_sw_python.mk
@@ -41,6 +41,7 @@ $(eval $(call gb_PythonTest_add_modules,sw_python,$(SRCDIR)/sw/qa/python,\
xscriptprovider \
xtextfieldssupplier \
xcontrolshape \
+ xstyleloader \
xtextcontent \
xtextrange \
xtext \
diff --git a/sw/inc/docsh.hxx b/sw/inc/docsh.hxx
index 865b6e243686..b3a993488c20 100644
--- a/sw/inc/docsh.hxx
+++ b/sw/inc/docsh.hxx
@@ -284,8 +284,7 @@ public:
void ToggleLayoutMode(SwView* pView);
- ErrCode LoadStylesFromFile( const OUString& rURL, SwgReaderOption const & rOpt,
- bool bUnoCall );
+ ErrCode LoadStylesFromFile(const OUString& rURL, SwgReaderOption& rOpt, bool bUnoCall);
void InvalidateModel();
void ReactivateModel();
diff --git a/sw/inc/shellio.hxx b/sw/inc/shellio.hxx
index 82da722ac10d..a959136a5244 100644
--- a/sw/inc/shellio.hxx
+++ b/sw/inc/shellio.hxx
@@ -112,6 +112,7 @@ class SwgReaderOption
bool m_bTextFormats;
bool m_bNumRules;
bool m_bMerge;
+ css::uno::Reference<css::io::XInputStream> m_xInputStream;
public:
void ResetAllFormatsOnly() { m_bFrameFormats = m_bPageDescs = m_bTextFormats = m_bNumRules = m_bMerge = false; }
bool IsFormatsOnly() const { return m_bFrameFormats || m_bPageDescs || m_bTextFormats || m_bNumRules || m_bMerge; }
@@ -135,6 +136,12 @@ public:
void SetASCIIOpts( const SwAsciiOptions& rOpts ) { aASCIIOpts = rOpts; }
void ResetASCIIOpts() { aASCIIOpts.Reset(); }
+ css::uno::Reference<css::io::XInputStream>& GetInputStream() { return m_xInputStream; }
+ void SetInputStream(css::uno::Reference<css::io::XInputStream>& xInputStream)
+ {
+ m_xInputStream = xInputStream;
+ }
+
SwgReaderOption()
{ ResetAllFormatsOnly(); aASCIIOpts.Reset(); }
};
diff --git a/sw/qa/python/testdocuments/xstyleloader.odt b/sw/qa/python/testdocuments/xstyleloader.odt
new file mode 100644
index 000000000000..921623f16077
--- /dev/null
+++ b/sw/qa/python/testdocuments/xstyleloader.odt
Binary files differ
diff --git a/sw/qa/python/xstyleloader.py b/sw/qa/python/xstyleloader.py
new file mode 100644
index 000000000000..ed2d7ffca4a4
--- /dev/null
+++ b/sw/qa/python/xstyleloader.py
@@ -0,0 +1,56 @@
+#! /usr/bin/env python
+# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+import os
+import pathlib
+import unittest
+import unohelper
+import uno
+
+from org.libreoffice.unotest import UnoInProcess, makeCopyFromTDOC
+from com.sun.star.beans import PropertyValue
+
+
+class TestXStyleLoader(unittest.TestCase):
+
+ @classmethod
+ def setUpClass(cls):
+ cls._uno = UnoInProcess()
+ cls._uno.setUp()
+
+ @classmethod
+ def tearDownClass(cls):
+ cls._uno.tearDown()
+
+ def test_loadStyleFromStream(self):
+ xDoc = self.__class__._uno.openEmptyWriterDoc()
+ self.assertIsNotNone(xDoc)
+
+ xServiceManager = self.__class__._uno.xContext.ServiceManager
+ simpleFileAccess = xServiceManager.createInstance(
+ "com.sun.star.ucb.SimpleFileAccess")
+ xInputStream = simpleFileAccess.openFileRead(
+ pathlib.Path(makeCopyFromTDOC("xstyleloader.odt")).as_uri())
+
+ p1 = PropertyValue(Name="InputStream", Value=xInputStream)
+ p2 = PropertyValue(Name="LoadTextStyles", Value=True)
+
+ styles = xDoc.getStyleFamilies()
+ styles.loadStylesFromURL("private:stream", [p1, p2])
+ textStyles = styles.getByName("ParagraphStyles")
+ self.assertTrue(textStyles.hasByName("Test_Template"))
+
+ xDoc.close(True)
+
+
+if __name__ == '__main__':
+ unittest.main()
+
+# vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx
index 011cd2dabf2f..6793e74602f0 100644
--- a/sw/source/core/unocore/unostyle.cxx
+++ b/sw/source/core/unocore/unostyle.cxx
@@ -77,8 +77,10 @@
#include <com/sun/star/beans/NamedValue.hpp>
#include <com/sun/star/drawing/BitmapMode.hpp>
#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
+#include <com/sun/star/lang/IllegalArgumentException.hpp>
#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
#include <com/sun/star/document/XEventsSupplier.hpp>
+#include <com/sun/star/io/XInputStream.hpp>
#include <istyleaccess.hxx>
#include <GetMetricVal.hxx>
#include <fmtfsize.hxx>
@@ -112,6 +114,11 @@
#include <set>
#include <limits>
+using namespace css;
+using namespace css::io;
+using namespace css::lang;
+using namespace css::uno;
+
namespace {
class SwXStyle;
@@ -552,9 +559,10 @@ void SwXStyleFamilies::loadStylesFromURL(const OUString& rURL,
aOpt.SetMerge(false);
for(const auto& rProperty: aOptions)
{
- if(rProperty.Value.getValueType() != cppu::UnoType<bool>::get())
- continue;
- const bool bValue = rProperty.Value.get<bool>();
+ bool bValue = false;
+ if(rProperty.Value.getValueType() == cppu::UnoType<bool>::get())
+ bValue = rProperty.Value.get<bool>();
+
if(rProperty.Name == UNO_NAME_OVERWRITE_STYLES)
aOpt.SetMerge(!bValue);
else if(rProperty.Name == UNO_NAME_LOAD_NUMBERING_STYLES)
@@ -565,6 +573,16 @@ void SwXStyleFamilies::loadStylesFromURL(const OUString& rURL,
aOpt.SetFrameFormats(bValue);
else if(rProperty.Name == UNO_NAME_LOAD_TEXT_STYLES)
aOpt.SetTextFormats(bValue);
+ else if(rProperty.Name == "InputStream")
+ {
+ Reference<XInputStream> xInputStream;
+ if (rProperty.Value >>= xInputStream)
+ aOpt.SetInputStream(xInputStream);
+ else
+ throw IllegalArgumentException("Parameter 'InputStream' could not be converted to "
+ "type 'com::sun::star::io::XInputStream'",
+ nullptr, 0);
+ }
}
const ErrCode nErr = m_pDocShell->LoadStylesFromFile( rURL, aOpt, true );
if(nErr)
diff --git a/sw/source/uibase/app/docsh2.cxx b/sw/source/uibase/app/docsh2.cxx
index 0f6c54e82e26..df49f29b5761 100644
--- a/sw/source/uibase/app/docsh2.cxx
+++ b/sw/source/uibase/app/docsh2.cxx
@@ -1565,8 +1565,7 @@ void SwDocShell::ReloadFromHtml( const OUString& rStreamName, SwSrcView* pSrcVie
m_xDoc->getIDocumentState().ResetModified();
}
-ErrCode SwDocShell::LoadStylesFromFile( const OUString& rURL,
- SwgReaderOption const & rOpt, bool bUnoCall )
+ErrCode SwDocShell::LoadStylesFromFile(const OUString& rURL, SwgReaderOption& rOpt, bool bUnoCall)
{
ErrCode nErr = ERRCODE_NONE;
@@ -1575,6 +1574,8 @@ ErrCode SwDocShell::LoadStylesFromFile( const OUString& rURL,
// search for filter in WebDocShell, too
SfxMedium aMed( rURL, StreamMode::STD_READ );
+ if (rURL == "private:stream")
+ aMed.setStreamToLoadFrom(rOpt.GetInputStream(), true);
std::shared_ptr<const SfxFilter> pFlt;
aMatcher.DetectFilter( aMed, pFlt );
if(!pFlt)
diff --git a/test/source/style/xstyleloader.cxx b/test/source/style/xstyleloader.cxx
index 573bc1e16152..fd3f8eec5303 100644
--- a/test/source/style/xstyleloader.cxx
+++ b/test/source/style/xstyleloader.cxx
@@ -11,16 +11,21 @@
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/container/XNameContainer.hpp>
+#include <com/sun/star/io/XInputStream.hpp>
#include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
#include <com/sun/star/style/XStyle.hpp>
#include <com/sun/star/style/XStyleLoader2.hpp>
+#include <com/sun/star/uno/Any.hxx>
#include <com/sun/star/uno/Reference.hxx>
#include <com/sun/star/uno/Sequence.hxx>
#include <rtl/ustring.hxx>
#include <cppunit/TestAssert.h>
+#include <comphelper/processfactory.hxx>
+#include <comphelper/storagehelper.hxx>
+using namespace comphelper;
using namespace css;
using namespace css::uno;
@@ -54,6 +59,31 @@ void XStyleLoader::testLoadStylesFromDocument()
checkStyleProperties(xFamilySupplier);
}
+void XStyleLoader::testLoadStylesFromStream()
+{
+ uno::Reference<style::XStyleLoader2> xStyleLoader(init(), uno::UNO_QUERY_THROW);
+
+ uno::Reference<sheet::XSpreadsheetDocument> xDoc(getTargetDoc(), uno::UNO_SET_THROW);
+ const OUString aFileURL = getTestURL();
+ const uno::Reference<io::XInputStream> xInputStream
+ = OStorageHelper::GetInputStreamFromURL(aFileURL, getProcessComponentContext());
+
+ uno::Sequence<beans::PropertyValue> aOptions = xStyleLoader->getStyleLoaderOptions();
+ auto nLength = aOptions.getLength();
+ aOptions.realloc(nLength + 1);
+ beans::PropertyValue aInputStream;
+ aInputStream.Name = "InputStream";
+ uno::Any aTmp;
+ aTmp <<= xInputStream;
+ aInputStream.Value = aTmp;
+ aOptions[nLength] = aInputStream;
+
+ xStyleLoader->loadStylesFromURL("private:stream", aOptions);
+
+ uno::Reference<style::XStyleFamiliesSupplier> xFamilySupplier(xDoc, UNO_QUERY_THROW);
+ checkStyleProperties(xFamilySupplier);
+}
+
void XStyleLoader::checkStyleProperties(
uno::Reference<style::XStyleFamiliesSupplier> const& xFamilySupplier)
{