Bump for 3.6-28
[LibreOffice.git] / ucb / source / ucp / cmis / cmis_url.cxx
blob3357a247c3ed5ddc8c17088bc6d7502b6c86f385
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * Version: MPL 1.1 / GPLv3+ / LGPLv3+
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License or as specified alternatively below. You may obtain a copy of
8 * the License at http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * Major Contributor(s):
16 * [ Copyright (C) 2011 SUSE <cbosdonnat@suse.com> (initial developer) ]
18 * All Rights Reserved.
20 * For minor contributions see the git repository.
22 * Alternatively, the contents of this file may be used under the terms of
23 * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
24 * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
25 * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
26 * instead of those above.
29 #include <libcmis/session-factory.hxx>
31 #include <rtl/uri.hxx>
33 #include "cmis_url.hxx"
35 using namespace std;
37 #define OUSTR_TO_STDSTR(s) string( rtl::OUStringToOString( s, RTL_TEXTENCODING_UTF8 ).getStr() )
40 namespace cmis
42 URL::URL( rtl::OUString const & urlStr )
44 rtl::OUString sBindingUrl;
45 rtl::OUString sRepositoryId;
47 INetURLObject aUrl( urlStr );
49 // Decode the authority to get the binding URL and repository id
50 rtl::OUString sDecodedHost = aUrl.GetHost( INetURLObject::DECODE_WITH_CHARSET );
51 INetURLObject aHostUrl( sDecodedHost );
52 m_sBindingUrl = aHostUrl.GetURLNoMark( );
53 m_sRepositoryId = aHostUrl.GetMark( );
55 m_sUser = aUrl.GetUser( );
56 m_sPass = aUrl.GetPass( );
58 // Store the path to the object
59 m_sPath = aUrl.GetURLPath( INetURLObject::DECODE_WITH_CHARSET );
60 m_sId = aUrl.GetMark( );
62 if ( !m_sId.isEmpty( ) )
63 m_sPath = rtl::OUString( );
66 map< int, string > URL::getSessionParams( )
68 map< int, string > params;
69 params[ATOMPUB_URL] = OUSTR_TO_STDSTR( m_sBindingUrl );
70 params[REPOSITORY_ID] = OUSTR_TO_STDSTR( m_sRepositoryId );
71 params[USERNAME] = OUSTR_TO_STDSTR( m_sUser );
72 params[PASSWORD] = OUSTR_TO_STDSTR( m_sPass );
74 return params;
77 rtl::OUString& URL::getObjectPath( )
79 return m_sPath;
82 rtl::OUString& URL::getObjectId( )
84 return m_sId;
87 rtl::OUString& URL::getBindingUrl( )
89 return m_sBindingUrl;
92 rtl::OUString& URL::getRepositoryId( )
94 return m_sRepositoryId;
97 void URL::setObjectPath( rtl::OUString sPath )
99 m_sPath = sPath;
100 m_sId = rtl::OUString( );
103 rtl::OUString URL::asString( )
105 rtl::OUString sUrl;
106 rtl::OUString sEncodedBinding = rtl::Uri::encode(
107 m_sBindingUrl + "#" + m_sRepositoryId,
108 rtl_UriCharClassRelSegment,
109 rtl_UriEncodeKeepEscapes,
110 RTL_TEXTENCODING_UTF8 );
111 sUrl = "vnd.libreoffice.cmis+atom://" + sEncodedBinding;
113 if ( !m_sPath.isEmpty( ) )
115 if ( m_sPath[0] != '/' )
116 sUrl += "/";
117 sUrl += m_sPath;
119 else if ( !m_sId.isEmpty( ) )
121 sUrl += "#" + m_sId;
124 return sUrl;
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */