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/session-factory.hxx>
12 #include <rtl/uri.hxx>
14 #include "cmis_url.hxx"
20 URL::URL( OUString
const & urlStr
)
22 INetURLObject
aUrl( urlStr
);
24 // Decode the authority to get the binding URL and repository id
25 OUString sDecodedHost
= aUrl
.GetHost( INetURLObject::DECODE_WITH_CHARSET
);
26 INetURLObject
aHostUrl( sDecodedHost
);
27 m_sBindingUrl
= aHostUrl
.GetURLNoMark( );
28 m_sRepositoryId
= aHostUrl
.GetMark( );
30 m_sUser
= aUrl
.GetUser( INetURLObject::DECODE_WITH_CHARSET
);
31 m_sPass
= aUrl
.GetPass( INetURLObject::DECODE_WITH_CHARSET
);
33 // Store the path to the object
34 m_sPath
= aUrl
.GetURLPath( INetURLObject::DECODE_WITH_CHARSET
);
35 m_sId
= aUrl
.GetMark( INetURLObject::DECODE_WITH_CHARSET
);
37 if ( !m_sId
.isEmpty( ) )
38 m_sPath
= OUString( );
41 OUString
& URL::getObjectPath( )
46 OUString
& URL::getObjectId( )
51 OUString
& URL::getBindingUrl( )
56 OUString
& URL::getRepositoryId( )
58 return m_sRepositoryId
;
61 void URL::setObjectPath( OUString sPath
)
67 void URL::setObjectId( OUString sId
)
69 m_sPath
= OUString( );
73 OUString
URL::asString( )
76 OUString sEncodedBinding
= rtl::Uri::encode(
77 m_sBindingUrl
+ "#" + m_sRepositoryId
,
78 rtl_UriCharClassRelSegment
,
79 rtl_UriEncodeKeepEscapes
,
80 RTL_TEXTENCODING_UTF8
);
81 sUrl
= "vnd.libreoffice.cmis://" + sEncodedBinding
;
83 if ( !m_sPath
.isEmpty( ) )
86 OUString sEncodedPath
;
89 sal_Int32 nStartPos
= nPos
+ 1;
90 nPos
= m_sPath
.indexOf( '/', nStartPos
);
91 sal_Int32 nLen
= nPos
- nStartPos
;
93 nLen
= m_sPath
.getLength( ) - nStartPos
;
94 OUString sSegment
= m_sPath
.copy( nStartPos
, nLen
);
96 if ( !sSegment
.isEmpty( ) )
98 sEncodedPath
+= "/" + rtl::Uri::encode( sSegment
,
99 rtl_UriCharClassRelSegment
,
100 rtl_UriEncodeKeepEscapes
,
101 RTL_TEXTENCODING_UTF8
);
104 while ( nPos
!= -1 );
105 sUrl
+= sEncodedPath
;
107 else if ( !m_sId
.isEmpty( ) )
109 sUrl
+= "#" + rtl::Uri::encode( m_sId
,
110 rtl_UriCharClassRelSegment
,
111 rtl_UriEncodeKeepEscapes
,
112 RTL_TEXTENCODING_UTF8
);
119 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */