update dev300-m58
[ooovba.git] / ucb / source / ucp / webdav / NeonPropFindRequest.cxx
blobab1132fa883f8ed6ff6fabc9bc9ac234381c56bf
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: NeonPropFindRequest.cxx,v $
10 * $Revision: 1.24 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_ucb.hxx"
33 #include <osl/diagnose.h>
34 #include "NeonTypes.hxx"
35 #include "DAVException.hxx"
36 #include "DAVProperties.hxx"
37 #include "NeonPropFindRequest.hxx"
38 #ifndef _LINKSEQUENCE_HXX_
39 #include "LinkSequence.hxx"
40 #endif
41 #include "LockSequence.hxx"
42 #include "LockEntrySequence.hxx"
43 #include "UCBDeadPropertyValue.hxx"
45 using namespace rtl;
46 using namespace com::sun::star::uno;
47 using namespace com::sun::star::ucb;
48 using namespace std;
49 using namespace webdav_ucp;
51 // -------------------------------------------------------------------
52 extern "C" int NPFR_propfind_iter( void* userdata,
53 const NeonPropName* pname,
54 const char* value,
55 const HttpStatus* status )
58 HTTP Response Status Classes:
60 - 1: Informational - Request received, continuing process
62 - 2: Success - The action was successfully received,
63 understood, and accepted
65 - 3: Redirection - Further action must be taken in order to
66 complete the request
68 - 4: Client Error - The request contains bad syntax or cannot
69 be fulfilled
71 - 5: Server Error - The server failed to fulfill an apparently
72 valid request
75 if ( status->klass > 2 )
76 return 0; // Error getting this property. Go on.
78 // Create & set the PropertyValue
79 DAVPropertyValue thePropertyValue;
80 thePropertyValue.IsCaseSensitive = true;
82 DAVProperties::createUCBPropName( pname->nspace,
83 pname->name,
84 thePropertyValue.Name );
85 bool bHasValue = false;
86 if ( DAVProperties::isUCBDeadProperty( *pname ) )
88 // DAV dead property added by WebDAV UCP?
89 if ( UCBDeadPropertyValue::createFromXML(
90 value, thePropertyValue.Value ) )
91 OSL_ENSURE( thePropertyValue.Value.hasValue(),
92 "NeonPropFindRequest::propfind_iter - No value!" );
93 bHasValue = true;
96 if ( !bHasValue )
98 if ( rtl_str_compareIgnoreAsciiCase(
99 pname->name, "resourcetype" ) == 0 )
101 OString aValue( value );
102 aValue = aValue.trim(); // #107358# remove leading/trailing spaces
103 if ( aValue.getLength() )
105 aValue = aValue.toAsciiLowerCase();
106 if (
107 ( aValue.compareTo(
108 RTL_CONSTASCII_STRINGPARAM( "<collection" ) ) == 0 ) ||
109 ( aValue.compareTo(
110 RTL_CONSTASCII_STRINGPARAM( "<dav:collection" ) ) == 0 )
113 thePropertyValue.Value
114 <<= OUString::createFromAscii( "collection" );
118 if ( !thePropertyValue.Value.hasValue() )
120 // Take over the value exactly as supplied by the server.
121 thePropertyValue.Value <<= OUString::createFromAscii( value );
124 else if ( rtl_str_compareIgnoreAsciiCase(
125 pname->name, "supportedlock" ) == 0 )
127 Sequence< LockEntry > aEntries;
128 LockEntrySequence::createFromXML( value, aEntries );
129 thePropertyValue.Value <<= aEntries;
131 else if ( rtl_str_compareIgnoreAsciiCase(
132 pname->name, "lockdiscovery" ) == 0 )
134 Sequence< Lock > aLocks;
135 LockSequence::createFromXML( value, aLocks );
136 thePropertyValue.Value <<= aLocks;
138 else if ( rtl_str_compareIgnoreAsciiCase( pname->name, "source" ) == 0 )
140 Sequence< Link > aLinks;
141 LinkSequence::createFromXML( value, aLinks );
142 thePropertyValue.Value <<= aLinks;
144 else
146 thePropertyValue.Value
147 <<= OStringToOUString( value, RTL_TEXTENCODING_UTF8 );
151 // Add the newly created PropertyValue
152 DAVResource* theResource = static_cast< DAVResource * >( userdata );
153 theResource->properties.push_back( thePropertyValue );
155 return 0; // Go on.
158 // -------------------------------------------------------------------
159 extern "C" void NPFR_propfind_results( void* userdata,
160 #if NEON_VERSION >= 0x0260
161 const ne_uri* uri,
162 #else
163 const char* href,
164 #endif
165 const NeonPropFindResultSet* set )
167 // @@@ href is not the uri! DAVResource ctor wants uri!
169 #if NEON_VERSION >= 0x0260
170 DAVResource theResource(
171 OStringToOUString( uri->path, RTL_TEXTENCODING_UTF8 ) );
172 #else
173 DAVResource theResource(
174 OStringToOUString( href, RTL_TEXTENCODING_UTF8 ) );
175 #endif
177 ne_propset_iterate( set, NPFR_propfind_iter, &theResource );
179 // Add entry to resources list.
180 vector< DAVResource > * theResources
181 = static_cast< vector< DAVResource > * >( userdata );
182 theResources->push_back( theResource );
184 // -------------------------------------------------------------------
185 extern "C" int NPFR_propnames_iter( void* userdata,
186 const NeonPropName* pname,
187 const char* /*value*/,
188 const HttpStatus* /*status*/ )
190 OUString aFullName;
191 DAVProperties::createUCBPropName( pname->nspace,
192 pname->name,
193 aFullName );
195 DAVResourceInfo* theResource = static_cast< DAVResourceInfo * >( userdata );
196 theResource->properties.push_back( aFullName );
197 return 0;
200 // -------------------------------------------------------------------
201 extern "C" void NPFR_propnames_results( void* userdata,
202 #if NEON_VERSION >= 0x0260
203 const ne_uri* uri,
204 #else
205 const char* href,
206 #endif
207 const NeonPropFindResultSet* results )
209 // @@@ href is not the uri! DAVResourceInfo ctor wants uri!
210 // Create entry for the resource.
211 #if NEON_VERSION >= 0x0260
212 DAVResourceInfo theResource(
213 OStringToOUString( uri->path, RTL_TEXTENCODING_UTF8 ) );
214 #else
215 DAVResourceInfo theResource(
216 OStringToOUString( href, RTL_TEXTENCODING_UTF8 ) );
217 #endif
219 // Fill entry.
220 ne_propset_iterate( results, NPFR_propnames_iter, &theResource );
222 // Add entry to resources list.
223 vector< DAVResourceInfo > * theResources
224 = static_cast< vector< DAVResourceInfo > * >( userdata );
225 theResources->push_back( theResource );
228 // -------------------------------------------------------------------
229 // Constructor
230 // -------------------------------------------------------------------
232 NeonPropFindRequest::NeonPropFindRequest( HttpSession* inSession,
233 const char* inPath,
234 const Depth inDepth,
235 const vector< OUString >& inPropNames,
236 vector< DAVResource >& ioResources,
237 int & nError )
239 // Generate the list of properties we're looking for
240 int thePropCount = inPropNames.size();
241 if ( thePropCount > 0 )
243 NeonPropName* thePropNames = new NeonPropName[ thePropCount + 1 ];
244 int theIndex;
246 for ( theIndex = 0; theIndex < thePropCount; theIndex ++ )
248 // Split fullname into namespace and name!
249 DAVProperties::createNeonPropName(
250 inPropNames[ theIndex ], thePropNames[ theIndex ] );
252 thePropNames[ theIndex ].nspace = NULL;
253 thePropNames[ theIndex ].name = NULL;
255 nError = ne_simple_propfind( inSession,
256 inPath,
257 inDepth,
258 thePropNames,
259 NPFR_propfind_results,
260 &ioResources );
262 for ( theIndex = 0; theIndex < thePropCount; theIndex ++ )
263 free( (void *)thePropNames[ theIndex ].name );
265 delete [] thePropNames;
267 else
269 // ALLPROP
270 nError = ne_simple_propfind( inSession,
271 inPath,
272 inDepth,
273 NULL, // 0 == allprop
274 NPFR_propfind_results,
275 &ioResources );
278 // #87585# - Sometimes neon lies (because some servers lie).
279 if ( ( nError == NE_OK ) && ioResources.empty() )
280 nError = NE_ERROR;
283 // -------------------------------------------------------------------
284 // Constructor
285 // - obtains property names
286 // -------------------------------------------------------------------
288 NeonPropFindRequest::NeonPropFindRequest(
289 HttpSession* inSession,
290 const char* inPath,
291 const Depth inDepth,
292 std::vector< DAVResourceInfo > & ioResInfo,
293 int & nError )
295 nError = ne_propnames( inSession,
296 inPath,
297 inDepth,
298 NPFR_propnames_results,
299 &ioResInfo );
301 // #87585# - Sometimes neon lies (because some servers lie).
302 if ( ( nError == NE_OK ) && ioResInfo.empty() )
303 nError = NE_ERROR;
306 // -------------------------------------------------------------------
307 // Destructor
308 // -------------------------------------------------------------------
309 NeonPropFindRequest::~NeonPropFindRequest( )