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
25cdf0e10cSrcweir #include "precompiled_ucb.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir /**************************************************************************
28cdf0e10cSrcweir                                 TODO
29cdf0e10cSrcweir  **************************************************************************
30cdf0e10cSrcweir 
31cdf0e10cSrcweir  *************************************************************************/
32cdf0e10cSrcweir #include <osl/diagnose.h>
33cdf0e10cSrcweir #include <com/sun/star/util/DateTime.hpp>
34*59ddfc10SAndre Fischer #include "SerfUri.hxx"
35cdf0e10cSrcweir #include "DAVResource.hxx"
36cdf0e10cSrcweir #include "DAVProperties.hxx"
37cdf0e10cSrcweir #include "DateTimeHelper.hxx"
38cdf0e10cSrcweir #include "webdavprovider.hxx"
39cdf0e10cSrcweir #include "ContentProperties.hxx"
40cdf0e10cSrcweir 
41cdf0e10cSrcweir using namespace com::sun::star;
42*59ddfc10SAndre Fischer using namespace http_dav_ucp;
43cdf0e10cSrcweir 
44cdf0e10cSrcweir /*
45cdf0e10cSrcweir =============================================================================
46cdf0e10cSrcweir 
47cdf0e10cSrcweir                             Property Mapping
48cdf0e10cSrcweir 
49cdf0e10cSrcweir =============================================================================
50cdf0e10cSrcweir HTTP (entity header)    WebDAV (property)   UCB (property)
51cdf0e10cSrcweir =============================================================================
52cdf0e10cSrcweir 
53cdf0e10cSrcweir Allow
54cdf0e10cSrcweir Content-Encoding
55cdf0e10cSrcweir Content-Language        getcontentlanguage
56cdf0e10cSrcweir Content-Length          getcontentlength    Size
57cdf0e10cSrcweir Content-Location
58cdf0e10cSrcweir Content-MD5
59cdf0e10cSrcweir Content-Range
60cdf0e10cSrcweir Content-Type            getcontenttype      MediaType
61cdf0e10cSrcweir Expires
62cdf0e10cSrcweir Last-Modified           getlastmodified     DateModified
63cdf0e10cSrcweir                         creationdate        DateCreated
64cdf0e10cSrcweir                         resourcetype        IsFolder,IsDocument,ContentType
65cdf0e10cSrcweir                         displayname
66cdf0e10cSrcweir ETag (actually          getetag
67cdf0e10cSrcweir a response header )
68cdf0e10cSrcweir                         lockdiscovery
69cdf0e10cSrcweir                         supportedlock
70cdf0e10cSrcweir                         source
71cdf0e10cSrcweir                                             Title (always taken from URI)
72cdf0e10cSrcweir 
73cdf0e10cSrcweir =============================================================================
74cdf0e10cSrcweir 
75cdf0e10cSrcweir Important: HTTP headers will not be mapped to DAV properties; only to UCB
76cdf0e10cSrcweir            properties. (Content-Length,Content-Type,Last-Modified)
77cdf0e10cSrcweir */
78cdf0e10cSrcweir 
79cdf0e10cSrcweir //=========================================================================
80cdf0e10cSrcweir //=========================================================================
81cdf0e10cSrcweir //
82cdf0e10cSrcweir // ContentProperties Implementation.
83cdf0e10cSrcweir //
84cdf0e10cSrcweir //=========================================================================
85cdf0e10cSrcweir //=========================================================================
86cdf0e10cSrcweir 
87cdf0e10cSrcweir // static member!
88cdf0e10cSrcweir uno::Any ContentProperties::m_aEmptyAny;
89cdf0e10cSrcweir 
ContentProperties(const DAVResource & rResource)90cdf0e10cSrcweir ContentProperties::ContentProperties( const DAVResource& rResource )
91cdf0e10cSrcweir : m_xProps( new PropertyValueMap ),
92cdf0e10cSrcweir   m_bTrailingSlash( false )
93cdf0e10cSrcweir {
94cdf0e10cSrcweir     OSL_ENSURE( rResource.uri.getLength(),
95cdf0e10cSrcweir                 "ContentProperties ctor - Empty resource URI!" );
96cdf0e10cSrcweir 
97cdf0e10cSrcweir     // Title
98cdf0e10cSrcweir     try
99cdf0e10cSrcweir     {
100*59ddfc10SAndre Fischer         SerfUri aURI( rResource.uri );
101cdf0e10cSrcweir         m_aEscapedTitle = aURI.GetPathBaseName();
102cdf0e10cSrcweir 
103cdf0e10cSrcweir         (*m_xProps)[ rtl::OUString::createFromAscii( "Title" ) ]
104cdf0e10cSrcweir             = PropertyValue(
105cdf0e10cSrcweir                 uno::makeAny( aURI.GetPathBaseNameUnescaped() ), true );
106cdf0e10cSrcweir     }
107cdf0e10cSrcweir     catch ( DAVException const & )
108cdf0e10cSrcweir     {
109cdf0e10cSrcweir         (*m_xProps)[ rtl::OUString::createFromAscii( "Title" ) ]
110cdf0e10cSrcweir             = PropertyValue(
111cdf0e10cSrcweir                 uno::makeAny(
112cdf0e10cSrcweir                     rtl::OUString(
113cdf0e10cSrcweir                         RTL_CONSTASCII_USTRINGPARAM( "*** unknown ***" ) ) ),
114cdf0e10cSrcweir                 true );
115cdf0e10cSrcweir     }
116cdf0e10cSrcweir 
117cdf0e10cSrcweir     std::vector< DAVPropertyValue >::const_iterator it
118cdf0e10cSrcweir         = rResource.properties.begin();
119cdf0e10cSrcweir     std::vector< DAVPropertyValue >::const_iterator end
120cdf0e10cSrcweir         = rResource.properties.end();
121cdf0e10cSrcweir 
122cdf0e10cSrcweir     while ( it != end )
123cdf0e10cSrcweir     {
124cdf0e10cSrcweir         addProperty( (*it) );
125cdf0e10cSrcweir         ++it;
126cdf0e10cSrcweir     }
127cdf0e10cSrcweir 
128cdf0e10cSrcweir     if ( rResource.uri.getStr()[ rResource.uri.getLength() - 1 ]
129cdf0e10cSrcweir         == sal_Unicode( '/' ) )
130cdf0e10cSrcweir         m_bTrailingSlash = sal_True;
131cdf0e10cSrcweir }
132cdf0e10cSrcweir 
133cdf0e10cSrcweir //=========================================================================
ContentProperties(const rtl::OUString & rTitle,sal_Bool bFolder)134cdf0e10cSrcweir ContentProperties::ContentProperties(
135cdf0e10cSrcweir                         const rtl::OUString & rTitle, sal_Bool bFolder )
136cdf0e10cSrcweir : m_xProps( new PropertyValueMap ),
137cdf0e10cSrcweir   m_bTrailingSlash( sal_False )
138cdf0e10cSrcweir {
139cdf0e10cSrcweir     (*m_xProps)[ rtl::OUString::createFromAscii( "Title" ) ]
140cdf0e10cSrcweir         = PropertyValue( uno::makeAny( rTitle ), true );
141cdf0e10cSrcweir     (*m_xProps)[ rtl::OUString::createFromAscii( "IsFolder" ) ]
142cdf0e10cSrcweir         = PropertyValue( uno::makeAny( bFolder ), true );
143cdf0e10cSrcweir     (*m_xProps)[ rtl::OUString::createFromAscii( "IsDocument" ) ]
144cdf0e10cSrcweir         = PropertyValue( uno::makeAny( sal_Bool( !bFolder ) ), true );
145cdf0e10cSrcweir }
146cdf0e10cSrcweir 
147cdf0e10cSrcweir //=========================================================================
ContentProperties(const rtl::OUString & rTitle)148cdf0e10cSrcweir ContentProperties::ContentProperties( const rtl::OUString & rTitle )
149cdf0e10cSrcweir : m_xProps( new PropertyValueMap ),
150cdf0e10cSrcweir   m_bTrailingSlash( sal_False )
151cdf0e10cSrcweir {
152cdf0e10cSrcweir     (*m_xProps)[ rtl::OUString::createFromAscii( "Title" ) ]
153cdf0e10cSrcweir         = PropertyValue( uno::makeAny( rTitle ), true );
154cdf0e10cSrcweir }
155cdf0e10cSrcweir 
156cdf0e10cSrcweir //=========================================================================
ContentProperties()157cdf0e10cSrcweir ContentProperties::ContentProperties()
158cdf0e10cSrcweir : m_xProps( new PropertyValueMap ),
159cdf0e10cSrcweir   m_bTrailingSlash( sal_False )
160cdf0e10cSrcweir {
161cdf0e10cSrcweir }
162cdf0e10cSrcweir 
163cdf0e10cSrcweir //=========================================================================
ContentProperties(const ContentProperties & rOther)164cdf0e10cSrcweir ContentProperties::ContentProperties( const ContentProperties & rOther )
165cdf0e10cSrcweir : m_aEscapedTitle( rOther.m_aEscapedTitle ),
166cdf0e10cSrcweir   m_xProps( rOther.m_xProps.get()
167cdf0e10cSrcweir             ? new PropertyValueMap( *rOther.m_xProps )
168cdf0e10cSrcweir             : new PropertyValueMap ),
169cdf0e10cSrcweir   m_bTrailingSlash( rOther.m_bTrailingSlash )
170cdf0e10cSrcweir {
171cdf0e10cSrcweir }
172cdf0e10cSrcweir 
173cdf0e10cSrcweir //=========================================================================
contains(const rtl::OUString & rName) const174cdf0e10cSrcweir bool ContentProperties::contains( const rtl::OUString & rName ) const
175cdf0e10cSrcweir {
176cdf0e10cSrcweir     if ( get( rName ) )
177cdf0e10cSrcweir         return true;
178cdf0e10cSrcweir     else
179cdf0e10cSrcweir         return false;
180cdf0e10cSrcweir }
181cdf0e10cSrcweir 
182cdf0e10cSrcweir //=========================================================================
getValue(const rtl::OUString & rName) const183cdf0e10cSrcweir const uno::Any & ContentProperties::getValue(
184cdf0e10cSrcweir                                     const rtl::OUString & rName ) const
185cdf0e10cSrcweir {
186cdf0e10cSrcweir     const PropertyValue * pProp = get( rName );
187cdf0e10cSrcweir     if ( pProp )
188cdf0e10cSrcweir         return pProp->value();
189cdf0e10cSrcweir     else
190cdf0e10cSrcweir         return m_aEmptyAny;
191cdf0e10cSrcweir }
192cdf0e10cSrcweir 
193cdf0e10cSrcweir //=========================================================================
get(const rtl::OUString & rName) const194cdf0e10cSrcweir const PropertyValue * ContentProperties::get(
195cdf0e10cSrcweir                                     const rtl::OUString & rName ) const
196cdf0e10cSrcweir {
197cdf0e10cSrcweir     PropertyValueMap::const_iterator it = m_xProps->find( rName );
198cdf0e10cSrcweir     const PropertyValueMap::const_iterator end = m_xProps->end();
199cdf0e10cSrcweir 
200cdf0e10cSrcweir     if ( it == end )
201cdf0e10cSrcweir     {
202cdf0e10cSrcweir         it  = m_xProps->begin();
203cdf0e10cSrcweir         while ( it != end )
204cdf0e10cSrcweir         {
205cdf0e10cSrcweir             if ( (*it).first.equalsIgnoreAsciiCase( rName ) )
206cdf0e10cSrcweir                 return &(*it).second;
207cdf0e10cSrcweir 
208cdf0e10cSrcweir             ++it;
209cdf0e10cSrcweir         }
210cdf0e10cSrcweir         return 0;
211cdf0e10cSrcweir     }
212cdf0e10cSrcweir     else
213cdf0e10cSrcweir         return &(*it).second;
214cdf0e10cSrcweir }
215cdf0e10cSrcweir 
216cdf0e10cSrcweir //=========================================================================
217cdf0e10cSrcweir // static
UCBNamesToDAVNames(const uno::Sequence<beans::Property> & rProps,std::vector<rtl::OUString> & propertyNames,bool bIncludeUnmatched)218cdf0e10cSrcweir void ContentProperties::UCBNamesToDAVNames(
219cdf0e10cSrcweir                             const uno::Sequence< beans::Property > & rProps,
220cdf0e10cSrcweir                             std::vector< rtl::OUString > & propertyNames,
221cdf0e10cSrcweir                             bool bIncludeUnmatched /* = true */ )
222cdf0e10cSrcweir {
223cdf0e10cSrcweir     //////////////////////////////////////////////////////////////
224cdf0e10cSrcweir     // Assemble list of DAV properties to obtain from server.
225cdf0e10cSrcweir     // Append DAV properties needed to obtain requested UCB props.
226cdf0e10cSrcweir     //////////////////////////////////////////////////////////////
227cdf0e10cSrcweir 
228cdf0e10cSrcweir     //       DAV              UCB
229cdf0e10cSrcweir     // creationdate     <- DateCreated
230cdf0e10cSrcweir     // getlastmodified  <- DateModified
231cdf0e10cSrcweir     // getcontenttype   <- MediaType
232cdf0e10cSrcweir     // getcontentlength <- Size
233cdf0e10cSrcweir     // resourcetype     <- IsFolder, IsDocument, ContentType
234cdf0e10cSrcweir     // (taken from URI) <- Title
235cdf0e10cSrcweir 
236cdf0e10cSrcweir     sal_Bool bCreationDate  = sal_False;
237cdf0e10cSrcweir     sal_Bool bLastModified  = sal_False;
238cdf0e10cSrcweir     sal_Bool bContentType   = sal_False;
239cdf0e10cSrcweir     sal_Bool bContentLength = sal_False;
240cdf0e10cSrcweir     sal_Bool bResourceType  = sal_False;
241cdf0e10cSrcweir 
242cdf0e10cSrcweir     sal_Int32 nCount = rProps.getLength();
243cdf0e10cSrcweir     for ( sal_Int32 n = 0; n < nCount; ++n )
244cdf0e10cSrcweir     {
245cdf0e10cSrcweir         const beans::Property & rProp = rProps[ n ];
246cdf0e10cSrcweir 
247cdf0e10cSrcweir         if ( rProp.Name.equalsAsciiL(
248cdf0e10cSrcweir                     RTL_CONSTASCII_STRINGPARAM( "Title" ) ) )
249cdf0e10cSrcweir         {
250cdf0e10cSrcweir             // Title is always obtained from resource's URI.
251cdf0e10cSrcweir             continue;
252cdf0e10cSrcweir         }
253cdf0e10cSrcweir         else if ( rProp.Name.equalsAsciiL(
254cdf0e10cSrcweir                     RTL_CONSTASCII_STRINGPARAM( "DateCreated" ) )
255cdf0e10cSrcweir                   ||
256cdf0e10cSrcweir                   ( rProp.Name == DAVProperties::CREATIONDATE ) )
257cdf0e10cSrcweir         {
258cdf0e10cSrcweir             if ( !bCreationDate )
259cdf0e10cSrcweir             {
260cdf0e10cSrcweir                     propertyNames.push_back( DAVProperties::CREATIONDATE );
261cdf0e10cSrcweir                 bCreationDate = sal_True;
262cdf0e10cSrcweir             }
263cdf0e10cSrcweir         }
264cdf0e10cSrcweir         else if ( rProp.Name.equalsAsciiL(
265cdf0e10cSrcweir                     RTL_CONSTASCII_STRINGPARAM( "DateModified" ) )
266cdf0e10cSrcweir                   ||
267cdf0e10cSrcweir                   ( rProp.Name == DAVProperties::GETLASTMODIFIED ) )
268cdf0e10cSrcweir         {
269cdf0e10cSrcweir             if ( !bLastModified )
270cdf0e10cSrcweir             {
271cdf0e10cSrcweir                     propertyNames.push_back(
272cdf0e10cSrcweir                     DAVProperties::GETLASTMODIFIED );
273cdf0e10cSrcweir                 bLastModified = sal_True;
274cdf0e10cSrcweir             }
275cdf0e10cSrcweir         }
276cdf0e10cSrcweir         else if ( rProp.Name.equalsAsciiL(
277cdf0e10cSrcweir                     RTL_CONSTASCII_STRINGPARAM( "MediaType" ) )
278cdf0e10cSrcweir                   ||
279cdf0e10cSrcweir                   ( rProp.Name == DAVProperties::GETCONTENTTYPE ) )
280cdf0e10cSrcweir         {
281cdf0e10cSrcweir             if ( !bContentType )
282cdf0e10cSrcweir             {
283cdf0e10cSrcweir                     propertyNames.push_back(
284cdf0e10cSrcweir                         DAVProperties::GETCONTENTTYPE );
285cdf0e10cSrcweir                 bContentType = sal_True;
286cdf0e10cSrcweir             }
287cdf0e10cSrcweir         }
288cdf0e10cSrcweir         else if ( rProp.Name.equalsAsciiL(
289cdf0e10cSrcweir                     RTL_CONSTASCII_STRINGPARAM( "Size" ) )
290cdf0e10cSrcweir                   ||
291cdf0e10cSrcweir                   ( rProp.Name == DAVProperties::GETCONTENTLENGTH ) )
292cdf0e10cSrcweir         {
293cdf0e10cSrcweir             if ( !bContentLength )
294cdf0e10cSrcweir             {
295cdf0e10cSrcweir                     propertyNames.push_back(
296cdf0e10cSrcweir                     DAVProperties::GETCONTENTLENGTH );
297cdf0e10cSrcweir                 bContentLength = sal_True;
298cdf0e10cSrcweir             }
299cdf0e10cSrcweir         }
300cdf0e10cSrcweir         else if ( rProp.Name.equalsAsciiL(
301cdf0e10cSrcweir                     RTL_CONSTASCII_STRINGPARAM( "ContentType" ) )
302cdf0e10cSrcweir                   ||
303cdf0e10cSrcweir                   rProp.Name.equalsAsciiL(
304cdf0e10cSrcweir                     RTL_CONSTASCII_STRINGPARAM( "IsDocument" ) )
305cdf0e10cSrcweir                   ||
306cdf0e10cSrcweir                   rProp.Name.equalsAsciiL(
307cdf0e10cSrcweir                     RTL_CONSTASCII_STRINGPARAM( "IsFolder" ) )
308cdf0e10cSrcweir                   ||
309cdf0e10cSrcweir                   ( rProp.Name == DAVProperties::RESOURCETYPE ) )
310cdf0e10cSrcweir         {
311cdf0e10cSrcweir             if ( !bResourceType )
312cdf0e10cSrcweir             {
313cdf0e10cSrcweir                     propertyNames.push_back( DAVProperties::RESOURCETYPE );
314cdf0e10cSrcweir                 bResourceType = sal_True;
315cdf0e10cSrcweir             }
316cdf0e10cSrcweir         }
317cdf0e10cSrcweir         else
318cdf0e10cSrcweir         {
319cdf0e10cSrcweir             if ( bIncludeUnmatched )
320cdf0e10cSrcweir                 propertyNames.push_back( rProp.Name );
321cdf0e10cSrcweir         }
322cdf0e10cSrcweir     }
323cdf0e10cSrcweir }
324cdf0e10cSrcweir 
325cdf0e10cSrcweir //=========================================================================
326cdf0e10cSrcweir // static
UCBNamesToHTTPNames(const uno::Sequence<beans::Property> & rProps,std::vector<rtl::OUString> & propertyNames,bool bIncludeUnmatched)327cdf0e10cSrcweir void ContentProperties::UCBNamesToHTTPNames(
328cdf0e10cSrcweir                             const uno::Sequence< beans::Property > & rProps,
329cdf0e10cSrcweir                             std::vector< rtl::OUString > & propertyNames,
330cdf0e10cSrcweir                             bool bIncludeUnmatched /* = true */ )
331cdf0e10cSrcweir {
332cdf0e10cSrcweir     //////////////////////////////////////////////////////////////
333cdf0e10cSrcweir     // Assemble list of HTTP header names to obtain from server.
334cdf0e10cSrcweir     // Append HTTP headers needed to obtain requested UCB props.
335cdf0e10cSrcweir     //////////////////////////////////////////////////////////////
336cdf0e10cSrcweir 
337cdf0e10cSrcweir     //       HTTP              UCB
338cdf0e10cSrcweir     // Last-Modified  <- DateModified
339cdf0e10cSrcweir     // Content-Type   <- MediaType
340cdf0e10cSrcweir     // Content-Length <- Size
341cdf0e10cSrcweir 
342cdf0e10cSrcweir     sal_Int32 nCount = rProps.getLength();
343cdf0e10cSrcweir     for ( sal_Int32 n = 0; n < nCount; ++n )
344cdf0e10cSrcweir     {
345cdf0e10cSrcweir         const beans::Property & rProp = rProps[ n ];
346cdf0e10cSrcweir 
347cdf0e10cSrcweir         if ( rProp.Name.equalsAsciiL(
348cdf0e10cSrcweir                     RTL_CONSTASCII_STRINGPARAM( "DateModified" ) ) )
349cdf0e10cSrcweir         {
350cdf0e10cSrcweir             propertyNames.push_back(
351cdf0e10cSrcweir                 rtl::OUString::createFromAscii( "Last-Modified" ) );
352cdf0e10cSrcweir         }
353cdf0e10cSrcweir         else if ( rProp.Name.equalsAsciiL(
354cdf0e10cSrcweir                     RTL_CONSTASCII_STRINGPARAM( "MediaType" ) ) )
355cdf0e10cSrcweir         {
356cdf0e10cSrcweir             propertyNames.push_back(
357cdf0e10cSrcweir                 rtl::OUString::createFromAscii( "Content-Type" ) );
358cdf0e10cSrcweir         }
359cdf0e10cSrcweir         else if ( rProp.Name.equalsAsciiL(
360cdf0e10cSrcweir                     RTL_CONSTASCII_STRINGPARAM( "Size" ) ) )
361cdf0e10cSrcweir         {
362cdf0e10cSrcweir             propertyNames.push_back(
363cdf0e10cSrcweir                 rtl::OUString::createFromAscii( "Content-Length" ) );
364cdf0e10cSrcweir         }
365cdf0e10cSrcweir         else
366cdf0e10cSrcweir         {
367cdf0e10cSrcweir             if ( bIncludeUnmatched )
368cdf0e10cSrcweir                 propertyNames.push_back( rProp.Name );
369cdf0e10cSrcweir         }
370cdf0e10cSrcweir     }
371cdf0e10cSrcweir }
372cdf0e10cSrcweir 
373cdf0e10cSrcweir //=========================================================================
containsAllNames(const uno::Sequence<beans::Property> & rProps,std::vector<rtl::OUString> & rNamesNotContained) const374cdf0e10cSrcweir bool ContentProperties::containsAllNames(
375cdf0e10cSrcweir                     const uno::Sequence< beans::Property >& rProps,
376cdf0e10cSrcweir                     std::vector< rtl::OUString > & rNamesNotContained ) const
377cdf0e10cSrcweir {
378cdf0e10cSrcweir     rNamesNotContained.clear();
379cdf0e10cSrcweir 
380cdf0e10cSrcweir     sal_Int32 nCount = rProps.getLength();
381cdf0e10cSrcweir     for ( sal_Int32 n = 0; n < nCount; ++n )
382cdf0e10cSrcweir     {
383cdf0e10cSrcweir         const rtl::OUString & rName = rProps[ n ].Name;
384cdf0e10cSrcweir         if ( !contains( rName ) )
385cdf0e10cSrcweir         {
386cdf0e10cSrcweir             // Not found.
387cdf0e10cSrcweir             rNamesNotContained.push_back( rName );
388cdf0e10cSrcweir         }
389cdf0e10cSrcweir     }
390cdf0e10cSrcweir 
391cdf0e10cSrcweir     return ( rNamesNotContained.size() == 0 );
392cdf0e10cSrcweir }
393cdf0e10cSrcweir 
394cdf0e10cSrcweir //=========================================================================
addProperties(const std::vector<rtl::OUString> & rProps,const ContentProperties & rContentProps)395cdf0e10cSrcweir void ContentProperties::addProperties(
396cdf0e10cSrcweir                                 const std::vector< rtl::OUString > & rProps,
397cdf0e10cSrcweir                                 const ContentProperties & rContentProps )
398cdf0e10cSrcweir {
399cdf0e10cSrcweir     std::vector< rtl::OUString >::const_iterator it  = rProps.begin();
400cdf0e10cSrcweir     std::vector< rtl::OUString >::const_iterator end = rProps.end();
401cdf0e10cSrcweir 
402cdf0e10cSrcweir     while ( it != end )
403cdf0e10cSrcweir     {
404cdf0e10cSrcweir         const rtl::OUString & rName = (*it);
405cdf0e10cSrcweir 
406cdf0e10cSrcweir         if ( !contains( rName ) ) // ignore duplicates
407cdf0e10cSrcweir         {
408cdf0e10cSrcweir             const PropertyValue * pProp = rContentProps.get( rName );
409cdf0e10cSrcweir             if ( pProp )
410cdf0e10cSrcweir             {
411cdf0e10cSrcweir                 // Add it.
412cdf0e10cSrcweir                 addProperty( rName, pProp->value(), pProp->isCaseSensitive() );
413cdf0e10cSrcweir             }
414cdf0e10cSrcweir             else
415cdf0e10cSrcweir             {
416cdf0e10cSrcweir                 addProperty( rName, uno::Any(), false );
417cdf0e10cSrcweir             }
418cdf0e10cSrcweir         }
419cdf0e10cSrcweir         ++it;
420cdf0e10cSrcweir     }
421cdf0e10cSrcweir }
422cdf0e10cSrcweir 
423cdf0e10cSrcweir //=========================================================================
addProperties(const ContentProperties & rProps)424cdf0e10cSrcweir void ContentProperties::addProperties( const ContentProperties & rProps )
425cdf0e10cSrcweir {
426cdf0e10cSrcweir     PropertyValueMap::const_iterator it = rProps.m_xProps->begin();
427cdf0e10cSrcweir     const PropertyValueMap::const_iterator end = rProps.m_xProps->end();
428cdf0e10cSrcweir 
429cdf0e10cSrcweir     while ( it != end )
430cdf0e10cSrcweir     {
431cdf0e10cSrcweir         addProperty(
432cdf0e10cSrcweir             (*it).first, (*it).second.value(), (*it).second.isCaseSensitive() );
433cdf0e10cSrcweir         ++it;
434cdf0e10cSrcweir     }
435cdf0e10cSrcweir }
436cdf0e10cSrcweir 
437cdf0e10cSrcweir //=========================================================================
addProperties(const std::vector<DAVPropertyValue> & rProps)438cdf0e10cSrcweir void ContentProperties::addProperties(
439cdf0e10cSrcweir     const std::vector< DAVPropertyValue > & rProps )
440cdf0e10cSrcweir {
441cdf0e10cSrcweir     std::vector< DAVPropertyValue >::const_iterator it  = rProps.begin();
442cdf0e10cSrcweir     const std::vector< DAVPropertyValue >::const_iterator end = rProps.end();
443cdf0e10cSrcweir 
444cdf0e10cSrcweir     while ( it != end )
445cdf0e10cSrcweir     {
446cdf0e10cSrcweir         addProperty( (*it) );
447cdf0e10cSrcweir         ++it;
448cdf0e10cSrcweir     }
449cdf0e10cSrcweir }
450cdf0e10cSrcweir 
451cdf0e10cSrcweir //=========================================================================
addProperty(const DAVPropertyValue & rProp)452cdf0e10cSrcweir void ContentProperties::addProperty( const DAVPropertyValue & rProp )
453cdf0e10cSrcweir {
454cdf0e10cSrcweir     addProperty( rProp.Name, rProp.Value, rProp.IsCaseSensitive );
455cdf0e10cSrcweir }
456cdf0e10cSrcweir 
457cdf0e10cSrcweir //=========================================================================
addProperty(const rtl::OUString & rName,const com::sun::star::uno::Any & rValue,bool bIsCaseSensitive)458cdf0e10cSrcweir void ContentProperties::addProperty( const rtl::OUString & rName,
459cdf0e10cSrcweir                                      const com::sun::star::uno::Any & rValue,
460cdf0e10cSrcweir                                      bool bIsCaseSensitive )
461cdf0e10cSrcweir {
462cdf0e10cSrcweir     if ( rName.equals( DAVProperties::CREATIONDATE ) )
463cdf0e10cSrcweir     {
464cdf0e10cSrcweir         // Map DAV:creationdate to UCP:DateCreated
465cdf0e10cSrcweir         rtl::OUString aValue;
466cdf0e10cSrcweir         rValue >>= aValue;
467cdf0e10cSrcweir         util::DateTime aDate;
468cdf0e10cSrcweir         DateTimeHelper::convert( aValue, aDate );
469cdf0e10cSrcweir 
470cdf0e10cSrcweir         (*m_xProps)[ rtl::OUString::createFromAscii( "DateCreated" ) ]
471cdf0e10cSrcweir             = PropertyValue( uno::makeAny( aDate ), true );
472cdf0e10cSrcweir     }
473cdf0e10cSrcweir     //  else if ( rName.equals( DAVProperties::DISPLAYNAME ) )
474cdf0e10cSrcweir     //  {
475cdf0e10cSrcweir     //  }
476cdf0e10cSrcweir     //  else if ( rName.equals( DAVProperties::GETCONTENTLANGUAGE ) )
477cdf0e10cSrcweir     //  {
478cdf0e10cSrcweir     //  }
479cdf0e10cSrcweir     else if ( rName.equals( DAVProperties::GETCONTENTLENGTH ) )
480cdf0e10cSrcweir     {
481cdf0e10cSrcweir         // Map DAV:getcontentlength to UCP:Size
482cdf0e10cSrcweir         rtl::OUString aValue;
483cdf0e10cSrcweir         rValue >>= aValue;
484cdf0e10cSrcweir 
485cdf0e10cSrcweir         (*m_xProps)[ rtl::OUString::createFromAscii( "Size" ) ]
486cdf0e10cSrcweir             = PropertyValue( uno::makeAny( aValue.toInt64() ), true );
487cdf0e10cSrcweir     }
488cdf0e10cSrcweir     else if ( rName.equalsAsciiL(
489cdf0e10cSrcweir                 RTL_CONSTASCII_STRINGPARAM( "Content-Length" ) ) )
490cdf0e10cSrcweir     {
491cdf0e10cSrcweir         // Do NOT map Content-Lenght entity header to DAV:getcontentlength!
492cdf0e10cSrcweir         // Only DAV resources have this property.
493cdf0e10cSrcweir 
494cdf0e10cSrcweir         // Map Content-Length entity header to UCP:Size
495cdf0e10cSrcweir         rtl::OUString aValue;
496cdf0e10cSrcweir         rValue >>= aValue;
497cdf0e10cSrcweir 
498cdf0e10cSrcweir         (*m_xProps)[ rtl::OUString::createFromAscii( "Size" ) ]
499cdf0e10cSrcweir             = PropertyValue( uno::makeAny( aValue.toInt64() ), true );
500cdf0e10cSrcweir     }
501cdf0e10cSrcweir     else if ( rName.equals( DAVProperties::GETCONTENTTYPE ) )
502cdf0e10cSrcweir     {
503cdf0e10cSrcweir         // Map DAV:getcontenttype to UCP:MediaType (1:1)
504cdf0e10cSrcweir         (*m_xProps)[ rtl::OUString::createFromAscii( "MediaType" ) ]
505cdf0e10cSrcweir             = PropertyValue( rValue, true );
506cdf0e10cSrcweir     }
507cdf0e10cSrcweir     else if ( rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Content-Type" ) ) )
508cdf0e10cSrcweir     {
509cdf0e10cSrcweir         // Do NOT map Content-Type entity header to DAV:getcontenttype!
510cdf0e10cSrcweir         // Only DAV resources have this property.
511cdf0e10cSrcweir 
512cdf0e10cSrcweir         // Map DAV:getcontenttype to UCP:MediaType (1:1)
513cdf0e10cSrcweir         (*m_xProps)[ rtl::OUString::createFromAscii( "MediaType" ) ]
514cdf0e10cSrcweir             = PropertyValue( rValue, true );
515cdf0e10cSrcweir     }
516cdf0e10cSrcweir     //  else if ( rName.equals( DAVProperties::GETETAG ) )
517cdf0e10cSrcweir     //  {
518cdf0e10cSrcweir     //  }
519cdf0e10cSrcweir     else if ( rName.equals( DAVProperties::GETLASTMODIFIED ) )
520cdf0e10cSrcweir     {
521cdf0e10cSrcweir         // Map the DAV:getlastmodified entity header to UCP:DateModified
522cdf0e10cSrcweir         rtl::OUString aValue;
523cdf0e10cSrcweir         rValue >>= aValue;
524cdf0e10cSrcweir         util::DateTime aDate;
525cdf0e10cSrcweir         DateTimeHelper::convert( aValue, aDate );
526cdf0e10cSrcweir 
527cdf0e10cSrcweir         (*m_xProps)[ rtl::OUString::createFromAscii( "DateModified" ) ]
528cdf0e10cSrcweir             = PropertyValue( uno::makeAny( aDate ), true );
529cdf0e10cSrcweir     }
530cdf0e10cSrcweir     else if ( rName.equalsAsciiL(
531cdf0e10cSrcweir                 RTL_CONSTASCII_STRINGPARAM( "Last-Modified" ) ) )
532cdf0e10cSrcweir     {
533cdf0e10cSrcweir         // Do not map Last-Modified entity header to DAV:getlastmodified!
534cdf0e10cSrcweir         // Only DAV resources have this property.
535cdf0e10cSrcweir 
536cdf0e10cSrcweir         // Map the Last-Modified entity header to UCP:DateModified
537cdf0e10cSrcweir         rtl::OUString aValue;
538cdf0e10cSrcweir         rValue >>= aValue;
539cdf0e10cSrcweir         util::DateTime aDate;
540cdf0e10cSrcweir         DateTimeHelper::convert( aValue, aDate );
541cdf0e10cSrcweir 
542cdf0e10cSrcweir         (*m_xProps)[ rtl::OUString::createFromAscii( "DateModified" ) ]
543cdf0e10cSrcweir             = PropertyValue( uno::makeAny( aDate ), true );
544cdf0e10cSrcweir     }
545cdf0e10cSrcweir     //  else if ( rName.equals( DAVProperties::LOCKDISCOVERY ) )
546cdf0e10cSrcweir     //  {
547cdf0e10cSrcweir     //  }
548cdf0e10cSrcweir     else if ( rName.equals( DAVProperties::RESOURCETYPE ) )
549cdf0e10cSrcweir     {
550cdf0e10cSrcweir         rtl::OUString aValue;
551cdf0e10cSrcweir         rValue >>= aValue;
552cdf0e10cSrcweir 
553cdf0e10cSrcweir         // Map DAV:resourceype to UCP:IsFolder, UCP:IsDocument, UCP:ContentType
554cdf0e10cSrcweir         sal_Bool bFolder =
555cdf0e10cSrcweir             aValue.equalsIgnoreAsciiCaseAsciiL(
556cdf0e10cSrcweir                 RTL_CONSTASCII_STRINGPARAM( "collection" ) );
557cdf0e10cSrcweir 
558cdf0e10cSrcweir         (*m_xProps)[ rtl::OUString::createFromAscii( "IsFolder" ) ]
559cdf0e10cSrcweir             = PropertyValue( uno::makeAny( bFolder ), true );
560cdf0e10cSrcweir         (*m_xProps)[ rtl::OUString::createFromAscii( "IsDocument" ) ]
561cdf0e10cSrcweir             = PropertyValue( uno::makeAny( sal_Bool( !bFolder ) ), true );
562cdf0e10cSrcweir         (*m_xProps)[ rtl::OUString::createFromAscii( "ContentType" ) ]
563cdf0e10cSrcweir             = PropertyValue( uno::makeAny( bFolder
564cdf0e10cSrcweir                 ? rtl::OUString::createFromAscii( WEBDAV_COLLECTION_TYPE )
565cdf0e10cSrcweir                 : rtl::OUString::createFromAscii( WEBDAV_CONTENT_TYPE ) ), true );
566cdf0e10cSrcweir     }
567cdf0e10cSrcweir     //  else if ( rName.equals( DAVProperties::SUPPORTEDLOCK ) )
568cdf0e10cSrcweir     //  {
569cdf0e10cSrcweir     //  }
570cdf0e10cSrcweir 
571cdf0e10cSrcweir     // Save property.
572cdf0e10cSrcweir     (*m_xProps)[ rName ] = PropertyValue( rValue, bIsCaseSensitive );
573cdf0e10cSrcweir }
574cdf0e10cSrcweir 
575cdf0e10cSrcweir //=========================================================================
576cdf0e10cSrcweir //=========================================================================
577cdf0e10cSrcweir //
578cdf0e10cSrcweir // CachableContentProperties Implementation.
579cdf0e10cSrcweir //
580cdf0e10cSrcweir //=========================================================================
581cdf0e10cSrcweir //=========================================================================
582cdf0e10cSrcweir 
583cdf0e10cSrcweir namespace
584cdf0e10cSrcweir {
isCachable(rtl::OUString const & rName,bool isCaseSensitive)585cdf0e10cSrcweir     bool isCachable( rtl::OUString const & rName,
586cdf0e10cSrcweir                      bool isCaseSensitive )
587cdf0e10cSrcweir     {
588cdf0e10cSrcweir         static rtl::OUString aNonCachableProps [] =
589cdf0e10cSrcweir         {
590cdf0e10cSrcweir             DAVProperties::LOCKDISCOVERY,
591cdf0e10cSrcweir 
592cdf0e10cSrcweir             DAVProperties::GETETAG,
593cdf0e10cSrcweir             rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ETag" ) ),
594cdf0e10cSrcweir 
595cdf0e10cSrcweir             rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DateModified" ) ),
596cdf0e10cSrcweir             rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Last-Modified" ) ),
597cdf0e10cSrcweir             DAVProperties::GETLASTMODIFIED,
598cdf0e10cSrcweir 
599cdf0e10cSrcweir             rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Size" ) ),
600cdf0e10cSrcweir             rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Content-Length" ) ),
601cdf0e10cSrcweir             DAVProperties::GETCONTENTLENGTH,
602cdf0e10cSrcweir 
603cdf0e10cSrcweir             rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Date" ) )
604cdf0e10cSrcweir         };
605cdf0e10cSrcweir 
606cdf0e10cSrcweir         for ( sal_uInt32 n = 0;
607cdf0e10cSrcweir               n <  ( sizeof( aNonCachableProps )
608cdf0e10cSrcweir                      / sizeof( aNonCachableProps[ 0 ] ) );
609cdf0e10cSrcweir               ++n )
610cdf0e10cSrcweir         {
611cdf0e10cSrcweir             if ( isCaseSensitive )
612cdf0e10cSrcweir             {
613cdf0e10cSrcweir                 if ( rName.equals( aNonCachableProps[ n ] ) )
614cdf0e10cSrcweir                     return false;
615cdf0e10cSrcweir             }
616cdf0e10cSrcweir             else
617cdf0e10cSrcweir                 if ( rName.equalsIgnoreAsciiCase( aNonCachableProps[ n ] ) )
618cdf0e10cSrcweir                     return false;
619cdf0e10cSrcweir         }
620cdf0e10cSrcweir         return true;
621cdf0e10cSrcweir     }
622cdf0e10cSrcweir 
623cdf0e10cSrcweir } // namespace
624cdf0e10cSrcweir 
625cdf0e10cSrcweir //=========================================================================
CachableContentProperties(const ContentProperties & rProps)626cdf0e10cSrcweir CachableContentProperties::CachableContentProperties(
627cdf0e10cSrcweir     const ContentProperties & rProps )
628cdf0e10cSrcweir {
629cdf0e10cSrcweir     addProperties( rProps );
630cdf0e10cSrcweir }
631cdf0e10cSrcweir 
632cdf0e10cSrcweir //=========================================================================
addProperties(const ContentProperties & rProps)633cdf0e10cSrcweir void CachableContentProperties::addProperties(
634cdf0e10cSrcweir     const ContentProperties & rProps )
635cdf0e10cSrcweir {
636cdf0e10cSrcweir     const std::auto_ptr< PropertyValueMap > & props = rProps.getProperties();
637cdf0e10cSrcweir 
638cdf0e10cSrcweir     PropertyValueMap::const_iterator it = props->begin();
639cdf0e10cSrcweir     const PropertyValueMap::const_iterator end = props->end();
640cdf0e10cSrcweir 
641cdf0e10cSrcweir     while ( it != end )
642cdf0e10cSrcweir     {
643cdf0e10cSrcweir         if ( isCachable( (*it).first, (*it).second.isCaseSensitive() ) )
644cdf0e10cSrcweir             m_aProps.addProperty( (*it).first,
645cdf0e10cSrcweir                                   (*it).second.value(),
646cdf0e10cSrcweir                                   (*it).second.isCaseSensitive() );
647cdf0e10cSrcweir 
648cdf0e10cSrcweir         ++it;
649cdf0e10cSrcweir     }
650cdf0e10cSrcweir }
651cdf0e10cSrcweir 
652cdf0e10cSrcweir //=========================================================================
addProperties(const std::vector<DAVPropertyValue> & rProps)653cdf0e10cSrcweir void CachableContentProperties::addProperties(
654cdf0e10cSrcweir     const std::vector< DAVPropertyValue > & rProps )
655cdf0e10cSrcweir {
656cdf0e10cSrcweir     std::vector< DAVPropertyValue >::const_iterator it  = rProps.begin();
657cdf0e10cSrcweir     const std::vector< DAVPropertyValue >::const_iterator end = rProps.end();
658cdf0e10cSrcweir 
659cdf0e10cSrcweir     while ( it != end )
660cdf0e10cSrcweir     {
661cdf0e10cSrcweir         if ( isCachable( (*it).Name, (*it).IsCaseSensitive ) )
662cdf0e10cSrcweir             m_aProps.addProperty( (*it) );
663cdf0e10cSrcweir 
664cdf0e10cSrcweir         ++it;
665cdf0e10cSrcweir      }
666cdf0e10cSrcweir }
667