1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
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.
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).
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.
27 ************************************************************************/
29 #ifndef INCLUDED_UCB_SOURCE_UCP_WEBDAV_NEON_CONTENTPROPERTIES_HXX
30 #define INCLUDED_UCB_SOURCE_UCP_WEBDAV_NEON_CONTENTPROPERTIES_HXX
32 #include <config_lgpl.h>
34 #include <unordered_map>
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"
41 namespace com
{ namespace sun
{ namespace star
{ namespace beans
{
54 css::uno::Any m_aValue
;
55 bool m_bIsCaseSensitive
;
59 : m_bIsCaseSensitive( true ) {}
61 PropertyValue( const css::uno::Any
& rValue
,
62 bool bIsCaseSensitive
)
64 m_bIsCaseSensitive( bIsCaseSensitive
) {}
66 bool isCaseSensitive() const { return m_bIsCaseSensitive
; }
67 const css::uno::Any
& value() const { return m_aValue
; }
71 typedef std::unordered_map
< OUString
, PropertyValue
> PropertyValueMap
;
73 class ContentProperties
78 explicit ContentProperties( const DAVResource
& rResource
);
80 // Mini props for transient contents.
81 ContentProperties( const OUString
& rTitle
, bool bFolder
);
83 // Micro props for non-existing contents.
84 explicit ContentProperties( const OUString
& rTitle
);
86 ContentProperties( const ContentProperties
& rOther
);
88 bool contains( const OUString
& rName
) const;
91 getValue( const OUString
& rName
) const;
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
);
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
);
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;
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
);
126 // overwrites probably existing entry.
127 void addProperty( const OUString
& rName
,
128 const css::uno::Any
& rValue
,
129 bool bIsCaseSensitive
);
131 // overwrites probably existing entry.
132 void addProperty( const DAVPropertyValue
& rProp
);
134 bool isTrailingSlash() const { return m_bTrailingSlash
; }
136 const OUString
& getEscapedTitle() const { return m_aEscapedTitle
; }
138 // Not good to expose implementation details, but this is actually an
140 const std::unique_ptr
< PropertyValueMap
> & getProperties() const
144 OUString m_aEscapedTitle
;
145 std::unique_ptr
< PropertyValueMap
> m_xProps
;
146 bool m_bTrailingSlash
;
148 static css::uno::Any m_aEmptyAny
;
150 ContentProperties
& operator=( const ContentProperties
& ) = delete;
152 const PropertyValue
* get( const OUString
& rName
) const;
155 class CachableContentProperties
158 ContentProperties m_aProps
;
160 CachableContentProperties
& operator=( const CachableContentProperties
& ) = delete;
161 CachableContentProperties( const CachableContentProperties
& ) = delete;
164 explicit CachableContentProperties( const ContentProperties
& rProps
);
166 void addProperties( const ContentProperties
& rProps
);
168 void addProperties( const std::vector
< DAVPropertyValue
> & rProps
);
170 bool containsAllNames(
171 const css::uno::Sequence
< css::beans::Property
>& rProps
,
172 std::vector
< OUString
> & rNamesNotContained
) const
173 { return m_aProps
.containsAllNames( rProps
, rNamesNotContained
); }
175 const css::uno::Any
&
176 getValue( const OUString
& rName
) const
177 { return m_aProps
.getValue( rName
); }
179 operator const ContentProperties
& () const { return m_aProps
; }
182 } // namespace webdav_ucp
184 #endif // INCLUDED_UCB_SOURCE_UCP_WEBDAV_NEON_CONTENTPROPERTIES_HXX
186 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */