summaryrefslogtreecommitdiff
path: root/writerfilter/source/dmapper/SdtHelper.cxx
diff options
context:
space:
mode:
authorVasily Melenchuk <vasily.melenchuk@cib.de>2021-11-19 15:09:31 +0300
committerMiklos Vajna <vmiklos@collabora.com>2022-02-18 08:26:28 +0100
commit20c7e0355ed83bfb235b1b188171d7cb4c6664c9 (patch)
treec71bbc1bfe2266a5effa408f56ffbb4a6d49c339 /writerfilter/source/dmapper/SdtHelper.cxx
parent83ce54624c7f0a17b9e0ebcf8eebdbc8bae33d46 (diff)
tdf#104823: basic support for reading field data from databinding
Change-Id: Ie45eb18205c1c54a631303b45887e54e456b6d5d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125550 Tested-by: Jenkins Reviewed-by: Vasily Melenchuk <vasily.melenchuk@cib.de> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127129 Tested-by: Thorsten Behrens <thorsten.behrens@allotropia.de> Reviewed-by: Thorsten Behrens <thorsten.behrens@allotropia.de> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130042 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'writerfilter/source/dmapper/SdtHelper.cxx')
-rw-r--r--writerfilter/source/dmapper/SdtHelper.cxx47
1 files changed, 46 insertions, 1 deletions
diff --git a/writerfilter/source/dmapper/SdtHelper.cxx b/writerfilter/source/dmapper/SdtHelper.cxx
index d64f6aaf5b55..58252661ef20 100644
--- a/writerfilter/source/dmapper/SdtHelper.cxx
+++ b/writerfilter/source/dmapper/SdtHelper.cxx
@@ -20,12 +20,19 @@
#include "DomainMapper_Impl.hxx"
#include "StyleSheetTable.hxx"
#include <officecfg/Office/Writer.hxx>
+#include <com/sun/star/util/XRefreshable.hpp>
+#include <com/sun/star/text/XTextFieldsSupplier.hpp>
+#include <ooxml/OOXMLDocument.hxx>
+#include <com/sun/star/xml/xpath/XPathAPI.hpp>
+#include <com/sun/star/xml/dom/XNode.hpp>
namespace writerfilter
{
namespace dmapper
+
{
using namespace ::com::sun::star;
+using namespace ::css::xml::xpath;
/// w:sdt's w:dropDownList doesn't have width, so guess the size based on the longest string.
static awt::Size lcl_getOptimalWidth(const StyleSheetTablePtr& pStyleSheet,
@@ -68,8 +75,10 @@ static awt::Size lcl_getOptimalWidth(const StyleSheetTablePtr& pStyleSheet,
return { nWidth + nBorder + nHeight, nHeight + nBorder };
}
-SdtHelper::SdtHelper(DomainMapper_Impl& rDM_Impl)
+SdtHelper::SdtHelper(DomainMapper_Impl& rDM_Impl,
+ css::uno::Reference<css::uno::XComponentContext> const& xContext)
: m_rDM_Impl(rDM_Impl)
+ , m_xComponentContext(xContext)
, m_aControlType(SdtControlType::unknown)
, m_bHasElements(false)
, m_bOutsideAParagraph(false)
@@ -78,6 +87,37 @@ SdtHelper::SdtHelper(DomainMapper_Impl& rDM_Impl)
SdtHelper::~SdtHelper() = default;
+std::optional<OUString> SdtHelper::getValueFromDataBinding()
+{
+ // No xpath - nothing to do
+ if (m_sDataBindingXPath.isEmpty())
+ return {};
+
+ writerfilter::ooxml::OOXMLDocument* pDocument = m_rDM_Impl.getDocumentReference();
+ assert(pDocument);
+ if (!pDocument)
+ return {};
+
+ // Iterate all custom xmls documents and evaluate xpath to get value
+ uno::Sequence<uno::Reference<xml::dom::XDocument>> aCustomXmls
+ = pDocument->getCustomXmlDomList();
+ for (const auto& xCustomXml : aCustomXmls)
+ {
+ uno::Reference<XXPathAPI> xXpathAPI = XPathAPI::create(m_xComponentContext);
+
+ //xXpathAPI->registerNS("ns0", m_sDataBindingPrefixMapping);
+ xXpathAPI->registerNS("ns0", "http://schemas.microsoft.com/vsto/samples");
+ uno::Reference<XXPathObject> xResult = xXpathAPI->eval(xCustomXml, m_sDataBindingXPath);
+
+ if (xResult.is())
+ {
+ return xResult->getString();
+ }
+ }
+
+ return {};
+}
+
void SdtHelper::createDropDownControl()
{
assert(getControlType() == SdtControlType::dropDown);
@@ -189,6 +229,11 @@ void SdtHelper::createDateContentControl()
uno::makeAny(m_sLocale.makeStringAndClear()));
}
OUString sFullDate = m_sDate.makeStringAndClear();
+
+ std::optional<OUString> oData = getValueFromDataBinding();
+ if (oData.has_value())
+ sFullDate = *oData;
+
if (!sFullDate.isEmpty())
{
sal_Int32 nTimeSep = sFullDate.indexOf("T");