bump product version to 5.0.4.1
[LibreOffice.git] / ucb / source / ucp / webdav-neon / DAVProperties.cxx
blob5d5634936dca07930a1e1628edb900171f43452f
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 ************************************************************************/
30 #include <string.h>
31 #include "DAVProperties.hxx"
33 using namespace webdav_ucp;
35 const OUString DAVProperties::CREATIONDATE("DAV:creationdate");
36 const OUString DAVProperties::DISPLAYNAME("DAV:displayname");
37 const OUString DAVProperties::GETCONTENTLANGUAGE("DAV:getcontentlanguage");
38 const OUString DAVProperties::GETCONTENTLENGTH("DAV:getcontentlength");
39 const OUString DAVProperties::GETCONTENTTYPE("DAV:getcontenttype");
40 const OUString DAVProperties::GETETAG("DAV:getetag");
41 const OUString DAVProperties::GETLASTMODIFIED("DAV:getlastmodified");
42 const OUString DAVProperties::LOCKDISCOVERY("DAV:lockdiscovery");
43 const OUString DAVProperties::RESOURCETYPE("DAV:resourcetype");
44 const OUString DAVProperties::SOURCE("DAV:source");
45 const OUString DAVProperties::SUPPORTEDLOCK("DAV:supportedlock");
47 const OUString DAVProperties::EXECUTABLE("http://apache.org/dav/props/executable");
49 void DAVProperties::createNeonPropName( const OUString & rFullName,
50 NeonPropName & rName )
52 if ( rFullName.startsWith( "DAV:" ) )
54 rName.nspace = "DAV:";
55 rName.name
56 = strdup( OUStringToOString(
57 rFullName.copy( RTL_CONSTASCII_LENGTH( "DAV:" ) ),
58 RTL_TEXTENCODING_UTF8 ).getStr() );
60 else if ( rFullName.startsWith( "http://apache.org/dav/props/" ) )
62 rName.nspace = "http://apache.org/dav/props/";
63 rName.name
64 = strdup( OUStringToOString(
65 rFullName.copy(
66 RTL_CONSTASCII_LENGTH(
67 "http://apache.org/dav/props/" ) ),
68 RTL_TEXTENCODING_UTF8 ).getStr() );
70 else if ( rFullName.startsWith( "http://ucb.openoffice.org/dav/props/" ) )
72 rName.nspace = "http://ucb.openoffice.org/dav/props/";
73 rName.name
74 = strdup( OUStringToOString(
75 rFullName.copy(
76 RTL_CONSTASCII_LENGTH(
77 "http://ucb.openoffice.org/dav/props/" ) ),
78 RTL_TEXTENCODING_UTF8 ).getStr() );
80 else if ( rFullName.startsWith( "<prop:" ) )
82 // Support for 3rd party namespaces/props
84 OString aFullName
85 = OUStringToOString( rFullName, RTL_TEXTENCODING_UTF8 );
87 // Format: <prop:the_propname xmlns:prop="the_namespace">
89 sal_Int32 nStart = RTL_CONSTASCII_LENGTH( "<prop:" );
90 sal_Int32 nLen = aFullName.indexOf( ' ' ) - nStart;
91 rName.name = strdup( aFullName.copy( nStart, nLen ).getStr() );
93 nStart = aFullName.indexOf( '=', nStart + nLen ) + 2; // after ="
94 nLen = aFullName.getLength() - RTL_CONSTASCII_LENGTH( "\">" ) - nStart;
95 rName.nspace = strdup( aFullName.copy( nStart, nLen ).getStr() );
97 else
99 // Add our namespace to our own properties.
100 rName.nspace = "http://ucb.openoffice.org/dav/props/";
101 rName.name
102 = strdup( OUStringToOString( rFullName,
103 RTL_TEXTENCODING_UTF8 ).getStr() );
107 void DAVProperties::createUCBPropName( const char * nspace,
108 const char * name,
109 OUString & rFullName )
111 OUString aNameSpace
112 = OStringToOUString( nspace, RTL_TEXTENCODING_UTF8 );
113 OUString aName
114 = OStringToOUString( name, RTL_TEXTENCODING_UTF8 );
116 if ( aNameSpace.isEmpty() )
118 // Some servers send XML without proper namespaces. Assume "DAV:"
119 // in this case, if name is a well-known dav property name.
120 // Although this is not 100% correct, it solves many problems.
122 if ( DAVProperties::RESOURCETYPE.matchIgnoreAsciiCase( aName, 4 ) ||
123 DAVProperties::SUPPORTEDLOCK.matchIgnoreAsciiCase( aName, 4 ) ||
124 DAVProperties::LOCKDISCOVERY.matchIgnoreAsciiCase( aName, 4 ) ||
125 DAVProperties::CREATIONDATE.matchIgnoreAsciiCase( aName, 4 ) ||
126 DAVProperties::DISPLAYNAME.matchIgnoreAsciiCase( aName, 4 ) ||
127 DAVProperties::GETCONTENTLANGUAGE.matchIgnoreAsciiCase( aName, 4 ) ||
128 DAVProperties::GETCONTENTLENGTH.matchIgnoreAsciiCase( aName, 4 ) ||
129 DAVProperties::GETCONTENTTYPE.matchIgnoreAsciiCase( aName, 4 ) ||
130 DAVProperties::GETETAG.matchIgnoreAsciiCase( aName, 4 ) ||
131 DAVProperties::GETLASTMODIFIED.matchIgnoreAsciiCase( aName, 4 ) ||
132 DAVProperties::SOURCE.matchIgnoreAsciiCase( aName, 4 ) )
133 aNameSpace = "DAV:";
136 // Note: Concatenating strings BEFORE comparing against known namespaces
137 // is important. See RFC 2815 ( 23.4.2 Meaning of Qualified Names ).
138 rFullName = aNameSpace;
139 rFullName += aName;
141 if ( rFullName.startsWith( "DAV:" ) )
143 // Okay, Just concat strings.
145 else if ( rFullName.startsWith( "http://apache.org/dav/props/" ) )
147 // Okay, Just concat strings.
149 else if ( rFullName.startsWith( "http://ucb.openoffice.org/dav/props/" ) )
151 // Remove namespace from our own properties.
152 rFullName = rFullName.copy(
153 RTL_CONSTASCII_LENGTH(
154 "http://ucb.openoffice.org/dav/props/" ) );
156 else
158 // Create property name that encodes, namespace and name ( XML ).
159 rFullName = "<prop:" + aName + " xmlns:prop=\"" + aNameSpace + "\">";
163 bool DAVProperties::isUCBDeadProperty( const NeonPropName & rName )
165 return ( rName.nspace &&
166 ( rtl_str_compareIgnoreAsciiCase(
167 rName.nspace, "http://ucb.openoffice.org/dav/props/" )
168 == 0 ) );
171 bool DAVProperties::isUCBSpecialProperty(
172 const OUString& rFullName, OUString& rParsedName)
174 if ( !rFullName.startsWith( "<prop:" ) || !rFullName.endsWith( "\">" ) )
175 return false;
177 sal_Int32 nStart = strlen( "<prop:" );
178 sal_Int32 nEnd = rFullName.indexOf( ' ', nStart );
179 if ( nEnd <= nStart ) // incl. -1 for "not found"
180 return false;
182 OUString sPropName( rFullName.copy( nStart, nEnd - nStart ) );
184 // TODO skip whitespaces?
185 if ( !rFullName.match( "xmlns:prop=\"", ++nEnd ) )
186 return false;
188 nStart = nEnd + strlen( "xmlns:prop=\"" );
189 nEnd = rFullName.indexOf( '"', nStart );
190 if ( nEnd != rFullName.getLength() - sal_Int32( strlen( "\">" ) )
191 || nEnd == nStart )
193 return false;
196 rParsedName = rFullName.copy( nStart, nEnd - nStart );
197 if ( !rParsedName.endsWith( "/" ) )
198 rParsedName += "/";
199 rParsedName += sPropName;
201 return rParsedName.getLength();
204 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */