Version 4.0.2.1, tag libreoffice-4.0.2.1
[LibreOffice.git] / dbaccess / source / filter / xml / xmlColumn.cxx
blobf5939174b184f6ef27a7f5aede1b1c0cb3c511fa
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "xmlColumn.hxx"
21 #include "xmlfilter.hxx"
22 #include <xmloff/xmltoken.hxx>
23 #include <xmloff/xmluconv.hxx>
24 #include <xmloff/xmlnmspe.hxx>
25 #include <xmloff/nmspmap.hxx>
26 #include "xmlEnums.hxx"
27 #include "xmlstrings.hrc"
28 #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
29 #include <com/sun/star/sdbcx/XAppend.hpp>
30 #include <com/sun/star/beans/PropertyValue.hpp>
31 #include <com/sun/star/container/XNameContainer.hpp>
32 #include <com/sun/star/container/XChild.hpp>
33 #include "xmlStyleImport.hxx"
34 #include <tools/debug.hxx>
36 namespace dbaxml
38 using namespace ::com::sun::star::uno;
39 using namespace ::com::sun::star::beans;
40 using namespace ::com::sun::star::sdbcx;
41 using namespace ::com::sun::star::container;
42 using namespace ::com::sun::star::xml::sax;
43 DBG_NAME(OXMLColumn)
45 OXMLColumn::OXMLColumn( ODBFilter& rImport
46 ,sal_uInt16 nPrfx
47 ,const ::rtl::OUString& _sLocalName
48 ,const Reference< XAttributeList > & _xAttrList
49 ,const Reference< XNameAccess >& _xParentContainer
50 ,const Reference< XPropertySet >& _xTable
51 ) :
52 SvXMLImportContext( rImport, nPrfx, _sLocalName )
53 ,m_xParentContainer(_xParentContainer)
54 ,m_xTable(_xTable)
55 ,m_bHidden(sal_False)
57 DBG_CTOR(OXMLColumn,NULL);
59 OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!");
60 const SvXMLNamespaceMap& rMap = rImport.GetNamespaceMap();
61 const SvXMLTokenMap& rTokenMap = rImport.GetColumnElemTokenMap();
63 sal_Int16 nLength = (_xAttrList.is()) ? _xAttrList->getLength() : 0;
64 ::rtl::OUString sType;
65 for(sal_Int16 i = 0; i < nLength; ++i)
67 ::rtl::OUString sLocalName;
68 rtl::OUString sAttrName = _xAttrList->getNameByIndex( i );
69 sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
70 rtl::OUString sValue = _xAttrList->getValueByIndex( i );
72 switch( rTokenMap.Get( nPrefix, sLocalName ) )
74 case XML_TOK_COLUMN_NAME:
75 m_sName = sValue;
76 break;
77 case XML_TOK_COLUMN_STYLE_NAME:
78 m_sStyleName = sValue;
79 break;
80 case XML_TOK_COLUMN_HELP_MESSAGE:
81 m_sHelpMessage = sValue;
82 break;
83 case XML_TOK_COLUMN_VISIBILITY:
84 m_bHidden = sValue != "visible";
85 break;
86 case XML_TOK_COLUMN_TYPE_NAME:
87 sType = sValue;
88 OSL_ENSURE(!sType.isEmpty(),"No type name set");
89 break;
90 case XML_TOK_COLUMN_DEFAULT_VALUE:
91 if ( !(sValue.isEmpty() || sType.isEmpty()) )
92 m_aDefaultValue <<= sValue;
93 break;
94 case XML_TOK_COLUMN_VISIBLE:
95 m_bHidden = sValue == "false";
96 break;
97 case XML_TOK_DEFAULT_CELL_STYLE_NAME:
98 m_sCellStyleName = sValue;
99 break;
103 // -----------------------------------------------------------------------------
105 OXMLColumn::~OXMLColumn()
108 DBG_DTOR(OXMLColumn,NULL);
110 // -----------------------------------------------------------------------------
111 void OXMLColumn::EndElement()
113 Reference<XDataDescriptorFactory> xFac(m_xParentContainer,UNO_QUERY);
114 if ( xFac.is() && !m_sName.isEmpty() )
116 Reference<XPropertySet> xProp(xFac->createDataDescriptor());
117 if ( xProp.is() )
119 xProp->setPropertyValue(PROPERTY_NAME,makeAny(m_sName));
120 xProp->setPropertyValue(PROPERTY_HIDDEN,makeAny(m_bHidden));
121 if ( !m_sHelpMessage.isEmpty() )
122 xProp->setPropertyValue(PROPERTY_HELPTEXT,makeAny(m_sHelpMessage));
124 if ( m_aDefaultValue.hasValue() )
125 xProp->setPropertyValue(PROPERTY_CONTROLDEFAULT,m_aDefaultValue);
127 Reference<XAppend> xAppend(m_xParentContainer,UNO_QUERY);
128 if ( xAppend.is() )
129 xAppend->appendByDescriptor(xProp);
130 m_xParentContainer->getByName(m_sName) >>= xProp;
132 if ( !m_sStyleName.isEmpty() )
134 const SvXMLStylesContext* pAutoStyles = GetOwnImport().GetAutoStyles();
135 if ( pAutoStyles )
137 OTableStyleContext* pAutoStyle = PTR_CAST(OTableStyleContext,pAutoStyles->FindStyleChildContext(XML_STYLE_FAMILY_TABLE_COLUMN,m_sStyleName));
138 if ( pAutoStyle )
140 pAutoStyle->FillPropertySet(xProp);
144 if ( !m_sCellStyleName.isEmpty() )
146 const SvXMLStylesContext* pAutoStyles = GetOwnImport().GetAutoStyles();
147 if ( pAutoStyles )
149 OTableStyleContext* pAutoStyle = PTR_CAST(OTableStyleContext,pAutoStyles->FindStyleChildContext(XML_STYLE_FAMILY_TABLE_CELL,m_sCellStyleName));
150 if ( pAutoStyle )
152 pAutoStyle->FillPropertySet(xProp);
153 // we also have to do this on the table to import text-properties
154 pAutoStyle->FillPropertySet(m_xTable);
161 else if ( !m_sCellStyleName.isEmpty() )
163 const SvXMLStylesContext* pAutoStyles = GetOwnImport().GetAutoStyles();
164 if ( pAutoStyles )
166 OTableStyleContext* pAutoStyle = PTR_CAST(OTableStyleContext,pAutoStyles->FindStyleChildContext(XML_STYLE_FAMILY_TABLE_CELL,m_sCellStyleName));
167 if ( pAutoStyle )
169 // we also have to do this on the table to import text-properties
170 pAutoStyle->FillPropertySet(m_xTable);
175 // -----------------------------------------------------------------------------
176 ODBFilter& OXMLColumn::GetOwnImport()
178 return static_cast<ODBFilter&>(GetImport());
180 //----------------------------------------------------------------------------
181 } // namespace dbaxml
182 // -----------------------------------------------------------------------------
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */