LibreOffice Module dbaccess (master) 1
xmlColumn.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
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
29namespace dbaxml
30{
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;
36
38 ,const Reference< XFastAttributeList > & _xAttrList
39 ,const Reference< XNameAccess >& _xParentContainer
40 ,const Reference< XPropertySet >& _xTable
41 ) :
42 SvXMLImportContext( rImport )
43 ,m_xParentContainer(_xParentContainer)
44 ,m_xTable(_xTable)
45 ,m_bHidden(false)
46{
47 OUString sType;
48 for (auto &aIter : sax_fastparser::castToFastAttributeList( _xAttrList ))
49 {
50 switch( aIter.getToken() & TOKEN_MASK )
51 {
52 case XML_NAME:
53 m_sName = aIter.toString();
54 break;
55 case XML_STYLE_NAME:
56 m_sStyleName = aIter.toString();
57 break;
59 m_sHelpMessage = aIter.toString();
60 break;
61 case XML_VISIBILITY:
62 m_bHidden = aIter.toView() != "visible";
63 break;
64 case XML_TYPE_NAME:
65 sType = aIter.toString();
66 OSL_ENSURE(!sType.isEmpty(),"No type name set");
67 break;
69 if ( !(aIter.isEmpty() || sType.isEmpty()) )
70 m_aDefaultValue <<= aIter.toString();
71 break;
72 case XML_VISIBLE:
73 m_bHidden = aIter.toView() == "false";
74 break;
76 m_sCellStyleName = aIter.toString();
77 break;
78 default:
79 XMLOFF_WARN_UNKNOWN("dbaccess", aIter);
80 }
81 }
82}
83
85{
86
87}
88
90{
91 Reference<XDataDescriptorFactory> xFac(m_xParentContainer,UNO_QUERY);
92 if ( xFac.is() && !m_sName.isEmpty() )
93 {
94 Reference<XPropertySet> xProp(xFac->createDataDescriptor());
95 if ( xProp.is() )
96 {
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));
101
102 if ( m_aDefaultValue.hasValue() )
103 xProp->setPropertyValue(PROPERTY_CONTROLDEFAULT,m_aDefaultValue);
104
105 Reference<XAppend> xAppend(m_xParentContainer,UNO_QUERY);
106 if ( xAppend.is() )
107 xAppend->appendByDescriptor(xProp);
108 m_xParentContainer->getByName(m_sName) >>= xProp;
109
110 if ( !m_sStyleName.isEmpty() )
111 {
112 const SvXMLStylesContext* pAutoStyles = GetOwnImport().GetAutoStyles();
113 if ( pAutoStyles )
114 {
115 OTableStyleContext* pAutoStyle = const_cast<OTableStyleContext*>(
116 dynamic_cast< const OTableStyleContext* >(pAutoStyles->FindStyleChildContext(XmlStyleFamily::TABLE_COLUMN,m_sStyleName)));
117 if ( pAutoStyle )
118 {
119 pAutoStyle->FillPropertySet(xProp);
120 }
121 }
122 }
123 if ( !m_sCellStyleName.isEmpty() )
124 {
125 const SvXMLStylesContext* pAutoStyles = GetOwnImport().GetAutoStyles();
126 if ( pAutoStyles )
127 {
128 OTableStyleContext* pAutoStyle = const_cast<OTableStyleContext*>(dynamic_cast<const OTableStyleContext* >(pAutoStyles->FindStyleChildContext(XmlStyleFamily::TABLE_CELL,m_sCellStyleName)));
129 if ( pAutoStyle )
130 {
131 pAutoStyle->FillPropertySet(xProp);
132 // we also have to do this on the table to import text-properties
133 pAutoStyle->FillPropertySet(m_xTable);
134 }
135 }
136 }
137
138 }
139 }
140 else if ( !m_sCellStyleName.isEmpty() )
141 {
142 const SvXMLStylesContext* pAutoStyles = GetOwnImport().GetAutoStyles();
143 if ( pAutoStyles )
144 {
145 OTableStyleContext* pAutoStyle = const_cast<OTableStyleContext*>(dynamic_cast< const OTableStyleContext* >(pAutoStyles->FindStyleChildContext(XmlStyleFamily::TABLE_CELL,m_sCellStyleName)));
146 if ( pAutoStyle )
147 {
148 // we also have to do this on the table to import text-properties
149 pAutoStyle->FillPropertySet(m_xTable);
150 }
151 }
152 }
153}
154
156{
157 return static_cast<ODBFilter&>(GetImport());
158}
159
160} // namespace dbaxml
161
162/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OptionalString sType
SvXMLImport & GetImport()
const SvXMLStyleContext * FindStyleChildContext(XmlStyleFamily nFamily, const OUString &rName, bool bCreateIndex=false) const
virtual void FillPropertySet(const css::uno::Reference< css::beans::XPropertySet > &rPropSet) override
OXMLColumn(ODBFilter &rImport, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList, const css::uno::Reference< css::container::XNameAccess > &_xParentContainer, const css::uno::Reference< css::beans::XPropertySet > &_xTable)
Definition: xmlColumn.cxx:37
css::uno::Reference< css::beans::XPropertySet > m_xTable
Definition: xmlColumn.hxx:31
css::uno::Any m_aDefaultValue
Definition: xmlColumn.hxx:37
OUString m_sHelpMessage
Definition: xmlColumn.hxx:36
OUString m_sStyleName
Definition: xmlColumn.hxx:34
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
Definition: xmlColumn.cxx:89
OUString m_sCellStyleName
Definition: xmlColumn.hxx:35
css::uno::Reference< css::container::XNameAccess > m_xParentContainer
Definition: xmlColumn.hxx:30
virtual ~OXMLColumn() override
Definition: xmlColumn.cxx:84
ODBFilter & GetOwnImport()
Definition: xmlColumn.cxx:155
Reference< XContent > m_xParentContainer
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
XML_VISIBILITY
XML_DEFAULT_CELL_STYLE_NAME
XML_STYLE_NAME
XML_TYPE_NAME
XML_DEFAULT_VALUE
XML_NAME
XML_VISIBLE
XML_HELP_MESSAGE
constexpr OUStringLiteral PROPERTY_CONTROLDEFAULT(u"ControlDefault")
constexpr OUStringLiteral PROPERTY_HELPTEXT(u"HelpText")
constexpr OUStringLiteral PROPERTY_NAME(u"Name")
constexpr OUStringLiteral PROPERTY_HIDDEN(u"Hidden")
#define XMLOFF_WARN_UNKNOWN(area, rIter)
constexpr sal_Int32 TOKEN_MASK