bump product version to 7.6.3.2-android
[LibreOffice.git] / ucb / source / ucp / cmis / cmis_url.cxx
blob86fde73b94bb4174b606064a292d4131d9a7d435
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 <sal/config.h>
12 #include <rtl/uri.hxx>
13 #include <tools/urlobj.hxx>
15 #include "cmis_url.hxx"
17 namespace cmis
19 URL::URL( std::u16string_view urlStr )
21 INetURLObject aUrl( urlStr );
23 // Decode the authority to get the binding URL and repository id
24 OUString sDecodedHost = aUrl.GetHost( INetURLObject::DecodeMechanism::WithCharset );
25 INetURLObject aHostUrl( sDecodedHost );
26 m_sBindingUrl = aHostUrl.GetURLNoMark( );
27 m_sRepositoryId = aHostUrl.GetMark( );
29 m_sUser = aUrl.GetUser( INetURLObject::DecodeMechanism::WithCharset );
30 m_sPass = aUrl.GetPass( INetURLObject::DecodeMechanism::WithCharset );
32 // Store the path to the object
33 m_sPath = aUrl.GetURLPath( INetURLObject::DecodeMechanism::WithCharset );
34 m_sId = aUrl.GetMark( INetURLObject::DecodeMechanism::WithCharset );
36 if ( m_sPath == "/" && m_sBindingUrl.indexOf( "google" ) != -1 )
37 m_sId = "root";
41 void URL::setObjectPath( const OUString& sPath )
43 m_sPath = sPath;
46 void URL::setObjectId( const OUString& sId )
48 m_sId = sId;
51 void URL::setUsername( const OUString& sUser )
53 m_sUser = sUser;
56 OUString URL::asString( ) const
58 OUString sUrl;
59 // Related tdf#96174, can no longer save on Google Drive
60 // the user field may contain characters that need to be escaped according to
61 // RFC3896 userinfo URI field
62 // see <https://tools.ietf.org/html/rfc3986#section-3.2.1>
63 OUString sEncodedUser = ( m_sUser.isEmpty() ?
64 OUString() :
65 rtl::Uri::encode( m_sUser, rtl_UriCharClassUserinfo,
66 rtl_UriEncodeIgnoreEscapes, RTL_TEXTENCODING_UTF8) );
67 OUString sEncodedBinding = rtl::Uri::encode(
68 m_sBindingUrl + "#" + m_sRepositoryId,
69 rtl_UriCharClassRelSegment,
70 rtl_UriEncodeKeepEscapes,
71 RTL_TEXTENCODING_UTF8 );
72 sUrl = "vnd.libreoffice.cmis://" +
73 ( sEncodedUser.isEmpty() ? OUString( ) : (sEncodedUser + "@") ) +
74 sEncodedBinding;
76 if ( !m_sPath.isEmpty( ) )
78 sal_Int32 nPos = -1;
79 OUStringBuffer sEncodedPath;
82 sal_Int32 nStartPos = nPos + 1;
83 nPos = m_sPath.indexOf( '/', nStartPos );
84 sal_Int32 nLen = nPos - nStartPos;
85 if ( nPos == -1 )
86 nLen = m_sPath.getLength( ) - nStartPos;
87 OUString sSegment = m_sPath.copy( nStartPos, nLen );
89 if ( !sSegment.isEmpty( ) )
91 sEncodedPath.append("/" + rtl::Uri::encode( sSegment,
92 rtl_UriCharClassRelSegment,
93 rtl_UriEncodeKeepEscapes,
94 RTL_TEXTENCODING_UTF8 ));
97 while ( nPos != -1 );
98 sUrl += sEncodedPath;
99 } else if ( !m_sId.isEmpty( ) )
101 sUrl += "#" + rtl::Uri::encode( m_sId,
102 rtl_UriCharClassRelSegment,
103 rtl_UriEncodeKeepEscapes,
104 RTL_TEXTENCODING_UTF8 );
107 return sUrl;
111 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */