1*b1cdbd2cSJim Jagielski /**************************************************************
2*b1cdbd2cSJim Jagielski *
3*b1cdbd2cSJim Jagielski * Licensed to the Apache Software Foundation (ASF) under one
4*b1cdbd2cSJim Jagielski * or more contributor license agreements. See the NOTICE file
5*b1cdbd2cSJim Jagielski * distributed with this work for additional information
6*b1cdbd2cSJim Jagielski * regarding copyright ownership. The ASF licenses this file
7*b1cdbd2cSJim Jagielski * to you under the Apache License, Version 2.0 (the
8*b1cdbd2cSJim Jagielski * "License"); you may not use this file except in compliance
9*b1cdbd2cSJim Jagielski * with the License. You may obtain a copy of the License at
10*b1cdbd2cSJim Jagielski *
11*b1cdbd2cSJim Jagielski * http://www.apache.org/licenses/LICENSE-2.0
12*b1cdbd2cSJim Jagielski *
13*b1cdbd2cSJim Jagielski * Unless required by applicable law or agreed to in writing,
14*b1cdbd2cSJim Jagielski * software distributed under the License is distributed on an
15*b1cdbd2cSJim Jagielski * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b1cdbd2cSJim Jagielski * KIND, either express or implied. See the License for the
17*b1cdbd2cSJim Jagielski * specific language governing permissions and limitations
18*b1cdbd2cSJim Jagielski * under the License.
19*b1cdbd2cSJim Jagielski *
20*b1cdbd2cSJim Jagielski *************************************************************/
21*b1cdbd2cSJim Jagielski
22*b1cdbd2cSJim Jagielski
23*b1cdbd2cSJim Jagielski
24*b1cdbd2cSJim Jagielski // MARKER(update_precomp.py): autogen include statement, do not remove
25*b1cdbd2cSJim Jagielski #include "precompiled_ucb.hxx"
26*b1cdbd2cSJim Jagielski
27*b1cdbd2cSJim Jagielski /**************************************************************************
28*b1cdbd2cSJim Jagielski TODO
29*b1cdbd2cSJim Jagielski **************************************************************************
30*b1cdbd2cSJim Jagielski
31*b1cdbd2cSJim Jagielski *************************************************************************/
32*b1cdbd2cSJim Jagielski
33*b1cdbd2cSJim Jagielski #include "rtl/ustrbuf.hxx"
34*b1cdbd2cSJim Jagielski #include "osl/diagnose.h"
35*b1cdbd2cSJim Jagielski
36*b1cdbd2cSJim Jagielski #include "hierarchyuri.hxx"
37*b1cdbd2cSJim Jagielski
38*b1cdbd2cSJim Jagielski using namespace hierarchy_ucp;
39*b1cdbd2cSJim Jagielski
40*b1cdbd2cSJim Jagielski //=========================================================================
41*b1cdbd2cSJim Jagielski
42*b1cdbd2cSJim Jagielski #define DEFAULT_DATA_SOURCE_SERVICE \
43*b1cdbd2cSJim Jagielski "com.sun.star.ucb.DefaultHierarchyDataSource"
44*b1cdbd2cSJim Jagielski
45*b1cdbd2cSJim Jagielski //=========================================================================
46*b1cdbd2cSJim Jagielski //=========================================================================
47*b1cdbd2cSJim Jagielski //
48*b1cdbd2cSJim Jagielski // HierarchyUri Implementation.
49*b1cdbd2cSJim Jagielski //
50*b1cdbd2cSJim Jagielski //=========================================================================
51*b1cdbd2cSJim Jagielski //=========================================================================
52*b1cdbd2cSJim Jagielski
init() const53*b1cdbd2cSJim Jagielski void HierarchyUri::init() const
54*b1cdbd2cSJim Jagielski {
55*b1cdbd2cSJim Jagielski // Already inited?
56*b1cdbd2cSJim Jagielski if ( m_aUri.getLength() && !m_aPath.getLength() )
57*b1cdbd2cSJim Jagielski {
58*b1cdbd2cSJim Jagielski // Note: Maybe it's a re-init, setUri only resets m_aPath!
59*b1cdbd2cSJim Jagielski m_aService = m_aParentUri = m_aName = rtl::OUString();
60*b1cdbd2cSJim Jagielski
61*b1cdbd2cSJim Jagielski // URI must match at least: <sheme>:
62*b1cdbd2cSJim Jagielski if ( ( m_aUri.getLength() < HIERARCHY_URL_SCHEME_LENGTH + 1 ) )
63*b1cdbd2cSJim Jagielski {
64*b1cdbd2cSJim Jagielski // error, but remember that we did a init().
65*b1cdbd2cSJim Jagielski m_aPath = rtl::OUString::createFromAscii( "/" );
66*b1cdbd2cSJim Jagielski return;
67*b1cdbd2cSJim Jagielski }
68*b1cdbd2cSJim Jagielski
69*b1cdbd2cSJim Jagielski // Scheme is case insensitive.
70*b1cdbd2cSJim Jagielski rtl::OUString aScheme
71*b1cdbd2cSJim Jagielski = m_aUri.copy( 0, HIERARCHY_URL_SCHEME_LENGTH ).toAsciiLowerCase();
72*b1cdbd2cSJim Jagielski if ( aScheme.equalsAsciiL(
73*b1cdbd2cSJim Jagielski RTL_CONSTASCII_STRINGPARAM( HIERARCHY_URL_SCHEME ) ) )
74*b1cdbd2cSJim Jagielski {
75*b1cdbd2cSJim Jagielski m_aUri = m_aUri.replaceAt( 0, aScheme.getLength(), aScheme );
76*b1cdbd2cSJim Jagielski
77*b1cdbd2cSJim Jagielski sal_Int32 nPos = 0;
78*b1cdbd2cSJim Jagielski
79*b1cdbd2cSJim Jagielski // If the URI has no service specifier, insert default service.
80*b1cdbd2cSJim Jagielski // This is for backward compatibility and for convenience.
81*b1cdbd2cSJim Jagielski
82*b1cdbd2cSJim Jagielski if ( m_aUri.getLength() == HIERARCHY_URL_SCHEME_LENGTH + 1 )
83*b1cdbd2cSJim Jagielski {
84*b1cdbd2cSJim Jagielski // root folder URI without path and service specifier.
85*b1cdbd2cSJim Jagielski m_aUri += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
86*b1cdbd2cSJim Jagielski "//" DEFAULT_DATA_SOURCE_SERVICE "/" ) );
87*b1cdbd2cSJim Jagielski m_aService
88*b1cdbd2cSJim Jagielski = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
89*b1cdbd2cSJim Jagielski DEFAULT_DATA_SOURCE_SERVICE ) );
90*b1cdbd2cSJim Jagielski
91*b1cdbd2cSJim Jagielski nPos = m_aUri.getLength() - 1;
92*b1cdbd2cSJim Jagielski }
93*b1cdbd2cSJim Jagielski else if ( ( m_aUri.getLength() == HIERARCHY_URL_SCHEME_LENGTH + 2 )
94*b1cdbd2cSJim Jagielski &&
95*b1cdbd2cSJim Jagielski ( m_aUri.getStr()[ HIERARCHY_URL_SCHEME_LENGTH + 1 ]
96*b1cdbd2cSJim Jagielski == sal_Unicode( '/' ) ) )
97*b1cdbd2cSJim Jagielski {
98*b1cdbd2cSJim Jagielski // root folder URI without service specifier.
99*b1cdbd2cSJim Jagielski m_aUri += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
100*b1cdbd2cSJim Jagielski "/" DEFAULT_DATA_SOURCE_SERVICE "/" ) );
101*b1cdbd2cSJim Jagielski m_aService
102*b1cdbd2cSJim Jagielski = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
103*b1cdbd2cSJim Jagielski DEFAULT_DATA_SOURCE_SERVICE ) );
104*b1cdbd2cSJim Jagielski
105*b1cdbd2cSJim Jagielski nPos = m_aUri.getLength() - 1;
106*b1cdbd2cSJim Jagielski }
107*b1cdbd2cSJim Jagielski else if ( ( m_aUri.getLength() > HIERARCHY_URL_SCHEME_LENGTH + 2 )
108*b1cdbd2cSJim Jagielski &&
109*b1cdbd2cSJim Jagielski ( m_aUri.getStr()[ HIERARCHY_URL_SCHEME_LENGTH + 2 ]
110*b1cdbd2cSJim Jagielski != sal_Unicode( '/' ) ) )
111*b1cdbd2cSJim Jagielski {
112*b1cdbd2cSJim Jagielski // other (no root folder) URI without service specifier.
113*b1cdbd2cSJim Jagielski m_aUri = m_aUri.replaceAt(
114*b1cdbd2cSJim Jagielski HIERARCHY_URL_SCHEME_LENGTH + 2,
115*b1cdbd2cSJim Jagielski 0,
116*b1cdbd2cSJim Jagielski rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
117*b1cdbd2cSJim Jagielski "/" DEFAULT_DATA_SOURCE_SERVICE "/" ) ) );
118*b1cdbd2cSJim Jagielski m_aService
119*b1cdbd2cSJim Jagielski = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
120*b1cdbd2cSJim Jagielski DEFAULT_DATA_SOURCE_SERVICE ) );
121*b1cdbd2cSJim Jagielski
122*b1cdbd2cSJim Jagielski nPos
123*b1cdbd2cSJim Jagielski = HIERARCHY_URL_SCHEME_LENGTH + 3 + m_aService.getLength();
124*b1cdbd2cSJim Jagielski }
125*b1cdbd2cSJim Jagielski else
126*b1cdbd2cSJim Jagielski {
127*b1cdbd2cSJim Jagielski // URI with service specifier.
128*b1cdbd2cSJim Jagielski sal_Int32 nStart = HIERARCHY_URL_SCHEME_LENGTH + 3;
129*b1cdbd2cSJim Jagielski
130*b1cdbd2cSJim Jagielski // Here: - m_aUri has at least the form "<scheme>://"
131*b1cdbd2cSJim Jagielski // - nStart points to char after <scheme>://
132*b1cdbd2cSJim Jagielski
133*b1cdbd2cSJim Jagielski // Only <scheme>:// ?
134*b1cdbd2cSJim Jagielski if ( nStart == m_aUri.getLength() )
135*b1cdbd2cSJim Jagielski {
136*b1cdbd2cSJim Jagielski // error, but remember that we did a init().
137*b1cdbd2cSJim Jagielski m_aPath = rtl::OUString::createFromAscii( "/" );
138*b1cdbd2cSJim Jagielski return;
139*b1cdbd2cSJim Jagielski }
140*b1cdbd2cSJim Jagielski
141*b1cdbd2cSJim Jagielski // Empty path segments?
142*b1cdbd2cSJim Jagielski if ( m_aUri.indexOf(
143*b1cdbd2cSJim Jagielski rtl::OUString::createFromAscii( "//" ),
144*b1cdbd2cSJim Jagielski nStart ) != -1 )
145*b1cdbd2cSJim Jagielski {
146*b1cdbd2cSJim Jagielski // error, but remember that we did a init().
147*b1cdbd2cSJim Jagielski m_aPath = rtl::OUString::createFromAscii( "/" );
148*b1cdbd2cSJim Jagielski return;
149*b1cdbd2cSJim Jagielski }
150*b1cdbd2cSJim Jagielski
151*b1cdbd2cSJim Jagielski sal_Int32 nEnd = m_aUri.indexOf( '/', nStart );
152*b1cdbd2cSJim Jagielski
153*b1cdbd2cSJim Jagielski // Only <scheme>:/// ?
154*b1cdbd2cSJim Jagielski if ( nEnd == nStart )
155*b1cdbd2cSJim Jagielski {
156*b1cdbd2cSJim Jagielski // error, but remember that we did a init().
157*b1cdbd2cSJim Jagielski m_aPath = rtl::OUString::createFromAscii( "/" );
158*b1cdbd2cSJim Jagielski return;
159*b1cdbd2cSJim Jagielski }
160*b1cdbd2cSJim Jagielski
161*b1cdbd2cSJim Jagielski if ( nEnd == -1 )
162*b1cdbd2cSJim Jagielski {
163*b1cdbd2cSJim Jagielski // Trailing slash missing.
164*b1cdbd2cSJim Jagielski nEnd = m_aUri.getLength();
165*b1cdbd2cSJim Jagielski m_aUri += rtl::OUString::createFromAscii( "/" );
166*b1cdbd2cSJim Jagielski }
167*b1cdbd2cSJim Jagielski
168*b1cdbd2cSJim Jagielski m_aService = m_aUri.copy( nStart, nEnd - nStart );
169*b1cdbd2cSJim Jagielski
170*b1cdbd2cSJim Jagielski nPos = nEnd;
171*b1cdbd2cSJim Jagielski }
172*b1cdbd2cSJim Jagielski
173*b1cdbd2cSJim Jagielski // Here: - m_aUri has at least the form "<scheme>://<service>/"
174*b1cdbd2cSJim Jagielski // - m_aService was set
175*b1cdbd2cSJim Jagielski // - m_aPath, m_aParentPath, m_aName not yet set
176*b1cdbd2cSJim Jagielski // - nPos points to slash after service specifier
177*b1cdbd2cSJim Jagielski
178*b1cdbd2cSJim Jagielski // Remove trailing slash, if not a root folder URI.
179*b1cdbd2cSJim Jagielski sal_Int32 nEnd = m_aUri.lastIndexOf( '/' );
180*b1cdbd2cSJim Jagielski if ( ( nEnd > nPos ) && ( nEnd == ( m_aUri.getLength() - 1 ) ) )
181*b1cdbd2cSJim Jagielski m_aUri = m_aUri.copy( 0, nEnd );
182*b1cdbd2cSJim Jagielski
183*b1cdbd2cSJim Jagielski // Path (includes leading slash)
184*b1cdbd2cSJim Jagielski m_aPath = m_aUri.copy( nPos );
185*b1cdbd2cSJim Jagielski
186*b1cdbd2cSJim Jagielski // parent URI + name
187*b1cdbd2cSJim Jagielski sal_Int32 nLastSlash = m_aUri.lastIndexOf( '/' );
188*b1cdbd2cSJim Jagielski if ( ( nLastSlash != -1 ) &&
189*b1cdbd2cSJim Jagielski ( nLastSlash != m_aUri.getLength() - 1 ) ) // root
190*b1cdbd2cSJim Jagielski {
191*b1cdbd2cSJim Jagielski m_aParentUri = m_aUri.copy( 0, nLastSlash );
192*b1cdbd2cSJim Jagielski m_aName = m_aUri.copy( nLastSlash + 1 );
193*b1cdbd2cSJim Jagielski }
194*b1cdbd2cSJim Jagielski
195*b1cdbd2cSJim Jagielski // success
196*b1cdbd2cSJim Jagielski m_bValid = true;
197*b1cdbd2cSJim Jagielski }
198*b1cdbd2cSJim Jagielski else
199*b1cdbd2cSJim Jagielski {
200*b1cdbd2cSJim Jagielski // error, but remember that we did a init().
201*b1cdbd2cSJim Jagielski m_aPath = rtl::OUString::createFromAscii( "/" );
202*b1cdbd2cSJim Jagielski }
203*b1cdbd2cSJim Jagielski }
204*b1cdbd2cSJim Jagielski }
205*b1cdbd2cSJim Jagielski
206