1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
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.
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).
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.
27 ************************************************************************/
29 #ifndef INCLUDED_UCB_SOURCE_UCP_WEBDAV_NEON_CONTENTPROPERTIES_HXX
30 #define INCLUDED_UCB_SOURCE_UCP_WEBDAV_NEON_CONTENTPROPERTIES_HXX
32 #include <config_lgpl.h>
34 #include <unordered_map>
36 #include <rtl/ustring.hxx>
37 #include <com/sun/star/uno/Any.hxx>
38 #include <com/sun/star/uno/Sequence.hxx>
40 namespace com
{ namespace sun
{ namespace star
{ namespace beans
{
53 ::com::sun::star::uno::Any m_aValue
;
54 bool m_bIsCaseSensitive
;
58 : m_bIsCaseSensitive( true ) {}
60 PropertyValue( const ::com::sun::star::uno::Any
& rValue
,
61 bool bIsCaseSensitive
)
63 m_bIsCaseSensitive( bIsCaseSensitive
) {}
65 bool isCaseSensitive() const { return m_bIsCaseSensitive
; }
66 const ::com::sun::star::uno::Any
& value() const { return m_aValue
; }
70 typedef std::unordered_map
80 class ContentProperties
85 ContentProperties( const DAVResource
& rResource
);
87 // Mini props for transient contents.
88 ContentProperties( const OUString
& rTitle
, bool bFolder
);
90 // Micro props for non-existing contents.
91 ContentProperties( const OUString
& rTitle
);
93 ContentProperties( const ContentProperties
& rOther
);
95 bool contains( const OUString
& rName
) const;
97 const com::sun::star::uno::Any
&
98 getValue( const OUString
& rName
) const;
100 // Maps the UCB property names contained in rProps with their DAV property
101 // counterparts, if possible. All unmappable properties will be included
102 // unchanged in resulting vector unless bIncludeUnmatched is set to false.
103 // The vector filles by this method can directly be handed over to
104 // DAVResourceAccess::PROPFIND. The result from PROPFIND
105 // (vector< DAVResource >) can be used to create a ContentProperties
106 // instance which can map DAV properties back to UCB properties.
107 static void UCBNamesToDAVNames( const com::sun::star::uno::Sequence
<
108 com::sun::star::beans::Property
> &
110 std::vector
< OUString
> & resources
,
111 bool bIncludeUnmatched
= true );
113 // Maps the UCB property names contained in rProps with their HTTP header
114 // counterparts, if possible. All unmappable properties will be included
115 // unchanged in resulting vector unless bIncludeUnmatched is set to false.
116 // The vector filles by this method can directly be handed over to
117 // DAVResourceAccess::HEAD. The result from HEAD (vector< DAVResource >)
118 // can be used to create a ContentProperties instance which can map header
119 // names back to UCB properties.
120 static void UCBNamesToHTTPNames( const com::sun::star::uno::Sequence
<
121 com::sun::star::beans::Property
> &
123 std::vector
< OUString
> & resources
,
124 bool bIncludeUnmatched
= true );
126 // return true, if all properties contained in rProps are contained in
127 // this ContentProperties instance. Otherwiese, false will be returned.
128 // rNamesNotContained contain the missing names.
129 bool containsAllNames(
130 const com::sun::star::uno::Sequence
<
131 com::sun::star::beans::Property
>& rProps
,
132 std::vector
< OUString
> & rNamesNotContained
) const;
134 // adds all properties described by rProps that are actually contained in
135 // rContentProps to this instance. In case of duplicates the value
136 // already contained in this will left unchanged.
137 void addProperties( const std::vector
< OUString
> & rProps
,
138 const ContentProperties
& rContentProps
);
140 // overwrites probably existing entry.
141 void addProperty( const OUString
& rName
,
142 const com::sun::star::uno::Any
& rValue
,
143 bool bIsCaseSensitive
);
145 // overwrites probably existing entry.
146 void addProperty( const DAVPropertyValue
& rProp
);
148 bool isTrailingSlash() const { return m_bTrailingSlash
; }
150 const OUString
& getEscapedTitle() const { return m_aEscapedTitle
; }
152 // Not good to expose implementation details, but this is actually an
154 const std::unique_ptr
< PropertyValueMap
> & getProperties() const
158 OUString m_aEscapedTitle
;
159 std::unique_ptr
< PropertyValueMap
> m_xProps
;
160 bool m_bTrailingSlash
;
162 static com::sun::star::uno::Any m_aEmptyAny
;
164 ContentProperties
& operator=( const ContentProperties
& ) SAL_DELETED_FUNCTION
;
166 const PropertyValue
* get( const OUString
& rName
) const;
169 class CachableContentProperties
172 ContentProperties m_aProps
;
174 CachableContentProperties
& operator=( const CachableContentProperties
& ) SAL_DELETED_FUNCTION
;
175 CachableContentProperties( const CachableContentProperties
& ) SAL_DELETED_FUNCTION
;
178 CachableContentProperties( const ContentProperties
& rProps
);
180 void addProperties( const ContentProperties
& rProps
);
182 void addProperties( const std::vector
< DAVPropertyValue
> & rProps
);
184 bool containsAllNames(
185 const com::sun::star::uno::Sequence
<
186 com::sun::star::beans::Property
>& rProps
,
187 std::vector
< OUString
> & rNamesNotContained
) const
188 { return m_aProps
.containsAllNames( rProps
, rNamesNotContained
); }
190 const com::sun::star::uno::Any
&
191 getValue( const OUString
& rName
) const
192 { return m_aProps
.getValue( rName
); }
194 operator const ContentProperties
& () const { return m_aProps
; }
197 } // namespace webdav_ucp
199 #endif // INCLUDED_UCB_SOURCE_UCP_WEBDAV_NEON_CONTENTPROPERTIES_HXX
201 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */