diff options
Diffstat (limited to 'ucb/source/ucp/webdav/ContentProperties.cxx')
-rw-r--r-- | ucb/source/ucp/webdav/ContentProperties.cxx | 170 |
1 files changed, 135 insertions, 35 deletions
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( '/' ) ) @@ -158,6 +158,13 @@ ContentProperties::ContentProperties( const rtl::OUString & rTitle ) } //========================================================================= +ContentProperties::ContentProperties() +: m_xProps( new PropertyValueMap ), + m_bTrailingSlash( sal_False ) +{ +} + +//========================================================================= ContentProperties::ContentProperties( const ContentProperties & rOther ) : m_aEscapedTitle( rOther.m_aEscapedTitle ), m_xProps( rOther.m_xProps.get() @@ -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; + } +} |