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