LCOV - code coverage report
Current view: top level - ucb/source/ucp/cmis - cmis_url.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 44 0.0 %
Date: 2014-11-03 Functions: 0 6 0.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             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  */
       9             : 
      10             : #include <libcmis/libcmis.hxx>
      11             : 
      12             : #include <config_oauth2.h>
      13             : #include <rtl/uri.hxx>
      14             : 
      15             : #include "cmis_url.hxx"
      16             : 
      17             : using namespace std;
      18             : 
      19             : namespace cmis
      20             : {
      21           0 :     URL::URL( OUString const & urlStr )
      22             :     {
      23           0 :         INetURLObject aUrl( urlStr );
      24             : 
      25             :         // Decode the authority to get the binding URL and repository id
      26           0 :         OUString sDecodedHost = aUrl.GetHost( INetURLObject::DECODE_WITH_CHARSET );
      27           0 :         INetURLObject aHostUrl( sDecodedHost );
      28           0 :         m_sBindingUrl = aHostUrl.GetURLNoMark( );
      29           0 :         m_sRepositoryId = aHostUrl.GetMark( );
      30             : 
      31           0 :         m_sUser = aUrl.GetUser( INetURLObject::DECODE_WITH_CHARSET );
      32           0 :         m_sPass = aUrl.GetPass( INetURLObject::DECODE_WITH_CHARSET );
      33             : 
      34             :         // Store the path to the object
      35           0 :         m_sPath = aUrl.GetURLPath( INetURLObject::DECODE_WITH_CHARSET );
      36           0 :         m_sId = aUrl.GetMark( INetURLObject::DECODE_WITH_CHARSET );
      37             : 
      38           0 :         if ( m_sPath == "/" && m_sBindingUrl.indexOf( "google" ) != -1 )
      39           0 :             m_sId = "root";
      40           0 :     }
      41             : 
      42             : 
      43             : 
      44             : 
      45             : 
      46           0 :     void URL::setObjectPath( const OUString& sPath )
      47             :     {
      48           0 :         m_sPath = sPath;
      49           0 :     }
      50             : 
      51           0 :     void URL::setObjectId( const OUString& sId )
      52             :     {
      53           0 :         m_sId = sId;
      54           0 :     }
      55             : 
      56           0 :     OUString URL::asString( )
      57             :     {
      58           0 :         OUString sUrl;
      59             :         OUString sEncodedBinding = rtl::Uri::encode(
      60           0 :                 m_sBindingUrl + "#" + m_sRepositoryId,
      61             :                 rtl_UriCharClassRelSegment,
      62             :                 rtl_UriEncodeKeepEscapes,
      63           0 :                 RTL_TEXTENCODING_UTF8 );
      64           0 :         sUrl = "vnd.libreoffice.cmis://" + sEncodedBinding;
      65             : 
      66           0 :         if ( !m_sPath.isEmpty( ) )
      67             :         {
      68           0 :             sal_Int32 nPos = -1;
      69           0 :             OUString sEncodedPath;
      70           0 :             do
      71             :             {
      72           0 :                 sal_Int32 nStartPos = nPos + 1;
      73           0 :                 nPos = m_sPath.indexOf( '/', nStartPos );
      74           0 :                 sal_Int32 nLen = nPos - nStartPos;
      75           0 :                 if ( nPos == -1 )
      76           0 :                     nLen = m_sPath.getLength( ) - nStartPos;
      77           0 :                 OUString sSegment = m_sPath.copy( nStartPos, nLen );
      78             : 
      79           0 :                 if ( !sSegment.isEmpty( ) )
      80             :                 {
      81           0 :                     sEncodedPath += "/" + rtl::Uri::encode( sSegment,
      82             :                             rtl_UriCharClassRelSegment,
      83             :                             rtl_UriEncodeKeepEscapes,
      84           0 :                             RTL_TEXTENCODING_UTF8 );
      85           0 :                 }
      86             :             }
      87             :             while ( nPos != -1 );
      88           0 :             sUrl += sEncodedPath;
      89           0 :         } else if ( !m_sId.isEmpty( ) )
      90             :         {
      91           0 :             sUrl += "#" + rtl::Uri::encode( m_sId,
      92             :                 rtl_UriCharClassRelSegment,
      93             :                 rtl_UriEncodeKeepEscapes,
      94           0 :                 RTL_TEXTENCODING_UTF8 );
      95             :         }
      96             : 
      97           0 :         return sUrl;
      98             :     }
      99           0 : }
     100             : 
     101             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10