LibreOffice Module ucb (master)  1
neon/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  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * Copyright 2000, 2010 Oracle and/or its affiliates.
7  *
8  * OpenOffice.org - a multi-platform office productivity suite
9  *
10  * This file is part of OpenOffice.org.
11  *
12  * OpenOffice.org is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU Lesser General Public License version 3
14  * only, as published by the Free Software Foundation.
15  *
16  * OpenOffice.org is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Lesser General Public License version 3 for more details
20  * (a copy is included in the LICENSE file that accompanied this code).
21  *
22  * You should have received a copy of the GNU Lesser General Public License
23  * version 3 along with OpenOffice.org. If not, see
24  * <http://www.openoffice.org/license.html>
25  * for a copy of the LGPLv3 License.
26  *
27  ************************************************************************/
28 
29 #pragma once
30 
31 #include <config_lgpl.h>
32 #include <memory>
33 #include <unordered_map>
34 #include <vector>
35 #include <rtl/ustring.hxx>
36 #include <com/sun/star/uno/Any.hxx>
37 #include <com/sun/star/uno/Sequence.hxx>
38 #include "DAVResource.hxx"
39 
40 namespace com::sun::star::beans {
41  struct Property;
42 }
43 
44 namespace webdav_ucp
45 {
46 
47 struct DAVResource;
48 
49 // PropertyValueMap.
51 {
52 private:
53  css::uno::Any m_aValue;
55 
56 public:
58  : m_bIsCaseSensitive( true ) {}
59 
60  PropertyValue( const css::uno::Any & rValue,
61  bool bIsCaseSensitive )
62  : m_aValue( rValue),
63  m_bIsCaseSensitive( bIsCaseSensitive ) {}
64 
65  bool isCaseSensitive() const { return m_bIsCaseSensitive; }
66  const css::uno::Any & value() const { return m_aValue; }
67 
68 };
69 
70 typedef std::unordered_map< OUString, PropertyValue> PropertyValueMap;
71 
73 {
74 public:
76 
77  explicit ContentProperties( const DAVResource& rResource );
78 
79  // Mini props for transient contents.
80  ContentProperties( const OUString & rTitle, bool bFolder );
81 
82  // Micro props for non-existing contents.
83  explicit ContentProperties( const OUString & rTitle );
84 
85  ContentProperties( const ContentProperties & rOther );
86 
87  bool contains( const OUString & rName ) const;
88 
89  const css::uno::Any &
90  getValue( const OUString & rName ) const;
91 
92  // Maps the UCB property names contained in rProps with their DAV property
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::PROPFIND. The result from PROPFIND
97  // (vector< DAVResource >) can be used to create a ContentProperties
98  // instance which can map DAV properties back to UCB properties.
99  static void UCBNamesToDAVNames( const css::uno::Sequence< css::beans::Property > & rProps,
100  std::vector< OUString > & resources );
101 
102  // Maps the UCB property names contained in rProps with their HTTP header
103  // counterparts, if possible. All unmappable properties will be included
104  // unchanged in resulting vector.
105  // The vector filled by this method can directly be handed over to
106  // DAVResourceAccess::HEAD. The result from HEAD (vector< DAVResource >)
107  // can be used to create a ContentProperties instance which can map header
108  // names back to UCB properties.
109  static void UCBNamesToHTTPNames( const css::uno::Sequence< css::beans::Property > & rProps,
110  std::vector< OUString > & resources );
111 
112  // return true, if all properties contained in rProps are contained in
113  // this ContentProperties instance. Otherwise, false will be returned.
114  // rNamesNotContained contain the missing names.
115  bool containsAllNames(
116  const css::uno::Sequence< css::beans::Property >& rProps,
117  std::vector< OUString > & rNamesNotContained ) const;
118 
119  // adds all properties described by rProps that are actually contained in
120  // rContentProps to this instance. In case of duplicates the value
121  // already contained in this will left unchanged.
122  void addProperties( const std::vector< OUString > & rProps,
123  const ContentProperties & rContentProps );
124 
125  // overwrites probably existing entry.
126  void addProperty( const OUString & rName,
127  const css::uno::Any & rValue,
128  bool bIsCaseSensitive );
129 
130  // overwrites probably existing entry.
131  void addProperty( const DAVPropertyValue & rProp );
132 
133  bool isTrailingSlash() const { return m_bTrailingSlash; }
134 
135  const OUString & getEscapedTitle() const { return m_aEscapedTitle; }
136 
137  // Not good to expose implementation details, but this is actually an
138  // internal class.
139  const std::unique_ptr< PropertyValueMap > & getProperties() const
140  { return m_xProps; }
141 
142 private:
143  OUString m_aEscapedTitle;
144  std::unique_ptr< PropertyValueMap > m_xProps;
146 
147  static css::uno::Any m_aEmptyAny;
148 
149  ContentProperties & operator=( const ContentProperties & ) = delete;
150 
151  const PropertyValue * get( const OUString & rName ) const;
152 };
153 
155 {
156 private:
158 
161 
162 public:
163  explicit CachableContentProperties( const ContentProperties & rProps );
164 
165  void addProperties( const ContentProperties & rProps );
166 
167  void addProperties( const std::vector< DAVPropertyValue > & rProps );
168 
170  const css::uno::Sequence< css::beans::Property >& rProps,
171  std::vector< OUString > & rNamesNotContained ) const
172  { return m_aProps.containsAllNames( rProps, rNamesNotContained ); }
173 
174  const css::uno::Any &
175  getValue( const OUString & rName ) const
176  { return m_aProps.getValue( rName ); }
177 
178  operator const ContentProperties & () const { return m_aProps; }
179 };
180 
181 } // namespace webdav_ucp
182 
183 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool containsAllNames(const css::uno::Sequence< css::beans::Property > &rProps, std::vector< OUString > &rNamesNotContained) const
CachableContentProperties(const CachableContentProperties &)=delete
bool contains(const OUString &rName) const
const css::uno::Any & value() const
PropertyValue(const css::uno::Any &rValue, bool bIsCaseSensitive)
static void UCBNamesToHTTPNames(const css::uno::Sequence< css::beans::Property > &rProps, std::vector< OUString > &resources)
css::uno::Any const & rValue
const OUString & getEscapedTitle() const
bool containsAllNames(const css::uno::Sequence< css::beans::Property > &rProps, std::vector< OUString > &rNamesNotContained) const
const std::unique_ptr< PropertyValueMap > & getProperties() const
CachableContentProperties & operator=(const CachableContentProperties &)=delete
ContentProperties & operator=(const ContentProperties &)=delete
std::unordered_map< OUString, PropertyValue > PropertyValueMap
void addProperties(const ContentProperties &rProps)
void addProperty(const OUString &rName, const css::uno::Any &rValue, bool bIsCaseSensitive)
const css::uno::Any & getValue(const OUString &rName) const
const css::uno::Any & getValue(const OUString &rName) const
std::unique_ptr< PropertyValueMap > m_xProps
static void UCBNamesToDAVNames(const css::uno::Sequence< css::beans::Property > &rProps, std::vector< OUString > &resources)
void addProperties(const std::vector< OUString > &rProps, const ContentProperties &rContentProps)