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 <vector>
26 #include <rtl/ustring.hxx>
27 #include <com/sun/star/uno/Any.hxx>
28 #include <com/sun/star/uno/Sequence.hxx>
29 #include "DAVResource.hxx"
30 
31 namespace com::sun::star::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.
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 
92  // Maps the UCB property names contained in rProps with their HTTP header
93  // counterparts, if possible. All unmappable properties will be included
94  // unchanged in resulting vector.
95  // The vector filled by this method can directly be handed over to
96  // DAVResourceAccess::HEAD. The result from HEAD (vector< DAVResource >)
97  // can be used to create a ContentProperties instance which can map header
98  // names back to UCB properties.
99  static void UCBNamesToHTTPNames( const css::uno::Sequence< css::beans::Property > & rProps,
100  std::vector< OUString > & resources );
101 
102  // return true, if all properties contained in rProps are contained in
103  // this ContentProperties instance. Otherwise, false will be returned.
104  // rNamesNotContained contain the missing names.
105  bool containsAllNames(
106  const css::uno::Sequence< css::beans::Property >& rProps,
107  std::vector< OUString > & rNamesNotContained ) const;
108 
109  // adds all properties described by rProps that are actually contained in
110  // rContentProps to this instance. In case of duplicates the value
111  // already contained in this will left unchanged.
112  void addProperties( const std::vector< OUString > & rProps,
113  const ContentProperties & rContentProps );
114 
115  // overwrites probably existing entry.
116  void addProperty( const OUString & rName,
117  const css::uno::Any & rValue,
118  bool bIsCaseSensitive );
119 
120  // overwrites probably existing entry.
121  void addProperty( const DAVPropertyValue & rProp );
122 
123  bool isTrailingSlash() const { return m_bTrailingSlash; }
124 
125  const OUString & getEscapedTitle() const { return m_aEscapedTitle; }
126 
127  // Not good to expose implementation details, but this is actually an
128  // internal class.
129  const std::unique_ptr< PropertyValueMap > & getProperties() const
130  { return m_xProps; }
131 
132 private:
133  OUString m_aEscapedTitle;
134  std::unique_ptr< PropertyValueMap > m_xProps;
136 
137  static css::uno::Any m_aEmptyAny;
138 
139  ContentProperties & operator=( const ContentProperties & ); // n.i.
140 
141  const PropertyValue * get( const OUString & rName ) const;
142 };
143 
145 {
146 private:
148 
151 
152 public:
153  explicit CachableContentProperties( const ContentProperties & rProps );
154 
155  void addProperties( const ContentProperties & rProps );
156 
157  void addProperties( const std::vector< DAVPropertyValue > & rProps );
158 
160  const css::uno::Sequence< css::beans::Property >& rProps,
161  std::vector< OUString > & rNamesNotContained ) const
162  { return m_aProps.containsAllNames( rProps, rNamesNotContained ); }
163 
164  const css::uno::Any &
165  getValue( const OUString & rName ) const
166  { return m_aProps.getValue( rName ); }
167 
168  operator const ContentProperties & () const { return m_aProps; }
169 };
170 
171 } // namespace http_dav_ucp
172 
173 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
CachableContentProperties(const CachableContentProperties &)
void addProperties(const ContentProperties &rProps)
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
void addProperties(const std::vector< OUString > &rProps, const ContentProperties &rContentProps)
static void UCBNamesToDAVNames(const css::uno::Sequence< css::beans::Property > &rProps, std::vector< OUString > &resources)
std::unique_ptr< PropertyValueMap > m_xProps
const css::uno::Any & getValue(const OUString &rName) const
static void UCBNamesToHTTPNames(const css::uno::Sequence< css::beans::Property > &rProps, std::vector< OUString > &resources)
const OUString & getEscapedTitle() const
ContentProperties & operator=(const ContentProperties &)
bool containsAllNames(const css::uno::Sequence< css::beans::Property > &rProps, std::vector< OUString > &rNamesNotContained) const
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