Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * Version: MPL 1.1 / GPLv3+ / LGPLv3+
4 : *
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/
9 : *
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.
14 : *
15 : * Major Contributor(s):
16 : * [ Copyright (C) 2011 SUSE <cbosdonnat@suse.com> (initial developer) ]
17 : *
18 : * All Rights Reserved.
19 : *
20 : * For minor contributions see the git repository.
21 : *
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.
27 : */
28 :
29 : #include <libcmis/session-factory.hxx>
30 :
31 : #include <rtl/uri.hxx>
32 :
33 : #include "cmis_url.hxx"
34 :
35 : using namespace std;
36 :
37 : #define OUSTR_TO_STDSTR(s) string( rtl::OUStringToOString( s, RTL_TEXTENCODING_UTF8 ).getStr() )
38 :
39 :
40 : namespace cmis
41 : {
42 0 : URL::URL( rtl::OUString const & urlStr )
43 : {
44 0 : rtl::OUString sBindingUrl;
45 0 : rtl::OUString sRepositoryId;
46 :
47 0 : INetURLObject aUrl( urlStr );
48 :
49 : // Decode the authority to get the binding URL and repository id
50 0 : rtl::OUString sDecodedHost = aUrl.GetHost( INetURLObject::DECODE_WITH_CHARSET );
51 0 : INetURLObject aHostUrl( sDecodedHost );
52 0 : m_sBindingUrl = aHostUrl.GetURLNoMark( );
53 0 : m_sRepositoryId = aHostUrl.GetMark( );
54 :
55 0 : m_sUser = aUrl.GetUser( );
56 0 : m_sPass = aUrl.GetPass( );
57 :
58 : // Store the path to the object
59 0 : m_sPath = aUrl.GetURLPath( INetURLObject::DECODE_WITH_CHARSET );
60 0 : m_sId = aUrl.GetMark( );
61 :
62 0 : if ( !m_sId.isEmpty( ) )
63 0 : m_sPath = rtl::OUString( );
64 0 : }
65 :
66 0 : rtl::OUString& URL::getObjectPath( )
67 : {
68 0 : return m_sPath;
69 : }
70 :
71 0 : rtl::OUString& URL::getObjectId( )
72 : {
73 0 : return m_sId;
74 : }
75 :
76 0 : rtl::OUString& URL::getBindingUrl( )
77 : {
78 0 : return m_sBindingUrl;
79 : }
80 :
81 0 : rtl::OUString& URL::getRepositoryId( )
82 : {
83 0 : return m_sRepositoryId;
84 : }
85 :
86 0 : void URL::setObjectPath( rtl::OUString sPath )
87 : {
88 0 : m_sPath = sPath;
89 0 : m_sId = rtl::OUString( );
90 0 : }
91 :
92 0 : void URL::setObjectId( rtl::OUString sId )
93 : {
94 0 : m_sPath = rtl::OUString( );
95 0 : m_sId = sId;
96 0 : }
97 :
98 0 : rtl::OUString URL::asString( )
99 : {
100 0 : rtl::OUString sUrl;
101 : rtl::OUString sEncodedBinding = rtl::Uri::encode(
102 0 : m_sBindingUrl + "#" + m_sRepositoryId,
103 : rtl_UriCharClassRelSegment,
104 : rtl_UriEncodeKeepEscapes,
105 0 : RTL_TEXTENCODING_UTF8 );
106 0 : sUrl = "vnd.libreoffice.cmis://" + sEncodedBinding;
107 :
108 0 : if ( !m_sPath.isEmpty( ) )
109 : {
110 0 : if ( m_sPath[0] != '/' )
111 0 : sUrl += "/";
112 0 : sUrl += m_sPath;
113 : }
114 0 : else if ( !m_sId.isEmpty( ) )
115 : {
116 0 : sUrl += "#" + m_sId;
117 : }
118 :
119 0 : return sUrl;
120 : }
121 0 : }
122 :
123 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|