24#include <com/sun/star/lang/XServiceInfo.hpp>
25#include <com/sun/star/xsd/DataTypeClass.hpp>
26#include <com/sun/star/util/NumberFormat.hpp>
27#include <com/sun/star/util/XNumberFormatTypes.hpp>
28#include <com/sun/star/util/XNumberFormatsSupplier.hpp>
29#include <com/sun/star/xforms/XDataTypeRepository.hpp>
47 namespace NumberFormat = ::com::sun::star::util::NumberFormat;
54 :
EFormsHelper( _rMutex, _rxIntrospectee, _rxContextDocument )
55 ,m_bInspectingFormattedField( false )
59 Reference< XPropertySetInfo > xPSI;
60 Reference< XServiceInfo > xSI( _rxIntrospectee, UNO_QUERY );
74 "caught an exception while examining the introspectee!");
86 if ( xRepository.is() )
88 const Sequence<OUString> aElements = xRepository->getElementNames();
90 _rNames.resize( aElements.getLength() );
91 std::copy( aElements.begin(), aElements.end(), _rNames.begin() );
96 TOOLS_WARN_EXCEPTION(
"extensions.propctrlr",
"XSDValidationHelper::getAvailableDataTypeNames" );
103 Reference< XDataTypeRepository > xRepository;
107 xRepository =
xModel->getDataTypeRepository();
115 Reference< XDataTypeRepository > xRepository;
119 xRepository =
xModel->getDataTypeRepository();
127 Reference< XDataType > xDataType;
129 if ( !_rName.isEmpty() )
132 if ( xRepository.is() )
133 xDataType = xRepository->getDataType( _rName );
141 OUString sDataTypeName;
153 TOOLS_WARN_EXCEPTION(
"extensions.propctrlr",
"XSDValidationHelper::getValidatingDataTypeName" );
155 return sDataTypeName;
165 Reference< XDataType > xValidatedAgainst;
167 if ( !_rName.isEmpty() )
170 if ( xValidatedAgainst.is() )
190 OSL_ENSURE( _pDataType.is(),
"XSDValidationHelper::removeDataTypeFromRepository: invalid data type!" );
191 if ( !_pDataType.is() )
197 OSL_ENSURE( xRepository.is(),
"XSDValidationHelper::removeDataTypeFromRepository: invalid data type repository!" );
198 if ( !xRepository.is() )
201 Reference< XDataType > xDataType( _pDataType->getUnoDataType() );
202 OSL_ENSURE( xDataType.is(),
"XSDValidationHelper::removeDataTypeFromRepository: invalid data type (II)!" );
203 if ( !xDataType.is() )
206 xRepository->cloneDataType( xDataType->getName(), _rNewName );
221 OSL_ENSURE( xRepository.is(),
"XSDValidationHelper::removeDataTypeFromRepository: invalid data type repository!" );
222 if ( !xRepository.is() )
225 if ( !xRepository->hasByName( _rName ) )
227 OSL_FAIL(
"XSDValidationHelper::removeDataTypeFromRepository: invalid repository and/or data type!" );
231 xRepository->revokeDataType( _rName );
235 TOOLS_WARN_EXCEPTION(
"extensions.propctrlr",
"XSDValidationHelper::removeDataTypeFromRepository" );
247 OSL_ENSURE( xBinding.is(),
"XSDValidationHelper::setValidatingDataTypeByName: no active binding - how this?" );
252 OUString sOldDataTypeName;
254 Reference< XPropertySet > xOldType;
263 Reference< XPropertySet > xNewType =
getDataType( _rName );
266 std::set< OUString > aFilter; aFilter.insert(
PROPERTY_NAME );
270 OUString sNewDataTypeName;
283 const OUString& _rDataTypeName )
const
285 if ( _rFromModel == _rToModel )
291 Reference< XDataTypeRepository > xFromRepository, xToRepository;
292 if ( !_rFromModel.isEmpty() )
294 if ( !_rToModel.isEmpty() )
297 if ( !xFromRepository.is() || !xToRepository.is() )
300 if ( !xFromRepository->hasByName( _rDataTypeName ) || xToRepository->hasByName( _rDataTypeName ) )
309 Reference< XDataType > xTargetType = xToRepository->cloneDataType( sTargetBaseType, _rDataTypeName );
313 pTargetType->copyFacetsFrom( pSourceType );
327 if ( xDataType.is() )
330 sal_Int16 nNumberFormatType = NumberFormat::NUMBER;
331 switch ( xDataType->classify() )
333 case DataTypeClass::DATETIME:
334 nNumberFormatType = NumberFormat::DATETIME;
336 case DataTypeClass::DATE:
337 nNumberFormatType = NumberFormat::DATE;
339 case DataTypeClass::TIME:
340 nNumberFormatType = NumberFormat::TIME;
342 case DataTypeClass::STRING:
343 case DataTypeClass::anyURI:
344 case DataTypeClass::QName:
345 case DataTypeClass::NOTATION:
346 nNumberFormatType = NumberFormat::TEXT;
351 Reference< XNumberFormatsSupplier > xSupplier;
352 Reference< XNumberFormatTypes > xFormatTypes;
354 if ( xSupplier.is() )
355 xFormatTypes.set(xSupplier->getNumberFormats(), css::uno::UNO_QUERY);
356 OSL_ENSURE( xFormatTypes.is(),
"XSDValidationHelper::findDefaultFormatForIntrospectee: no number formats for the introspectee!" );
357 if ( !xFormatTypes.is() )
361 sal_Int32 nDesiredFormat = xFormatTypes->getStandardFormat( nNumberFormatType,
SvtSysLocale().GetLanguageTag().
getLocale() );
369 TOOLS_WARN_EXCEPTION(
"extensions.propctrlr",
"XSDValidationHelper::findDefaultFormatForIntrospectee" );
383 OSL_ENSURE( _rxRepository.is(),
"XSDValidationHelper::getBasicTypeNameForClass: invalid repository!" );
384 if ( !_rxRepository.is() )
389 Reference< XDataType > xDataType = _rxRepository->getBasicDataType( _nClass );
390 OSL_ENSURE( xDataType.is(),
"XSDValidationHelper::getBasicTypeNameForClass: invalid data type returned!" );
391 if ( xDataType.is() )
392 sReturn = xDataType->getName();
394 catch(
const Exception& )
396 TOOLS_WARN_EXCEPTION(
"extensions.propctrlr",
"XSDValidationHelper::getBasicTypeNameForClass" );
css::uno::Reference< css::xsd::XDataType > getDataType(const OUString &_rName) const
retrieves the data type object for the given name
::rtl::Reference< XSDDataType > getDataTypeByName(const OUString &_rName) const
retrieves a particular data type given by name
void findDefaultFormatForIntrospectee()
finds (and sets) a default format for the formatted field we're inspecting, according to the current ...
void setValidatingDataTypeByName(const OUString &_rName) const
binds the validator to a new data type
OUString getValidatingDataTypeName() const
retrieves the name of the data type which the control model is currently validated against
css::uno::Reference< css::xforms::XDataTypeRepository > getDataTypeRepository() const
retrieves the data type repository associated with the current model
bool removeDataTypeFromRepository(const OUString &_rName) const
removes the data type given by name from the data type repository
XSDValidationHelper(::osl::Mutex &_rMutex, const css::uno::Reference< css::beans::XPropertySet > &_rxIntrospectee, const css::uno::Reference< css::frame::XModel > &_rxContextDocument)
::rtl::Reference< XSDDataType > getValidatingDataType() const
retrieves the DataType instance which the control model is currently validated against
bool cloneDataType(const ::rtl::Reference< XSDDataType > &_pDataType, const OUString &_rNewName) const
creates a new data type, which is a clone of an existing data type
bool m_bInspectingFormattedField
void getAvailableDataTypeNames(std::vector< OUString > &_rNames) const
retrieves the names of all XForms models in the document the control lives in
void copyDataType(const OUString &_rFromModel, const OUString &_rToModel, const OUString &_rDataTypeName) const
copy a data type from one model to another
OUString getBasicTypeNameForClass(sal_Int16 _eClass) const
retrieves the name of the basic data type which has the given class
#define TOOLS_WARN_EXCEPTION(area, stream)
#define DBG_UNHANDLED_EXCEPTION(...)
const LanguageTag & getLocale()
a property handler for any virtual string properties
Reference< XModel > xModel