LCOV - code coverage report
Current view: top level - ucb/source/ucp/hierarchy - hierarchyuri.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 56 0.0 %
Date: 2014-04-14 Functions: 0 1 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : 
      21             : /**************************************************************************
      22             :                                 TODO
      23             :  **************************************************************************
      24             : 
      25             :  *************************************************************************/
      26             : 
      27             : #include "rtl/ustrbuf.hxx"
      28             : #include "osl/diagnose.h"
      29             : 
      30             : #include "hierarchyuri.hxx"
      31             : 
      32             : using namespace hierarchy_ucp;
      33             : 
      34             : 
      35             : 
      36             : #define DEFAULT_DATA_SOURCE_SERVICE \
      37             :                     "com.sun.star.ucb.DefaultHierarchyDataSource"
      38             : 
      39             : 
      40             : 
      41             : 
      42             : // HierarchyUri Implementation.
      43             : 
      44             : 
      45             : 
      46             : 
      47           0 : void HierarchyUri::init() const
      48             : {
      49             :     // Already inited?
      50           0 :     if ( !m_aUri.isEmpty() && m_aPath.isEmpty() )
      51             :     {
      52             :         // Note: Maybe it's a re-init, setUri only resets m_aPath!
      53           0 :         m_aService = m_aParentUri = m_aName = "";
      54             : 
      55             :         // URI must match at least: <sheme>:
      56           0 :         if ( ( m_aUri.getLength() < HIERARCHY_URL_SCHEME_LENGTH + 1 ) )
      57             :         {
      58             :             // error, but remember that we did a init().
      59           0 :             m_aPath = "/";
      60           0 :             return;
      61             :         }
      62             : 
      63             :         // Scheme is case insensitive.
      64             :         OUString aScheme
      65           0 :             = m_aUri.copy( 0, HIERARCHY_URL_SCHEME_LENGTH ).toAsciiLowerCase();
      66           0 :         if ( aScheme == HIERARCHY_URL_SCHEME )
      67             :         {
      68           0 :             m_aUri = m_aUri.replaceAt( 0, aScheme.getLength(), aScheme );
      69             : 
      70           0 :             sal_Int32 nPos = 0;
      71             : 
      72             :             // If the URI has no service specifier, insert default service.
      73             :             // This is for backward compatibility and for convenience.
      74             : 
      75           0 :             if ( m_aUri.getLength() == HIERARCHY_URL_SCHEME_LENGTH + 1 )
      76             :             {
      77             :                 // root folder URI without path and service specifier.
      78           0 :                 m_aUri += "//" DEFAULT_DATA_SOURCE_SERVICE "/";
      79           0 :                 m_aService = DEFAULT_DATA_SOURCE_SERVICE ;
      80             : 
      81           0 :                 nPos = m_aUri.getLength() - 1;
      82             :             }
      83           0 :             else if ( ( m_aUri.getLength() == HIERARCHY_URL_SCHEME_LENGTH + 2 )
      84           0 :                       &&
      85           0 :                       ( m_aUri[ HIERARCHY_URL_SCHEME_LENGTH + 1 ] == '/' ) )
      86             :             {
      87             :                 // root folder URI without service specifier.
      88           0 :                 m_aUri += "/" DEFAULT_DATA_SOURCE_SERVICE "/";
      89           0 :                 m_aService = DEFAULT_DATA_SOURCE_SERVICE;
      90             : 
      91           0 :                 nPos = m_aUri.getLength() - 1;
      92             :             }
      93           0 :             else if ( ( m_aUri.getLength() > HIERARCHY_URL_SCHEME_LENGTH + 2 )
      94           0 :                       &&
      95           0 :                       ( m_aUri[ HIERARCHY_URL_SCHEME_LENGTH + 2 ] != '/' ) )
      96             :             {
      97             :                 // other (no root folder) URI without service specifier.
      98           0 :                 m_aUri = m_aUri.replaceAt(
      99             :                             HIERARCHY_URL_SCHEME_LENGTH + 2,
     100             :                             0,
     101           0 :                             OUString( "/" DEFAULT_DATA_SOURCE_SERVICE "/"  ) );
     102           0 :                 m_aService = DEFAULT_DATA_SOURCE_SERVICE;
     103             : 
     104             :                 nPos
     105           0 :                     = HIERARCHY_URL_SCHEME_LENGTH + 3 + m_aService.getLength();
     106             :             }
     107             :             else
     108             :             {
     109             :                 // URI with service specifier.
     110           0 :                 sal_Int32 nStart = HIERARCHY_URL_SCHEME_LENGTH + 3;
     111             : 
     112             :                 // Here: - m_aUri has at least the form "<scheme>://"
     113             :                 //       - nStart points to char after <scheme>:
     114             : 
     115             :                 // Only <scheme>:// ?
     116           0 :                 if ( nStart == m_aUri.getLength() )
     117             :                 {
     118             :                     // error, but remember that we did a init().
     119           0 :                     m_aPath = "/";
     120           0 :                     return;
     121             :                 }
     122             : 
     123             :                 // Empty path segments?
     124           0 :                 if ( m_aUri.indexOf(
     125             :                         OUString("//"),
     126           0 :                         nStart ) != -1 )
     127             :                 {
     128             :                     // error, but remember that we did a init().
     129           0 :                     m_aPath = "/";
     130           0 :                     return;
     131             :                 }
     132             : 
     133           0 :                 sal_Int32 nEnd = m_aUri.indexOf( '/', nStart );
     134             : 
     135             :                 // Only <scheme>:/// ?
     136           0 :                 if ( nEnd == nStart )
     137             :                 {
     138             :                     // error, but remember that we did a init().
     139           0 :                     m_aPath = "/";
     140           0 :                     return;
     141             :                 }
     142             : 
     143           0 :                 if ( nEnd == -1 )
     144             :                 {
     145             :                     // Trailing slash missing.
     146           0 :                     nEnd = m_aUri.getLength();
     147           0 :                     m_aUri += "/";
     148             :                 }
     149             : 
     150           0 :                 m_aService = m_aUri.copy( nStart, nEnd - nStart );
     151             : 
     152           0 :                 nPos = nEnd;
     153             :             }
     154             : 
     155             :             // Here: - m_aUri has at least the form "<scheme>://<service>/"
     156             :             //       - m_aService was set
     157             :             //       - m_aPath, m_aParentPath, m_aName not yet set
     158             :             //       - nPos points to slash after service specifier
     159             : 
     160             :             // Remove trailing slash, if not a root folder URI.
     161           0 :             sal_Int32 nEnd = m_aUri.lastIndexOf( '/' );
     162           0 :             if ( ( nEnd > nPos ) && ( nEnd == ( m_aUri.getLength() - 1 ) ) )
     163           0 :                 m_aUri = m_aUri.copy( 0, nEnd );
     164             : 
     165             :             // Path (includes leading slash)
     166           0 :             m_aPath = m_aUri.copy( nPos );
     167             : 
     168             :             // parent URI + name
     169           0 :             sal_Int32 nLastSlash = m_aUri.lastIndexOf( '/' );
     170           0 :             if ( ( nLastSlash != -1 ) &&
     171           0 :                  ( nLastSlash != m_aUri.getLength() - 1 ) ) // root
     172             :             {
     173           0 :                 m_aParentUri = m_aUri.copy( 0, nLastSlash );
     174           0 :                 m_aName      = m_aUri.copy( nLastSlash + 1 );
     175             :             }
     176             : 
     177             :             // success
     178           0 :             m_bValid = true;
     179             :         }
     180             :         else
     181             :         {
     182             :             // error, but remember that we did a init().
     183           0 :             m_aPath = "/";
     184           0 :         }
     185             :     }
     186             : }
     187             : 
     188             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10