nss: upgrade to release 3.73
[LibreOffice.git] / dbaccess / source / filter / xml / xmlColumn.cxx
blob9d8560cf1364874e4f1bcda37baf933415de6ad7
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 <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>
30 namespace dbaxml
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
42 ) :
43 SvXMLImportContext( rImport )
44 ,m_xParentContainer(_xParentContainer)
45 ,m_xTable(_xTable)
46 ,m_bHidden(false)
48 OUString sType;
49 for (auto &aIter : sax_fastparser::castToFastAttributeList( _xAttrList ))
51 OUString sValue = aIter.toString();
53 switch( aIter.getToken() & TOKEN_MASK )
55 case XML_NAME:
56 m_sName = sValue;
57 break;
58 case XML_STYLE_NAME:
59 m_sStyleName = sValue;
60 break;
61 case XML_HELP_MESSAGE:
62 m_sHelpMessage = sValue;
63 break;
64 case XML_VISIBILITY:
65 m_bHidden = sValue != "visible";
66 break;
67 case XML_TYPE_NAME:
68 sType = sValue;
69 OSL_ENSURE(!sType.isEmpty(),"No type name set");
70 break;
71 case XML_DEFAULT_VALUE:
72 if ( !(sValue.isEmpty() || sType.isEmpty()) )
73 m_aDefaultValue <<= sValue;
74 break;
75 case XML_VISIBLE:
76 m_bHidden = sValue == "false";
77 break;
78 case XML_DEFAULT_CELL_STYLE_NAME:
79 m_sCellStyleName = sValue;
80 break;
81 default:
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());
98 if ( xProp.is() )
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);
109 if ( xAppend.is() )
110 xAppend->appendByDescriptor(xProp);
111 m_xParentContainer->getByName(m_sName) >>= xProp;
113 if ( !m_sStyleName.isEmpty() )
115 const SvXMLStylesContext* pAutoStyles = GetOwnImport().GetAutoStyles();
116 if ( pAutoStyles )
118 OTableStyleContext* pAutoStyle = const_cast<OTableStyleContext*>(
119 dynamic_cast< const OTableStyleContext* >(pAutoStyles->FindStyleChildContext(XmlStyleFamily::TABLE_COLUMN,m_sStyleName)));
120 if ( pAutoStyle )
122 pAutoStyle->FillPropertySet(xProp);
126 if ( !m_sCellStyleName.isEmpty() )
128 const SvXMLStylesContext* pAutoStyles = GetOwnImport().GetAutoStyles();
129 if ( pAutoStyles )
131 OTableStyleContext* pAutoStyle = const_cast<OTableStyleContext*>(dynamic_cast<const OTableStyleContext* >(pAutoStyles->FindStyleChildContext(XmlStyleFamily::TABLE_CELL,m_sCellStyleName)));
132 if ( pAutoStyle )
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();
146 if ( pAutoStyles )
148 OTableStyleContext* pAutoStyle = const_cast<OTableStyleContext*>(dynamic_cast< const OTableStyleContext* >(pAutoStyles->FindStyleChildContext(XmlStyleFamily::TABLE_CELL,m_sCellStyleName)));
149 if ( pAutoStyle )
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: */