From ed5640d8b587fbcfed7dd7967f3de04b37a76f26 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:06:44 +0200 Subject: Adding upstream version 4:7.4.7. Signed-off-by: Daniel Baumann --- reportdesign/source/filter/xml/dbloader2.cxx | 111 ++ reportdesign/source/filter/xml/dbloader2.hxx | 48 + reportdesign/source/filter/xml/xmlAutoStyle.cxx | 83 ++ reportdesign/source/filter/xml/xmlAutoStyle.hxx | 52 + reportdesign/source/filter/xml/xmlCell.cxx | 262 ++++ reportdesign/source/filter/xml/xmlCell.hxx | 65 + reportdesign/source/filter/xml/xmlColumn.cxx | 166 +++ reportdesign/source/filter/xml/xmlColumn.hxx | 54 + reportdesign/source/filter/xml/xmlComponent.cxx | 71 + reportdesign/source/filter/xml/xmlComponent.hxx | 48 + reportdesign/source/filter/xml/xmlCondPrtExpr.cxx | 83 ++ reportdesign/source/filter/xml/xmlCondPrtExpr.hxx | 52 + .../source/filter/xml/xmlControlProperty.cxx | 332 +++++ .../source/filter/xml/xmlControlProperty.hxx | 79 + reportdesign/source/filter/xml/xmlEnums.hxx | 62 + reportdesign/source/filter/xml/xmlExport.cxx | 1537 ++++++++++++++++++++ reportdesign/source/filter/xml/xmlExport.hxx | 161 ++ .../source/filter/xml/xmlExportDocumentHandler.cxx | 408 ++++++ .../source/filter/xml/xmlExportDocumentHandler.hxx | 96 ++ reportdesign/source/filter/xml/xmlFixedContent.cxx | 215 +++ reportdesign/source/filter/xml/xmlFixedContent.hxx | 63 + .../source/filter/xml/xmlFormatCondition.cxx | 84 ++ .../source/filter/xml/xmlFormatCondition.hxx | 50 + .../source/filter/xml/xmlFormattedField.cxx | 77 + .../source/filter/xml/xmlFormattedField.hxx | 47 + reportdesign/source/filter/xml/xmlFunction.cxx | 115 ++ reportdesign/source/filter/xml/xmlFunction.hxx | 57 + reportdesign/source/filter/xml/xmlGroup.cxx | 246 ++++ reportdesign/source/filter/xml/xmlGroup.hxx | 55 + reportdesign/source/filter/xml/xmlHelper.cxx | 382 +++++ reportdesign/source/filter/xml/xmlHelper.hxx | 75 + reportdesign/source/filter/xml/xmlImage.cxx | 106 ++ reportdesign/source/filter/xml/xmlImage.hxx | 46 + .../source/filter/xml/xmlImportDocumentHandler.cxx | 385 +++++ .../source/filter/xml/xmlImportDocumentHandler.hxx | 97 ++ reportdesign/source/filter/xml/xmlMasterFields.cxx | 95 ++ reportdesign/source/filter/xml/xmlMasterFields.hxx | 48 + .../source/filter/xml/xmlPropertyHandler.cxx | 35 + .../source/filter/xml/xmlPropertyHandler.hxx | 40 + reportdesign/source/filter/xml/xmlReport.cxx | 208 +++ reportdesign/source/filter/xml/xmlReport.hxx | 61 + .../source/filter/xml/xmlReportElement.cxx | 116 ++ .../source/filter/xml/xmlReportElement.hxx | 50 + .../source/filter/xml/xmlReportElementBase.cxx | 97 ++ .../source/filter/xml/xmlReportElementBase.hxx | 66 + reportdesign/source/filter/xml/xmlSection.cxx | 114 ++ reportdesign/source/filter/xml/xmlSection.hxx | 53 + reportdesign/source/filter/xml/xmlStyleImport.cxx | 393 +++++ reportdesign/source/filter/xml/xmlStyleImport.hxx | 119 ++ reportdesign/source/filter/xml/xmlSubDocument.cxx | 150 ++ reportdesign/source/filter/xml/xmlSubDocument.hxx | 63 + reportdesign/source/filter/xml/xmlTable.cxx | 289 ++++ reportdesign/source/filter/xml/xmlTable.hxx | 90 ++ reportdesign/source/filter/xml/xmlfilter.cxx | 764 ++++++++++ reportdesign/source/filter/xml/xmlfilter.hxx | 140 ++ 55 files changed, 8861 insertions(+) create mode 100644 reportdesign/source/filter/xml/dbloader2.cxx create mode 100644 reportdesign/source/filter/xml/dbloader2.hxx create mode 100644 reportdesign/source/filter/xml/xmlAutoStyle.cxx create mode 100644 reportdesign/source/filter/xml/xmlAutoStyle.hxx create mode 100644 reportdesign/source/filter/xml/xmlCell.cxx create mode 100644 reportdesign/source/filter/xml/xmlCell.hxx create mode 100644 reportdesign/source/filter/xml/xmlColumn.cxx create mode 100644 reportdesign/source/filter/xml/xmlColumn.hxx create mode 100644 reportdesign/source/filter/xml/xmlComponent.cxx create mode 100644 reportdesign/source/filter/xml/xmlComponent.hxx create mode 100644 reportdesign/source/filter/xml/xmlCondPrtExpr.cxx create mode 100644 reportdesign/source/filter/xml/xmlCondPrtExpr.hxx create mode 100644 reportdesign/source/filter/xml/xmlControlProperty.cxx create mode 100644 reportdesign/source/filter/xml/xmlControlProperty.hxx create mode 100644 reportdesign/source/filter/xml/xmlEnums.hxx create mode 100644 reportdesign/source/filter/xml/xmlExport.cxx create mode 100644 reportdesign/source/filter/xml/xmlExport.hxx create mode 100644 reportdesign/source/filter/xml/xmlExportDocumentHandler.cxx create mode 100644 reportdesign/source/filter/xml/xmlExportDocumentHandler.hxx create mode 100644 reportdesign/source/filter/xml/xmlFixedContent.cxx create mode 100644 reportdesign/source/filter/xml/xmlFixedContent.hxx create mode 100644 reportdesign/source/filter/xml/xmlFormatCondition.cxx create mode 100644 reportdesign/source/filter/xml/xmlFormatCondition.hxx create mode 100644 reportdesign/source/filter/xml/xmlFormattedField.cxx create mode 100644 reportdesign/source/filter/xml/xmlFormattedField.hxx create mode 100644 reportdesign/source/filter/xml/xmlFunction.cxx create mode 100644 reportdesign/source/filter/xml/xmlFunction.hxx create mode 100644 reportdesign/source/filter/xml/xmlGroup.cxx create mode 100644 reportdesign/source/filter/xml/xmlGroup.hxx create mode 100644 reportdesign/source/filter/xml/xmlHelper.cxx create mode 100644 reportdesign/source/filter/xml/xmlHelper.hxx create mode 100644 reportdesign/source/filter/xml/xmlImage.cxx create mode 100644 reportdesign/source/filter/xml/xmlImage.hxx create mode 100644 reportdesign/source/filter/xml/xmlImportDocumentHandler.cxx create mode 100644 reportdesign/source/filter/xml/xmlImportDocumentHandler.hxx create mode 100644 reportdesign/source/filter/xml/xmlMasterFields.cxx create mode 100644 reportdesign/source/filter/xml/xmlMasterFields.hxx create mode 100644 reportdesign/source/filter/xml/xmlPropertyHandler.cxx create mode 100644 reportdesign/source/filter/xml/xmlPropertyHandler.hxx create mode 100644 reportdesign/source/filter/xml/xmlReport.cxx create mode 100644 reportdesign/source/filter/xml/xmlReport.hxx create mode 100644 reportdesign/source/filter/xml/xmlReportElement.cxx create mode 100644 reportdesign/source/filter/xml/xmlReportElement.hxx create mode 100644 reportdesign/source/filter/xml/xmlReportElementBase.cxx create mode 100644 reportdesign/source/filter/xml/xmlReportElementBase.hxx create mode 100644 reportdesign/source/filter/xml/xmlSection.cxx create mode 100644 reportdesign/source/filter/xml/xmlSection.hxx create mode 100644 reportdesign/source/filter/xml/xmlStyleImport.cxx create mode 100644 reportdesign/source/filter/xml/xmlStyleImport.hxx create mode 100644 reportdesign/source/filter/xml/xmlSubDocument.cxx create mode 100644 reportdesign/source/filter/xml/xmlSubDocument.hxx create mode 100644 reportdesign/source/filter/xml/xmlTable.cxx create mode 100644 reportdesign/source/filter/xml/xmlTable.hxx create mode 100644 reportdesign/source/filter/xml/xmlfilter.cxx create mode 100644 reportdesign/source/filter/xml/xmlfilter.hxx (limited to 'reportdesign/source/filter/xml') diff --git a/reportdesign/source/filter/xml/dbloader2.cxx b/reportdesign/source/filter/xml/dbloader2.cxx new file mode 100644 index 000000000..67ba9b489 --- /dev/null +++ b/reportdesign/source/filter/xml/dbloader2.cxx @@ -0,0 +1,111 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#include "dbloader2.hxx" +#include +#include +#include +#include +#include +#include +#include +#include + +namespace rptxml +{ + +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::io; +using namespace ::com::sun::star::util; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::document; +using namespace ::com::sun::star::embed; +using namespace ::com::sun::star::ui::dialogs; + + +ORptTypeDetection::ORptTypeDetection(Reference< XComponentContext > const & xContext) +: m_xContext(xContext) +{ +} + +OUString SAL_CALL ORptTypeDetection::detect( Sequence< css::beans::PropertyValue >& Descriptor ) +{ + + ::comphelper::SequenceAsHashMap aTemp(Descriptor); + OUString sTemp = aTemp.getUnpackedValueOrDefault("URL",OUString()); + + if ( !sTemp.isEmpty() ) + { + INetURLObject aURL(sTemp); + if ( aURL.GetFileExtension().equalsIgnoreAsciiCase("orp") ) + return "StarBaseReport"; + else + { + try + { + Reference xProp(::comphelper::OStorageHelper::GetStorageFromURL(sTemp,ElementModes::READ, m_xContext),UNO_QUERY); + if ( xProp.is() ) + { + OUString sMediaType; + xProp->getPropertyValue("MediaType") >>= sMediaType; + if ( sMediaType == MIMETYPE_OASIS_OPENDOCUMENT_REPORT_ASCII ) + return "StarBaseReport"; + ::comphelper::disposeComponent(xProp); + } + } + catch(Exception&) + { + } + } + } + return OUString(); +} + +// XServiceInfo +OUString SAL_CALL ORptTypeDetection::getImplementationName() +{ + return "com.sun.star.comp.report.ORptTypeDetection"; +} + + +// XServiceInfo +sal_Bool SAL_CALL ORptTypeDetection::supportsService(const OUString& ServiceName) +{ + return cppu::supportsService(this, ServiceName); +} + +// XServiceInfo +Sequence< OUString > SAL_CALL ORptTypeDetection::getSupportedServiceNames() +{ + return { "com.sun.star.document.ExtendedTypeDetection" }; +} + + +}//rptxml + +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* +reportdesign_ORptTypeDetection_get_implementation( + css::uno::XComponentContext* context, css::uno::Sequence const&) +{ + return cppu::acquire(new rptxml::ORptTypeDetection(context)); +} + + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/reportdesign/source/filter/xml/dbloader2.hxx b/reportdesign/source/filter/xml/dbloader2.hxx new file mode 100644 index 000000000..3f5d3d877 --- /dev/null +++ b/reportdesign/source/filter/xml/dbloader2.hxx @@ -0,0 +1,48 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_DBLOADER2_HXX +#define INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_DBLOADER2_HXX + +#include +#include +#include +#include + + +namespace rptxml +{ + +class ORptTypeDetection : public ::cppu::WeakImplHelper< css::document::XExtendedFilterDetection, css::lang::XServiceInfo> +{ + css::uno::Reference< css::uno::XComponentContext > m_xContext; +public: + explicit ORptTypeDetection(css::uno::Reference< css::uno::XComponentContext > const & xContext); + + // XServiceInfo + OUString SAL_CALL getImplementationName() override; + sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override; + css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; + + virtual OUString SAL_CALL detect( css::uno::Sequence< css::beans::PropertyValue >& Descriptor ) override; +}; +} +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/reportdesign/source/filter/xml/xmlAutoStyle.cxx b/reportdesign/source/filter/xml/xmlAutoStyle.cxx new file mode 100644 index 000000000..0e2fbb5a4 --- /dev/null +++ b/reportdesign/source/filter/xml/xmlAutoStyle.cxx @@ -0,0 +1,83 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#include "xmlAutoStyle.hxx" +#include "xmlHelper.hxx" +#include "xmlExport.hxx" +#include + +namespace rptxml +{ + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::xml::sax; + +void OXMLAutoStylePoolP::exportStyleAttributes( + SvXMLAttributeList& rAttrList, + XmlStyleFamily nFamily, + const ::std::vector< XMLPropertyState >& rProperties, + const SvXMLExportPropertyMapper& rPropExp + , const SvXMLUnitConverter& rUnitConverter, + const SvXMLNamespaceMap& rNamespaceMap + ) const +{ + SvXMLAutoStylePoolP::exportStyleAttributes( rAttrList, nFamily, rProperties, rPropExp, rUnitConverter, rNamespaceMap ); + if ( nFamily != XmlStyleFamily::TABLE_CELL ) + return; + + rtl::Reference< XMLPropertySetMapper > aPropMapper = rORptExport.GetCellStylePropertyMapper(); + for (const auto& rProp : rProperties) + { + sal_Int16 nContextID = aPropMapper->GetEntryContextId(rProp.mnIndex); + switch (nContextID) + { + case CTF_RPT_NUMBERFORMAT : + { + OUString sAttrValue; + if ( rProp.maValue >>= sAttrValue ) + { + if ( !sAttrValue.isEmpty() ) + { + rORptExport.AddAttribute( + aPropMapper->GetEntryNameSpace(rProp.mnIndex), + aPropMapper->GetEntryXMLName(rProp.mnIndex), + sAttrValue ); + } + } + break; + } + default: + break; + } + } +} + +OXMLAutoStylePoolP::OXMLAutoStylePoolP(ORptExport& rTempORptExport): + SvXMLAutoStylePoolP(rTempORptExport), + rORptExport(rTempORptExport) +{ +} + +OXMLAutoStylePoolP::~OXMLAutoStylePoolP() +{ +} + + +} // namespace rptxml + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/reportdesign/source/filter/xml/xmlAutoStyle.hxx b/reportdesign/source/filter/xml/xmlAutoStyle.hxx new file mode 100644 index 000000000..4f0643878 --- /dev/null +++ b/reportdesign/source/filter/xml/xmlAutoStyle.hxx @@ -0,0 +1,52 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLAUTOSTYLE_HXX +#define INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLAUTOSTYLE_HXX + +#include +#include + +namespace rptxml +{ + class ORptExport; + class OXMLAutoStylePoolP : public SvXMLAutoStylePoolP + { + ORptExport& rORptExport; + + virtual void exportStyleAttributes( + SvXMLAttributeList& rAttrList, + XmlStyleFamily nFamily, + const ::std::vector< XMLPropertyState >& rProperties, + const SvXMLExportPropertyMapper& rPropExp, + const SvXMLUnitConverter& rUnitConverter, + const SvXMLNamespaceMap& rNamespaceMap + ) const override; + + OXMLAutoStylePoolP(const OXMLAutoStylePoolP&) = delete; + void operator =(const OXMLAutoStylePoolP&) = delete; + public: + explicit OXMLAutoStylePoolP(ORptExport& rXMLExport); + virtual ~OXMLAutoStylePoolP() override; + }; + +} // rptxml + +#endif // INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLAUTOSTYLE_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/reportdesign/source/filter/xml/xmlCell.cxx b/reportdesign/source/filter/xml/xmlCell.cxx new file mode 100644 index 000000000..82fddb7a7 --- /dev/null +++ b/reportdesign/source/filter/xml/xmlCell.cxx @@ -0,0 +1,262 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#include "xmlCell.hxx" +#include "xmlHelper.hxx" +#include "xmlfilter.hxx" +#include +#include +#include +#include +#include +#include "xmlEnums.hxx" +#include +#include +#include +#include +#include +#include +#include +#include +#include "xmlTable.hxx" +#include "xmlFormattedField.hxx" +#include "xmlImage.hxx" +#include "xmlFixedContent.hxx" +#include "xmlSubDocument.hxx" + +namespace rptxml +{ + using namespace ::com::sun::star; + using namespace uno; + using namespace beans; + using namespace xml::sax; + + +OXMLCell::OXMLCell( ORptFilter& rImport + ,const Reference< XFastAttributeList > & _xAttrList + ,OXMLTable* _pContainer + ,OXMLCell* _pCell) : + SvXMLImportContext( rImport ) + ,m_pContainer(_pContainer) + ,m_pCell(_pCell) + ,m_nCurrentCount(0) + ,m_bContainsShape(false) +{ + if ( !m_pCell ) + m_pCell = this; + + for (auto &aIter : sax_fastparser::castToFastAttributeList( _xAttrList )) + { + switch( aIter.getToken() ) + { + case XML_ELEMENT(TABLE, XML_STYLE_NAME): + m_sStyleName = aIter.toString(); + break; + case XML_ELEMENT(TABLE, XML_NUMBER_COLUMNS_SPANNED): + m_pContainer->setColumnSpanned(aIter.toInt32()); + break; + case XML_ELEMENT(TABLE, XML_NUMBER_ROWS_SPANNED): + m_pContainer->setRowSpanned(aIter.toInt32()); + break; + default: + XMLOFF_WARN_UNKNOWN("reportdesign", aIter); + break; + } + } +} + +OXMLCell::~OXMLCell() +{ +} + +css::uno::Reference< css::xml::sax::XFastContextHandler > OXMLCell::createFastChildContext( + sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) +{ + css::uno::Reference< css::xml::sax::XFastContextHandler > xContext; + ORptFilter& rImport = GetOwnImport(); + Reference xFactor(rImport.GetModel(),uno::UNO_QUERY); + static constexpr char16_t s_sStringConcat[] = u" & "; + + switch( nElement ) + { + case XML_ELEMENT(REPORT, XML_FIXED_CONTENT): + { + rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + xContext = new OXMLFixedContent( rImport,*m_pCell,m_pContainer); + } + break; + case XML_ELEMENT(TEXT, XML_PAGE_NUMBER): + m_sText += OUString::Concat(s_sStringConcat) + " PageNumber()"; + break; + case XML_ELEMENT(TEXT, XML_PAGE_COUNT): + m_sText += OUString::Concat(s_sStringConcat) + " PageCount()"; + break; + case XML_ELEMENT(REPORT, XML_FORMATTED_TEXT): + { + rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + uno::Reference< uno::XInterface> xInt = xFactor->createInstance(SERVICE_FORMATTEDFIELD); + Reference< report::XFormattedField > xControl(xInt,uno::UNO_QUERY); + + OSL_ENSURE(xControl.is(),"Could not create FormattedField!"); + setComponent(xControl); + if ( xControl.is() ) + xContext = new OXMLFormattedField( rImport,xAttrList,xControl,m_pContainer, false); + } + break; + case XML_ELEMENT(REPORT, XML_IMAGE): + { + rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + Reference< XImageControl > xControl(xFactor->createInstance(SERVICE_IMAGECONTROL),uno::UNO_QUERY); + + OSL_ENSURE(xControl.is(),"Could not create ImageControl!"); + setComponent(xControl); + if ( xControl.is() ) + xContext = new OXMLImage( rImport,xAttrList,xControl,m_pContainer); + } + break; + case XML_ELEMENT(REPORT, XML_SUB_DOCUMENT): + { + rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + if ( !m_bContainsShape ) + m_nCurrentCount = m_pContainer->getSection()->getCount(); + uno::Reference< uno::XInterface> xInt = xFactor->createInstance(SERVICE_FORMATTEDFIELD); + Reference< report::XFormattedField > xControl(xInt,uno::UNO_QUERY); + xContext = new OXMLSubDocument( rImport,xControl,m_pContainer, this /* give the current cell as parent*/ ); + } + break; + + case XML_ELEMENT(TEXT, XML_P): + xContext = new OXMLCell( rImport,xAttrList ,m_pContainer,this); + break; + + case XML_ELEMENT(DRAW, XML_CUSTOM_SHAPE): + case XML_ELEMENT(DRAW, XML_FRAME): + { + if ( !m_bContainsShape ) + m_nCurrentCount = m_pContainer->getSection()->getCount(); + uno::Reference< drawing::XShapes > xShapes = m_pContainer->getSection(); + xContext = XMLShapeImportHelper::CreateGroupChildContext(rImport,nElement,xAttrList,xShapes); + m_bContainsShape = true; + } + break; + + default: + SAL_WARN("reportdesign", "unknown element " << SvXMLImport::getPrefixAndNameFromToken(nElement)); + } + + if ( m_xComponent.is() ) + m_pContainer->addCell(m_xComponent); + + return xContext; +} + +void OXMLCell::endFastElement(sal_Int32) +{ + if ( m_bContainsShape ) + { + const sal_Int32 nCount = m_pContainer->getSection()->getCount(); + for (sal_Int32 i = m_nCurrentCount; i < nCount; ++i) + { + uno::Reference xShape(m_pContainer->getSection()->getByIndex(i),uno::UNO_QUERY); + if ( xShape.is() ) + m_pContainer->addCell(xShape); + } + } + if ( m_pCell != this && !m_sText.isEmpty() ) + { + ORptFilter& rImport = GetOwnImport(); + Reference xFactor(rImport.GetModel(),uno::UNO_QUERY); + uno::Reference< uno::XInterface> xInt = xFactor->createInstance(SERVICE_FORMATTEDFIELD); + Reference< report::XFormattedField > xControl(xInt,uno::UNO_QUERY); + xControl->setDataField("rpt:" + m_sText); + + OSL_ENSURE(xControl.is(),"Could not create FormattedField!"); + setComponent(xControl); + m_xComponent = xControl.get(); + m_pContainer->getSection()->add(m_xComponent); + m_pContainer->addCell(m_xComponent); + } + // check if we have a FixedLine + else if ( !m_sStyleName.isEmpty() && !m_xComponent.is() && m_pCell == this ) + { + ORptFilter& rImport = GetOwnImport(); + Reference xFactor(rImport.GetModel(),uno::UNO_QUERY); + Reference xFixedLine(xFactor->createInstance(SERVICE_FIXEDLINE),uno::UNO_QUERY); + m_xComponent = xFixedLine.get(); + m_pContainer->getSection()->add(m_xComponent); + m_pContainer->addCell(m_xComponent); + XMLPropStyleContext* pAutoStyle = const_cast(dynamic_cast< const XMLPropStyleContext* >(GetImport().GetAutoStyles()->FindStyleChildContext(XmlStyleFamily::TABLE_CELL,m_sStyleName))); + if ( pAutoStyle ) + { + uno::Reference xBorderProp = OXMLHelper::createBorderPropertySet(); + try + { + pAutoStyle->FillPropertySet(xBorderProp); + table::BorderLine2 aRight,aLeft; + xBorderProp->getPropertyValue(PROPERTY_BORDERRIGHT) >>= aRight; + xBorderProp->getPropertyValue(PROPERTY_BORDERLEFT) >>= aLeft; + const sal_Int16 rWidth = (aRight.LineWidth == 0) ? aRight.OuterLineWidth : aRight.LineWidth; + const sal_Int16 lWidth = (aLeft.LineWidth == 0) ? aLeft.OuterLineWidth : aLeft.LineWidth; + xFixedLine->setOrientation( (rWidth != 0 || lWidth != 0) ? 1 : 0); + } + catch(uno::Exception&) + { + TOOLS_WARN_EXCEPTION( "reportdesign", "OXMLCell::EndElement -> exception caught"); + } + } + } + else + OXMLHelper::copyStyleElements(GetOwnImport().isOldFormat(),m_sStyleName,GetImport().GetAutoStyles(),m_xComponent); +} + +ORptFilter& OXMLCell::GetOwnImport() +{ + return static_cast(GetImport()); +} + +void OXMLCell::setComponent(const uno::Reference< report::XReportComponent >& _xComponent) +{ + m_pCell->m_xComponent = _xComponent; + m_xComponent = _xComponent; +} + +void OXMLCell::characters( const OUString& rChars ) +{ + if ( !rChars.isEmpty() ) + { + static const char s_Quote[] = "\""; + if ( !m_sText.isEmpty() ) + { + m_sText += " & "; + } + + m_sText += s_Quote + rChars + s_Quote; + } +} + +void OXMLCell::setContainsShape(bool _bContainsShape) +{ + m_bContainsShape = _bContainsShape; +} + + +} // namespace rptxml + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/reportdesign/source/filter/xml/xmlCell.hxx b/reportdesign/source/filter/xml/xmlCell.hxx new file mode 100644 index 000000000..065af60d7 --- /dev/null +++ b/reportdesign/source/filter/xml/xmlCell.hxx @@ -0,0 +1,65 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLCELL_HXX +#define INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLCELL_HXX + +#include +#include + +namespace rptxml +{ + class ORptFilter; + class OXMLTable; + class OXMLCell : public SvXMLImportContext + { + css::uno::Reference< css::report::XReportComponent > m_xComponent; + OXMLTable* m_pContainer; + OXMLCell* m_pCell; + OUString m_sStyleName; + OUString m_sText; + sal_Int32 m_nCurrentCount; + bool m_bContainsShape; + + ORptFilter& GetOwnImport(); + OXMLCell(const OXMLCell&) = delete; + OXMLCell& operator =(const OXMLCell&) = delete; + public: + + OXMLCell( ORptFilter& rImport + ,const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList + ,OXMLTable* _pContainer + ,OXMLCell* _pCell = nullptr); + virtual ~OXMLCell() override; + + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( + sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override; + + virtual void SAL_CALL characters( const OUString& rChars ) override; + virtual void SAL_CALL endFastElement(sal_Int32 nElement) override; + + void setComponent(const css::uno::Reference< css::report::XReportComponent >& _xComponent); + void setContainsShape(bool _bContainsShapes); + }; + +} // namespace rptxml + + +#endif // INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLCELL_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/reportdesign/source/filter/xml/xmlColumn.cxx b/reportdesign/source/filter/xml/xmlColumn.cxx new file mode 100644 index 000000000..43464a276 --- /dev/null +++ b/reportdesign/source/filter/xml/xmlColumn.cxx @@ -0,0 +1,166 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include "xmlColumn.hxx" +#include +#include "xmlfilter.hxx" +#include +#include +#include +#include +#include +#include "xmlEnums.hxx" +#include "xmlCell.hxx" +#include "xmlTable.hxx" +#include +#include +#include +#include + +#define PROPERTY_ID_WIDTH 1 +#define PROPERTY_ID_HEIGHT 2 +#define PROPERTY_ID_MINHEIGHT 3 + +namespace rptxml +{ + using namespace ::comphelper; + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::beans; + using namespace ::com::sun::star::xml::sax; + + +OXMLRowColumn::OXMLRowColumn( ORptFilter& rImport + ,const Reference< XFastAttributeList > & _xAttrList + ,OXMLTable* _pContainer + ) : + SvXMLImportContext( rImport ) + ,m_pContainer(_pContainer) +{ + for (auto &aIter : sax_fastparser::castToFastAttributeList( _xAttrList )) + { + switch( aIter.getToken() ) + { + case XML_ELEMENT(TABLE, XML_STYLE_NAME): + fillStyle(aIter.toString()); + break; + default: + XMLOFF_WARN_UNKNOWN("reportdesign", aIter); + break; + } + } +} + + +OXMLRowColumn::~OXMLRowColumn() +{ +} + +css::uno::Reference< css::xml::sax::XFastContextHandler > OXMLRowColumn::createFastChildContext( + sal_Int32 nElement, + const Reference< XFastAttributeList > & xAttrList ) +{ + css::uno::Reference< css::xml::sax::XFastContextHandler > xContext; + ORptFilter& rImport = GetOwnImport(); + + switch( nElement ) + { + case XML_ELEMENT(TABLE, XML_TABLE_COLUMN): + rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + xContext = new OXMLRowColumn( rImport,xAttrList,m_pContainer); + break; + case XML_ELEMENT(TABLE, XML_TABLE_ROW): + m_pContainer->incrementRowIndex(); + rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + xContext = new OXMLRowColumn( rImport,xAttrList,m_pContainer); + break; + case XML_ELEMENT(TABLE, XML_TABLE_CELL): + m_pContainer->incrementColumnIndex(); + rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + xContext = new OXMLCell( rImport,xAttrList,m_pContainer); + break; + case XML_ELEMENT(TABLE, XML_COVERED_TABLE_CELL): + m_pContainer->incrementColumnIndex(); + m_pContainer->addCell(nullptr); + break; + default: + break; + } + + return xContext; +} + +void OXMLRowColumn::fillStyle(const OUString& _sStyleName) +{ + if ( _sStyleName.isEmpty() ) + return; + + const SvXMLStylesContext* pAutoStyles = GetOwnImport().GetAutoStyles(); + if ( !pAutoStyles ) + return; + + rtl::Reference pInfo = new PropertySetInfo(); + static PropertyMapEntry const pMap[] = + { + {OUString(PROPERTY_WIDTH), PROPERTY_ID_WIDTH, ::cppu::UnoType::get() ,PropertyAttribute::BOUND,0}, + {OUString(PROPERTY_HEIGHT), PROPERTY_ID_HEIGHT, ::cppu::UnoType::get() ,PropertyAttribute::BOUND,0 }, + {OUString(PROPERTY_MINHEIGHT), PROPERTY_ID_MINHEIGHT, ::cppu::UnoType::get() ,PropertyAttribute::BOUND,0 }, + }; + pInfo->add(pMap); + Reference xProp = GenericPropertySet_CreateInstance(pInfo.get()); + XMLPropStyleContext* pAutoStyle = const_cast(dynamic_cast< const XMLPropStyleContext*>(pAutoStyles->FindStyleChildContext(XmlStyleFamily::TABLE_COLUMN,_sStyleName))); + if ( pAutoStyle ) + { + pAutoStyle->FillPropertySet(xProp); + sal_Int32 nWidth = 0; + xProp->getPropertyValue(PROPERTY_WIDTH) >>= nWidth; + m_pContainer->addWidth(nWidth); + } + else + { + pAutoStyle = const_cast(dynamic_cast< const XMLPropStyleContext* >(pAutoStyles->FindStyleChildContext(XmlStyleFamily::TABLE_ROW,_sStyleName))); + if ( pAutoStyle ) + { + pAutoStyle->FillPropertySet(xProp); + sal_Int32 nHeight = 0; + sal_Int32 nMinHeight = 0; + xProp->getPropertyValue(PROPERTY_HEIGHT) >>= nHeight; + xProp->getPropertyValue(PROPERTY_MINHEIGHT) >>= nMinHeight; + if (nHeight == 0 && nMinHeight > 0) + { + m_pContainer->addHeight(nMinHeight); + m_pContainer->addAutoHeight(true); + } + else + { + m_pContainer->addHeight(nHeight); + m_pContainer->addAutoHeight(false); + } + } + } +} + +ORptFilter& OXMLRowColumn::GetOwnImport() +{ + return static_cast(GetImport()); +} + +} // namespace rptxml + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/reportdesign/source/filter/xml/xmlColumn.hxx b/reportdesign/source/filter/xml/xmlColumn.hxx new file mode 100644 index 000000000..e5bed54f7 --- /dev/null +++ b/reportdesign/source/filter/xml/xmlColumn.hxx @@ -0,0 +1,54 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLCOLUMN_HXX +#define INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLCOLUMN_HXX + +#include + +namespace rptxml +{ + class ORptFilter; + class OXMLTable; + class OXMLRowColumn : public SvXMLImportContext + { + OXMLTable* m_pContainer; + + ORptFilter& GetOwnImport(); + + void fillStyle(const OUString& _sStyleName); + OXMLRowColumn(const OXMLRowColumn&) = delete; + void operator =(const OXMLRowColumn&) = delete; + public: + + OXMLRowColumn( ORptFilter& rImport + ,const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList + ,OXMLTable* _pContainer + ); + virtual ~OXMLRowColumn() override; + + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( + sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override; + }; + +} // namespace rptxml + + +#endif // INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLCOLUMN_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/reportdesign/source/filter/xml/xmlComponent.cxx b/reportdesign/source/filter/xml/xmlComponent.cxx new file mode 100644 index 000000000..68111bb04 --- /dev/null +++ b/reportdesign/source/filter/xml/xmlComponent.cxx @@ -0,0 +1,71 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#include "xmlComponent.hxx" +#include "xmlfilter.hxx" +#include +#include +#include +#include + +namespace rptxml +{ + using namespace ::com::sun::star; + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::beans; + using namespace ::com::sun::star::report; + using namespace ::com::sun::star::xml::sax; +OXMLComponent::OXMLComponent( ORptFilter& _rImport + ,const Reference< XFastAttributeList > & _xAttrList + ,const Reference< XReportComponent > & _xComponent + ) : + SvXMLImportContext( _rImport ) + ,m_xComponent(_xComponent) +{ + OSL_ENSURE(m_xComponent.is(),"Component is NULL!"); + + for (auto &aIter : sax_fastparser::castToFastAttributeList( _xAttrList )) + { + try + { + switch( aIter.getToken() ) + { + case XML_ELEMENT(DRAW, XML_NAME): + m_xComponent->setName(aIter.toString()); + break; + default: + XMLOFF_WARN_UNKNOWN("reportdesign", aIter); + } + } + catch(const Exception&) + { + TOOLS_WARN_EXCEPTION( "reportdesign", "Exception caught while putting props into report component!"); + } + } +} + + +OXMLComponent::~OXMLComponent() +{ +} + + +} // namespace rptxml + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/reportdesign/source/filter/xml/xmlComponent.hxx b/reportdesign/source/filter/xml/xmlComponent.hxx new file mode 100644 index 000000000..d48d7dcef --- /dev/null +++ b/reportdesign/source/filter/xml/xmlComponent.hxx @@ -0,0 +1,48 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLCOMPONENT_HXX +#define INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLCOMPONENT_HXX + +#include +#include + +namespace rptxml +{ + class ORptFilter; + class OXMLComponent final : public SvXMLImportContext + { + css::uno::Reference< css::report::XReportComponent > m_xComponent; + + OXMLComponent(const OXMLComponent&); + OXMLComponent& operator =(const OXMLComponent&); + public: + + OXMLComponent( ORptFilter& rImport + ,const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList + ,const css::uno::Reference< css::report::XReportComponent >& _xComponent + ); + virtual ~OXMLComponent() override; + }; + +} // namespace rptxml + + +#endif // INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLCOMPONENT_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/reportdesign/source/filter/xml/xmlCondPrtExpr.cxx b/reportdesign/source/filter/xml/xmlCondPrtExpr.cxx new file mode 100644 index 000000000..369d1f564 --- /dev/null +++ b/reportdesign/source/filter/xml/xmlCondPrtExpr.cxx @@ -0,0 +1,83 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#include "xmlCondPrtExpr.hxx" +#include "xmlfilter.hxx" +#include +#include +#include +#include +#include + +namespace rptxml +{ + using namespace ::com::sun::star; + using namespace report; + using namespace uno; + using namespace xml::sax; + +OXMLCondPrtExpr::OXMLCondPrtExpr( ORptFilter& _rImport + ,const uno::Reference< xml::sax::XFastAttributeList > & _xAttrList + ,const Reference< XPropertySet > & _xComponent ) : + SvXMLImportContext( _rImport ) +,m_xComponent(_xComponent) +{ + OSL_ENSURE(m_xComponent.is(),"Component is NULL!"); + try + { + for (auto &aIter : sax_fastparser::castToFastAttributeList( _xAttrList )) + { + switch( aIter.getToken() ) + { + case XML_ELEMENT(REPORT, XML_FORMULA): + m_xComponent->setPropertyValue(PROPERTY_CONDITIONALPRINTEXPRESSION,uno::Any(ORptFilter::convertFormula(aIter.toString()))); + break; + default: + XMLOFF_WARN_UNKNOWN("reportdesign", aIter); + break; + } + + } + } + catch(const Exception&) + { + TOOLS_WARN_EXCEPTION( "reportdesign", "Exception caught while putting Function props!"); + } +} + + +OXMLCondPrtExpr::~OXMLCondPrtExpr() +{ +} + + +void OXMLCondPrtExpr::characters( const OUString& rChars ) +{ + m_aCharBuffer.append(rChars); +} + +void OXMLCondPrtExpr::endFastElement( sal_Int32 ) +{ + if (m_aCharBuffer.getLength()) + m_xComponent->setPropertyValue(PROPERTY_CONDITIONALPRINTEXPRESSION,Any(m_aCharBuffer.makeStringAndClear())); +} + +} // namespace rptxml + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/reportdesign/source/filter/xml/xmlCondPrtExpr.hxx b/reportdesign/source/filter/xml/xmlCondPrtExpr.hxx new file mode 100644 index 000000000..a69c5a493 --- /dev/null +++ b/reportdesign/source/filter/xml/xmlCondPrtExpr.hxx @@ -0,0 +1,52 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLCONDPRTEXPR_HXX +#define INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLCONDPRTEXPR_HXX + +#include +#include +#include + +namespace rptxml +{ + class ORptFilter; + class OXMLCondPrtExpr : public SvXMLImportContext + { + css::uno::Reference< css::beans::XPropertySet > m_xComponent; + OUStringBuffer m_aCharBuffer; + + OXMLCondPrtExpr(const OXMLCondPrtExpr&) = delete; + void operator =(const OXMLCondPrtExpr&) = delete; + public: + + OXMLCondPrtExpr( ORptFilter& _rImport + ,const css::uno::Reference< css::xml::sax::XFastAttributeList > & _xAttrList + ,const css::uno::Reference< css::beans::XPropertySet >& _xComponent); + virtual ~OXMLCondPrtExpr() override; + + virtual void SAL_CALL characters( const OUString& rChars ) override; + virtual void SAL_CALL endFastElement( sal_Int32 nElement ) override; + }; + +} // namespace rptxml + + +#endif // INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLCONDPRTEXPR_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/reportdesign/source/filter/xml/xmlControlProperty.cxx b/reportdesign/source/filter/xml/xmlControlProperty.cxx new file mode 100644 index 000000000..95415257a --- /dev/null +++ b/reportdesign/source/filter/xml/xmlControlProperty.cxx @@ -0,0 +1,332 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include + +#include +#include + +#include "xmlControlProperty.hxx" + +#include +#include +#include +#include "xmlfilter.hxx" +#include +#include +#include +#include "xmlEnums.hxx" +#include +#include +#include +#include +#include + +#define TYPE_DATE 1 +#define TYPE_TIME 2 +#define TYPE_DATETIME 3 + +namespace rptxml +{ + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::beans; + using namespace ::com::sun::star::xml::sax; + +OXMLControlProperty::OXMLControlProperty( ORptFilter& rImport + ,const Reference< XFastAttributeList > & _xAttrList + ,const Reference< XPropertySet >& _xControl + ,OXMLControlProperty* _pContainer) : + SvXMLImportContext( rImport ) + ,m_xControl(_xControl) + ,m_pContainer(_pContainer) + ,m_bIsList(false) +{ + m_aPropType = cppu::UnoType::get(); + + OSL_ENSURE(m_xControl.is(),"Control is NULL!"); + + for (auto &aIter : sax_fastparser::castToFastAttributeList( _xAttrList )) + { + switch( aIter.getToken() ) + { + case XML_ELEMENT(FORM, XML_LIST_PROPERTY): + m_bIsList = aIter.toView() == "true"; + break; + case XML_ELEMENT(OOO, XML_VALUE_TYPE): + { + // needs to be translated into a css::uno::Type + static std::map< OUString, css::uno::Type > const s_aTypeNameMap + { + { GetXMLToken( XML_BOOLEAN) , cppu::UnoType::get() }, + // Not a copy paste error, see comment xmloff/source/forms/propertyimport.cxx lines 244-248 + { GetXMLToken( XML_FLOAT) , cppu::UnoType::get() }, + { GetXMLToken( XML_DOUBLE) , cppu::UnoType::get() }, + { GetXMLToken( XML_STRING) , cppu::UnoType::get() }, + { GetXMLToken( XML_INT) , cppu::UnoType::get() }, + { GetXMLToken( XML_SHORT) , cppu::UnoType::get() }, + { GetXMLToken( XML_DATE) , cppu::UnoType::get() }, + { GetXMLToken( XML_TIME) , cppu::UnoType::get() }, + { GetXMLToken( XML_VOID) , cppu::UnoType::get() }, + }; + + const std::map< OUString, css::uno::Type >::const_iterator aTypePos = s_aTypeNameMap.find(aIter.toString()); + OSL_ENSURE(s_aTypeNameMap.end() != aTypePos, "OXMLControlProperty::OXMLControlProperty: invalid type!"); + if (s_aTypeNameMap.end() != aTypePos) + m_aPropType = aTypePos->second; + } + break; + case XML_ELEMENT(FORM, XML_PROPERTY_NAME): + m_aSetting.Name = aIter.toString(); + break; + default: + XMLOFF_WARN_UNKNOWN("reportdesign", aIter); + break; + } + } + +} + + +OXMLControlProperty::~OXMLControlProperty() +{ +} + +css::uno::Reference< css::xml::sax::XFastContextHandler > OXMLControlProperty::createFastChildContext( + sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) +{ + css::uno::Reference< css::xml::sax::XFastContextHandler > xContext; + ORptFilter& rImport = GetOwnImport(); + + switch( nElement ) + { + case XML_ELEMENT(FORM, XML_LIST_PROPERTY): + rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + xContext = new OXMLControlProperty( rImport,xAttrList,m_xControl); + break; + case XML_ELEMENT(OOO, XML_VALUE): + rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + xContext = new OXMLControlProperty( rImport,xAttrList,m_xControl,this ); + break; + default: + break; + } + + return xContext; +} + +void OXMLControlProperty::endFastElement(sal_Int32 ) +{ + if ( m_pContainer ) + m_pContainer->addValue(m_aCharBuffer.makeStringAndClear()); + if ( m_aSetting.Name.isEmpty() || !m_xControl.is() ) + return; + + if ( m_bIsList && !m_aSequence.hasElements() ) + m_aSetting.Value <<= m_aSequence; + try + { + m_xControl->setPropertyValue(m_aSetting.Name,m_aSetting.Value); + } + catch(const Exception&) + { + OSL_FAIL("Unknown property found!"); + } +} + +void OXMLControlProperty::characters( const OUString& rChars ) +{ + m_aCharBuffer.append(rChars); +} + +void OXMLControlProperty::addValue(const OUString& _sValue) +{ + Any aValue; + if( TypeClass_VOID != m_aPropType.getTypeClass() ) + aValue = convertString(m_aPropType, _sValue); + + if ( !m_bIsList ) + m_aSetting.Value = aValue; + else + { + sal_Int32 nPos = m_aSequence.getLength(); + m_aSequence.realloc(nPos+1); + m_aSequence.getArray()[nPos] = aValue; + } +} + +ORptFilter& OXMLControlProperty::GetOwnImport() +{ + return static_cast(GetImport()); +} + +Any OXMLControlProperty::convertString(const css::uno::Type& _rExpectedType, const OUString& _rReadCharacters) +{ + Any aReturn; + switch (_rExpectedType.getTypeClass()) + { + case TypeClass_BOOLEAN: // sal_Bool + { + bool bValue(false); + bool bSuccess = + ::sax::Converter::convertBool(bValue, _rReadCharacters); + OSL_ENSURE(bSuccess, + OStringBuffer("OXMLControlProperty::convertString: could not convert \"" + + OUStringToOString(_rReadCharacters, RTL_TEXTENCODING_ASCII_US) + + "\" into a boolean!").getStr()); + aReturn <<= bValue; + } + break; + case TypeClass_SHORT: // sal_Int16 + case TypeClass_LONG: // sal_Int32 + { // it's a real int32/16 property + sal_Int32 nValue(0); + bool bSuccess = + ::sax::Converter::convertNumber(nValue, _rReadCharacters); + OSL_ENSURE(bSuccess, + OStringBuffer("OXMLControlProperty::convertString: could not convert \"" + + OUStringToOString(_rReadCharacters, RTL_TEXTENCODING_ASCII_US) + + "\" into an integer!").getStr()); + if (TypeClass_SHORT == _rExpectedType.getTypeClass()) + aReturn <<= static_cast(nValue); + else + aReturn <<= nValue; + break; + } + case TypeClass_HYPER: + { + OSL_FAIL("OXMLControlProperty::convertString: 64-bit integers not implemented yet!"); + } + break; + case TypeClass_DOUBLE: + { + double nValue = 0.0; + bool bSuccess = + ::sax::Converter::convertDouble(nValue, _rReadCharacters); + OSL_ENSURE(bSuccess, + OStringBuffer("OXMLControlProperty::convertString: could not convert \"" + + OUStringToOString(_rReadCharacters, RTL_TEXTENCODING_ASCII_US) + + "\" into a double!").getStr()); + aReturn <<= nValue; + } + break; + case TypeClass_STRING: + aReturn <<= _rReadCharacters; + break; + case TypeClass_STRUCT: + { + // recognized structs: + static css::uno::Type s_aDateType = ::cppu::UnoType::get(); + static css::uno::Type s_aTimeType = ::cppu::UnoType::get(); + static css::uno::Type s_aDateTimeType = ::cppu::UnoType::get(); + sal_Int32 nType = 0; + if ( _rExpectedType.equals(s_aDateType) ) + nType = TYPE_DATE; + else if ( _rExpectedType.equals(s_aTimeType) ) + nType = TYPE_TIME; + else if ( _rExpectedType.equals(s_aDateTimeType) ) + nType = TYPE_DATETIME; + if ( nType ) + { + // first extract the double + double nValue = 0; + bool bSuccess = + ::sax::Converter::convertDouble(nValue, _rReadCharacters); + OSL_ENSURE(bSuccess, + OStringBuffer("OPropertyImport::convertString: could not convert \"" + + OUStringToOString(_rReadCharacters, RTL_TEXTENCODING_ASCII_US) + + "\" into a double!").getStr()); + + // then convert it into the target type + switch (nType) + { + case TYPE_DATE: + { + OSL_ENSURE(std::modf(nValue, &o3tl::temporary(double())) == 0, + "OPropertyImport::convertString: a Date value with a fractional part?"); + aReturn <<= implGetDate(nValue); + } + break; + case TYPE_TIME: + { + OSL_ENSURE((static_cast(nValue)) == 0, + "OPropertyImport::convertString: a tools::Time value with more than a fractional part?"); + aReturn <<= implGetTime(nValue); + } + break; + case TYPE_DATETIME: + { + css::util::Time aTime = implGetTime(nValue); + css::util::Date aDate = implGetDate(nValue); + + css::util::DateTime aDateTime; + aDateTime.NanoSeconds = aTime.NanoSeconds; + aDateTime.Seconds = aTime.Seconds; + aDateTime.Minutes = aTime.Minutes; + aDateTime.Hours = aTime.Hours; + aDateTime.Day = aDate.Day; + aDateTime.Month = aDate.Month; + aDateTime.Year = aDate.Year; + aReturn <<= aDateTime; + } + break; + default: + break; + } + } + else + OSL_FAIL("OPropertyImport::convertString: unsupported property type!"); + } + break; + default: + OSL_FAIL("OXMLControlProperty::convertString: invalid type class!"); + } + + return aReturn; +} + +css::util::Time OXMLControlProperty::implGetTime(double _nValue) +{ + css::util::Time aTime; + sal_uInt64 nIntValue = ::rtl::math::round(_nValue * 86400000000000.0); + aTime.NanoSeconds = static_cast( nIntValue % 1000000000 ); + nIntValue /= 1000000000; + aTime.Seconds = static_cast( nIntValue % 60 ); + nIntValue /= 60; + aTime.Minutes = static_cast( nIntValue % 60 ); + nIntValue /= 60; + OSL_ENSURE(nIntValue < 24, "OPropertyImport::implGetTime: more than a day?"); + aTime.Hours = static_cast< sal_uInt16 >( nIntValue ); + + return aTime; +} + + +css::util::Date OXMLControlProperty::implGetDate(double _nValue) +{ + Date aToolsDate(static_cast(_nValue)); + css::util::Date aDate; + ::utl::typeConvert(aToolsDate, aDate); + return aDate; +} + +} // namespace rptxml + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/reportdesign/source/filter/xml/xmlControlProperty.hxx b/reportdesign/source/filter/xml/xmlControlProperty.hxx new file mode 100644 index 000000000..019ec8063 --- /dev/null +++ b/reportdesign/source/filter/xml/xmlControlProperty.hxx @@ -0,0 +1,79 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLCONTROLPROPERTY_HXX +#define INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLCONTROLPROPERTY_HXX + +#include +#include +#include +#include +#include +#include +#include + +namespace rptxml +{ + class ORptFilter; + class OXMLControlProperty : public SvXMLImportContext + { + css::uno::Reference< css::beans::XPropertySet > m_xControl; + css::beans::PropertyValue m_aSetting; + css::uno::Sequence< css::uno::Any> m_aSequence; + OXMLControlProperty* m_pContainer; + css::uno::Type m_aPropType; // the type of the property the instance imports currently + bool m_bIsList; + OUStringBuffer m_aCharBuffer; + + ORptFilter& GetOwnImport(); + static css::uno::Any convertString(const css::uno::Type& _rExpectedType, const OUString& _rReadCharacters); + OXMLControlProperty(const OXMLControlProperty&) = delete; + void operator =(const OXMLControlProperty&) = delete; + public: + + OXMLControlProperty( ORptFilter& rImport + ,const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList + ,const css::uno::Reference< css::beans::XPropertySet >& _xControl + ,OXMLControlProperty* _pContainer = nullptr); + virtual ~OXMLControlProperty() override; + + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( + sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override; + + virtual void SAL_CALL endFastElement(sal_Int32 nElement) override; + + virtual void SAL_CALL characters( const OUString& rChars ) override; + + + /** adds value to property + @param _sValue + The value to add. + */ + void addValue(const OUString& _sValue); + + private: + static css::util::Time implGetTime(double _nValue); + static css::util::Date implGetDate(double _nValue); + }; + +} // namespace rptxml + + +#endif // INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLCONTROLPROPERTY_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/reportdesign/source/filter/xml/xmlEnums.hxx b/reportdesign/source/filter/xml/xmlEnums.hxx new file mode 100644 index 000000000..36b7379ba --- /dev/null +++ b/reportdesign/source/filter/xml/xmlEnums.hxx @@ -0,0 +1,62 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLENUMS_HXX +#define INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLENUMS_HXX + +#define PROGRESS_BAR_STEP 20 + +namespace rptxml +{ + enum XMLReportToken + { + XML_TOK_REPORT_HEADER, + XML_TOK_PAGE_HEADER , + XML_TOK_GROUP, + XML_TOK_DETAIL , + XML_TOK_PAGE_FOOTER , + XML_TOK_REPORT_FOOTER, + XML_TOK_HEADER_ON_NEW_PAGE , + XML_TOK_FOOTER_ON_NEW_PAGE , + XML_TOK_COMMAND_TYPE , + XML_TOK_COMMAND , + XML_TOK_FILTER , + XML_TOK_CAPTION , + XML_TOK_ESCAPE_PROCESSING , + XML_TOK_REPORT_FUNCTION , + XML_TOK_REPORT_ELEMENT , + XML_TOK_REPORT_MIMETYPE , + XML_TOK_REPORT_NAME , + XML_TOK_MASTER_DETAIL_FIELDS , + XML_TOK_SUB_FRAME , + XML_TOK_SUB_BODY , + }; + + enum XMLSubDocument + { + XML_TOK_MASTER_DETAIL_FIELD + ,XML_TOK_MASTER + ,XML_TOK_SUB_DETAIL + }; + + +} // namespace rptxml + +#endif // INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLENUMS_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/reportdesign/source/filter/xml/xmlExport.cxx b/reportdesign/source/filter/xml/xmlExport.cxx new file mode 100644 index 000000000..7472b549e --- /dev/null +++ b/reportdesign/source/filter/xml/xmlExport.cxx @@ -0,0 +1,1537 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include +#include "xmlExport.hxx" +#include "xmlAutoStyle.hxx" +#include +#include +#include +#include +#include +#include +#include "xmlHelper.hxx" +#include +#include "xmlPropertyHandler.hxx" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define DEFAULT_LINE_WIDTH 2 + +namespace rptxml +{ + using namespace xmloff; + using namespace comphelper; + using namespace ::com::sun::star; + using namespace ::com::sun::star::report; + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::util; + using namespace ::com::sun::star::xml; + + + /** Exports only settings + * \ingroup reportdesign_source_filter_xml + * + */ + extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* + reportdesign_ORptExportHelper_get_implementation( + css::uno::XComponentContext* context, css::uno::Sequence const&) + { + return cppu::acquire(new ORptExport(context, + "com.sun.star.comp.report.XMLSettingsExporter", + SvXMLExportFlags::SETTINGS )); + } + + /** Exports only content + * \ingroup reportdesign_source_filter_xml + * + */ + extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* + reportdesign_ORptContentExportHelper_get_implementation( + css::uno::XComponentContext* context, css::uno::Sequence const&) + { + return cppu::acquire(new ORptExport(context, + "com.sun.star.comp.report.XMLContentExporter", + SvXMLExportFlags::CONTENT )); + } + + /** Exports only styles + * \ingroup reportdesign_source_filter_xml + * + */ + extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* + reportdesign_ORptStylesExportHelper_get_implementation( + css::uno::XComponentContext* context, css::uno::Sequence const&) + { + return cppu::acquire(new ORptExport(context, + "com.sun.star.comp.report.XMLStylesExporter", + SvXMLExportFlags::STYLES | SvXMLExportFlags::MASTERSTYLES | SvXMLExportFlags::AUTOSTYLES | + SvXMLExportFlags::FONTDECLS|SvXMLExportFlags::OASIS )); + } + + /** Exports only meta data + * \ingroup reportdesign_source_filter_xml + * + */ + extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* + reportdesign_ORptMetaExportHelper_get_implementation( + css::uno::XComponentContext* context, css::uno::Sequence const&) + { + return cppu::acquire(new ORptExport(context, + "com.sun.star.comp.report.XMLMetaExporter", + SvXMLExportFlags::META )); + } + + /** Exports all + * \ingroup reportdesign_source_filter_xml + * + */ + extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* + reportdesign_ODBFullExportHelper_get_implementation( + css::uno::XComponentContext* context, css::uno::Sequence const&) + { + return cppu::acquire(new ORptExport(context, + "com.sun.star.comp.report.XMLFullExporter", + SvXMLExportFlags::ALL)); + } + + namespace { + + class OSpecialHandleXMLExportPropertyMapper : public SvXMLExportPropertyMapper + { + public: + explicit OSpecialHandleXMLExportPropertyMapper(const rtl::Reference< XMLPropertySetMapper >& rMapper) : SvXMLExportPropertyMapper(rMapper ) + { + } + /** this method is called for every item that has the + MID_FLAG_SPECIAL_ITEM_EXPORT flag set */ + virtual void handleSpecialItem( + SvXMLAttributeList& /*rAttrList*/, + const XMLPropertyState& /*rProperty*/, + const SvXMLUnitConverter& /*rUnitConverter*/, + const SvXMLNamespaceMap& /*rNamespaceMap*/, + const ::std::vector< XMLPropertyState >* /*pProperties*/ = nullptr, + sal_uInt32 /*nIdx*/ = 0 ) const override + { + // nothing to do here + } + }; + + } + +static void lcl_adjustColumnSpanOverRows(ORptExport::TSectionsGrid& _rGrid) +{ + for (auto& rEntry : _rGrid) + { + ORptExport::TGrid::iterator aRowIter = rEntry.second.begin(); + ORptExport::TGrid::const_iterator aRowEnd = rEntry.second.end(); + for (; aRowIter != aRowEnd; ++aRowIter) + { + if ( aRowIter->first ) + { + sal_Int32 nColIndex = 0; + for (const auto& rCell : aRowIter->second) + { + if ( rCell.nRowSpan > 1 ) + { + sal_Int32 nColSpan = rCell.nColSpan; + for (sal_Int32 i = 1; i < rCell.nRowSpan; ++i) + { + (aRowIter+i)->second[nColIndex].nColSpan = nColSpan; + } + } + ++nColIndex; + } + } + } + } +} + +ORptExport::ORptExport(const Reference< XComponentContext >& _rxContext, OUString const & implementationName, SvXMLExportFlags nExportFlag) +: SvXMLExport( _rxContext, implementationName, util::MeasureUnit::MM_100TH, XML_REPORT, SvXMLExportFlags::OASIS) +,m_bAllreadyFilled(false) +{ + setExportFlags( SvXMLExportFlags::OASIS | nExportFlag); + GetMM100UnitConverter().SetCoreMeasureUnit(css::util::MeasureUnit::MM_100TH); + GetMM100UnitConverter().SetXMLMeasureUnit(css::util::MeasureUnit::CM); + + // (getExportFlags() & EXPORT_CONTENT) != 0 ? : XML_N_OOO + GetNamespaceMap_().Add( GetXMLToken(XML_NP_OFFICE), GetXMLToken(XML_N_OFFICE ), XML_NAMESPACE_OFFICE ); + GetNamespaceMap_().Add( GetXMLToken(XML_NP_OOO), GetXMLToken(XML_N_OOO), XML_NAMESPACE_OOO ); + + GetNamespaceMap_().Add( GetXMLToken(XML_NP_RPT), GetXMLToken(XML_N_RPT), XML_NAMESPACE_REPORT ); + GetNamespaceMap_().Add( GetXMLToken(XML_NP_SVG), GetXMLToken(XML_N_SVG_COMPAT), XML_NAMESPACE_SVG ); + GetNamespaceMap_().Add( GetXMLToken(XML_NP_FORM), GetXMLToken(XML_N_FORM), XML_NAMESPACE_FORM ); + GetNamespaceMap_().Add( GetXMLToken(XML_NP_DRAW), GetXMLToken(XML_N_DRAW), XML_NAMESPACE_DRAW ); + GetNamespaceMap_().Add( GetXMLToken(XML_NP_TEXT), GetXMLToken(XML_N_TEXT), XML_NAMESPACE_TEXT ); + + + if( getExportFlags() & (SvXMLExportFlags::STYLES|SvXMLExportFlags::MASTERSTYLES|SvXMLExportFlags::AUTOSTYLES|SvXMLExportFlags::FONTDECLS) ) + GetNamespaceMap_().Add( GetXMLToken(XML_NP_FO), GetXMLToken(XML_N_FO_COMPAT), XML_NAMESPACE_FO ); + + if( getExportFlags() & (SvXMLExportFlags::META|SvXMLExportFlags::STYLES|SvXMLExportFlags::MASTERSTYLES|SvXMLExportFlags::AUTOSTYLES|SvXMLExportFlags::CONTENT|SvXMLExportFlags::SCRIPTS|SvXMLExportFlags::SETTINGS) ) + { + GetNamespaceMap_().Add( GetXMLToken(XML_NP_XLINK), GetXMLToken(XML_N_XLINK), XML_NAMESPACE_XLINK ); + } + if( getExportFlags() & SvXMLExportFlags::SETTINGS ) + { + GetNamespaceMap_().Add( GetXMLToken(XML_NP_CONFIG), GetXMLToken(XML_N_CONFIG), XML_NAMESPACE_CONFIG ); + } + + if( getExportFlags() & (SvXMLExportFlags::STYLES|SvXMLExportFlags::MASTERSTYLES|SvXMLExportFlags::AUTOSTYLES|SvXMLExportFlags::CONTENT|SvXMLExportFlags::FONTDECLS) ) + { + GetNamespaceMap_().Add( GetXMLToken(XML_NP_STYLE), GetXMLToken(XML_N_STYLE), XML_NAMESPACE_STYLE ); + } + // RDFa: needed for content and header/footer styles + if( getExportFlags() & (SvXMLExportFlags::STYLES|SvXMLExportFlags::AUTOSTYLES|SvXMLExportFlags::MASTERSTYLES|SvXMLExportFlags::CONTENT) ) + { + GetNamespaceMap_().Add( GetXMLToken(XML_NP_XHTML),GetXMLToken(XML_N_XHTML), XML_NAMESPACE_XHTML ); + // loext, needed for paragraphs inside shapes + if (getSaneDefaultVersion() & SvtSaveOptions::ODFSVER_EXTENDED) + { + GetNamespaceMap_().Add( + GetXMLToken(XML_NP_LO_EXT), GetXMLToken(XML_N_LO_EXT), + XML_NAMESPACE_LO_EXT); + } + } + // GRDDL: to convert RDFa and meta.xml to RDF + if( getExportFlags() & (SvXMLExportFlags::META|SvXMLExportFlags::STYLES|SvXMLExportFlags::AUTOSTYLES|SvXMLExportFlags::MASTERSTYLES|SvXMLExportFlags::CONTENT) ) + { + GetNamespaceMap_().Add( GetXMLToken(XML_NP_GRDDL),GetXMLToken(XML_N_GRDDL), XML_NAMESPACE_GRDDL ); + } + + GetNamespaceMap_().Add( GetXMLToken(XML_NP_TABLE), GetXMLToken(XML_N_TABLE), XML_NAMESPACE_TABLE ); + GetNamespaceMap_().Add( GetXMLToken(XML_NP_NUMBER), GetXMLToken(XML_N_NUMBER), XML_NAMESPACE_NUMBER ); + + m_sTableStyle = GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_TABLE, GetXMLToken(XML_STYLE_NAME) ); + m_sCellStyle = GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_REPORT, GetXMLToken(XML_STYLE_NAME) ); + + + m_xPropHdlFactory = new OXMLRptPropHdlFactory(); + rtl::Reference < XMLPropertyHandlerFactory> xFac = new ::xmloff::OControlPropertyHandlerFactory(); + rtl::Reference < XMLPropertySetMapper > xTableStylesPropertySetMapper1 = new XMLPropertySetMapper(OXMLHelper::GetTableStyleProps(),xFac, true); + rtl::Reference < XMLPropertySetMapper > xTableStylesPropertySetMapper2 = new XMLTextPropertySetMapper(TextPropMap::TABLE_DEFAULTS, true ); + xTableStylesPropertySetMapper1->AddMapperEntry(xTableStylesPropertySetMapper2); + + m_xTableStylesExportPropertySetMapper = new SvXMLExportPropertyMapper(xTableStylesPropertySetMapper1); + + m_xCellStylesPropertySetMapper = OXMLHelper::GetCellStylePropertyMap( false, true); + m_xCellStylesExportPropertySetMapper = new OSpecialHandleXMLExportPropertyMapper(m_xCellStylesPropertySetMapper); + m_xCellStylesExportPropertySetMapper->ChainExportMapper(XMLTextParagraphExport::CreateParaExtPropMapper(*this)); + + rtl::Reference < XMLPropertySetMapper > xColumnStylesPropertySetMapper = new XMLPropertySetMapper(OXMLHelper::GetColumnStyleProps(), m_xPropHdlFactory, true); + m_xColumnStylesExportPropertySetMapper = new OSpecialHandleXMLExportPropertyMapper(xColumnStylesPropertySetMapper); + + rtl::Reference < XMLPropertySetMapper > xRowStylesPropertySetMapper = new XMLPropertySetMapper(OXMLHelper::GetRowStyleProps(), m_xPropHdlFactory, true); + m_xRowStylesExportPropertySetMapper = new OSpecialHandleXMLExportPropertyMapper(xRowStylesPropertySetMapper); + + rtl::Reference < XMLPropertySetMapper > xPropMapper(new XMLTextPropertySetMapper( TextPropMap::PARA, true )); + m_xParaPropMapper = new OSpecialHandleXMLExportPropertyMapper( xPropMapper); + + const OUString& sFamily( GetXMLToken(XML_PARAGRAPH) ); + GetAutoStylePool()->AddFamily( XmlStyleFamily::TEXT_PARAGRAPH, sFamily, + m_xParaPropMapper, "P" ); + + GetAutoStylePool()->AddFamily(XmlStyleFamily::TABLE_CELL, XML_STYLE_FAMILY_TABLE_CELL_STYLES_NAME, + m_xCellStylesExportPropertySetMapper, XML_STYLE_FAMILY_TABLE_CELL_STYLES_PREFIX); + GetAutoStylePool()->AddFamily(XmlStyleFamily::TABLE_COLUMN, XML_STYLE_FAMILY_TABLE_COLUMN_STYLES_NAME, + m_xColumnStylesExportPropertySetMapper, XML_STYLE_FAMILY_TABLE_COLUMN_STYLES_PREFIX); + GetAutoStylePool()->AddFamily(XmlStyleFamily::TABLE_ROW, XML_STYLE_FAMILY_TABLE_ROW_STYLES_NAME, + m_xRowStylesExportPropertySetMapper, XML_STYLE_FAMILY_TABLE_ROW_STYLES_PREFIX); + GetAutoStylePool()->AddFamily(XmlStyleFamily::TABLE_TABLE, XML_STYLE_FAMILY_TABLE_TABLE_STYLES_NAME, + m_xTableStylesExportPropertySetMapper, XML_STYLE_FAMILY_TABLE_TABLE_STYLES_PREFIX); +} + +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* +reportdesign_ORptExport_get_implementation( + css::uno::XComponentContext* context, css::uno::Sequence const&) +{ + return cppu::acquire(new ORptExport(context, + "com.sun.star.comp.report.ExportFilter", + SvXMLExportFlags::CONTENT | SvXMLExportFlags::AUTOSTYLES | SvXMLExportFlags::FONTDECLS)); +} + + +void ORptExport::exportFunctions(const Reference& _xFunctions) +{ + const sal_Int32 nCount = _xFunctions->getCount(); + for (sal_Int32 i = 0; i< nCount; ++i) + { + uno::Reference< report::XFunction> xFunction(_xFunctions->getByIndex(i),uno::UNO_QUERY_THROW); + exportFunction(xFunction); + } +} + +void ORptExport::exportFunction(const uno::Reference< XFunction>& _xFunction) +{ + exportFormula(XML_FORMULA,_xFunction->getFormula()); + beans::Optional< OUString> aInitial = _xFunction->getInitialFormula(); + if ( aInitial.IsPresent && !aInitial.Value.isEmpty() ) + exportFormula(XML_INITIAL_FORMULA ,aInitial.Value ); + AddAttribute( XML_NAMESPACE_REPORT, XML_NAME , _xFunction->getName() ); + if ( _xFunction->getPreEvaluated() ) + AddAttribute( XML_NAMESPACE_REPORT, XML_PRE_EVALUATED , XML_TRUE ); + if ( _xFunction->getDeepTraversing() ) + AddAttribute( XML_NAMESPACE_REPORT, XML_DEEP_TRAVERSING , XML_TRUE ); + + SvXMLElementExport aFunction(*this,XML_NAMESPACE_REPORT, XML_FUNCTION, true, true); +} + +void ORptExport::exportMasterDetailFields(const Reference& _xReportComponent) +{ + const uno::Sequence< OUString> aMasterFields = _xReportComponent->getMasterFields(); + if ( !aMasterFields.hasElements() ) + return; + + SvXMLElementExport aElement(*this,XML_NAMESPACE_REPORT, XML_MASTER_DETAIL_FIELDS, true, true); + const uno::Sequence< OUString> aDetailFields = _xReportComponent->getDetailFields(); + + OSL_ENSURE(aDetailFields.getLength() == aMasterFields.getLength(),"not equal length for master and detail fields!"); + + const OUString* pDetailFieldsIter = aDetailFields.getConstArray(); + for(const OUString& rMasterField : aMasterFields) + { + AddAttribute( XML_NAMESPACE_REPORT, XML_MASTER , rMasterField ); + if ( !pDetailFieldsIter->isEmpty() ) + AddAttribute( XML_NAMESPACE_REPORT, XML_DETAIL , *pDetailFieldsIter ); + SvXMLElementExport aPair(*this,XML_NAMESPACE_REPORT, XML_MASTER_DETAIL_FIELD, true, true); + ++pDetailFieldsIter; + } +} + +void ORptExport::exportReport(const Reference& _xReportDefinition) +{ + if ( !_xReportDefinition.is() ) + return; + + exportFunctions(_xReportDefinition->getFunctions()); + exportGroupsExpressionAsFunction(_xReportDefinition->getGroups()); + + if ( _xReportDefinition->getReportHeaderOn() ) + { + SvXMLElementExport aGroupSection(*this,XML_NAMESPACE_REPORT, XML_REPORT_HEADER, true, true); + exportSection(_xReportDefinition->getReportHeader()); + } + if ( _xReportDefinition->getPageHeaderOn() ) + { + OUStringBuffer sValue; + sal_Int16 nRet = _xReportDefinition->getPageHeaderOption(); + const SvXMLEnumMapEntry* aXML_EnumMap = OXMLHelper::GetReportPrintOptions(); + if ( SvXMLUnitConverter::convertEnum( sValue, nRet,aXML_EnumMap ) ) + AddAttribute(XML_NAMESPACE_REPORT, XML_PAGE_PRINT_OPTION,sValue.makeStringAndClear()); + + SvXMLElementExport aGroupSection(*this,XML_NAMESPACE_REPORT, XML_PAGE_HEADER, true, true); + exportSection(_xReportDefinition->getPageHeader(),true); + } + + exportGroup(_xReportDefinition,0); + + if ( _xReportDefinition->getPageFooterOn() ) + { + OUStringBuffer sValue; + sal_Int16 nRet = _xReportDefinition->getPageFooterOption(); + const SvXMLEnumMapEntry* aXML_EnumMap = OXMLHelper::GetReportPrintOptions(); + if ( SvXMLUnitConverter::convertEnum( sValue, nRet,aXML_EnumMap ) ) + AddAttribute(XML_NAMESPACE_REPORT, XML_PAGE_PRINT_OPTION,sValue.makeStringAndClear()); + SvXMLElementExport aGroupSection(*this,XML_NAMESPACE_REPORT, XML_PAGE_FOOTER, true, true); + exportSection(_xReportDefinition->getPageFooter(),true); + } + if ( _xReportDefinition->getReportFooterOn() ) + { + SvXMLElementExport aGroupSection(*this,XML_NAMESPACE_REPORT, XML_REPORT_FOOTER, true, true); + exportSection(_xReportDefinition->getReportFooter()); + } +} + +void ORptExport::exportComponent(const Reference& _xReportComponent) +{ + OSL_ENSURE(_xReportComponent.is(),"No component interface!"); + if ( !_xReportComponent.is() ) + return; + + AddAttribute(XML_NAMESPACE_DRAW, XML_NAME,_xReportComponent->getName()); + + SvXMLElementExport aElem(*this,XML_NAMESPACE_REPORT, XML_REPORT_COMPONENT, false, false); +} + +void ORptExport::exportFormatConditions(const Reference& _xReportElement) +{ + OSL_ENSURE(_xReportElement.is(),"_xReportElement is NULL -> GPF"); + const sal_Int32 nCount = _xReportElement->getCount(); + try + { + for (sal_Int32 i = 0; i < nCount ; ++i) + { + uno::Reference< report::XFormatCondition > xCond(_xReportElement->getByIndex(i),uno::UNO_QUERY); + if ( !xCond->getEnabled() ) + AddAttribute(XML_NAMESPACE_REPORT, XML_ENABLED,XML_FALSE); + + AddAttribute(XML_NAMESPACE_REPORT, XML_FORMULA,xCond->getFormula()); + + exportStyleName(xCond.get(),GetAttrList(),m_sCellStyle); + SvXMLElementExport aElem(*this,XML_NAMESPACE_REPORT, XML_FORMAT_CONDITION, true, true); + } + } + catch(uno::Exception&) + { + OSL_FAIL("Can not access format condition!"); + } +} + +void ORptExport::exportReportElement(const Reference& _xReportElement) +{ + OSL_ENSURE(_xReportElement.is(),"_xReportElement is NULL -> GPF"); + if ( !_xReportElement->getPrintWhenGroupChange() ) + AddAttribute(XML_NAMESPACE_REPORT, XML_PRINT_WHEN_GROUP_CHANGE, XML_FALSE ); + + if ( !_xReportElement->getPrintRepeatedValues() ) + AddAttribute(XML_NAMESPACE_REPORT, XML_PRINT_REPEATED_VALUES,XML_FALSE); + + SvXMLElementExport aElem(*this,XML_NAMESPACE_REPORT, XML_REPORT_ELEMENT, true, true); + if ( _xReportElement->getCount() ) + { + exportFormatConditions(_xReportElement); + } + + OUString sExpr = _xReportElement->getConditionalPrintExpression(); + if ( !sExpr.isEmpty() ) + { + exportFormula(XML_FORMULA,sExpr); + SvXMLElementExport aPrintExpr(*this,XML_NAMESPACE_REPORT, XML_CONDITIONAL_PRINT_EXPRESSION, true, true); + } + + // only export when parent exists + uno::Reference< report::XSection> xParent(_xReportElement->getParent(),uno::UNO_QUERY); + if ( xParent.is() ) + exportComponent(_xReportElement); +} + +static void lcl_calculate(const ::std::vector& _aPosX,const ::std::vector& _aPosY,ORptExport::TGrid& _rColumns) +{ + sal_Int32 nCountX = _aPosX.size() - 1; + sal_Int32 nCountY = _aPosY.size() - 1; + for (sal_Int32 j = 0; j < nCountY; ++j) + { + sal_Int32 nHeight = _aPosY[j+1] - _aPosY[j]; + if ( nHeight ) + for (sal_Int32 i = 0; i < nCountX ; ++i) + { + _rColumns[j].second[i] = ORptExport::TCell(1,1); + _rColumns[j].second[i].bSet = true; + } + } +} + +void ORptExport::collectStyleNames(XmlStyleFamily _nFamily,const ::std::vector< sal_Int32>& _aSize, std::vector& _rStyleNames) +{ + ::std::vector::const_iterator aIter = _aSize.begin(); + ::std::vector::const_iterator aIter2 = aIter + 1; + ::std::vector::const_iterator aEnd = _aSize.end(); + for (;aIter2 != aEnd ; ++aIter,++aIter2) + { + ::std::vector< XMLPropertyState > aPropertyStates(1, 0); + sal_Int32 nValue = static_cast(*aIter2 - *aIter); + aPropertyStates[0].maValue <<= nValue; + _rStyleNames.push_back(GetAutoStylePool()->Add(_nFamily, std::move(aPropertyStates) )); + } +} + +void ORptExport::collectStyleNames(XmlStyleFamily _nFamily, const ::std::vector< sal_Int32>& _aSize, const ::std::vector< sal_Int32>& _aSizeAutoGrow, std::vector& _rStyleNames) +{ + ::std::vector::const_iterator aIter = _aSize.begin(); + ::std::vector::const_iterator aIter2 = aIter + 1; + ::std::vector::const_iterator aEnd = _aSize.end(); + for (;aIter2 != aEnd; ++aIter, ++aIter2) + { + ::std::vector< XMLPropertyState > aPropertyStates(1, 0); + sal_Int32 nValue = static_cast(*aIter2 - *aIter); + aPropertyStates[0].maValue <<= nValue; + // note: there cannot be 0-height rows, because a call to std::unique has removed them + // it cannot be predicted that the size of _aSizeAutoGrow has any relation to the size of + // _aSize, because of the same std::unique operation (and _aSizeAutoGrow wasn't even the same + // size before that), so the matching element in _aSizeAutoGrow has to be found by lookup. + ::std::vector::const_iterator aAutoGrow = ::std::find(_aSizeAutoGrow.begin(), _aSizeAutoGrow.end(), *aIter2); + bool bAutoGrow = aAutoGrow != _aSizeAutoGrow.end(); + // the mnIndex is into the array returned by OXMLHelper::GetRowStyleProps() + aPropertyStates[0].mnIndex = bAutoGrow ? 1 : 0; + _rStyleNames.push_back(GetAutoStylePool()->Add(_nFamily, std::move(aPropertyStates))); + } +} + +void ORptExport::exportSectionAutoStyle(const Reference& _xProp) +{ + OSL_ENSURE(_xProp != nullptr,"Section is NULL -> GPF"); + exportAutoStyle(_xProp); + + Reference xReport = _xProp->getReportDefinition(); + const awt::Size aSize = rptui::getStyleProperty(xReport,PROPERTY_PAPERSIZE); + const sal_Int32 nOffset = rptui::getStyleProperty(xReport,PROPERTY_LEFTMARGIN); + const sal_Int32 nCount = _xProp->getCount(); + + ::std::vector aColumnPos; + aColumnPos.reserve(2*(nCount + 1)); + aColumnPos.push_back(nOffset); + aColumnPos.push_back(aSize.Width - rptui::getStyleProperty(xReport,PROPERTY_RIGHTMARGIN)); + + ::std::vector aRowPos; + aRowPos.reserve(2*(nCount + 1)); + aRowPos.push_back(0); + aRowPos.push_back(_xProp->getHeight()); + + + ::std::vector aRowPosAutoGrow; + aRowPosAutoGrow.reserve(2 * (nCount + 1)); + + + sal_Int32 i; + for (i = 0 ; i< nCount ; ++i) + { + Reference xReportElement(_xProp->getByIndex(i),uno::UNO_QUERY); + uno::Reference< XShape> xShape(xReportElement,uno::UNO_QUERY); + if ( xShape.is() ) + continue; + OSL_ENSURE( xReportElement.is(),"NULL Element in Section!" ); + if ( !xReportElement.is() ) + continue; + sal_Int32 nX = xReportElement->getPositionX(); + aColumnPos.push_back(nX); + Reference xFixedLine(xReportElement,uno::UNO_QUERY); + if ( xFixedLine.is() && xFixedLine->getOrientation() == 1 ) // vertical + { + sal_Int32 nWidth = static_cast(xReportElement->getWidth()*0.5); + nX += nWidth; + aColumnPos.push_back(nX); + nX += xReportElement->getWidth() - nWidth; + } + else + nX += xReportElement->getWidth(); + aColumnPos.push_back(nX); // --nX why? + + sal_Int32 nY = xReportElement->getPositionY(); + aRowPos.push_back(nY); + nY += xReportElement->getHeight(); + aRowPos.push_back(nY); // --nY why? + bool bAutoGrow = xReportElement->getAutoGrow(); + if (bAutoGrow) + { + // the resulting table row ending at nY should auto-grow + aRowPosAutoGrow.push_back(nY); + } + } + + ::std::sort(aColumnPos.begin(),aColumnPos.end(),::std::less()); + aColumnPos.erase(::std::unique(aColumnPos.begin(),aColumnPos.end()),aColumnPos.end()); + + // note: the aRowPos contains top and bottom position of every report control; we now compute the + // top of every row in the resulting table, by sorting and eliminating unnecessary duplicate + // positions. (the same for the columns in the preceding lines.) + ::std::sort(aRowPos.begin(),aRowPos.end(),::std::less()); + aRowPos.erase(::std::unique(aRowPos.begin(),aRowPos.end()),aRowPos.end()); + + TSectionsGrid::iterator aInsert = m_aSectionsGrid.emplace( + _xProp.get(), + TGrid(aRowPos.size() - 1,TGrid::value_type(false,TRow(aColumnPos.size() - 1))) + ).first; + lcl_calculate(aColumnPos,aRowPos,aInsert->second); + + TGridStyleMap::iterator aPos = m_aColumnStyleNames.emplace(_xProp.get(),std::vector()).first; + collectStyleNames(XmlStyleFamily::TABLE_COLUMN,aColumnPos,aPos->second); + aPos = m_aRowStyleNames.emplace(_xProp.get(),std::vector()).first; + collectStyleNames(XmlStyleFamily::TABLE_ROW, aRowPos, aRowPosAutoGrow, aPos->second); + + sal_Int32 x1 = 0; + sal_Int32 y1 = 0; + sal_Int32 x2 = 0; + sal_Int32 y2 = 0; + sal_Int32 xi = 0; + sal_Int32 yi = 0; + bool isOverlap = false; + + for (i = 0 ; i< nCount ; ++i) + { + Reference xReportElement(_xProp->getByIndex(i),uno::UNO_QUERY); + uno::Reference< XShape> xShape(xReportElement,uno::UNO_QUERY); + if ( xShape.is() ) + continue; + sal_Int32 nPos = xReportElement->getPositionX(); + x1 = (::std::find(aColumnPos.begin(),aColumnPos.end(),nPos) - aColumnPos.begin()); + Reference xFixedLine(xReportElement,uno::UNO_QUERY); + if ( xFixedLine.is() && xFixedLine->getOrientation() == 1 ) // vertical + nPos += static_cast(xReportElement->getWidth()*0.5); + else + nPos += xReportElement->getWidth(); // -1 why + x2 = (::std::find(aColumnPos.begin(),aColumnPos.end(),nPos) - aColumnPos.begin()); + + nPos = xReportElement->getPositionY(); + y1 = (::std::find(aRowPos.begin(),aRowPos.end(),nPos) - aRowPos.begin()); + nPos += xReportElement->getHeight(); // -1 why? + y2 = (::std::find(aRowPos.begin(),aRowPos.end(),nPos) - aRowPos.begin()); + + isOverlap = false; + yi = y1; + while(yi < y2 && !isOverlap) // find overlapping controls + { + xi = x1; + while(xi < x2 && !isOverlap) + { + if ( aInsert->second[yi].second[xi].xElement.is() ) + { + isOverlap = true; + } + ++xi; + } + ++yi; + } + + if (!isOverlap) + { + yi = y1; + while(yi < y2) + { + xi = x1; + while(xi < x2) + { + aInsert->second[yi].second[xi] = TCell(); + ++xi; + } + aInsert->second[yi].first = true; + ++yi; + } + + if (x2 - x1 != 0 && y2 - y1 != 0) + { + sal_Int32 nColSpan = x2 - x1; + sal_Int32 nRowSpan = y2 - y1; + aInsert->second[y1].second[x1] = + TCell( + nColSpan, + nRowSpan, + xReportElement + ); + } + } + } + + lcl_adjustColumnSpanOverRows(m_aSectionsGrid); + exportReportComponentAutoStyles(_xProp); +} + +void ORptExport::exportReportComponentAutoStyles(const Reference& _xProp) +{ + const sal_Int32 nCount = _xProp->getCount(); + for (sal_Int32 i = 0 ; i< nCount ; ++i) + { + const Reference xReportElement(_xProp->getByIndex(i),uno::UNO_QUERY); + const Reference< report::XShape > xShape(xReportElement,uno::UNO_QUERY); + if ( xShape.is() ) + { + rtl::Reference< XMLShapeExport > xShapeExport = GetShapeExport(); + xShapeExport->seekShapes(_xProp); + SolarMutexGuard aGuard; + xShapeExport->collectShapeAutoStyles(xShape); + } + else + { + exportAutoStyle(xReportElement.get()); + + Reference xFormattedField(xReportElement,uno::UNO_QUERY); + if ( xFormattedField.is() ) + { + try + { + const sal_Int32 nFormatCount = xFormattedField->getCount(); + for (sal_Int32 j = 0; j < nFormatCount ; ++j) + { + uno::Reference< report::XFormatCondition > xCond(xFormattedField->getByIndex(j),uno::UNO_QUERY); + exportAutoStyle(xCond.get(),xFormattedField); + } + } + catch(uno::Exception&) + { + OSL_FAIL("Can not access format condition!"); + } + } + } + } +} + +void ORptExport::exportSection(const Reference& _xSection,bool bHeader) +{ + OSL_ENSURE(_xSection.is(),"Section is NULL -> GPF"); + AddAttribute(XML_NAMESPACE_TABLE, XML_NAME,_xSection->getName()); + + if ( !_xSection->getVisible() ) + AddAttribute(XML_NAMESPACE_REPORT, XML_VISIBLE,XML_FALSE); + + if ( !bHeader ) + { + OUStringBuffer sValue; + sal_Int16 nRet = _xSection->getForceNewPage(); + const SvXMLEnumMapEntry* aXML_EnumMap = OXMLHelper::GetForceNewPageOptions(); + if ( SvXMLUnitConverter::convertEnum( sValue, nRet,aXML_EnumMap ) ) + AddAttribute(XML_NAMESPACE_REPORT, XML_FORCE_NEW_PAGE,sValue.makeStringAndClear()); + + nRet = _xSection->getNewRowOrCol(); + if ( SvXMLUnitConverter::convertEnum( sValue, nRet,aXML_EnumMap ) ) + AddAttribute(XML_NAMESPACE_REPORT, XML_FORCE_NEW_COLUMN,sValue.makeStringAndClear()); + if ( _xSection->getKeepTogether() ) + AddAttribute(XML_NAMESPACE_REPORT, XML_KEEP_TOGETHER, XML_TRUE ); + } + + exportStyleName(_xSection.get(),GetAttrList(),m_sTableStyle); + + /// TODO export as table layout + SvXMLElementExport aComponents(*this,XML_NAMESPACE_TABLE, XML_TABLE, true, true); + + OUString sExpr = _xSection->getConditionalPrintExpression(); + if ( !sExpr.isEmpty() ) + { + exportFormula(XML_FORMULA,sExpr); + SvXMLElementExport aPrintExpr(*this,XML_NAMESPACE_REPORT, XML_CONDITIONAL_PRINT_EXPRESSION, true, false); + } + + exportContainer(_xSection); +} + +void ORptExport::exportTableColumns(const Reference< XSection>& _xSection) +{ + SvXMLElementExport aColumns(*this,XML_NAMESPACE_TABLE, XML_TABLE_COLUMNS, true, true); + TGridStyleMap::const_iterator aColFind = m_aColumnStyleNames.find(_xSection); + OSL_ENSURE(aColFind != m_aColumnStyleNames.end(),"ORptExport::exportTableColumns: Section not found in m_aColumnStyleNames!"); + if ( aColFind == m_aColumnStyleNames.end() ) + return; + + for (auto& aCol : aColFind->second) + { + AddAttribute(m_sTableStyle, aCol); + SvXMLElementExport aColumn(*this,XML_NAMESPACE_TABLE, XML_TABLE_COLUMN, true, true); + } +} + +void ORptExport::exportContainer(const Reference< XSection>& _xSection) +{ + OSL_ENSURE(_xSection.is(),"Section is NULL -> GPF"); + + exportTableColumns(_xSection); + + TSectionsGrid::const_iterator aFind = m_aSectionsGrid.find(_xSection); + OSL_ENSURE(aFind != m_aSectionsGrid.end(),"ORptExport::exportContainer: Section not found in grid!"); + if ( aFind == m_aSectionsGrid.end() ) + return; + TGrid::const_iterator aRowIter = aFind->second.begin(); + TGrid::const_iterator aRowEnd = aFind->second.end(); + + TGridStyleMap::const_iterator aRowFind = m_aRowStyleNames.find(_xSection); + auto aHeightIter = aRowFind->second.cbegin(); + OSL_ENSURE(aRowFind->second.size() == aFind->second.size(),"Different count for rows"); + + bool bShapeHandled = false; + ::std::map aRowSpan; + for (sal_Int32 j = 0; aRowIter != aRowEnd; ++aRowIter,++j,++aHeightIter) + { + AddAttribute( m_sTableStyle,*aHeightIter ); + SvXMLElementExport aRow(*this,XML_NAMESPACE_TABLE, XML_TABLE_ROW, true, true); + if ( aRowIter->first ) + { + ::std::vector< TCell >::const_iterator aColIter = aRowIter->second.begin(); + ::std::vector< TCell >::const_iterator aColEnd = aRowIter->second.end(); + sal_Int32 nEmptyCellColSpan = 0; + for (; aColIter != aColEnd; ++aColIter) + { + bool bCoveredCell = false; + sal_Int32 nColSpan = 0; + sal_Int32 nColIndex = aColIter - aRowIter->second.begin(); + ::std::map::iterator aRowSpanFind = aRowSpan.find(nColIndex); + if ( aRowSpanFind != aRowSpan.end() ) + { + nColSpan = 1; + if ( !--(aRowSpanFind->second) ) + aRowSpan.erase(aRowSpanFind); + + if ( aColIter->nColSpan > 1 ) + nColSpan += aColIter->nColSpan - 1; + + bCoveredCell = true; + aColIter = aColIter + (aColIter->nColSpan - 1); + } + else if ( aColIter->bSet ) + { + if ( nEmptyCellColSpan > 0 ) + { + AddAttribute( XML_NAMESPACE_TABLE,XML_NUMBER_COLUMNS_SPANNED, OUString::number(nEmptyCellColSpan) ); + bCoveredCell = true; + nColSpan = nEmptyCellColSpan - 1; + nEmptyCellColSpan = 0; + } + sal_Int32 nSpan = aColIter->nColSpan; + if ( nSpan > 1 ) + { + AddAttribute( XML_NAMESPACE_TABLE,XML_NUMBER_COLUMNS_SPANNED, OUString::number(nSpan) ); + nColSpan = nSpan - 1; + bCoveredCell = true; + } + nSpan = aColIter->nRowSpan; + if ( nSpan > 1 ) + { + AddAttribute( XML_NAMESPACE_TABLE,XML_NUMBER_ROWS_SPANNED, OUString::number(nSpan) ); + aRowSpan[nColIndex] = nSpan - 1; + } + if ( aColIter->xElement.is() ) + exportStyleName(aColIter->xElement.get(),GetAttrList(),m_sTableStyle); + + // start + Reference xFormattedField(aColIter->xElement,uno::UNO_QUERY); + if ( xFormattedField.is() ) + { + sal_Int32 nFormatKey = xFormattedField->getFormatKey(); + XMLNumberFormatAttributesExportHelper aHelper(GetNumberFormatsSupplier(),*this); + bool bIsStandard = false; + sal_Int16 nCellType = aHelper.GetCellType(nFormatKey,bIsStandard); + // "Standard" means "no format set, value could be anything", + // so don't set a format attribute in this case. + // P.S.: "Standard" is called "General" in some languages + if (!bIsStandard) + { + if ( nCellType == util::NumberFormat::TEXT ) + aHelper.SetNumberFormatAttributes("", u""); + else + aHelper.SetNumberFormatAttributes(nFormatKey, 0.0, false); + } + } + SvXMLElementExport aCell(*this,XML_NAMESPACE_TABLE, XML_TABLE_CELL, true, false); + + if ( aColIter->xElement.is() ) + { + // start + SvXMLElementExport aParagraphContent(*this,XML_NAMESPACE_TEXT, XML_P, true, false); + Reference xElement(aColIter->xElement,uno::UNO_QUERY); + + if ( !bShapeHandled ) + { + bShapeHandled = true; + exportShapes(_xSection,false); + } + uno::Reference< XShape > xShape(xElement,uno::UNO_QUERY); + uno::Reference< XFixedLine > xFixedLine(xElement,uno::UNO_QUERY); + if ( !xShape.is() && !xFixedLine.is() ) + { + Reference xReportElement(xElement,uno::UNO_QUERY); + Reference xReportDefinition(xElement,uno::UNO_QUERY); + Reference< XImageControl > xImage(xElement,uno::UNO_QUERY); + Reference xSection(xElement,uno::UNO_QUERY); + + XMLTokenEnum eToken = XML_SECTION; + bool bExportData = false; + if ( xElement->supportsService(SERVICE_FIXEDTEXT) ) + { + eToken = XML_FIXED_CONTENT; + } + else if ( xElement->supportsService(SERVICE_FORMATTEDFIELD) ) + { + eToken = XML_FORMATTED_TEXT; + bExportData = true; + } + else if ( xElement->supportsService(SERVICE_IMAGECONTROL) ) + { + eToken = XML_IMAGE; + OUString sTargetLocation = xImage->getImageURL(); + if ( !sTargetLocation.isEmpty() ) + { + sTargetLocation = GetRelativeReference(sTargetLocation); + AddAttribute(XML_NAMESPACE_FORM, XML_IMAGE_DATA,sTargetLocation); + } + bExportData = true; + OUStringBuffer sValue; + const SvXMLEnumMapEntry* aXML_ImageScaleEnumMap = OXMLHelper::GetImageScaleOptions(); + if ( SvXMLUnitConverter::convertEnum( sValue, xImage->getScaleMode(),aXML_ImageScaleEnumMap ) ) + AddAttribute(XML_NAMESPACE_REPORT, XML_SCALE, sValue.makeStringAndClear() ); + } + else if ( xReportDefinition.is() ) + { + eToken = XML_SUB_DOCUMENT; + } + + if ( bExportData ) + { + const bool bPageSet = exportFormula(XML_FORMULA,xReportElement->getDataField()); + if ( bPageSet ) + eToken = XML_FIXED_CONTENT; + else if ( eToken == XML_IMAGE ) + AddAttribute(XML_NAMESPACE_REPORT, XML_PRESERVE_IRI, xImage->getPreserveIRI() ? XML_TRUE : XML_FALSE ); + } + + { + // start + SvXMLElementExport aComponents(*this,XML_NAMESPACE_REPORT, eToken, false, false); + if ( eToken == XML_FIXED_CONTENT ) + exportParagraph(xReportElement); + if ( xReportElement.is() ) + exportReportElement(xReportElement); + + if (eToken == XML_SUB_DOCUMENT && xReportDefinition.is()) + { + SvXMLElementExport aOfficeElement( *this, XML_NAMESPACE_OFFICE, XML_BODY, true, true ); + SvXMLElementExport aElem( *this, true, + XML_NAMESPACE_OFFICE, XML_REPORT, + true, true ); + + exportReportAttributes(xReportDefinition); + exportReport(xReportDefinition); + } + else if ( xSection.is() ) + exportSection(xSection); + } + } + } + else if ( !bShapeHandled ) + { + bShapeHandled = true; + exportShapes(_xSection); + } + aColIter = aColIter + (aColIter->nColSpan - 1); + } + else + ++nEmptyCellColSpan; + if ( bCoveredCell ) + { + for (sal_Int32 k = 0; k < nColSpan; ++k) + { + SvXMLElementExport aCell(*this,XML_NAMESPACE_TABLE, XML_COVERED_TABLE_CELL, true, true); + } + + } + } + if ( nEmptyCellColSpan ) + { + { + AddAttribute( XML_NAMESPACE_TABLE,XML_NUMBER_COLUMNS_SPANNED, OUString::number(nEmptyCellColSpan) ); + SvXMLElementExport aCell(*this,XML_NAMESPACE_TABLE, XML_TABLE_CELL, true, true); + if ( !bShapeHandled ) + { + bShapeHandled = true; + exportShapes(_xSection); + } + } + for (sal_Int32 k = 0; k < nEmptyCellColSpan; ++k) + { + SvXMLElementExport aCoveredCell(*this,XML_NAMESPACE_TABLE, XML_COVERED_TABLE_CELL, true, true); + } + } + } + else + { // empty rows + sal_Int32 nEmptyCellColSpan = aRowIter->second.size(); + if ( nEmptyCellColSpan ) + { + { + AddAttribute( XML_NAMESPACE_TABLE,XML_NUMBER_COLUMNS_SPANNED, OUString::number(nEmptyCellColSpan) ); + SvXMLElementExport aCell(*this,XML_NAMESPACE_TABLE, XML_TABLE_CELL, true, true); + if ( !bShapeHandled ) + { + bShapeHandled = true; + exportShapes(_xSection); + } + } + for (sal_Int32 k = 1; k < nEmptyCellColSpan; ++k) + { + SvXMLElementExport aCoveredCell(*this,XML_NAMESPACE_TABLE, XML_COVERED_TABLE_CELL, true, true); + } + } + } + } +} + +OUString ORptExport::convertFormula(const OUString& _sFormula) +{ + OUString sFormula = _sFormula; + if ( _sFormula == "rpt:" ) + sFormula.clear(); + return sFormula; +} + +bool ORptExport::exportFormula(enum ::xmloff::token::XMLTokenEnum eName,const OUString& _sFormula) +{ + const OUString sFieldData = convertFormula(_sFormula); + sal_Int32 nPageNumberIndex = sFieldData.indexOf("PageNumber()"); + sal_Int32 nPageCountIndex = sFieldData.indexOf("PageCount()"); + bool bRet = nPageNumberIndex != -1 || nPageCountIndex != -1; + if ( !bRet ) + AddAttribute(XML_NAMESPACE_REPORT, eName,sFieldData); + + return bRet; +} + +void ORptExport::exportStyleName(XPropertySet* _xProp,SvXMLAttributeList& _rAtt,const OUString& _sName) +{ + Reference xFind(_xProp); + TPropertyStyleMap::const_iterator aFind = m_aAutoStyleNames.find(xFind); + if ( aFind != m_aAutoStyleNames.end() ) + { + _rAtt.AddAttribute( _sName, + aFind->second ); + m_aAutoStyleNames.erase(aFind); + } +} + +void ORptExport::exportGroup(const Reference& _xReportDefinition,sal_Int32 _nPos,bool _bExportAutoStyle) +{ + if ( !_xReportDefinition.is() ) + return; + + Reference< XGroups > xGroups = _xReportDefinition->getGroups(); + if ( !xGroups.is() ) + return; + + sal_Int32 nCount = xGroups->getCount(); + if ( _nPos >= 0 && _nPos < nCount ) + { + Reference xGroup(xGroups->getByIndex(_nPos),uno::UNO_QUERY); + OSL_ENSURE(xGroup.is(),"No Group prepare for GPF"); + if ( _bExportAutoStyle ) + { + if ( xGroup->getHeaderOn() ) + exportSectionAutoStyle(xGroup->getHeader()); + exportGroup(_xReportDefinition,_nPos+1,_bExportAutoStyle); + if ( xGroup->getFooterOn() ) + exportSectionAutoStyle(xGroup->getFooter()); + } + else + { + if ( xGroup->getSortAscending() ) + AddAttribute(XML_NAMESPACE_REPORT, XML_SORT_ASCENDING, XML_TRUE ); + + if ( xGroup->getStartNewColumn() ) + AddAttribute(XML_NAMESPACE_REPORT, XML_START_NEW_COLUMN, XML_TRUE); + if ( xGroup->getResetPageNumber() ) + AddAttribute(XML_NAMESPACE_REPORT, XML_RESET_PAGE_NUMBER, XML_TRUE ); + + const OUString sField = xGroup->getExpression(); + OUString sExpression = sField; + if ( !sExpression.isEmpty() ) + { + sal_Int32 nIndex = sExpression.indexOf('"'); + while ( nIndex > -1 ) + { + sExpression = sExpression.replaceAt(nIndex, 1, u"\"\""); + nIndex = sExpression.indexOf('"',nIndex+2); + } + + TGroupFunctionMap::const_iterator aGroupFind = m_aGroupFunctionMap.find(xGroup); + if ( aGroupFind != m_aGroupFunctionMap.end() ) + sExpression = aGroupFind->second->getName(); + sExpression = "rpt:HASCHANGED(\"" + sExpression + "\")"; + } + AddAttribute(XML_NAMESPACE_REPORT, XML_SORT_EXPRESSION, sField); + AddAttribute(XML_NAMESPACE_REPORT, XML_GROUP_EXPRESSION,sExpression); + sal_Int16 nRet = xGroup->getKeepTogether(); + OUStringBuffer sValue; + const SvXMLEnumMapEntry* aXML_KeepTogetherEnumMap = OXMLHelper::GetKeepTogetherOptions(); + if ( SvXMLUnitConverter::convertEnum( sValue, nRet, aXML_KeepTogetherEnumMap ) ) + AddAttribute(XML_NAMESPACE_REPORT, XML_KEEP_TOGETHER,sValue.makeStringAndClear()); + + SvXMLElementExport aGroup(*this,XML_NAMESPACE_REPORT, XML_GROUP, true, true); + exportFunctions(xGroup->getFunctions()); + if ( xGroup->getHeaderOn() ) + { + Reference xSection = xGroup->getHeader(); + if ( xSection->getRepeatSection() ) + AddAttribute(XML_NAMESPACE_REPORT, XML_REPEAT_SECTION,XML_TRUE ); + SvXMLElementExport aGroupSection(*this,XML_NAMESPACE_REPORT, XML_GROUP_HEADER, true, true); + exportSection(xSection); + } + exportGroup(_xReportDefinition,_nPos+1,_bExportAutoStyle); + if ( xGroup->getFooterOn() ) + { + Reference xSection = xGroup->getFooter(); + if ( xSection->getRepeatSection() ) + AddAttribute(XML_NAMESPACE_REPORT, XML_REPEAT_SECTION,XML_TRUE ); + SvXMLElementExport aGroupSection(*this,XML_NAMESPACE_REPORT, XML_GROUP_FOOTER, true, true); + exportSection(xSection); + } + } + } + else if ( _bExportAutoStyle ) + { + exportSectionAutoStyle(_xReportDefinition->getDetail()); + } + else + { + SvXMLElementExport aGroupSection(*this,XML_NAMESPACE_REPORT, XML_DETAIL, true, true); + exportSection(_xReportDefinition->getDetail()); + } +} + +void ORptExport::exportAutoStyle(XPropertySet* _xProp,const Reference& _xParentFormattedField) +{ + const uno::Reference xFormat(_xProp,uno::UNO_QUERY); + if ( xFormat.is() ) + { + try + { + const awt::FontDescriptor aFont = xFormat->getFontDescriptor(); + OSL_ENSURE(!aFont.Name.isEmpty(),"No Font Name !"); + GetFontAutoStylePool()->Add(aFont.Name,aFont.StyleName,static_cast(aFont.Family), + static_cast(aFont.Pitch),aFont.CharSet ); + } + catch(beans::UnknownPropertyException&) + { + // not interested in + } + } + const uno::Reference< report::XShape> xShape(_xProp,uno::UNO_QUERY); + if ( xShape.is() ) + { + ::std::vector aPropertyStates(m_xParaPropMapper->Filter(*this, _xProp)); + if ( !aPropertyStates.empty() ) + m_aAutoStyleNames.emplace( _xProp,GetAutoStylePool()->Add( XmlStyleFamily::TEXT_PARAGRAPH, std::move(aPropertyStates) )); + } + ::std::vector aPropertyStates(m_xCellStylesExportPropertySetMapper->Filter(*this, _xProp)); + Reference xFixedLine(_xProp,uno::UNO_QUERY); + if ( xFixedLine.is() ) + { + uno::Reference xBorderProp = OXMLHelper::createBorderPropertySet(); + table::BorderLine2 aValue; + aValue.Color = sal_uInt32(COL_BLACK); + aValue.InnerLineWidth = aValue.LineDistance = 0; + aValue.OuterLineWidth = DEFAULT_LINE_WIDTH; + aValue.LineStyle = table::BorderLineStyle::SOLID; + aValue.LineWidth = DEFAULT_LINE_WIDTH; + + awt::Point aPos = xFixedLine->getPosition(); + awt::Size aSize = xFixedLine->getSize(); + sal_Int32 nSectionHeight = xFixedLine->getSection()->getHeight(); + + OUString sBorderProp; + ::std::vector< OUString> aProps; + if ( xFixedLine->getOrientation() == 1 ) // vertical + { + // check if border should be left + if ( !aPos.X ) + { + sBorderProp = PROPERTY_BORDERLEFT; + aProps.emplace_back(PROPERTY_BORDERRIGHT); + } + else + { + sBorderProp = PROPERTY_BORDERRIGHT; + aProps.emplace_back(PROPERTY_BORDERLEFT); + } + aProps.emplace_back(PROPERTY_BORDERTOP); + aProps.emplace_back(PROPERTY_BORDERBOTTOM); + } + else // horizontal + { + // check if border should be bottom + if ( (aPos.Y + aSize.Height) == nSectionHeight ) + { + sBorderProp = PROPERTY_BORDERBOTTOM; + aProps.emplace_back(PROPERTY_BORDERTOP); + } + else + { + sBorderProp = PROPERTY_BORDERTOP; + aProps.emplace_back(PROPERTY_BORDERBOTTOM); + } + aProps.emplace_back(PROPERTY_BORDERRIGHT); + aProps.emplace_back(PROPERTY_BORDERLEFT); + } + + xBorderProp->setPropertyValue(sBorderProp,uno::Any(aValue)); + + aValue.Color = aValue.OuterLineWidth = aValue.LineWidth = 0; + aValue.LineStyle = table::BorderLineStyle::NONE; + uno::Any aEmpty; + aEmpty <<= aValue; + for (auto const& it : aProps) + { + xBorderProp->setPropertyValue(it, aEmpty); + } + + ::std::vector aBorderStates(m_xCellStylesExportPropertySetMapper->Filter(*this, xBorderProp)); + aPropertyStates.insert( aPropertyStates.end(), aBorderStates.begin(), aBorderStates.end() ); + } + else + { + const Reference xFormattedField(_xProp,uno::UNO_QUERY); + if ( (_xParentFormattedField.is() || xFormattedField.is()) && !aPropertyStates.empty() ) + { + sal_Int32 nNumberFormat = 0; + if ( _xParentFormattedField.is() ) + nNumberFormat = _xParentFormattedField->getFormatKey(); + else + nNumberFormat = xFormattedField->getFormatKey(); + { + sal_Int32 nStyleMapIndex = m_xCellStylesExportPropertySetMapper->getPropertySetMapper()->FindEntryIndex( CTF_RPT_NUMBERFORMAT ); + addDataStyle(nNumberFormat); + XMLPropertyState aNumberStyleState( nStyleMapIndex, uno::Any( getDataStyleName(nNumberFormat) ) ); + auto const iter(::std::find_if( + aPropertyStates.begin(), aPropertyStates.end(), + [nStyleMapIndex] (XMLPropertyState const& rItem) + { return rItem.mnIndex == nStyleMapIndex; } )); + if (iter == aPropertyStates.end()) + { + aPropertyStates.push_back( aNumberStyleState ); + } + else + { // there is already a property but it has the wrong type + // (integer not string); TODO: can we prevent it + // getting added earlier? + (*iter) = aNumberStyleState; + } + } + } + } + + if ( !aPropertyStates.empty() ) + m_aAutoStyleNames.emplace( _xProp,GetAutoStylePool()->Add( XmlStyleFamily::TABLE_CELL, std::move(aPropertyStates) )); +} + +void ORptExport::exportAutoStyle(const Reference& _xProp) +{ + ::std::vector aPropertyStates(m_xTableStylesExportPropertySetMapper->Filter(*this, _xProp)); + if ( !aPropertyStates.empty() ) + m_aAutoStyleNames.emplace( _xProp.get(),GetAutoStylePool()->Add( XmlStyleFamily::TABLE_TABLE, std::move(aPropertyStates) )); +} + +void ORptExport::SetBodyAttributes() +{ + Reference xProp(getReportDefinition()); + exportReportAttributes(xProp); +} + +void ORptExport::exportReportAttributes(const Reference& _xReport) +{ + if ( !_xReport.is() ) + return; + + OUStringBuffer sValue; + const SvXMLEnumMapEntry* aXML_CommandTypeEnumMap = OXMLHelper::GetCommandTypeOptions(); + if ( SvXMLUnitConverter::convertEnum( sValue, _xReport->getCommandType(), aXML_CommandTypeEnumMap ) ) + AddAttribute(XML_NAMESPACE_REPORT, XML_COMMAND_TYPE,sValue.makeStringAndClear()); + + OUString sCommand = _xReport->getCommand(); + if ( !sCommand.isEmpty() ) + AddAttribute(XML_NAMESPACE_REPORT, XML_COMMAND, sCommand); + + OUString sFilter( _xReport->getFilter() ); + if ( !sFilter.isEmpty() ) + AddAttribute( XML_NAMESPACE_REPORT, XML_FILTER, sFilter ); + + AddAttribute(XML_NAMESPACE_OFFICE, XML_MIMETYPE,_xReport->getMimeType()); + + bool bEscapeProcessing( _xReport->getEscapeProcessing() ); + if ( !bEscapeProcessing ) + AddAttribute( XML_NAMESPACE_REPORT, XML_ESCAPE_PROCESSING, ::xmloff::token::GetXMLToken( XML_FALSE ) ); + + OUString sName = _xReport->getCaption(); + if ( !sName.isEmpty() ) + AddAttribute(XML_NAMESPACE_OFFICE, XML_CAPTION,sName); + sName = _xReport->getName(); + if ( !sName.isEmpty() ) + AddAttribute(XML_NAMESPACE_DRAW, XML_NAME,sName); +} + +void ORptExport::ExportContent_() +{ + exportReport(getReportDefinition()); +} + +void ORptExport::ExportMasterStyles_() +{ + GetPageExport()->exportMasterStyles( true ); +} + +void ORptExport::collectComponentStyles() +{ + if ( m_bAllreadyFilled ) + return; + + m_bAllreadyFilled = true; + Reference xProp(getReportDefinition()); + if ( !xProp.is() ) + return; + + uno::Reference< report::XSection> xParent(xProp->getParent(),uno::UNO_QUERY); + if ( xParent.is() ) + exportAutoStyle(xProp.get()); + + if ( xProp->getReportHeaderOn() ) + exportSectionAutoStyle(xProp->getReportHeader()); + if ( xProp->getPageHeaderOn() ) + exportSectionAutoStyle(xProp->getPageHeader()); + + exportGroup(xProp,0,true); + + if ( xProp->getPageFooterOn() ) + exportSectionAutoStyle(xProp->getPageFooter()); + if ( xProp->getReportFooterOn() ) + exportSectionAutoStyle(xProp->getReportFooter()); +} + +void ORptExport::ExportAutoStyles_() +{ + // there are no styles that require their own autostyles + if ( getExportFlags() & SvXMLExportFlags::CONTENT ) + { + collectComponentStyles(); + GetAutoStylePool()->exportXML(XmlStyleFamily::TABLE_TABLE); + GetAutoStylePool()->exportXML(XmlStyleFamily::TABLE_COLUMN); + GetAutoStylePool()->exportXML(XmlStyleFamily::TABLE_ROW); + GetAutoStylePool()->exportXML(XmlStyleFamily::TABLE_CELL); + exportDataStyles(); + GetShapeExport()->exportAutoStyles(); + } + // exported in _ExportMasterStyles + if( getExportFlags() & SvXMLExportFlags::MASTERSTYLES ) + GetPageExport()->collectAutoStyles( false ); + if( getExportFlags() & SvXMLExportFlags::MASTERSTYLES ) + GetPageExport()->exportAutoStyles(); +} + +void ORptExport::ExportStyles_(bool bUsed) +{ + SvXMLExport::ExportStyles_(bUsed); + + // write draw:style-name for object graphic-styles + GetShapeExport()->ExportGraphicDefaults(); +} + +SvXMLAutoStylePoolP* ORptExport::CreateAutoStylePool() +{ + return new OXMLAutoStylePoolP(*this); +} + +void SAL_CALL ORptExport::setSourceDocument( const Reference< XComponent >& xDoc ) +{ + m_xReportDefinition.set(xDoc,UNO_QUERY_THROW); + SvXMLExport::setSourceDocument(xDoc); +} + +void ORptExport::ExportFontDecls_() +{ + GetFontAutoStylePool(); // make sure the pool is created + collectComponentStyles(); + SvXMLExport::ExportFontDecls_(); +} + +void ORptExport::exportParagraph(const Reference< XReportControlModel >& _xReportElement) +{ + OSL_PRECOND(_xReportElement.is(),"Element is null!"); + // start + SvXMLElementExport aParagraphContent(*this,XML_NAMESPACE_TEXT, XML_P, false, false); + if ( Reference(_xReportElement,uno::UNO_QUERY).is() ) + { + OUString sFieldData = _xReportElement->getDataField(); + static const sal_Unicode s_sPageNumber[] = u"PageNumber()"; + static const char s_sReportPrefix[] = "rpt:"; + sFieldData = sFieldData.copy(strlen(s_sReportPrefix)); + sal_Int32 nPageNumberIndex = sFieldData.indexOf(s_sPageNumber); + if ( nPageNumberIndex != -1 ) + { + sal_Int32 nIndex = 0; + do + { + std::u16string_view sToken = o3tl::getToken(sFieldData, 0, '&', nIndex ); + sToken = o3tl::trim(sToken); + if ( !sToken.empty() ) + { + if ( sToken == s_sPageNumber ) + { + AddAttribute(XML_NAMESPACE_TEXT, XML_SELECT_PAGE, "current" ); + SvXMLElementExport aPageNumber(*this,XML_NAMESPACE_TEXT, XML_PAGE_NUMBER, false, false); + Characters("1"); + } + else if ( sToken == u"PageCount()" ) + { + SvXMLElementExport aPageNumber(*this,XML_NAMESPACE_TEXT, XML_PAGE_COUNT, false, false); + Characters("1"); + } + else + { + + if ( o3tl::starts_with(sToken, u"\"") && o3tl::ends_with(sToken, u"\"") ) + sToken = sToken.substr(1, sToken.size() - 2); + + bool bPrevCharIsSpace = false; + GetTextParagraphExport()->exportCharacterData(OUString(sToken), bPrevCharIsSpace); + } + } + } + while ( nIndex >= 0 ); + } + } + Reference< XFixedText > xFT(_xReportElement,UNO_QUERY); + if ( xFT.is() ) + { + OUString sExpr = xFT->getLabel(); + bool bPrevCharIsSpace = false; // FIXME this looks quite broken - does the corresponding import filter do whitespace collapsing at all? + GetTextParagraphExport()->exportCharacterData(sExpr, bPrevCharIsSpace); + } +} + +XMLShapeExport* ORptExport::CreateShapeExport() +{ + XMLShapeExport* pShapeExport = new XMLShapeExport( *this, XMLTextParagraphExport::CreateShapeExtPropMapper( *this ) ); + return pShapeExport; +} + +void ORptExport::exportShapes(const Reference< XSection>& _xSection,bool _bAddParagraph) +{ + rtl::Reference< XMLShapeExport > xShapeExport = GetShapeExport(); + xShapeExport->seekShapes(_xSection); + const sal_Int32 nCount = _xSection->getCount(); + ::std::unique_ptr pParagraphContent; + if ( _bAddParagraph ) + pParagraphContent.reset(new SvXMLElementExport(*this,XML_NAMESPACE_TEXT, XML_P, true, false)); + + awt::Point aRefPoint; + aRefPoint.X = rptui::getStyleProperty(_xSection->getReportDefinition(),PROPERTY_LEFTMARGIN); + for (sal_Int32 i = 0; i < nCount; ++i) + { + uno::Reference< XShape > xShape(_xSection->getByIndex(i),uno::UNO_QUERY); + if ( xShape.is() ) + { + ::std::unique_ptr pSubDocument; + uno::Reference< frame::XModel> xModel(xShape->getPropertyValue("Model"),uno::UNO_QUERY); + if ( xModel.is() ) // special handling for chart object + { + pSubDocument.reset(new SvXMLElementExport(*this,XML_NAMESPACE_REPORT, XML_SUB_DOCUMENT, false, false)); + exportMasterDetailFields(xShape); + exportReportElement(xShape); + } + + AddAttribute( XML_NAMESPACE_TEXT, XML_ANCHOR_TYPE, XML_PARAGRAPH ); + xShapeExport->exportShape(xShape, SEF_DEFAULT|XMLShapeExportFlags::NO_WS,&aRefPoint); + } + } +} + +void ORptExport::exportGroupsExpressionAsFunction(const Reference< XGroups>& _xGroups) +{ + if ( !_xGroups.is() ) + return; + + uno::Reference< XFunctions> xFunctions = _xGroups->getReportDefinition()->getFunctions(); + const sal_Int32 nCount = _xGroups->getCount(); + for (sal_Int32 i = 0; i < nCount; ++i) + { + uno::Reference< XGroup> xGroup(_xGroups->getByIndex(i),uno::UNO_QUERY_THROW); + const ::sal_Int16 nGroupOn = xGroup->getGroupOn(); + if ( nGroupOn != report::GroupOn::DEFAULT ) + { + uno::Reference< XFunction> xFunction = xFunctions->createFunction(); + OUString sFunction,sPrefix,sPostfix; + OUString sExpression = xGroup->getExpression(); + OUString sFunctionName; + OUString sInitialFormula; + switch(nGroupOn) + { + case report::GroupOn::PREFIX_CHARACTERS: + sFunction = "LEFT"; + sPrefix = ";" + OUString::number(xGroup->getGroupInterval()); + break; + case report::GroupOn::YEAR: + sFunction = "YEAR"; + break; + case report::GroupOn::QUARTAL: + sFunction = "INT((MONTH"; + sPostfix = "-1)/3)+1"; + sFunctionName = "QUARTAL_" + sExpression; + break; + case report::GroupOn::MONTH: + sFunction = "MONTH"; + break; + case report::GroupOn::WEEK: + sFunction = "WEEK"; + break; + case report::GroupOn::DAY: + sFunction = "DAY"; + break; + case report::GroupOn::HOUR: + sFunction = "HOUR"; + break; + case report::GroupOn::MINUTE: + sFunction = "MINUTE"; + break; + case report::GroupOn::INTERVAL: + { + sFunction = "INT"; + uno::Reference< XFunction> xCountFunction = xFunctions->createFunction(); + xCountFunction->setInitialFormula(beans::Optional< OUString>(true,OUString("rpt:0"))); + OUString sCountName = sFunction + "_count_" + sExpression; + xCountFunction->setName(sCountName); + xCountFunction->setFormula( "rpt:[" + sCountName + "] + 1" ); + exportFunction(xCountFunction); + sExpression = sCountName; + // The reference to sCountName in the formula of sFunctionName refers to the *old* value + // so we need to expand the formula of sCountName + sPrefix = " + 1) / " + OUString::number(xGroup->getGroupInterval()); + sFunctionName = sFunction + "_" + sExpression; + sFunction += "("; + sInitialFormula = "rpt:0"; + } + break; + default: + ; + } + if ( sFunctionName.isEmpty() ) + sFunctionName = sFunction + "_" + sExpression; + if ( !sFunction.isEmpty() ) + { + const sal_Unicode pReplaceChars[] = { '(',')',';',',','+','-','[',']','/','*'}; + for(sal_Unicode ch : pReplaceChars) + sFunctionName = sFunctionName.replace(ch,'_'); + + xFunction->setName(sFunctionName); + if ( !sInitialFormula.isEmpty() ) + xFunction->setInitialFormula(beans::Optional< OUString>(true, sInitialFormula)); + sFunction = "rpt:" + sFunction + "([" + sExpression + "]"; + + if ( !sPrefix.isEmpty() ) + sFunction += sPrefix; + sFunction += ")"; + if ( !sPostfix.isEmpty() ) + sFunction += sPostfix; + xFunction->setFormula(sFunction); + exportFunction(xFunction); + m_aGroupFunctionMap.emplace(xGroup,xFunction); + } + } + } +} + + +}// rptxml + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/reportdesign/source/filter/xml/xmlExport.hxx b/reportdesign/source/filter/xml/xmlExport.hxx new file mode 100644 index 000000000..f82d85aa7 --- /dev/null +++ b/reportdesign/source/filter/xml/xmlExport.hxx @@ -0,0 +1,161 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLEXPORT_HXX +#define INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLEXPORT_HXX + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace rptxml +{ +using namespace ::xmloff::token; +using namespace css::uno; +using namespace css::container; +using namespace css::lang; +using namespace css::beans; +using namespace css::document; +using namespace css::text; +using namespace css::report; +using namespace css::io; +using namespace css::xml::sax; + + +class ORptExport : public SvXMLExport +{ +public: + struct TCell + { + sal_Int32 nColSpan; + sal_Int32 nRowSpan; + Reference xElement; + bool bSet; + TCell( sal_Int32 _nColSpan, + sal_Int32 _nRowSpan, + Reference const & _xElement = Reference()) : + nColSpan(_nColSpan) + ,nRowSpan(_nRowSpan) + ,xElement(_xElement) + ,bSet(xElement.is()) + {} + + TCell( ) : + nColSpan(1) + ,nRowSpan(1) + ,bSet(true) + {} + }; + typedef ::std::pair< OUString ,OUString> TStringPair; + typedef ::std::map< Reference ,OUString > TPropertyStyleMap; + typedef ::std::map< Reference , std::vector> TGridStyleMap; + typedef ::std::vector< TCell > TRow; + typedef ::std::vector< ::std::pair< bool, TRow > > TGrid; + typedef ::std::map< Reference ,TGrid > TSectionsGrid; + typedef ::std::map< Reference ,Reference > TGroupFunctionMap; +private: + TSectionsGrid m_aSectionsGrid; + + TPropertyStyleMap m_aAutoStyleNames; + TGridStyleMap m_aColumnStyleNames; + TGridStyleMap m_aRowStyleNames; + TGroupFunctionMap m_aGroupFunctionMap; + + OUString m_sTableStyle; + OUString m_sCellStyle; + rtl::Reference < SvXMLExportPropertyMapper> m_xTableStylesExportPropertySetMapper; + rtl::Reference < SvXMLExportPropertyMapper> m_xCellStylesExportPropertySetMapper; + rtl::Reference < SvXMLExportPropertyMapper> m_xColumnStylesExportPropertySetMapper; + rtl::Reference < SvXMLExportPropertyMapper> m_xRowStylesExportPropertySetMapper; + rtl::Reference < SvXMLExportPropertyMapper > m_xParaPropMapper; + rtl::Reference < XMLPropertyHandlerFactory > m_xPropHdlFactory; + + mutable rtl::Reference < XMLPropertySetMapper > m_xCellStylesPropertySetMapper; + Reference m_xReportDefinition; + bool m_bAllreadyFilled; + + void exportReport(const Reference& _xReportDefinition); /// + void exportReportAttributes(const Reference& _xReport); + void exportFunctions(const Reference& _xFunctions); /// + void exportFunction(const Reference< XFunction>& _xFunction); + void exportMasterDetailFields(const Reference& _xReportComponent); + void exportComponent(const Reference& _xReportComponent); + void exportGroup(const Reference& _xReportDefinition,sal_Int32 _nPos,bool _bExportAutoStyle = false); + void exportStyleName(XPropertySet* _xProp,SvXMLAttributeList& _rAtt,const OUString& _sName); + void exportSection(const Reference& _xProp,bool bHeader = false); + void exportContainer(const Reference< XSection>& _xSection); + void exportShapes(const Reference< XSection>& _xSection,bool _bAddParagraph = true); + void exportTableColumns(const Reference< XSection>& _xSection); + void exportSectionAutoStyle(const Reference& _xProp); + void exportReportElement(const Reference& _xReportElement); + void exportFormatConditions(const Reference& _xReportElement); + void exportAutoStyle(XPropertySet* _xProp,const Reference& _xParentFormattedField = Reference()); + void exportAutoStyle(const Reference& _xProp); + void exportReportComponentAutoStyles(const Reference& _xProp); + void collectComponentStyles(); + void collectStyleNames(XmlStyleFamily _nFamily,const ::std::vector< sal_Int32>& _aSize, std::vector& _rStyleNames); + void collectStyleNames(XmlStyleFamily _nFamily,const ::std::vector< sal_Int32>& _aSize, const ::std::vector< sal_Int32>& _aSizeAutoGrow, std::vector& _rStyleNames); + void exportParagraph(const Reference< XReportControlModel >& _xReportElement); + bool exportFormula(enum ::xmloff::token::XMLTokenEnum eName,const OUString& _sFormula); + void exportGroupsExpressionAsFunction(const Reference< XGroups>& _xGroups); + static OUString convertFormula(const OUString& _sFormula); + + virtual void SetBodyAttributes() override; + +protected: + + virtual void ExportStyles_( bool bUsed ) override; + virtual void ExportAutoStyles_() override; + virtual void ExportContent_() override; + virtual void ExportMasterStyles_() override; + virtual void ExportFontDecls_() override; + virtual SvXMLAutoStylePoolP* CreateAutoStylePool() override; + virtual XMLShapeExport* CreateShapeExport() override; + + virtual ~ORptExport() override {}; +public: + + ORptExport(const Reference< XComponentContext >& _rxContext, OUString const & implementationName, SvXMLExportFlags nExportFlag); + + // XExporter + virtual void SAL_CALL setSourceDocument( const css::uno::Reference< css::lang::XComponent >& xDoc ) override; + + const Reference& getReportDefinition() const { return m_xReportDefinition; } + + const rtl::Reference < XMLPropertySetMapper >& GetCellStylePropertyMapper() const { return m_xCellStylesPropertySetMapper;} +}; + + +} // rptxml + +#endif // INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLEXPORT_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/reportdesign/source/filter/xml/xmlExportDocumentHandler.cxx b/reportdesign/source/filter/xml/xmlExportDocumentHandler.cxx new file mode 100644 index 000000000..b8b064cc6 --- /dev/null +++ b/reportdesign/source/filter/xml/xmlExportDocumentHandler.cxx @@ -0,0 +1,408 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include "xmlExportDocumentHandler.hxx" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace rptxml +{ +using namespace ::com::sun::star; +using namespace ::xmloff::token; + +static void lcl_exportPrettyPrinting(const uno::Reference< xml::sax::XDocumentHandler >& _xDelegatee) +{ + if ( officecfg::Office::Common::Save::Document::PrettyPrinting::get() ) + { + _xDelegatee->ignorableWhitespace(" "); + } +} + +OUString lcl_createAttribute(const xmloff::token::XMLTokenEnum& _eNamespace,const xmloff::token::XMLTokenEnum& _eAttribute) +{ + return + // ...if it's in our map, make the prefix + xmloff::token::GetXMLToken(_eNamespace) + + ":" + + xmloff::token::GetXMLToken(_eAttribute); +} + +static void lcl_correctCellAddress(const OUString & _sName, const uno::Reference< xml::sax::XAttributeList > & xAttribs) +{ + SvXMLAttributeList* pList = comphelper::getFromUnoTunnel(xAttribs); + OUString sCellAddress = pList->getValueByName(_sName); + const sal_Int32 nPos = sCellAddress.lastIndexOf('$'); + if ( nPos != -1 ) + { + sCellAddress = OUString::Concat(sCellAddress.subView(0,nPos)) + "$65535"; + pList->RemoveAttribute(_sName); + pList->AddAttribute(_sName,sCellAddress); + } +} + +ExportDocumentHandler::ExportDocumentHandler(uno::Reference< uno::XComponentContext > const & context) : + m_xContext(context) + ,m_nColumnCount(0) + ,m_bTableRowsStarted(false) + ,m_bFirstRowExported(false) + ,m_bCountColumnHeader(false) +{ +} + +ExportDocumentHandler::~ExportDocumentHandler() +{ + if ( m_xProxy.is() ) + { + m_xProxy->setDelegator( nullptr ); + m_xProxy.clear(); + } +} +IMPLEMENT_GET_IMPLEMENTATION_ID(ExportDocumentHandler) + +OUString SAL_CALL ExportDocumentHandler::getImplementationName( ) +{ + return "com.sun.star.comp.report.ExportDocumentHandler"; +} + +sal_Bool SAL_CALL ExportDocumentHandler::supportsService( const OUString& ServiceName ) +{ + return cppu::supportsService(this, ServiceName); +} + +uno::Sequence< OUString > SAL_CALL ExportDocumentHandler::getSupportedServiceNames( ) +{ + uno::Sequence< OUString > aSupported; + if ( m_xServiceInfo.is() ) + aSupported = m_xServiceInfo->getSupportedServiceNames(); + return ::comphelper::concatSequences(uno::Sequence< OUString > { "com.sun.star.report.ExportDocumentHandler" },aSupported); +} + +// xml::sax::XDocumentHandler: +void SAL_CALL ExportDocumentHandler::startDocument() +{ + m_xDelegatee->startDocument(); +} + +void SAL_CALL ExportDocumentHandler::endDocument() +{ + m_xDelegatee->endDocument(); +} + +void SAL_CALL ExportDocumentHandler::startElement(const OUString & _sName, const uno::Reference< xml::sax::XAttributeList > & xAttribs) +{ + bool bExport = true; + if ( _sName == "office:chart" ) + { + rtl::Reference pList = new SvXMLAttributeList(); + OUStringBuffer sValue; + static const SvXMLEnumMapEntry aXML_CommandTypeEnumMap[] = + { + { XML_TABLE, sdb::CommandType::TABLE }, + { XML_QUERY, sdb::CommandType::QUERY }, + { XML_TOKEN_INVALID, 0 } + }; + if ( SvXMLUnitConverter::convertEnum( sValue, static_cast(m_xDatabaseDataProvider->getCommandType()),aXML_CommandTypeEnumMap ) ) + { + pList->AddAttribute(lcl_createAttribute(XML_NP_RPT,XML_COMMAND_TYPE),sValue.makeStringAndClear()); + } + const OUString sCommand = m_xDatabaseDataProvider->getCommand(); + if ( !sCommand.isEmpty() ) + pList->AddAttribute(lcl_createAttribute(XML_NP_RPT,XML_COMMAND),sCommand); + + const OUString sFilter( m_xDatabaseDataProvider->getFilter() ); + if ( !sFilter.isEmpty() ) + pList->AddAttribute(lcl_createAttribute(XML_NP_RPT,XML_FILTER),sFilter); + + const bool bEscapeProcessing( m_xDatabaseDataProvider->getEscapeProcessing() ); + if ( !bEscapeProcessing ) + pList->AddAttribute(lcl_createAttribute(XML_NP_RPT,XML_ESCAPE_PROCESSING),::xmloff::token::GetXMLToken( XML_FALSE )); + + pList->AddAttribute(lcl_createAttribute(XML_NP_OFFICE,XML_MIMETYPE),MIMETYPE_OASIS_OPENDOCUMENT_CHART_ASCII); + + m_xDelegatee->startElement(lcl_createAttribute(XML_NP_OFFICE,XML_REPORT),pList); + + const OUString sTableCalc = lcl_createAttribute(XML_NP_TABLE,XML_CALCULATION_SETTINGS); + m_xDelegatee->startElement(sTableCalc,nullptr); + pList = new SvXMLAttributeList(); + pList->AddAttribute(lcl_createAttribute(XML_NP_TABLE,XML_DATE_VALUE),"1899-12-30"); + + const OUString sNullDate = lcl_createAttribute(XML_NP_TABLE,XML_NULL_DATE); + m_xDelegatee->startElement(sNullDate,pList); + m_xDelegatee->endElement(sNullDate); + m_xDelegatee->endElement(sTableCalc); + bExport = false; + } + else if ( _sName == "table:table" ) + { + m_xDelegatee->startElement(lcl_createAttribute(XML_NP_RPT,XML_DETAIL),nullptr); + lcl_exportPrettyPrinting(m_xDelegatee); + } + else if ( _sName == "table:table-header-rows" ) + { + m_bCountColumnHeader = true; + } + else if ( m_bCountColumnHeader && _sName == "table:table-cell" ) + { + ++m_nColumnCount; + } + else if ( _sName == "table:table-rows" ) + { + m_xDelegatee->startElement(_sName,xAttribs); + exportTableRows(); + bExport = false; + m_bTableRowsStarted = true; + m_bFirstRowExported = true; + } + else if ( m_bTableRowsStarted && m_bFirstRowExported && (_sName == "table:table-row" || _sName == "table:table-cell") ) + bExport = false; + else if ( _sName == "chart:plot-area" ) + { + SvXMLAttributeList* pList = comphelper::getFromUnoTunnel(xAttribs); + pList->RemoveAttribute("table:cell-range-address"); + } + else if ( _sName == "chart:categories" ) + { + static OUString s_sCellAddress(lcl_createAttribute(XML_NP_TABLE,XML_CELL_RANGE_ADDRESS)); + lcl_correctCellAddress(s_sCellAddress,xAttribs); + } + else if ( _sName == "chart:series" ) + { + static OUString s_sCellAddress(lcl_createAttribute(XML_NP_CHART,XML_VALUES_CELL_RANGE_ADDRESS)); + lcl_correctCellAddress(s_sCellAddress,xAttribs); + } + else if ( m_bTableRowsStarted && !m_bFirstRowExported && _sName == "table:table-cell" ) + { + SvXMLAttributeList* pList = comphelper::getFromUnoTunnel(xAttribs); + static OUString s_sValue(lcl_createAttribute(XML_NP_OFFICE,XML_VALUE)); + pList->RemoveAttribute(s_sValue); + } + else if ( m_bTableRowsStarted && _sName == "text:p" ) + { + bExport = false; + } + if ( bExport ) + m_xDelegatee->startElement(_sName,xAttribs); +} + +void SAL_CALL ExportDocumentHandler::endElement(const OUString & _sName) +{ + bool bExport = true; + OUString sNewName = _sName; + if ( _sName == "office:chart" ) + { + sNewName = lcl_createAttribute(XML_NP_OFFICE,XML_REPORT); + } + else if ( _sName == "table:table" ) + { + m_xDelegatee->endElement(_sName); + lcl_exportPrettyPrinting(m_xDelegatee); + sNewName = lcl_createAttribute(XML_NP_RPT,XML_DETAIL); + } + else if ( _sName == "table:table-header-rows" ) + { + m_bCountColumnHeader = false; + } + else if ( _sName == "table:table-rows" ) + m_bTableRowsStarted = false; + else if ( m_bTableRowsStarted && m_bFirstRowExported && (_sName == "table:table-row" || _sName == "table:table-cell") ) + bExport = false; + else if ( m_bTableRowsStarted && _sName == "table:table-row" ) + m_bFirstRowExported = true; + else if ( m_bTableRowsStarted && _sName == "text:p" ) + { + bExport = !m_bFirstRowExported; + } + + if ( bExport ) + m_xDelegatee->endElement(sNewName); +} + +void SAL_CALL ExportDocumentHandler::characters(const OUString & aChars) +{ + if ( !(m_bTableRowsStarted || m_bFirstRowExported) ) + { + m_xDelegatee->characters(aChars); + } +} + +void SAL_CALL ExportDocumentHandler::ignorableWhitespace(const OUString & aWhitespaces) +{ + m_xDelegatee->ignorableWhitespace(aWhitespaces); +} + +void SAL_CALL ExportDocumentHandler::processingInstruction(const OUString & aTarget, const OUString & aData) +{ + m_xDelegatee->processingInstruction(aTarget,aData); +} + +void SAL_CALL ExportDocumentHandler::setDocumentLocator(const uno::Reference< xml::sax::XLocator > & xLocator) +{ + m_xDelegatee->setDocumentLocator(xLocator); +} +void SAL_CALL ExportDocumentHandler::initialize( const uno::Sequence< uno::Any >& _aArguments ) +{ + ::osl::MutexGuard aGuard(m_aMutex); + comphelper::SequenceAsHashMap aArgs(_aArguments); + m_xDelegatee = aArgs.getUnpackedValueOrDefault("DocumentHandler",m_xDelegatee); + m_xModel = aArgs.getUnpackedValueOrDefault("Model",m_xModel); + + OSL_ENSURE(m_xDelegatee.is(),"No document handler available!"); + if ( !m_xDelegatee.is() || !m_xModel.is() ) + throw uno::Exception("no delegatee and no model", nullptr); + + m_xDatabaseDataProvider.set(m_xModel->getDataProvider(),uno::UNO_QUERY_THROW); + if ( !m_xDatabaseDataProvider->getActiveConnection().is() ) + throw uno::Exception("no active connection", nullptr); + + uno::Reference< reflection::XProxyFactory > xProxyFactory = reflection::ProxyFactory::create( m_xContext ); + m_xProxy = xProxyFactory->createProxy(m_xDelegatee); + ::comphelper::query_aggregation(m_xProxy,m_xDelegatee); + m_xTypeProvider.set(m_xDelegatee,uno::UNO_QUERY); + m_xServiceInfo.set(m_xDelegatee,uno::UNO_QUERY); + + // set ourself as delegator + m_xProxy->setDelegator( *this ); + const OUString sCommand = m_xDatabaseDataProvider->getCommand(); + if ( !sCommand.isEmpty() ) + m_aColumns = ::dbtools::getFieldNamesByCommandDescriptor(m_xDatabaseDataProvider->getActiveConnection() + ,m_xDatabaseDataProvider->getCommandType() + ,sCommand); + + uno::Reference< chart::XComplexDescriptionAccess > xDataProvider(m_xDatabaseDataProvider,uno::UNO_QUERY); + if ( !xDataProvider.is() ) + return; + + m_aColumns.realloc(1); + const uno::Sequence< OUString > aColumnNames = xDataProvider->getColumnDescriptions(); + for(const auto& rColumnName : aColumnNames) + { + if ( !rColumnName.isEmpty() ) + { + sal_Int32 nCount = m_aColumns.getLength(); + m_aColumns.realloc(nCount+1); + m_aColumns.getArray()[nCount] = rColumnName; + } + } +} + +uno::Any SAL_CALL ExportDocumentHandler::queryInterface( const uno::Type& _rType ) +{ + uno::Any aReturn = ExportDocumentHandler_BASE::queryInterface(_rType); + return aReturn.hasValue() ? aReturn : (m_xProxy.is() ? m_xProxy->queryAggregation(_rType) : aReturn); +} + +uno::Sequence< uno::Type > SAL_CALL ExportDocumentHandler::getTypes( ) +{ + if ( m_xTypeProvider.is() ) + return ::comphelper::concatSequences( + ExportDocumentHandler_BASE::getTypes(), + m_xTypeProvider->getTypes() + ); + return ExportDocumentHandler_BASE::getTypes(); +} + +void ExportDocumentHandler::exportTableRows() +{ + const OUString sRow( lcl_createAttribute(XML_NP_TABLE, XML_TABLE_ROW) ); + m_xDelegatee->startElement(sRow,nullptr); + + const OUString sValueType( lcl_createAttribute(XML_NP_OFFICE, XML_VALUE_TYPE) ); + + const OUString sCell( lcl_createAttribute(XML_NP_TABLE, XML_TABLE_CELL) ); + const OUString sP( lcl_createAttribute(XML_NP_TEXT, XML_P) ); + const OUString sFtext(lcl_createAttribute(XML_NP_RPT,XML_FORMATTED_TEXT) ); + const OUString sRElement(lcl_createAttribute(XML_NP_RPT,XML_REPORT_ELEMENT) ); + const OUString sRComponent( lcl_createAttribute(XML_NP_RPT,XML_REPORT_COMPONENT) ) ; + const OUString sFormulaAttrib( lcl_createAttribute(XML_NP_RPT,XML_FORMULA) ); + static constexpr OUStringLiteral s_sFloat = u"float"; + + rtl::Reference pCellAtt = new SvXMLAttributeList(); + pCellAtt->AddAttribute(sValueType, "string"); + + bool bRemoveString = true; + const sal_Int32 nCount = m_aColumns.getLength(); + if ( m_nColumnCount > nCount ) + { + const sal_Int32 nEmptyCellCount = m_nColumnCount - nCount; + for(sal_Int32 i = 0; i < nEmptyCellCount ; ++i) + { + m_xDelegatee->startElement(sCell,pCellAtt); + if ( bRemoveString ) + { + bRemoveString = false; + pCellAtt->RemoveAttribute(sValueType); + pCellAtt->AddAttribute(sValueType,s_sFloat); + } + m_xDelegatee->startElement(sP,nullptr); + m_xDelegatee->endElement(sP); + m_xDelegatee->endElement(sCell); + } + } + for(const auto& rColumn : std::as_const(m_aColumns)) + { + OUString sFormula = "field:[" + rColumn + "]"; + rtl::Reference pList = new SvXMLAttributeList(); + pList->AddAttribute(sFormulaAttrib,sFormula); + + m_xDelegatee->startElement(sCell,pCellAtt); + if ( bRemoveString ) + { + bRemoveString = false; + pCellAtt->RemoveAttribute(sValueType); + pCellAtt->AddAttribute(sValueType,s_sFloat); + } + m_xDelegatee->startElement(sP,nullptr); + m_xDelegatee->startElement(sFtext,pList); + m_xDelegatee->startElement(sRElement,nullptr); + m_xDelegatee->startElement(sRComponent,nullptr); + + m_xDelegatee->endElement(sRComponent); + m_xDelegatee->endElement(sRElement); + m_xDelegatee->endElement(sFtext); + m_xDelegatee->endElement(sP); + m_xDelegatee->endElement(sCell); + } + + m_xDelegatee->endElement(sRow); +} + +} // namespace rptxml + + +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* +reportdesign_ExportDocumentHandler_get_implementation( + css::uno::XComponentContext* context, css::uno::Sequence const&) +{ + return cppu::acquire(new rptxml::ExportDocumentHandler(context)); +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/reportdesign/source/filter/xml/xmlExportDocumentHandler.hxx b/reportdesign/source/filter/xml/xmlExportDocumentHandler.hxx new file mode 100644 index 000000000..9e7afe347 --- /dev/null +++ b/reportdesign/source/filter/xml/xmlExportDocumentHandler.hxx @@ -0,0 +1,96 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLEXPORTDOCUMENTHANDLER_HXX +#define INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLEXPORTDOCUMENTHANDLER_HXX + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace rptxml +{ + +OUString lcl_createAttribute(const xmloff::token::XMLTokenEnum& _eNamespace,const xmloff::token::XMLTokenEnum& _eAttribute); + +typedef ::cppu::WeakAggImplHelper3< css::xml::sax::XDocumentHandler + , css::lang::XInitialization + , css::lang::XServiceInfo> ExportDocumentHandler_BASE; + +class ExportDocumentHandler : public ExportDocumentHandler_BASE +{ +public: + explicit ExportDocumentHandler(css::uno::Reference< css::uno::XComponentContext > const & context); + +private: + // XServiceInfo + virtual OUString SAL_CALL getImplementationName( ) override; + virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override; + virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override; + + virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) override; + + DECLARE_XTYPEPROVIDER( ) + + // css::xml::sax::XDocumentHandler: + virtual void SAL_CALL startDocument() override; + virtual void SAL_CALL endDocument() override; + virtual void SAL_CALL startElement(const OUString & aName, const css::uno::Reference< css::xml::sax::XAttributeList > & xAttribs) override; + virtual void SAL_CALL endElement(const OUString & aName) override; + virtual void SAL_CALL characters(const OUString & aChars) override; + virtual void SAL_CALL ignorableWhitespace(const OUString & aWhitespaces) override; + virtual void SAL_CALL processingInstruction(const OUString & aTarget, const OUString & aData) override; + virtual void SAL_CALL setDocumentLocator(const css::uno::Reference< css::xml::sax::XLocator > & xLocator) override; + + virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override; + + void exportTableRows(); +private: + ExportDocumentHandler(ExportDocumentHandler const &) = delete; + void operator =(ExportDocumentHandler const &) = delete; + + virtual ~ExportDocumentHandler() override; + + ::osl::Mutex m_aMutex; + css::uno::Reference< css::uno::XComponentContext > m_xContext; + css::uno::Reference< css::xml::sax::XDocumentHandler > m_xDelegatee; + css::uno::Reference< css::uno::XAggregation > m_xProxy; + css::uno::Reference< css::lang::XTypeProvider > m_xTypeProvider; + css::uno::Reference< css::lang::XServiceInfo > m_xServiceInfo; + css::uno::Reference< css::chart2::XChartDocument > m_xModel; + css::uno::Reference< css::chart2::data::XDatabaseDataProvider > m_xDatabaseDataProvider; + css::uno::Sequence< OUString > m_aColumns; + sal_Int32 m_nColumnCount; + bool m_bTableRowsStarted; + bool m_bFirstRowExported; + bool m_bCountColumnHeader; +}; + +} // namespace rptxml + +#endif // INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLEXPORTDOCUMENTHANDLER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/reportdesign/source/filter/xml/xmlFixedContent.cxx b/reportdesign/source/filter/xml/xmlFixedContent.cxx new file mode 100644 index 000000000..4cffdd300 --- /dev/null +++ b/reportdesign/source/filter/xml/xmlFixedContent.cxx @@ -0,0 +1,215 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#include "xmlFixedContent.hxx" +#include "xmlfilter.hxx" +#include +#include +#include +#include "xmlEnums.hxx" +#include "xmlCell.hxx" +#include +#include +#include +#include +#include +#include "xmlTable.hxx" +#include +#include + +namespace rptxml +{ + using namespace ::com::sun::star; + +namespace { + +class OXMLCharContent: public XMLCharContext +{ + OXMLFixedContent* m_pFixedContent; + +public: + OXMLCharContent( + SvXMLImport& rImport, + OXMLFixedContent* _pFixedContent, + const uno::Reference< xml::sax::XFastAttributeList > & xAttrList, + sal_Unicode c, + bool bCount ); + OXMLCharContent( + SvXMLImport& rImport, + OXMLFixedContent* _pFixedContent, + sal_Int16 nControl ); + OXMLCharContent(const OXMLCharContent&) = delete; + OXMLCharContent& operator=(const OXMLCharContent&) = delete; + + virtual void InsertControlCharacter(sal_Int16 _nControl) override; + virtual void InsertString(const OUString& _sString) override; +}; + +} + +OXMLCharContent::OXMLCharContent( + SvXMLImport& rImport, + OXMLFixedContent* _pFixedContent, + const uno::Reference< xml::sax::XFastAttributeList > & xAttrList, + sal_Unicode c, + bool bCount ) + : XMLCharContext(rImport,xAttrList,c,bCount) + ,m_pFixedContent(_pFixedContent) +{ +} + +OXMLCharContent::OXMLCharContent( + SvXMLImport& rImport, + OXMLFixedContent* _pFixedContent, + sal_Int16 nControl ) + : XMLCharContext(rImport,nControl) + ,m_pFixedContent(_pFixedContent) +{ +} + +void OXMLCharContent::InsertControlCharacter(sal_Int16 _nControl) +{ + switch( _nControl ) + { + case ControlCharacter::LINE_BREAK: + m_pFixedContent->characters("\n"); + break; + default: + OSL_FAIL("Not supported control character"); + break; + } +} + +void OXMLCharContent::InsertString(const OUString& _sString) +{ + m_pFixedContent->characters(_sString); +} + + +OXMLFixedContent::OXMLFixedContent( ORptFilter& rImport + ,OXMLCell& _rCell + ,OXMLTable* _pContainer + ,OXMLFixedContent* _pInP) : + OXMLReportElementBase( rImport,nullptr,_pContainer) +,m_rCell(_rCell) +,m_pInP(_pInP) +,m_bFormattedField(false) +{ +} + + +OXMLFixedContent::~OXMLFixedContent() +{ + +} + + +css::uno::Reference< css::xml::sax::XFastContextHandler > OXMLFixedContent::createFastChildContext( + sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList ) +{ + css::uno::Reference< css::xml::sax::XFastContextHandler > xContext = OXMLReportElementBase::createFastChildContext(nElement,xAttrList); + if (xContext) + return xContext; + + static constexpr char16_t s_sStringConcat[] = u" & "; + + m_rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + switch( nElement ) + { + case XML_ELEMENT(TEXT, XML_P): + xContext = new OXMLFixedContent(m_rImport,m_rCell,m_pContainer,this); + break; + case XML_ELEMENT(TEXT, XML_TAB): + xContext = new OXMLCharContent( m_rImport, this, xAttrList, + 0x0009, false ); + break; + + case XML_ELEMENT(TEXT, XML_LINE_BREAK): + xContext = new OXMLCharContent( m_rImport, this, + ControlCharacter::LINE_BREAK ); + break; + + case XML_ELEMENT(TEXT, XML_S): + xContext = new OXMLCharContent( m_rImport, this, xAttrList, + 0x0020, true ); + break; + case XML_ELEMENT(TEXT, XML_PAGE_NUMBER): + m_sPageText += OUString::Concat(s_sStringConcat) + " PageNumber()"; + m_bFormattedField = true; + break; + case XML_ELEMENT(TEXT, XML_PAGE_COUNT): + m_sPageText += OUString::Concat(s_sStringConcat) + " PageCount()"; + m_bFormattedField = true; + break; + default: + ; + } + return xContext; +} + +void OXMLFixedContent::endFastElement(sal_Int32 nElement) +{ + if ( !m_pInP ) + return; + + const Reference xFactor(m_rImport.GetModel(),uno::UNO_QUERY); + if ( m_bFormattedField ) + { + uno::Reference< uno::XInterface> xInt = xFactor->createInstance(SERVICE_FORMATTEDFIELD); + Reference< report::XFormattedField > xControl(xInt,uno::UNO_QUERY); + xControl->setDataField("rpt:" + m_sPageText); + OSL_ENSURE(xControl.is(),"Could not create FormattedField!"); + m_pInP->m_xReportComponent = xControl.get(); + m_xReportComponent = xControl.get(); + } + else + { + Reference< XFixedText > xControl(xFactor->createInstance(SERVICE_FIXEDTEXT),uno::UNO_QUERY); + OSL_ENSURE(xControl.is(),"Could not create FixedContent!"); + m_pInP->m_xReportComponent = xControl.get(); + m_xReportComponent = xControl.get(); + xControl->setLabel(m_sLabel); + } + + m_pContainer->addCell(m_xReportComponent); + m_rCell.setComponent(m_xReportComponent); + + OXMLReportElementBase::endFastElement(nElement); +} + +void OXMLFixedContent::characters( const OUString& rChars ) +{ + m_sLabel += rChars; + if ( !rChars.isEmpty() ) + { + static const char s_Quote[] = "\""; + if ( !m_sPageText.isEmpty() ) + { + m_sPageText += " & "; + } + + m_sPageText += s_Quote + rChars + s_Quote; + } +} + + +} // namespace rptxml + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/reportdesign/source/filter/xml/xmlFixedContent.hxx b/reportdesign/source/filter/xml/xmlFixedContent.hxx new file mode 100644 index 000000000..916b61fed --- /dev/null +++ b/reportdesign/source/filter/xml/xmlFixedContent.hxx @@ -0,0 +1,63 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLFIXEDCONTENT_HXX +#define INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLFIXEDCONTENT_HXX + +#include "xmlReportElementBase.hxx" + + +namespace rptxml +{ + class ORptFilter; + class OXMLCell; + class OXMLFixedContent : public OXMLReportElementBase + { + OUString m_sPageText; // page count and page number + OUString m_sLabel; + OXMLCell& m_rCell; + OXMLFixedContent* m_pInP; // if set then we are in text-p element + bool m_bFormattedField; + + OXMLFixedContent(const OXMLFixedContent&) = delete; + OXMLFixedContent& operator =(const OXMLFixedContent&) = delete; + public: + + OXMLFixedContent( ORptFilter& rImport + ,OXMLCell& _rCell + ,OXMLTable* _pContainer + ,OXMLFixedContent* _pInP = nullptr); + virtual ~OXMLFixedContent() override; + + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( + sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList ) override; + + // This method is called for all characters that are contained in the + // current element. The default is to ignore them. + virtual void SAL_CALL characters( const OUString& rChars ) override; + + virtual void SAL_CALL endFastElement(sal_Int32 nElement) override; + }; + +} // namespace rptxml + + +#endif // INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLFIXEDCONTENT_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/reportdesign/source/filter/xml/xmlFormatCondition.cxx b/reportdesign/source/filter/xml/xmlFormatCondition.cxx new file mode 100644 index 000000000..6f5f43032 --- /dev/null +++ b/reportdesign/source/filter/xml/xmlFormatCondition.cxx @@ -0,0 +1,84 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#include "xmlFormatCondition.hxx" +#include "xmlfilter.hxx" +#include +#include +#include "xmlHelper.hxx" +#include +#include + +namespace rptxml +{ + using namespace ::com::sun::star; + using namespace ::com::sun::star::report; + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::xml::sax; + using namespace ::com::sun::star::beans; + +OXMLFormatCondition::OXMLFormatCondition( ORptFilter& rImport, + const Reference< XFastAttributeList > & _xAttrList + ,const Reference< XFormatCondition > & _xComponent ) : + SvXMLImportContext( rImport ) +,m_rImport(rImport) +,m_xComponent(_xComponent) +{ + + OSL_ENSURE(m_xComponent.is(),"Component is NULL!"); + try + { + for (auto &aIter : sax_fastparser::castToFastAttributeList( _xAttrList )) + { + switch( aIter.getToken() ) + { + case XML_ELEMENT(REPORT, XML_ENABLED): + m_xComponent->setEnabled(IsXMLToken(aIter, XML_TRUE)); + break; + case XML_ELEMENT(REPORT, XML_FORMULA): + m_xComponent->setFormula(ORptFilter::convertFormula(aIter.toString())); + break; + case XML_ELEMENT(REPORT, XML_STYLE_NAME): + m_sStyleName = aIter.toString(); + break; + default: + XMLOFF_WARN_UNKNOWN("reportdesign", aIter); + break; + } + } + } + catch(Exception&) + { + TOOLS_WARN_EXCEPTION( "reportdesign", "Exception caught while filling the report definition props"); + } +} + + +OXMLFormatCondition::~OXMLFormatCondition() +{ +} + +void OXMLFormatCondition::endFastElement(sal_Int32 ) +{ + OXMLHelper::copyStyleElements(m_rImport.isOldFormat(),m_sStyleName,GetImport().GetAutoStyles(),m_xComponent); +} + +} // namespace rptxml + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/reportdesign/source/filter/xml/xmlFormatCondition.hxx b/reportdesign/source/filter/xml/xmlFormatCondition.hxx new file mode 100644 index 000000000..56bd5602f --- /dev/null +++ b/reportdesign/source/filter/xml/xmlFormatCondition.hxx @@ -0,0 +1,50 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLFORMATCONDITION_HXX +#define INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLFORMATCONDITION_HXX + +#include +#include + +namespace rptxml +{ + class ORptFilter; + class OXMLFormatCondition : public SvXMLImportContext + { + ORptFilter& m_rImport; + OUString m_sStyleName; + css::uno::Reference< css::report::XFormatCondition > m_xComponent; + OXMLFormatCondition(const OXMLFormatCondition&) = delete; + void operator =(const OXMLFormatCondition&) = delete; + public: + + OXMLFormatCondition( ORptFilter& rImport, + const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList + ,const css::uno::Reference< css::report::XFormatCondition >& _xComponent + ); + virtual ~OXMLFormatCondition() override; + virtual void SAL_CALL endFastElement(sal_Int32 nElement) override; + }; + +} // namespace rptxml + + +#endif // INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLFORMATCONDITION_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/reportdesign/source/filter/xml/xmlFormattedField.cxx b/reportdesign/source/filter/xml/xmlFormattedField.cxx new file mode 100644 index 000000000..b7fd48ae2 --- /dev/null +++ b/reportdesign/source/filter/xml/xmlFormattedField.cxx @@ -0,0 +1,77 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#include "xmlFormattedField.hxx" +#include "xmlfilter.hxx" +#include +#include +#include +#include + + +namespace rptxml +{ + using namespace ::com::sun::star; + using namespace xml::sax; + +OXMLFormattedField::OXMLFormattedField( ORptFilter& rImport + ,const uno::Reference< xml::sax::XFastAttributeList > & _xAttrList + ,const uno::Reference< XFormattedField > & _xComponent + ,OXMLTable* _pContainer + ,bool _bPageCount) : + OXMLReportElementBase( rImport,_xComponent,_pContainer) +{ + OSL_ENSURE(m_xReportComponent.is(),"Component is NULL!"); + + try + { + for (auto &aIter : sax_fastparser::castToFastAttributeList( _xAttrList )) + { + switch( aIter.getToken() ) + { + case XML_ELEMENT(REPORT, XML_FORMULA): + _xComponent->setDataField(ORptFilter::convertFormula(aIter.toString())); + break; + case XML_ELEMENT(REPORT, XML_SELECT_PAGE): + _xComponent->setDataField("rpt:PageNumber()"); + break; + default: + XMLOFF_WARN_UNKNOWN("reportdesign", aIter); + break; + } + } + if ( _bPageCount ) + { + _xComponent->setDataField("rpt:PageCount()"); + } + } + catch(Exception&) + { + TOOLS_WARN_EXCEPTION( "reportdesign", "Exception caught while filling the report definition props"); + } +} + +OXMLFormattedField::~OXMLFormattedField() +{ +} + + +} // namespace rptxml + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/reportdesign/source/filter/xml/xmlFormattedField.hxx b/reportdesign/source/filter/xml/xmlFormattedField.hxx new file mode 100644 index 000000000..b181810f2 --- /dev/null +++ b/reportdesign/source/filter/xml/xmlFormattedField.hxx @@ -0,0 +1,47 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLFORMATTEDFIELD_HXX +#define INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLFORMATTEDFIELD_HXX + +#include "xmlReportElementBase.hxx" +#include + +namespace rptxml +{ + class ORptFilter; + class OXMLFormattedField : public OXMLReportElementBase + { + OXMLFormattedField(const OXMLFormattedField&) = delete; + void operator =(const OXMLFormattedField&) = delete; + public: + + OXMLFormattedField( ORptFilter& rImport + ,const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList + ,const css::uno::Reference< css::report::XFormattedField >& _xComponent + ,OXMLTable* _pContainer + ,bool _bPageCount); + virtual ~OXMLFormattedField() override; + }; + +} // namespace rptxml + + +#endif // INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLFORMATTEDFIELD_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/reportdesign/source/filter/xml/xmlFunction.cxx b/reportdesign/source/filter/xml/xmlFunction.cxx new file mode 100644 index 000000000..31df344be --- /dev/null +++ b/reportdesign/source/filter/xml/xmlFunction.cxx @@ -0,0 +1,115 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#include "xmlFunction.hxx" +#include "xmlfilter.hxx" +#include +#include +#include +#include + +namespace rptxml +{ + using namespace ::com::sun::star; + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::report; + using namespace ::com::sun::star::xml::sax; + + +OXMLFunction::OXMLFunction( ORptFilter& _rImport + ,const Reference< XFastAttributeList > & _xAttrList + ,const Reference< XFunctionsSupplier >& _xFunctions + ,bool _bAddToReport + ) : + SvXMLImportContext( _rImport ) + ,m_xFunctions(_xFunctions->getFunctions()) + ,m_bAddToReport(_bAddToReport) +{ + + OSL_ENSURE(m_xFunctions.is(),"Functions is NULL!"); + m_xFunction = m_xFunctions->createFunction(); + + for (auto &aIter : sax_fastparser::castToFastAttributeList( _xAttrList )) + { + try + { + switch( aIter.getToken() ) + { + case XML_ELEMENT(REPORT, XML_NAME): + m_xFunction->setName(aIter.toString()); + break; + case XML_ELEMENT(REPORT, XML_FORMULA): + m_xFunction->setFormula(ORptFilter::convertFormula(aIter.toString())); + break; + case XML_ELEMENT(REPORT, XML_PRE_EVALUATED): + m_xFunction->setPreEvaluated(IsXMLToken(aIter, XML_TRUE)); + break; + case XML_ELEMENT(REPORT, XML_INITIAL_FORMULA): + if ( !aIter.isEmpty() ) + m_xFunction->setInitialFormula(beans::Optional< OUString>(true,ORptFilter::convertFormula(aIter.toString()))); + break; + case XML_ELEMENT(REPORT, XML_DEEP_TRAVERSING): + m_xFunction->setDeepTraversing(IsXMLToken(aIter, XML_TRUE)); + break; + default: + XMLOFF_WARN_UNKNOWN("reportdesign", aIter); + break; + } + } + catch(const Exception&) + { + TOOLS_WARN_EXCEPTION( "reportdesign", "Exception caught while putting Function props!"); + } + } +} + + +OXMLFunction::~OXMLFunction() +{ +} + +ORptFilter& OXMLFunction::GetOwnImport() +{ + return static_cast(GetImport()); +} + +void OXMLFunction::endFastElement(sal_Int32 ) +{ + if ( m_bAddToReport ) + { + GetOwnImport().insertFunction(m_xFunction); + m_xFunction.clear(); + } + else + { + try + { + m_xFunctions->insertByIndex(m_xFunctions->getCount(),uno::Any(m_xFunction)); + m_xFunction.clear(); + }catch(uno::Exception&) + { + TOOLS_WARN_EXCEPTION( "reportdesign", ""); + } + } +} + + +} // namespace rptxml + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/reportdesign/source/filter/xml/xmlFunction.hxx b/reportdesign/source/filter/xml/xmlFunction.hxx new file mode 100644 index 000000000..fbbc38e3e --- /dev/null +++ b/reportdesign/source/filter/xml/xmlFunction.hxx @@ -0,0 +1,57 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLFUNCTION_HXX +#define INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLFUNCTION_HXX + +#include +#include +#include + + +namespace rptxml +{ + class ORptFilter; + class OXMLFunction final : public SvXMLImportContext + { + css::uno::Reference< css::report::XFunctions > m_xFunctions; + css::uno::Reference< css::report::XFunction > m_xFunction; + bool m_bAddToReport; + + ORptFilter& GetOwnImport(); + + OXMLFunction(const OXMLFunction&); + OXMLFunction& operator =(const OXMLFunction&); + public: + + OXMLFunction( ORptFilter& rImport + ,const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList + ,const css::uno::Reference< css::report::XFunctionsSupplier >& _xFunctions + ,bool _bAddToReport = false + ); + virtual ~OXMLFunction() override; + + virtual void SAL_CALL endFastElement(sal_Int32 nElement) override; + }; + +} // namespace rptxml + + +#endif // RPT_XMLFunction_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/reportdesign/source/filter/xml/xmlGroup.cxx b/reportdesign/source/filter/xml/xmlGroup.cxx new file mode 100644 index 000000000..249a27229 --- /dev/null +++ b/reportdesign/source/filter/xml/xmlGroup.cxx @@ -0,0 +1,246 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#include "xmlGroup.hxx" +#include "xmlSection.hxx" +#include "xmlFunction.hxx" +#include "xmlfilter.hxx" +#include +#include +#include +#include +#include "xmlHelper.hxx" +#include "xmlEnums.hxx" +#include +#include +#include +#include +#include + +namespace rptxml +{ + using namespace ::com::sun::star; + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::report; + using namespace ::com::sun::star::xml::sax; + + static sal_Int16 lcl_getKeepTogetherOption(std::string_view _sValue) + { + sal_Int16 nRet = report::KeepTogether::NO; + const SvXMLEnumMapEntry* aXML_EnumMap = OXMLHelper::GetKeepTogetherOptions(); + (void)SvXMLUnitConverter::convertEnum( nRet, _sValue, aXML_EnumMap ); + return nRet; + } + +OXMLGroup::OXMLGroup( ORptFilter& _rImport + ,const Reference< XFastAttributeList > & _xAttrList + ) : + SvXMLImportContext( _rImport ) +{ + + m_xGroups = _rImport.getReportDefinition()->getGroups(); + OSL_ENSURE(m_xGroups.is(),"Groups is NULL!"); + m_xGroup = m_xGroups->createGroup(); + + m_xGroup->setSortAscending(false);// the default value has to be set + for (auto &aIter : sax_fastparser::castToFastAttributeList( _xAttrList )) + { + try + { + switch( aIter.getToken() ) + { + case XML_ELEMENT(REPORT, XML_START_NEW_COLUMN): + m_xGroup->setStartNewColumn(IsXMLToken(aIter, XML_TRUE)); + break; + case XML_ELEMENT(REPORT, XML_RESET_PAGE_NUMBER): + m_xGroup->setResetPageNumber(IsXMLToken(aIter, XML_TRUE)); + break; + case XML_ELEMENT(REPORT, XML_SORT_ASCENDING): + m_xGroup->setSortAscending(IsXMLToken(aIter, XML_TRUE)); + break; + case XML_ELEMENT(REPORT, XML_GROUP_EXPRESSION): + { + OUString sValue = aIter.toString(); + sal_Int32 nLen = sValue.getLength(); + if ( nLen ) + { + + static const char s_sChanged[] = "rpt:HASCHANGED(\""; + sal_Int32 nPos = sValue.indexOf(s_sChanged); + if ( nPos == -1 ) + nPos = 5; + else + { + nPos = strlen(s_sChanged); + static const char s_sQuote[] = "\"\""; + sal_Int32 nIndex = sValue.indexOf(s_sQuote,nPos); + while ( nIndex > -1 ) + { + sValue = sValue.replaceAt(nIndex,2, u"\""); + nIndex = sValue.indexOf(s_sQuote,nIndex+2); + } + nLen = sValue.getLength() - 1; + } + sValue = sValue.copy(nPos,nLen-nPos-1); + const ORptFilter::TGroupFunctionMap& aFunctions = _rImport.getFunctions(); + ORptFilter::TGroupFunctionMap::const_iterator aFind = aFunctions.find(sValue); + if ( aFind != aFunctions.end() ) + { + const OUString sCompleteFormula = aFind->second->getFormula(); + OUString sExpression = sCompleteFormula.getToken(1,'['); + sExpression = sExpression.getToken(0,']'); + sal_Int32 nIndex = 0; + const std::u16string_view sFormula = o3tl::getToken(sCompleteFormula, 0,'(',nIndex); + ::sal_Int16 nGroupOn = report::GroupOn::DEFAULT; + + if ( sFormula == u"rpt:LEFT") + { + nGroupOn = report::GroupOn::PREFIX_CHARACTERS; + std::u16string_view sInterval = o3tl::getToken(sCompleteFormula, 1,';',nIndex); + sInterval = o3tl::getToken(sInterval, 0,')'); + m_xGroup->setGroupInterval(o3tl::toInt32(sInterval)); + } + else if ( sFormula == u"rpt:YEAR") + nGroupOn = report::GroupOn::YEAR; + else if ( sFormula == u"rpt:MONTH") + { + nGroupOn = report::GroupOn::MONTH; + } + else if ( sCompleteFormula.matchIgnoreAsciiCase("rpt:INT((MONTH",0) + && sCompleteFormula.endsWithIgnoreAsciiCase("-1)/3)+1") ) + { + nGroupOn = report::GroupOn::QUARTAL; + } + else if ( sFormula == u"rpt:WEEK") + nGroupOn = report::GroupOn::WEEK; + else if ( sFormula == u"rpt:DAY") + nGroupOn = report::GroupOn::DAY; + else if ( sFormula == u"rpt:HOUR") + nGroupOn = report::GroupOn::HOUR; + else if ( sFormula == u"rpt:MINUTE") + nGroupOn = report::GroupOn::MINUTE; + else if ( sFormula == u"rpt:INT") + { + nGroupOn = report::GroupOn::INTERVAL; + _rImport.removeFunction(sExpression); + sExpression = sExpression.copy(OUString("INT_count_").getLength()); + OUString sInterval = sCompleteFormula.getToken(1,'/'); + sInterval = sInterval.getToken(0,')'); + m_xGroup->setGroupInterval(sInterval.toInt32()); + } + + m_xGroup->setGroupOn(nGroupOn); + + _rImport.removeFunction(sValue); + sValue = sExpression; + } + m_xGroup->setExpression(sValue); + } + } + break; + case XML_ELEMENT(REPORT, XML_KEEP_TOGETHER): + m_xGroup->setKeepTogether(lcl_getKeepTogetherOption(aIter.toView())); + break; + default: + XMLOFF_WARN_UNKNOWN("reportdesign", aIter); + break; + } + } + catch(const Exception&) + { + TOOLS_WARN_EXCEPTION( "reportdesign", "Exception caught while putting group props!"); + } + } +} + + +OXMLGroup::~OXMLGroup() +{ + +} + +css::uno::Reference< css::xml::sax::XFastContextHandler > OXMLGroup::createFastChildContext( + sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) +{ + css::uno::Reference< css::xml::sax::XFastContextHandler > xContext; + ORptFilter& rImport = GetOwnImport(); + + switch( nElement ) + { + case XML_ELEMENT(REPORT, XML_FUNCTION): + { + rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + xContext = new OXMLFunction( rImport,xAttrList,m_xGroup); + } + break; + case XML_ELEMENT(REPORT, XML_GROUP_HEADER): + { + rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + m_xGroup->setHeaderOn(true); + xContext = new OXMLSection( rImport,xAttrList,m_xGroup->getHeader()); + } + break; + case XML_ELEMENT(REPORT, XML_GROUP): + rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + xContext = new OXMLGroup( rImport,xAttrList); + break; + case XML_ELEMENT(REPORT, XML_DETAIL): + { + rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + Reference xComponent = rImport.getReportDefinition(); + xContext = new OXMLSection( rImport,xAttrList, xComponent->getDetail()); + } + break; + + case XML_ELEMENT(REPORT, XML_GROUP_FOOTER): + { + rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + m_xGroup->setFooterOn(true); + xContext = new OXMLSection( rImport,xAttrList,m_xGroup->getFooter()); + } + break; + default: + break; + } + + return xContext; +} + +ORptFilter& OXMLGroup::GetOwnImport() +{ + return static_cast(GetImport()); +} + +void OXMLGroup::endFastElement(sal_Int32 ) +{ + try + { + // the group elements end in the reverse order + m_xGroups->insertByIndex(0,uno::Any(m_xGroup)); + }catch(uno::Exception&) + { + TOOLS_WARN_EXCEPTION( "reportdesign", ""); + } +} + + +} // namespace rptxml + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/reportdesign/source/filter/xml/xmlGroup.hxx b/reportdesign/source/filter/xml/xmlGroup.hxx new file mode 100644 index 000000000..92500cc21 --- /dev/null +++ b/reportdesign/source/filter/xml/xmlGroup.hxx @@ -0,0 +1,55 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLGROUP_HXX +#define INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLGROUP_HXX + +#include +#include + +namespace rptxml +{ + class ORptFilter; + class OXMLGroup final : public SvXMLImportContext + { + css::uno::Reference< css::report::XGroups > m_xGroups; + css::uno::Reference< css::report::XGroup > m_xGroup; + + ORptFilter& GetOwnImport(); + + OXMLGroup(const OXMLGroup&); + OXMLGroup& operator =(const OXMLGroup&); + public: + + OXMLGroup( ORptFilter& rImport + ,const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList + ); + virtual ~OXMLGroup() override; + + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( + sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override; + + virtual void SAL_CALL endFastElement(sal_Int32 nElement) override; + }; + +} // namespace rptxml + + +#endif // INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLGROUP_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/reportdesign/source/filter/xml/xmlHelper.cxx b/reportdesign/source/filter/xml/xmlHelper.cxx new file mode 100644 index 000000000..491f3e650 --- /dev/null +++ b/reportdesign/source/filter/xml/xmlHelper.cxx @@ -0,0 +1,382 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#include "xmlHelper.hxx" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "xmlEnums.hxx" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define XML_RPT_ALIGNMENT (XML_DB_TYPES_START+1) +namespace rptxml +{ + using namespace ::xmloff::token; + using namespace ::com::sun::star::awt; + using namespace ::com::sun::star; + using namespace ::com::sun::star::sdb; + using namespace ::com::sun::star::form; + using namespace ::com::sun::star::beans; +OPropertyHandlerFactory::OPropertyHandlerFactory() +{ +} + +OPropertyHandlerFactory::~OPropertyHandlerFactory() +{ +} + +const XMLPropertyHandler* OPropertyHandlerFactory::GetPropertyHandler(sal_Int32 _nType) const +{ + const XMLPropertyHandler* pHandler = nullptr; + sal_Int32 nType = _nType; + nType &= MID_FLAG_MASK; + + switch(nType) + { + case XML_RPT_ALIGNMENT: + { + static SvXMLEnumMapEntry const pXML_VerticalAlign_Enum[] = + { + { XML_TOP, style::VerticalAlignment_TOP }, + { XML_MIDDLE, style::VerticalAlignment_MIDDLE }, + { XML_BOTTOM, style::VerticalAlignment_BOTTOM }, + { XML_TOKEN_INVALID, style::VerticalAlignment(0) } + }; + + pHandler = new XMLEnumPropertyHdl( pXML_VerticalAlign_Enum ); + } + break; + case XML_SD_TYPES_START+34: // XML_SD_TYPE_IMAGE_SCALE_MODE + pHandler = new xmloff::ImageScaleModeHandler(); + break; + default: + break; + } + + if ( !pHandler ) + pHandler = OControlPropertyHandlerFactory::GetPropertyHandler(_nType); + else + PutHdlCache(nType, pHandler); + return pHandler; +} + +#define MAP_CONST_T_ASCII( name, prefix, token, type, context ) { name, XML_NAMESPACE_##prefix, XML_##token, type|XML_TYPE_PROP_TABLE, context, SvtSaveOptions::ODFSVER_010, false } +#define MAP_CONST_P_ASCII( name, prefix, token, type, context ) { name, XML_NAMESPACE_##prefix, XML_##token, type|XML_TYPE_PROP_PARAGRAPH, context, SvtSaveOptions::ODFSVER_010, false } +#define MAP_CONST_S( name, prefix, token, type, context ) { name, XML_NAMESPACE_##prefix, XML_##token, type|XML_TYPE_PROP_SECTION, context, SvtSaveOptions::ODFSVER_010, false } +#define MAP_CONST_C_ASCII( name, prefix, token, type, context ) { name, XML_NAMESPACE_##prefix, XML_##token, type|XML_TYPE_PROP_TABLE_CELL, context, SvtSaveOptions::ODFSVER_010, false } +#define MAP_END() { nullptr, 0, XML_TOKEN_INVALID, 0 ,0, SvtSaveOptions::ODFSVER_010, false} + +rtl::Reference < XMLPropertySetMapper > OXMLHelper::GetCellStylePropertyMap(bool _bOldFormat, bool bForExport) +{ + if ( _bOldFormat ) + { + static const XMLPropertyMapEntry s_aXMLCellStylesProperties[] = + { + MAP_CONST_C_ASCII( PROPERTY_FORMATKEY, STYLE, DATA_STYLE_NAME, XML_TYPE_NUMBER | MID_FLAG_SPECIAL_ITEM, CTF_RPT_NUMBERFORMAT ), + + MAP_CONST_C_ASCII( PROPERTY_CONTROLBACKGROUND, + FO, BACKGROUND_COLOR, XML_TYPE_COLORTRANSPARENT|MID_FLAG_MULTI_PROPERTY, 0 ), + MAP_CONST_C_ASCII( PROPERTY_VERTICALALIGN, STYLE, VERTICAL_ALIGN, XML_RPT_ALIGNMENT, 0 ), + MAP_CONST_C_ASCII( PROPERTY_CONTROLBACKGROUNDTRANSPARENT, + FO, BACKGROUND_COLOR, XML_TYPE_ISTRANSPARENT|MID_FLAG_MERGE_ATTRIBUTE, 0 ), + MAP_CONST_P_ASCII( PROPERTY_CONTROLBACKGROUND, + FO, BACKGROUND_COLOR, XML_TYPE_COLORTRANSPARENT|MID_FLAG_MULTI_PROPERTY, 0 ), + MAP_CONST_P_ASCII( PROPERTY_CONTROLBACKGROUNDTRANSPARENT, + FO, BACKGROUND_COLOR, XML_TYPE_ISTRANSPARENT|MID_FLAG_MERGE_ATTRIBUTE, 0 ), + MAP_CONST_C_ASCII( "BorderLeft", FO, BORDER_LEFT, XML_TYPE_BORDER, 0 ), + MAP_CONST_C_ASCII( "BorderRight", FO, BORDER_RIGHT, XML_TYPE_BORDER, 0 ), + MAP_CONST_C_ASCII( "BorderTop", FO, BORDER_TOP, XML_TYPE_BORDER, 0 ), + MAP_CONST_C_ASCII( "BorderBottom", FO, BORDER_BOTTOM, XML_TYPE_BORDER, 0 ), + MAP_END() + }; + return new XMLPropertySetMapper(s_aXMLCellStylesProperties,new OPropertyHandlerFactory(), bForExport); + } + else + { + static const XMLPropertyMapEntry s_aXMLCellStylesProperties[] = + { + MAP_CONST_C_ASCII( PROPERTY_FORMATKEY, STYLE, DATA_STYLE_NAME, XML_TYPE_NUMBER | MID_FLAG_SPECIAL_ITEM, CTF_RPT_NUMBERFORMAT ), + + MAP_CONST_C_ASCII( PROPERTY_CONTROLBACKGROUND, + FO, BACKGROUND_COLOR, XML_TYPE_COLORTRANSPARENT|MID_FLAG_MULTI_PROPERTY, 0 ), + MAP_CONST_C_ASCII( PROPERTY_CONTROLBACKGROUNDTRANSPARENT, + FO, BACKGROUND_COLOR, XML_TYPE_ISTRANSPARENT|MID_FLAG_MERGE_ATTRIBUTE, 0 ), + MAP_CONST_C_ASCII( PROPERTY_VERTICALALIGN, + STYLE, VERTICAL_ALIGN, XML_RPT_ALIGNMENT, 0 ), + MAP_CONST_C_ASCII( "BorderLeft", FO, BORDER_LEFT, XML_TYPE_BORDER, 0 ), + MAP_CONST_C_ASCII( "BorderRight", FO, BORDER_RIGHT, XML_TYPE_BORDER, 0 ), + MAP_CONST_C_ASCII( "BorderTop", FO, BORDER_TOP, XML_TYPE_BORDER, 0 ), + MAP_CONST_C_ASCII( "BorderBottom", FO, BORDER_BOTTOM, XML_TYPE_BORDER, 0 ), + MAP_END() + }; + return new XMLPropertySetMapper(s_aXMLCellStylesProperties,new OPropertyHandlerFactory(), bForExport); + } +} + +const XMLPropertyMapEntry* OXMLHelper::GetTableStyleProps() +{ + static const XMLPropertyMapEntry aXMLTableStylesProperties[] = + { + MAP_CONST_T_ASCII( PROPERTY_BACKCOLOR, FO, BACKGROUND_COLOR, XML_TYPE_COLORTRANSPARENT|MID_FLAG_MULTI_PROPERTY, 0 ), + MAP_CONST_T_ASCII( PROPERTY_BACKTRANSPARENT,FO, BACKGROUND_COLOR, XML_TYPE_ISTRANSPARENT | MID_FLAG_MERGE_ATTRIBUTE, 0 ), + MAP_END() + }; + return aXMLTableStylesProperties; +} + +const XMLPropertyMapEntry* OXMLHelper::GetRowStyleProps() +{ + static const XMLPropertyMapEntry aXMLStylesProperties[] = + { + MAP_CONST_S("Height", STYLE, ROW_HEIGHT, XML_TYPE_PROP_TABLE_ROW | XML_TYPE_MEASURE, 0), + MAP_CONST_S("MinHeight", STYLE, MIN_ROW_HEIGHT, XML_TYPE_PROP_TABLE_ROW | XML_TYPE_MEASURE, 0), + MAP_END() + }; + return aXMLStylesProperties; +} + +const XMLPropertyMapEntry* OXMLHelper::GetColumnStyleProps() +{ + static const XMLPropertyMapEntry aXMLColumnStylesProperties[] = + { + MAP_CONST_S( "Width", STYLE, COLUMN_WIDTH, XML_TYPE_PROP_TABLE_COLUMN|XML_TYPE_MEASURE, 0 ), + MAP_END() + }; + return aXMLColumnStylesProperties; +} + +const SvXMLEnumMapEntry* OXMLHelper::GetReportPrintOptions() +{ + static const SvXMLEnumMapEntry s_aXML_EnumMap[] = + { + { XML_NOT_WITH_REPORT_HEADER, report::ReportPrintOption::NOT_WITH_REPORT_HEADER }, + { XML_NOT_WITH_REPORT_FOOTER, report::ReportPrintOption::NOT_WITH_REPORT_FOOTER }, + { XML_NOT_WITH_REPORT_HEADER_NOR_FOOTER, report::ReportPrintOption::NOT_WITH_REPORT_HEADER_FOOTER }, + { XML_TOKEN_INVALID, 0 } + }; + return s_aXML_EnumMap; +} + +const SvXMLEnumMapEntry* OXMLHelper::GetForceNewPageOptions() +{ + static const SvXMLEnumMapEntry s_aXML_EnumMap[] = + { + { XML_BEFORE_SECTION, report::ForceNewPage::BEFORE_SECTION }, + { XML_AFTER_SECTION, report::ForceNewPage::AFTER_SECTION }, + { XML_BEFORE_AFTER_SECTION, report::ForceNewPage::BEFORE_AFTER_SECTION }, + { XML_TOKEN_INVALID, 0 } + }; + return s_aXML_EnumMap; +} + +const SvXMLEnumMapEntry* OXMLHelper::GetKeepTogetherOptions() +{ + static const SvXMLEnumMapEntry s_aXML_EnumMap[] = + { + { XML_WHOLE_GROUP, report::KeepTogether::WHOLE_GROUP }, + { XML_WITH_FIRST_DETAIL, report::KeepTogether::WITH_FIRST_DETAIL }, + { XML_TOKEN_INVALID, 0 } + }; + return s_aXML_EnumMap; +} + +const SvXMLEnumMapEntry* OXMLHelper::GetCommandTypeOptions() +{ + static const SvXMLEnumMapEntry s_aXML_EnumMap[] = + { + { XML_TABLE, CommandType::TABLE }, + { XML_QUERY, CommandType::QUERY }, + { XML_TOKEN_INVALID, 0 } + }; + return s_aXML_EnumMap; +} + +#define PROPERTY_ID_FONTNAME 1 +#define PROPERTY_ID_FONTHEIGHT 2 +#define PROPERTY_ID_FONTWIDTH 3 +#define PROPERTY_ID_FONTSTYLENAME 4 +#define PROPERTY_ID_FONTFAMILY 5 +#define PROPERTY_ID_FONTCHARSET 6 +#define PROPERTY_ID_FONTPITCH 7 +#define PROPERTY_ID_FONTCHARWIDTH 8 +#define PROPERTY_ID_FONTWEIGHT 9 +#define PROPERTY_ID_FONTSLANT 10 +#define PROPERTY_ID_FONTUNDERLINE 11 +#define PROPERTY_ID_FONTSTRIKEOUT 12 +#define PROPERTY_ID_FONTORIENTATION 13 +#define PROPERTY_ID_FONTKERNING 14 +#define PROPERTY_ID_FONTWORDLINEMODE 15 +#define PROPERTY_ID_FONTTYPE 16 +void OXMLHelper::copyStyleElements(const bool _bOld,const OUString& _sStyleName,const SvXMLStylesContext* _pAutoStyles,const uno::Reference& _xProp) +{ + if ( !_xProp.is() || _sStyleName.isEmpty() || !_pAutoStyles ) + return; + XMLPropStyleContext* pAutoStyle = const_cast(dynamic_cast< const XMLPropStyleContext *>(_pAutoStyles->FindStyleChildContext(XmlStyleFamily::TABLE_CELL,_sStyleName))); + if ( !pAutoStyle ) + return; + + css::awt::FontDescriptor aFont; + static comphelper::PropertyMapEntry const pMap[] = + { + {OUString(PROPERTY_FONTNAME), PROPERTY_ID_FONTNAME, cppu::UnoType::get() ,PropertyAttribute::BOUND,0}, + {OUString(PROPERTY_CHARFONTHEIGHT), PROPERTY_ID_FONTHEIGHT, cppu::UnoType::get() ,PropertyAttribute::BOUND,0}, + {OUString(PROPERTY_FONTWIDTH), PROPERTY_ID_FONTWIDTH, cppu::UnoType::get() ,PropertyAttribute::BOUND,0}, + {OUString(PROPERTY_FONTSTYLENAME), PROPERTY_ID_FONTSTYLENAME, cppu::UnoType::get() ,PropertyAttribute::BOUND,0}, + {OUString(PROPERTY_FONTFAMILY), PROPERTY_ID_FONTFAMILY, cppu::UnoType::get() ,PropertyAttribute::BOUND,0}, + {OUString(PROPERTY_FONTCHARSET), PROPERTY_ID_FONTCHARSET, cppu::UnoType::get() ,PropertyAttribute::BOUND,0}, + {OUString(PROPERTY_FONTPITCH), PROPERTY_ID_FONTPITCH, cppu::UnoType::get() ,PropertyAttribute::BOUND,0}, + {OUString(PROPERTY_FONTCHARWIDTH), PROPERTY_ID_FONTCHARWIDTH, cppu::UnoType::get(),PropertyAttribute::BOUND,0}, + {OUString(PROPERTY_FONTWEIGHT), PROPERTY_ID_FONTWEIGHT, cppu::UnoType::get() ,PropertyAttribute::BOUND,0}, + {OUString(PROPERTY_CHARPOSTURE), PROPERTY_ID_FONTSLANT, cppu::UnoType::get() ,PropertyAttribute::BOUND,0}, + {OUString(PROPERTY_FONTUNDERLINE), PROPERTY_ID_FONTUNDERLINE, cppu::UnoType::get() ,PropertyAttribute::BOUND,0}, + {OUString(PROPERTY_CHARSTRIKEOUT), PROPERTY_ID_FONTSTRIKEOUT, cppu::UnoType::get() ,PropertyAttribute::BOUND,0}, + {OUString(PROPERTY_FONTORIENTATION), PROPERTY_ID_FONTORIENTATION, cppu::UnoType::get() ,PropertyAttribute::BOUND,0}, + {OUString(PROPERTY_FONTKERNING), PROPERTY_ID_FONTKERNING, cppu::UnoType::get() ,PropertyAttribute::BOUND,0}, + {OUString(PROPERTY_CHARWORDMODE), PROPERTY_ID_FONTWORDLINEMODE, cppu::UnoType::get() ,PropertyAttribute::BOUND,0}, + {OUString(PROPERTY_FONTTYPE), PROPERTY_ID_FONTTYPE, cppu::UnoType::get() ,PropertyAttribute::BOUND,0}, + }; + try + { + pAutoStyle->FillPropertySet(_xProp); + if ( _bOld && _xProp->getPropertySetInfo()->hasPropertyByName(PROPERTY_CHARHIDDEN) ) + _xProp->setPropertyValue(PROPERTY_CHARHIDDEN,uno::Any(false)); + + uno::Reference xProp = comphelper::GenericPropertySet_CreateInstance(new comphelper::PropertySetInfo(pMap)); + pAutoStyle->FillPropertySet(xProp); + xProp->getPropertyValue(PROPERTY_FONTNAME) >>= aFont.Name; + xProp->getPropertyValue(PROPERTY_CHARFONTHEIGHT) >>= aFont.Height; + xProp->getPropertyValue(PROPERTY_FONTWIDTH) >>= aFont.Width; + xProp->getPropertyValue(PROPERTY_FONTSTYLENAME) >>= aFont.StyleName; + xProp->getPropertyValue(PROPERTY_FONTFAMILY) >>= aFont.Family; + xProp->getPropertyValue(PROPERTY_FONTCHARSET) >>= aFont.CharSet; + xProp->getPropertyValue(PROPERTY_FONTPITCH) >>= aFont.Pitch; + xProp->getPropertyValue(PROPERTY_FONTCHARWIDTH) >>= aFont.CharacterWidth; + xProp->getPropertyValue(PROPERTY_FONTWEIGHT) >>= aFont.Weight; + xProp->getPropertyValue(PROPERTY_CHARPOSTURE) >>= aFont.Slant; + xProp->getPropertyValue(PROPERTY_FONTUNDERLINE) >>= aFont.Underline; + xProp->getPropertyValue(PROPERTY_CHARSTRIKEOUT) >>= aFont.Strikeout; + xProp->getPropertyValue(PROPERTY_FONTORIENTATION) >>= aFont.Orientation; + xProp->getPropertyValue(PROPERTY_FONTKERNING) >>= aFont.Kerning; + xProp->getPropertyValue(PROPERTY_CHARWORDMODE) >>= aFont.WordLineMode; + xProp->getPropertyValue(PROPERTY_FONTTYPE) >>= aFont.Type; + uno::Reference xReportControlModel(_xProp,uno::UNO_QUERY); + if ( xReportControlModel.is() && !aFont.Name.isEmpty() ) + { + try + { + xReportControlModel->setFontDescriptor(aFont); + } + catch(const beans::UnknownPropertyException &){} + } + } + catch(uno::Exception&) + { + TOOLS_WARN_EXCEPTION( "reportdesign", "OXMLHelper::copyStyleElements"); + } +} + +uno::Reference OXMLHelper::createBorderPropertySet() +{ + static comphelper::PropertyMapEntry const pMap[] = + { + {OUString(PROPERTY_BORDERLEFT), 0, cppu::UnoType::get(),PropertyAttribute::BOUND,0}, + {OUString(PROPERTY_BORDERRIGHT), 1, cppu::UnoType::get(),PropertyAttribute::BOUND,0}, + {OUString(PROPERTY_BORDERTOP), 2, cppu::UnoType::get(),PropertyAttribute::BOUND,0}, + {OUString(PROPERTY_BORDERBOTTOM), 3, cppu::UnoType::get(),PropertyAttribute::BOUND,0}, + }; + return comphelper::GenericPropertySet_CreateInstance(new comphelper::PropertySetInfo(pMap)); +} + +std::unique_ptr OXMLHelper::GetReportElemTokenMap() +{ + static const SvXMLTokenMapEntry aElemTokenMap[]= + { + { XML_NAMESPACE_REPORT, XML_REPORT_HEADER, XML_TOK_REPORT_HEADER }, + { XML_NAMESPACE_REPORT, XML_PAGE_HEADER , XML_TOK_PAGE_HEADER }, + { XML_NAMESPACE_REPORT, XML_GROUP, XML_TOK_GROUP }, + { XML_NAMESPACE_REPORT, XML_DETAIL , XML_TOK_DETAIL }, + { XML_NAMESPACE_REPORT, XML_PAGE_FOOTER , XML_TOK_PAGE_FOOTER }, + { XML_NAMESPACE_REPORT, XML_REPORT_FOOTER, XML_TOK_REPORT_FOOTER }, + { XML_NAMESPACE_REPORT, XML_HEADER_ON_NEW_PAGE, XML_TOK_HEADER_ON_NEW_PAGE }, + { XML_NAMESPACE_REPORT, XML_FOOTER_ON_NEW_PAGE, XML_TOK_FOOTER_ON_NEW_PAGE }, + { XML_NAMESPACE_REPORT, XML_COMMAND_TYPE, XML_TOK_COMMAND_TYPE }, + { XML_NAMESPACE_REPORT, XML_COMMAND, XML_TOK_COMMAND }, + { XML_NAMESPACE_REPORT, XML_FILTER, XML_TOK_FILTER }, + { XML_NAMESPACE_REPORT, XML_CAPTION, XML_TOK_CAPTION }, + { XML_NAMESPACE_REPORT, XML_ESCAPE_PROCESSING, XML_TOK_ESCAPE_PROCESSING }, + { XML_NAMESPACE_REPORT, XML_FUNCTION, XML_TOK_REPORT_FUNCTION }, + { XML_NAMESPACE_OFFICE, XML_MIMETYPE, XML_TOK_REPORT_MIMETYPE }, + { XML_NAMESPACE_DRAW, XML_NAME, XML_TOK_REPORT_NAME }, + { XML_NAMESPACE_REPORT, XML_MASTER_DETAIL_FIELDS, XML_TOK_MASTER_DETAIL_FIELDS }, + { XML_NAMESPACE_DRAW, XML_FRAME, XML_TOK_SUB_FRAME }, + { XML_NAMESPACE_OFFICE, XML_BODY, XML_TOK_SUB_BODY }, + XML_TOKEN_MAP_END + }; + return std::make_unique( aElemTokenMap ); +} + +std::unique_ptr OXMLHelper::GetSubDocumentElemTokenMap() +{ + static const SvXMLTokenMapEntry aElemTokenMap[]= + { + { XML_NAMESPACE_REPORT, XML_MASTER_DETAIL_FIELD, XML_TOK_MASTER_DETAIL_FIELD}, + { XML_NAMESPACE_REPORT, XML_MASTER, XML_TOK_MASTER}, + { XML_NAMESPACE_REPORT, XML_DETAIL, XML_TOK_SUB_DETAIL}, + XML_TOKEN_MAP_END + }; + return std::make_unique( aElemTokenMap ); +} + +const SvXMLEnumMapEntry* OXMLHelper::GetImageScaleOptions() +{ + static const SvXMLEnumMapEntry s_aXML_EnumMap[] = + { + { XML_ISOTROPIC, awt::ImageScaleMode::ISOTROPIC }, + { XML_ANISOTROPIC, awt::ImageScaleMode::ANISOTROPIC }, + { XML_TOKEN_INVALID, 0 } + }; + return s_aXML_EnumMap; +} + + +} // rptxml + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/reportdesign/source/filter/xml/xmlHelper.hxx b/reportdesign/source/filter/xml/xmlHelper.hxx new file mode 100644 index 000000000..3a9ec4668 --- /dev/null +++ b/reportdesign/source/filter/xml/xmlHelper.hxx @@ -0,0 +1,75 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLHELPER_HXX +#define INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLHELPER_HXX + +#include +#include +#include +#include + +#include + +#define CTF_RPT_NUMBERFORMAT (XML_DB_CTF_START + 1) + + +class SvXMLStylesContext; +class SvXMLTokenMap; +namespace rptxml +{ + class OPropertyHandlerFactory : public ::xmloff::OControlPropertyHandlerFactory + { + OPropertyHandlerFactory(const OPropertyHandlerFactory&) = delete; + void operator =(const OPropertyHandlerFactory&) = delete; + public: + OPropertyHandlerFactory(); + virtual ~OPropertyHandlerFactory() override; + + virtual const XMLPropertyHandler* GetPropertyHandler(sal_Int32 _nType) const override; + }; + + class OXMLHelper + { + public: + static rtl::Reference < XMLPropertySetMapper > GetCellStylePropertyMap(bool _bOldFormat, bool bForExport); + + static const SvXMLEnumMapEntry* GetReportPrintOptions(); + static const SvXMLEnumMapEntry* GetForceNewPageOptions(); + static const SvXMLEnumMapEntry* GetKeepTogetherOptions(); + static const SvXMLEnumMapEntry* GetCommandTypeOptions(); + static const SvXMLEnumMapEntry* GetImageScaleOptions(); + + static const XMLPropertyMapEntry* GetTableStyleProps(); + static const XMLPropertyMapEntry* GetColumnStyleProps(); + + static const XMLPropertyMapEntry* GetRowStyleProps(); + + static void copyStyleElements(const bool _bOld,const OUString& _sStyleName,const SvXMLStylesContext* _pAutoStyles,const css::uno::Reference< css::beans::XPropertySet>& _xProp); + static css::uno::Reference< css::beans::XPropertySet> createBorderPropertySet(); + + static std::unique_ptr GetReportElemTokenMap(); + static std::unique_ptr GetSubDocumentElemTokenMap(); + + }; + +} // rptxml + +#endif // INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLHELPER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/reportdesign/source/filter/xml/xmlImage.cxx b/reportdesign/source/filter/xml/xmlImage.cxx new file mode 100644 index 000000000..c4310d3a8 --- /dev/null +++ b/reportdesign/source/filter/xml/xmlImage.cxx @@ -0,0 +1,106 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#include "xmlImage.hxx" +#include "xmlfilter.hxx" +#include +#include +#include +#include "xmlHelper.hxx" +#include +#include +#include +#include + +#include + +namespace rptxml +{ + using namespace ::com::sun::star; + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::xml::sax; + + +OXMLImage::OXMLImage( ORptFilter& rImport, + const Reference< XFastAttributeList > & _xAttrList + ,const Reference< XImageControl > & _xComponent + ,OXMLTable* _pContainer) : + OXMLReportElementBase( rImport,_xComponent,_pContainer) +{ + + OSL_ENSURE(m_xReportComponent.is(),"Component is NULL!"); + + try + { + for (auto &aIter : sax_fastparser::castToFastAttributeList( _xAttrList )) + { + switch( aIter.getToken() ) + { + case XML_ELEMENT(FORM, XML_IMAGE_DATA): + { + SvtPathOptions aPathOptions; + OUString sValue = aIter.toString(); + sValue = aPathOptions.SubstituteVariable(sValue); + _xComponent->setImageURL(rImport.GetAbsoluteReference( sValue )); + break; + } + case XML_ELEMENT(REPORT, XML_PRESERVE_IRI): + _xComponent->setPreserveIRI(IsXMLToken(aIter, XML_TRUE)); + break; + case XML_ELEMENT(REPORT, XML_SCALE): + { + sal_Int16 nRet = awt::ImageScaleMode::NONE; + if ( IsXMLToken(aIter, XML_TRUE) ) + { + nRet = awt::ImageScaleMode::ANISOTROPIC; + } + else + { + const SvXMLEnumMapEntry* aXML_EnumMap = OXMLHelper::GetImageScaleOptions(); + bool bConvertOk = SvXMLUnitConverter::convertEnum( nRet, aIter.toView(), aXML_EnumMap ); + SAL_WARN_IF(!bConvertOk, "reportdesign", "convertEnum failed"); + } + _xComponent->setScaleMode( nRet ); + break; + } + case XML_ELEMENT(REPORT, XML_FORMULA): + _xComponent->setDataField(ORptFilter::convertFormula(aIter.toString())); + break; + default: + XMLOFF_WARN_UNKNOWN("reportdesign", aIter); + break; + } + } + } + catch(Exception&) + { + TOOLS_WARN_EXCEPTION( "reportdesign", "Exception caught while filling the image props"); + } +} + + +OXMLImage::~OXMLImage() +{ + +} + + +} // namespace rptxml + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/reportdesign/source/filter/xml/xmlImage.hxx b/reportdesign/source/filter/xml/xmlImage.hxx new file mode 100644 index 000000000..32be8a8ac --- /dev/null +++ b/reportdesign/source/filter/xml/xmlImage.hxx @@ -0,0 +1,46 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLIMAGE_HXX +#define INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLIMAGE_HXX + +#include "xmlReportElementBase.hxx" +#include + +namespace rptxml +{ + class ORptFilter; + class OXMLImage : public OXMLReportElementBase + { + OXMLImage(const OXMLImage&) = delete; + void operator =(const OXMLImage&) = delete; + public: + + OXMLImage( ORptFilter& rImport, + const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList + ,const css::uno::Reference< css::report::XImageControl >& _xComponent + ,OXMLTable* _pContainer); + virtual ~OXMLImage() override; + }; + +} // namespace rptxml + + +#endif // INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLIMAGE_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/reportdesign/source/filter/xml/xmlImportDocumentHandler.cxx b/reportdesign/source/filter/xml/xmlImportDocumentHandler.cxx new file mode 100644 index 000000000..edb4dcaaa --- /dev/null +++ b/reportdesign/source/filter/xml/xmlImportDocumentHandler.cxx @@ -0,0 +1,385 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include +#include "xmlImportDocumentHandler.hxx" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "xmlHelper.hxx" +#include "xmlEnums.hxx" +#include "xmlExportDocumentHandler.hxx" + +namespace rptxml +{ +using namespace ::com::sun::star; +using namespace ::xmloff::token; + +ImportDocumentHandler::ImportDocumentHandler(uno::Reference< uno::XComponentContext > const & context) + :m_bImportedChart( false ) + ,m_xContext(context) +{ +} + +ImportDocumentHandler::~ImportDocumentHandler() +{ + if ( m_xProxy.is() ) + { + m_xProxy->setDelegator( nullptr ); + m_xProxy.clear(); + } +} +IMPLEMENT_GET_IMPLEMENTATION_ID(ImportDocumentHandler) + +OUString SAL_CALL ImportDocumentHandler::getImplementationName( ) +{ + return "com.sun.star.comp.report.ImportDocumentHandler"; +} + +sal_Bool SAL_CALL ImportDocumentHandler::supportsService( const OUString& ServiceName ) +{ + return cppu::supportsService(this, ServiceName); +} + +uno::Sequence< OUString > SAL_CALL ImportDocumentHandler::getSupportedServiceNames( ) +{ + uno::Sequence< OUString > aSupported; + if ( m_xServiceInfo.is() ) + aSupported = m_xServiceInfo->getSupportedServiceNames(); + return ::comphelper::concatSequences( uno::Sequence { "com.sun.star.report.ImportDocumentHandler" }, aSupported); +} + + +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* +reportdesign_ImportDocumentHandler_get_implementation( + css::uno::XComponentContext* context, css::uno::Sequence const&) +{ + return cppu::acquire(new ImportDocumentHandler(context)); +} + +// xml::sax::XDocumentHandler: +void SAL_CALL ImportDocumentHandler::startDocument() +{ + m_xDelegatee->startDocument(); +} + +void SAL_CALL ImportDocumentHandler::endDocument() +{ + m_xDelegatee->endDocument(); + uno::Reference< chart2::data::XDataReceiver > xReceiver(m_xModel,uno::UNO_QUERY_THROW); + if ( !m_bImportedChart ) + return; + + // this fills the chart again + ::comphelper::NamedValueCollection aArgs; + aArgs.put( "CellRangeRepresentation", OUString("all") ); + aArgs.put( "FirstCellAsLabel", uno::Any( true ) ); + aArgs.put( "DataRowSource", uno::Any( chart::ChartDataRowSource_COLUMNS ) ); + + bool bHasCategories = false; + + uno::Reference< chart2::data::XDataSource > xDataSource(m_xModel, uno::UNO_QUERY); + if( xDataSource.is()) + { + const uno::Sequence< uno::Reference< chart2::data::XLabeledDataSequence > > aSequences(xDataSource->getDataSequences()); + for( const auto& rSequence : aSequences ) + { + if( rSequence.is() ) + { + uno::Reference< beans::XPropertySet > xSeqProp( rSequence->getValues(), uno::UNO_QUERY ); + OUString aRole; + if ( xSeqProp.is() + && ( xSeqProp->getPropertyValue( "Role" ) >>= aRole ) + && aRole == "categories" + ) + { + bHasCategories = true; + break; + } + } + } + } + aArgs.put( "HasCategories", uno::Any( bHasCategories ) ); + + uno::Reference< chart::XComplexDescriptionAccess > xDataProvider(m_xModel->getDataProvider(),uno::UNO_QUERY); + if ( xDataProvider.is() ) + { + const uno::Sequence< OUString > aColumnNames = xDataProvider->getColumnDescriptions(); + aArgs.put( "ColumnDescriptions", uno::Any( aColumnNames ) ); + } + + xReceiver->attachDataProvider( m_xDatabaseDataProvider ); + xReceiver->setArguments( aArgs.getPropertyValues() ); +} + +void SAL_CALL ImportDocumentHandler::startElement(const OUString & _sName, const uno::Reference< xml::sax::XAttributeList > & _xAttrList) +{ + uno::Reference< xml::sax::XAttributeList > xNewAttribs = _xAttrList; + bool bExport = true; + if ( _sName == "office:report" ) + { + const sal_Int16 nLength = (_xAttrList.is()) ? _xAttrList->getLength() : 0; + static const OUString s_sTRUE = ::xmloff::token::GetXMLToken(XML_TRUE); + try + { + for(sal_Int16 i = 0; i < nLength; ++i) + { + OUString sLocalName; + const OUString sAttrName = _xAttrList->getNameByIndex( i ); + const sal_Int32 nColonPos = sAttrName.indexOf( ':' ); + if( -1 == nColonPos ) + sLocalName = sAttrName; + else + sLocalName = sAttrName.copy( nColonPos + 1 ); + const OUString sValue = _xAttrList->getValueByIndex( i ); + + switch( m_pReportElemTokenMap->Get( XML_NAMESPACE_REPORT, sLocalName ) ) + { + case XML_TOK_COMMAND_TYPE: + { + sal_Int32 nRet = sdb::CommandType::COMMAND; + const SvXMLEnumMapEntry* aXML_EnumMap = OXMLHelper::GetCommandTypeOptions(); + (void)SvXMLUnitConverter::convertEnum( nRet, sValue, aXML_EnumMap ); + m_xDatabaseDataProvider->setCommandType(nRet); + } + break; + case XML_TOK_COMMAND: + m_xDatabaseDataProvider->setCommand(sValue); + break; + case XML_TOK_FILTER: + m_xDatabaseDataProvider->setFilter(sValue); + break; + case XML_TOK_ESCAPE_PROCESSING: + m_xDatabaseDataProvider->setEscapeProcessing(sValue == s_sTRUE); + break; + default: + break; + } + } + } + catch(uno::Exception&) + { + } + m_xDelegatee->startElement(lcl_createAttribute(XML_NP_OFFICE,XML_CHART),nullptr); + bExport = false; + m_bImportedChart = true; + } + else if ( _sName == "rpt:master-detail-field" ) + { + const sal_Int16 nLength = (_xAttrList.is()) ? _xAttrList->getLength() : 0; + ::std::unique_ptr pMasterElemTokenMap( OXMLHelper::GetSubDocumentElemTokenMap()); + try + { + OUString sMasterField,sDetailField; + for(sal_Int16 i = 0; i < nLength; ++i) + { + OUString sLocalName; + const OUString sAttrName = _xAttrList->getNameByIndex( i ); + const sal_Int32 nColonPos = sAttrName.indexOf( ':' ); + if( -1 == nColonPos ) + sLocalName = sAttrName; + else + sLocalName = sAttrName.copy( nColonPos + 1 ); + const OUString sValue = _xAttrList->getValueByIndex( i ); + + switch( pMasterElemTokenMap->Get( XML_NAMESPACE_REPORT, sLocalName ) ) + { + case XML_TOK_MASTER: + sMasterField = sValue; + break; + case XML_TOK_SUB_DETAIL: + sDetailField = sValue; + break; + } + } + if ( sDetailField.isEmpty() ) + sDetailField = sMasterField; + m_aMasterFields.push_back(sMasterField); + m_aDetailFields.push_back(sDetailField); + } + catch(uno::Exception&) + { + TOOLS_WARN_EXCEPTION( "reportdesign", "Exception caught while filling the report definition props"); + } + bExport = false; + } + else if ( _sName == "rpt:detail" + || _sName == "rpt:formatted-text" + || _sName == "rpt:master-detail-fields" + || _sName == "rpt:report-component" + || _sName == "rpt:report-element") + bExport = false; + else if ( _sName == "chart:plot-area" ) + { + bool bHasCategories = true; + const sal_Int16 nLength = (_xAttrList.is()) ? _xAttrList->getLength() : 0; + for(sal_Int16 i = 0; i < nLength; ++i) + { + std::u16string_view sLocalName; + const OUString sAttrName = _xAttrList->getNameByIndex( i ); + const sal_Int32 nColonPos = sAttrName.indexOf( ':' ); + if( -1 == nColonPos ) + sLocalName = sAttrName; + else + sLocalName = sAttrName.subView( nColonPos + 1 ); + if ( sLocalName == u"data-source-has-labels" ) + { + const OUString sValue = _xAttrList->getValueByIndex( i ); + bHasCategories = sValue == "both"; + break; + } + } + for(beans::PropertyValue & propVal : asNonConstRange(m_aArguments)) + { + if ( propVal.Name == "HasCategories" ) + { + propVal.Value <<= bHasCategories; + break; + } + } + + rtl::Reference pList = new SvXMLAttributeList(); + xNewAttribs = pList; + pList->AppendAttributeList(_xAttrList); + pList->AddAttribute("table:cell-range-address","local-table.$A$1:.$Z$65536"); + + } + + if ( bExport ) + m_xDelegatee->startElement(_sName,xNewAttribs); +} + +void SAL_CALL ImportDocumentHandler::endElement(const OUString & _sName) +{ + bool bExport = true; + OUString sNewName = _sName; + if ( _sName == "office:report" ) + { + sNewName = lcl_createAttribute(XML_NP_OFFICE,XML_CHART); + } + else if ( _sName == "rpt:master-detail-fields" ) + { + if ( !m_aMasterFields.empty() ) + m_xDatabaseDataProvider->setMasterFields(uno::Sequence< OUString>(&*m_aMasterFields.begin(),m_aMasterFields.size())); + if ( !m_aDetailFields.empty() ) + m_xDatabaseDataProvider->setDetailFields(uno::Sequence< OUString>(&*m_aDetailFields.begin(),m_aDetailFields.size())); + bExport = false; + } + else if ( _sName == "rpt:detail" + || _sName == "rpt:formatted-text" + || _sName == "rpt:master-detail-field" + || _sName == "rpt:report-component" + || _sName == "rpt:report-element") + bExport = false; + + if ( bExport ) + m_xDelegatee->endElement(sNewName); +} + +void SAL_CALL ImportDocumentHandler::characters(const OUString & aChars) +{ + m_xDelegatee->characters(aChars); +} + +void SAL_CALL ImportDocumentHandler::ignorableWhitespace(const OUString & aWhitespaces) +{ + m_xDelegatee->ignorableWhitespace(aWhitespaces); +} + +void SAL_CALL ImportDocumentHandler::processingInstruction(const OUString & aTarget, const OUString & aData) +{ + m_xDelegatee->processingInstruction(aTarget,aData); +} + +void SAL_CALL ImportDocumentHandler::setDocumentLocator(const uno::Reference< xml::sax::XLocator > & xLocator) +{ + m_xDelegatee->setDocumentLocator(xLocator); +} +void SAL_CALL ImportDocumentHandler::initialize( const uno::Sequence< uno::Any >& _aArguments ) +{ + ::osl::MutexGuard aGuard(m_aMutex); + comphelper::SequenceAsHashMap aArgs(_aArguments); + m_xDocumentHandler = aArgs.getUnpackedValueOrDefault("DocumentHandler",m_xDocumentHandler); + m_xModel = aArgs.getUnpackedValueOrDefault("Model",m_xModel); + + OSL_ENSURE(m_xDocumentHandler.is(), "No document handler available!"); + if (!m_xDocumentHandler.is() || !m_xModel.is()) + throw uno::Exception("no delegatee and no model", nullptr); + + m_xDelegatee.set(new SvXMLLegacyToFastDocHandler(dynamic_cast(m_xDocumentHandler.get()))); + + m_xDatabaseDataProvider.set(m_xModel->getDataProvider(),uno::UNO_QUERY); + if ( !m_xDatabaseDataProvider.is() ) + { + // tdf#117162 reportbuilder needs the DataProvider to exist to progress further + setDataProvider(m_xModel, OUString()); + m_xDatabaseDataProvider.set(m_xModel->getDataProvider(), uno::UNO_QUERY_THROW); + } + + m_aArguments = m_xDatabaseDataProvider->detectArguments(nullptr); + + uno::Reference< reflection::XProxyFactory > xProxyFactory = reflection::ProxyFactory::create( m_xContext ); + m_xProxy = xProxyFactory->createProxy(m_xDelegatee); + ::comphelper::query_aggregation(m_xProxy,m_xDelegatee); + m_xTypeProvider.set(m_xDelegatee,uno::UNO_QUERY); + m_xServiceInfo.set(m_xDelegatee,uno::UNO_QUERY); + + // set ourself as delegator + m_xProxy->setDelegator( *this ); + + m_pReportElemTokenMap = OXMLHelper::GetReportElemTokenMap(); +} + +uno::Any SAL_CALL ImportDocumentHandler::queryInterface( const uno::Type& _rType ) +{ + uno::Any aReturn = ImportDocumentHandler_BASE::queryInterface(_rType); + return aReturn.hasValue() ? aReturn : (m_xProxy.is() ? m_xProxy->queryAggregation(_rType) : aReturn); +} + +uno::Sequence< uno::Type > SAL_CALL ImportDocumentHandler::getTypes( ) +{ + if ( m_xTypeProvider.is() ) + return ::comphelper::concatSequences( + ImportDocumentHandler_BASE::getTypes(), + m_xTypeProvider->getTypes() + ); + return ImportDocumentHandler_BASE::getTypes(); +} + + +} // namespace rptxml + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/reportdesign/source/filter/xml/xmlImportDocumentHandler.hxx b/reportdesign/source/filter/xml/xmlImportDocumentHandler.hxx new file mode 100644 index 000000000..aadea441c --- /dev/null +++ b/reportdesign/source/filter/xml/xmlImportDocumentHandler.hxx @@ -0,0 +1,97 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLIMPORTDOCUMENTHANDLER_HXX +#define INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLIMPORTDOCUMENTHANDLER_HXX + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +class SvXMLTokenMap; +namespace rptxml +{ +typedef ::cppu::WeakAggImplHelper3< css::xml::sax::XDocumentHandler + , css::lang::XInitialization + , css::lang::XServiceInfo> ImportDocumentHandler_BASE; + +class ImportDocumentHandler : public ImportDocumentHandler_BASE +{ +public: + explicit ImportDocumentHandler(css::uno::Reference< css::uno::XComponentContext > const & context); + +private: + // XServiceInfo + virtual OUString SAL_CALL getImplementationName( ) override; + virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override; + virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override; + + virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) override; + + DECLARE_XTYPEPROVIDER( ) + + // css::xml::sax::XDocumentHandler: + virtual void SAL_CALL startDocument() override; + virtual void SAL_CALL endDocument() override; + virtual void SAL_CALL startElement(const OUString & aName, const css::uno::Reference< css::xml::sax::XAttributeList > & xAttribs) override; + virtual void SAL_CALL endElement(const OUString & aName) override; + virtual void SAL_CALL characters(const OUString & aChars) override; + virtual void SAL_CALL ignorableWhitespace(const OUString & aWhitespaces) override; + virtual void SAL_CALL processingInstruction(const OUString & aTarget, const OUString & aData) override; + virtual void SAL_CALL setDocumentLocator(const css::uno::Reference< css::xml::sax::XLocator > & xLocator) override; + + virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override; + +private: + ImportDocumentHandler(ImportDocumentHandler const &) = delete; + void operator =(ImportDocumentHandler const &) = delete; + + virtual ~ImportDocumentHandler() override; + + ::osl::Mutex m_aMutex; + bool m_bImportedChart; + ::std::vector< OUString> m_aMasterFields; + ::std::vector< OUString> m_aDetailFields; + css::uno::Sequence< css::beans::PropertyValue > m_aArguments; + css::uno::Reference< css::uno::XComponentContext > m_xContext; + css::uno::Reference m_xDocumentHandler; + css::uno::Reference< css::xml::sax::XDocumentHandler > m_xDelegatee; + css::uno::Reference< css::uno::XAggregation > m_xProxy; + css::uno::Reference< css::lang::XTypeProvider > m_xTypeProvider; + css::uno::Reference< css::lang::XServiceInfo > m_xServiceInfo; + css::uno::Reference< css::chart2::XChartDocument > m_xModel; + css::uno::Reference< css::chart2::data::XDatabaseDataProvider > m_xDatabaseDataProvider; + + ::std::unique_ptr m_pReportElemTokenMap; +}; + +} // namespace rptxml + +#endif // INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLIMPORTDOCUMENTHANDLER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/reportdesign/source/filter/xml/xmlMasterFields.cxx b/reportdesign/source/filter/xml/xmlMasterFields.cxx new file mode 100644 index 000000000..2dfd0ac4d --- /dev/null +++ b/reportdesign/source/filter/xml/xmlMasterFields.cxx @@ -0,0 +1,95 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#include "xmlMasterFields.hxx" +#include "xmlReportElementBase.hxx" +#include "xmlfilter.hxx" +#include +#include +#include +#include "xmlEnums.hxx" + + +namespace rptxml +{ + using namespace ::com::sun::star; + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::xml::sax; + +OXMLMasterFields::OXMLMasterFields( ORptFilter& rImport, + const Reference< XFastAttributeList > & _xAttrList + ,IMasterDetailFieds* _pReport + ) : + SvXMLImportContext( rImport ) +,m_pReport(_pReport) +{ + OUString sMasterField,sDetailField; + for (auto &aIter : sax_fastparser::castToFastAttributeList( _xAttrList )) + { + OUString sValue = aIter.toString(); + + switch( aIter.getToken() ) + { + case XML_ELEMENT(REPORT, XML_MASTER): + sMasterField = sValue; + break; + case XML_ELEMENT(REPORT, XML_DETAIL): + sDetailField = sValue; + break; + default: + XMLOFF_WARN_UNKNOWN("reportdesign", aIter); + break; + } + } + if ( sDetailField.isEmpty() ) + sDetailField = sMasterField; + if ( !sMasterField.isEmpty() ) + m_pReport->addMasterDetailPair(::std::pair< OUString,OUString >(sMasterField,sDetailField)); +} + + +OXMLMasterFields::~OXMLMasterFields() +{ +} + +css::uno::Reference< css::xml::sax::XFastContextHandler > OXMLMasterFields::createFastChildContext( + sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) +{ + css::uno::Reference< css::xml::sax::XFastContextHandler > xContext; + + switch( nElement ) + { + case XML_ELEMENT(REPORT, XML_MASTER_DETAIL_FIELD): + { + GetImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + xContext = new OXMLMasterFields(static_cast(GetImport()),xAttrList ,m_pReport); + } + break; + default: + break; + } + + return xContext; +} + + +} // namespace rptxml + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/reportdesign/source/filter/xml/xmlMasterFields.hxx b/reportdesign/source/filter/xml/xmlMasterFields.hxx new file mode 100644 index 000000000..e8e212827 --- /dev/null +++ b/reportdesign/source/filter/xml/xmlMasterFields.hxx @@ -0,0 +1,48 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLMASTERFIELDS_HXX +#define INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLMASTERFIELDS_HXX + +#include +namespace rptxml +{ + class ORptFilter; + class IMasterDetailFieds; + class OXMLMasterFields : public SvXMLImportContext + { + IMasterDetailFieds* m_pReport; + OXMLMasterFields(const OXMLMasterFields&) = delete; + void operator =(const OXMLMasterFields&) = delete; + public: + + OXMLMasterFields( ORptFilter& rImport, + const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList + ,IMasterDetailFieds* _pReport); + virtual ~OXMLMasterFields() override; + + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( + sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override; + }; + +} // namespace rptxml + + +#endif // RPT_XMLMasterFields_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/reportdesign/source/filter/xml/xmlPropertyHandler.cxx b/reportdesign/source/filter/xml/xmlPropertyHandler.cxx new file mode 100644 index 000000000..3279629fa --- /dev/null +++ b/reportdesign/source/filter/xml/xmlPropertyHandler.cxx @@ -0,0 +1,35 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include "xmlPropertyHandler.hxx" +#include + +namespace rptxml +{ +using namespace ::com::sun::star; +using namespace xmloff; +using namespace ::com::sun::star::uno; + +OXMLRptPropHdlFactory::OXMLRptPropHdlFactory() {} + +OXMLRptPropHdlFactory::~OXMLRptPropHdlFactory() {} + +} // rptxml + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/reportdesign/source/filter/xml/xmlPropertyHandler.hxx b/reportdesign/source/filter/xml/xmlPropertyHandler.hxx new file mode 100644 index 000000000..5ca92d9c1 --- /dev/null +++ b/reportdesign/source/filter/xml/xmlPropertyHandler.hxx @@ -0,0 +1,40 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLPROPERTYHANDLER_HXX +#define INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLPROPERTYHANDLER_HXX + +#include + +namespace rptxml +{ + class OXMLRptPropHdlFactory : public XMLPropertyHandlerFactory + { + private: + OXMLRptPropHdlFactory(const OXMLRptPropHdlFactory&) = delete; + void operator =(const OXMLRptPropHdlFactory&) = delete; + public: + OXMLRptPropHdlFactory(); + virtual ~OXMLRptPropHdlFactory() override; + }; + +}// rptxml + +#endif // INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLPROPERTYHANDLER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/reportdesign/source/filter/xml/xmlReport.cxx b/reportdesign/source/filter/xml/xmlReport.cxx new file mode 100644 index 000000000..29f7315fe --- /dev/null +++ b/reportdesign/source/filter/xml/xmlReport.cxx @@ -0,0 +1,208 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#include "xmlReport.hxx" +#include "xmlfilter.hxx" +#include +#include +#include +#include +#include "xmlHelper.hxx" +#include "xmlGroup.hxx" +#include "xmlSection.hxx" +#include "xmlEnums.hxx" +#include "xmlFunction.hxx" +#include +#include +#include +#include "xmlMasterFields.hxx" + +namespace rptxml +{ + using namespace ::com::sun::star; + using namespace uno; + using namespace xml::sax; + + +OXMLReport::OXMLReport( ORptFilter& rImport, + const Reference< css::xml::sax::XFastAttributeList > & _xAttrList + ,const uno::Reference< report::XReportDefinition >& _xComponent) : + OXMLReportElementBase( rImport, _xComponent,nullptr) + ,m_xReportDefinition(_xComponent) +{ + OSL_ENSURE(m_xReportDefinition.is(),"No Report definition!"); + + impl_initRuntimeDefaults(); + + try + { + for (auto &aIter : sax_fastparser::castToFastAttributeList( _xAttrList )) + { + switch( aIter.getToken() ) + { + case XML_ELEMENT(REPORT, XML_COMMAND_TYPE): + { + sal_Int32 nRet = sdb::CommandType::COMMAND; + const SvXMLEnumMapEntry* aXML_EnumMap = OXMLHelper::GetCommandTypeOptions(); + bool bConvertOk = SvXMLUnitConverter::convertEnum( nRet, aIter.toView(), aXML_EnumMap ); + SAL_WARN_IF(!bConvertOk, "reportdesign", "convertEnum failed"); + m_xReportDefinition->setCommandType(nRet); + } + break; + case XML_ELEMENT(REPORT, XML_COMMAND): + m_xReportDefinition->setCommand(aIter.toString()); + break; + case XML_ELEMENT(REPORT, XML_FILTER): + m_xReportDefinition->setFilter(aIter.toString()); + break; + case XML_ELEMENT(REPORT, XML_CAPTION): + case XML_ELEMENT(OFFICE, XML_CAPTION): + m_xReportDefinition->setCaption(aIter.toString()); + break; + case XML_ELEMENT(REPORT, XML_ESCAPE_PROCESSING): + m_xReportDefinition->setEscapeProcessing(IsXMLToken(aIter, XML_TRUE)); + break; + case XML_ELEMENT(OFFICE, XML_MIMETYPE): + m_xReportDefinition->setMimeType(aIter.toString()); + break; + case XML_ELEMENT(DRAW, XML_NAME): + m_xReportDefinition->setName(aIter.toString()); + break; + default: + XMLOFF_WARN_UNKNOWN("reportdesign", aIter); + break; + } + } + } + catch(Exception&) + { + TOOLS_WARN_EXCEPTION( "reportdesign", "Exception caught while filling the report definition props"); + } +} + + +OXMLReport::~OXMLReport() +{ +} + + +void OXMLReport::impl_initRuntimeDefaults() const +{ + OSL_PRECOND( m_xReportDefinition.is(), "OXMLReport::impl_initRuntimeDefaults: no component!" ); + if ( !m_xReportDefinition.is() ) + return; + + try + { + m_xReportDefinition->setCommandType( sdb::CommandType::COMMAND ); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION("reportdesign"); + } +} + + +css::uno::Reference< css::xml::sax::XFastContextHandler > OXMLReport::createFastChildContext( + sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) +{ + css::uno::Reference< css::xml::sax::XFastContextHandler > xContext = OXMLReportElementBase::createFastChildContext(nElement,xAttrList); + if (xContext) + return xContext; + + switch( nElement ) + { + case XML_ELEMENT(REPORT, XML_FUNCTION): + { + m_rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + xContext = new OXMLFunction( m_rImport,xAttrList,m_xReportDefinition,true); + } + break; + case XML_ELEMENT(REPORT, XML_MASTER_DETAIL_FIELDS): + m_rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + xContext = new OXMLMasterFields(m_rImport,xAttrList ,this); + break; + case XML_ELEMENT(REPORT, XML_REPORT_HEADER): + { + m_rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + m_xReportDefinition->setReportHeaderOn(true); + xContext = new OXMLSection( m_rImport,xAttrList, m_xReportDefinition->getReportHeader()); + } + break; + case XML_ELEMENT(REPORT, XML_PAGE_HEADER): + { + m_rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + m_xReportDefinition->setPageHeaderOn(true); + xContext = new OXMLSection( m_rImport,xAttrList, m_xReportDefinition->getPageHeader()); + } + break; + case XML_ELEMENT(REPORT, XML_GROUP): + m_rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + xContext = new OXMLGroup( m_rImport,xAttrList); + break; + case XML_ELEMENT(REPORT, XML_DETAIL): + { + m_rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + xContext = new OXMLSection( m_rImport,xAttrList, m_xReportDefinition->getDetail()); + } + break; + case XML_ELEMENT(REPORT, XML_PAGE_FOOTER): + { + m_rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + m_xReportDefinition->setPageFooterOn(true); + xContext = new OXMLSection( m_rImport,xAttrList, m_xReportDefinition->getPageFooter(),false); + } + break; + case XML_ELEMENT(REPORT, XML_REPORT_FOOTER): + { + m_rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + m_xReportDefinition->setReportFooterOn(true); + xContext = new OXMLSection( m_rImport, xAttrList, m_xReportDefinition->getReportFooter()); + } + break; + default: + break; + } + + return xContext; +} + +void OXMLReport::endFastElement(sal_Int32) +{ + Reference< XFunctions > xFunctions = m_xReportDefinition->getFunctions(); + const ORptFilter::TGroupFunctionMap& aFunctions = m_rImport.getFunctions(); + for (const auto& rEntry : aFunctions) + xFunctions->insertByIndex(xFunctions->getCount(),uno::Any(rEntry.second)); + + if ( !m_aMasterFields.empty() ) + m_xReportDefinition->setMasterFields(Sequence< OUString>(&*m_aMasterFields.begin(),m_aMasterFields.size())); + if ( !m_aDetailFields.empty() ) + m_xReportDefinition->setDetailFields(Sequence< OUString>(&*m_aDetailFields.begin(),m_aDetailFields.size())); +} + +void OXMLReport::addMasterDetailPair(const ::std::pair< OUString,OUString >& _aPair) +{ + m_aMasterFields.push_back(_aPair.first); + m_aDetailFields.push_back(_aPair.second); +} + +} // namespace rptxml + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/reportdesign/source/filter/xml/xmlReport.hxx b/reportdesign/source/filter/xml/xmlReport.hxx new file mode 100644 index 000000000..eda2c0462 --- /dev/null +++ b/reportdesign/source/filter/xml/xmlReport.hxx @@ -0,0 +1,61 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLREPORT_HXX +#define INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLREPORT_HXX + +#include "xmlReportElementBase.hxx" +#include + +namespace rptxml +{ + class ORptFilter; + class OXMLReport final : public OXMLReportElementBase, public IMasterDetailFieds + { + css::uno::Reference< css::report::XReportDefinition > m_xReportDefinition; + ::std::vector< OUString> m_aMasterFields; + ::std::vector< OUString> m_aDetailFields; + OXMLReport(const OXMLReport&) = delete; + void operator =(const OXMLReport&) = delete; + public: + + OXMLReport( ORptFilter& rImport, + const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList + ,const css::uno::Reference< css::report::XReportDefinition >& _xComponent); + virtual ~OXMLReport() override; + + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( + sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override; + + virtual void SAL_CALL endFastElement(sal_Int32 nElement) override; + + virtual void addMasterDetailPair(const ::std::pair< OUString,OUString >& _aPair) override; + + private: + /** initializes our object's properties whose runtime (API) default is different from the file + format default. + */ + void impl_initRuntimeDefaults() const; + }; + +} // namespace rptxml + + +#endif // INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLREPORT_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/reportdesign/source/filter/xml/xmlReportElement.cxx b/reportdesign/source/filter/xml/xmlReportElement.cxx new file mode 100644 index 000000000..89025ae22 --- /dev/null +++ b/reportdesign/source/filter/xml/xmlReportElement.cxx @@ -0,0 +1,116 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#include "xmlReportElement.hxx" +#include "xmlfilter.hxx" +#include +#include +#include +#include "xmlEnums.hxx" +#include "xmlComponent.hxx" +#include "xmlCondPrtExpr.hxx" +#include "xmlFormatCondition.hxx" +#include +#include + +namespace rptxml +{ + using namespace ::com::sun::star; + using namespace report; + using namespace uno; + using namespace xml::sax; + +OXMLReportElement::OXMLReportElement( ORptFilter& rImport, + const Reference< XFastAttributeList > & _xAttrList + ,const Reference< XReportControlModel > & _xComponent) : + SvXMLImportContext( rImport ) +,m_xComponent(_xComponent) +{ + + OSL_ENSURE(m_xComponent.is(),"Component is NULL!"); + + try + { + for (auto &aIter : sax_fastparser::castToFastAttributeList( _xAttrList )) + { + switch( aIter.getToken() ) + { + case XML_ELEMENT(REPORT, XML_PRINT_WHEN_GROUP_CHANGE): + m_xComponent->setPrintWhenGroupChange(IsXMLToken(aIter, XML_TRUE)); + break; + case XML_ELEMENT(REPORT, XML_PRINT_REPEATED_VALUES): + m_xComponent->setPrintRepeatedValues(IsXMLToken(aIter, XML_TRUE)); + break; + default: + XMLOFF_WARN_UNKNOWN("reportdesign", aIter); + break; + } + } + } + catch(Exception&) + { + TOOLS_WARN_EXCEPTION( "reportdesign", "Exception caught while filling the report definition props"); + } +} + + +OXMLReportElement::~OXMLReportElement() +{ +} + +css::uno::Reference< css::xml::sax::XFastContextHandler > OXMLReportElement::createFastChildContext( + sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) +{ + css::uno::Reference< css::xml::sax::XFastContextHandler > xContext; + ORptFilter& rImport = GetOwnImport(); + + switch( nElement ) + { + case XML_ELEMENT(REPORT, XML_REPORT_COMPONENT): + rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + xContext = new OXMLComponent( rImport,xAttrList,m_xComponent); + break; + case XML_ELEMENT(REPORT, XML_CONDITIONAL_PRINT_EXPRESSION): + rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + xContext = new OXMLCondPrtExpr( rImport,xAttrList,m_xComponent); + break; + case XML_ELEMENT(REPORT, XML_FORMAT_CONDITION): + { + uno::Reference< report::XFormatCondition > xNewCond = m_xComponent->createFormatCondition(); + m_xComponent->insertByIndex(m_xComponent->getCount(),uno::Any(xNewCond)); + rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + xContext = new OXMLFormatCondition( rImport,xAttrList,xNewCond); + } + break; + default: + break; + } + + return xContext; +} + +ORptFilter& OXMLReportElement::GetOwnImport() +{ + return static_cast(GetImport()); +} + +} // namespace rptxml + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/reportdesign/source/filter/xml/xmlReportElement.hxx b/reportdesign/source/filter/xml/xmlReportElement.hxx new file mode 100644 index 000000000..5f64dbe73 --- /dev/null +++ b/reportdesign/source/filter/xml/xmlReportElement.hxx @@ -0,0 +1,50 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLREPORTELEMENT_HXX +#define INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLREPORTELEMENT_HXX + +#include +#include + +namespace rptxml +{ + class ORptFilter; + class OXMLReportElement : public SvXMLImportContext + { + css::uno::Reference< css::report::XReportControlModel > m_xComponent; + ORptFilter& GetOwnImport(); + OXMLReportElement(const OXMLReportElement&) = delete; + void operator =(const OXMLReportElement&) = delete; + public: + + OXMLReportElement( ORptFilter& rImport, + const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList + ,const css::uno::Reference< css::report::XReportControlModel >& _xComponent); + virtual ~OXMLReportElement() override; + + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( + sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override; + }; + +} // namespace rptxml + + +#endif // INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLREPORTELEMENT_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/reportdesign/source/filter/xml/xmlReportElementBase.cxx b/reportdesign/source/filter/xml/xmlReportElementBase.cxx new file mode 100644 index 000000000..ffcb8b7b6 --- /dev/null +++ b/reportdesign/source/filter/xml/xmlReportElementBase.cxx @@ -0,0 +1,97 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#include +#include +#include +#include "xmlReportElementBase.hxx" +#include "xmlfilter.hxx" +#include "xmlControlProperty.hxx" +#include "xmlReportElement.hxx" +#include "xmlEnums.hxx" +#include "xmlTable.hxx" +#include + +namespace rptxml +{ + using namespace ::com::sun::star; + using namespace ::com::sun::star::report; + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::xml::sax; + +OXMLReportElementBase::OXMLReportElementBase( ORptFilter& rImport + ,const Reference< XReportComponent > & _xComponent + ,OXMLTable* _pContainer) : + SvXMLImportContext( rImport ) +,m_rImport(rImport) +,m_pContainer(_pContainer) +,m_xReportComponent(_xComponent) +{ +} + + +OXMLReportElementBase::~OXMLReportElementBase() +{ +} + +css::uno::Reference< css::xml::sax::XFastContextHandler > OXMLReportElementBase::createFastChildContext( + sal_Int32 nElement, + const Reference< XFastAttributeList > & xAttrList ) +{ + css::uno::Reference< css::xml::sax::XFastContextHandler > xContext; + + switch( nElement ) + { + case XML_ELEMENT(REPORT, XML_REPORT_ELEMENT): + { + uno::Reference xReportModel(m_xReportComponent,uno::UNO_QUERY); + if ( xReportModel.is() ) + { + m_rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + xContext = new OXMLReportElement( m_rImport,xAttrList,xReportModel); + } + } + break; + case XML_ELEMENT(FORM, XML_PROPERTIES): + m_rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + xContext = new OXMLControlProperty( m_rImport,xAttrList,m_xReportComponent); + break; + default: + break; + } + + return xContext; +} + +void OXMLReportElementBase::endFastElement(sal_Int32 ) +{ + try + { + if ( m_pContainer && m_pContainer->getSection().is() && m_xReportComponent.is() ) + m_pContainer->getSection()->add(m_xReportComponent); + } + catch(Exception&) + { + TOOLS_WARN_EXCEPTION( "reportdesign", "Exception caught while inserting a new control!"); + } +} + +} // namespace rptxml + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/reportdesign/source/filter/xml/xmlReportElementBase.hxx b/reportdesign/source/filter/xml/xmlReportElementBase.hxx new file mode 100644 index 000000000..c37e17c50 --- /dev/null +++ b/reportdesign/source/filter/xml/xmlReportElementBase.hxx @@ -0,0 +1,66 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLREPORTELEMENTBASE_HXX +#define INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLREPORTELEMENTBASE_HXX + +#include +#include + +namespace rptxml +{ + class ORptFilter; + class OXMLTable; + + class SAL_NO_VTABLE IMasterDetailFieds + { + public: + virtual void addMasterDetailPair(const ::std::pair< OUString,OUString >& _aPair) = 0; + + protected: + ~IMasterDetailFieds() {} + }; + + class OXMLReportElementBase : public SvXMLImportContext + { + OXMLReportElementBase(const OXMLReportElementBase&) = delete; + void operator =(const OXMLReportElementBase&) = delete; + protected: + ORptFilter& m_rImport; + OXMLTable* m_pContainer; + css::uno::Reference< css::report::XReportComponent > m_xReportComponent; + + public: + + OXMLReportElementBase( ORptFilter& rImport + ,const css::uno::Reference< css::report::XReportComponent >& _xComponent + ,OXMLTable* _pContainer); + virtual ~OXMLReportElementBase() override; + + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( + sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override; + + virtual void SAL_CALL endFastElement(sal_Int32 nElement) override; + }; + +} // namespace rptxml + + +#endif // INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLREPORTELEMENTBASE_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/reportdesign/source/filter/xml/xmlSection.cxx b/reportdesign/source/filter/xml/xmlSection.cxx new file mode 100644 index 000000000..957c3a2ca --- /dev/null +++ b/reportdesign/source/filter/xml/xmlSection.cxx @@ -0,0 +1,114 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#include "xmlSection.hxx" +#include "xmlfilter.hxx" +#include +#include +#include +#include "xmlHelper.hxx" +#include +#include "xmlTable.hxx" +#include + + +namespace rptxml +{ + using namespace ::xmloff; + using namespace ::com::sun::star; + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::xml::sax; + + static sal_Int16 lcl_getReportPrintOption(std::string_view _sValue) + { + sal_Int16 nRet = report::ReportPrintOption::ALL_PAGES; + const SvXMLEnumMapEntry* aXML_EnumMap = OXMLHelper::GetReportPrintOptions(); + (void)SvXMLUnitConverter::convertEnum( nRet, _sValue, aXML_EnumMap ); + return nRet; + } + + +OXMLSection::OXMLSection( ORptFilter& rImport, + const uno::Reference< xml::sax::XFastAttributeList > & _xAttrList + ,const uno::Reference< report::XSection >& _xSection + ,bool _bPageHeader) +:SvXMLImportContext( rImport ) +,m_xSection(_xSection) +{ + + if (!m_xSection.is()) + return; + try + { + for (auto &aIter : sax_fastparser::castToFastAttributeList( _xAttrList )) + { + switch( aIter.getToken() ) + { + case XML_ELEMENT(REPORT, XML_PAGE_PRINT_OPTION): + if ( _bPageHeader ) + m_xSection->getReportDefinition()->setPageHeaderOption(lcl_getReportPrintOption(aIter.toView())); + else + m_xSection->getReportDefinition()->setPageFooterOption(lcl_getReportPrintOption(aIter.toView())); + break; + case XML_ELEMENT(REPORT, XML_REPEAT_SECTION): + m_xSection->setRepeatSection(IsXMLToken(aIter, XML_TRUE)); + break; + default: + XMLOFF_WARN_UNKNOWN("reportdesign", aIter); + } + } + } + catch(Exception&) + { + TOOLS_WARN_EXCEPTION( "reportdesign", "Exception caught while filling the section props"); + } +} + +OXMLSection::~OXMLSection() +{ +} + +css::uno::Reference< css::xml::sax::XFastContextHandler > OXMLSection::createFastChildContext( + sal_Int32 nElement, + const Reference< XFastAttributeList > & xAttrList ) +{ + css::uno::Reference< css::xml::sax::XFastContextHandler > xContext; + ORptFilter& rImport = GetOwnImport(); + + switch( nElement ) + { + case XML_ELEMENT(TABLE, XML_TABLE): + xContext = new OXMLTable( rImport, xAttrList, m_xSection); + break; + default: + break; + } + + return xContext; +} + +ORptFilter& OXMLSection::GetOwnImport() +{ + return static_cast(GetImport()); +} + + +} // namespace rptxml + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/reportdesign/source/filter/xml/xmlSection.hxx b/reportdesign/source/filter/xml/xmlSection.hxx new file mode 100644 index 000000000..c1e25cd83 --- /dev/null +++ b/reportdesign/source/filter/xml/xmlSection.hxx @@ -0,0 +1,53 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLSECTION_HXX +#define INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLSECTION_HXX + +#include +#include + +namespace rptxml +{ + class ORptFilter; + class OXMLSection : public SvXMLImportContext + { + private: + css::uno::Reference< css::report::XSection > m_xSection; + ORptFilter& GetOwnImport(); + + OXMLSection(const OXMLSection&) = delete; + void operator =(const OXMLSection&) = delete; + public: + + OXMLSection( ORptFilter& rImport + ,const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList + ,const css::uno::Reference< css::report::XSection >& _xSection + ,bool _bPageHeader = true); + virtual ~OXMLSection() override; + + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( + sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override; + }; + +} // namespace rptxml + + +#endif // INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLSECTION_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/reportdesign/source/filter/xml/xmlStyleImport.cxx b/reportdesign/source/filter/xml/xmlStyleImport.cxx new file mode 100644 index 000000000..595bd5506 --- /dev/null +++ b/reportdesign/source/filter/xml/xmlStyleImport.cxx @@ -0,0 +1,393 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#include "xmlStyleImport.hxx" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "xmlfilter.hxx" +#include "xmlHelper.hxx" +#include + +namespace rptxml +{ + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::xml::sax; +using namespace ::com::sun::star::style; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::container; +using namespace xmloff::token; + +namespace { + +class OSpecialHandleXMLImportPropertyMapper : public SvXMLImportPropertyMapper +{ +public: + OSpecialHandleXMLImportPropertyMapper(const rtl::Reference< XMLPropertySetMapper >& rMapper,SvXMLImport& _rImport) : SvXMLImportPropertyMapper(rMapper ,_rImport) + { + } + /** this method is called for every item that has the MID_FLAG_SPECIAL_ITEM_IMPORT flag set */ + virtual bool handleSpecialItem( + XMLPropertyState& /*rProperty*/, + ::std::vector< XMLPropertyState >& /*rProperties*/, + const OUString& /*rValue*/, + const SvXMLUnitConverter& /*rUnitConverter*/, + const SvXMLNamespaceMap& /*rNamespaceMap*/ ) const override + { + // nothing to do here + return true; + } +}; + +} + +OControlStyleContext::OControlStyleContext( ORptFilter& rImport, + SvXMLStylesContext& rStyles, XmlStyleFamily nFamily ) : + XMLPropStyleContext( rImport, rStyles, nFamily, false/*bDefaultStyle*/ ), + pStyles(&rStyles), + m_nNumberFormat(-1), + m_rImport(rImport) +{ + +} + + +OControlStyleContext::~OControlStyleContext() +{ + +} + + +void OControlStyleContext::FillPropertySet(const Reference< XPropertySet > & rPropSet ) +{ + if ( !IsDefaultStyle() ) + { + if ( GetFamily() == XmlStyleFamily::TABLE_CELL ) + { + if ((m_nNumberFormat == -1) && !m_sDataStyleName.isEmpty()) + { + SvXMLNumFormatContext* pStyle = const_cast< SvXMLNumFormatContext*>(dynamic_cast(pStyles->FindStyleChildContext( + XmlStyleFamily::DATA_STYLE, m_sDataStyleName))); + if ( !pStyle ) + { + OReportStylesContext* pMyStyles = dynamic_cast< OReportStylesContext *>(m_rImport.GetAutoStyles()); + if ( pMyStyles ) + pStyle = const_cast(dynamic_cast< const SvXMLNumFormatContext *>(pMyStyles-> + FindStyleChildContext(XmlStyleFamily::DATA_STYLE, m_sDataStyleName, true))); + else { + OSL_FAIL("not possible to get style"); + } + } + if ( pStyle ) + { + m_nNumberFormat = pStyle->GetKey(); + AddProperty(CTF_RPT_NUMBERFORMAT, uno::Any(m_nNumberFormat)); + } + } + } + } + XMLPropStyleContext::FillPropertySet(rPropSet); +} + +void OControlStyleContext::SetDefaults() +{ +} + + +void OControlStyleContext::AddProperty(const sal_Int16 nContextID, const uno::Any& rValue) +{ + sal_Int32 nIndex(static_cast(pStyles)->GetIndex(nContextID)); + OSL_ENSURE(nIndex != -1, "Property not found in Map"); + XMLPropertyState aPropState(nIndex, rValue); + GetProperties().push_back(aPropState); // has to be inserted in a sort order later +} + +void OControlStyleContext::SetAttribute( sal_Int32 nElement, + const OUString& rValue ) +{ + switch(nElement & TOKEN_MASK) + { + case XML_DATA_STYLE_NAME: + m_sDataStyleName = rValue; + break; + case XML_MASTER_PAGE_NAME: + break; + default: + XMLPropStyleContext::SetAttribute( nElement, rValue ); + } +} + + +OReportStylesContext::OReportStylesContext( ORptFilter& rImport, + const bool bTempAutoStyles ) : + SvXMLStylesContext( rImport ), + m_rImport(rImport), + m_nNumberFormatIndex(-1), + bAutoStyles(bTempAutoStyles) +{ + +} + + +OReportStylesContext::~OReportStylesContext() +{ + +} + + +void OReportStylesContext::endFastElement(sal_Int32 ) +{ + if (bAutoStyles) + GetImport().GetTextImport()->SetAutoStyles( this ); + else + GetImport().GetStyles()->CopyStylesToDoc(true); +} + + +rtl::Reference < SvXMLImportPropertyMapper > + OReportStylesContext::GetImportPropertyMapper( + XmlStyleFamily nFamily ) const +{ + rtl::Reference < SvXMLImportPropertyMapper > xMapper(SvXMLStylesContext::GetImportPropertyMapper(nFamily)); + + if (!xMapper.is()) + { + ORptFilter& rImport = GetOwnImport(); + switch( nFamily ) + { + case XmlStyleFamily::TABLE_CELL: + { + if( !m_xCellImpPropMapper.is() ) + { + m_xCellImpPropMapper = + new XMLTextImportPropertyMapper/*OSpecialHandleXMLImportPropertyMapper*/( rImport.GetCellStylesPropertySetMapper(), m_rImport ); + + m_xCellImpPropMapper->ChainImportMapper(XMLTextImportHelper::CreateParaExtPropMapper(m_rImport)); + } + xMapper = m_xCellImpPropMapper; + } + break; + case XmlStyleFamily::TABLE_COLUMN: + { + if( !m_xColumnImpPropMapper.is() ) + m_xColumnImpPropMapper = + new SvXMLImportPropertyMapper( rImport.GetColumnStylesPropertySetMapper(), m_rImport ); + + xMapper = m_xColumnImpPropMapper; + } + break; + case XmlStyleFamily::TABLE_ROW: + { + if( !m_xRowImpPropMapper.is() ) + m_xRowImpPropMapper =new OSpecialHandleXMLImportPropertyMapper( rImport.GetRowStylesPropertySetMapper(), m_rImport ); + xMapper = m_xRowImpPropMapper; + } + break; + case XmlStyleFamily::TABLE_TABLE: + { + if( !m_xTableImpPropMapper.is() ) + { + rtl::Reference < XMLPropertyHandlerFactory> xFac = new ::xmloff::OControlPropertyHandlerFactory(); + m_xTableImpPropMapper = new SvXMLImportPropertyMapper( new XMLPropertySetMapper(OXMLHelper::GetTableStyleProps(), xFac, false), m_rImport ); + } + xMapper = m_xTableImpPropMapper; + } + break; + default: + break; + } + } + + return xMapper; +} + +SvXMLStyleContext *OReportStylesContext::CreateDefaultStyleStyleChildContext( + XmlStyleFamily nFamily, sal_Int32 /*nElement*/, + const uno::Reference< xml::sax::XFastAttributeList > & /*xAttrList*/ ) +{ + switch( nFamily ) + { + case XmlStyleFamily::SD_GRAPHICS_ID: + // There are no writer specific defaults for graphic styles! + return new XMLGraphicsDefaultStyle( GetImport(), *this ); + default: + return nullptr; + } +} + +SvXMLStyleContext *OReportStylesContext::CreateStyleStyleChildContext( + XmlStyleFamily nFamily, sal_Int32 nElement, + const Reference< xml::sax::XFastAttributeList > & xAttrList ) +{ + SvXMLStyleContext *pStyle = SvXMLStylesContext::CreateStyleStyleChildContext( nFamily, nElement, + xAttrList ); + if (!pStyle) + { + switch( nFamily ) + { + case XmlStyleFamily::TABLE_TABLE: + case XmlStyleFamily::TABLE_COLUMN: + case XmlStyleFamily::TABLE_ROW: + case XmlStyleFamily::TABLE_CELL: + pStyle = new OControlStyleContext( GetOwnImport(), *this, nFamily ); + break; + default: + OSL_FAIL("OReportStylesContext::CreateStyleStyleChildContext: Unknown style family. Please check."); + break; + } + } + + return pStyle; +} + +Reference < XNameContainer > + OReportStylesContext::GetStylesContainer( XmlStyleFamily nFamily ) const +{ + Reference < XNameContainer > xStyles(SvXMLStylesContext::GetStylesContainer(nFamily)); + if (!xStyles.is()) + { + OUString sName; + switch( nFamily ) + { + case XmlStyleFamily::TABLE_TABLE: + { + if( m_xTableStyles.is() ) + xStyles.set(m_xTableStyles); + else + sName = "TableStyles"; + } + break; + case XmlStyleFamily::TABLE_CELL: + { + if( m_xCellStyles.is() ) + xStyles.set(m_xCellStyles); + else + sName = "CellStyles"; + } + break; + case XmlStyleFamily::TABLE_COLUMN: + { + if( m_xColumnStyles.is() ) + xStyles.set(m_xColumnStyles); + else + sName = "ColumnStyles"; + } + break; + case XmlStyleFamily::TABLE_ROW: + { + if( m_xRowStyles.is() ) + xStyles.set(m_xRowStyles); + else + sName = "RowStyles"; + } + break; + case XmlStyleFamily::SD_GRAPHICS_ID: + xStyles = const_cast(&GetImport())->GetTextImport()->GetFrameStyles(); + break; + default: + OSL_FAIL("OReportStylesContext::CreateStyleStyleChildContext: Unknown style family. Please check."); + break; + } + if( !xStyles.is() && !sName.isEmpty() && GetOwnImport().GetModel().is() ) + { + Reference< XStyleFamiliesSupplier > xFamiliesSupp( + GetOwnImport().GetModel(), UNO_QUERY ); + if (xFamiliesSupp.is()) + { + Reference< XNameAccess > xFamilies(xFamiliesSupp->getStyleFamilies()); + + xStyles.set(xFamilies->getByName( sName ), uno::UNO_QUERY); + switch( nFamily ) + { + case XmlStyleFamily::TABLE_TABLE: + m_xTableStyles.set(xStyles); + break; + case XmlStyleFamily::TABLE_CELL: + m_xCellStyles.set(xStyles); + break; + case XmlStyleFamily::TABLE_COLUMN: + m_xColumnStyles.set(xStyles); + break; + case XmlStyleFamily::TABLE_ROW: + m_xRowStyles.set(xStyles); + break; + default: + break; + } + } + } + } + + return xStyles; +} + + +OUString OReportStylesContext::GetServiceName( XmlStyleFamily nFamily ) const +{ + OUString sServiceName = SvXMLStylesContext::GetServiceName(nFamily); + if (sServiceName.isEmpty()) + { + switch( nFamily ) + { + case XmlStyleFamily::TABLE_TABLE: + sServiceName = XML_STYLE_FAMILY_TABLE_TABLE_STYLES_NAME; + break; + case XmlStyleFamily::TABLE_COLUMN: + sServiceName = XML_STYLE_FAMILY_TABLE_COLUMN_STYLES_NAME; + break; + case XmlStyleFamily::TABLE_ROW: + sServiceName = XML_STYLE_FAMILY_TABLE_ROW_STYLES_NAME; + break; + case XmlStyleFamily::TABLE_CELL: + sServiceName = XML_STYLE_FAMILY_TABLE_CELL_STYLES_NAME; + break; + default: + break; + } + } + return sServiceName; +} + + +sal_Int32 OReportStylesContext::GetIndex(const sal_Int16 nContextID) +{ + if ( nContextID == CTF_RPT_NUMBERFORMAT ) + { + if (m_nNumberFormatIndex == -1) + m_nNumberFormatIndex = + GetImportPropertyMapper(XmlStyleFamily::TABLE_CELL)->getPropertySetMapper()->FindEntryIndex(nContextID); + return m_nNumberFormatIndex; + } + return -1; +} + + +} // rptxml + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/reportdesign/source/filter/xml/xmlStyleImport.hxx b/reportdesign/source/filter/xml/xmlStyleImport.hxx new file mode 100644 index 000000000..b51108fd5 --- /dev/null +++ b/reportdesign/source/filter/xml/xmlStyleImport.hxx @@ -0,0 +1,119 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLSTYLEIMPORT_HXX +#define INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLSTYLEIMPORT_HXX + +#include +#include +#include + +namespace rptxml +{ + class ORptFilter; + + class OControlStyleContext : public XMLPropStyleContext + { + OUString m_sDataStyleName; + SvXMLStylesContext* pStyles; + // std::vector aMaps; + sal_Int32 m_nNumberFormat; + ORptFilter& m_rImport; + + OControlStyleContext(const OControlStyleContext&) = delete; + void operator =(const OControlStyleContext&) = delete; + protected: + + virtual void SetAttribute( sal_Int32 nElement, + const OUString& rValue ) override; + + public: + + OControlStyleContext( ORptFilter& rImport, + SvXMLStylesContext& rStyles, XmlStyleFamily nFamily ); + + virtual ~OControlStyleContext() override; + + + virtual void FillPropertySet(const css::uno::Reference< + css::beans::XPropertySet > & rPropSet ) override; + + virtual void SetDefaults() override; + + void AddProperty(sal_Int16 nContextID, const css::uno::Any& aValue); + }; + + class OReportStylesContext : public SvXMLStylesContext + { + ORptFilter& m_rImport; + sal_Int32 m_nNumberFormatIndex; + bool bAutoStyles : 1; + + //mutable rtl::Reference < SvXMLImportPropertyMapper > m_xControlImpPropMapper; + mutable rtl::Reference < SvXMLImportPropertyMapper > m_xCellImpPropMapper; + mutable rtl::Reference < SvXMLImportPropertyMapper > m_xColumnImpPropMapper; + mutable rtl::Reference < SvXMLImportPropertyMapper > m_xRowImpPropMapper; + mutable rtl::Reference < SvXMLImportPropertyMapper > m_xTableImpPropMapper; + + mutable css::uno::Reference< css::container::XNameContainer > m_xCellStyles; + mutable css::uno::Reference< css::container::XNameContainer > m_xColumnStyles; + mutable css::uno::Reference< css::container::XNameContainer > m_xRowStyles; + mutable css::uno::Reference< css::container::XNameContainer > m_xTableStyles; + + ORptFilter& GetOwnImport() const { return m_rImport;} + + OReportStylesContext(const OReportStylesContext&) = delete; + void operator =(const OReportStylesContext&) = delete; + protected: + + // Create a style context. + using SvXMLStylesContext::CreateStyleStyleChildContext; + virtual SvXMLStyleContext *CreateStyleStyleChildContext( + XmlStyleFamily nFamily, + sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList ) override; + + using SvXMLStylesContext::CreateDefaultStyleStyleChildContext; + virtual SvXMLStyleContext *CreateDefaultStyleStyleChildContext( + XmlStyleFamily nFamily, sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList ) override; + + public: + + + OReportStylesContext( ORptFilter& rImport, + const bool bAutoStyles ); + virtual ~OReportStylesContext() override; + + virtual void SAL_CALL endFastElement(sal_Int32 nElement) override; + + virtual rtl::Reference < SvXMLImportPropertyMapper > GetImportPropertyMapper( + XmlStyleFamily nFamily ) const override; + virtual css::uno::Reference< css::container::XNameContainer > + GetStylesContainer( XmlStyleFamily nFamily ) const override; + virtual OUString GetServiceName( XmlStyleFamily nFamily ) const override; + + sal_Int32 GetIndex(const sal_Int16 nContextID); + }; + +} // rptxml + +#endif // INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLSTYLEIMPORT_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/reportdesign/source/filter/xml/xmlSubDocument.cxx b/reportdesign/source/filter/xml/xmlSubDocument.cxx new file mode 100644 index 000000000..4a5f9fd5c --- /dev/null +++ b/reportdesign/source/filter/xml/xmlSubDocument.cxx @@ -0,0 +1,150 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#include "xmlSubDocument.hxx" +#include "xmlCell.hxx" +#include "xmlfilter.hxx" +#include +#include +#include +#include "xmlEnums.hxx" +#include "xmlMasterFields.hxx" +#include "xmlTable.hxx" +#include +#include +#include +#include + +namespace rptxml +{ + using namespace ::com::sun::star; + using namespace ::com::sun::star::report; + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::xml::sax; + +OXMLSubDocument::OXMLSubDocument( ORptFilter& rImport + ,const Reference< XReportComponent > & _xComponent + ,OXMLTable* _pContainer + ,OXMLCell* _pCellParent) : + OXMLReportElementBase( rImport,_xComponent,_pContainer) +,m_xFake(_xComponent) +,m_pCellParent(_pCellParent) +,m_nCurrentCount(0) +,m_bContainsShape(false) +{ + +} + +OXMLSubDocument::~OXMLSubDocument() +{ +} + +css::uno::Reference< css::xml::sax::XFastContextHandler > OXMLSubDocument::createFastChildContext( + sal_Int32 nElement, + const Reference< XFastAttributeList > & xAttrList ) +{ + css::uno::Reference< css::xml::sax::XFastContextHandler > xContext = OXMLReportElementBase::createFastChildContext(nElement,xAttrList); + if (xContext) + return xContext; + + switch( nElement ) + { + case XML_ELEMENT(REPORT, XML_MASTER_DETAIL_FIELDS): + { + GetImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + xContext = new OXMLMasterFields(static_cast(GetImport()),xAttrList ,this); + } + break; + // FIXME: is it *intentional* that this is supported? + // ORptExport::exportContainer() can export this but the import + // used to be rather accidental previously + case XML_ELEMENT(OFFICE, XML_BODY): + xContext = new RptXMLDocumentBodyContext(GetImport()); + break; + + case XML_ELEMENT(DRAW, XML_FRAME): + { + if ( !m_bContainsShape ) + m_nCurrentCount = m_pContainer->getSection()->getCount(); + uno::Reference< drawing::XShapes > xShapes = m_pContainer->getSection(); + xContext = XMLShapeImportHelper::CreateGroupChildContext(GetImport(),nElement,xAttrList,xShapes); + m_bContainsShape = true; + if (m_pCellParent) + { + // #i94115 say to the parent Cell it contains shapes + m_pCellParent->setContainsShape(true); + } + } + break; + default: + SAL_WARN("reportdesign", "unknown element " << SvXMLImport::getPrefixAndNameFromToken(nElement)); + break; + } + + return xContext; +} + +void OXMLSubDocument::endFastElement(sal_Int32 ) +{ + if ( !m_bContainsShape ) + return; + + m_xReportComponent.set(m_pContainer->getSection()->getByIndex(m_nCurrentCount),uno::UNO_QUERY); + if ( !m_xReportComponent.is() ) + return; + + if ( !m_aMasterFields.empty() ) + m_xReportComponent->setMasterFields(Sequence< OUString>(&*m_aMasterFields.begin(),m_aMasterFields.size())); + if ( !m_aDetailFields.empty() ) + m_xReportComponent->setDetailFields(Sequence< OUString>(&*m_aDetailFields.begin(),m_aDetailFields.size())); + + m_xReportComponent->setName(m_xFake->getName()); + m_xReportComponent->setPrintRepeatedValues(m_xFake->getPrintRepeatedValues()); + uno::Reference< report::XReportControlModel > xFakeModel(m_xFake,uno::UNO_QUERY); + uno::Reference< report::XReportControlModel > xComponentModel(m_xReportComponent,uno::UNO_QUERY); + if ( !(xComponentModel.is() && xFakeModel.is()) ) + return; + + xComponentModel->setPrintWhenGroupChange(xFakeModel->getPrintWhenGroupChange()); + const sal_Int32 nCount = xFakeModel->getCount(); + try + { + for (sal_Int32 i = 0; i < nCount ; ++i) + { + uno::Reference< report::XFormatCondition > xCond(xFakeModel->getByIndex(i),uno::UNO_QUERY); + uno::Reference< report::XFormatCondition > xNewCond = xComponentModel->createFormatCondition(); + ::comphelper::copyProperties(xCond, xNewCond); + xComponentModel->insertByIndex(xComponentModel->getCount(),uno::Any(xNewCond)); + } + } + catch(uno::Exception&) + { + OSL_FAIL("Can not access format condition!"); + } +} + +void OXMLSubDocument::addMasterDetailPair(const ::std::pair< OUString,OUString >& _aPair) +{ + m_aMasterFields.push_back(_aPair.first); + m_aDetailFields.push_back(_aPair.second); +} + +} // namespace rptxml + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/reportdesign/source/filter/xml/xmlSubDocument.hxx b/reportdesign/source/filter/xml/xmlSubDocument.hxx new file mode 100644 index 000000000..f4cbf9848 --- /dev/null +++ b/reportdesign/source/filter/xml/xmlSubDocument.hxx @@ -0,0 +1,63 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLSUBDOCUMENT_HXX +#define INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLSUBDOCUMENT_HXX + +#include "xmlReportElementBase.hxx" +#include +#include + +namespace rptxml +{ + class ORptFilter; + class OXMLCell; + class OXMLSubDocument : public OXMLReportElementBase, public IMasterDetailFieds + { + css::uno::Reference< css::report::XReportComponent> m_xFake; + ::std::vector< OUString> m_aMasterFields; + ::std::vector< OUString> m_aDetailFields; + OXMLCell* m_pCellParent; + sal_Int32 m_nCurrentCount; + bool m_bContainsShape; + + OXMLSubDocument(const OXMLSubDocument&) = delete; + void operator =(const OXMLSubDocument&) = delete; + + public: + + OXMLSubDocument( ORptFilter& rImport + ,const css::uno::Reference< css::report::XReportComponent >& _xComponent + ,OXMLTable* _pContainer + ,OXMLCell* _pCellParent); + virtual ~OXMLSubDocument() override; + + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( + sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList ) override; + + virtual void SAL_CALL endFastElement(sal_Int32 nElement) override; + virtual void addMasterDetailPair(const ::std::pair< OUString,OUString >& _aPair) override; + }; + +} // namespace rptxml + + +#endif // RPT_XMLSubDocument_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/reportdesign/source/filter/xml/xmlTable.cxx b/reportdesign/source/filter/xml/xmlTable.cxx new file mode 100644 index 000000000..34075b46d --- /dev/null +++ b/reportdesign/source/filter/xml/xmlTable.cxx @@ -0,0 +1,289 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#include "xmlTable.hxx" +#include "xmlfilter.hxx" +#include +#include +#include +#include +#include +#include +#include +#include +#include "xmlHelper.hxx" +#include "xmlEnums.hxx" +#include "xmlColumn.hxx" +#include +#include "xmlCondPrtExpr.hxx" +#include +#include +#include +#include +#include + +#include + +#define MIN_WIDTH 80 +#define MIN_HEIGHT 20 + +namespace rptxml +{ + using namespace ::xmloff; + using namespace ::com::sun::star; + using ::com::sun::star::uno::Reference; + using namespace ::com::sun::star::xml::sax; + + static sal_Int16 lcl_getForceNewPageOption(std::string_view _sValue) + { + sal_Int16 nRet = report::ForceNewPage::NONE; + const SvXMLEnumMapEntry* aXML_EnumMap = OXMLHelper::GetForceNewPageOptions(); + (void)SvXMLUnitConverter::convertEnum( nRet,_sValue,aXML_EnumMap ); + return nRet; + } + +OXMLTable::OXMLTable( ORptFilter& rImport + ,const Reference< XFastAttributeList > & _xAttrList + ,const uno::Reference< report::XSection >& _xSection + ) +:SvXMLImportContext( rImport ) +,m_xSection(_xSection) +,m_nColSpan(1) +,m_nRowSpan(0) +,m_nRowIndex(0) +,m_nColumnIndex(0) +{ + + if (!m_xSection.is()) + return; + try + { + for (auto &aIter : sax_fastparser::castToFastAttributeList( _xAttrList )) + { + switch( aIter.getToken() ) + { + case XML_ELEMENT(REPORT, XML_VISIBLE): + m_xSection->setVisible(IsXMLToken(aIter, XML_TRUE)); + break; + case XML_ELEMENT(REPORT, XML_FORCE_NEW_PAGE): + m_xSection->setForceNewPage(lcl_getForceNewPageOption(aIter.toView())); + break; + case XML_ELEMENT(REPORT, XML_FORCE_NEW_COLUMN): + m_xSection->setNewRowOrCol(lcl_getForceNewPageOption(aIter.toView())); + break; + case XML_ELEMENT(REPORT, XML_KEEP_TOGETHER): + m_xSection->setKeepTogether(IsXMLToken(aIter, XML_TRUE)); + break; + case XML_ELEMENT(TABLE, XML_NAME): + m_xSection->setName(aIter.toString()); + break; + case XML_ELEMENT(TABLE, XML_STYLE_NAME): + m_sStyleName = aIter.toString(); + break; + default: + XMLOFF_WARN_UNKNOWN("reportdesign", aIter); + break; + } + } + } + catch(Exception&) + { + TOOLS_WARN_EXCEPTION( "reportdesign", "Exception caught while filling the section props"); + } +} + +OXMLTable::~OXMLTable() +{ +} + +css::uno::Reference< css::xml::sax::XFastContextHandler > OXMLTable::createFastChildContext( + sal_Int32 nElement, + const Reference< XFastAttributeList > & xAttrList ) +{ + css::uno::Reference< css::xml::sax::XFastContextHandler > xContext; + ORptFilter& rImport = GetOwnImport(); + + switch( nElement ) + { + case XML_ELEMENT(TABLE, XML_TABLE_COLUMNS): + case XML_ELEMENT(TABLE, XML_TABLE_ROWS): + xContext = new OXMLRowColumn( rImport,xAttrList ,this); + break; + case XML_ELEMENT(TABLE, XML_TABLE_ROW): + incrementRowIndex(); + rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + xContext = new OXMLRowColumn( rImport,xAttrList,this); + break; + case XML_ELEMENT(TABLE, XML_TABLE_COLUMN): + rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + xContext = new OXMLRowColumn( rImport,xAttrList,this); + break; + case XML_ELEMENT(REPORT, XML_CONDITIONAL_PRINT_EXPRESSION): + xContext = new OXMLCondPrtExpr( rImport,xAttrList,m_xSection); + break; + default: + break; + } + + return xContext; +} + +ORptFilter& OXMLTable::GetOwnImport() +{ + return static_cast(GetImport()); +} + +void OXMLTable::endFastElement(sal_Int32 ) +{ + try + { + if ( m_xSection.is() ) + { + if ( !m_sStyleName.isEmpty() ) + { + const SvXMLStylesContext* pAutoStyles = GetImport().GetAutoStyles(); + if ( pAutoStyles ) + { + XMLPropStyleContext* pAutoStyle = const_cast(dynamic_cast< const XMLPropStyleContext *>(pAutoStyles->FindStyleChildContext(XmlStyleFamily::TABLE_TABLE,m_sStyleName))); + if ( pAutoStyle ) + { + pAutoStyle->FillPropertySet(m_xSection); + } + } + } + // set height + sal_Int32 nHeight = std::accumulate(m_aHeight.begin(), m_aHeight.end(), sal_Int32(0), + [](const sal_Int32& rSum, const sal_Int32& rHeight) { return rSum + rHeight; }); + m_xSection->setHeight( nHeight ); + // set positions, widths, and heights + sal_Int32 nLeftMargin = rptui::getStyleProperty(m_xSection->getReportDefinition(),PROPERTY_LEFTMARGIN); + sal_Int32 nPosY = 0; + ::std::vector< ::std::vector >::iterator aRowIter = m_aGrid.begin(); + ::std::vector< ::std::vector >::const_iterator aRowEnd = m_aGrid.end(); + for (sal_Int32 i = 0; aRowIter != aRowEnd; ++aRowIter,++i) + { + sal_Int32 nPosX = nLeftMargin; + ::std::vector::iterator aColIter = (*aRowIter).begin(); + ::std::vector::const_iterator aColEnd = (*aRowIter).end(); + for (sal_Int32 j = 0; aColIter != aColEnd; ++aColIter,++j) + { + TCell& rCell = *aColIter; + for (const auto& rxElement : rCell.xElements) + { + uno::Reference xShape(rxElement,uno::UNO_QUERY); + if ( xShape.is() ) + { + xShape->setPositionX(xShape->getPositionX() + nLeftMargin); + } + else + { + sal_Int32 nWidth = rCell.nWidth; + sal_Int32 nColSpan = rCell.nColSpan; + if ( nColSpan > 1 ) + { + ::std::vector::const_iterator aWidthIter = aColIter + 1; + while ( nColSpan > 1 ) + { + nWidth += (aWidthIter++)->nWidth; + --nColSpan; + } + } + nHeight = rCell.nHeight; + sal_Int32 nRowSpan = rCell.nRowSpan; + if ( nRowSpan > 1 ) + { + ::std::vector< ::std::vector >::const_iterator aHeightIter = aRowIter + 1; + while( nRowSpan > 1) + { + nHeight += (*aHeightIter)[j].nHeight; + ++aHeightIter; + --nRowSpan; + } + } + Reference xFixedLine(rxElement,uno::UNO_QUERY); + if ( xFixedLine.is() ) + { + if ( xFixedLine->getOrientation() == 1 ) // vertical + { + OSL_ENSURE(o3tl::make_unsigned(j+1) < m_aWidth.size(),"Illegal pos of col iter. There should be an empty cell for the next line part."); + nWidth += m_aWidth[j+1]; + if ( nWidth < MIN_WIDTH ) + nWidth = MIN_WIDTH; + } + else if ( nHeight < MIN_HEIGHT ) + nHeight = MIN_HEIGHT; + } + try + { + rxElement->setSize(awt::Size(nWidth,nHeight)); + rxElement->setPosition(awt::Point(nPosX,nPosY)); + rxElement->setAutoGrow(rCell.bAutoHeight); + } + catch(const beans::PropertyVetoException &) + { + OSL_FAIL("Could not set the correct position or size!"); + } + } + } + nPosX += m_aWidth[j]; + } + nPosY += m_aHeight[i]; + } + } + } + catch(Exception&) + { + TOOLS_WARN_EXCEPTION( "reportdesign", "OXMLTable::EndElement"); + } +} + +void OXMLTable::addCell(const Reference& _xElement) +{ + uno::Reference xShape(_xElement,uno::UNO_QUERY); + OSL_ENSURE(o3tl::make_unsigned(m_nRowIndex-1 ) < m_aGrid.size() && o3tl::make_unsigned( m_nColumnIndex-1 ) < m_aGrid[m_nRowIndex-1].size(), + "OXMLTable::addCell: Invalid column and row index"); + if ( o3tl::make_unsigned(m_nRowIndex-1 ) < m_aGrid.size() && o3tl::make_unsigned( m_nColumnIndex-1 ) < m_aGrid[m_nRowIndex-1].size() ) + { + TCell& rCell = m_aGrid[m_nRowIndex-1][m_nColumnIndex-1]; + if ( _xElement.is() ) + rCell.xElements.push_back( _xElement ); + if ( !xShape.is() ) + { + rCell.nWidth = m_aWidth[m_nColumnIndex-1]; + rCell.nHeight = m_aHeight[m_nRowIndex-1]; + rCell.bAutoHeight = m_aAutoHeight[m_nRowIndex-1]; + rCell.nColSpan = m_nColSpan; + rCell.nRowSpan = m_nRowSpan; + } + } + + if ( !xShape.is() ) + m_nColSpan = m_nRowSpan = 1; +} + +void OXMLTable::incrementRowIndex() +{ + ++m_nRowIndex; + m_nColumnIndex = 0; + m_aGrid.push_back(::std::vector(m_aWidth.size())); +} + +} // namespace rptxml + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/reportdesign/source/filter/xml/xmlTable.hxx b/reportdesign/source/filter/xml/xmlTable.hxx new file mode 100644 index 000000000..508ad5087 --- /dev/null +++ b/reportdesign/source/filter/xml/xmlTable.hxx @@ -0,0 +1,90 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLTABLE_HXX +#define INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLTABLE_HXX + +#include +#include +#include + +namespace rptxml +{ + class ORptFilter; + class OXMLTable : public SvXMLImportContext + { + public: + struct TCell + { + sal_Int32 nWidth; + sal_Int32 nHeight; + sal_Int32 nColSpan; + sal_Int32 nRowSpan; + bool bAutoHeight; + ::std::vector< css::uno::Reference< css::report::XReportComponent> > xElements; + TCell() : nWidth(0),nHeight(0),nColSpan(1),nRowSpan(1),bAutoHeight(false){} + }; + private: + ::std::vector< ::std::vector > m_aGrid; + ::std::vector m_aHeight; + ::std::vector m_aAutoHeight; + ::std::vector m_aWidth; + css::uno::Reference< css::report::XSection > m_xSection; + OUString m_sStyleName; + sal_Int32 m_nColSpan; + sal_Int32 m_nRowSpan; + sal_Int32 m_nRowIndex; + sal_Int32 m_nColumnIndex; + ORptFilter& GetOwnImport(); + + OXMLTable(const OXMLTable&) = delete; + void operator =(const OXMLTable&) = delete; + public: + + OXMLTable( ORptFilter& rImport + ,const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList + ,const css::uno::Reference< css::report::XSection >& _xSection + ); + virtual ~OXMLTable() override; + + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( + sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override; + + virtual void SAL_CALL endFastElement(sal_Int32 nElement) override; + + void addHeight(sal_Int32 _nHeight) { m_aHeight.push_back(_nHeight); } + void addAutoHeight(bool _bAutoHeight) { m_aAutoHeight.push_back(_bAutoHeight); } + void addWidth(sal_Int32 _nWidth) { m_aWidth.push_back( _nWidth ); } + + void setColumnSpanned(sal_Int32 _nColSpan) { m_nColSpan = _nColSpan; } + void setRowSpanned( sal_Int32 _nRowSpan) { m_nRowSpan = _nRowSpan; } + + void incrementRowIndex(); + void incrementColumnIndex() { ++m_nColumnIndex; } + + void addCell(const css::uno::Reference< css::report::XReportComponent>& _xElement); + + const css::uno::Reference< css::report::XSection >& getSection() const { return m_xSection; } + }; + +} // namespace rptxml + + +#endif // INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLTABLE_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/reportdesign/source/filter/xml/xmlfilter.cxx b/reportdesign/source/filter/xml/xmlfilter.cxx new file mode 100644 index 000000000..166c8c435 --- /dev/null +++ b/reportdesign/source/filter/xml/xmlfilter.cxx @@ -0,0 +1,764 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include "xmlfilter.hxx" +#include "xmlReport.hxx" +#include +#include "xmlHelper.hxx" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "xmlEnums.hxx" +#include "xmlStyleImport.hxx" +#include +#include "xmlPropertyHandler.hxx" +#include + +namespace rptxml +{ +using namespace ::com::sun::star::uno; +using ::com::sun::star::uno::Reference; +using namespace ::com::sun::star; +using namespace ::com::sun::star::container; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::document; +using namespace ::com::sun::star::text; +using namespace ::com::sun::star::io; +using namespace ::com::sun::star::report; +using namespace ::com::sun::star::xml::sax; +using namespace xmloff; +using namespace ::com::sun::star::util; + +namespace { + +class RptMLMasterStylesContext_Impl: + public XMLTextMasterStylesContext +{ + ORptFilter& GetImport() { return static_cast(XMLTextMasterStylesContext::GetImport()); } + +public: + + + RptMLMasterStylesContext_Impl( ORptFilter& rImport ); + + RptMLMasterStylesContext_Impl(const RptMLMasterStylesContext_Impl&) = delete; + RptMLMasterStylesContext_Impl& operator=(const RptMLMasterStylesContext_Impl&) = delete; + virtual void SAL_CALL endFastElement(sal_Int32 nElement) override; +}; + +} + +RptMLMasterStylesContext_Impl::RptMLMasterStylesContext_Impl( ORptFilter& rImport ) : + XMLTextMasterStylesContext( rImport ) +{ +} + +void RptMLMasterStylesContext_Impl::endFastElement(sal_Int32 ) +{ + FinishStyles( true ); + GetImport().FinishStyles(); +} + + /// read a component (file + filter version) +static ErrCode ReadThroughComponent( + const uno::Reference& xInputStream, + const uno::Reference& xModelComponent, + const uno::Reference & rContext, + const uno::Reference& rFastParser ) +{ + OSL_ENSURE(xInputStream.is(), "input stream missing"); + OSL_ENSURE(xModelComponent.is(), "document missing"); + OSL_ENSURE(rContext.is(), "factory missing"); + + // prepare Parser InputSource + InputSource aParserInput; + aParserInput.aInputStream = xInputStream; + + // get filter + SAL_WARN_IF( !rFastParser.is(), "reportdesign", "Can't instantiate filter component." ); + if( !rFastParser.is() ) + return ErrCode(1); + + // connect model and filter + uno::Reference < XImporter > xImporter( rFastParser, UNO_QUERY ); + xImporter->setTargetDocument( xModelComponent ); + + // finally, parser the stream + try + { + rFastParser->parseStream( aParserInput ); + } + catch (const SAXParseException&) + { + TOOLS_WARN_EXCEPTION( "reportdesign", ""); + return ErrCode(1); + } + catch (const SAXException&) + { + return ErrCode(1); + } + catch (const packages::zip::ZipIOException&) + { + return ERRCODE_IO_BROKENPACKAGE; + } + catch (const IOException&) + { + TOOLS_WARN_EXCEPTION( "reportdesign", ""); + return ErrCode(1); + } + catch (const Exception&) + { + TOOLS_WARN_EXCEPTION( "reportdesign", ""); + return ErrCode(1); + } + + // success! + return ERRCODE_NONE; +} + +/// read a component (storage version) +static ErrCode ReadThroughComponent( + const uno::Reference< embed::XStorage >& xStorage, + const uno::Reference& xModelComponent, + const char* pStreamName, + const uno::Reference & rxContext, + const Reference & rxGraphicStorageHandler, + const Reference& _xEmbeddedObjectResolver, + const OUString& _sFilterName + ,const uno::Reference& _xProp) +{ + OSL_ENSURE( xStorage.is(), "Need storage!"); + OSL_ENSURE(nullptr != pStreamName, "Please, please, give me a name!"); + + if ( !xStorage ) + // TODO/LATER: better error handling + return ErrCode(1); + + uno::Reference< io::XStream > xDocStream; + + try + { + // open stream (and set parser input) + OUString sStreamName = OUString::createFromAscii(pStreamName); + if ( !xStorage->hasByName( sStreamName ) || !xStorage->isStreamElement( sStreamName ) ) + { + // stream name not found! return immediately with OK signal + return ERRCODE_NONE; + } + + // get input stream + xDocStream = xStorage->openStreamElement( sStreamName, embed::ElementModes::READ ); + } + catch (const packages::WrongPasswordException&) + { + return ERRCODE_SFX_WRONGPASSWORD; + } + catch (const uno::Exception&) + { + return ErrCode(1); // TODO/LATER: error handling + } + + sal_Int32 nArgs = 0; + if (rxGraphicStorageHandler.is()) + nArgs++; + if( _xEmbeddedObjectResolver.is()) + nArgs++; + if ( _xProp.is() ) + nArgs++; + + uno::Sequence< uno::Any > aFilterCompArgs( nArgs ); + auto aFilterCompArgsRange = asNonConstRange(aFilterCompArgs); + + nArgs = 0; + if (rxGraphicStorageHandler.is()) + aFilterCompArgsRange[nArgs++] <<= rxGraphicStorageHandler; + if( _xEmbeddedObjectResolver.is()) + aFilterCompArgsRange[ nArgs++ ] <<= _xEmbeddedObjectResolver; + if ( _xProp.is() ) + aFilterCompArgsRange[ nArgs++ ] <<= _xProp; + + // the underlying SvXMLImport implements XFastParser, XImporter, XFastDocumentHandler + Reference< XFastParser > xFastParser( + rxContext->getServiceManager()->createInstanceWithArgumentsAndContext(_sFilterName, aFilterCompArgs, rxContext), + uno::UNO_QUERY_THROW ); + uno::Reference< XInputStream > xInputStream = xDocStream->getInputStream(); + // read from the stream + return ReadThroughComponent( xInputStream + ,xModelComponent + ,rxContext + ,xFastParser ); +} + + +/** Imports only settings + * \ingroup reportdesign_source_filter_xml + * + */ +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* +reportdesign_ORptImportHelper_get_implementation( + css::uno::XComponentContext* context, css::uno::Sequence const&) +{ + return cppu::acquire(new ORptFilter(context, + SERVICE_SETTINGSIMPORTER, + SvXMLImportFlags::SETTINGS )); +} + +/** Imports only content + * \ingroup reportdesign_source_filter_xml + * + */ +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* +reportdesign_XMLOasisContentImporter_get_implementation( + css::uno::XComponentContext* context, css::uno::Sequence const&) +{ + return cppu::acquire(new ORptFilter(context, + SERVICE_CONTENTIMPORTER, + SvXMLImportFlags::AUTOSTYLES | SvXMLImportFlags::CONTENT | SvXMLImportFlags::SCRIPTS | SvXMLImportFlags::FONTDECLS )); +} + +/** Imports only styles + * \ingroup reportdesign_source_filter_xml + * + */ +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* +reportdesign_ORptStylesImportHelper_get_implementation( + css::uno::XComponentContext* context, css::uno::Sequence const&) +{ + return cppu::acquire(new ORptFilter(context, + SERVICE_STYLESIMPORTER, + SvXMLImportFlags::STYLES | SvXMLImportFlags::MASTERSTYLES | SvXMLImportFlags::AUTOSTYLES | + SvXMLImportFlags::FONTDECLS )); +} + +/** Imports only meta data + * \ingroup reportdesign_source_filter_xml + * + */ +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* +reportdesign_ORptMetaImportHelper_get_implementation( + css::uno::XComponentContext* context, css::uno::Sequence const&) +{ + return cppu::acquire(new ORptFilter(context, + SERVICE_METAIMPORTER, + SvXMLImportFlags::META )); +} + + +ORptFilter::ORptFilter( const uno::Reference< XComponentContext >& _rxContext, OUString const & rImplementationName, SvXMLImportFlags nImportFlags ) + :SvXMLImport(_rxContext, rImplementationName, nImportFlags) +{ + GetMM100UnitConverter().SetCoreMeasureUnit(util::MeasureUnit::MM_100TH); + GetMM100UnitConverter().SetXMLMeasureUnit(util::MeasureUnit::CM); + GetNamespaceMap().Add( "_report", + GetXMLToken(XML_N_RPT), + XML_NAMESPACE_REPORT ); + + GetNamespaceMap().Add( "__report", + GetXMLToken(XML_N_RPT_OASIS), + XML_NAMESPACE_REPORT ); + + m_xPropHdlFactory = new OXMLRptPropHdlFactory; + m_xCellStylesPropertySetMapper = OXMLHelper::GetCellStylePropertyMap(true, false); + m_xColumnStylesPropertySetMapper = new XMLPropertySetMapper(OXMLHelper::GetColumnStyleProps(), m_xPropHdlFactory, false); + m_xRowStylesPropertySetMapper = new XMLPropertySetMapper(OXMLHelper::GetRowStyleProps(), m_xPropHdlFactory, false); +} + + +ORptFilter::~ORptFilter() noexcept +{ +} + +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* +reportdesign_OReportFilter_get_implementation( + css::uno::XComponentContext* context, css::uno::Sequence const&) +{ + return cppu::acquire(new ORptFilter(context, + "com.sun.star.comp.report.OReportFilter", + SvXMLImportFlags::ALL )); +} + +sal_Bool SAL_CALL ORptFilter::filter( const Sequence< PropertyValue >& rDescriptor ) +{ + vcl::Window* pFocusWindow = Application::GetFocusWindow(); + bool bRet = false; + + if( pFocusWindow ) + pFocusWindow->EnterWait(); + + if ( GetModel().is() ) + bRet = implImport( rDescriptor ); + + if ( pFocusWindow ) + pFocusWindow->LeaveWait(); + + return bRet; +} + +bool ORptFilter::implImport( const Sequence< PropertyValue >& rDescriptor ) +{ + OUString sFileName; + uno::Reference< embed::XStorage > xStorage; + uno::Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier; + + for(const PropertyValue& rProp : rDescriptor) + { + if ( rProp.Name == "FileName" ) + rProp.Value >>= sFileName; + else if ( rProp.Name == "Storage" ) + rProp.Value >>= xStorage; + else if ( rProp.Name == "ComponentData" ) + { + Sequence< PropertyValue > aComponent; + rProp.Value >>= aComponent; + const PropertyValue* pComponentIter = aComponent.getConstArray(); + const PropertyValue* pComponentEnd = pComponentIter + aComponent.getLength(); + pComponentIter = std::find_if(pComponentIter, pComponentEnd, + [](const PropertyValue& rComponent) { return rComponent.Name == "ActiveConnection"; }); + if (pComponentIter != pComponentEnd) + { + uno::Reference xCon(pComponentIter->Value, uno::UNO_QUERY); + xNumberFormatsSupplier = ::dbtools::getNumberFormats(xCon); + } + } + } + + if ( !sFileName.isEmpty() ) + { + tools::SvRef pMedium = new SfxMedium( + sFileName, ( StreamMode::READ | StreamMode::NOCREATE ) ); + + if( pMedium.is() ) + { + try + { + xStorage = pMedium->GetStorage(); + } + catch (const Exception&) + { + } + } + } + bool bRet = xStorage.is(); + if ( bRet ) + { + m_xReportDefinition.set(GetModel(),UNO_QUERY_THROW); + +#if OSL_DEBUG_LEVEL > 1 + uno::Reference < container::XNameAccess > xAccess( xStorage, uno::UNO_QUERY ); + uno::Sequence< OUString> aSeq = xAccess->getElementNames(); + const OUString* pDebugIter = aSeq.getConstArray(); + const OUString* pDebugEnd = pDebugIter + aSeq.getLength(); + for(;pDebugIter != pDebugEnd;++pDebugIter) + { + (void)*pDebugIter; + } +#endif + + uno::Reference xGraphicStorageHandler; + uno::Reference xEmbeddedObjectResolver; + uno::Reference< uno::XComponentContext > xContext = GetComponentContext(); + + uno::Sequence aArgs{ uno::Any(xStorage) }; + xGraphicStorageHandler.set( + xContext->getServiceManager()->createInstanceWithArgumentsAndContext("com.sun.star.comp.Svx.GraphicImportHelper", aArgs, xContext), + uno::UNO_QUERY); + + uno::Reference< lang::XMultiServiceFactory > xReportServiceFactory( m_xReportDefinition, uno::UNO_QUERY); + aArgs.getArray()[0] <<= beans::NamedValue("Storage", uno::Any(xStorage)); + xEmbeddedObjectResolver.set( xReportServiceFactory->createInstanceWithArguments("com.sun.star.document.ImportEmbeddedObjectResolver",aArgs) , uno::UNO_QUERY); + + static constexpr OUStringLiteral s_sOld = u"OldFormat"; + static comphelper::PropertyMapEntry const pMap[] = + { + { OUString("OldFormat") , 1, cppu::UnoType::get(), beans::PropertyAttribute::BOUND, 0 }, + { OUString("StreamName"), 0, cppu::UnoType::get(), beans::PropertyAttribute::MAYBEVOID, 0 }, + { OUString("PrivateData"),0, cppu::UnoType::get(), beans::PropertyAttribute::MAYBEVOID, 0 }, + { OUString("BaseURI"), 0, cppu::UnoType::get(), beans::PropertyAttribute::MAYBEVOID, 0 }, + { OUString("StreamRelPath"), 0, cppu::UnoType::get(), beans::PropertyAttribute::MAYBEVOID, 0 }, + }; + utl::MediaDescriptor aDescriptor(rDescriptor); + uno::Reference xProp = comphelper::GenericPropertySet_CreateInstance(new comphelper::PropertySetInfo(pMap)); + const OUString sVal( aDescriptor.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_DOCUMENTBASEURL, OUString()) ); + assert(!sVal.isEmpty()); // needed for relative URLs + xProp->setPropertyValue("BaseURI", uno::Any(sVal)); + const OUString sHierarchicalDocumentName( aDescriptor.getUnpackedValueOrDefault("HierarchicalDocumentName",OUString()) ); + xProp->setPropertyValue("StreamRelPath", uno::Any(sHierarchicalDocumentName)); + + uno::Reference xModel = GetModel(); + static constexpr OUStringLiteral s_sMeta = u"meta.xml"; + static constexpr OUStringLiteral s_sStreamName = u"StreamName"; + xProp->setPropertyValue(s_sStreamName, uno::Any(OUString(s_sMeta))); + ErrCode nRet = ReadThroughComponent( xStorage + ,xModel + ,"meta.xml" + ,GetComponentContext() + ,xGraphicStorageHandler + ,xEmbeddedObjectResolver + ,SERVICE_METAIMPORTER + ,xProp + ); + + + try + { + xProp->setPropertyValue(s_sOld,uno::Any(!(xStorage->hasByName(s_sMeta) || xStorage->isStreamElement( s_sMeta )))); + } + catch (const uno::Exception&) + { + xProp->setPropertyValue(s_sOld,uno::Any(true)); + } + + if ( nRet == ERRCODE_NONE ) + { + xProp->setPropertyValue(s_sStreamName, uno::Any(OUString("settings.xml"))); + nRet = ReadThroughComponent( xStorage + ,xModel + ,"settings.xml" + ,GetComponentContext() + ,xGraphicStorageHandler + ,xEmbeddedObjectResolver + ,SERVICE_SETTINGSIMPORTER + ,xProp + ); + } + if ( nRet == ERRCODE_NONE ) + { + xProp->setPropertyValue(s_sStreamName, uno::Any(OUString("styles.xml"))); + nRet = ReadThroughComponent(xStorage + ,xModel + ,"styles.xml" + ,GetComponentContext() + ,xGraphicStorageHandler + ,xEmbeddedObjectResolver + ,SERVICE_STYLESIMPORTER + ,xProp); + } + + if ( nRet == ERRCODE_NONE ) + { + xProp->setPropertyValue(s_sStreamName, uno::Any(OUString("content.xml"))); + nRet = ReadThroughComponent( xStorage + ,xModel + ,"content.xml" + ,GetComponentContext() + ,xGraphicStorageHandler + ,xEmbeddedObjectResolver + ,SERVICE_CONTENTIMPORTER + ,xProp + ); + } + + + bRet = nRet == ERRCODE_NONE; + + if ( bRet ) + { + m_xReportDefinition->setModified(false); + } + else + { + if( nRet == ERRCODE_IO_BROKENPACKAGE && xStorage.is() ) + ; // TODO/LATER: no way to transport the error outside from the filter! + else + { + // TODO/LATER: this is completely wrong! Filter code should never call ErrorHandler directly! But for now this is the only way! + ErrorHandler::HandleError( nRet ); + if( nRet.IsWarning() ) + bRet = true; + } + } + } + + return bRet; +} + +namespace { + +class RptXMLDocumentSettingsContext : public SvXMLImportContext +{ +public: + RptXMLDocumentSettingsContext(SvXMLImport & rImport) + : SvXMLImportContext(rImport) + { + } + + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( + sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& /*xAttrList*/ ) override + { + if (nElement == XML_ELEMENT(OFFICE, XML_SETTINGS)) + { + return new XMLDocumentSettingsContext(GetImport()); + } + return nullptr; + } +}; + +class RptXMLDocumentStylesContext : public SvXMLImportContext +{ +public: + RptXMLDocumentStylesContext(SvXMLImport & rImport) + : SvXMLImportContext(rImport) + { + } + + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( + sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& /*xAttrList*/ ) override + { + ORptFilter & rImport(static_cast(GetImport())); + switch (nElement) + { + case XML_ELEMENT(OFFICE, XML_FONT_FACE_DECLS): + rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + return rImport.CreateFontDeclsContext(); + case XML_ELEMENT(OFFICE, XML_MASTER_STYLES): + { + SvXMLStylesContext* pStyleContext = new RptMLMasterStylesContext_Impl(rImport); + rImport.SetMasterStyles(pStyleContext); + return pStyleContext; + } + case XML_ELEMENT(OFFICE, XML_STYLES): + rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + return rImport.CreateStylesContext(false); + case XML_ELEMENT(OFFICE, XML_AUTOMATIC_STYLES): + // don't use the autostyles from the styles-document for the progress + return rImport.CreateStylesContext(true); + } + return nullptr; + } +}; + +} + +css::uno::Reference< css::xml::sax::XFastContextHandler > RptXMLDocumentBodyContext::createFastChildContext( + sal_Int32 nElement, + const uno::Reference & xAttrList) +{ + ORptFilter & rImport(static_cast(GetImport())); + if (nElement == XML_ELEMENT(OFFICE, XML_REPORT) || nElement == XML_ELEMENT(OOO, XML_REPORT)) + { + rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + const SvXMLStylesContext* pAutoStyles = rImport.GetAutoStyles(); + if (pAutoStyles) + { + XMLPropStyleContext* pAutoStyle = const_cast(dynamic_cast(pAutoStyles->FindStyleChildContext(XmlStyleFamily::PAGE_MASTER, "pm1"))); + if (pAutoStyle) + { + pAutoStyle->FillPropertySet(rImport.getReportDefinition()); + } + } + return new OXMLReport(rImport, xAttrList, rImport.getReportDefinition()); + } + return nullptr; +} + +namespace { + +class RptXMLDocumentContentContext : public SvXMLImportContext +{ +public: + RptXMLDocumentContentContext(SvXMLImport & rImport) + : SvXMLImportContext(rImport) + { + } + + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( + sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& /*xAttrList*/ ) override + { + ORptFilter & rImport(static_cast(GetImport())); + switch (nElement) + { + case XML_ELEMENT(OFFICE, XML_BODY): + return new RptXMLDocumentBodyContext(rImport); + case XML_ELEMENT(OFFICE, XML_FONT_FACE_DECLS): + rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + return rImport.CreateFontDeclsContext(); + case XML_ELEMENT(OFFICE, XML_AUTOMATIC_STYLES): + rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + return rImport.CreateStylesContext(true); + } + return nullptr; + } +}; + +} + +SvXMLImportContext *ORptFilter::CreateFastContext( sal_Int32 nElement, + const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ ) +{ + SvXMLImportContext *pContext = nullptr; + + switch (nElement) + { + case XML_ELEMENT( OFFICE, XML_DOCUMENT_META ): + GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + pContext = CreateMetaContext( nElement ); + break; + case XML_ELEMENT( OFFICE, XML_DOCUMENT_CONTENT ): + pContext = new RptXMLDocumentContentContext(*this); + break; + case XML_ELEMENT( OFFICE, XML_DOCUMENT_STYLES ): + pContext = new RptXMLDocumentStylesContext(*this); + break; + case XML_ELEMENT( OFFICE, XML_DOCUMENT_SETTINGS ): + GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + pContext = new RptXMLDocumentSettingsContext(*this); + break; + } + return pContext; +} + +SvXMLImportContext* ORptFilter::CreateStylesContext( bool bIsAutoStyle ) +{ + SvXMLImportContext* pContext = bIsAutoStyle ? GetAutoStyles() : GetStyles(); + if ( !pContext ) + { + pContext = new OReportStylesContext(*this, bIsAutoStyle); + if (bIsAutoStyle) + SetAutoStyles(static_cast(pContext)); + else + SetStyles(static_cast(pContext)); + } + return pContext; +} + +SvXMLImportContext *ORptFilter::CreateFontDeclsContext() +{ + XMLFontStylesContext *pFSContext = + new XMLFontStylesContext( *this, osl_getThreadTextEncoding() ); + SetFontDecls( pFSContext ); + return pFSContext; +} + +XMLShapeImportHelper* ORptFilter::CreateShapeImport() +{ + return new XMLShapeImportHelper( *this,GetModel() ); +} + +void ORptFilter::FinishStyles() +{ + if( GetStyles() ) + GetStyles()->FinishStyles( true ); +} + +const OUString& ORptFilter::convertFormula(const OUString& _sFormula) +{ + return _sFormula; +} + +void SAL_CALL ORptFilter::startDocument() +{ + m_xReportDefinition.set(GetModel(),UNO_QUERY_THROW); + m_pReportModel = reportdesign::OReportDefinition::getSdrModel(m_xReportDefinition); + OSL_ENSURE(m_pReportModel,"Report model is NULL!"); + + SvXMLImport::startDocument(); +} + +void ORptFilter::endDocument() +{ + OSL_ENSURE( GetModel().is(), "model missing; maybe startDocument wasn't called?" ); + if( !GetModel().is() ) + return; + + // this method will modify the document directly -> lock SolarMutex + SolarMutexGuard aGuard; + // Clear the shape import to sort the shapes (and not in the + // destructor that might be called after the import has finished + // for Java filters. + if( HasShapeImport() ) + ClearShapeImport(); + + // delegate to parent: takes care of error handling + SvXMLImport::endDocument(); +} + +void ORptFilter::removeFunction(const OUString& _sFunctionName) +{ + m_aFunctions.erase(_sFunctionName); +} + +void ORptFilter::insertFunction(const css::uno::Reference< css::report::XFunction > & _xFunction) +{ + m_aFunctions.emplace(_xFunction->getName(),_xFunction); +} + +SvXMLImportContext* ORptFilter::CreateMetaContext(const sal_Int32 /*nElement*/) +{ + SvXMLImportContext* pContext = nullptr; + + if ( getImportFlags() & SvXMLImportFlags::META ) + { + uno::Reference xDPS(GetModel(), uno::UNO_QUERY_THROW); + pContext = new SvXMLMetaDocumentContext(*this, xDPS->getDocumentProperties()); + } + return pContext; +} + +bool ORptFilter::isOldFormat() const +{ + bool bOldFormat = true; + uno::Reference xProp = getImportInfo(); + if ( xProp.is() ) + { + static constexpr OUStringLiteral s_sOld = u"OldFormat"; + if ( xProp->getPropertySetInfo()->hasPropertyByName(s_sOld)) + { + xProp->getPropertyValue(s_sOld) >>= bOldFormat; + } + } + return bOldFormat; +} + + +}// rptxml + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/reportdesign/source/filter/xml/xmlfilter.hxx b/reportdesign/source/filter/xml/xmlfilter.hxx new file mode 100644 index 000000000..0a101c635 --- /dev/null +++ b/reportdesign/source/filter/xml/xmlfilter.hxx @@ -0,0 +1,140 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLFILTER_HXX +#define INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLFILTER_HXX + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace rptui +{ +class OReportModel; +} +namespace rptxml +{ +using namespace ::xmloff::token; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::container; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::document; +using namespace ::com::sun::star::text; +using namespace ::com::sun::star::io; +using namespace ::com::sun::star::report; +using namespace ::com::sun::star::xml::sax; + + +class ORptFilter : public SvXMLImport +{ +public: + typedef std::map< OUString, Sequence > TPropertyNameMap; + typedef std::map< OUString, Reference > TGroupFunctionMap; +private: + + TGroupFunctionMap m_aFunctions; + + rtl::Reference < XMLPropertyHandlerFactory > m_xPropHdlFactory; + rtl::Reference < XMLPropertySetMapper > m_xCellStylesPropertySetMapper; + rtl::Reference < XMLPropertySetMapper > m_xColumnStylesPropertySetMapper; + rtl::Reference < XMLPropertySetMapper > m_xRowStylesPropertySetMapper; + + Reference m_xReportDefinition; + std::shared_ptr m_pReportModel; + + /// @throws RuntimeException + bool implImport( const Sequence< PropertyValue >& rDescriptor ); + +public: + using SvXMLImport::SetMasterStyles; + SvXMLImportContext* CreateStylesContext( bool bIsAutoStyle ); + SvXMLImportContext* CreateMetaContext(const sal_Int32 nElement); + SvXMLImportContext* CreateFontDeclsContext(); +protected: + // SvXMLImport + virtual SvXMLImportContext *CreateFastContext( sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override; + + virtual XMLShapeImportHelper* CreateShapeImport() override; + + virtual ~ORptFilter() noexcept override; +public: + + ORptFilter( const Reference< XComponentContext >& _rxContext, OUString const & rImplementationName, SvXMLImportFlags nImportFlags ); + + // XFilter + virtual sal_Bool SAL_CALL filter( const Sequence< PropertyValue >& rDescriptor ) override; + + const Reference& getReportDefinition() const { + return m_xReportDefinition; + } + void FinishStyles(); + + virtual void SAL_CALL startDocument() override; + virtual void SAL_CALL endDocument() override; + + const rtl::Reference< XMLPropertySetMapper >& GetCellStylesPropertySetMapper() const { + return m_xCellStylesPropertySetMapper; + } + const rtl::Reference< XMLPropertySetMapper >& GetColumnStylesPropertySetMapper() const { + return m_xColumnStylesPropertySetMapper; + } + const rtl::Reference< XMLPropertySetMapper >& GetRowStylesPropertySetMapper() const { + return m_xRowStylesPropertySetMapper; + } + static const OUString& convertFormula(const OUString& _sFormula); + /** inserts a new function + * + * \param _xFunction + */ + void insertFunction(const css::uno::Reference< css::report::XFunction > & _xFunction); + void removeFunction(const OUString& _sFunctionName); + const TGroupFunctionMap& getFunctions() const { + return m_aFunctions; + } + + bool isOldFormat() const; +}; + + +class RptXMLDocumentBodyContext : public SvXMLImportContext +{ +public: + RptXMLDocumentBodyContext(SvXMLImport & rImport) + : SvXMLImportContext(rImport) + { + } + + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( + sal_Int32 /*nElement*/, const css::uno::Reference< css::xml::sax::XFastAttributeList >& /*xAttrList*/ ) override; +}; + +} // rptxml + +#endif // INCLUDED_REPORTDESIGN_SOURCE_FILTER_XML_XMLFILTER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3