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 ************************************************************************/
31 #include "DAVProperties.hxx"
33 using namespace webdav_ucp
;
35 const ::rtl::OUString
DAVProperties::CREATIONDATE("DAV:creationdate");
36 const ::rtl::OUString
DAVProperties::DISPLAYNAME("DAV:displayname");
37 const ::rtl::OUString
DAVProperties::GETCONTENTLANGUAGE("DAV:getcontentlanguage");
38 const ::rtl::OUString
DAVProperties::GETCONTENTLENGTH("DAV:getcontentlength");
39 const ::rtl::OUString
DAVProperties::GETCONTENTTYPE("DAV:getcontenttype");
40 const ::rtl::OUString
DAVProperties::GETETAG("DAV:getetag");
41 const ::rtl::OUString
DAVProperties::GETLASTMODIFIED("DAV:getlastmodified");
42 const ::rtl::OUString
DAVProperties::LOCKDISCOVERY("DAV:lockdiscovery");
43 const ::rtl::OUString
DAVProperties::RESOURCETYPE("DAV:resourcetype");
44 const ::rtl::OUString
DAVProperties::SOURCE("DAV:source");
45 const ::rtl::OUString
DAVProperties::SUPPORTEDLOCK("DAV:supportedlock");
47 const ::rtl::OUString
DAVProperties::EXECUTABLE("http://apache.org/dav/props/executable");
49 // -------------------------------------------------------------------
51 void DAVProperties::createNeonPropName( const rtl::OUString
& rFullName
,
52 NeonPropName
& rName
)
54 if ( rFullName
.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "DAV:" ) ) == 0 )
56 rName
.nspace
= "DAV:";
58 = strdup( rtl::OUStringToOString(
59 rFullName
.copy( RTL_CONSTASCII_LENGTH( "DAV:" ) ),
60 RTL_TEXTENCODING_UTF8
).getStr() );
62 else if ( rFullName
.compareToAscii( RTL_CONSTASCII_STRINGPARAM(
63 "http://apache.org/dav/props/" ) ) == 0 )
65 rName
.nspace
= "http://apache.org/dav/props/";
67 = strdup( rtl::OUStringToOString(
69 RTL_CONSTASCII_LENGTH(
70 "http://apache.org/dav/props/" ) ),
71 RTL_TEXTENCODING_UTF8
).getStr() );
73 else if ( rFullName
.compareToAscii( RTL_CONSTASCII_STRINGPARAM(
74 "http://ucb.openoffice.org/dav/props/" ) ) == 0 )
76 rName
.nspace
= "http://ucb.openoffice.org/dav/props/";
78 = strdup( rtl::OUStringToOString(
80 RTL_CONSTASCII_LENGTH(
81 "http://ucb.openoffice.org/dav/props/" ) ),
82 RTL_TEXTENCODING_UTF8
).getStr() );
84 else if ( rFullName
.compareToAscii( RTL_CONSTASCII_STRINGPARAM(
87 // Support for 3rd party namespaces/props
89 rtl::OString aFullName
90 = rtl::OUStringToOString( rFullName
, RTL_TEXTENCODING_UTF8
);
92 // Format: <prop:the_propname xmlns:prop="the_namespace">
94 sal_Int32 nStart
= RTL_CONSTASCII_LENGTH( "<prop:" );
95 sal_Int32 nLen
= aFullName
.indexOf( ' ' ) - nStart
;
96 rName
.name
= strdup( aFullName
.copy( nStart
, nLen
).getStr() );
98 nStart
= aFullName
.indexOf( '=', nStart
+ nLen
) + 2; // after ="
99 nLen
= aFullName
.getLength() - RTL_CONSTASCII_LENGTH( "\">" ) - nStart
;
100 rName
.nspace
= strdup( aFullName
.copy( nStart
, nLen
).getStr() );
104 // Add our namespace to our own properties.
105 rName
.nspace
= "http://ucb.openoffice.org/dav/props/";
107 = strdup( rtl::OUStringToOString( rFullName
,
108 RTL_TEXTENCODING_UTF8
).getStr() );
112 // -------------------------------------------------------------------
114 void DAVProperties::createUCBPropName( const char * nspace
,
116 rtl::OUString
& rFullName
)
118 rtl::OUString aNameSpace
119 = rtl::OStringToOUString( nspace
, RTL_TEXTENCODING_UTF8
);
121 = rtl::OStringToOUString( name
, RTL_TEXTENCODING_UTF8
);
123 if ( aNameSpace
.isEmpty() )
125 // Some servers send XML without proper namespaces. Assume "DAV:"
126 // in this case, if name is a well-known dav property name.
127 // Although this is not 100% correct, it solves many problems.
129 if ( DAVProperties::RESOURCETYPE
.matchIgnoreAsciiCase( aName
, 4 ) ||
130 DAVProperties::SUPPORTEDLOCK
.matchIgnoreAsciiCase( aName
, 4 ) ||
131 DAVProperties::LOCKDISCOVERY
.matchIgnoreAsciiCase( aName
, 4 ) ||
132 DAVProperties::CREATIONDATE
.matchIgnoreAsciiCase( aName
, 4 ) ||
133 DAVProperties::DISPLAYNAME
.matchIgnoreAsciiCase( aName
, 4 ) ||
134 DAVProperties::GETCONTENTLANGUAGE
.matchIgnoreAsciiCase( aName
, 4 ) ||
135 DAVProperties::GETCONTENTLENGTH
.matchIgnoreAsciiCase( aName
, 4 ) ||
136 DAVProperties::GETCONTENTTYPE
.matchIgnoreAsciiCase( aName
, 4 ) ||
137 DAVProperties::GETETAG
.matchIgnoreAsciiCase( aName
, 4 ) ||
138 DAVProperties::GETLASTMODIFIED
.matchIgnoreAsciiCase( aName
, 4 ) ||
139 DAVProperties::SOURCE
.matchIgnoreAsciiCase( aName
, 4 ) )
140 aNameSpace
= rtl::OUString( "DAV:" );
143 // Note: Concatenating strings BEFORE comparing against known namespaces
144 // is important. See RFC 2815 ( 23.4.2 Meaning of Qualified Names ).
145 rFullName
= aNameSpace
;
148 if ( rFullName
.compareToAscii( RTL_CONSTASCII_STRINGPARAM(
151 // Okay, Just concat strings.
153 else if ( rFullName
.compareToAscii( RTL_CONSTASCII_STRINGPARAM(
154 "http://apache.org/dav/props/" ) ) == 0 )
156 // Okay, Just concat strings.
158 else if ( rFullName
.compareToAscii( RTL_CONSTASCII_STRINGPARAM(
159 "http://ucb.openoffice.org/dav/props/" ) ) == 0 )
161 // Remove namespace from our own properties.
162 rFullName
= rFullName
.copy(
163 RTL_CONSTASCII_LENGTH(
164 "http://ucb.openoffice.org/dav/props/" ) );
168 // Create property name that encodes, namespace and name ( XML ).
169 rFullName
= rtl::OUString("<prop:");
171 rFullName
+= rtl::OUString( " xmlns:prop=\"" );
172 rFullName
+= aNameSpace
;
173 rFullName
+= rtl::OUString( "\">" );
177 // -------------------------------------------------------------------
179 bool DAVProperties::isUCBDeadProperty( const NeonPropName
& rName
)
181 return ( rName
.nspace
&&
182 ( rtl_str_compareIgnoreAsciiCase(
183 rName
.nspace
, "http://ucb.openoffice.org/dav/props/" )
187 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */