1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmlfilter.cxx,v $
10 * $Revision: 1.20.2.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
34 #ifndef _COM_SUN_STAR_PACKAGES_ZIP_ZIPIOEXCEPTION_HPP_
35 #include <com/sun/star/packages/zip/ZipIOException.hpp>
37 #ifndef _COM_SUN_STAR_EMBED_ELEMENTMODES_HPP_
38 #include <com/sun/star/embed/ElementModes.hpp>
40 #ifndef _COM_SUN_STAR_SDB_XOFFICEDATABASEDOCUMENT_HPP_
41 #include <com/sun/star/sdb/XOfficeDatabaseDocument.hpp>
43 #ifndef DBA_XMLFILTER_HXX
44 #include "xmlfilter.hxx"
46 #ifndef _FLT_REGHELPER_HXX_
47 #include "flt_reghelper.hxx"
50 #include <vcl/svapp.hxx>
52 #ifndef _SV_WINDOW_HXX
53 #include <vcl/window.hxx>
55 #ifndef _XMLOFF_XMLNMSPE_HXX
56 #include <xmloff/xmlnmspe.hxx>
58 #ifndef _XMLOFF_XMLSCRIPTI_HXX
59 #include <xmloff/xmlscripti.hxx>
61 #ifndef _XMLOFF_XMLTOKEN_HXX
62 #include <xmloff/xmltoken.hxx>
64 #ifndef _XMLOFF_TEXTIMP_HXX_
65 #include <xmloff/txtimp.hxx>
67 #ifndef _XMLOFF_NMSPMAP_HXX
68 #include <xmloff/nmspmap.hxx>
70 #ifndef _RTL_LOGFILE_HXX_
71 #include <rtl/logfile.hxx>
73 #ifndef _COM_SUN_STAR_XML_SAX_INPUTSOURCE_HPP_
74 #include <com/sun/star/xml/sax/InputSource.hpp>
76 #ifndef _COM_SUN_STAR_XML_SAX_XPARSER_HPP_
77 #include <com/sun/star/xml/sax/XParser.hpp>
79 #ifndef _XMLOFF_PROGRESSBARHELPER_HXX
80 #include <xmloff/ProgressBarHelper.hxx>
82 #ifndef _SFXDOCFILE_HXX //autogen wg. SfxMedium
83 #include <sfx2/docfile.hxx>
85 #ifndef _COM_SUN_STAR_IO_XINPUTSTREAM_HPP_
86 #include <com/sun/star/io/XInputStream.hpp>
88 #ifndef _COM_SUN_STAR_UNO_XNAMINGSERVICE_HPP_
89 #include <com/sun/star/uno/XNamingService.hpp>
91 #ifndef DBA_XMLDATABASE_HXX
92 #include "xmlDatabase.hxx"
94 #ifndef DBA_XMLENUMS_HXX
95 #include "xmlEnums.hxx"
97 #ifndef _URLOBJ_HXX //autogen wg. INetURLObject
98 #include <tools/urlobj.hxx>
100 #ifndef DBACCESS_SHARED_XMLSTRINGS_HRC
101 #include "xmlstrings.hrc"
103 #ifndef _XMLOFF_DOCUMENTSETTINGSCONTEXT_HXX
104 #include <xmloff/DocumentSettingsContext.hxx>
106 #ifndef DBA_XMLSTYLEIMPORT_HXX
107 #include "xmlStyleImport.hxx"
109 #ifndef _XMLOFF_XMLUCONV_HXX
110 #include <xmloff/xmluconv.hxx>
112 #ifndef DBA_XMLHELPER_HXX
113 #include "xmlHelper.hxx"
115 #ifndef _COM_SUN_STAR_UTIL_XMODIFIABLE_HPP_
116 #include <com/sun/star/util/XModifiable.hpp>
118 #include <com/sun/star/frame/XComponentLoader.hpp>
119 #include <com/sun/star/frame/FrameSearchFlag.hpp>
120 #ifndef _SV_SVAPP_HXX //autogen
121 #include <vcl/svapp.hxx>
123 #ifndef _VOS_MUTEX_HXX_
124 #include <vos/mutex.hxx>
126 #include <svtools/sfxecode.hxx>
127 #include <svtools/moduleoptions.hxx>
128 #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
129 #include <toolkit/helper/vclunohelper.hxx>
131 #include <tools/diagnose_ex.h>
132 #include <comphelper/namedvaluecollection.hxx>
133 #include <comphelper/mimeconfighelper.hxx>
134 #include <comphelper/documentconstants.hxx>
135 #include <comphelper/uno3.hxx>
136 #include <osl/thread.hxx>
137 #include <connectivity/CommonTools.hxx>
138 #include <connectivity/DriversConfig.hxx>
139 #include "dsntypes.hxx"
141 using namespace ::com::sun::star
;
143 extern "C" void SAL_CALL
createRegistryInfo_ODBFilter( )
145 static ::dbaxml::OMultiInstanceAutoRegistration
< ::dbaxml::ODBFilter
> aAutoRegistration
;
147 //--------------------------------------------------------------------------
152 class FastLoader
: public ::osl::Thread
155 typedef enum { E_JAVA
, E_CALC
} StartType
;
156 FastLoader(uno::Reference
< lang::XMultiServiceFactory
> const & _xFactory
,StartType _eType
)
157 :m_xFactory(_xFactory
)
162 virtual ~FastLoader(){}
164 /// Working method which should be overridden.
165 virtual void SAL_CALL
run();
166 virtual void SAL_CALL
onTerminated();
168 uno::Reference
< lang::XMultiServiceFactory
> m_xFactory
;
172 void SAL_CALL
FastLoader::run()
174 if ( m_eWhat
== E_JAVA
)
176 static bool s_bFirstTime
= true;
179 s_bFirstTime
= false;
182 ::rtl::Reference
< jvmaccess::VirtualMachine
> xJVM
= ::connectivity::getJavaVM(m_xFactory
);
184 catch(uno::Exception
& ex
)
189 } // if ( s_bFirstTime )
190 } // if ( m_eWhat == E_JAVA )
191 else if ( m_eWhat
== E_CALC
)
193 static bool s_bFirstTime
= true;
196 s_bFirstTime
= false;
199 uno::Reference
<frame::XComponentLoader
> xFrameLoad( m_xFactory
->createInstance(
200 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.Desktop")))
202 const ::rtl::OUString
sTarget(RTL_CONSTASCII_USTRINGPARAM("_blank"));
203 sal_Int32 nFrameSearchFlag
= frame::FrameSearchFlag::TASKS
| frame::FrameSearchFlag::CREATE
;
204 uno::Reference
< frame::XFrame
> xFrame
= uno::Reference
< frame::XFrame
>(xFrameLoad
,uno::UNO_QUERY_THROW
)->findFrame(sTarget
,nFrameSearchFlag
);
205 xFrameLoad
.set( xFrame
,uno::UNO_QUERY
);
207 if ( xFrameLoad
.is() )
209 uno::Sequence
< beans::PropertyValue
> aArgs( 3);
211 aArgs
[nLen
].Name
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AsTemplate"));
212 aArgs
[nLen
++].Value
<<= sal_False
;
214 aArgs
[nLen
].Name
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ReadOnly"));
215 aArgs
[nLen
++].Value
<<= sal_True
;
217 aArgs
[nLen
].Name
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Hidden"));
218 aArgs
[nLen
++].Value
<<= sal_True
;
220 ::comphelper::MimeConfigurationHelper
aHelper(m_xFactory
);
221 SvtModuleOptions aModuleOptions
;
222 uno::Reference
< frame::XModel
> xModel(xFrameLoad
->loadComponentFromURL(
223 aModuleOptions
.GetFactoryEmptyDocumentURL( aModuleOptions
.ClassifyFactoryByServiceName( aHelper
.GetDocServiceNameFromMediaType(MIMETYPE_OASIS_OPENDOCUMENT_SPREADSHEET
) )),
224 ::rtl::OUString(), // empty frame name
228 ::comphelper::disposeComponent(xModel
);
231 catch(uno::Exception
& ex
)
239 void SAL_CALL
FastLoader::onTerminated()
244 class DatasourceURLListener
: public ::cppu::WeakImplHelper1
< beans::XPropertyChangeListener
>
246 uno::Reference
< lang::XMultiServiceFactory
> m_xFactory
;
247 ::dbaccess::ODsnTypeCollection m_aTypeCollection
;
248 DatasourceURLListener(const DatasourceURLListener
&);
249 void operator =(const DatasourceURLListener
&);
251 virtual ~DatasourceURLListener(){}
253 DatasourceURLListener(uno::Reference
< lang::XMultiServiceFactory
> const & _xFactory
) : m_xFactory(_xFactory
),m_aTypeCollection(_xFactory
){}
254 // XPropertyChangeListener
255 virtual void SAL_CALL
propertyChange( const beans::PropertyChangeEvent
& _rEvent
) throw (uno::RuntimeException
)
257 ::rtl::OUString sURL
;
258 _rEvent
.NewValue
>>= sURL
;
259 FastLoader
* pCreatorThread
= NULL
;
261 if ( m_aTypeCollection
.needsJVM(sURL
) )
263 pCreatorThread
= new FastLoader(m_xFactory
,FastLoader::E_JAVA
);
264 } // if ( m_aTypeCollection.needsJVM(sURL) )
265 else if ( sURL
.matchIgnoreAsciiCaseAsciiL("sdbc:calc:",10,0) )
267 pCreatorThread
= new FastLoader(m_xFactory
,FastLoader::E_CALC
);
269 if ( pCreatorThread
)
271 pCreatorThread
->createSuspended();
272 pCreatorThread
->setPriority(osl_Thread_PriorityBelowNormal
);
273 pCreatorThread
->resume();
277 virtual void SAL_CALL
disposing( const lang::EventObject
& /*_rSource*/ ) throw (uno::RuntimeException
)
282 sal_Char __READONLY_DATA sXML_np__db
[] = "_db";
283 sal_Char __READONLY_DATA sXML_np___db
[] = "__db";
285 using namespace ::com::sun::star::util
;
286 /// read a component (file + filter version)
287 sal_Int32
ReadThroughComponent(
288 const uno::Reference
<XInputStream
>& xInputStream
,
289 const uno::Reference
<XComponent
>& xModelComponent
,
290 const uno::Reference
<XMultiServiceFactory
> & rFactory
,
291 const uno::Reference
< XDocumentHandler
>& _xFilter
)
293 DBG_ASSERT(xInputStream
.is(), "input stream missing");
294 DBG_ASSERT(xModelComponent
.is(), "document missing");
295 DBG_ASSERT(rFactory
.is(), "factory missing");
297 RTL_LOGFILE_CONTEXT_AUTHOR( aLog
, "dbaxml", "oj", "ReadThroughComponent" );
299 // prepare ParserInputSrouce
300 InputSource aParserInput
;
301 aParserInput
.aInputStream
= xInputStream
;
304 uno::Reference
< XParser
> xParser(
305 rFactory
->createInstance(
306 ::rtl::OUString::createFromAscii("com.sun.star.xml.sax.Parser") ),
308 DBG_ASSERT( xParser
.is(), "Can't create parser" );
311 RTL_LOGFILE_CONTEXT_TRACE( aLog
, "parser created" );
314 DBG_ASSERT( _xFilter
.is(), "Can't instantiate filter component." );
318 // connect parser and filter
319 xParser
->setDocumentHandler( _xFilter
);
321 // connect model and filter
322 uno::Reference
< XImporter
> xImporter( _xFilter
, UNO_QUERY
);
323 xImporter
->setTargetDocument( xModelComponent
);
327 // finally, parser the stream
330 xParser
->parseStream( aParserInput
);
332 #if OSL_DEBUG_LEVEL > 1
333 catch( SAXParseException
& r
)
335 ByteString
aError( "SAX parse exception catched while importing:\n" );
336 aError
+= ByteString( String( r
.Message
), RTL_TEXTENCODING_ASCII_US
);
337 aError
+= ByteString::CreateFromInt32( r
.LineNumber
);
339 aError
+= ByteString::CreateFromInt32( r
.ColumnNumber
);
341 DBG_ERROR( aError
.GetBuffer() );
345 catch( SAXParseException
& )
350 catch( SAXException
& )
354 catch( packages::zip::ZipIOException
& )
356 return ERRCODE_IO_BROKENPACKAGE
;
360 DBG_UNHANDLED_EXCEPTION();
367 /// read a component (storage version)
368 sal_Int32
ReadThroughComponent(
369 uno::Reference
< embed::XStorage
> xStorage
,
370 const uno::Reference
<XComponent
>& xModelComponent
,
371 const sal_Char
* pStreamName
,
372 const sal_Char
* pCompatibilityStreamName
,
373 const uno::Reference
<XMultiServiceFactory
> & rFactory
,
374 const uno::Reference
< XDocumentHandler
>& _xFilter
)
376 DBG_ASSERT( xStorage
.is(), "Need storage!");
377 DBG_ASSERT(NULL
!= pStreamName
, "Please, please, give me a name!");
381 uno::Reference
< io::XStream
> xDocStream
;
382 sal_Bool bEncrypted
= sal_False
;
386 // open stream (and set parser input)
387 ::rtl::OUString sStreamName
= ::rtl::OUString::createFromAscii(pStreamName
);
388 if ( !xStorage
->hasByName( sStreamName
) || !xStorage
->isStreamElement( sStreamName
) )
390 // stream name not found! Then try the compatibility name.
391 // if no stream can be opened, return immediatly with OK signal
393 // do we even have an alternative name?
394 if ( NULL
== pCompatibilityStreamName
)
397 // if so, does the stream exist?
398 sStreamName
= ::rtl::OUString::createFromAscii(pCompatibilityStreamName
);
399 if ( !xStorage
->hasByName( sStreamName
) || !xStorage
->isStreamElement( sStreamName
) )
404 xDocStream
= xStorage
->openStreamElement( sStreamName
, embed::ElementModes::READ
);
406 uno::Reference
< beans::XPropertySet
> xProps( xDocStream
, uno::UNO_QUERY_THROW
);
407 uno::Any aAny
= xProps
->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Encrypted") ) );
410 catch( packages::WrongPasswordException
& )
412 return ERRCODE_SFX_WRONGPASSWORD
;
414 catch ( uno::Exception
& )
416 return 1; // TODO/LATER: error handling
420 // if we do profiling, we want to know the stream
421 RTL_LOGFILE_TRACE_AUTHOR1( "dbaxml", "oj",
422 "ReadThroughComponent : parsing \"%s\"", pStreamName
);
425 uno::Reference
< XInputStream
> xInputStream
= xDocStream
->getInputStream();
426 // read from the stream
427 return ReadThroughComponent( xInputStream
433 // TODO/LATER: better error handling
442 ODBFilter::ODBFilter( const uno::Reference
< XMultiServiceFactory
>& _rxMSF
)
446 DBG_CTOR(ODBFilter
,NULL
);
448 GetMM100UnitConverter().setCoreMeasureUnit(MAP_10TH_MM
);
449 GetMM100UnitConverter().setXMLMeasureUnit(MAP_CM
);
450 GetNamespaceMap().Add( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__db
) ),
451 GetXMLToken(XML_N_DB
),
454 GetNamespaceMap().Add( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np___db
) ),
455 GetXMLToken(XML_N_DB_OASIS
),
459 // -----------------------------------------------------------------------------
461 ODBFilter::~ODBFilter() throw()
464 DBG_DTOR(ODBFilter
,NULL
);
466 // -----------------------------------------------------------------------------
467 IMPLEMENT_SERVICE_INFO1_STATIC( ODBFilter
, "com.sun.star.comp.sdb.DBFilter", "com.sun.star.document.ImportFilter")
468 // -----------------------------------------------------------------------------
469 sal_Bool SAL_CALL
ODBFilter::filter( const Sequence
< PropertyValue
>& rDescriptor
)
470 throw (RuntimeException
)
472 uno::Reference
< ::com::sun::star::awt::XWindow
> xWindow
;
474 ::vos::OGuard
aGuard(Application::GetSolarMutex());
475 Window
* pFocusWindow
= Application::GetFocusWindow();
476 xWindow
= VCLUnoHelper::GetInterface( pFocusWindow
);
478 pFocusWindow
->EnterWait();
480 sal_Bool bRet
= sal_False
;
482 if ( GetModel().is() )
483 bRet
= implImport( rDescriptor
);
487 ::vos::OGuard
aGuard(Application::GetSolarMutex());
488 Window
* pFocusWindow
= VCLUnoHelper::GetWindow( xWindow
);
490 pFocusWindow
->LeaveWait();
496 // -----------------------------------------------------------------------------
497 sal_Bool
ODBFilter::implImport( const Sequence
< PropertyValue
>& rDescriptor
)
498 throw (RuntimeException
)
500 ::rtl::OUString sFileName
;
501 ::comphelper::NamedValueCollection
aMediaDescriptor( rDescriptor
);
502 if ( aMediaDescriptor
.has( "URL" ) )
503 sFileName
= aMediaDescriptor
.getOrDefault( "URL", ::rtl::OUString() );
504 if ( !sFileName
.getLength() && aMediaDescriptor
.has( "FileName" ) )
505 sFileName
= aMediaDescriptor
.getOrDefault( "FileName", sFileName
);
507 OSL_ENSURE( sFileName
.getLength(), "ODBFilter::implImport: no URL given!" );
508 sal_Bool bRet
= ( sFileName
.getLength() != 0 );
512 uno::Reference
<XComponent
> xCom(GetModel(),UNO_QUERY
);
514 SfxMediumRef pMedium
= new SfxMedium(
515 sFileName
, ( STREAM_READ
| STREAM_NOCREATE
), FALSE
, 0 );
516 uno::Reference
< embed::XStorage
> xStorage
;
521 xStorage
= pMedium
->GetStorage( sal_False
);
522 // nError = pMedium->GetError();
524 catch(const Exception
&)
529 OSL_ENSURE(xStorage
.is(),"No Storage for read!");
532 uno::Reference
<sdb::XOfficeDatabaseDocument
> xOfficeDoc(GetModel(),UNO_QUERY_THROW
);
533 m_xDataSource
.set(xOfficeDoc
->getDataSource(),UNO_QUERY_THROW
);
534 uno::Reference
<beans::XPropertyChangeListener
> xListener
= new DatasourceURLListener(getServiceFactory());
535 m_xDataSource
->addPropertyChangeListener(PROPERTY_URL
,xListener
);
536 uno::Reference
< XNumberFormatsSupplier
> xNum(m_xDataSource
->getPropertyValue(PROPERTY_NUMBERFORMATSSUPPLIER
),UNO_QUERY
);
537 SetNumberFormatsSupplier(xNum
);
539 uno::Reference
<XComponent
> xModel(GetModel(),UNO_QUERY
);
540 sal_Int32 nRet
= ReadThroughComponent( xStorage
549 nRet
= ReadThroughComponent( xStorage
561 uno::Reference
< XModifiable
> xModi(GetModel(),UNO_QUERY
);
563 xModi
->setModified(sal_False
);
569 case ERRCODE_IO_BROKENPACKAGE
:
572 // TODO/LATER: no way to transport the error outside from the filter!
575 // fall through intented
578 // TODO/LATER: this is completely wrong! Filter code should never call ErrorHandler directly! But for now this is the only way!
579 ErrorHandler::HandleError( nRet
);
580 if( nRet
& ERRCODE_WARNING_MASK
)
590 // -----------------------------------------------------------------------------
591 SvXMLImportContext
* ODBFilter::CreateContext( sal_uInt16 nPrefix
,
592 const ::rtl::OUString
& rLocalName
,
593 const uno::Reference
< ::com::sun::star::xml::sax::XAttributeList
>& xAttrList
)
595 SvXMLImportContext
*pContext
= 0;
597 const SvXMLTokenMap
& rTokenMap
= GetDocElemTokenMap();
598 switch( rTokenMap
.Get( nPrefix
, rLocalName
) )
600 case XML_TOK_DOC_SETTINGS
:
601 GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP
);
602 pContext
= new XMLDocumentSettingsContext( *this, nPrefix
, rLocalName
,xAttrList
);
604 case XML_TOK_DOC_DATABASE
:
605 GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP
);
606 pContext
= new OXMLDatabase( *this, nPrefix
, rLocalName
);
608 case XML_TOK_DOC_STYLES
:
609 GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP
);
610 pContext
= CreateStylesContext(nPrefix
, rLocalName
, xAttrList
, sal_False
);
612 case XML_TOK_DOC_AUTOSTYLES
:
613 GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP
);
614 pContext
= CreateStylesContext(nPrefix
, rLocalName
, xAttrList
, sal_True
);
616 case XML_TOK_DOC_SCRIPT
:
617 pContext
= CreateScriptContext( rLocalName
);
622 pContext
= SvXMLImport::CreateContext( nPrefix
, rLocalName
, xAttrList
);
626 // -----------------------------------------------------------------------------
627 void ODBFilter::SetViewSettings(const Sequence
<PropertyValue
>& aViewProps
)
629 const PropertyValue
*pIter
= aViewProps
.getConstArray();
630 const PropertyValue
*pEnd
= pIter
+ aViewProps
.getLength();
631 for (; pIter
!= pEnd
; ++pIter
)
633 if ( pIter
->Name
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "Queries" ) ) )
635 fillPropertyMap(pIter
->Value
,m_aQuerySettings
);
637 else if ( pIter
->Name
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "Tables" ) ) )
639 fillPropertyMap(pIter
->Value
,m_aTablesSettings
);
643 // -----------------------------------------------------------------------------
644 void ODBFilter::SetConfigurationSettings(const Sequence
<PropertyValue
>& aConfigProps
)
646 const PropertyValue
*pIter
= aConfigProps
.getConstArray();
647 const PropertyValue
*pEnd
= pIter
+ aConfigProps
.getLength();
648 for (; pIter
!= pEnd
; ++pIter
)
650 if ( pIter
->Name
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "layout-settings" ) ) )
652 Sequence
<PropertyValue
> aWindows
;
653 pIter
->Value
>>= aWindows
;
654 uno::Reference
<XPropertySet
> xProp(getDataSource());
656 xProp
->setPropertyValue(PROPERTY_LAYOUTINFORMATION
,makeAny(aWindows
));
660 // -----------------------------------------------------------------------------
661 void ODBFilter::fillPropertyMap(const Any
& _rValue
,TPropertyNameMap
& _rMap
)
663 Sequence
<PropertyValue
> aWindows
;
664 _rValue
>>= aWindows
;
665 const PropertyValue
*pIter
= aWindows
.getConstArray();
666 const PropertyValue
*pEnd
= pIter
+ aWindows
.getLength();
667 for (; pIter
!= pEnd
; ++pIter
)
669 Sequence
<PropertyValue
> aValue
;
670 pIter
->Value
>>= aValue
;
671 _rMap
.insert(TPropertyNameMap::value_type(pIter
->Name
,aValue
));
675 // -----------------------------------------------------------------------------
676 const SvXMLTokenMap
& ODBFilter::GetDocElemTokenMap() const
678 if ( !m_pDocElemTokenMap
.get() )
680 static __FAR_DATA SvXMLTokenMapEntry aElemTokenMap
[]=
682 { XML_NAMESPACE_OFFICE
, XML_SETTINGS
, XML_TOK_DOC_SETTINGS
},
683 { XML_NAMESPACE_OOO
, XML_SETTINGS
, XML_TOK_DOC_SETTINGS
},
684 { XML_NAMESPACE_OFFICE
, XML_STYLES
, XML_TOK_DOC_STYLES
},
685 { XML_NAMESPACE_OOO
, XML_STYLES
, XML_TOK_DOC_STYLES
},
686 { XML_NAMESPACE_OFFICE
, XML_AUTOMATIC_STYLES
, XML_TOK_DOC_AUTOSTYLES
},
687 { XML_NAMESPACE_OOO
, XML_AUTOMATIC_STYLES
, XML_TOK_DOC_AUTOSTYLES
},
688 { XML_NAMESPACE_OFFICE
, XML_DATABASE
, XML_TOK_DOC_DATABASE
},
689 { XML_NAMESPACE_OOO
, XML_DATABASE
, XML_TOK_DOC_DATABASE
},
690 { XML_NAMESPACE_OFFICE
, XML_SCRIPTS
, XML_TOK_DOC_SCRIPT
},
693 m_pDocElemTokenMap
.reset(new SvXMLTokenMap( aElemTokenMap
));
695 return *m_pDocElemTokenMap
;
697 // -----------------------------------------------------------------------------
698 const SvXMLTokenMap
& ODBFilter::GetDatabaseElemTokenMap() const
700 if ( !m_pDatabaseElemTokenMap
.get() )
702 static __FAR_DATA SvXMLTokenMapEntry aElemTokenMap
[]=
704 { XML_NAMESPACE_DB
, XML_DATASOURCE
, XML_TOK_DATASOURCE
},
705 { XML_NAMESPACE_DB
, XML_FORMS
, XML_TOK_FORMS
},
706 { XML_NAMESPACE_DB
, XML_REPORTS
, XML_TOK_REPORTS
},
707 { XML_NAMESPACE_DB
, XML_QUERIES
, XML_TOK_QUERIES
},
708 { XML_NAMESPACE_DB
, XML_TABLES
, XML_TOK_TABLES
},
709 { XML_NAMESPACE_DB
, XML_TABLE_REPRESENTATIONS
, XML_TOK_TABLES
},
710 { XML_NAMESPACE_DB
, XML_SCHEMA_DEFINITION
, XML_TOK_SCHEMA_DEFINITION
},
713 m_pDatabaseElemTokenMap
.reset(new SvXMLTokenMap( aElemTokenMap
));
715 return *m_pDatabaseElemTokenMap
;
717 // -----------------------------------------------------------------------------
718 const SvXMLTokenMap
& ODBFilter::GetDataSourceElemTokenMap() const
720 if ( !m_pDataSourceElemTokenMap
.get() )
722 static __FAR_DATA SvXMLTokenMapEntry aElemTokenMap
[]=
724 { XML_NAMESPACE_DB
, XML_CONNECTION_RESOURCE
, XML_TOK_CONNECTION_RESOURCE
},
725 { XML_NAMESPACE_DB
, XML_SUPPRESS_VERSION_COLUMNS
, XML_TOK_SUPPRESS_VERSION_COLUMNS
},
726 { XML_NAMESPACE_DB
, XML_JAVA_DRIVER_CLASS
, XML_TOK_JAVA_DRIVER_CLASS
},
727 { XML_NAMESPACE_DB
, XML_EXTENSION
, XML_TOK_EXTENSION
},
728 { XML_NAMESPACE_DB
, XML_IS_FIRST_ROW_HEADER_LINE
, XML_TOK_IS_FIRST_ROW_HEADER_LINE
},
729 { XML_NAMESPACE_DB
, XML_SHOW_DELETED
, XML_TOK_SHOW_DELETED
},
730 { XML_NAMESPACE_DB
, XML_IS_TABLE_NAME_LENGTH_LIMITED
, XML_TOK_IS_TABLE_NAME_LENGTH_LIMITED
},
731 { XML_NAMESPACE_DB
, XML_SYSTEM_DRIVER_SETTINGS
, XML_TOK_SYSTEM_DRIVER_SETTINGS
},
732 { XML_NAMESPACE_DB
, XML_ENABLE_SQL92_CHECK
, XML_TOK_ENABLE_SQL92_CHECK
},
733 { XML_NAMESPACE_DB
, XML_APPEND_TABLE_ALIAS_NAME
, XML_TOK_APPEND_TABLE_ALIAS_NAME
},
734 { XML_NAMESPACE_DB
, XML_PARAMETER_NAME_SUBSTITUTION
, XML_TOK_PARAMETER_NAME_SUBSTITUTION
},
735 { XML_NAMESPACE_DB
, XML_IGNORE_DRIVER_PRIVILEGES
, XML_TOK_IGNORE_DRIVER_PRIVILEGES
},
736 { XML_NAMESPACE_DB
, XML_BOOLEAN_COMPARISON_MODE
, XML_TOK_BOOLEAN_COMPARISON_MODE
},
737 { XML_NAMESPACE_DB
, XML_USE_CATALOG
, XML_TOK_USE_CATALOG
},
738 { XML_NAMESPACE_DB
, XML_BASE_DN
, XML_TOK_BASE_DN
},
739 { XML_NAMESPACE_DB
, XML_MAX_ROW_COUNT
, XML_TOK_MAX_ROW_COUNT
},
740 { XML_NAMESPACE_DB
, XML_LOGIN
, XML_TOK_LOGIN
},
741 { XML_NAMESPACE_DB
, XML_TABLE_FILTER
, XML_TOK_TABLE_FILTER
},
742 { XML_NAMESPACE_DB
, XML_TABLE_TYPE_FILTER
, XML_TOK_TABLE_TYPE_FILTER
},
743 { XML_NAMESPACE_DB
, XML_AUTO_INCREMENT
, XML_TOK_AUTO_INCREMENT
},
744 { XML_NAMESPACE_DB
, XML_DELIMITER
, XML_TOK_DELIMITER
},
745 { XML_NAMESPACE_DB
, XML_DATA_SOURCE_SETTINGS
, XML_TOK_DATA_SOURCE_SETTINGS
},
746 { XML_NAMESPACE_DB
, XML_FONT_CHARSET
, XML_TOK_FONT_CHARSET
},
748 { XML_NAMESPACE_DB
, XML_CONNECTION_DATA
, XML_TOK_CONNECTION_DATA
},
749 { XML_NAMESPACE_DB
, XML_DATABASE_DESCRIPTION
, XML_TOK_DATABASE_DESCRIPTION
},
750 { XML_NAMESPACE_DB
, XML_COMPOUND_DATABASE
, XML_TOK_COMPOUND_DATABASE
},
751 { XML_NAMESPACE_XLINK
, XML_HREF
, XML_TOK_DB_HREF
},
752 { XML_NAMESPACE_DB
, XML_MEDIA_TYPE
, XML_TOK_MEDIA_TYPE
},
753 { XML_NAMESPACE_DB
, XML_TYPE
, XML_TOK_DB_TYPE
},
754 { XML_NAMESPACE_DB
, XML_HOSTNAME
, XML_TOK_HOSTNAME
},
755 { XML_NAMESPACE_DB
, XML_PORT
, XML_TOK_PORT
},
756 { XML_NAMESPACE_DB
, XML_LOCAL_SOCKET
, XML_TOK_LOCAL_SOCKET
},
757 { XML_NAMESPACE_DB
, XML_DATABASE_NAME
, XML_TOK_DATABASE_NAME
},
758 { XML_NAMESPACE_DB
, XML_DRIVER_SETTINGS
, XML_TOK_DRIVER_SETTINGS
},
759 { XML_NAMESPACE_DB
, XML_JAVA_CLASSPATH
, XML_TOK_JAVA_CLASSPATH
},
760 { XML_NAMESPACE_DB
, XML_CHARACTER_SET
, XML_TOK_CHARACTER_SET
},
761 { XML_NAMESPACE_DB
, XML_APPLICATION_CONNECTION_SETTINGS
,XML_TOK_APPLICATION_CONNECTION_SETTINGS
},
764 m_pDataSourceElemTokenMap
.reset(new SvXMLTokenMap( aElemTokenMap
));
766 return *m_pDataSourceElemTokenMap
;
768 // -----------------------------------------------------------------------------
769 const SvXMLTokenMap
& ODBFilter::GetLoginElemTokenMap() const
771 if ( !m_pLoginElemTokenMap
.get() )
773 static __FAR_DATA SvXMLTokenMapEntry aElemTokenMap
[]=
775 { XML_NAMESPACE_DB
, XML_USER_NAME
, XML_TOK_USER_NAME
},
776 { XML_NAMESPACE_DB
, XML_IS_PASSWORD_REQUIRED
, XML_TOK_IS_PASSWORD_REQUIRED
},
777 { XML_NAMESPACE_DB
, XML_USE_SYSTEM_USER
, XML_TOK_USE_SYSTEM_USER
},
778 { XML_NAMESPACE_DB
, XML_LOGIN_TIMEOUT
, XML_TOK_LOGIN_TIMEOUT
},
781 m_pLoginElemTokenMap
.reset(new SvXMLTokenMap( aElemTokenMap
));
783 return *m_pLoginElemTokenMap
;
785 // -----------------------------------------------------------------------------
786 const SvXMLTokenMap
& ODBFilter::GetDatabaseDescriptionElemTokenMap() const
788 if ( !m_pDatabaseDescriptionElemTokenMap
.get() )
790 static __FAR_DATA SvXMLTokenMapEntry aElemTokenMap
[]=
792 { XML_NAMESPACE_DB
, XML_FILE_BASED_DATABASE
, XML_TOK_FILE_BASED_DATABASE
},
793 { XML_NAMESPACE_DB
, XML_SERVER_DATABASE
, XML_TOK_SERVER_DATABASE
},
796 m_pDatabaseDescriptionElemTokenMap
.reset(new SvXMLTokenMap( aElemTokenMap
));
798 return *m_pDatabaseDescriptionElemTokenMap
;
800 // -----------------------------------------------------------------------------
801 const SvXMLTokenMap
& ODBFilter::GetDataSourceInfoElemTokenMap() const
803 if ( !m_pDataSourceInfoElemTokenMap
.get() )
805 static __FAR_DATA SvXMLTokenMapEntry aElemTokenMap
[]=
807 { XML_NAMESPACE_DB
, XML_ADDITIONAL_COLUMN_STATEMENT
,XML_TOK_ADDITIONAL_COLUMN_STATEMENT
},
808 { XML_NAMESPACE_DB
, XML_ROW_RETRIEVING_STATEMENT
, XML_TOK_ROW_RETRIEVING_STATEMENT
},
809 { XML_NAMESPACE_DB
, XML_STRING
, XML_TOK_STRING
},
810 { XML_NAMESPACE_DB
, XML_FIELD
, XML_TOK_FIELD
},
811 { XML_NAMESPACE_DB
, XML_DECIMAL
, XML_TOK_DECIMAL
},
812 { XML_NAMESPACE_DB
, XML_THOUSAND
, XML_TOK_THOUSAND
},
813 { XML_NAMESPACE_DB
, XML_DATA_SOURCE_SETTING
, XML_TOK_DATA_SOURCE_SETTING
},
814 { XML_NAMESPACE_DB
, XML_DATA_SOURCE_SETTING_VALUE
, XML_TOK_DATA_SOURCE_SETTING_VALUE
},
815 { XML_NAMESPACE_DB
, XML_DATA_SOURCE_SETTING_IS_LIST
,XML_TOK_DATA_SOURCE_SETTING_IS_LIST
},
816 { XML_NAMESPACE_DB
, XML_DATA_SOURCE_SETTING_TYPE
, XML_TOK_DATA_SOURCE_SETTING_TYPE
},
817 { XML_NAMESPACE_DB
, XML_DATA_SOURCE_SETTING_NAME
, XML_TOK_DATA_SOURCE_SETTING_NAME
},
818 { XML_NAMESPACE_DB
, XML_FONT_CHARSET
, XML_TOK_FONT_CHARSET
},
819 { XML_NAMESPACE_DB
, XML_ENCODING
, XML_TOK_ENCODING
},
822 m_pDataSourceInfoElemTokenMap
.reset(new SvXMLTokenMap( aElemTokenMap
));
824 return *m_pDataSourceInfoElemTokenMap
;
826 // -----------------------------------------------------------------------------
827 const SvXMLTokenMap
& ODBFilter::GetDocumentsElemTokenMap() const
829 if ( !m_pDocumentsElemTokenMap
.get() )
831 static __FAR_DATA SvXMLTokenMapEntry aElemTokenMap
[]=
833 { XML_NAMESPACE_DB
, XML_COMPONENT
, XML_TOK_COMPONENT
},
834 { XML_NAMESPACE_DB
, XML_COMPONENT_COLLECTION
, XML_TOK_COMPONENT_COLLECTION
},
835 { XML_NAMESPACE_DB
, XML_QUERY_COLLECTION
, XML_TOK_QUERY_COLLECTION
},
836 { XML_NAMESPACE_DB
, XML_QUERY
, XML_TOK_QUERY
},
837 { XML_NAMESPACE_DB
, XML_TABLE
, XML_TOK_TABLE
},
838 { XML_NAMESPACE_DB
, XML_TABLE_REPRESENTATION
, XML_TOK_TABLE
},
839 { XML_NAMESPACE_DB
, XML_COLUMN
, XML_TOK_COLUMN
},
842 m_pDocumentsElemTokenMap
.reset(new SvXMLTokenMap( aElemTokenMap
));
844 return *m_pDocumentsElemTokenMap
;
846 // -----------------------------------------------------------------------------
847 const SvXMLTokenMap
& ODBFilter::GetComponentElemTokenMap() const
849 if ( !m_pComponentElemTokenMap
.get() )
851 static __FAR_DATA SvXMLTokenMapEntry aElemTokenMap
[]=
853 { XML_NAMESPACE_XLINK
, XML_HREF
, XML_TOK_HREF
},
854 { XML_NAMESPACE_XLINK
, XML_TYPE
, XML_TOK_TYPE
},
855 { XML_NAMESPACE_XLINK
, XML_SHOW
, XML_TOK_SHOW
},
856 { XML_NAMESPACE_XLINK
, XML_ACTUATE
, XML_TOK_ACTUATE
},
857 { XML_NAMESPACE_DB
, XML_AS_TEMPLATE
, XML_TOK_AS_TEMPLATE
},
858 { XML_NAMESPACE_DB
, XML_NAME
, XML_TOK_COMPONENT_NAME
},
861 m_pComponentElemTokenMap
.reset(new SvXMLTokenMap( aElemTokenMap
));
863 return *m_pComponentElemTokenMap
;
865 // -----------------------------------------------------------------------------
866 const SvXMLTokenMap
& ODBFilter::GetQueryElemTokenMap() const
868 if ( !m_pQueryElemTokenMap
.get() )
870 static __FAR_DATA SvXMLTokenMapEntry aElemTokenMap
[]=
872 { XML_NAMESPACE_DB
, XML_COMMAND
, XML_TOK_COMMAND
},
873 { XML_NAMESPACE_DB
, XML_ESCAPE_PROCESSING
, XML_TOK_ESCAPE_PROCESSING
},
874 { XML_NAMESPACE_DB
, XML_NAME
, XML_TOK_QUERY_NAME
},
875 { XML_NAMESPACE_DB
, XML_FILTER_STATEMENT
, XML_TOK_FILTER_STATEMENT
},
876 { XML_NAMESPACE_DB
, XML_ORDER_STATEMENT
, XML_TOK_ORDER_STATEMENT
},
877 { XML_NAMESPACE_DB
, XML_CATALOG_NAME
, XML_TOK_CATALOG_NAME
},
878 { XML_NAMESPACE_DB
, XML_SCHEMA_NAME
, XML_TOK_SCHEMA_NAME
},
879 { XML_NAMESPACE_DB
, XML_STYLE_NAME
, XML_TOK_STYLE_NAME
},
880 { XML_NAMESPACE_DB
, XML_APPLY_FILTER
, XML_TOK_APPLY_FILTER
},
881 { XML_NAMESPACE_DB
, XML_APPLY_ORDER
, XML_TOK_APPLY_ORDER
},
882 { XML_NAMESPACE_DB
, XML_COLUMNS
, XML_TOK_COLUMNS
},
885 m_pQueryElemTokenMap
.reset(new SvXMLTokenMap( aElemTokenMap
));
887 return *m_pQueryElemTokenMap
;
889 // -----------------------------------------------------------------------------
890 const SvXMLTokenMap
& ODBFilter::GetColumnElemTokenMap() const
892 if ( !m_pColumnElemTokenMap
.get() )
894 static __FAR_DATA SvXMLTokenMapEntry aElemTokenMap
[]=
896 { XML_NAMESPACE_DB
, XML_NAME
, XML_TOK_COLUMN_NAME
},
897 { XML_NAMESPACE_DB
, XML_STYLE_NAME
, XML_TOK_COLUMN_STYLE_NAME
},
898 { XML_NAMESPACE_DB
, XML_HELP_MESSAGE
, XML_TOK_COLUMN_HELP_MESSAGE
},
899 { XML_NAMESPACE_DB
, XML_VISIBILITY
, XML_TOK_COLUMN_VISIBILITY
},
900 { XML_NAMESPACE_DB
, XML_DEFAULT_VALUE
, XML_TOK_COLUMN_DEFAULT_VALUE
},
901 { XML_NAMESPACE_DB
, XML_TYPE_NAME
, XML_TOK_COLUMN_TYPE_NAME
},
902 { XML_NAMESPACE_DB
, XML_VISIBLE
, XML_TOK_COLUMN_VISIBLE
},
903 { XML_NAMESPACE_DB
, XML_DEFAULT_CELL_STYLE_NAME
, XML_TOK_DEFAULT_CELL_STYLE_NAME
},
906 m_pColumnElemTokenMap
.reset(new SvXMLTokenMap( aElemTokenMap
));
908 return *m_pColumnElemTokenMap
;
910 // -----------------------------------------------------------------------------
911 SvXMLImportContext
* ODBFilter::CreateStylesContext(sal_uInt16 _nPrefix
,const ::rtl::OUString
& rLocalName
,
912 const uno::Reference
< XAttributeList
>& xAttrList
, sal_Bool bIsAutoStyle
)
914 SvXMLImportContext
*pContext
= NULL
;
917 pContext
= new OTableStylesContext(*this, _nPrefix
, rLocalName
, xAttrList
, bIsAutoStyle
);
919 //xAutoStyles = pContext;
920 SetAutoStyles((SvXMLStylesContext
*)pContext
);
922 //xStyles = pContext;
923 SetStyles((SvXMLStylesContext
*)pContext
);
927 // -----------------------------------------------------------------------------
928 SvXMLImportContext
* ODBFilter::CreateScriptContext( const ::rtl::OUString
& _rLocalName
)
930 return new XMLScriptContext( *this, XML_NAMESPACE_OFFICE
, _rLocalName
, GetModel() );
932 // -----------------------------------------------------------------------------
933 UniReference
< XMLPropertySetMapper
> ODBFilter::GetTableStylesPropertySetMapper() const
935 if ( !m_xTableStylesPropertySetMapper
.is() )
937 m_xTableStylesPropertySetMapper
= OXMLHelper::GetTableStylesPropertySetMapper();
939 return m_xTableStylesPropertySetMapper
;
941 // -----------------------------------------------------------------------------
942 UniReference
< XMLPropertySetMapper
> ODBFilter::GetColumnStylesPropertySetMapper() const
944 if ( !m_xColumnStylesPropertySetMapper
.is() )
946 m_xColumnStylesPropertySetMapper
= OXMLHelper::GetColumnStylesPropertySetMapper();
948 return m_xColumnStylesPropertySetMapper
;
950 // -----------------------------------------------------------------------------
951 UniReference
< XMLPropertySetMapper
> ODBFilter::GetCellStylesPropertySetMapper() const
953 if ( !m_xCellStylesPropertySetMapper
.is() )
955 m_xCellStylesPropertySetMapper
= OXMLHelper::GetCellStylesPropertySetMapper();
957 return m_xCellStylesPropertySetMapper
;
959 // -----------------------------------------------------------------------------
960 void ODBFilter::setPropertyInfo()
962 Reference
<XPropertySet
> xDataSource(getDataSource());
963 if ( !xDataSource
.is() )
966 ::connectivity::DriversConfig
aDriverConfig(getServiceFactory());
967 const ::rtl::OUString sURL
= ::comphelper::getString(xDataSource
->getPropertyValue(PROPERTY_URL
));
968 ::comphelper::NamedValueCollection aDataSourceSettings
= aDriverConfig
.getProperties( sURL
);
970 Sequence
<PropertyValue
> aInfo
;
971 if ( !m_aInfoSequence
.empty() )
972 aInfo
= Sequence
<PropertyValue
>(&(*m_aInfoSequence
.begin()),m_aInfoSequence
.size());
973 aDataSourceSettings
.merge( ::comphelper::NamedValueCollection( aInfo
), true );
975 aDataSourceSettings
>>= aInfo
;
976 if ( aInfo
.getLength() )
980 xDataSource
->setPropertyValue(PROPERTY_INFO
,makeAny(aInfo
));
984 DBG_UNHANDLED_EXCEPTION();
988 // -----------------------------------------------------------------------------
990 // -----------------------------------------------------------------------------