1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #include <sal/config.h>
12 #include <rtl/uri.hxx>
13 #include <tools/urlobj.hxx>
15 #include "cmis_url.hxx"
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::DecodeMechanism::WithCharset
);
27 INetURLObject
aHostUrl( sDecodedHost
);
28 m_sBindingUrl
= aHostUrl
.GetURLNoMark( );
29 m_sRepositoryId
= aHostUrl
.GetMark( );
31 m_sUser
= aUrl
.GetUser( INetURLObject::DecodeMechanism::WithCharset
);
32 m_sPass
= aUrl
.GetPass( INetURLObject::DecodeMechanism::WithCharset
);
34 // Store the path to the object
35 m_sPath
= aUrl
.GetURLPath( INetURLObject::DecodeMechanism::WithCharset
);
36 m_sId
= aUrl
.GetMark( INetURLObject::DecodeMechanism::WithCharset
);
38 if ( m_sPath
== "/" && m_sBindingUrl
.indexOf( "google" ) != -1 )
43 void URL::setObjectPath( const OUString
& sPath
)
48 void URL::setObjectId( const OUString
& sId
)
53 void URL::setUsername( const OUString
& sUser
)
58 OUString
URL::asString( )
61 // Related tdf#96174, can no longer save on Google Drive
62 // the user field may contain characters that need to be escaped according to
63 // RFC3896 userinfo URI field
64 // see <https://tools.ietf.org/html/rfc3986#section-3.2.1>
65 OUString sEncodedUser
= ( m_sUser
.isEmpty() ?
67 rtl::Uri::encode( m_sUser
, rtl_UriCharClassUserinfo
,
68 rtl_UriEncodeIgnoreEscapes
, RTL_TEXTENCODING_UTF8
) );
69 OUString sEncodedBinding
= rtl::Uri::encode(
70 m_sBindingUrl
+ "#" + m_sRepositoryId
,
71 rtl_UriCharClassRelSegment
,
72 rtl_UriEncodeKeepEscapes
,
73 RTL_TEXTENCODING_UTF8
);
74 sUrl
= "vnd.libreoffice.cmis://" +
75 ( sEncodedUser
.isEmpty() ? OUString( ) : (sEncodedUser
+ "@") ) +
78 if ( !m_sPath
.isEmpty( ) )
81 OUStringBuffer sEncodedPath
;
84 sal_Int32 nStartPos
= nPos
+ 1;
85 nPos
= m_sPath
.indexOf( '/', nStartPos
);
86 sal_Int32 nLen
= nPos
- nStartPos
;
88 nLen
= m_sPath
.getLength( ) - nStartPos
;
89 OUString sSegment
= m_sPath
.copy( nStartPos
, nLen
);
91 if ( !sSegment
.isEmpty( ) )
93 sEncodedPath
.append("/").append(rtl::Uri::encode( sSegment
,
94 rtl_UriCharClassRelSegment
,
95 rtl_UriEncodeKeepEscapes
,
96 RTL_TEXTENCODING_UTF8
));
100 sUrl
+= sEncodedPath
.makeStringAndClear();
101 } else if ( !m_sId
.isEmpty( ) )
103 sUrl
+= "#" + rtl::Uri::encode( m_sId
,
104 rtl_UriCharClassRelSegment
,
105 rtl_UriEncodeKeepEscapes
,
106 RTL_TEXTENCODING_UTF8
);
113 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */