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 #ifndef INCLUDED_UCB_SOURCE_UCP_WEBDAV_CONTENTPROPERTIES_HXX
22 #define INCLUDED_UCB_SOURCE_UCP_WEBDAV_CONTENTPROPERTIES_HXX
23 
24 #include <memory>
25 #include <unordered_map>
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 
31 namespace com { namespace sun { namespace star { namespace beans {
32  struct Property;
33 } } } }
34 
35 namespace http_dav_ucp
36 {
37 
38 struct DAVResource;
39 
40 // PropertyValueMap.
42 {
43 private:
44  css::uno::Any m_aValue;
46 
47 public:
49  : m_bIsCaseSensitive( true ) {}
50 
51  explicit PropertyValue( const css::uno::Any & rValue,
52  bool bIsCaseSensitive )
53  : m_aValue( rValue),
54  m_bIsCaseSensitive( bIsCaseSensitive ) {}
55 
56  bool isCaseSensitive() const { return m_bIsCaseSensitive; }
57  const css::uno::Any & value() const { return m_aValue; }
58 
59 };
60 
61 typedef std::unordered_map< OUString, PropertyValue > PropertyValueMap;
62 
64 {
65 public:
67 
68  explicit ContentProperties( const DAVResource& rResource );
69 
70  // Mini props for transient contents.
71  ContentProperties( const OUString & rTitle, bool bFolder );
72 
73  // Micro props for non-existing contents.
74  explicit ContentProperties( const OUString & rTitle );
75 
76  ContentProperties( const ContentProperties & rOther );
77 
78  bool contains( const OUString & rName ) const;
79 
80  const css::uno::Any& getValue( const OUString & rName ) const;
81 
82  // Maps the UCB property names contained in rProps with their DAV property
83  // counterparts, if possible. All unmappable properties will be included
84  // unchanged in resulting vector unless bIncludeUnmatched is set to false.
85  // The vector filled by this method can directly be handed over to
86  // DAVResourceAccess::PROPFIND. The result from PROPFIND
87  // (vector< DAVResource >) can be used to create a ContentProperties
88  // instance which can map DAV properties back to UCB properties.
89  static void UCBNamesToDAVNames( const css::uno::Sequence< css::beans::Property > & rProps,
90  std::vector< OUString > & resources,
91  bool bIncludeUnmatched = true );
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 unless bIncludeUnmatched is set to false.
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  bool bIncludeUnmatched = true );
103 
104  // return true, if all properties contained in rProps are contained in
105  // this ContentProperties instance. Otherwise, false will be returned.
106  // rNamesNotContained contain the missing names.
107  bool containsAllNames(
108  const css::uno::Sequence< css::beans::Property >& rProps,
109  std::vector< OUString > & rNamesNotContained ) const;
110 
111  // adds all properties described by rProps that are actually contained in
112  // rContentProps to this instance. In case of duplicates the value
113  // already contained in this will left unchanged.
114  void addProperties( const std::vector< OUString > & rProps,
115  const ContentProperties & rContentProps );
116 
117  // overwrites probably existing entries.
118  void addProperties( const ContentProperties & rProps );
119 
120  // overwrites probably existing entries.
121  void addProperties( const std::vector< DAVPropertyValue > & rProps );
122 
123  // overwrites probably existing entry.
124  void addProperty( const OUString & rName,
125  const css::uno::Any & rValue,
126  bool bIsCaseSensitive );
127 
128  // overwrites probably existing entry.
129  void addProperty( const DAVPropertyValue & rProp );
130 
131  bool isTrailingSlash() const { return m_bTrailingSlash; }
132 
133  const OUString & getEscapedTitle() const { return m_aEscapedTitle; }
134 
135  // Not good to expose implementation details, but this is actually an
136  // internal class.
137  const std::unique_ptr< PropertyValueMap > & getProperties() const
138  { return m_xProps; }
139 
140 private:
141  OUString m_aEscapedTitle;
142  std::unique_ptr< PropertyValueMap > m_xProps;
144 
145  static css::uno::Any m_aEmptyAny;
146 
147  ContentProperties & operator=( const ContentProperties & ); // n.i.
148 
149  const PropertyValue * get( const OUString & rName ) const;
150 };
151 
153 {
154 private:
156 
159 
160 public:
161  explicit CachableContentProperties( const ContentProperties & rProps );
162 
163  void addProperties( const ContentProperties & rProps );
164 
165  void addProperties( const std::vector< DAVPropertyValue > & rProps );
166 
168  const css::uno::Sequence< css::beans::Property >& rProps,
169  std::vector< OUString > & rNamesNotContained ) const
170  { return m_aProps.containsAllNames( rProps, rNamesNotContained ); }
171 
172  const css::uno::Any &
173  getValue( const OUString & rName ) const
174  { return m_aProps.getValue( rName ); }
175 
176  operator const ContentProperties & () const { return m_aProps; }
177 };
178 
179 } // namespace http_dav_ucp
180 
181 #endif // INCLUDED_UCB_SOURCE_UCP_WEBDAV_CONTENTPROPERTIES_HXX
182 
183 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
CachableContentProperties(const CachableContentProperties &)
void addProperties(const ContentProperties &rProps)
static void UCBNamesToHTTPNames(const css::uno::Sequence< css::beans::Property > &rProps, std::vector< OUString > &resources, bool bIncludeUnmatched=true)
void addProperty(const OUString &rName, const css::uno::Any &rValue, bool bIsCaseSensitive)
bool containsAllNames(const css::uno::Sequence< css::beans::Property > &rProps, std::vector< OUString > &rNamesNotContained) const
std::unordered_map< OUString, PropertyValue > PropertyValueMap
static void UCBNamesToDAVNames(const css::uno::Sequence< css::beans::Property > &rProps, std::vector< OUString > &resources, bool bIncludeUnmatched=true)
void addProperties(const std::vector< OUString > &rProps, const ContentProperties &rContentProps)
std::unique_ptr< PropertyValueMap > m_xProps
const css::uno::Any & getValue(const OUString &rName) const
bool containsAllNames(const css::uno::Sequence< css::beans::Property > &rProps, std::vector< OUString > &rNamesNotContained) const
const OUString & getEscapedTitle() const
ContentProperties & operator=(const ContentProperties &)
const css::uno::Any & getValue(const OUString &rName) const
CachableContentProperties & operator=(const CachableContentProperties &)
const std::unique_ptr< PropertyValueMap > & getProperties() const
PropertyValue(const css::uno::Any &rValue, bool bIsCaseSensitive)
bool contains(const OUString &rName) const
const css::uno::Any & value() const