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 <libcmis/libcmis.hxx>
12 #include <config_oauth2.h>
13 #include <rtl/uri.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::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 )
46 void URL::setObjectPath( const OUString
& sPath
)
51 void URL::setObjectId( const OUString
& sId
)
56 OUString
URL::asString( )
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( ) )
69 OUString sEncodedPath
;
72 sal_Int32 nStartPos
= nPos
+ 1;
73 nPos
= m_sPath
.indexOf( '/', nStartPos
);
74 sal_Int32 nLen
= nPos
- nStartPos
;
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
);
89 } else if ( !m_sId
.isEmpty( ) )
91 sUrl
+= "#" + rtl::Uri::encode( m_sId
,
92 rtl_UriCharClassRelSegment
,
93 rtl_UriEncodeKeepEscapes
,
94 RTL_TEXTENCODING_UTF8
);
101 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */