1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 // MARKER(update_precomp.py): autogen include statement, do not remove 23 #include "precompiled_webdav.hxx" 24 25 #include <rtl/ustrbuf.hxx> 26 #include "DAVProperties.hxx" 27 #include "PropfindRequest.hxx" 28 29 using namespace http_dav_ucp; 30 generatePROPFINDRequestBody(const std::vector<::rtl::OUString> * propNames,const bool onlyPropertyNames)31rtl::OString PropfindRequest::generatePROPFINDRequestBody( 32 const std::vector< ::rtl::OUString > * propNames, 33 const bool onlyPropertyNames ) 34 { 35 #define PROPFIND_HEADER "<?xml version=\"1.0\" encoding=\"utf-8\"?><propfind xmlns=\"DAV:\">" 36 #define PROPFIND_TRAILER "</propfind>" 37 38 // TODO is it really needed a Unicode string buffer? 39 // All properties and property names aren't supposed to be ASCII? 40 rtl::OUStringBuffer aBuffer; 41 aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( PROPFIND_HEADER )); 42 43 // create and fill body with requested properties 44 const int nPropCount = ( !onlyPropertyNames && propNames ) 45 ? propNames->size() 46 : 0; 47 if ( nPropCount > 0 ) 48 { 49 aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( "<prop>" ) ); 50 CurlPropName thePropName; 51 for ( int theIndex = 0; theIndex < nPropCount; theIndex ++ ) 52 { 53 // split fullname into namespace and name! 54 DAVProperties::createCurlPropName( (*propNames)[ theIndex ], 55 thePropName ); 56 57 /* <*propname* xmlns="*propns*" /> */ 58 aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( "<" )); 59 aBuffer.appendAscii( thePropName.name ); 60 aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( " xmlnx=\"" )); 61 aBuffer.appendAscii( thePropName.nspace ); 62 aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( "\"/>" )); 63 } 64 65 aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( "</prop>" )); 66 } 67 else 68 { 69 if ( onlyPropertyNames ) 70 { 71 aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( "<propname/>" )); 72 } 73 else 74 { 75 aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( "<allprop/>" )); 76 } 77 } 78 79 aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( PROPFIND_TRAILER )); 80 return rtl::OUStringToOString( aBuffer.makeStringAndClear(), RTL_TEXTENCODING_UTF8 ); 81 } 82