1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/config.h>
22 #include <com/sun/star/util/MeasureUnit.hpp>
23 #include <com/sun/star/packages/zip/ZipIOException.hpp>
24 #include <com/sun/star/embed/ElementModes.hpp>
25 #include <com/sun/star/sdb/XOfficeDatabaseDocument.hpp>
26 #include "xmlfilter.hxx"
27 #include "xmlservices.hxx"
28 #include "flt_reghelper.hxx"
29 #include <vcl/svapp.hxx>
30 #include <vcl/window.hxx>
31 #include <xmloff/xmlnmspe.hxx>
32 #include <xmloff/xmlscripti.hxx>
33 #include <xmloff/xmltoken.hxx>
34 #include <xmloff/txtimp.hxx>
35 #include <xmloff/nmspmap.hxx>
36 #include <com/sun/star/xml/sax/InputSource.hpp>
37 #include <com/sun/star/xml/sax/Parser.hpp>
38 #include <xmloff/ProgressBarHelper.hxx>
39 #include <sfx2/docfile.hxx>
40 #include <com/sun/star/io/XInputStream.hpp>
41 #include <com/sun/star/uno/XNamingService.hpp>
42 #include "xmlDatabase.hxx"
43 #include "xmlEnums.hxx"
44 #include "xmlstrings.hrc"
45 #include <xmloff/DocumentSettingsContext.hxx>
46 #include "xmlStyleImport.hxx"
47 #include <xmloff/xmluconv.hxx>
48 #include "xmlHelper.hxx"
49 #include <com/sun/star/util/XModifiable.hpp>
50 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
51 #include <osl/mutex.hxx>
52 #include <svtools/sfxecode.hxx>
53 #include <toolkit/helper/vclunohelper.hxx>
54 #include <tools/diagnose_ex.h>
55 #include <osl/diagnose.h>
56 #include <comphelper/processfactory.hxx>
57 #include <comphelper/namedvaluecollection.hxx>
58 #include <comphelper/uno3.hxx>
59 #include <cppuhelper/exc_hlp.hxx>
60 #include <connectivity/DriversConfig.hxx>
61 #include "dsntypes.hxx"
62 #include <rtl/strbuf.hxx>
64 using namespace ::com::sun::star
;
66 extern "C" void SAL_CALL
createRegistryInfo_ODBFilter( )
68 static ::dbaxml::OMultiInstanceAutoRegistration
< ::dbaxml::ODBFilter
> aAutoRegistration
;
74 using namespace ::com::sun::star::util
;
75 /// read a component (file + filter version)
76 sal_Int32
ReadThroughComponent(
77 const uno::Reference
<XInputStream
>& xInputStream
,
78 const uno::Reference
<XComponent
>& xModelComponent
,
79 const uno::Reference
<XComponentContext
> & rxContext
,
80 const uno::Reference
< XDocumentHandler
>& _xFilter
)
82 OSL_ENSURE(xInputStream
.is(), "input stream missing");
83 OSL_ENSURE(xModelComponent
.is(), "document missing");
84 OSL_ENSURE(rxContext
.is(), "factory missing");
86 // prepare ParserInputSrouce
87 InputSource aParserInput
;
88 aParserInput
.aInputStream
= xInputStream
;
91 uno::Reference
< XParser
> xParser
= Parser::create(rxContext
);
92 SAL_INFO("dbaccess", "parser created" );
95 OSL_ENSURE( _xFilter
.is(), "Can't instantiate filter component." );
99 // connect parser and filter
100 xParser
->setDocumentHandler( _xFilter
);
102 // connect model and filter
103 uno::Reference
< XImporter
> xImporter( _xFilter
, UNO_QUERY
);
104 xImporter
->setTargetDocument( xModelComponent
);
106 // finally, parser the stream
109 xParser
->parseStream( aParserInput
);
111 catch (const SAXParseException
& r
)
113 #if OSL_DEBUG_LEVEL > 0
114 SAL_WARN("dbaccess", "SAX parse exception catched while importing:\n" << r
.Message
<< r
.LineNumber
<< "," << r
.ColumnNumber
);
120 catch (const SAXException
&)
124 catch (const packages::zip::ZipIOException
&)
126 return ERRCODE_IO_BROKENPACKAGE
;
128 catch (const Exception
&)
130 DBG_UNHANDLED_EXCEPTION();
138 /// read a component (storage version)
139 sal_Int32
ReadThroughComponent(
140 const uno::Reference
< embed::XStorage
>& xStorage
,
141 const uno::Reference
<XComponent
>& xModelComponent
,
142 const sal_Char
* pStreamName
,
143 const sal_Char
* pCompatibilityStreamName
,
144 const uno::Reference
<XComponentContext
> & rxContext
,
145 const uno::Reference
< XDocumentHandler
>& _xFilter
)
147 OSL_ENSURE( xStorage
.is(), "Need storage!");
148 OSL_ENSURE(nullptr != pStreamName
, "Please, please, give me a name!");
152 uno::Reference
< io::XStream
> xDocStream
;
156 bool bEncrypted
= false;
157 // open stream (and set parser input)
158 OUString sStreamName
= OUString::createFromAscii(pStreamName
);
159 if ( !xStorage
->hasByName( sStreamName
) || !xStorage
->isStreamElement( sStreamName
) )
161 // stream name not found! Then try the compatibility name.
162 // if no stream can be opened, return immediately with OK signal
164 // do we even have an alternative name?
165 if ( nullptr == pCompatibilityStreamName
)
168 // if so, does the stream exist?
169 sStreamName
= OUString::createFromAscii(pCompatibilityStreamName
);
170 if ( !xStorage
->hasByName( sStreamName
) || !xStorage
->isStreamElement( sStreamName
) )
175 xDocStream
= xStorage
->openStreamElement( sStreamName
, embed::ElementModes::READ
);
177 uno::Reference
< beans::XPropertySet
> xProps( xDocStream
, uno::UNO_QUERY_THROW
);
178 uno::Any aAny
= xProps
->getPropertyValue("Encrypted");
181 catch (const packages::WrongPasswordException
&)
183 return ERRCODE_SFX_WRONGPASSWORD
;
185 catch (const uno::Exception
&)
187 return 1; // TODO/LATER: error handling
190 uno::Reference
< XInputStream
> xInputStream
= xDocStream
->getInputStream();
191 // read from the stream
192 return ReadThroughComponent( xInputStream
198 // TODO/LATER: better error handling
203 ODBFilter::ODBFilter( const uno::Reference
< XComponentContext
>& _rxContext
)
204 : SvXMLImport(_rxContext
, getImplementationName_Static())
205 , m_bNewFormat(false)
208 GetMM100UnitConverter().SetCoreMeasureUnit(util::MeasureUnit::MM_10TH
);
209 GetMM100UnitConverter().SetXMLMeasureUnit(util::MeasureUnit::CM
);
210 GetNamespaceMap().Add( "_db",
211 GetXMLToken(XML_N_DB
),
214 GetNamespaceMap().Add( "__db",
215 GetXMLToken(XML_N_DB_OASIS
),
220 ODBFilter::~ODBFilter() throw()
226 OUString
ODBFilter::getImplementationName_Static()
227 throw (css::uno::RuntimeException
)
229 return OUString("com.sun.star.comp.sdb.DBFilter");
233 css::uno::Sequence
<OUString
> ODBFilter::getSupportedServiceNames_Static()
234 throw (css::uno::RuntimeException
)
236 css::uno::Sequence
<OUString
> s
{ "com.sun.star.document.ImportFilter" };
241 css::uno::Reference
< css::uno::XInterface
>
242 SAL_CALL
ODBFilter::Create(const css::uno::Reference
< css::lang::XMultiServiceFactory
>& _rxORB
)
244 return static_cast< XServiceInfo
* >(new ODBFilter( comphelper::getComponentContext(_rxORB
)));
248 sal_Bool SAL_CALL
ODBFilter::filter( const Sequence
< PropertyValue
>& rDescriptor
)
249 throw (RuntimeException
, std::exception
)
251 uno::Reference
< css::awt::XWindow
> xWindow
;
253 SolarMutexGuard aGuard
;
254 vcl::Window
* pFocusWindow
= Application::GetFocusWindow();
255 xWindow
= VCLUnoHelper::GetInterface( pFocusWindow
);
257 pFocusWindow
->EnterWait();
261 if ( GetModel().is() )
262 bRet
= implImport( rDescriptor
);
266 SolarMutexGuard aGuard
;
267 vcl::Window
* pFocusWindow
= VCLUnoHelper::GetWindow( xWindow
);
269 pFocusWindow
->LeaveWait();
276 bool ODBFilter::implImport( const Sequence
< PropertyValue
>& rDescriptor
)
277 throw (RuntimeException
, std::exception
)
280 ::comphelper::NamedValueCollection
aMediaDescriptor( rDescriptor
);
282 uno::Reference
<embed::XStorage
> xStorage
= GetSourceStorage();
287 if (aMediaDescriptor
.has("URL"))
288 sFileName
= aMediaDescriptor
.getOrDefault("URL", OUString());
289 if (sFileName
.isEmpty() && aMediaDescriptor
.has("FileName"))
290 sFileName
= aMediaDescriptor
.getOrDefault("FileName", sFileName
);
292 OSL_ENSURE(!sFileName
.isEmpty(), "ODBFilter::implImport: no URL given!");
293 bRet
= !sFileName
.isEmpty();
298 uno::Reference
<XComponent
> xCom(GetModel(),UNO_QUERY
);
300 tools::SvRef
<SfxMedium
> pMedium(nullptr);
303 OUString sStreamRelPath
;
304 if (sFileName
.startsWithIgnoreAsciiCase("vnd.sun.star.pkg:"))
306 // In this case the host contains the real path, and the path is the embedded stream name.
307 INetURLObject
aURL(sFileName
);
308 sFileName
= aURL
.GetHost(INetURLObject::DECODE_WITH_CHARSET
);
309 sStreamRelPath
= aURL
.GetURLPath(INetURLObject::DECODE_WITH_CHARSET
);
310 if (sStreamRelPath
.startsWith("/"))
311 sStreamRelPath
= sStreamRelPath
.copy(1);
314 pMedium
= new SfxMedium(sFileName
, (StreamMode::READ
| StreamMode::NOCREATE
));
317 xStorage
.set(pMedium
->GetStorage(false), UNO_QUERY_THROW
);
319 if (!sStreamRelPath
.isEmpty())
320 xStorage
= xStorage
->openStorageElement(sStreamRelPath
, embed::ElementModes::READ
);
322 catch (const Exception
&)
324 Any aError
= ::cppu::getCaughtException();
325 if (aError
.isExtractableTo(::cppu::UnoType
<RuntimeException
>::get()))
327 throw lang::WrappedTargetRuntimeException(OUString(), *this, aError
);
331 uno::Reference
<sdb::XOfficeDatabaseDocument
> xOfficeDoc(GetModel(),UNO_QUERY_THROW
);
332 m_xDataSource
.set(xOfficeDoc
->getDataSource(),UNO_QUERY_THROW
);
333 uno::Reference
< XNumberFormatsSupplier
> xNum(m_xDataSource
->getPropertyValue(PROPERTY_NUMBERFORMATSSUPPLIER
),UNO_QUERY
);
334 SetNumberFormatsSupplier(xNum
);
336 uno::Reference
<XComponent
> xModel(GetModel(),UNO_QUERY
);
337 sal_Int32 nRet
= ReadThroughComponent( xStorage
341 ,GetComponentContext()
346 nRet
= ReadThroughComponent( xStorage
350 ,GetComponentContext()
358 uno::Reference
< XModifiable
> xModi(GetModel(),UNO_QUERY
);
360 xModi
->setModified(false);
366 case ERRCODE_IO_BROKENPACKAGE
:
367 // TODO/LATER: no way to transport the error outside from the filter!
371 // TODO/LATER: this is completely wrong! Filter code should never call ErrorHandler directly! But for now this is the only way!
372 ErrorHandler::HandleError( nRet
);
373 if( nRet
& ERRCODE_WARNING_MASK
)
384 SvXMLImportContext
* ODBFilter::CreateContext( sal_uInt16 nPrefix
,
385 const OUString
& rLocalName
,
386 const uno::Reference
< css::xml::sax::XAttributeList
>& xAttrList
)
388 SvXMLImportContext
*pContext
= nullptr;
390 const SvXMLTokenMap
& rTokenMap
= GetDocElemTokenMap();
391 switch( rTokenMap
.Get( nPrefix
, rLocalName
) )
393 case XML_TOK_DOC_SETTINGS
:
394 GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP
);
395 pContext
= new XMLDocumentSettingsContext( *this, nPrefix
, rLocalName
,xAttrList
);
397 case XML_TOK_DOC_DATABASE
:
398 GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP
);
399 pContext
= new OXMLDatabase( *this, nPrefix
, rLocalName
);
401 case XML_TOK_DOC_STYLES
:
402 GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP
);
403 pContext
= CreateStylesContext(nPrefix
, rLocalName
, xAttrList
, false);
405 case XML_TOK_DOC_AUTOSTYLES
:
406 GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP
);
407 pContext
= CreateStylesContext(nPrefix
, rLocalName
, xAttrList
, true);
409 case XML_TOK_DOC_SCRIPT
:
410 pContext
= CreateScriptContext( rLocalName
);
415 pContext
= SvXMLImport::CreateContext( nPrefix
, rLocalName
, xAttrList
);
421 void ODBFilter::SetViewSettings(const Sequence
<PropertyValue
>& aViewProps
)
423 const PropertyValue
*pIter
= aViewProps
.getConstArray();
424 const PropertyValue
*pEnd
= pIter
+ aViewProps
.getLength();
425 for (; pIter
!= pEnd
; ++pIter
)
427 if ( pIter
->Name
== "Queries" )
429 fillPropertyMap(pIter
->Value
,m_aQuerySettings
);
431 else if ( pIter
->Name
== "Tables" )
433 fillPropertyMap(pIter
->Value
,m_aTablesSettings
);
439 void ODBFilter::SetConfigurationSettings(const Sequence
<PropertyValue
>& aConfigProps
)
441 const PropertyValue
*pIter
= aConfigProps
.getConstArray();
442 const PropertyValue
*pEnd
= pIter
+ aConfigProps
.getLength();
443 for (; pIter
!= pEnd
; ++pIter
)
445 if ( pIter
->Name
== "layout-settings" )
447 Sequence
<PropertyValue
> aWindows
;
448 pIter
->Value
>>= aWindows
;
449 uno::Reference
<XPropertySet
> xProp(getDataSource());
451 xProp
->setPropertyValue(PROPERTY_LAYOUTINFORMATION
,makeAny(aWindows
));
457 void ODBFilter::fillPropertyMap(const Any
& _rValue
,TPropertyNameMap
& _rMap
)
459 Sequence
<PropertyValue
> aWindows
;
460 _rValue
>>= aWindows
;
461 const PropertyValue
*pIter
= aWindows
.getConstArray();
462 const PropertyValue
*pEnd
= pIter
+ aWindows
.getLength();
463 for (; pIter
!= pEnd
; ++pIter
)
465 Sequence
<PropertyValue
> aValue
;
466 pIter
->Value
>>= aValue
;
467 _rMap
.insert(TPropertyNameMap::value_type(pIter
->Name
,aValue
));
473 const SvXMLTokenMap
& ODBFilter::GetDocElemTokenMap() const
475 if ( !m_pDocElemTokenMap
.get() )
477 static const SvXMLTokenMapEntry aElemTokenMap
[]=
479 { XML_NAMESPACE_OFFICE
, XML_SETTINGS
, XML_TOK_DOC_SETTINGS
},
480 { XML_NAMESPACE_OOO
, XML_SETTINGS
, XML_TOK_DOC_SETTINGS
},
481 { XML_NAMESPACE_OFFICE
, XML_STYLES
, XML_TOK_DOC_STYLES
},
482 { XML_NAMESPACE_OOO
, XML_STYLES
, XML_TOK_DOC_STYLES
},
483 { XML_NAMESPACE_OFFICE
, XML_AUTOMATIC_STYLES
, XML_TOK_DOC_AUTOSTYLES
},
484 { XML_NAMESPACE_OOO
, XML_AUTOMATIC_STYLES
, XML_TOK_DOC_AUTOSTYLES
},
485 { XML_NAMESPACE_OFFICE
, XML_DATABASE
, XML_TOK_DOC_DATABASE
},
486 { XML_NAMESPACE_OOO
, XML_DATABASE
, XML_TOK_DOC_DATABASE
},
487 { XML_NAMESPACE_OFFICE
, XML_SCRIPTS
, XML_TOK_DOC_SCRIPT
},
490 m_pDocElemTokenMap
.reset(new SvXMLTokenMap( aElemTokenMap
));
492 return *m_pDocElemTokenMap
;
496 const SvXMLTokenMap
& ODBFilter::GetDatabaseElemTokenMap() const
498 if ( !m_pDatabaseElemTokenMap
.get() )
500 static const SvXMLTokenMapEntry aElemTokenMap
[]=
502 { XML_NAMESPACE_DB
, XML_DATASOURCE
, XML_TOK_DATASOURCE
},
503 { XML_NAMESPACE_DB
, XML_FORMS
, XML_TOK_FORMS
},
504 { XML_NAMESPACE_DB
, XML_REPORTS
, XML_TOK_REPORTS
},
505 { XML_NAMESPACE_DB
, XML_QUERIES
, XML_TOK_QUERIES
},
506 { XML_NAMESPACE_DB
, XML_TABLES
, XML_TOK_TABLES
},
507 { XML_NAMESPACE_DB
, XML_TABLE_REPRESENTATIONS
, XML_TOK_TABLES
},
508 { XML_NAMESPACE_DB
, XML_SCHEMA_DEFINITION
, XML_TOK_SCHEMA_DEFINITION
},
511 m_pDatabaseElemTokenMap
.reset(new SvXMLTokenMap( aElemTokenMap
));
513 return *m_pDatabaseElemTokenMap
;
517 const SvXMLTokenMap
& ODBFilter::GetDataSourceElemTokenMap() const
519 if ( !m_pDataSourceElemTokenMap
.get() )
521 static const SvXMLTokenMapEntry aElemTokenMap
[]=
523 { XML_NAMESPACE_DB
, XML_CONNECTION_RESOURCE
, XML_TOK_CONNECTION_RESOURCE
},
524 { XML_NAMESPACE_DB
, XML_SUPPRESS_VERSION_COLUMNS
, XML_TOK_SUPPRESS_VERSION_COLUMNS
},
525 { XML_NAMESPACE_DB
, XML_JAVA_DRIVER_CLASS
, XML_TOK_JAVA_DRIVER_CLASS
},
526 { XML_NAMESPACE_DB
, XML_EXTENSION
, XML_TOK_EXTENSION
},
527 { XML_NAMESPACE_DB
, XML_IS_FIRST_ROW_HEADER_LINE
, XML_TOK_IS_FIRST_ROW_HEADER_LINE
},
528 { XML_NAMESPACE_DB
, XML_SHOW_DELETED
, XML_TOK_SHOW_DELETED
},
529 { XML_NAMESPACE_DB
, XML_IS_TABLE_NAME_LENGTH_LIMITED
, XML_TOK_IS_TABLE_NAME_LENGTH_LIMITED
},
530 { XML_NAMESPACE_DB
, XML_SYSTEM_DRIVER_SETTINGS
, XML_TOK_SYSTEM_DRIVER_SETTINGS
},
531 { XML_NAMESPACE_DB
, XML_ENABLE_SQL92_CHECK
, XML_TOK_ENABLE_SQL92_CHECK
},
532 { XML_NAMESPACE_DB
, XML_APPEND_TABLE_ALIAS_NAME
, XML_TOK_APPEND_TABLE_ALIAS_NAME
},
533 { XML_NAMESPACE_DB
, XML_PARAMETER_NAME_SUBSTITUTION
, XML_TOK_PARAMETER_NAME_SUBSTITUTION
},
534 { XML_NAMESPACE_DB
, XML_IGNORE_DRIVER_PRIVILEGES
, XML_TOK_IGNORE_DRIVER_PRIVILEGES
},
535 { XML_NAMESPACE_DB
, XML_BOOLEAN_COMPARISON_MODE
, XML_TOK_BOOLEAN_COMPARISON_MODE
},
536 { XML_NAMESPACE_DB
, XML_USE_CATALOG
, XML_TOK_USE_CATALOG
},
537 { XML_NAMESPACE_DB
, XML_BASE_DN
, XML_TOK_BASE_DN
},
538 { XML_NAMESPACE_DB
, XML_MAX_ROW_COUNT
, XML_TOK_MAX_ROW_COUNT
},
539 { XML_NAMESPACE_DB
, XML_LOGIN
, XML_TOK_LOGIN
},
540 { XML_NAMESPACE_DB
, XML_TABLE_FILTER
, XML_TOK_TABLE_FILTER
},
541 { XML_NAMESPACE_DB
, XML_TABLE_TYPE_FILTER
, XML_TOK_TABLE_TYPE_FILTER
},
542 { XML_NAMESPACE_DB
, XML_AUTO_INCREMENT
, XML_TOK_AUTO_INCREMENT
},
543 { XML_NAMESPACE_DB
, XML_DELIMITER
, XML_TOK_DELIMITER
},
544 { XML_NAMESPACE_DB
, XML_DATA_SOURCE_SETTINGS
, XML_TOK_DATA_SOURCE_SETTINGS
},
545 { XML_NAMESPACE_DB
, XML_FONT_CHARSET
, XML_TOK_FONT_CHARSET
},
547 { XML_NAMESPACE_DB
, XML_CONNECTION_DATA
, XML_TOK_CONNECTION_DATA
},
548 { XML_NAMESPACE_DB
, XML_DATABASE_DESCRIPTION
, XML_TOK_DATABASE_DESCRIPTION
},
549 { XML_NAMESPACE_DB
, XML_COMPOUND_DATABASE
, XML_TOK_COMPOUND_DATABASE
},
550 { XML_NAMESPACE_XLINK
, XML_HREF
, XML_TOK_DB_HREF
},
551 { XML_NAMESPACE_DB
, XML_MEDIA_TYPE
, XML_TOK_MEDIA_TYPE
},
552 { XML_NAMESPACE_DB
, XML_TYPE
, XML_TOK_DB_TYPE
},
553 { XML_NAMESPACE_DB
, XML_HOSTNAME
, XML_TOK_HOSTNAME
},
554 { XML_NAMESPACE_DB
, XML_PORT
, XML_TOK_PORT
},
555 { XML_NAMESPACE_DB
, XML_LOCAL_SOCKET
, XML_TOK_LOCAL_SOCKET
},
556 { XML_NAMESPACE_DB
, XML_DATABASE_NAME
, XML_TOK_DATABASE_NAME
},
557 { XML_NAMESPACE_DB
, XML_DRIVER_SETTINGS
, XML_TOK_DRIVER_SETTINGS
},
558 { XML_NAMESPACE_DB
, XML_JAVA_CLASSPATH
, XML_TOK_JAVA_CLASSPATH
},
559 { XML_NAMESPACE_DB
, XML_CHARACTER_SET
, XML_TOK_CHARACTER_SET
},
560 { XML_NAMESPACE_DB
, XML_APPLICATION_CONNECTION_SETTINGS
,XML_TOK_APPLICATION_CONNECTION_SETTINGS
},
563 m_pDataSourceElemTokenMap
.reset(new SvXMLTokenMap( aElemTokenMap
));
565 return *m_pDataSourceElemTokenMap
;
569 const SvXMLTokenMap
& ODBFilter::GetLoginElemTokenMap() const
571 if ( !m_pLoginElemTokenMap
.get() )
573 static const SvXMLTokenMapEntry aElemTokenMap
[]=
575 { XML_NAMESPACE_DB
, XML_USER_NAME
, XML_TOK_USER_NAME
},
576 { XML_NAMESPACE_DB
, XML_IS_PASSWORD_REQUIRED
, XML_TOK_IS_PASSWORD_REQUIRED
},
577 { XML_NAMESPACE_DB
, XML_USE_SYSTEM_USER
, XML_TOK_USE_SYSTEM_USER
},
578 { XML_NAMESPACE_DB
, XML_LOGIN_TIMEOUT
, XML_TOK_LOGIN_TIMEOUT
},
581 m_pLoginElemTokenMap
.reset(new SvXMLTokenMap( aElemTokenMap
));
583 return *m_pLoginElemTokenMap
;
587 const SvXMLTokenMap
& ODBFilter::GetDatabaseDescriptionElemTokenMap() const
589 if ( !m_pDatabaseDescriptionElemTokenMap
.get() )
591 static const SvXMLTokenMapEntry aElemTokenMap
[]=
593 { XML_NAMESPACE_DB
, XML_FILE_BASED_DATABASE
, XML_TOK_FILE_BASED_DATABASE
},
594 { XML_NAMESPACE_DB
, XML_SERVER_DATABASE
, XML_TOK_SERVER_DATABASE
},
597 m_pDatabaseDescriptionElemTokenMap
.reset(new SvXMLTokenMap( aElemTokenMap
));
599 return *m_pDatabaseDescriptionElemTokenMap
;
603 const SvXMLTokenMap
& ODBFilter::GetDataSourceInfoElemTokenMap() const
605 if ( !m_pDataSourceInfoElemTokenMap
.get() )
607 static const SvXMLTokenMapEntry aElemTokenMap
[]=
609 { XML_NAMESPACE_DB
, XML_ADDITIONAL_COLUMN_STATEMENT
,XML_TOK_ADDITIONAL_COLUMN_STATEMENT
},
610 { XML_NAMESPACE_DB
, XML_ROW_RETRIEVING_STATEMENT
, XML_TOK_ROW_RETRIEVING_STATEMENT
},
611 { XML_NAMESPACE_DB
, XML_STRING
, XML_TOK_STRING
},
612 { XML_NAMESPACE_DB
, XML_FIELD
, XML_TOK_FIELD
},
613 { XML_NAMESPACE_DB
, XML_DECIMAL
, XML_TOK_DECIMAL
},
614 { XML_NAMESPACE_DB
, XML_THOUSAND
, XML_TOK_THOUSAND
},
615 { XML_NAMESPACE_DB
, XML_DATA_SOURCE_SETTING
, XML_TOK_DATA_SOURCE_SETTING
},
616 { XML_NAMESPACE_DB
, XML_DATA_SOURCE_SETTING_VALUE
, XML_TOK_DATA_SOURCE_SETTING_VALUE
},
617 { XML_NAMESPACE_DB
, XML_DATA_SOURCE_SETTING_IS_LIST
,XML_TOK_DATA_SOURCE_SETTING_IS_LIST
},
618 { XML_NAMESPACE_DB
, XML_DATA_SOURCE_SETTING_TYPE
, XML_TOK_DATA_SOURCE_SETTING_TYPE
},
619 { XML_NAMESPACE_DB
, XML_DATA_SOURCE_SETTING_NAME
, XML_TOK_DATA_SOURCE_SETTING_NAME
},
620 { XML_NAMESPACE_DB
, XML_FONT_CHARSET
, XML_TOK_FONT_CHARSET
},
621 { XML_NAMESPACE_DB
, XML_ENCODING
, XML_TOK_ENCODING
},
624 m_pDataSourceInfoElemTokenMap
.reset(new SvXMLTokenMap( aElemTokenMap
));
626 return *m_pDataSourceInfoElemTokenMap
;
630 const SvXMLTokenMap
& ODBFilter::GetDocumentsElemTokenMap() const
632 if ( !m_pDocumentsElemTokenMap
.get() )
634 static const SvXMLTokenMapEntry aElemTokenMap
[]=
636 { XML_NAMESPACE_DB
, XML_COMPONENT
, XML_TOK_COMPONENT
},
637 { XML_NAMESPACE_DB
, XML_COMPONENT_COLLECTION
, XML_TOK_COMPONENT_COLLECTION
},
638 { XML_NAMESPACE_DB
, XML_QUERY_COLLECTION
, XML_TOK_QUERY_COLLECTION
},
639 { XML_NAMESPACE_DB
, XML_QUERY
, XML_TOK_QUERY
},
640 { XML_NAMESPACE_DB
, XML_TABLE
, XML_TOK_TABLE
},
641 { XML_NAMESPACE_DB
, XML_TABLE_REPRESENTATION
, XML_TOK_TABLE
},
642 { XML_NAMESPACE_DB
, XML_COLUMN
, XML_TOK_COLUMN
},
645 m_pDocumentsElemTokenMap
.reset(new SvXMLTokenMap( aElemTokenMap
));
647 return *m_pDocumentsElemTokenMap
;
651 const SvXMLTokenMap
& ODBFilter::GetComponentElemTokenMap() const
653 if ( !m_pComponentElemTokenMap
.get() )
655 static const SvXMLTokenMapEntry aElemTokenMap
[]=
657 { XML_NAMESPACE_XLINK
, XML_HREF
, XML_TOK_HREF
},
658 { XML_NAMESPACE_XLINK
, XML_TYPE
, XML_TOK_TYPE
},
659 { XML_NAMESPACE_XLINK
, XML_SHOW
, XML_TOK_SHOW
},
660 { XML_NAMESPACE_XLINK
, XML_ACTUATE
, XML_TOK_ACTUATE
},
661 { XML_NAMESPACE_DB
, XML_AS_TEMPLATE
, XML_TOK_AS_TEMPLATE
},
662 { XML_NAMESPACE_DB
, XML_NAME
, XML_TOK_COMPONENT_NAME
},
665 m_pComponentElemTokenMap
.reset(new SvXMLTokenMap( aElemTokenMap
));
667 return *m_pComponentElemTokenMap
;
671 const SvXMLTokenMap
& ODBFilter::GetQueryElemTokenMap() const
673 if ( !m_pQueryElemTokenMap
.get() )
675 static const SvXMLTokenMapEntry aElemTokenMap
[]=
677 { XML_NAMESPACE_DB
, XML_COMMAND
, XML_TOK_COMMAND
},
678 { XML_NAMESPACE_DB
, XML_ESCAPE_PROCESSING
, XML_TOK_ESCAPE_PROCESSING
},
679 { XML_NAMESPACE_DB
, XML_NAME
, XML_TOK_QUERY_NAME
},
680 { XML_NAMESPACE_DB
, XML_FILTER_STATEMENT
, XML_TOK_FILTER_STATEMENT
},
681 { XML_NAMESPACE_DB
, XML_ORDER_STATEMENT
, XML_TOK_ORDER_STATEMENT
},
682 { XML_NAMESPACE_DB
, XML_CATALOG_NAME
, XML_TOK_CATALOG_NAME
},
683 { XML_NAMESPACE_DB
, XML_SCHEMA_NAME
, XML_TOK_SCHEMA_NAME
},
684 { XML_NAMESPACE_DB
, XML_STYLE_NAME
, XML_TOK_STYLE_NAME
},
685 { XML_NAMESPACE_DB
, XML_APPLY_FILTER
, XML_TOK_APPLY_FILTER
},
686 { XML_NAMESPACE_DB
, XML_APPLY_ORDER
, XML_TOK_APPLY_ORDER
},
687 { XML_NAMESPACE_DB
, XML_COLUMNS
, XML_TOK_COLUMNS
},
690 m_pQueryElemTokenMap
.reset(new SvXMLTokenMap( aElemTokenMap
));
692 return *m_pQueryElemTokenMap
;
696 const SvXMLTokenMap
& ODBFilter::GetColumnElemTokenMap() const
698 if ( !m_pColumnElemTokenMap
.get() )
700 static const SvXMLTokenMapEntry aElemTokenMap
[]=
702 { XML_NAMESPACE_DB
, XML_NAME
, XML_TOK_COLUMN_NAME
},
703 { XML_NAMESPACE_DB
, XML_STYLE_NAME
, XML_TOK_COLUMN_STYLE_NAME
},
704 { XML_NAMESPACE_DB
, XML_HELP_MESSAGE
, XML_TOK_COLUMN_HELP_MESSAGE
},
705 { XML_NAMESPACE_DB
, XML_VISIBILITY
, XML_TOK_COLUMN_VISIBILITY
},
706 { XML_NAMESPACE_DB
, XML_DEFAULT_VALUE
, XML_TOK_COLUMN_DEFAULT_VALUE
},
707 { XML_NAMESPACE_DB
, XML_TYPE_NAME
, XML_TOK_COLUMN_TYPE_NAME
},
708 { XML_NAMESPACE_DB
, XML_VISIBLE
, XML_TOK_COLUMN_VISIBLE
},
709 { XML_NAMESPACE_DB
, XML_DEFAULT_CELL_STYLE_NAME
, XML_TOK_DEFAULT_CELL_STYLE_NAME
},
712 m_pColumnElemTokenMap
.reset(new SvXMLTokenMap( aElemTokenMap
));
714 return *m_pColumnElemTokenMap
;
718 SvXMLImportContext
* ODBFilter::CreateStylesContext(sal_uInt16 _nPrefix
,const OUString
& rLocalName
,
719 const uno::Reference
< XAttributeList
>& xAttrList
, bool bIsAutoStyle
)
721 SvXMLImportContext
*pContext
= new OTableStylesContext(*this, _nPrefix
, rLocalName
, xAttrList
, bIsAutoStyle
);
723 SetAutoStyles(static_cast<SvXMLStylesContext
*>(pContext
));
725 SetStyles(static_cast<SvXMLStylesContext
*>(pContext
));
731 SvXMLImportContext
* ODBFilter::CreateScriptContext( const OUString
& _rLocalName
)
733 return new XMLScriptContext( *this, _rLocalName
, GetModel() );
737 rtl::Reference
< XMLPropertySetMapper
> ODBFilter::GetTableStylesPropertySetMapper() const
739 if ( !m_xTableStylesPropertySetMapper
.is() )
741 m_xTableStylesPropertySetMapper
= OXMLHelper::GetTableStylesPropertySetMapper( false);
743 return m_xTableStylesPropertySetMapper
;
747 rtl::Reference
< XMLPropertySetMapper
> ODBFilter::GetColumnStylesPropertySetMapper() const
749 if ( !m_xColumnStylesPropertySetMapper
.is() )
751 m_xColumnStylesPropertySetMapper
= OXMLHelper::GetColumnStylesPropertySetMapper( false);
753 return m_xColumnStylesPropertySetMapper
;
757 rtl::Reference
< XMLPropertySetMapper
> ODBFilter::GetCellStylesPropertySetMapper() const
759 if ( !m_xCellStylesPropertySetMapper
.is() )
761 m_xCellStylesPropertySetMapper
= OXMLHelper::GetCellStylesPropertySetMapper( false);
763 return m_xCellStylesPropertySetMapper
;
767 void ODBFilter::setPropertyInfo()
769 Reference
<XPropertySet
> xDataSource(getDataSource());
770 if ( !xDataSource
.is() )
773 ::connectivity::DriversConfig
aDriverConfig(GetComponentContext());
774 const OUString sURL
= ::comphelper::getString(xDataSource
->getPropertyValue(PROPERTY_URL
));
775 ::comphelper::NamedValueCollection aDataSourceSettings
= aDriverConfig
.getProperties( sURL
);
777 Sequence
<PropertyValue
> aInfo
;
778 if ( !m_aInfoSequence
.empty() )
779 aInfo
= Sequence
<PropertyValue
>(&(*m_aInfoSequence
.begin()),m_aInfoSequence
.size());
780 aDataSourceSettings
.merge( ::comphelper::NamedValueCollection( aInfo
), true );
782 aDataSourceSettings
>>= aInfo
;
783 if ( aInfo
.getLength() )
787 xDataSource
->setPropertyValue(PROPERTY_INFO
,makeAny(aInfo
));
789 catch (const Exception
&)
791 DBG_UNHANDLED_EXCEPTION();
796 } // namespace dbaxml
798 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */