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