xref: /AOO41X/main/dbaccess/source/filter/xml/xmlQuery.cxx (revision 96de54900b79e13b861fbc62cbf36018b54e21b7) !
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 #ifndef DBA_XMLQUERY_HXX
27 #include "xmlQuery.hxx"
28 #endif
29 #ifndef DBA_XMLFILTER_HXX
30 #include "xmlfilter.hxx"
31 #endif
32 #ifndef _XMLOFF_XMLTOKEN_HXX
33 #include <xmloff/xmltoken.hxx>
34 #endif
35 #ifndef _XMLOFF_XMLNMSPE_HXX
36 #include <xmloff/xmlnmspe.hxx>
37 #endif
38 #ifndef _XMLOFF_NMSPMAP_HXX
39 #include <xmloff/nmspmap.hxx>
40 #endif
41 #ifndef DBA_XMLENUMS_HXX
42 #include "xmlEnums.hxx"
43 #endif
44 #ifndef DBACCESS_SHARED_XMLSTRINGS_HRC
45 #include "xmlstrings.hrc"
46 #endif
47 #ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_
48 #include <com/sun/star/beans/PropertyValue.hpp>
49 #endif
50 #ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
51 #include <com/sun/star/beans/XPropertySet.hpp>
52 #endif
53 #ifndef _COM_SUN_STAR_CONTAINER_XNAMECONTAINER_HPP_
54 #include <com/sun/star/container/XNameContainer.hpp>
55 #endif
56 #ifndef _TOOLS_DEBUG_HXX
57 #include <tools/debug.hxx>
58 #endif
59 
60 namespace dbaxml
61 {
62     using namespace ::com::sun::star::uno;
63     using namespace ::com::sun::star::beans;
64     using namespace ::com::sun::star::container;
65     using namespace ::com::sun::star::xml::sax;
66 
DBG_NAME(OXMLQuery)67 DBG_NAME(OXMLQuery)
68 
69 OXMLQuery::OXMLQuery( ODBFilter& rImport
70                 ,sal_uInt16 nPrfx
71                 ,const ::rtl::OUString& _sLocalName
72                 ,const Reference< XAttributeList > & _xAttrList
73                 ,const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& _xParentContainer
74                 ) :
75     OXMLTable( rImport, nPrfx, _sLocalName,_xAttrList,_xParentContainer,SERVICE_SDB_COMMAND_DEFINITION )
76         ,m_bEscapeProcessing(sal_True)
77 {
78     DBG_CTOR(OXMLQuery,NULL);
79 
80     OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!");
81     const SvXMLNamespaceMap& rMap = rImport.GetNamespaceMap();
82     const SvXMLTokenMap& rTokenMap = rImport.GetQueryElemTokenMap();
83 
84     sal_Int16 nLength = (_xAttrList.is()) ? _xAttrList->getLength() : 0;
85     for(sal_Int16 i = 0; i < nLength; ++i)
86     {
87         ::rtl::OUString sLocalName;
88         rtl::OUString sAttrName = _xAttrList->getNameByIndex( i );
89         sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
90         rtl::OUString sValue = _xAttrList->getValueByIndex( i );
91 
92         switch( rTokenMap.Get( nPrefix, sLocalName ) )
93         {
94             case XML_TOK_COMMAND:
95                 m_sCommand = sValue;
96                 break;
97             case XML_TOK_ESCAPE_PROCESSING:
98                 m_bEscapeProcessing = sValue.equalsAscii("true");
99                 break;
100         }
101     }
102 }
103 // -----------------------------------------------------------------------------
104 
~OXMLQuery()105 OXMLQuery::~OXMLQuery()
106 {
107 
108     DBG_DTOR(OXMLQuery,NULL);
109 }
110 // -----------------------------------------------------------------------------
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLocalName,const Reference<XAttributeList> & xAttrList)111 SvXMLImportContext* OXMLQuery::CreateChildContext(
112         sal_uInt16 nPrefix,
113         const ::rtl::OUString& rLocalName,
114         const Reference< XAttributeList > & xAttrList )
115 {
116     SvXMLImportContext* pContext = OXMLTable::CreateChildContext(nPrefix, rLocalName,xAttrList );
117     if ( !pContext )
118     {
119         const SvXMLTokenMap& rTokenMap = GetOwnImport().GetQueryElemTokenMap();
120 
121         switch( rTokenMap.Get( nPrefix, rLocalName ) )
122         {
123             case XML_TOK_UPDATE_TABLE:
124                 {
125                     GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
126                     ::rtl::OUString s1;
127                     fillAttributes(nPrefix, rLocalName,xAttrList,s1,m_sTable,m_sSchema,m_sCatalog);
128                 }
129                 break;
130         }
131     }
132 
133     if( !pContext )
134         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
135 
136     return pContext;
137 }
138 // -----------------------------------------------------------------------------
setProperties(Reference<XPropertySet> & _xProp)139 void OXMLQuery::setProperties(Reference< XPropertySet > & _xProp )
140 {
141     try
142     {
143         if ( _xProp.is() )
144         {
145             OXMLTable::setProperties(_xProp);
146 
147             _xProp->setPropertyValue(PROPERTY_COMMAND,makeAny(m_sCommand));
148             _xProp->setPropertyValue(PROPERTY_ESCAPE_PROCESSING,makeAny(m_bEscapeProcessing));
149 
150             if ( m_sTable.getLength() )
151                 _xProp->setPropertyValue(PROPERTY_UPDATE_TABLENAME,makeAny(m_sTable));
152             if ( m_sCatalog.getLength() )
153                 _xProp->setPropertyValue(PROPERTY_UPDATE_CATALOGNAME,makeAny(m_sCatalog));
154             if ( m_sSchema.getLength() )
155                 _xProp->setPropertyValue(PROPERTY_UPDATE_SCHEMANAME,makeAny(m_sSchema));
156 
157             const ODBFilter::TPropertyNameMap& rSettings = GetOwnImport().getQuerySettings();
158             ODBFilter::TPropertyNameMap::const_iterator aFind = rSettings.find(m_sName);
159             if ( aFind != rSettings.end() )
160                 _xProp->setPropertyValue(PROPERTY_LAYOUTINFORMATION,makeAny(aFind->second));
161         }
162     }
163     catch(Exception&)
164     {
165         OSL_ENSURE(0,"OXMLTable::EndElement -> exception catched");
166     }
167 }
168 //----------------------------------------------------------------------------
169 } // namespace dbaxml
170 // -----------------------------------------------------------------------------
171