1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #ifndef INCLUDED_UCB_SOURCE_UCP_WEBDAV_CONTENTPROPERTIES_HXX
22 #define INCLUDED_UCB_SOURCE_UCP_WEBDAV_CONTENTPROPERTIES_HXX
25 #include <unordered_map>
27 #include <rtl/ustring.hxx>
28 #include <com/sun/star/uno/Any.hxx>
29 #include <com/sun/star/uno/Sequence.hxx>
30 #include "DAVResource.hxx"
32 namespace com
{ namespace sun
{ namespace star
{ namespace beans
{
36 namespace http_dav_ucp
45 css::uno::Any m_aValue
;
46 bool m_bIsCaseSensitive
;
50 : m_bIsCaseSensitive( true ) {}
52 explicit PropertyValue( const css::uno::Any
& rValue
,
53 bool bIsCaseSensitive
)
55 m_bIsCaseSensitive( bIsCaseSensitive
) {}
57 bool isCaseSensitive() const { return m_bIsCaseSensitive
; }
58 const css::uno::Any
& value() const { return m_aValue
; }
62 typedef std::unordered_map
< OUString
, PropertyValue
> PropertyValueMap
;
64 class ContentProperties
69 explicit ContentProperties( const DAVResource
& rResource
);
71 // Mini props for transient contents.
72 ContentProperties( const OUString
& rTitle
, bool bFolder
);
74 // Micro props for non-existing contents.
75 explicit ContentProperties( const OUString
& rTitle
);
77 ContentProperties( const ContentProperties
& rOther
);
79 bool contains( const OUString
& rName
) const;
81 const css::uno::Any
& getValue( const OUString
& rName
) const;
83 // Maps the UCB property names contained in rProps with their DAV property
84 // counterparts, if possible. All unmappable properties will be included
85 // unchanged in resulting vector unless bIncludeUnmatched is set to false.
86 // The vector filled by this method can directly be handed over to
87 // DAVResourceAccess::PROPFIND. The result from PROPFIND
88 // (vector< DAVResource >) can be used to create a ContentProperties
89 // instance which can map DAV properties back to UCB properties.
90 static void UCBNamesToDAVNames( const css::uno::Sequence
< css::beans::Property
> & rProps
,
91 std::vector
< OUString
> & resources
,
92 bool bIncludeUnmatched
= true );
94 // Maps the UCB property names contained in rProps with their HTTP header
95 // counterparts, if possible. All unmappable properties will be included
96 // unchanged in resulting vector unless bIncludeUnmatched is set to false.
97 // The vector filled by this method can directly be handed over to
98 // DAVResourceAccess::HEAD. The result from HEAD (vector< DAVResource >)
99 // can be used to create a ContentProperties instance which can map header
100 // names back to UCB properties.
101 static void UCBNamesToHTTPNames( const css::uno::Sequence
< css::beans::Property
> & rProps
,
102 std::vector
< OUString
> & resources
,
103 bool bIncludeUnmatched
= true );
105 // return true, if all properties contained in rProps are contained in
106 // this ContentProperties instance. Otherwise, false will be returned.
107 // rNamesNotContained contain the missing names.
108 bool containsAllNames(
109 const css::uno::Sequence
< css::beans::Property
>& rProps
,
110 std::vector
< OUString
> & rNamesNotContained
) const;
112 // adds all properties described by rProps that are actually contained in
113 // rContentProps to this instance. In case of duplicates the value
114 // already contained in this will left unchanged.
115 void addProperties( const std::vector
< OUString
> & rProps
,
116 const ContentProperties
& rContentProps
);
118 // overwrites probably existing entries.
119 void addProperties( const ContentProperties
& rProps
);
121 // overwrites probably existing entries.
122 void addProperties( const std::vector
< DAVPropertyValue
> & rProps
);
124 // overwrites probably existing entry.
125 void addProperty( const OUString
& rName
,
126 const css::uno::Any
& rValue
,
127 bool bIsCaseSensitive
);
129 // overwrites probably existing entry.
130 void addProperty( const DAVPropertyValue
& rProp
);
132 bool isTrailingSlash() const { return m_bTrailingSlash
; }
134 const OUString
& getEscapedTitle() const { return m_aEscapedTitle
; }
136 // Not good to expose implementation details, but this is actually an
138 const std::unique_ptr
< PropertyValueMap
> & getProperties() const
142 OUString m_aEscapedTitle
;
143 std::unique_ptr
< PropertyValueMap
> m_xProps
;
144 bool m_bTrailingSlash
;
146 static css::uno::Any m_aEmptyAny
;
148 ContentProperties
& operator=( const ContentProperties
& ); // n.i.
150 const PropertyValue
* get( const OUString
& rName
) const;
153 class CachableContentProperties
156 ContentProperties m_aProps
;
158 CachableContentProperties
& operator=( const CachableContentProperties
& ); // n.i.
159 CachableContentProperties( const CachableContentProperties
& ); // n.i.
162 explicit CachableContentProperties( const ContentProperties
& rProps
);
164 void addProperties( const ContentProperties
& rProps
);
166 void addProperties( const std::vector
< DAVPropertyValue
> & rProps
);
168 bool containsAllNames(
169 const css::uno::Sequence
< css::beans::Property
>& rProps
,
170 std::vector
< OUString
> & rNamesNotContained
) const
171 { return m_aProps
.containsAllNames( rProps
, rNamesNotContained
); }
173 const css::uno::Any
&
174 getValue( const OUString
& rName
) const
175 { return m_aProps
.getValue( rName
); }
177 operator const ContentProperties
& () const { return m_aProps
; }
180 } // namespace http_dav_ucp
182 #endif // INCLUDED_UCB_SOURCE_UCP_WEBDAV_CONTENTPROPERTIES_HXX
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */