Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*************************************************************************
3 : *
4 : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : *
6 : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : *
8 : * OpenOffice.org - a multi-platform office productivity suite
9 : *
10 : * This file is part of OpenOffice.org.
11 : *
12 : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : * it under the terms of the GNU Lesser General Public License version 3
14 : * only, as published by the Free Software Foundation.
15 : *
16 : * OpenOffice.org is distributed in the hope that it will be useful,
17 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : * GNU Lesser General Public License version 3 for more details
20 : * (a copy is included in the LICENSE file that accompanied this code).
21 : *
22 : * You should have received a copy of the GNU Lesser General Public License
23 : * version 3 along with OpenOffice.org. If not, see
24 : * <http://www.openoffice.org/license.html>
25 : * for a copy of the LGPLv3 License.
26 : *
27 : ************************************************************************/
28 :
29 : #ifndef _WEBDAV_UCP_CONTENTPROPERTIES_HXX
30 : #define _WEBDAV_UCP_CONTENTPROPERTIES_HXX
31 :
32 : #include <memory>
33 : #include <vector>
34 : #include <boost/unordered_map.hpp>
35 : #include <rtl/ustring.hxx>
36 : #include <com/sun/star/uno/Any.hxx>
37 : #include <com/sun/star/uno/Sequence.hxx>
38 :
39 : namespace com { namespace sun { namespace star { namespace beans {
40 : struct Property;
41 : } } } }
42 :
43 : namespace webdav_ucp
44 : {
45 :
46 : struct DAVResource;
47 :
48 : //=========================================================================
49 :
50 : struct equalString
51 : {
52 0 : bool operator()( const rtl::OUString& s1, const rtl::OUString& s2 ) const
53 : {
54 0 : return !!( s1 == s2 );
55 : }
56 : };
57 :
58 : struct hashString
59 : {
60 0 : size_t operator()( const rtl::OUString & rName ) const
61 : {
62 0 : return rName.hashCode();
63 : }
64 : };
65 :
66 : //=========================================================================
67 : //
68 : // PropertyValueMap.
69 : //
70 : //=========================================================================
71 :
72 0 : class PropertyValue
73 : {
74 : private:
75 : ::com::sun::star::uno::Any m_aValue;
76 : bool m_bIsCaseSensitive;
77 :
78 : public:
79 0 : PropertyValue()
80 0 : : m_bIsCaseSensitive( true ) {}
81 :
82 0 : PropertyValue( const ::com::sun::star::uno::Any & rValue,
83 : bool bIsCaseSensitive )
84 : : m_aValue( rValue),
85 0 : m_bIsCaseSensitive( bIsCaseSensitive ) {}
86 :
87 0 : bool isCaseSensitive() const { return m_bIsCaseSensitive; }
88 0 : const ::com::sun::star::uno::Any & value() const { return m_aValue; }
89 :
90 : };
91 :
92 : typedef boost::unordered_map
93 : <
94 : rtl::OUString,
95 : PropertyValue,
96 : hashString,
97 : equalString
98 : >
99 : PropertyValueMap;
100 :
101 : struct DAVResource;
102 :
103 0 : class ContentProperties
104 : {
105 : public:
106 : ContentProperties();
107 :
108 : ContentProperties( const DAVResource& rResource );
109 :
110 : // Mini props for transient contents.
111 : ContentProperties( const rtl::OUString & rTitle, sal_Bool bFolder );
112 :
113 : // Micro props for non-existing contents.
114 : ContentProperties( const rtl::OUString & rTitle );
115 :
116 : ContentProperties( const ContentProperties & rOther );
117 :
118 : bool contains( const rtl::OUString & rName ) const;
119 :
120 : const com::sun::star::uno::Any &
121 : getValue( const rtl::OUString & rName ) const;
122 :
123 : // Maps the UCB property names contained in rProps with their DAV property
124 : // counterparts, if possible. All unmappable properties will be included
125 : // unchanged in resulting vector unless bIncludeUnmatched is set to false.
126 : // The vector filles by this method can directly be handed over to
127 : // DAVResourceAccess::PROPFIND. The result from PROPFIND
128 : // (vector< DAVResource >) can be used to create a ContentProperties
129 : // instance which can map DAV properties back to UCB properties.
130 : static void UCBNamesToDAVNames( const com::sun::star::uno::Sequence<
131 : com::sun::star::beans::Property > &
132 : rProps,
133 : std::vector< rtl::OUString > & resources,
134 : bool bIncludeUnmatched = true );
135 :
136 : // Maps the UCB property names contained in rProps with their HTTP header
137 : // counterparts, if possible. All unmappable properties will be included
138 : // unchanged in resulting vector unless bIncludeUnmatched is set to false.
139 : // The vector filles by this method can directly be handed over to
140 : // DAVResourceAccess::HEAD. The result from HEAD (vector< DAVResource >)
141 : // can be used to create a ContentProperties instance which can map header
142 : // names back to UCB properties.
143 : static void UCBNamesToHTTPNames( const com::sun::star::uno::Sequence<
144 : com::sun::star::beans::Property > &
145 : rProps,
146 : std::vector< rtl::OUString > & resources,
147 : bool bIncludeUnmatched = true );
148 :
149 : // return true, if all properties contained in rProps are contained in
150 : // this ContentProperties instance. Otherwiese, false will be returned.
151 : // rNamesNotContained contain the missing names.
152 : bool containsAllNames(
153 : const com::sun::star::uno::Sequence<
154 : com::sun::star::beans::Property >& rProps,
155 : std::vector< rtl::OUString > & rNamesNotContained ) const;
156 :
157 : // adds all properties described by rProps that are actually contained in
158 : // rContentProps to this instance. In case of duplicates the value
159 : // already contained in this will left unchanged.
160 : void addProperties( const std::vector< rtl::OUString > & rProps,
161 : const ContentProperties & rContentProps );
162 :
163 : // overwrites probably existing entry.
164 : void addProperty( const rtl::OUString & rName,
165 : const com::sun::star::uno::Any & rValue,
166 : bool bIsCaseSensitive );
167 :
168 : // overwrites probably existing entry.
169 : void addProperty( const DAVPropertyValue & rProp );
170 :
171 0 : bool isTrailingSlash() const { return m_bTrailingSlash; }
172 :
173 0 : const rtl::OUString & getEscapedTitle() const { return m_aEscapedTitle; }
174 :
175 : // Not good to expose implementation details, but this is actually an
176 : // internal class.
177 0 : const std::auto_ptr< PropertyValueMap > & getProperties() const
178 0 : { return m_xProps; }
179 :
180 : private:
181 : ::rtl::OUString m_aEscapedTitle;
182 : std::auto_ptr< PropertyValueMap > m_xProps;
183 : bool m_bTrailingSlash;
184 :
185 : static com::sun::star::uno::Any m_aEmptyAny;
186 :
187 : ContentProperties & operator=( const ContentProperties & ); // n.i.
188 :
189 : const PropertyValue * get( const rtl::OUString & rName ) const;
190 : };
191 :
192 0 : class CachableContentProperties
193 : {
194 : private:
195 : ContentProperties m_aProps;
196 :
197 : CachableContentProperties & operator=( const CachableContentProperties & ); // n.i.
198 : CachableContentProperties( const CachableContentProperties & ); // n.i.
199 :
200 : public:
201 : CachableContentProperties( const ContentProperties & rProps );
202 :
203 : void addProperties( const ContentProperties & rProps );
204 :
205 : void addProperties( const std::vector< DAVPropertyValue > & rProps );
206 :
207 0 : bool containsAllNames(
208 : const com::sun::star::uno::Sequence<
209 : com::sun::star::beans::Property >& rProps,
210 : std::vector< rtl::OUString > & rNamesNotContained ) const
211 0 : { return m_aProps.containsAllNames( rProps, rNamesNotContained ); }
212 :
213 : const com::sun::star::uno::Any &
214 0 : getValue( const rtl::OUString & rName ) const
215 0 : { return m_aProps.getValue( rName ); }
216 :
217 0 : operator const ContentProperties & () const { return m_aProps; }
218 : };
219 :
220 : } // namespace webdav_ucp
221 :
222 : #endif /* !_WEBDAV_UCP_CONTENTPROPERTIES_HXX */
223 :
224 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|