LCOV - code coverage report
Current view: top level - ucb/source/ucp/hierarchy - hierarchyuri.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 39 49 79.6 %
Date: 2012-08-25 Functions: 1 1 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 32 46 69.6 %

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

Generated by: LCOV version 1.10