tdf#130857 qt weld: Support mail merge "Server Auth" dialog
[LibreOffice.git] / extensions / source / propctrlr / xsddatatypes.cxx
blob25af46895adbb0481f6a1ea8a74fed8178cbb52f
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 "xsddatatypes.hxx"
22 #include <com/sun/star/xsd/DataTypeClass.hpp>
23 #include <com/sun/star/xsd/XDataType.hpp>
24 #include <com/sun/star/beans/XPropertySet.hpp>
25 #include <tools/debug.hxx>
26 #include <osl/diagnose.h>
27 #include <comphelper/diagnose_ex.hxx>
30 namespace pcr
34 using namespace ::com::sun::star::uno;
35 using namespace ::com::sun::star::xsd;
36 using namespace ::com::sun::star::beans;
38 template< typename INTERFACE, typename ARGUMENT >
39 static ARGUMENT getSave( INTERFACE* pObject, ARGUMENT ( SAL_CALL INTERFACE::*pGetter )( ) )
41 ARGUMENT aReturn = ARGUMENT();
42 try
44 aReturn = (pObject->*pGetter)( );
46 catch( const Exception& )
48 TOOLS_WARN_EXCEPTION( "extensions.propctrlr", "XSDDataType: getSave" );
50 return aReturn;
53 XSDDataType::XSDDataType( const Reference< XDataType >& _rxDataType )
54 :m_xDataType( _rxDataType )
56 DBG_ASSERT( m_xDataType.is(), "XSDDataType::XSDDataType: invalid UNO object!" );
57 if ( m_xDataType.is() )
58 m_xFacetInfo = m_xDataType->getPropertySetInfo();
62 XSDDataType::~XSDDataType()
67 sal_Int16 XSDDataType::classify() const
69 sal_Int16 nTypeClass = DataTypeClass::STRING;
70 try
72 if ( m_xDataType.is() )
73 nTypeClass = m_xDataType->getTypeClass();
75 catch( const Exception& )
77 TOOLS_WARN_EXCEPTION( "extensions.propctrlr", "XSDDataType::classify" );
79 return nTypeClass;
83 bool XSDDataType::isBasicType() const
85 return getSave( m_xDataType.get(), &XDataType::getIsBasic );
89 OUString XSDDataType::getName() const
91 return getSave( m_xDataType.get(), &XDataType::getName );
95 void XSDDataType::setFacet( const OUString& _rFacetName, const Any& _rValue )
97 try
99 m_xDataType->setPropertyValue( _rFacetName, _rValue );
101 catch( const Exception& )
103 TOOLS_WARN_EXCEPTION( "extensions.propctrlr", "XSDDataType::setFacet: caught an exception - sure this is the right data type class for this property?" );
108 bool XSDDataType::hasFacet( const OUString& _rFacetName ) const
110 bool bReturn = false;
113 bReturn = m_xFacetInfo.is() && m_xFacetInfo->hasPropertyByName( _rFacetName );
115 catch( const Exception& )
117 TOOLS_WARN_EXCEPTION( "extensions.propctrlr", "XSDDataType::hasFacet" );
119 return bReturn;
122 Any XSDDataType::getFacet( const OUString& _rFacetName )
124 Any aReturn;
127 aReturn = m_xDataType->getPropertyValue( _rFacetName );
129 catch( const Exception& )
131 TOOLS_WARN_EXCEPTION( "extensions.propctrlr", "XSDDataType::getFacet: caught an exception - sure this is the right data type class for this property?" );
133 return aReturn;
137 namespace
139 void lcl_copyProperties( const Reference< XPropertySet >& _rxSource, const Reference< XPropertySet >& _rxDest )
141 Reference< XPropertySetInfo > xSourceInfo;
142 if ( _rxSource.is() )
143 xSourceInfo = _rxSource->getPropertySetInfo();
144 Reference< XPropertySetInfo > xDestInfo;
145 if ( _rxDest.is() )
146 xDestInfo = _rxDest->getPropertySetInfo();
147 OSL_ENSURE( xSourceInfo.is() && xDestInfo.is(), "lcl_copyProperties: invalid property set( info)s!" );
148 if ( !xSourceInfo.is() || !xDestInfo.is() )
149 return;
151 Sequence< Property > aProperties( xSourceInfo->getProperties() );
152 const Property* pProperties = aProperties.getConstArray();
153 const Property* pPropertiesEnd = pProperties + aProperties.getLength();
154 for ( ; pProperties != pPropertiesEnd; ++pProperties )
156 if ( xDestInfo->hasPropertyByName( pProperties->Name ) )
157 _rxDest->setPropertyValue( pProperties->Name, _rxSource->getPropertyValue( pProperties->Name ) );
163 void XSDDataType::copyFacetsFrom( const ::rtl::Reference< XSDDataType >& _pSourceType )
165 OSL_ENSURE( _pSourceType.is(), "XSDDataType::copyFacetsFrom: invalid source type!" );
166 if ( !_pSourceType.is() )
167 return;
171 Reference< XPropertySet > xSource = _pSourceType->getUnoDataType();
172 Reference< XPropertySet > xDest = getUnoDataType();
173 lcl_copyProperties( xSource, xDest );
175 catch( const Exception& )
177 TOOLS_WARN_EXCEPTION( "extensions.propctrlr", "XSDDataType::copyFacetsFrom" );
182 } // namespace pcr
185 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */