Line data Source code
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 :
30 : #include <string.h>
31 : #include "DAVProperties.hxx"
32 :
33 : using namespace webdav_ucp;
34 :
35 0 : const ::rtl::OUString DAVProperties::CREATIONDATE("DAV:creationdate");
36 0 : const ::rtl::OUString DAVProperties::DISPLAYNAME("DAV:displayname");
37 0 : const ::rtl::OUString DAVProperties::GETCONTENTLANGUAGE("DAV:getcontentlanguage");
38 0 : const ::rtl::OUString DAVProperties::GETCONTENTLENGTH("DAV:getcontentlength");
39 0 : const ::rtl::OUString DAVProperties::GETCONTENTTYPE("DAV:getcontenttype");
40 0 : const ::rtl::OUString DAVProperties::GETETAG("DAV:getetag");
41 0 : const ::rtl::OUString DAVProperties::GETLASTMODIFIED("DAV:getlastmodified");
42 0 : const ::rtl::OUString DAVProperties::LOCKDISCOVERY("DAV:lockdiscovery");
43 0 : const ::rtl::OUString DAVProperties::RESOURCETYPE("DAV:resourcetype");
44 0 : const ::rtl::OUString DAVProperties::SOURCE("DAV:source");
45 0 : const ::rtl::OUString DAVProperties::SUPPORTEDLOCK("DAV:supportedlock");
46 :
47 0 : const ::rtl::OUString DAVProperties::EXECUTABLE("http://apache.org/dav/props/executable");
48 :
49 : // -------------------------------------------------------------------
50 : // static
51 0 : void DAVProperties::createNeonPropName( const rtl::OUString & rFullName,
52 : NeonPropName & rName )
53 : {
54 0 : if ( rFullName.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "DAV:" ) ) == 0 )
55 : {
56 0 : rName.nspace = "DAV:";
57 : rName.name
58 : = strdup( rtl::OUStringToOString(
59 : rFullName.copy( RTL_CONSTASCII_LENGTH( "DAV:" ) ),
60 0 : RTL_TEXTENCODING_UTF8 ).getStr() );
61 : }
62 0 : else if ( rFullName.compareToAscii( RTL_CONSTASCII_STRINGPARAM(
63 0 : "http://apache.org/dav/props/" ) ) == 0 )
64 : {
65 0 : rName.nspace = "http://apache.org/dav/props/";
66 : rName.name
67 : = strdup( rtl::OUStringToOString(
68 : rFullName.copy(
69 : RTL_CONSTASCII_LENGTH(
70 : "http://apache.org/dav/props/" ) ),
71 0 : RTL_TEXTENCODING_UTF8 ).getStr() );
72 : }
73 0 : else if ( rFullName.compareToAscii( RTL_CONSTASCII_STRINGPARAM(
74 0 : "http://ucb.openoffice.org/dav/props/" ) ) == 0 )
75 : {
76 0 : rName.nspace = "http://ucb.openoffice.org/dav/props/";
77 : rName.name
78 : = strdup( rtl::OUStringToOString(
79 : rFullName.copy(
80 : RTL_CONSTASCII_LENGTH(
81 : "http://ucb.openoffice.org/dav/props/" ) ),
82 0 : RTL_TEXTENCODING_UTF8 ).getStr() );
83 : }
84 0 : else if ( rFullName.compareToAscii( RTL_CONSTASCII_STRINGPARAM(
85 0 : "<prop:" ) ) == 0 )
86 : {
87 : // Support for 3rd party namespaces/props
88 :
89 : rtl::OString aFullName
90 0 : = rtl::OUStringToOString( rFullName, RTL_TEXTENCODING_UTF8 );
91 :
92 : // Format: <prop:the_propname xmlns:prop="the_namespace">
93 :
94 0 : sal_Int32 nStart = RTL_CONSTASCII_LENGTH( "<prop:" );
95 0 : sal_Int32 nLen = aFullName.indexOf( ' ' ) - nStart;
96 0 : rName.name = strdup( aFullName.copy( nStart, nLen ).getStr() );
97 :
98 0 : nStart = aFullName.indexOf( '=', nStart + nLen ) + 2; // after ="
99 0 : nLen = aFullName.getLength() - RTL_CONSTASCII_LENGTH( "\">" ) - nStart;
100 0 : rName.nspace = strdup( aFullName.copy( nStart, nLen ).getStr() );
101 : }
102 : else
103 : {
104 : // Add our namespace to our own properties.
105 0 : rName.nspace = "http://ucb.openoffice.org/dav/props/";
106 : rName.name
107 : = strdup( rtl::OUStringToOString( rFullName,
108 0 : RTL_TEXTENCODING_UTF8 ).getStr() );
109 : }
110 0 : }
111 :
112 : // -------------------------------------------------------------------
113 : // static
114 0 : void DAVProperties::createUCBPropName( const char * nspace,
115 : const char * name,
116 : rtl::OUString & rFullName )
117 : {
118 : rtl::OUString aNameSpace
119 0 : = rtl::OStringToOUString( nspace, RTL_TEXTENCODING_UTF8 );
120 : rtl::OUString aName
121 0 : = rtl::OStringToOUString( name, RTL_TEXTENCODING_UTF8 );
122 :
123 0 : if ( aNameSpace.isEmpty() )
124 : {
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.
128 :
129 0 : if ( DAVProperties::RESOURCETYPE.matchIgnoreAsciiCase( aName, 4 ) ||
130 0 : DAVProperties::SUPPORTEDLOCK.matchIgnoreAsciiCase( aName, 4 ) ||
131 0 : DAVProperties::LOCKDISCOVERY.matchIgnoreAsciiCase( aName, 4 ) ||
132 0 : DAVProperties::CREATIONDATE.matchIgnoreAsciiCase( aName, 4 ) ||
133 0 : DAVProperties::DISPLAYNAME.matchIgnoreAsciiCase( aName, 4 ) ||
134 0 : DAVProperties::GETCONTENTLANGUAGE.matchIgnoreAsciiCase( aName, 4 ) ||
135 0 : DAVProperties::GETCONTENTLENGTH.matchIgnoreAsciiCase( aName, 4 ) ||
136 0 : DAVProperties::GETCONTENTTYPE.matchIgnoreAsciiCase( aName, 4 ) ||
137 0 : DAVProperties::GETETAG.matchIgnoreAsciiCase( aName, 4 ) ||
138 0 : DAVProperties::GETLASTMODIFIED.matchIgnoreAsciiCase( aName, 4 ) ||
139 0 : DAVProperties::SOURCE.matchIgnoreAsciiCase( aName, 4 ) )
140 0 : aNameSpace = rtl::OUString( "DAV:" );
141 : }
142 :
143 : // Note: Concatenating strings BEFORE comparing against known namespaces
144 : // is important. See RFC 2815 ( 23.4.2 Meaning of Qualified Names ).
145 0 : rFullName = aNameSpace;
146 0 : rFullName += aName;
147 :
148 0 : if ( rFullName.compareToAscii( RTL_CONSTASCII_STRINGPARAM(
149 0 : "DAV:" ) ) == 0 )
150 : {
151 : // Okay, Just concat strings.
152 : }
153 0 : else if ( rFullName.compareToAscii( RTL_CONSTASCII_STRINGPARAM(
154 0 : "http://apache.org/dav/props/" ) ) == 0 )
155 : {
156 : // Okay, Just concat strings.
157 : }
158 0 : else if ( rFullName.compareToAscii( RTL_CONSTASCII_STRINGPARAM(
159 0 : "http://ucb.openoffice.org/dav/props/" ) ) == 0 )
160 : {
161 : // Remove namespace from our own properties.
162 : rFullName = rFullName.copy(
163 : RTL_CONSTASCII_LENGTH(
164 0 : "http://ucb.openoffice.org/dav/props/" ) );
165 : }
166 : else
167 : {
168 : // Create property name that encodes, namespace and name ( XML ).
169 0 : rFullName = rtl::OUString("<prop:");
170 0 : rFullName += aName;
171 0 : rFullName += rtl::OUString( " xmlns:prop=\"" );
172 0 : rFullName += aNameSpace;
173 0 : rFullName += rtl::OUString( "\">" );
174 0 : }
175 0 : }
176 :
177 : // -------------------------------------------------------------------
178 : // static
179 0 : bool DAVProperties::isUCBDeadProperty( const NeonPropName & rName )
180 : {
181 : return ( rName.nspace &&
182 : ( rtl_str_compareIgnoreAsciiCase(
183 0 : rName.nspace, "http://ucb.openoffice.org/dav/props/" )
184 0 : == 0 ) );
185 0 : }
186 :
187 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|