LCOV - code coverage report
Current view: top level - ucb/source/ucp/cmis - cmis_url.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 52 0.0 %
Date: 2014-04-14 Functions: 0 10 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           0 :     OUString& URL::getObjectPath( )
      43             :     {
      44           0 :         return m_sPath;
      45             :     }
      46             : 
      47           0 :     OUString& URL::getObjectId( )
      48             :     {
      49           0 :         return m_sId;
      50             :     }
      51             : 
      52           0 :     OUString& URL::getBindingUrl( )
      53             :     {
      54           0 :         return m_sBindingUrl;
      55             :     }
      56             : 
      57           0 :     OUString& URL::getRepositoryId( )
      58             :     {
      59           0 :         return m_sRepositoryId;
      60             :     }
      61             : 
      62           0 :     void URL::setObjectPath( const OUString& sPath )
      63             :     {
      64           0 :         m_sPath = sPath;
      65           0 :     }
      66             : 
      67           0 :     void URL::setObjectId( const OUString& sId )
      68             :     {
      69           0 :         m_sId = sId;
      70           0 :     }
      71             : 
      72           0 :     OUString URL::asString( )
      73             :     {
      74           0 :         OUString sUrl;
      75             :         OUString sEncodedBinding = rtl::Uri::encode(
      76           0 :                 m_sBindingUrl + "#" + m_sRepositoryId,
      77             :                 rtl_UriCharClassRelSegment,
      78             :                 rtl_UriEncodeKeepEscapes,
      79           0 :                 RTL_TEXTENCODING_UTF8 );
      80           0 :         sUrl = "vnd.libreoffice.cmis://" + sEncodedBinding;
      81             : 
      82           0 :         if ( !m_sPath.isEmpty( ) )
      83             :         {
      84           0 :             sal_Int32 nPos = -1;
      85           0 :             OUString sEncodedPath;
      86           0 :             do
      87             :             {
      88           0 :                 sal_Int32 nStartPos = nPos + 1;
      89           0 :                 nPos = m_sPath.indexOf( '/', nStartPos );
      90           0 :                 sal_Int32 nLen = nPos - nStartPos;
      91           0 :                 if ( nPos == -1 )
      92           0 :                     nLen = m_sPath.getLength( ) - nStartPos;
      93           0 :                 OUString sSegment = m_sPath.copy( nStartPos, nLen );
      94             : 
      95           0 :                 if ( !sSegment.isEmpty( ) )
      96             :                 {
      97           0 :                     sEncodedPath += "/" + rtl::Uri::encode( sSegment,
      98             :                             rtl_UriCharClassRelSegment,
      99             :                             rtl_UriEncodeKeepEscapes,
     100           0 :                             RTL_TEXTENCODING_UTF8 );
     101           0 :                 }
     102             :             }
     103             :             while ( nPos != -1 );
     104           0 :             sUrl += sEncodedPath;
     105           0 :         } else if ( !m_sId.isEmpty( ) )
     106             :         {
     107           0 :             sUrl += "#" + rtl::Uri::encode( m_sId,
     108             :                 rtl_UriCharClassRelSegment,
     109             :                 rtl_UriEncodeKeepEscapes,
     110           0 :                 RTL_TEXTENCODING_UTF8 );
     111             :         }
     112             : 
     113           0 :         return sUrl;
     114             :     }
     115           0 : }
     116             : 
     117             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10