1*2f86921cSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*2f86921cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*2f86921cSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*2f86921cSAndrew Rist * distributed with this work for additional information 6*2f86921cSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*2f86921cSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*2f86921cSAndrew Rist * "License"); you may not use this file except in compliance 9*2f86921cSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*2f86921cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*2f86921cSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*2f86921cSAndrew Rist * software distributed under the License is distributed on an 15*2f86921cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*2f86921cSAndrew Rist * KIND, either express or implied. See the License for the 17*2f86921cSAndrew Rist * specific language governing permissions and limitations 18*2f86921cSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*2f86921cSAndrew Rist *************************************************************/ 21*2f86921cSAndrew Rist 22*2f86921cSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_ucb.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <string.h> 28cdf0e10cSrcweir #include <ne_xml.h> 29cdf0e10cSrcweir #include <osl/diagnose.h> 30cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 31cdf0e10cSrcweir #include "UCBDeadPropertyValue.hxx" 32cdf0e10cSrcweir 33cdf0e10cSrcweir using namespace webdav_ucp; 34cdf0e10cSrcweir using namespace com::sun::star; 35cdf0e10cSrcweir 36cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////// 37cdf0e10cSrcweir 38cdf0e10cSrcweir struct UCBDeadPropertyValueParseContext 39cdf0e10cSrcweir { 40cdf0e10cSrcweir rtl::OUString * pType; 41cdf0e10cSrcweir rtl::OUString * pValue; 42cdf0e10cSrcweir 43cdf0e10cSrcweir UCBDeadPropertyValueParseContext() : pType( 0 ), pValue( 0 ) {} 44cdf0e10cSrcweir ~UCBDeadPropertyValueParseContext() { delete pType; delete pValue; } 45cdf0e10cSrcweir }; 46cdf0e10cSrcweir 47cdf0e10cSrcweir // static 48cdf0e10cSrcweir const rtl::OUString UCBDeadPropertyValue::aTypeString 49cdf0e10cSrcweir = rtl::OUString::createFromAscii( "string" ); 50cdf0e10cSrcweir const rtl::OUString UCBDeadPropertyValue::aTypeLong 51cdf0e10cSrcweir = rtl::OUString::createFromAscii( "long" ); 52cdf0e10cSrcweir const rtl::OUString UCBDeadPropertyValue::aTypeShort 53cdf0e10cSrcweir = rtl::OUString::createFromAscii( "short" ); 54cdf0e10cSrcweir const rtl::OUString UCBDeadPropertyValue::aTypeBoolean 55cdf0e10cSrcweir = rtl::OUString::createFromAscii( "boolean" ); 56cdf0e10cSrcweir const rtl::OUString UCBDeadPropertyValue::aTypeChar 57cdf0e10cSrcweir = rtl::OUString::createFromAscii( "char" ); 58cdf0e10cSrcweir const rtl::OUString UCBDeadPropertyValue::aTypeByte 59cdf0e10cSrcweir = rtl::OUString::createFromAscii( "byte" ); 60cdf0e10cSrcweir const rtl::OUString UCBDeadPropertyValue::aTypeHyper 61cdf0e10cSrcweir = rtl::OUString::createFromAscii( "hyper" ); 62cdf0e10cSrcweir const rtl::OUString UCBDeadPropertyValue::aTypeFloat 63cdf0e10cSrcweir = rtl::OUString::createFromAscii( "float" ); 64cdf0e10cSrcweir const rtl::OUString UCBDeadPropertyValue::aTypeDouble 65cdf0e10cSrcweir = rtl::OUString::createFromAscii( "double" ); 66cdf0e10cSrcweir 67cdf0e10cSrcweir // static 68cdf0e10cSrcweir const rtl::OUString UCBDeadPropertyValue::aXMLPre 69cdf0e10cSrcweir = rtl::OUString::createFromAscii( "<ucbprop><type>" ); 70cdf0e10cSrcweir const rtl::OUString UCBDeadPropertyValue::aXMLMid 71cdf0e10cSrcweir = rtl::OUString::createFromAscii( "</type><value>" ); 72cdf0e10cSrcweir const rtl::OUString UCBDeadPropertyValue::aXMLEnd 73cdf0e10cSrcweir = rtl::OUString::createFromAscii( "</value></ucbprop>" ); 74cdf0e10cSrcweir 75cdf0e10cSrcweir #define STATE_TOP (1) 76cdf0e10cSrcweir 77cdf0e10cSrcweir #define STATE_UCBPROP (STATE_TOP) 78cdf0e10cSrcweir #define STATE_TYPE (STATE_TOP + 1) 79cdf0e10cSrcweir #define STATE_VALUE (STATE_TOP + 2) 80cdf0e10cSrcweir 81cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////// 82cdf0e10cSrcweir extern "C" int UCBDeadPropertyValue_startelement_callback( 83cdf0e10cSrcweir void *, 84cdf0e10cSrcweir int parent, 85cdf0e10cSrcweir const char * /*nspace*/, 86cdf0e10cSrcweir const char *name, 87cdf0e10cSrcweir const char ** ) 88cdf0e10cSrcweir { 89cdf0e10cSrcweir if ( name != 0 ) 90cdf0e10cSrcweir { 91cdf0e10cSrcweir switch ( parent ) 92cdf0e10cSrcweir { 93cdf0e10cSrcweir case NE_XML_STATEROOT: 94cdf0e10cSrcweir if ( strcmp( name, "ucbprop" ) == 0 ) 95cdf0e10cSrcweir return STATE_UCBPROP; 96cdf0e10cSrcweir break; 97cdf0e10cSrcweir 98cdf0e10cSrcweir case STATE_UCBPROP: 99cdf0e10cSrcweir if ( strcmp( name, "type" ) == 0 ) 100cdf0e10cSrcweir return STATE_TYPE; 101cdf0e10cSrcweir else if ( strcmp( name, "value" ) == 0 ) 102cdf0e10cSrcweir return STATE_VALUE; 103cdf0e10cSrcweir break; 104cdf0e10cSrcweir } 105cdf0e10cSrcweir } 106cdf0e10cSrcweir return NE_XML_DECLINE; 107cdf0e10cSrcweir } 108cdf0e10cSrcweir 109cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////// 110cdf0e10cSrcweir extern "C" int UCBDeadPropertyValue_chardata_callback( 111cdf0e10cSrcweir void *userdata, 112cdf0e10cSrcweir int state, 113cdf0e10cSrcweir const char *buf, 114cdf0e10cSrcweir size_t len ) 115cdf0e10cSrcweir { 116cdf0e10cSrcweir UCBDeadPropertyValueParseContext * pCtx 117cdf0e10cSrcweir = static_cast< UCBDeadPropertyValueParseContext * >( userdata ); 118cdf0e10cSrcweir 119cdf0e10cSrcweir switch ( state ) 120cdf0e10cSrcweir { 121cdf0e10cSrcweir case STATE_TYPE: 122cdf0e10cSrcweir OSL_ENSURE( !pCtx->pType, 123cdf0e10cSrcweir "UCBDeadPropertyValue_endelement_callback - " 124cdf0e10cSrcweir "Type already set!" ); 125cdf0e10cSrcweir pCtx->pType 126cdf0e10cSrcweir = new rtl::OUString( buf, len, RTL_TEXTENCODING_ASCII_US ); 127cdf0e10cSrcweir break; 128cdf0e10cSrcweir 129cdf0e10cSrcweir case STATE_VALUE: 130cdf0e10cSrcweir OSL_ENSURE( !pCtx->pValue, 131cdf0e10cSrcweir "UCBDeadPropertyValue_endelement_callback - " 132cdf0e10cSrcweir "Value already set!" ); 133cdf0e10cSrcweir pCtx->pValue 134cdf0e10cSrcweir = new rtl::OUString( buf, len, RTL_TEXTENCODING_ASCII_US ); 135cdf0e10cSrcweir break; 136cdf0e10cSrcweir } 137cdf0e10cSrcweir return 0; // zero to continue, non-zero to abort parsing 138cdf0e10cSrcweir } 139cdf0e10cSrcweir 140cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////// 141cdf0e10cSrcweir extern "C" int UCBDeadPropertyValue_endelement_callback( 142cdf0e10cSrcweir void *userdata, 143cdf0e10cSrcweir int state, 144cdf0e10cSrcweir const char *, 145cdf0e10cSrcweir const char * ) 146cdf0e10cSrcweir { 147cdf0e10cSrcweir UCBDeadPropertyValueParseContext * pCtx 148cdf0e10cSrcweir = static_cast< UCBDeadPropertyValueParseContext * >( userdata ); 149cdf0e10cSrcweir 150cdf0e10cSrcweir switch ( state ) 151cdf0e10cSrcweir { 152cdf0e10cSrcweir case STATE_TYPE: 153cdf0e10cSrcweir if ( !pCtx->pType ) 154cdf0e10cSrcweir return 1; // abort 155cdf0e10cSrcweir break; 156cdf0e10cSrcweir 157cdf0e10cSrcweir case STATE_VALUE: 158cdf0e10cSrcweir if ( !pCtx->pValue ) 159cdf0e10cSrcweir return 1; // abort 160cdf0e10cSrcweir break; 161cdf0e10cSrcweir 162cdf0e10cSrcweir case STATE_UCBPROP: 163cdf0e10cSrcweir if ( !pCtx->pType || ! pCtx->pValue ) 164cdf0e10cSrcweir return 1; // abort 165cdf0e10cSrcweir break; 166cdf0e10cSrcweir } 167cdf0e10cSrcweir return 0; // zero to continue, non-zero to abort parsing 168cdf0e10cSrcweir } 169cdf0e10cSrcweir 170cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////// 171cdf0e10cSrcweir static rtl::OUString encodeValue( const rtl::OUString & rValue ) 172cdf0e10cSrcweir { 173cdf0e10cSrcweir // Note: I do not use the usual & + < + > encoding, because 174cdf0e10cSrcweir // I want to prevent any XML parser from trying to 'understand' 175cdf0e10cSrcweir // the value. This caused problems: 176cdf0e10cSrcweir // 177cdf0e10cSrcweir // Example: 178cdf0e10cSrcweir // - Unencoded property value: x<z 179cdf0e10cSrcweir // PROPPATCH: 180cdf0e10cSrcweir // - Encoded property value: x<z 181cdf0e10cSrcweir // - UCBDeadPropertyValue::toXML result: 182cdf0e10cSrcweir // <ucbprop><type>string</type><value>x<z</value></ucbprop> 183cdf0e10cSrcweir // PROPFIND: 184cdf0e10cSrcweir // - parser replaces < by > ==> error (not well formed) 185cdf0e10cSrcweir 186cdf0e10cSrcweir rtl::OUStringBuffer aResult; 187cdf0e10cSrcweir const sal_Unicode * pValue = rValue.getStr(); 188cdf0e10cSrcweir 189cdf0e10cSrcweir sal_Int32 nCount = rValue.getLength(); 190cdf0e10cSrcweir for ( sal_Int32 n = 0; n < nCount; ++n ) 191cdf0e10cSrcweir { 192cdf0e10cSrcweir const sal_Unicode c = pValue[ n ]; 193cdf0e10cSrcweir 194cdf0e10cSrcweir if ( '%' == c ) 195cdf0e10cSrcweir aResult.appendAscii( "%per;" ); 196cdf0e10cSrcweir else if ( '<' == c ) 197cdf0e10cSrcweir aResult.appendAscii( "%lt;" ); 198cdf0e10cSrcweir else if ( '>' == c ) 199cdf0e10cSrcweir aResult.appendAscii( "%gt;" ); 200cdf0e10cSrcweir else 201cdf0e10cSrcweir aResult.append( c ); 202cdf0e10cSrcweir } 203cdf0e10cSrcweir return rtl::OUString( aResult ); 204cdf0e10cSrcweir } 205cdf0e10cSrcweir 206cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////// 207cdf0e10cSrcweir static rtl::OUString decodeValue( const rtl::OUString & rValue ) 208cdf0e10cSrcweir { 209cdf0e10cSrcweir rtl::OUStringBuffer aResult; 210cdf0e10cSrcweir const sal_Unicode * pValue = rValue.getStr(); 211cdf0e10cSrcweir 212cdf0e10cSrcweir sal_Int32 nPos = 0; 213cdf0e10cSrcweir sal_Int32 nEnd = rValue.getLength(); 214cdf0e10cSrcweir 215cdf0e10cSrcweir while ( nPos < nEnd ) 216cdf0e10cSrcweir { 217cdf0e10cSrcweir sal_Unicode c = pValue[ nPos ]; 218cdf0e10cSrcweir 219cdf0e10cSrcweir if ( '%' == c ) 220cdf0e10cSrcweir { 221cdf0e10cSrcweir nPos++; 222cdf0e10cSrcweir 223cdf0e10cSrcweir if ( nPos == nEnd ) 224cdf0e10cSrcweir { 225cdf0e10cSrcweir OSL_ENSURE( sal_False, 226cdf0e10cSrcweir "UCBDeadPropertyValue::decodeValue - syntax error!" ); 227cdf0e10cSrcweir return rtl::OUString(); 228cdf0e10cSrcweir } 229cdf0e10cSrcweir 230cdf0e10cSrcweir c = pValue[ nPos ]; 231cdf0e10cSrcweir 232cdf0e10cSrcweir if ( 'p' == c ) 233cdf0e10cSrcweir { 234cdf0e10cSrcweir // %per; 235cdf0e10cSrcweir 236cdf0e10cSrcweir if ( nPos > nEnd - 4 ) 237cdf0e10cSrcweir { 238cdf0e10cSrcweir OSL_ENSURE( sal_False, 239cdf0e10cSrcweir "UCBDeadPropertyValue::decodeValue - syntax error!" ); 240cdf0e10cSrcweir return rtl::OUString(); 241cdf0e10cSrcweir } 242cdf0e10cSrcweir 243cdf0e10cSrcweir if ( ( 'e' == pValue[ nPos + 1 ] ) 244cdf0e10cSrcweir && 245cdf0e10cSrcweir ( 'r' == pValue[ nPos + 2 ] ) 246cdf0e10cSrcweir && 247cdf0e10cSrcweir ( ';' == pValue[ nPos + 3 ] ) ) 248cdf0e10cSrcweir { 249cdf0e10cSrcweir aResult.append( sal_Unicode( '%' ) ); 250cdf0e10cSrcweir nPos += 3; 251cdf0e10cSrcweir } 252cdf0e10cSrcweir else 253cdf0e10cSrcweir { 254cdf0e10cSrcweir OSL_ENSURE( sal_False, 255cdf0e10cSrcweir "UCBDeadPropertyValue::decodeValue - syntax error!" ); 256cdf0e10cSrcweir return rtl::OUString(); 257cdf0e10cSrcweir } 258cdf0e10cSrcweir } 259cdf0e10cSrcweir else if ( 'l' == c ) 260cdf0e10cSrcweir { 261cdf0e10cSrcweir // %lt; 262cdf0e10cSrcweir 263cdf0e10cSrcweir if ( nPos > nEnd - 3 ) 264cdf0e10cSrcweir { 265cdf0e10cSrcweir OSL_ENSURE( sal_False, 266cdf0e10cSrcweir "UCBDeadPropertyValue::decodeValue - syntax error!" ); 267cdf0e10cSrcweir return rtl::OUString(); 268cdf0e10cSrcweir } 269cdf0e10cSrcweir 270cdf0e10cSrcweir if ( ( 't' == pValue[ nPos + 1 ] ) 271cdf0e10cSrcweir && 272cdf0e10cSrcweir ( ';' == pValue[ nPos + 2 ] ) ) 273cdf0e10cSrcweir { 274cdf0e10cSrcweir aResult.append( sal_Unicode( '<' ) ); 275cdf0e10cSrcweir nPos += 2; 276cdf0e10cSrcweir } 277cdf0e10cSrcweir else 278cdf0e10cSrcweir { 279cdf0e10cSrcweir OSL_ENSURE( sal_False, 280cdf0e10cSrcweir "UCBDeadPropertyValue::decodeValue - syntax error!" ); 281cdf0e10cSrcweir return rtl::OUString(); 282cdf0e10cSrcweir } 283cdf0e10cSrcweir } 284cdf0e10cSrcweir else if ( 'g' == c ) 285cdf0e10cSrcweir { 286cdf0e10cSrcweir // %gt; 287cdf0e10cSrcweir 288cdf0e10cSrcweir if ( nPos > nEnd - 3 ) 289cdf0e10cSrcweir { 290cdf0e10cSrcweir OSL_ENSURE( sal_False, 291cdf0e10cSrcweir "UCBDeadPropertyValue::decodeValue - syntax error!" ); 292cdf0e10cSrcweir return rtl::OUString(); 293cdf0e10cSrcweir } 294cdf0e10cSrcweir 295cdf0e10cSrcweir if ( ( 't' == pValue[ nPos + 1 ] ) 296cdf0e10cSrcweir && 297cdf0e10cSrcweir ( ';' == pValue[ nPos + 2 ] ) ) 298cdf0e10cSrcweir { 299cdf0e10cSrcweir aResult.append( sal_Unicode( '>' ) ); 300cdf0e10cSrcweir nPos += 2; 301cdf0e10cSrcweir } 302cdf0e10cSrcweir else 303cdf0e10cSrcweir { 304cdf0e10cSrcweir OSL_ENSURE( sal_False, 305cdf0e10cSrcweir "UCBDeadPropertyValue::decodeValue - syntax error!" ); 306cdf0e10cSrcweir return rtl::OUString(); 307cdf0e10cSrcweir } 308cdf0e10cSrcweir } 309cdf0e10cSrcweir else 310cdf0e10cSrcweir { 311cdf0e10cSrcweir OSL_ENSURE( sal_False, 312cdf0e10cSrcweir "UCBDeadPropertyValue::decodeValue - syntax error!" ); 313cdf0e10cSrcweir return rtl::OUString(); 314cdf0e10cSrcweir } 315cdf0e10cSrcweir } 316cdf0e10cSrcweir else 317cdf0e10cSrcweir aResult.append( c ); 318cdf0e10cSrcweir 319cdf0e10cSrcweir nPos++; 320cdf0e10cSrcweir } 321cdf0e10cSrcweir 322cdf0e10cSrcweir return rtl::OUString( aResult ); 323cdf0e10cSrcweir } 324cdf0e10cSrcweir 325cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////// 326cdf0e10cSrcweir // static 327cdf0e10cSrcweir bool UCBDeadPropertyValue::supportsType( const uno::Type & rType ) 328cdf0e10cSrcweir { 329cdf0e10cSrcweir if ( ( rType != getCppuType( static_cast< const rtl::OUString * >( 0 ) ) ) 330cdf0e10cSrcweir && 331cdf0e10cSrcweir ( rType != getCppuType( static_cast< const sal_Int32 * >( 0 ) ) ) 332cdf0e10cSrcweir && 333cdf0e10cSrcweir ( rType != getCppuType( static_cast< const sal_Int16 * >( 0 ) ) ) 334cdf0e10cSrcweir && 335cdf0e10cSrcweir ( rType != getCppuBooleanType() ) 336cdf0e10cSrcweir && 337cdf0e10cSrcweir ( rType != getCppuCharType() ) 338cdf0e10cSrcweir && 339cdf0e10cSrcweir ( rType != getCppuType( static_cast< const sal_Int8 * >( 0 ) ) ) 340cdf0e10cSrcweir && 341cdf0e10cSrcweir ( rType != getCppuType( static_cast< const sal_Int64 * >( 0 ) ) ) 342cdf0e10cSrcweir && 343cdf0e10cSrcweir ( rType != getCppuType( static_cast< const float * >( 0 ) ) ) 344cdf0e10cSrcweir && 345cdf0e10cSrcweir ( rType != getCppuType( static_cast< const double * >( 0 ) ) ) ) 346cdf0e10cSrcweir { 347cdf0e10cSrcweir return false; 348cdf0e10cSrcweir } 349cdf0e10cSrcweir 350cdf0e10cSrcweir return true; 351cdf0e10cSrcweir } 352cdf0e10cSrcweir 353cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////// 354cdf0e10cSrcweir // static 355cdf0e10cSrcweir bool UCBDeadPropertyValue::createFromXML( const rtl::OString & rInData, 356cdf0e10cSrcweir uno::Any & rOutData ) 357cdf0e10cSrcweir { 358cdf0e10cSrcweir bool success = false; 359cdf0e10cSrcweir 360cdf0e10cSrcweir ne_xml_parser * parser = ne_xml_create(); 361cdf0e10cSrcweir if ( parser ) 362cdf0e10cSrcweir { 363cdf0e10cSrcweir UCBDeadPropertyValueParseContext aCtx; 364cdf0e10cSrcweir ne_xml_push_handler( parser, 365cdf0e10cSrcweir UCBDeadPropertyValue_startelement_callback, 366cdf0e10cSrcweir UCBDeadPropertyValue_chardata_callback, 367cdf0e10cSrcweir UCBDeadPropertyValue_endelement_callback, 368cdf0e10cSrcweir &aCtx ); 369cdf0e10cSrcweir 370cdf0e10cSrcweir ne_xml_parse( parser, rInData.getStr(), rInData.getLength() ); 371cdf0e10cSrcweir 372cdf0e10cSrcweir success = !ne_xml_failed( parser ); 373cdf0e10cSrcweir 374cdf0e10cSrcweir ne_xml_destroy( parser ); 375cdf0e10cSrcweir 376cdf0e10cSrcweir if ( success ) 377cdf0e10cSrcweir { 378cdf0e10cSrcweir if ( aCtx.pType && aCtx.pValue ) 379cdf0e10cSrcweir { 380cdf0e10cSrcweir // Decode aCtx.pValue! It may contain XML reserved chars. 381cdf0e10cSrcweir rtl::OUString aStringValue = decodeValue( *aCtx.pValue ); 382cdf0e10cSrcweir if ( aCtx.pType->equalsIgnoreAsciiCase( aTypeString ) ) 383cdf0e10cSrcweir { 384cdf0e10cSrcweir rOutData <<= aStringValue; 385cdf0e10cSrcweir } 386cdf0e10cSrcweir else if ( aCtx.pType->equalsIgnoreAsciiCase( aTypeLong ) ) 387cdf0e10cSrcweir { 388cdf0e10cSrcweir rOutData <<= aStringValue.toInt32(); 389cdf0e10cSrcweir } 390cdf0e10cSrcweir else if ( aCtx.pType->equalsIgnoreAsciiCase( aTypeShort ) ) 391cdf0e10cSrcweir { 392cdf0e10cSrcweir rOutData <<= sal_Int16( aStringValue.toInt32() ); 393cdf0e10cSrcweir } 394cdf0e10cSrcweir else if ( aCtx.pType->equalsIgnoreAsciiCase( aTypeBoolean ) ) 395cdf0e10cSrcweir { 396cdf0e10cSrcweir if ( aStringValue.equalsIgnoreAsciiCase( 397cdf0e10cSrcweir rtl::OUString::createFromAscii( "true" ) ) ) 398cdf0e10cSrcweir rOutData <<= sal_Bool( sal_True ); 399cdf0e10cSrcweir else 400cdf0e10cSrcweir rOutData <<= sal_Bool( sal_False ); 401cdf0e10cSrcweir } 402cdf0e10cSrcweir else if ( aCtx.pType->equalsIgnoreAsciiCase( aTypeChar ) ) 403cdf0e10cSrcweir { 404cdf0e10cSrcweir rOutData <<= aStringValue.toChar(); 405cdf0e10cSrcweir } 406cdf0e10cSrcweir else if ( aCtx.pType->equalsIgnoreAsciiCase( aTypeByte ) ) 407cdf0e10cSrcweir { 408cdf0e10cSrcweir rOutData <<= sal_Int8( aStringValue.toChar() ); 409cdf0e10cSrcweir } 410cdf0e10cSrcweir else if ( aCtx.pType->equalsIgnoreAsciiCase( aTypeHyper ) ) 411cdf0e10cSrcweir { 412cdf0e10cSrcweir rOutData <<= aStringValue.toInt64(); 413cdf0e10cSrcweir } 414cdf0e10cSrcweir else if ( aCtx.pType->equalsIgnoreAsciiCase( aTypeFloat ) ) 415cdf0e10cSrcweir { 416cdf0e10cSrcweir rOutData <<= aStringValue.toFloat(); 417cdf0e10cSrcweir } 418cdf0e10cSrcweir else if ( aCtx.pType->equalsIgnoreAsciiCase( aTypeDouble ) ) 419cdf0e10cSrcweir { 420cdf0e10cSrcweir rOutData <<= aStringValue.toDouble(); 421cdf0e10cSrcweir } 422cdf0e10cSrcweir else 423cdf0e10cSrcweir { 424cdf0e10cSrcweir OSL_ENSURE( sal_False, 425cdf0e10cSrcweir "UCBDeadPropertyValue::createFromXML - " 426cdf0e10cSrcweir "Unsupported property type!" ); 427cdf0e10cSrcweir success = false; 428cdf0e10cSrcweir } 429cdf0e10cSrcweir } 430cdf0e10cSrcweir else 431cdf0e10cSrcweir success = false; 432cdf0e10cSrcweir } 433cdf0e10cSrcweir } 434cdf0e10cSrcweir 435cdf0e10cSrcweir return success; 436cdf0e10cSrcweir } 437cdf0e10cSrcweir 438cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////// 439cdf0e10cSrcweir // static 440cdf0e10cSrcweir bool UCBDeadPropertyValue::toXML( const uno::Any & rInData, 441cdf0e10cSrcweir rtl::OUString & rOutData ) 442cdf0e10cSrcweir { 443cdf0e10cSrcweir // <ucbprop><type>the_type</type><value>the_value</value></ucbprop> 444cdf0e10cSrcweir 445cdf0e10cSrcweir // Check property type. Extract type and value as string. 446cdf0e10cSrcweir 447cdf0e10cSrcweir const uno::Type& rType = rInData.getValueType(); 448cdf0e10cSrcweir rtl::OUString aStringValue; 449cdf0e10cSrcweir rtl::OUString aStringType; 450cdf0e10cSrcweir 451cdf0e10cSrcweir if ( rType == getCppuType( static_cast< const rtl::OUString * >( 0 ) ) ) 452cdf0e10cSrcweir { 453cdf0e10cSrcweir // string 454cdf0e10cSrcweir rInData >>= aStringValue; 455cdf0e10cSrcweir aStringType = aTypeString; 456cdf0e10cSrcweir } 457cdf0e10cSrcweir else if ( rType == getCppuType( static_cast< const sal_Int32 * >( 0 ) ) ) 458cdf0e10cSrcweir { 459cdf0e10cSrcweir // long 460cdf0e10cSrcweir sal_Int32 nValue = 0; 461cdf0e10cSrcweir rInData >>= nValue; 462cdf0e10cSrcweir aStringValue = rtl::OUString::valueOf( nValue ); 463cdf0e10cSrcweir aStringType = aTypeLong; 464cdf0e10cSrcweir } 465cdf0e10cSrcweir else if ( rType == getCppuType( static_cast< const sal_Int16 * >( 0 ) ) ) 466cdf0e10cSrcweir { 467cdf0e10cSrcweir // short 468cdf0e10cSrcweir sal_Int32 nValue = 0; 469cdf0e10cSrcweir rInData >>= nValue; 470cdf0e10cSrcweir aStringValue = rtl::OUString::valueOf( nValue ); 471cdf0e10cSrcweir aStringType = aTypeShort; 472cdf0e10cSrcweir } 473cdf0e10cSrcweir else if ( rType == getCppuBooleanType() ) 474cdf0e10cSrcweir { 475cdf0e10cSrcweir // boolean 476cdf0e10cSrcweir sal_Bool bValue = false; 477cdf0e10cSrcweir rInData >>= bValue; 478cdf0e10cSrcweir aStringValue = rtl::OUString::valueOf( bValue ); 479cdf0e10cSrcweir aStringType = aTypeBoolean; 480cdf0e10cSrcweir } 481cdf0e10cSrcweir else if ( rType == getCppuCharType() ) 482cdf0e10cSrcweir { 483cdf0e10cSrcweir // char 484cdf0e10cSrcweir sal_Unicode cValue = 0; 485cdf0e10cSrcweir rInData >>= cValue; 486cdf0e10cSrcweir aStringValue = rtl::OUString::valueOf( cValue ); 487cdf0e10cSrcweir aStringType = aTypeChar; 488cdf0e10cSrcweir } 489cdf0e10cSrcweir else if ( rType == getCppuType( static_cast< const sal_Int8 * >( 0 ) ) ) 490cdf0e10cSrcweir { 491cdf0e10cSrcweir // byte 492cdf0e10cSrcweir sal_Int8 nValue = 0; 493cdf0e10cSrcweir rInData >>= nValue; 494cdf0e10cSrcweir aStringValue = rtl::OUString::valueOf( sal_Unicode( nValue ) ); 495cdf0e10cSrcweir aStringType = aTypeByte; 496cdf0e10cSrcweir } 497cdf0e10cSrcweir else if ( rType == getCppuType( static_cast< const sal_Int64 * >( 0 ) ) ) 498cdf0e10cSrcweir { 499cdf0e10cSrcweir // hyper 500cdf0e10cSrcweir sal_Int64 nValue = 0; 501cdf0e10cSrcweir rInData >>= nValue; 502cdf0e10cSrcweir aStringValue = rtl::OUString::valueOf( nValue ); 503cdf0e10cSrcweir aStringType = aTypeHyper; 504cdf0e10cSrcweir } 505cdf0e10cSrcweir else if ( rType == getCppuType( static_cast< const float * >( 0 ) ) ) 506cdf0e10cSrcweir { 507cdf0e10cSrcweir // float 508cdf0e10cSrcweir float nValue = 0; 509cdf0e10cSrcweir rInData >>= nValue; 510cdf0e10cSrcweir aStringValue = rtl::OUString::valueOf( nValue ); 511cdf0e10cSrcweir aStringType = aTypeFloat; 512cdf0e10cSrcweir } 513cdf0e10cSrcweir else if ( rType == getCppuType( static_cast< const double * >( 0 ) ) ) 514cdf0e10cSrcweir { 515cdf0e10cSrcweir // double 516cdf0e10cSrcweir double nValue = 0; 517cdf0e10cSrcweir rInData >>= nValue; 518cdf0e10cSrcweir aStringValue = rtl::OUString::valueOf( nValue ); 519cdf0e10cSrcweir aStringType = aTypeDouble; 520cdf0e10cSrcweir } 521cdf0e10cSrcweir else 522cdf0e10cSrcweir { 523cdf0e10cSrcweir OSL_ENSURE( sal_False, 524cdf0e10cSrcweir "UCBDeadPropertyValue::toXML - " 525cdf0e10cSrcweir "Unsupported property type!" ); 526cdf0e10cSrcweir return false; 527cdf0e10cSrcweir } 528cdf0e10cSrcweir 529cdf0e10cSrcweir // Encode value! It must not contain XML reserved chars! 530cdf0e10cSrcweir aStringValue = encodeValue( aStringValue ); 531cdf0e10cSrcweir 532cdf0e10cSrcweir rOutData = aXMLPre; 533cdf0e10cSrcweir rOutData += aStringType; 534cdf0e10cSrcweir rOutData += aXMLMid; 535cdf0e10cSrcweir rOutData += aStringValue; 536cdf0e10cSrcweir rOutData += aXMLEnd; 537cdf0e10cSrcweir 538cdf0e10cSrcweir return true; 539cdf0e10cSrcweir } 540