xref: /AOO41X/main/dbaccess/source/filter/xml/xmlColumn.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_XMLCOLUMN_HXX
27 #include "xmlColumn.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_XMLUCONV_HXX
36 #include <xmloff/xmluconv.hxx>
37 #endif
38 #ifndef _XMLOFF_XMLNMSPE_HXX
39 #include <xmloff/xmlnmspe.hxx>
40 #endif
41 #ifndef _XMLOFF_NMSPMAP_HXX
42 #include <xmloff/nmspmap.hxx>
43 #endif
44 #ifndef DBA_XMLENUMS_HXX
45 #include "xmlEnums.hxx"
46 #endif
47 #ifndef DBACCESS_SHARED_XMLSTRINGS_HRC
48 #include "xmlstrings.hrc"
49 #endif
50 #ifndef _COM_SUN_STAR_SDBCX_XDATADESCRIPTORFACTORY_HPP_
51 #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
52 #endif
53 #ifndef _COM_SUN_STAR_SDBCX_XAPPEND_HPP_
54 #include <com/sun/star/sdbcx/XAppend.hpp>
55 #endif
56 #ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_
57 #include <com/sun/star/beans/PropertyValue.hpp>
58 #endif
59 #ifndef _COM_SUN_STAR_CONTAINER_XNAMECONTAINER_HPP_
60 #include <com/sun/star/container/XNameContainer.hpp>
61 #endif
62 #include <com/sun/star/container/XChild.hpp>
63 #ifndef DBA_XMLSTYLEIMPORT_HXX
64 #include "xmlStyleImport.hxx"
65 #endif
66 #ifndef _TOOLS_DEBUG_HXX
67 #include <tools/debug.hxx>
68 #endif
69 
70 namespace dbaxml
71 {
72     using namespace ::com::sun::star::uno;
73     using namespace ::com::sun::star::beans;
74     using namespace ::com::sun::star::sdbcx;
75     using namespace ::com::sun::star::container;
76     using namespace ::com::sun::star::xml::sax;
DBG_NAME(OXMLColumn)77 DBG_NAME(OXMLColumn)
78 
79 OXMLColumn::OXMLColumn( ODBFilter& rImport
80                 ,sal_uInt16 nPrfx
81                 ,const ::rtl::OUString& _sLocalName
82                 ,const Reference< XAttributeList > & _xAttrList
83                 ,const Reference< XNameAccess >& _xParentContainer
84                 ,const Reference< XPropertySet >& _xTable
85                 ) :
86     SvXMLImportContext( rImport, nPrfx, _sLocalName )
87     ,m_xParentContainer(_xParentContainer)
88     ,m_xTable(_xTable)
89     ,m_bHidden(sal_False)
90 {
91     DBG_CTOR(OXMLColumn,NULL);
92 
93     OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!");
94     const SvXMLNamespaceMap& rMap = rImport.GetNamespaceMap();
95     const SvXMLTokenMap& rTokenMap = rImport.GetColumnElemTokenMap();
96 
97     sal_Int16 nLength = (_xAttrList.is()) ? _xAttrList->getLength() : 0;
98     ::rtl::OUString sType;
99     for(sal_Int16 i = 0; i < nLength; ++i)
100     {
101         ::rtl::OUString sLocalName;
102         rtl::OUString sAttrName = _xAttrList->getNameByIndex( i );
103         sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
104         rtl::OUString sValue = _xAttrList->getValueByIndex( i );
105 
106         switch( rTokenMap.Get( nPrefix, sLocalName ) )
107         {
108             case XML_TOK_COLUMN_NAME:
109                 m_sName = sValue;
110                 break;
111             case XML_TOK_COLUMN_STYLE_NAME:
112                 m_sStyleName = sValue;
113                 break;
114             case XML_TOK_COLUMN_HELP_MESSAGE:
115                 m_sHelpMessage = sValue;
116                 break;
117             case XML_TOK_COLUMN_VISIBILITY:
118                 m_bHidden = !sValue.equalsAscii("visible");
119                 break;
120             case XML_TOK_COLUMN_TYPE_NAME:
121                 sType = sValue;
122                 OSL_ENSURE(sType.getLength(),"No type name set");
123                 break;
124             case XML_TOK_COLUMN_DEFAULT_VALUE:
125                 if ( sValue.getLength() && sType.getLength() )
126                     m_aDefaultValue <<= sValue;
127                 //    SvXMLUnitConverter::convertAny(m_aDefaultValue,sType,sValue);
128                 break;
129             case XML_TOK_COLUMN_VISIBLE:
130                 m_bHidden = sValue.equalsAscii("false");
131                 break;
132             case XML_TOK_DEFAULT_CELL_STYLE_NAME:
133                 m_sCellStyleName = sValue;
134                 break;
135         }
136     }
137 }
138 // -----------------------------------------------------------------------------
139 
~OXMLColumn()140 OXMLColumn::~OXMLColumn()
141 {
142 
143     DBG_DTOR(OXMLColumn,NULL);
144 }
145 // -----------------------------------------------------------------------------
EndElement()146 void OXMLColumn::EndElement()
147 {
148     Reference<XDataDescriptorFactory> xFac(m_xParentContainer,UNO_QUERY);
149     if ( xFac.is() && m_sName.getLength() )
150     {
151         Reference<XPropertySet> xProp(xFac->createDataDescriptor());
152         if ( xProp.is() )
153         {
154             xProp->setPropertyValue(PROPERTY_NAME,makeAny(m_sName));
155             xProp->setPropertyValue(PROPERTY_HIDDEN,makeAny(m_bHidden));
156             if ( m_sHelpMessage.getLength() )
157                 xProp->setPropertyValue(PROPERTY_HELPTEXT,makeAny(m_sHelpMessage));
158 
159             if ( m_aDefaultValue.hasValue() )
160                 xProp->setPropertyValue(PROPERTY_CONTROLDEFAULT,m_aDefaultValue);
161 
162             Reference<XAppend> xAppend(m_xParentContainer,UNO_QUERY);
163             if ( xAppend.is() )
164                 xAppend->appendByDescriptor(xProp);
165             m_xParentContainer->getByName(m_sName) >>= xProp;
166 
167             if ( m_sStyleName.getLength() )
168             {
169                 const SvXMLStylesContext* pAutoStyles = GetOwnImport().GetAutoStyles();
170                 if ( pAutoStyles )
171                 {
172                     OTableStyleContext* pAutoStyle = PTR_CAST(OTableStyleContext,pAutoStyles->FindStyleChildContext(XML_STYLE_FAMILY_TABLE_COLUMN,m_sStyleName));
173                     if ( pAutoStyle )
174                     {
175                         pAutoStyle->FillPropertySet(xProp);
176                     }
177                 }
178             } // if ( m_sStyleName.getLength() )
179             if ( m_sCellStyleName.getLength() )
180             {
181                 const SvXMLStylesContext* pAutoStyles = GetOwnImport().GetAutoStyles();
182                 if ( pAutoStyles )
183                 {
184                     OTableStyleContext* pAutoStyle = PTR_CAST(OTableStyleContext,pAutoStyles->FindStyleChildContext(XML_STYLE_FAMILY_TABLE_CELL,m_sCellStyleName));
185                     if ( pAutoStyle )
186                     {
187                         pAutoStyle->FillPropertySet(xProp);
188                         // we also have to do this on the table to import text-properties
189                         pAutoStyle->FillPropertySet(m_xTable);
190                     }
191                 }
192             }
193 
194         }
195     } // if ( xFac.is() && m_sName.getLength() )
196     else if ( m_sCellStyleName.getLength() )
197     {
198         const SvXMLStylesContext* pAutoStyles = GetOwnImport().GetAutoStyles();
199         if ( pAutoStyles )
200         {
201             OTableStyleContext* pAutoStyle = PTR_CAST(OTableStyleContext,pAutoStyles->FindStyleChildContext(XML_STYLE_FAMILY_TABLE_CELL,m_sCellStyleName));
202             if ( pAutoStyle )
203             {
204                 // we also have to do this on the table to import text-properties
205                 pAutoStyle->FillPropertySet(m_xTable);
206             }
207         }
208     }
209 }
210 // -----------------------------------------------------------------------------
GetOwnImport()211 ODBFilter& OXMLColumn::GetOwnImport()
212 {
213     return static_cast<ODBFilter&>(GetImport());
214 }
215 //----------------------------------------------------------------------------
216 } // namespace dbaxml
217 // -----------------------------------------------------------------------------
218