bump product version to 5.0.4.1
[LibreOffice.git] / dbaccess / source / filter / xml / xmlfilter.cxx
blob6b1e16b71cb9b62d9c95830cc2baba79ecae1e0c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <boost/noncopyable.hpp>
23 #include <config_features.h>
24 #include <com/sun/star/util/MeasureUnit.hpp>
25 #include <com/sun/star/packages/zip/ZipIOException.hpp>
26 #include <com/sun/star/embed/ElementModes.hpp>
27 #include <com/sun/star/sdb/XOfficeDatabaseDocument.hpp>
28 #if HAVE_FEATURE_JAVA
29 #include <jvmaccess/virtualmachine.hxx>
30 #endif
31 #include "xmlfilter.hxx"
32 #include "xmlservices.hxx"
33 #include "flt_reghelper.hxx"
34 #include <vcl/svapp.hxx>
35 #include <vcl/window.hxx>
36 #include <xmloff/xmlnmspe.hxx>
37 #include <xmloff/xmlscripti.hxx>
38 #include <xmloff/xmltoken.hxx>
39 #include <xmloff/txtimp.hxx>
40 #include <xmloff/nmspmap.hxx>
41 #include <com/sun/star/xml/sax/InputSource.hpp>
42 #include <com/sun/star/xml/sax/Parser.hpp>
43 #include <xmloff/ProgressBarHelper.hxx>
44 #include <sfx2/docfile.hxx>
45 #include <com/sun/star/io/XInputStream.hpp>
46 #include <com/sun/star/uno/XNamingService.hpp>
47 #include "xmlDatabase.hxx"
48 #include "xmlEnums.hxx"
49 #include "xmlstrings.hrc"
50 #include <xmloff/DocumentSettingsContext.hxx>
51 #include "xmlStyleImport.hxx"
52 #include <xmloff/xmluconv.hxx>
53 #include "xmlHelper.hxx"
54 #include <com/sun/star/util/XModifiable.hpp>
55 #include <com/sun/star/frame/Desktop.hpp>
56 #include <com/sun/star/frame/XComponentLoader.hpp>
57 #include <com/sun/star/frame/FrameSearchFlag.hpp>
58 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
59 #include <osl/mutex.hxx>
60 #include <svtools/sfxecode.hxx>
61 #include <unotools/moduleoptions.hxx>
62 #include <toolkit/helper/vclunohelper.hxx>
63 #include <tools/diagnose_ex.h>
64 #include <osl/diagnose.h>
65 #include <comphelper/processfactory.hxx>
66 #include <comphelper/namedvaluecollection.hxx>
67 #include <comphelper/mimeconfighelper.hxx>
68 #include <comphelper/documentconstants.hxx>
69 #include <comphelper/uno3.hxx>
70 #include <cppuhelper/exc_hlp.hxx>
71 #include <osl/thread.hxx>
72 #include <connectivity/CommonTools.hxx>
73 #include <connectivity/DriversConfig.hxx>
74 #include "dsntypes.hxx"
75 #include <rtl/strbuf.hxx>
77 using namespace ::com::sun::star;
79 extern "C" void SAL_CALL createRegistryInfo_ODBFilter( )
81 static ::dbaxml::OMultiInstanceAutoRegistration< ::dbaxml::ODBFilter > aAutoRegistration;
84 namespace dbaxml
86 namespace
88 class FastLoader : public ::osl::Thread
90 public:
91 typedef enum { E_JAVA, E_CALC } StartType;
92 FastLoader(uno::Reference< uno::XComponentContext > const & _xContext,StartType _eType)
93 :m_xContext(_xContext)
94 ,m_eWhat(_eType)
97 protected:
98 virtual ~FastLoader(){}
100 /// Working method which should be overridden.
101 virtual void SAL_CALL run() SAL_OVERRIDE;
102 virtual void SAL_CALL onTerminated() SAL_OVERRIDE;
103 private:
104 uno::Reference< uno::XComponentContext > m_xContext;
105 StartType m_eWhat;
108 void SAL_CALL FastLoader::run()
110 osl_setThreadName("dbaxml::FastLoader");
112 if ( m_eWhat == E_JAVA )
114 #if HAVE_FEATURE_JAVA
115 static bool s_bFirstTime = true;
116 if ( s_bFirstTime )
118 s_bFirstTime = false;
121 ::rtl::Reference< jvmaccess::VirtualMachine > xJVM = ::connectivity::getJavaVM(m_xContext);
123 catch (const uno::Exception&)
125 OSL_ASSERT(false);
128 #endif
130 else if ( m_eWhat == E_CALC )
132 static bool s_bFirstTime = true;
133 if ( s_bFirstTime )
135 s_bFirstTime = false;
138 uno::Reference<frame::XDesktop2> xDesktop = frame::Desktop::create( m_xContext );
139 const OUString sTarget("_blank");
140 sal_Int32 nFrameSearchFlag = frame::FrameSearchFlag::TASKS | frame::FrameSearchFlag::CREATE;
141 uno::Reference< frame::XFrame> xFrame = xDesktop->findFrame(sTarget,nFrameSearchFlag);
142 uno::Reference<frame::XComponentLoader> xFrameLoad(xFrame,uno::UNO_QUERY);
144 if ( xFrameLoad.is() )
146 uno::Sequence < beans::PropertyValue > aArgs( 3);
147 sal_Int32 nLen = 0;
148 aArgs[nLen].Name = "AsTemplate";
149 aArgs[nLen++].Value <<= sal_False;
151 aArgs[nLen].Name = "ReadOnly";
152 aArgs[nLen++].Value <<= sal_True;
154 aArgs[nLen].Name = "Hidden";
155 aArgs[nLen++].Value <<= sal_True;
157 ::comphelper::MimeConfigurationHelper aHelper( m_xContext );
158 SvtModuleOptions aModuleOptions;
159 // This looks like it makes no sense,
160 // but is probably used to lower latency
161 // of the user interface for the user:
162 // when the user will do anything that requires
163 // the data connection to be established,
164 // calc will already have been loaded, initialised, etc
165 // so establishing the data connection (to a Calc sheet)
166 // will be "faster".
167 uno::Reference< frame::XModel > xModel(xFrameLoad->loadComponentFromURL(
168 aModuleOptions.GetFactoryEmptyDocumentURL( SvtModuleOptions::ClassifyFactoryByServiceName( aHelper.GetDocServiceNameFromMediaType(MIMETYPE_OASIS_OPENDOCUMENT_SPREADSHEET_ASCII) )),
169 OUString(), // empty frame name
171 aArgs
172 ),uno::UNO_QUERY);
173 ::comphelper::disposeComponent(xModel);
176 catch (const uno::Exception&)
178 OSL_ASSERT(false);
183 void SAL_CALL FastLoader::onTerminated()
185 delete this;
188 class DatasourceURLListener:
189 public cppu::WeakImplHelper1<beans::XPropertyChangeListener>,
190 private boost::noncopyable
192 uno::Reference< uno::XComponentContext > m_xContext;
193 ::dbaccess::ODsnTypeCollection m_aTypeCollection;
194 protected:
195 virtual ~DatasourceURLListener(){}
196 public:
197 DatasourceURLListener(uno::Reference< uno::XComponentContext > const & _xContext) : m_xContext(_xContext), m_aTypeCollection(_xContext){}
198 // XPropertyChangeListener
199 virtual void SAL_CALL propertyChange( const beans::PropertyChangeEvent& _rEvent ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
201 OUString sURL;
202 _rEvent.NewValue >>= sURL;
203 FastLoader* pCreatorThread = NULL;
205 if ( m_aTypeCollection.needsJVM(sURL) )
207 #if HAVE_FEATURE_JAVA
208 pCreatorThread = new FastLoader(m_xContext, FastLoader::E_JAVA);
209 #endif
211 else if ( sURL.startsWithIgnoreAsciiCase("sdbc:calc:") )
213 pCreatorThread = new FastLoader(m_xContext, FastLoader::E_CALC);
215 if ( pCreatorThread )
217 pCreatorThread->createSuspended();
218 pCreatorThread->setPriority(osl_Thread_PriorityBelowNormal);
219 pCreatorThread->resume();
222 // XEventListener
223 virtual void SAL_CALL disposing( const lang::EventObject& /*_rSource*/ ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
228 sal_Char const sXML_np__db[] = "_db";
229 sal_Char const sXML_np___db[] = "__db";
231 using namespace ::com::sun::star::util;
232 /// read a component (file + filter version)
233 sal_Int32 ReadThroughComponent(
234 const uno::Reference<XInputStream>& xInputStream,
235 const uno::Reference<XComponent>& xModelComponent,
236 const uno::Reference<XComponentContext> & rxContext,
237 const uno::Reference< XDocumentHandler >& _xFilter )
239 OSL_ENSURE(xInputStream.is(), "input stream missing");
240 OSL_ENSURE(xModelComponent.is(), "document missing");
241 OSL_ENSURE(rxContext.is(), "factory missing");
243 // prepare ParserInputSrouce
244 InputSource aParserInput;
245 aParserInput.aInputStream = xInputStream;
247 // get parser
248 uno::Reference< XParser > xParser = Parser::create(rxContext);
249 SAL_INFO("dbaccess", "parser created" );
251 // get filter
252 OSL_ENSURE( _xFilter.is(), "Can't instantiate filter component." );
253 if( !_xFilter.is() )
254 return 1;
256 // connect parser and filter
257 xParser->setDocumentHandler( _xFilter );
259 // connect model and filter
260 uno::Reference < XImporter > xImporter( _xFilter, UNO_QUERY );
261 xImporter->setTargetDocument( xModelComponent );
263 // finally, parser the stream
266 xParser->parseStream( aParserInput );
268 catch (const SAXParseException& r)
270 #if OSL_DEBUG_LEVEL > 1
271 SAL_WARN("dbaccess", "SAX parse exception catched while importing:\n" << r.Message << r.LineNumber << "," << r.ColumnNumber);
272 #else
273 (void)r;
274 #endif
275 return 1;
277 catch (const SAXException&)
279 return 1;
281 catch (const packages::zip::ZipIOException&)
283 return ERRCODE_IO_BROKENPACKAGE;
285 catch (const Exception&)
287 DBG_UNHANDLED_EXCEPTION();
290 // success!
291 return 0;
294 /// read a component (storage version)
295 sal_Int32 ReadThroughComponent(
296 uno::Reference< embed::XStorage > xStorage,
297 const uno::Reference<XComponent>& xModelComponent,
298 const sal_Char* pStreamName,
299 const sal_Char* pCompatibilityStreamName,
300 const uno::Reference<XComponentContext> & rxContext,
301 const uno::Reference< XDocumentHandler >& _xFilter)
303 OSL_ENSURE( xStorage.is(), "Need storage!");
304 OSL_ENSURE(NULL != pStreamName, "Please, please, give me a name!");
306 if ( xStorage.is() )
308 uno::Reference< io::XStream > xDocStream;
312 bool bEncrypted = false;
313 // open stream (and set parser input)
314 OUString sStreamName = OUString::createFromAscii(pStreamName);
315 if ( !xStorage->hasByName( sStreamName ) || !xStorage->isStreamElement( sStreamName ) )
317 // stream name not found! Then try the compatibility name.
318 // if no stream can be opened, return immediately with OK signal
320 // do we even have an alternative name?
321 if ( NULL == pCompatibilityStreamName )
322 return 0;
324 // if so, does the stream exist?
325 sStreamName = OUString::createFromAscii(pCompatibilityStreamName);
326 if ( !xStorage->hasByName( sStreamName ) || !xStorage->isStreamElement( sStreamName ) )
327 return 0;
330 // get input stream
331 xDocStream = xStorage->openStreamElement( sStreamName, embed::ElementModes::READ );
333 uno::Reference< beans::XPropertySet > xProps( xDocStream, uno::UNO_QUERY_THROW );
334 uno::Any aAny = xProps->getPropertyValue("Encrypted");
335 aAny >>= bEncrypted;
337 catch (const packages::WrongPasswordException&)
339 return ERRCODE_SFX_WRONGPASSWORD;
341 catch (const uno::Exception&)
343 return 1; // TODO/LATER: error handling
346 uno::Reference< XInputStream > xInputStream = xDocStream->getInputStream();
347 // read from the stream
348 return ReadThroughComponent( xInputStream
349 ,xModelComponent
350 ,rxContext
351 ,_xFilter );
354 // TODO/LATER: better error handling
355 return 1;
358 // - ODBFilter -
360 ODBFilter::ODBFilter( const uno::Reference< XComponentContext >& _rxContext )
361 : SvXMLImport(_rxContext, getImplementationName_Static())
362 , m_nPreviewMode(0)
363 , m_bNewFormat(false)
366 GetMM100UnitConverter().SetCoreMeasureUnit(util::MeasureUnit::MM_10TH);
367 GetMM100UnitConverter().SetXMLMeasureUnit(util::MeasureUnit::CM);
368 GetNamespaceMap().Add( OUString ( sXML_np__db ),
369 GetXMLToken(XML_N_DB),
370 XML_NAMESPACE_DB );
372 GetNamespaceMap().Add( OUString ( sXML_np___db ),
373 GetXMLToken(XML_N_DB_OASIS),
374 XML_NAMESPACE_DB );
377 ODBFilter::~ODBFilter() throw()
382 OUString ODBFilter::getImplementationName_Static()
383 throw (css::uno::RuntimeException)
385 return OUString("com.sun.star.comp.sdb.DBFilter");
388 css::uno::Sequence<OUString> ODBFilter::getSupportedServiceNames_Static()
389 throw (css::uno::RuntimeException)
391 css::uno::Sequence<OUString> s(1);
392 s[0] = "com.sun.star.document.ImportFilter";
393 return s;
396 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
397 SAL_CALL ODBFilter::Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB)
399 return static_cast< XServiceInfo* >(new ODBFilter( comphelper::getComponentContext(_rxORB)));
402 sal_Bool SAL_CALL ODBFilter::filter( const Sequence< PropertyValue >& rDescriptor )
403 throw (RuntimeException, std::exception)
405 uno::Reference< ::com::sun::star::awt::XWindow > xWindow;
407 SolarMutexGuard aGuard;
408 vcl::Window* pFocusWindow = Application::GetFocusWindow();
409 xWindow = VCLUnoHelper::GetInterface( pFocusWindow );
410 if( pFocusWindow )
411 pFocusWindow->EnterWait();
413 bool bRet = false;
415 if ( GetModel().is() )
416 bRet = implImport( rDescriptor );
418 if ( xWindow.is() )
420 SolarMutexGuard aGuard;
421 vcl::Window* pFocusWindow = VCLUnoHelper::GetWindow( xWindow );
422 if ( pFocusWindow )
423 pFocusWindow->LeaveWait();
426 return bRet;
429 bool ODBFilter::implImport( const Sequence< PropertyValue >& rDescriptor )
430 throw (RuntimeException)
432 OUString sFileName;
433 ::comphelper::NamedValueCollection aMediaDescriptor( rDescriptor );
435 uno::Reference<embed::XStorage> xStorage = GetSourceStorage();
437 bool bRet = true;
438 if (!xStorage.is())
440 if (aMediaDescriptor.has("URL"))
441 sFileName = aMediaDescriptor.getOrDefault("URL", OUString());
442 if (sFileName.isEmpty() && aMediaDescriptor.has("FileName"))
443 sFileName = aMediaDescriptor.getOrDefault("FileName", sFileName);
445 OSL_ENSURE(!sFileName.isEmpty(), "ODBFilter::implImport: no URL given!");
446 bRet = !sFileName.isEmpty();
449 if ( bRet )
451 uno::Reference<XComponent> xCom(GetModel(),UNO_QUERY);
453 SfxMediumRef pMedium(0);
454 if (!xStorage.is())
456 OUString sStreamRelPath;
457 if (sFileName.startsWithIgnoreAsciiCase("vnd.sun.star.pkg:"))
459 // In this case the host contains the real path, and the the path is the embedded stream name.
460 INetURLObject aURL(sFileName);
461 sFileName = aURL.GetHost(INetURLObject::DECODE_WITH_CHARSET);
462 sStreamRelPath = aURL.GetURLPath(INetURLObject::DECODE_WITH_CHARSET);
463 if (sStreamRelPath.startsWith("/"))
464 sStreamRelPath = sStreamRelPath.copy(1);
467 pMedium = new SfxMedium(sFileName, (StreamMode::READ | StreamMode::NOCREATE));
470 xStorage.set(pMedium->GetStorage(false), UNO_QUERY_THROW);
472 if (!sStreamRelPath.isEmpty())
473 xStorage = xStorage->openStorageElement(sStreamRelPath, embed::ElementModes::READ);
475 catch (const Exception&)
477 Any aError = ::cppu::getCaughtException();
478 if (aError.isExtractableTo(::cppu::UnoType<RuntimeException>::get()))
479 throw;
480 throw lang::WrappedTargetRuntimeException(OUString(), *this, aError);
484 uno::Reference<sdb::XOfficeDatabaseDocument> xOfficeDoc(GetModel(),UNO_QUERY_THROW);
485 m_xDataSource.set(xOfficeDoc->getDataSource(),UNO_QUERY_THROW);
486 uno::Reference<beans::XPropertyChangeListener> xListener = new DatasourceURLListener( GetComponentContext());
487 m_xDataSource->addPropertyChangeListener(PROPERTY_URL,xListener);
488 uno::Reference< XNumberFormatsSupplier > xNum(m_xDataSource->getPropertyValue(PROPERTY_NUMBERFORMATSSUPPLIER),UNO_QUERY);
489 SetNumberFormatsSupplier(xNum);
491 uno::Reference<XComponent> xModel(GetModel(),UNO_QUERY);
492 sal_Int32 nRet = ReadThroughComponent( xStorage
493 ,xModel
494 ,"settings.xml"
495 ,"Settings.xml"
496 ,GetComponentContext()
497 ,this
500 if ( nRet == 0 )
501 nRet = ReadThroughComponent( xStorage
502 ,xModel
503 ,"content.xml"
504 ,"Content.xml"
505 ,GetComponentContext()
506 ,this
509 bRet = nRet == 0;
511 if ( bRet )
513 uno::Reference< XModifiable > xModi(GetModel(),UNO_QUERY);
514 if ( xModi.is() )
515 xModi->setModified(sal_False);
517 else
519 switch( nRet )
521 case ERRCODE_IO_BROKENPACKAGE:
522 // TODO/LATER: no way to transport the error outside from the filter!
523 break;
524 default:
526 // TODO/LATER: this is completely wrong! Filter code should never call ErrorHandler directly! But for now this is the only way!
527 ErrorHandler::HandleError( nRet );
528 if( nRet & ERRCODE_WARNING_MASK )
529 bRet = true;
535 return bRet;
538 SvXMLImportContext* ODBFilter::CreateContext( sal_uInt16 nPrefix,
539 const OUString& rLocalName,
540 const uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList )
542 SvXMLImportContext *pContext = 0;
544 const SvXMLTokenMap& rTokenMap = GetDocElemTokenMap();
545 switch( rTokenMap.Get( nPrefix, rLocalName ) )
547 case XML_TOK_DOC_SETTINGS:
548 GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
549 pContext = new XMLDocumentSettingsContext( *this, nPrefix, rLocalName,xAttrList );
550 break;
551 case XML_TOK_DOC_DATABASE:
552 GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
553 pContext = new OXMLDatabase( *this, nPrefix, rLocalName );
554 break;
555 case XML_TOK_DOC_STYLES:
556 GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
557 pContext = CreateStylesContext(nPrefix, rLocalName, xAttrList, false);
558 break;
559 case XML_TOK_DOC_AUTOSTYLES:
560 GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
561 pContext = CreateStylesContext(nPrefix, rLocalName, xAttrList, true);
562 break;
563 case XML_TOK_DOC_SCRIPT:
564 pContext = CreateScriptContext( rLocalName );
565 break;
568 if ( !pContext )
569 pContext = SvXMLImport::CreateContext( nPrefix, rLocalName, xAttrList );
571 return pContext;
574 void ODBFilter::SetViewSettings(const Sequence<PropertyValue>& aViewProps)
576 const PropertyValue *pIter = aViewProps.getConstArray();
577 const PropertyValue *pEnd = pIter + aViewProps.getLength();
578 for (; pIter != pEnd; ++pIter)
580 if ( pIter->Name == "Queries" )
582 fillPropertyMap(pIter->Value,m_aQuerySettings);
584 else if ( pIter->Name == "Tables" )
586 fillPropertyMap(pIter->Value,m_aTablesSettings);
591 void ODBFilter::SetConfigurationSettings(const Sequence<PropertyValue>& aConfigProps)
593 const PropertyValue *pIter = aConfigProps.getConstArray();
594 const PropertyValue *pEnd = pIter + aConfigProps.getLength();
595 for (; pIter != pEnd; ++pIter)
597 if ( pIter->Name == "layout-settings" )
599 Sequence<PropertyValue> aWindows;
600 pIter->Value >>= aWindows;
601 uno::Reference<XPropertySet> xProp(getDataSource());
602 if ( xProp.is() )
603 xProp->setPropertyValue(PROPERTY_LAYOUTINFORMATION,makeAny(aWindows));
608 void ODBFilter::fillPropertyMap(const Any& _rValue,TPropertyNameMap& _rMap)
610 Sequence<PropertyValue> aWindows;
611 _rValue >>= aWindows;
612 const PropertyValue *pIter = aWindows.getConstArray();
613 const PropertyValue *pEnd = pIter + aWindows.getLength();
614 for (; pIter != pEnd; ++pIter)
616 Sequence<PropertyValue> aValue;
617 pIter->Value >>= aValue;
618 _rMap.insert(TPropertyNameMap::value_type(pIter->Name,aValue));
623 const SvXMLTokenMap& ODBFilter::GetDocElemTokenMap() const
625 if ( !m_pDocElemTokenMap.get() )
627 static const SvXMLTokenMapEntry aElemTokenMap[]=
629 { XML_NAMESPACE_OFFICE, XML_SETTINGS, XML_TOK_DOC_SETTINGS },
630 { XML_NAMESPACE_OOO, XML_SETTINGS, XML_TOK_DOC_SETTINGS },
631 { XML_NAMESPACE_OFFICE, XML_STYLES, XML_TOK_DOC_STYLES },
632 { XML_NAMESPACE_OOO, XML_STYLES, XML_TOK_DOC_STYLES },
633 { XML_NAMESPACE_OFFICE, XML_AUTOMATIC_STYLES, XML_TOK_DOC_AUTOSTYLES },
634 { XML_NAMESPACE_OOO, XML_AUTOMATIC_STYLES, XML_TOK_DOC_AUTOSTYLES },
635 { XML_NAMESPACE_OFFICE, XML_DATABASE, XML_TOK_DOC_DATABASE },
636 { XML_NAMESPACE_OOO, XML_DATABASE, XML_TOK_DOC_DATABASE },
637 { XML_NAMESPACE_OFFICE, XML_SCRIPTS, XML_TOK_DOC_SCRIPT },
638 XML_TOKEN_MAP_END
640 m_pDocElemTokenMap.reset(new SvXMLTokenMap( aElemTokenMap ));
642 return *m_pDocElemTokenMap;
645 const SvXMLTokenMap& ODBFilter::GetDatabaseElemTokenMap() const
647 if ( !m_pDatabaseElemTokenMap.get() )
649 static const SvXMLTokenMapEntry aElemTokenMap[]=
651 { XML_NAMESPACE_DB, XML_DATASOURCE, XML_TOK_DATASOURCE },
652 { XML_NAMESPACE_DB, XML_FORMS, XML_TOK_FORMS},
653 { XML_NAMESPACE_DB, XML_REPORTS, XML_TOK_REPORTS},
654 { XML_NAMESPACE_DB, XML_QUERIES, XML_TOK_QUERIES},
655 { XML_NAMESPACE_DB, XML_TABLES, XML_TOK_TABLES},
656 { XML_NAMESPACE_DB, XML_TABLE_REPRESENTATIONS, XML_TOK_TABLES},
657 { XML_NAMESPACE_DB, XML_SCHEMA_DEFINITION, XML_TOK_SCHEMA_DEFINITION},
658 XML_TOKEN_MAP_END
660 m_pDatabaseElemTokenMap.reset(new SvXMLTokenMap( aElemTokenMap ));
662 return *m_pDatabaseElemTokenMap;
665 const SvXMLTokenMap& ODBFilter::GetDataSourceElemTokenMap() const
667 if ( !m_pDataSourceElemTokenMap.get() )
669 static const SvXMLTokenMapEntry aElemTokenMap[]=
671 { XML_NAMESPACE_DB, XML_CONNECTION_RESOURCE, XML_TOK_CONNECTION_RESOURCE},
672 { XML_NAMESPACE_DB, XML_SUPPRESS_VERSION_COLUMNS, XML_TOK_SUPPRESS_VERSION_COLUMNS},
673 { XML_NAMESPACE_DB, XML_JAVA_DRIVER_CLASS, XML_TOK_JAVA_DRIVER_CLASS},
674 { XML_NAMESPACE_DB, XML_EXTENSION, XML_TOK_EXTENSION},
675 { XML_NAMESPACE_DB, XML_IS_FIRST_ROW_HEADER_LINE, XML_TOK_IS_FIRST_ROW_HEADER_LINE},
676 { XML_NAMESPACE_DB, XML_SHOW_DELETED, XML_TOK_SHOW_DELETED},
677 { XML_NAMESPACE_DB, XML_IS_TABLE_NAME_LENGTH_LIMITED, XML_TOK_IS_TABLE_NAME_LENGTH_LIMITED},
678 { XML_NAMESPACE_DB, XML_SYSTEM_DRIVER_SETTINGS, XML_TOK_SYSTEM_DRIVER_SETTINGS},
679 { XML_NAMESPACE_DB, XML_ENABLE_SQL92_CHECK, XML_TOK_ENABLE_SQL92_CHECK},
680 { XML_NAMESPACE_DB, XML_APPEND_TABLE_ALIAS_NAME, XML_TOK_APPEND_TABLE_ALIAS_NAME},
681 { XML_NAMESPACE_DB, XML_PARAMETER_NAME_SUBSTITUTION, XML_TOK_PARAMETER_NAME_SUBSTITUTION},
682 { XML_NAMESPACE_DB, XML_IGNORE_DRIVER_PRIVILEGES, XML_TOK_IGNORE_DRIVER_PRIVILEGES},
683 { XML_NAMESPACE_DB, XML_BOOLEAN_COMPARISON_MODE, XML_TOK_BOOLEAN_COMPARISON_MODE},
684 { XML_NAMESPACE_DB, XML_USE_CATALOG, XML_TOK_USE_CATALOG},
685 { XML_NAMESPACE_DB, XML_BASE_DN, XML_TOK_BASE_DN},
686 { XML_NAMESPACE_DB, XML_MAX_ROW_COUNT, XML_TOK_MAX_ROW_COUNT},
687 { XML_NAMESPACE_DB, XML_LOGIN, XML_TOK_LOGIN},
688 { XML_NAMESPACE_DB, XML_TABLE_FILTER, XML_TOK_TABLE_FILTER},
689 { XML_NAMESPACE_DB, XML_TABLE_TYPE_FILTER, XML_TOK_TABLE_TYPE_FILTER},
690 { XML_NAMESPACE_DB, XML_AUTO_INCREMENT, XML_TOK_AUTO_INCREMENT},
691 { XML_NAMESPACE_DB, XML_DELIMITER, XML_TOK_DELIMITER},
692 { XML_NAMESPACE_DB, XML_DATA_SOURCE_SETTINGS, XML_TOK_DATA_SOURCE_SETTINGS},
693 { XML_NAMESPACE_DB, XML_FONT_CHARSET, XML_TOK_FONT_CHARSET},
694 // db odf 12
695 { XML_NAMESPACE_DB, XML_CONNECTION_DATA, XML_TOK_CONNECTION_DATA},
696 { XML_NAMESPACE_DB, XML_DATABASE_DESCRIPTION, XML_TOK_DATABASE_DESCRIPTION},
697 { XML_NAMESPACE_DB, XML_COMPOUND_DATABASE, XML_TOK_COMPOUND_DATABASE},
698 { XML_NAMESPACE_XLINK, XML_HREF, XML_TOK_DB_HREF},
699 { XML_NAMESPACE_DB, XML_MEDIA_TYPE, XML_TOK_MEDIA_TYPE},
700 { XML_NAMESPACE_DB, XML_TYPE, XML_TOK_DB_TYPE},
701 { XML_NAMESPACE_DB, XML_HOSTNAME, XML_TOK_HOSTNAME},
702 { XML_NAMESPACE_DB, XML_PORT, XML_TOK_PORT},
703 { XML_NAMESPACE_DB, XML_LOCAL_SOCKET, XML_TOK_LOCAL_SOCKET},
704 { XML_NAMESPACE_DB, XML_DATABASE_NAME, XML_TOK_DATABASE_NAME},
705 { XML_NAMESPACE_DB, XML_DRIVER_SETTINGS, XML_TOK_DRIVER_SETTINGS},
706 { XML_NAMESPACE_DB, XML_JAVA_CLASSPATH, XML_TOK_JAVA_CLASSPATH},
707 { XML_NAMESPACE_DB, XML_CHARACTER_SET, XML_TOK_CHARACTER_SET},
708 { XML_NAMESPACE_DB, XML_APPLICATION_CONNECTION_SETTINGS,XML_TOK_APPLICATION_CONNECTION_SETTINGS},
709 XML_TOKEN_MAP_END
711 m_pDataSourceElemTokenMap.reset(new SvXMLTokenMap( aElemTokenMap ));
713 return *m_pDataSourceElemTokenMap;
716 const SvXMLTokenMap& ODBFilter::GetLoginElemTokenMap() const
718 if ( !m_pLoginElemTokenMap.get() )
720 static const SvXMLTokenMapEntry aElemTokenMap[]=
722 { XML_NAMESPACE_DB, XML_USER_NAME, XML_TOK_USER_NAME},
723 { XML_NAMESPACE_DB, XML_IS_PASSWORD_REQUIRED, XML_TOK_IS_PASSWORD_REQUIRED},
724 { XML_NAMESPACE_DB, XML_USE_SYSTEM_USER, XML_TOK_USE_SYSTEM_USER},
725 { XML_NAMESPACE_DB, XML_LOGIN_TIMEOUT, XML_TOK_LOGIN_TIMEOUT},
726 XML_TOKEN_MAP_END
728 m_pLoginElemTokenMap.reset(new SvXMLTokenMap( aElemTokenMap ));
730 return *m_pLoginElemTokenMap;
733 const SvXMLTokenMap& ODBFilter::GetDatabaseDescriptionElemTokenMap() const
735 if ( !m_pDatabaseDescriptionElemTokenMap.get() )
737 static const SvXMLTokenMapEntry aElemTokenMap[]=
739 { XML_NAMESPACE_DB, XML_FILE_BASED_DATABASE, XML_TOK_FILE_BASED_DATABASE},
740 { XML_NAMESPACE_DB, XML_SERVER_DATABASE, XML_TOK_SERVER_DATABASE},
741 XML_TOKEN_MAP_END
743 m_pDatabaseDescriptionElemTokenMap.reset(new SvXMLTokenMap( aElemTokenMap ));
745 return *m_pDatabaseDescriptionElemTokenMap;
748 const SvXMLTokenMap& ODBFilter::GetDataSourceInfoElemTokenMap() const
750 if ( !m_pDataSourceInfoElemTokenMap.get() )
752 static const SvXMLTokenMapEntry aElemTokenMap[]=
754 { XML_NAMESPACE_DB, XML_ADDITIONAL_COLUMN_STATEMENT,XML_TOK_ADDITIONAL_COLUMN_STATEMENT},
755 { XML_NAMESPACE_DB, XML_ROW_RETRIEVING_STATEMENT, XML_TOK_ROW_RETRIEVING_STATEMENT},
756 { XML_NAMESPACE_DB, XML_STRING, XML_TOK_STRING},
757 { XML_NAMESPACE_DB, XML_FIELD, XML_TOK_FIELD},
758 { XML_NAMESPACE_DB, XML_DECIMAL, XML_TOK_DECIMAL},
759 { XML_NAMESPACE_DB, XML_THOUSAND, XML_TOK_THOUSAND},
760 { XML_NAMESPACE_DB, XML_DATA_SOURCE_SETTING, XML_TOK_DATA_SOURCE_SETTING},
761 { XML_NAMESPACE_DB, XML_DATA_SOURCE_SETTING_VALUE, XML_TOK_DATA_SOURCE_SETTING_VALUE},
762 { XML_NAMESPACE_DB, XML_DATA_SOURCE_SETTING_IS_LIST,XML_TOK_DATA_SOURCE_SETTING_IS_LIST},
763 { XML_NAMESPACE_DB, XML_DATA_SOURCE_SETTING_TYPE, XML_TOK_DATA_SOURCE_SETTING_TYPE},
764 { XML_NAMESPACE_DB, XML_DATA_SOURCE_SETTING_NAME, XML_TOK_DATA_SOURCE_SETTING_NAME},
765 { XML_NAMESPACE_DB, XML_FONT_CHARSET, XML_TOK_FONT_CHARSET},
766 { XML_NAMESPACE_DB, XML_ENCODING, XML_TOK_ENCODING},
767 XML_TOKEN_MAP_END
769 m_pDataSourceInfoElemTokenMap.reset(new SvXMLTokenMap( aElemTokenMap ));
771 return *m_pDataSourceInfoElemTokenMap;
774 const SvXMLTokenMap& ODBFilter::GetDocumentsElemTokenMap() const
776 if ( !m_pDocumentsElemTokenMap.get() )
778 static const SvXMLTokenMapEntry aElemTokenMap[]=
780 { XML_NAMESPACE_DB, XML_COMPONENT, XML_TOK_COMPONENT},
781 { XML_NAMESPACE_DB, XML_COMPONENT_COLLECTION, XML_TOK_COMPONENT_COLLECTION},
782 { XML_NAMESPACE_DB, XML_QUERY_COLLECTION, XML_TOK_QUERY_COLLECTION},
783 { XML_NAMESPACE_DB, XML_QUERY, XML_TOK_QUERY},
784 { XML_NAMESPACE_DB, XML_TABLE, XML_TOK_TABLE},
785 { XML_NAMESPACE_DB, XML_TABLE_REPRESENTATION, XML_TOK_TABLE},
786 { XML_NAMESPACE_DB, XML_COLUMN, XML_TOK_COLUMN},
787 XML_TOKEN_MAP_END
789 m_pDocumentsElemTokenMap.reset(new SvXMLTokenMap( aElemTokenMap ));
791 return *m_pDocumentsElemTokenMap;
794 const SvXMLTokenMap& ODBFilter::GetComponentElemTokenMap() const
796 if ( !m_pComponentElemTokenMap.get() )
798 static const SvXMLTokenMapEntry aElemTokenMap[]=
800 { XML_NAMESPACE_XLINK, XML_HREF, XML_TOK_HREF },
801 { XML_NAMESPACE_XLINK, XML_TYPE, XML_TOK_TYPE },
802 { XML_NAMESPACE_XLINK, XML_SHOW, XML_TOK_SHOW },
803 { XML_NAMESPACE_XLINK, XML_ACTUATE, XML_TOK_ACTUATE},
804 { XML_NAMESPACE_DB, XML_AS_TEMPLATE, XML_TOK_AS_TEMPLATE },
805 { XML_NAMESPACE_DB, XML_NAME, XML_TOK_COMPONENT_NAME },
806 XML_TOKEN_MAP_END
808 m_pComponentElemTokenMap.reset(new SvXMLTokenMap( aElemTokenMap ));
810 return *m_pComponentElemTokenMap;
813 const SvXMLTokenMap& ODBFilter::GetQueryElemTokenMap() const
815 if ( !m_pQueryElemTokenMap.get() )
817 static const SvXMLTokenMapEntry aElemTokenMap[]=
819 { XML_NAMESPACE_DB, XML_COMMAND, XML_TOK_COMMAND },
820 { XML_NAMESPACE_DB, XML_ESCAPE_PROCESSING, XML_TOK_ESCAPE_PROCESSING },
821 { XML_NAMESPACE_DB, XML_NAME, XML_TOK_QUERY_NAME },
822 { XML_NAMESPACE_DB, XML_FILTER_STATEMENT, XML_TOK_FILTER_STATEMENT },
823 { XML_NAMESPACE_DB, XML_ORDER_STATEMENT, XML_TOK_ORDER_STATEMENT },
824 { XML_NAMESPACE_DB, XML_CATALOG_NAME, XML_TOK_CATALOG_NAME },
825 { XML_NAMESPACE_DB, XML_SCHEMA_NAME, XML_TOK_SCHEMA_NAME },
826 { XML_NAMESPACE_DB, XML_STYLE_NAME, XML_TOK_STYLE_NAME},
827 { XML_NAMESPACE_DB, XML_APPLY_FILTER, XML_TOK_APPLY_FILTER},
828 { XML_NAMESPACE_DB, XML_APPLY_ORDER, XML_TOK_APPLY_ORDER},
829 { XML_NAMESPACE_DB, XML_COLUMNS, XML_TOK_COLUMNS},
830 XML_TOKEN_MAP_END
832 m_pQueryElemTokenMap.reset(new SvXMLTokenMap( aElemTokenMap ));
834 return *m_pQueryElemTokenMap;
837 const SvXMLTokenMap& ODBFilter::GetColumnElemTokenMap() const
839 if ( !m_pColumnElemTokenMap.get() )
841 static const SvXMLTokenMapEntry aElemTokenMap[]=
843 { XML_NAMESPACE_DB, XML_NAME, XML_TOK_COLUMN_NAME },
844 { XML_NAMESPACE_DB, XML_STYLE_NAME, XML_TOK_COLUMN_STYLE_NAME },
845 { XML_NAMESPACE_DB, XML_HELP_MESSAGE, XML_TOK_COLUMN_HELP_MESSAGE },
846 { XML_NAMESPACE_DB, XML_VISIBILITY, XML_TOK_COLUMN_VISIBILITY },
847 { XML_NAMESPACE_DB, XML_DEFAULT_VALUE, XML_TOK_COLUMN_DEFAULT_VALUE },
848 { XML_NAMESPACE_DB, XML_TYPE_NAME, XML_TOK_COLUMN_TYPE_NAME },
849 { XML_NAMESPACE_DB, XML_VISIBLE, XML_TOK_COLUMN_VISIBLE },
850 { XML_NAMESPACE_DB, XML_DEFAULT_CELL_STYLE_NAME, XML_TOK_DEFAULT_CELL_STYLE_NAME },
851 XML_TOKEN_MAP_END
853 m_pColumnElemTokenMap.reset(new SvXMLTokenMap( aElemTokenMap ));
855 return *m_pColumnElemTokenMap;
858 SvXMLImportContext* ODBFilter::CreateStylesContext(sal_uInt16 _nPrefix,const OUString& rLocalName,
859 const uno::Reference< XAttributeList>& xAttrList, bool bIsAutoStyle )
861 SvXMLImportContext *pContext = NULL;
862 if (!pContext)
864 pContext = new OTableStylesContext(*this, _nPrefix, rLocalName, xAttrList, bIsAutoStyle);
865 if (bIsAutoStyle)
866 SetAutoStyles(static_cast<SvXMLStylesContext*>(pContext));
867 else
868 SetStyles(static_cast<SvXMLStylesContext*>(pContext));
870 return pContext;
873 SvXMLImportContext* ODBFilter::CreateScriptContext( const OUString& _rLocalName )
875 return new XMLScriptContext( *this, XML_NAMESPACE_OFFICE, _rLocalName, GetModel() );
878 rtl::Reference < XMLPropertySetMapper > ODBFilter::GetTableStylesPropertySetMapper() const
880 if ( !m_xTableStylesPropertySetMapper.is() )
882 m_xTableStylesPropertySetMapper = OXMLHelper::GetTableStylesPropertySetMapper( false);
884 return m_xTableStylesPropertySetMapper;
887 rtl::Reference < XMLPropertySetMapper > ODBFilter::GetColumnStylesPropertySetMapper() const
889 if ( !m_xColumnStylesPropertySetMapper.is() )
891 m_xColumnStylesPropertySetMapper = OXMLHelper::GetColumnStylesPropertySetMapper( false);
893 return m_xColumnStylesPropertySetMapper;
896 rtl::Reference < XMLPropertySetMapper > ODBFilter::GetCellStylesPropertySetMapper() const
898 if ( !m_xCellStylesPropertySetMapper.is() )
900 m_xCellStylesPropertySetMapper = OXMLHelper::GetCellStylesPropertySetMapper( false);
902 return m_xCellStylesPropertySetMapper;
905 void ODBFilter::setPropertyInfo()
907 Reference<XPropertySet> xDataSource(getDataSource());
908 if ( !xDataSource.is() )
909 return;
911 ::connectivity::DriversConfig aDriverConfig(GetComponentContext());
912 const OUString sURL = ::comphelper::getString(xDataSource->getPropertyValue(PROPERTY_URL));
913 ::comphelper::NamedValueCollection aDataSourceSettings = aDriverConfig.getProperties( sURL );
915 Sequence<PropertyValue> aInfo;
916 if ( !m_aInfoSequence.empty() )
917 aInfo = Sequence<PropertyValue>(&(*m_aInfoSequence.begin()),m_aInfoSequence.size());
918 aDataSourceSettings.merge( ::comphelper::NamedValueCollection( aInfo ), true );
920 aDataSourceSettings >>= aInfo;
921 if ( aInfo.getLength() )
925 xDataSource->setPropertyValue(PROPERTY_INFO,makeAny(aInfo));
927 catch (const Exception&)
929 DBG_UNHANDLED_EXCEPTION();
934 }// dbaxml
936 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */