1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_dbaccess.hxx"
26 #include "xmlDatabase.hxx"
27 #include "xmlfilter.hxx"
28 #include <xmloff/xmltoken.hxx>
29 #include <xmloff/xmlnmspe.hxx>
30 #include "xmlDataSource.hxx"
31 #include "xmlDocuments.hxx"
32 #include "xmlEnums.hxx"
33 #include <com/sun/star/sdb/XReportDocumentsSupplier.hpp>
34 #include <com/sun/star/sdb/XFormDocumentsSupplier.hpp>
35 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
36 #include <com/sun/star/sdb/XQueryDefinitionsSupplier.hpp>
37 #include "xmlstrings.hrc"
38 #include <tools/debug.hxx>
39 #include <connectivity/dbtools.hxx>
40 
41 namespace dbaxml
42 {
43 	using namespace ::com::sun::star::uno;
44 	using namespace ::com::sun::star::sdb;
45 	using namespace ::com::sun::star::sdbcx;
46 	using namespace ::com::sun::star::xml::sax;
DBG_NAME(OXMLDatabase)47 DBG_NAME(OXMLDatabase)
48 
49 OXMLDatabase::OXMLDatabase( ODBFilter& rImport,
50 				sal_uInt16 nPrfx, const ::rtl::OUString& rLName ) :
51 	SvXMLImportContext( rImport, nPrfx, rLName )
52 {
53     DBG_CTOR(OXMLDatabase,NULL);
54 
55 }
56 // -----------------------------------------------------------------------------
57 
~OXMLDatabase()58 OXMLDatabase::~OXMLDatabase()
59 {
60 
61     DBG_DTOR(OXMLDatabase,NULL);
62 }
63 // -----------------------------------------------------------------------------
64 
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLocalName,const Reference<XAttributeList> & xAttrList)65 SvXMLImportContext* OXMLDatabase::CreateChildContext(
66 		sal_uInt16 nPrefix,
67 		const ::rtl::OUString& rLocalName,
68 		const Reference< XAttributeList > & xAttrList )
69 {
70 	SvXMLImportContext *pContext = 0;
71 	const SvXMLTokenMap&	rTokenMap	= GetOwnImport().GetDatabaseElemTokenMap();
72 
73 	switch( rTokenMap.Get( nPrefix, rLocalName ) )
74 	{
75 		case XML_TOK_DATASOURCE:
76 			GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
77             pContext = new OXMLDataSource( GetOwnImport(), nPrefix, rLocalName, xAttrList, OXMLDataSource::eDataSource );
78 			break;
79 		case XML_TOK_FORMS:
80 			{
81 				GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
82                 Any aValue;
83                 ::rtl::OUString sService;
84                 dbtools::getDataSourceSetting(GetOwnImport().getDataSource(),"Forms",aValue);
85                 aValue >>= sService;
86                 if ( !sService.getLength() )
87                 {
88 				    Reference<XFormDocumentsSupplier> xSup(GetOwnImport().GetModel(),UNO_QUERY);
89 				    if ( xSup.is() )
90 					    pContext = new OXMLDocuments( GetOwnImport(), nPrefix, rLocalName,xSup->getFormDocuments(),SERVICE_NAME_FORM_COLLECTION,SERVICE_SDB_DOCUMENTDEFINITION);
91                 }
92 			}
93 			break;
94 		case XML_TOK_REPORTS:
95 			{
96 				GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
97                 Any aValue;
98                 ::rtl::OUString sService;
99                 dbtools::getDataSourceSetting(GetOwnImport().getDataSource(),"Reports",aValue);
100                 aValue >>= sService;
101                 if ( !sService.getLength() )
102                 {
103 				    Reference<XReportDocumentsSupplier> xSup(GetOwnImport().GetModel(),UNO_QUERY);
104 				    if ( xSup.is() )
105 					    pContext = new OXMLDocuments( GetOwnImport(), nPrefix, rLocalName,xSup->getReportDocuments(),SERVICE_NAME_REPORT_COLLECTION,SERVICE_SDB_DOCUMENTDEFINITION);
106                 }
107 			}
108 			break;
109 		case XML_TOK_QUERIES:
110 			{
111 				GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
112                 Any aValue;
113                 ::rtl::OUString sService;
114                 dbtools::getDataSourceSetting(GetOwnImport().getDataSource(),"CommandDefinitions",aValue);
115                 aValue >>= sService;
116                 if ( !sService.getLength() )
117                 {
118 				    Reference<XQueryDefinitionsSupplier> xSup(GetOwnImport().getDataSource(),UNO_QUERY);
119 				    if ( xSup.is() )
120 					    pContext = new OXMLDocuments( GetOwnImport(), nPrefix, rLocalName,xSup->getQueryDefinitions(),SERVICE_NAME_QUERY_COLLECTION);
121                 }
122 			}
123 			break;
124 		case XML_TOK_TABLES:
125         case XML_TOK_SCHEMA_DEFINITION:
126 			{
127 				GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
128 				Reference<XTablesSupplier> xSup(GetOwnImport().getDataSource(),UNO_QUERY);
129 				if ( xSup.is() )
130 					pContext = new OXMLDocuments( GetOwnImport(), nPrefix, rLocalName,xSup->getTables());
131 			}
132 			break;
133 	}
134 
135 	if( !pContext )
136 		pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
137 
138 
139 	return pContext;
140 }
141 // -----------------------------------------------------------------------------
GetOwnImport()142 ODBFilter& OXMLDatabase::GetOwnImport()
143 {
144 	return static_cast<ODBFilter&>(GetImport());
145 }
146 // -----------------------------------------------------------------------------
EndElement()147 void OXMLDatabase::EndElement()
148 {
149 	GetOwnImport().setPropertyInfo();
150 }
151 
152 //----------------------------------------------------------------------------
153 } // namespace dbaxml
154 // -----------------------------------------------------------------------------
155