merge the formfield patch from ooo-build
[ooovba.git] / ucb / source / ucp / tdoc / tdoc_uri.cxx
blob2eef39f6e0acbaee6cd740f67e2bdb0b91f2e286
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tdoc_uri.cxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_ucb.hxx"
34 /**************************************************************************
35 TODO
36 **************************************************************************
38 *************************************************************************/
40 #include "rtl/ustrbuf.hxx"
41 #include "../inc/urihelper.hxx"
43 #include "tdoc_uri.hxx"
45 using namespace tdoc_ucp;
47 //=========================================================================
48 //=========================================================================
50 // Uri Implementation.
52 //=========================================================================
53 //=========================================================================
55 void Uri::init() const
57 // Already inited?
58 if ( m_eState == UNKNOWN )
60 m_eState = INVALID;
62 // Check for proper length: must be at least length of <sheme>:/
63 if ( ( m_aUri.getLength() < TDOC_URL_SCHEME_LENGTH + 2 ) )
65 // Invaild length (to short).
66 return;
69 // Check for proper scheme. (Scheme is case insensitive.)
70 rtl::OUString aScheme
71 = m_aUri.copy( 0, TDOC_URL_SCHEME_LENGTH ).toAsciiLowerCase();
72 if ( !aScheme.equalsAsciiL(
73 RTL_CONSTASCII_STRINGPARAM( TDOC_URL_SCHEME ) ) )
75 // Invaild scheme.
76 return;
79 // Remember normalized scheme string.
80 m_aUri = m_aUri.replaceAt( 0, aScheme.getLength(), aScheme );
82 if ( m_aUri.getStr()[ TDOC_URL_SCHEME_LENGTH ]
83 != sal_Unicode( ':' ) )
85 // Invaild (no ':' after <scheme>).
86 return;
89 if ( m_aUri.getStr()[ TDOC_URL_SCHEME_LENGTH + 1 ]
90 != sal_Unicode( '/' ) )
92 // Invaild (no '/' after <scheme>:).
93 return;
96 m_aPath = m_aUri.copy( TDOC_URL_SCHEME_LENGTH + 1 );
98 // Note: There must be at least one slash; see above.
99 sal_Int32 nLastSlash = m_aUri.lastIndexOf( '/' );
100 bool bTrailingSlash = false;
101 if ( nLastSlash == m_aUri.getLength() - 1 )
103 // ignore trailing slash
104 bTrailingSlash = true;
105 nLastSlash = m_aUri.lastIndexOf( '/', nLastSlash );
108 if ( nLastSlash != -1 ) // -1 is valid for the root folder
110 m_aParentUri = m_aUri.copy( 0, nLastSlash + 1 );
112 if ( bTrailingSlash )
113 m_aName = m_aUri.copy( nLastSlash + 1,
114 m_aUri.getLength() - nLastSlash - 2 );
115 else
116 m_aName = m_aUri.copy( nLastSlash + 1 );
118 m_aDecodedName = ::ucb_impl::urihelper::decodeSegment( m_aName );
120 sal_Int32 nSlash = m_aPath.indexOf( '/', 1 );
121 if ( nSlash == -1 )
122 m_aDocId = m_aPath.copy( 1 );
123 else
124 m_aDocId = m_aPath.copy( 1, nSlash - 1 );
127 if ( m_aDocId.getLength() > 0 )
129 sal_Int32 nSlash = m_aPath.indexOf( '/', 1 );
130 if ( nSlash != - 1 )
131 m_aInternalPath = m_aPath.copy( nSlash );
132 else
133 m_aInternalPath = rtl::OUString::createFromAscii( "/" );
136 m_eState = VALID;