1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_extensions.hxx" 30*cdf0e10cSrcweir #include "xsdvalidationhelper.hxx" 31*cdf0e10cSrcweir #include "xsddatatypes.hxx" 32*cdf0e10cSrcweir #include "formstrings.hxx" 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir /** === begin UNO includes === **/ 35*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp> 36*cdf0e10cSrcweir #include <com/sun/star/xsd/DataTypeClass.hpp> 37*cdf0e10cSrcweir #include <com/sun/star/util/NumberFormat.hpp> 38*cdf0e10cSrcweir #include <com/sun/star/util/XNumberFormatTypes.hpp> 39*cdf0e10cSrcweir #include <com/sun/star/util/XNumberFormatsSupplier.hpp> 40*cdf0e10cSrcweir #include <com/sun/star/xforms/XDataTypeRepository.hpp> 41*cdf0e10cSrcweir /** === end UNO includes === **/ 42*cdf0e10cSrcweir #include <unotools/syslocale.hxx> 43*cdf0e10cSrcweir #include <tools/diagnose_ex.h> 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir //........................................................................ 46*cdf0e10cSrcweir namespace pcr 47*cdf0e10cSrcweir { 48*cdf0e10cSrcweir //........................................................................ 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir using namespace ::com::sun::star; 51*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 52*cdf0e10cSrcweir using namespace ::com::sun::star::beans; 53*cdf0e10cSrcweir using namespace ::com::sun::star::xsd; 54*cdf0e10cSrcweir using namespace ::com::sun::star::util; 55*cdf0e10cSrcweir using namespace ::com::sun::star::lang; 56*cdf0e10cSrcweir using namespace ::com::sun::star::xforms; 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir namespace NumberFormat = ::com::sun::star::util::NumberFormat; 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir //==================================================================== 61*cdf0e10cSrcweir //= XSDValidationHelper 62*cdf0e10cSrcweir //==================================================================== 63*cdf0e10cSrcweir //-------------------------------------------------------------------- 64*cdf0e10cSrcweir XSDValidationHelper::XSDValidationHelper( ::osl::Mutex& _rMutex, const Reference< XPropertySet >& _rxIntrospectee, const Reference< frame::XModel >& _rxContextDocument ) 65*cdf0e10cSrcweir :EFormsHelper( _rMutex, _rxIntrospectee, _rxContextDocument ) 66*cdf0e10cSrcweir ,m_bInspectingFormattedField( false ) 67*cdf0e10cSrcweir { 68*cdf0e10cSrcweir try 69*cdf0e10cSrcweir { 70*cdf0e10cSrcweir Reference< XPropertySetInfo > xPSI; 71*cdf0e10cSrcweir Reference< XServiceInfo > xSI( _rxIntrospectee, UNO_QUERY ); 72*cdf0e10cSrcweir if ( m_xControlModel.is() ) 73*cdf0e10cSrcweir xPSI = m_xControlModel->getPropertySetInfo(); 74*cdf0e10cSrcweir if ( xPSI.is() 75*cdf0e10cSrcweir && xPSI->hasPropertyByName( PROPERTY_FORMATKEY ) 76*cdf0e10cSrcweir && xPSI->hasPropertyByName( PROPERTY_FORMATSSUPPLIER ) 77*cdf0e10cSrcweir && xSI.is() 78*cdf0e10cSrcweir && xSI->supportsService( SERVICE_COMPONENT_FORMATTEDFIELD ) 79*cdf0e10cSrcweir ) 80*cdf0e10cSrcweir m_bInspectingFormattedField = true; 81*cdf0e10cSrcweir } 82*cdf0e10cSrcweir catch( const Exception& ) 83*cdf0e10cSrcweir { 84*cdf0e10cSrcweir OSL_ENSURE( sal_False, "XSDValidationHelper::XSDValidationHelper: caught an exception while examining the introspectee!" ); 85*cdf0e10cSrcweir } 86*cdf0e10cSrcweir } 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir //-------------------------------------------------------------------- 89*cdf0e10cSrcweir void XSDValidationHelper::getAvailableDataTypeNames( ::std::vector< ::rtl::OUString >& /* [out] */ _rNames ) const SAL_THROW(()) 90*cdf0e10cSrcweir { 91*cdf0e10cSrcweir _rNames.resize( 0 ); 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir try 94*cdf0e10cSrcweir { 95*cdf0e10cSrcweir Reference< XDataTypeRepository > xRepository = getDataTypeRepository(); 96*cdf0e10cSrcweir Sequence< ::rtl::OUString > aElements; 97*cdf0e10cSrcweir if ( xRepository.is() ) 98*cdf0e10cSrcweir aElements = xRepository->getElementNames(); 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir _rNames.resize( aElements.getLength() ); 101*cdf0e10cSrcweir ::std::copy( aElements.getConstArray(), aElements.getConstArray() + aElements.getLength(), _rNames.begin() ); 102*cdf0e10cSrcweir } 103*cdf0e10cSrcweir catch( const Exception& ) 104*cdf0e10cSrcweir { 105*cdf0e10cSrcweir OSL_ENSURE( sal_False, "XSDValidationHelper::getAvailableDataTypeNames: caught an exception!" ); 106*cdf0e10cSrcweir } 107*cdf0e10cSrcweir } 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir //-------------------------------------------------------------------- 110*cdf0e10cSrcweir Reference< XDataTypeRepository > XSDValidationHelper::getDataTypeRepository() const SAL_THROW((Exception)) 111*cdf0e10cSrcweir { 112*cdf0e10cSrcweir Reference< XDataTypeRepository > xRepository; 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir Reference< xforms::XModel > xModel( getCurrentFormModel( ) ); 115*cdf0e10cSrcweir if ( xModel.is() ) 116*cdf0e10cSrcweir xRepository = xModel->getDataTypeRepository(); 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir return xRepository; 119*cdf0e10cSrcweir } 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir //-------------------------------------------------------------------- 122*cdf0e10cSrcweir Reference< XDataTypeRepository > XSDValidationHelper::getDataTypeRepository( const ::rtl::OUString& _rModelName ) const SAL_THROW((Exception)) 123*cdf0e10cSrcweir { 124*cdf0e10cSrcweir Reference< XDataTypeRepository > xRepository; 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir Reference< xforms::XModel > xModel( getFormModelByName( _rModelName ) ); 127*cdf0e10cSrcweir if ( xModel.is() ) 128*cdf0e10cSrcweir xRepository = xModel->getDataTypeRepository(); 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir return xRepository; 131*cdf0e10cSrcweir } 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir //-------------------------------------------------------------------- 134*cdf0e10cSrcweir Reference< XDataType > XSDValidationHelper::getDataType( const ::rtl::OUString& _rName ) const SAL_THROW((Exception)) 135*cdf0e10cSrcweir { 136*cdf0e10cSrcweir Reference< XDataType > xDataType; 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir if ( _rName.getLength() ) 139*cdf0e10cSrcweir { 140*cdf0e10cSrcweir Reference< XDataTypeRepository > xRepository = getDataTypeRepository(); 141*cdf0e10cSrcweir if ( xRepository.is() ) 142*cdf0e10cSrcweir xDataType = xRepository->getDataType( _rName ); 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir return xDataType; 145*cdf0e10cSrcweir } 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir //-------------------------------------------------------------------- 148*cdf0e10cSrcweir ::rtl::OUString XSDValidationHelper::getValidatingDataTypeName( ) const SAL_THROW(()) 149*cdf0e10cSrcweir { 150*cdf0e10cSrcweir ::rtl::OUString sDataTypeName; 151*cdf0e10cSrcweir try 152*cdf0e10cSrcweir { 153*cdf0e10cSrcweir Reference< XPropertySet > xBinding( getCurrentBinding() ); 154*cdf0e10cSrcweir // it's allowed here to not (yet) have a binding 155*cdf0e10cSrcweir if ( xBinding.is() ) 156*cdf0e10cSrcweir { 157*cdf0e10cSrcweir OSL_VERIFY( xBinding->getPropertyValue( PROPERTY_XSD_DATA_TYPE ) >>= sDataTypeName ); 158*cdf0e10cSrcweir } 159*cdf0e10cSrcweir } 160*cdf0e10cSrcweir catch( const Exception& ) 161*cdf0e10cSrcweir { 162*cdf0e10cSrcweir OSL_ENSURE( sal_False, "XSDValidationHelper::getValidatingDataTypeName: caught an exception!" ); 163*cdf0e10cSrcweir } 164*cdf0e10cSrcweir return sDataTypeName; 165*cdf0e10cSrcweir } 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir //-------------------------------------------------------------------- 168*cdf0e10cSrcweir ::rtl::Reference< XSDDataType > XSDValidationHelper::getDataTypeByName( const ::rtl::OUString& _rName ) const SAL_THROW(()) 169*cdf0e10cSrcweir { 170*cdf0e10cSrcweir ::rtl::Reference< XSDDataType > pReturn; 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir try 173*cdf0e10cSrcweir { 174*cdf0e10cSrcweir Reference< XDataType > xValidatedAgainst; 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir if ( _rName.getLength() ) 177*cdf0e10cSrcweir xValidatedAgainst = getDataType( _rName ); 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir if ( xValidatedAgainst.is() ) 180*cdf0e10cSrcweir pReturn = new XSDDataType( xValidatedAgainst ); 181*cdf0e10cSrcweir } 182*cdf0e10cSrcweir catch( const Exception& ) 183*cdf0e10cSrcweir { 184*cdf0e10cSrcweir OSL_ENSURE( sal_False, "XSDValidationHelper::getDataTypeByName: caught an exception!" ); 185*cdf0e10cSrcweir } 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir return pReturn; 188*cdf0e10cSrcweir } 189*cdf0e10cSrcweir 190*cdf0e10cSrcweir //-------------------------------------------------------------------- 191*cdf0e10cSrcweir ::rtl::Reference< XSDDataType > XSDValidationHelper::getValidatingDataType( ) const SAL_THROW(()) 192*cdf0e10cSrcweir { 193*cdf0e10cSrcweir return getDataTypeByName( getValidatingDataTypeName() ); 194*cdf0e10cSrcweir } 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir //-------------------------------------------------------------------- 197*cdf0e10cSrcweir bool XSDValidationHelper::cloneDataType( const ::rtl::Reference< XSDDataType >& _pDataType, const ::rtl::OUString& _rNewName ) const SAL_THROW(()) 198*cdf0e10cSrcweir { 199*cdf0e10cSrcweir OSL_ENSURE( _pDataType.is(), "XSDValidationHelper::removeDataTypeFromRepository: invalid data type!" ); 200*cdf0e10cSrcweir if ( !_pDataType.is() ) 201*cdf0e10cSrcweir return false; 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir try 204*cdf0e10cSrcweir { 205*cdf0e10cSrcweir Reference< XDataTypeRepository > xRepository( getDataTypeRepository() ); 206*cdf0e10cSrcweir OSL_ENSURE( xRepository.is(), "XSDValidationHelper::removeDataTypeFromRepository: invalid data type repository!" ); 207*cdf0e10cSrcweir if ( !xRepository.is() ) 208*cdf0e10cSrcweir return false; 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir Reference< XDataType > xDataType( _pDataType->getUnoDataType() ); 211*cdf0e10cSrcweir OSL_ENSURE( xDataType.is(), "XSDValidationHelper::removeDataTypeFromRepository: invalid data type (II)!" ); 212*cdf0e10cSrcweir if ( !xDataType.is() ) 213*cdf0e10cSrcweir return false; 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir xRepository->cloneDataType( xDataType->getName(), _rNewName ); 216*cdf0e10cSrcweir } 217*cdf0e10cSrcweir catch( const Exception& ) 218*cdf0e10cSrcweir { 219*cdf0e10cSrcweir OSL_ENSURE( sal_False, "XSDValidationHelper::cloneDataType: caught an exception!" ); 220*cdf0e10cSrcweir } 221*cdf0e10cSrcweir return true; 222*cdf0e10cSrcweir } 223*cdf0e10cSrcweir 224*cdf0e10cSrcweir //-------------------------------------------------------------------- 225*cdf0e10cSrcweir bool XSDValidationHelper::removeDataTypeFromRepository( const ::rtl::OUString& _rName ) const SAL_THROW(()) 226*cdf0e10cSrcweir { 227*cdf0e10cSrcweir try 228*cdf0e10cSrcweir { 229*cdf0e10cSrcweir Reference< XDataTypeRepository > xRepository( getDataTypeRepository() ); 230*cdf0e10cSrcweir OSL_ENSURE( xRepository.is(), "XSDValidationHelper::removeDataTypeFromRepository: invalid data type repository!" ); 231*cdf0e10cSrcweir if ( !xRepository.is() ) 232*cdf0e10cSrcweir return false; 233*cdf0e10cSrcweir 234*cdf0e10cSrcweir if ( !xRepository->hasByName( _rName ) ) 235*cdf0e10cSrcweir { 236*cdf0e10cSrcweir OSL_ENSURE( sal_False, "XSDValidationHelper::removeDataTypeFromRepository: invalid repository and/or data type!" ); 237*cdf0e10cSrcweir return false; 238*cdf0e10cSrcweir } 239*cdf0e10cSrcweir 240*cdf0e10cSrcweir xRepository->revokeDataType( _rName ); 241*cdf0e10cSrcweir } 242*cdf0e10cSrcweir catch( const Exception& ) 243*cdf0e10cSrcweir { 244*cdf0e10cSrcweir OSL_ENSURE( sal_False, "XSDValidationHelper::removeDataTypeFromRepository: caught an exception!" ); 245*cdf0e10cSrcweir return false; 246*cdf0e10cSrcweir } 247*cdf0e10cSrcweir return true; 248*cdf0e10cSrcweir } 249*cdf0e10cSrcweir 250*cdf0e10cSrcweir //-------------------------------------------------------------------- 251*cdf0e10cSrcweir void XSDValidationHelper::setValidatingDataTypeByName( const ::rtl::OUString& _rName ) const SAL_THROW(()) 252*cdf0e10cSrcweir { 253*cdf0e10cSrcweir try 254*cdf0e10cSrcweir { 255*cdf0e10cSrcweir Reference< XPropertySet > xBinding( getCurrentBinding() ); 256*cdf0e10cSrcweir OSL_ENSURE( xBinding.is(), "XSDValidationHelper::setValidatingDataTypeByName: no active binding - how this?" ); 257*cdf0e10cSrcweir 258*cdf0e10cSrcweir if ( xBinding.is() ) 259*cdf0e10cSrcweir { 260*cdf0e10cSrcweir // get the old data type - this is necessary for notifying property changes 261*cdf0e10cSrcweir ::rtl::OUString sOldDataTypeName; 262*cdf0e10cSrcweir OSL_VERIFY( xBinding->getPropertyValue( PROPERTY_XSD_DATA_TYPE ) >>= sOldDataTypeName ); 263*cdf0e10cSrcweir Reference< XPropertySet > xOldType; 264*cdf0e10cSrcweir try { xOldType = xOldType.query( getDataType( sOldDataTypeName ) ); } catch( const Exception& ) { } 265*cdf0e10cSrcweir 266*cdf0e10cSrcweir // set the new data type name 267*cdf0e10cSrcweir xBinding->setPropertyValue( PROPERTY_XSD_DATA_TYPE, makeAny( _rName ) ); 268*cdf0e10cSrcweir 269*cdf0e10cSrcweir // retrieve the new data type object 270*cdf0e10cSrcweir Reference< XPropertySet > xNewType( getDataType( _rName ), UNO_QUERY ); 271*cdf0e10cSrcweir 272*cdf0e10cSrcweir // fire any changes in the properties which result from this new type 273*cdf0e10cSrcweir std::set< ::rtl::OUString > aFilter; aFilter.insert( PROPERTY_NAME ); 274*cdf0e10cSrcweir firePropertyChanges( xOldType, xNewType, aFilter ); 275*cdf0e10cSrcweir 276*cdf0e10cSrcweir // fire the change in the Data Type property 277*cdf0e10cSrcweir ::rtl::OUString sNewDataTypeName; 278*cdf0e10cSrcweir OSL_VERIFY( xBinding->getPropertyValue( PROPERTY_XSD_DATA_TYPE ) >>= sNewDataTypeName ); 279*cdf0e10cSrcweir firePropertyChange( PROPERTY_XSD_DATA_TYPE, makeAny( sOldDataTypeName ), makeAny( sNewDataTypeName ) ); 280*cdf0e10cSrcweir } 281*cdf0e10cSrcweir } 282*cdf0e10cSrcweir catch( const Exception& ) 283*cdf0e10cSrcweir { 284*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 285*cdf0e10cSrcweir } 286*cdf0e10cSrcweir } 287*cdf0e10cSrcweir 288*cdf0e10cSrcweir //-------------------------------------------------------------------- 289*cdf0e10cSrcweir void XSDValidationHelper::copyDataType( const ::rtl::OUString& _rFromModel, const ::rtl::OUString& _rToModel, 290*cdf0e10cSrcweir const ::rtl::OUString& _rDataTypeName ) const SAL_THROW(()) 291*cdf0e10cSrcweir { 292*cdf0e10cSrcweir if ( _rFromModel == _rToModel ) 293*cdf0e10cSrcweir // nothing to do (me thinks) 294*cdf0e10cSrcweir return; 295*cdf0e10cSrcweir 296*cdf0e10cSrcweir try 297*cdf0e10cSrcweir { 298*cdf0e10cSrcweir Reference< XDataTypeRepository > xFromRepository, xToRepository; 299*cdf0e10cSrcweir if ( _rFromModel.getLength() ) 300*cdf0e10cSrcweir xFromRepository = getDataTypeRepository( _rFromModel ); 301*cdf0e10cSrcweir if ( _rToModel.getLength() ) 302*cdf0e10cSrcweir xToRepository = getDataTypeRepository( _rToModel ); 303*cdf0e10cSrcweir 304*cdf0e10cSrcweir if ( !xFromRepository.is() || !xToRepository.is() ) 305*cdf0e10cSrcweir return; 306*cdf0e10cSrcweir 307*cdf0e10cSrcweir if ( !xFromRepository->hasByName( _rDataTypeName ) || xToRepository->hasByName( _rDataTypeName ) ) 308*cdf0e10cSrcweir // not existent in the source, or already existent (by name) in the destination 309*cdf0e10cSrcweir return; 310*cdf0e10cSrcweir 311*cdf0e10cSrcweir // determine the built-in type belonging to the source type 312*cdf0e10cSrcweir ::rtl::Reference< XSDDataType > pSourceType = new XSDDataType( xFromRepository->getDataType( _rDataTypeName ) ); 313*cdf0e10cSrcweir ::rtl::OUString sTargetBaseType = getBasicTypeNameForClass( pSourceType->classify(), xToRepository ); 314*cdf0e10cSrcweir 315*cdf0e10cSrcweir // create the target type 316*cdf0e10cSrcweir Reference< XDataType > xTargetType = xToRepository->cloneDataType( sTargetBaseType, _rDataTypeName ); 317*cdf0e10cSrcweir ::rtl::Reference< XSDDataType > pTargetType = new XSDDataType( xTargetType ); 318*cdf0e10cSrcweir 319*cdf0e10cSrcweir // copy the facets 320*cdf0e10cSrcweir pTargetType->copyFacetsFrom( pSourceType ); 321*cdf0e10cSrcweir } 322*cdf0e10cSrcweir catch( const Exception& ) 323*cdf0e10cSrcweir { 324*cdf0e10cSrcweir OSL_ENSURE( sal_False, "XSDValidationHelper::copyDataType: caught an exception!" ); 325*cdf0e10cSrcweir } 326*cdf0e10cSrcweir } 327*cdf0e10cSrcweir 328*cdf0e10cSrcweir //-------------------------------------------------------------------- 329*cdf0e10cSrcweir void XSDValidationHelper::findDefaultFormatForIntrospectee() SAL_THROW(()) 330*cdf0e10cSrcweir { 331*cdf0e10cSrcweir try 332*cdf0e10cSrcweir { 333*cdf0e10cSrcweir ::rtl::Reference< XSDDataType > xDataType = getValidatingDataType(); 334*cdf0e10cSrcweir if ( xDataType.is() ) 335*cdf0e10cSrcweir { 336*cdf0e10cSrcweir // find a NumberFormat type corresponding to the DataTypeClass 337*cdf0e10cSrcweir sal_Int16 nNumberFormatType = NumberFormat::NUMBER; 338*cdf0e10cSrcweir switch ( xDataType->classify() ) 339*cdf0e10cSrcweir { 340*cdf0e10cSrcweir case DataTypeClass::DATETIME: 341*cdf0e10cSrcweir nNumberFormatType = NumberFormat::DATETIME; 342*cdf0e10cSrcweir break; 343*cdf0e10cSrcweir case DataTypeClass::DATE: 344*cdf0e10cSrcweir nNumberFormatType = NumberFormat::DATE; 345*cdf0e10cSrcweir break; 346*cdf0e10cSrcweir case DataTypeClass::TIME: 347*cdf0e10cSrcweir nNumberFormatType = NumberFormat::TIME; 348*cdf0e10cSrcweir break; 349*cdf0e10cSrcweir case DataTypeClass::STRING: 350*cdf0e10cSrcweir case DataTypeClass::anyURI: 351*cdf0e10cSrcweir case DataTypeClass::QName: 352*cdf0e10cSrcweir case DataTypeClass::NOTATION: 353*cdf0e10cSrcweir nNumberFormatType = NumberFormat::TEXT; 354*cdf0e10cSrcweir break; 355*cdf0e10cSrcweir } 356*cdf0e10cSrcweir 357*cdf0e10cSrcweir // get the number formatter from the introspectee 358*cdf0e10cSrcweir Reference< XNumberFormatsSupplier > xSupplier; 359*cdf0e10cSrcweir Reference< XNumberFormatTypes > xFormatTypes; 360*cdf0e10cSrcweir OSL_VERIFY( m_xControlModel->getPropertyValue( PROPERTY_FORMATSSUPPLIER ) >>= xSupplier ); 361*cdf0e10cSrcweir if ( xSupplier.is() ) 362*cdf0e10cSrcweir xFormatTypes = xFormatTypes.query( xSupplier->getNumberFormats() ); 363*cdf0e10cSrcweir OSL_ENSURE( xFormatTypes.is(), "XSDValidationHelper::findDefaultFormatForIntrospectee: no number formats for the introspectee!" ); 364*cdf0e10cSrcweir if ( !xFormatTypes.is() ) 365*cdf0e10cSrcweir return; 366*cdf0e10cSrcweir 367*cdf0e10cSrcweir // and the standard format for the given NumberFormat type 368*cdf0e10cSrcweir sal_Int32 nDesiredFormat = xFormatTypes->getStandardFormat( nNumberFormatType, SvtSysLocale().GetLocaleData().getLocale() ); 369*cdf0e10cSrcweir 370*cdf0e10cSrcweir // set this at the introspectee 371*cdf0e10cSrcweir m_xControlModel->setPropertyValue( PROPERTY_FORMATKEY, makeAny( nDesiredFormat ) ); 372*cdf0e10cSrcweir } 373*cdf0e10cSrcweir } 374*cdf0e10cSrcweir catch( const Exception& ) 375*cdf0e10cSrcweir { 376*cdf0e10cSrcweir OSL_ENSURE( sal_False, "XSDValidationHelper::findDefaultFormatForIntrospectee: caught an exception!" ); 377*cdf0e10cSrcweir } 378*cdf0e10cSrcweir } 379*cdf0e10cSrcweir 380*cdf0e10cSrcweir //-------------------------------------------------------------------- 381*cdf0e10cSrcweir ::rtl::OUString XSDValidationHelper::getBasicTypeNameForClass( sal_Int16 _nClass ) const SAL_THROW(()) 382*cdf0e10cSrcweir { 383*cdf0e10cSrcweir return getBasicTypeNameForClass( _nClass, getDataTypeRepository() ); 384*cdf0e10cSrcweir } 385*cdf0e10cSrcweir 386*cdf0e10cSrcweir //-------------------------------------------------------------------- 387*cdf0e10cSrcweir ::rtl::OUString XSDValidationHelper::getBasicTypeNameForClass( sal_Int16 _nClass, Reference< XDataTypeRepository > _rxRepository ) const SAL_THROW(()) 388*cdf0e10cSrcweir { 389*cdf0e10cSrcweir ::rtl::OUString sReturn; 390*cdf0e10cSrcweir OSL_ENSURE( _rxRepository.is(), "XSDValidationHelper::getBasicTypeNameForClass: invalid repository!" ); 391*cdf0e10cSrcweir if ( !_rxRepository.is() ) 392*cdf0e10cSrcweir return sReturn; 393*cdf0e10cSrcweir 394*cdf0e10cSrcweir try 395*cdf0e10cSrcweir { 396*cdf0e10cSrcweir Reference< XDataType > xDataType = _rxRepository->getBasicDataType( _nClass ); 397*cdf0e10cSrcweir OSL_ENSURE( xDataType.is(), "XSDValidationHelper::getBasicTypeNameForClass: invalid data type returned!" ); 398*cdf0e10cSrcweir if ( xDataType.is() ) 399*cdf0e10cSrcweir sReturn = xDataType->getName(); 400*cdf0e10cSrcweir } 401*cdf0e10cSrcweir catch( const Exception& ) 402*cdf0e10cSrcweir { 403*cdf0e10cSrcweir OSL_ENSURE( sal_False, "XSDValidationHelper::getBasicTypeNameForClass: caught an exception!" ); 404*cdf0e10cSrcweir } 405*cdf0e10cSrcweir 406*cdf0e10cSrcweir return sReturn; 407*cdf0e10cSrcweir } 408*cdf0e10cSrcweir 409*cdf0e10cSrcweir //........................................................................ 410*cdf0e10cSrcweir } // namespace pcr 411*cdf0e10cSrcweir //........................................................................ 412*cdf0e10cSrcweir 413