/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
void XSDValidationHelper::setValidatingDataTypeByName( const OUString& _rName ) const
{ try
{
Reference< XPropertySet > xBinding( getCurrentBinding() );
OSL_ENSURE( xBinding.is(), "XSDValidationHelper::setValidatingDataTypeByName: no active binding - how this?" );
if ( xBinding.is() )
{ // get the old data type - this is necessary for notifying property changes
OUString sOldDataTypeName;
OSL_VERIFY( xBinding->getPropertyValue( PROPERTY_XSD_DATA_TYPE ) >>= sOldDataTypeName );
Reference< XPropertySet > xOldType; try {
xOldType = getDataType( sOldDataTypeName );
} catch( const Exception& ) { }
// set the new data type name
xBinding->setPropertyValue( PROPERTY_XSD_DATA_TYPE, Any( _rName ) );
// retrieve the new data type object
Reference< XPropertySet > xNewType = getDataType( _rName );
// fire any changes in the properties which result from this new type
std::set< OUString > aFilter; aFilter.insert( PROPERTY_NAME );
firePropertyChanges( xOldType, xNewType, aFilter );
// fire the change in the Data Type property
OUString sNewDataTypeName;
OSL_VERIFY( xBinding->getPropertyValue( PROPERTY_XSD_DATA_TYPE ) >>= sNewDataTypeName );
firePropertyChange( PROPERTY_XSD_DATA_TYPE, Any( sOldDataTypeName ), Any( sNewDataTypeName ) );
}
} catch( const Exception& )
{
DBG_UNHANDLED_EXCEPTION("extensions.propctrlr");
}
}
void XSDValidationHelper::copyDataType( const OUString& _rFromModel, const OUString& _rToModel, const OUString& _rDataTypeName ) const
{ if ( _rFromModel == _rToModel ) // nothing to do (me thinks) return;
if ( !xFromRepository.is() || !xToRepository.is() ) return;
if ( !xFromRepository->hasByName( _rDataTypeName ) || xToRepository->hasByName( _rDataTypeName ) ) // not existent in the source, or already existent (by name) in the destination return;
// determine the built-in type belonging to the source type
::rtl::Reference< XSDDataType > pSourceType = new XSDDataType( xFromRepository->getDataType( _rDataTypeName ) );
OUString sTargetBaseType = getBasicTypeNameForClass( pSourceType->classify(), xToRepository );
// create the target type
Reference< XDataType > xTargetType = xToRepository->cloneDataType( sTargetBaseType, _rDataTypeName );
::rtl::Reference< XSDDataType > pTargetType = new XSDDataType( xTargetType );
void XSDValidationHelper::findDefaultFormatForIntrospectee()
{ try
{
::rtl::Reference< XSDDataType > xDataType = getValidatingDataType(); if ( xDataType.is() )
{ // find a NumberFormat type corresponding to the DataTypeClass
sal_Int16 nNumberFormatType = NumberFormat::NUMBER; switch ( xDataType->classify() )
{ case DataTypeClass::DATETIME:
nNumberFormatType = NumberFormat::DATETIME; break; case DataTypeClass::DATE:
nNumberFormatType = NumberFormat::DATE; break; case DataTypeClass::TIME:
nNumberFormatType = NumberFormat::TIME; break; case DataTypeClass::STRING: case DataTypeClass::anyURI: case DataTypeClass::QName: case DataTypeClass::NOTATION:
nNumberFormatType = NumberFormat::TEXT; break;
}
// get the number formatter from the introspectee
Reference< XNumberFormatsSupplier > xSupplier;
Reference< XNumberFormatTypes > xFormatTypes;
OSL_VERIFY( m_xControlModel->getPropertyValue( PROPERTY_FORMATSSUPPLIER ) >>= xSupplier ); if ( xSupplier.is() )
xFormatTypes.set(xSupplier->getNumberFormats(), css::uno::UNO_QUERY);
OSL_ENSURE( xFormatTypes.is(), "XSDValidationHelper::findDefaultFormatForIntrospectee: no number formats for the introspectee!" ); if ( !xFormatTypes.is() ) return;
// and the standard format for the given NumberFormat type
sal_Int32 nDesiredFormat = xFormatTypes->getStandardFormat( nNumberFormatType, SvtSysLocale().GetLanguageTag().getLocale() );
// set this at the introspectee
m_xControlModel->setPropertyValue( PROPERTY_FORMATKEY, Any( nDesiredFormat ) );
}
} catch( const Exception& )
{
TOOLS_WARN_EXCEPTION( "extensions.propctrlr", "XSDValidationHelper::findDefaultFormatForIntrospectee" );
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.