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 --- dbaccess/source/filter/xml/dbaxml.component | 46 + dbaccess/source/filter/xml/dbloader2.cxx | 535 ++++++++ dbaccess/source/filter/xml/xmlAutoStyle.cxx | 82 ++ dbaccess/source/filter/xml/xmlAutoStyle.hxx | 45 + dbaccess/source/filter/xml/xmlColumn.cxx | 162 +++ dbaccess/source/filter/xml/xmlColumn.hxx | 53 + dbaccess/source/filter/xml/xmlComponent.cxx | 99 ++ dbaccess/source/filter/xml/xmlComponent.hxx | 40 + dbaccess/source/filter/xml/xmlConnectionData.cxx | 93 ++ dbaccess/source/filter/xml/xmlConnectionData.hxx | 41 + .../source/filter/xml/xmlConnectionResource.cxx | 88 ++ .../source/filter/xml/xmlConnectionResource.hxx | 36 + dbaccess/source/filter/xml/xmlDataSource.cxx | 251 ++++ dbaccess/source/filter/xml/xmlDataSource.hxx | 47 + dbaccess/source/filter/xml/xmlDataSourceInfo.cxx | 119 ++ dbaccess/source/filter/xml/xmlDataSourceInfo.hxx | 37 + .../source/filter/xml/xmlDataSourceSetting.cxx | 215 ++++ .../source/filter/xml/xmlDataSourceSetting.hxx | 60 + .../source/filter/xml/xmlDataSourceSettings.cxx | 66 + .../source/filter/xml/xmlDataSourceSettings.hxx | 39 + dbaccess/source/filter/xml/xmlDatabase.cxx | 135 ++ dbaccess/source/filter/xml/xmlDatabase.hxx | 41 + .../source/filter/xml/xmlDatabaseDescription.cxx | 79 ++ .../source/filter/xml/xmlDatabaseDescription.hxx | 41 + dbaccess/source/filter/xml/xmlDocuments.cxx | 99 ++ dbaccess/source/filter/xml/xmlDocuments.hxx | 56 + dbaccess/source/filter/xml/xmlEnums.hxx | 23 + dbaccess/source/filter/xml/xmlExport.cxx | 1342 ++++++++++++++++++++ dbaccess/source/filter/xml/xmlExport.hxx | 176 +++ .../source/filter/xml/xmlFileBasedDatabase.cxx | 113 ++ .../source/filter/xml/xmlFileBasedDatabase.hxx | 36 + dbaccess/source/filter/xml/xmlHelper.cxx | 157 +++ dbaccess/source/filter/xml/xmlHelper.hxx | 57 + .../source/filter/xml/xmlHierarchyCollection.cxx | 131 ++ .../source/filter/xml/xmlHierarchyCollection.hxx | 55 + dbaccess/source/filter/xml/xmlLogin.cxx | 111 ++ dbaccess/source/filter/xml/xmlLogin.hxx | 37 + dbaccess/source/filter/xml/xmlQuery.cxx | 117 ++ dbaccess/source/filter/xml/xmlQuery.hxx | 46 + dbaccess/source/filter/xml/xmlServerDatabase.cxx | 136 ++ dbaccess/source/filter/xml/xmlServerDatabase.hxx | 36 + dbaccess/source/filter/xml/xmlStyleImport.cxx | 263 ++++ dbaccess/source/filter/xml/xmlStyleImport.hxx | 98 ++ dbaccess/source/filter/xml/xmlTable.cxx | 226 ++++ dbaccess/source/filter/xml/xmlTable.hxx | 67 + dbaccess/source/filter/xml/xmlTableFilterList.cxx | 95 ++ dbaccess/source/filter/xml/xmlTableFilterList.hxx | 64 + .../source/filter/xml/xmlTableFilterPattern.cxx | 59 + .../source/filter/xml/xmlTableFilterPattern.hxx | 44 + dbaccess/source/filter/xml/xmlfilter.cxx | 617 +++++++++ dbaccess/source/filter/xml/xmlfilter.hxx | 121 ++ 51 files changed, 6832 insertions(+) create mode 100644 dbaccess/source/filter/xml/dbaxml.component create mode 100644 dbaccess/source/filter/xml/dbloader2.cxx create mode 100644 dbaccess/source/filter/xml/xmlAutoStyle.cxx create mode 100644 dbaccess/source/filter/xml/xmlAutoStyle.hxx create mode 100644 dbaccess/source/filter/xml/xmlColumn.cxx create mode 100644 dbaccess/source/filter/xml/xmlColumn.hxx create mode 100644 dbaccess/source/filter/xml/xmlComponent.cxx create mode 100644 dbaccess/source/filter/xml/xmlComponent.hxx create mode 100644 dbaccess/source/filter/xml/xmlConnectionData.cxx create mode 100644 dbaccess/source/filter/xml/xmlConnectionData.hxx create mode 100644 dbaccess/source/filter/xml/xmlConnectionResource.cxx create mode 100644 dbaccess/source/filter/xml/xmlConnectionResource.hxx create mode 100644 dbaccess/source/filter/xml/xmlDataSource.cxx create mode 100644 dbaccess/source/filter/xml/xmlDataSource.hxx create mode 100644 dbaccess/source/filter/xml/xmlDataSourceInfo.cxx create mode 100644 dbaccess/source/filter/xml/xmlDataSourceInfo.hxx create mode 100644 dbaccess/source/filter/xml/xmlDataSourceSetting.cxx create mode 100644 dbaccess/source/filter/xml/xmlDataSourceSetting.hxx create mode 100644 dbaccess/source/filter/xml/xmlDataSourceSettings.cxx create mode 100644 dbaccess/source/filter/xml/xmlDataSourceSettings.hxx create mode 100644 dbaccess/source/filter/xml/xmlDatabase.cxx create mode 100644 dbaccess/source/filter/xml/xmlDatabase.hxx create mode 100644 dbaccess/source/filter/xml/xmlDatabaseDescription.cxx create mode 100644 dbaccess/source/filter/xml/xmlDatabaseDescription.hxx create mode 100644 dbaccess/source/filter/xml/xmlDocuments.cxx create mode 100644 dbaccess/source/filter/xml/xmlDocuments.hxx create mode 100644 dbaccess/source/filter/xml/xmlEnums.hxx create mode 100644 dbaccess/source/filter/xml/xmlExport.cxx create mode 100644 dbaccess/source/filter/xml/xmlExport.hxx create mode 100644 dbaccess/source/filter/xml/xmlFileBasedDatabase.cxx create mode 100644 dbaccess/source/filter/xml/xmlFileBasedDatabase.hxx create mode 100644 dbaccess/source/filter/xml/xmlHelper.cxx create mode 100644 dbaccess/source/filter/xml/xmlHelper.hxx create mode 100644 dbaccess/source/filter/xml/xmlHierarchyCollection.cxx create mode 100644 dbaccess/source/filter/xml/xmlHierarchyCollection.hxx create mode 100644 dbaccess/source/filter/xml/xmlLogin.cxx create mode 100644 dbaccess/source/filter/xml/xmlLogin.hxx create mode 100644 dbaccess/source/filter/xml/xmlQuery.cxx create mode 100644 dbaccess/source/filter/xml/xmlQuery.hxx create mode 100644 dbaccess/source/filter/xml/xmlServerDatabase.cxx create mode 100644 dbaccess/source/filter/xml/xmlServerDatabase.hxx create mode 100644 dbaccess/source/filter/xml/xmlStyleImport.cxx create mode 100644 dbaccess/source/filter/xml/xmlStyleImport.hxx create mode 100644 dbaccess/source/filter/xml/xmlTable.cxx create mode 100644 dbaccess/source/filter/xml/xmlTable.hxx create mode 100644 dbaccess/source/filter/xml/xmlTableFilterList.cxx create mode 100644 dbaccess/source/filter/xml/xmlTableFilterList.hxx create mode 100644 dbaccess/source/filter/xml/xmlTableFilterPattern.cxx create mode 100644 dbaccess/source/filter/xml/xmlTableFilterPattern.hxx create mode 100644 dbaccess/source/filter/xml/xmlfilter.cxx create mode 100644 dbaccess/source/filter/xml/xmlfilter.hxx (limited to 'dbaccess/source/filter/xml') diff --git a/dbaccess/source/filter/xml/dbaxml.component b/dbaccess/source/filter/xml/dbaxml.component new file mode 100644 index 000000000..4842eb4ad --- /dev/null +++ b/dbaccess/source/filter/xml/dbaxml.component @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dbaccess/source/filter/xml/dbloader2.cxx b/dbaccess/source/filter/xml/dbloader2.cxx new file mode 100644 index 000000000..0513af5a2 --- /dev/null +++ b/dbaccess/source/filter/xml/dbloader2.cxx @@ -0,0 +1,535 @@ +/* -*- 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace ::ucbhelper; +using namespace ::com::sun::star::task; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::ucb; +using namespace ::com::sun::star::io; +using namespace ::com::sun::star::util; +using namespace ::com::sun::star::frame; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::container; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::document; +using namespace ::com::sun::star::sdb; +using namespace ::com::sun::star::embed; +using namespace ::com::sun::star::ui::dialogs; +using ::com::sun::star::awt::XWindow; +using ::com::sun::star::sdb::application::NamedDatabaseObject; + +namespace dbaxml +{ + +namespace { + +class DBTypeDetection : public ::cppu::WeakImplHelper< XExtendedFilterDetection, XServiceInfo> +{ + const Reference< XComponentContext > m_aContext; + +public: + explicit DBTypeDetection(const Reference< XComponentContext >&); + + // XServiceInfo + OUString SAL_CALL getImplementationName() override; + sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override; + Sequence< OUString > SAL_CALL getSupportedServiceNames() override; + + virtual OUString SAL_CALL detect( css::uno::Sequence< css::beans::PropertyValue >& Descriptor ) override; +}; + +} + +DBTypeDetection::DBTypeDetection(const Reference< XComponentContext >& _rxContext) + :m_aContext( _rxContext ) +{ +} + +OUString SAL_CALL DBTypeDetection::detect( css::uno::Sequence< css::beans::PropertyValue >& Descriptor ) +{ + try + { + ::comphelper::NamedValueCollection aMedia( Descriptor ); + bool bStreamFromDescr = false; + OUString sURL = aMedia.getOrDefault( "URL", OUString() ); + + Reference< XInputStream > xInStream( aMedia.getOrDefault( "InputStream", Reference< XInputStream >() ) ); + Reference< XPropertySet > xStorageProperties; + if ( xInStream.is() ) + { + bStreamFromDescr = true; + xStorageProperties.set( ::comphelper::OStorageHelper::GetStorageFromInputStream( + xInStream, m_aContext ), UNO_QUERY ); + } + else + { + OUString sSalvagedURL( aMedia.getOrDefault( "SalvagedFile", OUString() ) ); + + OUString sFileLocation( sSalvagedURL.isEmpty() ? sURL : sSalvagedURL ); + if ( !sFileLocation.isEmpty() ) + { + xStorageProperties.set( ::comphelper::OStorageHelper::GetStorageFromURL( + sFileLocation, ElementModes::READ, m_aContext ), UNO_QUERY ); + } + } + + if ( xStorageProperties.is() ) + { + OUString sMediaType; + xStorageProperties->getPropertyValue( INFO_MEDIATYPE ) >>= sMediaType; + if ( sMediaType == MIMETYPE_OASIS_OPENDOCUMENT_DATABASE_ASCII || sMediaType == MIMETYPE_VND_SUN_XML_BASE_ASCII ) + { + if ( bStreamFromDescr && !sURL.startsWith( "private:stream" ) ) + { + // After fixing of the i88522 issue ( use the new file locking for database files ) the stream from the type detection can be used further + // for now the file should be reopened to have read/write access + aMedia.remove( "InputStream" ); + aMedia.remove( "Stream" ); + aMedia >>= Descriptor; + try + { + ::comphelper::disposeComponent(xStorageProperties); + if ( xInStream.is() ) + xInStream->closeInput(); + } + catch( Exception& ) + { + DBG_UNHANDLED_EXCEPTION("dbaccess"); + } + } + + return "StarBase"; + } + ::comphelper::disposeComponent(xStorageProperties); + } + } catch(Exception&){} + return OUString(); +} + +// XServiceInfo +OUString SAL_CALL DBTypeDetection::getImplementationName() +{ + return "org.openoffice.comp.dbflt.DBTypeDetection"; +} + +// XServiceInfo +sal_Bool SAL_CALL DBTypeDetection::supportsService(const OUString& ServiceName) +{ + return cppu::supportsService(this, ServiceName); +} + +// XServiceInfo +Sequence< OUString > SAL_CALL DBTypeDetection::getSupportedServiceNames() +{ + return { "com.sun.star.document.ExtendedTypeDetection" }; +} + +} // namespace dbaxml + +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* +org_openoffice_comp_dbflt_DBTypeDetection_get_implementation( + css::uno::XComponentContext* context, css::uno::Sequence const& ) +{ + return cppu::acquire(new ::dbaxml::DBTypeDetection(context)); +} + +namespace dbaxml +{ + +namespace { + +class DBContentLoader : public ::cppu::WeakImplHelper< XFrameLoader, XServiceInfo> +{ +private: + const Reference< XComponentContext > m_aContext; + Reference< XFrameLoader > m_xMySelf; + OUString m_sCurrentURL; + ImplSVEvent * m_nStartWizard; + + DECL_LINK( OnStartTableWizard, void*, void ); +public: + explicit DBContentLoader(const Reference< XComponentContext >&); + + // XServiceInfo + OUString SAL_CALL getImplementationName() override; + sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override; + Sequence< OUString > SAL_CALL getSupportedServiceNames() override; + + // XLoader + virtual void SAL_CALL load( const Reference< XFrame > & _rFrame, const OUString& _rURL, + const Sequence< PropertyValue >& _rArgs, + const Reference< XLoadEventListener > & _rListener) override; + virtual void SAL_CALL cancel() override; + +private: + bool impl_executeNewDatabaseWizard( Reference< XModel > const & _rxModel, bool& _bShouldStartTableWizard ); +}; + +} + +DBContentLoader::DBContentLoader(const Reference< XComponentContext >& _rxFactory) + :m_aContext( _rxFactory ) + ,m_nStartWizard(nullptr) +{ + +} + +// XServiceInfo +OUString SAL_CALL DBContentLoader::getImplementationName() +{ + return "org.openoffice.comp.dbflt.DBContentLoader2"; +} + +// XServiceInfo +sal_Bool SAL_CALL DBContentLoader::supportsService(const OUString& ServiceName) +{ + return cppu::supportsService(this, ServiceName); +} + +// XServiceInfo +Sequence< OUString > SAL_CALL DBContentLoader::getSupportedServiceNames() +{ + return { "com.sun.star.frame.FrameLoader" }; +} + + +namespace +{ + bool lcl_urlAllowsInteraction( const Reference & _rContext, const OUString& _rURL ) + { + bool bDoesAllow = false; + try + { + Reference< XURLTransformer > xTransformer( URLTransformer::create(_rContext) ); + URL aURL; + aURL.Complete = _rURL; + xTransformer->parseStrict( aURL ); + bDoesAllow = aURL.Arguments == "Interactive"; + } + catch( const Exception& ) + { + TOOLS_WARN_EXCEPTION( "dbaccess", "lcl_urlAllowsInteraction: caught an exception while analyzing the URL!" ); + } + return bDoesAllow; + } + + Reference< XWindow > lcl_getTopMostWindow( const Reference & _rxContext ) + { + Reference< XWindow > xWindow; + // get the top most window + Reference < XDesktop2 > xDesktop = Desktop::create(_rxContext); + Reference < XFrame > xActiveFrame = xDesktop->getActiveFrame(); + if ( xActiveFrame.is() ) + { + xWindow = xActiveFrame->getContainerWindow(); + Reference xFrame = xActiveFrame; + while ( xFrame.is() && !xFrame->isTop() ) + xFrame = xFrame->getCreator(); + + if ( xFrame.is() ) + xWindow = xFrame->getContainerWindow(); + } + return xWindow; + } +} + +bool DBContentLoader::impl_executeNewDatabaseWizard( Reference< XModel > const & _rxModel, bool& _bShouldStartTableWizard ) +{ + Sequence aWizardArgs(comphelper::InitAnyPropertySequence( + { + {"ParentWindow", Any(lcl_getTopMostWindow( m_aContext ))}, + {"InitialSelection", Any(_rxModel)} + })); + + // create the dialog + Reference< XExecutableDialog > xAdminDialog( m_aContext->getServiceManager()->createInstanceWithArgumentsAndContext("com.sun.star.sdb.DatabaseWizardDialog", aWizardArgs, m_aContext), UNO_QUERY_THROW); + + // execute it + if ( RET_OK != xAdminDialog->execute() ) + return false; + + Reference xProp(xAdminDialog,UNO_QUERY); + bool bSuccess = false; + xProp->getPropertyValue("OpenDatabase") >>= bSuccess; + xProp->getPropertyValue("StartTableWizard") >>= _bShouldStartTableWizard; + return bSuccess; +} + +void SAL_CALL DBContentLoader::load(const Reference< XFrame > & rFrame, const OUString& _rURL, + const Sequence< PropertyValue >& rArgs, + const Reference< XLoadEventListener > & rListener) +{ + // first check if preview is true, if so return without creating a controller. Preview is not supported + ::comphelper::NamedValueCollection aMediaDesc( rArgs ); + bool bPreview = aMediaDesc.getOrDefault( "Preview", false ); + if ( bPreview ) + { + if (rListener.is()) + rListener->loadCancelled(this); + return; + } + + Reference< XModel > xModel = aMediaDesc.getOrDefault( "Model", Reference< XModel >() ); + OUString sSalvagedURL = aMediaDesc.getOrDefault( "SalvagedFile", _rURL ); + + bool bCreateNew = false; // does the URL denote the private:factory URL? + bool bStartTableWizard = false; // start the table wizard after everything was loaded successfully? + + bool bSuccess = true; + + // If there's no interaction handler in the media descriptor, put one. + // By definition, loading via loadComponentFromURL (and thus via the content loader here) + // is allowed to raise UI. To not burden every place inside the document with creating + // a default handler, we simply ensure there is one. + // If a handler is present in the media descriptor, even if it is NULL, we will + // not touch it. + if ( !aMediaDesc.has( "InteractionHandler" ) ) + { + Reference< XInteractionHandler2 > xHandler( InteractionHandler::createWithParent(m_aContext, nullptr) ); + aMediaDesc.put( "InteractionHandler", xHandler ); + } + + // it's allowed to pass an existing document + Reference< XOfficeDatabaseDocument > xExistentDBDoc; + xModel.set( aMediaDesc.getOrDefault( "Model", xExistentDBDoc ), UNO_QUERY ); + aMediaDesc.remove( "Model" ); + + // also, it's allowed to specify the type of view which should be created + OUString sViewName = aMediaDesc.getOrDefault( "ViewName", OUString( "Default" ) ); + aMediaDesc.remove( "ViewName" ); + + // this needs to stay alive for duration of this method + Reference< XDatabaseContext > xDatabaseContext; + + sal_Int32 nInitialSelection = -1; + if ( !xModel.is() ) + { + xDatabaseContext = DatabaseContext::create(m_aContext); + + OUString sFactoryName = SvtModuleOptions().GetFactoryEmptyDocumentURL(SvtModuleOptions::EFactory::DATABASE); + bCreateNew = sFactoryName.match(_rURL); + + Reference< XDocumentDataSource > xDocumentDataSource; + bool bNewAndInteractive = false; + if ( bCreateNew ) + { + bNewAndInteractive = lcl_urlAllowsInteraction( m_aContext, _rURL ); + xDocumentDataSource.set( xDatabaseContext->createInstance(), UNO_QUERY_THROW ); + } + else + { + ::comphelper::NamedValueCollection aCreationArgs; + aCreationArgs.put( INFO_POOLURL, sSalvagedURL ); + xDocumentDataSource.set( xDatabaseContext->createInstanceWithArguments( aCreationArgs.getWrappedNamedValues() ), UNO_QUERY_THROW ); + } + + xModel.set( xDocumentDataSource->getDatabaseDocument(), UNO_QUERY ); + + if ( bCreateNew && xModel.is() ) + { + if ( bNewAndInteractive ) + { + bSuccess = impl_executeNewDatabaseWizard( xModel, bStartTableWizard ); + } + else + { + try + { + Reference< XLoadable > xLoad( xModel, UNO_QUERY_THROW ); + xLoad->initNew(); + bSuccess = true; + } + catch( const Exception& ) + { + bSuccess = false; + } + } + + // initially select the "Tables" category (will be done below) + nInitialSelection = css::sdb::application::DatabaseObjectContainer::TABLES; + } + } + + if ( !xModel.is() ) + { + if ( rListener.is() ) + rListener->loadCancelled(this); + return; + } + + if ( !bCreateNew ) + { + // We need to XLoadable::load the document if it does not yet have a URL. + // If it already *does* have a URL, then it was either passed in the arguments, or a previous incarnation + // of that model existed before (which can happen if a model is closed, but an associated DataSource is kept + // alive 'til loading the document again). + bool bNeedLoad = xModel->getURL().isEmpty(); + try + { + aMediaDesc.put( "FileName", _rURL ); + Sequence< PropertyValue > aResource( aMediaDesc.getPropertyValues() ); + + if ( bNeedLoad ) + { + Reference< XLoadable > xLoad( xModel, UNO_QUERY_THROW ); + xLoad->load( aResource ); + } + + // always attach the resource, even if the document has not been freshly loaded + xModel->attachResource( _rURL, aResource ); + } + catch(const Exception&) + { + DBG_UNHANDLED_EXCEPTION("dbaccess"); + bSuccess = false; + } + } + + if ( bSuccess ) + { + try + { + Reference< XModel2 > xModel2( xModel, UNO_QUERY_THROW ); + Reference< XController2 > xController( xModel2->createViewController( sViewName, Sequence< PropertyValue >(), rFrame ), UNO_SET_THROW ); + + xController->attachModel( xModel ); + xModel->connectController( xController ); + rFrame->setComponent( xController->getComponentWindow(), xController ); + xController->attachFrame( rFrame ); + xModel->setCurrentController( xController ); + + bSuccess = true; + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION("dbaccess"); + bSuccess = false; + } + } + + if (bSuccess) + { + if ( rListener.is() ) + rListener->loadFinished(this); + + if ( nInitialSelection != -1 ) + { + Reference< css::view::XSelectionSupplier > xDocView( xModel->getCurrentController(), UNO_QUERY ); + if ( xDocView.is() ) + { + NamedDatabaseObject aSelection; + aSelection.Type = nInitialSelection; + xDocView->select( Any( aSelection ) ); + } + } + + if ( bStartTableWizard ) + { + // reset the data of the previous async drop (if any) + if ( m_nStartWizard ) + Application::RemoveUserEvent(m_nStartWizard); + m_sCurrentURL = xModel->getURL(); + m_xMySelf = this; + m_nStartWizard = Application::PostUserEvent(LINK(this, DBContentLoader, OnStartTableWizard)); + } + } + else + { + if ( rListener.is() ) + rListener->loadCancelled( this ); + } + + if ( !bSuccess ) + ::comphelper::disposeComponent(xModel); +} + +void DBContentLoader::cancel() +{ +} + +IMPL_LINK_NOARG( DBContentLoader, OnStartTableWizard, void*, void ) +{ + m_nStartWizard = nullptr; + try + { + Sequence aWizArgs(comphelper::InitAnyPropertySequence( + { + {"DatabaseLocation", Any(m_sCurrentURL)} + })); + SolarMutexGuard aGuard; + Reference< XJobExecutor > xTableWizard( m_aContext->getServiceManager()->createInstanceWithArgumentsAndContext("com.sun.star.wizards.table.CallTableWizard", aWizArgs, m_aContext), UNO_QUERY); + if ( xTableWizard.is() ) + xTableWizard->trigger("start"); + } + catch(const Exception&) + { + TOOLS_WARN_EXCEPTION( "dbaccess", "caught an exception while starting the table wizard!"); + } + m_xMySelf = nullptr; +} + +} + +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* +org_openoffice_comp_dbflt_DBContentLoader2_get_implementation( + css::uno::XComponentContext* context, css::uno::Sequence const& ) +{ + return cppu::acquire(new ::dbaxml::DBContentLoader(context)); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/filter/xml/xmlAutoStyle.cxx b/dbaccess/source/filter/xml/xmlAutoStyle.cxx new file mode 100644 index 000000000..991015671 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlAutoStyle.cxx @@ -0,0 +1,82 @@ +/* -*- 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 dbaxml +{ + 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_COLUMN ) + return; + + rtl::Reference< XMLPropertySetMapper > aPropMapper = rODBExport.GetColumnStylesPropertySetMapper(); + for (auto const& property : rProperties) + { + sal_Int16 nContextID = aPropMapper->GetEntryContextId(property.mnIndex); + switch (nContextID) + { + case CTF_DB_NUMBERFORMAT : + { + sal_Int32 nNumberFormat = 0; + if ( property.maValue >>= nNumberFormat ) + { + OUString sAttrValue = rODBExport.getDataStyleName(nNumberFormat); + if ( !sAttrValue.isEmpty() ) + { + GetExport().AddAttribute( + aPropMapper->GetEntryNameSpace(property.mnIndex), + aPropMapper->GetEntryXMLName(property.mnIndex), + sAttrValue ); + } + } + break; + } + } + } +} + +OXMLAutoStylePoolP::OXMLAutoStylePoolP(ODBExport& rTempODBExport): + SvXMLAutoStylePoolP(rTempODBExport), + rODBExport(rTempODBExport) +{ + +} + +OXMLAutoStylePoolP::~OXMLAutoStylePoolP() +{ + +} + +} // namespace dbaxml + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/filter/xml/xmlAutoStyle.hxx b/dbaccess/source/filter/xml/xmlAutoStyle.hxx new file mode 100644 index 000000000..54748a22c --- /dev/null +++ b/dbaccess/source/filter/xml/xmlAutoStyle.hxx @@ -0,0 +1,45 @@ +/* -*- 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 . + */ +#pragma once +#include +#include + +namespace dbaxml +{ + class ODBExport; + class OXMLAutoStylePoolP : public SvXMLAutoStylePoolP + { + ODBExport& rODBExport; + + virtual void exportStyleAttributes( + SvXMLAttributeList& rAttrList, + XmlStyleFamily nFamily, + const std::vector< XMLPropertyState >& rProperties, + const SvXMLExportPropertyMapper& rPropExp, + const SvXMLUnitConverter& rUnitConverter, + const SvXMLNamespaceMap& rNamespaceMap + ) const override; + + public: + explicit OXMLAutoStylePoolP(ODBExport& rXMLExport); + virtual ~OXMLAutoStylePoolP() override; + }; +} // dbaxml + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/filter/xml/xmlColumn.cxx b/dbaccess/source/filter/xml/xmlColumn.cxx new file mode 100644 index 000000000..1afbf9f0f --- /dev/null +++ b/dbaccess/source/filter/xml/xmlColumn.cxx @@ -0,0 +1,162 @@ +/* -*- 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 "xmlfilter.hxx" +#include +#include +#include +#include +#include "xmlStyleImport.hxx" +#include + +namespace dbaxml +{ + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::beans; + using namespace ::com::sun::star::sdbcx; + using namespace ::com::sun::star::container; + using namespace ::com::sun::star::xml::sax; + +OXMLColumn::OXMLColumn( ODBFilter& rImport + ,const Reference< XFastAttributeList > & _xAttrList + ,const Reference< XNameAccess >& _xParentContainer + ,const Reference< XPropertySet >& _xTable + ) : + SvXMLImportContext( rImport ) + ,m_xParentContainer(_xParentContainer) + ,m_xTable(_xTable) + ,m_bHidden(false) +{ + OUString sType; + for (auto &aIter : sax_fastparser::castToFastAttributeList( _xAttrList )) + { + switch( aIter.getToken() & TOKEN_MASK ) + { + case XML_NAME: + m_sName = aIter.toString(); + break; + case XML_STYLE_NAME: + m_sStyleName = aIter.toString(); + break; + case XML_HELP_MESSAGE: + m_sHelpMessage = aIter.toString(); + break; + case XML_VISIBILITY: + m_bHidden = aIter.toView() != "visible"; + break; + case XML_TYPE_NAME: + sType = aIter.toString(); + OSL_ENSURE(!sType.isEmpty(),"No type name set"); + break; + case XML_DEFAULT_VALUE: + if ( !(aIter.isEmpty() || sType.isEmpty()) ) + m_aDefaultValue <<= aIter.toString(); + break; + case XML_VISIBLE: + m_bHidden = aIter.toView() == "false"; + break; + case XML_DEFAULT_CELL_STYLE_NAME: + m_sCellStyleName = aIter.toString(); + break; + default: + XMLOFF_WARN_UNKNOWN("dbaccess", aIter); + } + } +} + +OXMLColumn::~OXMLColumn() +{ + +} + +void OXMLColumn::endFastElement(sal_Int32 ) +{ + Reference xFac(m_xParentContainer,UNO_QUERY); + if ( xFac.is() && !m_sName.isEmpty() ) + { + Reference xProp(xFac->createDataDescriptor()); + if ( xProp.is() ) + { + xProp->setPropertyValue(PROPERTY_NAME,Any(m_sName)); + xProp->setPropertyValue(PROPERTY_HIDDEN,Any(m_bHidden)); + if ( !m_sHelpMessage.isEmpty() ) + xProp->setPropertyValue(PROPERTY_HELPTEXT,Any(m_sHelpMessage)); + + if ( m_aDefaultValue.hasValue() ) + xProp->setPropertyValue(PROPERTY_CONTROLDEFAULT,m_aDefaultValue); + + Reference xAppend(m_xParentContainer,UNO_QUERY); + if ( xAppend.is() ) + xAppend->appendByDescriptor(xProp); + m_xParentContainer->getByName(m_sName) >>= xProp; + + if ( !m_sStyleName.isEmpty() ) + { + const SvXMLStylesContext* pAutoStyles = GetOwnImport().GetAutoStyles(); + if ( pAutoStyles ) + { + OTableStyleContext* pAutoStyle = const_cast( + dynamic_cast< const OTableStyleContext* >(pAutoStyles->FindStyleChildContext(XmlStyleFamily::TABLE_COLUMN,m_sStyleName))); + if ( pAutoStyle ) + { + pAutoStyle->FillPropertySet(xProp); + } + } + } + if ( !m_sCellStyleName.isEmpty() ) + { + const SvXMLStylesContext* pAutoStyles = GetOwnImport().GetAutoStyles(); + if ( pAutoStyles ) + { + OTableStyleContext* pAutoStyle = const_cast(dynamic_cast(pAutoStyles->FindStyleChildContext(XmlStyleFamily::TABLE_CELL,m_sCellStyleName))); + if ( pAutoStyle ) + { + pAutoStyle->FillPropertySet(xProp); + // we also have to do this on the table to import text-properties + pAutoStyle->FillPropertySet(m_xTable); + } + } + } + + } + } + else if ( !m_sCellStyleName.isEmpty() ) + { + const SvXMLStylesContext* pAutoStyles = GetOwnImport().GetAutoStyles(); + if ( pAutoStyles ) + { + OTableStyleContext* pAutoStyle = const_cast(dynamic_cast< const OTableStyleContext* >(pAutoStyles->FindStyleChildContext(XmlStyleFamily::TABLE_CELL,m_sCellStyleName))); + if ( pAutoStyle ) + { + // we also have to do this on the table to import text-properties + pAutoStyle->FillPropertySet(m_xTable); + } + } + } +} + +ODBFilter& OXMLColumn::GetOwnImport() +{ + return static_cast(GetImport()); +} + +} // namespace dbaxml + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/filter/xml/xmlColumn.hxx b/dbaccess/source/filter/xml/xmlColumn.hxx new file mode 100644 index 000000000..8deca87c7 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlColumn.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 . + */ +#pragma once + +#include +#include +#include + +namespace dbaxml +{ + class ODBFilter; + class OXMLColumn : public SvXMLImportContext + { + css::uno::Reference< css::container::XNameAccess > m_xParentContainer; + css::uno::Reference< css::beans::XPropertySet > m_xTable; + + OUString m_sName; + OUString m_sStyleName; + OUString m_sCellStyleName; + OUString m_sHelpMessage; + css::uno::Any m_aDefaultValue; + bool m_bHidden; + + ODBFilter& GetOwnImport(); + public: + + OXMLColumn( ODBFilter& rImport + ,const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList + ,const css::uno::Reference< css::container::XNameAccess >& _xParentContainer + ,const css::uno::Reference< css::beans::XPropertySet >& _xTable + ); + virtual ~OXMLColumn() override; + virtual void SAL_CALL endFastElement(sal_Int32 nElement) override; + }; +} // namespace dbaxml + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/filter/xml/xmlComponent.cxx b/dbaccess/source/filter/xml/xmlComponent.cxx new file mode 100644 index 000000000..97423f14a --- /dev/null +++ b/dbaccess/source/filter/xml/xmlComponent.cxx @@ -0,0 +1,99 @@ +/* -*- 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 +#include +#include +#include + +namespace dbaxml +{ + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::beans; + using namespace ::com::sun::star::container; + using namespace ::com::sun::star::xml::sax; + +OXMLComponent::OXMLComponent( ODBFilter& rImport + ,const Reference< XFastAttributeList > & _xAttrList + ,const Reference< XNameAccess >& _xParentContainer + ,const OUString& _sComponentServiceName + ) : + SvXMLImportContext( rImport ) +{ + OUString sName; + OUString sHREF; + bool bAsTemplate(false); + for (auto &aIter : sax_fastparser::castToFastAttributeList( _xAttrList )) + { + switch( aIter.getToken() ) + { + case XML_ELEMENT(XLINK, XML_HREF): + sHREF = aIter.toString(); + break; + case XML_ELEMENT(DB, XML_NAME): + case XML_ELEMENT(DB_OASIS, XML_NAME): + sName = aIter.toString(); + // sanitize the name. Previously, we allowed to create forms/reports/queries which contain + // a / in their name, which nowadays is forbidden. To not lose such objects if they're contained + // in older files, we replace the slash with something less offending. + sName = sName.replace( '/', '_' ); + break; + case XML_ELEMENT(DB, XML_AS_TEMPLATE): + case XML_ELEMENT(DB_OASIS, XML_AS_TEMPLATE): + bAsTemplate = IsXMLToken(aIter, XML_TRUE); + break; + default: + XMLOFF_WARN_UNKNOWN("dbaccess", aIter); + } + } + if ( !(!sHREF.isEmpty() && !sName.isEmpty() && _xParentContainer.is()) ) + return; + + Sequence aArguments(comphelper::InitAnyPropertySequence( + { + {PROPERTY_NAME, Any(sName)}, // set as folder + {PROPERTY_PERSISTENT_NAME, Any(sHREF.copy(sHREF.lastIndexOf('/')+1))}, + {PROPERTY_AS_TEMPLATE, Any(bAsTemplate)}, + })); + try + { + Reference< XMultiServiceFactory > xORB( _xParentContainer, UNO_QUERY_THROW ); + Reference< XInterface > xComponent( xORB->createInstanceWithArguments( _sComponentServiceName, aArguments ) ); + Reference< XNameContainer > xNameContainer( _xParentContainer, UNO_QUERY_THROW ); + xNameContainer->insertByName( sName, Any( xComponent ) ); + } + catch(Exception&) + { + DBG_UNHANDLED_EXCEPTION("dbaccess"); + } +} + +OXMLComponent::~OXMLComponent() +{ + +} + +} // namespace dbaxml + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/filter/xml/xmlComponent.hxx b/dbaccess/source/filter/xml/xmlComponent.hxx new file mode 100644 index 000000000..136d5b685 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlComponent.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 . + */ +#pragma once + +#include +#include + +namespace dbaxml +{ + class ODBFilter; + class OXMLComponent : public SvXMLImportContext + { + public: + + OXMLComponent( ODBFilter& rImport + ,const css::uno::Reference< css::xml::sax::XFastAttributeList > & _xAttrList + ,const css::uno::Reference< css::container::XNameAccess >& _xParentContainer + ,const OUString& _sComponentServiceName + ); + virtual ~OXMLComponent() override; + }; +} // namespace dbaxml + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/filter/xml/xmlConnectionData.cxx b/dbaccess/source/filter/xml/xmlConnectionData.cxx new file mode 100644 index 000000000..221358537 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlConnectionData.cxx @@ -0,0 +1,93 @@ +/* -*- 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 "xmlConnectionData.hxx" +#include "xmlLogin.hxx" +#include "xmlfilter.hxx" +#include +#include +#include "xmlEnums.hxx" +#include "xmlDatabaseDescription.hxx" +#include "xmlConnectionResource.hxx" +#include + +namespace dbaxml +{ + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::xml::sax; + +OXMLConnectionData::OXMLConnectionData( ODBFilter& rImport) : + SvXMLImportContext( rImport ) + ,m_bFoundOne(false) +{ + rImport.setNewFormat(true); +} + +OXMLConnectionData::~OXMLConnectionData() +{ + +} + +css::uno::Reference< css::xml::sax::XFastContextHandler > OXMLConnectionData::createFastChildContext( + sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) +{ + SvXMLImportContext *pContext = nullptr; + + switch( nElement & TOKEN_MASK ) + { + case XML_LOGIN: + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + pContext = new OXMLLogin( GetOwnImport(), xAttrList ); + break; + case XML_DATABASE_DESCRIPTION: + if ( !m_bFoundOne ) + { + m_bFoundOne = true; + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + pContext = new OXMLDatabaseDescription( GetOwnImport() ); + } + break; + case XML_CONNECTION_RESOURCE: + if ( !m_bFoundOne ) + { + m_bFoundOne = true; + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + pContext = new OXMLConnectionResource( GetOwnImport(), xAttrList ); + } + break; + case XML_COMPOUND_DATABASE: + if ( !m_bFoundOne ) + { + m_bFoundOne = true; + OSL_FAIL("Not supported yet!"); + } + break; + } + + return pContext; +} + +ODBFilter& OXMLConnectionData::GetOwnImport() +{ + return static_cast(GetImport()); +} + +} // namespace dbaxml + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/filter/xml/xmlConnectionData.hxx b/dbaccess/source/filter/xml/xmlConnectionData.hxx new file mode 100644 index 000000000..466c04788 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlConnectionData.hxx @@ -0,0 +1,41 @@ +/* -*- 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 . + */ +#pragma once + +#include + +namespace dbaxml +{ + class ODBFilter; + class OXMLConnectionData : public SvXMLImportContext + { + bool m_bFoundOne; + + ODBFilter& GetOwnImport(); + public: + + OXMLConnectionData( ODBFilter& rImport ); + virtual ~OXMLConnectionData() override; + + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( + sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override; + }; +} // namespace dbaxml + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/filter/xml/xmlConnectionResource.cxx b/dbaccess/source/filter/xml/xmlConnectionResource.cxx new file mode 100644 index 000000000..2df2a1a73 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlConnectionResource.cxx @@ -0,0 +1,88 @@ +/* -*- 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 "xmlConnectionResource.hxx" +#include "xmlfilter.hxx" +#include +#include +#include +#include + +namespace dbaxml +{ + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::xml::sax; + +OXMLConnectionResource::OXMLConnectionResource( ODBFilter& rImport, + const Reference< XFastAttributeList > & _xAttrList) : + SvXMLImportContext( rImport ) +{ + Reference xDataSource = rImport.getDataSource(); + + PropertyValue aProperty; + + if (!xDataSource.is()) + return; + + for (auto &aIter : sax_fastparser::castToFastAttributeList( _xAttrList )) + { + aProperty.Name.clear(); + aProperty.Value = Any(); + + switch( aIter.getToken() ) + { + case XML_ELEMENT(XLINK, XML_HREF): + try + { + xDataSource->setPropertyValue(PROPERTY_URL,Any(aIter.toString())); + } + catch(const Exception&) + { + DBG_UNHANDLED_EXCEPTION("dbaccess"); + } + break; + case XML_ELEMENT(XLINK, XML_TYPE): + aProperty.Name = PROPERTY_TYPE; + break; + case XML_ELEMENT(XLINK, XML_SHOW): + aProperty.Name = "Show"; + break; + case XML_ELEMENT(XLINK, XML_ACTUATE): + aProperty.Name = "Actuate"; + break; + default: + XMLOFF_WARN_UNKNOWN("dbaccess", aIter); + } + if ( !aProperty.Name.isEmpty() ) + { + if ( !aProperty.Value.hasValue() ) + aProperty.Value <<= aIter.toString(); + rImport.addInfo(aProperty); + } + } +} + +OXMLConnectionResource::~OXMLConnectionResource() +{ + +} + +} // namespace dbaxml + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/filter/xml/xmlConnectionResource.hxx b/dbaccess/source/filter/xml/xmlConnectionResource.hxx new file mode 100644 index 000000000..357bbe1e1 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlConnectionResource.hxx @@ -0,0 +1,36 @@ +/* -*- 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 . + */ +#pragma once + +#include + +namespace dbaxml +{ + class ODBFilter; + class OXMLConnectionResource : public SvXMLImportContext + { + public: + + OXMLConnectionResource( ODBFilter& rImport, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ); + virtual ~OXMLConnectionResource() override; + }; +} // namespace dbaxml + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/filter/xml/xmlDataSource.cxx b/dbaccess/source/filter/xml/xmlDataSource.cxx new file mode 100644 index 000000000..bf63d4f79 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlDataSource.cxx @@ -0,0 +1,251 @@ +/* -*- 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 "xmlDataSource.hxx" +#include "xmlLogin.hxx" +#include "xmlTableFilterList.hxx" +#include "xmlDataSourceInfo.hxx" +#include "xmlDataSourceSettings.hxx" +#include "xmlfilter.hxx" +#include +#include +#include "xmlEnums.hxx" +#include +#include +#include "xmlConnectionData.hxx" + +namespace dbaxml +{ + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::xml::sax; + +OXMLDataSource::OXMLDataSource( ODBFilter& rImport, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& _xAttrList, + const UsedFor _eUsedFor ) : + SvXMLImportContext( rImport ) +{ + + Reference xDataSource = rImport.getDataSource(); + + PropertyValue aProperty; + bool bFoundParamNameSubstitution = false; + bool bFoundTableNameLengthLimited = false; + bool bFoundAppendTableAliasName = false; + bool bFoundSuppressVersionColumns = false; + + if (xDataSource.is()) + { + for (auto &aIter : sax_fastparser::castToFastAttributeList( _xAttrList )) + { + aProperty.Name.clear(); + aProperty.Value = Any(); + + switch( aIter.getToken() & TOKEN_MASK ) + { + case XML_CONNECTION_RESOURCE: + try + { + xDataSource->setPropertyValue(PROPERTY_URL,Any(aIter.toString())); + } + catch(const Exception&) + { + DBG_UNHANDLED_EXCEPTION("dbaccess"); + } + break; + case XML_SUPPRESS_VERSION_COLUMNS: + try + { + xDataSource->setPropertyValue(PROPERTY_SUPPRESSVERSIONCL,Any(IsXMLToken(aIter, XML_TRUE))); + bFoundSuppressVersionColumns = true; + } + catch(const Exception&) + { + DBG_UNHANDLED_EXCEPTION("dbaccess"); + } + break; + case XML_JAVA_DRIVER_CLASS: + aProperty.Name = INFO_JDBCDRIVERCLASS; + break; + case XML_EXTENSION: + aProperty.Name = INFO_TEXTFILEEXTENSION; + break; + case XML_IS_FIRST_ROW_HEADER_LINE: + aProperty.Name = INFO_TEXTFILEHEADER; + aProperty.Value <<= IsXMLToken(aIter, XML_TRUE); + break; + case XML_SHOW_DELETED: + aProperty.Name = INFO_SHOWDELETEDROWS; + aProperty.Value <<= IsXMLToken(aIter, XML_TRUE); + break; + case XML_IS_TABLE_NAME_LENGTH_LIMITED: + aProperty.Name = INFO_ALLOWLONGTABLENAMES; + aProperty.Value <<= IsXMLToken(aIter, XML_TRUE); + bFoundTableNameLengthLimited = true; + break; + case XML_SYSTEM_DRIVER_SETTINGS: + aProperty.Name = INFO_ADDITIONALOPTIONS; + break; + case XML_ENABLE_SQL92_CHECK: + aProperty.Name = PROPERTY_ENABLESQL92CHECK; + aProperty.Value <<= IsXMLToken(aIter, XML_TRUE); + break; + case XML_APPEND_TABLE_ALIAS_NAME: + aProperty.Name = INFO_APPEND_TABLE_ALIAS; + aProperty.Value <<= IsXMLToken(aIter, XML_TRUE); + bFoundAppendTableAliasName = true; + break; + case XML_PARAMETER_NAME_SUBSTITUTION: + aProperty.Name = INFO_PARAMETERNAMESUBST; + aProperty.Value <<= IsXMLToken(aIter, XML_TRUE); + bFoundParamNameSubstitution = true; + break; + case XML_IGNORE_DRIVER_PRIVILEGES: + aProperty.Name = INFO_IGNOREDRIVER_PRIV; + aProperty.Value <<= IsXMLToken(aIter, XML_TRUE); + break; + case XML_BOOLEAN_COMPARISON_MODE: + aProperty.Name = PROPERTY_BOOLEANCOMPARISONMODE; + if ( aIter.toView() == "equal-integer" ) + aProperty.Value <<= sal_Int32(0); + else if ( aIter.toView() == "is-boolean" ) + aProperty.Value <<= sal_Int32(1); + else if ( aIter.toView() == "equal-boolean" ) + aProperty.Value <<= sal_Int32(2); + else if ( aIter.toView() == "equal-use-only-zero" ) + aProperty.Value <<= sal_Int32(3); + break; + case XML_USE_CATALOG: + aProperty.Name = INFO_USECATALOG; + aProperty.Value <<= IsXMLToken(aIter, XML_TRUE); + break; + case XML_BASE_DN: + aProperty.Name = INFO_CONN_LDAP_BASEDN; + break; + case XML_MAX_ROW_COUNT: + aProperty.Name = INFO_CONN_LDAP_ROWCOUNT; + aProperty.Value <<= aIter.toInt32(); + break; + case XML_JAVA_CLASSPATH: + aProperty.Name = "JavaDriverClassPath"; + break; + default: + XMLOFF_WARN_UNKNOWN("dbaccess", aIter); + } + if ( !aProperty.Name.isEmpty() ) + { + if ( !aProperty.Value.hasValue() ) + aProperty.Value <<= aIter.toString(); + rImport.addInfo(aProperty); + } + } + } + if ( !rImport.isNewFormat() ) + return; + + if ( !bFoundTableNameLengthLimited && ( _eUsedFor == eAppSettings ) ) + { + aProperty.Name = INFO_ALLOWLONGTABLENAMES; + aProperty.Value <<= true; + rImport.addInfo(aProperty); + } + if ( !bFoundParamNameSubstitution && ( _eUsedFor == eDriverSettings ) ) + { + aProperty.Name = INFO_PARAMETERNAMESUBST; + aProperty.Value <<= true; + rImport.addInfo(aProperty); + } + if ( !bFoundAppendTableAliasName && ( _eUsedFor == eAppSettings ) ) + { + aProperty.Name = INFO_APPEND_TABLE_ALIAS; + aProperty.Value <<= true; + rImport.addInfo(aProperty); + } + if ( !bFoundSuppressVersionColumns && ( _eUsedFor == eAppSettings ) ) + { + try + { + xDataSource->setPropertyValue(PROPERTY_SUPPRESSVERSIONCL,Any(true)); + } + catch(const Exception&) + { + DBG_UNHANDLED_EXCEPTION("dbaccess"); + } + } +} + +OXMLDataSource::~OXMLDataSource() +{ + +} + +css::uno::Reference< css::xml::sax::XFastContextHandler > OXMLDataSource::createFastChildContext( + sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) +{ + SvXMLImportContext *pContext = nullptr; + + switch( nElement & TOKEN_MASK ) + { + case XML_LOGIN: + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + pContext = new OXMLLogin( GetOwnImport(), xAttrList ); + break; + + case XML_TABLE_FILTER: + case XML_TABLE_TYPE_FILTER: + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + pContext = new OXMLTableFilterList( GetImport() ); + break; + case XML_AUTO_INCREMENT: + case XML_DELIMITER: + case XML_FONT_CHARSET: + case XML_CHARACTER_SET: + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + pContext = new OXMLDataSourceInfo( GetOwnImport(), nElement, xAttrList ); + break; + case XML_DATA_SOURCE_SETTINGS: + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + pContext = new OXMLDataSourceSettings( GetOwnImport() ); + break; + case XML_CONNECTION_DATA: + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + pContext = new OXMLConnectionData( GetOwnImport() ); + break; + case XML_DRIVER_SETTINGS: + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + pContext = new OXMLDataSource( GetOwnImport(), xAttrList, OXMLDataSource::eDriverSettings ); + break; + case XML_APPLICATION_CONNECTION_SETTINGS: + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + pContext = new OXMLDataSource( GetOwnImport(), xAttrList, OXMLDataSource::eAppSettings ); + break; + default: + SAL_WARN("dbaccess", "unknown element " << nElement); + } + + return pContext; +} + +ODBFilter& OXMLDataSource::GetOwnImport() +{ + return static_cast(GetImport()); +} + +} // namespace dbaxml + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/filter/xml/xmlDataSource.hxx b/dbaccess/source/filter/xml/xmlDataSource.hxx new file mode 100644 index 000000000..5b78ff4fe --- /dev/null +++ b/dbaccess/source/filter/xml/xmlDataSource.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 . + */ +#pragma once + +#include + +namespace dbaxml +{ + class ODBFilter; + class OXMLDataSource : public SvXMLImportContext + { + ODBFilter& GetOwnImport(); + public: + enum UsedFor + { + eDataSource, + eDriverSettings, + eAppSettings + }; + + OXMLDataSource( ODBFilter& rImport, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& _xAttrList, + const UsedFor _eUsedFor ); + virtual ~OXMLDataSource() override; + + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( + sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override; + }; +} // namespace dbaxml + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/filter/xml/xmlDataSourceInfo.cxx b/dbaccess/source/filter/xml/xmlDataSourceInfo.cxx new file mode 100644 index 000000000..eefc08e41 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlDataSourceInfo.cxx @@ -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 . + */ + +#include "xmlDataSourceInfo.hxx" +#include "xmlfilter.hxx" +#include +#include +#include + +namespace dbaxml +{ + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::xml::sax; + +OXMLDataSourceInfo::OXMLDataSourceInfo( ODBFilter& rImport + ,sal_Int32 nElement + ,const Reference< XFastAttributeList > & _xAttrList) : + SvXMLImportContext( rImport ) +{ + PropertyValue aProperty; + bool bAutoEnabled = false; + bool bFoundField = false,bFoundThousand = false, bFoundCharset = false; + for (auto &aIter : sax_fastparser::castToFastAttributeList( _xAttrList )) + { + aProperty.Name.clear(); + + switch( aIter.getToken() & TOKEN_MASK ) + { + case XML_ADDITIONAL_COLUMN_STATEMENT: + aProperty.Name = PROPERTY_AUTOINCREMENTCREATION; + bAutoEnabled = true; + break; + case XML_ROW_RETRIEVING_STATEMENT: + aProperty.Name = INFO_AUTORETRIEVEVALUE; + bAutoEnabled = true; + break; + case XML_STRING: + aProperty.Name = INFO_TEXTDELIMITER; + break; + case XML_FIELD: + aProperty.Name = INFO_FIELDDELIMITER; + bFoundField = true; + break; + case XML_DECIMAL: + aProperty.Name = INFO_DECIMALDELIMITER; + break; + case XML_THOUSAND: + aProperty.Name = INFO_THOUSANDSDELIMITER; + bFoundThousand = true; + break; + case XML_ENCODING: + aProperty.Name = INFO_CHARSET; + bFoundCharset = true; + break; + default: + XMLOFF_WARN_UNKNOWN("dbaccess", aIter); + } + if ( !aProperty.Name.isEmpty() ) + { + aProperty.Value <<= aIter.toString(); + rImport.addInfo(aProperty); + } + } + if ( bAutoEnabled ) + { + aProperty.Name = INFO_AUTORETRIEVEENABLED; + aProperty.Value <<= true; + rImport.addInfo(aProperty); + } + if ( !rImport.isNewFormat() ) + return; + + if ( (nElement & TOKEN_MASK) == XML_DELIMITER ) + { + if ( !bFoundField ) + { + aProperty.Name = INFO_FIELDDELIMITER; + aProperty.Value <<= OUString(";"); + rImport.addInfo(aProperty); + } + if ( !bFoundThousand ) + { + aProperty.Name = INFO_THOUSANDSDELIMITER; + aProperty.Value <<= OUString(","); + rImport.addInfo(aProperty); + } + } + if ( (nElement & TOKEN_MASK) == XML_FONT_CHARSET && !bFoundCharset ) + { + aProperty.Name = INFO_CHARSET; + aProperty.Value <<= OUString("utf8"); + rImport.addInfo(aProperty); + } +} + +OXMLDataSourceInfo::~OXMLDataSourceInfo() +{ + +} + +} // namespace dbaxml + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/filter/xml/xmlDataSourceInfo.hxx b/dbaccess/source/filter/xml/xmlDataSourceInfo.hxx new file mode 100644 index 000000000..e29d37a7d --- /dev/null +++ b/dbaccess/source/filter/xml/xmlDataSourceInfo.hxx @@ -0,0 +1,37 @@ +/* -*- 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 . + */ +#pragma once + +#include + +namespace dbaxml +{ + class ODBFilter; + class OXMLDataSourceInfo : public SvXMLImportContext + { + public: + + OXMLDataSourceInfo( ODBFilter& rImport, + sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList > & _xAttrList); + virtual ~OXMLDataSourceInfo() override; + }; +} // namespace dbaxml + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/filter/xml/xmlDataSourceSetting.cxx b/dbaccess/source/filter/xml/xmlDataSourceSetting.cxx new file mode 100644 index 000000000..9402bb399 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlDataSourceSetting.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 +#include + +#include + +#include "xmlDataSourceSetting.hxx" +#include +#include "xmlfilter.hxx" +#include +#include +#include "xmlEnums.hxx" +#include + +namespace dbaxml +{ + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::xml::sax; + +OXMLDataSourceSetting::OXMLDataSourceSetting( ODBFilter& rImport + ,const Reference< XFastAttributeList > & _xAttrList + ,OXMLDataSourceSetting* _pContainer) : + SvXMLImportContext( rImport ) + ,m_pContainer(_pContainer) + ,m_bIsList(false) +{ + + m_aPropType = cppu::UnoType::get(); + + for (auto &aIter : sax_fastparser::castToFastAttributeList( _xAttrList )) + { + switch( aIter.getToken() & TOKEN_MASK ) + { + case XML_DATA_SOURCE_SETTING_IS_LIST: + m_bIsList = aIter.toView() == "true"; + break; + case XML_DATA_SOURCE_SETTING_TYPE: + { + // needs to be translated into a css::uno::Type + static std::map< OUString, css::uno::Type > s_aTypeNameMap = []() + { + std::map< OUString, css::uno::Type > tmp; + tmp[GetXMLToken( XML_BOOLEAN)] = cppu::UnoType::get(); + // Not a copy paste error, see comment xmloff/source/forms/propertyimport.cxx lines 244-248 + tmp[GetXMLToken( XML_FLOAT)] = ::cppu::UnoType::get(); + tmp[GetXMLToken( XML_DOUBLE)] = ::cppu::UnoType::get(); + tmp[GetXMLToken( XML_STRING)] = ::cppu::UnoType::get(); + tmp[GetXMLToken( XML_INT)] = ::cppu::UnoType::get(); + tmp[GetXMLToken( XML_SHORT)] = ::cppu::UnoType::get(); + tmp[GetXMLToken( XML_VOID)] = cppu::UnoType::get(); + return tmp; + }(); + + const std::map< OUString, css::uno::Type >::const_iterator aTypePos = s_aTypeNameMap.find(aIter.toString()); + OSL_ENSURE(s_aTypeNameMap.end() != aTypePos, "OXMLDataSourceSetting::OXMLDataSourceSetting: invalid type!"); + if (s_aTypeNameMap.end() != aTypePos) + m_aPropType = aTypePos->second; + } + break; + case XML_DATA_SOURCE_SETTING_NAME: + m_aSetting.Name = aIter.toString(); + break; + default: + XMLOFF_WARN_UNKNOWN("dbaccess", aIter); + } + } + +} + +OXMLDataSourceSetting::~OXMLDataSourceSetting() +{ +} + +css::uno::Reference< css::xml::sax::XFastContextHandler > OXMLDataSourceSetting::createFastChildContext( + sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) +{ + SvXMLImportContext *pContext = nullptr; + + switch( nElement & TOKEN_MASK ) + { + case XML_DATA_SOURCE_SETTING: + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + pContext = new OXMLDataSourceSetting( GetOwnImport(), xAttrList); + break; + case XML_DATA_SOURCE_SETTING_VALUE: + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + pContext = new OXMLDataSourceSetting( GetOwnImport(), xAttrList,this ); + break; + } + + return pContext; +} + +void OXMLDataSourceSetting::endFastElement(sal_Int32 ) +{ + if ( !m_aSetting.Name.isEmpty() ) + { + if ( m_bIsList && m_aInfoSequence.hasElements() ) + m_aSetting.Value <<= m_aInfoSequence; + + // if our property is of type string, but was empty, ensure that + // we don't add a VOID value + if ( !m_bIsList && ( m_aPropType.getTypeClass() == TypeClass_STRING ) && !m_aSetting.Value.hasValue() ) + m_aSetting.Value <<= OUString(); + + GetOwnImport().addInfo(m_aSetting); + } +} + +void OXMLDataSourceSetting::characters( const OUString& rChars ) +{ + if ( m_pContainer ) + m_pContainer->addValue(rChars); +} + +void OXMLDataSourceSetting::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_aInfoSequence.getLength(); + m_aInfoSequence.realloc(nPos+1); + m_aInfoSequence.getArray()[nPos] = aValue; + } +} + +ODBFilter& OXMLDataSourceSetting::GetOwnImport() +{ + return static_cast(GetImport()); +} + +Any OXMLDataSourceSetting::convertString(const css::uno::Type& _rExpectedType, const OUString& _rReadCharacters) +{ + Any aReturn; + switch (_rExpectedType.getTypeClass()) + { + case TypeClass_BOOLEAN: // sal_Bool + { + bool bValue(false); + bool const bSuccess = + ::sax::Converter::convertBool(bValue, _rReadCharacters); + SAL_WARN_IF(!bSuccess, "dbaccess", + "OXMLDataSourceSetting::convertString: could not convert \"" + << _rReadCharacters << "\" into a boolean!"); + 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 const bSuccess = + ::sax::Converter::convertNumber(nValue, _rReadCharacters); + SAL_WARN_IF(!bSuccess, "dbaccess", + "OXMLDataSourceSetting::convertString: could not convert \"" + << _rReadCharacters << "\" into an integer!"); + if (TypeClass_SHORT == _rExpectedType.getTypeClass()) + aReturn <<= static_cast(nValue); + else + aReturn <<= nValue; + break; + } + case TypeClass_HYPER: + { + OSL_FAIL("OXMLDataSourceSetting::convertString: 64-bit integers not implemented yet!"); + } + break; + case TypeClass_DOUBLE: + { + double nValue = 0.0; + bool const bSuccess = + ::sax::Converter::convertDouble(nValue, _rReadCharacters); + SAL_WARN_IF(!bSuccess, "dbaccess", + "OXMLDataSourceSetting::convertString: could not convert \"" + << _rReadCharacters << "\" into a double!"); + aReturn <<= nValue; + } + break; + case TypeClass_STRING: + aReturn <<= _rReadCharacters; + break; + default: + SAL_WARN("dbaccess", + "OXMLDataSourceSetting::convertString: invalid type class!"); + } + + return aReturn; +} + +} // namespace dbaxml + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/filter/xml/xmlDataSourceSetting.hxx b/dbaccess/source/filter/xml/xmlDataSourceSetting.hxx new file mode 100644 index 000000000..3ed92f80e --- /dev/null +++ b/dbaccess/source/filter/xml/xmlDataSourceSetting.hxx @@ -0,0 +1,60 @@ +/* -*- 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 . + */ +#pragma once + +#include +#include +#include + +namespace dbaxml +{ + class ODBFilter; + class OXMLDataSourceSetting : public SvXMLImportContext + { + css::beans::PropertyValue m_aSetting; + css::uno::Sequence< css::uno::Any> m_aInfoSequence; + OXMLDataSourceSetting* m_pContainer; + css::uno::Type m_aPropType; // the type of the property the instance imports currently + bool m_bIsList; + + ODBFilter& GetOwnImport(); + static css::uno::Any convertString(const css::uno::Type& _rExpectedType, const OUString& _rReadCharacters); + public: + + OXMLDataSourceSetting( ODBFilter& rImport + ,const css::uno::Reference< css::xml::sax::XFastAttributeList > & _xAttrList + ,OXMLDataSourceSetting* _pContainer = nullptr); + virtual ~OXMLDataSourceSetting() override; + + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( + sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) 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); + }; +} // namespace dbaxml + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/filter/xml/xmlDataSourceSettings.cxx b/dbaccess/source/filter/xml/xmlDataSourceSettings.cxx new file mode 100644 index 000000000..49847ef54 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlDataSourceSettings.cxx @@ -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 . + */ + +#include "xmlDataSourceSettings.hxx" +#include "xmlDataSourceSetting.hxx" +#include "xmlfilter.hxx" +#include +#include +#include "xmlEnums.hxx" + +namespace dbaxml +{ + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::xml::sax; + +OXMLDataSourceSettings::OXMLDataSourceSettings( ODBFilter& rImport ) : + SvXMLImportContext( rImport ) +{ + +} + +OXMLDataSourceSettings::~OXMLDataSourceSettings() +{ + +} + +css::uno::Reference< css::xml::sax::XFastContextHandler > OXMLDataSourceSettings::createFastChildContext( + sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) +{ + SvXMLImportContext *pContext = nullptr; + + switch( nElement & TOKEN_MASK ) + { + case XML_DATA_SOURCE_SETTING: + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + pContext = new OXMLDataSourceSetting( GetOwnImport(), xAttrList ); + break; + } + + return pContext; +} + +ODBFilter& OXMLDataSourceSettings::GetOwnImport() +{ + return static_cast(GetImport()); +} + +} // namespace dbaxml + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/filter/xml/xmlDataSourceSettings.hxx b/dbaccess/source/filter/xml/xmlDataSourceSettings.hxx new file mode 100644 index 000000000..50fea5c00 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlDataSourceSettings.hxx @@ -0,0 +1,39 @@ +/* -*- 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 . + */ +#pragma once + +#include + +namespace dbaxml +{ + class ODBFilter; + class OXMLDataSourceSettings : public SvXMLImportContext + { + ODBFilter& GetOwnImport(); + public: + + OXMLDataSourceSettings( ODBFilter& rImport ); + virtual ~OXMLDataSourceSettings() override; + + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( + sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override; + }; +} // namespace dbaxml + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/filter/xml/xmlDatabase.cxx b/dbaccess/source/filter/xml/xmlDatabase.cxx new file mode 100644 index 000000000..2f629caff --- /dev/null +++ b/dbaccess/source/filter/xml/xmlDatabase.cxx @@ -0,0 +1,135 @@ +/* -*- 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 "xmlDatabase.hxx" +#include "xmlfilter.hxx" +#include +#include +#include "xmlDataSource.hxx" +#include "xmlDocuments.hxx" +#include "xmlEnums.hxx" +#include +#include +#include +#include +#include +#include +#include + +namespace dbaxml +{ + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::sdb; + using namespace ::com::sun::star::sdbcx; + using namespace ::com::sun::star::xml::sax; + +OXMLDatabase::OXMLDatabase( ODBFilter& rImport ) : + SvXMLImportContext( rImport ) +{ + +} + +OXMLDatabase::~OXMLDatabase() +{ + +} + +css::uno::Reference< css::xml::sax::XFastContextHandler > OXMLDatabase::createFastChildContext( + sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) +{ + SvXMLImportContext *pContext = nullptr; + + switch( nElement & TOKEN_MASK ) + { + case XML_DATA_SOURCE: + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + pContext = new OXMLDataSource( GetOwnImport(), xAttrList, OXMLDataSource::eDataSource ); + break; + case XML_FORMS: + { + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + Any aValue; + OUString sService; + dbtools::getDataSourceSetting(GetOwnImport().getDataSource(),"Forms",aValue); + aValue >>= sService; + if ( sService.isEmpty() ) + { + Reference xSup(GetOwnImport().GetModel(),UNO_QUERY); + if ( xSup.is() ) + pContext = new OXMLDocuments( GetOwnImport(), xSup->getFormDocuments(),SERVICE_NAME_FORM_COLLECTION,SERVICE_SDB_DOCUMENTDEFINITION); + } + } + break; + case XML_REPORTS: + { + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + Any aValue; + OUString sService; + dbtools::getDataSourceSetting(GetOwnImport().getDataSource(),"Reports",aValue); + aValue >>= sService; + if ( sService.isEmpty() ) + { + Reference xSup(GetOwnImport().GetModel(),UNO_QUERY); + if ( xSup.is() ) + pContext = new OXMLDocuments( GetOwnImport(), xSup->getReportDocuments(),SERVICE_NAME_REPORT_COLLECTION,SERVICE_SDB_DOCUMENTDEFINITION); + } + } + break; + case XML_QUERIES: + { + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + Any aValue; + OUString sService; + dbtools::getDataSourceSetting(GetOwnImport().getDataSource(),"CommandDefinitions",aValue); + aValue >>= sService; + if ( sService.isEmpty() ) + { + Reference xSup(GetOwnImport().getDataSource(),UNO_QUERY); + if ( xSup.is() ) + pContext = new OXMLDocuments( GetOwnImport(), xSup->getQueryDefinitions(),SERVICE_NAME_QUERY_COLLECTION); + } + } + break; + case XML_TABLE_REPRESENTATIONS: + case XML_SCHEMA_DEFINITION: + { + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + Reference xSup(GetOwnImport().getDataSource(),UNO_QUERY); + if ( xSup.is() ) + pContext = new OXMLDocuments( GetOwnImport(), xSup->getTables()); + } + break; + } + + return pContext; +} + +ODBFilter& OXMLDatabase::GetOwnImport() +{ + return static_cast(GetImport()); +} + +void OXMLDatabase::endFastElement(sal_Int32) +{ + GetOwnImport().setPropertyInfo(); +} + +} // namespace dbaxml + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/filter/xml/xmlDatabase.hxx b/dbaccess/source/filter/xml/xmlDatabase.hxx new file mode 100644 index 000000000..0dab56c51 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlDatabase.hxx @@ -0,0 +1,41 @@ +/* -*- 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 . + */ +#pragma once + +#include + +namespace dbaxml +{ + class ODBFilter; + class OXMLDatabase final : public SvXMLImportContext + { + ODBFilter& GetOwnImport(); + public: + + OXMLDatabase( ODBFilter& rImport ); + virtual ~OXMLDatabase() override; + + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( + sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override; + + virtual void SAL_CALL endFastElement(sal_Int32 nElement) override; + }; +} // namespace dbaxml + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/filter/xml/xmlDatabaseDescription.cxx b/dbaccess/source/filter/xml/xmlDatabaseDescription.cxx new file mode 100644 index 000000000..a8168e129 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlDatabaseDescription.cxx @@ -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 . + */ + +#include "xmlDatabaseDescription.hxx" +#include "xmlfilter.hxx" +#include +#include +#include "xmlEnums.hxx" +#include "xmlFileBasedDatabase.hxx" +#include "xmlServerDatabase.hxx" + +namespace dbaxml +{ + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::xml::sax; + +OXMLDatabaseDescription::OXMLDatabaseDescription( ODBFilter& rImport ) : + SvXMLImportContext( rImport ) + ,m_bFoundOne(false) +{ +} + +OXMLDatabaseDescription::~OXMLDatabaseDescription() +{ + +} + +css::uno::Reference< css::xml::sax::XFastContextHandler > OXMLDatabaseDescription::createFastChildContext( + sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) +{ + SvXMLImportContext *pContext = nullptr; + + switch( nElement & TOKEN_MASK ) + { + case XML_FILE_BASED_DATABASE: + if ( !m_bFoundOne ) + { + m_bFoundOne = true; + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + pContext = new OXMLFileBasedDatabase( GetOwnImport(), xAttrList ); + } + break; + case XML_SERVER_DATABASE: + if ( !m_bFoundOne ) + { + m_bFoundOne = true; + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + pContext = new OXMLServerDatabase( GetOwnImport(), xAttrList ); + } + break; + } + + return pContext; +} + +ODBFilter& OXMLDatabaseDescription::GetOwnImport() +{ + return static_cast(GetImport()); +} + +} // namespace dbaxml + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/filter/xml/xmlDatabaseDescription.hxx b/dbaccess/source/filter/xml/xmlDatabaseDescription.hxx new file mode 100644 index 000000000..146ecb401 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlDatabaseDescription.hxx @@ -0,0 +1,41 @@ +/* -*- 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 . + */ +#pragma once + +#include + +namespace dbaxml +{ + class ODBFilter; + class OXMLDatabaseDescription : public SvXMLImportContext + { + bool m_bFoundOne; + + ODBFilter& GetOwnImport(); + public: + + OXMLDatabaseDescription( ODBFilter& rImport); + virtual ~OXMLDatabaseDescription() override; + + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( + sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override; + }; +} // namespace dbaxml + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/filter/xml/xmlDocuments.cxx b/dbaccess/source/filter/xml/xmlDocuments.cxx new file mode 100644 index 000000000..71d5b4589 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlDocuments.cxx @@ -0,0 +1,99 @@ +/* -*- 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 "xmlDocuments.hxx" +#include "xmlfilter.hxx" +#include +#include +#include "xmlQuery.hxx" +#include "xmlTable.hxx" +#include "xmlComponent.hxx" +#include "xmlHierarchyCollection.hxx" +#include "xmlEnums.hxx" + +namespace dbaxml +{ + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::container; + using namespace ::com::sun::star::xml::sax; + +OXMLDocuments::OXMLDocuments( ODBFilter& rImport + ,const Reference< XNameAccess >& _xContainer + ,const OUString& _sCollectionServiceName + ,const OUString& _sComponentServiceName) : + SvXMLImportContext( rImport ) + ,m_xContainer(_xContainer) + ,m_sCollectionServiceName(_sCollectionServiceName) + ,m_sComponentServiceName(_sComponentServiceName) +{ + +} + +OXMLDocuments::OXMLDocuments( ODBFilter& rImport + ,const Reference< XNameAccess >& _xContainer + ,const OUString& _sCollectionServiceName + ) : + SvXMLImportContext( rImport ) + ,m_xContainer(_xContainer) + ,m_sCollectionServiceName(_sCollectionServiceName) +{ +} + +OXMLDocuments::~OXMLDocuments() +{ + +} + +css::uno::Reference< css::xml::sax::XFastContextHandler > OXMLDocuments::createFastChildContext( + sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) +{ + SvXMLImportContext *pContext = nullptr; + + switch( nElement & TOKEN_MASK ) + { + case XML_TABLE: + case XML_TABLE_REPRESENTATION: + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + pContext = new OXMLTable( GetOwnImport(), xAttrList, m_xContainer, "com.sun.star.sdb.TableDefinition"); + break; + case XML_QUERY: + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + pContext = new OXMLQuery( GetOwnImport(), xAttrList, m_xContainer ); + break; + case XML_COMPONENT: + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + pContext = new OXMLComponent( GetOwnImport(), xAttrList, m_xContainer,m_sComponentServiceName ); + break; + case XML_COMPONENT_COLLECTION: + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + pContext = new OXMLHierarchyCollection( GetOwnImport(), xAttrList, m_xContainer,m_sCollectionServiceName,m_sComponentServiceName ); + break; + } + + return pContext; +} + +ODBFilter& OXMLDocuments::GetOwnImport() +{ + return static_cast(GetImport()); +} + +} // namespace dbaxml + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/filter/xml/xmlDocuments.hxx b/dbaccess/source/filter/xml/xmlDocuments.hxx new file mode 100644 index 000000000..c0542dcfb --- /dev/null +++ b/dbaccess/source/filter/xml/xmlDocuments.hxx @@ -0,0 +1,56 @@ +/* -*- 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 . + */ +#pragma once + +#include +#include + +namespace dbaxml +{ + class ODBFilter; + class OXMLDocuments : public SvXMLImportContext + { + private: + css::uno::Reference< css::container::XNameAccess > m_xContainer; + OUString m_sCollectionServiceName; + OUString m_sComponentServiceName; + + ODBFilter& GetOwnImport(); + public: + + // for forms and reports + OXMLDocuments( ODBFilter& rImport + ,const css::uno::Reference< css::container::XNameAccess >& _xContainer + ,const OUString& _sCollectionServiceName + ,const OUString& _sComponentServiceName); + + // for queries + OXMLDocuments( ODBFilter& rImport + ,const css::uno::Reference< css::container::XNameAccess >& _xContainer + ,const OUString& _sCollectionServiceName = OUString() + ); + + virtual ~OXMLDocuments() override; + + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( + sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override; + }; +} // namespace dbaxml + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/filter/xml/xmlEnums.hxx b/dbaccess/source/filter/xml/xmlEnums.hxx new file mode 100644 index 000000000..552f7eb24 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlEnums.hxx @@ -0,0 +1,23 @@ +/* -*- 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 . + */ +#pragma once + +#define PROGRESS_BAR_STEP 20 + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/filter/xml/xmlExport.cxx b/dbaccess/source/filter/xml/xmlExport.cxx new file mode 100644 index 000000000..74cb97721 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlExport.cxx @@ -0,0 +1,1342 @@ +/* -*- 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 "xmlExport.hxx" +#include "xmlAutoStyle.hxx" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include "xmlHelper.hxx" +#include +#include +#include +#include +#include +#include + +#include +#include + +using namespace comphelper; +using namespace ::com::sun::star::sdb; +using namespace ::com::sun::star::sdbcx; +using namespace ::com::sun::star::util; +using namespace ::com::sun::star; + +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* +com_sun_star_comp_sdb_DBExportFilter_get_implementation( + css::uno::XComponentContext* context, css::uno::Sequence const&) +{ + return cppu::acquire(new ::dbaxml::ODBExport(context, + "com.sun.star.comp.sdb.DBExportFilter")); +} + +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* +com_sun_star_comp_sdb_XMLSettingsExporter_get_implementation( + css::uno::XComponentContext* context, css::uno::Sequence const&) +{ + return cppu::acquire(new ::dbaxml::ODBExport(context, + "com.sun.star.comp.sdb.XMLSettingsExporter", + SvXMLExportFlags::SETTINGS | SvXMLExportFlags::PRETTY )); +} + +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* +com_sun_star_comp_sdb_XMLFullExporter_get_implementation( + css::uno::XComponentContext* context, css::uno::Sequence const&) +{ + return cppu::acquire(new ::dbaxml::ODBExport(context, + "com.sun.star.comp.sdb.XMLFullExporter", + SvXMLExportFlags::ALL)); +} + +namespace dbaxml +{ + static OUString lcl_implGetPropertyXMLType(const Type& _rType) + { + // possible types we can write (either because we recognize them directly or because we convert _rValue + // into one of these types) + + // handle the type description + switch (_rType.getTypeClass()) + { + case TypeClass_STRING: + return "string"; + case TypeClass_DOUBLE: + return "double"; + case TypeClass_BOOLEAN: + return "boolean"; + case TypeClass_BYTE: + case TypeClass_SHORT: + return "short"; + case TypeClass_LONG: + return "int"; + case TypeClass_HYPER: + return "long"; + case TypeClass_ENUM: + return "int"; + + default: + OSL_FAIL( "lcl_implGetPropertyXMLType: unsupported value type!" ); + return "double"; + } + } + + 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*/ , + sal_uInt32 /*nIdx*/ ) const override + { + // nothing to do here + } + }; + + } + +ODBExport::ODBExport(const Reference< XComponentContext >& _rxContext, OUString const & implementationName, SvXMLExportFlags nExportFlag) +: SvXMLExport( _rxContext, implementationName, util::MeasureUnit::MM_10TH, XML_DATABASE, + SvXMLExportFlags::OASIS | nExportFlag) +,m_aTypeCollection(_rxContext) +,m_bAllreadyFilled(false) +{ + GetMM100UnitConverter().SetCoreMeasureUnit(util::MeasureUnit::MM_10TH); + GetMM100UnitConverter().SetXMLMeasureUnit(util::MeasureUnit::CM); + + 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_SVG), GetXMLToken(XML_N_SVG), XML_NAMESPACE_SVG ); + + GetNamespaceMap_().Add( GetXMLToken(XML_NP_DB), GetXMLToken(XML_N_DB_OASIS), XML_NAMESPACE_DB ); + + if( nExportFlag & (SvXMLExportFlags::STYLES|SvXMLExportFlags::MASTERSTYLES|SvXMLExportFlags::AUTOSTYLES|SvXMLExportFlags::FONTDECLS) ) + GetNamespaceMap_().Add( GetXMLToken(XML_NP_FO), GetXMLToken(XML_N_FO_COMPAT), XML_NAMESPACE_FO ); + + if( nExportFlag & (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( nExportFlag & SvXMLExportFlags::SETTINGS ) + { + GetNamespaceMap_().Add( GetXMLToken(XML_NP_CONFIG), GetXMLToken(XML_N_CONFIG), XML_NAMESPACE_CONFIG ); + } + + if( nExportFlag & (SvXMLExportFlags::STYLES|SvXMLExportFlags::MASTERSTYLES|SvXMLExportFlags::AUTOSTYLES|SvXMLExportFlags::CONTENT|SvXMLExportFlags::FONTDECLS) ) + { + GetNamespaceMap_().Add( GetXMLToken(XML_NP_STYLE), GetXMLToken(XML_N_STYLE), XML_NAMESPACE_STYLE ); + } + + 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_xExportHelper = new SvXMLExportPropertyMapper(GetTableStylesPropertySetMapper()); + m_xColumnExportHelper = new OSpecialHandleXMLExportPropertyMapper(GetColumnStylesPropertySetMapper()); + + m_xCellExportHelper = new OSpecialHandleXMLExportPropertyMapper(GetCellStylesPropertySetMapper()); + m_xRowExportHelper = new OSpecialHandleXMLExportPropertyMapper(OXMLHelper::GetRowStylesPropertySetMapper()); + + GetAutoStylePool()->AddFamily( + XmlStyleFamily::TABLE_TABLE, + OUString(XML_STYLE_FAMILY_TABLE_TABLE_STYLES_NAME ), + m_xExportHelper.get(), + OUString(XML_STYLE_FAMILY_TABLE_TABLE_STYLES_PREFIX )); + + GetAutoStylePool()->AddFamily( + XmlStyleFamily::TABLE_COLUMN, + OUString(XML_STYLE_FAMILY_TABLE_COLUMN_STYLES_NAME ), + m_xColumnExportHelper.get(), + OUString(XML_STYLE_FAMILY_TABLE_COLUMN_STYLES_PREFIX )); + + GetAutoStylePool()->AddFamily( + XmlStyleFamily::TABLE_CELL, + OUString(XML_STYLE_FAMILY_TABLE_CELL_STYLES_NAME ), + m_xCellExportHelper.get(), + OUString(XML_STYLE_FAMILY_TABLE_CELL_STYLES_PREFIX )); + + GetAutoStylePool()->AddFamily( + XmlStyleFamily::TABLE_ROW, + OUString(XML_STYLE_FAMILY_TABLE_ROW_STYLES_NAME ), + m_xRowExportHelper.get(), + OUString(XML_STYLE_FAMILY_TABLE_ROW_STYLES_PREFIX )); +} + +void ODBExport::exportDataSource() +{ + try + { + Reference xProp( getDataSource(), UNO_SET_THROW ); + + bool bAutoIncrementEnabled = true; + TStringPair aAutoIncrement; + + Reference< XPropertySet > xDataSourceSettings; + OSL_VERIFY( xProp->getPropertyValue( PROPERTY_SETTINGS ) >>= xDataSourceSettings ); + Reference< XPropertyState > xSettingsState( xDataSourceSettings, UNO_QUERY_THROW ); + Reference< XPropertySetInfo > xSettingsInfo( xDataSourceSettings->getPropertySetInfo(), UNO_SET_THROW ); + + TDelimiter aDelimiter; + xSettingsState->getPropertyDefault( INFO_TEXTDELIMITER ) >>= aDelimiter.sText; + xSettingsState->getPropertyDefault( INFO_FIELDDELIMITER ) >>= aDelimiter.sField; + xSettingsState->getPropertyDefault( INFO_DECIMALDELIMITER ) >>= aDelimiter.sDecimal; + xSettingsState->getPropertyDefault( INFO_THOUSANDSDELIMITER ) >>= aDelimiter.sThousand; + + ::connectivity::DriversConfig aDriverConfig(getComponentContext()); + const OUString sURL = ::comphelper::getString(xProp->getPropertyValue(PROPERTY_URL)); + const ::comphelper::NamedValueCollection& aDriverSupportedProperties( aDriverConfig.getProperties( sURL ) ); + + static OUString s_sTrue(::xmloff::token::GetXMLToken( XML_TRUE )); + static OUString s_sFalse(::xmloff::token::GetXMLToken( XML_FALSE )); + // loop through the properties, and export only those which are not defaulted + TSettingsMap aSettingsMap; + // Don't try to get XPropertySetInfo from xProp, simply wrap the attempt into try block + try + { + const Any aValue = xProp->getPropertyValue(PROPERTY_SUPPRESSVERSIONCL); + if (!getBOOL(aValue)) // default in the XML schema is true -> only write false + aSettingsMap.emplace(XML_SUPPRESS_VERSION_COLUMNS, s_sFalse); + } + catch (const UnknownPropertyException&) + { + } + + Sequence< Property > aProperties = xSettingsInfo->getProperties(); + const Property* pProperties = aProperties.getConstArray(); + const Property* pPropertiesEnd = pProperties + aProperties.getLength(); + for ( ; pProperties != pPropertiesEnd; ++pProperties ) + { + OUString sValue; + Any aValue = xDataSourceSettings->getPropertyValue( pProperties->Name ); + switch ( aValue.getValueTypeClass() ) + { + case TypeClass_STRING: + aValue >>= sValue; + break; + case TypeClass_DOUBLE: + // let the unit converter format is as string + sValue = OUString::number( getDouble( aValue ) ); + break; + case TypeClass_BOOLEAN: + sValue = ::xmloff::token::GetXMLToken( getBOOL( aValue ) ? XML_TRUE : XML_FALSE ); + break; + case TypeClass_BYTE: + case TypeClass_SHORT: + case TypeClass_LONG: + // let the unit converter format is as string + sValue = OUString::number( getINT32( aValue ) ); + break; + default: + break; + } + + ::xmloff::token::XMLTokenEnum eToken = XML_TOKEN_INVALID; + + struct PropertyMap + { + const OUString sPropertyName; + const XMLTokenEnum eAttributeToken; + const ::std::optional< OUString > aXMLDefault; + + PropertyMap( const OUString& _rPropertyName, const XMLTokenEnum _eToken ) + :sPropertyName( _rPropertyName ) + ,eAttributeToken( _eToken ) + ,aXMLDefault() + { + } + + PropertyMap( const OUString& _rPropertyName, const XMLTokenEnum _eToken, const OUString& _rDefault ) + :sPropertyName( _rPropertyName ) + ,eAttributeToken( _eToken ) + ,aXMLDefault( _rDefault ) + { + } + }; + + const PropertyMap aTokens[] = + { + PropertyMap( INFO_TEXTFILEHEADER, XML_IS_FIRST_ROW_HEADER_LINE, s_sTrue ), + PropertyMap( INFO_SHOWDELETEDROWS, XML_SHOW_DELETED, s_sFalse ), + PropertyMap( INFO_ALLOWLONGTABLENAMES, XML_IS_TABLE_NAME_LENGTH_LIMITED, s_sTrue ), + PropertyMap( INFO_ADDITIONALOPTIONS, XML_SYSTEM_DRIVER_SETTINGS ), + PropertyMap( PROPERTY_ENABLESQL92CHECK, XML_ENABLE_SQL92_CHECK, s_sFalse ), + PropertyMap( INFO_APPEND_TABLE_ALIAS, XML_APPEND_TABLE_ALIAS_NAME, s_sTrue ), + PropertyMap( INFO_PARAMETERNAMESUBST, XML_PARAMETER_NAME_SUBSTITUTION, s_sTrue ), + PropertyMap( INFO_IGNOREDRIVER_PRIV, XML_IGNORE_DRIVER_PRIVILEGES, s_sTrue ), + PropertyMap( INFO_USECATALOG, XML_USE_CATALOG, s_sFalse ), + PropertyMap( INFO_CONN_LDAP_BASEDN, XML_BASE_DN ), + PropertyMap( INFO_CONN_LDAP_ROWCOUNT, XML_MAX_ROW_COUNT ) + }; + + bool bIsXMLDefault = false; + for (const auto & aToken : aTokens) + { + if ( pProperties->Name == aToken.sPropertyName ) + { + eToken = aToken.eAttributeToken; + + if ( !!aToken.aXMLDefault + && ( sValue == *aToken.aXMLDefault ) + ) + { + bIsXMLDefault = true; + } + break; + } + } + + if ( bIsXMLDefault ) + // the property has the value which is specified as default in the XML schema -> no need to write it + continue; + + if ( eToken == XML_TOKEN_INVALID ) + { + // for properties which are not REMOVABLE, we care for their state, and + // only export them if they're not DEFAULTed + if ( ( pProperties->Attributes & PropertyAttribute::REMOVABLE ) == 0 ) + { + PropertyState ePropertyState = xSettingsState->getPropertyState( pProperties->Name ); + if ( PropertyState_DEFAULT_VALUE == ePropertyState ) + continue; + } + + // special handlings + if ( pProperties->Name == PROPERTY_BOOLEANCOMPARISONMODE ) + { + if ( sValue == "0" ) + sValue = "equal-integer"; + else if ( sValue == "1" ) + sValue = "is-boolean"; + else if ( sValue == "2" ) + sValue = "equal-boolean"; + else if ( sValue == "3" ) + sValue = "equal-use-only-zero"; + if ( sValue == "equal-integer" ) + continue; + eToken = XML_BOOLEAN_COMPARISON_MODE; + } + else if ( pProperties->Name == INFO_AUTORETRIEVEENABLED ) + { + aValue >>= bAutoIncrementEnabled; + continue; + } + else if ( pProperties->Name == INFO_AUTORETRIEVEVALUE ) + { + aAutoIncrement.first = sValue; + continue; + } + else if ( pProperties->Name == PROPERTY_AUTOINCREMENTCREATION ) + { + aAutoIncrement.second = sValue; + continue; + } + else if ( pProperties->Name == INFO_TEXTDELIMITER ) + { + aDelimiter.sText = sValue; + aDelimiter.bUsed = true; + continue; + } + else if ( pProperties->Name == INFO_FIELDDELIMITER ) + { + aDelimiter.sField = sValue; + aDelimiter.bUsed = true; + continue; + } + else if ( pProperties->Name == INFO_DECIMALDELIMITER ) + { + aDelimiter.sDecimal = sValue; + aDelimiter.bUsed = true; + continue; + } + else if ( pProperties->Name == INFO_THOUSANDSDELIMITER ) + { + aDelimiter.sThousand = sValue; + aDelimiter.bUsed = true; + continue; + } + else if ( pProperties->Name == INFO_CHARSET ) + { + m_sCharSet = sValue; + continue; + } + else + { + if ( !aDriverSupportedProperties.has(pProperties->Name) || aDriverSupportedProperties.get(pProperties->Name) != aValue ) + { + m_aDataSourceSettings.emplace_back( + pProperties->Name, pProperties->Type, aValue ); + } + continue; + } + } + + aSettingsMap.emplace(eToken,sValue); + } + if ( bAutoIncrementEnabled && !(aAutoIncrement.first.isEmpty() && aAutoIncrement.second.isEmpty()) ) + m_aAutoIncrement.reset( new TStringPair(aAutoIncrement)); + if ( aDelimiter.bUsed ) + m_aDelimiter.reset( new TDelimiter( aDelimiter ) ); + + SvXMLElementExport aElem(*this, XML_NAMESPACE_DB, XML_DATA_SOURCE, true, true); + + exportConnectionData(); + exportDriverSettings(aSettingsMap); + exportApplicationConnectionSettings(aSettingsMap); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION("dbaccess"); + } +} + +void ODBExport::exportApplicationConnectionSettings(const TSettingsMap& _aSettings) +{ + const ::xmloff::token::XMLTokenEnum pSettings[] = { + XML_IS_TABLE_NAME_LENGTH_LIMITED + ,XML_ENABLE_SQL92_CHECK + ,XML_APPEND_TABLE_ALIAS_NAME + ,XML_IGNORE_DRIVER_PRIVILEGES + ,XML_BOOLEAN_COMPARISON_MODE + ,XML_USE_CATALOG + ,XML_MAX_ROW_COUNT + ,XML_SUPPRESS_VERSION_COLUMNS + }; + for (::xmloff::token::XMLTokenEnum i : pSettings) + { + TSettingsMap::const_iterator aFind = _aSettings.find(i); + if ( aFind != _aSettings.end() ) + AddAttribute(XML_NAMESPACE_DB, aFind->first,aFind->second); + } + SvXMLElementExport aElem(*this,XML_NAMESPACE_DB, XML_APPLICATION_CONNECTION_SETTINGS, true, true); + + Reference xProp(getDataSource()); + Sequence< OUString> aValue; + xProp->getPropertyValue(PROPERTY_TABLEFILTER) >>= aValue; + if ( aValue.hasElements() ) + { + SvXMLElementExport aElem2(*this,XML_NAMESPACE_DB, XML_TABLE_FILTER, true, true); + exportSequence(aValue,XML_TABLE_INCLUDE_FILTER,XML_TABLE_FILTER_PATTERN); + } + + xProp->getPropertyValue(PROPERTY_TABLETYPEFILTER) >>= aValue; + if ( aValue.hasElements() ) + exportSequence(aValue,XML_TABLE_TYPE_FILTER,XML_TABLE_TYPE); + + exportDataSourceSettings(); +} + +void ODBExport::exportDriverSettings(const TSettingsMap& _aSettings) +{ + const ::xmloff::token::XMLTokenEnum pSettings[] = { + XML_SHOW_DELETED + ,XML_SYSTEM_DRIVER_SETTINGS + ,XML_BASE_DN + ,XML_IS_FIRST_ROW_HEADER_LINE + ,XML_PARAMETER_NAME_SUBSTITUTION + }; + for (::xmloff::token::XMLTokenEnum nSetting : pSettings) + { + TSettingsMap::const_iterator aFind = _aSettings.find(nSetting); + if ( aFind != _aSettings.end() ) + AddAttribute(XML_NAMESPACE_DB, aFind->first,aFind->second); + } + SvXMLElementExport aElem(*this,XML_NAMESPACE_DB, XML_DRIVER_SETTINGS, true, true); + exportAutoIncrement(); + exportDelimiter(); + exportCharSet(); +} + +void ODBExport::exportConnectionData() +{ + SvXMLElementExport aConnData(*this,XML_NAMESPACE_DB, XML_CONNECTION_DATA, true, true); + + { + OUString sValue; + Reference xProp(getDataSource()); + xProp->getPropertyValue(PROPERTY_URL) >>= sValue; + if ( m_aTypeCollection.isFileSystemBased(sValue) ) + { + SvXMLElementExport aDatabaseDescription(*this,XML_NAMESPACE_DB, XML_DATABASE_DESCRIPTION, true, true); + { + SvtPathOptions aPathOptions; + const OUString sOrigUrl = m_aTypeCollection.cutPrefix(sValue); + OUString sFileName = aPathOptions.SubstituteVariable(sOrigUrl); + if ( sOrigUrl == sFileName ) + { + ::svt::OFileNotation aTransformer( sFileName ); + OUStringBuffer sURL( aTransformer.get( ::svt::OFileNotation::N_URL ) ); + if (sURL.isEmpty() || sURL[sURL.getLength() - 1] != '/') + sURL.append('/'); + + AddAttribute(XML_NAMESPACE_XLINK,XML_HREF,GetRelativeReference(sURL.makeStringAndClear())); + } + else + AddAttribute(XML_NAMESPACE_XLINK,XML_HREF,sOrigUrl); + AddAttribute(XML_NAMESPACE_DB,XML_MEDIA_TYPE,m_aTypeCollection.getMediaType(sValue)); + const ::dbaccess::DATASOURCE_TYPE eType = m_aTypeCollection.determineType(sValue); + try + { + OUString sExtension; + if ( eType == dbaccess::DST_MSACCESS ) + sExtension = "mdb"; + else + { + Reference< XPropertySet > xDataSourceSettings; + OSL_VERIFY( xProp->getPropertyValue( PROPERTY_SETTINGS ) >>= xDataSourceSettings ); + xDataSourceSettings->getPropertyValue( INFO_TEXTFILEEXTENSION ) >>= sExtension; + } + if ( !sExtension.isEmpty() ) + AddAttribute(XML_NAMESPACE_DB,XML_EXTENSION,sExtension); + } + catch(const Exception&) + { + } + SvXMLElementExport aFileBasedDB(*this,XML_NAMESPACE_DB, XML_FILE_BASED_DATABASE, true, true); + } + } + else + { + OUString sDatabaseName,sHostName; + sal_Int32 nPort = -1; + m_aTypeCollection.extractHostNamePort(sValue,sDatabaseName,sHostName,nPort); + if ( sHostName.getLength() ) + { + SvXMLElementExport aDatabaseDescription(*this,XML_NAMESPACE_DB, XML_DATABASE_DESCRIPTION, true, true); + { + OUString sType = comphelper::string::stripEnd(m_aTypeCollection.getPrefix(sValue), ':'); + AddAttribute(XML_NAMESPACE_DB,XML_TYPE,sType); + AddAttribute(XML_NAMESPACE_DB,XML_HOSTNAME,sHostName); + if ( nPort != -1 ) + AddAttribute(XML_NAMESPACE_DB,XML_PORT,OUString::number(nPort)); + if ( sDatabaseName.getLength() ) + AddAttribute(XML_NAMESPACE_DB,XML_DATABASE_NAME,sDatabaseName); + + try + { + Reference< XPropertySet > xDataSourceSettings( xProp->getPropertyValue( PROPERTY_SETTINGS ), UNO_QUERY_THROW ); + Reference< XPropertySetInfo > xSettingsInfo( xDataSourceSettings->getPropertySetInfo(), UNO_SET_THROW ); + + + static const OUStringLiteral sPropertyName = u"LocalSocket"; + if ( xSettingsInfo->hasPropertyByName( sPropertyName ) ) + { + OUString sPropertyValue; + if ( ( xDataSourceSettings->getPropertyValue( sPropertyName ) >>= sPropertyValue ) && !sPropertyValue.isEmpty() ) + AddAttribute( XML_NAMESPACE_DB, XML_LOCAL_SOCKET, sPropertyValue ); + } + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION("dbaccess"); + } + + SvXMLElementExport aServerDB(*this,XML_NAMESPACE_DB, XML_SERVER_DATABASE, true, true); + } + } + else + { + AddAttribute(XML_NAMESPACE_XLINK, XML_HREF,sValue); + AddAttribute(XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE); + SvXMLElementExport aElem(*this,XML_NAMESPACE_DB, XML_CONNECTION_RESOURCE, true, true); + } + } + + } + + exportLogin(); +} + +template< typename T > void ODBExport::exportDataSourceSettingsSequence( + std::vector< TypedPropertyValue >::iterator const & in) +{ + css::uno::Sequence anySeq; + bool bSuccess = in->Value >>= anySeq; + assert(bSuccess); (void)bSuccess; + for (T const & i : std::as_const(anySeq) ) + { + SvXMLElementExport aDataValue(*this,XML_NAMESPACE_DB, XML_DATA_SOURCE_SETTING_VALUE, true, false); + // (no whitespace inside the tag) + Characters(implConvertAny(css::uno::Any(i))); + } +} + +void ODBExport::exportDataSourceSettings() +{ + if ( m_aDataSourceSettings.empty() ) + return; + + SvXMLElementExport aElem(*this,XML_NAMESPACE_DB, XML_DATA_SOURCE_SETTINGS, true, true); + std::vector< TypedPropertyValue >::iterator aIter = m_aDataSourceSettings.begin(); + std::vector< TypedPropertyValue >::const_iterator aEnd = m_aDataSourceSettings.end(); + for ( ; aIter != aEnd; ++aIter ) + { + const bool bIsSequence = TypeClass_SEQUENCE == aIter->Type.getTypeClass(); + + Type aSimpleType(bIsSequence ? comphelper::getSequenceElementType(aIter->Value.getValueType()) : aIter->Type); + + AddAttribute( XML_NAMESPACE_DB, XML_DATA_SOURCE_SETTING_IS_LIST,bIsSequence ? XML_TRUE : XML_FALSE ); + AddAttribute( XML_NAMESPACE_DB, XML_DATA_SOURCE_SETTING_NAME, aIter->Name ); + + OUString sTypeName = lcl_implGetPropertyXMLType( aSimpleType ); + if ( bIsSequence && aSimpleType.getTypeClass() == TypeClass_ANY ) + { + Sequence aSeq; + aIter->Value >>= aSeq; + if ( aSeq.hasElements() ) + sTypeName = lcl_implGetPropertyXMLType(aSeq[0].getValueType()); + } + + AddAttribute( XML_NAMESPACE_DB, XML_DATA_SOURCE_SETTING_TYPE, sTypeName ); + + SvXMLElementExport aDataSourceSetting( *this, XML_NAMESPACE_DB, XML_DATA_SOURCE_SETTING, true, true ); + + if ( !bIsSequence ) + { + SvXMLElementExport aDataValue( *this, XML_NAMESPACE_DB, XML_DATA_SOURCE_SETTING_VALUE, true, false ); + // (no whitespace inside the tag) + Characters( implConvertAny( aIter->Value ) ); + } + else + { + // the not-that-simple case, we need to iterate through the sequence elements + switch (aSimpleType.getTypeClass()) + { + case TypeClass_STRING: + exportDataSourceSettingsSequence< OUString >( + aIter ); + break; + case TypeClass_DOUBLE: + exportDataSourceSettingsSequence< double >( aIter ); + break; + case TypeClass_BOOLEAN: + exportDataSourceSettingsSequence< sal_Bool >( aIter ); + break; + case TypeClass_BYTE: + exportDataSourceSettingsSequence< sal_Int8 >( aIter ); + break; + case TypeClass_SHORT: + exportDataSourceSettingsSequence< sal_Int16 >( aIter ); + break; + case TypeClass_LONG: + exportDataSourceSettingsSequence< sal_Int32 >( aIter ); + break; + case TypeClass_ANY: + exportDataSourceSettingsSequence< Any >( aIter ); + break; + default: + OSL_FAIL("unsupported sequence type !"); + break; + } + } + } +} + +void ODBExport::exportCharSet() +{ + if ( !m_sCharSet.isEmpty() ) + { + AddAttribute(XML_NAMESPACE_DB, XML_ENCODING,m_sCharSet); + + SvXMLElementExport aElem(*this,XML_NAMESPACE_DB, XML_FONT_CHARSET, true, true); + } +} + +void ODBExport::exportDelimiter() +{ + if ( m_aDelimiter && m_aDelimiter->bUsed ) + { + AddAttribute(XML_NAMESPACE_DB, XML_FIELD,m_aDelimiter->sField); + AddAttribute(XML_NAMESPACE_DB, XML_STRING,m_aDelimiter->sText); + AddAttribute(XML_NAMESPACE_DB, XML_DECIMAL,m_aDelimiter->sDecimal); + AddAttribute(XML_NAMESPACE_DB, XML_THOUSAND,m_aDelimiter->sThousand); + SvXMLElementExport aElem(*this,XML_NAMESPACE_DB, XML_DELIMITER, true, true); + } +} + +void ODBExport::exportAutoIncrement() +{ + if (m_aAutoIncrement) + { + AddAttribute(XML_NAMESPACE_DB, XML_ADDITIONAL_COLUMN_STATEMENT,m_aAutoIncrement->second); + AddAttribute(XML_NAMESPACE_DB, XML_ROW_RETRIEVING_STATEMENT,m_aAutoIncrement->first); + SvXMLElementExport aElem(*this,XML_NAMESPACE_DB, XML_AUTO_INCREMENT, true, true); + } +} + +void ODBExport::exportSequence(const Sequence< OUString>& _aValue + ,::xmloff::token::XMLTokenEnum _eTokenFilter + ,::xmloff::token::XMLTokenEnum _eTokenType) +{ + if ( _aValue.hasElements() ) + { + SvXMLElementExport aElem(*this,XML_NAMESPACE_DB, _eTokenFilter, true, true); + + const OUString* pIter = _aValue.getConstArray(); + const OUString* pEnd = pIter + _aValue.getLength(); + for(;pIter != pEnd;++pIter) + { + SvXMLElementExport aDataSource(*this,XML_NAMESPACE_DB, _eTokenType, true, false); + Characters(*pIter); + } + } +} + +void ODBExport::exportLogin() +{ + Reference xProp(getDataSource()); + OUString sValue; + xProp->getPropertyValue(PROPERTY_USER) >>= sValue; + bool bAddLogin = !sValue.isEmpty(); + if ( bAddLogin ) + AddAttribute(XML_NAMESPACE_DB, XML_USER_NAME,sValue); + bool bValue = false; + if ( xProp->getPropertyValue(PROPERTY_ISPASSWORDREQUIRED) >>= bValue ) + { + bAddLogin = true; + AddAttribute(XML_NAMESPACE_DB, XML_IS_PASSWORD_REQUIRED,bValue ? XML_TRUE : XML_FALSE); + } + if ( bAddLogin ) + SvXMLElementExport aElem(*this,XML_NAMESPACE_DB, XML_LOGIN, true, true); +} + +void ODBExport::exportCollection(const Reference< XNameAccess >& _xCollection + ,enum ::xmloff::token::XMLTokenEnum _eComponents + ,enum ::xmloff::token::XMLTokenEnum _eSubComponents + ,bool _bExportContext + ,const ::comphelper::mem_fun1_t& _aMemFunc + ) +{ + if ( !_xCollection.is() ) + return; + + std::unique_ptr pComponents; + if ( _bExportContext ) + pComponents.reset( new SvXMLElementExport(*this,XML_NAMESPACE_DB, _eComponents, true, true)); + Sequence< OUString> aSeq = _xCollection->getElementNames(); + const OUString* pIter = aSeq.getConstArray(); + const OUString* pEnd = pIter + aSeq.getLength(); + for(;pIter != pEnd;++pIter) + { + Reference xProp(_xCollection->getByName(*pIter),UNO_QUERY); + if ( _bExportContext && XML_TABLE_REPRESENTATIONS != _eComponents ) + AddAttribute(XML_NAMESPACE_DB, XML_NAME,*pIter); + Reference< XNameAccess > xSub(xProp,UNO_QUERY); + if ( xSub.is() ) + { + exportCollection(xSub,_eSubComponents,_eSubComponents,_bExportContext,_aMemFunc); + } + else if ( xProp.is() ) + _aMemFunc(this,xProp.get()); + } +} + +void ODBExport::exportComponent(XPropertySet* _xProp) +{ + OUString sValue; + _xProp->getPropertyValue(PROPERTY_PERSISTENT_NAME) >>= sValue; + bool bIsForm = true; + _xProp->getPropertyValue("IsForm") >>= bIsForm; + if ( bIsForm ) + sValue = "forms/" + sValue; + else + sValue = "reports/" + sValue; + + AddAttribute(XML_NAMESPACE_XLINK, XML_HREF, sValue); + AddAttribute(XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE); + bool bAsTemplate = false; + _xProp->getPropertyValue(PROPERTY_AS_TEMPLATE) >>= bAsTemplate; + AddAttribute(XML_NAMESPACE_DB, XML_AS_TEMPLATE,bAsTemplate ? XML_TRUE : XML_FALSE); + SvXMLElementExport aComponents(*this,XML_NAMESPACE_DB, XML_COMPONENT, true, true); +} + +void ODBExport::exportQuery(XPropertySet* _xProp) +{ + AddAttribute(XML_NAMESPACE_DB, XML_COMMAND,getString(_xProp->getPropertyValue(PROPERTY_COMMAND))); + + if ( getBOOL(_xProp->getPropertyValue(PROPERTY_APPLYFILTER)) ) + AddAttribute(XML_NAMESPACE_DB, XML_APPLY_FILTER,XML_TRUE); + + if ( _xProp->getPropertySetInfo()->hasPropertyByName(PROPERTY_APPLYORDER) + && getBOOL(_xProp->getPropertyValue(PROPERTY_APPLYORDER)) ) + AddAttribute(XML_NAMESPACE_DB, XML_APPLY_ORDER,XML_TRUE); + + if ( ! getBOOL(_xProp->getPropertyValue(PROPERTY_ESCAPE_PROCESSING)) ) + AddAttribute(XML_NAMESPACE_DB, XML_ESCAPE_PROCESSING,XML_FALSE); + + exportStyleName(_xProp,GetAttrList()); + + SvXMLElementExport aComponents(*this,XML_NAMESPACE_DB, XML_QUERY, true, true); + Reference xCol(_xProp,UNO_QUERY); + exportColumns(xCol); + exportFilter(_xProp,PROPERTY_FILTER,XML_FILTER_STATEMENT); + exportFilter(_xProp,PROPERTY_ORDER,XML_ORDER_STATEMENT); + exportTableName(_xProp,true); +} + +void ODBExport::exportTable(XPropertySet* _xProp) +{ + exportTableName(_xProp,false); + + if ( _xProp->getPropertySetInfo()->hasPropertyByName(PROPERTY_DESCRIPTION) ) + AddAttribute(XML_NAMESPACE_DB, XML_DESCRIPTION,getString(_xProp->getPropertyValue(PROPERTY_DESCRIPTION))); + + if ( getBOOL(_xProp->getPropertyValue(PROPERTY_APPLYFILTER)) ) + AddAttribute(XML_NAMESPACE_DB, XML_APPLY_FILTER,XML_TRUE); + + if ( _xProp->getPropertySetInfo()->hasPropertyByName(PROPERTY_APPLYORDER) + && getBOOL(_xProp->getPropertyValue(PROPERTY_APPLYORDER)) ) + AddAttribute(XML_NAMESPACE_DB, XML_APPLY_ORDER,XML_TRUE); + + exportStyleName(_xProp,GetAttrList()); + + SvXMLElementExport aComponents(*this,XML_NAMESPACE_DB, XML_TABLE_REPRESENTATION, true, true); + Reference xCol(_xProp,UNO_QUERY); + exportColumns(xCol); + exportFilter(_xProp,PROPERTY_FILTER,XML_FILTER_STATEMENT); + exportFilter(_xProp,PROPERTY_ORDER,XML_ORDER_STATEMENT); +} + +void ODBExport::exportStyleName(XPropertySet* _xProp,SvXMLAttributeList& _rAtt) +{ + Reference xFind(_xProp); + exportStyleName(XML_STYLE_NAME,xFind,_rAtt,m_aAutoStyleNames); + exportStyleName(XML_DEFAULT_CELL_STYLE_NAME,xFind,_rAtt,m_aCellAutoStyleNames); + exportStyleName(XML_DEFAULT_ROW_STYLE_NAME,xFind,_rAtt,m_aRowAutoStyleNames); +} + +void ODBExport::exportStyleName(const ::xmloff::token::XMLTokenEnum _eToken,const uno::Reference& _xProp,SvXMLAttributeList& _rAtt,TPropertyStyleMap& _rMap) +{ + TPropertyStyleMap::const_iterator aFind = _rMap.find(_xProp); + if ( aFind != _rMap.end() ) + { + _rAtt.AddAttribute( GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_DB, GetXMLToken(_eToken) ), + aFind->second ); + _rMap.erase(aFind); + } +} + +void ODBExport::exportTableName(XPropertySet* _xProp,bool _bUpdate) +{ + OUString sValue; + _xProp->getPropertyValue(_bUpdate ? OUString(PROPERTY_UPDATE_TABLENAME) : OUString(PROPERTY_NAME)) >>= sValue; + if ( sValue.isEmpty() ) + return; + + AddAttribute(XML_NAMESPACE_DB, XML_NAME,sValue); + _xProp->getPropertyValue(_bUpdate ? OUString(PROPERTY_UPDATE_SCHEMANAME) : OUString(PROPERTY_SCHEMANAME)) >>= sValue; + if ( !sValue.isEmpty() ) + AddAttribute(XML_NAMESPACE_DB, XML_SCHEMA_NAME,sValue); + _xProp->getPropertyValue(_bUpdate ? OUString(PROPERTY_UPDATE_CATALOGNAME) : OUString(PROPERTY_CATALOGNAME)) >>= sValue; + if ( !sValue.isEmpty() ) + AddAttribute(XML_NAMESPACE_DB, XML_CATALOG_NAME,sValue); + + if ( _bUpdate ) + { + SvXMLElementExport aComponents(*this,XML_NAMESPACE_DB, XML_UPDATE_TABLE, true, true); + } +} + +void ODBExport::exportFilter(XPropertySet* _xProp + ,const OUString& _sProp + ,enum ::xmloff::token::XMLTokenEnum _eStatementType) +{ + OSL_PRECOND(!GetAttrList().getLength(),"Invalid attribute length!"); + OUString sCommand; + _xProp->getPropertyValue(_sProp) >>= sCommand; + if ( !sCommand.isEmpty() ) + { + AddAttribute(XML_NAMESPACE_DB, XML_COMMAND,sCommand); + SvXMLElementExport aComponents(*this,XML_NAMESPACE_DB, _eStatementType, true, true); + } + SAL_WARN_IF(GetAttrList().getLength(), "dbaccess", "Invalid attribute length!"); +} + +void ODBExport::exportColumns(const Reference& _xColSup) +{ + OSL_PRECOND( _xColSup.is(), "ODBExport::exportColumns: invalid columns supplier!" ); + if ( !_xColSup.is() ) + return; + + try + { + Reference xNameAccess( _xColSup->getColumns(), UNO_SET_THROW ); + if ( !xNameAccess->hasElements() ) + { + Reference< XPropertySet > xComponent(_xColSup,UNO_QUERY); + TTableColumnMap::const_iterator aFind = m_aTableDummyColumns.find(xComponent); + if ( aFind != m_aTableDummyColumns.end() ) + { + SvXMLElementExport aColumns(*this,XML_NAMESPACE_DB, XML_COLUMNS, true, true); + rtl::Reference pAtt = new SvXMLAttributeList; + exportStyleName(aFind->second.get(),*pAtt); + AddAttributeList(pAtt); + SvXMLElementExport aColumn(*this,XML_NAMESPACE_DB, XML_COLUMN, true, true); + + } + return; + } + + SvXMLElementExport aColumns(*this,XML_NAMESPACE_DB, XML_COLUMNS, true, true); + Sequence< OUString> aSeq = xNameAccess->getElementNames(); + const OUString* pIter = aSeq.getConstArray(); + const OUString* pEnd = pIter + aSeq.getLength(); + for( ; pIter != pEnd ; ++pIter) + { + Reference xProp(xNameAccess->getByName(*pIter),UNO_QUERY); + if ( xProp.is() ) + { + rtl::Reference pAtt = new SvXMLAttributeList; + exportStyleName(xProp.get(),*pAtt); + + bool bHidden = getBOOL(xProp->getPropertyValue(PROPERTY_HIDDEN)); + + OUString sValue; + xProp->getPropertyValue(PROPERTY_HELPTEXT) >>= sValue; + Any aColumnDefault = xProp->getPropertyValue(PROPERTY_CONTROLDEFAULT); + + if ( bHidden || !sValue.isEmpty() || aColumnDefault.hasValue() || pAtt->getLength() ) + { + AddAttribute(XML_NAMESPACE_DB, XML_NAME,*pIter); + if ( bHidden ) + AddAttribute(XML_NAMESPACE_DB, XML_VISIBLE,XML_FALSE); + + if ( !sValue.isEmpty() ) + AddAttribute(XML_NAMESPACE_DB, XML_HELP_MESSAGE,sValue); + + if ( aColumnDefault.hasValue() ) + { + OUStringBuffer sColumnDefaultString,sType; + ::sax::Converter::convertAny( + sColumnDefaultString, sType, aColumnDefault ); + AddAttribute(XML_NAMESPACE_DB, XML_TYPE_NAME,sType.makeStringAndClear()); + AddAttribute(XML_NAMESPACE_DB, XML_DEFAULT_VALUE,sColumnDefaultString.makeStringAndClear()); + } + + if ( pAtt->getLength() ) + AddAttributeList(pAtt); + } + + if ( GetAttrList().getLength() ) + { + SvXMLElementExport aComponents(*this,XML_NAMESPACE_DB, XML_COLUMN, true, true); + } + } + } + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION("dbaccess"); + } +} + +void ODBExport::exportForms() +{ + Any aValue; + OUString sService; + dbtools::getDataSourceSetting(getDataSource(),"Forms",aValue); + aValue >>= sService; + if ( !sService.isEmpty() ) + return; + + Reference xSup(GetModel(),UNO_QUERY); + if ( xSup.is() ) + { + Reference< XNameAccess > xCollection = xSup->getFormDocuments(); + if ( xCollection.is() && xCollection->hasElements() ) + { + ::comphelper::mem_fun1_t aMemFunc(&ODBExport::exportComponent); + exportCollection(xCollection,XML_FORMS,XML_COMPONENT_COLLECTION,true,aMemFunc); + } + } +} + +void ODBExport::exportReports() +{ + Any aValue; + OUString sService; + dbtools::getDataSourceSetting(getDataSource(),"Reports",aValue); + aValue >>= sService; + if ( !sService.isEmpty() ) + return; + + Reference xSup(GetModel(),UNO_QUERY); + if ( xSup.is() ) + { + Reference< XNameAccess > xCollection = xSup->getReportDocuments(); + if ( xCollection.is() && xCollection->hasElements() ) + { + ::comphelper::mem_fun1_t aMemFunc(&ODBExport::exportComponent); + exportCollection(xCollection,XML_REPORTS,XML_COMPONENT_COLLECTION,true,aMemFunc); + } + } +} + +void ODBExport::exportQueries(bool _bExportContext) +{ + Any aValue; + OUString sService; + dbtools::getDataSourceSetting(getDataSource(),"CommandDefinitions",aValue); + aValue >>= sService; + if ( !sService.isEmpty() ) + return; + + Reference xSup(getDataSource(),UNO_QUERY); + if ( !xSup.is() ) + return; + + Reference< XNameAccess > xCollection = xSup->getQueryDefinitions(); + if ( xCollection.is() && xCollection->hasElements() ) + { + std::unique_ptr< ::comphelper::mem_fun1_t > pMemFunc; + if ( _bExportContext ) + pMemFunc.reset( new ::comphelper::mem_fun1_t(&ODBExport::exportQuery) ); + else + pMemFunc.reset( new ::comphelper::mem_fun1_t(&ODBExport::exportAutoStyle) ); + + exportCollection(xCollection,XML_QUERIES,XML_QUERY_COLLECTION,_bExportContext,*pMemFunc); + } +} + +void ODBExport::exportTables(bool _bExportContext) +{ + Reference xSup(getDataSource(),UNO_QUERY); + if ( !xSup.is() ) + return; + + Reference< XNameAccess > xCollection = xSup->getTables(); + if ( xCollection.is() && xCollection->hasElements() ) + { + std::unique_ptr< ::comphelper::mem_fun1_t > pMemFunc; + if ( _bExportContext ) + pMemFunc.reset( new ::comphelper::mem_fun1_t(&ODBExport::exportTable) ); + else + pMemFunc.reset( new ::comphelper::mem_fun1_t(&ODBExport::exportAutoStyle) ); + exportCollection(xCollection,XML_TABLE_REPRESENTATIONS,XML_TOKEN_INVALID,_bExportContext,*pMemFunc); + } +} + +void ODBExport::exportAutoStyle(XPropertySet* _xProp) +{ + typedef std::pair TEnumMapperPair; + typedef std::pair< rtl::Reference < SvXMLExportPropertyMapper> , TEnumMapperPair> TExportPropMapperPair; + Reference xSup(_xProp,UNO_QUERY); + if ( xSup.is() ) + { + const TExportPropMapperPair pExportHelper[] = { + TExportPropMapperPair(m_xExportHelper,TEnumMapperPair(&m_aAutoStyleNames,XmlStyleFamily::TABLE_TABLE )) + // ,TExportPropMapperPair(m_xCellExportHelper,TEnumMapperPair(&m_aCellAutoStyleNames,XmlStyleFamily::TABLE_CELL)) + ,TExportPropMapperPair(m_xRowExportHelper,TEnumMapperPair(&m_aRowAutoStyleNames,XmlStyleFamily::TABLE_ROW)) + }; + + for (const auto & i : pExportHelper) + { + std::vector< XMLPropertyState > aPropertyStates = i.first->Filter(*this, _xProp); + if ( !aPropertyStates.empty() ) + i.second.first->emplace( _xProp,GetAutoStylePool()->Add( i.second.second, std::move(aPropertyStates) ) ); + } + + Reference< XNameAccess > xCollection; + try + { + xCollection.set( xSup->getColumns(), UNO_SET_THROW ); + awt::FontDescriptor aFont; + _xProp->getPropertyValue(PROPERTY_FONT) >>= aFont; + GetFontAutoStylePool()->Add(aFont.Name,aFont.StyleName,static_cast(aFont.Family), + static_cast(aFont.Pitch),aFont.CharSet ); + + m_aCurrentPropertyStates = m_xCellExportHelper->Filter(*this, _xProp); + if ( !m_aCurrentPropertyStates.empty() && !xCollection->hasElements() ) + { + Reference< XDataDescriptorFactory> xFac(xCollection,UNO_QUERY); + if ( xFac.is() ) + { + Reference< XPropertySet> xColumn = xFac->createDataDescriptor(); + m_aTableDummyColumns.emplace( Reference< XPropertySet>(_xProp),xColumn ); + exportAutoStyle(xColumn.get()); + } + } + else + { + ::comphelper::mem_fun1_t aMemFunc(&ODBExport::exportAutoStyle); + exportCollection(xCollection,XML_TOKEN_INVALID,XML_TOKEN_INVALID,false,aMemFunc); + } + } + catch(const Exception&) + { + DBG_UNHANDLED_EXCEPTION("dbaccess"); + } + m_aCurrentPropertyStates.clear(); + } + else + { // here I know I have a column + const TExportPropMapperPair pExportHelper[] = { + TExportPropMapperPair(m_xColumnExportHelper,TEnumMapperPair(&m_aAutoStyleNames,XmlStyleFamily::TABLE_COLUMN )) + ,TExportPropMapperPair(m_xCellExportHelper,TEnumMapperPair(&m_aCellAutoStyleNames,XmlStyleFamily::TABLE_CELL)) + }; + for (const auto & i : pExportHelper) + { + std::vector< XMLPropertyState > aPropStates = i.first->Filter(*this, _xProp); + if ( !aPropStates.empty() ) + { + const rtl::Reference < XMLPropertySetMapper >& pStyle = i.first->getPropertySetMapper(); + for (auto & propState : aPropStates) + { + if ( propState.mnIndex != -1 ) + { + switch ( pStyle->GetEntryContextId(propState.mnIndex) ) + { + case CTF_DB_NUMBERFORMAT: + { + sal_Int32 nNumberFormat = -1; + if ( propState.maValue >>= nNumberFormat ) + addDataStyle(nNumberFormat); + } + break; + case CTF_DB_COLUMN_TEXT_ALIGN: + if ( !propState.maValue.hasValue() ) + propState.maValue <<= css::awt::TextAlign::LEFT; + break; + } + } + } + + } + if ( XmlStyleFamily::TABLE_CELL == i.second.second ) + aPropStates.insert( aPropStates.end(), m_aCurrentPropertyStates.begin(), m_aCurrentPropertyStates.end() ); + if ( !aPropStates.empty() ) + i.second.first->emplace( _xProp,GetAutoStylePool()->Add( i.second.second, std::move(aPropStates) ) ); + } + } +} + +void ODBExport::ExportContent_() +{ + exportDataSource(); + exportForms(); + exportReports(); + exportQueries(true); + exportTables(true); +} + +void ODBExport::ExportMasterStyles_() +{ + GetPageExport()->exportMasterStyles( true ); +} + +void ODBExport::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_CELL); + GetAutoStylePool()->exportXML(XmlStyleFamily::TABLE_ROW); + exportDataStyles(); + } +} + +void ODBExport::GetViewSettings(Sequence& aProps) +{ + Reference xSup(getDataSource(),UNO_QUERY); + if ( !xSup.is() ) + return; + + Reference< XNameAccess > xCollection = xSup->getQueryDefinitions(); + if ( !(xCollection.is() && xCollection->hasElements()) ) + return; + + try + { + sal_Int32 nLength = aProps.getLength(); + aProps.realloc(nLength + 1); + auto pProps = aProps.getArray(); + pProps[nLength].Name = "Queries"; + Sequence< OUString> aSeq = xCollection->getElementNames(); + const OUString* pIter = aSeq.getConstArray(); + const OUString* pEnd = pIter + aSeq.getLength(); + + Sequence aQueries(aSeq.getLength()); + auto aQueriesRange = asNonConstRange(aQueries); + for(sal_Int32 i = 0;pIter != pEnd;++pIter,++i) + { + Reference xProp(xCollection->getByName(*pIter),UNO_QUERY); + if ( xProp.is() ) + { + aQueriesRange[i].Name = *pIter; + aQueriesRange[i].Value = xProp->getPropertyValue(PROPERTY_LAYOUTINFORMATION); + } + } + pProps[nLength].Value <<= aQueries; + } + catch(const Exception&) + { + TOOLS_WARN_EXCEPTION( "dbaccess", "ODBExport::GetViewSettings"); + } + +} + +void ODBExport::GetConfigurationSettings(Sequence& aProps) +{ + Reference xProp(getDataSource()); + if ( !xProp.is() ) + return; + + sal_Int32 nLength = aProps.getLength(); + try + { + Any aValue = xProp->getPropertyValue(PROPERTY_LAYOUTINFORMATION); + Sequence< PropertyValue > aPropValues; + aValue >>= aPropValues; + if ( aPropValues.hasElements() ) + { + aProps.realloc(nLength + 1); + auto pProps = aProps.getArray(); + pProps[nLength].Name = "layout-settings"; + pProps[nLength].Value = aValue; + } + } + catch(const Exception&) + { + OSL_FAIL("Could not access layout information from the data source!"); + } +} + +OUString ODBExport::implConvertAny(const Any& _rValue) +{ + OUStringBuffer aBuffer; + switch (_rValue.getValueTypeClass()) + { + case TypeClass_STRING: + { // extract the string + OUString sCurrentValue; + _rValue >>= sCurrentValue; + aBuffer.append(sCurrentValue); + } + break; + case TypeClass_DOUBLE: + // let the unit converter format is as string + ::sax::Converter::convertDouble(aBuffer, getDouble(_rValue)); + break; + case TypeClass_BOOLEAN: + aBuffer = getBOOL(_rValue) ? ::xmloff::token::GetXMLToken(XML_TRUE) : ::xmloff::token::GetXMLToken(XML_FALSE); + break; + case TypeClass_BYTE: + case TypeClass_SHORT: + case TypeClass_LONG: + // let the unit converter format is as string + aBuffer.append(getINT32(_rValue)); + break; + default: + OSL_FAIL("ODBExport::implConvertAny: Invalid type"); + } + + return aBuffer.makeStringAndClear(); +} + +rtl::Reference < XMLPropertySetMapper > const & ODBExport::GetTableStylesPropertySetMapper() const +{ + if ( !m_xTableStylesPropertySetMapper.is() ) + { + m_xTableStylesPropertySetMapper = OXMLHelper::GetTableStylesPropertySetMapper( true); + } + return m_xTableStylesPropertySetMapper; +} + +rtl::Reference < XMLPropertySetMapper > const & ODBExport::GetCellStylesPropertySetMapper() const +{ + if ( !m_xCellStylesPropertySetMapper.is() ) + { + m_xCellStylesPropertySetMapper = OXMLHelper::GetCellStylesPropertySetMapper( true); + } + return m_xCellStylesPropertySetMapper; +} + +rtl::Reference < XMLPropertySetMapper > const & ODBExport::GetColumnStylesPropertySetMapper() const +{ + if ( !m_xColumnStylesPropertySetMapper.is() ) + { + m_xColumnStylesPropertySetMapper = OXMLHelper::GetColumnStylesPropertySetMapper( true); + } + return m_xColumnStylesPropertySetMapper; +} + +SvXMLAutoStylePoolP* ODBExport::CreateAutoStylePool() +{ + return new OXMLAutoStylePoolP(*this); +} + +void SAL_CALL ODBExport::setSourceDocument( const Reference< XComponent >& xDoc ) +{ + Reference xOfficeDoc(xDoc,UNO_QUERY_THROW); + m_xDataSource.set(xOfficeDoc->getDataSource(),UNO_QUERY_THROW); + OSL_ENSURE(m_xDataSource.is(),"DataSource is NULL!"); + Reference< XNumberFormatsSupplier > xNum(m_xDataSource->getPropertyValue(PROPERTY_NUMBERFORMATSSUPPLIER),UNO_QUERY); + SetNumberFormatsSupplier(xNum); + SvXMLExport::setSourceDocument(xDoc); +} + +void ODBExport::ExportFontDecls_() +{ + GetFontAutoStylePool(); // make sure the pool is created + collectComponentStyles(); + SvXMLExport::ExportFontDecls_(); +} + +void ODBExport::collectComponentStyles() +{ + if ( m_bAllreadyFilled ) + return; + + m_bAllreadyFilled = true; + exportQueries(false); + exportTables(false); +} + +}// dbaxml + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/filter/xml/xmlExport.hxx b/dbaccess/source/filter/xml/xmlExport.hxx new file mode 100644 index 000000000..7e1d148e1 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlExport.hxx @@ -0,0 +1,176 @@ +/* -*- 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 . + */ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + + +namespace dbaxml { + +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::sdbcx; +using namespace ::com::sun::star::text; +using namespace ::com::sun::star::io; +using namespace ::com::sun::star::xml::sax; + + +class ODBExport : public SvXMLExport +{ + typedef std::map< ::xmloff::token::XMLTokenEnum, OUString> TSettingsMap; + + typedef std::pair< OUString ,OUString> TStringPair; + struct TDelimiter + { + OUString sText; + OUString sField; + OUString sDecimal; + OUString sThousand; + bool bUsed; + + TDelimiter() : bUsed( false ) { } + }; + typedef std::map< Reference ,OUString > TPropertyStyleMap; + typedef std::map< Reference ,Reference > TTableColumnMap; + + struct TypedPropertyValue + { + OUString Name; + css::uno::Type Type; + css::uno::Any Value; + + TypedPropertyValue( const OUString& _name, const css::uno::Type& _type, const css::uno::Any& _value ) + :Name( _name ) + ,Type( _type ) + ,Value( _value ) + { + } + }; + + std::unique_ptr< TStringPair > m_aAutoIncrement; + std::unique_ptr< TDelimiter > m_aDelimiter; + std::vector< TypedPropertyValue > m_aDataSourceSettings; + std::vector< XMLPropertyState > m_aCurrentPropertyStates; + TPropertyStyleMap m_aAutoStyleNames; + TPropertyStyleMap m_aCellAutoStyleNames; + TPropertyStyleMap m_aRowAutoStyleNames; + TTableColumnMap m_aTableDummyColumns; + OUString m_sCharSet; + rtl::Reference < SvXMLExportPropertyMapper> m_xExportHelper; + rtl::Reference < SvXMLExportPropertyMapper> m_xColumnExportHelper; + rtl::Reference < SvXMLExportPropertyMapper> m_xCellExportHelper; + rtl::Reference < SvXMLExportPropertyMapper> m_xRowExportHelper; + + mutable rtl::Reference < XMLPropertySetMapper > m_xTableStylesPropertySetMapper; + mutable rtl::Reference < XMLPropertySetMapper > m_xColumnStylesPropertySetMapper; + mutable rtl::Reference < XMLPropertySetMapper > m_xCellStylesPropertySetMapper; + + Reference m_xDataSource; + ::dbaccess::ODsnTypeCollection m_aTypeCollection; + bool m_bAllreadyFilled; + + void exportDataSource(); + void exportConnectionData(); + void exportDriverSettings(const TSettingsMap& _aSettings); + void exportApplicationConnectionSettings(const TSettingsMap& _aSettings); + void exportLogin(); + void exportSequence(const Sequence< OUString>& _aValue + ,::xmloff::token::XMLTokenEnum _eTokenFilter + ,::xmloff::token::XMLTokenEnum _eTokenType); + void exportDelimiter(); + void exportAutoIncrement(); + void exportCharSet(); + template< typename T > void exportDataSourceSettingsSequence( + std::vector< TypedPropertyValue >::iterator const & in); + void exportDataSourceSettings(); + void exportForms(); + void exportReports(); + void exportQueries(bool _bExportContext); + void exportTables(bool _bExportContext); + void exportStyleName(XPropertySet* _xProp,SvXMLAttributeList& _rAtt); + void exportStyleName(const ::xmloff::token::XMLTokenEnum _eToken,const Reference& _xProp,SvXMLAttributeList& _rAtt,TPropertyStyleMap& _rMap); + void exportCollection(const Reference< XNameAccess >& _xCollection + ,enum ::xmloff::token::XMLTokenEnum _eComponents + ,enum ::xmloff::token::XMLTokenEnum _eSubComponents + ,bool _bExportContext + ,const ::comphelper::mem_fun1_t& _aMemFunc + ); + void exportComponent(XPropertySet* _xProp); + void exportQuery(XPropertySet* _xProp); + void exportTable(XPropertySet* _xProp); + void exportFilter(XPropertySet* _xProp + ,const OUString& _sProp + ,enum ::xmloff::token::XMLTokenEnum _eStatementType); + void exportTableName(XPropertySet* _xProp,bool _bUpdate); + void exportAutoStyle(XPropertySet* _xProp); + void exportColumns(const Reference& _xColSup); + void collectComponentStyles(); + + static OUString implConvertAny(const Any& _rValue); + + rtl::Reference < XMLPropertySetMapper > const & GetTableStylesPropertySetMapper() const; + + ODBExport() = delete; +protected: + + virtual void ExportAutoStyles_() override; + virtual void ExportContent_() override; + virtual void ExportMasterStyles_() override; + virtual void ExportFontDecls_() override; + virtual SvXMLAutoStylePoolP* CreateAutoStylePool() override; + + virtual void GetViewSettings(css::uno::Sequence& aProps) override; + virtual void GetConfigurationSettings(css::uno::Sequence& aProps) override; + + virtual ~ODBExport() override {}; +public: + + ODBExport(const Reference< XComponentContext >& _rxContext, OUString const & implementationName, SvXMLExportFlags nExportFlag = SvXMLExportFlags::CONTENT | SvXMLExportFlags::AUTOSTYLES | SvXMLExportFlags::PRETTY | SvXMLExportFlags::FONTDECLS | SvXMLExportFlags::SCRIPTS ); + + rtl::Reference < XMLPropertySetMapper > const & GetColumnStylesPropertySetMapper() const; + rtl::Reference < XMLPropertySetMapper > const & GetCellStylesPropertySetMapper() const; + + // XExporter + virtual void SAL_CALL setSourceDocument( const css::uno::Reference< css::lang::XComponent >& xDoc ) override; + + const Reference& getDataSource() const { return m_xDataSource; } +}; + +} // dbaxml + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/filter/xml/xmlFileBasedDatabase.cxx b/dbaccess/source/filter/xml/xmlFileBasedDatabase.cxx new file mode 100644 index 000000000..37e4058ab --- /dev/null +++ b/dbaccess/source/filter/xml/xmlFileBasedDatabase.cxx @@ -0,0 +1,113 @@ +/* -*- 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 "xmlFileBasedDatabase.hxx" +#include "xmlfilter.hxx" +#include +#include +#include +#include +#include +#include +#include +namespace dbaxml +{ + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::xml::sax; + +OXMLFileBasedDatabase::OXMLFileBasedDatabase( ODBFilter& rImport, + const Reference< XFastAttributeList > & _xAttrList) : + SvXMLImportContext( rImport ) +{ + Reference xDataSource = rImport.getDataSource(); + + PropertyValue aProperty; + + OUString sLocation,sMediaType,sFileTypeExtension; + if (xDataSource.is()) + { + for (auto &aIter : sax_fastparser::castToFastAttributeList( _xAttrList )) + { + OUString sValue = aIter.toString(); + + aProperty.Name.clear(); + aProperty.Value = Any(); + + switch( aIter.getToken() ) + { + case XML_ELEMENT(XLINK, XML_HREF): + { + SvtPathOptions aPathOptions; + OUString sFileName = aPathOptions.SubstituteVariable(sValue); + if ( sValue == sFileName ) + { + const sal_Int32 nFileNameLength = sFileName.getLength(); + if ( sFileName.endsWith("/") ) + sFileName = sFileName.copy( 0, nFileNameLength - 1 ); + + sLocation = ::svt::OFileNotation( rImport.GetAbsoluteReference( sFileName ) ).get( ::svt::OFileNotation::N_SYSTEM ); + } + + if ( sLocation.isEmpty() ) + sLocation = sValue; + } + break; + case XML_ELEMENT(DB, XML_MEDIA_TYPE): + case XML_ELEMENT(DB_OASIS, XML_MEDIA_TYPE): + sMediaType = sValue; + break; + case XML_ELEMENT(DB, XML_EXTENSION): + case XML_ELEMENT(DB_OASIS, XML_EXTENSION): + aProperty.Name = INFO_TEXTFILEEXTENSION; + sFileTypeExtension = sValue; + break; + default: + XMLOFF_WARN_UNKNOWN("dbaccess", aIter); + } + if ( !aProperty.Name.isEmpty() ) + { + if ( !aProperty.Value.hasValue() ) + aProperty.Value <<= sValue; + rImport.addInfo(aProperty); + } + } + } + if ( sLocation.isEmpty() || sMediaType.isEmpty() ) + return; + + ::dbaccess::ODsnTypeCollection aTypeCollection(rImport.GetComponentContext()); + OUString sURL = aTypeCollection.getDatasourcePrefixFromMediaType(sMediaType,sFileTypeExtension) + sLocation; + try + { + xDataSource->setPropertyValue(PROPERTY_URL,Any(sURL)); + } + catch(const Exception&) + { + DBG_UNHANDLED_EXCEPTION("dbaccess"); + } +} + +OXMLFileBasedDatabase::~OXMLFileBasedDatabase() +{ + +} + +} // namespace dbaxml + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/filter/xml/xmlFileBasedDatabase.hxx b/dbaccess/source/filter/xml/xmlFileBasedDatabase.hxx new file mode 100644 index 000000000..3720e1da3 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlFileBasedDatabase.hxx @@ -0,0 +1,36 @@ +/* -*- 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 . + */ +#pragma once + +#include + +namespace dbaxml +{ + class ODBFilter; + class OXMLFileBasedDatabase : public SvXMLImportContext + { + public: + + OXMLFileBasedDatabase( ODBFilter& rImport, + const css::uno::Reference< css::xml::sax::XFastAttributeList > & _xAttrList ); + virtual ~OXMLFileBasedDatabase() override; + }; +} // namespace dbaxml + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/filter/xml/xmlHelper.cxx b/dbaccess/source/filter/xml/xmlHelper.cxx new file mode 100644 index 000000000..85b98ec1e --- /dev/null +++ b/dbaccess/source/filter/xml/xmlHelper.cxx @@ -0,0 +1,157 @@ +/* -*- 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 + +namespace dbaxml +{ + using namespace ::xmloff::token; + using namespace ::com::sun::star::awt; + +OPropertyHandlerFactory::OPropertyHandlerFactory() +{ +} + +OPropertyHandlerFactory::~OPropertyHandlerFactory() +{ + +} + +const XMLPropertyHandler* OPropertyHandlerFactory::GetPropertyHandler(sal_Int32 _nType) const +{ + const XMLPropertyHandler* pHandler = nullptr; + + switch (_nType) + { + case XML_DB_TYPE_EQUAL: + if (!m_pDisplayHandler) + { + static const SvXMLEnumMapEntry aDisplayMap[] = + { + { XML_VISIBLE, true }, + { XML_COLLAPSE, false }, + { XML_TOKEN_INVALID, false } + }; + m_pDisplayHandler.reset(new XMLConstantsPropertyHandler(aDisplayMap, XML_TOKEN_INVALID )); + } + pHandler = m_pDisplayHandler.get(); + break; + } + if ( !pHandler ) + pHandler = OControlPropertyHandlerFactory::GetPropertyHandler(_nType); + return pHandler; +} + +rtl::Reference < XMLPropertySetMapper > OXMLHelper::GetTableStylesPropertySetMapper( bool bForExport ) +{ + static const XMLPropertyMapEntry s_aTableStylesProperties[] = + { + { nullptr, 0, XML_TOKEN_INVALID, 0 , 0, SvtSaveOptions::ODFSVER_010, false} + }; + rtl::Reference < XMLPropertyHandlerFactory> xFac = new ::xmloff::OControlPropertyHandlerFactory(); + return new XMLPropertySetMapper(s_aTableStylesProperties, xFac, bForExport); +} + +rtl::Reference < XMLPropertySetMapper > OXMLHelper::GetColumnStylesPropertySetMapper( bool bForExport ) +{ + static const XMLPropertyMapEntry s_aColumnStylesProperties[] = + { + { PROPERTY_WIDTH, XML_NAMESPACE_STYLE, XML_COLUMN_WIDTH, XML_TYPE_MEASURE|XML_TYPE_PROP_TABLE_COLUMN, 0, SvtSaveOptions::ODFSVER_010, false }, + { PROPERTY_HIDDEN, XML_NAMESPACE_TABLE, XML_DISPLAY, XML_DB_TYPE_EQUAL|MID_FLAG_SPECIAL_ITEM|XML_TYPE_PROP_TABLE_COLUMN, + CTF_DB_ISVISIBLE, SvtSaveOptions::ODFSVER_010, false }, + { PROPERTY_NUMBERFORMAT, XML_NAMESPACE_STYLE, XML_DATA_STYLE_NAME, XML_TYPE_NUMBER|MID_FLAG_SPECIAL_ITEM|XML_TYPE_PROP_TABLE_COLUMN, + CTF_DB_NUMBERFORMAT, SvtSaveOptions::ODFSVER_010, false }, + { nullptr, 0, XML_TOKEN_INVALID, 0 , 0, SvtSaveOptions::ODFSVER_010, false} + }; + rtl::Reference < XMLPropertyHandlerFactory> xFac = new OPropertyHandlerFactory(); + return new XMLPropertySetMapper(s_aColumnStylesProperties, xFac, bForExport); +} + +rtl::Reference < XMLPropertySetMapper > OXMLHelper::GetCellStylesPropertySetMapper( bool bForExport ) +{ + static const XMLPropertyMapEntry s_aCellStylesProperties[] = + { + { PROPERTY_ALIGN, XML_NAMESPACE_FO, XML_TEXT_ALIGN, XML_TYPE_TEXT_ALIGN|XML_TYPE_PROP_PARAGRAPH, CTF_DB_COLUMN_TEXT_ALIGN, SvtSaveOptions::ODFSVER_010, false }, + { PROPERTY_FONTNAME, XML_NAMESPACE_STYLE, XML_FONT_NAME, XML_TYPE_STRING|XML_TYPE_PROP_TEXT, 0 , SvtSaveOptions::ODFSVER_010, false }, + { PROPERTY_TEXTCOLOR, XML_NAMESPACE_FO, XML_COLOR, XML_TYPE_COLOR|XML_TYPE_PROP_TEXT, 0 , SvtSaveOptions::ODFSVER_010, false }, + { PROPERTY_TEXTLINECOLOR, XML_NAMESPACE_STYLE, XML_TEXT_UNDERLINE_COLOR, + XML_TYPE_TEXT_UNDERLINE_COLOR|MID_FLAG_MULTI_PROPERTY|XML_TYPE_PROP_TEXT, 0 , SvtSaveOptions::ODFSVER_010, false }, + { PROPERTY_TEXTRELIEF, XML_NAMESPACE_STYLE, XML_FONT_RELIEF, + XML_TYPE_TEXT_FONT_RELIEF|MID_FLAG_MULTI_PROPERTY|XML_TYPE_PROP_TEXT, 0 , SvtSaveOptions::ODFSVER_010, false }, + { PROPERTY_TEXTEMPHASIS, XML_NAMESPACE_STYLE, XML_TEXT_EMPHASIZE, XML_TYPE_CONTROL_TEXT_EMPHASIZE|XML_TYPE_PROP_TEXT, 0 , SvtSaveOptions::ODFSVER_010, false }, + { PROPERTY_FONTCHARWIDTH, XML_NAMESPACE_STYLE, XML_FONT_CHAR_WIDTH, XML_TYPE_NUMBER16|XML_TYPE_PROP_TEXT, 0 , SvtSaveOptions::ODFSVER_010, false }, + { PROPERTY_FONTCHARSET, XML_NAMESPACE_STYLE, XML_FONT_CHARSET, XML_TYPE_TEXT_FONTENCODING|XML_TYPE_PROP_TEXT, 0 , SvtSaveOptions::ODFSVER_010, false }, + { PROPERTY_FONTFAMILY, XML_NAMESPACE_STYLE, XML_FONT_FAMILY_GENERIC, XML_TYPE_TEXT_FONTFAMILY|XML_TYPE_PROP_TEXT, 0 , SvtSaveOptions::ODFSVER_010, false }, + { PROPERTY_FONTHEIGHT, XML_NAMESPACE_FO, XML_FONT_SIZE, XML_TYPE_MEASURE16|XML_TYPE_PROP_TEXT, 0 , SvtSaveOptions::ODFSVER_010, false }, + { PROPERTY_FONTKERNING, XML_NAMESPACE_STYLE, XML_LETTER_KERNING, XML_TYPE_BOOL|XML_TYPE_PROP_TEXT, 0 , SvtSaveOptions::ODFSVER_010, false }, + { PROPERTY_FONTORIENTATION, XML_NAMESPACE_STYLE, XML_ROTATION_ANGLE, XML_TYPE_ROTATION_ANGLE|XML_TYPE_PROP_TEXT, 0 , SvtSaveOptions::ODFSVER_010, false }, + { PROPERTY_FONTPITCH, XML_NAMESPACE_STYLE, XML_FONT_PITCH, XML_TYPE_TEXT_FONTPITCH|XML_TYPE_PROP_TEXT, 0 , SvtSaveOptions::ODFSVER_010, false }, + { PROPERTY_FONTSLANT, XML_NAMESPACE_FO, XML_FONT_STYLE, XML_TYPE_TEXT_POSTURE|XML_TYPE_PROP_TEXT, 0 , SvtSaveOptions::ODFSVER_010, false }, + { "CharStrikeout", XML_NAMESPACE_STYLE, XML_TEXT_LINE_THROUGH_STYLE, + XML_TYPE_TEXT_CROSSEDOUT_STYLE|MID_FLAG_MERGE_PROPERTY|XML_TYPE_PROP_TEXT, 0, SvtSaveOptions::ODFSVER_010, false }, + { "CharStrikeout", XML_NAMESPACE_STYLE, XML_TEXT_LINE_THROUGH_TYPE, + XML_TYPE_TEXT_CROSSEDOUT_TYPE|MID_FLAG_MERGE_PROPERTY|XML_TYPE_PROP_TEXT, 0, SvtSaveOptions::ODFSVER_010, false }, + { "CharStrikeout", XML_NAMESPACE_STYLE, XML_TEXT_LINE_THROUGH_WIDTH, + XML_TYPE_TEXT_CROSSEDOUT_WIDTH|MID_FLAG_MERGE_PROPERTY|XML_TYPE_PROP_TEXT, 0, SvtSaveOptions::ODFSVER_010, false }, + { "CharStrikeout", XML_NAMESPACE_STYLE, XML_TEXT_LINE_THROUGH_TEXT, + XML_TYPE_TEXT_CROSSEDOUT_TEXT|MID_FLAG_MERGE_PROPERTY|XML_TYPE_PROP_TEXT, 0, SvtSaveOptions::ODFSVER_010, false }, + { PROPERTY_FONTSTYLENAME, XML_NAMESPACE_STYLE, XML_FONT_STYLE_NAME, XML_TYPE_STRING|XML_TYPE_PROP_TEXT, 0 , SvtSaveOptions::ODFSVER_010, false }, + { "CharUnderline", XML_NAMESPACE_STYLE, XML_TEXT_UNDERLINE_STYLE, + XML_TYPE_TEXT_UNDERLINE_STYLE|MID_FLAG_MERGE_PROPERTY|XML_TYPE_PROP_TEXT, 0 , SvtSaveOptions::ODFSVER_010, false }, + { "CharUnderline", XML_NAMESPACE_STYLE, XML_TEXT_UNDERLINE_TYPE, + XML_TYPE_TEXT_UNDERLINE_TYPE|MID_FLAG_MERGE_PROPERTY|XML_TYPE_PROP_TEXT, 0 , SvtSaveOptions::ODFSVER_010, false }, + { "CharUnderline", XML_NAMESPACE_STYLE, XML_TEXT_UNDERLINE_WIDTH, + XML_TYPE_TEXT_UNDERLINE_WIDTH|MID_FLAG_MERGE_PROPERTY|XML_TYPE_PROP_TEXT, 0 , SvtSaveOptions::ODFSVER_010, false }, + { "CharUnderlineColor", XML_NAMESPACE_STYLE, XML_TEXT_UNDERLINE_COLOR, + XML_TYPE_TEXT_UNDERLINE_COLOR|MID_FLAG_MULTI_PROPERTY|XML_TYPE_PROP_TEXT, 0 , SvtSaveOptions::ODFSVER_010, false }, + { "CharUnderlineHasColor", XML_NAMESPACE_STYLE, XML_TEXT_UNDERLINE_COLOR, XML_TYPE_TEXT_UNDERLINE_HASCOLOR|MID_FLAG_MERGE_ATTRIBUTE|XML_TYPE_PROP_TEXT, 0 , SvtSaveOptions::ODFSVER_010, false }, + { PROPERTY_FONTWEIGHT, XML_NAMESPACE_FO, XML_FONT_WEIGHT, XML_TYPE_TEXT_WEIGHT|XML_TYPE_PROP_TEXT, 0 , SvtSaveOptions::ODFSVER_010, false }, + { PROPERTY_FONTWIDTH, XML_NAMESPACE_STYLE, XML_FONT_WIDTH, XML_TYPE_FONT_WIDTH|XML_TYPE_PROP_TEXT, 0 , SvtSaveOptions::ODFSVER_010, false }, + { PROPERTY_FONTWORDLINEMODE, XML_NAMESPACE_STYLE, XML_TEXT_UNDERLINE_MODE, + XML_TYPE_TEXT_LINE_MODE|MID_FLAG_MERGE_PROPERTY|XML_TYPE_PROP_TEXT, 0 , SvtSaveOptions::ODFSVER_010, false }, + { nullptr, 0, XML_TOKEN_INVALID, 0 , 0, SvtSaveOptions::ODFSVER_010, false} + }; + rtl::Reference < XMLPropertyHandlerFactory> xFac = new /*OPropertyHandlerFactory*/::xmloff::OControlPropertyHandlerFactory(); + return new XMLPropertySetMapper(s_aCellStylesProperties, xFac, bForExport); +} + +rtl::Reference < XMLPropertySetMapper > OXMLHelper::GetRowStylesPropertySetMapper() +{ + static const XMLPropertyMapEntry s_aStylesProperties[] = + { + { PROPERTY_ROW_HEIGHT, XML_NAMESPACE_STYLE, XML_ROW_HEIGHT, XML_TYPE_MEASURE|XML_TYPE_PROP_TABLE_ROW, 0, SvtSaveOptions::ODFSVER_010, false }, + { nullptr, 0, XML_TOKEN_INVALID, 0 , 0, SvtSaveOptions::ODFSVER_010, false} + }; + rtl::Reference < XMLPropertyHandlerFactory> xFac = new OPropertyHandlerFactory(); + return new XMLPropertySetMapper(s_aStylesProperties, xFac, true/*bForExport*/); +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/filter/xml/xmlHelper.hxx b/dbaccess/source/filter/xml/xmlHelper.hxx new file mode 100644 index 000000000..a65cef9b3 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlHelper.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 . + */ +#pragma once + +#include +#include +#include + +#include + +#define CTF_DB_ROWHEIGHT (XML_DB_CTF_START + 1) +#define CTF_DB_ISVISIBLE (XML_DB_CTF_START + 2) +#define CTF_DB_MASTERPAGENAME (XML_DB_CTF_START + 3) +#define CTF_DB_NUMBERFORMAT (XML_DB_CTF_START + 4) +#define CTF_DB_COLUMN_TEXT_ALIGN (XML_DB_CTF_START + 5) + +#define XML_DB_TYPE_EQUAL (XML_DB_TYPES_START + 1) + +namespace dbaxml +{ + class OPropertyHandlerFactory final : public ::xmloff::OControlPropertyHandlerFactory + { + mutable std::unique_ptr m_pDisplayHandler; + public: + OPropertyHandlerFactory(); + virtual ~OPropertyHandlerFactory() override; + + virtual const XMLPropertyHandler* GetPropertyHandler(sal_Int32 _nType) const override; + }; + + class OXMLHelper + { + public: + static rtl::Reference < XMLPropertySetMapper > GetTableStylesPropertySetMapper( bool bForExport ); + static rtl::Reference < XMLPropertySetMapper > GetColumnStylesPropertySetMapper( bool bForExport ); + static rtl::Reference < XMLPropertySetMapper > GetCellStylesPropertySetMapper( bool bForExport ); + static rtl::Reference < XMLPropertySetMapper > GetRowStylesPropertySetMapper(); + }; +} // dbaxml + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/filter/xml/xmlHierarchyCollection.cxx b/dbaccess/source/filter/xml/xmlHierarchyCollection.cxx new file mode 100644 index 000000000..8528f11c8 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlHierarchyCollection.cxx @@ -0,0 +1,131 @@ +/* -*- 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 "xmlHierarchyCollection.hxx" +#include "xmlComponent.hxx" +#include "xmlColumn.hxx" +#include "xmlfilter.hxx" +#include +#include +#include "xmlEnums.hxx" +#include +#include +#include +#include + +namespace dbaxml +{ + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::beans; + using namespace ::com::sun::star::container; + using namespace ::com::sun::star::xml::sax; + +OXMLHierarchyCollection::OXMLHierarchyCollection( ODBFilter& rImport + ,const Reference< XFastAttributeList > & _xAttrList + ,const Reference< XNameAccess >& _xParentContainer + ,const OUString& _sCollectionServiceName + ,const OUString& _sComponentServiceName) : + SvXMLImportContext( rImport ) + ,m_sCollectionServiceName(_sCollectionServiceName) + ,m_sComponentServiceName(_sComponentServiceName) +{ + OUString sName; + for (auto &aIter : sax_fastparser::castToFastAttributeList( _xAttrList )) + { + switch( aIter.getToken() & TOKEN_MASK ) + { + case XML_NAME: + sName = aIter.toString(); + break; + default: + XMLOFF_WARN_UNKNOWN("dbaccess", aIter); + } + } + if ( sName.isEmpty() || !_xParentContainer.is() ) + return; + + try + { + Reference xORB(_xParentContainer,UNO_QUERY); + if ( xORB.is() ) + { + Sequence aArguments(comphelper::InitAnyPropertySequence( + { + {"Name", Any(sName)}, // set as folder + {"Parent", Any(_xParentContainer)}, + })); + m_xContainer.set(xORB->createInstanceWithArguments(_sCollectionServiceName,aArguments),UNO_QUERY); + Reference xNameContainer(_xParentContainer,UNO_QUERY); + if ( xNameContainer.is() && !xNameContainer->hasByName(sName) ) + xNameContainer->insertByName(sName,Any(m_xContainer)); + } + } + catch(Exception&) + { + TOOLS_WARN_EXCEPTION( "dbaccess", "OXMLHierarchyCollection::OXMLHierarchyCollection"); + } +} + +OXMLHierarchyCollection::OXMLHierarchyCollection( ODBFilter& rImport + ,const Reference< XNameAccess >& _xContainer + ,const Reference< XPropertySet >& _xTable + ) : + SvXMLImportContext( rImport ) + ,m_xContainer(_xContainer) + ,m_xTable(_xTable) +{ +} + +OXMLHierarchyCollection::~OXMLHierarchyCollection() +{ + +} + +css::uno::Reference< css::xml::sax::XFastContextHandler > OXMLHierarchyCollection::createFastChildContext( + sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) +{ + SvXMLImportContext *pContext = nullptr; + + switch( nElement & TOKEN_MASK ) + { + case XML_COMPONENT: + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + pContext = new OXMLComponent( GetOwnImport(), xAttrList,m_xContainer,m_sComponentServiceName ); + break; + case XML_COLUMN: + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + pContext = new OXMLColumn( GetOwnImport(), xAttrList,m_xContainer,m_xTable); + break; + case XML_COMPONENT_COLLECTION: + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + pContext = new OXMLHierarchyCollection( GetOwnImport(), xAttrList,m_xContainer,m_sCollectionServiceName,m_sComponentServiceName); + break; + } + + return pContext; +} + +ODBFilter& OXMLHierarchyCollection::GetOwnImport() +{ + return static_cast(GetImport()); +} + +} // namespace dbaxml + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/filter/xml/xmlHierarchyCollection.hxx b/dbaccess/source/filter/xml/xmlHierarchyCollection.hxx new file mode 100644 index 000000000..689434822 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlHierarchyCollection.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 . + */ +#pragma once + +#include +#include +#include + +namespace dbaxml +{ + class ODBFilter; + class OXMLHierarchyCollection : public SvXMLImportContext + { + css::uno::Reference< css::container::XNameAccess > m_xContainer; + css::uno::Reference< css::beans::XPropertySet > m_xTable; + OUString m_sCollectionServiceName; + OUString m_sComponentServiceName; + + ODBFilter& GetOwnImport(); + public: + + OXMLHierarchyCollection( ODBFilter& rImport + ,const css::uno::Reference< css::xml::sax::XFastAttributeList > & _xAttrList + ,const css::uno::Reference< css::container::XNameAccess >& _xParentContainer + ,const OUString& _sCollectionServiceName + ,const OUString& _sComponentServiceName + ); + OXMLHierarchyCollection( ODBFilter& rImport + ,const css::uno::Reference< css::container::XNameAccess >& _xContainer + ,const css::uno::Reference< css::beans::XPropertySet >& _xTable + ); + virtual ~OXMLHierarchyCollection() override; + + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( + sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override; + }; +} // namespace dbaxml + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/filter/xml/xmlLogin.cxx b/dbaccess/source/filter/xml/xmlLogin.cxx new file mode 100644 index 000000000..fb4bb9eb8 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlLogin.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 "xmlLogin.hxx" +#include "xmlfilter.hxx" +#include +#include +#include +#include + +namespace dbaxml +{ + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::sdbc; + using namespace ::com::sun::star::xml::sax; + +OXMLLogin::OXMLLogin( ODBFilter& rImport, + const Reference< XFastAttributeList > & _xAttrList ) : + SvXMLImportContext( rImport ) +{ + Reference xDataSource(rImport.getDataSource()); + + bool bUserFound = false; + if (!xDataSource.is()) + return; + + for (auto &aIter : sax_fastparser::castToFastAttributeList( _xAttrList )) + { + try + { + switch( aIter.getToken() & TOKEN_MASK ) + { + case XML_USER_NAME: + if ( !bUserFound ) + { + bUserFound = true; + try + { + xDataSource->setPropertyValue(PROPERTY_USER,Any(aIter.toString())); + } + catch(const Exception&) + { + DBG_UNHANDLED_EXCEPTION("dbaccess"); + } + } + break; + case XML_IS_PASSWORD_REQUIRED: + try + { + xDataSource->setPropertyValue(PROPERTY_ISPASSWORDREQUIRED,Any(IsXMLToken(aIter, XML_TRUE))); + } + catch(const Exception&) + { + DBG_UNHANDLED_EXCEPTION("dbaccess"); + } + break; + case XML_USE_SYSTEM_USER: + if ( !bUserFound ) + { + bUserFound = true; + PropertyValue aProperty; + aProperty.Name = "UseSystemUser"; + aProperty.Value <<= IsXMLToken(aIter, XML_TRUE); + rImport.addInfo(aProperty); + } + break; + case XML_LOGIN_TIMEOUT: + try + { + Reference< XDataSource>(xDataSource,UNO_QUERY_THROW)->setLoginTimeout(aIter.toInt32()); + } + catch(const Exception&) + { + DBG_UNHANDLED_EXCEPTION("dbaccess"); + } + break; + default: + XMLOFF_WARN_UNKNOWN("dbaccess", aIter); + } + } + catch(const Exception&) + { + DBG_UNHANDLED_EXCEPTION("dbaccess"); + } + } +} + +OXMLLogin::~OXMLLogin() +{ + +} + +} // namespace dbaxml + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/filter/xml/xmlLogin.hxx b/dbaccess/source/filter/xml/xmlLogin.hxx new file mode 100644 index 000000000..adb25c739 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlLogin.hxx @@ -0,0 +1,37 @@ +/* -*- 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 . + */ +#pragma once + +#include + +namespace dbaxml +{ + class ODBFilter; + class OXMLLogin : public SvXMLImportContext + { + public: + + OXMLLogin( ODBFilter& rImport, + const css::uno::Reference< css::xml::sax::XFastAttributeList > & _xAttrList ); + virtual ~OXMLLogin() override; + + }; +} // namespace dbaxml + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/filter/xml/xmlQuery.cxx b/dbaccess/source/filter/xml/xmlQuery.cxx new file mode 100644 index 000000000..18ba034da --- /dev/null +++ b/dbaccess/source/filter/xml/xmlQuery.cxx @@ -0,0 +1,117 @@ +/* -*- 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 "xmlQuery.hxx" +#include "xmlfilter.hxx" +#include +#include +#include "xmlEnums.hxx" +#include +#include + +namespace dbaxml +{ + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::beans; + using namespace ::com::sun::star::container; + using namespace ::com::sun::star::xml::sax; + + +OXMLQuery::OXMLQuery( ODBFilter& rImport + ,const Reference< XFastAttributeList > & _xAttrList + ,const css::uno::Reference< css::container::XNameAccess >& _xParentContainer + ) : + OXMLTable( rImport, _xAttrList,_xParentContainer, "com.sun.star.sdb.CommandDefinition" ) + ,m_bEscapeProcessing(true) +{ + for (auto &aIter : sax_fastparser::castToFastAttributeList( _xAttrList )) + { + switch( aIter.getToken() & TOKEN_MASK ) + { + case XML_COMMAND: + m_sCommand = aIter.toString(); + break; + case XML_ESCAPE_PROCESSING: + m_bEscapeProcessing = aIter.toView() == "true"; + break; + default: + XMLOFF_WARN_UNKNOWN("dbaccess", aIter); + } + } +} + +OXMLQuery::~OXMLQuery() +{ + +} + +css::uno::Reference< css::xml::sax::XFastContextHandler > OXMLQuery::createFastChildContext( + sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) +{ + css::uno::Reference< css::xml::sax::XFastContextHandler > xContext = OXMLTable::createFastChildContext(nElement,xAttrList ); + if (!xContext) + { + switch( nElement & TOKEN_MASK ) + { + case XML_UPDATE_TABLE: + { + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + OUString s1; + fillAttributes(xAttrList,s1,m_sTable,m_sSchema,m_sCatalog); + break; + } + } + } + + return xContext; +} + +void OXMLQuery::setProperties(Reference< XPropertySet > & _xProp ) +{ + try + { + if ( _xProp.is() ) + { + OXMLTable::setProperties(_xProp); + + _xProp->setPropertyValue(PROPERTY_COMMAND,Any(m_sCommand)); + _xProp->setPropertyValue(PROPERTY_ESCAPE_PROCESSING,Any(m_bEscapeProcessing)); + + if ( !m_sTable.isEmpty() ) + _xProp->setPropertyValue(PROPERTY_UPDATE_TABLENAME,Any(m_sTable)); + if ( !m_sCatalog.isEmpty() ) + _xProp->setPropertyValue(PROPERTY_UPDATE_CATALOGNAME,Any(m_sCatalog)); + if ( !m_sSchema.isEmpty() ) + _xProp->setPropertyValue(PROPERTY_UPDATE_SCHEMANAME,Any(m_sSchema)); + + const ODBFilter::TPropertyNameMap& rSettings = GetOwnImport().getQuerySettings(); + ODBFilter::TPropertyNameMap::const_iterator aFind = rSettings.find(m_sName); + if ( aFind != rSettings.end() ) + _xProp->setPropertyValue(PROPERTY_LAYOUTINFORMATION,Any(aFind->second)); + } + } + catch(Exception&) + { + TOOLS_WARN_EXCEPTION( "dbaccess", "OXMLTable::EndElement"); + } +} + +} // namespace dbaxml + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/filter/xml/xmlQuery.hxx b/dbaccess/source/filter/xml/xmlQuery.hxx new file mode 100644 index 000000000..d3e01193c --- /dev/null +++ b/dbaccess/source/filter/xml/xmlQuery.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 . + */ +#pragma once + +#include "xmlTable.hxx" + +namespace dbaxml +{ + class ODBFilter; + class OXMLQuery : public OXMLTable + { + OUString m_sCommand; + OUString m_sTable; + bool m_bEscapeProcessing; + protected: + virtual void setProperties(css::uno::Reference< css::beans::XPropertySet > & _xProp) override; + public: + + OXMLQuery( ODBFilter& rImport + ,const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList + ,const css::uno::Reference< css::container::XNameAccess >& _xParentContainer + ); + virtual ~OXMLQuery() override; + + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( + sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override; + }; +} // namespace dbaxml + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/filter/xml/xmlServerDatabase.cxx b/dbaccess/source/filter/xml/xmlServerDatabase.cxx new file mode 100644 index 000000000..ff41590f0 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlServerDatabase.cxx @@ -0,0 +1,136 @@ +/* -*- 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 "xmlServerDatabase.hxx" +#include "xmlfilter.hxx" +#include +#include +#include +#include + +namespace dbaxml +{ + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::xml::sax; + +OXMLServerDatabase::OXMLServerDatabase( ODBFilter& rImport, + const Reference< XFastAttributeList > & _xAttrList) : + SvXMLImportContext( rImport ) +{ + Reference xDataSource = rImport.getDataSource(); + + PropertyValue aProperty; + + OUString sType,sHostName,sPortNumber,sDatabaseName; + if (xDataSource.is()) + { + for (auto &aIter : sax_fastparser::castToFastAttributeList( _xAttrList )) + { + OUString sValue = aIter.toString(); + + switch( aIter.getToken() & TOKEN_MASK ) + { + case XML_TYPE: + sType = sValue; + break; + case XML_HOSTNAME: + sHostName = sValue; + break; + case XML_PORT: + sPortNumber = sValue; + break; + case XML_LOCAL_SOCKET: + aProperty.Name = "LocalSocket"; + aProperty.Value <<= sValue; + rImport.addInfo(aProperty); + break; + case XML_DATABASE_NAME: + sDatabaseName = sValue; + break; + default: + XMLOFF_WARN_UNKNOWN("dbaccess", aIter); + } + } + } + if ( sType.isEmpty() ) + return; + + OUStringBuffer sURL; + if ( sType == "sdbc:mysql:jdbc" || sType == "sdbc:mysqlc" || sType == "sdbc:mysql:mysqlc" ) + { + sURL.append( sType + ":" + sHostName); + if ( !sPortNumber.isEmpty() ) + { + sURL.append(":" + sPortNumber); + } + if ( !sDatabaseName.isEmpty() ) + { + sURL.append("/" + sDatabaseName); + } + } + else if ( sType == "jdbc:oracle:thin" ) + { + sURL.append("jdbc:oracle:thin:@" + sHostName); + if ( !sPortNumber.isEmpty() ) + { + sURL.append(":" + sPortNumber); + } + if ( !sDatabaseName.isEmpty() ) + { + sURL.append(":" + sDatabaseName); + } + } + else if ( sType == "sdbc:address:ldap" ) + { + sURL.append("sdbc:address:ldap:" + sHostName); + if ( !sPortNumber.isEmpty() ) + { + sURL.append(":" + sPortNumber); + } + } + else + { + sURL.append(sType + ":" + sHostName); + if ( !sPortNumber.isEmpty() ) + { + sURL.append(":" + sPortNumber); + } + if ( !sDatabaseName.isEmpty() ) + { + sURL.append(":" + sDatabaseName); + } + } + try + { + xDataSource->setPropertyValue(PROPERTY_URL,Any(sURL.makeStringAndClear())); + } + catch(const Exception&) + { + DBG_UNHANDLED_EXCEPTION("dbaccess"); + } +} + +OXMLServerDatabase::~OXMLServerDatabase() +{ + +} + +} // namespace dbaxml + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/filter/xml/xmlServerDatabase.hxx b/dbaccess/source/filter/xml/xmlServerDatabase.hxx new file mode 100644 index 000000000..ec3401fff --- /dev/null +++ b/dbaccess/source/filter/xml/xmlServerDatabase.hxx @@ -0,0 +1,36 @@ +/* -*- 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 . + */ +#pragma once + +#include + +namespace dbaxml +{ + class ODBFilter; + class OXMLServerDatabase : public SvXMLImportContext + { + public: + + OXMLServerDatabase( ODBFilter& rImport, + const css::uno::Reference< css::xml::sax::XFastAttributeList > & _xAttrList ); + virtual ~OXMLServerDatabase() override; + }; +} // namespace dbaxml + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/filter/xml/xmlStyleImport.cxx b/dbaccess/source/filter/xml/xmlStyleImport.cxx new file mode 100644 index 000000000..ddadc5e3b --- /dev/null +++ b/dbaccess/source/filter/xml/xmlStyleImport.cxx @@ -0,0 +1,263 @@ +/* -*- 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 "xmlfilter.hxx" +#include "xmlHelper.hxx" + +namespace dbaxml +{ + +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; + + +OTableStyleContext::OTableStyleContext( ODBFilter& rImport, + SvXMLStylesContext& rStyles, XmlStyleFamily nFamily ) + :XMLPropStyleContext( rImport, rStyles, nFamily, false ) + ,pStyles(&rStyles) + ,m_nNumberFormat(-1) +{ + +} + +OTableStyleContext::~OTableStyleContext() +{ + +} + +void OTableStyleContext::FillPropertySet( + const Reference< XPropertySet > & rPropSet ) +{ + if ( !IsDefaultStyle() ) + { + if ( GetFamily() == XmlStyleFamily::TABLE_TABLE ) + { + if ( !sPageStyle.isEmpty() ) + { + AddProperty(CTF_DB_MASTERPAGENAME, Any(sPageStyle)); + } + } + else if ( GetFamily() == XmlStyleFamily::TABLE_COLUMN ) + { + if ((m_nNumberFormat == -1) && !m_sDataStyleName.isEmpty()) + { + SvXMLNumFormatContext* pStyle = const_cast(dynamic_cast< const SvXMLNumFormatContext* >(pStyles->FindStyleChildContext( + XmlStyleFamily::DATA_STYLE, m_sDataStyleName, true))); + if ( !pStyle ) + { + OTableStylesContext* pMyStyles = dynamic_cast(GetOwnImport().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 ) + { + uno::Any aNumberFormat; + m_nNumberFormat = pStyle->GetKey(); + aNumberFormat <<= m_nNumberFormat; + AddProperty(CTF_DB_NUMBERFORMAT, aNumberFormat); + } + } + } + } + XMLPropStyleContext::FillPropertySet(rPropSet); +} + +void OTableStyleContext::SetDefaults() +{ +} + +void OTableStyleContext::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 OTableStyleContext::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: + sPageStyle = rValue; + break; + default: + XMLPropStyleContext::SetAttribute( nElement, rValue ); + } +} + +ODBFilter& OTableStyleContext::GetOwnImport() +{ + return static_cast(GetImport()); +} + + +OTableStylesContext::OTableStylesContext( SvXMLImport& rImport, + bool bTempAutoStyles ) + : SvXMLStylesContext( rImport ) + , m_nNumberFormatIndex(-1) + , m_nMasterPageNameIndex(-1) + , bAutoStyles(bTempAutoStyles) +{ + +} + +OTableStylesContext::~OTableStylesContext() +{ + +} + +void OTableStylesContext::endFastElement(sal_Int32 ) +{ + if (bAutoStyles) + GetImport().GetTextImport()->SetAutoStyles( this ); + else + GetImport().GetStyles()->CopyStylesToDoc(true); +} + +rtl::Reference < SvXMLImportPropertyMapper > + OTableStylesContext::GetImportPropertyMapper( + XmlStyleFamily nFamily ) const +{ + rtl::Reference < SvXMLImportPropertyMapper > xMapper = SvXMLStylesContext::GetImportPropertyMapper(nFamily); + + if (!xMapper.is()) + { + switch( nFamily ) + { + case XmlStyleFamily::TABLE_TABLE: + { + if ( !m_xTableImpPropMapper.is() ) + m_xTableImpPropMapper = new SvXMLImportPropertyMapper( const_cast(this)->GetOwnImport().GetTableStylesPropertySetMapper(), const_cast(GetImport()) ); + xMapper = m_xTableImpPropMapper; + } + break; + case XmlStyleFamily::TABLE_COLUMN: + { + if ( !m_xColumnImpPropMapper.is() ) + m_xColumnImpPropMapper = new SvXMLImportPropertyMapper( const_cast(this)->GetOwnImport().GetColumnStylesPropertySetMapper(), const_cast(GetImport()) ); + xMapper = m_xColumnImpPropMapper; + } + break; + case XmlStyleFamily::TABLE_CELL: + { + if ( !m_xCellImpPropMapper.is() ) + m_xCellImpPropMapper = new SvXMLImportPropertyMapper( const_cast(this)->GetOwnImport().GetCellStylesPropertySetMapper(), const_cast(GetImport()) ); + xMapper = m_xCellImpPropMapper; + } + break; + default: break; + } + } + + return xMapper; +} + +SvXMLStyleContext *OTableStylesContext::CreateStyleStyleChildContext( + XmlStyleFamily nFamily, sal_Int32 nElement, + const Reference< xml::sax::XFastAttributeList > & xAttrList ) +{ + SvXMLStyleContext *pStyle = SvXMLStylesContext::CreateStyleStyleChildContext( nFamily, nElement, + xAttrList ); + if (pStyle) + return pStyle; + + switch( nFamily ) + { + case XmlStyleFamily::TABLE_TABLE: + case XmlStyleFamily::TABLE_COLUMN: + case XmlStyleFamily::TABLE_CELL: + return new OTableStyleContext( GetOwnImport(), *this, nFamily ); + default: break; + } + + return nullptr; +} + +OUString OTableStylesContext::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_CELL: + sServiceName = XML_STYLE_FAMILY_TABLE_CELL_STYLES_NAME; + break; + default: break; + } + } + return sServiceName; +} + +sal_Int32 OTableStylesContext::GetIndex(const sal_Int16 nContextID) +{ + if ( nContextID == CTF_DB_NUMBERFORMAT ) + { + if (m_nNumberFormatIndex == -1) + m_nNumberFormatIndex = + GetImportPropertyMapper(XmlStyleFamily::TABLE_COLUMN)->getPropertySetMapper()->FindEntryIndex(nContextID); + return m_nNumberFormatIndex; + } + else if ( nContextID == CTF_DB_MASTERPAGENAME ) + { + if (m_nMasterPageNameIndex == -1) + m_nMasterPageNameIndex = + GetImportPropertyMapper(XmlStyleFamily::TABLE_TABLE)->getPropertySetMapper()->FindEntryIndex(nContextID); + return m_nMasterPageNameIndex; + } + else + return -1; +} + +ODBFilter& OTableStylesContext::GetOwnImport() +{ + return static_cast(GetImport()); +} + +} // dbaxml + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/filter/xml/xmlStyleImport.hxx b/dbaccess/source/filter/xml/xmlStyleImport.hxx new file mode 100644 index 000000000..d3fc001b0 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlStyleImport.hxx @@ -0,0 +1,98 @@ +/* -*- 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 . + */ + +#pragma once + +#include +#include +#include +#include + +namespace dbaxml +{ + class ODBFilter; + + class OTableStyleContext : public XMLPropStyleContext + { + OUString m_sDataStyleName; + OUString sPageStyle; + SvXMLStylesContext* pStyles; + sal_Int32 m_nNumberFormat; + + ODBFilter& GetOwnImport(); + + protected: + + virtual void SetAttribute( sal_Int32 nElement, + const OUString& rValue ) override; + + public: + + + OTableStyleContext( ODBFilter& rImport, + SvXMLStylesContext& rStyles, XmlStyleFamily nFamily ); + + virtual ~OTableStyleContext() 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 OTableStylesContext : public SvXMLStylesContext + { + sal_Int32 m_nNumberFormatIndex; + sal_Int32 m_nMasterPageNameIndex; + bool bAutoStyles : 1; + + mutable rtl::Reference < SvXMLImportPropertyMapper > m_xTableImpPropMapper; + mutable rtl::Reference < SvXMLImportPropertyMapper > m_xColumnImpPropMapper; + mutable rtl::Reference < SvXMLImportPropertyMapper > m_xCellImpPropMapper; + + ODBFilter& GetOwnImport(); + + 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; + + public: + + + OTableStylesContext( SvXMLImport& rImport, bool bAutoStyles ); + virtual ~OTableStylesContext() override; + + virtual void SAL_CALL endFastElement(sal_Int32 nElement) override; + + virtual rtl::Reference < SvXMLImportPropertyMapper > GetImportPropertyMapper( + XmlStyleFamily nFamily ) const override; + virtual OUString GetServiceName( XmlStyleFamily nFamily ) const override; + + sal_Int32 GetIndex(const sal_Int16 nContextID); + }; +} // dbaxml + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/filter/xml/xmlTable.cxx b/dbaccess/source/filter/xml/xmlTable.cxx new file mode 100644 index 000000000..403486ee5 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlTable.cxx @@ -0,0 +1,226 @@ +/* -*- 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 "xmlEnums.hxx" +#include "xmlStyleImport.hxx" +#include "xmlHierarchyCollection.hxx" +#include +#include +#include +#include +#include +#include + +namespace dbaxml +{ + using namespace ::com::sun::star; + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::sdbcx; + using namespace ::com::sun::star::xml::sax; + +OXMLTable::OXMLTable( ODBFilter& _rImport + ,const uno::Reference< XFastAttributeList > & _xAttrList + ,const uno::Reference< css::container::XNameAccess >& _xParentContainer + ,const OUString& _sServiceName + ) + :SvXMLImportContext( _rImport ) + ,m_xParentContainer(_xParentContainer) + ,m_bApplyFilter(false) + ,m_bApplyOrder(false) +{ + for (auto &aIter : sax_fastparser::castToFastAttributeList( _xAttrList )) + { + OUString sValue = aIter.toString(); + + switch( aIter.getToken() & TOKEN_MASK ) + { + case XML_NAME: + m_sName = sValue; + break; + case XML_CATALOG_NAME: + m_sCatalog = sValue; + break; + case XML_SCHEMA_NAME: + m_sSchema = sValue; + break; + case XML_STYLE_NAME: + m_sStyleName = sValue; + break; + case XML_APPLY_FILTER: + m_bApplyFilter = sValue == "true"; + break; + case XML_APPLY_ORDER: + m_bApplyOrder = sValue == "true"; + break; + default: + XMLOFF_WARN_UNKNOWN("dbaccess", aIter); + } + } + uno::Sequence aArguments(comphelper::InitAnyPropertySequence( + { + {"Name", uno::Any(m_sName)}, // set as folder + {"Parent", uno::Any(m_xParentContainer)} + })); + m_xTable.set( + GetOwnImport().GetComponentContext()->getServiceManager()->createInstanceWithArgumentsAndContext(_sServiceName,aArguments, GetOwnImport().GetComponentContext()), + UNO_QUERY); +} + +OXMLTable::~OXMLTable() +{ + +} + +css::uno::Reference< css::xml::sax::XFastContextHandler > OXMLTable::createFastChildContext( + sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) +{ + SvXMLImportContext *pContext = nullptr; + + switch( nElement & TOKEN_MASK ) + { + case XML_FILTER_STATEMENT: + { + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + OUString s1,s2,s3; + fillAttributes(xAttrList,m_sFilterStatement,s1,s2,s3); + } + break; + case XML_ORDER_STATEMENT: + { + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + OUString s1,s2,s3; + fillAttributes(xAttrList,m_sOrderStatement,s1,s2,s3); + } + break; + + case XML_COLUMNS: + { + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + uno::Reference< XColumnsSupplier > xColumnsSup(m_xTable,UNO_QUERY); + uno::Reference< XNameAccess > xColumns; + if ( xColumnsSup.is() ) + { + xColumns = xColumnsSup->getColumns(); + } + pContext = new OXMLHierarchyCollection( GetOwnImport(), xColumns,m_xTable); + } + break; + } + + return pContext; +} + +ODBFilter& OXMLTable::GetOwnImport() +{ + return static_cast(GetImport()); +} + +void OXMLTable::setProperties(uno::Reference< XPropertySet > & _xProp ) +{ + try + { + if ( _xProp.is() ) + { + _xProp->setPropertyValue(PROPERTY_APPLYFILTER,Any(m_bApplyFilter)); + _xProp->setPropertyValue(PROPERTY_FILTER,Any(m_sFilterStatement)); + + if ( _xProp->getPropertySetInfo()->hasPropertyByName(PROPERTY_APPLYORDER) ) + _xProp->setPropertyValue(PROPERTY_APPLYORDER,Any(m_bApplyOrder)); + _xProp->setPropertyValue(PROPERTY_ORDER,Any(m_sOrderStatement)); + } + } + catch(Exception&) + { + TOOLS_WARN_EXCEPTION( "dbaccess", "OXMLTable::EndElement -> exception caught"); + } +} + +void OXMLTable::endFastElement(sal_Int32 ) +{ + uno::Reference xNameContainer(m_xParentContainer,UNO_QUERY); + if ( !xNameContainer.is() ) + return; + + try + { + if ( m_xTable.is() ) + { + setProperties(m_xTable); + + if ( !m_sStyleName.isEmpty() ) + { + const SvXMLStylesContext* pAutoStyles = GetOwnImport().GetAutoStyles(); + if ( pAutoStyles ) + { + OTableStyleContext* pAutoStyle = const_cast(dynamic_cast< const OTableStyleContext* >(pAutoStyles->FindStyleChildContext(XmlStyleFamily::TABLE_TABLE,m_sStyleName))); + if ( pAutoStyle ) + { + pAutoStyle->FillPropertySet(m_xTable); + } + } + } + + xNameContainer->insertByName(m_sName,Any(m_xTable)); + } + } + catch(Exception&) + { + TOOLS_WARN_EXCEPTION( "dbaccess", "OXMLQuery::EndElement"); + } + +} + +void OXMLTable::fillAttributes(const uno::Reference< XFastAttributeList > & _xAttrList + ,OUString& _rsCommand + ,OUString& _rsTableName + ,OUString& _rsTableSchema + ,OUString& _rsTableCatalog + ) +{ + for (auto &aIter : sax_fastparser::castToFastAttributeList( _xAttrList )) + { + OUString sValue = aIter.toString(); + + switch( aIter.getToken() & TOKEN_MASK ) + { + case XML_COMMAND: + _rsCommand = sValue; + break; + case XML_CATALOG_NAME: + _rsTableCatalog = sValue; + break; + case XML_SCHEMA_NAME: + _rsTableSchema = sValue; + break; + case XML_QUERY_NAME: + _rsTableName = sValue; + break; + default: + XMLOFF_WARN_UNKNOWN("dbaccess", aIter); + } + } +} + +} // namespace dbaxml + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/filter/xml/xmlTable.hxx b/dbaccess/source/filter/xml/xmlTable.hxx new file mode 100644 index 000000000..cee19ef19 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlTable.hxx @@ -0,0 +1,67 @@ +/* -*- 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 . + */ +#pragma once + +#include +#include +#include + +namespace dbaxml +{ + class ODBFilter; + class OXMLTable : public SvXMLImportContext + { + protected: + css::uno::Reference< css::container::XNameAccess > m_xParentContainer; + css::uno::Reference< css::beans::XPropertySet > m_xTable; + OUString m_sFilterStatement; + OUString m_sOrderStatement; + OUString m_sName; + OUString m_sSchema; + OUString m_sCatalog; + OUString m_sStyleName; + bool m_bApplyFilter; + bool m_bApplyOrder; + + ODBFilter& GetOwnImport(); + + static void fillAttributes( const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList + ,OUString& _rsCommand + ,OUString& _rsTableName + ,OUString& _rsTableSchema + ,OUString& _rsTableCatalog + ); + + virtual void setProperties(css::uno::Reference< css::beans::XPropertySet > & _xProp); + public: + + OXMLTable( ODBFilter& rImport + ,const css::uno::Reference< css::xml::sax::XFastAttributeList > & _xAttrList + ,const css::uno::Reference< css::container::XNameAccess >& _xParentContainer + ,const OUString& _sServiceName + ); + 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 >& AttrList ) override; + virtual void SAL_CALL endFastElement(sal_Int32 nElement) override; + }; +} // namespace dbaxml + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/filter/xml/xmlTableFilterList.cxx b/dbaccess/source/filter/xml/xmlTableFilterList.cxx new file mode 100644 index 000000000..a6541684a --- /dev/null +++ b/dbaccess/source/filter/xml/xmlTableFilterList.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 "xmlTableFilterList.hxx" +#include "xmlTableFilterPattern.hxx" +#include "xmlEnums.hxx" +#include +#include +#include +#include +#include +#include +#include +#include "xmlfilter.hxx" + +namespace dbaxml +{ + using namespace ::xmloff::token; + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::beans; + using namespace ::com::sun::star::xml::sax; + +OXMLTableFilterList::OXMLTableFilterList( SvXMLImport& rImport) + :SvXMLImportContext( rImport ) +{ + +} + +OXMLTableFilterList::~OXMLTableFilterList() +{ +} + +css::uno::Reference< css::xml::sax::XFastContextHandler > OXMLTableFilterList::createFastChildContext( + sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& /*xAttrList*/ ) +{ + SvXMLImportContext *pContext = nullptr; + + if ( IsTokenInNamespace(nElement, XML_NAMESPACE_DB) || + IsTokenInNamespace(nElement, XML_NAMESPACE_DB_OASIS) ) + { + GetImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + switch (nElement & TOKEN_MASK) + { + case XML_TABLE_FILTER_PATTERN: + pContext = new OXMLTableFilterPattern( GetImport(), true,*this); + break; + case XML_TABLE_TYPE: + pContext = new OXMLTableFilterPattern( GetImport(), false,*this); + break; + case XML_TABLE_INCLUDE_FILTER: + pContext = new OXMLTableFilterList( GetImport() ); + break; + default: break; + } + } + + return pContext; +} + +ODBFilter& OXMLTableFilterList::GetOwnImport() +{ + return static_cast(GetImport()); +} + +void OXMLTableFilterList::endFastElement(sal_Int32 ) +{ + Reference xDataSource(GetOwnImport().getDataSource()); + if ( xDataSource.is() ) + { + if ( !m_aPatterns.empty() ) + xDataSource->setPropertyValue(PROPERTY_TABLEFILTER,Any(comphelper::containerToSequence(m_aPatterns))); + if ( !m_aTypes.empty() ) + xDataSource->setPropertyValue(PROPERTY_TABLETYPEFILTER,Any(comphelper::containerToSequence(m_aTypes))); + } +} + +} // namespace dbaxml + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/filter/xml/xmlTableFilterList.hxx b/dbaccess/source/filter/xml/xmlTableFilterList.hxx new file mode 100644 index 000000000..1988bdd29 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlTableFilterList.hxx @@ -0,0 +1,64 @@ +/* -*- 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 . + */ +#pragma once + +#include +#include + +namespace dbaxml +{ + class ODBFilter; + class OXMLTableFilterList : public SvXMLImportContext + { + std::vector< OUString> m_aPatterns; + std::vector< OUString> m_aTypes; + + ODBFilter& GetOwnImport(); + public: + + OXMLTableFilterList( SvXMLImport& rImport ); + + virtual ~OXMLTableFilterList() override; + + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( + sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override; + + virtual void SAL_CALL endFastElement(sal_Int32 nElement) override; + + /** pushes a new TableFilterPattern to the list of patterns + @param _sTableFilterPattern + The new filter pattern. + */ + void pushTableFilterPattern(const OUString& _sTableFilterPattern) + { + m_aPatterns.push_back(_sTableFilterPattern); + } + + /** pushes a new TableTypeFilter to the list of patterns + @param _sTypeFilter + The new type filter. + */ + void pushTableTypeFilter(const OUString& _sTypeFilter) + { + m_aTypes.push_back(_sTypeFilter); + } + }; +} // namespace dbaxml + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/filter/xml/xmlTableFilterPattern.cxx b/dbaccess/source/filter/xml/xmlTableFilterPattern.cxx new file mode 100644 index 000000000..0c4b2892d --- /dev/null +++ b/dbaccess/source/filter/xml/xmlTableFilterPattern.cxx @@ -0,0 +1,59 @@ +/* -*- 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 "xmlTableFilterPattern.hxx" +#include "xmlTableFilterList.hxx" + +namespace dbaxml +{ + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::xml::sax; + +OXMLTableFilterPattern::OXMLTableFilterPattern( SvXMLImport& rImport + ,bool _bNameFilter + ,OXMLTableFilterList& _rParent) + :SvXMLImportContext( rImport ) + ,m_rParent(_rParent) + ,m_bNameFilter(_bNameFilter) +{ + +} + +OXMLTableFilterPattern::~OXMLTableFilterPattern() +{ + +} + +void OXMLTableFilterPattern::characters( const OUString& rChars ) +{ + maBuffer.append(rChars); +} + +void OXMLTableFilterPattern::endFastElement( sal_Int32 ) +{ + OUString sChars = maBuffer.makeStringAndClear(); + if ( m_bNameFilter ) + m_rParent.pushTableFilterPattern(sChars); + else + m_rParent.pushTableTypeFilter(sChars); +} + +} // namespace dbaxml + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/filter/xml/xmlTableFilterPattern.hxx b/dbaccess/source/filter/xml/xmlTableFilterPattern.hxx new file mode 100644 index 000000000..8f0b64f37 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlTableFilterPattern.hxx @@ -0,0 +1,44 @@ +/* -*- 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 . + */ +#pragma once + +#include +#include + +namespace dbaxml +{ + class OXMLTableFilterList; + class OXMLTableFilterPattern : public SvXMLImportContext + { + OXMLTableFilterList& m_rParent; + bool m_bNameFilter; + OUStringBuffer maBuffer; + public: + OXMLTableFilterPattern( SvXMLImport& rImport + ,bool _bNameFilter + ,OXMLTableFilterList& _rParent); + + virtual ~OXMLTableFilterPattern() override; + + virtual void SAL_CALL endFastElement( sal_Int32 nElement ) override; + virtual void SAL_CALL characters( const OUString& rChars ) override; + }; +} // namespace dbaxml + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/filter/xml/xmlfilter.cxx b/dbaccess/source/filter/xml/xmlfilter.cxx new file mode 100644 index 000000000..d089359c8 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlfilter.cxx @@ -0,0 +1,617 @@ +/* -*- 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 +#include "xmlfilter.hxx" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "xmlDatabase.hxx" +#include "xmlEnums.hxx" +#include +#include +#include "xmlStyleImport.hxx" +#include +#include "xmlHelper.hxx" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace ::com::sun::star; + +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* +com_sun_star_comp_sdb_DBFilter_get_implementation( + css::uno::XComponentContext* context, css::uno::Sequence const&) +{ + return cppu::acquire(new ::dbaxml::ODBFilter(context)); +} + + +namespace dbaxml +{ + using namespace ::com::sun::star::util; + /// read a component (file + filter version) +static ErrCode ReadThroughComponent( + const uno::Reference& xInputStream, + const uno::Reference& xModelComponent, + const uno::Reference & rxContext, + ODBFilter& _rFilter ) +{ + OSL_ENSURE(xInputStream.is(), "input stream missing"); + OSL_ENSURE(xModelComponent.is(), "document missing"); + OSL_ENSURE(rxContext.is(), "factory missing"); + + // prepare ParserInputSource + InputSource aParserInput; + aParserInput.aInputStream = xInputStream; + + // connect model and filter + _rFilter.setTargetDocument( xModelComponent ); + + // finally, parser the stream + try + { + _rFilter.parseStream( aParserInput ); + } + catch (const SAXParseException&) + { +#if OSL_DEBUG_LEVEL > 0 + TOOLS_WARN_EXCEPTION("dbaccess", "SAX parse exception caught while importing"); +#endif + return ErrCode(1); + } + catch (const SAXException&) + { + return ErrCode(1); + } + catch (const packages::zip::ZipIOException&) + { + return ERRCODE_IO_BROKENPACKAGE; + } + catch (const Exception&) + { + DBG_UNHANDLED_EXCEPTION("dbaccess"); + } + + // 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, + ODBFilter& _rFilter) +{ + 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 + } + + uno::Reference< XInputStream > xInputStream = xDocStream->getInputStream(); + // read from the stream + return ReadThroughComponent( xInputStream + ,xModelComponent + ,rxContext + ,_rFilter ); +} + + +ODBFilter::ODBFilter( const uno::Reference< XComponentContext >& _rxContext ) + : SvXMLImport(_rxContext, getImplementationName_Static()) + , m_bNewFormat(false) +{ + + GetMM100UnitConverter().SetCoreMeasureUnit(util::MeasureUnit::MM_10TH); + GetMM100UnitConverter().SetXMLMeasureUnit(util::MeasureUnit::CM); + GetNamespaceMap().Add( "_db", + GetXMLToken(XML_N_DB), + XML_NAMESPACE_DB ); + + GetNamespaceMap().Add( "__db", + GetXMLToken(XML_N_DB_OASIS), + XML_NAMESPACE_DB ); +} + + +ODBFilter::~ODBFilter() noexcept +{ + +} + + +OUString ODBFilter::getImplementationName_Static() +{ + return "com.sun.star.comp.sdb.DBFilter"; +} + + +namespace { +class FocusWindowWaitGuard +{ +public: + FocusWindowWaitGuard() + { + SolarMutexGuard aGuard; + mpWindow.set(Application::GetFocusWindow()); + if (mpWindow) + mpWindow->EnterWait(); + } + ~FocusWindowWaitGuard() + { + if (mpWindow) + { + SolarMutexGuard aGuard; + mpWindow->LeaveWait(); + } + } +private: + VclPtr mpWindow; +}; +} + +sal_Bool SAL_CALL ODBFilter::filter( const Sequence< PropertyValue >& rDescriptor ) +{ + FocusWindowWaitGuard aWindowFocusGuard; + bool bRet = false; + + if ( GetModel().is() ) + bRet = implImport( rDescriptor ); + + return bRet; +} + + +bool ODBFilter::implImport( const Sequence< PropertyValue >& rDescriptor ) +{ + OUString sFileName; + ::comphelper::NamedValueCollection aMediaDescriptor( rDescriptor ); + + uno::Reference xStorage = GetSourceStorage(); + + bool bRet = true; + if (!xStorage.is()) + { + if (aMediaDescriptor.has("URL")) + sFileName = aMediaDescriptor.getOrDefault("URL", OUString()); + if (sFileName.isEmpty() && aMediaDescriptor.has("FileName")) + sFileName = aMediaDescriptor.getOrDefault("FileName", sFileName); + + OSL_ENSURE(!sFileName.isEmpty(), "ODBFilter::implImport: no URL given!"); + bRet = !sFileName.isEmpty(); + } + + if ( bRet ) + { + + tools::SvRef pMedium; + if (!xStorage.is()) + { + OUString sStreamRelPath; + if (sFileName.startsWithIgnoreAsciiCase("vnd.sun.star.pkg:")) + { + // In this case the authority contains the real path, and the path is the embedded stream name. + auto const uri = css::uri::UriReferenceFactory::create(GetComponentContext()) + ->parse(sFileName); + if (uri.is() && uri->isAbsolute() + && uri->hasAuthority() && !uri->hasQuery() && !uri->hasFragment()) + { + auto const auth = uri->getAuthority(); + auto const decAuth = rtl::Uri::decode( + auth, rtl_UriDecodeStrict, RTL_TEXTENCODING_UTF8); + auto path = uri->getPath(); + if (!path.isEmpty()) { + assert(path[0] == '/'); + path = path.copy(1); + } + auto const decPath = rtl::Uri::decode( + path, rtl_UriDecodeStrict, RTL_TEXTENCODING_UTF8); + //TODO: really decode path? + if (auth.isEmpty() == decAuth.isEmpty() && path.isEmpty() == decPath.isEmpty()) + { + // Decoding of auth and path to UTF-8 succeeded: + sFileName = decAuth; + sStreamRelPath = decPath; + } else { + SAL_WARN( + "dbaccess", + "<" << sFileName << "> cannot be parse as vnd.sun.star.pkg URL"); + } + } else { + SAL_WARN( + "dbaccess", + "<" << sFileName << "> cannot be parse as vnd.sun.star.pkg URL"); + } + } + + pMedium = new SfxMedium(sFileName, (StreamMode::READ | StreamMode::NOCREATE)); + try + { + xStorage.set(pMedium->GetStorage(false), UNO_SET_THROW); + + if (!sStreamRelPath.isEmpty()) + xStorage = xStorage->openStorageElement(sStreamRelPath, embed::ElementModes::READ); + } + catch (const RuntimeException&) + { + throw; + } + catch (const Exception&) + { + Any aError = ::cppu::getCaughtException(); + throw lang::WrappedTargetRuntimeException(OUString(), *this, aError); + } + } + + uno::Reference xOfficeDoc(GetModel(),UNO_QUERY_THROW); + m_xDataSource.set(xOfficeDoc->getDataSource(),UNO_QUERY_THROW); + uno::Reference< XNumberFormatsSupplier > xNum(m_xDataSource->getPropertyValue(PROPERTY_NUMBERFORMATSSUPPLIER),UNO_QUERY); + SetNumberFormatsSupplier(xNum); + + uno::Reference xModel(GetModel()); + ErrCode nRet = ReadThroughComponent( xStorage + ,xModel + ,"settings.xml" + ,GetComponentContext() + ,*this + ); + + if ( nRet == ERRCODE_NONE ) + nRet = ReadThroughComponent( xStorage + ,xModel + ,"content.xml" + ,GetComponentContext() + ,*this + ); + + bRet = nRet == ERRCODE_NONE; + + if ( bRet ) + { + uno::Reference< XModifiable > xModi(GetModel(),UNO_QUERY); + if ( xModi.is() ) + xModi->setModified(false); + } + else + { + if ( nRet == ERRCODE_IO_BROKENPACKAGE ) + ;// 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 DBXMLDocumentSettingsContext : public SvXMLImportContext +{ +public: + DBXMLDocumentSettingsContext(SvXMLImport & rImport) + : SvXMLImportContext(rImport) + { + } + + virtual uno::Reference< xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( + sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ ) override + { + if (nElement == XML_ELEMENT(OFFICE, XML_SETTINGS)) + { + return new XMLDocumentSettingsContext(GetImport()); + } + return nullptr; + } +}; + +class DBXMLDocumentStylesContext : public SvXMLImportContext +{ +public: + DBXMLDocumentStylesContext(SvXMLImport & rImport) + : SvXMLImportContext(rImport) + { + } + + virtual uno::Reference< xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( + sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ ) override + { + ODBFilter & rImport(static_cast(GetImport())); + switch (nElement) + { + case XML_ELEMENT(OFFICE, XML_STYLES): + case XML_ELEMENT(OOO, XML_STYLES): + rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + return rImport.CreateStylesContext(false); + case XML_ELEMENT(OFFICE, XML_AUTOMATIC_STYLES): + case XML_ELEMENT(OOO, XML_AUTOMATIC_STYLES): + rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + return rImport.CreateStylesContext(true); + } + return nullptr; + } +}; + +class DBXMLDocumentBodyContext : public SvXMLImportContext +{ +public: + DBXMLDocumentBodyContext(SvXMLImport & rImport) + : SvXMLImportContext(rImport) + { + } + + virtual uno::Reference< xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( + sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ ) override + { + ODBFilter & rImport(static_cast(GetImport())); + switch (nElement) + { + case XML_ELEMENT(OFFICE, XML_DATABASE): + case XML_ELEMENT(OOO, XML_DATABASE): + rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + return new OXMLDatabase(rImport); + default: break; + } + return nullptr; + } +}; + +class DBXMLDocumentContentContext : public SvXMLImportContext +{ +public: + DBXMLDocumentContentContext(SvXMLImport & rImport) + : SvXMLImportContext(rImport) + { + } + + virtual uno::Reference< xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( + sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ ) override + { + ODBFilter & rImport(static_cast(GetImport())); + switch (nElement) + { + case XML_ELEMENT(OFFICE, XML_BODY): + case XML_ELEMENT(OOO, XML_BODY): + return new DBXMLDocumentBodyContext(rImport); + case XML_ELEMENT(OFFICE, XML_SCRIPTS): + return new XMLScriptContext(GetImport(), rImport.GetModel()); + case XML_ELEMENT(OFFICE, XML_AUTOMATIC_STYLES): + case XML_ELEMENT(OOO, XML_AUTOMATIC_STYLES): + rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + return rImport.CreateStylesContext(true); + default: break; + } + return nullptr; + } +}; + +} + +SvXMLImportContext* ODBFilter::CreateFastContext(sal_Int32 nElement, + const ::css::uno::Reference< ::css::xml::sax::XFastAttributeList >& /*xAttrList*/ ) +{ + SvXMLImportContext *pContext = nullptr; + + switch( nElement ) + { + case XML_ELEMENT(OFFICE, XML_DOCUMENT_SETTINGS): + case XML_ELEMENT(OOO, XML_DOCUMENT_SETTINGS): + GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + pContext = new DBXMLDocumentSettingsContext(*this); + break; + case XML_ELEMENT(OFFICE, XML_DOCUMENT_STYLES): + case XML_ELEMENT(OOO, XML_DOCUMENT_STYLES): + pContext = new DBXMLDocumentStylesContext(*this); + break; + case XML_ELEMENT(OFFICE, XML_DOCUMENT_CONTENT): + case XML_ELEMENT(OOO, XML_DOCUMENT_CONTENT): + pContext = new DBXMLDocumentContentContext(*this); + break; + } + + return pContext; +} + + +void ODBFilter::SetViewSettings(const Sequence& aViewProps) +{ + const PropertyValue *pIter = aViewProps.getConstArray(); + const PropertyValue *pEnd = pIter + aViewProps.getLength(); + for (; pIter != pEnd; ++pIter) + { + if ( pIter->Name == "Queries" ) + { + fillPropertyMap(pIter->Value,m_aQuerySettings); + } + else if ( pIter->Name == "Tables" ) + { + fillPropertyMap(pIter->Value,m_aTablesSettings); + } + } +} + + +void ODBFilter::SetConfigurationSettings(const Sequence& aConfigProps) +{ + const PropertyValue *pIter = aConfigProps.getConstArray(); + const PropertyValue *pEnd = pIter + aConfigProps.getLength(); + for (; pIter != pEnd; ++pIter) + { + if ( pIter->Name == "layout-settings" ) + { + Sequence aWindows; + pIter->Value >>= aWindows; + uno::Reference xProp(getDataSource()); + if ( xProp.is() ) + xProp->setPropertyValue(PROPERTY_LAYOUTINFORMATION,Any(aWindows)); + } + } +} + + +void ODBFilter::fillPropertyMap(const Any& _rValue,TPropertyNameMap& _rMap) +{ + Sequence aWindows; + _rValue >>= aWindows; + const PropertyValue *pIter = aWindows.getConstArray(); + const PropertyValue *pEnd = pIter + aWindows.getLength(); + for (; pIter != pEnd; ++pIter) + { + Sequence aValue; + pIter->Value >>= aValue; + _rMap.emplace( pIter->Name,aValue ); + } + +} + +SvXMLImportContext* ODBFilter::CreateStylesContext( bool bIsAutoStyle ) +{ + SvXMLImportContext *pContext = new OTableStylesContext(*this, bIsAutoStyle); + if (bIsAutoStyle) + SetAutoStyles(static_cast(pContext)); + else + SetStyles(static_cast(pContext)); + + return pContext; +} + + +rtl::Reference < XMLPropertySetMapper > const & ODBFilter::GetTableStylesPropertySetMapper() const +{ + if ( !m_xTableStylesPropertySetMapper.is() ) + { + m_xTableStylesPropertySetMapper = OXMLHelper::GetTableStylesPropertySetMapper( false); + } + return m_xTableStylesPropertySetMapper; +} + + +rtl::Reference < XMLPropertySetMapper > const & ODBFilter::GetColumnStylesPropertySetMapper() const +{ + if ( !m_xColumnStylesPropertySetMapper.is() ) + { + m_xColumnStylesPropertySetMapper = OXMLHelper::GetColumnStylesPropertySetMapper( false); + } + return m_xColumnStylesPropertySetMapper; +} + + +rtl::Reference < XMLPropertySetMapper > const & ODBFilter::GetCellStylesPropertySetMapper() const +{ + if ( !m_xCellStylesPropertySetMapper.is() ) + { + m_xCellStylesPropertySetMapper = OXMLHelper::GetCellStylesPropertySetMapper( false); + } + return m_xCellStylesPropertySetMapper; +} + + +void ODBFilter::setPropertyInfo() +{ + Reference xDataSource(getDataSource()); + if ( !xDataSource.is() ) + return; + + ::connectivity::DriversConfig aDriverConfig(GetComponentContext()); + const OUString sURL = ::comphelper::getString(xDataSource->getPropertyValue(PROPERTY_URL)); + ::comphelper::NamedValueCollection aDataSourceSettings = aDriverConfig.getProperties( sURL ); + + Sequence aInfo; + if ( !m_aInfoSequence.empty() ) + aInfo = comphelper::containerToSequence(m_aInfoSequence); + aDataSourceSettings.merge( ::comphelper::NamedValueCollection( aInfo ), true ); + + aDataSourceSettings >>= aInfo; + if ( aInfo.hasElements() ) + { + try + { + xDataSource->setPropertyValue(PROPERTY_INFO,Any(aInfo)); + } + catch (const Exception&) + { + DBG_UNHANDLED_EXCEPTION("dbaccess"); + } + } +} + +} // namespace dbaxml + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/filter/xml/xmlfilter.hxx b/dbaccess/source/filter/xml/xmlfilter.hxx new file mode 100644 index 000000000..ec776cd75 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlfilter.hxx @@ -0,0 +1,121 @@ +/* -*- 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 . + */ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + + +namespace dbaxml +{ + +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::xml::sax; + + +class ODBFilter : public SvXMLImport +{ +public: + typedef std::map< OUString, Sequence > TPropertyNameMap; +private: + TPropertyNameMap m_aQuerySettings; + TPropertyNameMap m_aTablesSettings; + std::vector< css::beans::PropertyValue> m_aInfoSequence; + + mutable rtl::Reference < XMLPropertySetMapper > m_xTableStylesPropertySetMapper; + mutable rtl::Reference < XMLPropertySetMapper > m_xColumnStylesPropertySetMapper; + mutable rtl::Reference < XMLPropertySetMapper > m_xCellStylesPropertySetMapper; + Reference m_xDataSource; + bool m_bNewFormat; + + /// @throws RuntimeException + bool implImport( const Sequence< PropertyValue >& rDescriptor ); + + /** fills the map with the Properties + @param _rValue + The Any where the sequence resists in. + @param _rMap + The map to fill. + */ + static void fillPropertyMap(const Any& _rValue,TPropertyNameMap& _rMap); + +public: + SvXMLImportContext* CreateStylesContext( bool bIsAutoStyle ); + +protected: + // SvXMLImport + virtual SvXMLImportContext *CreateFastContext(sal_Int32 Element, + const ::css::uno::Reference< ::css::xml::sax::XFastAttributeList >& xAttrList ) override; + + virtual ~ODBFilter() noexcept override; +public: + + explicit ODBFilter( const Reference< XComponentContext >& _rxContext ); + + // XFilter + virtual sal_Bool SAL_CALL filter( const Sequence< PropertyValue >& rDescriptor ) override; + + /// @throws css::uno::RuntimeException + static OUString getImplementationName_Static(); + + // helper class + virtual void SetViewSettings(const css::uno::Sequence& aViewProps) override; + virtual void SetConfigurationSettings(const css::uno::Sequence& aConfigProps) override; + + const Reference& getDataSource() const { return m_xDataSource; } + + const TPropertyNameMap& getQuerySettings() const { return m_aQuerySettings;} + + rtl::Reference < XMLPropertySetMapper > const & GetTableStylesPropertySetMapper() const; + rtl::Reference < XMLPropertySetMapper > const & GetColumnStylesPropertySetMapper() const; + rtl::Reference < XMLPropertySetMapper > const & GetCellStylesPropertySetMapper() const; + + /** add an Info to the sequence which will be appended to the data source + @param _rInfo The property to append. + */ + void addInfo(const css::beans::PropertyValue& _rInfo) + { + m_aInfoSequence.push_back(_rInfo); + } + + void setPropertyInfo(); + + bool isNewFormat() const { return m_bNewFormat; } + void setNewFormat(bool _bNewFormat) { m_bNewFormat = _bNewFormat; } +}; + +} // namespace dbaxml + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3