1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
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"
37 #define OUSTR_TO_STDSTR(s) string( rtl::OUStringToOString( s, RTL_TEXTENCODING_UTF8 ).getStr() )
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
);
77 rtl::OUString
& URL::getObjectPath( )
82 rtl::OUString
& URL::getObjectId( )
87 rtl::OUString
& URL::getBindingUrl( )
92 rtl::OUString
& URL::getRepositoryId( )
94 return m_sRepositoryId
;
97 void URL::setObjectPath( rtl::OUString sPath
)
100 m_sId
= rtl::OUString( );
103 rtl::OUString
URL::asString( )
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] != '/' )
119 else if ( !m_sId
.isEmpty( ) )
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */