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