1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 /**************************************************************************
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
43 if ( m_aUri
.isEmpty() || !m_aPath
.isEmpty() )
46 // Note: Maybe it's a re-init, setUri only resets m_aPath!
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().
58 // Scheme is case insensitive.
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
);
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
;
100 = HIERARCHY_URL_SCHEME_LENGTH
+ 3 + m_aService
.getLength();
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().
118 // Empty path segments?
119 if ( m_aUri
.indexOf("//", nStart
) != -1 )
121 // error, but remember that we did an init().
126 sal_Int32 nEnd
= m_aUri
.indexOf( '/', nStart
);
128 // Only <scheme>:/// ?
129 if ( nEnd
== nStart
)
131 // error, but remember that we did an init().
138 // Trailing slash missing.
139 nEnd
= m_aUri
.getLength();
143 m_aService
= m_aUri
.copy( nStart
, nEnd
- nStart
);
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
);
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
);
174 // error, but remember that we did an init().
179 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */