22#include <com/sun/star/sdb/CommandType.hpp>
23#include <com/sun/star/chart2/data/XDatabaseDataProvider.hpp>
24#include <com/sun/star/chart2/data/XDataReceiver.hpp>
25#include <com/sun/star/chart2/data/XDataSource.hpp>
26#include <com/sun/star/chart/XComplexDescriptionAccess.hpp>
27#include <com/sun/star/chart/ChartDataRowSource.hpp>
28#include <com/sun/star/reflection/ProxyFactory.hpp>
52 :m_bImportedChart( false )
57ImportDocumentHandler::~ImportDocumentHandler()
61 m_xProxy->setDelegator(
nullptr );
69 return "com.sun.star.comp.report.ImportDocumentHandler";
72sal_Bool SAL_CALL ImportDocumentHandler::supportsService(
const OUString& ServiceName )
77uno::Sequence< OUString > SAL_CALL ImportDocumentHandler::getSupportedServiceNames( )
79 uno::Sequence< OUString > aSupported;
80 if ( m_xServiceInfo.is() )
81 aSupported = m_xServiceInfo->getSupportedServiceNames();
82 return ::comphelper::concatSequences( uno::Sequence<OUString> {
"com.sun.star.report.ImportDocumentHandler" }, aSupported);
86extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
88 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any>
const&)
94void SAL_CALL ImportDocumentHandler::startDocument()
96 m_xDelegatee->startDocument();
99void SAL_CALL ImportDocumentHandler::endDocument()
101 m_xDelegatee->endDocument();
102 uno::Reference< chart2::data::XDataReceiver > xReceiver(
m_xModel,uno::UNO_QUERY_THROW);
103 if ( !m_bImportedChart )
108 aArgs.
put(
"CellRangeRepresentation", OUString(
"all") );
110 aArgs.
put(
"DataRowSource",
uno::Any( chart::ChartDataRowSource_COLUMNS ) );
112 bool bHasCategories =
false;
114 uno::Reference< chart2::data::XDataSource > xDataSource(
m_xModel, uno::UNO_QUERY);
115 if( xDataSource.is())
117 const uno::Sequence< uno::Reference< chart2::data::XLabeledDataSequence > > aSequences(xDataSource->getDataSequences());
118 for(
const auto& rSequence : aSequences )
122 uno::Reference< beans::XPropertySet > xSeqProp( rSequence->getValues(), uno::UNO_QUERY );
125 && ( xSeqProp->getPropertyValue(
"Role" ) >>= aRole )
126 && aRole ==
"categories"
129 bHasCategories =
true;
135 aArgs.
put(
"HasCategories",
uno::Any( bHasCategories ) );
137 uno::Reference< chart::XComplexDescriptionAccess > xDataProvider(
m_xModel->getDataProvider(),uno::UNO_QUERY);
138 if ( xDataProvider.is() )
140 const uno::Sequence< OUString > aColumnNames = xDataProvider->getColumnDescriptions();
141 aArgs.
put(
"ColumnDescriptions",
uno::Any( aColumnNames ) );
144 xReceiver->attachDataProvider( m_xDatabaseDataProvider );
148void SAL_CALL ImportDocumentHandler::startElement(
const OUString & _sName,
const uno::Reference< xml::sax::XAttributeList > & _xAttrList)
150 uno::Reference< xml::sax::XAttributeList > xNewAttribs = _xAttrList;
152 if ( _sName ==
"office:report" )
154 const sal_Int16
nLength = (_xAttrList.is()) ? _xAttrList->getLength() : 0;
155 static const OUString s_sTRUE = ::xmloff::token::GetXMLToken(
XML_TRUE);
161 const OUString sAttrName = _xAttrList->getNameByIndex(
i );
162 const sal_Int32 nColonPos = sAttrName.indexOf(
':' );
163 if( -1 == nColonPos )
164 sLocalName = sAttrName;
166 sLocalName = sAttrName.copy( nColonPos + 1 );
167 const OUString sValue = _xAttrList->getValueByIndex(
i );
173 sal_Int32 nRet = sdb::CommandType::COMMAND;
176 m_xDatabaseDataProvider->setCommandType(nRet);
180 m_xDatabaseDataProvider->setCommand(sValue);
183 m_xDatabaseDataProvider->setFilter(sValue);
186 m_xDatabaseDataProvider->setEscapeProcessing(sValue == s_sTRUE);
193 catch(uno::Exception&)
198 m_bImportedChart =
true;
200 else if ( _sName ==
"rpt:master-detail-field" )
202 const sal_Int16
nLength = (_xAttrList.is()) ? _xAttrList->getLength() : 0;
203 ::std::unique_ptr<SvXMLTokenMap> pMasterElemTokenMap( OXMLHelper::GetSubDocumentElemTokenMap());
206 OUString sMasterField,sDetailField;
210 const OUString sAttrName = _xAttrList->getNameByIndex(
i );
211 const sal_Int32 nColonPos = sAttrName.indexOf(
':' );
212 if( -1 == nColonPos )
213 sLocalName = sAttrName;
215 sLocalName = sAttrName.copy( nColonPos + 1 );
216 const OUString sValue = _xAttrList->getValueByIndex(
i );
221 sMasterField = sValue;
224 sDetailField = sValue;
228 if ( sDetailField.isEmpty() )
229 sDetailField = sMasterField;
230 m_aMasterFields.push_back(sMasterField);
231 m_aDetailFields.push_back(sDetailField);
233 catch(uno::Exception&)
235 TOOLS_WARN_EXCEPTION(
"reportdesign",
"Exception caught while filling the report definition props");
239 else if ( _sName ==
"rpt:detail"
240 || _sName ==
"rpt:formatted-text"
241 || _sName ==
"rpt:master-detail-fields"
242 || _sName ==
"rpt:report-component"
243 || _sName ==
"rpt:report-element")
245 else if ( _sName ==
"chart:plot-area" )
247 bool bHasCategories =
true;
248 const sal_Int16
nLength = (_xAttrList.is()) ? _xAttrList->getLength() : 0;
251 std::u16string_view sLocalName;
252 const OUString sAttrName = _xAttrList->getNameByIndex(
i );
253 const sal_Int32 nColonPos = sAttrName.indexOf(
':' );
254 if( -1 == nColonPos )
255 sLocalName = sAttrName;
257 sLocalName = sAttrName.subView( nColonPos + 1 );
258 if ( sLocalName ==
u"data-source-has-labels" )
260 const OUString sValue = _xAttrList->getValueByIndex(
i );
261 bHasCategories = sValue ==
"both";
265 for(beans::PropertyValue & propVal : asNonConstRange(m_aArguments))
267 if ( propVal.Name ==
"HasCategories" )
269 propVal.Value <<= bHasCategories;
276 pList->AppendAttributeList(_xAttrList);
277 pList->AddAttribute(
"table:cell-range-address",
"local-table.$A$1:.$Z$65536");
282 m_xDelegatee->startElement(_sName,xNewAttribs);
285void SAL_CALL ImportDocumentHandler::endElement(
const OUString & _sName)
288 OUString sNewName = _sName;
289 if ( _sName ==
"office:report" )
293 else if ( _sName ==
"rpt:master-detail-fields" )
295 if ( !m_aMasterFields.empty() )
296 m_xDatabaseDataProvider->setMasterFields(uno::Sequence< OUString>(&*m_aMasterFields.begin(),m_aMasterFields.size()));
297 if ( !m_aDetailFields.empty() )
298 m_xDatabaseDataProvider->setDetailFields(uno::Sequence< OUString>(&*m_aDetailFields.begin(),m_aDetailFields.size()));
301 else if ( _sName ==
"rpt:detail"
302 || _sName ==
"rpt:formatted-text"
303 || _sName ==
"rpt:master-detail-field"
304 || _sName ==
"rpt:report-component"
305 || _sName ==
"rpt:report-element")
309 m_xDelegatee->endElement(sNewName);
312void SAL_CALL ImportDocumentHandler::characters(
const OUString & aChars)
314 m_xDelegatee->characters(aChars);
317void SAL_CALL ImportDocumentHandler::ignorableWhitespace(
const OUString & aWhitespaces)
319 m_xDelegatee->ignorableWhitespace(aWhitespaces);
322void SAL_CALL ImportDocumentHandler::processingInstruction(
const OUString & aTarget,
const OUString & aData)
324 m_xDelegatee->processingInstruction(aTarget,
aData);
327void SAL_CALL ImportDocumentHandler::setDocumentLocator(
const uno::Reference< xml::sax::XLocator > & xLocator)
329 m_xDelegatee->setDocumentLocator(xLocator);
331void SAL_CALL ImportDocumentHandler::initialize(
const uno::Sequence< uno::Any >& _aArguments )
338 OSL_ENSURE(m_xDocumentHandler.is(),
"No document handler available!");
339 if (!m_xDocumentHandler.is() || !
m_xModel.is())
340 throw uno::Exception(
"no delegatee and no model",
nullptr);
344 m_xDatabaseDataProvider.set(
m_xModel->getDataProvider(),uno::UNO_QUERY);
345 if ( !m_xDatabaseDataProvider.is() )
349 m_xDatabaseDataProvider.set(
m_xModel->getDataProvider(), uno::UNO_QUERY_THROW);
352 m_aArguments = m_xDatabaseDataProvider->detectArguments(
nullptr);
354 uno::Reference< reflection::XProxyFactory > xProxyFactory = reflection::ProxyFactory::create(
m_xContext );
355 m_xProxy = xProxyFactory->createProxy(m_xDelegatee);
356 ::comphelper::query_aggregation(m_xProxy,m_xDelegatee);
357 m_xTypeProvider.set(m_xDelegatee,uno::UNO_QUERY);
358 m_xServiceInfo.set(m_xDelegatee,uno::UNO_QUERY);
361 m_xProxy->setDelegator( *
this );
363 m_pReportElemTokenMap = OXMLHelper::GetReportElemTokenMap();
368 uno::Any aReturn = ImportDocumentHandler_BASE::queryInterface(_rType);
369 return aReturn.
hasValue() ? aReturn : (m_xProxy.is() ? m_xProxy->queryAggregation(_rType) : aReturn);
372uno::Sequence< uno::Type > SAL_CALL ImportDocumentHandler::getTypes( )
374 if ( m_xTypeProvider.is() )
375 return ::comphelper::concatSequences(
376 ImportDocumentHandler_BASE::getTypes(),
377 m_xTypeProvider->getTypes()
379 return ImportDocumentHandler_BASE::getTypes();
Reference< XComponentContext > m_xContext
XMLOFF_DLLPUBLIC void setDataProvider(css::uno::Reference< css::chart2::XChartDocument > const &xChartDoc, OUString const &sDataPilotSource)
static bool convertEnum(EnumT &rEnum, std::u16string_view rValue, const SvXMLEnumMapEntry< EnumT > *pMap)
bool put(const OUString &_rValueName, const VALUE_TYPE &_rValue)
css::uno::Sequence< css::beans::PropertyValue > getPropertyValues() const
TValueType getUnpackedValueOrDefault(const OUString &sKey, const TValueType &aDefault) const
ImportDocumentHandler(css::uno::Reference< css::uno::XComponentContext > context)
#define TOOLS_WARN_EXCEPTION(area, stream)
Reference< frame::XModel > m_xModel
constexpr OUStringLiteral aData
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
@ XML_TOK_ESCAPE_PROCESSING
OUString lcl_createAttribute(const xmloff::token::XMLTokenEnum &_eNamespace, const xmloff::token::XMLTokenEnum &_eAttribute)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * reportdesign_ImportDocumentHandler_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
IMPLEMENT_GET_IMPLEMENTATION_ID(DrawController)
constexpr sal_uInt16 XML_NAMESPACE_REPORT