xref: /AOO41X/main/ucb/source/ucp/webdav/ContentProperties.hxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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 #ifndef _WEBDAV_UCP_CONTENTPROPERTIES_HXX
29*cdf0e10cSrcweir #define _WEBDAV_UCP_CONTENTPROPERTIES_HXX
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <memory>
32*cdf0e10cSrcweir #include <vector>
33*cdf0e10cSrcweir #include <hash_map>
34*cdf0e10cSrcweir #include <rtl/ustring.hxx>
35*cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx>
36*cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx>
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir namespace com { namespace sun { namespace star { namespace beans {
39*cdf0e10cSrcweir     struct Property;
40*cdf0e10cSrcweir } } } }
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir namespace webdav_ucp
43*cdf0e10cSrcweir {
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir struct DAVResource;
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir //=========================================================================
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir struct equalString
50*cdf0e10cSrcweir {
51*cdf0e10cSrcweir   bool operator()( const rtl::OUString& s1, const rtl::OUString& s2 ) const
52*cdf0e10cSrcweir   {
53*cdf0e10cSrcweir       return !!( s1 == s2 );
54*cdf0e10cSrcweir   }
55*cdf0e10cSrcweir };
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir struct hashString
58*cdf0e10cSrcweir {
59*cdf0e10cSrcweir     size_t operator()( const rtl::OUString & rName ) const
60*cdf0e10cSrcweir     {
61*cdf0e10cSrcweir         return rName.hashCode();
62*cdf0e10cSrcweir     }
63*cdf0e10cSrcweir };
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir //=========================================================================
66*cdf0e10cSrcweir //
67*cdf0e10cSrcweir // PropertyValueMap.
68*cdf0e10cSrcweir //
69*cdf0e10cSrcweir //=========================================================================
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir class PropertyValue
72*cdf0e10cSrcweir {
73*cdf0e10cSrcweir private:
74*cdf0e10cSrcweir     ::com::sun::star::uno::Any m_aValue;
75*cdf0e10cSrcweir     bool                       m_bIsCaseSensitive;
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir public:
78*cdf0e10cSrcweir     PropertyValue()
79*cdf0e10cSrcweir     : m_bIsCaseSensitive( true ) {}
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir     PropertyValue( const ::com::sun::star::uno::Any & rValue,
82*cdf0e10cSrcweir                    bool bIsCaseSensitive )
83*cdf0e10cSrcweir     : m_aValue( rValue),
84*cdf0e10cSrcweir       m_bIsCaseSensitive( bIsCaseSensitive ) {}
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir     bool isCaseSensitive() const { return m_bIsCaseSensitive; }
87*cdf0e10cSrcweir     const ::com::sun::star::uno::Any & value() const { return m_aValue; }
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir };
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir typedef std::hash_map
92*cdf0e10cSrcweir <
93*cdf0e10cSrcweir     rtl::OUString,
94*cdf0e10cSrcweir     PropertyValue,
95*cdf0e10cSrcweir     hashString,
96*cdf0e10cSrcweir     equalString
97*cdf0e10cSrcweir >
98*cdf0e10cSrcweir PropertyValueMap;
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir struct DAVResource;
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir class ContentProperties
103*cdf0e10cSrcweir {
104*cdf0e10cSrcweir public:
105*cdf0e10cSrcweir     ContentProperties();
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir     ContentProperties( const DAVResource& rResource );
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir     // Mini props for transient contents.
110*cdf0e10cSrcweir     ContentProperties( const rtl::OUString & rTitle, sal_Bool bFolder );
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir     // Micro props for non-existing contents.
113*cdf0e10cSrcweir     ContentProperties( const rtl::OUString & rTitle );
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir     ContentProperties( const ContentProperties & rOther );
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir     bool contains( const rtl::OUString & rName ) const;
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir     const com::sun::star::uno::Any &
120*cdf0e10cSrcweir     getValue( const rtl::OUString & rName ) const;
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir     // Maps the UCB property names contained in rProps with their DAV property
123*cdf0e10cSrcweir     // counterparts, if possible. All unmappable properties will be included
124*cdf0e10cSrcweir     // unchanged in resulting vector unless bIncludeUnmatched is set to false.
125*cdf0e10cSrcweir     // The vector filles by this method can directly be handed over to
126*cdf0e10cSrcweir     // DAVResourceAccess::PROPFIND. The result from PROPFIND
127*cdf0e10cSrcweir     // (vector< DAVResource >) can be used to create a ContentProperties
128*cdf0e10cSrcweir     // instance which can map DAV properties back to UCB properties.
129*cdf0e10cSrcweir     static void UCBNamesToDAVNames( const com::sun::star::uno::Sequence<
130*cdf0e10cSrcweir                                         com::sun::star::beans::Property > &
131*cdf0e10cSrcweir                                             rProps,
132*cdf0e10cSrcweir                                     std::vector< rtl::OUString > & resources,
133*cdf0e10cSrcweir                                     bool bIncludeUnmatched = true );
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir     // Maps the UCB property names contained in rProps with their HTTP header
136*cdf0e10cSrcweir     // counterparts, if possible. All unmappable properties will be included
137*cdf0e10cSrcweir     // unchanged in resulting vector unless bIncludeUnmatched is set to false.
138*cdf0e10cSrcweir     // The vector filles by this method can directly be handed over to
139*cdf0e10cSrcweir     // DAVResourceAccess::HEAD. The result from HEAD (vector< DAVResource >)
140*cdf0e10cSrcweir     // can be used to create a ContentProperties instance which can map header
141*cdf0e10cSrcweir     // names back to UCB properties.
142*cdf0e10cSrcweir     static void UCBNamesToHTTPNames( const com::sun::star::uno::Sequence<
143*cdf0e10cSrcweir                                         com::sun::star::beans::Property > &
144*cdf0e10cSrcweir                                             rProps,
145*cdf0e10cSrcweir                                     std::vector< rtl::OUString > & resources,
146*cdf0e10cSrcweir                                     bool bIncludeUnmatched = true );
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir     // return true, if all properties contained in rProps are contained in
149*cdf0e10cSrcweir     // this ContentProperties instance. Otherwiese, false will be returned.
150*cdf0e10cSrcweir     // rNamesNotContained contain the missing names.
151*cdf0e10cSrcweir     bool containsAllNames(
152*cdf0e10cSrcweir                     const com::sun::star::uno::Sequence<
153*cdf0e10cSrcweir                         com::sun::star::beans::Property >& rProps,
154*cdf0e10cSrcweir                     std::vector< rtl::OUString > & rNamesNotContained ) const;
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir     // adds all properties described by rProps that are actually contained in
157*cdf0e10cSrcweir     // rContentProps to this instance. In case of duplicates the value
158*cdf0e10cSrcweir     // already contained in this will left unchanged.
159*cdf0e10cSrcweir     void addProperties( const std::vector< rtl::OUString > & rProps,
160*cdf0e10cSrcweir                         const ContentProperties & rContentProps );
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir     // overwrites probably existing entries.
163*cdf0e10cSrcweir     void addProperties( const ContentProperties & rProps );
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir     // overwrites probably existing entries.
166*cdf0e10cSrcweir     void addProperties( const std::vector< DAVPropertyValue > & rProps );
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir     // overwrites probably existing entry.
169*cdf0e10cSrcweir     void addProperty( const rtl::OUString & rName,
170*cdf0e10cSrcweir                      const com::sun::star::uno::Any & rValue,
171*cdf0e10cSrcweir                      bool bIsCaseSensitive );
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir     // overwrites probably existing entry.
174*cdf0e10cSrcweir     void addProperty( const DAVPropertyValue & rProp );
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir     bool isTrailingSlash() const { return m_bTrailingSlash; }
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir     const rtl::OUString & getEscapedTitle() const { return m_aEscapedTitle; }
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir     // Not good to expose implementation details, but this is actually an
181*cdf0e10cSrcweir     // internal class.
182*cdf0e10cSrcweir     const std::auto_ptr< PropertyValueMap > & getProperties() const
183*cdf0e10cSrcweir     { return m_xProps; }
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir private:
186*cdf0e10cSrcweir     ::rtl::OUString m_aEscapedTitle;
187*cdf0e10cSrcweir     std::auto_ptr< PropertyValueMap > m_xProps;
188*cdf0e10cSrcweir     bool m_bTrailingSlash;
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir     static com::sun::star::uno::Any m_aEmptyAny;
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir     ContentProperties & operator=( const ContentProperties & ); // n.i.
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir     const PropertyValue * get( const rtl::OUString & rName ) const;
195*cdf0e10cSrcweir };
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir class CachableContentProperties
198*cdf0e10cSrcweir {
199*cdf0e10cSrcweir private:
200*cdf0e10cSrcweir     ContentProperties m_aProps;
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir     CachableContentProperties & operator=( const CachableContentProperties & ); // n.i.
203*cdf0e10cSrcweir     CachableContentProperties( const CachableContentProperties & ); // n.i.
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir public:
206*cdf0e10cSrcweir     CachableContentProperties( const ContentProperties & rProps );
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir     void addProperties( const ContentProperties & rProps );
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir     void addProperties( const std::vector< DAVPropertyValue > & rProps );
211*cdf0e10cSrcweir 
212*cdf0e10cSrcweir     bool containsAllNames(
213*cdf0e10cSrcweir                     const com::sun::star::uno::Sequence<
214*cdf0e10cSrcweir                         com::sun::star::beans::Property >& rProps,
215*cdf0e10cSrcweir                     std::vector< rtl::OUString > & rNamesNotContained ) const
216*cdf0e10cSrcweir     { return m_aProps.containsAllNames( rProps, rNamesNotContained ); }
217*cdf0e10cSrcweir 
218*cdf0e10cSrcweir     const com::sun::star::uno::Any &
219*cdf0e10cSrcweir     getValue( const rtl::OUString & rName ) const
220*cdf0e10cSrcweir     { return m_aProps.getValue( rName ); }
221*cdf0e10cSrcweir 
222*cdf0e10cSrcweir     operator const ContentProperties & () const { return m_aProps; }
223*cdf0e10cSrcweir };
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir } // namespace webdav_ucp
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir #endif /* !_WEBDAV_UCP_CONTENTPROPERTIES_HXX */
228