1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_ucb.hxx" 30 31 /************************************************************************** 32 TODO 33 ************************************************************************** 34 35 *************************************************************************/ 36 37 #include "rtl/ustrbuf.hxx" 38 #include "../inc/urihelper.hxx" 39 40 #include "tdoc_uri.hxx" 41 42 using namespace tdoc_ucp; 43 44 //========================================================================= 45 //========================================================================= 46 // 47 // Uri Implementation. 48 // 49 //========================================================================= 50 //========================================================================= 51 52 void Uri::init() const 53 { 54 // Already inited? 55 if ( m_eState == UNKNOWN ) 56 { 57 m_eState = INVALID; 58 59 // Check for proper length: must be at least length of <sheme>:/ 60 if ( ( m_aUri.getLength() < TDOC_URL_SCHEME_LENGTH + 2 ) ) 61 { 62 // Invaild length (to short). 63 return; 64 } 65 66 // Check for proper scheme. (Scheme is case insensitive.) 67 rtl::OUString aScheme 68 = m_aUri.copy( 0, TDOC_URL_SCHEME_LENGTH ).toAsciiLowerCase(); 69 if ( !aScheme.equalsAsciiL( 70 RTL_CONSTASCII_STRINGPARAM( TDOC_URL_SCHEME ) ) ) 71 { 72 // Invaild scheme. 73 return; 74 } 75 76 // Remember normalized scheme string. 77 m_aUri = m_aUri.replaceAt( 0, aScheme.getLength(), aScheme ); 78 79 if ( m_aUri.getStr()[ TDOC_URL_SCHEME_LENGTH ] 80 != sal_Unicode( ':' ) ) 81 { 82 // Invaild (no ':' after <scheme>). 83 return; 84 } 85 86 if ( m_aUri.getStr()[ TDOC_URL_SCHEME_LENGTH + 1 ] 87 != sal_Unicode( '/' ) ) 88 { 89 // Invaild (no '/' after <scheme>:). 90 return; 91 } 92 93 m_aPath = m_aUri.copy( TDOC_URL_SCHEME_LENGTH + 1 ); 94 95 // Note: There must be at least one slash; see above. 96 sal_Int32 nLastSlash = m_aUri.lastIndexOf( '/' ); 97 bool bTrailingSlash = false; 98 if ( nLastSlash == m_aUri.getLength() - 1 ) 99 { 100 // ignore trailing slash 101 bTrailingSlash = true; 102 nLastSlash = m_aUri.lastIndexOf( '/', nLastSlash ); 103 } 104 105 if ( nLastSlash != -1 ) // -1 is valid for the root folder 106 { 107 m_aParentUri = m_aUri.copy( 0, nLastSlash + 1 ); 108 109 if ( bTrailingSlash ) 110 m_aName = m_aUri.copy( nLastSlash + 1, 111 m_aUri.getLength() - nLastSlash - 2 ); 112 else 113 m_aName = m_aUri.copy( nLastSlash + 1 ); 114 115 m_aDecodedName = ::ucb_impl::urihelper::decodeSegment( m_aName ); 116 117 sal_Int32 nSlash = m_aPath.indexOf( '/', 1 ); 118 if ( nSlash == -1 ) 119 m_aDocId = m_aPath.copy( 1 ); 120 else 121 m_aDocId = m_aPath.copy( 1, nSlash - 1 ); 122 } 123 124 if ( m_aDocId.getLength() > 0 ) 125 { 126 sal_Int32 nSlash = m_aPath.indexOf( '/', 1 ); 127 if ( nSlash != - 1 ) 128 m_aInternalPath = m_aPath.copy( nSlash ); 129 else 130 m_aInternalPath = rtl::OUString::createFromAscii( "/" ); 131 } 132 133 m_eState = VALID; 134 } 135 } 136