bump product version to 4.1.6.2
[LibreOffice.git] / ucb / source / ucp / cmis / cmis_url.cxx
blob5235add025b1039852f86c74e912adde6909a19d
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/session-factory.hxx>
12 #include <rtl/uri.hxx>
14 #include "cmis_url.hxx"
16 using namespace std;
18 namespace cmis
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( )
43 return m_sPath;
46 OUString& URL::getObjectId( )
48 return m_sId;
51 OUString& URL::getBindingUrl( )
53 return m_sBindingUrl;
56 OUString& URL::getRepositoryId( )
58 return m_sRepositoryId;
61 void URL::setObjectPath( OUString sPath )
63 m_sPath = sPath;
64 m_sId = OUString( );
67 void URL::setObjectId( OUString sId )
69 m_sPath = OUString( );
70 m_sId = sId;
73 OUString URL::asString( )
75 OUString sUrl;
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( ) )
85 sal_Int32 nPos = -1;
86 OUString sEncodedPath;
89 sal_Int32 nStartPos = nPos + 1;
90 nPos = m_sPath.indexOf( '/', nStartPos );
91 sal_Int32 nLen = nPos - nStartPos;
92 if ( nPos == -1 )
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 );
115 return sUrl;
119 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */