Version 4.0.2.1, tag libreoffice-4.0.2.1
[LibreOffice.git] / ucb / source / ucp / tdoc / tdoc_uri.cxx
blob8d5584df2d14583224d40f735558bb2dced75774
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 "rtl/ustrbuf.hxx"
28 #include "../inc/urihelper.hxx"
30 #include "tdoc_uri.hxx"
32 using namespace tdoc_ucp;
34 //=========================================================================
35 //=========================================================================
37 // Uri Implementation.
39 //=========================================================================
40 //=========================================================================
42 void Uri::init() const
44 // Already inited?
45 if ( m_eState == UNKNOWN )
47 m_eState = INVALID;
49 // Check for proper length: must be at least length of <sheme>:/
50 if ( ( m_aUri.getLength() < TDOC_URL_SCHEME_LENGTH + 2 ) )
52 // Invaild length (to short).
53 return;
56 // Check for proper scheme. (Scheme is case insensitive.)
57 rtl::OUString aScheme
58 = m_aUri.copy( 0, TDOC_URL_SCHEME_LENGTH ).toAsciiLowerCase();
59 if ( aScheme != TDOC_URL_SCHEME )
61 // Invaild scheme.
62 return;
65 // Remember normalized scheme string.
66 m_aUri = m_aUri.replaceAt( 0, aScheme.getLength(), aScheme );
68 if ( m_aUri.getStr()[ TDOC_URL_SCHEME_LENGTH ]
69 != sal_Unicode( ':' ) )
71 // Invaild (no ':' after <scheme>).
72 return;
75 if ( m_aUri.getStr()[ TDOC_URL_SCHEME_LENGTH + 1 ]
76 != sal_Unicode( '/' ) )
78 // Invaild (no '/' after <scheme>:).
79 return;
82 m_aPath = m_aUri.copy( TDOC_URL_SCHEME_LENGTH + 1 );
84 // Note: There must be at least one slash; see above.
85 sal_Int32 nLastSlash = m_aUri.lastIndexOf( '/' );
86 bool bTrailingSlash = false;
87 if ( nLastSlash == m_aUri.getLength() - 1 )
89 // ignore trailing slash
90 bTrailingSlash = true;
91 nLastSlash = m_aUri.lastIndexOf( '/', nLastSlash );
94 if ( nLastSlash != -1 ) // -1 is valid for the root folder
96 m_aParentUri = m_aUri.copy( 0, nLastSlash + 1 );
98 if ( bTrailingSlash )
99 m_aName = m_aUri.copy( nLastSlash + 1,
100 m_aUri.getLength() - nLastSlash - 2 );
101 else
102 m_aName = m_aUri.copy( nLastSlash + 1 );
104 m_aDecodedName = ::ucb_impl::urihelper::decodeSegment( m_aName );
106 sal_Int32 nSlash = m_aPath.indexOf( '/', 1 );
107 if ( nSlash == -1 )
108 m_aDocId = m_aPath.copy( 1 );
109 else
110 m_aDocId = m_aPath.copy( 1, nSlash - 1 );
113 if ( !m_aDocId.isEmpty() )
115 sal_Int32 nSlash = m_aPath.indexOf( '/', 1 );
116 if ( nSlash != - 1 )
117 m_aInternalPath = m_aPath.copy( nSlash );
118 else
119 m_aInternalPath = rtl::OUString("/");
122 m_eState = VALID;
126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */