Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "datatypes.hxx"
30 : : #include "resourcehelper.hxx"
31 : : #include "property.hrc"
32 : : #include "convert.hxx"
33 : :
34 : : #include <com/sun/star/xsd/WhiteSpaceTreatment.hpp>
35 : : #include <tools/datetime.hxx>
36 : : #include <rtl/math.hxx>
37 : :
38 : : //........................................................................
39 : : namespace xforms
40 : : {
41 : : //........................................................................
42 : :
43 : : using ::com::sun::star::uno::Reference;
44 : : using ::com::sun::star::uno::RuntimeException;
45 : : using ::com::sun::star::uno::Any;
46 : : using ::com::sun::star::uno::makeAny;
47 : : using ::com::sun::star::uno::Type;
48 : : using ::com::sun::star::uno::Sequence;
49 : : using ::com::sun::star::uno::Exception;
50 : : using ::com::sun::star::util::VetoException;
51 : : using ::com::sun::star::util::Date;
52 : : using ::com::sun::star::util::Time;
53 : : using ::com::sun::star::util::DateTime;
54 : : using ::com::sun::star::lang::IllegalArgumentException;
55 : : using ::com::sun::star::lang::WrappedTargetException;
56 : : using ::com::sun::star::beans::UnknownPropertyException;
57 : : using ::com::sun::star::beans::PropertyVetoException;
58 : : using ::com::sun::star::beans::XPropertyChangeListener;
59 : : using ::com::sun::star::beans::XVetoableChangeListener;
60 : :
61 : : using ::com::sun::star::beans::PropertyAttribute::BOUND;
62 : : using ::com::sun::star::beans::PropertyAttribute::READONLY;
63 : :
64 : : using namespace ::com::sun::star::xsd;
65 : : using namespace ::frm;
66 : : U_NAMESPACE_USE
67 : :
68 : : //====================================================================
69 : : //= OXSDDataType
70 : : //====================================================================
71 : : //--------------------------------------------------------------------
72 : 0 : OXSDDataType::OXSDDataType( const ::rtl::OUString& _rName, sal_Int16 _nTypeClass )
73 : : :OXSDDataType_PBase( m_aBHelper )
74 : : ,m_bIsBasic( sal_True )
75 : : ,m_nTypeClass( _nTypeClass )
76 : : ,m_sName( _rName )
77 : : ,m_nWST( WhiteSpaceTreatment::Preserve )
78 [ # # ][ # # ]: 0 : ,m_bPatternMatcherDirty( true )
79 : : {
80 : 0 : }
81 : :
82 : : //--------------------------------------------------------------------
83 [ # # ][ # # ]: 0 : OXSDDataType::~OXSDDataType()
[ # # ]
84 : : {
85 [ # # ]: 0 : }
86 : :
87 : : //--------------------------------------------------------------------
88 : 0 : void OXSDDataType::registerProperties()
89 : : {
90 [ # # ]: 0 : registerProperty( PROPERTY_NAME, PROPERTY_ID_NAME, BOUND, &m_sName, ::getCppuType( &m_sName ) );
91 [ # # ]: 0 : registerProperty( PROPERTY_XSD_WHITESPACE, PROPERTY_ID_XSD_WHITESPACE, BOUND, &m_nWST, ::getCppuType( &m_nWST ) );
92 [ # # ]: 0 : registerProperty( PROPERTY_XSD_PATTERN, PROPERTY_ID_XSD_PATTERN, BOUND, &m_sPattern, ::getCppuType( &m_sPattern ) );
93 : :
94 [ # # ]: 0 : registerProperty( PROPERTY_XSD_IS_BASIC, PROPERTY_ID_XSD_IS_BASIC, READONLY, &m_bIsBasic, ::getCppuType( &m_bIsBasic ) );
95 [ # # ]: 0 : registerProperty( PROPERTY_XSD_TYPE_CLASS, PROPERTY_ID_XSD_TYPE_CLASS, READONLY, &m_nTypeClass, ::getCppuType( &m_nTypeClass ) );
96 : 0 : }
97 : :
98 : : //--------------------------------------------------------------------
99 : 0 : void OXSDDataType::initializeClone( const OXSDDataType& _rCloneSource )
100 : : {
101 : 0 : m_bIsBasic = sal_False;
102 : 0 : m_nTypeClass = _rCloneSource.m_nTypeClass;
103 : 0 : m_sPattern = _rCloneSource.m_sPattern;
104 : 0 : m_nWST = _rCloneSource.m_nWST;
105 : 0 : }
106 : :
107 : : //--------------------------------------------------------------------
108 : 0 : OXSDDataType* OXSDDataType::clone( const ::rtl::OUString& _rNewName ) const
109 : : {
110 : 0 : OXSDDataType* pClone = createClone( _rNewName );
111 : 0 : pClone->initializeClone( *this );
112 : 0 : return pClone;
113 : : }
114 : :
115 : : //--------------------------------------------------------------------
116 [ # # ][ # # ]: 0 : IMPLEMENT_FORWARD_XINTERFACE2( OXSDDataType, OXSDDataType_Base, ::comphelper::OPropertyContainer )
117 : :
118 : : //--------------------------------------------------------------------
119 [ # # ][ # # ]: 0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( OXSDDataType, OXSDDataType_Base, ::comphelper::OPropertyContainer )
[ # # ]
120 : :
121 : : #define SET_PROPERTY( propertyid, value, member ) \
122 : : setFastPropertyValue( PROPERTY_ID_##propertyid, makeAny( value ) ); \
123 : : OSL_POSTCOND( member == value, "OXSDDataType::setFoo: inconsistency!" );
124 : :
125 : : //--------------------------------------------------------------------
126 : 0 : ::rtl::OUString SAL_CALL OXSDDataType::getName( ) throw (RuntimeException)
127 : : {
128 : 0 : return m_sName;
129 : : }
130 : :
131 : : //--------------------------------------------------------------------
132 : 0 : void SAL_CALL OXSDDataType::setName( const ::rtl::OUString& aName ) throw (RuntimeException, VetoException)
133 : : {
134 : : // TODO: check the name for conflicts in the repository
135 [ # # ]: 0 : SET_PROPERTY( NAME, aName, m_sName );
136 : 0 : }
137 : :
138 : : //--------------------------------------------------------------------
139 : 0 : ::rtl::OUString SAL_CALL OXSDDataType::getPattern() throw (RuntimeException)
140 : : {
141 : 0 : return m_sPattern;
142 : : }
143 : :
144 : : //--------------------------------------------------------------------
145 : 0 : void SAL_CALL OXSDDataType::setPattern( const ::rtl::OUString& _pattern ) throw (RuntimeException)
146 : : {
147 [ # # ]: 0 : SET_PROPERTY( XSD_PATTERN, _pattern, m_sPattern );
148 : 0 : }
149 : :
150 : : //--------------------------------------------------------------------
151 : 0 : sal_Int16 SAL_CALL OXSDDataType::getWhiteSpaceTreatment() throw (RuntimeException)
152 : : {
153 : 0 : return m_nWST;
154 : : }
155 : :
156 : : //--------------------------------------------------------------------
157 : 0 : void SAL_CALL OXSDDataType::setWhiteSpaceTreatment( sal_Int16 _whitespacetreatment ) throw (RuntimeException, IllegalArgumentException)
158 : : {
159 [ # # ]: 0 : SET_PROPERTY( XSD_WHITESPACE, _whitespacetreatment, m_nWST );
160 : 0 : }
161 : :
162 : : //--------------------------------------------------------------------
163 : 0 : sal_Bool SAL_CALL OXSDDataType::getIsBasic() throw (RuntimeException)
164 : : {
165 : 0 : return m_bIsBasic;
166 : : }
167 : :
168 : :
169 : : //--------------------------------------------------------------------
170 : 0 : sal_Int16 SAL_CALL OXSDDataType::getTypeClass() throw (RuntimeException)
171 : : {
172 : 0 : return m_nTypeClass;
173 : : }
174 : :
175 : : //--------------------------------------------------------------------
176 : 0 : sal_Bool OXSDDataType::validate( const ::rtl::OUString& sValue ) throw( RuntimeException )
177 : : {
178 : 0 : return ( _validate( sValue ) == 0 );
179 : : }
180 : :
181 : : //--------------------------------------------------------------------
182 : 0 : ::rtl::OUString OXSDDataType::explainInvalid( const ::rtl::OUString& sValue ) throw( RuntimeException )
183 : : {
184 : : // get reason
185 : 0 : sal_uInt16 nReason = _validate( sValue );
186 : :
187 : : // get resource and return localized string
188 : : return ( nReason == 0 )
189 : : ? ::rtl::OUString()
190 : : : getResource( nReason, sValue,
191 [ # # ][ # # ]: 0 : _explainInvalid( nReason ) );
[ # # ][ # # ]
[ # # ]
192 : : }
193 : :
194 : : //--------------------------------------------------------------------
195 : 0 : ::rtl::OUString OXSDDataType::_explainInvalid( sal_uInt16 nReason )
196 : : {
197 [ # # ]: 0 : if ( RID_STR_XFORMS_PATTERN_DOESNT_MATCH == nReason )
198 : : {
199 : : OSL_ENSURE( !m_sPattern.isEmpty(), "OXSDDataType::_explainInvalid: how can this error occur without a regular expression?" );
200 : 0 : return m_sPattern;
201 : : }
202 : 0 : return ::rtl::OUString();
203 : : }
204 : :
205 : : //--------------------------------------------------------------------
206 : : namespace
207 : : {
208 : : SAL_WNODEPRECATED_DECLARATIONS_PUSH
209 : 0 : static void lcl_initializePatternMatcher( ::std::auto_ptr< RegexMatcher >& _rpMatcher, const ::rtl::OUString& _rPattern )
210 : : {
211 : 0 : UErrorCode nMatchStatus = U_ZERO_ERROR;
212 [ # # ]: 0 : UnicodeString aIcuPattern( reinterpret_cast<const UChar *>(_rPattern.getStr()), _rPattern.getLength() ); // UChar != sal_Unicode in MinGW
213 [ # # ][ # # ]: 0 : _rpMatcher.reset( new RegexMatcher( aIcuPattern, 0, nMatchStatus ) );
214 [ # # ]: 0 : OSL_ENSURE( U_SUCCESS( nMatchStatus ), "lcl_initializePatternMatcher: invalid pattern property!" );
215 : : // if asserts, then something changed our pattern without going to convertFastPropertyValue/checkPropertySanity
216 : 0 : }
217 : : SAL_WNODEPRECATED_DECLARATIONS_POP
218 : :
219 : 0 : static bool lcl_matchString( RegexMatcher& _rMatcher, const ::rtl::OUString& _rText )
220 : : {
221 : 0 : UErrorCode nMatchStatus = U_ZERO_ERROR;
222 [ # # ]: 0 : UnicodeString aInput( reinterpret_cast<const UChar *>(_rText.getStr()), _rText.getLength() ); // UChar != sal_Unicode in MinGW
223 [ # # ]: 0 : _rMatcher.reset( aInput );
224 [ # # ][ # # ]: 0 : if ( _rMatcher.matches( nMatchStatus ) )
225 : : {
226 [ # # ]: 0 : int32_t nStart = _rMatcher.start( nMatchStatus );
227 [ # # ]: 0 : int32_t nEnd = _rMatcher.end ( nMatchStatus );
228 [ # # ][ # # ]: 0 : if ( ( nStart == 0 ) && ( nEnd == _rText.getLength() ) )
[ # # ]
229 : 0 : return true;
230 : : }
231 : :
232 [ # # ]: 0 : return false;
233 : : }
234 : : }
235 : :
236 : : //--------------------------------------------------------------------
237 : 0 : sal_uInt16 OXSDDataType::_validate( const ::rtl::OUString& _rValue )
238 : : {
239 : : // care for the whitespaces
240 [ # # ]: 0 : ::rtl::OUString sConverted = Convert::convertWhitespace( _rValue, m_nWST );
241 : :
242 : : // care for the regular expression
243 [ # # ]: 0 : if ( !m_sPattern.isEmpty() )
244 : : {
245 : : // ensure our pattern matcher is up to date
246 [ # # ]: 0 : if ( m_bPatternMatcherDirty )
247 : : {
248 [ # # ]: 0 : lcl_initializePatternMatcher( m_pPatternMatcher, m_sPattern );
249 : 0 : m_bPatternMatcherDirty = false;
250 : : }
251 : :
252 : : // let it match the string
253 [ # # ][ # # ]: 0 : if ( !lcl_matchString( *m_pPatternMatcher.get(), _rValue ) )
254 : 0 : return RID_STR_XFORMS_PATTERN_DOESNT_MATCH;
255 : : }
256 : :
257 : 0 : return 0;
258 : : }
259 : :
260 : : //--------------------------------------------------------------------
261 : 0 : sal_Bool OXSDDataType::convertFastPropertyValue( Any& _rConvertedValue, Any& _rOldValue, sal_Int32 _nHandle, const Any& _rValue ) throw(IllegalArgumentException)
262 : : {
263 : : // let the base class do the conversion
264 [ # # ][ # # ]: 0 : if ( !OXSDDataType_PBase::convertFastPropertyValue( _rConvertedValue, _rOldValue, _nHandle, _rValue ) )
265 : 0 : return sal_False;
266 : :
267 : : // sanity checks
268 : 0 : ::rtl::OUString sErrorMessage;
269 [ # # ][ # # ]: 0 : if ( !checkPropertySanity( _nHandle, _rConvertedValue, sErrorMessage ) )
270 : : {
271 [ # # ]: 0 : IllegalArgumentException aException;
272 : 0 : aException.Message = sErrorMessage;
273 [ # # ][ # # ]: 0 : aException.Context = *this;
274 [ # # ]: 0 : throw IllegalArgumentException( aException );
275 : : }
276 : :
277 : 0 : return sal_True;
278 : : }
279 : :
280 : : //--------------------------------------------------------------------
281 : 0 : void SAL_CALL OXSDDataType::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle, const Any& _rValue ) throw (Exception)
282 : : {
283 : 0 : OXSDDataType_PBase::setFastPropertyValue_NoBroadcast( _nHandle, _rValue );
284 [ # # ]: 0 : if ( _nHandle == PROPERTY_ID_XSD_PATTERN )
285 : 0 : m_bPatternMatcherDirty = true;
286 : 0 : }
287 : :
288 : : //--------------------------------------------------------------------
289 : 0 : bool OXSDDataType::checkPropertySanity( sal_Int32 _nHandle, const ::com::sun::star::uno::Any& _rNewValue, ::rtl::OUString& _rErrorMessage )
290 : : {
291 [ # # ]: 0 : if ( _nHandle == PROPERTY_ID_XSD_PATTERN )
292 : : {
293 : 0 : ::rtl::OUString sPattern;
294 : 0 : OSL_VERIFY( _rNewValue >>= sPattern );
295 : :
296 [ # # ]: 0 : UnicodeString aIcuPattern( reinterpret_cast<const UChar *>(sPattern.getStr()), sPattern.getLength() ); // UChar != sal_Unicode in MinGW
297 : 0 : UErrorCode nMatchStatus = U_ZERO_ERROR;
298 [ # # ]: 0 : RegexMatcher aMatcher( aIcuPattern, 0, nMatchStatus );
299 [ # # ]: 0 : if ( U_FAILURE( nMatchStatus ) )
300 : : {
301 [ # # ]: 0 : _rErrorMessage = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "This is no valid pattern." ) );
302 : 0 : return false;
303 [ # # ][ # # ]: 0 : }
[ # # ][ # # ]
[ # # ]
304 : : }
305 : 0 : return true;
306 : : }
307 : :
308 : : //--------------------------------------------------------------------
309 : 0 : void SAL_CALL OXSDDataType::setPropertyValue( const ::rtl::OUString& aPropertyName, const Any& aValue ) throw (UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
310 : : {
311 : 0 : OXSDDataType_PBase::setPropertyValue( aPropertyName, aValue );
312 : 0 : }
313 : :
314 : : //--------------------------------------------------------------------
315 : 0 : Any SAL_CALL OXSDDataType::getPropertyValue( const ::rtl::OUString& PropertyName ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
316 : : {
317 : 0 : return OXSDDataType_PBase::getPropertyValue( PropertyName );
318 : : }
319 : :
320 : : //--------------------------------------------------------------------
321 : 0 : void SAL_CALL OXSDDataType::addPropertyChangeListener( const ::rtl::OUString& aPropertyName, const Reference< XPropertyChangeListener >& xListener ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
322 : : {
323 : 0 : OXSDDataType_PBase::addPropertyChangeListener( aPropertyName, xListener );
324 : 0 : }
325 : :
326 : : //--------------------------------------------------------------------
327 : 0 : void SAL_CALL OXSDDataType::removePropertyChangeListener( const ::rtl::OUString& aPropertyName, const Reference< XPropertyChangeListener >& aListener ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
328 : : {
329 : 0 : OXSDDataType_PBase::removePropertyChangeListener( aPropertyName, aListener );
330 : 0 : }
331 : :
332 : : //--------------------------------------------------------------------
333 : 0 : void SAL_CALL OXSDDataType::addVetoableChangeListener( const ::rtl::OUString& PropertyName, const Reference< XVetoableChangeListener >& aListener ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
334 : : {
335 : 0 : OXSDDataType_PBase::addVetoableChangeListener( PropertyName, aListener );
336 : 0 : }
337 : :
338 : : //--------------------------------------------------------------------
339 : 0 : void SAL_CALL OXSDDataType::removeVetoableChangeListener( const ::rtl::OUString& PropertyName, const Reference< XVetoableChangeListener >& aListener ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
340 : : {
341 : 0 : OXSDDataType_PBase::removeVetoableChangeListener( PropertyName, aListener );
342 : 0 : }
343 : :
344 : : //====================================================================
345 : : //= OValueLimitedType_Base
346 : : //====================================================================
347 : 0 : OValueLimitedType_Base::OValueLimitedType_Base( const ::rtl::OUString& _rName, sal_Int16 _nTypeClass )
348 : : :OXSDDataType( _rName, _nTypeClass )
349 : : ,m_fCachedMaxInclusive( 0 )
350 : : ,m_fCachedMaxExclusive( 0 )
351 : : ,m_fCachedMinInclusive( 0 )
352 : 0 : ,m_fCachedMinExclusive( 0 )
353 : : {
354 : 0 : }
355 : :
356 : : //--------------------------------------------------------------------
357 : 0 : void OValueLimitedType_Base::initializeClone( const OXSDDataType& _rCloneSource )
358 : : {
359 : 0 : OXSDDataType::initializeClone( _rCloneSource );
360 : 0 : initializeTypedClone( static_cast< const OValueLimitedType_Base& >( _rCloneSource ) );
361 : 0 : }
362 : :
363 : : //--------------------------------------------------------------------
364 : 0 : void OValueLimitedType_Base::initializeTypedClone( const OValueLimitedType_Base& _rCloneSource )
365 : : {
366 : 0 : m_aMaxInclusive = _rCloneSource.m_aMaxInclusive;
367 : 0 : m_aMaxExclusive = _rCloneSource.m_aMaxExclusive;
368 : 0 : m_aMinInclusive = _rCloneSource.m_aMinInclusive;
369 : 0 : m_aMinExclusive = _rCloneSource.m_aMinExclusive;
370 : 0 : m_fCachedMaxInclusive = _rCloneSource.m_fCachedMaxInclusive;
371 : 0 : m_fCachedMaxExclusive = _rCloneSource.m_fCachedMaxExclusive;
372 : 0 : m_fCachedMinInclusive = _rCloneSource.m_fCachedMinInclusive;
373 : 0 : m_fCachedMinExclusive = _rCloneSource.m_fCachedMinExclusive;
374 : 0 : }
375 : :
376 : : //--------------------------------------------------------------------
377 : 0 : void SAL_CALL OValueLimitedType_Base::setFastPropertyValue_NoBroadcast(
378 : : sal_Int32 _nHandle, const ::com::sun::star::uno::Any& _rValue ) throw (::com::sun::star::uno::Exception)
379 : : {
380 : 0 : OXSDDataType::setFastPropertyValue_NoBroadcast( _nHandle, _rValue );
381 : :
382 : : // if one of our limit properties has been set, translate it into a double
383 : : // value, for later efficient validation
384 [ # # # # : 0 : switch ( _nHandle )
# ]
385 : : {
386 : : case PROPERTY_ID_XSD_MAX_INCLUSIVE_INT:
387 : : case PROPERTY_ID_XSD_MAX_INCLUSIVE_DOUBLE:
388 : : case PROPERTY_ID_XSD_MAX_INCLUSIVE_DATE:
389 : : case PROPERTY_ID_XSD_MAX_INCLUSIVE_TIME:
390 : : case PROPERTY_ID_XSD_MAX_INCLUSIVE_DATE_TIME:
391 [ # # ]: 0 : if ( m_aMaxInclusive.hasValue() )
392 : 0 : normalizeValue( m_aMaxInclusive, m_fCachedMaxInclusive );
393 : : else
394 : 0 : m_fCachedMaxInclusive = 0;
395 : 0 : break;
396 : : case PROPERTY_ID_XSD_MAX_EXCLUSIVE_INT:
397 : : case PROPERTY_ID_XSD_MAX_EXCLUSIVE_DOUBLE:
398 : : case PROPERTY_ID_XSD_MAX_EXCLUSIVE_DATE:
399 : : case PROPERTY_ID_XSD_MAX_EXCLUSIVE_TIME:
400 : : case PROPERTY_ID_XSD_MAX_EXCLUSIVE_DATE_TIME:
401 [ # # ]: 0 : if ( m_aMaxExclusive.hasValue() )
402 : 0 : normalizeValue( m_aMaxExclusive, m_fCachedMaxExclusive );
403 : : else
404 : 0 : m_fCachedMaxExclusive = 0;
405 : 0 : break;
406 : : case PROPERTY_ID_XSD_MIN_INCLUSIVE_INT:
407 : : case PROPERTY_ID_XSD_MIN_INCLUSIVE_DOUBLE:
408 : : case PROPERTY_ID_XSD_MIN_INCLUSIVE_DATE:
409 : : case PROPERTY_ID_XSD_MIN_INCLUSIVE_TIME:
410 : : case PROPERTY_ID_XSD_MIN_INCLUSIVE_DATE_TIME:
411 [ # # ]: 0 : if ( m_aMinInclusive.hasValue() )
412 : 0 : normalizeValue( m_aMinInclusive, m_fCachedMinInclusive );
413 : : else
414 : 0 : m_fCachedMinInclusive = 0;
415 : 0 : break;
416 : : case PROPERTY_ID_XSD_MIN_EXCLUSIVE_INT:
417 : : case PROPERTY_ID_XSD_MIN_EXCLUSIVE_DOUBLE:
418 : : case PROPERTY_ID_XSD_MIN_EXCLUSIVE_DATE:
419 : : case PROPERTY_ID_XSD_MIN_EXCLUSIVE_TIME:
420 : : case PROPERTY_ID_XSD_MIN_EXCLUSIVE_DATE_TIME:
421 [ # # ]: 0 : if ( m_aMinExclusive.hasValue() )
422 : 0 : normalizeValue( m_aMinExclusive, m_fCachedMinExclusive );
423 : : else
424 : 0 : m_fCachedMinExclusive = 0;
425 : 0 : break;
426 : : }
427 : 0 : }
428 : :
429 : : //--------------------------------------------------------------------
430 : 0 : bool OValueLimitedType_Base::_getValue( const ::rtl::OUString& rValue, double& fValue )
431 : : {
432 : : // convert to double
433 : : rtl_math_ConversionStatus eStatus;
434 : : sal_Int32 nEnd;
435 : : double f = ::rtl::math::stringToDouble(
436 : 0 : rValue, sal_Unicode('.'), sal_Unicode(0), &eStatus, &nEnd );
437 : :
438 : : // error checking...
439 : 0 : bool bReturn = false;
440 [ # # ]: 0 : if( eStatus == rtl_math_ConversionStatus_Ok
[ # # # # ]
441 : 0 : && nEnd == rValue.getLength() )
442 : : {
443 : 0 : bReturn = true;
444 : 0 : fValue = f;
445 : : }
446 : 0 : return bReturn;
447 : : }
448 : :
449 : : //--------------------------------------------------------------------
450 : 0 : sal_uInt16 OValueLimitedType_Base::_validate( const ::rtl::OUString& rValue )
451 : : {
452 : 0 : sal_uInt16 nReason = OXSDDataType::_validate( rValue );
453 [ # # ]: 0 : if( nReason == 0 )
454 : : {
455 : :
456 : : // convert value and check format
457 : : double f;
458 [ # # ][ # # ]: 0 : if( ! _getValue( rValue, f ) )
459 : 0 : nReason = RID_STR_XFORMS_VALUE_IS_NOT_A;
460 : :
461 : : // check range
462 [ # # ][ # # ]: 0 : else if( ( m_aMaxInclusive.hasValue() ) && f > m_fCachedMaxInclusive )
[ # # ]
463 : 0 : nReason = RID_STR_XFORMS_VALUE_MAX_INCL;
464 [ # # ][ # # ]: 0 : else if( ( m_aMaxExclusive.hasValue() ) && f >= m_fCachedMaxExclusive )
[ # # ]
465 : 0 : nReason = RID_STR_XFORMS_VALUE_MAX_EXCL;
466 [ # # ][ # # ]: 0 : else if( ( m_aMinInclusive.hasValue() ) && f < m_fCachedMinInclusive )
[ # # ]
467 : 0 : nReason = RID_STR_XFORMS_VALUE_MIN_INCL;
468 [ # # ][ # # ]: 0 : else if( ( m_aMinExclusive.hasValue() ) && f <= m_fCachedMinExclusive )
[ # # ]
469 : 0 : nReason = RID_STR_XFORMS_VALUE_MIN_EXCL;
470 : : }
471 : 0 : return nReason;
472 : : }
473 : :
474 : : //--------------------------------------------------------------------
475 : 0 : ::rtl::OUString OValueLimitedType_Base::_explainInvalid( sal_uInt16 nReason )
476 : : {
477 : 0 : ::rtl::OUStringBuffer sInfo;
478 [ # # # # : 0 : switch( nReason )
# # # ]
479 : : {
480 : : case 0:
481 : : // nothing to do!
482 : 0 : break;
483 : :
484 : : case RID_STR_XFORMS_VALUE_IS_NOT_A:
485 [ # # ][ # # ]: 0 : sInfo.append( getName() );
486 : 0 : break;
487 : :
488 : : case RID_STR_XFORMS_VALUE_MAX_INCL:
489 [ # # ][ # # ]: 0 : sInfo.append( typedValueAsHumanReadableString( m_aMaxInclusive ) );
490 : 0 : break;
491 : :
492 : : case RID_STR_XFORMS_VALUE_MAX_EXCL:
493 [ # # ][ # # ]: 0 : sInfo.append( typedValueAsHumanReadableString( m_aMaxExclusive ) );
494 : 0 : break;
495 : :
496 : : case RID_STR_XFORMS_VALUE_MIN_INCL:
497 [ # # ][ # # ]: 0 : sInfo.append( typedValueAsHumanReadableString( m_aMinInclusive ) );
498 : 0 : break;
499 : :
500 : : case RID_STR_XFORMS_VALUE_MIN_EXCL:
501 [ # # ][ # # ]: 0 : sInfo.append( typedValueAsHumanReadableString( m_aMinExclusive ) );
502 : 0 : break;
503 : :
504 : : default:
505 : : OSL_FAIL( "OValueLimitedType::_explainInvalid: unknown reason!" );
506 : 0 : break;
507 : : }
508 : :
509 [ # # ]: 0 : return sInfo.makeStringAndClear();
510 : : }
511 : :
512 : : //====================================================================
513 : : //= OStringType
514 : : //====================================================================
515 : : //--------------------------------------------------------------------
516 : 0 : OStringType::OStringType( const ::rtl::OUString& _rName, sal_Int16 _nTypeClass )
517 : 0 : :OStringType_Base( _rName, _nTypeClass )
518 : : {
519 : 0 : }
520 : :
521 : : //--------------------------------------------------------------------
522 : 0 : void OStringType::registerProperties()
523 : : {
524 : 0 : OStringType_Base::registerProperties();
525 : :
526 [ # # ]: 0 : REGISTER_VOID_PROP( XSD_LENGTH, m_aLength, sal_Int32 );
527 [ # # ]: 0 : REGISTER_VOID_PROP( XSD_MIN_LENGTH, m_aMinLength, sal_Int32 );
528 [ # # ]: 0 : REGISTER_VOID_PROP( XSD_MAX_LENGTH, m_aMaxLength, sal_Int32 );
529 : 0 : }
530 : :
531 : : //--------------------------------------------------------------------
532 [ # # ]: 0 : IMPLEMENT_DEFAULT_TYPED_CLONING( OStringType, OStringType_Base )
533 : :
534 : : //--------------------------------------------------------------------
535 : 0 : void OStringType::initializeTypedClone( const OStringType& _rCloneSource )
536 : : {
537 : 0 : m_aLength = _rCloneSource.m_aLength;
538 : 0 : m_aMinLength = _rCloneSource.m_aMinLength;
539 : 0 : m_aMaxLength = _rCloneSource.m_aMaxLength;
540 : 0 : }
541 : :
542 : : //--------------------------------------------------------------------
543 : 0 : bool OStringType::checkPropertySanity( sal_Int32 _nHandle, const Any& _rNewValue, ::rtl::OUString& _rErrorMessage )
544 : : {
545 : : // let the base class do the conversion
546 [ # # ]: 0 : if ( !OStringType_Base::checkPropertySanity( _nHandle, _rNewValue, _rErrorMessage ) )
547 : 0 : return false;
548 : :
549 : 0 : _rErrorMessage = ::rtl::OUString();
550 [ # # ]: 0 : switch ( _nHandle )
551 : : {
552 : : case PROPERTY_ID_XSD_LENGTH:
553 : : case PROPERTY_ID_XSD_MIN_LENGTH:
554 : : case PROPERTY_ID_XSD_MAX_LENGTH:
555 : : {
556 : 0 : sal_Int32 nValue( 0 );
557 : 0 : OSL_VERIFY( _rNewValue >>= nValue );
558 [ # # ]: 0 : if ( nValue <= 0 )
559 [ # # ]: 0 : _rErrorMessage = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Length limits must denote positive integer values." ) );
560 : : // TODO/eforms: localize the error message
561 : : }
562 : 0 : break;
563 : : }
564 : :
565 : 0 : return _rErrorMessage.isEmpty();
566 : : }
567 : :
568 : : //--------------------------------------------------------------------
569 : 0 : sal_uInt16 OStringType::_validate( const ::rtl::OUString& rValue )
570 : : {
571 : : // check regexp, whitespace etc. in parent class
572 : 0 : sal_uInt16 nReason = OStringType_Base::_validate( rValue );
573 : :
574 [ # # ]: 0 : if( nReason == 0 )
575 : : {
576 : : // check string constraints
577 : 0 : sal_Int32 nLength = rValue.getLength();
578 : 0 : sal_Int32 nLimit = 0;
579 [ # # ]: 0 : if ( m_aLength >>= nLimit )
580 : : {
581 [ # # ]: 0 : if ( nLimit != nLength )
582 : 0 : nReason = RID_STR_XFORMS_VALUE_LENGTH;
583 : : }
584 : : else
585 : : {
586 [ # # ][ # # ]: 0 : if ( ( m_aMaxLength >>= nLimit ) && ( nLength > nLimit ) )
[ # # ]
587 : 0 : nReason = RID_STR_XFORMS_VALUE_MAX_LENGTH;
588 [ # # ][ # # ]: 0 : else if ( ( m_aMinLength >>= nLimit ) && ( nLength < nLimit ) )
[ # # ]
589 : 0 : nReason = RID_STR_XFORMS_VALUE_MIN_LENGTH;
590 : : }
591 : : }
592 : 0 : return nReason;
593 : : }
594 : :
595 : : //--------------------------------------------------------------------
596 : 0 : ::rtl::OUString OStringType::_explainInvalid( sal_uInt16 nReason )
597 : : {
598 : 0 : sal_Int32 nValue = 0;
599 : 0 : ::rtl::OUStringBuffer sInfo;
600 [ # # # # : 0 : switch( nReason )
# ]
601 : : {
602 : : case 0:
603 : : // nothing to do!
604 : 0 : break;
605 : :
606 : : case RID_STR_XFORMS_VALUE_LENGTH:
607 [ # # ]: 0 : if( m_aLength >>= nValue )
608 [ # # ]: 0 : sInfo.append( nValue );
609 : 0 : break;
610 : :
611 : : case RID_STR_XFORMS_VALUE_MAX_LENGTH:
612 [ # # ]: 0 : if( m_aMaxLength >>= nValue )
613 [ # # ]: 0 : sInfo.append( nValue );
614 : 0 : break;
615 : :
616 : : case RID_STR_XFORMS_VALUE_MIN_LENGTH:
617 [ # # ]: 0 : if( m_aMinLength >>= nValue )
618 [ # # ]: 0 : sInfo.append( nValue );
619 : 0 : break;
620 : :
621 : : default:
622 [ # # ]: 0 : sInfo.append( OStringType_Base::_explainInvalid( nReason ) );
623 : 0 : break;
624 : : }
625 [ # # ]: 0 : return sInfo.makeStringAndClear();
626 : : }
627 : :
628 : : //====================================================================
629 : : //= OBooleanType
630 : : //====================================================================
631 : : //--------------------------------------------------------------------
632 : 0 : OBooleanType::OBooleanType( const ::rtl::OUString& _rName )
633 : 0 : :OBooleanType_Base( _rName, DataTypeClass::BOOLEAN )
634 : : {
635 : 0 : }
636 : :
637 : : //--------------------------------------------------------------------
638 [ # # ]: 0 : IMPLEMENT_DEFAULT_CLONING( OBooleanType, OBooleanType_Base )
639 : :
640 : : //--------------------------------------------------------------------
641 : 0 : void OBooleanType::initializeTypedClone( const OBooleanType& /*_rCloneSource*/ )
642 : : {
643 : 0 : }
644 : :
645 : : //--------------------------------------------------------------------
646 : 0 : sal_uInt16 OBooleanType::_validate( const ::rtl::OUString& sValue )
647 : : {
648 : 0 : sal_uInt16 nInvalidityReason = OBooleanType_Base::_validate( sValue );
649 [ # # ]: 0 : if ( nInvalidityReason )
650 : 0 : return nInvalidityReason;
651 : :
652 [ # # ][ # # ]: 0 : bool bValid = sValue == "0" || sValue == "1" || sValue == "true" || sValue == "false";
[ # # ][ # # ]
653 [ # # ]: 0 : return bValid ? 0 : RID_STR_XFORMS_INVALID_VALUE;
654 : : }
655 : :
656 : : //--------------------------------------------------------------------
657 : 0 : ::rtl::OUString OBooleanType::_explainInvalid( sal_uInt16 nReason )
658 : : {
659 [ # # ]: 0 : return ( nReason == 0 ) ? ::rtl::OUString() : getName();
660 : : }
661 : :
662 : : //====================================================================
663 : : //= ODecimalType
664 : : //====================================================================
665 : : //--------------------------------------------------------------------
666 : 0 : ODecimalType::ODecimalType( const ::rtl::OUString& _rName, sal_Int16 _nTypeClass )
667 : 0 : :ODecimalType_Base( _rName, _nTypeClass )
668 : : {
669 : 0 : }
670 : :
671 : : //--------------------------------------------------------------------
672 [ # # ]: 0 : IMPLEMENT_DEFAULT_TYPED_CLONING( ODecimalType, ODecimalType_Base )
673 : :
674 : : //--------------------------------------------------------------------
675 : 0 : void ODecimalType::initializeTypedClone( const ODecimalType& _rCloneSource )
676 : : {
677 : 0 : m_aTotalDigits = _rCloneSource.m_aTotalDigits;
678 : 0 : m_aFractionDigits = _rCloneSource.m_aFractionDigits;
679 : 0 : }
680 : :
681 : : //--------------------------------------------------------------------
682 : 0 : void ODecimalType::registerProperties()
683 : : {
684 : 0 : ODecimalType_Base::registerProperties();
685 : :
686 [ # # ]: 0 : REGISTER_VOID_PROP( XSD_TOTAL_DIGITS, m_aTotalDigits, sal_Int32 );
687 [ # # ]: 0 : REGISTER_VOID_PROP( XSD_FRACTION_DIGITS, m_aFractionDigits, sal_Int32 );
688 : 0 : }
689 : :
690 : : //--------------------------------------------------------------------
691 : :
692 : : // validate decimals and return code for which facets failed
693 : : // to be used by: ODecimalType::validate and ODecimalType::explainInvalid
694 : 0 : sal_uInt16 ODecimalType::_validate( const ::rtl::OUString& rValue )
695 : : {
696 : 0 : sal_Int16 nReason = ODecimalType_Base::_validate( rValue );
697 : :
698 : : // check digits (if no other cause is available so far)
699 [ # # ]: 0 : if( nReason == 0 )
700 : : {
701 : 0 : sal_Int32 nLength = rValue.getLength();
702 : 0 : sal_Int32 n = 0;
703 : 0 : sal_Int32 nTotalDigits = 0;
704 : 0 : sal_Int32 nFractionDigits = 0;
705 : 0 : const sal_Unicode* pValue = rValue.getStr();
706 [ # # ][ # # ]: 0 : for( ; pValue[n] != sal_Unicode('.') && n < nLength; n++ )
[ # # ]
707 [ # # ][ # # ]: 0 : if( pValue[n] >= sal_Unicode('0')
708 : 0 : && pValue[n] <= sal_Unicode('9'))
709 : 0 : nTotalDigits++;
710 [ # # ]: 0 : for( ; n < nLength; n++ )
711 [ # # ][ # # ]: 0 : if( pValue[n] >= sal_Unicode('0')
712 : 0 : && pValue[n] <= sal_Unicode('9'))
713 : 0 : nFractionDigits++;
714 : 0 : nTotalDigits += nFractionDigits;
715 : :
716 : 0 : sal_Int32 nValue = 0;
717 [ # # ][ # # ]: 0 : if( ( m_aTotalDigits >>= nValue ) && nTotalDigits > nValue )
[ # # ]
718 : 0 : nReason = RID_STR_XFORMS_VALUE_TOTAL_DIGITS;
719 [ # # ][ # # ]: 0 : else if( ( m_aFractionDigits >>= nValue ) &&
[ # # ]
720 : : ( nFractionDigits > nValue ) )
721 : 0 : nReason = RID_STR_XFORMS_VALUE_FRACTION_DIGITS;
722 : : }
723 : :
724 : 0 : return nReason;
725 : : }
726 : :
727 : : //--------------------------------------------------------------------
728 : 0 : ::rtl::OUString ODecimalType::_explainInvalid( sal_uInt16 nReason )
729 : : {
730 : 0 : sal_Int32 nValue = 0;
731 : 0 : ::rtl::OUStringBuffer sInfo;
732 [ # # # ]: 0 : switch( nReason )
733 : : {
734 : : case RID_STR_XFORMS_VALUE_TOTAL_DIGITS:
735 [ # # ]: 0 : if( m_aTotalDigits >>= nValue )
736 [ # # ]: 0 : sInfo.append( nValue );
737 : 0 : break;
738 : :
739 : : case RID_STR_XFORMS_VALUE_FRACTION_DIGITS:
740 [ # # ]: 0 : if( m_aFractionDigits >>= nValue )
741 [ # # ]: 0 : sInfo.append( nValue );
742 : 0 : break;
743 : :
744 : : default:
745 [ # # ][ # # ]: 0 : sInfo.append( ODecimalType_Base::_explainInvalid( nReason ) );
746 : 0 : break;
747 : : }
748 [ # # ]: 0 : return sInfo.makeStringAndClear();
749 : : }
750 : :
751 : : //--------------------------------------------------------------------
752 : 0 : ::rtl::OUString ODecimalType::typedValueAsHumanReadableString( const Any& _rValue ) const
753 : : {
754 : 0 : double fValue( 0 );
755 [ # # ]: 0 : normalizeValue( _rValue, fValue );
756 : 0 : return ::rtl::OUString::valueOf( fValue );
757 : : }
758 : :
759 : : //--------------------------------------------------------------------
760 : 0 : void ODecimalType::normalizeValue( const Any& _rValue, double& _rDoubleValue ) const
761 : : {
762 : 0 : OSL_VERIFY( _rValue >>= _rDoubleValue );
763 : 0 : }
764 : :
765 : : //====================================================================
766 : : //=
767 : : //====================================================================
768 : : #define DEFAULT_IMPLEMNENT_SUBTYPE( classname, typeclass ) \
769 : : classname::classname( const ::rtl::OUString& _rName ) \
770 : : :classname##_Base( _rName, DataTypeClass::typeclass ) \
771 : : { \
772 : : } \
773 : : \
774 : : IMPLEMENT_DEFAULT_CLONING( classname, classname##_Base ) \
775 : : \
776 : : void classname::initializeTypedClone( const classname& /*_rCloneSource*/ ) \
777 : : { \
778 : : } \
779 : :
780 : :
781 : : //====================================================================
782 : : //= ODateType
783 : : //====================================================================
784 : : //--------------------------------------------------------------------
785 [ # # ]: 0 : DEFAULT_IMPLEMNENT_SUBTYPE( ODateType, DATE )
786 : :
787 : : //--------------------------------------------------------------------
788 : 0 : sal_uInt16 ODateType::_validate( const ::rtl::OUString& _rValue )
789 : : {
790 : 0 : return ODateType_Base::_validate( _rValue );
791 : : }
792 : :
793 : : //--------------------------------------------------------------------
794 : 0 : bool ODateType::_getValue( const ::rtl::OUString& value, double& fValue )
795 : : {
796 [ # # ][ # # ]: 0 : Any aTypeValue = Convert::get().toAny( value, getCppuType() );
[ # # ]
797 : :
798 : 0 : Date aValue;
799 [ # # ][ # # ]: 0 : if ( !( aTypeValue >>= aValue ) )
800 : 0 : return false;
801 : :
802 : 0 : ::Date aToolsDate( aValue.Day, aValue.Month, aValue.Year );
803 : 0 : fValue = aToolsDate.GetDate();
804 : 0 : return true;
805 : : }
806 : :
807 : : //--------------------------------------------------------------------
808 : 0 : ::rtl::OUString ODateType::typedValueAsHumanReadableString( const Any& _rValue ) const
809 : : {
810 : : OSL_PRECOND( _rValue.getValueType().equals( getCppuType() ), "ODateType::typedValueAsHumanReadableString: unexpected type" );
811 : 0 : return Convert::get().toXSD( _rValue );
812 : : }
813 : :
814 : : //--------------------------------------------------------------------
815 : 0 : void ODateType::normalizeValue( const Any& _rValue, double& _rDoubleValue ) const
816 : : {
817 : 0 : Date aValue;
818 [ # # ]: 0 : OSL_VERIFY( _rValue >>= aValue );
819 : 0 : ::Date aToolsDate( aValue.Day, aValue.Month, aValue.Year );
820 : 0 : _rDoubleValue = aToolsDate.GetDate();
821 : 0 : }
822 : :
823 : : //====================================================================
824 : : //= OTimeType
825 : : //====================================================================
826 : : //--------------------------------------------------------------------
827 [ # # ]: 0 : DEFAULT_IMPLEMNENT_SUBTYPE( OTimeType, TIME )
828 : :
829 : : //--------------------------------------------------------------------
830 : 0 : sal_uInt16 OTimeType::_validate( const ::rtl::OUString& _rValue )
831 : : {
832 : 0 : return OTimeType_Base::_validate( _rValue );
833 : : }
834 : :
835 : : //--------------------------------------------------------------------
836 : 0 : bool OTimeType::_getValue( const ::rtl::OUString& value, double& fValue )
837 : : {
838 [ # # ][ # # ]: 0 : Any aTypedValue = Convert::get().toAny( value, getCppuType() );
[ # # ]
839 : :
840 : 0 : Time aValue;
841 [ # # ][ # # ]: 0 : if ( !( aTypedValue >>= aValue ) )
842 : 0 : return false;
843 : :
844 [ # # ]: 0 : ::Time aToolsTime( aValue.Hours, aValue.Minutes, aValue.Seconds, aValue.HundredthSeconds );
845 : 0 : fValue = aToolsTime.GetTime();
846 : 0 : return true;
847 : : }
848 : :
849 : : //--------------------------------------------------------------------
850 : 0 : ::rtl::OUString OTimeType::typedValueAsHumanReadableString( const Any& _rValue ) const
851 : : {
852 : : OSL_PRECOND( _rValue.getValueType().equals( getCppuType() ), "OTimeType::typedValueAsHumanReadableString: unexpected type" );
853 : 0 : return Convert::get().toXSD( _rValue );
854 : : }
855 : :
856 : : //--------------------------------------------------------------------
857 : 0 : void OTimeType::normalizeValue( const Any& _rValue, double& _rDoubleValue ) const
858 : : {
859 : 0 : Time aValue;
860 [ # # ]: 0 : OSL_VERIFY( _rValue >>= aValue );
861 [ # # ]: 0 : ::Time aToolsTime( aValue.Hours, aValue.Minutes, aValue.Seconds, aValue.HundredthSeconds );
862 : 0 : _rDoubleValue = aToolsTime.GetTime();
863 : 0 : }
864 : :
865 : : //====================================================================
866 : : //= ODateTimeType
867 : : //====================================================================
868 : : //--------------------------------------------------------------------
869 [ # # ]: 0 : DEFAULT_IMPLEMNENT_SUBTYPE( ODateTimeType, DATETIME )
870 : :
871 : : //--------------------------------------------------------------------
872 : 0 : sal_uInt16 ODateTimeType::_validate( const ::rtl::OUString& _rValue )
873 : : {
874 : 0 : return ODateTimeType_Base::_validate( _rValue );
875 : : }
876 : :
877 : : //--------------------------------------------------------------------
878 : : namespace
879 : : {
880 : 0 : double lcl_normalizeDateTime( const DateTime& _rValue )
881 : : {
882 : : ::DateTime aToolsValue(
883 : : ::Date( _rValue.Day, _rValue.Month, _rValue.Year ),
884 : : ::Time( _rValue.Hours, _rValue.Minutes, _rValue.Seconds, _rValue.HundredthSeconds )
885 [ # # ][ # # ]: 0 : );
886 : :
887 : 0 : double fValue = 0;
888 : : // days since 1.1.1900 (which is relatively arbitrary but fixed date)
889 [ # # ]: 0 : fValue += ::Date( aToolsValue ) - ::Date( 1, 1, 1900 );
890 : : // time
891 [ # # ]: 0 : fValue += aToolsValue.GetTimeInDays();
892 : 0 : return fValue;
893 : : }
894 : : }
895 : :
896 : : //--------------------------------------------------------------------
897 : 0 : bool ODateTimeType::_getValue( const ::rtl::OUString& value, double& fValue )
898 : : {
899 [ # # ][ # # ]: 0 : Any aTypedValue = Convert::get().toAny( value, getCppuType() );
[ # # ]
900 : :
901 : 0 : DateTime aValue;
902 [ # # ][ # # ]: 0 : if ( !( aTypedValue >>= aValue ) )
903 : 0 : return false;
904 : :
905 [ # # ]: 0 : fValue = lcl_normalizeDateTime( aValue );
906 : 0 : return true;
907 : : }
908 : :
909 : : //--------------------------------------------------------------------
910 : 0 : ::rtl::OUString ODateTimeType::typedValueAsHumanReadableString( const Any& _rValue ) const
911 : : {
912 : : OSL_PRECOND( _rValue.getValueType().equals( getCppuType() ), "OTimeType::typedValueAsHumanReadableString: unexpected type" );
913 [ # # ][ # # ]: 0 : ::rtl::OUString sString = Convert::get().toXSD( _rValue );
914 : :
915 : : // ISO 8601 notation has a "T" to separate between date and time. Our only concession
916 : : // to the "human readable" in the method name is to replace this T with a whitespace.
917 : : OSL_ENSURE( sString.indexOf( 'T' ) != -1, "ODateTimeType::typedValueAsHumanReadableString: hmm - no ISO notation?" );
918 : 0 : return sString.replace( 'T', ' ' );
919 : : }
920 : :
921 : : //--------------------------------------------------------------------
922 : 0 : void ODateTimeType::normalizeValue( const Any& _rValue, double& _rDoubleValue ) const
923 : : {
924 : 0 : DateTime aValue;
925 [ # # ]: 0 : OSL_VERIFY( _rValue >>= aValue );
926 [ # # ]: 0 : _rDoubleValue = lcl_normalizeDateTime( aValue );
927 : 0 : }
928 : :
929 : : //====================================================================
930 : : //= OShortIntegerType
931 : : //====================================================================
932 : : //--------------------------------------------------------------------
933 : 0 : OShortIntegerType::OShortIntegerType( const ::rtl::OUString& _rName, sal_Int16 _nTypeClass )
934 : 0 : :OShortIntegerType_Base( _rName, _nTypeClass )
935 : : {
936 : 0 : }
937 : :
938 : : //--------------------------------------------------------------------
939 [ # # ]: 0 : IMPLEMENT_DEFAULT_TYPED_CLONING( OShortIntegerType, OShortIntegerType_Base )
940 : :
941 : : //--------------------------------------------------------------------
942 : 0 : void OShortIntegerType::initializeTypedClone( const OShortIntegerType& /*_rCloneSource*/ )
943 : : {
944 : 0 : }
945 : :
946 : : //--------------------------------------------------------------------
947 : 0 : bool OShortIntegerType::_getValue( const ::rtl::OUString& value, double& fValue )
948 : : {
949 : 0 : fValue = (double)(sal_Int16)value.toInt32();
950 : : // TODO/eforms
951 : : // this does not care for values which do not fit into a sal_Int16, but simply
952 : : // cuts them down. A better implementation here should probably return <FALSE/>
953 : : // for those values.
954 : : // Else, we may have a situation where the UI claims an input to be valid
955 : : // (say "12345678"), while internally, and at submission time, this is cut to
956 : : // some smaller value.
957 : : //
958 : : // Additionally, this of course does not care for strings which are no numers ...
959 : 0 : return true;
960 : : }
961 : :
962 : : //--------------------------------------------------------------------
963 : 0 : ::rtl::OUString OShortIntegerType::typedValueAsHumanReadableString( const Any& _rValue ) const
964 : : {
965 : 0 : sal_Int16 nValue( 0 );
966 : 0 : OSL_VERIFY( _rValue >>= nValue );
967 : 0 : return ::rtl::OUString::valueOf( (sal_Int32)nValue );
968 : : }
969 : :
970 : : //--------------------------------------------------------------------
971 : 0 : void OShortIntegerType::normalizeValue( const Any& _rValue, double& _rDoubleValue ) const
972 : : {
973 : 0 : sal_Int16 nValue( 0 );
974 : 0 : OSL_VERIFY( _rValue >>= nValue );
975 : 0 : _rDoubleValue = nValue;
976 : 0 : }
977 : : //====================================================================
978 : : //====================================================================
979 : :
980 : : #define DATATYPES_INCLUDED_BY_MASTER_HEADER
981 : : #include "datatypes_impl.hxx"
982 : : #undef DATATYPES_INCLUDED_BY_MASTER_HEADER
983 : :
984 : : //........................................................................
985 : : } // namespace xforms
986 : : //........................................................................
987 : :
988 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|