tdf#154285 Check upper bound of arguments in SbRtl_Minute function
[LibreOffice.git] / dbaccess / source / filter / xml / xmlColumn.cxx
blob1afbf9f0f419d9ff3a268f058b13f0950ca57a77
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>
29 namespace dbaxml
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
41 ) :
42 SvXMLImportContext( rImport )
43 ,m_xParentContainer(_xParentContainer)
44 ,m_xTable(_xTable)
45 ,m_bHidden(false)
47 OUString sType;
48 for (auto &aIter : sax_fastparser::castToFastAttributeList( _xAttrList ))
50 switch( aIter.getToken() & TOKEN_MASK )
52 case XML_NAME:
53 m_sName = aIter.toString();
54 break;
55 case XML_STYLE_NAME:
56 m_sStyleName = aIter.toString();
57 break;
58 case XML_HELP_MESSAGE:
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;
68 case XML_DEFAULT_VALUE:
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;
75 case XML_DEFAULT_CELL_STYLE_NAME:
76 m_sCellStyleName = aIter.toString();
77 break;
78 default:
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());
95 if ( xProp.is() )
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);
106 if ( xAppend.is() )
107 xAppend->appendByDescriptor(xProp);
108 m_xParentContainer->getByName(m_sName) >>= xProp;
110 if ( !m_sStyleName.isEmpty() )
112 const SvXMLStylesContext* pAutoStyles = GetOwnImport().GetAutoStyles();
113 if ( pAutoStyles )
115 OTableStyleContext* pAutoStyle = const_cast<OTableStyleContext*>(
116 dynamic_cast< const OTableStyleContext* >(pAutoStyles->FindStyleChildContext(XmlStyleFamily::TABLE_COLUMN,m_sStyleName)));
117 if ( pAutoStyle )
119 pAutoStyle->FillPropertySet(xProp);
123 if ( !m_sCellStyleName.isEmpty() )
125 const SvXMLStylesContext* pAutoStyles = GetOwnImport().GetAutoStyles();
126 if ( pAutoStyles )
128 OTableStyleContext* pAutoStyle = const_cast<OTableStyleContext*>(dynamic_cast<const OTableStyleContext* >(pAutoStyles->FindStyleChildContext(XmlStyleFamily::TABLE_CELL,m_sCellStyleName)));
129 if ( pAutoStyle )
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();
143 if ( pAutoStyles )
145 OTableStyleContext* pAutoStyle = const_cast<OTableStyleContext*>(dynamic_cast< const OTableStyleContext* >(pAutoStyles->FindStyleChildContext(XmlStyleFamily::TABLE_CELL,m_sCellStyleName)));
146 if ( pAutoStyle )
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: */