21#include <officecfg/Office/Common.hxx>
22#include <com/sun/star/sdb/CommandType.hpp>
23#include <com/sun/star/chart2/data/XDatabaseDataProvider.hpp>
24#include <com/sun/star/chart/XComplexDescriptionAccess.hpp>
25#include <com/sun/star/reflection/ProxyFactory.hpp>
34#include <rtl/ustrbuf.hxx>
44 if ( officecfg::Office::Common::Save::Document::PrettyPrinting::get() )
46 _xDelegatee->ignorableWhitespace(
" ");
59static void lcl_correctCellAddress(
const OUString & _sName,
const uno::Reference< xml::sax::XAttributeList > & xAttribs)
62 assert(pList &&
"can only succeed");
64 const sal_Int32
nPos = sCellAddress.lastIndexOf(
'$');
67 sCellAddress = OUString::Concat(sCellAddress.subView(0,
nPos)) +
"$65535";
76 ,m_bTableRowsStarted(false)
77 ,m_bFirstRowExported(false)
78 ,m_bCountColumnHeader(false)
82ExportDocumentHandler::~ExportDocumentHandler()
86 m_xProxy->setDelegator(
nullptr );
94 return "com.sun.star.comp.report.ExportDocumentHandler";
97sal_Bool SAL_CALL ExportDocumentHandler::supportsService(
const OUString& ServiceName )
102uno::Sequence< OUString > SAL_CALL ExportDocumentHandler::getSupportedServiceNames( )
104 uno::Sequence< OUString > aSupported;
105 if ( m_xServiceInfo.is() )
106 aSupported = m_xServiceInfo->getSupportedServiceNames();
107 return ::comphelper::concatSequences(uno::Sequence< OUString > {
"com.sun.star.report.ExportDocumentHandler" },aSupported);
111void SAL_CALL ExportDocumentHandler::startDocument()
113 m_xDelegatee->startDocument();
116void SAL_CALL ExportDocumentHandler::endDocument()
118 m_xDelegatee->endDocument();
121void SAL_CALL ExportDocumentHandler::startElement(
const OUString & _sName,
const uno::Reference< xml::sax::XAttributeList > & xAttribs)
124 if ( _sName ==
"office:chart" )
127 OUStringBuffer sValue;
138 const OUString sCommand = m_xDatabaseDataProvider->getCommand();
139 if ( !sCommand.isEmpty() )
142 const OUString sFilter( m_xDatabaseDataProvider->getFilter() );
143 if ( !sFilter.isEmpty() )
146 const bool bEscapeProcessing( m_xDatabaseDataProvider->getEscapeProcessing() );
147 if ( !bEscapeProcessing )
155 m_xDelegatee->startElement(sTableCalc,
nullptr);
160 m_xDelegatee->startElement(sNullDate,pList);
161 m_xDelegatee->endElement(sNullDate);
162 m_xDelegatee->endElement(sTableCalc);
165 else if ( _sName ==
"table:table" )
170 else if ( _sName ==
"table:table-header-rows" )
172 m_bCountColumnHeader =
true;
174 else if ( m_bCountColumnHeader && _sName ==
"table:table-cell" )
178 else if ( _sName ==
"table:table-rows" )
180 m_xDelegatee->startElement(_sName,xAttribs);
183 m_bTableRowsStarted =
true;
184 m_bFirstRowExported =
true;
186 else if ( m_bTableRowsStarted && m_bFirstRowExported && (_sName ==
"table:table-row" || _sName ==
"table:table-cell") )
188 else if ( _sName ==
"chart:plot-area" )
191 assert(pList &&
"can only succeed");
194 else if ( _sName ==
"chart:categories" )
199 else if ( _sName ==
"chart:series" )
204 else if ( m_bTableRowsStarted && !m_bFirstRowExported && _sName ==
"table:table-cell" )
207 assert(pList &&
"can only succeed");
211 else if ( m_bTableRowsStarted && _sName ==
"text:p" )
216 m_xDelegatee->startElement(_sName,xAttribs);
219void SAL_CALL ExportDocumentHandler::endElement(
const OUString & _sName)
222 OUString sNewName = _sName;
223 if ( _sName ==
"office:chart" )
227 else if ( _sName ==
"table:table" )
229 m_xDelegatee->endElement(_sName);
233 else if ( _sName ==
"table:table-header-rows" )
235 m_bCountColumnHeader =
false;
237 else if ( _sName ==
"table:table-rows" )
238 m_bTableRowsStarted =
false;
239 else if ( m_bTableRowsStarted && m_bFirstRowExported && (_sName ==
"table:table-row" || _sName ==
"table:table-cell") )
241 else if ( m_bTableRowsStarted && _sName ==
"table:table-row" )
242 m_bFirstRowExported =
true;
243 else if ( m_bTableRowsStarted && _sName ==
"text:p" )
245 bExport = !m_bFirstRowExported;
249 m_xDelegatee->endElement(sNewName);
252void SAL_CALL ExportDocumentHandler::characters(
const OUString & aChars)
254 if ( !(m_bTableRowsStarted || m_bFirstRowExported) )
256 m_xDelegatee->characters(aChars);
260void SAL_CALL ExportDocumentHandler::ignorableWhitespace(
const OUString & aWhitespaces)
262 m_xDelegatee->ignorableWhitespace(aWhitespaces);
265void SAL_CALL ExportDocumentHandler::processingInstruction(
const OUString & aTarget,
const OUString & aData)
267 m_xDelegatee->processingInstruction(aTarget,
aData);
270void SAL_CALL ExportDocumentHandler::setDocumentLocator(
const uno::Reference< xml::sax::XLocator > & xLocator)
272 m_xDelegatee->setDocumentLocator(xLocator);
274void SAL_CALL ExportDocumentHandler::initialize(
const uno::Sequence< uno::Any >& _aArguments )
281 OSL_ENSURE(m_xDelegatee.is(),
"No document handler available!");
282 if ( !m_xDelegatee.is() || !
m_xModel.is() )
283 throw uno::Exception(
"no delegatee and no model",
nullptr);
285 m_xDatabaseDataProvider.set(
m_xModel->getDataProvider(),uno::UNO_QUERY_THROW);
286 if ( !m_xDatabaseDataProvider->getActiveConnection().is() )
287 throw uno::Exception(
"no active connection",
nullptr);
289 uno::Reference< reflection::XProxyFactory > xProxyFactory = reflection::ProxyFactory::create(
m_xContext );
290 m_xProxy = xProxyFactory->createProxy(m_xDelegatee);
291 ::comphelper::query_aggregation(m_xProxy,m_xDelegatee);
292 m_xTypeProvider.set(m_xDelegatee,uno::UNO_QUERY);
293 m_xServiceInfo.set(m_xDelegatee,uno::UNO_QUERY);
296 m_xProxy->setDelegator( *
this );
297 const OUString sCommand = m_xDatabaseDataProvider->getCommand();
298 if ( !sCommand.isEmpty() )
299 m_aColumns = ::dbtools::getFieldNamesByCommandDescriptor(m_xDatabaseDataProvider->getActiveConnection()
300 ,m_xDatabaseDataProvider->getCommandType()
303 uno::Reference< chart::XComplexDescriptionAccess > xDataProvider(m_xDatabaseDataProvider,uno::UNO_QUERY);
304 if ( !xDataProvider.is() )
307 m_aColumns.realloc(1);
308 const uno::Sequence< OUString > aColumnNames = xDataProvider->getColumnDescriptions();
309 for(
const auto& rColumnName : aColumnNames)
311 if ( !rColumnName.isEmpty() )
313 sal_Int32
nCount = m_aColumns.getLength();
314 m_aColumns.realloc(
nCount+1);
315 m_aColumns.getArray()[
nCount] = rColumnName;
322 uno::Any aReturn = ExportDocumentHandler_BASE::queryInterface(_rType);
323 return aReturn.
hasValue() ? aReturn : (m_xProxy.is() ? m_xProxy->queryAggregation(_rType) : aReturn);
326uno::Sequence< uno::Type > SAL_CALL ExportDocumentHandler::getTypes( )
328 if ( m_xTypeProvider.is() )
329 return ::comphelper::concatSequences(
330 ExportDocumentHandler_BASE::getTypes(),
331 m_xTypeProvider->getTypes()
333 return ExportDocumentHandler_BASE::getTypes();
336void ExportDocumentHandler::exportTableRows()
339 m_xDelegatee->startElement(sRow,
nullptr);
349 static constexpr OUStringLiteral s_sFloat =
u"float";
352 pCellAtt->AddAttribute(sValueType,
"string");
354 bool bRemoveString =
true;
355 const sal_Int32
nCount = m_aColumns.getLength();
356 if ( m_nColumnCount >
nCount )
358 const sal_Int32 nEmptyCellCount = m_nColumnCount -
nCount;
359 for(sal_Int32
i = 0;
i < nEmptyCellCount ; ++
i)
361 m_xDelegatee->startElement(sCell,pCellAtt);
364 bRemoveString =
false;
365 pCellAtt->RemoveAttribute(sValueType);
366 pCellAtt->AddAttribute(sValueType,s_sFloat);
368 m_xDelegatee->startElement(sP,
nullptr);
369 m_xDelegatee->endElement(sP);
370 m_xDelegatee->endElement(sCell);
373 for(
const auto& rColumn : std::as_const(m_aColumns))
375 OUString
sFormula =
"field:[" + rColumn +
"]";
377 pList->AddAttribute(sFormulaAttrib,
sFormula);
379 m_xDelegatee->startElement(sCell,pCellAtt);
382 bRemoveString =
false;
383 pCellAtt->RemoveAttribute(sValueType);
384 pCellAtt->AddAttribute(sValueType,s_sFloat);
386 m_xDelegatee->startElement(sP,
nullptr);
387 m_xDelegatee->startElement(sFtext,pList);
388 m_xDelegatee->startElement(sRElement,
nullptr);
389 m_xDelegatee->startElement(sRComponent,
nullptr);
391 m_xDelegatee->endElement(sRComponent);
392 m_xDelegatee->endElement(sRElement);
393 m_xDelegatee->endElement(sFtext);
394 m_xDelegatee->endElement(sP);
395 m_xDelegatee->endElement(sCell);
398 m_xDelegatee->endElement(sRow);
404extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
406 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any>
const&)
Reference< XComponentContext > m_xContext
static bool convertEnum(EnumT &rEnum, std::u16string_view rValue, const SvXMLEnumMapEntry< EnumT > *pMap)
virtual OUString SAL_CALL getValueByName(const OUString &aName) override
void AddAttribute(const OUString &sName, const OUString &sValue)
void RemoveAttribute(const OUString &sName)
TValueType getUnpackedValueOrDefault(const OUString &sKey, const TValueType &aDefault) const
ExportDocumentHandler(css::uno::Reference< css::uno::XComponentContext > context)
Reference< frame::XModel > m_xModel
constexpr OUStringLiteral MIMETYPE_OASIS_OPENDOCUMENT_CHART_ASCII
constexpr OUStringLiteral aData
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
static void lcl_exportPrettyPrinting(const uno::Reference< xml::sax::XDocumentHandler > &_xDelegatee)
OUString lcl_createAttribute(const xmloff::token::XMLTokenEnum &_eNamespace, const xmloff::token::XMLTokenEnum &_eAttribute)
static void lcl_correctCellAddress(const OUString &_sName, const uno::Reference< xml::sax::XAttributeList > &xAttribs)
IMPLEMENT_GET_IMPLEMENTATION_ID(DrawController)
XML_VALUES_CELL_RANGE_ADDRESS
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * reportdesign_ExportDocumentHandler_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)