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