xref: /aoo41x/main/ucb/source/ucp/tdoc/tdoc_uri.cxx (revision 2f86921c)
1*2f86921cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*2f86921cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*2f86921cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*2f86921cSAndrew Rist  * distributed with this work for additional information
6*2f86921cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*2f86921cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*2f86921cSAndrew Rist  * "License"); you may not use this file except in compliance
9*2f86921cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*2f86921cSAndrew Rist  *
11*2f86921cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*2f86921cSAndrew Rist  *
13*2f86921cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*2f86921cSAndrew Rist  * software distributed under the License is distributed on an
15*2f86921cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2f86921cSAndrew Rist  * KIND, either express or implied.  See the License for the
17*2f86921cSAndrew Rist  * specific language governing permissions and limitations
18*2f86921cSAndrew Rist  * under the License.
19*2f86921cSAndrew Rist  *
20*2f86921cSAndrew Rist  *************************************************************/
21*2f86921cSAndrew Rist 
22*2f86921cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_ucb.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir /**************************************************************************
28cdf0e10cSrcweir                                 TODO
29cdf0e10cSrcweir  **************************************************************************
30cdf0e10cSrcweir 
31cdf0e10cSrcweir  *************************************************************************/
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include "rtl/ustrbuf.hxx"
34cdf0e10cSrcweir #include "../inc/urihelper.hxx"
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include "tdoc_uri.hxx"
37cdf0e10cSrcweir 
38cdf0e10cSrcweir using namespace tdoc_ucp;
39cdf0e10cSrcweir 
40cdf0e10cSrcweir //=========================================================================
41cdf0e10cSrcweir //=========================================================================
42cdf0e10cSrcweir //
43cdf0e10cSrcweir // Uri Implementation.
44cdf0e10cSrcweir //
45cdf0e10cSrcweir //=========================================================================
46cdf0e10cSrcweir //=========================================================================
47cdf0e10cSrcweir 
init() const48cdf0e10cSrcweir void Uri::init() const
49cdf0e10cSrcweir {
50cdf0e10cSrcweir     // Already inited?
51cdf0e10cSrcweir     if ( m_eState == UNKNOWN )
52cdf0e10cSrcweir     {
53cdf0e10cSrcweir         m_eState = INVALID;
54cdf0e10cSrcweir 
55cdf0e10cSrcweir         // Check for proper length: must be at least length of <sheme>:/
56cdf0e10cSrcweir         if ( ( m_aUri.getLength() < TDOC_URL_SCHEME_LENGTH + 2 ) )
57cdf0e10cSrcweir         {
58cdf0e10cSrcweir             // Invaild length (to short).
59cdf0e10cSrcweir             return;
60cdf0e10cSrcweir         }
61cdf0e10cSrcweir 
62cdf0e10cSrcweir         // Check for proper scheme. (Scheme is case insensitive.)
63cdf0e10cSrcweir         rtl::OUString aScheme
64cdf0e10cSrcweir             = m_aUri.copy( 0, TDOC_URL_SCHEME_LENGTH ).toAsciiLowerCase();
65cdf0e10cSrcweir         if ( !aScheme.equalsAsciiL(
66cdf0e10cSrcweir                 RTL_CONSTASCII_STRINGPARAM( TDOC_URL_SCHEME ) ) )
67cdf0e10cSrcweir         {
68cdf0e10cSrcweir             // Invaild scheme.
69cdf0e10cSrcweir             return;
70cdf0e10cSrcweir         }
71cdf0e10cSrcweir 
72cdf0e10cSrcweir         // Remember normalized scheme string.
73cdf0e10cSrcweir         m_aUri = m_aUri.replaceAt( 0, aScheme.getLength(), aScheme );
74cdf0e10cSrcweir 
75cdf0e10cSrcweir         if ( m_aUri.getStr()[ TDOC_URL_SCHEME_LENGTH ]
76cdf0e10cSrcweir                 != sal_Unicode( ':' ) )
77cdf0e10cSrcweir         {
78cdf0e10cSrcweir             // Invaild (no ':' after <scheme>).
79cdf0e10cSrcweir             return;
80cdf0e10cSrcweir         }
81cdf0e10cSrcweir 
82cdf0e10cSrcweir         if ( m_aUri.getStr()[ TDOC_URL_SCHEME_LENGTH + 1 ]
83cdf0e10cSrcweir                 != sal_Unicode( '/' ) )
84cdf0e10cSrcweir         {
85cdf0e10cSrcweir             // Invaild (no '/' after <scheme>:).
86cdf0e10cSrcweir             return;
87cdf0e10cSrcweir         }
88cdf0e10cSrcweir 
89cdf0e10cSrcweir         m_aPath = m_aUri.copy( TDOC_URL_SCHEME_LENGTH + 1 );
90cdf0e10cSrcweir 
91cdf0e10cSrcweir         // Note: There must be at least one slash; see above.
92cdf0e10cSrcweir         sal_Int32 nLastSlash = m_aUri.lastIndexOf( '/' );
93cdf0e10cSrcweir         bool bTrailingSlash = false;
94cdf0e10cSrcweir         if ( nLastSlash == m_aUri.getLength() - 1 )
95cdf0e10cSrcweir         {
96cdf0e10cSrcweir             // ignore trailing slash
97cdf0e10cSrcweir             bTrailingSlash = true;
98cdf0e10cSrcweir             nLastSlash = m_aUri.lastIndexOf( '/', nLastSlash );
99cdf0e10cSrcweir         }
100cdf0e10cSrcweir 
101cdf0e10cSrcweir         if ( nLastSlash != -1 ) // -1 is valid for the root folder
102cdf0e10cSrcweir         {
103cdf0e10cSrcweir             m_aParentUri = m_aUri.copy( 0, nLastSlash + 1 );
104cdf0e10cSrcweir 
105cdf0e10cSrcweir             if ( bTrailingSlash )
106cdf0e10cSrcweir                 m_aName = m_aUri.copy( nLastSlash + 1,
107cdf0e10cSrcweir                                        m_aUri.getLength() - nLastSlash - 2 );
108cdf0e10cSrcweir             else
109cdf0e10cSrcweir                 m_aName = m_aUri.copy( nLastSlash + 1 );
110cdf0e10cSrcweir 
111cdf0e10cSrcweir             m_aDecodedName = ::ucb_impl::urihelper::decodeSegment( m_aName );
112cdf0e10cSrcweir 
113cdf0e10cSrcweir             sal_Int32 nSlash = m_aPath.indexOf( '/', 1 );
114cdf0e10cSrcweir             if ( nSlash == -1 )
115cdf0e10cSrcweir                 m_aDocId = m_aPath.copy( 1 );
116cdf0e10cSrcweir             else
117cdf0e10cSrcweir                 m_aDocId = m_aPath.copy( 1, nSlash - 1 );
118cdf0e10cSrcweir         }
119cdf0e10cSrcweir 
120cdf0e10cSrcweir         if ( m_aDocId.getLength() > 0 )
121cdf0e10cSrcweir         {
122cdf0e10cSrcweir             sal_Int32 nSlash = m_aPath.indexOf( '/', 1 );
123cdf0e10cSrcweir             if ( nSlash != - 1 )
124cdf0e10cSrcweir                 m_aInternalPath = m_aPath.copy( nSlash );
125cdf0e10cSrcweir             else
126cdf0e10cSrcweir                 m_aInternalPath = rtl::OUString::createFromAscii( "/" );
127cdf0e10cSrcweir         }
128cdf0e10cSrcweir 
129cdf0e10cSrcweir         m_eState = VALID;
130cdf0e10cSrcweir     }
131cdf0e10cSrcweir }
132