2010-10-12 15:53:47 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-10-04 11:25:41 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2001-07-03 10:15:56 +00:00
|
|
|
|
2006-09-17 12:57:02 +00:00
|
|
|
|
2001-07-03 10:15:56 +00:00
|
|
|
/**************************************************************************
|
|
|
|
TODO
|
|
|
|
**************************************************************************
|
|
|
|
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#include "hierarchyuri.hxx"
|
|
|
|
|
|
|
|
using namespace hierarchy_ucp;
|
|
|
|
|
2014-02-25 22:38:20 +01:00
|
|
|
|
2001-07-03 10:15:56 +00:00
|
|
|
#define DEFAULT_DATA_SOURCE_SERVICE \
|
|
|
|
"com.sun.star.ucb.DefaultHierarchyDataSource"
|
|
|
|
|
2014-02-25 22:38:20 +01:00
|
|
|
|
2001-07-03 10:15:56 +00:00
|
|
|
// HierarchyUri Implementation.
|
2014-02-25 22:38:20 +01:00
|
|
|
|
|
|
|
|
2001-07-03 10:15:56 +00:00
|
|
|
void HierarchyUri::init() const
|
|
|
|
{
|
|
|
|
// Already inited?
|
2012-01-18 23:47:02 -02:00
|
|
|
if ( !m_aUri.isEmpty() && m_aPath.isEmpty() )
|
2001-07-03 10:15:56 +00:00
|
|
|
{
|
|
|
|
// Note: Maybe it's a re-init, setUri only resets m_aPath!
|
2014-12-18 13:37:12 +01:00
|
|
|
m_aService.clear();
|
|
|
|
m_aParentUri.clear();
|
2001-07-03 10:15:56 +00:00
|
|
|
|
2019-08-11 18:19:03 +02:00
|
|
|
// URI must match at least: <scheme>:
|
2017-07-05 15:29:30 +02:00
|
|
|
if ( m_aUri.getLength() < HIERARCHY_URL_SCHEME_LENGTH + 1 )
|
2001-07-03 10:15:56 +00:00
|
|
|
{
|
2019-08-11 18:19:03 +02:00
|
|
|
// error, but remember that we did an init().
|
2013-10-31 15:40:40 +02:00
|
|
|
m_aPath = "/";
|
2001-07-06 06:56:28 +00:00
|
|
|
return;
|
2001-07-04 06:20:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Scheme is case insensitive.
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString aScheme
|
2001-07-04 06:20:58 +00:00
|
|
|
= m_aUri.copy( 0, HIERARCHY_URL_SCHEME_LENGTH ).toAsciiLowerCase();
|
2012-04-06 19:49:53 +02:00
|
|
|
if ( aScheme == HIERARCHY_URL_SCHEME )
|
2001-07-04 06:20:58 +00:00
|
|
|
{
|
|
|
|
m_aUri = m_aUri.replaceAt( 0, aScheme.getLength(), aScheme );
|
|
|
|
|
2001-07-03 10:15:56 +00:00
|
|
|
sal_Int32 nPos = 0;
|
|
|
|
|
|
|
|
// If the URI has no service specifier, insert default service.
|
|
|
|
// This is for backward compatibility and for convenience.
|
2001-07-03 14:23:22 +00:00
|
|
|
|
|
|
|
if ( m_aUri.getLength() == HIERARCHY_URL_SCHEME_LENGTH + 1 )
|
|
|
|
{
|
|
|
|
// root folder URI without path and service specifier.
|
2013-10-25 17:17:50 +02:00
|
|
|
m_aUri += "//" DEFAULT_DATA_SOURCE_SERVICE "/";
|
2013-10-31 15:40:40 +02:00
|
|
|
m_aService = DEFAULT_DATA_SOURCE_SERVICE ;
|
2001-07-03 14:23:22 +00:00
|
|
|
|
|
|
|
nPos = m_aUri.getLength() - 1;
|
|
|
|
}
|
|
|
|
else if ( ( m_aUri.getLength() == HIERARCHY_URL_SCHEME_LENGTH + 2 )
|
|
|
|
&&
|
2013-10-23 13:29:32 +02:00
|
|
|
( m_aUri[ HIERARCHY_URL_SCHEME_LENGTH + 1 ] == '/' ) )
|
2001-07-03 10:15:56 +00:00
|
|
|
{
|
|
|
|
// root folder URI without service specifier.
|
2013-10-25 17:17:50 +02:00
|
|
|
m_aUri += "/" DEFAULT_DATA_SOURCE_SERVICE "/";
|
2013-10-31 15:40:40 +02:00
|
|
|
m_aService = DEFAULT_DATA_SOURCE_SERVICE;
|
2001-07-03 10:15:56 +00:00
|
|
|
|
|
|
|
nPos = m_aUri.getLength() - 1;
|
|
|
|
}
|
2001-07-03 14:23:22 +00:00
|
|
|
else if ( ( m_aUri.getLength() > HIERARCHY_URL_SCHEME_LENGTH + 2 )
|
|
|
|
&&
|
2013-10-23 13:29:32 +02:00
|
|
|
( m_aUri[ HIERARCHY_URL_SCHEME_LENGTH + 2 ] != '/' ) )
|
2001-07-03 10:15:56 +00:00
|
|
|
{
|
|
|
|
// other (no root folder) URI without service specifier.
|
|
|
|
m_aUri = m_aUri.replaceAt(
|
|
|
|
HIERARCHY_URL_SCHEME_LENGTH + 2,
|
|
|
|
0,
|
2015-11-06 09:38:13 +01:00
|
|
|
"/" DEFAULT_DATA_SOURCE_SERVICE "/" );
|
2013-10-31 15:40:40 +02:00
|
|
|
m_aService = DEFAULT_DATA_SOURCE_SERVICE;
|
2001-07-03 10:15:56 +00:00
|
|
|
|
2007-05-10 12:04:58 +00:00
|
|
|
nPos
|
|
|
|
= HIERARCHY_URL_SCHEME_LENGTH + 3 + m_aService.getLength();
|
2001-07-03 10:15:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// URI with service specifier.
|
|
|
|
sal_Int32 nStart = HIERARCHY_URL_SCHEME_LENGTH + 3;
|
2001-07-03 14:23:22 +00:00
|
|
|
|
|
|
|
// Here: - m_aUri has at least the form "<scheme>://"
|
2014-02-25 22:38:20 +01:00
|
|
|
// - nStart points to char after <scheme>:
|
2001-07-03 14:23:22 +00:00
|
|
|
|
|
|
|
// Only <scheme>:// ?
|
|
|
|
if ( nStart == m_aUri.getLength() )
|
|
|
|
{
|
2019-08-11 18:19:03 +02:00
|
|
|
// error, but remember that we did an init().
|
2013-10-31 15:40:40 +02:00
|
|
|
m_aPath = "/";
|
2001-07-03 14:23:22 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Empty path segments?
|
2015-06-25 12:37:25 +02:00
|
|
|
if ( m_aUri.indexOf("//", nStart) != -1 )
|
2001-07-03 14:23:22 +00:00
|
|
|
{
|
2019-08-11 18:19:03 +02:00
|
|
|
// error, but remember that we did an init().
|
2013-10-31 15:40:40 +02:00
|
|
|
m_aPath = "/";
|
2001-07-03 14:23:22 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_Int32 nEnd = m_aUri.indexOf( '/', nStart );
|
|
|
|
|
|
|
|
// Only <scheme>:/// ?
|
|
|
|
if ( nEnd == nStart )
|
|
|
|
{
|
2019-08-11 18:19:03 +02:00
|
|
|
// error, but remember that we did an init().
|
2013-10-31 15:40:40 +02:00
|
|
|
m_aPath = "/";
|
2001-07-03 14:23:22 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-07-03 10:15:56 +00:00
|
|
|
|
|
|
|
if ( nEnd == -1 )
|
|
|
|
{
|
|
|
|
// Trailing slash missing.
|
|
|
|
nEnd = m_aUri.getLength();
|
2013-10-25 17:17:50 +02:00
|
|
|
m_aUri += "/";
|
2001-07-03 10:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_aService = m_aUri.copy( nStart, nEnd - nStart );
|
|
|
|
|
|
|
|
nPos = nEnd;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Here: - m_aUri has at least the form "<scheme>://<service>/"
|
|
|
|
// - m_aService was set
|
2001-07-03 14:23:22 +00:00
|
|
|
// - m_aPath, m_aParentPath, m_aName not yet set
|
|
|
|
// - nPos points to slash after service specifier
|
2001-07-03 10:15:56 +00:00
|
|
|
|
|
|
|
// Remove trailing slash, if not a root folder URI.
|
|
|
|
sal_Int32 nEnd = m_aUri.lastIndexOf( '/' );
|
|
|
|
if ( ( nEnd > nPos ) && ( nEnd == ( m_aUri.getLength() - 1 ) ) )
|
|
|
|
m_aUri = m_aUri.copy( 0, nEnd );
|
|
|
|
|
|
|
|
// Path (includes leading slash)
|
|
|
|
m_aPath = m_aUri.copy( nPos );
|
|
|
|
|
|
|
|
// parent URI + name
|
|
|
|
sal_Int32 nLastSlash = m_aUri.lastIndexOf( '/' );
|
|
|
|
if ( ( nLastSlash != -1 ) &&
|
|
|
|
( nLastSlash != m_aUri.getLength() - 1 ) ) // root
|
|
|
|
{
|
|
|
|
m_aParentUri = m_aUri.copy( 0, nLastSlash );
|
|
|
|
}
|
|
|
|
|
|
|
|
// success
|
|
|
|
m_bValid = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-08-11 18:19:03 +02:00
|
|
|
// error, but remember that we did an init().
|
2013-10-31 15:40:40 +02:00
|
|
|
m_aPath = "/";
|
2001-07-03 10:15:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-12 15:53:47 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|