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