LibreOffice Module ucb (master) 1
ContentProperties.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20
21#pragma once
22
23#include <memory>
24#include <unordered_map>
25#include <utility>
26#include <vector>
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"
31
32namespace com::sun::star::beans {
33 struct Property;
34}
35
36namespace http_dav_ucp
37{
38
39struct DAVResource;
40
41// PropertyValueMap.
43{
44private:
45 css::uno::Any m_aValue;
47
48public:
50 : m_bIsCaseSensitive( true ) {}
51
52 explicit PropertyValue( css::uno::Any aValue,
53 bool bIsCaseSensitive )
54 : m_aValue(std::move( aValue)),
55 m_bIsCaseSensitive( bIsCaseSensitive ) {}
56
57 bool isCaseSensitive() const { return m_bIsCaseSensitive; }
58 const css::uno::Any & value() const { return m_aValue; }
59
60};
61
62typedef std::unordered_map< OUString, PropertyValue > PropertyValueMap;
63
65{
66public:
68
69 explicit ContentProperties( const DAVResource& rResource );
70
71 // Mini props for transient contents.
72 ContentProperties( const OUString & rTitle, bool bFolder );
73
74 // Micro props for non-existing contents.
75 explicit ContentProperties( const OUString & rTitle );
76
77 ContentProperties( const ContentProperties & rOther );
78
79 bool contains( const OUString & rName ) const;
80
81 const css::uno::Any& getValue( const OUString & rName ) const;
82
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 );
92
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 );
102
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;
109
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 );
115
116 // overwrites probably existing entry.
117 void addProperty( const OUString & rName,
118 const css::uno::Any & rValue,
119 bool bIsCaseSensitive );
120
121 // overwrites probably existing entry.
122 void addProperty( const DAVPropertyValue & rProp );
123
124 bool isTrailingSlash() const { return m_bTrailingSlash; }
125
126 const OUString & getEscapedTitle() const { return m_aEscapedTitle; }
127
128 // Not good to expose implementation details, but this is actually an
129 // internal class.
130 const std::unique_ptr< PropertyValueMap > & getProperties() const
131 { return m_xProps; }
132
133private:
135 std::unique_ptr< PropertyValueMap > m_xProps;
137
138 static css::uno::Any m_aEmptyAny;
139
141
142 const PropertyValue * get( const OUString & rName ) const;
143};
144
146{
147private:
149
152
153public:
154 explicit CachableContentProperties( const ContentProperties & rProps );
155
156 void addProperties( const ContentProperties & rProps );
157
158 void addProperties( const std::vector< DAVPropertyValue > & rProps );
159
161 const css::uno::Sequence< css::beans::Property >& rProps,
162 std::vector< OUString > & rNamesNotContained ) const
163 { return m_aProps.containsAllNames( rProps, rNamesNotContained ); }
164
165 const css::uno::Any &
166 getValue( const OUString & rName ) const
167 { return m_aProps.getValue( rName ); }
168
169 operator const ContentProperties & () const { return m_aProps; }
170};
171
172} // namespace http_dav_ucp
173
174/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool containsAllNames(const css::uno::Sequence< css::beans::Property > &rProps, std::vector< OUString > &rNamesNotContained) const
CachableContentProperties & operator=(const CachableContentProperties &)
CachableContentProperties(const CachableContentProperties &)
void addProperties(const ContentProperties &rProps)
const css::uno::Any & getValue(const OUString &rName) const
void addProperty(const OUString &rName, const css::uno::Any &rValue, bool bIsCaseSensitive)
bool contains(const OUString &rName) const
const std::unique_ptr< PropertyValueMap > & getProperties() const
const PropertyValue * get(const OUString &rName) const
void addProperties(const std::vector< OUString > &rProps, const ContentProperties &rContentProps)
std::unique_ptr< PropertyValueMap > m_xProps
const OUString & getEscapedTitle() const
bool containsAllNames(const css::uno::Sequence< css::beans::Property > &rProps, std::vector< OUString > &rNamesNotContained) const
static void UCBNamesToDAVNames(const css::uno::Sequence< css::beans::Property > &rProps, std::vector< OUString > &resources)
ContentProperties & operator=(const ContentProperties &)
const css::uno::Any & getValue(const OUString &rName) const
static void UCBNamesToHTTPNames(const css::uno::Sequence< css::beans::Property > &rProps, std::vector< OUString > &resources)
PropertyValue(css::uno::Any aValue, bool bIsCaseSensitive)
const css::uno::Any & value() const
std::unordered_map< OUString, PropertyValue > PropertyValueMap