update dev300-m58
[ooovba.git] / ucb / source / ucp / webdav / ContentProperties.hxx
blob4fb9af57f2c9dc9b85b137bf9573f8d1a5ad2aed
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ContentProperties.hxx,v $
10 * $Revision: 1.12.34.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _WEBDAV_UCP_CONTENTPROPERTIES_HXX
32 #define _WEBDAV_UCP_CONTENTPROPERTIES_HXX
34 #include <memory>
35 #include <vector>
36 #include <hash_map>
37 #include <rtl/ustring.hxx>
38 #include <com/sun/star/uno/Any.hxx>
39 #include <com/sun/star/uno/Sequence.hxx>
41 namespace com { namespace sun { namespace star { namespace beans {
42 struct Property;
43 } } } }
45 namespace webdav_ucp
48 struct DAVResource;
50 //=========================================================================
52 struct equalString
54 bool operator()( const rtl::OUString& s1, const rtl::OUString& s2 ) const
56 return !!( s1 == s2 );
60 struct hashString
62 size_t operator()( const rtl::OUString & rName ) const
64 return rName.hashCode();
68 //=========================================================================
70 // PropertyValueMap.
72 //=========================================================================
74 class PropertyValue
76 private:
77 ::com::sun::star::uno::Any m_aValue;
78 bool m_bIsCaseSensitive;
80 public:
81 PropertyValue()
82 : m_bIsCaseSensitive( true ) {}
84 PropertyValue( const ::com::sun::star::uno::Any & rValue,
85 bool bIsCaseSensitive )
86 : m_aValue( rValue),
87 m_bIsCaseSensitive( bIsCaseSensitive ) {}
89 bool isCaseSensitive() const { return m_bIsCaseSensitive; }
90 const ::com::sun::star::uno::Any & value() const { return m_aValue; }
94 typedef std::hash_map
96 rtl::OUString,
97 PropertyValue,
98 hashString,
99 equalString
101 PropertyValueMap;
103 struct DAVResource;
105 class ContentProperties
107 public:
108 ContentProperties( const DAVResource& rResource );
110 // Mini props for transient contents.
111 ContentProperties( const rtl::OUString & rTitle, sal_Bool bFolder );
113 // Micro props for non-existing contents.
114 ContentProperties( const rtl::OUString & rTitle );
116 ContentProperties( const ContentProperties & rOther );
118 bool contains( const rtl::OUString & rName ) const;
120 const com::sun::star::uno::Any &
121 getValue( const rtl::OUString & rName ) const;
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 );
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 );
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;
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 );
163 // overwrites probably existing entries.
164 void addProperties( const ContentProperties & rProps );
166 // overwrites probably existing entries.
167 void addProperties( const std::vector< DAVPropertyValue > & rProps );
169 // overwrites probably existing entry.
170 void addProperty( const rtl::OUString & rName,
171 const com::sun::star::uno::Any & rValue,
172 bool bIsCaseSensitive );
174 // overwrites probably existing entry.
175 void addProperty( const DAVPropertyValue & rProp );
177 bool isTrailingSlash() const { return m_bTrailingSlash; }
179 const rtl::OUString & getEscapedTitle() const { return m_aEscapedTitle; }
181 // Not good to expose implementation details, but this is actually an
182 // internal class.
183 const std::auto_ptr< PropertyValueMap > & getProperties() const
184 { return m_xProps; }
186 private:
187 ::rtl::OUString m_aEscapedTitle; // escaped Title
188 std::auto_ptr< PropertyValueMap > m_xProps;
189 bool m_bTrailingSlash;
191 static com::sun::star::uno::Any m_aEmptyAny;
193 ContentProperties & operator=( const ContentProperties & ); // n.i.
195 const PropertyValue * get( const rtl::OUString & rName ) const;
200 #endif /* !_WEBDAV_UCP_CONTENTPROPERTIES_HXX */