1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmlColumn.cxx,v $
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"
36 #ifndef DBA_XMLFILTER_HXX
37 #include "xmlfilter.hxx"
39 #ifndef _XMLOFF_XMLTOKEN_HXX
40 #include <xmloff/xmltoken.hxx>
42 #ifndef _XMLOFF_XMLUCONV_HXX
43 #include <xmloff/xmluconv.hxx>
45 #ifndef _XMLOFF_XMLNMSPE_HXX
46 #include <xmloff/xmlnmspe.hxx>
48 #ifndef _XMLOFF_NMSPMAP_HXX
49 #include <xmloff/nmspmap.hxx>
51 #ifndef DBA_XMLENUMS_HXX
52 #include "xmlEnums.hxx"
54 #ifndef DBACCESS_SHARED_XMLSTRINGS_HRC
55 #include "xmlstrings.hrc"
57 #ifndef _COM_SUN_STAR_SDBCX_XDATADESCRIPTORFACTORY_HPP_
58 #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
60 #ifndef _COM_SUN_STAR_SDBCX_XAPPEND_HPP_
61 #include <com/sun/star/sdbcx/XAppend.hpp>
63 #ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_
64 #include <com/sun/star/beans/PropertyValue.hpp>
66 #ifndef _COM_SUN_STAR_CONTAINER_XNAMECONTAINER_HPP_
67 #include <com/sun/star/container/XNameContainer.hpp>
69 #include <com/sun/star/container/XChild.hpp>
70 #ifndef DBA_XMLSTYLEIMPORT_HXX
71 #include "xmlStyleImport.hxx"
73 #ifndef _TOOLS_DEBUG_HXX
74 #include <tools/debug.hxx>
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
;
86 OXMLColumn::OXMLColumn( ODBFilter
& rImport
88 ,const ::rtl::OUString
& _sLocalName
89 ,const Reference
< XAttributeList
> & _xAttrList
90 ,const Reference
< XNameAccess
>& _xParentContainer
91 ,const Reference
< XPropertySet
>& _xTable
93 SvXMLImportContext( rImport
, nPrfx
, _sLocalName
)
94 ,m_xParentContainer(_xParentContainer
)
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
:
118 case XML_TOK_COLUMN_STYLE_NAME
:
119 m_sStyleName
= sValue
;
121 case XML_TOK_COLUMN_HELP_MESSAGE
:
122 m_sHelpMessage
= sValue
;
124 case XML_TOK_COLUMN_VISIBILITY
:
125 m_bHidden
= !sValue
.equalsAscii("visible");
127 case XML_TOK_COLUMN_TYPE_NAME
:
129 OSL_ENSURE(sType
.getLength(),"No type name set");
131 case XML_TOK_COLUMN_DEFAULT_VALUE
:
132 if ( sValue
.getLength() && sType
.getLength() )
133 SvXMLUnitConverter::convertAny(m_aDefaultValue
,sType
,sValue
);
135 case XML_TOK_COLUMN_VISIBLE
:
136 m_bHidden
= sValue
.equalsAscii("false");
138 case XML_TOK_DEFAULT_CELL_STYLE_NAME
:
139 m_sCellStyleName
= sValue
;
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());
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
);
170 xAppend
->appendByDescriptor(xProp
);
171 m_xParentContainer
->getByName(m_sName
) >>= xProp
;
173 if ( m_sStyleName
.getLength() )
175 const SvXMLStylesContext
* pAutoStyles
= GetOwnImport().GetAutoStyles();
178 OTableStyleContext
* pAutoStyle
= PTR_CAST(OTableStyleContext
,pAutoStyles
->FindStyleChildContext(XML_STYLE_FAMILY_TABLE_COLUMN
,m_sStyleName
));
181 pAutoStyle
->FillPropertySet(xProp
);
184 } // if ( m_sStyleName.getLength() )
185 if ( m_sCellStyleName
.getLength() )
187 const SvXMLStylesContext
* pAutoStyles
= GetOwnImport().GetAutoStyles();
190 OTableStyleContext
* pAutoStyle
= PTR_CAST(OTableStyleContext
,pAutoStyles
->FindStyleChildContext(XML_STYLE_FAMILY_TABLE_CELL
,m_sCellStyleName
));
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();
207 OTableStyleContext
* pAutoStyle
= PTR_CAST(OTableStyleContext
,pAutoStyles
->FindStyleChildContext(XML_STYLE_FAMILY_TABLE_CELL
,m_sCellStyleName
));
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 // -----------------------------------------------------------------------------