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