diff options
Diffstat (limited to 'dbaccess/source/filter/xml')
53 files changed, 8947 insertions, 0 deletions
diff --git a/dbaccess/source/filter/xml/dbaxml.component b/dbaccess/source/filter/xml/dbaxml.component new file mode 100644 index 000000000000..23b3a5c1a776 --- /dev/null +++ b/dbaccess/source/filter/xml/dbaxml.component @@ -0,0 +1,49 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!--********************************************************************** +* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* Copyright 2000, 2010 Oracle and/or its affiliates. +* +* OpenOffice.org - a multi-platform office productivity suite +* +* This file is part of OpenOffice.org. +* +* OpenOffice.org is free software: you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License version 3 +* only, as published by the Free Software Foundation. +* +* OpenOffice.org is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License version 3 for more details +* (a copy is included in the LICENSE file that accompanied this code). +* +* You should have received a copy of the GNU Lesser General Public License +* version 3 along with OpenOffice.org. If not, see +* <http://www.openoffice.org/license.html> +* for a copy of the LGPLv3 License. +* +**********************************************************************--> + +<component loader="com.sun.star.loader.SharedLibrary" + xmlns="http://openoffice.org/2010/uno-components"> + <implementation name="com.sun.star.comp.sdb.DBExportFilter"> + <service name="com.sun.star.document.ExportFilter"/> + </implementation> + <implementation name="com.sun.star.comp.sdb.DBFilter"> + <service name="com.sun.star.document.ImportFilter"/> + </implementation> + <implementation name="com.sun.star.comp.sdb.XMLFullExporter"> + <service name="com.sun.star.document.ExportFilter"/> + </implementation> + <implementation name="com.sun.star.comp.sdb.XMLSettingsExporter"> + <service name="com.sun.star.document.ExportFilter"/> + </implementation> + <implementation name="org.openoffice.comp.dbflt.DBContentLoader2"> + <service name="com.sun.star.frame.FrameLoader"/> + </implementation> + <implementation name="org.openoffice.comp.dbflt.DBTypeDetection"> + <service name="com.sun.star.document.ExtendedTypeDetection"/> + </implementation> +</component> diff --git a/dbaccess/source/filter/xml/dbloader2.cxx b/dbaccess/source/filter/xml/dbloader2.cxx new file mode 100644 index 000000000000..11f0b667abd8 --- /dev/null +++ b/dbaccess/source/filter/xml/dbloader2.cxx @@ -0,0 +1,660 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_dbaccess.hxx" + +#include "flt_reghelper.hxx" +#include "xmlstrings.hrc" + +/** === begin UNO includes === **/ +#include <com/sun/star/beans/NamedValue.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/document/XEventListener.hpp> +#include <com/sun/star/document/XExtendedFilterDetection.hpp> +#include <com/sun/star/document/XFilter.hpp> +#include <com/sun/star/embed/ElementModes.hpp> +#include <com/sun/star/embed/XStorage.hpp> +#include <com/sun/star/frame/XController.hpp> +#include <com/sun/star/frame/XFrame.hpp> +#include <com/sun/star/frame/XFrameLoader.hpp> +#include <com/sun/star/frame/XFramesSupplier.hpp> +#include <com/sun/star/frame/XLoadEventListener.hpp> +#include <com/sun/star/frame/XModel2.hpp> +#include <com/sun/star/io/XInputStream.hpp> +#include <com/sun/star/lang/XInitialization.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/lang/XSingleServiceFactory.hpp> +#include <com/sun/star/registry/XRegistryKey.hpp> +#include <com/sun/star/sdb/XDocumentDataSource.hpp> +#include <com/sun/star/task/XJobExecutor.hpp> +#include <com/sun/star/ui/dialogs/XExecutableDialog.hpp> +#include <com/sun/star/util/XURLTransformer.hpp> +#include <com/sun/star/view/XSelectionSupplier.hpp> +#include <com/sun/star/sdb/application/DatabaseObjectContainer.hpp> +#include <com/sun/star/sdb/application/NamedDatabaseObject.hpp> +#include <com/sun/star/frame/XLoadable.hpp> +/** === end UNO includes === **/ + +#include <comphelper/componentcontext.hxx> +#include <comphelper/documentconstants.hxx> +#include <comphelper/namedvaluecollection.hxx> +#include <comphelper/processfactory.hxx> +#include <comphelper/sequenceashashmap.hxx> +#include <comphelper/stl_types.hxx> +#include <comphelper/storagehelper.hxx> +#include <comphelper/types.hxx> +#include <cppuhelper/implbase2.hxx> +#include <osl/file.hxx> +#include <sfx2/docfile.hxx> +#include <unotools/moduleoptions.hxx> +#include <toolkit/awt/vclxwindow.hxx> +#include <toolkit/helper/vclunohelper.hxx> +#include <tools/diagnose_ex.h> +#include <tools/urlobj.hxx> +#include <ucbhelper/commandenvironment.hxx> +#include <ucbhelper/content.hxx> +#include <ucbhelper/contentbroker.hxx> +#include <vcl/msgbox.hxx> +#include <vcl/svapp.hxx> + +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::registry; +using namespace ::com::sun::star::sdb; +using namespace ::com::sun::star::embed; +namespace css = ::com::sun::star; +using namespace ::com::sun::star::ui::dialogs; +using ::com::sun::star::awt::XWindow; +using ::com::sun::star::sdb::application::NamedDatabaseObject; + +// ------------------------------------------------------------------------- +namespace dbaxml +{ + +class DBTypeDetection : public ::cppu::WeakImplHelper2< XExtendedFilterDetection, XServiceInfo> +{ + ::comphelper::ComponentContext m_aContext; + +public: + DBTypeDetection(const Reference< XMultiServiceFactory >&); + + // XServiceInfo + ::rtl::OUString SAL_CALL getImplementationName() throw( ); + sal_Bool SAL_CALL supportsService(const ::rtl::OUString& ServiceName) throw( ); + Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(void) throw( ); + + // static methods + static ::rtl::OUString getImplementationName_Static() throw( ) + { + return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("org.openoffice.comp.dbflt.DBTypeDetection")); + } + static Sequence< ::rtl::OUString> getSupportedServiceNames_Static(void) throw( ); + static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > + SAL_CALL Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&); + + virtual ::rtl::OUString SAL_CALL detect( ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& Descriptor ) throw (::com::sun::star::uno::RuntimeException); +}; +// ------------------------------------------------------------------------- +DBTypeDetection::DBTypeDetection(const Reference< XMultiServiceFactory >& _rxFactory) + :m_aContext( _rxFactory ) +{ +} +// ------------------------------------------------------------------------- +::rtl::OUString SAL_CALL DBTypeDetection::detect( ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& Descriptor ) throw (::com::sun::star::uno::RuntimeException) +{ + try + { + ::comphelper::NamedValueCollection aMedia( Descriptor ); + sal_Bool bStreamFromDescr = sal_False; + ::rtl::OUString sURL = aMedia.getOrDefault( "URL", ::rtl::OUString() ); + + Reference< XInputStream > xInStream( aMedia.getOrDefault( "InputStream", Reference< XInputStream >() ) ); + Reference< XPropertySet > xStorageProperties; + if ( xInStream.is() ) + { + bStreamFromDescr = sal_True; + xStorageProperties.set( ::comphelper::OStorageHelper::GetStorageFromInputStream( + xInStream, m_aContext.getLegacyServiceFactory() ), UNO_QUERY ); + } + else + { + ::rtl::OUString sSalvagedURL( aMedia.getOrDefault( "SalvagedFile", ::rtl::OUString() ) ); + + ::rtl::OUString sFileLocation( sSalvagedURL.getLength() ? sSalvagedURL : sURL ); + if ( sFileLocation.getLength() ) + { + xStorageProperties.set( ::comphelper::OStorageHelper::GetStorageFromURL( + sFileLocation, ElementModes::READ, m_aContext.getLegacyServiceFactory() ), UNO_QUERY ); + } + } + + if ( xStorageProperties.is() ) + { + ::rtl::OUString sMediaType; + xStorageProperties->getPropertyValue( INFO_MEDIATYPE ) >>= sMediaType; + if ( sMediaType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(MIMETYPE_OASIS_OPENDOCUMENT_DATABASE_ASCII)) || sMediaType.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(MIMETYPE_VND_SUN_XML_BASE_ASCII)) ) + { + if ( bStreamFromDescr && sURL.compareTo( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:stream" ) ), 14 ) != COMPARE_EQUAL ) + { + // 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( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "InputStream" ) ) ); + aMedia.remove( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Stream" ) ) ); + aMedia >>= Descriptor; + try + { + ::comphelper::disposeComponent(xStorageProperties); + if ( xInStream.is() ) + xInStream->closeInput(); + } + catch( Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + } + + return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("StarBase")); + } + ::comphelper::disposeComponent(xStorageProperties); + } + } catch(Exception&){} + return ::rtl::OUString(); +} +// ------------------------------------------------------------------------- +Reference< XInterface > SAL_CALL DBTypeDetection::Create( const Reference< XMultiServiceFactory > & rSMgr ) +{ + return *(new DBTypeDetection(rSMgr)); +} +// ------------------------------------------------------------------------- +// XServiceInfo +::rtl::OUString SAL_CALL DBTypeDetection::getImplementationName() throw( ) +{ + return getImplementationName_Static(); +} +// ------------------------------------------------------------------------- + +// XServiceInfo +sal_Bool SAL_CALL DBTypeDetection::supportsService(const ::rtl::OUString& ServiceName) throw( ) +{ + Sequence< ::rtl::OUString > aSNL = getSupportedServiceNames(); + const ::rtl::OUString * pBegin = aSNL.getConstArray(); + const ::rtl::OUString * pEnd = pBegin + aSNL.getLength(); + for( ; pBegin != pEnd; ++pBegin) + if( *pBegin == ServiceName ) + return sal_True; + return sal_False; +} +// ------------------------------------------------------------------------- +// XServiceInfo +Sequence< ::rtl::OUString > SAL_CALL DBTypeDetection::getSupportedServiceNames(void) throw( ) +{ + return getSupportedServiceNames_Static(); +} +// ------------------------------------------------------------------------- +// ORegistryServiceManager_Static +Sequence< ::rtl::OUString > DBTypeDetection::getSupportedServiceNames_Static(void) throw( ) +{ + Sequence< ::rtl::OUString > aSNS( 1 ); + aSNS.getArray()[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.document.ExtendedTypeDetection")); + return aSNS; +} +// ------------------------------------------------------------------------- +extern "C" void SAL_CALL createRegistryInfo_DBTypeDetection() +{ + static ::dbaxml::OMultiInstanceAutoRegistration< ::dbaxml::DBTypeDetection > aAutoRegistration; +} +// ----------------------------------------------------------------------------- + +class DBContentLoader : public ::cppu::WeakImplHelper2< XFrameLoader, XServiceInfo> +{ +private: + ::comphelper::ComponentContext m_aContext; + Reference< XFrameLoader > m_xMySelf; + ::rtl::OUString m_sCurrentURL; + sal_uLong m_nStartWizard; + + DECL_LINK( OnStartTableWizard, void* ); +public: + DBContentLoader(const Reference< XMultiServiceFactory >&); + ~DBContentLoader(); + + // XServiceInfo + ::rtl::OUString SAL_CALL getImplementationName() throw( ); + sal_Bool SAL_CALL supportsService(const ::rtl::OUString& ServiceName) throw( ); + Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(void) throw( ); + + // static methods + static ::rtl::OUString getImplementationName_Static() throw( ) + { + return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("org.openoffice.comp.dbflt.DBContentLoader2")); + } + static Sequence< ::rtl::OUString> getSupportedServiceNames_Static(void) throw( ); + static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > + SAL_CALL Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&); + + // XLoader + virtual void SAL_CALL load( const Reference< XFrame > & _rFrame, const ::rtl::OUString& _rURL, + const Sequence< PropertyValue >& _rArgs, + const Reference< XLoadEventListener > & _rListener) throw(::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL cancel(void) throw(); + +private: + sal_Bool impl_executeNewDatabaseWizard( Reference< XModel >& _rxModel, sal_Bool& _bShouldStartTableWizard ); +}; +DBG_NAME(DBContentLoader) + +DBContentLoader::DBContentLoader(const Reference< XMultiServiceFactory >& _rxFactory) + :m_aContext( _rxFactory ) + ,m_nStartWizard(0) +{ + DBG_CTOR(DBContentLoader,NULL); + +} +// ------------------------------------------------------------------------- + +DBContentLoader::~DBContentLoader() +{ + + DBG_DTOR(DBContentLoader,NULL); +} +// ------------------------------------------------------------------------- + +// ------------------------------------------------------------------------- +Reference< XInterface > SAL_CALL DBContentLoader::Create( const Reference< XMultiServiceFactory > & rSMgr ) +{ + return *(new DBContentLoader(rSMgr)); +} +// ------------------------------------------------------------------------- +// XServiceInfo +::rtl::OUString SAL_CALL DBContentLoader::getImplementationName() throw( ) +{ + return getImplementationName_Static(); +} +// ------------------------------------------------------------------------- + +// XServiceInfo +sal_Bool SAL_CALL DBContentLoader::supportsService(const ::rtl::OUString& ServiceName) throw( ) +{ + Sequence< ::rtl::OUString > aSNL = getSupportedServiceNames(); + const ::rtl::OUString * pBegin = aSNL.getConstArray(); + const ::rtl::OUString * pEnd = pBegin + aSNL.getLength(); + for( ; pBegin != pEnd; ++pBegin) + if( *pBegin == ServiceName ) + return sal_True; + return sal_False; +} +// ------------------------------------------------------------------------- +// XServiceInfo +Sequence< ::rtl::OUString > SAL_CALL DBContentLoader::getSupportedServiceNames(void) throw( ) +{ + return getSupportedServiceNames_Static(); +} +// ------------------------------------------------------------------------- +// ORegistryServiceManager_Static +Sequence< ::rtl::OUString > DBContentLoader::getSupportedServiceNames_Static(void) throw( ) +{ + Sequence< ::rtl::OUString > aSNS( 1 ); + aSNS.getArray()[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.FrameLoader")); + return aSNS; +} + +// ----------------------------------------------------------------------- +namespace +{ + // ................................................................... + sal_Bool lcl_urlAllowsInteraction( const ::comphelper::ComponentContext& _rContext, const ::rtl::OUString& _rURL ) + { + bool bDoesAllow = sal_False; + try + { + Reference< XURLTransformer > xTransformer; + if ( _rContext.createComponent( "com.sun.star.util.URLTransformer", xTransformer ) ) + { + URL aURL; + aURL.Complete = _rURL; + xTransformer->parseStrict( aURL ); + bDoesAllow = aURL.Arguments.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Interactive" ) ); + } + } + catch( const Exception& ) + { + OSL_FAIL( "lcl_urlAllowsInteraction: caught an exception while analyzing the URL!" ); + } + return bDoesAllow; + } + + // ................................................................... + Reference< XWindow > lcl_getTopMostWindow( const ::comphelper::ComponentContext& _rContext ) + { + Reference< XWindow > xWindow; + // get the top most window + Reference < XFramesSupplier > xDesktop; + if ( _rContext.createComponent( "com.sun.star.frame.Desktop", xDesktop ) ) + { + Reference < XFrame > xActiveFrame = xDesktop->getActiveFrame(); + if ( xActiveFrame.is() ) + { + xWindow = xActiveFrame->getContainerWindow(); + Reference<XFrame> xFrame = xActiveFrame; + while ( xFrame.is() && !xFrame->isTop() ) + xFrame.set(xFrame->getCreator(),UNO_QUERY); + + if ( xFrame.is() ) + xWindow = xFrame->getContainerWindow(); + } + } + return xWindow; + } +} + +// ----------------------------------------------------------------------- +sal_Bool DBContentLoader::impl_executeNewDatabaseWizard( Reference< XModel >& _rxModel, sal_Bool& _bShouldStartTableWizard ) +{ + Sequence< Any > aWizardArgs(2); + aWizardArgs[0] <<= PropertyValue( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ParentWindow")), + 0, + makeAny( lcl_getTopMostWindow( m_aContext ) ), + PropertyState_DIRECT_VALUE); + + aWizardArgs[1] <<= PropertyValue( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("InitialSelection")), + 0, + makeAny( _rxModel ), + PropertyState_DIRECT_VALUE); + + // create the dialog + Reference< XExecutableDialog > xAdminDialog; + OSL_VERIFY( m_aContext.createComponentWithArguments( "com.sun.star.sdb.DatabaseWizardDialog", aWizardArgs, xAdminDialog ) ); + + // execute it + if ( !xAdminDialog.is() || ( RET_OK != xAdminDialog->execute() ) ) + return sal_False; + + Reference<XPropertySet> xProp(xAdminDialog,UNO_QUERY); + sal_Bool bSuccess = sal_False; + xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("OpenDatabase"))) >>= bSuccess; + xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("StartTableWizard"))) >>= _bShouldStartTableWizard; + return bSuccess; +} + +// ----------------------------------------------------------------------- +void SAL_CALL DBContentLoader::load(const Reference< XFrame > & rFrame, const ::rtl::OUString& _rURL, + const Sequence< PropertyValue >& rArgs, + const Reference< XLoadEventListener > & rListener) throw(::com::sun::star::uno::RuntimeException) +{ + // first check if preview is true, if so return with out creating a controller. Preview is not supported + ::comphelper::NamedValueCollection aMediaDesc( rArgs ); + sal_Bool bPreview = aMediaDesc.getOrDefault( "Preview", sal_False ); + if ( bPreview ) + { + if (rListener.is()) + rListener->loadCancelled(this); + return; + } + + Reference< XModel > xModel = aMediaDesc.getOrDefault( "Model", Reference< XModel >() ); + ::rtl::OUString sSalvagedURL = aMediaDesc.getOrDefault( "SalvagedFile", _rURL ); + + sal_Bool bCreateNew = sal_False; // does the URL denote the private:factory URL? + sal_Bool bStartTableWizard = sal_False; // start the table wizard after everything was loaded successfully? + + sal_Bool bSuccess = sal_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< XInteractionHandler > xHandler; + if ( m_aContext.createComponent( "com.sun.star.task.InteractionHandler", xHandler ) ) + 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 + ::rtl::OUString sViewName = aMediaDesc.getOrDefault( "ViewName", ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Default" ) ) ); + aMediaDesc.remove( "ViewName" ); + + sal_Int32 nInitialSelection = -1; + if ( !xModel.is() ) + { + Reference< XSingleServiceFactory > xDatabaseContext; + if ( !m_aContext.createComponent( (::rtl::OUString)SERVICE_SDB_DATABASECONTEXT, xDatabaseContext ) ) + throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "css.sdb.DatabaseContext not available" ) ), NULL ); + + ::rtl::OUString sFactoryName = SvtModuleOptions().GetFactoryEmptyDocumentURL(SvtModuleOptions::E_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( (::rtl::OUString)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 = ::com::sun::star::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 an URL. + // If it already *does* have an 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().getLength() == 0 ); + 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(); + bSuccess = sal_False; + } + } + + if ( bSuccess ) + { + try + { + Reference< XModel2 > xModel2( xModel, UNO_QUERY_THROW ); + Reference< XController2 > xController( xModel2->createViewController( sViewName, Sequence< PropertyValue >(), rFrame ), UNO_QUERY_THROW ); + + xController->attachModel( xModel ); + xModel->connectController( xController.get() ); + rFrame->setComponent( xController->getComponentWindow(), xController.get() ); + xController->attachFrame( rFrame ); + xModel->setCurrentController( xController.get() ); + + bSuccess = sal_True; + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + bSuccess = sal_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( makeAny( 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(void) throw() +{ +} +// ----------------------------------------------------------------------------- +IMPL_LINK( DBContentLoader, OnStartTableWizard, void*, /*NOTINTERESTEDIN*/ ) +{ + m_nStartWizard = 0; + try + { + Sequence< Any > aWizArgs(1); + PropertyValue aValue; + aValue.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DatabaseLocation")); + aValue.Value <<= m_sCurrentURL; + aWizArgs[0] <<= aValue; + + SolarMutexGuard aGuard; + Reference< XJobExecutor > xTableWizard; + if ( m_aContext.createComponentWithArguments( "com.sun.star.wizards.table.CallTableWizard", aWizArgs, xTableWizard ) ) + xTableWizard->trigger(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("start"))); + } + catch(const Exception&) + { + OSL_FAIL("caught an exception while starting the table wizard!"); + } + m_xMySelf = NULL; + return 0L; +} +} +// ------------------------------------------------------------------------- +extern "C" void SAL_CALL createRegistryInfo_DBContentLoader2() +{ + static ::dbaxml::OMultiInstanceAutoRegistration< ::dbaxml::DBContentLoader > aAutoRegistration; +} +// ------------------------------------------------------------------------- +extern "C" void SAL_CALL writeDBLoaderInfo2(void* pRegistryKey) +{ + Reference< XRegistryKey> xKey(reinterpret_cast< XRegistryKey*>(pRegistryKey)); + + // register content loader for dispatch + ::rtl::OUString aImpl(RTL_CONSTASCII_USTRINGPARAM("/")); + aImpl += ::dbaxml::DBContentLoader::getImplementationName_Static(); + + ::rtl::OUString aImpltwo = aImpl; + aImpltwo += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/UNO/Loader")); + Reference< XRegistryKey> xNewKey = xKey->createKey( aImpltwo ); + aImpltwo = aImpl; + aImpltwo += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/Loader")); + Reference< XRegistryKey > xLoaderKey = xKey->createKey( aImpltwo ); + xNewKey = xLoaderKey->createKey( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Pattern")) ); + xNewKey->setAsciiValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("private:factory/sdatabase")) ); +} +// ----------------------------------------------------------------------------- + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/filter/xml/makefile.mk b/dbaccess/source/filter/xml/makefile.mk new file mode 100644 index 000000000000..33ff074b8012 --- /dev/null +++ b/dbaccess/source/filter/xml/makefile.mk @@ -0,0 +1,121 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/..$/.. +PRJINC=$(PRJ)$/source +PRJNAME=dbaccess +TARGET=dbaxml + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ---------------------------------- + +.INCLUDE : settings.mk + +# --- Files ------------------------------------- + +SLOFILES= $(SLO)$/xmlfilter.obj \ + $(SLO)$/dbloader2.obj \ + $(SLO)$/xmlDatabase.obj \ + $(SLO)$/xmlDataSource.obj \ + $(SLO)$/xmlTableFilterPattern.obj \ + $(SLO)$/xmlTableFilterList.obj \ + $(SLO)$/xmlDataSourceInfo.obj \ + $(SLO)$/xmlDataSourceSetting.obj \ + $(SLO)$/xmlDataSourceSettings.obj \ + $(SLO)$/xmlDocuments.obj \ + $(SLO)$/xmlComponent.obj \ + $(SLO)$/xmlHierarchyCollection.obj \ + $(SLO)$/xmlLogin.obj \ + $(SLO)$/xmlExport.obj \ + $(SLO)$/xmlQuery.obj \ + $(SLO)$/xmlTable.obj \ + $(SLO)$/xmlColumn.obj \ + $(SLO)$/xmlStyleImport.obj \ + $(SLO)$/xmlHelper.obj \ + $(SLO)$/xmlAutoStyle.obj \ + $(SLO)$/xmlConnectionData.obj \ + $(SLO)$/xmlDatabaseDescription.obj \ + $(SLO)$/xmlFileBasedDatabase.obj \ + $(SLO)$/xmlServerDatabase.obj \ + $(SLO)$/xmlConnectionResource.obj \ + $(SLO)$/xmlservices.obj + +# --- Library ----------------------------------- +LIB1TARGET=$(SLB)$/dba_flt.lib +LIB1FILES=\ + $(SLB)$/fltshared.lib \ + $(SLB)$/$(TARGET).lib + +SHL1TARGET=$(TARGET)$(DLLPOSTFIX) + +SHL1STDLIBS=\ + $(XMLOFFLIB) \ + $(VCLLIB) \ + $(TOOLSLIB) \ + $(TKLIB) \ + $(COMPHELPERLIB) \ + $(CPPUHELPERLIB) \ + $(CPPULIB) \ + $(SFXLIB) \ + $(SVLLIB) \ + $(DBTOOLSLIB) \ + $(UNOTOOLSLIB) \ + $(SO2LIB) \ + $(SALLIB) + +.IF "$(GUI)"=="OS2" +SHL1STDLIBS+= \ + idba.lib +.ELIF "$(GUI)"!="WNT" || "$(COM)"=="GCC" +SHL1STDLIBS+= \ + -ldba$(DLLPOSTFIX) +.ELSE +SHL1STDLIBS+= \ + idba.lib +.ENDIF + + +SHL1DEPN= +SHL1LIBS=$(LIB1TARGET) +SHL1IMPLIB= i$(SHL1TARGET) +SHL1VERSIONMAP=$(SOLARENV)/src/component.map +SHL1DEF= $(MISC)$/$(SHL1TARGET).def + +DEF1NAME=$(SHL1TARGET) + +# --- Targets ---------------------------------- + +.INCLUDE : target.mk + +ALLTAR : $(MISC)/dbaxml.component + +$(MISC)/dbaxml.component .ERRREMOVE : $(SOLARENV)/bin/createcomponent.xslt \ + dbaxml.component + $(XSLTPROC) --nonet --stringparam uri \ + '$(COMPONENTPREFIX_BASIS_NATIVE)$(SHL1TARGETN:f)' -o $@ \ + $(SOLARENV)/bin/createcomponent.xslt dbaxml.component diff --git a/dbaccess/source/filter/xml/xmlAutoStyle.cxx b/dbaccess/source/filter/xml/xmlAutoStyle.cxx new file mode 100644 index 000000000000..a84b69dfa43b --- /dev/null +++ b/dbaccess/source/filter/xml/xmlAutoStyle.cxx @@ -0,0 +1,102 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_dbaccess.hxx" +#include "xmlAutoStyle.hxx" +#include "xmlHelper.hxx" +#include "xmlExport.hxx" +#include <xmloff/families.hxx> +#include <tools/debug.hxx> +namespace dbaxml +{ + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::xml::sax; + +void OXMLAutoStylePoolP::exportStyleAttributes( + SvXMLAttributeList& rAttrList, + sal_Int32 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 == XML_STYLE_FAMILY_TABLE_COLUMN ) + { + UniReference< XMLPropertySetMapper > aPropMapper = rODBExport.GetColumnStylesPropertySetMapper(); + ::std::vector< XMLPropertyState >::const_iterator i = rProperties.begin(); + ::std::vector< XMLPropertyState >::const_iterator aEnd = rProperties.end(); + for ( ; i != aEnd ; ++i ) + { + sal_Int16 nContextID = aPropMapper->GetEntryContextId(i->mnIndex); + switch (nContextID) + { + case CTF_DB_NUMBERFORMAT : + { + sal_Int32 nNumberFormat = 0; + if ( i->maValue >>= nNumberFormat ) + { + rtl::OUString sAttrValue = rODBExport.getDataStyleName(nNumberFormat); + if ( sAttrValue.getLength() ) + { + GetExport().AddAttribute( + aPropMapper->GetEntryNameSpace(i->mnIndex), + aPropMapper->GetEntryXMLName(i->mnIndex), + sAttrValue ); + } + } + break; + } + } + } + } +} +DBG_NAME(OXMLAutoStylePoolP) +// ----------------------------------------------------------------------------- +OXMLAutoStylePoolP::OXMLAutoStylePoolP(ODBExport& rTempODBExport): + SvXMLAutoStylePoolP(rTempODBExport), + rODBExport(rTempODBExport) +{ + DBG_CTOR(OXMLAutoStylePoolP,NULL); + +} +// ----------------------------------------------------------------------------- +OXMLAutoStylePoolP::~OXMLAutoStylePoolP() +{ + + DBG_DTOR(OXMLAutoStylePoolP,NULL); +} +// ----------------------------------------------------------------------------- + +//---------------------------------------------------------------------------- +} // 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 000000000000..6d3da1fa34aa --- /dev/null +++ b/dbaccess/source/filter/xml/xmlAutoStyle.hxx @@ -0,0 +1,60 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef DBA_XMLAUTOSTYLE_HXX +#define DBA_XMLAUTOSTYLE_HXX +#include <xmloff/maptype.hxx> +#include <xmloff/xmlaustp.hxx> +#include <xmloff/xmltypes.hxx> +#include <xmloff/xmlprmap.hxx> + +namespace dbaxml +{ + class ODBExport; + class OXMLAutoStylePoolP : public SvXMLAutoStylePoolP + { + ODBExport& rODBExport; + + virtual void exportStyleAttributes( + SvXMLAttributeList& rAttrList, + sal_Int32 nFamily, + const ::std::vector< XMLPropertyState >& rProperties, + const SvXMLExportPropertyMapper& rPropExp, + const SvXMLUnitConverter& rUnitConverter, + const SvXMLNamespaceMap& rNamespaceMap + ) const; + + public: + OXMLAutoStylePoolP(ODBExport& rXMLExport); + virtual ~OXMLAutoStylePoolP(); + }; +// ----------------------------------------------------------------------------- +} // dbaxml +// ----------------------------------------------------------------------------- +#endif // DBA_XMLAUTOSTYLE_HXX + +/* 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 000000000000..47b9126acdd5 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlColumn.cxx @@ -0,0 +1,195 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_dbaccess.hxx" +#include "xmlColumn.hxx" +#include "xmlfilter.hxx" +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmluconv.hxx> +#include <xmloff/xmlnmspe.hxx> +#include <xmloff/nmspmap.hxx> +#include "xmlEnums.hxx" +#include "xmlstrings.hrc" +#include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp> +#include <com/sun/star/sdbcx/XAppend.hpp> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/container/XChild.hpp> +#include "xmlStyleImport.hxx" +#include <tools/debug.hxx> + +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; +DBG_NAME(OXMLColumn) + +OXMLColumn::OXMLColumn( ODBFilter& rImport + ,sal_uInt16 nPrfx + ,const ::rtl::OUString& _sLocalName + ,const Reference< XAttributeList > & _xAttrList + ,const Reference< XNameAccess >& _xParentContainer + ,const Reference< XPropertySet >& _xTable + ) : + SvXMLImportContext( rImport, nPrfx, _sLocalName ) + ,m_xParentContainer(_xParentContainer) + ,m_xTable(_xTable) + ,m_bHidden(sal_False) +{ + DBG_CTOR(OXMLColumn,NULL); + + OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!"); + const SvXMLNamespaceMap& rMap = rImport.GetNamespaceMap(); + const SvXMLTokenMap& rTokenMap = rImport.GetColumnElemTokenMap(); + + sal_Int16 nLength = (_xAttrList.is()) ? _xAttrList->getLength() : 0; + ::rtl::OUString sType; + for(sal_Int16 i = 0; i < nLength; ++i) + { + ::rtl::OUString sLocalName; + rtl::OUString sAttrName = _xAttrList->getNameByIndex( i ); + sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName ); + rtl::OUString sValue = _xAttrList->getValueByIndex( i ); + + switch( rTokenMap.Get( nPrefix, sLocalName ) ) + { + case XML_TOK_COLUMN_NAME: + m_sName = sValue; + break; + case XML_TOK_COLUMN_STYLE_NAME: + m_sStyleName = sValue; + break; + case XML_TOK_COLUMN_HELP_MESSAGE: + m_sHelpMessage = sValue; + break; + case XML_TOK_COLUMN_VISIBILITY: + m_bHidden = !sValue.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("visible")); + break; + case XML_TOK_COLUMN_TYPE_NAME: + sType = sValue; + OSL_ENSURE(sType.getLength(),"No type name set"); + break; + case XML_TOK_COLUMN_DEFAULT_VALUE: + if ( sValue.getLength() && sType.getLength() ) + m_aDefaultValue <<= sValue; + break; + case XML_TOK_COLUMN_VISIBLE: + m_bHidden = sValue.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("false")); + break; + case XML_TOK_DEFAULT_CELL_STYLE_NAME: + m_sCellStyleName = sValue; + break; + } + } +} +// ----------------------------------------------------------------------------- + +OXMLColumn::~OXMLColumn() +{ + + DBG_DTOR(OXMLColumn,NULL); +} +// ----------------------------------------------------------------------------- +void OXMLColumn::EndElement() +{ + Reference<XDataDescriptorFactory> xFac(m_xParentContainer,UNO_QUERY); + if ( xFac.is() && m_sName.getLength() ) + { + Reference<XPropertySet> xProp(xFac->createDataDescriptor()); + if ( xProp.is() ) + { + xProp->setPropertyValue(PROPERTY_NAME,makeAny(m_sName)); + xProp->setPropertyValue(PROPERTY_HIDDEN,makeAny(m_bHidden)); + if ( m_sHelpMessage.getLength() ) + xProp->setPropertyValue(PROPERTY_HELPTEXT,makeAny(m_sHelpMessage)); + + if ( m_aDefaultValue.hasValue() ) + xProp->setPropertyValue(PROPERTY_CONTROLDEFAULT,m_aDefaultValue); + + Reference<XAppend> xAppend(m_xParentContainer,UNO_QUERY); + if ( xAppend.is() ) + xAppend->appendByDescriptor(xProp); + m_xParentContainer->getByName(m_sName) >>= xProp; + + if ( m_sStyleName.getLength() ) + { + const SvXMLStylesContext* pAutoStyles = GetOwnImport().GetAutoStyles(); + if ( pAutoStyles ) + { + OTableStyleContext* pAutoStyle = PTR_CAST(OTableStyleContext,pAutoStyles->FindStyleChildContext(XML_STYLE_FAMILY_TABLE_COLUMN,m_sStyleName)); + if ( pAutoStyle ) + { + pAutoStyle->FillPropertySet(xProp); + } + } + } + if ( m_sCellStyleName.getLength() ) + { + const SvXMLStylesContext* pAutoStyles = GetOwnImport().GetAutoStyles(); + if ( pAutoStyles ) + { + OTableStyleContext* pAutoStyle = PTR_CAST(OTableStyleContext,pAutoStyles->FindStyleChildContext(XML_STYLE_FAMILY_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.getLength() ) + { + const SvXMLStylesContext* pAutoStyles = GetOwnImport().GetAutoStyles(); + if ( pAutoStyles ) + { + OTableStyleContext* pAutoStyle = PTR_CAST(OTableStyleContext,pAutoStyles->FindStyleChildContext(XML_STYLE_FAMILY_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<ODBFilter&>(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 000000000000..e417e0398825 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlColumn.hxx @@ -0,0 +1,69 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef DBA_XMLCOLUMN_HXX +#define DBA_XMLCOLUMN_HXX + +#include <xmloff/xmlictxt.hxx> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> + +namespace dbaxml +{ + class ODBFilter; + class OXMLColumn : public SvXMLImportContext + { + ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > m_xParentContainer; + ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > m_xTable; + + ::rtl::OUString m_sName; + ::rtl::OUString m_sStyleName; + ::rtl::OUString m_sCellStyleName; + ::rtl::OUString m_sHelpMessage; + ::com::sun::star::uno::Any m_aDefaultValue; + sal_Bool m_bHidden; + + ODBFilter& GetOwnImport(); + public: + + OXMLColumn( ODBFilter& rImport + , sal_uInt16 nPrfx + ,const ::rtl::OUString& rLName + ,const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttrList + ,const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& _xParentContainer + ,const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _xTable + ); + virtual ~OXMLColumn(); + virtual void EndElement(); + }; +// ----------------------------------------------------------------------------- +} // namespace dbaxml +// ----------------------------------------------------------------------------- + +#endif // DBA_XMLCOLUMN_HXX + +/* 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 000000000000..2af3b4d9c102 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlComponent.cxx @@ -0,0 +1,136 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_dbaccess.hxx" +#include "xmlComponent.hxx" +#include "xmlfilter.hxx" +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmlnmspe.hxx> +#include <xmloff/nmspmap.hxx> +#include "xmlEnums.hxx" +#include "xmlstrings.hrc" +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <tools/debug.hxx> +#include <tools/diagnose_ex.h> + +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; +DBG_NAME(OXMLComponent) + +OXMLComponent::OXMLComponent( ODBFilter& rImport + ,sal_uInt16 nPrfx + ,const ::rtl::OUString& _sLocalName + ,const Reference< XAttributeList > & _xAttrList + ,const Reference< XNameAccess >& _xParentContainer + ,const ::rtl::OUString& _sComponentServiceName + ) : + SvXMLImportContext( rImport, nPrfx, _sLocalName ) + ,m_bAsTemplate(sal_False) +{ + DBG_CTOR(OXMLComponent,NULL); + + OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!"); + const SvXMLNamespaceMap& rMap = rImport.GetNamespaceMap(); + const SvXMLTokenMap& rTokenMap = rImport.GetComponentElemTokenMap(); + + sal_Int16 nLength = (_xAttrList.is()) ? _xAttrList->getLength() : 0; + static const ::rtl::OUString s_sTRUE = ::xmloff::token::GetXMLToken(XML_TRUE); + for(sal_Int16 i = 0; i < nLength; ++i) + { + ::rtl::OUString sLocalName; + rtl::OUString sAttrName = _xAttrList->getNameByIndex( i ); + sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName ); + rtl::OUString sValue = _xAttrList->getValueByIndex( i ); + + switch( rTokenMap.Get( nPrefix, sLocalName ) ) + { + case XML_TOK_HREF: + m_sHREF = sValue; + break; + case XML_TOK_COMPONENT_NAME: + m_sName = sValue; + // 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. + m_sName = m_sName.replace( '/', '_' ); + break; + case XML_TOK_AS_TEMPLATE: + m_bAsTemplate = (sValue == s_sTRUE ? sal_True : sal_False); + break; + } + } + if ( m_sHREF.getLength() && m_sName.getLength() && _xParentContainer.is() ) + { + Sequence< Any > aArguments(3); + PropertyValue aValue; + // set as folder + aValue.Name = PROPERTY_NAME; + aValue.Value <<= m_sName; + aArguments[0] <<= aValue; + + aValue.Name = PROPERTY_PERSISTENT_NAME; + sal_Int32 nIndex = m_sHREF.lastIndexOf('/')+1; + aValue.Value <<= m_sHREF.getToken(0,'/',nIndex); + aArguments[1] <<= aValue; + + aValue.Name = PROPERTY_AS_TEMPLATE; + aValue.Value <<= m_bAsTemplate; + aArguments[2] <<= aValue; + + try + { + Reference< XMultiServiceFactory > xORB( _xParentContainer, UNO_QUERY_THROW ); + Reference< XInterface > xComponent( xORB->createInstanceWithArguments( _sComponentServiceName, aArguments ) ); + Reference< XNameContainer > xNameContainer( _xParentContainer, UNO_QUERY_THROW ); + xNameContainer->insertByName( m_sName, makeAny( xComponent ) ); + } + catch(Exception&) + { + DBG_UNHANDLED_EXCEPTION(); + } + } +} +// ----------------------------------------------------------------------------- + +OXMLComponent::~OXMLComponent() +{ + + DBG_DTOR(OXMLComponent,NULL); +} +// ----------------------------------------------------------------------------- +//---------------------------------------------------------------------------- +} // 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 000000000000..1d950173b1b4 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlComponent.hxx @@ -0,0 +1,63 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef DBA_XMLCOMPONENT_HXX +#define DBA_XMLCOMPONENT_HXX + +#include <xmloff/xmlictxt.hxx> +#include <com/sun/star/container/XNameAccess.hpp> + + +namespace dbaxml +{ + class ODBFilter; + class OXMLComponent : public SvXMLImportContext + { + ::rtl::OUString m_sName; + ::rtl::OUString m_sHREF; + ::rtl::OUString m_sComponentServiceName; + sal_Bool m_bAsTemplate; + + ODBFilter& GetOwnImport(); + public: + + OXMLComponent( ODBFilter& rImport + , sal_uInt16 nPrfx + ,const ::rtl::OUString& rLName + ,const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttrList + ,const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& _xParentContainer + ,const ::rtl::OUString& _sComponentServiceName + ); + virtual ~OXMLComponent(); + }; +// ----------------------------------------------------------------------------- +} // namespace dbaxml +// ----------------------------------------------------------------------------- + +#endif // DBA_XMLCOMPONENT_HXX + +/* 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 000000000000..3695f24c6590 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlConnectionData.cxx @@ -0,0 +1,122 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_dbaccess.hxx" +#include "xmlConnectionData.hxx" +#include "xmlLogin.hxx" +#include "xmlTableFilterList.hxx" +#include "xmlfilter.hxx" +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmlnmspe.hxx> +#include <xmloff/nmspmap.hxx> +#include "xmlEnums.hxx" +#include "xmlDatabaseDescription.hxx" +#include "xmlConnectionResource.hxx" +#include "xmlstrings.hrc" +#include <tools/debug.hxx> +#include <tools/diagnose_ex.h> + +namespace dbaxml +{ + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::xml::sax; +DBG_NAME(OXMLConnectionData) + +OXMLConnectionData::OXMLConnectionData( ODBFilter& rImport, + sal_uInt16 nPrfx, const ::rtl::OUString& _sLocalName) : + SvXMLImportContext( rImport, nPrfx, _sLocalName ) + ,m_bFoundOne(false) +{ + rImport.setNewFormat(true); + DBG_CTOR(OXMLConnectionData,NULL); +} +// ----------------------------------------------------------------------------- + +OXMLConnectionData::~OXMLConnectionData() +{ + + DBG_DTOR(OXMLConnectionData,NULL); +} +// ----------------------------------------------------------------------------- + +SvXMLImportContext* OXMLConnectionData::CreateChildContext( + sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const Reference< XAttributeList > & xAttrList ) +{ + SvXMLImportContext *pContext = 0; + const SvXMLTokenMap& rTokenMap = GetOwnImport().GetDataSourceElemTokenMap(); + + switch( rTokenMap.Get( nPrefix, rLocalName ) ) + { + case XML_TOK_LOGIN: + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + pContext = new OXMLLogin( GetOwnImport(), nPrefix, rLocalName,xAttrList ); + break; + case XML_TOK_DATABASE_DESCRIPTION: + if ( !m_bFoundOne ) + { + m_bFoundOne = true; + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + pContext = new OXMLDatabaseDescription( GetOwnImport(), nPrefix, rLocalName); + } + break; + case XML_TOK_CONNECTION_RESOURCE: + if ( !m_bFoundOne ) + { + m_bFoundOne = true; + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + pContext = new OXMLConnectionResource( GetOwnImport(), nPrefix, rLocalName,xAttrList ); + } + break; + case XML_TOK_COMPOUND_DATABASE: + if ( !m_bFoundOne ) + { + m_bFoundOne = true; + OSL_FAIL("Not supported yet!"); + } + break; + } + + if( !pContext ) + pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName ); + + return pContext; +} +// ----------------------------------------------------------------------------- +ODBFilter& OXMLConnectionData::GetOwnImport() +{ + return static_cast<ODBFilter&>(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 000000000000..2cf32047c99c --- /dev/null +++ b/dbaccess/source/filter/xml/xmlConnectionData.hxx @@ -0,0 +1,59 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef DBA_XMLCONNECTIONDATA_HXX_INCLUDED +#define DBA_XMLCONNECTIONDATA_HXX_INCLUDED + +#include <xmloff/xmlictxt.hxx> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <vector> + +namespace dbaxml +{ + class ODBFilter; + class OXMLConnectionData : public SvXMLImportContext + { + bool m_bFoundOne; + + ODBFilter& GetOwnImport(); + public: + + OXMLConnectionData( ODBFilter& rImport, sal_uInt16 nPrfx, + const ::rtl::OUString& rLName); + virtual ~OXMLConnectionData(); + + virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttrList ); + }; +// ----------------------------------------------------------------------------- +} // namespace dbaxml +// ----------------------------------------------------------------------------- + +#endif // DBA_XMLCONNECTIONDATA_HXX_INCLUDED + +/* 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 000000000000..5b0b6aeee3de --- /dev/null +++ b/dbaccess/source/filter/xml/xmlConnectionResource.cxx @@ -0,0 +1,115 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_dbaccess.hxx" +#include "xmlConnectionResource.hxx" +#include "xmlfilter.hxx" +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmlnmspe.hxx> +#include <xmloff/nmspmap.hxx> +#include "xmlEnums.hxx" +#include "xmlstrings.hrc" +#include <tools/debug.hxx> +#include <tools/diagnose_ex.h> + +namespace dbaxml +{ + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::xml::sax; +DBG_NAME(OXMLConnectionResource) + +OXMLConnectionResource::OXMLConnectionResource( ODBFilter& rImport, + sal_uInt16 nPrfx, const ::rtl::OUString& _sLocalName, + const Reference< XAttributeList > & _xAttrList) : + SvXMLImportContext( rImport, nPrfx, _sLocalName ) +{ + DBG_CTOR(OXMLConnectionResource,NULL); + + OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!"); + const SvXMLNamespaceMap& rMap = rImport.GetNamespaceMap(); + const SvXMLTokenMap& rTokenMap = rImport.GetComponentElemTokenMap(); + + Reference<XPropertySet> xDataSource = rImport.getDataSource(); + + PropertyValue aProperty; + + const sal_Int16 nLength = (xDataSource.is() && _xAttrList.is()) ? _xAttrList->getLength() : 0; + for(sal_Int16 i = 0; i < nLength; ++i) + { + ::rtl::OUString sLocalName; + const rtl::OUString sAttrName = _xAttrList->getNameByIndex( i ); + const sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName ); + const rtl::OUString sValue = _xAttrList->getValueByIndex( i ); + + aProperty.Name = ::rtl::OUString(); + aProperty.Value = Any(); + + switch( rTokenMap.Get( nPrefix, sLocalName ) ) + { + case XML_TOK_HREF: + try + { + xDataSource->setPropertyValue(PROPERTY_URL,makeAny(sValue)); + } + catch(Exception) + { + DBG_UNHANDLED_EXCEPTION(); + } + break; + case XML_TOK_TYPE: + aProperty.Name = PROPERTY_TYPE; + break; + case XML_TOK_SHOW: + aProperty.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Show")); + break; + case XML_TOK_ACTUATE: + aProperty.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Actuate")); + break; + } + if ( aProperty.Name.getLength() ) + { + if ( !aProperty.Value.hasValue() ) + aProperty.Value <<= sValue; + rImport.addInfo(aProperty); + } + } +} +// ----------------------------------------------------------------------------- + +OXMLConnectionResource::~OXMLConnectionResource() +{ + + DBG_DTOR(OXMLConnectionResource,NULL); +} +// ----------------------------------------------------------------------------- +//---------------------------------------------------------------------------- +} // 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 000000000000..ea6be03655fb --- /dev/null +++ b/dbaccess/source/filter/xml/xmlConnectionResource.hxx @@ -0,0 +1,53 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef DBA_XMLCONNECTIONRESOURCE_HXX_INCLUDED +#define DBA_XMLCONNECTIONRESOURCE_HXX_INCLUDED + +#include <xmloff/xmlictxt.hxx> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <vector> + +namespace dbaxml +{ + class ODBFilter; + class OXMLConnectionResource : public SvXMLImportContext + { + public: + + OXMLConnectionResource( ODBFilter& rImport, sal_uInt16 nPrfx, + const ::rtl::OUString& rLName, + const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttrList); + virtual ~OXMLConnectionResource(); + }; +// ----------------------------------------------------------------------------- +} // namespace dbaxml +// ----------------------------------------------------------------------------- + +#endif // DBA_XMLCONNECTIONRESOURCE_HXX_INCLUDED + +/* 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 000000000000..b13ec0b730e7 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlDataSource.cxx @@ -0,0 +1,284 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_dbaccess.hxx" +#include "xmlDataSource.hxx" +#include "xmlLogin.hxx" +#include "xmlTableFilterList.hxx" +#include "xmlDataSourceInfo.hxx" +#include "xmlDataSourceSettings.hxx" +#include "xmlDataSourceSetting.hxx" +#include "xmlfilter.hxx" +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmlnmspe.hxx> +#include <xmloff/nmspmap.hxx> +#include "xmlEnums.hxx" +#include "xmlstrings.hrc" +#include <tools/debug.hxx> +#include <tools/diagnose_ex.h> +#include "xmlConnectionData.hxx" + +namespace dbaxml +{ + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::xml::sax; +DBG_NAME(OXMLDataSource) + +OXMLDataSource::OXMLDataSource( ODBFilter& rImport, + sal_uInt16 nPrfx, const ::rtl::OUString& _sLocalName, + const Reference< XAttributeList > & _xAttrList, const UsedFor _eUsedFor ) : + SvXMLImportContext( rImport, nPrfx, _sLocalName ) +{ + DBG_CTOR(OXMLDataSource,NULL); + + OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!"); + const SvXMLNamespaceMap& rMap = rImport.GetNamespaceMap(); + const SvXMLTokenMap& rTokenMap = rImport.GetDataSourceElemTokenMap(); + + Reference<XPropertySet> xDataSource = rImport.getDataSource(); + + PropertyValue aProperty; + bool bFoundParamNameSubstitution = false; + bool bFoundTableNameLengthLimited = false; + bool bFoundAppendTableAliasName = false; + bool bFoundSuppressVersionColumns = false; + + const sal_Int16 nLength = (xDataSource.is() && _xAttrList.is()) ? _xAttrList->getLength() : 0; + static const ::rtl::OUString s_sTRUE = ::xmloff::token::GetXMLToken(XML_TRUE); + for(sal_Int16 i = 0; i < nLength; ++i) + { + ::rtl::OUString sLocalName; + rtl::OUString sAttrName = _xAttrList->getNameByIndex( i ); + sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName ); + rtl::OUString sValue = _xAttrList->getValueByIndex( i ); + + aProperty.Name = ::rtl::OUString(); + aProperty.Value = Any(); + + switch( rTokenMap.Get( nPrefix, sLocalName ) ) + { + case XML_TOK_CONNECTION_RESOURCE: + try + { + xDataSource->setPropertyValue(PROPERTY_URL,makeAny(sValue)); + } + catch(Exception) + { + DBG_UNHANDLED_EXCEPTION(); + } + break; + case XML_TOK_SUPPRESS_VERSION_COLUMNS: + try + { + xDataSource->setPropertyValue(PROPERTY_SUPPRESSVERSIONCL,makeAny(sValue == s_sTRUE ? sal_True : sal_False)); + bFoundSuppressVersionColumns = true; + } + catch(Exception) + { + DBG_UNHANDLED_EXCEPTION(); + } + break; + case XML_TOK_JAVA_DRIVER_CLASS: + aProperty.Name = INFO_JDBCDRIVERCLASS; + break; + case XML_TOK_EXTENSION: + aProperty.Name = INFO_TEXTFILEEXTENSION; + break; + case XML_TOK_IS_FIRST_ROW_HEADER_LINE: + aProperty.Name = INFO_TEXTFILEHEADER; + aProperty.Value <<= (sValue == s_sTRUE ? sal_True : sal_False); + break; + case XML_TOK_SHOW_DELETED: + aProperty.Name = INFO_SHOWDELETEDROWS; + aProperty.Value <<= (sValue == s_sTRUE ? sal_True : sal_False); + break; + case XML_TOK_IS_TABLE_NAME_LENGTH_LIMITED: + aProperty.Name = INFO_ALLOWLONGTABLENAMES; + aProperty.Value <<= (sValue == s_sTRUE ? sal_True : sal_False); + bFoundTableNameLengthLimited = true; + break; + case XML_TOK_SYSTEM_DRIVER_SETTINGS: + aProperty.Name = INFO_ADDITIONALOPTIONS; + break; + case XML_TOK_ENABLE_SQL92_CHECK: + aProperty.Name = PROPERTY_ENABLESQL92CHECK; + aProperty.Value <<= (sValue == s_sTRUE ? sal_True : sal_False); + break; + case XML_TOK_APPEND_TABLE_ALIAS_NAME: + aProperty.Name = INFO_APPEND_TABLE_ALIAS; + aProperty.Value <<= (sValue == s_sTRUE ? sal_True : sal_False); + bFoundAppendTableAliasName = true; + break; + case XML_TOK_PARAMETER_NAME_SUBSTITUTION: + aProperty.Name = INFO_PARAMETERNAMESUBST; + aProperty.Value <<= (sValue == s_sTRUE ? sal_True : sal_False); + bFoundParamNameSubstitution = true; + break; + case XML_TOK_IGNORE_DRIVER_PRIVILEGES: + aProperty.Name = INFO_IGNOREDRIVER_PRIV; + aProperty.Value <<= (sValue == s_sTRUE ? sal_True : sal_False); + break; + case XML_TOK_BOOLEAN_COMPARISON_MODE: + aProperty.Name = PROPERTY_BOOLEANCOMPARISONMODE; + if ( sValue.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("equal-integer")) ) + aProperty.Value <<= sal_Int32(0); + else if ( sValue.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("is-boolean")) ) + aProperty.Value <<= sal_Int32(1); + else if ( sValue.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("equal-boolean")) ) + aProperty.Value <<= sal_Int32(2); + else if ( sValue.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("equal-use-only-zero")) ) + aProperty.Value <<= sal_Int32(3); + break; + case XML_TOK_USE_CATALOG: + aProperty.Name = INFO_USECATALOG; + aProperty.Value <<= (sValue == s_sTRUE ? sal_True : sal_False); + break; + case XML_TOK_BASE_DN: + aProperty.Name = INFO_CONN_LDAP_BASEDN; + break; + case XML_TOK_MAX_ROW_COUNT: + aProperty.Name = INFO_CONN_LDAP_ROWCOUNT; + aProperty.Value <<= sValue.toInt32(); + break; + case XML_TOK_JAVA_CLASSPATH: + aProperty.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JavaDriverClassPath")); + break; + } + if ( aProperty.Name.getLength() ) + { + if ( !aProperty.Value.hasValue() ) + aProperty.Value <<= sValue; + rImport.addInfo(aProperty); + } + } + if ( rImport.isNewFormat() ) + { + if ( !bFoundTableNameLengthLimited && ( _eUsedFor == eAppSettings ) ) + { + aProperty.Name = INFO_ALLOWLONGTABLENAMES; + aProperty.Value <<= sal_True; + rImport.addInfo(aProperty); + } + if ( !bFoundParamNameSubstitution && ( _eUsedFor == eDriverSettings ) ) + { + aProperty.Name = INFO_PARAMETERNAMESUBST; + aProperty.Value <<= sal_True; + rImport.addInfo(aProperty); + } + if ( !bFoundAppendTableAliasName && ( _eUsedFor == eAppSettings ) ) + { + aProperty.Name = INFO_APPEND_TABLE_ALIAS; + aProperty.Value <<= sal_True; + rImport.addInfo(aProperty); + } + if ( !bFoundSuppressVersionColumns && ( _eUsedFor == eAppSettings ) ) + { + try + { + xDataSource->setPropertyValue(PROPERTY_SUPPRESSVERSIONCL,makeAny(sal_True)); + } + catch(Exception) + { + DBG_UNHANDLED_EXCEPTION(); + } + } + } +} +// ----------------------------------------------------------------------------- + +OXMLDataSource::~OXMLDataSource() +{ + + DBG_DTOR(OXMLDataSource,NULL); +} +// ----------------------------------------------------------------------------- + +SvXMLImportContext* OXMLDataSource::CreateChildContext( + sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const Reference< XAttributeList > & xAttrList ) +{ + SvXMLImportContext *pContext = 0; + const SvXMLTokenMap& rTokenMap = GetOwnImport().GetDataSourceElemTokenMap(); + const sal_uInt16 nToken = rTokenMap.Get( nPrefix, rLocalName ); + + switch( nToken ) + { + case XML_TOK_LOGIN: + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + pContext = new OXMLLogin( GetOwnImport(), nPrefix, rLocalName,xAttrList ); + break; + + case XML_TOK_TABLE_FILTER: + case XML_TOK_TABLE_TYPE_FILTER: + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + pContext = new OXMLTableFilterList( GetImport(), nPrefix, rLocalName ); + break; + case XML_TOK_AUTO_INCREMENT: + case XML_TOK_DELIMITER: + case XML_TOK_FONT_CHARSET: + case XML_TOK_CHARACTER_SET: + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + pContext = new OXMLDataSourceInfo( GetOwnImport(), nPrefix, rLocalName,xAttrList,nToken); + break; + case XML_TOK_DATA_SOURCE_SETTINGS: + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + pContext = new OXMLDataSourceSettings( GetOwnImport(), nPrefix, rLocalName); + break; + case XML_TOK_CONNECTION_DATA: + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + pContext = new OXMLConnectionData( GetOwnImport(), nPrefix, rLocalName); + break; + case XML_TOK_DRIVER_SETTINGS: + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + pContext = new OXMLDataSource( GetOwnImport(), nPrefix, rLocalName, xAttrList, OXMLDataSource::eDriverSettings ); + break; + case XML_TOK_APPLICATION_CONNECTION_SETTINGS: + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + pContext = new OXMLDataSource( GetOwnImport(), nPrefix, rLocalName, xAttrList, OXMLDataSource::eAppSettings ); + break; + } + + if( !pContext ) + pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName ); + + return pContext; +} +// ----------------------------------------------------------------------------- +ODBFilter& OXMLDataSource::GetOwnImport() +{ + return static_cast<ODBFilter&>(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 000000000000..87038f05ef30 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlDataSource.hxx @@ -0,0 +1,65 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef DBA_XMLDATASOURCE_HXX +#define DBA_XMLDATASOURCE_HXX + +#include <xmloff/xmlictxt.hxx> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <vector> + +namespace dbaxml +{ + class ODBFilter; + class OXMLDataSource : public SvXMLImportContext + { + ODBFilter& GetOwnImport(); + public: + enum UsedFor + { + eDataSource, + eDriverSettings, + eAppSettings + }; + + OXMLDataSource( ODBFilter& rImport, sal_uInt16 nPrfx, + const ::rtl::OUString& rLName, + const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttrList, + const UsedFor _eUsedFor = eDataSource ); + virtual ~OXMLDataSource(); + + virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttrList ); + }; +// ----------------------------------------------------------------------------- +} // namespace dbaxml +// ----------------------------------------------------------------------------- + +#endif // DBA_XMLDATASOURCE_HXX + +/* 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 000000000000..ad1b238ee836 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlDataSourceInfo.cxx @@ -0,0 +1,156 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_dbaccess.hxx" +#include "xmlDataSourceInfo.hxx" +#include "xmlDataSource.hxx" +#include "xmlfilter.hxx" +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmlnmspe.hxx> +#include <xmloff/nmspmap.hxx> +#include "xmlEnums.hxx" +#include "xmlstrings.hrc" +#include <com/sun/star/beans/PropertyValue.hpp> +#include <tools/debug.hxx> +#include <vector> + +namespace dbaxml +{ + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::xml::sax; +DBG_NAME(OXMLDataSourceInfo) + +OXMLDataSourceInfo::OXMLDataSourceInfo( ODBFilter& rImport + ,sal_uInt16 nPrfx + ,const ::rtl::OUString& _sLocalName + ,const Reference< XAttributeList > & _xAttrList + ,const sal_uInt16 _nToken) : + SvXMLImportContext( rImport, nPrfx, _sLocalName ) +{ + DBG_CTOR(OXMLDataSourceInfo,NULL); + + OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!"); + const SvXMLNamespaceMap& rMap = rImport.GetNamespaceMap(); + const SvXMLTokenMap& rTokenMap = rImport.GetDataSourceInfoElemTokenMap(); + + PropertyValue aProperty; + sal_Int16 nLength = (_xAttrList.is()) ? _xAttrList->getLength() : 0; + bool bAutoEnabled = false; + bool bFoundField = false,bFoundThousand = false, bFoundCharset = false; + ::std::vector< sal_uInt16 > aTokens; + for(sal_Int16 i = 0; i < nLength; ++i) + { + ::rtl::OUString sLocalName; + rtl::OUString sAttrName = _xAttrList->getNameByIndex( i ); + sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName ); + rtl::OUString sValue = _xAttrList->getValueByIndex( i ); + + aProperty.Name = ::rtl::OUString(); + + sal_uInt16 nToken = rTokenMap.Get( nPrefix, sLocalName ); + aTokens.push_back(nToken); + switch( nToken ) + { + case XML_TOK_ADDITIONAL_COLUMN_STATEMENT: + aProperty.Name = PROPERTY_AUTOINCREMENTCREATION; + bAutoEnabled = true; + break; + case XML_TOK_ROW_RETRIEVING_STATEMENT: + aProperty.Name = INFO_AUTORETRIEVEVALUE; + bAutoEnabled = true; + break; + case XML_TOK_STRING: + aProperty.Name = INFO_TEXTDELIMITER; + break; + case XML_TOK_FIELD: + aProperty.Name = INFO_FIELDDELIMITER; + bFoundField = true; + break; + case XML_TOK_DECIMAL: + aProperty.Name = INFO_DECIMALDELIMITER; + break; + case XML_TOK_THOUSAND: + aProperty.Name = INFO_THOUSANDSDELIMITER; + bFoundThousand = true; + break; + case XML_TOK_ENCODING: + aProperty.Name = INFO_CHARSET; + bFoundCharset = true; + break; + } + if ( aProperty.Name.getLength() ) + { + aProperty.Value <<= sValue; + rImport.addInfo(aProperty); + } + } + if ( bAutoEnabled ) + { + aProperty.Name = INFO_AUTORETRIEVEENABLED; + aProperty.Value <<= sal_True; + rImport.addInfo(aProperty); + } + if ( rImport.isNewFormat() ) + { + if ( XML_TOK_DELIMITER == _nToken ) + { + if ( !bFoundField ) + { + aProperty.Name = INFO_FIELDDELIMITER; + aProperty.Value <<= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(";")); + rImport.addInfo(aProperty); + } + if ( !bFoundThousand ) + { + aProperty.Name = INFO_THOUSANDSDELIMITER; + aProperty.Value <<= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(",")); + rImport.addInfo(aProperty); + } + } + if ( XML_TOK_FONT_CHARSET == _nToken && !bFoundCharset ) + { + aProperty.Name = INFO_CHARSET; + aProperty.Value <<= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("utf8")); + rImport.addInfo(aProperty); + } + } +} +// ----------------------------------------------------------------------------- + +OXMLDataSourceInfo::~OXMLDataSourceInfo() +{ + + DBG_DTOR(OXMLDataSourceInfo,NULL); +} +// ----------------------------------------------------------------------------- +//---------------------------------------------------------------------------- +} // 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 000000000000..89f9dde6a242 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlDataSourceInfo.hxx @@ -0,0 +1,53 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef DBA_XMLDATASOURCEINFO_HXX +#define DBA_XMLDATASOURCEINFO_HXX + +#include <xmloff/xmlictxt.hxx> + +namespace dbaxml +{ + class ODBFilter; + class OXMLDataSourceInfo : public SvXMLImportContext + { + ODBFilter& GetOwnImport(); + public: + + OXMLDataSourceInfo( ODBFilter& rImport, sal_uInt16 nPrfx, + const ::rtl::OUString& rLName, + const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttrList + ,const sal_uInt16 _nToken); + virtual ~OXMLDataSourceInfo(); + }; +// ----------------------------------------------------------------------------- +} // namespace dbaxml +// ----------------------------------------------------------------------------- + +#endif // DBA_XMLDATASOURCEINFO_HXX + +/* 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 000000000000..c004e7b62534 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlDataSourceSetting.cxx @@ -0,0 +1,254 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_dbaccess.hxx" +#include "xmlDataSourceSetting.hxx" +#include "xmlDataSource.hxx" +#include <xmloff/xmluconv.hxx> +#include "xmlfilter.hxx" +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmlnmspe.hxx> +#include <xmloff/nmspmap.hxx> +#include "xmlEnums.hxx" +#include "xmlstrings.hrc" +#include <tools/debug.hxx> + +namespace dbaxml +{ + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::xml::sax; +DBG_NAME(OXMLDataSourceSetting) + +OXMLDataSourceSetting::OXMLDataSourceSetting( ODBFilter& rImport + ,sal_uInt16 nPrfx + ,const ::rtl::OUString& _sLocalName + ,const Reference< XAttributeList > & _xAttrList + ,OXMLDataSourceSetting* _pContainer) : + SvXMLImportContext( rImport, nPrfx, _sLocalName ) + ,m_pContainer(_pContainer) + ,m_bIsList(sal_False) +{ + DBG_CTOR(OXMLDataSourceSetting,NULL); + + m_aPropType = ::getVoidCppuType(); + + OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!"); + const SvXMLNamespaceMap& rMap = rImport.GetNamespaceMap(); + const SvXMLTokenMap& rTokenMap = rImport.GetDataSourceInfoElemTokenMap(); + + sal_Int16 nLength = (_xAttrList.is()) ? _xAttrList->getLength() : 0; + for(sal_Int16 i = 0; i < nLength; ++i) + { + ::rtl::OUString sLocalName; + rtl::OUString sAttrName = _xAttrList->getNameByIndex( i ); + sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName ); + rtl::OUString sValue = _xAttrList->getValueByIndex( i ); + + switch( rTokenMap.Get( nPrefix, sLocalName ) ) + { + case XML_TOK_DATA_SOURCE_SETTING_IS_LIST: + m_bIsList = sValue.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("true")); + break; + case XML_TOK_DATA_SOURCE_SETTING_TYPE: + { + // needs to be translated into a ::com::sun::star::uno::Type + DECLARE_STL_USTRINGACCESS_MAP( ::com::sun::star::uno::Type, MapString2Type ); + static MapString2Type s_aTypeNameMap; + if (!s_aTypeNameMap.size()) + { + s_aTypeNameMap[GetXMLToken( XML_BOOLEAN)] = ::getBooleanCppuType(); + s_aTypeNameMap[GetXMLToken( XML_FLOAT)] = ::getCppuType( static_cast< double* >(NULL) ); + s_aTypeNameMap[GetXMLToken( XML_DOUBLE)] = ::getCppuType( static_cast< double* >(NULL) ); + s_aTypeNameMap[GetXMLToken( XML_STRING)] = ::getCppuType( static_cast< ::rtl::OUString* >(NULL) ); + s_aTypeNameMap[GetXMLToken( XML_INT)] = ::getCppuType( static_cast< sal_Int32* >(NULL) ); + s_aTypeNameMap[GetXMLToken( XML_SHORT)] = ::getCppuType( static_cast< sal_Int16* >(NULL) ); + s_aTypeNameMap[GetXMLToken( XML_VOID)] = ::getVoidCppuType(); + } + + const ConstMapString2TypeIterator aTypePos = s_aTypeNameMap.find(sValue); + OSL_ENSURE(s_aTypeNameMap.end() != aTypePos, "OXMLDataSourceSetting::OXMLDataSourceSetting: invalid type!"); + if (s_aTypeNameMap.end() != aTypePos) + m_aPropType = aTypePos->second; + } + break; + case XML_TOK_DATA_SOURCE_SETTING_NAME: + m_aSetting.Name = sValue; + break; + } + } + +} +// ----------------------------------------------------------------------------- + +OXMLDataSourceSetting::~OXMLDataSourceSetting() +{ + DBG_DTOR(OXMLDataSourceSetting,NULL); +} +// ----------------------------------------------------------------------------- +SvXMLImportContext* OXMLDataSourceSetting::CreateChildContext( + sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const Reference< XAttributeList > & xAttrList ) +{ + SvXMLImportContext *pContext = 0; + const SvXMLTokenMap& rTokenMap = GetOwnImport().GetDataSourceInfoElemTokenMap(); + + switch( rTokenMap.Get( nPrefix, rLocalName ) ) + { + case XML_TOK_DATA_SOURCE_SETTING: + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + pContext = new OXMLDataSourceSetting( GetOwnImport(), nPrefix, rLocalName,xAttrList); + break; + case XML_TOK_DATA_SOURCE_SETTING_VALUE: + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + pContext = new OXMLDataSourceSetting( GetOwnImport(), nPrefix, rLocalName,xAttrList,this ); + break; + } + + if( !pContext ) + pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName ); + + return pContext; +} +// ----------------------------------------------------------------------------- +void OXMLDataSourceSetting::EndElement() +{ + if ( m_aSetting.Name.getLength() ) + { + if ( m_bIsList && m_aInfoSequence.getLength() ) + 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 <<= ::rtl::OUString(); + + GetOwnImport().addInfo(m_aSetting); + } +} +// ----------------------------------------------------------------------------- +void OXMLDataSourceSetting::Characters( const ::rtl::OUString& rChars ) +{ + if ( m_pContainer ) + m_pContainer->addValue(rChars); +} +// ----------------------------------------------------------------------------- +void OXMLDataSourceSetting::addValue(const ::rtl::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[nPos] = aValue; + } +} +// ----------------------------------------------------------------------------- +ODBFilter& OXMLDataSourceSetting::GetOwnImport() +{ + return static_cast<ODBFilter&>(GetImport()); +} +// ----------------------------------------------------------------------------- +Any OXMLDataSourceSetting::convertString(const ::com::sun::star::uno::Type& _rExpectedType, const ::rtl::OUString& _rReadCharacters) +{ + ODBFilter& rImporter = GetOwnImport(); + Any aReturn; + switch (_rExpectedType.getTypeClass()) + { + case TypeClass_BOOLEAN: // sal_Bool + { + bool bValue; + #if OSL_DEBUG_LEVEL > 0 + sal_Bool bSuccess = + #endif + rImporter.GetMM100UnitConverter().convertBool(bValue, _rReadCharacters); + OSL_ENSURE(bSuccess, + ::rtl::OString("OXMLDataSourceSetting::convertString: could not convert \"") + += ::rtl::OString(_rReadCharacters.getStr(), _rReadCharacters.getLength(), RTL_TEXTENCODING_ASCII_US) + += ::rtl::OString("\" 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); + #if OSL_DEBUG_LEVEL > 0 + sal_Bool bSuccess = + #endif + rImporter.GetMM100UnitConverter().convertNumber(nValue, _rReadCharacters); + OSL_ENSURE(bSuccess, + ::rtl::OString("OXMLDataSourceSetting::convertString: could not convert \"") + += ::rtl::OString(_rReadCharacters.getStr(), _rReadCharacters.getLength(), RTL_TEXTENCODING_ASCII_US) + += ::rtl::OString("\" into an integer!")); + if (TypeClass_SHORT == _rExpectedType.getTypeClass()) + aReturn <<= (sal_Int16)nValue; + else + aReturn <<= (sal_Int32)nValue; + break; + } + case TypeClass_HYPER: + { + OSL_FAIL("OXMLDataSourceSetting::convertString: 64-bit integers not implemented yet!"); + } + break; + case TypeClass_DOUBLE: + { + double nValue = 0.0; + #if OSL_DEBUG_LEVEL > 0 + sal_Bool bSuccess = + #endif + rImporter.GetMM100UnitConverter().convertDouble(nValue, _rReadCharacters); + OSL_ENSURE(bSuccess, + ::rtl::OString("OXMLDataSourceSetting::convertString: could not convert \"") + += ::rtl::OString(_rReadCharacters.getStr(), _rReadCharacters.getLength(), RTL_TEXTENCODING_ASCII_US) + += ::rtl::OString("\" into a double!")); + aReturn <<= (double)nValue; + } + break; + case TypeClass_STRING: + aReturn <<= _rReadCharacters; + break; + default: + OSL_FAIL("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 000000000000..4740a7834306 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlDataSourceSetting.hxx @@ -0,0 +1,78 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef DBA_XMLDATASOURCESETTING_HXX +#define DBA_XMLDATASOURCESETTING_HXX + +#include <xmloff/xmlictxt.hxx> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/uno/Sequence.hxx> + +namespace dbaxml +{ + class ODBFilter; + class OXMLDataSource; + class OXMLDataSourceSetting : public SvXMLImportContext + { + ::com::sun::star::beans::PropertyValue m_aSetting; + ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any> m_aInfoSequence; + OXMLDataSourceSetting* m_pContainer; + ::com::sun::star::uno::Type m_aPropType; // the type of the property the instance imports currently + sal_Bool m_bIsList; + + ODBFilter& GetOwnImport(); + ::com::sun::star::uno::Any convertString(const ::com::sun::star::uno::Type& _rExpectedType, const ::rtl::OUString& _rReadCharacters); + public: + + OXMLDataSourceSetting( ODBFilter& rImport, sal_uInt16 nPrfx, + const ::rtl::OUString& rLName, + const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttrList + ,OXMLDataSourceSetting* _pContainer = NULL); + virtual ~OXMLDataSourceSetting(); + + virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttrList ); + + virtual void EndElement(); + + virtual void Characters( const ::rtl::OUString& rChars ); + + + /** adds value to property + @param _sValue + The value to add. + */ + void addValue(const ::rtl::OUString& _sValue); + }; +// ----------------------------------------------------------------------------- +} // namespace dbaxml +// ----------------------------------------------------------------------------- + +#endif // DBA_XMLDATASOURCESETTING_HXX + +/* 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 000000000000..284971fd8a07 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlDataSourceSettings.cxx @@ -0,0 +1,97 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_dbaccess.hxx" +#include "xmlDataSourceSettings.hxx" +#include "xmlDataSourceSetting.hxx" +#include "xmlfilter.hxx" +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmlnmspe.hxx> +#include <xmloff/nmspmap.hxx> +#include "xmlEnums.hxx" +#include "xmlstrings.hrc" +#include <com/sun/star/beans/PropertyValue.hpp> +#include <tools/debug.hxx> + +#include <vector> + +namespace dbaxml +{ + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::xml::sax; +DBG_NAME(OXMLDataSourceSettings) + +OXMLDataSourceSettings::OXMLDataSourceSettings( ODBFilter& rImport + ,sal_uInt16 nPrfx + ,const ::rtl::OUString& _sLocalName) : + SvXMLImportContext( rImport, nPrfx, _sLocalName ) +{ + DBG_CTOR(OXMLDataSourceSettings,NULL); + +} +// ----------------------------------------------------------------------------- + +OXMLDataSourceSettings::~OXMLDataSourceSettings() +{ + + DBG_DTOR(OXMLDataSourceSettings,NULL); +} +// ----------------------------------------------------------------------------- +SvXMLImportContext* OXMLDataSourceSettings::CreateChildContext( + sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const Reference< XAttributeList > & xAttrList ) +{ + SvXMLImportContext *pContext = 0; + const SvXMLTokenMap& rTokenMap = GetOwnImport().GetDataSourceInfoElemTokenMap(); + + switch( rTokenMap.Get( nPrefix, rLocalName ) ) + { + case XML_TOK_DATA_SOURCE_SETTING: + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + pContext = new OXMLDataSourceSetting( GetOwnImport(), nPrefix, rLocalName,xAttrList); + break; + } + + if( !pContext ) + pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName ); + + return pContext; +} +// ----------------------------------------------------------------------------- +ODBFilter& OXMLDataSourceSettings::GetOwnImport() +{ + return static_cast<ODBFilter&>(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 000000000000..67d3f02e432d --- /dev/null +++ b/dbaccess/source/filter/xml/xmlDataSourceSettings.hxx @@ -0,0 +1,54 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef DBA_XMLDATASOURCESETTINGS_HXX +#define DBA_XMLDATASOURCESETTINGS_HXX + +#include <xmloff/xmlictxt.hxx> + +namespace dbaxml +{ + class ODBFilter; + class OXMLDataSourceSettings : public SvXMLImportContext + { + ODBFilter& GetOwnImport(); + public: + + OXMLDataSourceSettings( ODBFilter& rImport, sal_uInt16 nPrfx,const ::rtl::OUString& rLName); + virtual ~OXMLDataSourceSettings(); + + virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttrList ); + }; +// ----------------------------------------------------------------------------- +} // namespace dbaxml +// ----------------------------------------------------------------------------- + +#endif // DBA_XMLDATASOURCESETTINGS_HXX + +/* 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 000000000000..6bb928b2b541 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlDatabase.cxx @@ -0,0 +1,161 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_dbaccess.hxx" +#include "xmlDatabase.hxx" +#include "xmlfilter.hxx" +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmlnmspe.hxx> +#include "xmlDataSource.hxx" +#include "xmlDocuments.hxx" +#include "xmlEnums.hxx" +#include <com/sun/star/sdb/XReportDocumentsSupplier.hpp> +#include <com/sun/star/sdb/XFormDocumentsSupplier.hpp> +#include <com/sun/star/sdbcx/XTablesSupplier.hpp> +#include <com/sun/star/sdb/XQueryDefinitionsSupplier.hpp> +#include "xmlstrings.hrc" +#include <tools/debug.hxx> +#include <connectivity/dbtools.hxx> + +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; +DBG_NAME(OXMLDatabase) + +OXMLDatabase::OXMLDatabase( ODBFilter& rImport, + sal_uInt16 nPrfx, const ::rtl::OUString& rLName ) : + SvXMLImportContext( rImport, nPrfx, rLName ) +{ + DBG_CTOR(OXMLDatabase,NULL); + +} +// ----------------------------------------------------------------------------- + +OXMLDatabase::~OXMLDatabase() +{ + + DBG_DTOR(OXMLDatabase,NULL); +} +// ----------------------------------------------------------------------------- + +SvXMLImportContext* OXMLDatabase::CreateChildContext( + sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const Reference< XAttributeList > & xAttrList ) +{ + SvXMLImportContext *pContext = 0; + const SvXMLTokenMap& rTokenMap = GetOwnImport().GetDatabaseElemTokenMap(); + + switch( rTokenMap.Get( nPrefix, rLocalName ) ) + { + case XML_TOK_DATASOURCE: + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + pContext = new OXMLDataSource( GetOwnImport(), nPrefix, rLocalName, xAttrList, OXMLDataSource::eDataSource ); + break; + case XML_TOK_FORMS: + { + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + Any aValue; + ::rtl::OUString sService; + dbtools::getDataSourceSetting(GetOwnImport().getDataSource(),"Forms",aValue); + aValue >>= sService; + if ( !sService.getLength() ) + { + Reference<XFormDocumentsSupplier> xSup(GetOwnImport().GetModel(),UNO_QUERY); + if ( xSup.is() ) + pContext = new OXMLDocuments( GetOwnImport(), nPrefix, rLocalName,xSup->getFormDocuments(),SERVICE_NAME_FORM_COLLECTION,SERVICE_SDB_DOCUMENTDEFINITION); + } + } + break; + case XML_TOK_REPORTS: + { + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + Any aValue; + ::rtl::OUString sService; + dbtools::getDataSourceSetting(GetOwnImport().getDataSource(),"Reports",aValue); + aValue >>= sService; + if ( !sService.getLength() ) + { + Reference<XReportDocumentsSupplier> xSup(GetOwnImport().GetModel(),UNO_QUERY); + if ( xSup.is() ) + pContext = new OXMLDocuments( GetOwnImport(), nPrefix, rLocalName,xSup->getReportDocuments(),SERVICE_NAME_REPORT_COLLECTION,SERVICE_SDB_DOCUMENTDEFINITION); + } + } + break; + case XML_TOK_QUERIES: + { + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + Any aValue; + ::rtl::OUString sService; + dbtools::getDataSourceSetting(GetOwnImport().getDataSource(),"CommandDefinitions",aValue); + aValue >>= sService; + if ( !sService.getLength() ) + { + Reference<XQueryDefinitionsSupplier> xSup(GetOwnImport().getDataSource(),UNO_QUERY); + if ( xSup.is() ) + pContext = new OXMLDocuments( GetOwnImport(), nPrefix, rLocalName,xSup->getQueryDefinitions(),SERVICE_NAME_QUERY_COLLECTION); + } + } + break; + case XML_TOK_TABLES: + case XML_TOK_SCHEMA_DEFINITION: + { + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + Reference<XTablesSupplier> xSup(GetOwnImport().getDataSource(),UNO_QUERY); + if ( xSup.is() ) + pContext = new OXMLDocuments( GetOwnImport(), nPrefix, rLocalName,xSup->getTables()); + } + break; + } + + if( !pContext ) + pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName ); + + + return pContext; +} +// ----------------------------------------------------------------------------- +ODBFilter& OXMLDatabase::GetOwnImport() +{ + return static_cast<ODBFilter&>(GetImport()); +} +// ----------------------------------------------------------------------------- +void OXMLDatabase::EndElement() +{ + 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 000000000000..ed70500fdca3 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlDatabase.hxx @@ -0,0 +1,57 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef DBA_XMLDATABASE_HXX +#define DBA_XMLDATABASE_HXX + +#include <xmloff/xmlictxt.hxx> + +namespace dbaxml +{ + class ODBFilter; + class OXMLDatabase : public SvXMLImportContext + { + ODBFilter& GetOwnImport(); + public: + + OXMLDatabase( ODBFilter& rImport, sal_uInt16 nPrfx, + const ::rtl::OUString& rLName ); + virtual ~OXMLDatabase(); + + virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttrList ); + + virtual void EndElement(); + }; +// ----------------------------------------------------------------------------- +} // namespace dbaxml +// ----------------------------------------------------------------------------- + +#endif // DBA_XMLDATABASE_HXX + +/* 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 000000000000..73faf3a5a64a --- /dev/null +++ b/dbaccess/source/filter/xml/xmlDatabaseDescription.cxx @@ -0,0 +1,109 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_dbaccess.hxx" +#include "xmlDatabaseDescription.hxx" +#include "xmlLogin.hxx" +#include "xmlfilter.hxx" +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmlnmspe.hxx> +#include <xmloff/nmspmap.hxx> +#include "xmlEnums.hxx" +#include "xmlFileBasedDatabase.hxx" +#include "xmlServerDatabase.hxx" +#include "xmlstrings.hrc" +#include <tools/debug.hxx> +#include <tools/diagnose_ex.h> + +namespace dbaxml +{ + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::xml::sax; +DBG_NAME(OXMLDatabaseDescription) + +OXMLDatabaseDescription::OXMLDatabaseDescription( ODBFilter& rImport, + sal_uInt16 nPrfx, const ::rtl::OUString& _sLocalName) : + SvXMLImportContext( rImport, nPrfx, _sLocalName ) + ,m_bFoundOne(false) +{ + DBG_CTOR(OXMLDatabaseDescription,NULL); +} +// ----------------------------------------------------------------------------- + +OXMLDatabaseDescription::~OXMLDatabaseDescription() +{ + + DBG_DTOR(OXMLDatabaseDescription,NULL); +} +// ----------------------------------------------------------------------------- + +SvXMLImportContext* OXMLDatabaseDescription::CreateChildContext( + sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const Reference< XAttributeList > & xAttrList ) +{ + SvXMLImportContext *pContext = 0; + const SvXMLTokenMap& rTokenMap = GetOwnImport().GetDatabaseDescriptionElemTokenMap(); + + switch( rTokenMap.Get( nPrefix, rLocalName ) ) + { + case XML_TOK_FILE_BASED_DATABASE: + if ( !m_bFoundOne ) + { + m_bFoundOne = true; + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + pContext = new OXMLFileBasedDatabase( GetOwnImport(), nPrefix, rLocalName,xAttrList ); + } + break; + case XML_TOK_SERVER_DATABASE: + if ( !m_bFoundOne ) + { + m_bFoundOne = true; + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + pContext = new OXMLServerDatabase( GetOwnImport(), nPrefix, rLocalName,xAttrList ); + } + break; + } + + if( !pContext ) + pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName ); + + return pContext; +} +// ----------------------------------------------------------------------------- +ODBFilter& OXMLDatabaseDescription::GetOwnImport() +{ + return static_cast<ODBFilter&>(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 000000000000..6a056412e57a --- /dev/null +++ b/dbaccess/source/filter/xml/xmlDatabaseDescription.hxx @@ -0,0 +1,59 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef DBA_XMLDATABASEDESCRIPTION_HXX_INCLUDED +#define DBA_XMLDATABASEDESCRIPTION_HXX_INCLUDED + +#include <xmloff/xmlictxt.hxx> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <vector> + +namespace dbaxml +{ + class ODBFilter; + class OXMLDatabaseDescription : public SvXMLImportContext + { + bool m_bFoundOne; + + ODBFilter& GetOwnImport(); + public: + + OXMLDatabaseDescription( ODBFilter& rImport, sal_uInt16 nPrfx, + const ::rtl::OUString& rLName); + virtual ~OXMLDatabaseDescription(); + + virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttrList ); + }; +// ----------------------------------------------------------------------------- +} // namespace dbaxml +// ----------------------------------------------------------------------------- + +#endif // DBA_XMLDATABASEDESCRIPTION_HXX_INCLUDED + +/* 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 000000000000..259425f2aff0 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlDocuments.cxx @@ -0,0 +1,130 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_dbaccess.hxx" +#include "xmlDocuments.hxx" +#include "xmlfilter.hxx" +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmlnmspe.hxx> +#include "xmlQuery.hxx" +#include "xmlTable.hxx" +#include "xmlComponent.hxx" +#include "xmlHierarchyCollection.hxx" +#include "xmlEnums.hxx" +#include "xmlstrings.hrc" +#include <tools/debug.hxx> + +namespace dbaxml +{ + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::container; + using namespace ::com::sun::star::xml::sax; +DBG_NAME(OXMLDocuments) + +OXMLDocuments::OXMLDocuments( ODBFilter& rImport + ,sal_uInt16 nPrfx + , const ::rtl::OUString& rLName + ,const Reference< XNameAccess >& _xContainer + ,const ::rtl::OUString& _sCollectionServiceName + ,const ::rtl::OUString& _sComponentServiceName) : + SvXMLImportContext( rImport, nPrfx, rLName ) + ,m_xContainer(_xContainer) + ,m_sCollectionServiceName(_sCollectionServiceName) + ,m_sComponentServiceName(_sComponentServiceName) +{ + DBG_CTOR(OXMLDocuments,NULL); + +} +// ----------------------------------------------------------------------------- +OXMLDocuments::OXMLDocuments( ODBFilter& rImport + ,sal_uInt16 nPrfx + , const ::rtl::OUString& rLName + ,const Reference< XNameAccess >& _xContainer + ,const ::rtl::OUString& _sCollectionServiceName + ) : + SvXMLImportContext( rImport, nPrfx, rLName ) + ,m_xContainer(_xContainer) + ,m_sCollectionServiceName(_sCollectionServiceName) +{ + DBG_CTOR(OXMLDocuments,NULL); +} +// ----------------------------------------------------------------------------- + +OXMLDocuments::~OXMLDocuments() +{ + + DBG_DTOR(OXMLDocuments,NULL); +} +// ----------------------------------------------------------------------------- + +SvXMLImportContext* OXMLDocuments::CreateChildContext( + sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const Reference< XAttributeList > & xAttrList ) +{ + SvXMLImportContext *pContext = 0; + const SvXMLTokenMap& rTokenMap = GetOwnImport().GetDocumentsElemTokenMap(); + + switch( rTokenMap.Get( nPrefix, rLocalName ) ) + { + case XML_TOK_TABLE: + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + pContext = new OXMLTable( GetOwnImport(), nPrefix, rLocalName,xAttrList,m_xContainer,SERVICE_SDB_TABLEDEFINITION); + break; + case XML_TOK_QUERY: + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + pContext = new OXMLQuery( GetOwnImport(), nPrefix, rLocalName,xAttrList,m_xContainer ); + break; + case XML_TOK_COMPONENT: + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + pContext = new OXMLComponent( GetOwnImport(), nPrefix, rLocalName,xAttrList,m_xContainer,m_sComponentServiceName ); + break; + case XML_TOK_COMPONENT_COLLECTION: + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + pContext = new OXMLHierarchyCollection( GetOwnImport(), nPrefix, rLocalName,xAttrList,m_xContainer,m_sCollectionServiceName,m_sComponentServiceName ); + break; + } + + if( !pContext ) + pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName ); + + + return pContext; +} +// ----------------------------------------------------------------------------- +ODBFilter& OXMLDocuments::GetOwnImport() +{ + return static_cast<ODBFilter&>(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 000000000000..1a84dfa4c94e --- /dev/null +++ b/dbaccess/source/filter/xml/xmlDocuments.hxx @@ -0,0 +1,76 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef DBA_XMLDOCUMENTS_HXX +#define DBA_XMLDOCUMENTS_HXX + +#include <xmloff/xmlictxt.hxx> +#include "xmlEnums.hxx" +#include <com/sun/star/container/XNameAccess.hpp> + +namespace dbaxml +{ + class ODBFilter; + class OXMLDocuments : public SvXMLImportContext + { + private: + ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > m_xContainer; + ::rtl::OUString m_sCollectionServiceName; + ::rtl::OUString m_sComponentServiceName; + + ODBFilter& GetOwnImport(); + public: + + // for forms and reports + OXMLDocuments( ODBFilter& rImport + ,sal_uInt16 nPrfx + ,const ::rtl::OUString& rLName + ,const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& _xContainer + ,const ::rtl::OUString& _sCollectionServiceName + ,const ::rtl::OUString& _sComponentServiceName); + + // for queries + OXMLDocuments( ODBFilter& rImport + ,sal_uInt16 nPrfx + ,const ::rtl::OUString& rLName + ,const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& _xContainer + ,const ::rtl::OUString& _sCollectionServiceName = ::rtl::OUString() + ); + + virtual ~OXMLDocuments(); + + virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttrList ); + }; +// ----------------------------------------------------------------------------- +} // namespace dbaxml +// ----------------------------------------------------------------------------- + +#endif // DBA_XMLDOCUMENTS_HXX + +/* 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 000000000000..2248050d09b3 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlEnums.hxx @@ -0,0 +1,175 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef DBA_XMLENUMS_HXX +#define DBA_XMLENUMS_HXX + +#define PROGRESS_BAR_STEP 20 + +namespace dbaxml +{ + enum XMLDocTokens + { + XML_TOK_DOC_AUTOSTYLES, + XML_TOK_DOC_SETTINGS, + XML_TOK_DOC_DATABASE, + XML_TOK_DOC_STYLES, + XML_TOK_DOC_SCRIPT + }; + enum XMLDatabaseToken + { + XML_TOK_DATASOURCE, + XML_TOK_FORMS, + XML_TOK_REPORTS, + XML_TOK_QUERIES, + XML_TOK_TABLES, + XML_TOK_SCHEMA_DEFINITION + }; + enum XMLDataSource + { + XML_TOK_CONNECTION_RESOURCE, + XML_TOK_SUPPRESS_VERSION_COLUMNS, + XML_TOK_JAVA_DRIVER_CLASS, + XML_TOK_EXTENSION, + XML_TOK_IS_FIRST_ROW_HEADER_LINE, + XML_TOK_SHOW_DELETED, + XML_TOK_IS_TABLE_NAME_LENGTH_LIMITED, + XML_TOK_SYSTEM_DRIVER_SETTINGS, + XML_TOK_ENABLE_SQL92_CHECK, + XML_TOK_APPEND_TABLE_ALIAS_NAME, + XML_TOK_PARAMETER_NAME_SUBSTITUTION, + XML_TOK_IGNORE_DRIVER_PRIVILEGES, + XML_TOK_BOOLEAN_COMPARISON_MODE, + XML_TOK_USE_CATALOG, + XML_TOK_BASE_DN, + XML_TOK_MAX_ROW_COUNT, + XML_TOK_LOGIN, + XML_TOK_TABLE_FILTER, + XML_TOK_TABLE_TYPE_FILTER, + XML_TOK_AUTO_INCREMENT, + XML_TOK_DELIMITER, + XML_TOK_DATA_SOURCE_SETTINGS, + XML_TOK_FONT_CHARSET, + XML_TOK_ENCODING, + XML_TOK_DATABASE_DESCRIPTION, + XML_TOK_COMPOUND_DATABASE, + XML_TOK_DB_HREF, + XML_TOK_MEDIA_TYPE, + XML_TOK_DB_TYPE, + XML_TOK_HOSTNAME, + XML_TOK_PORT, + XML_TOK_LOCAL_SOCKET, + XML_TOK_DATABASE_NAME, + XML_TOK_CONNECTION_DATA, + XML_TOK_DRIVER_SETTINGS, + XML_TOK_JAVA_CLASSPATH, + XML_TOK_CHARACTER_SET, + XML_TOK_APPLICATION_CONNECTION_SETTINGS + }; + enum XMLDatabaseDescription + { + XML_TOK_FILE_BASED_DATABASE, + XML_TOK_SERVER_DATABASE + }; + enum XMLLogin + { + XML_TOK_USER_NAME, + XML_TOK_IS_PASSWORD_REQUIRED, + XML_TOK_USE_SYSTEM_USER, + XML_TOK_LOGIN_TIMEOUT + }; + enum XMLDataSourceInfo + { + XML_TOK_STRING, + XML_TOK_FIELD, + XML_TOK_DECIMAL, + XML_TOK_THOUSAND, + XML_TOK_ADDITIONAL_COLUMN_STATEMENT, + XML_TOK_ROW_RETRIEVING_STATEMENT, + XML_TOK_DATA_SOURCE_SETTING, + XML_TOK_DATA_SOURCE_SETTING_VALUE, + XML_TOK_DATA_SOURCE_SETTING_IS_LIST, + XML_TOK_DATA_SOURCE_SETTING_TYPE, + XML_TOK_DATA_SOURCE_SETTING_NAME + }; + enum XMLDocuments + { + XML_TOK_COMPONENT, + XML_TOK_COMPONENT_COLLECTION, + XML_TOK_QUERY_COLLECTION, + XML_TOK_QUERY, + XML_TOK_TABLE, + XML_TOK_COLUMN + }; + enum XMLComponent + { + XML_TOK_HREF , + XML_TOK_TYPE , + XML_TOK_SHOW , + XML_TOK_ACTUATE , + XML_TOK_AS_TEMPLATE , + XML_TOK_COMPONENT_NAME + }; + enum XMLType + { + XML_TYPE_FORMS, + XML_TYPE_REPORTS, + XML_TYPE_QUERIES, + XML_TYPE_TABLES + }; + enum XMLQueryTable + { + XML_TOK_QUERY_NAME, + XML_TOK_COMMAND, + XML_TOK_ESCAPE_PROCESSING, + XML_TOK_FILTER_STATEMENT, + XML_TOK_ORDER_STATEMENT, + XML_TOK_UPDATE_TABLE, + XML_TOK_CATALOG_NAME, + XML_TOK_SCHEMA_NAME, + XML_TOK_STYLE_NAME, + XML_TOK_APPLY_FILTER, + XML_TOK_APPLY_ORDER, + XML_TOK_COLUMNS + }; + enum XMLColumn + { + XML_TOK_COLUMN_NAME, + XML_TOK_COLUMN_STYLE_NAME, + XML_TOK_COLUMN_HELP_MESSAGE, + XML_TOK_COLUMN_VISIBILITY, + XML_TOK_COLUMN_DEFAULT_VALUE, + XML_TOK_COLUMN_TYPE_NAME, + XML_TOK_COLUMN_VISIBLE, + XML_TOK_DEFAULT_CELL_STYLE_NAME + }; +// ----------------------------------------------------------------------------- +} // namespace dbaxml +// ----------------------------------------------------------------------------- +#endif // DBA_XMLENUMS_HXX + +/* 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 000000000000..6ca38bb37f89 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlExport.cxx @@ -0,0 +1,1454 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_dbaccess.hxx" + +#include "xmlExport.hxx" +#include "xmlAutoStyle.hxx" +#include "flt_reghelper.hxx" +#include <xmloff/ProgressBarHelper.hxx> +#include <xmloff/xmltoken.hxx> +#include <xmloff/txtimp.hxx> +#include <xmloff/xmlnmspe.hxx> +#include <xmloff/xmluconv.hxx> +#include <xmloff/nmspmap.hxx> +#include <comphelper/types.hxx> +#include "xmlstrings.hrc" +#include "xmlEnums.hxx" +#include <xmloff/nmspmap.hxx> +#include <com/sun/star/beans/XPropertyState.hpp> +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <com/sun/star/sdb/XFormDocumentsSupplier.hpp> +#include <com/sun/star/sdb/XOfficeDatabaseDocument.hpp> +#include <com/sun/star/sdb/XReportDocumentsSupplier.hpp> +#include <com/sun/star/sdb/XQueryDefinitionsSupplier.hpp> +#include <com/sun/star/sdbcx/XTablesSupplier.hpp> +#include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp> + +#include <com/sun/star/awt/TextAlign.hpp> +#include <xmloff/xmluconv.hxx> +#include "xmlHelper.hxx" +#include <com/sun/star/awt/FontDescriptor.hpp> +#include <svl/filenotation.hxx> +#include <unotools/pathoptions.hxx> +#include <tools/diagnose_ex.h> +#include <connectivity/DriversConfig.hxx> +#include <connectivity/dbtools.hxx> +#include <sal/macros.h> + +#include <boost/optional.hpp> + +namespace dbaxml +{ + 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; + + class ODBExportHelper + { + public: + static ::rtl::OUString SAL_CALL getImplementationName_Static( ) throw (RuntimeException); + static Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames_Static( ) throw(RuntimeException); + static Reference< XInterface > SAL_CALL Create(const Reference< ::com::sun::star::lang::XMultiServiceFactory >&); + }; + class ODBFullExportHelper + { + public: + static ::rtl::OUString SAL_CALL getImplementationName_Static( ) throw (RuntimeException); + static Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames_Static( ) throw(RuntimeException); + static Reference< XInterface > SAL_CALL Create(const Reference< ::com::sun::star::lang::XMultiServiceFactory >&); + }; +} +// ----------------------------------------------------------------------------- +extern "C" void SAL_CALL createRegistryInfo_ODBFilterExport( ) +{ + static ::dbaxml::OMultiInstanceAutoRegistration< ::dbaxml::ODBExport > aAutoRegistration; +} +//-------------------------------------------------------------------------- +extern "C" void SAL_CALL createRegistryInfo_OSettingsExport( ) +{ + static ::dbaxml::OMultiInstanceAutoRegistration< ::dbaxml::ODBExportHelper > aAutoRegistration; +} +//-------------------------------------------------------------------------- +extern "C" void SAL_CALL createRegistryInfo_OFullExport( ) +{ + static ::dbaxml::OMultiInstanceAutoRegistration< ::dbaxml::ODBFullExportHelper > aAutoRegistration; +} +//-------------------------------------------------------------------------- +namespace dbaxml +{ + using namespace comphelper; + using namespace ::com::sun::star::sdb; + using namespace ::com::sun::star::sdbcx; + using namespace ::com::sun::star::util; + + //--------------------------------------------------------------------- + Reference< XInterface > SAL_CALL ODBExportHelper::Create(const Reference< XMultiServiceFactory >& _rxORB) + { + return static_cast< XServiceInfo* >(new ODBExport(_rxORB,EXPORT_SETTINGS | EXPORT_PRETTY )); + } + //--------------------------------------------------------------------- + ::rtl::OUString SAL_CALL ODBExportHelper::getImplementationName_Static( ) throw (RuntimeException) + { + return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.sdb.XMLSettingsExporter")); + } + //--------------------------------------------------------------------- + Sequence< ::rtl::OUString > SAL_CALL ODBExportHelper::getSupportedServiceNames_Static( ) throw(RuntimeException) + { + Sequence< ::rtl::OUString > aSupported(1); + aSupported[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.document.ExportFilter")); + return aSupported; + } + + + //--------------------------------------------------------------------- + Reference< XInterface > SAL_CALL ODBFullExportHelper::Create(const Reference< XMultiServiceFactory >& _rxORB) + { + return static_cast< XServiceInfo* >(new ODBExport(_rxORB,EXPORT_ALL)); + } + //--------------------------------------------------------------------- + ::rtl::OUString SAL_CALL ODBFullExportHelper::getImplementationName_Static( ) throw (RuntimeException) + { + return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.sdb.XMLFullExporter")); + } + //--------------------------------------------------------------------- + Sequence< ::rtl::OUString > SAL_CALL ODBFullExportHelper::getSupportedServiceNames_Static( ) throw(RuntimeException) + { + Sequence< ::rtl::OUString > aSupported(1); + aSupported[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.document.ExportFilter")); + return aSupported; + } + + //--------------------------------------------------------------------- + ::rtl::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) + static const ::rtl::OUString s_sTypeBoolean (RTL_CONSTASCII_USTRINGPARAM("boolean")); + static const ::rtl::OUString s_sTypeShort (RTL_CONSTASCII_USTRINGPARAM("short")); + static const ::rtl::OUString s_sTypeInteger (RTL_CONSTASCII_USTRINGPARAM("int")); + static const ::rtl::OUString s_sTypeLong (RTL_CONSTASCII_USTRINGPARAM("long")); + static const ::rtl::OUString s_sTypeDouble (RTL_CONSTASCII_USTRINGPARAM("double")); + static const ::rtl::OUString s_sTypeString (RTL_CONSTASCII_USTRINGPARAM("string")); + + // handle the type description + switch (_rType.getTypeClass()) + { + case TypeClass_STRING: + return s_sTypeString; + case TypeClass_DOUBLE: + return s_sTypeDouble; + case TypeClass_BOOLEAN: + return s_sTypeBoolean; + case TypeClass_BYTE: + case TypeClass_SHORT: + return s_sTypeShort; + case TypeClass_LONG: + return s_sTypeInteger; + case TypeClass_HYPER: + return s_sTypeLong; + case TypeClass_ENUM: + return s_sTypeInteger; + + default: + OSL_FAIL( "lcl_implGetPropertyXMLType: unsupported value type!" ); + return s_sTypeDouble; + } + } + + class OSpecialHanldeXMLExportPropertyMapper : public SvXMLExportPropertyMapper + { + public: + OSpecialHanldeXMLExportPropertyMapper(const UniReference< 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 + { + // nothing to do here + } + }; +// ----------------------------------------------------------------------------- +ODBExport::ODBExport(const Reference< XMultiServiceFactory >& _rxMSF,sal_uInt16 nExportFlag) +: SvXMLExport( _rxMSF,MAP_10TH_MM,XML_DATABASE, EXPORT_OASIS | nExportFlag) +,m_aTypeCollection(_rxMSF) +,m_bAllreadyFilled(sal_False) +{ + GetMM100UnitConverter().setCoreMeasureUnit(MAP_10TH_MM); + GetMM100UnitConverter().setXMLMeasureUnit(MAP_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 & (EXPORT_STYLES|EXPORT_MASTERSTYLES|EXPORT_AUTOSTYLES|EXPORT_FONTDECLS) ) != 0 ) + _GetNamespaceMap().Add( GetXMLToken(XML_NP_FO), GetXMLToken(XML_N_FO_COMPAT), XML_NAMESPACE_FO ); + + if( (nExportFlag & (EXPORT_META|EXPORT_STYLES|EXPORT_MASTERSTYLES|EXPORT_AUTOSTYLES|EXPORT_CONTENT|EXPORT_SCRIPTS|EXPORT_SETTINGS) ) != 0 ) + { + _GetNamespaceMap().Add( GetXMLToken(XML_NP_XLINK), GetXMLToken(XML_N_XLINK), XML_NAMESPACE_XLINK ); + } + if( (nExportFlag & EXPORT_SETTINGS) != 0 ) + { + _GetNamespaceMap().Add( GetXMLToken(XML_NP_CONFIG), GetXMLToken(XML_N_CONFIG), XML_NAMESPACE_CONFIG ); + } + + if( (nExportFlag & (EXPORT_STYLES|EXPORT_MASTERSTYLES|EXPORT_AUTOSTYLES|EXPORT_CONTENT|EXPORT_FONTDECLS) ) != 0 ) + { + _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 OSpecialHanldeXMLExportPropertyMapper(GetColumnStylesPropertySetMapper()); + + m_xCellExportHelper = new OSpecialHanldeXMLExportPropertyMapper(GetCellStylesPropertySetMapper()); + m_xRowExportHelper = new OSpecialHanldeXMLExportPropertyMapper(OXMLHelper::GetRowStylesPropertySetMapper()); + + GetAutoStylePool()->AddFamily( + XML_STYLE_FAMILY_TABLE_TABLE, + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( XML_STYLE_FAMILY_TABLE_TABLE_STYLES_NAME )), + m_xExportHelper.get(), + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( XML_STYLE_FAMILY_TABLE_TABLE_STYLES_PREFIX ))); + + GetAutoStylePool()->AddFamily( + XML_STYLE_FAMILY_TABLE_COLUMN, + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( XML_STYLE_FAMILY_TABLE_COLUMN_STYLES_NAME )), + m_xColumnExportHelper.get(), + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( XML_STYLE_FAMILY_TABLE_COLUMN_STYLES_PREFIX ))); + + GetAutoStylePool()->AddFamily( + XML_STYLE_FAMILY_TABLE_CELL, + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( XML_STYLE_FAMILY_TABLE_CELL_STYLES_NAME )), + m_xCellExportHelper.get(), + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( XML_STYLE_FAMILY_TABLE_CELL_STYLES_PREFIX ))); + + GetAutoStylePool()->AddFamily( + XML_STYLE_FAMILY_TABLE_ROW, + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( XML_STYLE_FAMILY_TABLE_ROW_STYLES_NAME )), + m_xRowExportHelper.get(), + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( XML_STYLE_FAMILY_TABLE_ROW_STYLES_PREFIX ))); +} +// ----------------------------------------------------------------------------- +IMPLEMENT_SERVICE_INFO1_STATIC( ODBExport, "com.sun.star.comp.sdb.DBExportFilter", "com.sun.star.document.ExportFilter") +// ----------------------------------------------------------------------------- +void ODBExport::exportDataSource() +{ + try + { + Reference<XPropertySet> xProp( getDataSource(), UNO_SET_THROW ); + + sal_Bool bAutoIncrementEnabled = sal_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(getServiceFactory()); + const ::rtl::OUString sURL = ::comphelper::getString(xProp->getPropertyValue(PROPERTY_URL)); + ::comphelper::NamedValueCollection aDriverSupportedProperties( aDriverConfig.getProperties( sURL ) ); + + static ::rtl::OUString s_sTrue(::xmloff::token::GetXMLToken( XML_TRUE )); + static ::rtl::OUString s_sFalse(::xmloff::token::GetXMLToken( XML_FALSE )); + // loop through the properties, and export only those which are not defaulted + TSettingsMap aSettingsMap; + Sequence< Property > aProperties = xSettingsInfo->getProperties(); + const Property* pProperties = aProperties.getConstArray(); + const Property* pPropertiesEnd = pProperties + aProperties.getLength(); + for ( ; pProperties != pPropertiesEnd; ++pProperties ) + { + ::rtl::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 = ::rtl::OUString::valueOf( 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 = ::rtl::OUString::valueOf( getINT32( aValue ) ); + break; + default: + break; + } + + ::xmloff::token::XMLTokenEnum eToken = XML_TOKEN_INVALID; + + struct PropertyMap + { + const ::rtl::OUString sPropertyName; + const XMLTokenEnum eAttributeToken; + const ::boost::optional< ::rtl::OUString > aXMLDefault; + + PropertyMap( const ::rtl::OUString& _rPropertyName, const XMLTokenEnum _eToken ) + :sPropertyName( _rPropertyName ) + ,eAttributeToken( _eToken ) + ,aXMLDefault() + { + } + + PropertyMap( const ::rtl::OUString& _rPropertyName, const XMLTokenEnum _eToken, const ::rtl::OUString& _rDefault ) + :sPropertyName( _rPropertyName ) + ,eAttributeToken( _eToken ) + ,aXMLDefault( _rDefault ) + { + } + }; + + 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( PROPERTY_SUPPRESSVERSIONCL,XML_SUPPRESS_VERSION_COLUMNS, s_sTrue ), + PropertyMap( INFO_CONN_LDAP_BASEDN, XML_BASE_DN ), + PropertyMap( INFO_CONN_LDAP_ROWCOUNT, XML_MAX_ROW_COUNT ) + }; + + bool bIsXMLDefault = false; + for ( size_t i=0; i < SAL_N_ELEMENTS( aTokens ); ++i ) + { + if ( pProperties->Name == aTokens[i].sPropertyName ) + { + eToken = aTokens[i].eAttributeToken; + + if ( !!aTokens[i].aXMLDefault + && ( sValue == *aTokens[i].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 REMOVEABLE, we care for their state, and + // only export them if they're not DEFAULTed + if ( ( pProperties->Attributes & PropertyAttribute::REMOVEABLE ) == 0 ) + { + PropertyState ePropertyState = xSettingsState->getPropertyState( pProperties->Name ); + if ( PropertyState_DEFAULT_VALUE == ePropertyState ) + continue; + } + + // special handlings + if ( pProperties->Name == PROPERTY_BOOLEANCOMPARISONMODE ) + { + sal_Int32 nValue = 0; + aValue >>= nValue; + if ( sValue.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("0")) ) + sValue = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("equal-integer")); + else if ( sValue.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("1")) ) + sValue = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("is-boolean")); + else if ( sValue.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("2")) ) + sValue = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("equal-boolean")); + else if ( sValue.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("3")) ) + sValue = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("equal-use-only-zero")); + if ( sValue.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("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.push_back( TypedPropertyValue( + pProperties->Name, pProperties->Type, aValue ) ); + } + continue; + } + } + + aSettingsMap.insert(TSettingsMap::value_type(eToken,sValue)); + } + if ( bAutoIncrementEnabled && (aAutoIncrement.first.getLength() || aAutoIncrement.second.getLength()) ) + m_aAutoIncrement.reset( new TStringPair(aAutoIncrement)); + if ( aDelimiter.bUsed ) + m_aDelimiter.reset( new TDelimiter( aDelimiter ) ); + + SvXMLElementExport aElem(*this,XML_NAMESPACE_DB, XML_DATASOURCE, sal_True, sal_True); + + exportConnectionData(); + exportDriverSettings(aSettingsMap); + exportApplicationConnectionSettings(aSettingsMap); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } +} +// ----------------------------------------------------------------------------- +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 (size_t i = 0; i< SAL_N_ELEMENTS(pSettings); ++i) + { + TSettingsMap::const_iterator aFind = _aSettings.find(pSettings[i]); + if ( aFind != _aSettings.end() ) + AddAttribute(XML_NAMESPACE_DB, aFind->first,aFind->second); + } + SvXMLElementExport aElem(*this,XML_NAMESPACE_DB, XML_APPLICATION_CONNECTION_SETTINGS, sal_True, sal_True); + + Reference<XPropertySet> xProp(getDataSource()); + Sequence< ::rtl::OUString> aValue; + xProp->getPropertyValue(PROPERTY_TABLEFILTER) >>= aValue; + if ( aValue.getLength() ) + { + SvXMLElementExport aElem2(*this,XML_NAMESPACE_DB, XML_TABLE_FILTER, sal_True, sal_True); + exportSequence(aValue,XML_TABLE_INCLUDE_FILTER,XML_TABLE_FILTER_PATTERN); + } + + xProp->getPropertyValue(PROPERTY_TABLETYPEFILTER) >>= aValue; + if ( aValue.getLength() ) + 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 (size_t i = 0; i< SAL_N_ELEMENTS(pSettings); ++i) + { + TSettingsMap::const_iterator aFind = _aSettings.find(pSettings[i]); + if ( aFind != _aSettings.end() ) + AddAttribute(XML_NAMESPACE_DB, aFind->first,aFind->second); + } + SvXMLElementExport aElem(*this,XML_NAMESPACE_DB, XML_DRIVER_SETTINGS, sal_True, sal_True); + exportAutoIncrement(); + exportDelimiter(); + exportCharSet(); +} +// ----------------------------------------------------------------------------- +void ODBExport::exportConnectionData() +{ + SvXMLElementExport aConnData(*this,XML_NAMESPACE_DB, XML_CONNECTION_DATA, sal_True, sal_True); + + { + ::rtl::OUString sValue; + Reference<XPropertySet> xProp(getDataSource()); + xProp->getPropertyValue(PROPERTY_URL) >>= sValue; + if ( m_aTypeCollection.isFileSystemBased(sValue) ) + { + SvXMLElementExport aDatabaseDescription(*this,XML_NAMESPACE_DB, XML_DATABASE_DESCRIPTION, sal_True, sal_True); + { + SvtPathOptions aPathOptions; + const String sOrigUrl = m_aTypeCollection.cutPrefix(sValue); + String sFileName = aPathOptions.SubstituteVariable(sOrigUrl); + if ( sOrigUrl == sFileName ) + { + ::svt::OFileNotation aTransformer( sFileName ); + ::rtl::OUStringBuffer sURL( aTransformer.get( ::svt::OFileNotation::N_URL ) ); + if ( sURL.charAt(sURL.getLength()-1) != '/' ) + sURL.append(sal_Unicode('/')); + + 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 + { + ::rtl::OUString sExtension; + if ( eType == dbaccess::DST_MSACCESS ) + sExtension = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("mdb")); + else + { + Reference< XPropertySet > xDataSourceSettings; + OSL_VERIFY( xProp->getPropertyValue( PROPERTY_SETTINGS ) >>= xDataSourceSettings ); + xDataSourceSettings->getPropertyValue( INFO_TEXTFILEEXTENSION ) >>= sExtension; + } + if ( sExtension.getLength() ) + AddAttribute(XML_NAMESPACE_DB,XML_EXTENSION,sExtension); + } + catch(const Exception&) + { + } + SvXMLElementExport aFileBasedDB(*this,XML_NAMESPACE_DB, XML_FILE_BASED_DATABASE, sal_True, sal_True); + } + } + else + { + String sDatabaseName,sHostName; + sal_Int32 nPort = -1; + m_aTypeCollection.extractHostNamePort(sValue,sDatabaseName,sHostName,nPort); + if ( sHostName.Len() ) + { + SvXMLElementExport aDatabaseDescription(*this,XML_NAMESPACE_DB, XML_DATABASE_DESCRIPTION, sal_True, sal_True); + { + String sType = m_aTypeCollection.getPrefix(sValue); + sType.EraseTrailingChars(':'); + AddAttribute(XML_NAMESPACE_DB,XML_TYPE,sType); + AddAttribute(XML_NAMESPACE_DB,XML_HOSTNAME,sHostName); + if ( nPort != -1 ) + AddAttribute(XML_NAMESPACE_DB,XML_PORT,::rtl::OUString::valueOf(nPort)); + if ( sDatabaseName.Len() ) + 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 ); + + struct PropertyMap + { + const sal_Char* pAsciiPropertyName; + sal_uInt16 nAttributeId; + + PropertyMap() :pAsciiPropertyName( NULL ), nAttributeId(0) { } + PropertyMap( const sal_Char* _pAsciiPropertyName, const sal_uInt16 _nAttributeId ) + :pAsciiPropertyName( _pAsciiPropertyName ) + ,nAttributeId( _nAttributeId ) + { + } + }; + PropertyMap aProperties[] = + { + PropertyMap( "LocalSocket", XML_LOCAL_SOCKET ) + //PropertyMap( "NamedPipe", 0 /* TODO */ ) + }; + + for ( size_t i=0; + i < SAL_N_ELEMENTS( aProperties ); + ++i + ) + { + const ::rtl::OUString sPropertyName = ::rtl::OUString::createFromAscii( aProperties[i].pAsciiPropertyName ); + if ( xSettingsInfo->hasPropertyByName( sPropertyName ) ) + { + ::rtl::OUString sPropertyValue; + if ( ( xDataSourceSettings->getPropertyValue( sPropertyName ) >>= sPropertyValue ) && sPropertyValue.getLength() ) + AddAttribute( XML_NAMESPACE_DB, XML_LOCAL_SOCKET, sPropertyValue ); + + } + } + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + + SvXMLElementExport aServerDB(*this,XML_NAMESPACE_DB, XML_SERVER_DATABASE, sal_True, sal_True); + } + } + else + { + AddAttribute(XML_NAMESPACE_XLINK, XML_HREF,sValue); + SvXMLElementExport aElem(*this,XML_NAMESPACE_DB, XML_CONNECTION_RESOURCE, sal_True, sal_True); + } + } + + } + + exportLogin(); +} +// ----------------------------------------------------------------------------- +void ODBExport::exportDataSourceSettings() +{ + if ( m_aDataSourceSettings.empty() ) + return; + + SvXMLElementExport aElem(*this,XML_NAMESPACE_DB, XML_DATA_SOURCE_SETTINGS, sal_True, sal_True); + ::std::vector< TypedPropertyValue >::iterator aIter = m_aDataSourceSettings.begin(); + ::std::vector< TypedPropertyValue >::iterator aEnd = m_aDataSourceSettings.end(); + for ( ; aIter != aEnd; ++aIter ) + { + sal_Bool bIsSequence = TypeClass_SEQUENCE == aIter->Type.getTypeClass(); + + Type aSimpleType; + if ( bIsSequence ) + aSimpleType = ::comphelper::getSequenceElementType( aIter->Value.getValueType() ); + else + aSimpleType = 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 ); + + ::rtl::OUString sTypeName = lcl_implGetPropertyXMLType( aSimpleType ); + if ( bIsSequence && aSimpleType.getTypeClass() == TypeClass_ANY ) + { + Sequence<Any> aSeq; + aIter->Value >>= aSeq; + if ( aSeq.getLength() ) + 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, sal_True, sal_True ); + + if ( !bIsSequence ) + { + SvXMLElementExport aDataValue( *this, XML_NAMESPACE_DB, XML_DATA_SOURCE_SETTING_VALUE, sal_True, sal_False ); + // (no whitespace inside the tag) + Characters( implConvertAny( aIter->Value ) ); + } + else + { + // the not-that-simple case, we need to iterate through the sequence elements + ::std::auto_ptr<IIterator> pSequenceIterator; + switch (aSimpleType.getTypeClass()) + { + case TypeClass_STRING: + pSequenceIterator.reset( new OSequenceIterator< ::rtl::OUString >( aIter->Value ) ); + break; + case TypeClass_DOUBLE: + pSequenceIterator.reset( new OSequenceIterator< double >( aIter->Value ) ); + break; + case TypeClass_BOOLEAN: + pSequenceIterator.reset( new OSequenceIterator< sal_Bool >( aIter->Value ) ); + break; + case TypeClass_BYTE: + pSequenceIterator.reset( new OSequenceIterator< sal_Int8 >( aIter->Value ) ); + break; + case TypeClass_SHORT: + pSequenceIterator.reset( new OSequenceIterator< sal_Int16 >( aIter->Value ) ); + break; + case TypeClass_LONG: + pSequenceIterator.reset( new OSequenceIterator< sal_Int32 >( aIter->Value ) ); + break; + case TypeClass_ANY: + pSequenceIterator.reset( new OSequenceIterator< Any >( aIter->Value ) ); + break; + default: + OSL_FAIL("unsupported sequence type !"); + break; + } + if ( pSequenceIterator.get() ) + { + ::rtl::OUString sCurrent; + while (pSequenceIterator->hasMoreElements()) + { + SvXMLElementExport aDataValue(*this,XML_NAMESPACE_DB, XML_DATA_SOURCE_SETTING_VALUE, sal_True, sal_False); + // (no whitespace inside the tag) + Characters(implConvertAny(pSequenceIterator->nextElement())); + } + } + } + } +} +// ----------------------------------------------------------------------------- +void ODBExport::exportCharSet() +{ + if ( m_sCharSet.getLength() ) + { + AddAttribute(XML_NAMESPACE_DB, XML_ENCODING,m_sCharSet); + + SvXMLElementExport aElem(*this,XML_NAMESPACE_DB, XML_FONT_CHARSET, sal_True, sal_True); + } +} +// ----------------------------------------------------------------------------- +void ODBExport::exportDelimiter() +{ + if ( m_aDelimiter.get() && 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, sal_True, sal_True); + } +} +// ----------------------------------------------------------------------------- +void ODBExport::exportAutoIncrement() +{ + if ( m_aAutoIncrement.get() ) + { + 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, sal_True, sal_True); + } +} +// ----------------------------------------------------------------------------- +void ODBExport::exportSequence(const Sequence< ::rtl::OUString>& _aValue + ,::xmloff::token::XMLTokenEnum _eTokenFilter + ,::xmloff::token::XMLTokenEnum _eTokenType) +{ + Reference<XPropertySet> xProp(getDataSource()); + Sequence< ::rtl::OUString> aValue; + if ( _aValue.getLength() ) + { + SvXMLElementExport aElem(*this,XML_NAMESPACE_DB, _eTokenFilter, sal_True, sal_True); + + const ::rtl::OUString* pIter = _aValue.getConstArray(); + const ::rtl::OUString* pEnd = pIter + _aValue.getLength(); + for(;pIter != pEnd;++pIter) + { + SvXMLElementExport aDataSource(*this,XML_NAMESPACE_DB, _eTokenType, sal_True, sal_False); + Characters(*pIter); + } + } +} +// ----------------------------------------------------------------------------- +void ODBExport::exportLogin() +{ + Reference<XPropertySet> xProp(getDataSource()); + ::rtl::OUString sValue; + xProp->getPropertyValue(PROPERTY_USER) >>= sValue; + sal_Bool bAddLogin = sValue.getLength() > 0; + if ( bAddLogin ) + AddAttribute(XML_NAMESPACE_DB, XML_USER_NAME,sValue); + sal_Bool bValue = sal_False; + if ( xProp->getPropertyValue(PROPERTY_ISPASSWORDREQUIRED) >>= bValue ) + { + bAddLogin = sal_True; + AddAttribute(XML_NAMESPACE_DB, XML_IS_PASSWORD_REQUIRED,bValue ? XML_TRUE : XML_FALSE); + } + if ( bAddLogin ) + SvXMLElementExport aElem(*this,XML_NAMESPACE_DB, XML_LOGIN, sal_True, sal_True); +} +// ----------------------------------------------------------------------------- +void ODBExport::exportCollection(const Reference< XNameAccess >& _xCollection + ,enum ::xmloff::token::XMLTokenEnum _eComponents + ,enum ::xmloff::token::XMLTokenEnum _eSubComponents + ,sal_Bool _bExportContext + ,const ::comphelper::mem_fun1_t<ODBExport,XPropertySet* >& _aMemFunc + ) +{ + if ( _xCollection.is() ) + { + ::std::auto_ptr<SvXMLElementExport> pComponents; + if ( _bExportContext ) + pComponents.reset( new SvXMLElementExport(*this,XML_NAMESPACE_DB, _eComponents, sal_True, sal_True)); + Sequence< ::rtl::OUString> aSeq = _xCollection->getElementNames(); + const ::rtl::OUString* pIter = aSeq.getConstArray(); + const ::rtl::OUString* pEnd = pIter + aSeq.getLength(); + for(;pIter != pEnd;++pIter) + { + Reference<XPropertySet> 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) +{ + ::rtl::OUString sValue; + _xProp->getPropertyValue(PROPERTY_PERSISTENT_NAME) >>= sValue; + sal_Bool bIsForm = sal_True; + _xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IsForm"))) >>= bIsForm; + if ( bIsForm ) + sValue = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("forms/")) + sValue; + else + sValue = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("reports/")) + sValue; + + AddAttribute(XML_NAMESPACE_XLINK, XML_HREF,sValue); + sal_Bool bAsTemplate = sal_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, sal_True, sal_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, sal_True, sal_True); + Reference<XColumnsSupplier> xCol(_xProp,UNO_QUERY); + exportColumns(xCol); + exportFilter(_xProp,PROPERTY_FILTER,XML_FILTER_STATEMENT); + exportFilter(_xProp,PROPERTY_ORDER,XML_ORDER_STATEMENT); + exportTableName(_xProp,sal_True); +} +// ----------------------------------------------------------------------------- +void ODBExport::exportTable(XPropertySet* _xProp) +{ + exportTableName(_xProp,sal_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, sal_True, sal_True); + Reference<XColumnsSupplier> 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<XPropertySet> 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<beans::XPropertySet>& _xProp,SvXMLAttributeList& _rAtt,TPropertyStyleMap& _rMap) +{ + TPropertyStyleMap::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,sal_Bool _bUpdate) +{ + ::rtl::OUString sValue; + _xProp->getPropertyValue(_bUpdate ? PROPERTY_UPDATE_TABLENAME : PROPERTY_NAME) >>= sValue; + if ( sValue.getLength() ) + { + AddAttribute(XML_NAMESPACE_DB, XML_NAME,sValue); + _xProp->getPropertyValue(_bUpdate ? PROPERTY_UPDATE_SCHEMANAME : PROPERTY_SCHEMANAME) >>= sValue; + if ( sValue.getLength() ) + AddAttribute(XML_NAMESPACE_DB, XML_SCHEMA_NAME,sValue); + _xProp->getPropertyValue(_bUpdate ? PROPERTY_UPDATE_CATALOGNAME : PROPERTY_CATALOGNAME) >>= sValue; + if ( sValue.getLength() ) + AddAttribute(XML_NAMESPACE_DB, XML_CATALOG_NAME,sValue); + + if ( _bUpdate ) + { + SvXMLElementExport aComponents(*this,XML_NAMESPACE_DB, XML_UPDATE_TABLE, sal_True, sal_True); + } + } +} +// ----------------------------------------------------------------------------- +void ODBExport::exportFilter(XPropertySet* _xProp + ,const ::rtl::OUString& _sProp + ,enum ::xmloff::token::XMLTokenEnum _eStatementType) +{ + OSL_PRECOND(!GetAttrList().getLength(),"Invalid attribute length!"); + ::rtl::OUString sCommand; + _xProp->getPropertyValue(_sProp) >>= sCommand; + if ( sCommand.getLength() ) + { + AddAttribute(XML_NAMESPACE_DB, XML_COMMAND,sCommand); + SvXMLElementExport aComponents(*this,XML_NAMESPACE_DB, _eStatementType, sal_True, sal_True); + } + OSL_POSTCOND(!GetAttrList().getLength(),"Invalid attribute length!"); +} +// ----------------------------------------------------------------------------- +void ODBExport::exportColumns(const Reference<XColumnsSupplier>& _xColSup) +{ + OSL_PRECOND( _xColSup.is(), "ODBExport::exportColumns: invalid columns supplier!" ); + if ( !_xColSup.is() ) + return; + + try + { + Reference<XNameAccess> xNameAccess( _xColSup->getColumns(), UNO_SET_THROW ); + if ( !xNameAccess->hasElements() ) + { + Reference< XPropertySet > xComponent(_xColSup,UNO_QUERY); + TTableColumnMap::iterator aFind = m_aTableDummyColumns.find(xComponent); + if ( aFind != m_aTableDummyColumns.end() ) + { + SvXMLElementExport aColumns(*this,XML_NAMESPACE_DB, XML_COLUMNS, sal_True, sal_True); + SvXMLAttributeList* pAtt = new SvXMLAttributeList; + Reference<XAttributeList> xAtt = pAtt; + exportStyleName(aFind->second.get(),*pAtt); + AddAttributeList(xAtt); + SvXMLElementExport aColumn(*this,XML_NAMESPACE_DB, XML_COLUMN, sal_True, sal_True); + + } + return; + } + + SvXMLElementExport aColumns(*this,XML_NAMESPACE_DB, XML_COLUMNS, sal_True, sal_True); + Sequence< ::rtl::OUString> aSeq = xNameAccess->getElementNames(); + const ::rtl::OUString* pIter = aSeq.getConstArray(); + const ::rtl::OUString* pEnd = pIter + aSeq.getLength(); + for( ; pIter != pEnd ; ++pIter) + { + Reference<XPropertySet> xProp(xNameAccess->getByName(*pIter),UNO_QUERY); + if ( xProp.is() ) + { + SvXMLAttributeList* pAtt = new SvXMLAttributeList; + Reference<XAttributeList> xAtt = pAtt; + exportStyleName(xProp.get(),*pAtt); + + sal_Bool bHidden = getBOOL(xProp->getPropertyValue(PROPERTY_HIDDEN)); + + ::rtl::OUString sValue; + xProp->getPropertyValue(PROPERTY_HELPTEXT) >>= sValue; + Any aColumnDefault; + aColumnDefault = xProp->getPropertyValue(PROPERTY_CONTROLDEFAULT); + + if ( bHidden || sValue.getLength() || aColumnDefault.hasValue() || pAtt->getLength() ) + { + AddAttribute(XML_NAMESPACE_DB, XML_NAME,*pIter); + if ( bHidden ) + AddAttribute(XML_NAMESPACE_DB, XML_VISIBLE,XML_FALSE); + + if ( sValue.getLength() ) + AddAttribute(XML_NAMESPACE_DB, XML_HELP_MESSAGE,sValue); + + if ( aColumnDefault.hasValue() ) + { + ::rtl::OUStringBuffer sColumnDefaultString,sType; + SvXMLUnitConverter::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(xAtt); + } + + if ( GetAttrList().getLength() ) + { + SvXMLElementExport aComponents(*this,XML_NAMESPACE_DB, XML_COLUMN, sal_True, sal_True); + } + } + } + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } +} +// ----------------------------------------------------------------------------- +void ODBExport::exportForms() +{ + Any aValue; + ::rtl::OUString sService; + dbtools::getDataSourceSetting(getDataSource(),"Forms",aValue); + aValue >>= sService; + if ( !sService.getLength() ) + { + Reference<XFormDocumentsSupplier> xSup(GetModel(),UNO_QUERY); + if ( xSup.is() ) + { + Reference< XNameAccess > xCollection = xSup->getFormDocuments(); + if ( xCollection.is() && xCollection->hasElements() ) + { + ::comphelper::mem_fun1_t<ODBExport,XPropertySet* > aMemFunc(&ODBExport::exportComponent); + exportCollection(xCollection,XML_FORMS,XML_COMPONENT_COLLECTION,sal_True,aMemFunc); + } + } + } +} +// ----------------------------------------------------------------------------- +void ODBExport::exportReports() +{ + Any aValue; + ::rtl::OUString sService; + dbtools::getDataSourceSetting(getDataSource(),"Reports",aValue); + aValue >>= sService; + if ( !sService.getLength() ) + { + Reference<XReportDocumentsSupplier> xSup(GetModel(),UNO_QUERY); + if ( xSup.is() ) + { + Reference< XNameAccess > xCollection = xSup->getReportDocuments(); + if ( xCollection.is() && xCollection->hasElements() ) + { + ::comphelper::mem_fun1_t<ODBExport,XPropertySet* > aMemFunc(&ODBExport::exportComponent); + exportCollection(xCollection,XML_REPORTS,XML_COMPONENT_COLLECTION,sal_True,aMemFunc); + } + } + } +} +// ----------------------------------------------------------------------------- +void ODBExport::exportQueries(sal_Bool _bExportContext) +{ + Any aValue; + ::rtl::OUString sService; + dbtools::getDataSourceSetting(getDataSource(),"CommandDefinitions",aValue); + aValue >>= sService; + if ( !sService.getLength() ) + { + Reference<XQueryDefinitionsSupplier> xSup(getDataSource(),UNO_QUERY); + if ( xSup.is() ) + { + Reference< XNameAccess > xCollection = xSup->getQueryDefinitions(); + if ( xCollection.is() && xCollection->hasElements() ) + { + ::std::auto_ptr< ::comphelper::mem_fun1_t<ODBExport,XPropertySet* > > pMemFunc; + if ( _bExportContext ) + pMemFunc.reset( new ::comphelper::mem_fun1_t<ODBExport,XPropertySet* >(&ODBExport::exportQuery) ); + else + pMemFunc.reset( new ::comphelper::mem_fun1_t<ODBExport,XPropertySet* >(&ODBExport::exportAutoStyle) ); + + exportCollection(xCollection,XML_QUERIES,XML_QUERY_COLLECTION,_bExportContext,*pMemFunc); + } + } + } +} +// ----------------------------------------------------------------------------- +void ODBExport::exportTables(sal_Bool _bExportContext) +{ + Reference<XTablesSupplier> xSup(getDataSource(),UNO_QUERY); + if ( xSup.is() ) + { + Reference< XNameAccess > xCollection = xSup->getTables(); + if ( xCollection.is() && xCollection->hasElements() ) + { + ::std::auto_ptr< ::comphelper::mem_fun1_t<ODBExport,XPropertySet* > > pMemFunc; + if ( _bExportContext ) + pMemFunc.reset( new ::comphelper::mem_fun1_t<ODBExport,XPropertySet* >(&ODBExport::exportTable) ); + else + pMemFunc.reset( new ::comphelper::mem_fun1_t<ODBExport,XPropertySet* >(&ODBExport::exportAutoStyle) ); + exportCollection(xCollection,XML_TABLE_REPRESENTATIONS,XML_TOKEN_INVALID,_bExportContext,*pMemFunc); + } + } +} +// ----------------------------------------------------------------------------- +void ODBExport::exportAutoStyle(XPropertySet* _xProp) +{ + typedef ::std::pair<TPropertyStyleMap*,sal_uInt16> TEnumMapperPair; + typedef ::std::pair< UniReference < SvXMLExportPropertyMapper> , TEnumMapperPair> TExportPropMapperPair; + Reference<XColumnsSupplier> xSup(_xProp,UNO_QUERY); + if ( xSup.is() ) + { + const TExportPropMapperPair pExportHelper[] = { + TExportPropMapperPair(m_xExportHelper,TEnumMapperPair(&m_aAutoStyleNames,XML_STYLE_FAMILY_TABLE_TABLE )) + // ,TExportPropMapperPair(m_xCellExportHelper,TEnumMapperPair(&m_aCellAutoStyleNames,XML_STYLE_FAMILY_TABLE_CELL)) + ,TExportPropMapperPair(m_xRowExportHelper,TEnumMapperPair(&m_aRowAutoStyleNames,XML_STYLE_FAMILY_TABLE_ROW)) + }; + + ::std::vector< XMLPropertyState > aPropertyStates; + for (size_t i = 0 ; i < SAL_N_ELEMENTS(pExportHelper); ++i) + { + aPropertyStates = pExportHelper[i].first->Filter(_xProp); + if ( !aPropertyStates.empty() ) + pExportHelper[i].second.first->insert( TPropertyStyleMap::value_type(_xProp,GetAutoStylePool()->Add( pExportHelper[i].second.second, 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,aFont.Family,aFont.Pitch,aFont.CharSet ); + + m_aCurrentPropertyStates = m_xCellExportHelper->Filter(_xProp); + if ( !m_aCurrentPropertyStates.empty() && !xCollection->hasElements() ) + { + Reference< XDataDescriptorFactory> xFac(xCollection,UNO_QUERY); + if ( xFac.is() ) + { + Reference< XPropertySet> xColumn = xFac->createDataDescriptor(); + m_aTableDummyColumns.insert(TTableColumnMap::value_type(Reference< XPropertySet>(_xProp),xColumn)); + exportAutoStyle(xColumn.get()); + } + } + else + { + ::comphelper::mem_fun1_t<ODBExport,XPropertySet* > aMemFunc(&ODBExport::exportAutoStyle); + exportCollection(xCollection,XML_TOKEN_INVALID,XML_TOKEN_INVALID,sal_False,aMemFunc); + } + } + catch(Exception&) + { + DBG_UNHANDLED_EXCEPTION(); + } + m_aCurrentPropertyStates.clear(); + } + else + { // here I know I have a column + TExportPropMapperPair pExportHelper[] = { + TExportPropMapperPair(m_xColumnExportHelper,TEnumMapperPair(&m_aAutoStyleNames,XML_STYLE_FAMILY_TABLE_COLUMN )) + ,TExportPropMapperPair(m_xCellExportHelper,TEnumMapperPair(&m_aCellAutoStyleNames,XML_STYLE_FAMILY_TABLE_CELL)) + }; + for (size_t i = 0 ; i < SAL_N_ELEMENTS(pExportHelper); ++i) + { + ::std::vector< XMLPropertyState > aPropStates = pExportHelper[i].first->Filter( _xProp ); + if ( !aPropStates.empty() ) + { + ::std::vector< XMLPropertyState >::iterator aItr = aPropStates.begin(); + ::std::vector< XMLPropertyState >::iterator aEnd = aPropStates.end(); + const UniReference < XMLPropertySetMapper >& pStyle = pExportHelper[i].first->getPropertySetMapper(); + while ( aItr != aEnd ) + { + if ( aItr->mnIndex != -1 ) + { + switch ( pStyle->GetEntryContextId(aItr->mnIndex) ) + { + case CTF_DB_NUMBERFORMAT: + { + sal_Int32 nNumberFormat = -1; + if ( aItr->maValue >>= nNumberFormat ) + addDataStyle(nNumberFormat); + } + break; + case CTF_DB_COLUMN_TEXT_ALIGN: + if ( !aItr->maValue.hasValue() ) + aItr->maValue <<= ::com::sun::star::awt::TextAlign::LEFT; + break; + } + } + ++aItr; + } + + } + if ( XML_STYLE_FAMILY_TABLE_CELL == pExportHelper[i].second.second ) + ::std::copy( m_aCurrentPropertyStates.begin(), m_aCurrentPropertyStates.end(), ::std::back_inserter( aPropStates )); + if ( !aPropStates.empty() ) + pExportHelper[i].second.first->insert( TPropertyStyleMap::value_type(_xProp,GetAutoStylePool()->Add( pExportHelper[i].second.second, aPropStates ))); + } + } +} +// ----------------------------------------------------------------------------- +void ODBExport::_ExportContent() +{ + exportDataSource(); + exportForms(); + exportReports(); + exportQueries(sal_True); + exportTables(sal_True); +} +// ----------------------------------------------------------------------------- +void ODBExport::_ExportMasterStyles() +{ + GetPageExport()->exportMasterStyles( sal_True ); +} +// ----------------------------------------------------------------------------- +void ODBExport::_ExportAutoStyles() +{ + // there are no styles that require their own autostyles + if ( getExportFlags() & EXPORT_CONTENT ) + { + collectComponentStyles(); + GetAutoStylePool()->exportXML(XML_STYLE_FAMILY_TABLE_TABLE + ,GetDocHandler() + ,GetMM100UnitConverter() + ,GetNamespaceMap() + ); + GetAutoStylePool()->exportXML(XML_STYLE_FAMILY_TABLE_COLUMN + ,GetDocHandler() + ,GetMM100UnitConverter() + ,GetNamespaceMap() + ); + GetAutoStylePool()->exportXML(XML_STYLE_FAMILY_TABLE_CELL + ,GetDocHandler() + ,GetMM100UnitConverter() + ,GetNamespaceMap() + ); + GetAutoStylePool()->exportXML(XML_STYLE_FAMILY_TABLE_ROW + ,GetDocHandler() + ,GetMM100UnitConverter() + ,GetNamespaceMap() + ); + exportDataStyles(); + } +} +// ----------------------------------------------------------------------------- +void ODBExport::_ExportStyles(sal_Bool bUsed) +{ + SvXMLExport::_ExportStyles(bUsed); +} +// ----------------------------------------------------------------------------- +sal_uInt32 ODBExport::exportDoc(enum ::xmloff::token::XMLTokenEnum eClass) +{ + return SvXMLExport::exportDoc( eClass ); +} +// ----------------------------------------------------------------------------- +void ODBExport::GetViewSettings(Sequence<PropertyValue>& aProps) +{ + Reference<XQueryDefinitionsSupplier> xSup(getDataSource(),UNO_QUERY); + if ( xSup.is() ) + { + Reference< XNameAccess > xCollection = xSup->getQueryDefinitions(); + if ( xCollection.is() && xCollection->hasElements() ) + { + try + { + sal_Int32 nLength = aProps.getLength(); + aProps.realloc(nLength + 1); + aProps[nLength].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Queries")); + Sequence< ::rtl::OUString> aSeq = xCollection->getElementNames(); + const ::rtl::OUString* pIter = aSeq.getConstArray(); + const ::rtl::OUString* pEnd = pIter + aSeq.getLength(); + + Sequence<PropertyValue> aQueries(aSeq.getLength()); + for(sal_Int32 i = 0;pIter != pEnd;++pIter,++i) + { + Reference<XPropertySet> xProp(xCollection->getByName(*pIter),UNO_QUERY); + if ( xProp.is() ) + { + aQueries[i].Name = *pIter; + aQueries[i].Value = xProp->getPropertyValue(PROPERTY_LAYOUTINFORMATION); + } + } + aProps[nLength].Value <<= aQueries; + } + catch(Exception) + { + OSL_FAIL("ODBExport::GetViewSettings: Exception catched!"); + } + } + } + +} +// ----------------------------------------------------------------------------- +void ODBExport::GetConfigurationSettings(Sequence<PropertyValue>& aProps) +{ + Reference<XPropertySet> xProp(getDataSource()); + if ( xProp.is() ) + { + sal_Int32 nLength = aProps.getLength(); + try + { + Any aValue = xProp->getPropertyValue(PROPERTY_LAYOUTINFORMATION); + Sequence< PropertyValue > aPropValues; + aValue >>= aPropValues; + if ( aPropValues.getLength() ) + { + aProps.realloc(nLength + 1); + aProps[nLength].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("layout-settings")); + aProps[nLength].Value = aValue; + } + } + catch(Exception) + { + OSL_FAIL("Could not access layout information from the data source!"); + } + } +} +// ----------------------------------------------------------------------------- +::rtl::OUString ODBExport::implConvertAny(const Any& _rValue) +{ + ::rtl::OUStringBuffer aBuffer; + switch (_rValue.getValueTypeClass()) + { + case TypeClass_STRING: + { // extract the string + ::rtl::OUString sCurrentValue; + _rValue >>= sCurrentValue; + aBuffer.append(sCurrentValue); + } + break; + case TypeClass_DOUBLE: + // let the unit converter format is as string + GetMM100UnitConverter().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 + GetMM100UnitConverter().convertNumber(aBuffer, getINT32(_rValue)); + break; + default: + OSL_FAIL("ODBExport::implConvertAny: Invalid type"); + } + + return aBuffer.makeStringAndClear(); +} +// ----------------------------------------------------------------------------- +UniReference < XMLPropertySetMapper > ODBExport::GetTableStylesPropertySetMapper() const +{ + if ( !m_xTableStylesPropertySetMapper.is() ) + { + m_xTableStylesPropertySetMapper = OXMLHelper::GetTableStylesPropertySetMapper(); + } + return m_xTableStylesPropertySetMapper; +} +// ----------------------------------------------------------------------------- +UniReference < XMLPropertySetMapper > ODBExport::GetCellStylesPropertySetMapper() const +{ + if ( !m_xCellStylesPropertySetMapper.is() ) + { + m_xCellStylesPropertySetMapper = OXMLHelper::GetCellStylesPropertySetMapper(); + } + return m_xCellStylesPropertySetMapper; +} +// ----------------------------------------------------------------------------- +UniReference < XMLPropertySetMapper > ODBExport::GetColumnStylesPropertySetMapper() const +{ + if ( !m_xColumnStylesPropertySetMapper.is() ) + { + m_xColumnStylesPropertySetMapper = OXMLHelper::GetColumnStylesPropertySetMapper(); + } + return m_xColumnStylesPropertySetMapper; +} +// ----------------------------------------------------------------------------- +SvXMLAutoStylePoolP* ODBExport::CreateAutoStylePool() +{ + return new OXMLAutoStylePoolP(*this); +} +// ----------------------------------------------------------------------------- +void SAL_CALL ODBExport::setSourceDocument( const Reference< XComponent >& xDoc ) throw(IllegalArgumentException, RuntimeException) +{ + Reference<XOfficeDatabaseDocument> 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 = sal_True; + exportQueries(sal_False); + exportTables(sal_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 000000000000..8dc662f85705 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlExport.hxx @@ -0,0 +1,204 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef DBA_XMLEXPORT_HXX +#define DBA_XMLEXPORT_HXX + +#include <com/sun/star/container/XNamed.hpp> +#include <com/sun/star/document/XFilter.hpp> +#include <com/sun/star/document/XImporter.hpp> +#include <com/sun/star/document/XExporter.hpp> +#include <com/sun/star/lang/XInitialization.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <cppuhelper/implbase1.hxx> +#include <cppuhelper/implbase5.hxx> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/io/XActiveDataSource.hpp> +#include <osl/diagnose.h> +#include <unotools/tempfile.hxx> +#include <unotools/localfilehelper.hxx> +#include <unotools/ucbstreamhelper.hxx> +#include <xmloff/xmlexp.hxx> +#include <xmloff/xmlimp.hxx> +#include "apitools.hxx" +#include "dsntypes.hxx" +#include <comphelper/stl_types.hxx> +#include <com/sun/star/sdbcx/XColumnsSupplier.hpp> + +#include <memory> + +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; +// ------------- +// - ODBExport - +// ------------- +#define PROGRESS_BAR_STEP 20 + +class ODBExport : public SvXMLExport +{ + typedef ::std::map< ::xmloff::token::XMLTokenEnum, ::rtl::OUString> TSettingsMap; + + typedef ::std::pair< ::rtl::OUString ,::rtl::OUString> TStringPair; + struct TDelimiter + { + ::rtl::OUString sText; + ::rtl::OUString sField; + ::rtl::OUString sDecimal; + ::rtl::OUString sThousand; + bool bUsed; + + TDelimiter() : bUsed( false ) { } + }; + typedef ::std::map< Reference<XPropertySet> ,::rtl::OUString > TPropertyStyleMap; + typedef ::std::map< Reference<XPropertySet> ,Reference<XPropertySet> > TTableColumnMap; + + struct TypedPropertyValue + { + ::rtl::OUString Name; + ::com::sun::star::uno::Type Type; + ::com::sun::star::uno::Any Value; + + TypedPropertyValue( const ::rtl::OUString& _name, const ::com::sun::star::uno::Type& _type, const ::com::sun::star::uno::Any& _value ) + :Name( _name ) + ,Type( _type ) + ,Value( _value ) + { + } + }; + + ::std::auto_ptr< TStringPair > m_aAutoIncrement; + ::std::auto_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; + ::rtl::OUString m_sCharSet; + UniReference < SvXMLExportPropertyMapper> m_xExportHelper; + UniReference < SvXMLExportPropertyMapper> m_xColumnExportHelper; + UniReference < SvXMLExportPropertyMapper> m_xCellExportHelper; + UniReference < SvXMLExportPropertyMapper> m_xRowExportHelper; + + mutable UniReference < XMLPropertySetMapper > m_xTableStylesPropertySetMapper; + mutable UniReference < XMLPropertySetMapper > m_xColumnStylesPropertySetMapper; + mutable UniReference < XMLPropertySetMapper > m_xCellStylesPropertySetMapper; + mutable UniReference < XMLPropertySetMapper > m_xRowStylesPropertySetMapper; + + Reference<XPropertySet> m_xDataSource; + ::dbaccess::ODsnTypeCollection m_aTypeCollection; + sal_Bool m_bAllreadyFilled; + + void exportDataSource(); + void exportConnectionData(); + void exportDriverSettings(const TSettingsMap& _aSettings); + void exportApplicationConnectionSettings(const TSettingsMap& _aSettings); + void exportLogin(); + void exportSequence(const Sequence< ::rtl::OUString>& _aValue + ,::xmloff::token::XMLTokenEnum _eTokenFilter + ,::xmloff::token::XMLTokenEnum _eTokenType); + void exportDelimiter(); + void exportAutoIncrement(); + void exportCharSet(); + void exportDataSourceSettings(); + void exportForms(); + void exportReports(); + void exportQueries(sal_Bool _bExportContext); + void exportTables(sal_Bool _bExportContext); + void exportStyleName(XPropertySet* _xProp,SvXMLAttributeList& _rAtt); + void exportStyleName(const ::xmloff::token::XMLTokenEnum _eToken,const Reference<XPropertySet>& _xProp,SvXMLAttributeList& _rAtt,TPropertyStyleMap& _rMap); + void exportCollection(const Reference< XNameAccess >& _xCollection + ,enum ::xmloff::token::XMLTokenEnum _eComponents + ,enum ::xmloff::token::XMLTokenEnum _eSubComponents + ,sal_Bool _bExportContext + ,const ::comphelper::mem_fun1_t<ODBExport,XPropertySet* >& _aMemFunc + ); + void exportComponent(XPropertySet* _xProp); + void exportQuery(XPropertySet* _xProp); + void exportTable(XPropertySet* _xProp); + void exportFilter(XPropertySet* _xProp + ,const ::rtl::OUString& _sProp + ,enum ::xmloff::token::XMLTokenEnum _eStatementType); + void exportTableName(XPropertySet* _xProp,sal_Bool _bUpdate); + void exportAutoStyle(XPropertySet* _xProp); + void exportColumns(const Reference<XColumnsSupplier>& _xColSup); + void collectComponentStyles(); + + ::rtl::OUString implConvertAny(const Any& _rValue); + + UniReference < XMLPropertySetMapper > GetTableStylesPropertySetMapper() const; + +private: + ODBExport(); +protected: + + virtual void _ExportStyles( sal_Bool bUsed ); + virtual void _ExportAutoStyles(); + virtual void _ExportContent(); + virtual void _ExportMasterStyles(); + virtual void _ExportFontDecls(); + virtual sal_uInt32 exportDoc( enum ::xmloff::token::XMLTokenEnum eClass ); + virtual SvXMLAutoStylePoolP* CreateAutoStylePool(); + + virtual void GetViewSettings(com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>& aProps); + virtual void GetConfigurationSettings(com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>& aProps); + + virtual ~ODBExport(){}; +public: + + ODBExport(const Reference< XMultiServiceFactory >& _rxMSF, sal_uInt16 nExportFlag = EXPORT_CONTENT | EXPORT_AUTOSTYLES | EXPORT_PRETTY | EXPORT_FONTDECLS | EXPORT_SCRIPTS ); + // XServiceInfo + DECLARE_SERVICE_INFO_STATIC( ); + + UniReference < XMLPropertySetMapper > GetColumnStylesPropertySetMapper() const; + UniReference < XMLPropertySetMapper > GetCellStylesPropertySetMapper() const; + + // XExporter + virtual void SAL_CALL setSourceDocument( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& xDoc ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + + inline Reference<XPropertySet> getDataSource() const { return m_xDataSource; } +}; + +// ----------------------------------------------------------------------------- +} // dbaxml +// ----------------------------------------------------------------------------- +#endif // DBA_XMLEXPORT_HXX + +/* 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 000000000000..c4a9893f8493 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlFileBasedDatabase.cxx @@ -0,0 +1,138 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_dbaccess.hxx" +#include "xmlFileBasedDatabase.hxx" +#include "xmlfilter.hxx" +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmlnmspe.hxx> +#include <xmloff/nmspmap.hxx> +#include "xmlEnums.hxx" +#include "xmlstrings.hrc" +#include <tools/debug.hxx> +#include <tools/diagnose_ex.h> +#include <comphelper/sequence.hxx> +#include <svl/filenotation.hxx> +#include <unotools/pathoptions.hxx> +#include "dsntypes.hxx" +namespace dbaxml +{ + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::xml::sax; +DBG_NAME(OXMLFileBasedDatabase) + +OXMLFileBasedDatabase::OXMLFileBasedDatabase( ODBFilter& rImport, + sal_uInt16 nPrfx, const ::rtl::OUString& _sLocalName, + const Reference< XAttributeList > & _xAttrList) : + SvXMLImportContext( rImport, nPrfx, _sLocalName ) +{ + DBG_CTOR(OXMLFileBasedDatabase,NULL); + + OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!"); + const SvXMLNamespaceMap& rMap = rImport.GetNamespaceMap(); + const SvXMLTokenMap& rTokenMap = rImport.GetDataSourceElemTokenMap(); + + Reference<XPropertySet> xDataSource = rImport.getDataSource(); + + PropertyValue aProperty; + + const sal_Int16 nLength = (xDataSource.is() && _xAttrList.is()) ? _xAttrList->getLength() : 0; + ::rtl::OUString sLocation,sMediaType,sFileTypeExtension; + for(sal_Int16 i = 0; i < nLength; ++i) + { + ::rtl::OUString sLocalName; + const rtl::OUString sAttrName = _xAttrList->getNameByIndex( i ); + const sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName ); + const rtl::OUString sValue = _xAttrList->getValueByIndex( i ); + + aProperty.Name = ::rtl::OUString(); + aProperty.Value = Any(); + + switch( rTokenMap.Get( nPrefix, sLocalName ) ) + { + case XML_TOK_DB_HREF: + { + SvtPathOptions aPathOptions; + rtl::OUString sFileName = aPathOptions.SubstituteVariable(sValue); + if ( sValue == sFileName ) + { + const sal_Int32 nFileNameLength = sFileName.getLength(); + if ( ( nFileNameLength > 0 ) && ( sFileName.getStr()[ nFileNameLength - 1 ] == '/' ) ) + sFileName = sFileName.copy( 0, nFileNameLength - 1 ); + + sLocation = ::svt::OFileNotation( rImport.GetAbsoluteReference( sFileName ) ).get( ::svt::OFileNotation::N_SYSTEM ); + } + + if ( sLocation.getLength() == 0 ) + sLocation = sValue; + } + break; + case XML_TOK_MEDIA_TYPE: + sMediaType = sValue; + break; + case XML_TOK_EXTENSION: + aProperty.Name = INFO_TEXTFILEEXTENSION; + sFileTypeExtension = sValue; + break; + } + if ( aProperty.Name.getLength() ) + { + if ( !aProperty.Value.hasValue() ) + aProperty.Value <<= sValue; + rImport.addInfo(aProperty); + } + } + if ( sLocation.getLength() && sMediaType.getLength() ) + { + ::dbaccess::ODsnTypeCollection aTypeCollection(rImport.getORB()); + ::rtl::OUString sURL(aTypeCollection.getDatasourcePrefixFromMediaType(sMediaType,sFileTypeExtension)); + sURL += sLocation; + try + { + xDataSource->setPropertyValue(PROPERTY_URL,makeAny(sURL)); + } + catch(Exception) + { + DBG_UNHANDLED_EXCEPTION(); + } + } +} +// ----------------------------------------------------------------------------- + +OXMLFileBasedDatabase::~OXMLFileBasedDatabase() +{ + + DBG_DTOR(OXMLFileBasedDatabase,NULL); +} +// ----------------------------------------------------------------------------- +//---------------------------------------------------------------------------- +} // 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 000000000000..9f58f4b0f03f --- /dev/null +++ b/dbaccess/source/filter/xml/xmlFileBasedDatabase.hxx @@ -0,0 +1,53 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef DBA_XMLFILEBASEDDATABASE_HXX_INCLUDED +#define DBA_XMLFILEBASEDDATABASE_HXX_INCLUDED + +#include <xmloff/xmlictxt.hxx> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <vector> + +namespace dbaxml +{ + class ODBFilter; + class OXMLFileBasedDatabase : public SvXMLImportContext + { + public: + + OXMLFileBasedDatabase( ODBFilter& rImport, sal_uInt16 nPrfx, + const ::rtl::OUString& rLName, + const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttrList); + virtual ~OXMLFileBasedDatabase(); + }; +// ----------------------------------------------------------------------------- +} // namespace dbaxml +// ----------------------------------------------------------------------------- + +#endif // DBA_XMLFILEBASEDDATABASE_HXX_INCLUDED + +/* 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 000000000000..4854bdce71fd --- /dev/null +++ b/dbaccess/source/filter/xml/xmlHelper.cxx @@ -0,0 +1,170 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_dbaccess.hxx" +#include "xmlHelper.hxx" +#include <xmloff/xmlnmspe.hxx> +#include <xmloff/xmltoken.hxx> +#include <com/sun/star/awt/TextAlign.hpp> +#include "xmlstrings.hrc" +#include "xmlEnums.hxx" +#include <xmloff/contextid.hxx> +#include <xmloff/XMLConstantsPropertyHandler.hxx> +#include <xmloff/xmlement.hxx> +#include <com/sun/star/awt/TextAlign.hpp> +#include <tools/debug.hxx> + +namespace dbaxml +{ + using namespace ::xmloff::token; + using namespace ::com::sun::star::awt; +DBG_NAME(OPropertyHandlerFactory) + +OPropertyHandlerFactory::OPropertyHandlerFactory() +{ + DBG_CTOR(OPropertyHandlerFactory,NULL); + +} +// ----------------------------------------------------------------------------- +OPropertyHandlerFactory::~OPropertyHandlerFactory() +{ + + DBG_DTOR(OPropertyHandlerFactory,NULL); +} +// ----------------------------------------------------------------------------- +const XMLPropertyHandler* OPropertyHandlerFactory::GetPropertyHandler(sal_Int32 _nType) const +{ + const XMLPropertyHandler* pHandler = NULL; + + switch (_nType) + { + case XML_DB_TYPE_EQUAL: + if ( !m_pDisplayHandler.get() ) + { + static SvXMLEnumMapEntry aDisplayMap[] = + { + { XML_VISIBLE, sal_True }, + { XML_COLLAPSE, sal_False }, + { XML_TOKEN_INVALID, 0 } + }; + m_pDisplayHandler.reset(new XMLConstantsPropertyHandler(aDisplayMap, XML_TOKEN_INVALID )); + } + pHandler = m_pDisplayHandler.get(); + break; + } + if ( !pHandler ) + pHandler = OControlPropertyHandlerFactory::GetPropertyHandler(_nType); + return pHandler; +} +// ----------------------------------------------------------------------------- +#define MAP_CONST( name, prefix, token, type, context ) { name.ascii, name.length, prefix, token, type|XML_TYPE_PROP_TABLE, context, SvtSaveOptions::ODFVER_010 } +#define MAP_CONST_ASCII( name, prefix, token, type, context ) { name, sizeof(name)-1, prefix, token, type|XML_TYPE_PROP_TABLE, context, SvtSaveOptions::ODFVER_010 } +#define MAP_END() { NULL, 0, 0, XML_TOKEN_INVALID, 0 , 0, SvtSaveOptions::ODFVER_010} +// ----------------------------------------------------------------------------- +UniReference < XMLPropertySetMapper > OXMLHelper::GetTableStylesPropertySetMapper() +{ + static const XMLPropertyMapEntry s_aTableStylesProperties[] = + { + MAP_END() + }; + UniReference < XMLPropertyHandlerFactory> xFac = new ::xmloff::OControlPropertyHandlerFactory(); + return new XMLPropertySetMapper((XMLPropertyMapEntry*)s_aTableStylesProperties, xFac); +} +// ----------------------------------------------------------------------------- +UniReference < XMLPropertySetMapper > OXMLHelper::GetColumnStylesPropertySetMapper() +{ +#define MAP_CONST_COLUMN( name, prefix, token, type, context ) { name.ascii, name.length, prefix, token, type|XML_TYPE_PROP_TABLE_COLUMN, context, SvtSaveOptions::ODFVER_010 } + static const XMLPropertyMapEntry s_aColumnStylesProperties[] = + { + MAP_CONST_COLUMN( PROPERTY_WIDTH, XML_NAMESPACE_STYLE, XML_COLUMN_WIDTH, XML_TYPE_MEASURE, 0), + MAP_CONST_COLUMN( PROPERTY_HIDDEN, XML_NAMESPACE_TABLE, XML_DISPLAY, XML_DB_TYPE_EQUAL|MID_FLAG_SPECIAL_ITEM, CTF_DB_ISVISIBLE ), + MAP_CONST_COLUMN( PROPERTY_NUMBERFORMAT, XML_NAMESPACE_STYLE, XML_DATA_STYLE_NAME, XML_TYPE_NUMBER|MID_FLAG_SPECIAL_ITEM, CTF_DB_NUMBERFORMAT), + MAP_END() + }; + UniReference < XMLPropertyHandlerFactory> xFac = new OPropertyHandlerFactory(); + return new XMLPropertySetMapper((XMLPropertyMapEntry*)s_aColumnStylesProperties, xFac); +} +// ----------------------------------------------------------------------------- +UniReference < XMLPropertySetMapper > OXMLHelper::GetCellStylesPropertySetMapper() +{ +#define MAP_CONST_CELL( name, prefix, token, type, context ) { name.ascii, name.length, prefix, token, type|XML_TYPE_PROP_PARAGRAPH, context, SvtSaveOptions::ODFVER_010 } +#define MAP_CONST_TEXT( name, prefix, token, type, context ) { name.ascii, name.length, prefix, token, type|XML_TYPE_PROP_TEXT, context, SvtSaveOptions::ODFVER_010 } +#define MAP_CONST_TEXT_ASCII( name, prefix, token, type, context ) { name, sizeof(name)-1, prefix, token, type|XML_TYPE_PROP_TEXT, context, SvtSaveOptions::ODFVER_010 } + static const XMLPropertyMapEntry s_aCellStylesProperties[] = + { + MAP_CONST_CELL( PROPERTY_ALIGN, XML_NAMESPACE_FO, XML_TEXT_ALIGN, XML_TYPE_TEXT_ALIGN, CTF_DB_COLUMN_TEXT_ALIGN), + MAP_CONST_TEXT( PROPERTY_FONTNAME, XML_NAMESPACE_STYLE, XML_FONT_NAME, XML_TYPE_STRING, 0 ), + MAP_CONST_TEXT( PROPERTY_TEXTCOLOR, XML_NAMESPACE_FO, XML_COLOR, XML_TYPE_COLOR, 0 ), + MAP_CONST_TEXT( PROPERTY_TEXTLINECOLOR, XML_NAMESPACE_STYLE, XML_TEXT_UNDERLINE_COLOR, XML_TYPE_TEXT_UNDERLINE_COLOR|MID_FLAG_MULTI_PROPERTY, 0 ), + + MAP_CONST_TEXT( PROPERTY_TEXTRELIEF, XML_NAMESPACE_STYLE, XML_FONT_RELIEF, XML_TYPE_TEXT_FONT_RELIEF|MID_FLAG_MULTI_PROPERTY, 0 ), + MAP_CONST_TEXT( PROPERTY_TEXTEMPHASIS, XML_NAMESPACE_STYLE, XML_TEXT_EMPHASIZE, XML_TYPE_CONTROL_TEXT_EMPHASIZE, 0 ), + MAP_CONST_TEXT( PROPERTY_FONTCHARWIDTH, XML_NAMESPACE_STYLE, XML_FONT_CHAR_WIDTH, XML_TYPE_NUMBER16, 0 ), + MAP_CONST_TEXT( PROPERTY_FONTCHARSET, XML_NAMESPACE_STYLE, XML_FONT_CHARSET, XML_TYPE_TEXT_FONTENCODING, 0 ), + MAP_CONST_TEXT( PROPERTY_FONTFAMILY, XML_NAMESPACE_STYLE, XML_FONT_FAMILY_GENERIC, XML_TYPE_TEXT_FONTFAMILY, 0 ), + MAP_CONST_TEXT( PROPERTY_FONTHEIGHT, XML_NAMESPACE_FO, XML_FONT_SIZE, XML_TYPE_MEASURE16, 0 ), + MAP_CONST_TEXT( PROPERTY_FONTKERNING, XML_NAMESPACE_STYLE, XML_LETTER_KERNING, XML_TYPE_BOOL, 0 ), + + MAP_CONST_TEXT( PROPERTY_FONTORIENTATION, XML_NAMESPACE_STYLE, XML_ROTATION_ANGLE, XML_TYPE_ROTATION_ANGLE, 0 ), + MAP_CONST_TEXT( PROPERTY_FONTPITCH, XML_NAMESPACE_STYLE, XML_FONT_PITCH, XML_TYPE_TEXT_FONTPITCH, 0 ), + MAP_CONST_TEXT( PROPERTY_FONTSLANT, XML_NAMESPACE_FO, XML_FONT_STYLE, XML_TYPE_TEXT_POSTURE, 0 ), + MAP_CONST_TEXT_ASCII( "CharStrikeout", XML_NAMESPACE_STYLE, XML_TEXT_LINE_THROUGH_STYLE, XML_TYPE_TEXT_CROSSEDOUT_STYLE|MID_FLAG_MERGE_PROPERTY, 0), + MAP_CONST_TEXT_ASCII( "CharStrikeout", XML_NAMESPACE_STYLE, XML_TEXT_LINE_THROUGH_TYPE, XML_TYPE_TEXT_CROSSEDOUT_TYPE|MID_FLAG_MERGE_PROPERTY, 0), + MAP_CONST_TEXT_ASCII( "CharStrikeout", XML_NAMESPACE_STYLE, XML_TEXT_LINE_THROUGH_WIDTH, XML_TYPE_TEXT_CROSSEDOUT_WIDTH|MID_FLAG_MERGE_PROPERTY, 0), + MAP_CONST_TEXT_ASCII( "CharStrikeout", XML_NAMESPACE_STYLE, XML_TEXT_LINE_THROUGH_TEXT, XML_TYPE_TEXT_CROSSEDOUT_TEXT|MID_FLAG_MERGE_PROPERTY, 0), + MAP_CONST_TEXT( PROPERTY_FONTSTYLENAME, XML_NAMESPACE_STYLE, XML_FONT_STYLE_NAME, XML_TYPE_STRING, 0 ), + MAP_CONST_TEXT_ASCII( "CharUnderline", XML_NAMESPACE_STYLE, XML_TEXT_UNDERLINE_STYLE, XML_TYPE_TEXT_UNDERLINE_STYLE|MID_FLAG_MERGE_PROPERTY, 0 ), + MAP_CONST_TEXT_ASCII( "CharUnderline", XML_NAMESPACE_STYLE, XML_TEXT_UNDERLINE_TYPE, XML_TYPE_TEXT_UNDERLINE_TYPE|MID_FLAG_MERGE_PROPERTY, 0 ), + MAP_CONST_TEXT_ASCII( "CharUnderline", XML_NAMESPACE_STYLE, XML_TEXT_UNDERLINE_WIDTH, XML_TYPE_TEXT_UNDERLINE_WIDTH|MID_FLAG_MERGE_PROPERTY, 0 ), + MAP_CONST_TEXT_ASCII( "CharUnderlineColor", XML_NAMESPACE_STYLE, XML_TEXT_UNDERLINE_COLOR, XML_TYPE_TEXT_UNDERLINE_COLOR|MID_FLAG_MULTI_PROPERTY, 0 ), + MAP_CONST_TEXT_ASCII( "CharUnderlineHasColor",XML_NAMESPACE_STYLE, XML_TEXT_UNDERLINE_COLOR, XML_TYPE_TEXT_UNDERLINE_HASCOLOR|MID_FLAG_MERGE_ATTRIBUTE, 0 ), + MAP_CONST_TEXT( PROPERTY_FONTWEIGHT, XML_NAMESPACE_FO, XML_FONT_WEIGHT, XML_TYPE_TEXT_WEIGHT, 0 ), + MAP_CONST_TEXT( PROPERTY_FONTWIDTH, XML_NAMESPACE_STYLE, XML_FONT_WIDTH, XML_TYPE_FONT_WIDTH, 0 ), + MAP_CONST_TEXT( PROPERTY_FONTWORDLINEMODE, XML_NAMESPACE_STYLE, XML_TEXT_UNDERLINE_MODE, XML_TYPE_TEXT_LINE_MODE|MID_FLAG_MERGE_PROPERTY, 0 ), + MAP_END() + }; + UniReference < XMLPropertyHandlerFactory> xFac = new /*OPropertyHandlerFactory*/::xmloff::OControlPropertyHandlerFactory(); + return new XMLPropertySetMapper((XMLPropertyMapEntry*)s_aCellStylesProperties, xFac); +} +// ----------------------------------------------------------------------------- +UniReference < XMLPropertySetMapper > OXMLHelper::GetRowStylesPropertySetMapper() +{ +#define MAP_CONST_ROW( name, prefix, token, type, context ) { name.ascii, name.length, prefix, token, type|XML_TYPE_PROP_TABLE_ROW, context, SvtSaveOptions::ODFVER_010 } + static const XMLPropertyMapEntry s_aStylesProperties[] = + { + MAP_CONST_ROW( PROPERTY_ROW_HEIGHT, XML_NAMESPACE_STYLE, XML_ROW_HEIGHT, XML_TYPE_MEASURE, 0), + MAP_END() + }; + UniReference < XMLPropertyHandlerFactory> xFac = new OPropertyHandlerFactory(); + return new XMLPropertySetMapper((XMLPropertyMapEntry*)s_aStylesProperties, xFac); +} +// ----------------------------------------------------------------------------- +} + +/* 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 000000000000..fcc9ca8af74e --- /dev/null +++ b/dbaccess/source/filter/xml/xmlHelper.hxx @@ -0,0 +1,72 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef DBA_XMLHELPER_HXX +#define DBA_XMLHELPER_HXX + +#include <xmloff/xmlprmap.hxx> +#include <xmloff/contextid.hxx> +#include <xmloff/controlpropertyhdl.hxx> + +#include <memory> + +#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 : public ::xmloff::OControlPropertyHandlerFactory + { + protected: + mutable ::std::auto_ptr<XMLConstantsPropertyHandler> m_pDisplayHandler; + mutable ::std::auto_ptr<XMLPropertyHandler> m_pTextAlignHandler; + public: + OPropertyHandlerFactory(); + virtual ~OPropertyHandlerFactory(); + + virtual const XMLPropertyHandler* GetPropertyHandler(sal_Int32 _nType) const; + }; + + class OXMLHelper + { + public: + static UniReference < XMLPropertySetMapper > GetTableStylesPropertySetMapper(); + static UniReference < XMLPropertySetMapper > GetColumnStylesPropertySetMapper(); + static UniReference < XMLPropertySetMapper > GetCellStylesPropertySetMapper(); + static UniReference < XMLPropertySetMapper > GetRowStylesPropertySetMapper(); + }; +// ----------------------------------------------------------------------------- +} // dbaxml +// ----------------------------------------------------------------------------- +#endif // DBA_XMLHELPER_HXX + +/* 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 000000000000..4b3639d1300f --- /dev/null +++ b/dbaccess/source/filter/xml/xmlHierarchyCollection.cxx @@ -0,0 +1,176 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_dbaccess.hxx" +#include "xmlHierarchyCollection.hxx" +#include "xmlComponent.hxx" +#include "xmlQuery.hxx" +#include "xmlColumn.hxx" +#include "xmlfilter.hxx" +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmlnmspe.hxx> +#include <xmloff/nmspmap.hxx> +#include "xmlEnums.hxx" +#include "xmlstrings.hrc" +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <tools/debug.hxx> + + +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; +DBG_NAME(OXMLHierarchyCollection) + +OXMLHierarchyCollection::OXMLHierarchyCollection( ODBFilter& rImport + ,sal_uInt16 nPrfx + ,const ::rtl::OUString& _sLocalName + ,const Reference< XAttributeList > & _xAttrList + ,const Reference< XNameAccess >& _xParentContainer + ,const ::rtl::OUString& _sCollectionServiceName + ,const ::rtl::OUString& _sComponentServiceName) : + SvXMLImportContext( rImport, nPrfx, _sLocalName ) + ,m_xParentContainer(_xParentContainer) + ,m_sCollectionServiceName(_sCollectionServiceName) + ,m_sComponentServiceName(_sComponentServiceName) +{ + DBG_CTOR(OXMLHierarchyCollection,NULL); + + const SvXMLNamespaceMap& rMap = rImport.GetNamespaceMap(); + const SvXMLTokenMap& rTokenMap = rImport.GetComponentElemTokenMap(); + + sal_Int16 nLength = (_xAttrList.is()) ? _xAttrList->getLength() : 0; + for(sal_Int16 i = 0; i < nLength; ++i) + { + ::rtl::OUString sLocalName; + rtl::OUString sAttrName = _xAttrList->getNameByIndex( i ); + sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName ); + rtl::OUString sValue = _xAttrList->getValueByIndex( i ); + + switch( rTokenMap.Get( nPrefix, sLocalName ) ) + { + case XML_TOK_COMPONENT_NAME: + m_sName = sValue; + break; + } + } + if ( m_sName.getLength() && _xParentContainer.is() ) + { + try + { + Sequence< Any > aArguments(2); + PropertyValue aValue; + // set as folder + aValue.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Name")); + aValue.Value <<= m_sName; + aArguments[0] <<= aValue; + //parent + aValue.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Parent")); + aValue.Value <<= _xParentContainer; + aArguments[1] <<= aValue; + + Reference<XMultiServiceFactory> xORB(_xParentContainer,UNO_QUERY); + if ( xORB.is() ) + { + m_xContainer.set(xORB->createInstanceWithArguments(_sCollectionServiceName,aArguments),UNO_QUERY); + Reference<XNameContainer> xNameContainer(_xParentContainer,UNO_QUERY); + if ( xNameContainer.is() && !xNameContainer->hasByName(m_sName) ) + xNameContainer->insertByName(m_sName,makeAny(m_xContainer)); + } + } + catch(Exception&) + { + OSL_FAIL("OXMLHierarchyCollection::OXMLHierarchyCollection -> exception catched"); + } + } +} +// ----------------------------------------------------------------------------- +OXMLHierarchyCollection::OXMLHierarchyCollection( ODBFilter& rImport + ,sal_uInt16 nPrfx + ,const ::rtl::OUString& _sLocalName + ,const Reference< XNameAccess >& _xContainer + ,const Reference< XPropertySet >& _xTable + ) : + SvXMLImportContext( rImport, nPrfx, _sLocalName ) + ,m_xContainer(_xContainer) + ,m_xTable(_xTable) +{ + DBG_CTOR(OXMLHierarchyCollection,NULL); +} +// ----------------------------------------------------------------------------- + +OXMLHierarchyCollection::~OXMLHierarchyCollection() +{ + + DBG_DTOR(OXMLHierarchyCollection,NULL); +} +// ----------------------------------------------------------------------------- +SvXMLImportContext* OXMLHierarchyCollection::CreateChildContext( + sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const Reference< XAttributeList > & xAttrList ) +{ + SvXMLImportContext *pContext = 0; + const SvXMLTokenMap& rTokenMap = GetOwnImport().GetDocumentsElemTokenMap(); + + switch( rTokenMap.Get( nPrefix, rLocalName ) ) + { + case XML_TOK_COMPONENT: + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + pContext = new OXMLComponent( GetOwnImport(), nPrefix, rLocalName,xAttrList,m_xContainer,m_sComponentServiceName ); + break; + case XML_TOK_COLUMN: + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + pContext = new OXMLColumn( GetOwnImport(), nPrefix, rLocalName,xAttrList,m_xContainer,m_xTable); + break; + case XML_TOK_COMPONENT_COLLECTION: + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + pContext = new OXMLHierarchyCollection( GetOwnImport(), nPrefix, rLocalName,xAttrList,m_xContainer,m_sCollectionServiceName,m_sComponentServiceName); + break; + } + + if( !pContext ) + pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName ); + + return pContext; +} +// ----------------------------------------------------------------------------- +ODBFilter& OXMLHierarchyCollection::GetOwnImport() +{ + return static_cast<ODBFilter&>(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 000000000000..3d87826a928d --- /dev/null +++ b/dbaccess/source/filter/xml/xmlHierarchyCollection.hxx @@ -0,0 +1,78 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef DBA_XMLHIERARCHYCOLLECTION_HXX +#define DBA_XMLHIERARCHYCOLLECTION_HXX + +#include <xmloff/xmlictxt.hxx> +#include "xmlEnums.hxx" +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> + + +namespace dbaxml +{ + class ODBFilter; + class OXMLHierarchyCollection : public SvXMLImportContext + { + ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > m_xParentContainer; + ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > m_xContainer; + ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > m_xTable; + ::rtl::OUString m_sName; + ::rtl::OUString m_sCollectionServiceName; + ::rtl::OUString m_sComponentServiceName; + + ODBFilter& GetOwnImport(); + public: + + OXMLHierarchyCollection( ODBFilter& rImport + ,sal_uInt16 nPrfx + ,const ::rtl::OUString& rLName + ,const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttrList + ,const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& _xParentContainer + ,const ::rtl::OUString& _sCollectionServiceName + ,const ::rtl::OUString& _sComponentServiceName + ); + OXMLHierarchyCollection( ODBFilter& rImport + ,sal_uInt16 nPrfx + ,const ::rtl::OUString& rLName + ,const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& _xContainer + ,const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _xTable + ); + virtual ~OXMLHierarchyCollection(); + + virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttrList ); + }; +// ----------------------------------------------------------------------------- +} // namespace dbaxml +// ----------------------------------------------------------------------------- + +#endif // DBA_XMLHIERARCHYCOLLECTION_HXX + +/* 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 000000000000..21d30473872b --- /dev/null +++ b/dbaccess/source/filter/xml/xmlLogin.cxx @@ -0,0 +1,142 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_dbaccess.hxx" +#include "xmlLogin.hxx" +#include "xmlfilter.hxx" +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmlnmspe.hxx> +#include <xmloff/nmspmap.hxx> +#include "xmlEnums.hxx" +#include "xmlstrings.hrc" +#include <tools/debug.hxx> +#include <tools/diagnose_ex.h> +#include <com/sun/star/sdbc/XDataSource.hpp> +#include <vector> + +namespace dbaxml +{ + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::sdbc; + using namespace ::com::sun::star::xml::sax; +DBG_NAME(OXMLLogin) + +OXMLLogin::OXMLLogin( ODBFilter& rImport, + sal_uInt16 nPrfx, const ::rtl::OUString& _sLocalName, + const Reference< XAttributeList > & _xAttrList ) : + SvXMLImportContext( rImport, nPrfx, _sLocalName ) +{ + DBG_CTOR(OXMLLogin,NULL); + + OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!"); + const SvXMLNamespaceMap& rMap = rImport.GetNamespaceMap(); + const SvXMLTokenMap& rTokenMap = rImport.GetLoginElemTokenMap(); + + Reference<XPropertySet> xDataSource(rImport.getDataSource()); + + const sal_Int16 nLength = (xDataSource.is() && _xAttrList.is()) ? _xAttrList->getLength() : 0; + static const ::rtl::OUString s_sTRUE = ::xmloff::token::GetXMLToken(XML_TRUE); + bool bUserFound = false; + for(sal_Int16 i = 0; i < nLength; ++i) + { + ::rtl::OUString sLocalName; + rtl::OUString sAttrName = _xAttrList->getNameByIndex( i ); + sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName ); + rtl::OUString sValue = _xAttrList->getValueByIndex( i ); + + try + { + switch( rTokenMap.Get( nPrefix, sLocalName ) ) + { + case XML_TOK_USER_NAME: + if ( !bUserFound ) + { + bUserFound = true; + try + { + xDataSource->setPropertyValue(PROPERTY_USER,makeAny(sValue)); + } + catch(Exception) + { + DBG_UNHANDLED_EXCEPTION(); + } + } + break; + case XML_TOK_IS_PASSWORD_REQUIRED: + try + { + xDataSource->setPropertyValue(PROPERTY_ISPASSWORDREQUIRED,makeAny((sValue == s_sTRUE ? sal_True : sal_False))); + } + catch(Exception) + { + DBG_UNHANDLED_EXCEPTION(); + } + break; + case XML_TOK_USE_SYSTEM_USER: + if ( !bUserFound ) + { + bUserFound = true; + PropertyValue aProperty; + aProperty.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("UseSystemUser")); + aProperty.Value <<= (sValue == s_sTRUE ? sal_True : sal_False); + rImport.addInfo(aProperty); + } + break; + case XML_TOK_LOGIN_TIMEOUT: + try + { + Reference< XDataSource>(xDataSource,UNO_QUERY_THROW)->setLoginTimeout(sValue.toInt32()); + } + catch(Exception) + { + DBG_UNHANDLED_EXCEPTION(); + } + break; + } + } + catch(Exception) + { + DBG_UNHANDLED_EXCEPTION(); + } + } +} +// ----------------------------------------------------------------------------- + +OXMLLogin::~OXMLLogin() +{ + + DBG_DTOR(OXMLLogin,NULL); +} +// ----------------------------------------------------------------------------- + +//---------------------------------------------------------------------------- +} // 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 000000000000..6f2751eb300b --- /dev/null +++ b/dbaccess/source/filter/xml/xmlLogin.hxx @@ -0,0 +1,53 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef DBA_XMLLOGIN_HXX +#define DBA_XMLLOGIN_HXX + +#include <xmloff/xmlictxt.hxx> + +namespace dbaxml +{ + class ODBFilter; + class OXMLLogin : public SvXMLImportContext + { + ODBFilter& GetOwnImport(); + public: + + OXMLLogin( ODBFilter& rImport, sal_uInt16 nPrfx, + const ::rtl::OUString& rLName, + const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttrList ); + virtual ~OXMLLogin(); + + }; +// ----------------------------------------------------------------------------- +} // namespace dbaxml +// ----------------------------------------------------------------------------- + +#endif // DBA_XMLLOGIN_HXX + +/* 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 000000000000..dd083f616e33 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlQuery.cxx @@ -0,0 +1,155 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_dbaccess.hxx" +#include "xmlQuery.hxx" +#include "xmlfilter.hxx" +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmlnmspe.hxx> +#include <xmloff/nmspmap.hxx> +#include "xmlEnums.hxx" +#include "xmlstrings.hrc" +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <tools/debug.hxx> + +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; + +DBG_NAME(OXMLQuery) + +OXMLQuery::OXMLQuery( ODBFilter& rImport + ,sal_uInt16 nPrfx + ,const ::rtl::OUString& _sLocalName + ,const Reference< XAttributeList > & _xAttrList + ,const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& _xParentContainer + ) : + OXMLTable( rImport, nPrfx, _sLocalName,_xAttrList,_xParentContainer,SERVICE_SDB_COMMAND_DEFINITION ) + ,m_bEscapeProcessing(sal_True) +{ + DBG_CTOR(OXMLQuery,NULL); + + OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!"); + const SvXMLNamespaceMap& rMap = rImport.GetNamespaceMap(); + const SvXMLTokenMap& rTokenMap = rImport.GetQueryElemTokenMap(); + + sal_Int16 nLength = (_xAttrList.is()) ? _xAttrList->getLength() : 0; + for(sal_Int16 i = 0; i < nLength; ++i) + { + ::rtl::OUString sLocalName; + rtl::OUString sAttrName = _xAttrList->getNameByIndex( i ); + sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName ); + rtl::OUString sValue = _xAttrList->getValueByIndex( i ); + + switch( rTokenMap.Get( nPrefix, sLocalName ) ) + { + case XML_TOK_COMMAND: + m_sCommand = sValue; + break; + case XML_TOK_ESCAPE_PROCESSING: + m_bEscapeProcessing = sValue.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("true")); + break; + } + } +} +// ----------------------------------------------------------------------------- + +OXMLQuery::~OXMLQuery() +{ + + DBG_DTOR(OXMLQuery,NULL); +} +// ----------------------------------------------------------------------------- +SvXMLImportContext* OXMLQuery::CreateChildContext( + sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const Reference< XAttributeList > & xAttrList ) +{ + SvXMLImportContext* pContext = OXMLTable::CreateChildContext(nPrefix, rLocalName,xAttrList ); + if ( !pContext ) + { + const SvXMLTokenMap& rTokenMap = GetOwnImport().GetQueryElemTokenMap(); + + switch( rTokenMap.Get( nPrefix, rLocalName ) ) + { + case XML_TOK_UPDATE_TABLE: + { + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + ::rtl::OUString s1; + fillAttributes(nPrefix, rLocalName,xAttrList,s1,m_sTable,m_sSchema,m_sCatalog); + } + break; + } + } + + if( !pContext ) + pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName ); + + return pContext; +} +// ----------------------------------------------------------------------------- +void OXMLQuery::setProperties(Reference< XPropertySet > & _xProp ) +{ + try + { + if ( _xProp.is() ) + { + OXMLTable::setProperties(_xProp); + + _xProp->setPropertyValue(PROPERTY_COMMAND,makeAny(m_sCommand)); + _xProp->setPropertyValue(PROPERTY_ESCAPE_PROCESSING,makeAny(m_bEscapeProcessing)); + + if ( m_sTable.getLength() ) + _xProp->setPropertyValue(PROPERTY_UPDATE_TABLENAME,makeAny(m_sTable)); + if ( m_sCatalog.getLength() ) + _xProp->setPropertyValue(PROPERTY_UPDATE_CATALOGNAME,makeAny(m_sCatalog)); + if ( m_sSchema.getLength() ) + _xProp->setPropertyValue(PROPERTY_UPDATE_SCHEMANAME,makeAny(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,makeAny(aFind->second)); + } + } + catch(Exception&) + { + OSL_FAIL("OXMLTable::EndElement -> exception catched"); + } +} +//---------------------------------------------------------------------------- +} // 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 000000000000..4e4bfde87be0 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlQuery.hxx @@ -0,0 +1,65 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef DBA_XMLQUERY_HXX +#define DBA_XMLQUERY_HXX + +#include <xmloff/xmlictxt.hxx> +#include "xmlTable.hxx" + + +namespace dbaxml +{ + class ODBFilter; + class OXMLQuery : public OXMLTable + { + ::rtl::OUString m_sCommand; + ::rtl::OUString m_sTable; + sal_Bool m_bEscapeProcessing; + protected: + virtual void setProperties(::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > & _xProp); + public: + + OXMLQuery( ODBFilter& rImport + , sal_uInt16 nPrfx + ,const ::rtl::OUString& rLName + ,const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttrList + ,const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& _xParentContainer + ); + virtual ~OXMLQuery(); + + virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttrList ); + }; +// ----------------------------------------------------------------------------- +} // namespace dbaxml +// ----------------------------------------------------------------------------- + +#endif // DBA_XMLQUERY_HXX + +/* 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 000000000000..112524ddbe98 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlServerDatabase.cxx @@ -0,0 +1,178 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_dbaccess.hxx" +#include "xmlServerDatabase.hxx" +#include "xmlfilter.hxx" +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmlnmspe.hxx> +#include <xmloff/nmspmap.hxx> +#include "xmlEnums.hxx" +#include "xmlstrings.hrc" +#include <tools/debug.hxx> +#include <tools/diagnose_ex.h> + +namespace dbaxml +{ + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::xml::sax; +DBG_NAME(OXMLServerDatabase) + +OXMLServerDatabase::OXMLServerDatabase( ODBFilter& rImport, + sal_uInt16 nPrfx, const ::rtl::OUString& _sLocalName, + const Reference< XAttributeList > & _xAttrList) : + SvXMLImportContext( rImport, nPrfx, _sLocalName ) +{ + DBG_CTOR(OXMLServerDatabase,NULL); + + OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!"); + const SvXMLNamespaceMap& rMap = rImport.GetNamespaceMap(); + const SvXMLTokenMap& rTokenMap = rImport.GetDataSourceElemTokenMap(); + + Reference<XPropertySet> xDataSource = rImport.getDataSource(); + + PropertyValue aProperty; + + const sal_Int16 nLength = (xDataSource.is() && _xAttrList.is()) ? _xAttrList->getLength() : 0; + ::rtl::OUString sType,sHostName,sPortNumber,sDatabaseName; + for(sal_Int16 i = 0; i < nLength; ++i) + { + ::rtl::OUString sLocalName; + const rtl::OUString sAttrName = _xAttrList->getNameByIndex( i ); + const sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName ); + const rtl::OUString sValue = _xAttrList->getValueByIndex( i ); + + switch( rTokenMap.Get( nPrefix, sLocalName ) ) + { + case XML_TOK_DB_TYPE: + sType = sValue; + break; + case XML_TOK_HOSTNAME: + sHostName = sValue; + break; + case XML_TOK_PORT: + sPortNumber = sValue; + break; + case XML_TOK_LOCAL_SOCKET: + aProperty.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("LocalSocket")); + aProperty.Value <<= sValue; + rImport.addInfo(aProperty); + break; + case XML_TOK_DATABASE_NAME: + sDatabaseName = sValue; + break; + } + } + if ( sType.getLength() ) + { + ::rtl::OUStringBuffer sURL; + if ( sType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "sdbc:mysql:jdbc" ) ) + || sType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "sdbc:mysqlc" ) ) + || sType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "sdbc:mysql:mysqlc" ) ) + ) + { + sURL.append( sType ); + sURL.append( sal_Unicode( ':' ) ); + sURL.append(sHostName); + if ( sPortNumber.getLength() ) + { + sURL.appendAscii(":"); + sURL.append(sPortNumber); + } + if ( sDatabaseName.getLength() ) + { + sURL.appendAscii("/"); + sURL.append(sDatabaseName); + } + } + else if ( sType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "jdbc:oracle:thin" ) ) ) + { + sURL.appendAscii("jdbc:oracle:thin:@"); + sURL.append(sHostName); + if ( sPortNumber.getLength() ) + { + sURL.appendAscii(":"); + sURL.append(sPortNumber); + } + if ( sDatabaseName.getLength() ) + { + sURL.appendAscii(":"); + sURL.append(sDatabaseName); + } + } + else if ( sType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "sdbc:address:ldap" ) ) ) + { + sURL.appendAscii("sdbc:address:ldap:"); + sURL.append(sHostName); + if ( sPortNumber.getLength() ) + { + sURL.appendAscii(":"); + sURL.append(sPortNumber); + } + } + else + { + sURL.append(sType); + sURL.appendAscii(":"); + sURL.append(sHostName); + if ( sPortNumber.getLength() ) + { + sURL.appendAscii(":"); + sURL.append(sPortNumber); + } + if ( sDatabaseName.getLength() ) + { + sURL.appendAscii(":"); + sURL.append(sDatabaseName); + } + } + try + { + xDataSource->setPropertyValue(PROPERTY_URL,makeAny(sURL.makeStringAndClear())); + } + catch(Exception) + { + DBG_UNHANDLED_EXCEPTION(); + } + } +} +// ----------------------------------------------------------------------------- + +OXMLServerDatabase::~OXMLServerDatabase() +{ + + DBG_DTOR(OXMLServerDatabase,NULL); +} +// ----------------------------------------------------------------------------- + +//---------------------------------------------------------------------------- +} // 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 000000000000..c94d2184f793 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlServerDatabase.hxx @@ -0,0 +1,53 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef DBA_XMLSERVERDATABASE_HXX_INCLUDED +#define DBA_XMLSERVERDATABASE_HXX_INCLUDED + +#include <xmloff/xmlictxt.hxx> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <vector> + +namespace dbaxml +{ + class ODBFilter; + class OXMLServerDatabase : public SvXMLImportContext + { + public: + + OXMLServerDatabase( ODBFilter& rImport, sal_uInt16 nPrfx, + const ::rtl::OUString& rLName, + const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttrList); + virtual ~OXMLServerDatabase(); + }; +// ----------------------------------------------------------------------------- +} // namespace dbaxml +// ----------------------------------------------------------------------------- + +#endif // DBA_XMLSERVERDATABASE_HXX_INCLUDED + +/* 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 000000000000..2e1fb2db2bfc --- /dev/null +++ b/dbaccess/source/filter/xml/xmlStyleImport.cxx @@ -0,0 +1,330 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_dbaccess.hxx" + +#include "xmlStyleImport.hxx" + +#include <xmloff/nmspmap.hxx> +#include <xmloff/xmlnmspe.hxx> +#include <xmloff/xmlimppr.hxx> +#include <xmloff/families.hxx> +#include <xmloff/xmlnumfi.hxx> +#include <xmloff/xmltoken.hxx> +#include <com/sun/star/style/XStyleFamiliesSupplier.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/table/BorderLine.hpp> +#include <comphelper/extract.hxx> +#include <xmloff/xmlprcon.hxx> +#include <xmloff/xmluconv.hxx> +#include <osl/diagnose.h> +#include "xmlfilter.hxx" +#include "xmlHelper.hxx" + + +#define XML_LINE_LEFT 0 +#define XML_LINE_RIGHT 1 +#define XML_LINE_TOP 2 +#define XML_LINE_BOTTOM 3 + +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::frame; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::container; +using namespace xmloff::token; + +// ----------------------------------------------------------------------------- +TYPEINIT1( OTableStyleContext, XMLPropStyleContext ); +TYPEINIT1( OTableStylesContext, SvXMLStylesContext ); +DBG_NAME(OTableStyleContext) + +OTableStyleContext::OTableStyleContext( ODBFilter& rImport, + sal_uInt16 nPrfx, const ::rtl::OUString& rLName, + const Reference< XAttributeList > & xAttrList, + SvXMLStylesContext& rStyles, sal_uInt16 nFamily, sal_Bool bDefaultStyle ) + :XMLPropStyleContext( rImport, nPrfx, rLName, xAttrList, rStyles, nFamily, bDefaultStyle ) + ,sNumberFormat(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("NumberFormat"))) + ,pStyles(&rStyles) + ,m_nNumberFormat(-1) + ,bConditionalFormatCreated(sal_False) + ,bParentSet(sal_False) +{ + DBG_CTOR(OTableStyleContext,NULL); + +} +// ----------------------------------------------------------------------------- + +OTableStyleContext::~OTableStyleContext() +{ + + DBG_DTOR(OTableStyleContext,NULL); +} +// ----------------------------------------------------------------------------- + +void OTableStyleContext::FillPropertySet( + const Reference< XPropertySet > & rPropSet ) +{ + if ( !IsDefaultStyle() ) + { + if ( GetFamily() == XML_STYLE_FAMILY_TABLE_TABLE ) + { + if ( sPageStyle.getLength() ) + { + uno::Any aAny; + aAny <<= sPageStyle; + AddProperty(CTF_DB_MASTERPAGENAME, aAny); + } + } + else if ( GetFamily() == XML_STYLE_FAMILY_TABLE_COLUMN ) + { + if ((m_nNumberFormat == -1) && m_sDataStyleName.getLength()) + { + SvXMLNumFormatContext* pStyle = PTR_CAST(SvXMLNumFormatContext,pStyles->FindStyleChildContext( + XML_STYLE_FAMILY_DATA_STYLE, m_sDataStyleName, sal_True)); + if ( !pStyle ) + { + OTableStylesContext* pMyStyles = PTR_CAST(OTableStylesContext,GetOwnImport().GetAutoStyles()); + if ( pMyStyles ) + pStyle = PTR_CAST(SvXMLNumFormatContext,pMyStyles-> + FindStyleChildContext(XML_STYLE_FAMILY_DATA_STYLE, m_sDataStyleName, sal_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<OTableStylesContext *>(pStyles)->GetIndex(nContextID)); + OSL_ENSURE(nIndex != -1, "Property not found in Map"); + XMLPropertyState aPropState(nIndex, rValue); + GetProperties().push_back(aPropState); // has to be insertes in a sort order later +} +// ----------------------------------------------------------------------------- +void OTableStyleContext::SetAttribute( sal_uInt16 nPrefixKey, + const ::rtl::OUString& rLocalName, + const ::rtl::OUString& rValue ) +{ + // TODO: use a map here + if( IsXMLToken(rLocalName, XML_DATA_STYLE_NAME ) ) + m_sDataStyleName = rValue; + else if ( IsXMLToken(rLocalName, XML_MASTER_PAGE_NAME ) ) + sPageStyle = rValue; + else + XMLPropStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue ); +} +// ----------------------------------------------------------------------------- +ODBFilter& OTableStyleContext::GetOwnImport() +{ + return static_cast<ODBFilter&>(GetImport()); +} +// ----------------------------------------------------------------------------- +DBG_NAME(OTableStylesContext) + +OTableStylesContext::OTableStylesContext( SvXMLImport& rImport, + sal_uInt16 nPrfx , + const ::rtl::OUString& rLName , + const Reference< XAttributeList > & xAttrList, + const sal_Bool bTempAutoStyles ) : + SvXMLStylesContext( rImport, nPrfx, rLName, xAttrList ), + sTableStyleServiceName( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( XML_STYLE_FAMILY_TABLE_TABLE_STYLES_NAME ))), + sColumnStyleServiceName( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( XML_STYLE_FAMILY_TABLE_COLUMN_STYLES_NAME ))), + sCellStyleServiceName( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( XML_STYLE_FAMILY_TABLE_CELL_STYLES_NAME ))), + m_nNumberFormatIndex(-1), + bAutoStyles(bTempAutoStyles) +{ + DBG_CTOR(OTableStylesContext,NULL); + +} +// ----------------------------------------------------------------------------- + +OTableStylesContext::~OTableStylesContext() +{ + + DBG_DTOR(OTableStylesContext,NULL); +} +// ----------------------------------------------------------------------------- + +void OTableStylesContext::EndElement() +{ + SvXMLStylesContext::EndElement(); + if (bAutoStyles) + GetImport().GetTextImport()->SetAutoStyles( this ); + else + GetImport().GetStyles()->CopyStylesToDoc(sal_True); +} +// ----------------------------------------------------------------------------- + +UniReference < SvXMLImportPropertyMapper > + OTableStylesContext::GetImportPropertyMapper( + sal_uInt16 nFamily ) const +{ + UniReference < SvXMLImportPropertyMapper > xMapper = SvXMLStylesContext::GetImportPropertyMapper(nFamily); + + if (!xMapper.is()) + { + switch( nFamily ) + { + case XML_STYLE_FAMILY_TABLE_TABLE: + { + if ( !m_xTableImpPropMapper.is() ) + m_xTableImpPropMapper = new SvXMLImportPropertyMapper( const_cast<OTableStylesContext*>(this)->GetOwnImport().GetTableStylesPropertySetMapper(), const_cast<SvXMLImport&>(GetImport()) ); + xMapper = m_xTableImpPropMapper; + } + break; + case XML_STYLE_FAMILY_TABLE_COLUMN: + { + if ( !m_xColumnImpPropMapper.is() ) + m_xColumnImpPropMapper = new SvXMLImportPropertyMapper( const_cast<OTableStylesContext*>(this)->GetOwnImport().GetColumnStylesPropertySetMapper(), const_cast<SvXMLImport&>(GetImport()) ); + xMapper = m_xColumnImpPropMapper; + } + break; + case XML_STYLE_FAMILY_TABLE_CELL: + { + if ( !m_xCellImpPropMapper.is() ) + m_xCellImpPropMapper = new SvXMLImportPropertyMapper( const_cast<OTableStylesContext*>(this)->GetOwnImport().GetCellStylesPropertySetMapper(), const_cast<SvXMLImport&>(GetImport()) ); + xMapper = m_xCellImpPropMapper; + } + break; + } + } + + return xMapper; +} +// ---------------------------------------------------------------------------- +SvXMLStyleContext *OTableStylesContext::CreateStyleStyleChildContext( + sal_uInt16 nFamily, sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, + const Reference< xml::sax::XAttributeList > & xAttrList ) +{ + SvXMLStyleContext *pStyle = SvXMLStylesContext::CreateStyleStyleChildContext( nFamily, nPrefix, + rLocalName, + xAttrList ); + if (!pStyle) + { + switch( nFamily ) + { + case XML_STYLE_FAMILY_TABLE_TABLE: + case XML_STYLE_FAMILY_TABLE_COLUMN: + case XML_STYLE_FAMILY_TABLE_CELL: + pStyle = new OTableStyleContext( GetOwnImport(), nPrefix, rLocalName, + xAttrList, *this, nFamily ); + break; + } + } + + return pStyle; +} +// ----------------------------------------------------------------------------- +Reference < XNameContainer > + OTableStylesContext::GetStylesContainer( sal_uInt16 nFamily ) const +{ + Reference < XNameContainer > xStyles = SvXMLStylesContext::GetStylesContainer(nFamily); + return xStyles; +} +// ----------------------------------------------------------------------------- + +::rtl::OUString OTableStylesContext::GetServiceName( sal_uInt16 nFamily ) const +{ + rtl::OUString sServiceName = SvXMLStylesContext::GetServiceName(nFamily); + if (!sServiceName.getLength()) + { + switch( nFamily ) + { + case XML_STYLE_FAMILY_TABLE_TABLE: + sServiceName = sTableStyleServiceName; + break; + case XML_STYLE_FAMILY_TABLE_COLUMN: + sServiceName = sColumnStyleServiceName; + break; + case XML_STYLE_FAMILY_TABLE_CELL: + sServiceName = sCellStyleServiceName; + break; + + } + } + return sServiceName; +} +// ----------------------------------------------------------------------------- + +sal_Int32 OTableStylesContext::GetIndex(const sal_Int16 nContextID) +{ + if ( nContextID == CTF_DB_NUMBERFORMAT ) + { + if (m_nNumberFormatIndex == -1) + m_nNumberFormatIndex = + GetImportPropertyMapper(XML_STYLE_FAMILY_TABLE_COLUMN)->getPropertySetMapper()->FindEntryIndex(nContextID); + return m_nNumberFormatIndex; + } + else if ( nContextID == CTF_DB_MASTERPAGENAME ) + { + if (nMasterPageNameIndex == -1) + nMasterPageNameIndex = + GetImportPropertyMapper(XML_STYLE_FAMILY_TABLE_TABLE)->getPropertySetMapper()->FindEntryIndex(nContextID); + return nMasterPageNameIndex; + } + else if ( nContextID == CTF_DB_ISVISIBLE ) + { + return -1; + } + else + return -1; +} +// ----------------------------------------------------------------------------- +ODBFilter& OTableStylesContext::GetOwnImport() +{ + return static_cast<ODBFilter&>(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 000000000000..87c93c793c02 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlStyleImport.hxx @@ -0,0 +1,139 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef DBA_XMLSTYLEIMPORT_HXX +#define DBA_XMLSTYLEIMPORT_HXX + +#include <rtl/ustring.hxx> +#include <xmloff/xmlimp.hxx> +#include <xmloff/xmlictxt.hxx> +#include <xmloff/maptype.hxx> +#include <xmloff/prstylei.hxx> +#include <xmloff/xmlimppr.hxx> +#include <xmloff/XMLTextMasterPageContext.hxx> +#include <xmloff/XMLTextMasterStylesContext.hxx> +#include <xmloff/contextid.hxx> +#include <xmloff/controlpropertyhdl.hxx> +#include <vector> + +namespace dbaxml +{ + class ODBFilter; + + class OTableStyleContext : public XMLPropStyleContext + { + ::rtl::OUString m_sDataStyleName; + ::rtl::OUString sPageStyle; + const rtl::OUString sNumberFormat; + SvXMLStylesContext* pStyles; + com::sun::star::uno::Any aConditionalFormat; + sal_Int32 m_nNumberFormat; + sal_Bool bConditionalFormatCreated : 1; + sal_Bool bParentSet : 1; + + ODBFilter& GetOwnImport(); + + protected: + + virtual void SetAttribute( sal_uInt16 nPrefixKey, + const ::rtl::OUString& rLocalName, + const ::rtl::OUString& rValue ); + + public: + + TYPEINFO(); + + OTableStyleContext( ODBFilter& rImport, sal_uInt16 nPrfx, + const ::rtl::OUString& rLName, + const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttrList, + SvXMLStylesContext& rStyles, sal_uInt16 nFamily, sal_Bool bDefaultStyle = sal_False ); + + virtual ~OTableStyleContext(); + + + virtual void FillPropertySet(const ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet > & rPropSet ); + + virtual void SetDefaults(); + + void AddProperty(sal_Int16 nContextID, const com::sun::star::uno::Any& aValue); + + sal_Int32 GetNumberFormat() { return m_nNumberFormat; } + }; + + class OTableStylesContext : public SvXMLStylesContext + { + const ::rtl::OUString sTableStyleServiceName; + const ::rtl::OUString sColumnStyleServiceName; + const ::rtl::OUString sCellStyleServiceName; + sal_Int32 m_nNumberFormatIndex; + sal_Int32 nMasterPageNameIndex; + sal_Bool bAutoStyles : 1; + + mutable UniReference < SvXMLImportPropertyMapper > m_xTableImpPropMapper; + mutable UniReference < SvXMLImportPropertyMapper > m_xColumnImpPropMapper; + mutable UniReference < SvXMLImportPropertyMapper > m_xCellImpPropMapper; + + ODBFilter& GetOwnImport(); + + protected: + + // Create a style context. + virtual SvXMLStyleContext *CreateStyleStyleChildContext( + sal_uInt16 nFamily, + sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttrList ); + + public: + + TYPEINFO(); + + OTableStylesContext( SvXMLImport& rImport, sal_uInt16 nPrfx , + const ::rtl::OUString& rLName , + const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttrList, + const sal_Bool bAutoStyles ); + virtual ~OTableStylesContext(); + + virtual void EndElement(); + + virtual UniReference < SvXMLImportPropertyMapper > GetImportPropertyMapper( + sal_uInt16 nFamily ) const; + virtual ::com::sun::star::uno::Reference < + ::com::sun::star::container::XNameContainer > + GetStylesContainer( sal_uInt16 nFamily ) const; + virtual ::rtl::OUString GetServiceName( sal_uInt16 nFamily ) const; + + sal_Int32 GetIndex(const sal_Int16 nContextID); + }; +// ----------------------------------------------------------------------------- +} // dbaxml +// ----------------------------------------------------------------------------- +#endif // DBA_XMLSTYLEIMPORT_HXX + +/* 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 000000000000..21958d06a28e --- /dev/null +++ b/dbaccess/source/filter/xml/xmlTable.cxx @@ -0,0 +1,270 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_dbaccess.hxx" +#include "xmlTable.hxx" +#include "xmlfilter.hxx" +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmlnmspe.hxx> +#include <xmloff/nmspmap.hxx> +#include "xmlEnums.hxx" +#include "xmlStyleImport.hxx" +#include "xmlHierarchyCollection.hxx" +#include "xmlstrings.hrc" +#include <ucbhelper/content.hxx> +#include <com/sun/star/ucb/XCommandEnvironment.hpp> +#include <com/sun/star/sdbcx/XColumnsSupplier.hpp> +#include <comphelper/namecontainer.hxx> +#include <tools/debug.hxx> + +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; +DBG_NAME(OXMLTable) + +OXMLTable::OXMLTable( ODBFilter& _rImport + ,sal_uInt16 nPrfx + ,const ::rtl::OUString& _sLocalName + ,const uno::Reference< XAttributeList > & _xAttrList + ,const uno::Reference< ::com::sun::star::container::XNameAccess >& _xParentContainer + ,const ::rtl::OUString& _sServiceName + ) + :SvXMLImportContext( _rImport, nPrfx, _sLocalName ) + ,m_xParentContainer(_xParentContainer) + ,m_sServiceName(_sServiceName) + ,m_bApplyFilter(sal_False) + ,m_bApplyOrder(sal_False) +{ + DBG_CTOR(OXMLTable,NULL); + + OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!"); + const SvXMLNamespaceMap& rMap = GetOwnImport().GetNamespaceMap(); + const SvXMLTokenMap& rTokenMap = GetOwnImport().GetQueryElemTokenMap(); + + sal_Int16 nLength = (_xAttrList.is()) ? _xAttrList->getLength() : 0; + for(sal_Int16 i = 0; i < nLength; ++i) + { + ::rtl::OUString sLocalName; + rtl::OUString sAttrName = _xAttrList->getNameByIndex( i ); + sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName ); + rtl::OUString sValue = _xAttrList->getValueByIndex( i ); + + switch( rTokenMap.Get( nPrefix, sLocalName ) ) + { + case XML_TOK_QUERY_NAME: + m_sName = sValue; + break; + case XML_TOK_CATALOG_NAME: + m_sCatalog = sValue; + break; + case XML_TOK_SCHEMA_NAME: + m_sSchema = sValue; + break; + case XML_TOK_STYLE_NAME: + m_sStyleName = sValue; + break; + case XML_TOK_APPLY_FILTER: + m_bApplyFilter = sValue.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("true")); + break; + case XML_TOK_APPLY_ORDER: + m_bApplyOrder = sValue.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("true")); + break; + } + } + Sequence< Any > aArguments(2); + PropertyValue aValue; + // set as folder + aValue.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Name")); + aValue.Value <<= m_sName; + aArguments[0] <<= aValue; + //parent + aValue.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Parent")); + aValue.Value <<= m_xParentContainer; + aArguments[1] <<= aValue; + m_xTable.set(GetOwnImport().getORB()->createInstanceWithArguments(m_sServiceName,aArguments),UNO_QUERY); +} +// ----------------------------------------------------------------------------- + +OXMLTable::~OXMLTable() +{ + + DBG_DTOR(OXMLTable,NULL); +} +// ----------------------------------------------------------------------------- +SvXMLImportContext* OXMLTable::CreateChildContext( + sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const uno::Reference< XAttributeList > & xAttrList ) +{ + SvXMLImportContext *pContext = 0; + const SvXMLTokenMap& rTokenMap = GetOwnImport().GetQueryElemTokenMap(); + + switch( rTokenMap.Get( nPrefix, rLocalName ) ) + { + case XML_TOK_FILTER_STATEMENT: + { + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + ::rtl::OUString s1,s2,s3; + fillAttributes(nPrefix, rLocalName,xAttrList,m_sFilterStatement,s1,s2,s3); + } + break; + case XML_TOK_ORDER_STATEMENT: + { + GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + ::rtl::OUString s1,s2,s3; + fillAttributes(nPrefix, rLocalName,xAttrList,m_sOrderStatement,s1,s2,s3); + } + break; + + case XML_TOK_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(), nPrefix, rLocalName ,xColumns,m_xTable); + } + break; + } + + if( !pContext ) + pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName ); + + return pContext; +} +// ----------------------------------------------------------------------------- +ODBFilter& OXMLTable::GetOwnImport() +{ + return static_cast<ODBFilter&>(GetImport()); +} +// ----------------------------------------------------------------------------- +void OXMLTable::setProperties(uno::Reference< XPropertySet > & _xProp ) +{ + try + { + if ( _xProp.is() ) + { + _xProp->setPropertyValue(PROPERTY_APPLYFILTER,makeAny(m_bApplyFilter)); + _xProp->setPropertyValue(PROPERTY_FILTER,makeAny(m_sFilterStatement)); + + if ( _xProp->getPropertySetInfo()->hasPropertyByName(PROPERTY_APPLYORDER) ) + _xProp->setPropertyValue(PROPERTY_APPLYORDER,makeAny(m_bApplyOrder)); + _xProp->setPropertyValue(PROPERTY_ORDER,makeAny(m_sOrderStatement)); + } + } + catch(Exception&) + { + OSL_FAIL("OXMLTable::EndElement -> exception catched"); + } +} +// ----------------------------------------------------------------------------- +void OXMLTable::EndElement() +{ + uno::Reference<XNameContainer> xNameContainer(m_xParentContainer,UNO_QUERY); + if ( xNameContainer.is() ) + { + try + { + if ( m_xTable.is() ) + { + setProperties(m_xTable); + + if ( m_sStyleName.getLength() ) + { + const SvXMLStylesContext* pAutoStyles = GetOwnImport().GetAutoStyles(); + if ( pAutoStyles ) + { + OTableStyleContext* pAutoStyle = PTR_CAST(OTableStyleContext,pAutoStyles->FindStyleChildContext(XML_STYLE_FAMILY_TABLE_TABLE,m_sStyleName)); + if ( pAutoStyle ) + { + pAutoStyle->FillPropertySet(m_xTable); + } + } + } + + xNameContainer->insertByName(m_sName,makeAny(m_xTable)); + } + } + catch(Exception&) + { + OSL_FAIL("OXMLQuery::EndElement -> exception catched"); + } + } + +} +// ----------------------------------------------------------------------------- +void OXMLTable::fillAttributes(sal_uInt16 /*nPrfx*/ + ,const ::rtl::OUString& /*_sLocalName*/ + ,const uno::Reference< XAttributeList > & _xAttrList + , ::rtl::OUString& _rsCommand + ,::rtl::OUString& _rsTableName + ,::rtl::OUString& _rsTableSchema + ,::rtl::OUString& _rsTableCatalog + ) +{ + OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!"); + const SvXMLNamespaceMap& rMap = GetOwnImport().GetNamespaceMap(); + const SvXMLTokenMap& rTokenMap = GetOwnImport().GetQueryElemTokenMap(); + + sal_Int16 nLength = (_xAttrList.is()) ? _xAttrList->getLength() : 0; + for(sal_Int16 i = 0; i < nLength; ++i) + { + ::rtl::OUString sLocalName; + rtl::OUString sAttrName = _xAttrList->getNameByIndex( i ); + sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName ); + rtl::OUString sValue = _xAttrList->getValueByIndex( i ); + + switch( rTokenMap.Get( nPrefix, sLocalName ) ) + { + case XML_TOK_COMMAND: + _rsCommand = sValue; + break; + case XML_TOK_CATALOG_NAME: + _rsTableCatalog = sValue; + break; + case XML_TOK_SCHEMA_NAME: + _rsTableSchema = sValue; + break; + case XML_TOK_QUERY_NAME: + _rsTableName = sValue; + break; + } + } +} +//---------------------------------------------------------------------------- +} // 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 000000000000..925497ce92a8 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlTable.hxx @@ -0,0 +1,88 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef DBA_XMLTABLE_HXX +#define DBA_XMLTABLE_HXX + +#include <xmloff/xmlictxt.hxx> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XNameAccess.hpp> + +namespace dbaxml +{ + class ODBFilter; + class OXMLTable : public SvXMLImportContext + { + protected: + ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > m_xParentContainer; + ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > m_xTable; + ::rtl::OUString m_sFilterStatement; + ::rtl::OUString m_sOrderStatement; + ::rtl::OUString m_sName; + ::rtl::OUString m_sSchema; + ::rtl::OUString m_sCatalog; + ::rtl::OUString m_sStyleName; + ::rtl::OUString m_sServiceName; + sal_Bool m_bApplyFilter; + sal_Bool m_bApplyOrder; + + + ODBFilter& GetOwnImport(); + + void fillAttributes( sal_uInt16 nPrfx + ,const ::rtl::OUString& _sLocalName + ,const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttrList + , ::rtl::OUString& _rsCommand + ,::rtl::OUString& _rsTableName + ,::rtl::OUString& _rsTableSchema + ,::rtl::OUString& _rsTableCatalog + ); + + virtual void setProperties(::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > & _xProp); + public: + + OXMLTable( ODBFilter& rImport + , sal_uInt16 nPrfx + ,const ::rtl::OUString& rLName + ,const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttrList + ,const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& _xParentContainer + ,const ::rtl::OUString& _sServiceName + ); + virtual ~OXMLTable(); + + virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttrList ); + virtual void EndElement(); + }; +// ----------------------------------------------------------------------------- +} // namespace dbaxml +// ----------------------------------------------------------------------------- + +#endif // DBA_XMLTABLE_HXX + +/* 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 000000000000..4291c244a341 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlTableFilterList.cxx @@ -0,0 +1,111 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_dbaccess.hxx" +#include "xmlTableFilterList.hxx" +#include "xmlTableFilterPattern.hxx" +#include "xmlEnums.hxx" +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmlnmspe.hxx> +#include <xmloff/nmspmap.hxx> +#include <xmloff/xmltoken.hxx> +#include "xmlstrings.hrc" +#include <com/sun/star/beans/XPropertySet.hpp> +#include <xmloff/xmlimp.hxx> +#include "xmlfilter.hxx" +#include <tools/debug.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; +DBG_NAME(OXMLTableFilterList) + +OXMLTableFilterList::OXMLTableFilterList( SvXMLImport& rImport, sal_uInt16 nPrfx, const ::rtl::OUString& _sLocalName ) + :SvXMLImportContext( rImport, nPrfx, _sLocalName ) +{ + DBG_CTOR(OXMLTableFilterList,NULL); + +} +// ----------------------------------------------------------------------------- + +OXMLTableFilterList::~OXMLTableFilterList() +{ + DBG_DTOR(OXMLTableFilterList,NULL); +} +// ----------------------------------------------------------------------------- + +SvXMLImportContext* OXMLTableFilterList::CreateChildContext( + sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const Reference< XAttributeList > & /*xAttrList*/ ) +{ + SvXMLImportContext *pContext = 0; + + if ( XML_NAMESPACE_DB == nPrefix ) + { + GetImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + if ( IsXMLToken( rLocalName, XML_TABLE_FILTER_PATTERN ) ) + pContext = new OXMLTableFilterPattern( GetImport(), nPrefix, rLocalName,sal_True,*this); + else if ( IsXMLToken( rLocalName, XML_TABLE_TYPE ) ) + pContext = new OXMLTableFilterPattern( GetImport(), nPrefix, rLocalName,sal_False,*this); + else if ( IsXMLToken( rLocalName, XML_TABLE_INCLUDE_FILTER ) ) + pContext = new OXMLTableFilterList( GetImport(), nPrefix, rLocalName ); + } + + if( !pContext ) + pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName ); + + return pContext; +} +// ----------------------------------------------------------------------------- +ODBFilter& OXMLTableFilterList::GetOwnImport() +{ + return static_cast<ODBFilter&>(GetImport()); +} + +// ----------------------------------------------------------------------------- +void OXMLTableFilterList::EndElement() +{ + Reference<XPropertySet> xDataSource(GetOwnImport().getDataSource()); + if ( xDataSource.is() ) + { + if ( !m_aPatterns.empty() ) + xDataSource->setPropertyValue(PROPERTY_TABLEFILTER,makeAny(Sequence< ::rtl::OUString>(&(*m_aPatterns.begin()),m_aPatterns.size()))); + if ( !m_aTypes.empty() ) + xDataSource->setPropertyValue(PROPERTY_TABLETYPEFILTER,makeAny(Sequence< ::rtl::OUString>(&(*m_aTypes.begin()),m_aTypes.size()))); + } +} +//---------------------------------------------------------------------------- +} // 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 000000000000..d288b23ae7d1 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlTableFilterList.hxx @@ -0,0 +1,80 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef DBA_XMLTABLEFILTERLIST_HXX +#define DBA_XMLTABLEFILTERLIST_HXX + +#include <xmloff/xmlictxt.hxx> +#include <vector> + +namespace dbaxml +{ + class ODBFilter; + class OXMLTableFilterList : public SvXMLImportContext + { + ::std::vector< ::rtl::OUString> m_aPatterns; + ::std::vector< ::rtl::OUString> m_aTypes; + + ODBFilter& GetOwnImport(); + public: + + OXMLTableFilterList( SvXMLImport& rImport, sal_uInt16 nPrfx, + const ::rtl::OUString& rLName); + + virtual ~OXMLTableFilterList(); + + virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttrList ); + + virtual void EndElement(); + + /** pushes a new TableFilterPattern to the list of patterns + @param _sTableFilterPattern + The new filter pattern. + */ + inline void pushTableFilterPattern(const ::rtl::OUString& _sTableFilterPattern) + { + m_aPatterns.push_back(_sTableFilterPattern); + } + + /** pushes a new TableTypeFilter to the list of patterns + @param _sTypeFilter + The new type filter. + */ + inline void pushTableTypeFilter(const ::rtl::OUString& _sTypeFilter) + { + m_aTypes.push_back(_sTypeFilter); + } + }; +// ----------------------------------------------------------------------------- +} // namespace dbaxml +// ----------------------------------------------------------------------------- + +#endif // DBA_XMLTABLEFILTERLIST_HXX + +/* 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 000000000000..12ce89a823f1 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlTableFilterPattern.cxx @@ -0,0 +1,73 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_dbaccess.hxx" +#include "xmlTableFilterPattern.hxx" +#include "xmlTableFilterList.hxx" +#include <tools/debug.hxx> + +namespace dbaxml +{ + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::xml::sax; +DBG_NAME(OXMLTableFilterPattern) + +OXMLTableFilterPattern::OXMLTableFilterPattern( SvXMLImport& rImport, + sal_uInt16 nPrfx + ,const ::rtl::OUString& _sLocalName + ,sal_Bool _bNameFilter + ,OXMLTableFilterList& _rParent) + :SvXMLImportContext( rImport, nPrfx, _sLocalName ) + ,m_rParent(_rParent) + ,m_bNameFilter(_bNameFilter) +{ + DBG_CTOR(OXMLTableFilterPattern,NULL); + +} +// ----------------------------------------------------------------------------- + +OXMLTableFilterPattern::~OXMLTableFilterPattern() +{ + + DBG_DTOR(OXMLTableFilterPattern,NULL); +} +// ----------------------------------------------------------------------------- +void OXMLTableFilterPattern::Characters( const ::rtl::OUString& rChars ) +{ + if ( m_bNameFilter ) + m_rParent.pushTableFilterPattern(rChars); + else + m_rParent.pushTableTypeFilter(rChars); +} + +//---------------------------------------------------------------------------- +} // 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 000000000000..460d896ecc89 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlTableFilterPattern.hxx @@ -0,0 +1,57 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef DBA_XMLTABLEFILTERPATTERN_HXX +#define DBA_XMLTABLEFILTERPATTERN_HXX + +#include <xmloff/xmlictxt.hxx> + +namespace dbaxml +{ + class OXMLTableFilterList; + class OXMLTableFilterPattern : public SvXMLImportContext + { + OXMLTableFilterList& m_rParent; + sal_Bool m_bNameFilter; + public: + OXMLTableFilterPattern( SvXMLImport& rImport + ,sal_uInt16 nPrfx + ,const ::rtl::OUString& rLName + ,sal_Bool _bNameFilter + ,OXMLTableFilterList& _rParent); + + virtual ~OXMLTableFilterPattern(); + + virtual void Characters( const ::rtl::OUString& rChars ); + }; +// ----------------------------------------------------------------------------- +} // namespace dbaxml +// ----------------------------------------------------------------------------- + +#endif // DBA_XMLTABLEFILTERPATTERN_HXX + +/* 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 000000000000..5814c969eb92 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlfilter.cxx @@ -0,0 +1,921 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ + /************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_dbaccess.hxx" + +#include <com/sun/star/packages/zip/ZipIOException.hpp> +#include <com/sun/star/embed/ElementModes.hpp> +#include <com/sun/star/sdb/XOfficeDatabaseDocument.hpp> +#include "xmlfilter.hxx" +#include "flt_reghelper.hxx" +#include <vcl/svapp.hxx> +#include <vcl/window.hxx> +#include <xmloff/xmlnmspe.hxx> +#include <xmloff/xmlscripti.hxx> +#include <xmloff/xmltoken.hxx> +#include <xmloff/txtimp.hxx> +#include <xmloff/nmspmap.hxx> +#include <rtl/logfile.hxx> +#include <com/sun/star/xml/sax/InputSource.hpp> +#include <com/sun/star/xml/sax/XParser.hpp> +#include <xmloff/ProgressBarHelper.hxx> +#include <sfx2/docfile.hxx> +#include <com/sun/star/io/XInputStream.hpp> +#include <com/sun/star/uno/XNamingService.hpp> +#include "xmlDatabase.hxx" +#include "xmlEnums.hxx" +#include <tools/urlobj.hxx> +#include "xmlstrings.hrc" +#include <xmloff/DocumentSettingsContext.hxx> +#include "xmlStyleImport.hxx" +#include <xmloff/xmluconv.hxx> +#include "xmlHelper.hxx" +#include <com/sun/star/util/XModifiable.hpp> +#include <com/sun/star/frame/XComponentLoader.hpp> +#include <com/sun/star/frame/FrameSearchFlag.hpp> +#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp> +#include <vcl/svapp.hxx> +#include <osl/mutex.hxx> +#include <svtools/sfxecode.hxx> +#include <unotools/moduleoptions.hxx> +#include <toolkit/helper/vclunohelper.hxx> +#include <tools/diagnose_ex.h> +#include <osl/diagnose.h> +#include <comphelper/namedvaluecollection.hxx> +#include <comphelper/mimeconfighelper.hxx> +#include <comphelper/documentconstants.hxx> +#include <comphelper/uno3.hxx> +#include <cppuhelper/exc_hlp.hxx> +#include <osl/thread.hxx> +#include <connectivity/CommonTools.hxx> +#include <connectivity/DriversConfig.hxx> +#include "dsntypes.hxx" + +using namespace ::com::sun::star; + +extern "C" void SAL_CALL createRegistryInfo_ODBFilter( ) +{ + static ::dbaxml::OMultiInstanceAutoRegistration< ::dbaxml::ODBFilter > aAutoRegistration; +} +//-------------------------------------------------------------------------- +namespace dbaxml +{ + namespace + { + class FastLoader : public ::osl::Thread + { + public: + typedef enum { E_JAVA, E_CALC } StartType; + FastLoader(uno::Reference< lang::XMultiServiceFactory > const & _xFactory,StartType _eType) + :m_xFactory(_xFactory) + ,m_eWhat(_eType) + {} + + protected: + virtual ~FastLoader(){} + + /// Working method which should be overridden. + virtual void SAL_CALL run(); + virtual void SAL_CALL onTerminated(); + private: + uno::Reference< lang::XMultiServiceFactory > m_xFactory; + StartType m_eWhat; + }; + + void SAL_CALL FastLoader::run() + { + if ( m_eWhat == E_JAVA ) + { + static bool s_bFirstTime = true; + if ( s_bFirstTime ) + { + s_bFirstTime = false; + try + { + ::rtl::Reference< jvmaccess::VirtualMachine > xJVM = ::connectivity::getJavaVM(m_xFactory); + } + catch(uno::Exception& ex) + { + (void)ex; + OSL_ASSERT(0); + } + } + } + else if ( m_eWhat == E_CALC ) + { + static bool s_bFirstTime = true; + if ( s_bFirstTime ) + { + s_bFirstTime = false; + try + { + uno::Reference<frame::XComponentLoader> xFrameLoad( m_xFactory->createInstance( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.Desktop"))) + ,uno::UNO_QUERY); + const ::rtl::OUString sTarget(RTL_CONSTASCII_USTRINGPARAM("_blank")); + sal_Int32 nFrameSearchFlag = frame::FrameSearchFlag::TASKS | frame::FrameSearchFlag::CREATE; + uno::Reference< frame::XFrame> xFrame = uno::Reference< frame::XFrame>(xFrameLoad,uno::UNO_QUERY_THROW)->findFrame(sTarget,nFrameSearchFlag); + xFrameLoad.set( xFrame,uno::UNO_QUERY); + + if ( xFrameLoad.is() ) + { + uno::Sequence < beans::PropertyValue > aArgs( 3); + sal_Int32 nLen = 0; + aArgs[nLen].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AsTemplate")); + aArgs[nLen++].Value <<= sal_False; + + aArgs[nLen].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ReadOnly")); + aArgs[nLen++].Value <<= sal_True; + + aArgs[nLen].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Hidden")); + aArgs[nLen++].Value <<= sal_True; + + ::comphelper::MimeConfigurationHelper aHelper(m_xFactory); + SvtModuleOptions aModuleOptions; + uno::Reference< frame::XModel > xModel(xFrameLoad->loadComponentFromURL( + aModuleOptions.GetFactoryEmptyDocumentURL( aModuleOptions.ClassifyFactoryByServiceName( aHelper.GetDocServiceNameFromMediaType(MIMETYPE_OASIS_OPENDOCUMENT_SPREADSHEET) )), + ::rtl::OUString(), // empty frame name + 0, + aArgs + ),uno::UNO_QUERY); + ::comphelper::disposeComponent(xModel); + } + } + catch(uno::Exception& ex) + { + (void)ex; + OSL_ASSERT(0); + } + } + } + } + void SAL_CALL FastLoader::onTerminated() + { + delete this; + } + + class DatasourceURLListener : public ::cppu::WeakImplHelper1< beans::XPropertyChangeListener > + { + uno::Reference< lang::XMultiServiceFactory > m_xFactory; + ::dbaccess::ODsnTypeCollection m_aTypeCollection; + DatasourceURLListener(const DatasourceURLListener&); + void operator =(const DatasourceURLListener&); + protected: + virtual ~DatasourceURLListener(){} + public: + DatasourceURLListener(uno::Reference< lang::XMultiServiceFactory > const & _xFactory) : m_xFactory(_xFactory),m_aTypeCollection(_xFactory){} + // XPropertyChangeListener + virtual void SAL_CALL propertyChange( const beans::PropertyChangeEvent& _rEvent ) throw (uno::RuntimeException) + { + ::rtl::OUString sURL; + _rEvent.NewValue >>= sURL; + FastLoader* pCreatorThread = NULL; + + if ( m_aTypeCollection.needsJVM(sURL) ) + { + pCreatorThread = new FastLoader(m_xFactory,FastLoader::E_JAVA); + } + else if ( sURL.matchIgnoreAsciiCaseAsciiL("sdbc:calc:",10,0) ) + { + pCreatorThread = new FastLoader(m_xFactory,FastLoader::E_CALC); + } + if ( pCreatorThread ) + { + pCreatorThread->createSuspended(); + pCreatorThread->setPriority(osl_Thread_PriorityBelowNormal); + pCreatorThread->resume(); + } + } + // XEventListener + virtual void SAL_CALL disposing( const lang::EventObject& /*_rSource*/ ) throw (uno::RuntimeException) + { + } + }; + } + sal_Char const sXML_np__db[] = "_db"; + sal_Char const sXML_np___db[] = "__db"; + + using namespace ::com::sun::star::util; + /// read a component (file + filter version) +sal_Int32 ReadThroughComponent( + const uno::Reference<XInputStream>& xInputStream, + const uno::Reference<XComponent>& xModelComponent, + const uno::Reference<XMultiServiceFactory> & rFactory, + const uno::Reference< XDocumentHandler >& _xFilter ) +{ + OSL_ENSURE(xInputStream.is(), "input stream missing"); + OSL_ENSURE(xModelComponent.is(), "document missing"); + OSL_ENSURE(rFactory.is(), "factory missing"); + + RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "dbaxml", "oj", "ReadThroughComponent" ); + + // prepare ParserInputSrouce + InputSource aParserInput; + aParserInput.aInputStream = xInputStream; + + // get parser + uno::Reference< XParser > xParser( + rFactory->createInstance( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.xml.sax.Parser"))), + UNO_QUERY ); + OSL_ENSURE( xParser.is(), "Can't create parser" ); + if( !xParser.is() ) + return 1; + RTL_LOGFILE_CONTEXT_TRACE( aLog, "parser created" ); + + // get filter + OSL_ENSURE( _xFilter.is(), "Can't instantiate filter component." ); + if( !_xFilter.is() ) + return 1; + + // connect parser and filter + xParser->setDocumentHandler( _xFilter ); + + // connect model and filter + uno::Reference < XImporter > xImporter( _xFilter, UNO_QUERY ); + xImporter->setTargetDocument( xModelComponent ); + + + + // finally, parser the stream + try + { + xParser->parseStream( aParserInput ); + } +#if OSL_DEBUG_LEVEL > 1 + catch( SAXParseException& r ) + { + ByteString aError( "SAX parse exception catched while importing:\n" ); + aError += ByteString( String( r.Message), RTL_TEXTENCODING_ASCII_US ); + aError += ByteString::CreateFromInt32( r.LineNumber ); + aError += ','; + aError += ByteString::CreateFromInt32( r.ColumnNumber ); + + OSL_FAIL( aError.GetBuffer() ); + return 1; + } +#else + catch( SAXParseException& ) + { + return 1; + } +#endif + catch( SAXException& ) + { + return 1; + } + catch( packages::zip::ZipIOException& ) + { + return ERRCODE_IO_BROKENPACKAGE; + } + catch( Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + + // success! + return 0; +} + +/// read a component (storage version) +sal_Int32 ReadThroughComponent( + uno::Reference< embed::XStorage > xStorage, + const uno::Reference<XComponent>& xModelComponent, + const sal_Char* pStreamName, + const sal_Char* pCompatibilityStreamName, + const uno::Reference<XMultiServiceFactory> & rFactory, + const uno::Reference< XDocumentHandler >& _xFilter) +{ + OSL_ENSURE( xStorage.is(), "Need storage!"); + OSL_ENSURE(NULL != pStreamName, "Please, please, give me a name!"); + + if ( xStorage.is() ) + { + uno::Reference< io::XStream > xDocStream; + sal_Bool bEncrypted = sal_False; + + try + { + // open stream (and set parser input) + ::rtl::OUString sStreamName = ::rtl::OUString::createFromAscii(pStreamName); + if ( !xStorage->hasByName( sStreamName ) || !xStorage->isStreamElement( sStreamName ) ) + { + // stream name not found! Then try the compatibility name. + // if no stream can be opened, return immediatly with OK signal + + // do we even have an alternative name? + if ( NULL == pCompatibilityStreamName ) + return 0; + + // if so, does the stream exist? + sStreamName = ::rtl::OUString::createFromAscii(pCompatibilityStreamName); + if ( !xStorage->hasByName( sStreamName ) || !xStorage->isStreamElement( sStreamName ) ) + return 0; + } + + // get input stream + xDocStream = xStorage->openStreamElement( sStreamName, embed::ElementModes::READ ); + + uno::Reference< beans::XPropertySet > xProps( xDocStream, uno::UNO_QUERY_THROW ); + uno::Any aAny = xProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Encrypted") ) ); + aAny >>= bEncrypted; + } + catch( packages::WrongPasswordException& ) + { + return ERRCODE_SFX_WRONGPASSWORD; + } + catch ( uno::Exception& ) + { + return 1; // TODO/LATER: error handling + } + +#ifdef TIMELOG + // if we do profiling, we want to know the stream + RTL_LOGFILE_TRACE_AUTHOR1( "dbaxml", "oj", + "ReadThroughComponent : parsing \"%s\"", pStreamName ); +#endif + + uno::Reference< XInputStream > xInputStream = xDocStream->getInputStream(); + // read from the stream + return ReadThroughComponent( xInputStream + ,xModelComponent + ,rFactory + ,_xFilter ); + } + + // TODO/LATER: better error handling + return 1; +} + +// ------------- +// - ODBFilter - +// ------------- +DBG_NAME(ODBFilter) + +ODBFilter::ODBFilter( const uno::Reference< XMultiServiceFactory >& _rxMSF ) + :SvXMLImport(_rxMSF) + ,m_bNewFormat(false) +{ + DBG_CTOR(ODBFilter,NULL); + + GetMM100UnitConverter().setCoreMeasureUnit(MAP_10TH_MM); + GetMM100UnitConverter().setXMLMeasureUnit(MAP_CM); + GetNamespaceMap().Add( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__db) ), + GetXMLToken(XML_N_DB), + XML_NAMESPACE_DB ); + + GetNamespaceMap().Add( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np___db) ), + GetXMLToken(XML_N_DB_OASIS), + XML_NAMESPACE_DB ); +} + +// ----------------------------------------------------------------------------- + +ODBFilter::~ODBFilter() throw() +{ + + DBG_DTOR(ODBFilter,NULL); +} +// ----------------------------------------------------------------------------- +IMPLEMENT_SERVICE_INFO1_STATIC( ODBFilter, "com.sun.star.comp.sdb.DBFilter", "com.sun.star.document.ImportFilter") +// ----------------------------------------------------------------------------- +sal_Bool SAL_CALL ODBFilter::filter( const Sequence< PropertyValue >& rDescriptor ) + throw (RuntimeException) +{ + uno::Reference< ::com::sun::star::awt::XWindow > xWindow; + { + SolarMutexGuard aGuard; + Window* pFocusWindow = Application::GetFocusWindow(); + xWindow = VCLUnoHelper::GetInterface( pFocusWindow ); + if( pFocusWindow ) + pFocusWindow->EnterWait(); + } + sal_Bool bRet = sal_False; + + if ( GetModel().is() ) + bRet = implImport( rDescriptor ); + + if ( xWindow.is() ) + { + SolarMutexGuard aGuard; + Window* pFocusWindow = VCLUnoHelper::GetWindow( xWindow ); + if ( pFocusWindow ) + pFocusWindow->LeaveWait(); + } + + + return bRet; +} +// ----------------------------------------------------------------------------- +sal_Bool ODBFilter::implImport( const Sequence< PropertyValue >& rDescriptor ) + throw (RuntimeException) +{ + ::rtl::OUString sFileName; + ::comphelper::NamedValueCollection aMediaDescriptor( rDescriptor ); + if ( aMediaDescriptor.has( "URL" ) ) + sFileName = aMediaDescriptor.getOrDefault( "URL", ::rtl::OUString() ); + if ( !sFileName.getLength() && aMediaDescriptor.has( "FileName" ) ) + sFileName = aMediaDescriptor.getOrDefault( "FileName", sFileName ); + + OSL_ENSURE( sFileName.getLength(), "ODBFilter::implImport: no URL given!" ); + sal_Bool bRet = ( sFileName.getLength() != 0 ); + + if ( bRet ) + { + uno::Reference<XComponent> xCom(GetModel(),UNO_QUERY); + + SfxMediumRef pMedium = new SfxMedium( + sFileName, ( STREAM_READ | STREAM_NOCREATE ), sal_False, 0 ); + uno::Reference< embed::XStorage > xStorage; + try + { + xStorage.set( pMedium->GetStorage( sal_False ), UNO_QUERY_THROW ); + } + catch( const Exception& ) + { + Any aError = ::cppu::getCaughtException(); + if ( aError.isExtractableTo( ::cppu::UnoType< RuntimeException >::get() ) ) + throw; + throw lang::WrappedTargetRuntimeException( ::rtl::OUString(), *this, aError ); + } + + uno::Reference<sdb::XOfficeDatabaseDocument> xOfficeDoc(GetModel(),UNO_QUERY_THROW); + m_xDataSource.set(xOfficeDoc->getDataSource(),UNO_QUERY_THROW); + uno::Reference<beans::XPropertyChangeListener> xListener = new DatasourceURLListener(getServiceFactory()); + m_xDataSource->addPropertyChangeListener(PROPERTY_URL,xListener); + uno::Reference< XNumberFormatsSupplier > xNum(m_xDataSource->getPropertyValue(PROPERTY_NUMBERFORMATSSUPPLIER),UNO_QUERY); + SetNumberFormatsSupplier(xNum); + + uno::Reference<XComponent> xModel(GetModel(),UNO_QUERY); + sal_Int32 nRet = ReadThroughComponent( xStorage + ,xModel + ,"settings.xml" + ,"Settings.xml" + ,getServiceFactory() + ,this + ); + + if ( nRet == 0 ) + nRet = ReadThroughComponent( xStorage + ,xModel + ,"content.xml" + ,"Content.xml" + ,getServiceFactory() + ,this + ); + + bRet = nRet == 0; + + if ( bRet ) + { + uno::Reference< XModifiable > xModi(GetModel(),UNO_QUERY); + if ( xModi.is() ) + xModi->setModified(sal_False); + } + else + { + switch( nRet ) + { + case ERRCODE_IO_BROKENPACKAGE: + // TODO/LATER: no way to transport the error outside from the filter! + break; + default: + { + // 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 & ERRCODE_WARNING_MASK ) + bRet = sal_True; + } + } + } + } + + return bRet; +} +// ----------------------------------------------------------------------------- +SvXMLImportContext* ODBFilter::CreateContext( sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList ) +{ + SvXMLImportContext *pContext = 0; + + const SvXMLTokenMap& rTokenMap = GetDocElemTokenMap(); + switch( rTokenMap.Get( nPrefix, rLocalName ) ) + { + case XML_TOK_DOC_SETTINGS: + GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + pContext = new XMLDocumentSettingsContext( *this, nPrefix, rLocalName,xAttrList ); + break; + case XML_TOK_DOC_DATABASE: + GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + pContext = new OXMLDatabase( *this, nPrefix, rLocalName ); + break; + case XML_TOK_DOC_STYLES: + GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + pContext = CreateStylesContext(nPrefix, rLocalName, xAttrList, sal_False); + break; + case XML_TOK_DOC_AUTOSTYLES: + GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP ); + pContext = CreateStylesContext(nPrefix, rLocalName, xAttrList, sal_True); + break; + case XML_TOK_DOC_SCRIPT: + pContext = CreateScriptContext( rLocalName ); + break; + } + + if ( !pContext ) + pContext = SvXMLImport::CreateContext( nPrefix, rLocalName, xAttrList ); + + return pContext; +} +// ----------------------------------------------------------------------------- +void ODBFilter::SetViewSettings(const Sequence<PropertyValue>& aViewProps) +{ + const PropertyValue *pIter = aViewProps.getConstArray(); + const PropertyValue *pEnd = pIter + aViewProps.getLength(); + for (; pIter != pEnd; ++pIter) + { + if ( pIter->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "Queries" ) ) ) + { + fillPropertyMap(pIter->Value,m_aQuerySettings); + } + else if ( pIter->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "Tables" ) ) ) + { + fillPropertyMap(pIter->Value,m_aTablesSettings); + } + } +} +// ----------------------------------------------------------------------------- +void ODBFilter::SetConfigurationSettings(const Sequence<PropertyValue>& aConfigProps) +{ + const PropertyValue *pIter = aConfigProps.getConstArray(); + const PropertyValue *pEnd = pIter + aConfigProps.getLength(); + for (; pIter != pEnd; ++pIter) + { + if ( pIter->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "layout-settings" ) ) ) + { + Sequence<PropertyValue> aWindows; + pIter->Value >>= aWindows; + uno::Reference<XPropertySet> xProp(getDataSource()); + if ( xProp.is() ) + xProp->setPropertyValue(PROPERTY_LAYOUTINFORMATION,makeAny(aWindows)); + } + } +} +// ----------------------------------------------------------------------------- +void ODBFilter::fillPropertyMap(const Any& _rValue,TPropertyNameMap& _rMap) +{ + Sequence<PropertyValue> aWindows; + _rValue >>= aWindows; + const PropertyValue *pIter = aWindows.getConstArray(); + const PropertyValue *pEnd = pIter + aWindows.getLength(); + for (; pIter != pEnd; ++pIter) + { + Sequence<PropertyValue> aValue; + pIter->Value >>= aValue; + _rMap.insert(TPropertyNameMap::value_type(pIter->Name,aValue)); + } + +} +// ----------------------------------------------------------------------------- +const SvXMLTokenMap& ODBFilter::GetDocElemTokenMap() const +{ + if ( !m_pDocElemTokenMap.get() ) + { + static SvXMLTokenMapEntry aElemTokenMap[]= + { + { XML_NAMESPACE_OFFICE, XML_SETTINGS, XML_TOK_DOC_SETTINGS }, + { XML_NAMESPACE_OOO, XML_SETTINGS, XML_TOK_DOC_SETTINGS }, + { XML_NAMESPACE_OFFICE, XML_STYLES, XML_TOK_DOC_STYLES }, + { XML_NAMESPACE_OOO, XML_STYLES, XML_TOK_DOC_STYLES }, + { XML_NAMESPACE_OFFICE, XML_AUTOMATIC_STYLES, XML_TOK_DOC_AUTOSTYLES }, + { XML_NAMESPACE_OOO, XML_AUTOMATIC_STYLES, XML_TOK_DOC_AUTOSTYLES }, + { XML_NAMESPACE_OFFICE, XML_DATABASE, XML_TOK_DOC_DATABASE }, + { XML_NAMESPACE_OOO, XML_DATABASE, XML_TOK_DOC_DATABASE }, + { XML_NAMESPACE_OFFICE, XML_SCRIPTS, XML_TOK_DOC_SCRIPT }, + XML_TOKEN_MAP_END + }; + m_pDocElemTokenMap.reset(new SvXMLTokenMap( aElemTokenMap )); + } + return *m_pDocElemTokenMap; +} +// ----------------------------------------------------------------------------- +const SvXMLTokenMap& ODBFilter::GetDatabaseElemTokenMap() const +{ + if ( !m_pDatabaseElemTokenMap.get() ) + { + static SvXMLTokenMapEntry aElemTokenMap[]= + { + { XML_NAMESPACE_DB, XML_DATASOURCE, XML_TOK_DATASOURCE }, + { XML_NAMESPACE_DB, XML_FORMS, XML_TOK_FORMS}, + { XML_NAMESPACE_DB, XML_REPORTS, XML_TOK_REPORTS}, + { XML_NAMESPACE_DB, XML_QUERIES, XML_TOK_QUERIES}, + { XML_NAMESPACE_DB, XML_TABLES, XML_TOK_TABLES}, + { XML_NAMESPACE_DB, XML_TABLE_REPRESENTATIONS, XML_TOK_TABLES}, + { XML_NAMESPACE_DB, XML_SCHEMA_DEFINITION, XML_TOK_SCHEMA_DEFINITION}, + XML_TOKEN_MAP_END + }; + m_pDatabaseElemTokenMap.reset(new SvXMLTokenMap( aElemTokenMap )); + } + return *m_pDatabaseElemTokenMap; +} +// ----------------------------------------------------------------------------- +const SvXMLTokenMap& ODBFilter::GetDataSourceElemTokenMap() const +{ + if ( !m_pDataSourceElemTokenMap.get() ) + { + static SvXMLTokenMapEntry aElemTokenMap[]= + { + { XML_NAMESPACE_DB, XML_CONNECTION_RESOURCE, XML_TOK_CONNECTION_RESOURCE}, + { XML_NAMESPACE_DB, XML_SUPPRESS_VERSION_COLUMNS, XML_TOK_SUPPRESS_VERSION_COLUMNS}, + { XML_NAMESPACE_DB, XML_JAVA_DRIVER_CLASS, XML_TOK_JAVA_DRIVER_CLASS}, + { XML_NAMESPACE_DB, XML_EXTENSION, XML_TOK_EXTENSION}, + { XML_NAMESPACE_DB, XML_IS_FIRST_ROW_HEADER_LINE, XML_TOK_IS_FIRST_ROW_HEADER_LINE}, + { XML_NAMESPACE_DB, XML_SHOW_DELETED, XML_TOK_SHOW_DELETED}, + { XML_NAMESPACE_DB, XML_IS_TABLE_NAME_LENGTH_LIMITED, XML_TOK_IS_TABLE_NAME_LENGTH_LIMITED}, + { XML_NAMESPACE_DB, XML_SYSTEM_DRIVER_SETTINGS, XML_TOK_SYSTEM_DRIVER_SETTINGS}, + { XML_NAMESPACE_DB, XML_ENABLE_SQL92_CHECK, XML_TOK_ENABLE_SQL92_CHECK}, + { XML_NAMESPACE_DB, XML_APPEND_TABLE_ALIAS_NAME, XML_TOK_APPEND_TABLE_ALIAS_NAME}, + { XML_NAMESPACE_DB, XML_PARAMETER_NAME_SUBSTITUTION, XML_TOK_PARAMETER_NAME_SUBSTITUTION}, + { XML_NAMESPACE_DB, XML_IGNORE_DRIVER_PRIVILEGES, XML_TOK_IGNORE_DRIVER_PRIVILEGES}, + { XML_NAMESPACE_DB, XML_BOOLEAN_COMPARISON_MODE, XML_TOK_BOOLEAN_COMPARISON_MODE}, + { XML_NAMESPACE_DB, XML_USE_CATALOG, XML_TOK_USE_CATALOG}, + { XML_NAMESPACE_DB, XML_BASE_DN, XML_TOK_BASE_DN}, + { XML_NAMESPACE_DB, XML_MAX_ROW_COUNT, XML_TOK_MAX_ROW_COUNT}, + { XML_NAMESPACE_DB, XML_LOGIN, XML_TOK_LOGIN}, + { XML_NAMESPACE_DB, XML_TABLE_FILTER, XML_TOK_TABLE_FILTER}, + { XML_NAMESPACE_DB, XML_TABLE_TYPE_FILTER, XML_TOK_TABLE_TYPE_FILTER}, + { XML_NAMESPACE_DB, XML_AUTO_INCREMENT, XML_TOK_AUTO_INCREMENT}, + { XML_NAMESPACE_DB, XML_DELIMITER, XML_TOK_DELIMITER}, + { XML_NAMESPACE_DB, XML_DATA_SOURCE_SETTINGS, XML_TOK_DATA_SOURCE_SETTINGS}, + { XML_NAMESPACE_DB, XML_FONT_CHARSET, XML_TOK_FONT_CHARSET}, + // db odf 12 + { XML_NAMESPACE_DB, XML_CONNECTION_DATA, XML_TOK_CONNECTION_DATA}, + { XML_NAMESPACE_DB, XML_DATABASE_DESCRIPTION, XML_TOK_DATABASE_DESCRIPTION}, + { XML_NAMESPACE_DB, XML_COMPOUND_DATABASE, XML_TOK_COMPOUND_DATABASE}, + { XML_NAMESPACE_XLINK, XML_HREF, XML_TOK_DB_HREF}, + { XML_NAMESPACE_DB, XML_MEDIA_TYPE, XML_TOK_MEDIA_TYPE}, + { XML_NAMESPACE_DB, XML_TYPE, XML_TOK_DB_TYPE}, + { XML_NAMESPACE_DB, XML_HOSTNAME, XML_TOK_HOSTNAME}, + { XML_NAMESPACE_DB, XML_PORT, XML_TOK_PORT}, + { XML_NAMESPACE_DB, XML_LOCAL_SOCKET, XML_TOK_LOCAL_SOCKET}, + { XML_NAMESPACE_DB, XML_DATABASE_NAME, XML_TOK_DATABASE_NAME}, + { XML_NAMESPACE_DB, XML_DRIVER_SETTINGS, XML_TOK_DRIVER_SETTINGS}, + { XML_NAMESPACE_DB, XML_JAVA_CLASSPATH, XML_TOK_JAVA_CLASSPATH}, + { XML_NAMESPACE_DB, XML_CHARACTER_SET, XML_TOK_CHARACTER_SET}, + { XML_NAMESPACE_DB, XML_APPLICATION_CONNECTION_SETTINGS,XML_TOK_APPLICATION_CONNECTION_SETTINGS}, + XML_TOKEN_MAP_END + }; + m_pDataSourceElemTokenMap.reset(new SvXMLTokenMap( aElemTokenMap )); + } + return *m_pDataSourceElemTokenMap; +} +// ----------------------------------------------------------------------------- +const SvXMLTokenMap& ODBFilter::GetLoginElemTokenMap() const +{ + if ( !m_pLoginElemTokenMap.get() ) + { + static SvXMLTokenMapEntry aElemTokenMap[]= + { + { XML_NAMESPACE_DB, XML_USER_NAME, XML_TOK_USER_NAME}, + { XML_NAMESPACE_DB, XML_IS_PASSWORD_REQUIRED, XML_TOK_IS_PASSWORD_REQUIRED}, + { XML_NAMESPACE_DB, XML_USE_SYSTEM_USER, XML_TOK_USE_SYSTEM_USER}, + { XML_NAMESPACE_DB, XML_LOGIN_TIMEOUT, XML_TOK_LOGIN_TIMEOUT}, + XML_TOKEN_MAP_END + }; + m_pLoginElemTokenMap.reset(new SvXMLTokenMap( aElemTokenMap )); + } + return *m_pLoginElemTokenMap; +} +// ----------------------------------------------------------------------------- +const SvXMLTokenMap& ODBFilter::GetDatabaseDescriptionElemTokenMap() const +{ + if ( !m_pDatabaseDescriptionElemTokenMap.get() ) + { + static SvXMLTokenMapEntry aElemTokenMap[]= + { + { XML_NAMESPACE_DB, XML_FILE_BASED_DATABASE, XML_TOK_FILE_BASED_DATABASE}, + { XML_NAMESPACE_DB, XML_SERVER_DATABASE, XML_TOK_SERVER_DATABASE}, + XML_TOKEN_MAP_END + }; + m_pDatabaseDescriptionElemTokenMap.reset(new SvXMLTokenMap( aElemTokenMap )); + } + return *m_pDatabaseDescriptionElemTokenMap; +} +// ----------------------------------------------------------------------------- +const SvXMLTokenMap& ODBFilter::GetDataSourceInfoElemTokenMap() const +{ + if ( !m_pDataSourceInfoElemTokenMap.get() ) + { + static SvXMLTokenMapEntry aElemTokenMap[]= + { + { XML_NAMESPACE_DB, XML_ADDITIONAL_COLUMN_STATEMENT,XML_TOK_ADDITIONAL_COLUMN_STATEMENT}, + { XML_NAMESPACE_DB, XML_ROW_RETRIEVING_STATEMENT, XML_TOK_ROW_RETRIEVING_STATEMENT}, + { XML_NAMESPACE_DB, XML_STRING, XML_TOK_STRING}, + { XML_NAMESPACE_DB, XML_FIELD, XML_TOK_FIELD}, + { XML_NAMESPACE_DB, XML_DECIMAL, XML_TOK_DECIMAL}, + { XML_NAMESPACE_DB, XML_THOUSAND, XML_TOK_THOUSAND}, + { XML_NAMESPACE_DB, XML_DATA_SOURCE_SETTING, XML_TOK_DATA_SOURCE_SETTING}, + { XML_NAMESPACE_DB, XML_DATA_SOURCE_SETTING_VALUE, XML_TOK_DATA_SOURCE_SETTING_VALUE}, + { XML_NAMESPACE_DB, XML_DATA_SOURCE_SETTING_IS_LIST,XML_TOK_DATA_SOURCE_SETTING_IS_LIST}, + { XML_NAMESPACE_DB, XML_DATA_SOURCE_SETTING_TYPE, XML_TOK_DATA_SOURCE_SETTING_TYPE}, + { XML_NAMESPACE_DB, XML_DATA_SOURCE_SETTING_NAME, XML_TOK_DATA_SOURCE_SETTING_NAME}, + { XML_NAMESPACE_DB, XML_FONT_CHARSET, XML_TOK_FONT_CHARSET}, + { XML_NAMESPACE_DB, XML_ENCODING, XML_TOK_ENCODING}, + XML_TOKEN_MAP_END + }; + m_pDataSourceInfoElemTokenMap.reset(new SvXMLTokenMap( aElemTokenMap )); + } + return *m_pDataSourceInfoElemTokenMap; +} +// ----------------------------------------------------------------------------- +const SvXMLTokenMap& ODBFilter::GetDocumentsElemTokenMap() const +{ + if ( !m_pDocumentsElemTokenMap.get() ) + { + static SvXMLTokenMapEntry aElemTokenMap[]= + { + { XML_NAMESPACE_DB, XML_COMPONENT, XML_TOK_COMPONENT}, + { XML_NAMESPACE_DB, XML_COMPONENT_COLLECTION, XML_TOK_COMPONENT_COLLECTION}, + { XML_NAMESPACE_DB, XML_QUERY_COLLECTION, XML_TOK_QUERY_COLLECTION}, + { XML_NAMESPACE_DB, XML_QUERY, XML_TOK_QUERY}, + { XML_NAMESPACE_DB, XML_TABLE, XML_TOK_TABLE}, + { XML_NAMESPACE_DB, XML_TABLE_REPRESENTATION, XML_TOK_TABLE}, + { XML_NAMESPACE_DB, XML_COLUMN, XML_TOK_COLUMN}, + XML_TOKEN_MAP_END + }; + m_pDocumentsElemTokenMap.reset(new SvXMLTokenMap( aElemTokenMap )); + } + return *m_pDocumentsElemTokenMap; +} +// ----------------------------------------------------------------------------- +const SvXMLTokenMap& ODBFilter::GetComponentElemTokenMap() const +{ + if ( !m_pComponentElemTokenMap.get() ) + { + static SvXMLTokenMapEntry aElemTokenMap[]= + { + { XML_NAMESPACE_XLINK, XML_HREF, XML_TOK_HREF }, + { XML_NAMESPACE_XLINK, XML_TYPE, XML_TOK_TYPE }, + { XML_NAMESPACE_XLINK, XML_SHOW, XML_TOK_SHOW }, + { XML_NAMESPACE_XLINK, XML_ACTUATE, XML_TOK_ACTUATE}, + { XML_NAMESPACE_DB, XML_AS_TEMPLATE, XML_TOK_AS_TEMPLATE }, + { XML_NAMESPACE_DB, XML_NAME, XML_TOK_COMPONENT_NAME }, + XML_TOKEN_MAP_END + }; + m_pComponentElemTokenMap.reset(new SvXMLTokenMap( aElemTokenMap )); + } + return *m_pComponentElemTokenMap; +} +// ----------------------------------------------------------------------------- +const SvXMLTokenMap& ODBFilter::GetQueryElemTokenMap() const +{ + if ( !m_pQueryElemTokenMap.get() ) + { + static SvXMLTokenMapEntry aElemTokenMap[]= + { + { XML_NAMESPACE_DB, XML_COMMAND, XML_TOK_COMMAND }, + { XML_NAMESPACE_DB, XML_ESCAPE_PROCESSING, XML_TOK_ESCAPE_PROCESSING }, + { XML_NAMESPACE_DB, XML_NAME, XML_TOK_QUERY_NAME }, + { XML_NAMESPACE_DB, XML_FILTER_STATEMENT, XML_TOK_FILTER_STATEMENT }, + { XML_NAMESPACE_DB, XML_ORDER_STATEMENT, XML_TOK_ORDER_STATEMENT }, + { XML_NAMESPACE_DB, XML_CATALOG_NAME, XML_TOK_CATALOG_NAME }, + { XML_NAMESPACE_DB, XML_SCHEMA_NAME, XML_TOK_SCHEMA_NAME }, + { XML_NAMESPACE_DB, XML_STYLE_NAME, XML_TOK_STYLE_NAME}, + { XML_NAMESPACE_DB, XML_APPLY_FILTER, XML_TOK_APPLY_FILTER}, + { XML_NAMESPACE_DB, XML_APPLY_ORDER, XML_TOK_APPLY_ORDER}, + { XML_NAMESPACE_DB, XML_COLUMNS, XML_TOK_COLUMNS}, + XML_TOKEN_MAP_END + }; + m_pQueryElemTokenMap.reset(new SvXMLTokenMap( aElemTokenMap )); + } + return *m_pQueryElemTokenMap; +} +// ----------------------------------------------------------------------------- +const SvXMLTokenMap& ODBFilter::GetColumnElemTokenMap() const +{ + if ( !m_pColumnElemTokenMap.get() ) + { + static SvXMLTokenMapEntry aElemTokenMap[]= + { + { XML_NAMESPACE_DB, XML_NAME, XML_TOK_COLUMN_NAME }, + { XML_NAMESPACE_DB, XML_STYLE_NAME, XML_TOK_COLUMN_STYLE_NAME }, + { XML_NAMESPACE_DB, XML_HELP_MESSAGE, XML_TOK_COLUMN_HELP_MESSAGE }, + { XML_NAMESPACE_DB, XML_VISIBILITY, XML_TOK_COLUMN_VISIBILITY }, + { XML_NAMESPACE_DB, XML_DEFAULT_VALUE, XML_TOK_COLUMN_DEFAULT_VALUE }, + { XML_NAMESPACE_DB, XML_TYPE_NAME, XML_TOK_COLUMN_TYPE_NAME }, + { XML_NAMESPACE_DB, XML_VISIBLE, XML_TOK_COLUMN_VISIBLE }, + { XML_NAMESPACE_DB, XML_DEFAULT_CELL_STYLE_NAME, XML_TOK_DEFAULT_CELL_STYLE_NAME }, + XML_TOKEN_MAP_END + }; + m_pColumnElemTokenMap.reset(new SvXMLTokenMap( aElemTokenMap )); + } + return *m_pColumnElemTokenMap; +} +// ----------------------------------------------------------------------------- +SvXMLImportContext* ODBFilter::CreateStylesContext(sal_uInt16 _nPrefix,const ::rtl::OUString& rLocalName, + const uno::Reference< XAttributeList>& xAttrList, sal_Bool bIsAutoStyle ) +{ + SvXMLImportContext *pContext = NULL; + if (!pContext) + { + pContext = new OTableStylesContext(*this, _nPrefix, rLocalName, xAttrList, bIsAutoStyle); + if (bIsAutoStyle) + SetAutoStyles((SvXMLStylesContext*)pContext); + else + SetStyles((SvXMLStylesContext*)pContext); + } + return pContext; +} +// ----------------------------------------------------------------------------- +SvXMLImportContext* ODBFilter::CreateScriptContext( const ::rtl::OUString& _rLocalName ) +{ + return new XMLScriptContext( *this, XML_NAMESPACE_OFFICE, _rLocalName, GetModel() ); +} +// ----------------------------------------------------------------------------- +UniReference < XMLPropertySetMapper > ODBFilter::GetTableStylesPropertySetMapper() const +{ + if ( !m_xTableStylesPropertySetMapper.is() ) + { + m_xTableStylesPropertySetMapper = OXMLHelper::GetTableStylesPropertySetMapper(); + } + return m_xTableStylesPropertySetMapper; +} +// ----------------------------------------------------------------------------- +UniReference < XMLPropertySetMapper > ODBFilter::GetColumnStylesPropertySetMapper() const +{ + if ( !m_xColumnStylesPropertySetMapper.is() ) + { + m_xColumnStylesPropertySetMapper = OXMLHelper::GetColumnStylesPropertySetMapper(); + } + return m_xColumnStylesPropertySetMapper; +} +// ----------------------------------------------------------------------------- +UniReference < XMLPropertySetMapper > ODBFilter::GetCellStylesPropertySetMapper() const +{ + if ( !m_xCellStylesPropertySetMapper.is() ) + { + m_xCellStylesPropertySetMapper = OXMLHelper::GetCellStylesPropertySetMapper(); + } + return m_xCellStylesPropertySetMapper; +} +// ----------------------------------------------------------------------------- +void ODBFilter::setPropertyInfo() +{ + Reference<XPropertySet> xDataSource(getDataSource()); + if ( !xDataSource.is() ) + return; + + ::connectivity::DriversConfig aDriverConfig(getServiceFactory()); + const ::rtl::OUString sURL = ::comphelper::getString(xDataSource->getPropertyValue(PROPERTY_URL)); + ::comphelper::NamedValueCollection aDataSourceSettings = aDriverConfig.getProperties( sURL ); + + Sequence<PropertyValue> aInfo; + if ( !m_aInfoSequence.empty() ) + aInfo = Sequence<PropertyValue>(&(*m_aInfoSequence.begin()),m_aInfoSequence.size()); + aDataSourceSettings.merge( ::comphelper::NamedValueCollection( aInfo ), true ); + + aDataSourceSettings >>= aInfo; + if ( aInfo.getLength() ) + { + try + { + xDataSource->setPropertyValue(PROPERTY_INFO,makeAny(aInfo)); + } + catch(Exception) + { + DBG_UNHANDLED_EXCEPTION(); + } + } +} +// ----------------------------------------------------------------------------- +}// 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 000000000000..c4e2a16dc856 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlfilter.hxx @@ -0,0 +1,175 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef DBA_XMLFILTER_HXX +#define DBA_XMLFILTER_HXX + +#include <com/sun/star/container/XNamed.hpp> +#include <com/sun/star/document/XFilter.hpp> +#include <com/sun/star/document/XImporter.hpp> +#include <com/sun/star/document/XExporter.hpp> +#include <com/sun/star/lang/XInitialization.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <cppuhelper/implbase1.hxx> +#include <cppuhelper/implbase5.hxx> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/io/XActiveDataSource.hpp> +#include <osl/diagnose.h> +#include <unotools/tempfile.hxx> +#include <unotools/localfilehelper.hxx> +#include <unotools/ucbstreamhelper.hxx> +#include <xmloff/xmlimp.hxx> +#include "apitools.hxx" +#include <comphelper/stl_types.hxx> + +#include <memory> + +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; + +// ------------- +// - ODBFilter - +// ------------- +class ODBFilter : public SvXMLImport +{ +public: + DECLARE_STL_USTRINGACCESS_MAP(Sequence<PropertyValue>,TPropertyNameMap); + typedef ::std::vector< ::com::sun::star::beans::PropertyValue> TInfoSequence; +private: + TPropertyNameMap m_aQuerySettings; + TPropertyNameMap m_aTablesSettings; + TInfoSequence m_aInfoSequence; + Reference< XComponent > m_xSrcDoc; + mutable ::std::auto_ptr<SvXMLTokenMap> m_pDocElemTokenMap; + mutable ::std::auto_ptr<SvXMLTokenMap> m_pDatabaseElemTokenMap; + mutable ::std::auto_ptr<SvXMLTokenMap> m_pDataSourceElemTokenMap; + mutable ::std::auto_ptr<SvXMLTokenMap> m_pLoginElemTokenMap; + mutable ::std::auto_ptr<SvXMLTokenMap> m_pDatabaseDescriptionElemTokenMap; + mutable ::std::auto_ptr<SvXMLTokenMap> m_pDataSourceInfoElemTokenMap; + mutable ::std::auto_ptr<SvXMLTokenMap> m_pDocumentsElemTokenMap; + mutable ::std::auto_ptr<SvXMLTokenMap> m_pComponentElemTokenMap; + mutable ::std::auto_ptr<SvXMLTokenMap> m_pQueryElemTokenMap; + mutable ::std::auto_ptr<SvXMLTokenMap> m_pColumnElemTokenMap; + + mutable UniReference < XMLPropertySetMapper > m_xTableStylesPropertySetMapper; + mutable UniReference < XMLPropertySetMapper > m_xColumnStylesPropertySetMapper; + mutable UniReference < XMLPropertySetMapper > m_xCellStylesPropertySetMapper; + Reference<XPropertySet> m_xDataSource; + sal_Int32 m_nPreviewMode; + bool m_bNewFormat; + + sal_Bool implImport( const Sequence< PropertyValue >& rDescriptor ) throw (RuntimeException); + + + /** fills the map with the Properties + @param _rValue + The Any where the sequence resists in. + @param _rMap + The map to fill. + */ + void fillPropertyMap(const Any& _rValue,TPropertyNameMap& _rMap); + + SvXMLImportContext* CreateStylesContext(sal_uInt16 nPrefix,const ::rtl::OUString& rLocalName, + const Reference< XAttributeList>& xAttrList, sal_Bool bIsAutoStyle ); + SvXMLImportContext* CreateScriptContext( const ::rtl::OUString& rLocalName ); + +protected: + // SvXMLImport + virtual SvXMLImportContext *CreateContext( sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList ); + + virtual ~ODBFilter() throw(); +public: + + ODBFilter( const Reference< XMultiServiceFactory >& _rxMSF ); + + // XFilter + virtual sal_Bool SAL_CALL filter( const Sequence< PropertyValue >& rDescriptor ) throw(RuntimeException); + + // XServiceInfo + DECLARE_SERVICE_INFO_STATIC( ); + + // helper class + virtual void SetViewSettings(const com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>& aViewProps); + virtual void SetConfigurationSettings(const com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>& aConfigProps); + + inline Reference< XMultiServiceFactory > getORB() { return getServiceFactory(); } + inline Reference<XPropertySet> getDataSource() const { return m_xDataSource; } + + inline const TPropertyNameMap& getQuerySettings() const { return m_aQuerySettings;} + inline const TPropertyNameMap& getTableSettings() const { return m_aTablesSettings;} + + const SvXMLTokenMap& GetDocElemTokenMap() const; + const SvXMLTokenMap& GetDatabaseElemTokenMap() const; + const SvXMLTokenMap& GetDataSourceElemTokenMap() const; + const SvXMLTokenMap& GetLoginElemTokenMap() const; + const SvXMLTokenMap& GetDatabaseDescriptionElemTokenMap() const; + const SvXMLTokenMap& GetDataSourceInfoElemTokenMap() const; + const SvXMLTokenMap& GetDocumentsElemTokenMap() const; + const SvXMLTokenMap& GetComponentElemTokenMap() const; + const SvXMLTokenMap& GetQueryElemTokenMap() const; + const SvXMLTokenMap& GetColumnElemTokenMap() const; + + UniReference < XMLPropertySetMapper > GetTableStylesPropertySetMapper() const; + UniReference < XMLPropertySetMapper > GetColumnStylesPropertySetMapper() const; + UniReference < XMLPropertySetMapper > GetCellStylesPropertySetMapper() const; + + /** add a Info to the sequence which will be appened to the data source + @param _rInfo The property to append. + */ + inline void addInfo(const ::com::sun::star::beans::PropertyValue& _rInfo) + { + m_aInfoSequence.push_back(_rInfo); + } + + void setPropertyInfo(); + + const ::std::map< sal_uInt16,com::sun::star::beans::Property>& GetDataSourceInfoDefaulValueMap() const; + + inline bool isNewFormat() const { return m_bNewFormat; } + inline void setNewFormat(bool _bNewFormat) { m_bNewFormat = _bNewFormat; } +}; + +// ----------------------------------------------------------------------------- +} // dbaxml +// ----------------------------------------------------------------------------- +#endif // DBA_XMLFILTER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/filter/xml/xmlservices.cxx b/dbaccess/source/filter/xml/xmlservices.cxx new file mode 100644 index 000000000000..a70c1d9c4981 --- /dev/null +++ b/dbaccess/source/filter/xml/xmlservices.cxx @@ -0,0 +1,100 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_dbaccess.hxx" + +#include <cppuhelper/factory.hxx> +#include <osl/diagnose.h> +#include "flt_reghelper.hxx" + +/********************************************************************************************/ + +using namespace ::dbaxml; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::registry; + +//*************************************************************************************** +// +// registry functions +extern "C" void SAL_CALL createRegistryInfo_ODBFilter(); +extern "C" void SAL_CALL createRegistryInfo_ODBFilterExport(); +extern "C" void SAL_CALL createRegistryInfo_OSettingsExport(); +extern "C" void SAL_CALL createRegistryInfo_OFullExport(); +extern "C" void SAL_CALL createRegistryInfo_DBContentLoader2(); +extern "C" void SAL_CALL createRegistryInfo_DBTypeDetection(); +extern "C" void SAL_CALL writeDBLoaderInfo2(void* pRegistryKey); + +//*************************************************************************************** +extern "C" void SAL_CALL createRegistryInfo_dbaxml() +{ + static sal_Bool bInit = sal_False; + if (!bInit) + { + createRegistryInfo_DBTypeDetection(); + createRegistryInfo_ODBFilter(); + createRegistryInfo_ODBFilterExport(); + createRegistryInfo_OSettingsExport(); + createRegistryInfo_OFullExport(); + createRegistryInfo_DBContentLoader2(); + bInit = sal_True; + } +} + +//--------------------------------------------------------------------------------------- + +extern "C" void SAL_CALL component_getImplementationEnvironment( + const sal_Char **ppEnvTypeName, + uno_Environment ** + ) +{ + createRegistryInfo_dbaxml(); + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; +} + +//--------------------------------------------------------------------------------------- +extern "C" void* SAL_CALL component_getFactory( + const sal_Char* pImplementationName, + void* pServiceManager, + void* /*pRegistryKey*/) +{ + Reference< XInterface > xRet; + if (pServiceManager && pImplementationName) + { + xRet = ::dbaxml::OModuleRegistration::getComponentFactory( + ::rtl::OUString::createFromAscii(pImplementationName), + static_cast< XMultiServiceFactory* >(pServiceManager)); + } + + if (xRet.is()) + xRet->acquire(); + return xRet.get(); +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |