1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "DAVProperties.hxx"
23 using namespace http_dav_ucp
;
25 const OUString
DAVProperties::CREATIONDATE
=
26 OUString::createFromAscii( "DAV:creationdate" );
27 const OUString
DAVProperties::DISPLAYNAME
=
28 OUString::createFromAscii( "DAV:displayname" );
29 const OUString
DAVProperties::GETCONTENTLANGUAGE
=
30 OUString::createFromAscii( "DAV:getcontentlanguage" );
31 const OUString
DAVProperties::GETCONTENTLENGTH
=
32 OUString::createFromAscii( "DAV:getcontentlength" );
33 const OUString
DAVProperties::GETCONTENTTYPE
=
34 OUString::createFromAscii( "DAV:getcontenttype" );
35 const OUString
DAVProperties::GETETAG
=
36 OUString::createFromAscii( "DAV:getetag" );
37 const OUString
DAVProperties::GETLASTMODIFIED
=
38 OUString::createFromAscii( "DAV:getlastmodified" );
39 const OUString
DAVProperties::LOCKDISCOVERY
=
40 OUString::createFromAscii( "DAV:lockdiscovery" );
41 const OUString
DAVProperties::RESOURCETYPE
=
42 OUString::createFromAscii( "DAV:resourcetype" );
43 const OUString
DAVProperties::SUPPORTEDLOCK
=
44 OUString::createFromAscii( "DAV:supportedlock" );
46 const OUString
DAVProperties::EXECUTABLE
=
47 OUString::createFromAscii(
48 "http://apache.org/dav/props/executable" );
50 // -------------------------------------------------------------------
52 void DAVProperties::createSerfPropName( const OUString
& rFullName
,
53 SerfPropName
& rName
)
55 if ( rFullName
.startsWith( "DAV:" ) )
57 rName
.nspace
= "DAV:";
59 = strdup( OUStringToOString(
60 rFullName
.copy( RTL_CONSTASCII_LENGTH( "DAV:" ) ),
61 RTL_TEXTENCODING_UTF8
) );
63 else if ( rFullName
.startsWith( "http://apache.org/dav/props/" ) )
65 rName
.nspace
= "http://apache.org/dav/props/";
67 = strdup( OUStringToOString(
69 RTL_CONSTASCII_LENGTH(
70 "http://apache.org/dav/props/" ) ),
71 RTL_TEXTENCODING_UTF8
) );
73 else if ( rFullName
.startsWith( "http://ucb.openoffice.org/dav/props/" ) )
75 rName
.nspace
= "http://ucb.openoffice.org/dav/props/";
77 = strdup( OUStringToOString(
79 RTL_CONSTASCII_LENGTH(
80 "http://ucb.openoffice.org/dav/props/" ) ),
81 RTL_TEXTENCODING_UTF8
) );
83 else if ( rFullName
.startsWith( "<prop:" ) )
85 // Support for 3rd party namespaces/props
88 = OUStringToOString( rFullName
, RTL_TEXTENCODING_UTF8
);
90 // Format: <prop:the_propname xmlns:prop="the_namespace">
92 sal_Int32 nStart
= RTL_CONSTASCII_LENGTH( "<prop:" );
93 sal_Int32 nLen
= aFullName
.indexOf( ' ' ) - nStart
;
94 rName
.name
= strdup( aFullName
.copy( nStart
, nLen
) );
96 nStart
= aFullName
.indexOf( '=', nStart
+ nLen
) + 2; // after ="
97 nLen
= aFullName
.getLength() - RTL_CONSTASCII_LENGTH( "\">" ) - nStart
;
98 rName
.nspace
= strdup( aFullName
.copy( nStart
, nLen
) );
102 // Add our namespace to our own properties.
103 rName
.nspace
= "http://ucb.openoffice.org/dav/props/";
105 = strdup( OUStringToOString( rFullName
,
106 RTL_TEXTENCODING_UTF8
) );
110 // -------------------------------------------------------------------
112 void DAVProperties::createUCBPropName( const char * nspace
,
114 OUString
& rFullName
)
117 = OStringToOUString( nspace
, RTL_TEXTENCODING_UTF8
);
119 = OStringToOUString( name
, RTL_TEXTENCODING_UTF8
);
121 if ( !aNameSpace
.getLength() )
123 // Some servers send XML without proper namespaces. Assume "DAV:"
124 // in this case, if name is a well-known dav property name.
125 // Although this is not 100% correct, it solves many problems.
127 if ( DAVProperties::RESOURCETYPE
.matchIgnoreAsciiCase( aName
, 4 ) ||
128 DAVProperties::SUPPORTEDLOCK
.matchIgnoreAsciiCase( aName
, 4 ) ||
129 DAVProperties::LOCKDISCOVERY
.matchIgnoreAsciiCase( aName
, 4 ) ||
130 DAVProperties::CREATIONDATE
.matchIgnoreAsciiCase( aName
, 4 ) ||
131 DAVProperties::DISPLAYNAME
.matchIgnoreAsciiCase( aName
, 4 ) ||
132 DAVProperties::GETCONTENTLANGUAGE
.matchIgnoreAsciiCase( aName
, 4 ) ||
133 DAVProperties::GETCONTENTLENGTH
.matchIgnoreAsciiCase( aName
, 4 ) ||
134 DAVProperties::GETCONTENTTYPE
.matchIgnoreAsciiCase( aName
, 4 ) ||
135 DAVProperties::GETETAG
.matchIgnoreAsciiCase( aName
, 4 ) ||
136 DAVProperties::GETLASTMODIFIED
.matchIgnoreAsciiCase( aName
, 4 ) )
138 aNameSpace
= OUString( "DAV:" );
142 // Note: Concatenating strings BEFORE comparing against known namespaces
143 // is important. See RFC 2815 ( 23.4.2 Meaning of Qualified Names ).
144 rFullName
= aNameSpace
;
147 if ( rFullName
.startsWith( "DAV:" ) )
149 // Okay, Just concat strings.
151 else if ( rFullName
.startsWith( "http://apache.org/dav/props/" ) )
153 // Okay, Just concat strings.
155 else if ( rFullName
.startsWith( "http://ucb.openoffice.org/dav/props/" ) )
157 // Remove namespace from our own properties.
158 rFullName
= rFullName
.copy(
159 RTL_CONSTASCII_LENGTH(
160 "http://ucb.openoffice.org/dav/props/" ) );
164 // Create property name that encodes, namespace and name ( XML ).
165 rFullName
= OUString::createFromAscii( "<prop:" );
167 rFullName
+= OUString::createFromAscii( " xmlns:prop=\"" );
168 rFullName
+= aNameSpace
;
169 rFullName
+= OUString::createFromAscii( "\">" );
173 // -------------------------------------------------------------------
175 bool DAVProperties::isUCBDeadProperty( const SerfPropName
& rName
)
177 return ( rName
.nspace
&&
178 ( rtl_str_compareIgnoreAsciiCase(
179 rName
.nspace
, "http://ucb.openoffice.org/dav/props/" )
183 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */