fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / ucb / source / ucp / cmis / cmis_url.cxx
blobff0763c829f30838de01139871e64bf184bc80ee
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 */
10 #include <libcmis/libcmis.hxx>
12 #include <config_oauth2.h>
13 #include <rtl/uri.hxx>
15 #include "cmis_url.hxx"
17 using namespace std;
19 namespace cmis
21 URL::URL( OUString const & urlStr )
23 INetURLObject aUrl( urlStr );
25 // Decode the authority to get the binding URL and repository id
26 OUString sDecodedHost = aUrl.GetHost( INetURLObject::DECODE_WITH_CHARSET );
27 INetURLObject aHostUrl( sDecodedHost );
28 m_sBindingUrl = aHostUrl.GetURLNoMark( );
29 m_sRepositoryId = aHostUrl.GetMark( );
31 m_sUser = aUrl.GetUser( INetURLObject::DECODE_WITH_CHARSET );
32 m_sPass = aUrl.GetPass( INetURLObject::DECODE_WITH_CHARSET );
34 // Store the path to the object
35 m_sPath = aUrl.GetURLPath( INetURLObject::DECODE_WITH_CHARSET );
36 m_sId = aUrl.GetMark( INetURLObject::DECODE_WITH_CHARSET );
38 if ( m_sPath == "/" && m_sBindingUrl.indexOf( "google" ) != -1 )
39 m_sId = "root";
46 void URL::setObjectPath( const OUString& sPath )
48 m_sPath = sPath;
51 void URL::setObjectId( const OUString& sId )
53 m_sId = sId;
56 OUString URL::asString( )
58 OUString sUrl;
59 OUString sEncodedBinding = rtl::Uri::encode(
60 m_sBindingUrl + "#" + m_sRepositoryId,
61 rtl_UriCharClassRelSegment,
62 rtl_UriEncodeKeepEscapes,
63 RTL_TEXTENCODING_UTF8 );
64 sUrl = "vnd.libreoffice.cmis://" + sEncodedBinding;
66 if ( !m_sPath.isEmpty( ) )
68 sal_Int32 nPos = -1;
69 OUString sEncodedPath;
72 sal_Int32 nStartPos = nPos + 1;
73 nPos = m_sPath.indexOf( '/', nStartPos );
74 sal_Int32 nLen = nPos - nStartPos;
75 if ( nPos == -1 )
76 nLen = m_sPath.getLength( ) - nStartPos;
77 OUString sSegment = m_sPath.copy( nStartPos, nLen );
79 if ( !sSegment.isEmpty( ) )
81 sEncodedPath += "/" + rtl::Uri::encode( sSegment,
82 rtl_UriCharClassRelSegment,
83 rtl_UriEncodeKeepEscapes,
84 RTL_TEXTENCODING_UTF8 );
87 while ( nPos != -1 );
88 sUrl += sEncodedPath;
89 } else if ( !m_sId.isEmpty( ) )
91 sUrl += "#" + rtl::Uri::encode( m_sId,
92 rtl_UriCharClassRelSegment,
93 rtl_UriEncodeKeepEscapes,
94 RTL_TEXTENCODING_UTF8 );
97 return sUrl;
101 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */