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 .
24 #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::sun::star::beans
{
36 namespace http_dav_ucp
45 css::uno::Any m_aValue
;
46 bool m_bIsCaseSensitive
;
50 : m_bIsCaseSensitive( true ) {}
52 explicit PropertyValue( css::uno::Any aValue
,
53 bool bIsCaseSensitive
)
54 : m_aValue(std::move( aValue
)),
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.
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
);
93 // Maps the UCB property names contained in rProps with their HTTP header
94 // counterparts, if possible. All unmappable properties will be included
95 // unchanged in resulting vector.
96 // The vector filled by this method can directly be handed over to
97 // DAVResourceAccess::HEAD. The result from HEAD (vector< DAVResource >)
98 // can be used to create a ContentProperties instance which can map header
99 // names back to UCB properties.
100 static void UCBNamesToHTTPNames( const css::uno::Sequence
< css::beans::Property
> & rProps
,
101 std::vector
< OUString
> & resources
);
103 // return true, if all properties contained in rProps are contained in
104 // this ContentProperties instance. Otherwise, false will be returned.
105 // rNamesNotContained contain the missing names.
106 bool containsAllNames(
107 const css::uno::Sequence
< css::beans::Property
>& rProps
,
108 std::vector
< OUString
> & rNamesNotContained
) const;
110 // adds all properties described by rProps that are actually contained in
111 // rContentProps to this instance. In case of duplicates the value
112 // already contained in this will left unchanged.
113 void addProperties( const std::vector
< OUString
> & rProps
,
114 const ContentProperties
& rContentProps
);
116 // overwrites probably existing entry.
117 void addProperty( const OUString
& rName
,
118 const css::uno::Any
& rValue
,
119 bool bIsCaseSensitive
);
121 // overwrites probably existing entry.
122 void addProperty( const DAVPropertyValue
& rProp
);
124 bool isTrailingSlash() const { return m_bTrailingSlash
; }
126 const OUString
& getEscapedTitle() const { return m_aEscapedTitle
; }
128 // Not good to expose implementation details, but this is actually an
130 const std::unique_ptr
< PropertyValueMap
> & getProperties() const
134 OUString m_aEscapedTitle
;
135 std::unique_ptr
< PropertyValueMap
> m_xProps
;
136 bool m_bTrailingSlash
;
138 static css::uno::Any m_aEmptyAny
;
140 ContentProperties
& operator=( const ContentProperties
& ); // n.i.
142 const PropertyValue
* get( const OUString
& rName
) const;
145 class CachableContentProperties
148 ContentProperties m_aProps
;
150 CachableContentProperties
& operator=( const CachableContentProperties
& ); // n.i.
151 CachableContentProperties( const CachableContentProperties
& ); // n.i.
154 explicit CachableContentProperties( const ContentProperties
& rProps
);
156 void addProperties( const ContentProperties
& rProps
);
158 void addProperties( const std::vector
< DAVPropertyValue
> & rProps
);
160 bool containsAllNames(
161 const css::uno::Sequence
< css::beans::Property
>& rProps
,
162 std::vector
< OUString
> & rNamesNotContained
) const
163 { return m_aProps
.containsAllNames( rProps
, rNamesNotContained
); }
165 const css::uno::Any
&
166 getValue( const OUString
& rName
) const
167 { return m_aProps
.getValue( rName
); }
169 operator const ContentProperties
& () const { return m_aProps
; }
172 } // namespace http_dav_ucp
174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */