From 8a60662a76cd93fd7485de524dc3d4daecd53f66 Mon Sep 17 00:00:00 2001 From: Kai Sommerfeld Date: Wed, 5 Jan 2011 15:06:59 +0100 Subject: #i116314# - Do not cache certain properties, like dav:lockdiscovery --- ucb/source/ucp/webdav/ContentProperties.cxx | 170 ++++++++++++++++++++++------ ucb/source/ucp/webdav/ContentProperties.hxx | 50 ++++++-- ucb/source/ucp/webdav/webdavcontent.cxx | 8 +- ucb/source/ucp/webdav/webdavcontent.hxx | 6 +- 4 files changed, 183 insertions(+), 51 deletions(-) (limited to 'ucb') diff --git a/ucb/source/ucp/webdav/ContentProperties.cxx b/ucb/source/ucp/webdav/ContentProperties.cxx index 4bb54dea94..95bc573eca 100644 --- a/ucb/source/ucp/webdav/ContentProperties.cxx +++ b/ucb/source/ucp/webdav/ContentProperties.cxx @@ -1,7 +1,7 @@ /************************************************************************* * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * + * * Copyright 2000, 2010 Oracle and/or its affiliates. * * OpenOffice.org - a multi-platform office productivity suite @@ -105,29 +105,29 @@ ContentProperties::ContentProperties( const DAVResource& rResource ) m_aEscapedTitle = aURI.GetPathBaseName(); (*m_xProps)[ rtl::OUString::createFromAscii( "Title" ) ] - = PropertyValue( + = PropertyValue( uno::makeAny( aURI.GetPathBaseNameUnescaped() ), true ); } catch ( DAVException const & ) { (*m_xProps)[ rtl::OUString::createFromAscii( "Title" ) ] - = PropertyValue( - uno::makeAny( - rtl::OUString( - RTL_CONSTASCII_USTRINGPARAM( "*** unknown ***" ) ) ), + = PropertyValue( + uno::makeAny( + rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM( "*** unknown ***" ) ) ), true ); } std::vector< DAVPropertyValue >::const_iterator it = rResource.properties.begin(); - std::vector< DAVPropertyValue >::const_iterator end + std::vector< DAVPropertyValue >::const_iterator end = rResource.properties.end(); - while ( it != end ) - { + while ( it != end ) + { addProperty( (*it) ); ++it; - } + } if ( rResource.uri.getStr()[ rResource.uri.getLength() - 1 ] == sal_Unicode( '/' ) ) @@ -157,6 +157,13 @@ ContentProperties::ContentProperties( const rtl::OUString & rTitle ) = PropertyValue( uno::makeAny( rTitle ), true ); } +//========================================================================= +ContentProperties::ContentProperties() +: m_xProps( new PropertyValueMap ), + m_bTrailingSlash( sal_False ) +{ +} + //========================================================================= ContentProperties::ContentProperties( const ContentProperties & rOther ) : m_aEscapedTitle( rOther.m_aEscapedTitle ), @@ -201,7 +208,7 @@ const PropertyValue * ContentProperties::get( { if ( (*it).first.equalsIgnoreAsciiCase( rName ) ) return &(*it).second; - + ++it; } return 0; @@ -254,7 +261,7 @@ void ContentProperties::UCBNamesToDAVNames( { if ( !bCreationDate ) { - propertyNames.push_back( DAVProperties::CREATIONDATE ); + propertyNames.push_back( DAVProperties::CREATIONDATE ); bCreationDate = sal_True; } } @@ -265,7 +272,7 @@ void ContentProperties::UCBNamesToDAVNames( { if ( !bLastModified ) { - propertyNames.push_back( + propertyNames.push_back( DAVProperties::GETLASTMODIFIED ); bLastModified = sal_True; } @@ -277,7 +284,7 @@ void ContentProperties::UCBNamesToDAVNames( { if ( !bContentType ) { - propertyNames.push_back( + propertyNames.push_back( DAVProperties::GETCONTENTTYPE ); bContentType = sal_True; } @@ -289,7 +296,7 @@ void ContentProperties::UCBNamesToDAVNames( { if ( !bContentLength ) { - propertyNames.push_back( + propertyNames.push_back( DAVProperties::GETCONTENTLENGTH ); bContentLength = sal_True; } @@ -307,7 +314,7 @@ void ContentProperties::UCBNamesToDAVNames( { if ( !bResourceType ) { - propertyNames.push_back( DAVProperties::RESOURCETYPE ); + propertyNames.push_back( DAVProperties::RESOURCETYPE ); bResourceType = sal_True; } } @@ -407,7 +414,7 @@ void ContentProperties::addProperties( { // Add it. addProperty( rName, pProp->value(), pProp->isCaseSensitive() ); - } + } else { addProperty( rName, uno::Any(), false ); @@ -422,27 +429,27 @@ void ContentProperties::addProperties( const ContentProperties & rProps ) { PropertyValueMap::const_iterator it = rProps.m_xProps->begin(); const PropertyValueMap::const_iterator end = rProps.m_xProps->end(); - + while ( it != end ) { - addProperty( + addProperty( (*it).first, (*it).second.value(), (*it).second.isCaseSensitive() ); ++it; } } //========================================================================= -void ContentProperties::addProperties( +void ContentProperties::addProperties( const std::vector< DAVPropertyValue > & rProps ) { std::vector< DAVPropertyValue >::const_iterator it = rProps.begin(); - std::vector< DAVPropertyValue >::const_iterator end = rProps.end(); - + const std::vector< DAVPropertyValue >::const_iterator end = rProps.end(); + while ( it != end ) { addProperty( (*it) ); ++it; - } + } } //========================================================================= @@ -463,7 +470,7 @@ void ContentProperties::addProperty( const rtl::OUString & rName, rValue >>= aValue; util::DateTime aDate; DateTimeHelper::convert( aValue, aDate ); - + (*m_xProps)[ rtl::OUString::createFromAscii( "DateCreated" ) ] = PropertyValue( uno::makeAny( aDate ), true ); } @@ -474,11 +481,11 @@ void ContentProperties::addProperty( const rtl::OUString & rName, // { // } else if ( rName.equals( DAVProperties::GETCONTENTLENGTH ) ) - { + { // Map DAV:getcontentlength to UCP:Size rtl::OUString aValue; rValue >>= aValue; - + (*m_xProps)[ rtl::OUString::createFromAscii( "Size" ) ] = PropertyValue( uno::makeAny( aValue.toInt64() ), true ); } @@ -487,11 +494,11 @@ void ContentProperties::addProperty( const rtl::OUString & rName, { // Do NOT map Content-Lenght entity header to DAV:getcontentlength! // Only DAV resources have this property. - + // Map Content-Length entity header to UCP:Size rtl::OUString aValue; rValue >>= aValue; - + (*m_xProps)[ rtl::OUString::createFromAscii( "Size" ) ] = PropertyValue( uno::makeAny( aValue.toInt64() ), true ); } @@ -505,7 +512,7 @@ void ContentProperties::addProperty( const rtl::OUString & rName, { // Do NOT map Content-Type entity header to DAV:getcontenttype! // Only DAV resources have this property. - + // Map DAV:getcontenttype to UCP:MediaType (1:1) (*m_xProps)[ rtl::OUString::createFromAscii( "MediaType" ) ] = PropertyValue( rValue, true ); @@ -520,7 +527,7 @@ void ContentProperties::addProperty( const rtl::OUString & rName, rValue >>= aValue; util::DateTime aDate; DateTimeHelper::convert( aValue, aDate ); - + (*m_xProps)[ rtl::OUString::createFromAscii( "DateModified" ) ] = PropertyValue( uno::makeAny( aDate ), true ); } @@ -529,13 +536,13 @@ void ContentProperties::addProperty( const rtl::OUString & rName, { // Do not map Last-Modified entity header to DAV:getlastmodified! // Only DAV resources have this property. - + // Map the Last-Modified entity header to UCP:DateModified rtl::OUString aValue; rValue >>= aValue; util::DateTime aDate; DateTimeHelper::convert( aValue, aDate ); - + (*m_xProps)[ rtl::OUString::createFromAscii( "DateModified" ) ] = PropertyValue( uno::makeAny( aDate ), true ); } @@ -546,12 +553,12 @@ void ContentProperties::addProperty( const rtl::OUString & rName, { rtl::OUString aValue; rValue >>= aValue; - + // Map DAV:resourceype to UCP:IsFolder, UCP:IsDocument, UCP:ContentType sal_Bool bFolder = aValue.equalsIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "collection" ) ); - + (*m_xProps)[ rtl::OUString::createFromAscii( "IsFolder" ) ] = PropertyValue( uno::makeAny( bFolder ), true ); (*m_xProps)[ rtl::OUString::createFromAscii( "IsDocument" ) ] @@ -567,7 +574,100 @@ void ContentProperties::addProperty( const rtl::OUString & rName, // else if ( rName.equals( DAVProperties::SUPPORTEDLOCK ) ) // { // } - + // Save property. (*m_xProps)[ rName ] = PropertyValue( rValue, bIsCaseSensitive ); } + +//========================================================================= +//========================================================================= +// +// CachableContentProperties Implementation. +// +//========================================================================= +//========================================================================= + +namespace +{ + bool isCachable( rtl::OUString const & rName, + bool isCaseSensitive ) + { + static rtl::OUString aNonCachableProps [] = + { + DAVProperties::LOCKDISCOVERY, + + DAVProperties::GETETAG, + rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ETag" ) ), + + rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DateModified" ) ), + rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Last-Modified" ) ), + DAVProperties::GETLASTMODIFIED, + + rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Size" ) ), + rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Content-Length" ) ), + DAVProperties::GETCONTENTLENGTH, + + rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Date" ) ) + }; + + for ( sal_uInt32 n = 0; + n < ( sizeof( aNonCachableProps ) + / sizeof( aNonCachableProps[ 0 ] ) ); + ++n ) + { + if ( isCaseSensitive ) + { + if ( rName.equals( aNonCachableProps[ n ] ) ) + return false; + } + else + if ( rName.equalsIgnoreAsciiCase( aNonCachableProps[ n ] ) ) + return false; + } + return true; + } + +} // namespace + +//========================================================================= +CachableContentProperties::CachableContentProperties( + const ContentProperties & rProps ) +{ + addProperties( rProps ); +} + +//========================================================================= +void CachableContentProperties::addProperties( + const ContentProperties & rProps ) +{ + const std::auto_ptr< PropertyValueMap > & props = rProps.getProperties(); + + PropertyValueMap::const_iterator it = props->begin(); + const PropertyValueMap::const_iterator end = props->end(); + + while ( it != end ) + { + if ( isCachable( (*it).first, (*it).second.isCaseSensitive() ) ) + m_aProps.addProperty( (*it).first, + (*it).second.value(), + (*it).second.isCaseSensitive() ); + + ++it; + } +} + +//========================================================================= +void CachableContentProperties::addProperties( + const std::vector< DAVPropertyValue > & rProps ) +{ + std::vector< DAVPropertyValue >::const_iterator it = rProps.begin(); + const std::vector< DAVPropertyValue >::const_iterator end = rProps.end(); + + while ( it != end ) + { + if ( isCachable( (*it).Name, (*it).IsCaseSensitive ) ) + m_aProps.addProperty( (*it) ); + + ++it; + } +} diff --git a/ucb/source/ucp/webdav/ContentProperties.hxx b/ucb/source/ucp/webdav/ContentProperties.hxx index 5a21dba08a..fb07ad19a7 100644 --- a/ucb/source/ucp/webdav/ContentProperties.hxx +++ b/ucb/source/ucp/webdav/ContentProperties.hxx @@ -1,7 +1,7 @@ /************************************************************************* * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * + * * Copyright 2000, 2010 Oracle and/or its affiliates. * * OpenOffice.org - a multi-platform office productivity suite @@ -71,13 +71,13 @@ struct hashString class PropertyValue { private: - ::com::sun::star::uno::Any m_aValue; + ::com::sun::star::uno::Any m_aValue; bool m_bIsCaseSensitive; public: PropertyValue() : m_bIsCaseSensitive( true ) {} - + PropertyValue( const ::com::sun::star::uno::Any & rValue, bool bIsCaseSensitive ) : m_aValue( rValue), @@ -85,7 +85,7 @@ public: bool isCaseSensitive() const { return m_bIsCaseSensitive; } const ::com::sun::star::uno::Any & value() const { return m_aValue; } - + }; typedef std::hash_map @@ -102,10 +102,12 @@ struct DAVResource; class ContentProperties { public: - ContentProperties( const DAVResource& rResource ); + ContentProperties(); + + ContentProperties( const DAVResource& rResource ); // Mini props for transient contents. - ContentProperties( const rtl::OUString & rTitle, sal_Bool bFolder ); + ContentProperties( const rtl::OUString & rTitle, sal_Bool bFolder ); // Micro props for non-existing contents. ContentProperties( const rtl::OUString & rTitle ); @@ -167,10 +169,10 @@ public: void addProperty( const rtl::OUString & rName, const com::sun::star::uno::Any & rValue, bool bIsCaseSensitive ); - + // overwrites probably existing entry. void addProperty( const DAVPropertyValue & rProp ); - + bool isTrailingSlash() const { return m_bTrailingSlash; } const rtl::OUString & getEscapedTitle() const { return m_aEscapedTitle; } @@ -181,7 +183,7 @@ public: { return m_xProps; } private: - ::rtl::OUString m_aEscapedTitle; // escaped Title + ::rtl::OUString m_aEscapedTitle; std::auto_ptr< PropertyValueMap > m_xProps; bool m_bTrailingSlash; @@ -192,6 +194,34 @@ private: const PropertyValue * get( const rtl::OUString & rName ) const; }; -} +class CachableContentProperties +{ +private: + ContentProperties m_aProps; + + CachableContentProperties & operator=( const CachableContentProperties & ); // n.i. + CachableContentProperties( const CachableContentProperties & ); // n.i. + +public: + CachableContentProperties( const ContentProperties & rProps ); + + void addProperties( const ContentProperties & rProps ); + + void addProperties( const std::vector< DAVPropertyValue > & rProps ); + + bool containsAllNames( + const com::sun::star::uno::Sequence< + com::sun::star::beans::Property >& rProps, + std::vector< rtl::OUString > & rNamesNotContained ) const + { return m_aProps.containsAllNames( rProps, rNamesNotContained ); } + + const com::sun::star::uno::Any & + getValue( const rtl::OUString & rName ) const + { return m_aProps.getValue( rName ); } + + operator const ContentProperties & () const { return m_aProps; } +}; + +} // namespace webdav_ucp #endif /* !_WEBDAV_UCP_CONTENTPROPERTIES_HXX */ diff --git a/ucb/source/ucp/webdav/webdavcontent.cxx b/ucb/source/ucp/webdav/webdavcontent.cxx index c58ba20719..9a77a7e941 100644 --- a/ucb/source/ucp/webdav/webdavcontent.cxx +++ b/ucb/source/ucp/webdav/webdavcontent.cxx @@ -1476,7 +1476,7 @@ uno::Reference< sdbc::XRow > Content::getPropertyValues( osl::Guard< osl::Mutex > aGuard( m_aMutex ); if ( !m_xCachedProps.get() ) - m_xCachedProps.reset( new ContentProperties( *xProps.get() ) ); + m_xCachedProps.reset( new CachableContentProperties( *xProps.get() ) ); else m_xCachedProps->addProperties( *xProps.get() ); @@ -2012,7 +2012,7 @@ uno::Any Content::open( // cache headers. if ( !m_xCachedProps.get()) m_xCachedProps.reset( - new ContentProperties( aResource ) ); + new CachableContentProperties( aResource ) ); else m_xCachedProps->addProperties( aResource ); @@ -2058,7 +2058,7 @@ uno::Any Content::open( // cache headers. if ( !m_xCachedProps.get()) m_xCachedProps.reset( - new ContentProperties( aResource ) ); + new CachableContentProperties( aResource ) ); else m_xCachedProps->addProperties( aResource.properties ); @@ -3229,7 +3229,7 @@ const Content::ResourceType & Content::getResourceType( if ( resources.size() == 1 ) { m_xCachedProps.reset( - new ContentProperties( resources[ 0 ] ) ); + new CachableContentProperties( resources[ 0 ] ) ); m_xCachedProps->containsAllNames( aProperties, m_aFailedPropNames ); } diff --git a/ucb/source/ucp/webdav/webdavcontent.hxx b/ucb/source/ucp/webdav/webdavcontent.hxx index 85b9b710f3..dcc544a9b2 100644 --- a/ucb/source/ucp/webdav/webdavcontent.hxx +++ b/ucb/source/ucp/webdav/webdavcontent.hxx @@ -1,7 +1,7 @@ /************************************************************************* * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * + * * Copyright 2000, 2010 Oracle and/or its affiliates. * * OpenOffice.org - a multi-platform office productivity suite @@ -68,6 +68,7 @@ namespace webdav_ucp class ContentProvider; class ContentProperties; +class CachableContentProperties; class Content : public ::ucbhelper::ContentImplHelper, public com::sun::star::ucb::XContentCreator @@ -81,7 +82,8 @@ class Content : public ::ucbhelper::ContentImplHelper, }; std::auto_ptr< DAVResourceAccess > m_xResAccess; - std::auto_ptr< ContentProperties > m_xCachedProps; // locally cached props + std::auto_ptr< CachableContentProperties > + m_xCachedProps; // locally cached props rtl::OUString m_aEscapedTitle; ResourceType m_eResourceType; ContentProvider* m_pProvider; // No need for a ref, base class holds object -- cgit v1.2.3