LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/ucb/source/ucp/webdav-neon - DAVProperties.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 13 72 18.1 %
Date: 2013-07-09 Functions: 2 5 40.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10