Fix GNU C++ version check
[LibreOffice.git] / ucb / source / ucp / hierarchy / hierarchyuri.cxx
blobb637fd85f93549730cf5a2e59137a139ddf9d5ab
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 /**************************************************************************
22 TODO
23 **************************************************************************
25 *************************************************************************/
27 #include "hierarchyuri.hxx"
29 using namespace hierarchy_ucp;
31 constexpr OUString HIERARCHY_URL_SCHEME = u"vnd.sun.star.hier"_ustr;
32 constexpr OUString DEFAULT_DATA_SOURCE_SERVICE =
33 u"com.sun.star.ucb.DefaultHierarchyDataSource"_ustr;
36 // HierarchyUri Implementation.
39 void HierarchyUri::init() const
41 // Already inited?
42 if ( m_aUri.isEmpty() || !m_aPath.isEmpty() )
43 return;
45 // Note: Maybe it's a re-init, setUri only resets m_aPath!
46 m_aService.clear();
47 m_aParentUri.clear();
49 // URI must match at least: <scheme>:
50 if ( m_aUri.getLength() < HIERARCHY_URL_SCHEME.getLength() + 1 )
52 // error, but remember that we did an init().
53 m_aPath = "/";
54 return;
57 // Scheme is case insensitive.
58 OUString aScheme
59 = m_aUri.copy( 0, HIERARCHY_URL_SCHEME.getLength() ).toAsciiLowerCase();
60 if ( aScheme == HIERARCHY_URL_SCHEME )
62 m_aUri = m_aUri.replaceAt( 0, aScheme.getLength(), aScheme );
64 sal_Int32 nPos = 0;
66 // If the URI has no service specifier, insert default service.
67 // This is for backward compatibility and for convenience.
69 if ( m_aUri.getLength() == HIERARCHY_URL_SCHEME.getLength() + 1 )
71 // root folder URI without path and service specifier.
72 m_aUri += "//" + DEFAULT_DATA_SOURCE_SERVICE + "/";
73 m_aService = DEFAULT_DATA_SOURCE_SERVICE ;
75 nPos = m_aUri.getLength() - 1;
77 else if ( ( m_aUri.getLength() == HIERARCHY_URL_SCHEME.getLength() + 2 )
79 ( m_aUri[ HIERARCHY_URL_SCHEME.getLength() + 1 ] == '/' ) )
81 // root folder URI without service specifier.
82 m_aUri += "/" + DEFAULT_DATA_SOURCE_SERVICE + "/";
83 m_aService = DEFAULT_DATA_SOURCE_SERVICE;
85 nPos = m_aUri.getLength() - 1;
87 else if ( ( m_aUri.getLength() > HIERARCHY_URL_SCHEME.getLength() + 2 )
89 ( m_aUri[ HIERARCHY_URL_SCHEME.getLength() + 2 ] != '/' ) )
91 // other (no root folder) URI without service specifier.
92 m_aUri = m_aUri.replaceAt(
93 HIERARCHY_URL_SCHEME.getLength() + 2,
95 rtl::Concat2View("/" + DEFAULT_DATA_SOURCE_SERVICE + "/") );
96 m_aService = DEFAULT_DATA_SOURCE_SERVICE;
98 nPos
99 = HIERARCHY_URL_SCHEME.getLength() + 3 + m_aService.getLength();
101 else
103 // URI with service specifier.
104 sal_Int32 nStart = HIERARCHY_URL_SCHEME.getLength() + 3;
106 // Here: - m_aUri has at least the form "<scheme>://"
107 // - nStart points to char after <scheme>:
109 // Only <scheme>:// ?
110 if ( nStart == m_aUri.getLength() )
112 // error, but remember that we did an init().
113 m_aPath = "/";
114 return;
117 // Empty path segments?
118 if ( m_aUri.indexOf("//", nStart) != -1 )
120 // error, but remember that we did an init().
121 m_aPath = "/";
122 return;
125 sal_Int32 nEnd = m_aUri.indexOf( '/', nStart );
127 // Only <scheme>:/// ?
128 if ( nEnd == nStart )
130 // error, but remember that we did an init().
131 m_aPath = "/";
132 return;
135 if ( nEnd == -1 )
137 // Trailing slash missing.
138 nEnd = m_aUri.getLength();
139 m_aUri += "/";
142 m_aService = m_aUri.copy( nStart, nEnd - nStart );
144 nPos = nEnd;
147 // Here: - m_aUri has at least the form "<scheme>://<service>/"
148 // - m_aService was set
149 // - m_aPath, m_aParentPath, m_aName not yet set
150 // - nPos points to slash after service specifier
152 // Remove trailing slash, if not a root folder URI.
153 sal_Int32 nEnd = m_aUri.lastIndexOf( '/' );
154 if ( ( nEnd > nPos ) && ( nEnd == ( m_aUri.getLength() - 1 ) ) )
155 m_aUri = m_aUri.copy( 0, nEnd );
157 // Path (includes leading slash)
158 m_aPath = m_aUri.copy( nPos );
160 // parent URI + name
161 sal_Int32 nLastSlash = m_aUri.lastIndexOf( '/' );
162 if ( ( nLastSlash != -1 ) &&
163 ( nLastSlash != m_aUri.getLength() - 1 ) ) // root
165 m_aParentUri = m_aUri.copy( 0, nLastSlash );
168 // success
169 m_bValid = true;
171 else
173 // error, but remember that we did an init().
174 m_aPath = "/";
178 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */