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 #include "DAVResource.hxx"
31 
32 namespace com { namespace sun { namespace star { namespace beans {
33  struct Property;
34 } } } }
35 
36 namespace http_dav_ucp
37 {
38 
39 struct DAVResource;
40 
41 // PropertyValueMap.
43 {
44 private:
45  css::uno::Any m_aValue;
47 
48 public:
50  : m_bIsCaseSensitive( true ) {}
51 
52  explicit PropertyValue( const css::uno::Any & rValue,
53  bool bIsCaseSensitive )
54  : m_aValue( rValue),
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 
62 typedef std::unordered_map< OUString, PropertyValue > PropertyValueMap;
63 
65 {
66 public:
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 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 );
93 
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 );
104 
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;
111 
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 );
117 
118  // overwrites probably existing entries.
119  void addProperties( const ContentProperties & rProps );
120 
121  // overwrites probably existing entries.
122  void addProperties( const std::vector< DAVPropertyValue > & rProps );
123 
124  // overwrites probably existing entry.
125  void addProperty( const OUString & rName,
126  const css::uno::Any & rValue,
127  bool bIsCaseSensitive );
128 
129  // overwrites probably existing entry.
130  void addProperty( const DAVPropertyValue & rProp );
131 
132  bool isTrailingSlash() const { return m_bTrailingSlash; }
133 
134  const OUString & getEscapedTitle() const { return m_aEscapedTitle; }
135 
136  // Not good to expose implementation details, but this is actually an
137  // internal class.
138  const std::unique_ptr< PropertyValueMap > & getProperties() const
139  { return m_xProps; }
140 
141 private:
142  OUString m_aEscapedTitle;
143  std::unique_ptr< PropertyValueMap > m_xProps;
145 
146  static css::uno::Any m_aEmptyAny;
147 
148  ContentProperties & operator=( const ContentProperties & ); // n.i.
149 
150  const PropertyValue * get( const OUString & rName ) const;
151 };
152 
154 {
155 private:
157 
160 
161 public:
162  explicit CachableContentProperties( const ContentProperties & rProps );
163 
164  void addProperties( const ContentProperties & rProps );
165 
166  void addProperties( const std::vector< DAVPropertyValue > & rProps );
167 
169  const css::uno::Sequence< css::beans::Property >& rProps,
170  std::vector< OUString > & rNamesNotContained ) const
171  { return m_aProps.containsAllNames( rProps, rNamesNotContained ); }
172 
173  const css::uno::Any &
174  getValue( const OUString & rName ) const
175  { return m_aProps.getValue( rName ); }
176 
177  operator const ContentProperties & () const { return m_aProps; }
178 };
179 
180 } // namespace http_dav_ucp
181 
182 #endif // INCLUDED_UCB_SOURCE_UCP_WEBDAV_CONTENTPROPERTIES_HXX
183 
184 /* 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