bump product version to 7.2.5.1
[LibreOffice.git] / ucb / source / ucp / hierarchy / hierarchyuri.cxx
blobd936b810a3ab59b6dd59bdb136499a371a715fbd
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 #define HIERARCHY_URL_SCHEME "vnd.sun.star.hier"
32 #define HIERARCHY_URL_SCHEME_LENGTH 17
33 #define DEFAULT_DATA_SOURCE_SERVICE \
34 "com.sun.star.ucb.DefaultHierarchyDataSource"
37 // HierarchyUri Implementation.
40 void HierarchyUri::init() const
42 // Already inited?
43 if ( m_aUri.isEmpty() || !m_aPath.isEmpty() )
44 return;
46 // Note: Maybe it's a re-init, setUri only resets m_aPath!
47 m_aService.clear();
48 m_aParentUri.clear();
50 // URI must match at least: <scheme>:
51 if ( m_aUri.getLength() < HIERARCHY_URL_SCHEME_LENGTH + 1 )
53 // error, but remember that we did an init().
54 m_aPath = "/";
55 return;
58 // Scheme is case insensitive.
59 OUString aScheme
60 = m_aUri.copy( 0, HIERARCHY_URL_SCHEME_LENGTH ).toAsciiLowerCase();
61 if ( aScheme == HIERARCHY_URL_SCHEME )
63 m_aUri = m_aUri.replaceAt( 0, aScheme.getLength(), aScheme );
65 sal_Int32 nPos = 0;
67 // If the URI has no service specifier, insert default service.
68 // This is for backward compatibility and for convenience.
70 if ( m_aUri.getLength() == HIERARCHY_URL_SCHEME_LENGTH + 1 )
72 // root folder URI without path and service specifier.
73 m_aUri += "//" DEFAULT_DATA_SOURCE_SERVICE "/";
74 m_aService = DEFAULT_DATA_SOURCE_SERVICE ;
76 nPos = m_aUri.getLength() - 1;
78 else if ( ( m_aUri.getLength() == HIERARCHY_URL_SCHEME_LENGTH + 2 )
80 ( m_aUri[ HIERARCHY_URL_SCHEME_LENGTH + 1 ] == '/' ) )
82 // root folder URI without service specifier.
83 m_aUri += "/" DEFAULT_DATA_SOURCE_SERVICE "/";
84 m_aService = DEFAULT_DATA_SOURCE_SERVICE;
86 nPos = m_aUri.getLength() - 1;
88 else if ( ( m_aUri.getLength() > HIERARCHY_URL_SCHEME_LENGTH + 2 )
90 ( m_aUri[ HIERARCHY_URL_SCHEME_LENGTH + 2 ] != '/' ) )
92 // other (no root folder) URI without service specifier.
93 m_aUri = m_aUri.replaceAt(
94 HIERARCHY_URL_SCHEME_LENGTH + 2,
96 "/" DEFAULT_DATA_SOURCE_SERVICE "/" );
97 m_aService = DEFAULT_DATA_SOURCE_SERVICE;
99 nPos
100 = HIERARCHY_URL_SCHEME_LENGTH + 3 + m_aService.getLength();
102 else
104 // URI with service specifier.
105 sal_Int32 nStart = HIERARCHY_URL_SCHEME_LENGTH + 3;
107 // Here: - m_aUri has at least the form "<scheme>://"
108 // - nStart points to char after <scheme>:
110 // Only <scheme>:// ?
111 if ( nStart == m_aUri.getLength() )
113 // error, but remember that we did an init().
114 m_aPath = "/";
115 return;
118 // Empty path segments?
119 if ( m_aUri.indexOf("//", nStart) != -1 )
121 // error, but remember that we did an init().
122 m_aPath = "/";
123 return;
126 sal_Int32 nEnd = m_aUri.indexOf( '/', nStart );
128 // Only <scheme>:/// ?
129 if ( nEnd == nStart )
131 // error, but remember that we did an init().
132 m_aPath = "/";
133 return;
136 if ( nEnd == -1 )
138 // Trailing slash missing.
139 nEnd = m_aUri.getLength();
140 m_aUri += "/";
143 m_aService = m_aUri.copy( nStart, nEnd - nStart );
145 nPos = nEnd;
148 // Here: - m_aUri has at least the form "<scheme>://<service>/"
149 // - m_aService was set
150 // - m_aPath, m_aParentPath, m_aName not yet set
151 // - nPos points to slash after service specifier
153 // Remove trailing slash, if not a root folder URI.
154 sal_Int32 nEnd = m_aUri.lastIndexOf( '/' );
155 if ( ( nEnd > nPos ) && ( nEnd == ( m_aUri.getLength() - 1 ) ) )
156 m_aUri = m_aUri.copy( 0, nEnd );
158 // Path (includes leading slash)
159 m_aPath = m_aUri.copy( nPos );
161 // parent URI + name
162 sal_Int32 nLastSlash = m_aUri.lastIndexOf( '/' );
163 if ( ( nLastSlash != -1 ) &&
164 ( nLastSlash != m_aUri.getLength() - 1 ) ) // root
166 m_aParentUri = m_aUri.copy( 0, nLastSlash );
169 // success
170 m_bValid = true;
172 else
174 // error, but remember that we did an init().
175 m_aPath = "/";
179 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */