Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "xmlQuery.hxx"
21 : #include "xmlfilter.hxx"
22 : #include <xmloff/xmltoken.hxx>
23 : #include <xmloff/xmlnmspe.hxx>
24 : #include <xmloff/nmspmap.hxx>
25 : #include "xmlEnums.hxx"
26 : #include "xmlstrings.hrc"
27 : #include <com/sun/star/beans/PropertyValue.hpp>
28 : #include <com/sun/star/beans/XPropertySet.hpp>
29 : #include <com/sun/star/container/XNameContainer.hpp>
30 : #include <tools/debug.hxx>
31 :
32 : namespace dbaxml
33 : {
34 : using namespace ::com::sun::star::uno;
35 : using namespace ::com::sun::star::beans;
36 : using namespace ::com::sun::star::container;
37 : using namespace ::com::sun::star::xml::sax;
38 :
39 :
40 4 : OXMLQuery::OXMLQuery( ODBFilter& rImport
41 : ,sal_uInt16 nPrfx
42 : ,const OUString& _sLocalName
43 : ,const Reference< XAttributeList > & _xAttrList
44 : ,const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& _xParentContainer
45 : ) :
46 : OXMLTable( rImport, nPrfx, _sLocalName,_xAttrList,_xParentContainer, "com.sun.star.sdb.CommandDefinition" )
47 4 : ,m_bEscapeProcessing(true)
48 : {
49 :
50 : OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!");
51 4 : const SvXMLNamespaceMap& rMap = rImport.GetNamespaceMap();
52 4 : const SvXMLTokenMap& rTokenMap = rImport.GetQueryElemTokenMap();
53 :
54 4 : sal_Int16 nLength = (_xAttrList.is()) ? _xAttrList->getLength() : 0;
55 12 : for(sal_Int16 i = 0; i < nLength; ++i)
56 : {
57 8 : OUString sLocalName;
58 16 : OUString sAttrName = _xAttrList->getNameByIndex( i );
59 8 : sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
60 16 : OUString sValue = _xAttrList->getValueByIndex( i );
61 :
62 8 : switch( rTokenMap.Get( nPrefix, sLocalName ) )
63 : {
64 : case XML_TOK_COMMAND:
65 4 : m_sCommand = sValue;
66 4 : break;
67 : case XML_TOK_ESCAPE_PROCESSING:
68 0 : m_bEscapeProcessing = sValue == "true";
69 0 : break;
70 : }
71 8 : }
72 4 : }
73 :
74 8 : OXMLQuery::~OXMLQuery()
75 : {
76 :
77 8 : }
78 :
79 0 : SvXMLImportContext* OXMLQuery::CreateChildContext(
80 : sal_uInt16 nPrefix,
81 : const OUString& rLocalName,
82 : const Reference< XAttributeList > & xAttrList )
83 : {
84 0 : SvXMLImportContext* pContext = OXMLTable::CreateChildContext(nPrefix, rLocalName,xAttrList );
85 0 : if ( !pContext )
86 : {
87 0 : const SvXMLTokenMap& rTokenMap = GetOwnImport().GetQueryElemTokenMap();
88 :
89 0 : switch( rTokenMap.Get( nPrefix, rLocalName ) )
90 : {
91 : case XML_TOK_UPDATE_TABLE:
92 : {
93 0 : GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
94 0 : OUString s1;
95 0 : fillAttributes(nPrefix, rLocalName,xAttrList,s1,m_sTable,m_sSchema,m_sCatalog);
96 : }
97 0 : break;
98 : }
99 : }
100 :
101 0 : if( !pContext )
102 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
103 :
104 0 : return pContext;
105 : }
106 :
107 4 : void OXMLQuery::setProperties(Reference< XPropertySet > & _xProp )
108 : {
109 : try
110 : {
111 4 : if ( _xProp.is() )
112 : {
113 4 : OXMLTable::setProperties(_xProp);
114 :
115 4 : _xProp->setPropertyValue(PROPERTY_COMMAND,makeAny(m_sCommand));
116 4 : _xProp->setPropertyValue(PROPERTY_ESCAPE_PROCESSING,makeAny(m_bEscapeProcessing));
117 :
118 4 : if ( !m_sTable.isEmpty() )
119 0 : _xProp->setPropertyValue(PROPERTY_UPDATE_TABLENAME,makeAny(m_sTable));
120 4 : if ( !m_sCatalog.isEmpty() )
121 0 : _xProp->setPropertyValue(PROPERTY_UPDATE_CATALOGNAME,makeAny(m_sCatalog));
122 4 : if ( !m_sSchema.isEmpty() )
123 0 : _xProp->setPropertyValue(PROPERTY_UPDATE_SCHEMANAME,makeAny(m_sSchema));
124 :
125 4 : const ODBFilter::TPropertyNameMap& rSettings = GetOwnImport().getQuerySettings();
126 4 : ODBFilter::TPropertyNameMap::const_iterator aFind = rSettings.find(m_sName);
127 4 : if ( aFind != rSettings.end() )
128 0 : _xProp->setPropertyValue(PROPERTY_LAYOUTINFORMATION,makeAny(aFind->second));
129 : }
130 : }
131 0 : catch(Exception&)
132 : {
133 : OSL_FAIL("OXMLTable::EndElement -> exception catched");
134 : }
135 4 : }
136 :
137 : } // namespace dbaxml
138 :
139 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|