summaryrefslogtreecommitdiff
path: root/ucb/source
diff options
context:
space:
mode:
authorKai Sommerfeld <kso@openoffice.org>2001-07-06 07:11:17 +0000
committerKai Sommerfeld <kso@openoffice.org>2001-07-06 07:11:17 +0000
commit3ef99d8f32e0863047a61f7e7a12b73951f8db86 (patch)
tree7f0c19d7bd70c3225e00776bddb1c68f488fc291 /ucb/source
parentda98d91653c6017373f46bd8aa4f22728680a16d (diff)
#87186# - Improved PackageUri implementation and usage.
Diffstat (limited to 'ucb/source')
-rw-r--r--ucb/source/ucp/package/pkgprovider.cxx16
-rw-r--r--ucb/source/ucp/package/pkguri.cxx56
-rw-r--r--ucb/source/ucp/package/pkguri.hxx14
3 files changed, 63 insertions, 23 deletions
diff --git a/ucb/source/ucp/package/pkgprovider.cxx b/ucb/source/ucp/package/pkgprovider.cxx
index da6f0c100411..e6054fddef15 100644
--- a/ucb/source/ucp/package/pkgprovider.cxx
+++ b/ucb/source/ucp/package/pkgprovider.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: pkgprovider.cxx,v $
*
- * $Revision: 1.12 $
+ * $Revision: 1.13 $
*
- * last change: $Author: kso $ $Date: 2001-06-27 08:21:24 $
+ * last change: $Author: kso $ $Date: 2001-07-06 08:11:17 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -261,16 +261,12 @@ uno::Reference< star::ucb::XContent > SAL_CALL ContentProvider::queryContent(
if ( !Identifier.is() )
return uno::Reference< star::ucb::XContent >();
- // Check URL scheme...
-
- rtl::OUString aScheme(
- rtl::OUString::createFromAscii( PACKAGE_URL_SCHEME ) );
- if ( !Identifier->getContentProviderScheme().equalsIgnoreAsciiCase(
- aScheme ) )
+ PackageUri aUri( Identifier->getContentIdentifier() );
+ if ( !aUri.isValid() )
throw star::ucb::IllegalIdentifierException();
- // Normalize URL...
- PackageUri aUri( Identifier->getContentIdentifier() );
+ // Create a new identifier for the mormalized URL returned by
+ // PackageUri::getUri().
uno::Reference< star::ucb::XContentIdentifier > xId
= new ::ucb::ContentIdentifier( m_xSMgr, aUri.getUri() );
diff --git a/ucb/source/ucp/package/pkguri.cxx b/ucb/source/ucp/package/pkguri.cxx
index 777292a3345b..4a5b0bb5b4d4 100644
--- a/ucb/source/ucp/package/pkguri.cxx
+++ b/ucb/source/ucp/package/pkguri.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: pkguri.cxx,v $
*
- * $Revision: 1.7 $
+ * $Revision: 1.8 $
*
- * last change: $Author: kso $ $Date: 2001-06-25 09:11:47 $
+ * last change: $Author: kso $ $Date: 2001-07-06 08:11:17 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -115,14 +115,44 @@ void PackageUri::init() const
// Note: Maybe it's a re-init, setUri only resets m_aPath!
m_aPackage = m_aParentUri = m_aName = OUString();
- if ( m_aUri.getLength() &&
- ( m_aUri.compareToAscii( PACKAGE_URL_SCHEME,
- PACKAGE_URL_SCHEME_LENGTH ) == 0 ) )
+ // URI must match at least: <sheme>://<non_empty_url_to_file>
+ if ( ( m_aUri.getLength() < PACKAGE_URL_SCHEME_LENGTH + 4 ) )
{
+ // error, but remember that we did a init().
+ m_aPath = rtl::OUString::createFromAscii( "/" );
+ return;
+ }
+
+ // Scheme is case insensitive.
+ rtl::OUString aScheme
+ = m_aUri.copy( 0, PACKAGE_URL_SCHEME_LENGTH ).toAsciiLowerCase();
+ if ( aScheme.equalsAsciiL(
+ RTL_CONSTASCII_STRINGPARAM( PACKAGE_URL_SCHEME ) ) )
+ {
+ m_aUri = m_aUri.replaceAt( 0, aScheme.getLength(), aScheme );
+
sal_Int32 nStart = PACKAGE_URL_SCHEME_LENGTH + 3;
sal_Int32 nEnd = m_aUri.lastIndexOf( '/' );
- if ( nEnd == ( m_aUri.getLength() - 1 ) )
+ if ( nEnd == PACKAGE_URL_SCHEME_LENGTH + 3 )
+ {
+ // Only <scheme>:/// - Empty authority
+
+ // error, but remember that we did a init().
+ m_aPath = rtl::OUString::createFromAscii( "/" );
+ return;
+ }
+ else if ( nEnd == ( m_aUri.getLength() - 1 ) )
{
+ if ( m_aUri.getStr()[ m_aUri.getLength() - 2 ]
+ == sal_Unicode( '/' ) )
+ {
+ // Only <scheme>://// or <scheme>://<something>//
+
+ // error, but remember that we did a init().
+ m_aPath = rtl::OUString::createFromAscii( "/" );
+ return;
+ }
+
// Remove trailing slash.
m_aUri = m_aUri.copy( 0, nEnd );
}
@@ -142,14 +172,23 @@ void PackageUri::init() const
}
else
{
+ m_aPath = m_aUri.copy( nEnd + 1 );
+
+ // Empty path segments?
+ if ( m_aPath.indexOf(
+ rtl::OUString::createFromAscii( "//" ) ) != -1 )
+ {
+ // error, but remember that we did a init().
+ m_aPath = rtl::OUString::createFromAscii( "/" );
+ return;
+ }
+
OUString aNormPackage = m_aUri.copy( nStart, nEnd - nStart );
normalize( aNormPackage );
m_aUri = m_aUri.replaceAt(
nStart, nEnd - nStart, aNormPackage );
m_aPackage = decodeSegment( aNormPackage );
-// m_aPath = m_aUri.copy( nEnd );
- m_aPath = m_aUri.copy( nEnd + 1 );
sal_Int32 nLastSlash = m_aUri.lastIndexOf( '/' );
if ( nLastSlash != -1 )
@@ -160,6 +199,7 @@ void PackageUri::init() const
}
// success
+ m_bValid = true;
}
else
{
diff --git a/ucb/source/ucp/package/pkguri.hxx b/ucb/source/ucp/package/pkguri.hxx
index b9a7802ec748..dcd41bab0d58 100644
--- a/ucb/source/ucp/package/pkguri.hxx
+++ b/ucb/source/ucp/package/pkguri.hxx
@@ -2,9 +2,9 @@
*
* $RCSfile: pkguri.hxx,v $
*
- * $Revision: 1.3 $
+ * $Revision: 1.4 $
*
- * last change: $Author: kso $ $Date: 2001-06-25 09:11:47 $
+ * last change: $Author: kso $ $Date: 2001-07-06 08:11:17 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -82,21 +82,25 @@ class PackageUri
mutable ::rtl::OUString m_aPackage;
mutable ::rtl::OUString m_aPath;
mutable ::rtl::OUString m_aName;
+ mutable bool m_bValid;
private:
void init() const;
static ::rtl::OUString decodeSegment( const ::rtl::OUString& rSource );
public:
- PackageUri() {}
+ PackageUri() : m_bValid( false ) {}
PackageUri( const ::rtl::OUString & rPackageUri )
- : m_aUri( rPackageUri ) {}
+ : m_aUri( rPackageUri ), m_bValid( false ) {}
+
+ sal_Bool isValid() const
+ { init(); return m_bValid; }
const ::rtl::OUString & getUri() const
{ init(); return m_aUri; }
void setUri( const ::rtl::OUString & rPackageUri )
- { m_aPath = ::rtl::OUString(); m_aUri = rPackageUri; }
+ { m_aPath = ::rtl::OUString(); m_aUri = rPackageUri; m_bValid = false; }
const ::rtl::OUString & getParentUri() const
{ init(); return m_aParentUri; }