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>
31 using namespace ::com::sun::star::uno
;
32 using namespace ::com::sun::star::beans
;
33 using namespace ::com::sun::star::sdbcx
;
34 using namespace ::com::sun::star::container
;
35 using namespace ::com::sun::star::xml::sax
;
37 OXMLColumn::OXMLColumn( ODBFilter
& rImport
38 ,const Reference
< XFastAttributeList
> & _xAttrList
39 ,const Reference
< XNameAccess
>& _xParentContainer
40 ,const Reference
< XPropertySet
>& _xTable
42 SvXMLImportContext( rImport
)
43 ,m_xParentContainer(_xParentContainer
)
48 for (auto &aIter
: sax_fastparser::castToFastAttributeList( _xAttrList
))
50 switch( aIter
.getToken() & TOKEN_MASK
)
53 m_sName
= aIter
.toString();
56 m_sStyleName
= aIter
.toString();
58 case XML_HELP_MESSAGE
:
59 m_sHelpMessage
= aIter
.toString();
62 m_bHidden
= aIter
.toView() != "visible";
65 sType
= aIter
.toString();
66 OSL_ENSURE(!sType
.isEmpty(),"No type name set");
68 case XML_DEFAULT_VALUE
:
69 if ( !(aIter
.isEmpty() || sType
.isEmpty()) )
70 m_aDefaultValue
<<= aIter
.toString();
73 m_bHidden
= aIter
.toView() == "false";
75 case XML_DEFAULT_CELL_STYLE_NAME
:
76 m_sCellStyleName
= aIter
.toString();
79 XMLOFF_WARN_UNKNOWN("dbaccess", aIter
);
84 OXMLColumn::~OXMLColumn()
89 void OXMLColumn::endFastElement(sal_Int32
)
91 Reference
<XDataDescriptorFactory
> xFac(m_xParentContainer
,UNO_QUERY
);
92 if ( xFac
.is() && !m_sName
.isEmpty() )
94 Reference
<XPropertySet
> xProp(xFac
->createDataDescriptor());
97 xProp
->setPropertyValue(PROPERTY_NAME
,Any(m_sName
));
98 xProp
->setPropertyValue(PROPERTY_HIDDEN
,Any(m_bHidden
));
99 if ( !m_sHelpMessage
.isEmpty() )
100 xProp
->setPropertyValue(PROPERTY_HELPTEXT
,Any(m_sHelpMessage
));
102 if ( m_aDefaultValue
.hasValue() )
103 xProp
->setPropertyValue(PROPERTY_CONTROLDEFAULT
,m_aDefaultValue
);
105 Reference
<XAppend
> xAppend(m_xParentContainer
,UNO_QUERY
);
107 xAppend
->appendByDescriptor(xProp
);
108 m_xParentContainer
->getByName(m_sName
) >>= xProp
;
110 if ( !m_sStyleName
.isEmpty() )
112 const SvXMLStylesContext
* pAutoStyles
= GetOwnImport().GetAutoStyles();
115 OTableStyleContext
* pAutoStyle
= const_cast<OTableStyleContext
*>(
116 dynamic_cast< const OTableStyleContext
* >(pAutoStyles
->FindStyleChildContext(XmlStyleFamily::TABLE_COLUMN
,m_sStyleName
)));
119 pAutoStyle
->FillPropertySet(xProp
);
123 if ( !m_sCellStyleName
.isEmpty() )
125 const SvXMLStylesContext
* pAutoStyles
= GetOwnImport().GetAutoStyles();
128 OTableStyleContext
* pAutoStyle
= const_cast<OTableStyleContext
*>(dynamic_cast<const OTableStyleContext
* >(pAutoStyles
->FindStyleChildContext(XmlStyleFamily::TABLE_CELL
,m_sCellStyleName
)));
131 pAutoStyle
->FillPropertySet(xProp
);
132 // we also have to do this on the table to import text-properties
133 pAutoStyle
->FillPropertySet(m_xTable
);
140 else if ( !m_sCellStyleName
.isEmpty() )
142 const SvXMLStylesContext
* pAutoStyles
= GetOwnImport().GetAutoStyles();
145 OTableStyleContext
* pAutoStyle
= const_cast<OTableStyleContext
*>(dynamic_cast< const OTableStyleContext
* >(pAutoStyles
->FindStyleChildContext(XmlStyleFamily::TABLE_CELL
,m_sCellStyleName
)));
148 // we also have to do this on the table to import text-properties
149 pAutoStyle
->FillPropertySet(m_xTable
);
155 ODBFilter
& OXMLColumn::GetOwnImport()
157 return static_cast<ODBFilter
&>(GetImport());
160 } // namespace dbaxml
162 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */