1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <strings.hxx>
24 #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
25 #include <com/sun/star/sdbcx/XAppend.hpp>
26 #include "xmlStyleImport.hxx"
27 #include <osl/diagnose.h>
28 #include <sal/log.hxx>
32 using namespace ::com::sun::star::uno
;
33 using namespace ::com::sun::star::beans
;
34 using namespace ::com::sun::star::sdbcx
;
35 using namespace ::com::sun::star::container
;
36 using namespace ::com::sun::star::xml::sax
;
38 OXMLColumn::OXMLColumn( ODBFilter
& rImport
39 ,const Reference
< XFastAttributeList
> & _xAttrList
40 ,const Reference
< XNameAccess
>& _xParentContainer
41 ,const Reference
< XPropertySet
>& _xTable
43 SvXMLImportContext( rImport
)
44 ,m_xParentContainer(_xParentContainer
)
49 for (auto &aIter
: sax_fastparser::castToFastAttributeList( _xAttrList
))
51 OUString sValue
= aIter
.toString();
53 switch( aIter
.getToken() & TOKEN_MASK
)
59 m_sStyleName
= sValue
;
61 case XML_HELP_MESSAGE
:
62 m_sHelpMessage
= sValue
;
65 m_bHidden
= sValue
!= "visible";
69 OSL_ENSURE(!sType
.isEmpty(),"No type name set");
71 case XML_DEFAULT_VALUE
:
72 if ( !(sValue
.isEmpty() || sType
.isEmpty()) )
73 m_aDefaultValue
<<= sValue
;
76 m_bHidden
= sValue
== "false";
78 case XML_DEFAULT_CELL_STYLE_NAME
:
79 m_sCellStyleName
= sValue
;
82 XMLOFF_WARN_UNKNOWN_ATTR("dbaccess", aIter
.getToken(), aIter
.toString());
87 OXMLColumn::~OXMLColumn()
92 void OXMLColumn::endFastElement(sal_Int32
)
94 Reference
<XDataDescriptorFactory
> xFac(m_xParentContainer
,UNO_QUERY
);
95 if ( xFac
.is() && !m_sName
.isEmpty() )
97 Reference
<XPropertySet
> xProp(xFac
->createDataDescriptor());
100 xProp
->setPropertyValue(PROPERTY_NAME
,makeAny(m_sName
));
101 xProp
->setPropertyValue(PROPERTY_HIDDEN
,makeAny(m_bHidden
));
102 if ( !m_sHelpMessage
.isEmpty() )
103 xProp
->setPropertyValue(PROPERTY_HELPTEXT
,makeAny(m_sHelpMessage
));
105 if ( m_aDefaultValue
.hasValue() )
106 xProp
->setPropertyValue(PROPERTY_CONTROLDEFAULT
,m_aDefaultValue
);
108 Reference
<XAppend
> xAppend(m_xParentContainer
,UNO_QUERY
);
110 xAppend
->appendByDescriptor(xProp
);
111 m_xParentContainer
->getByName(m_sName
) >>= xProp
;
113 if ( !m_sStyleName
.isEmpty() )
115 const SvXMLStylesContext
* pAutoStyles
= GetOwnImport().GetAutoStyles();
118 OTableStyleContext
* pAutoStyle
= const_cast<OTableStyleContext
*>(
119 dynamic_cast< const OTableStyleContext
* >(pAutoStyles
->FindStyleChildContext(XmlStyleFamily::TABLE_COLUMN
,m_sStyleName
)));
122 pAutoStyle
->FillPropertySet(xProp
);
126 if ( !m_sCellStyleName
.isEmpty() )
128 const SvXMLStylesContext
* pAutoStyles
= GetOwnImport().GetAutoStyles();
131 OTableStyleContext
* pAutoStyle
= const_cast<OTableStyleContext
*>(dynamic_cast<const OTableStyleContext
* >(pAutoStyles
->FindStyleChildContext(XmlStyleFamily::TABLE_CELL
,m_sCellStyleName
)));
134 pAutoStyle
->FillPropertySet(xProp
);
135 // we also have to do this on the table to import text-properties
136 pAutoStyle
->FillPropertySet(m_xTable
);
143 else if ( !m_sCellStyleName
.isEmpty() )
145 const SvXMLStylesContext
* pAutoStyles
= GetOwnImport().GetAutoStyles();
148 OTableStyleContext
* pAutoStyle
= const_cast<OTableStyleContext
*>(dynamic_cast< const OTableStyleContext
* >(pAutoStyles
->FindStyleChildContext(XmlStyleFamily::TABLE_CELL
,m_sCellStyleName
)));
151 // we also have to do this on the table to import text-properties
152 pAutoStyle
->FillPropertySet(m_xTable
);
158 ODBFilter
& OXMLColumn::GetOwnImport()
160 return static_cast<ODBFilter
&>(GetImport());
163 } // namespace dbaxml
165 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */