Stop leaking all ScPostIt instances.
[LibreOffice.git] / ucb / source / ucp / cmis / cmis_url.cxx
blobdd6f8610555cb98358733a52f6cf339cfe197228
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";
42 OUString& URL::getObjectPath( )
44 return m_sPath;
47 OUString& URL::getObjectId( )
49 return m_sId;
52 OUString& URL::getBindingUrl( )
54 return m_sBindingUrl;
57 OUString& URL::getRepositoryId( )
59 return m_sRepositoryId;
62 void URL::setObjectPath( OUString sPath )
64 m_sPath = sPath;
67 void URL::setObjectId( OUString sId )
69 m_sId = sId;
72 OUString URL::asString( )
74 OUString sUrl;
75 OUString sEncodedBinding = rtl::Uri::encode(
76 m_sBindingUrl + "#" + m_sRepositoryId,
77 rtl_UriCharClassRelSegment,
78 rtl_UriEncodeKeepEscapes,
79 RTL_TEXTENCODING_UTF8 );
80 sUrl = "vnd.libreoffice.cmis://" + sEncodedBinding;
82 if ( !m_sPath.isEmpty( ) )
84 sal_Int32 nPos = -1;
85 OUString sEncodedPath;
88 sal_Int32 nStartPos = nPos + 1;
89 nPos = m_sPath.indexOf( '/', nStartPos );
90 sal_Int32 nLen = nPos - nStartPos;
91 if ( nPos == -1 )
92 nLen = m_sPath.getLength( ) - nStartPos;
93 OUString sSegment = m_sPath.copy( nStartPos, nLen );
95 if ( !sSegment.isEmpty( ) )
97 sEncodedPath += "/" + rtl::Uri::encode( sSegment,
98 rtl_UriCharClassRelSegment,
99 rtl_UriEncodeKeepEscapes,
100 RTL_TEXTENCODING_UTF8 );
103 while ( nPos != -1 );
104 sUrl += sEncodedPath;
105 } else if ( !m_sId.isEmpty( ) )
107 sUrl += "#" + rtl::Uri::encode( m_sId,
108 rtl_UriCharClassRelSegment,
109 rtl_UriEncodeKeepEscapes,
110 RTL_TEXTENCODING_UTF8 );
113 return sUrl;
117 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */