Bump for 3.6-28
[LibreOffice.git] / ucb / source / ucp / tdoc / tdoc_uri.cxx
blob6526a10dc2e6cbab05e8782567b78f3387dec94a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 /**************************************************************************
31 TODO
32 **************************************************************************
34 *************************************************************************/
36 #include "rtl/ustrbuf.hxx"
37 #include "../inc/urihelper.hxx"
39 #include "tdoc_uri.hxx"
41 using namespace tdoc_ucp;
43 //=========================================================================
44 //=========================================================================
46 // Uri Implementation.
48 //=========================================================================
49 //=========================================================================
51 void Uri::init() const
53 // Already inited?
54 if ( m_eState == UNKNOWN )
56 m_eState = INVALID;
58 // Check for proper length: must be at least length of <sheme>:/
59 if ( ( m_aUri.getLength() < TDOC_URL_SCHEME_LENGTH + 2 ) )
61 // Invaild length (to short).
62 return;
65 // Check for proper scheme. (Scheme is case insensitive.)
66 rtl::OUString aScheme
67 = m_aUri.copy( 0, TDOC_URL_SCHEME_LENGTH ).toAsciiLowerCase();
68 if ( aScheme != TDOC_URL_SCHEME )
70 // Invaild scheme.
71 return;
74 // Remember normalized scheme string.
75 m_aUri = m_aUri.replaceAt( 0, aScheme.getLength(), aScheme );
77 if ( m_aUri.getStr()[ TDOC_URL_SCHEME_LENGTH ]
78 != sal_Unicode( ':' ) )
80 // Invaild (no ':' after <scheme>).
81 return;
84 if ( m_aUri.getStr()[ TDOC_URL_SCHEME_LENGTH + 1 ]
85 != sal_Unicode( '/' ) )
87 // Invaild (no '/' after <scheme>:).
88 return;
91 m_aPath = m_aUri.copy( TDOC_URL_SCHEME_LENGTH + 1 );
93 // Note: There must be at least one slash; see above.
94 sal_Int32 nLastSlash = m_aUri.lastIndexOf( '/' );
95 bool bTrailingSlash = false;
96 if ( nLastSlash == m_aUri.getLength() - 1 )
98 // ignore trailing slash
99 bTrailingSlash = true;
100 nLastSlash = m_aUri.lastIndexOf( '/', nLastSlash );
103 if ( nLastSlash != -1 ) // -1 is valid for the root folder
105 m_aParentUri = m_aUri.copy( 0, nLastSlash + 1 );
107 if ( bTrailingSlash )
108 m_aName = m_aUri.copy( nLastSlash + 1,
109 m_aUri.getLength() - nLastSlash - 2 );
110 else
111 m_aName = m_aUri.copy( nLastSlash + 1 );
113 m_aDecodedName = ::ucb_impl::urihelper::decodeSegment( m_aName );
115 sal_Int32 nSlash = m_aPath.indexOf( '/', 1 );
116 if ( nSlash == -1 )
117 m_aDocId = m_aPath.copy( 1 );
118 else
119 m_aDocId = m_aPath.copy( 1, nSlash - 1 );
122 if ( !m_aDocId.isEmpty() )
124 sal_Int32 nSlash = m_aPath.indexOf( '/', 1 );
125 if ( nSlash != - 1 )
126 m_aInternalPath = m_aPath.copy( nSlash );
127 else
128 m_aInternalPath = rtl::OUString("/");
131 m_eState = VALID;
135 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */