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_XMLCONNECTIONRESOURCE_HXX_INCLUDED
27 #include "xmlConnectionResource.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 _TOOLS_DEBUG_HXX
48 #include <tools/debug.hxx>
49 #endif
50 #ifndef TOOLS_DIAGNOSE_EX_H
51 #include <tools/diagnose_ex.h>
52 #endif
53 
54 namespace dbaxml
55 {
56 	using namespace ::com::sun::star::uno;
57 	using namespace ::com::sun::star::xml::sax;
DBG_NAME(OXMLConnectionResource)58 DBG_NAME(OXMLConnectionResource)
59 
60 OXMLConnectionResource::OXMLConnectionResource( ODBFilter& rImport,
61 				sal_uInt16 nPrfx, const ::rtl::OUString& _sLocalName,
62 				const Reference< XAttributeList > & _xAttrList) :
63 	SvXMLImportContext( rImport, nPrfx, _sLocalName )
64 {
65     DBG_CTOR(OXMLConnectionResource,NULL);
66 
67 	OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!");
68 	const SvXMLNamespaceMap& rMap = rImport.GetNamespaceMap();
69 	const SvXMLTokenMap& rTokenMap = rImport.GetComponentElemTokenMap();
70 
71 	Reference<XPropertySet> xDataSource = rImport.getDataSource();
72 
73 	PropertyValue aProperty;
74 
75 	const sal_Int16 nLength = (xDataSource.is() && _xAttrList.is()) ? _xAttrList->getLength() : 0;
76 	for(sal_Int16 i = 0; i < nLength; ++i)
77 	{
78 		::rtl::OUString sLocalName;
79 		const rtl::OUString sAttrName = _xAttrList->getNameByIndex( i );
80 		const sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
81 		const rtl::OUString sValue = _xAttrList->getValueByIndex( i );
82 
83 		aProperty.Name = ::rtl::OUString();
84 		aProperty.Value = Any();
85 
86 		switch( rTokenMap.Get( nPrefix, sLocalName ) )
87 		{
88 			case XML_TOK_HREF:
89                 try
90 				{
91 					xDataSource->setPropertyValue(PROPERTY_URL,makeAny(sValue));
92 				}
93 				catch(Exception)
94 				{
95                     DBG_UNHANDLED_EXCEPTION();
96 				}
97 				break;
98 			case XML_TOK_TYPE:
99                 aProperty.Name = PROPERTY_TYPE;
100 				break;
101             case XML_TOK_SHOW:
102                 aProperty.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Show"));
103 				break;
104 			case XML_TOK_ACTUATE:
105                 aProperty.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Actuate"));
106 				break;
107 		}
108 		if ( aProperty.Name.getLength() )
109 		{
110 			if ( !aProperty.Value.hasValue() )
111 				aProperty.Value <<= sValue;
112 			rImport.addInfo(aProperty);
113 		}
114 	}
115 }
116 // -----------------------------------------------------------------------------
117 
~OXMLConnectionResource()118 OXMLConnectionResource::~OXMLConnectionResource()
119 {
120 
121     DBG_DTOR(OXMLConnectionResource,NULL);
122 }
123 // -----------------------------------------------------------------------------
124 //----------------------------------------------------------------------------
125 } // namespace dbaxml
126 // -----------------------------------------------------------------------------
127