merge the formfield patch from ooo-build
[ooovba.git] / dbaccess / source / filter / xml / xmlQuery.cxx
blob28ab86a132f99804553d26b50022664aa4d6e58e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmlQuery.cxx,v $
10 * $Revision: 1.9 $
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"
33 #ifndef DBA_XMLQUERY_HXX
34 #include "xmlQuery.hxx"
35 #endif
36 #ifndef DBA_XMLFILTER_HXX
37 #include "xmlfilter.hxx"
38 #endif
39 #ifndef _XMLOFF_XMLTOKEN_HXX
40 #include <xmloff/xmltoken.hxx>
41 #endif
42 #ifndef _XMLOFF_XMLNMSPE_HXX
43 #include <xmloff/xmlnmspe.hxx>
44 #endif
45 #ifndef _XMLOFF_NMSPMAP_HXX
46 #include <xmloff/nmspmap.hxx>
47 #endif
48 #ifndef DBA_XMLENUMS_HXX
49 #include "xmlEnums.hxx"
50 #endif
51 #ifndef DBACCESS_SHARED_XMLSTRINGS_HRC
52 #include "xmlstrings.hrc"
53 #endif
54 #ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_
55 #include <com/sun/star/beans/PropertyValue.hpp>
56 #endif
57 #ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
58 #include <com/sun/star/beans/XPropertySet.hpp>
59 #endif
60 #ifndef _COM_SUN_STAR_CONTAINER_XNAMECONTAINER_HPP_
61 #include <com/sun/star/container/XNameContainer.hpp>
62 #endif
63 #ifndef _TOOLS_DEBUG_HXX
64 #include <tools/debug.hxx>
65 #endif
67 namespace dbaxml
69 using namespace ::com::sun::star::uno;
70 using namespace ::com::sun::star::beans;
71 using namespace ::com::sun::star::container;
72 using namespace ::com::sun::star::xml::sax;
74 DBG_NAME(OXMLQuery)
76 OXMLQuery::OXMLQuery( ODBFilter& rImport
77 ,sal_uInt16 nPrfx
78 ,const ::rtl::OUString& _sLocalName
79 ,const Reference< XAttributeList > & _xAttrList
80 ,const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& _xParentContainer
81 ) :
82 OXMLTable( rImport, nPrfx, _sLocalName,_xAttrList,_xParentContainer,SERVICE_SDB_COMMAND_DEFINITION )
83 ,m_bEscapeProcessing(sal_True)
85 DBG_CTOR(OXMLQuery,NULL);
87 OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!");
88 const SvXMLNamespaceMap& rMap = rImport.GetNamespaceMap();
89 const SvXMLTokenMap& rTokenMap = rImport.GetQueryElemTokenMap();
91 sal_Int16 nLength = (_xAttrList.is()) ? _xAttrList->getLength() : 0;
92 for(sal_Int16 i = 0; i < nLength; ++i)
94 ::rtl::OUString sLocalName;
95 rtl::OUString sAttrName = _xAttrList->getNameByIndex( i );
96 sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
97 rtl::OUString sValue = _xAttrList->getValueByIndex( i );
99 switch( rTokenMap.Get( nPrefix, sLocalName ) )
101 case XML_TOK_COMMAND:
102 m_sCommand = sValue;
103 break;
104 case XML_TOK_ESCAPE_PROCESSING:
105 m_bEscapeProcessing = sValue.equalsAscii("true");
106 break;
110 // -----------------------------------------------------------------------------
112 OXMLQuery::~OXMLQuery()
115 DBG_DTOR(OXMLQuery,NULL);
117 // -----------------------------------------------------------------------------
118 SvXMLImportContext* OXMLQuery::CreateChildContext(
119 sal_uInt16 nPrefix,
120 const ::rtl::OUString& rLocalName,
121 const Reference< XAttributeList > & xAttrList )
123 SvXMLImportContext* pContext = OXMLTable::CreateChildContext(nPrefix, rLocalName,xAttrList );
124 if ( !pContext )
126 const SvXMLTokenMap& rTokenMap = GetOwnImport().GetQueryElemTokenMap();
128 switch( rTokenMap.Get( nPrefix, rLocalName ) )
130 case XML_TOK_UPDATE_TABLE:
132 GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
133 ::rtl::OUString s1;
134 fillAttributes(nPrefix, rLocalName,xAttrList,s1,m_sTable,m_sSchema,m_sCatalog);
136 break;
140 if( !pContext )
141 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
143 return pContext;
145 // -----------------------------------------------------------------------------
146 void OXMLQuery::setProperties(Reference< XPropertySet > & _xProp )
150 if ( _xProp.is() )
152 OXMLTable::setProperties(_xProp);
154 _xProp->setPropertyValue(PROPERTY_COMMAND,makeAny(m_sCommand));
155 _xProp->setPropertyValue(PROPERTY_ESCAPE_PROCESSING,makeAny(m_bEscapeProcessing));
157 if ( m_sTable.getLength() )
158 _xProp->setPropertyValue(PROPERTY_UPDATE_TABLENAME,makeAny(m_sTable));
159 if ( m_sCatalog.getLength() )
160 _xProp->setPropertyValue(PROPERTY_UPDATE_CATALOGNAME,makeAny(m_sCatalog));
161 if ( m_sSchema.getLength() )
162 _xProp->setPropertyValue(PROPERTY_UPDATE_SCHEMANAME,makeAny(m_sSchema));
164 const ODBFilter::TPropertyNameMap& rSettings = GetOwnImport().getQuerySettings();
165 ODBFilter::TPropertyNameMap::const_iterator aFind = rSettings.find(m_sName);
166 if ( aFind != rSettings.end() )
167 _xProp->setPropertyValue(PROPERTY_LAYOUTINFORMATION,makeAny(aFind->second));
170 catch(Exception&)
172 OSL_ENSURE(0,"OXMLTable::EndElement -> exception catched");
175 //----------------------------------------------------------------------------
176 } // namespace dbaxml
177 // -----------------------------------------------------------------------------