diff options
109 files changed, 45001 insertions, 0 deletions
diff --git a/ucb/source/cacher/cachedcontentresultset.cxx b/ucb/source/cacher/cachedcontentresultset.cxx new file mode 100644 index 000000000000..bced7b5dba08 --- /dev/null +++ b/ucb/source/cacher/cachedcontentresultset.cxx @@ -0,0 +1,2221 @@ +/************************************************************************* + * + * $RCSfile: cachedcontentresultset.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:52:35 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include <cachedcontentresultset.hxx> + +#ifndef _COM_SUN_STAR_SDBC_FETCHDIRECTION_HPP_ +#include <com/sun/star/sdbc/FetchDirection.hpp> +#endif + +#ifndef _COM_SUN_STAR_UCB_FETCHERROR_HPP_ +#include <com/sun/star/ucb/FetchError.hpp> +#endif + +#ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HPP_ +#include <com/sun/star/beans/PropertyAttribute.hpp> +#endif + +#ifndef _COM_SUN_STAR_SDBC_RESULTSETTYPE_HPP_ +#include <com/sun/star/sdbc/ResultSetType.hpp> +#endif + +#ifndef _RTL_USTRING_HXX_ +#include <rtl/ustring.hxx> +#endif + +#ifndef _TOOLS_DEBUG_HXX +#include <tools/debug.hxx> +#endif + +using namespace com::sun::star::beans; +using namespace com::sun::star::lang; +using namespace com::sun::star::sdbc; +using namespace com::sun::star::ucb; +using namespace com::sun::star::uno; +using namespace com::sun::star::util; +using namespace cppu; +using namespace rtl; + +#define COMSUNSTARUCBCCRS_DEFAULT_FETCH_SIZE 256 +#define COMSUNSTARUCBCCRS_DEFAULT_FETCH_DIRECTION FetchDirection::FORWARD + +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- +//define for getXXX methods of interface XRow +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- + +//if you change this macro please pay attention to +//function ::getObject, where this is similar implemented + +#define XROW_GETXXX( getXXX, Type ) \ +impl_EnsureNotDisposed(); \ +ReacquireableGuard aGuard( m_aMutex ); \ +sal_Int32 nRow = m_nRow; \ +sal_Int32 nFetchSize = m_nFetchSize; \ +sal_Int32 nFetchDirection = m_nFetchDirection; \ +if( !m_aCache.hasRow( nRow ) ) \ +{ \ + if( !m_aCache.hasCausedException( nRow ) ) \ +{ \ + if( !m_xFetchProvider.is() ) \ + { \ + DBG_ERROR( "broadcaster was disposed already" ); \ + throw SQLException(); \ + } \ + aGuard.clear(); \ + if( impl_isForwardOnly() ) \ + applyPositionToOrigin( nRow ); \ + \ + impl_fetchData( nRow, nFetchSize, nFetchDirection ); \ + } \ + aGuard.reacquire(); \ + if( !m_aCache.hasRow( nRow ) ) \ + { \ + m_bLastReadWasFromCache = sal_False; \ + aGuard.clear(); \ + applyPositionToOrigin( nRow ); \ + return m_xRowOrigin->getXXX( columnIndex ); \ + } \ +} \ +const Any& rValue = m_aCache.getAny( nRow, columnIndex );\ +Type aRet; \ +m_bLastReadWasFromCache = sal_True; \ +m_bLastCachedReadWasNull = !( rValue >>= aRet ); \ +return aRet; + +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- +// CCRS_Cache methoeds. +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- + +CachedContentResultSet::CCRS_Cache::CCRS_Cache( + const Reference< XContentIdentifierMapping > & xMapping ) + : m_pResult( NULL ) + , m_xContentIdentifierMapping( xMapping ) + , m_pMappedReminder( NULL ) +{ +} + +CachedContentResultSet::CCRS_Cache::~CCRS_Cache() +{ + delete m_pResult; +} + +void SAL_CALL CachedContentResultSet::CCRS_Cache + ::clear() +{ + if( m_pResult ) + { + delete m_pResult; + m_pResult = NULL; + } + clearMappedReminder(); +} + +void SAL_CALL CachedContentResultSet::CCRS_Cache + ::loadData( const FetchResult& rResult ) +{ + clear(); + m_pResult = new FetchResult( rResult ); +} + +sal_Bool SAL_CALL CachedContentResultSet::CCRS_Cache + ::hasRow( sal_Int32 row ) +{ + if( !m_pResult ) + return FALSE; + long nStart = m_pResult->StartIndex; + long nEnd = nStart; + if( m_pResult->Orientation ) + nEnd += m_pResult->Rows.getLength() - 1; + else + nStart -= m_pResult->Rows.getLength() + 1; + + return nStart <= row && row <= nEnd; +} + +sal_Int32 SAL_CALL CachedContentResultSet::CCRS_Cache + ::getMaxRow() +{ + if( !m_pResult ) + return 0; + long nEnd = m_pResult->StartIndex; + if( m_pResult->Orientation ) + return nEnd += m_pResult->Rows.getLength() - 1; + else + return nEnd; +} + +sal_Bool SAL_CALL CachedContentResultSet::CCRS_Cache + ::hasKnownLast() +{ + if( !m_pResult ) + return sal_False; + + if( ( m_pResult->FetchError & FetchError::ENDOFDATA ) + && m_pResult->Orientation + && m_pResult->Rows.getLength() ) + return sal_True; + + return sal_False; +} + +sal_Bool SAL_CALL CachedContentResultSet::CCRS_Cache + ::hasCausedException( sal_Int32 nRow ) +{ + if( !m_pResult ) + return FALSE; + if( !( m_pResult->FetchError & FetchError::EXCEPTION ) ) + return FALSE; + + long nEnd = m_pResult->StartIndex; + if( m_pResult->Orientation ) + nEnd += m_pResult->Rows.getLength(); + + return nRow == nEnd+1; +} + +Any& SAL_CALL CachedContentResultSet::CCRS_Cache + ::getRowAny( sal_Int32 nRow ) + throw( SQLException, + RuntimeException ) +{ + if( !nRow ) + throw SQLException(); + if( !m_pResult ) + throw SQLException(); + if( !hasRow( nRow ) ) + throw SQLException(); + + long nDiff = nRow - m_pResult->StartIndex; + if( nDiff < 0 ) + nDiff *= -1; + + return (m_pResult->Rows)[nDiff]; +} + +void SAL_CALL CachedContentResultSet::CCRS_Cache + ::remindMapped( sal_Int32 nRow ) +{ + //remind that this row was mapped + if( !m_pResult ) + return; + long nDiff = nRow - m_pResult->StartIndex; + if( nDiff < 0 ) + nDiff *= -1; + Sequence< sal_Bool >* pMappedReminder = getMappedReminder(); + if( nDiff < pMappedReminder->getLength() ) + (*pMappedReminder)[nDiff] = sal_True; +} + +sal_Bool SAL_CALL CachedContentResultSet::CCRS_Cache + ::isRowMapped( sal_Int32 nRow ) +{ + if( !m_pMappedReminder || !m_pResult ) + return sal_False; + long nDiff = nRow - m_pResult->StartIndex; + if( nDiff < 0 ) + nDiff *= -1; + if( nDiff < m_pMappedReminder->getLength() ) + return (*m_pMappedReminder)[nDiff]; + return sal_False; +} + +void SAL_CALL CachedContentResultSet::CCRS_Cache + ::clearMappedReminder() +{ + delete m_pMappedReminder; + m_pMappedReminder = NULL; +} + +Sequence< sal_Bool >* SAL_CALL CachedContentResultSet::CCRS_Cache + ::getMappedReminder() +{ + if( !m_pMappedReminder ) + { + sal_Int32 nCount = m_pResult->Rows.getLength(); + m_pMappedReminder = new Sequence< sal_Bool >( nCount ); + for( nCount; nCount--; ) + (*m_pMappedReminder)[nCount] = sal_False; + } + return m_pMappedReminder; +} + +const Any& SAL_CALL CachedContentResultSet::CCRS_Cache + ::getAny( sal_Int32 nRow, sal_Int32 nColumnIndex ) + throw( SQLException, + RuntimeException ) +{ + if( !nColumnIndex ) + throw SQLException(); + if( m_xContentIdentifierMapping.is() && !isRowMapped( nRow ) ) + { + Any& rRow = getRowAny( nRow ); + Sequence< Any > aValue; + rRow >>= aValue; + if( m_xContentIdentifierMapping->mapRow( aValue ) ) + { + rRow <<= aValue; + remindMapped( nRow ); + } + else + m_xContentIdentifierMapping.clear(); + } + const Sequence< Any >& rRow = + (* reinterpret_cast< const Sequence< Any > * > + (getRowAny( nRow ).getValue() )); + + sal_Int32 nTest = rRow.getLength(); + if( nColumnIndex > rRow.getLength() ) + throw SQLException(); + return rRow[nColumnIndex-1]; +} + +const rtl::OUString& SAL_CALL CachedContentResultSet::CCRS_Cache + ::getContentIdentifierString( sal_Int32 nRow ) + throw( com::sun::star::uno::RuntimeException ) +{ + try + { + if( m_xContentIdentifierMapping.is() && !isRowMapped( nRow ) ) + { + Any& rRow = getRowAny( nRow ); + rtl::OUString aValue; + rRow >>= aValue; + rRow <<= m_xContentIdentifierMapping->mapContentIdentifierString( aValue ); + remindMapped( nRow ); + } + return (* reinterpret_cast< const rtl::OUString * > + (getRowAny( nRow ).getValue() )); + } + catch( SQLException ) + { + throw RuntimeException(); + } +} + +const Reference< XContentIdentifier >& SAL_CALL CachedContentResultSet::CCRS_Cache + ::getContentIdentifier( sal_Int32 nRow ) + throw( com::sun::star::uno::RuntimeException ) +{ + try + { + if( m_xContentIdentifierMapping.is() && !isRowMapped( nRow ) ) + { + Any& rRow = getRowAny( nRow ); + Reference< XContentIdentifier > aValue; + rRow >>= aValue; + rRow <<= m_xContentIdentifierMapping->mapContentIdentifier( aValue ); + remindMapped( nRow ); + } + return (* reinterpret_cast< const Reference< XContentIdentifier > * > + (getRowAny( nRow ).getValue() )); + } + catch( SQLException ) + { + throw RuntimeException(); + } +} + +const Reference< XContent >& SAL_CALL CachedContentResultSet::CCRS_Cache + ::getContent( sal_Int32 nRow ) + throw( com::sun::star::uno::RuntimeException ) +{ + try + { + if( m_xContentIdentifierMapping.is() && !isRowMapped( nRow ) ) + { + Any& rRow = getRowAny( nRow ); + Reference< XContent > aValue; + rRow >>= aValue; + rRow <<= m_xContentIdentifierMapping->mapContent( aValue ); + remindMapped( nRow ); + } + return (* reinterpret_cast< const Reference< XContent > * > + (getRowAny( nRow ).getValue() )); + } + catch( SQLException ) + { + throw RuntimeException(); + } +} + +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- +// class CCRS_PropertySetInfo +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- + +class CCRS_PropertySetInfo : + public cppu::OWeakObject, + public com::sun::star::lang::XTypeProvider, + public com::sun::star::beans::XPropertySetInfo +{ +friend CachedContentResultSet; + //my Properties + Sequence< com::sun::star::beans::Property >* + m_pProperties; + + //some helping variables ( names for my special properties ) + static rtl::OUString m_aPropertyNameForCount; + static rtl::OUString m_aPropertyNameForFinalCount; + static rtl::OUString m_aPropertyNameForFetchSize; + static rtl::OUString m_aPropertyNameForFetchDirection; + + long m_nFetchSizePropertyHandle; + long m_nFetchDirectionPropertyHandle; + +private: + sal_Int32 SAL_CALL + impl_getRemainedHandle() const; + + sal_Bool SAL_CALL + impl_queryProperty( + const rtl::OUString& rName + , com::sun::star::beans::Property& rProp ) const; + sal_Int32 SAL_CALL + impl_getPos( const rtl::OUString& rName ) const; + + static sal_Bool SAL_CALL + impl_isMyPropertyName( const rtl::OUString& rName ); + +public: + CCRS_PropertySetInfo( Reference< + XPropertySetInfo > xPropertySetInfoOrigin ); + + virtual ~CCRS_PropertySetInfo(); + + // XInterface + XINTERFACE_DECL() + + // XTypeProvider + XTYPEPROVIDER_DECL() + + // XPropertySetInfo + virtual Sequence< com::sun::star::beans::Property > SAL_CALL + getProperties() + throw( RuntimeException ); + + virtual com::sun::star::beans::Property SAL_CALL + getPropertyByName( const rtl::OUString& aName ) + throw( com::sun::star::beans::UnknownPropertyException, RuntimeException ); + + virtual sal_Bool SAL_CALL + hasPropertyByName( const rtl::OUString& Name ) + throw( RuntimeException ); +}; + +OUString CCRS_PropertySetInfo::m_aPropertyNameForCount( OUString::createFromAscii( "RowCount" ) ); +OUString CCRS_PropertySetInfo::m_aPropertyNameForFinalCount( OUString::createFromAscii( "IsRowCountFinal" ) ); +OUString CCRS_PropertySetInfo::m_aPropertyNameForFetchSize( OUString::createFromAscii( "FetchSize" ) ); +OUString CCRS_PropertySetInfo::m_aPropertyNameForFetchDirection( OUString::createFromAscii( "FetchDirection" ) ); + +CCRS_PropertySetInfo::CCRS_PropertySetInfo( + Reference< XPropertySetInfo > xInfo ) + : m_pProperties( NULL ) + , m_nFetchSizePropertyHandle( -1 ) + , m_nFetchDirectionPropertyHandle( -1 ) +{ + //initialize list of properties: + + // it is required, that the received xInfo contains the two + // properties with names 'm_aPropertyNameForCount' and + // 'm_aPropertyNameForFinalCount' + + if( xInfo.is() ) + { + Sequence<Property> aProps = xInfo->getProperties(); + m_pProperties = new Sequence<Property> ( aProps ); + } + else + { + DBG_ERROR( "The received XPropertySetInfo doesn't contain required properties" ); + m_pProperties = new Sequence<Property>; + } + + //ensure, that we haven't got the Properties 'FetchSize' and 'Direction' twice: + sal_Int32 nFetchSize = impl_getPos( m_aPropertyNameForFetchSize ); + sal_Int32 nFetchDirection = impl_getPos( m_aPropertyNameForFetchDirection ); + sal_Int32 nDeleted = 0; + if( nFetchSize != -1 ) + nDeleted++; + if( nFetchDirection != -1 ) + nDeleted++; + + Sequence< Property >* pOrigProps = new Sequence<Property> ( *m_pProperties ); + sal_Int32 nOrigProps = pOrigProps->getLength(); + + m_pProperties->realloc( nOrigProps + 2 - nDeleted );//note that nDeleted is <= 2 + for( sal_Int32 n = 0, m = 0; n < nOrigProps; n++, m++ ) + { + if( n == nFetchSize || n == nFetchDirection ) + m--; + else + (*m_pProperties)[ m ] = (*pOrigProps)[ n ]; + } + { + Property& rMyProp = (*m_pProperties)[ nOrigProps - nDeleted ]; + rMyProp.Name = m_aPropertyNameForFetchSize; + rMyProp.Type = getCppuType( static_cast< const sal_Int32 * >( 0 ) ); + rMyProp.Attributes = PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT; + + if( nFetchSize != -1 ) + m_nFetchSizePropertyHandle = (*pOrigProps)[nFetchSize].Handle; + else + m_nFetchSizePropertyHandle = impl_getRemainedHandle(); + + rMyProp.Handle = m_nFetchSizePropertyHandle; + + } + { + Property& rMyProp = (*m_pProperties)[ nOrigProps - nDeleted + 1 ]; + rMyProp.Name = m_aPropertyNameForFetchDirection; + rMyProp.Type = getCppuType( static_cast< const sal_Bool * >( 0 ) ); + rMyProp.Attributes = PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT; + + if( nFetchSize != -1 ) + m_nFetchDirectionPropertyHandle = (*pOrigProps)[nFetchDirection].Handle; + else + m_nFetchDirectionPropertyHandle = impl_getRemainedHandle(); + + m_nFetchDirectionPropertyHandle = rMyProp.Handle; + } + delete pOrigProps; +} + +CCRS_PropertySetInfo::~CCRS_PropertySetInfo() +{ + delete m_pProperties; +} + +//-------------------------------------------------------------------------- +// XInterface methods. +//-------------------------------------------------------------------------- +//list all interfaces inclusive baseclasses of interfaces +XINTERFACE_IMPL_2( CCRS_PropertySetInfo + , XTypeProvider + , XPropertySetInfo + ); + +//-------------------------------------------------------------------------- +// XTypeProvider methods. +//-------------------------------------------------------------------------- +//list all interfaces exclusive baseclasses +XTYPEPROVIDER_IMPL_2( CCRS_PropertySetInfo + , XTypeProvider + , XPropertySetInfo + ); +//-------------------------------------------------------------------------- +// XPropertySetInfo methods. +//-------------------------------------------------------------------------- +//virtual +Sequence< Property > SAL_CALL CCRS_PropertySetInfo + ::getProperties() throw( RuntimeException ) +{ + return *m_pProperties; +} + +//virtual +Property SAL_CALL CCRS_PropertySetInfo + ::getPropertyByName( const rtl::OUString& aName ) + throw( UnknownPropertyException, RuntimeException ) +{ + if ( !aName.getLength() ) + throw UnknownPropertyException(); + + Property aProp; + if ( impl_queryProperty( aName, aProp ) ) + return aProp; + + throw UnknownPropertyException(); +} + +//virtual +sal_Bool SAL_CALL CCRS_PropertySetInfo + ::hasPropertyByName( const rtl::OUString& Name ) + throw( RuntimeException ) +{ + return ( impl_getPos( Name ) != -1 ); +} + +//-------------------------------------------------------------------------- +// impl_ methods. +//-------------------------------------------------------------------------- + +sal_Int32 SAL_CALL CCRS_PropertySetInfo + ::impl_getPos( const OUString& rName ) const +{ + for( sal_Int32 nN = m_pProperties->getLength(); nN--; ) + { + const Property& rMyProp = (*m_pProperties)[nN]; + if( rMyProp.Name == rName ) + return nN; + } + return -1; +} + +sal_Bool SAL_CALL CCRS_PropertySetInfo + ::impl_queryProperty( const OUString& rName, Property& rProp ) const +{ + for( sal_Int32 nN = m_pProperties->getLength(); nN--; ) + { + const Property& rMyProp = (*m_pProperties)[nN]; + if( rMyProp.Name == rName ) + { + rProp.Name = rMyProp.Name; + rProp.Handle = rMyProp.Handle; + rProp.Type = rMyProp.Type; + rProp.Attributes = rMyProp.Attributes; + + return sal_True; + } + } + return sal_False; +} + +//static +sal_Bool SAL_CALL CCRS_PropertySetInfo + ::impl_isMyPropertyName( const OUString& rPropertyName ) +{ + return ( rPropertyName == m_aPropertyNameForCount + || rPropertyName == m_aPropertyNameForFinalCount + || rPropertyName == m_aPropertyNameForFetchSize + || rPropertyName == m_aPropertyNameForFetchDirection ); +} + +sal_Int32 SAL_CALL CCRS_PropertySetInfo + ::impl_getRemainedHandle( ) const +{ + sal_Int32 nHandle = 1; + + if( !m_pProperties ) + { + DBG_ERROR( "Properties not initialized yet" ); + return nHandle; + } + sal_Bool bFound = TRUE; + while( bFound ) + { + bFound = FALSE; + for( sal_Int32 nN = m_pProperties->getLength(); nN--; ) + { + if( nHandle == (*m_pProperties)[nN].Handle ) + { + bFound = TRUE; + nHandle++; + break; + } + } + } + return nHandle; +} + +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- +// class CachedContentResultSet +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- + +CachedContentResultSet::CachedContentResultSet( Reference< XResultSet > xOrigin + , Reference< XContentIdentifierMapping > + xContentIdentifierMapping ) + : ContentResultSetWrapper( xOrigin ) + + , m_xFetchProvider( NULL ) + , m_xFetchProviderForContentAccess( NULL ) + , m_xContentIdentifierMapping( xContentIdentifierMapping ) + + , m_pMyPropSetInfo( NULL ) + , m_xMyPropertySetInfo( NULL ) + + , m_nRow( 0 ) // Position is one-based. Zero means: before first element. + , m_nLastAppliedPos( 0 ) + , m_bAfterLast( sal_False ) + , m_bAfterLastApplied( sal_False ) + , m_nKnownCount( 0 ) + , m_bFinalCount( sal_False ) + , m_nFetchSize( + COMSUNSTARUCBCCRS_DEFAULT_FETCH_SIZE ) + , m_nFetchDirection( + COMSUNSTARUCBCCRS_DEFAULT_FETCH_DIRECTION ) + + , m_bLastReadWasFromCache( sal_False ) + , m_bLastCachedReadWasNull( sal_True ) + , m_aCache( m_xContentIdentifierMapping ) + , m_aCacheContentIdentifierString( m_xContentIdentifierMapping ) + , m_aCacheContentIdentifier( m_xContentIdentifierMapping ) + , m_aCacheContent( m_xContentIdentifierMapping ) +{ + m_xFetchProvider = Reference< XFetchProvider >( m_xResultSetOrigin, UNO_QUERY ); + DBG_ASSERT( m_xFetchProvider.is(), "interface XFetchProvider is required" ); + + m_xFetchProviderForContentAccess = Reference< XFetchProviderForContentAccess >( m_xResultSetOrigin, UNO_QUERY ); + DBG_ASSERT( m_xFetchProviderForContentAccess.is(), "interface XFetchProviderForContentAccess is required" ); + + impl_init(); +}; + +CachedContentResultSet::~CachedContentResultSet() +{ + impl_deinit(); + //do not delete m_pMyPropSetInfo, cause it is hold via reference +}; + +//-------------------------------------------------------------------------- +// impl_ methods. +//-------------------------------------------------------------------------- + +sal_Bool SAL_CALL CachedContentResultSet + ::applyPositionToOrigin( sal_Int32 nRow ) + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + //------------------------------------------------------------------------- + /** + @returns + <TRUE/> if the cursor is on a valid row; <FALSE/> if it is off + the result set. + */ + + ReacquireableGuard aGuard( m_aMutex ); + DBG_ASSERT( nRow >= 0, "only positive values supported" ); + if( !m_xResultSetOrigin.is() ) + { + DBG_ERROR( "broadcaster was disposed already" ); + return sal_False; + } +// DBG_ASSERT( nRow <= m_nKnownCount, "don't step into regions you don't know with this method" ); + + sal_Int32 nLastAppliedPos = m_nLastAppliedPos; + sal_Bool bAfterLastApplied = m_bAfterLastApplied; + sal_Bool bAfterLast = m_bAfterLast; + sal_Int32 nForwardOnly = m_nForwardOnly; + + aGuard.clear(); + + if( bAfterLastApplied || nLastAppliedPos != nRow ) + { + if( nForwardOnly == 1 ) + { + if( bAfterLastApplied || bAfterLast || !nRow || nRow < nLastAppliedPos ) + throw SQLException(); + + sal_Int32 nN = nRow - nLastAppliedPos; + for( sal_Int32 nM = 0; nN--; nM++ ) + { + if( !m_xResultSetOrigin->next() ) + break; + } + + aGuard.reacquire(); + m_nLastAppliedPos += nM; + m_bAfterLastApplied = nRow != m_nLastAppliedPos; + return nRow == m_nLastAppliedPos; + } + + if( !nRow ) //absolute( 0 ) will throw exception + { + m_xResultSetOrigin->beforeFirst(); + + aGuard.reacquire(); + m_nLastAppliedPos = 0; + m_bAfterLastApplied = sal_False; + return sal_False; + } + try + { + //move absolute, if !nLastAppliedPos + //because move relative would throw exception + if( !nLastAppliedPos || bAfterLast || bAfterLastApplied ) + { + sal_Bool bValid = m_xResultSetOrigin->absolute( nRow ); + + aGuard.reacquire(); + m_nLastAppliedPos = nRow; + m_bAfterLastApplied = !bValid; + return bValid; + } + else + { + sal_Bool bValid = m_xResultSetOrigin->relative( nRow - nLastAppliedPos ); + + aGuard.reacquire(); + m_nLastAppliedPos += ( nRow - nLastAppliedPos ); + m_bAfterLastApplied = !bValid; + return bValid; + } + } + catch( SQLException& rEx ) + { + if( !bAfterLastApplied && !bAfterLast && nRow > nLastAppliedPos && impl_isForwardOnly() ) + { + sal_Int32 nN = nRow - nLastAppliedPos; + for( sal_Int32 nM = 0; nN--; nM++ ) + { + if( !m_xResultSetOrigin->next() ) + break; + } + + aGuard.reacquire(); + m_nLastAppliedPos += nM; + m_bAfterLastApplied = nRow != m_nLastAppliedPos; + return nRow == m_nLastAppliedPos; + } + else + throw rEx; + } + } + else + return sal_True; +}; + +sal_Bool SAL_CALL CachedContentResultSet + ::applyPositionToOrigin() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + sal_Int32 nRow; + { + vos::OGuard aGuard( m_aMutex ); + if( m_bAfterLast ) + throw SQLException(); + nRow = m_nRow; + if( !nRow ) + throw SQLException(); + } + return applyPositionToOrigin( nRow ); +}; + +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- +//define for fetching data +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- + +#define FETCH_XXX( aCache, fetchInterface, fetchMethod ) \ +sal_Bool bDirection = !!( \ + nFetchDirection != FetchDirection::REVERSE ); \ +FetchResult aResult = \ + fetchInterface->fetchMethod( nRow, nFetchSize, bDirection ); \ +vos::OClearableGuard aGuard( m_aMutex ); \ +aCache.loadData( aResult ); \ +sal_Int32 nMax = aCache.getMaxRow(); \ +sal_Int32 nCurCount = m_nKnownCount; \ +sal_Bool bIsFinalCount = aCache.hasKnownLast(); \ +sal_Bool bCurIsFinalCount = m_bFinalCount; \ +aGuard.clear(); \ +if( nMax > nCurCount ) \ + impl_changeRowCount( nCurCount, nMax ); \ +if( bIsFinalCount && !bCurIsFinalCount ) \ + impl_changeIsRowCountFinal( bCurIsFinalCount, bIsFinalCount ); + +void SAL_CALL CachedContentResultSet + ::impl_fetchData( sal_Int32 nRow + , sal_Int32 nFetchSize, sal_Int32 nFetchDirection ) + throw( com::sun::star::uno::RuntimeException ) +{ + FETCH_XXX( m_aCache, m_xFetchProvider, fetch ); +} + +void SAL_CALL CachedContentResultSet + ::impl_changeRowCount( sal_Int32 nOld, sal_Int32 nNew ) +{ + DBG_ASSERT( nNew > nOld, "RowCount only can grow" ); + if( nNew <= nOld ) + return; + + //create PropertyChangeEvent and set value + PropertyChangeEvent aEvt; + { + vos::OGuard aGuard( m_aMutex ); + aEvt.Source = static_cast< XPropertySet * >( this ); + aEvt.Further = FALSE; + aEvt.OldValue <<= nOld; + aEvt.NewValue <<= nNew; + + m_nKnownCount = nNew; + } + + //send PropertyChangeEvent to listeners + impl_notifyPropertyChangeListeners( aEvt ); +} + +void SAL_CALL CachedContentResultSet + ::impl_changeIsRowCountFinal( sal_Bool bOld, sal_Bool bNew ) +{ + DBG_ASSERT( !bOld && bNew, "This change is not allowed for IsRowCountFinal" ); + if( ! (!bOld && bNew ) ) + return; + + //create PropertyChangeEvent and set value + PropertyChangeEvent aEvt; + { + vos::OGuard aGuard( m_aMutex ); + aEvt.Source = static_cast< XPropertySet * >( this ); + aEvt.Further = FALSE; + aEvt.OldValue <<= bOld; + aEvt.NewValue <<= bNew; + + m_bFinalCount = bNew; + } + + //send PropertyChangeEvent to listeners + impl_notifyPropertyChangeListeners( aEvt ); +} + +sal_Bool SAL_CALL CachedContentResultSet + ::impl_isKnownValidPosition( sal_Int32 nRow ) +{ + return m_nKnownCount && nRow + && nRow <= m_nKnownCount; +} + +sal_Bool SAL_CALL CachedContentResultSet + ::impl_isKnownInvalidPosition( sal_Int32 nRow ) +{ + if( !nRow ) + return sal_True; + if( !m_bFinalCount ) + return sal_False; + return nRow > m_nKnownCount; +} + + +//virtual +void SAL_CALL CachedContentResultSet + ::impl_initPropertySetInfo() +{ + ContentResultSetWrapper::impl_initPropertySetInfo(); + + vos::OGuard aGuard( m_aMutex ); + if( m_pMyPropSetInfo ) + return; + m_pMyPropSetInfo = new CCRS_PropertySetInfo( m_xPropertySetInfo ); + m_xMyPropertySetInfo = m_pMyPropSetInfo; + m_xPropertySetInfo = m_xMyPropertySetInfo; +} + +//-------------------------------------------------------------------------- +// XInterface methods. ( inherited ) +//-------------------------------------------------------------------------- +XINTERFACE_COMMON_IMPL( CachedContentResultSet ) + +Any SAL_CALL CachedContentResultSet + ::queryInterface( const Type& rType ) + throw ( RuntimeException ) +{ + //list all interfaces inclusive baseclasses of interfaces + + Any aRet = ContentResultSetWrapper::queryInterface( rType ); + if( aRet.hasValue() ) + return aRet; + + aRet = cppu::queryInterface( rType, + static_cast< XTypeProvider* >( this ), + static_cast< XServiceInfo* >( this ) ); + + return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ); +} + +//-------------------------------------------------------------------------- +// XTypeProvider methods. +//-------------------------------------------------------------------------- +//list all interfaces exclusive baseclasses +XTYPEPROVIDER_IMPL_11( CachedContentResultSet + , XTypeProvider + , XServiceInfo + , XComponent + , XCloseable + , XResultSetMetaDataSupplier + , XPropertySet + + , XPropertyChangeListener + , XVetoableChangeListener + + , XContentAccess + + , XResultSet + , XRow ); + +//-------------------------------------------------------------------------- +// XServiceInfo methods. +//-------------------------------------------------------------------------- + +XSERVICEINFO_NOFACTORY_IMPL_1( CachedContentResultSet, + OUString::createFromAscii( "CachedContentResultSet" ), + OUString::createFromAscii( CACHED_CONTENT_RESULTSET_SERVICE_NAME ) ); + +//-------------------------------------------------------------------------- +// XPropertySet methods. ( inherited ) +//-------------------------------------------------------------------------- + +// virtual +void SAL_CALL CachedContentResultSet + ::setPropertyValue( const OUString& aPropertyName, const Any& aValue ) + throw( UnknownPropertyException, + PropertyVetoException, + IllegalArgumentException, + WrappedTargetException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( !getPropertySetInfo().is() ) + { + DBG_ERROR( "broadcaster was disposed already" ); + throw UnknownPropertyException(); + } + + Property aProp = m_pMyPropSetInfo->getPropertyByName( aPropertyName ); + //throws UnknownPropertyException, if so + + if( aProp.Attributes & PropertyAttribute::READONLY ) + { + //It is assumed, that the properties + //'RowCount' and 'IsRowCountFinal' are readonly! + throw IllegalArgumentException(); + } + if( aProp.Name == CCRS_PropertySetInfo + ::m_aPropertyNameForFetchDirection ) + { + //check value + sal_Int32 nNew; + if( !( aValue >>= nNew ) ) + { + throw IllegalArgumentException(); + } + + if( nNew == FetchDirection::UNKNOWN ) + { + nNew = COMSUNSTARUCBCCRS_DEFAULT_FETCH_DIRECTION; + } + else if( !( nNew == FetchDirection::FORWARD + || nNew == FetchDirection::REVERSE ) ) + { + throw IllegalArgumentException(); + } + + //create PropertyChangeEvent and set value + PropertyChangeEvent aEvt; + { + vos::OGuard aGuard( m_aMutex ); + aEvt.Source = static_cast< XPropertySet * >( this ); + aEvt.PropertyName = aPropertyName; + aEvt.Further = FALSE; + aEvt.PropertyHandle = m_pMyPropSetInfo-> + m_nFetchDirectionPropertyHandle; + aEvt.OldValue <<= m_nFetchDirection; + aEvt.NewValue <<= nNew; + + m_nFetchDirection = nNew; + } + + //send PropertyChangeEvent to listeners + impl_notifyPropertyChangeListeners( aEvt ); + } + else if( aProp.Name == CCRS_PropertySetInfo + ::m_aPropertyNameForFetchSize ) + { + //check value + sal_Int32 nNew; + if( !( aValue >>= nNew ) ) + { + throw IllegalArgumentException(); + } + + if( nNew < 0 ) + { + nNew = COMSUNSTARUCBCCRS_DEFAULT_FETCH_SIZE; + } + + //create PropertyChangeEvent and set value + PropertyChangeEvent aEvt; + { + vos::OGuard aGuard( m_aMutex ); + aEvt.Source = static_cast< XPropertySet * >( this ); + aEvt.PropertyName = aPropertyName; + aEvt.Further = FALSE; + aEvt.PropertyHandle = m_pMyPropSetInfo-> + m_nFetchSizePropertyHandle; + aEvt.OldValue <<= m_nFetchSize; + aEvt.NewValue <<= nNew; + + m_nFetchSize = nNew; + } + + //send PropertyChangeEvent to listeners + impl_notifyPropertyChangeListeners( aEvt ); + } + else + { + vos::OGuard aGuard( m_aMutex ); + if( !m_xPropertySetOrigin.is() ) + { + DBG_ERROR( "broadcaster was disposed already" ); + return; + } + m_xPropertySetOrigin->setPropertyValue( aPropertyName, aValue ); + } +} + +//-------------------------------------------------------------------------- +// virtual +Any SAL_CALL CachedContentResultSet + ::getPropertyValue( const OUString& rPropertyName ) + throw( UnknownPropertyException, + WrappedTargetException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( !getPropertySetInfo().is() ) + { + DBG_ERROR( "broadcaster was disposed already" ); + throw UnknownPropertyException(); + } + + Property aProp = m_pMyPropSetInfo->getPropertyByName( rPropertyName ); + //throws UnknownPropertyException, if so + + Any aValue; + if( rPropertyName == CCRS_PropertySetInfo + ::m_aPropertyNameForCount ) + { + vos::OGuard aGuard( m_aMutex ); + aValue <<= m_nKnownCount; + } + else if( rPropertyName == CCRS_PropertySetInfo + ::m_aPropertyNameForFinalCount ) + { + vos::OGuard aGuard( m_aMutex ); + aValue <<= m_bFinalCount; + } + else if( rPropertyName == CCRS_PropertySetInfo + ::m_aPropertyNameForFetchSize ) + { + vos::OGuard aGuard( m_aMutex ); + aValue <<= m_nFetchSize; + } + else if( rPropertyName == CCRS_PropertySetInfo + ::m_aPropertyNameForFetchDirection ) + { + vos::OGuard aGuard( m_aMutex ); + aValue <<= m_nFetchDirection; + } + else + { + { + vos::OGuard aGuard( m_aMutex ); + if( !m_xPropertySetOrigin.is() ) + { + DBG_ERROR( "broadcaster was disposed already" ); + throw UnknownPropertyException(); + } + } + aValue = m_xPropertySetOrigin->getPropertyValue( rPropertyName ); + } + return aValue; +} + +//-------------------------------------------------------------------------- +// own methods. ( inherited ) +//-------------------------------------------------------------------------- + +//virtual +void SAL_CALL CachedContentResultSet + ::impl_disposing( const EventObject& rEventObject ) + throw( RuntimeException ) +{ + { + impl_EnsureNotDisposed(); + vos::OGuard aGuard( m_aMutex ); + //release all references to the broadcaster: + m_xFetchProvider.clear(); + m_xFetchProviderForContentAccess.clear(); + } + ContentResultSetWrapper::impl_disposing( rEventObject ); +} + +//virtual +void SAL_CALL CachedContentResultSet + ::impl_propertyChange( const PropertyChangeEvent& rEvt ) + throw( RuntimeException ) +{ + impl_EnsureNotDisposed(); + + PropertyChangeEvent aEvt( rEvt ); + aEvt.Source = static_cast< XPropertySet * >( this ); + aEvt.Further = FALSE; + //--------- + + if( CCRS_PropertySetInfo + ::impl_isMyPropertyName( rEvt.PropertyName ) ) + { + //don't notify foreign events on fetchsize and fetchdirection + if( aEvt.PropertyName == CCRS_PropertySetInfo + ::m_aPropertyNameForFetchSize + || aEvt.PropertyName == CCRS_PropertySetInfo + ::m_aPropertyNameForFetchDirection ) + return; + + //adjust my props 'RowCount' and 'IsRowCountFinal' + if( aEvt.PropertyName == CCRS_PropertySetInfo + ::m_aPropertyNameForCount ) + {//RowCount changed + + //check value + sal_Int32 nNew; + if( !( aEvt.NewValue >>= nNew ) ) + { + DBG_ERROR( "PropertyChangeEvent contains wrong data" ); + return; + } + + impl_changeRowCount( m_nKnownCount, nNew ); + } + else if( aEvt.PropertyName == CCRS_PropertySetInfo + ::m_aPropertyNameForFinalCount ) + {//IsRowCountFinal changed + + //check value + sal_Bool bNew; + if( !( aEvt.NewValue >>= bNew ) ) + { + DBG_ERROR( "PropertyChangeEvent contains wrong data" ); + return; + } + impl_changeIsRowCountFinal( m_bFinalCount, bNew ); + } + return; + } + + //----------- + impl_notifyPropertyChangeListeners( aEvt ); +} + + +//virtual +void SAL_CALL CachedContentResultSet + ::impl_vetoableChange( const PropertyChangeEvent& rEvt ) + throw( PropertyVetoException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + //don't notify events on my properties, cause they are not vetoable + if( CCRS_PropertySetInfo + ::impl_isMyPropertyName( rEvt.PropertyName ) ) + { + return; + } + + + PropertyChangeEvent aEvt( rEvt ); + aEvt.Source = static_cast< XPropertySet * >( this ); + aEvt.Further = FALSE; + + impl_notifyVetoableChangeListeners( aEvt ); +} + +//-------------------------------------------------------------------------- +// XContentAccess methods. ( inherited ) ( -- position dependent ) +//-------------------------------------------------------------------------- + +#define XCONTENTACCESS_queryXXX( queryXXX, XXX, TYPE ) \ +impl_EnsureNotDisposed(); \ +ReacquireableGuard aGuard( m_aMutex ); \ +sal_Int32 nRow = m_nRow; \ +sal_Int32 nFetchSize = m_nFetchSize; \ +sal_Int32 nFetchDirection = m_nFetchDirection; \ +if( !m_aCache##XXX.hasRow( nRow ) ) \ +{ \ + if( !m_aCache##XXX.hasCausedException( nRow ) ) \ +{ \ + if( !m_xFetchProviderForContentAccess.is() ) \ + { \ + DBG_ERROR( "broadcaster was disposed already" );\ + throw RuntimeException(); \ + } \ + aGuard.clear(); \ + if( impl_isForwardOnly() ) \ + applyPositionToOrigin( nRow ); \ + \ + FETCH_XXX( m_aCache##XXX, m_xFetchProviderForContentAccess, fetch##XXX##s ); \ + } \ + aGuard.reacquire(); \ + if( !m_aCache##XXX.hasRow( nRow ) ) \ + { \ + aGuard.clear(); \ + applyPositionToOrigin( nRow ); \ + TYPE aRet = ContentResultSetWrapper::queryXXX(); \ + if( m_xContentIdentifierMapping.is() ) \ + return m_xContentIdentifierMapping->map##XXX( aRet );\ + return aRet; \ + } \ +} \ +return m_aCache##XXX.get##XXX( nRow ); + +//-------------------------------------------------------------------------- +// virtual +OUString SAL_CALL CachedContentResultSet + ::queryContentIdentfierString() + throw( RuntimeException ) +{ + XCONTENTACCESS_queryXXX( queryContentIdentfierString, ContentIdentifierString, OUString ) +} + +//-------------------------------------------------------------------------- +// virtual +Reference< XContentIdentifier > SAL_CALL CachedContentResultSet + ::queryContentIdentifier() + throw( RuntimeException ) +{ + XCONTENTACCESS_queryXXX( queryContentIdentifier, ContentIdentifier, Reference< XContentIdentifier > ) +} + +//-------------------------------------------------------------------------- +// virtual +Reference< XContent > SAL_CALL CachedContentResultSet + ::queryContent() + throw( RuntimeException ) +{ + XCONTENTACCESS_queryXXX( queryContent, Content, Reference< XContent > ) +} + +//----------------------------------------------------------------- +// XResultSet methods. ( inherited ) +//----------------------------------------------------------------- +//virtual + +sal_Bool SAL_CALL CachedContentResultSet + ::next() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + ReacquireableGuard aGuard( m_aMutex ); + //after last + if( m_bAfterLast ) + return sal_False; + //last + aGuard.clear(); + if( isLast() ) + { + aGuard.reacquire(); + m_nRow++; + m_bAfterLast = sal_True; + return sal_False; + } + aGuard.reacquire(); + //known valid position + if( impl_isKnownValidPosition( m_nRow + 1 ) ) + { + m_nRow++; + return sal_True; + } + + //unknown position + sal_Int32 nRow = m_nRow; + aGuard.clear(); + + sal_Bool bValid = applyPositionToOrigin( nRow + 1 ); + + aGuard.reacquire(); + m_nRow = nRow + 1; + m_bAfterLast = !bValid; + return bValid; +} + +//virtual +sal_Bool SAL_CALL CachedContentResultSet + ::previous() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( impl_isForwardOnly() ) + throw SQLException(); + + ReacquireableGuard aGuard( m_aMutex ); + //before first ?: + if( !m_bAfterLast && !m_nRow ) + return sal_False; + //first ?: + if( !m_bAfterLast && m_nKnownCount && m_nRow == 1 ) + { + m_nRow--; + m_bAfterLast = sal_False; + return sal_False; + } + //known valid position ?: + if( impl_isKnownValidPosition( m_nRow - 1 ) ) + { + m_nRow--; + m_bAfterLast = sal_False; + return sal_True; + } + //unknown position: + sal_Int32 nRow = m_nRow; + aGuard.clear(); + + sal_Bool bValid = applyPositionToOrigin( nRow - 1 ); + + aGuard.reacquire(); + m_nRow = nRow - 1; + m_bAfterLast = sal_False; + return bValid; +} + +//virtual +sal_Bool SAL_CALL CachedContentResultSet + ::absolute( sal_Int32 row ) + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( !row ) + throw SQLException(); + + if( impl_isForwardOnly() ) + throw SQLException(); + + ReacquireableGuard aGuard( m_aMutex ); + + if( !m_xResultSetOrigin.is() ) + { + DBG_ERROR( "broadcaster was disposed already" ); + return sal_False; + } + if( row < 0 ) + { + if( m_bFinalCount ) + { + sal_Int32 nNewRow = m_nKnownCount + 1 + row; + sal_Bool bValid = sal_True; + if( nNewRow <= 0 ) + { + nNewRow = 0; + bValid = sal_False; + } + m_nRow = nNewRow; + m_bAfterLast = sal_False; + return bValid; + } + //unknown final count: + aGuard.clear(); + + sal_Bool bValid = m_xResultSetOrigin->absolute( row ); + + aGuard.reacquire(); + if( m_bFinalCount ) + { + sal_Int32 nNewRow = m_nKnownCount + 1 + row; + if( nNewRow < 0 ) + nNewRow = 0; + m_nLastAppliedPos = nNewRow; + m_nRow = nNewRow; + m_bAfterLastApplied = m_bAfterLast = sal_False; + return bValid; + } + aGuard.clear(); + + sal_Int32 nCurRow = m_xResultSetOrigin->getRow(); + + aGuard.reacquire(); + m_nLastAppliedPos = nCurRow; + m_nRow = nCurRow; + m_bAfterLast = sal_False; + return nCurRow; + } + //row > 0: + if( m_bFinalCount ) + { + if( row > m_nKnownCount ) + { + m_nRow = m_nKnownCount + 1; + m_bAfterLast = sal_True; + return sal_False; + } + m_nRow = row; + m_bAfterLast = sal_False; + return sal_True; + } + //unknown new position: + aGuard.clear(); + + sal_Bool bValid = m_xResultSetOrigin->absolute( row ); + + aGuard.reacquire(); + if( m_bFinalCount ) + { + sal_Int32 nNewRow = row; + if( nNewRow > m_nKnownCount ) + { + nNewRow = m_nKnownCount + 1; + m_bAfterLastApplied = m_bAfterLast = sal_True; + } + else + m_bAfterLastApplied = m_bAfterLast = sal_False; + + m_nLastAppliedPos = nNewRow; + m_nRow = nNewRow; + return bValid; + } + aGuard.clear(); + + sal_Int32 nCurRow = m_xResultSetOrigin->getRow(); + sal_Bool bIsAfterLast = m_xResultSetOrigin->isAfterLast(); + + aGuard.reacquire(); + m_nLastAppliedPos = nCurRow; + m_nRow = nCurRow; + m_bAfterLastApplied = m_bAfterLast = bIsAfterLast; + return nCurRow && !bIsAfterLast; +} + +//virtual +sal_Bool SAL_CALL CachedContentResultSet + ::relative( sal_Int32 rows ) + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( impl_isForwardOnly() ) + throw SQLException(); + + ReacquireableGuard aGuard( m_aMutex ); + if( m_bAfterLast || impl_isKnownInvalidPosition( m_nRow ) ) + throw SQLException(); + + if( !rows ) + return sal_True; + + sal_Int32 nNewRow = m_nRow + rows; + if( nNewRow < 0 ) + nNewRow = 0; + + if( impl_isKnownValidPosition( nNewRow ) ) + { + m_nRow = nNewRow; + m_bAfterLast = sal_False; + return sal_True; + } + else + { + //known invalid new position: + if( nNewRow == 0 ) + { + m_bAfterLast = sal_False; + m_nRow = 0; + return sal_False; + } + if( m_bFinalCount && nNewRow > m_nKnownCount ) + { + m_bAfterLast = sal_True; + m_nRow = m_nKnownCount + 1; + return sal_False; + } + //unknown new position: + aGuard.clear(); + sal_Bool bValid = applyPositionToOrigin( nNewRow ); + + aGuard.reacquire(); + m_nRow = nNewRow; + m_bAfterLast = !bValid && nNewRow > 0; + return bValid; + } +} + + +//virtual +sal_Bool SAL_CALL CachedContentResultSet + ::first() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( impl_isForwardOnly() ) + throw SQLException(); + + ReacquireableGuard aGuard( m_aMutex ); + if( impl_isKnownValidPosition( 1 ) ) + { + m_nRow = 1; + m_bAfterLast = sal_False; + return sal_True; + } + if( impl_isKnownInvalidPosition( 1 ) ) + { + m_nRow = 1; + m_bAfterLast = sal_False; + return sal_False; + } + //unknown position + aGuard.clear(); + + sal_Bool bValid = applyPositionToOrigin( 1 ); + + aGuard.reacquire(); + m_nRow = 1; + m_bAfterLast = sal_False; + return bValid; +} + +//virtual +sal_Bool SAL_CALL CachedContentResultSet + ::last() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( impl_isForwardOnly() ) + throw SQLException(); + + ReacquireableGuard aGuard( m_aMutex ); + if( m_bFinalCount ) + { + m_nRow = m_nKnownCount; + m_bAfterLast = sal_False; + return m_nKnownCount; + } + //unknown position + if( !m_xResultSetOrigin.is() ) + { + DBG_ERROR( "broadcaster was disposed already" ); + return sal_False; + } + aGuard.clear(); + + sal_Bool bValid = m_xResultSetOrigin->last(); + + aGuard.reacquire(); + m_bAfterLastApplied = m_bAfterLast = sal_False; + if( m_bFinalCount ) + { + m_nLastAppliedPos = m_nKnownCount; + m_nRow = m_nKnownCount; + return bValid; + } + aGuard.clear(); + + sal_Int32 nCurRow = m_xResultSetOrigin->getRow(); + + aGuard.reacquire(); + m_nLastAppliedPos = nCurRow; + m_nRow = nCurRow; + DBG_ASSERT( nCurRow >= m_nKnownCount, "position of last row < known Count, that could not be" ); + m_nKnownCount = nCurRow; + m_bFinalCount = sal_True; + return nCurRow; +} + +//virtual +void SAL_CALL CachedContentResultSet + ::beforeFirst() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( impl_isForwardOnly() ) + throw SQLException(); + + vos::OGuard aGuard( m_aMutex ); + m_nRow = 0; + m_bAfterLast = sal_False; +} + +//virtual +void SAL_CALL CachedContentResultSet + ::afterLast() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( impl_isForwardOnly() ) + throw SQLException(); + + vos::OGuard aGuard( m_aMutex ); + m_nRow = 1; + m_bAfterLast = sal_True; +} + +//virtual +sal_Bool SAL_CALL CachedContentResultSet + ::isAfterLast() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + ReacquireableGuard aGuard( m_aMutex ); + if( !m_bAfterLast ) + return sal_False; + if( m_nKnownCount ) + return m_bAfterLast; + if( m_bFinalCount ) + return sal_False; + + if( !m_xResultSetOrigin.is() ) + { + DBG_ERROR( "broadcaster was disposed already" ); + return sal_False; + } + aGuard.clear(); + + //find out whethter the original resultset contains rows or not + m_xResultSetOrigin->afterLast(); + + aGuard.reacquire(); + m_bAfterLastApplied = sal_True; + aGuard.clear(); + + return m_xResultSetOrigin->isAfterLast(); +} + +//virtual +sal_Bool SAL_CALL CachedContentResultSet + ::isBeforeFirst() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + ReacquireableGuard aGuard( m_aMutex ); + if( m_bAfterLast ) + return sal_False; + if( m_nRow ) + return sal_False; + if( m_nKnownCount ) + return !m_nRow; + if( m_bFinalCount ) + return sal_False; + + if( !m_xResultSetOrigin.is() ) + { + DBG_ERROR( "broadcaster was disposed already" ); + return sal_False; + } + aGuard.clear(); + + //find out whethter the original resultset contains rows or not + m_xResultSetOrigin->beforeFirst(); + + aGuard.reacquire(); + m_bAfterLastApplied = sal_False; + m_nLastAppliedPos = 0; + aGuard.clear(); + + return m_xResultSetOrigin->isBeforeFirst(); +} + +//virtual +sal_Bool SAL_CALL CachedContentResultSet + ::isFirst() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + sal_Int32 nRow; + Reference< XResultSet > xResultSetOrigin; + + { + vos::OGuard aGuard( m_aMutex ); + if( m_bAfterLast ) + return sal_False; + if( m_nRow != 1 ) + return sal_False; + if( m_nKnownCount ) + return m_nRow == 1; + if( m_bFinalCount ) + return sal_False; + + nRow = m_nRow; + xResultSetOrigin = m_xResultSetOrigin; + } + + //need to ask origin + { + if( applyPositionToOrigin( nRow ) ) + return xResultSetOrigin->isFirst(); + else + return sal_False; + } +} + +//virtual +sal_Bool SAL_CALL CachedContentResultSet + ::isLast() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + sal_Int32 nRow; + Reference< XResultSet > xResultSetOrigin; + { + vos::OGuard aGuard( m_aMutex ); + if( m_bAfterLast ) + return sal_False; + if( m_nRow < m_nKnownCount ) + return sal_False; + if( m_bFinalCount ) + return m_nKnownCount && m_nRow == m_nKnownCount; + + nRow = m_nRow; + xResultSetOrigin = m_xResultSetOrigin; + } + + //need to ask origin + { + if( applyPositionToOrigin( nRow ) ) + return xResultSetOrigin->isLast(); + else + return sal_False; + } +} + + +//virtual +sal_Int32 SAL_CALL CachedContentResultSet + ::getRow() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + vos::OGuard aGuard( m_aMutex ); + if( m_bAfterLast ) + return 0; + return m_nRow; +} + +//virtual +void SAL_CALL CachedContentResultSet + ::refreshRow() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + //the ContentResultSet is static and will not change + //therefore we don't need to reload anything +} + +//virtual +sal_Bool SAL_CALL CachedContentResultSet + ::rowUpdated() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + //the ContentResultSet is static and will not change + return sal_False; +} +//virtual +sal_Bool SAL_CALL CachedContentResultSet + ::rowInserted() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + //the ContentResultSet is static and will not change + return sal_False; +} + +//virtual +sal_Bool SAL_CALL CachedContentResultSet + ::rowDeleted() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + //the ContentResultSet is static and will not change + return sal_False; +} + +//virtual +Reference< XInterface > SAL_CALL CachedContentResultSet + ::getStatement() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + //@todo ?return anything + return Reference< XInterface >(); +} + +//----------------------------------------------------------------- +// XRow methods. ( inherited ) +//----------------------------------------------------------------- + +//virtual +sal_Bool SAL_CALL CachedContentResultSet + ::wasNull() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + { + vos::OGuard aGuard( m_aMutex ); + if( m_bLastReadWasFromCache ) + return m_bLastCachedReadWasNull; + if( !m_xRowOrigin.is() ) + { + DBG_ERROR( "broadcaster was disposed already" ); + return sal_False; + } + } + return m_xRowOrigin->wasNull(); +} + +//virtual +rtl::OUString SAL_CALL CachedContentResultSet + ::getString( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getString, OUString ); +} + +//virtual +sal_Bool SAL_CALL CachedContentResultSet + ::getBoolean( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getBoolean, sal_Bool ); +} + +//virtual +sal_Int8 SAL_CALL CachedContentResultSet + ::getByte( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getByte, sal_Int8 ); +} + +//virtual +sal_Int16 SAL_CALL CachedContentResultSet + ::getShort( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getShort, sal_Int16 ); +} + +//virtual +sal_Int32 SAL_CALL CachedContentResultSet + ::getInt( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getInt, sal_Int32 ); +} + +//virtual +sal_Int64 SAL_CALL CachedContentResultSet + ::getLong( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getLong, sal_Int64 ); +} + +//virtual +float SAL_CALL CachedContentResultSet + ::getFloat( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getFloat, float ); +} + +//virtual +double SAL_CALL CachedContentResultSet + ::getDouble( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getDouble, double ); +} + +//virtual +Sequence< sal_Int8 > SAL_CALL CachedContentResultSet + ::getBytes( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getBytes, Sequence< sal_Int8 > ); +} + +//virtual +Date SAL_CALL CachedContentResultSet + ::getDate( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getDate, Date ); +} + +//virtual +Time SAL_CALL CachedContentResultSet + ::getTime( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getTime, Time ); +} + +//virtual +DateTime SAL_CALL CachedContentResultSet + ::getTimestamp( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getTimestamp, DateTime ); +} + +//virtual +Reference< com::sun::star::io::XInputStream > + SAL_CALL CachedContentResultSet + ::getBinaryStream( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getBinaryStream, Reference< com::sun::star::io::XInputStream > ); +} + +//virtual +Reference< com::sun::star::io::XInputStream > + SAL_CALL CachedContentResultSet + ::getCharacterStream( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getCharacterStream, Reference< com::sun::star::io::XInputStream > ); +} + +//virtual +Any SAL_CALL CachedContentResultSet + ::getObject( sal_Int32 columnIndex, + const Reference< + com::sun::star::container::XNameAccess >& typeMap ) + throw( SQLException, + RuntimeException ) +{ + //if you change this macro please pay attention to + //define XROW_GETXXX, where this is similar implemented + + ReacquireableGuard aGuard( m_aMutex ); + sal_Int32 nRow = m_nRow; + sal_Int32 nFetchSize = m_nFetchSize; + sal_Int32 nFetchDirection = m_nFetchDirection; + if( !m_aCache.hasRow( nRow ) ) + { + if( !m_aCache.hasCausedException( nRow ) ) + { + if( !m_xFetchProvider.is() ) + { + DBG_ERROR( "broadcaster was disposed already" ); + return Any(); + } + aGuard.clear(); + + impl_fetchData( nRow, nFetchSize, nFetchDirection ); + } + aGuard.reacquire(); + if( !m_aCache.hasRow( nRow ) ) + { + m_bLastReadWasFromCache = sal_False; + aGuard.clear(); + applyPositionToOrigin( nRow ); + return m_xRowOrigin->getObject( columnIndex, typeMap ); + } + } + //@todo: pay attention to typeMap + DBG_ASSERTWARNING( !typeMap.is(), "special TypeMaps are not supported" ); + const Any& rValue = m_aCache.getAny( nRow, columnIndex ); + Any aRet; + m_bLastReadWasFromCache = sal_True; + m_bLastCachedReadWasNull = !( rValue >>= aRet ); + return aRet; +} + +//virtual +Reference< XRef > SAL_CALL CachedContentResultSet + ::getRef( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getRef, Reference< XRef > ); +} + +//virtual +Reference< XBlob > SAL_CALL CachedContentResultSet + ::getBlob( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getBlob, Reference< XBlob > ); +} + +//virtual +Reference< XClob > SAL_CALL CachedContentResultSet + ::getClob( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getClob, Reference< XClob > ); +} + +//virtual +Reference< XArray > SAL_CALL CachedContentResultSet + ::getArray( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getArray, Reference< XArray > ); +} + + +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- +// class CachedContentResultSetFactory +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- + +CachedContentResultSetFactory::CachedContentResultSetFactory( + const Reference< XMultiServiceFactory > & rSMgr ) +{ + m_xSMgr = rSMgr; +} + +CachedContentResultSetFactory::~CachedContentResultSetFactory() +{ +} + +//-------------------------------------------------------------------------- +// CachedContentResultSetFactory XInterface methods. +//-------------------------------------------------------------------------- + +XINTERFACE_IMPL_3( CachedContentResultSetFactory, + XTypeProvider, + XServiceInfo, + XCachedContentResultSetFactory ); + +//-------------------------------------------------------------------------- +// CachedContentResultSetFactory XTypeProvider methods. +//-------------------------------------------------------------------------- + +XTYPEPROVIDER_IMPL_3( CachedContentResultSetFactory, + XTypeProvider, + XServiceInfo, + XCachedContentResultSetFactory ); + +//-------------------------------------------------------------------------- +// CachedContentResultSetFactory XServiceInfo methods. +//-------------------------------------------------------------------------- + +XSERVICEINFO_IMPL_1( CachedContentResultSetFactory, + OUString::createFromAscii( "CachedContentResultSetFactory" ), + OUString::createFromAscii( CACHED_CONTENT_RESULTSET_FACTORY_NAME ) ); + +//-------------------------------------------------------------------------- +// Service factory implementation. +//-------------------------------------------------------------------------- + +ONE_INSTANCE_SERVICE_FACTORY_IMPL( CachedContentResultSetFactory ); + +//-------------------------------------------------------------------------- +// CachedContentResultSetFactory XCachedContentResultSetFactory methods. +//-------------------------------------------------------------------------- + + //virtual +Reference< XResultSet > SAL_CALL CachedContentResultSetFactory + ::createCachedContentResultSet( + const Reference< XResultSet > & xSource, + const Reference< XContentIdentifierMapping > & xMapping ) + throw( com::sun::star::uno::RuntimeException ) +{ + Reference< XResultSet > xRet; + xRet = new CachedContentResultSet( xSource, xMapping ); + return xRet; +} + diff --git a/ucb/source/cacher/cachedcontentresultset.hxx b/ucb/source/cacher/cachedcontentresultset.hxx new file mode 100644 index 000000000000..0ef978b82e30 --- /dev/null +++ b/ucb/source/cacher/cachedcontentresultset.hxx @@ -0,0 +1,560 @@ +/************************************************************************* + * + * $RCSfile: cachedcontentresultset.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:52:35 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CACHED_CONTENT_RESULTSET_HXX +#define _CACHED_CONTENT_RESULTSET_HXX + +#ifndef _CONTENT_RESULTSET_WRAPPER_HXX +#include <contentresultsetwrapper.hxx> +#endif + +#ifndef _COM_SUN_STAR_LANG_XTYPEPROVIDER_HPP_ +#include <com/sun/star/lang/XTypeProvider.hpp> +#endif + +#ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_ +#include <com/sun/star/lang/XServiceInfo.hpp> +#endif + +#ifndef _COM_SUN_STAR_UCB_XFETCHPROVIDER_HPP_ +#include <com/sun/star/ucb/XFetchProvider.hpp> +#endif + +#ifndef _COM_SUN_STAR_UCB_XFETCHPROVIDERFORCONTENTACCESS_HPP_ +#include <com/sun/star/ucb/XFetchProviderForContentAccess.hpp> +#endif + +#ifndef _COM_SUN_STAR_UCB_FETCHRESULT_HPP_ +#include <com/sun/star/ucb/FetchResult.hpp> +#endif + +#ifndef _COM_SUN_STAR_UCB_XCONTENTIDENTIFIERMAPPING_HPP_ +#include <com/sun/star/ucb/XContentIdentifierMapping.hpp> +#endif + +#ifndef _COM_SUN_STAR_UCB_XCACHEDCONTENTRESULTSETFACTORY_HPP_ +#include <com/sun/star/ucb/XCachedContentResultSetFactory.hpp> +#endif + +#define CACHED_CONTENT_RESULTSET_SERVICE_NAME "com.sun.star.ucb.CachedContentResultSet" +#define CACHED_CONTENT_RESULTSET_FACTORY_NAME "com.sun.star.ucb.CachedContentResultSetFactory" + +//========================================================================= + +class CCRS_PropertySetInfo; +class CachedContentResultSet + : public ContentResultSetWrapper + , public com::sun::star::lang::XTypeProvider + , public com::sun::star::lang::XServiceInfo +{ + //-------------------------------------------------------------------------- + // class CCRS_Cache + + class CCRS_Cache + { + private: + com::sun::star::ucb::FetchResult* m_pResult; + com::sun::star::uno::Reference< + com::sun::star::ucb::XContentIdentifierMapping > + m_xContentIdentifierMapping; + com::sun::star::uno::Sequence< sal_Bool >* m_pMappedReminder; + + private: + com::sun::star::uno::Any& SAL_CALL + getRowAny( sal_Int32 nRow ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + void SAL_CALL clear(); + + + void SAL_CALL remindMapped( sal_Int32 nRow ); + sal_Bool SAL_CALL isRowMapped( sal_Int32 nRow ); + void SAL_CALL clearMappedReminder(); + com::sun::star::uno::Sequence< sal_Bool >* SAL_CALL getMappedReminder(); + + public: + CCRS_Cache( const com::sun::star::uno::Reference< + com::sun::star::ucb::XContentIdentifierMapping > & xMapping ); + ~CCRS_Cache(); + + void SAL_CALL loadData( + const com::sun::star::ucb::FetchResult& rResult ); + + sal_Bool SAL_CALL + hasRow( sal_Int32 nRow ); + + sal_Bool SAL_CALL + hasCausedException( sal_Int32 nRow ); + + sal_Int32 SAL_CALL + getMaxRow(); + + sal_Bool SAL_CALL + hasKnownLast(); + + //--- + const com::sun::star::uno::Any& SAL_CALL + getAny( sal_Int32 nRow, sal_Int32 nColumnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + const rtl::OUString& SAL_CALL + getContentIdentifierString( sal_Int32 nRow ) + throw( com::sun::star::uno::RuntimeException ); + + const com::sun::star::uno::Reference< + com::sun::star::ucb::XContentIdentifier >& SAL_CALL + getContentIdentifier( sal_Int32 nRow ) + throw( com::sun::star::uno::RuntimeException ); + + const com::sun::star::uno::Reference< + com::sun::star::ucb::XContent >& SAL_CALL + getContent( sal_Int32 nRow ) + throw( com::sun::star::uno::RuntimeException ); + }; + //----------------------------------------------------------------- + //members + + //different Interfaces from Origin: + com::sun::star::uno::Reference< com::sun::star::ucb::XFetchProvider > + m_xFetchProvider; //XFetchProvider-interface from m_xOrigin + + com::sun::star::uno::Reference< com::sun::star::ucb::XFetchProviderForContentAccess > + m_xFetchProviderForContentAccess; //XFetchProviderForContentAccess-interface from m_xOrigin + + //my PropertySetInfo + com::sun::star::uno::Reference< com::sun::star::beans::XPropertySetInfo > + m_xMyPropertySetInfo;//holds m_pMyPropSetInfo alive + CCRS_PropertySetInfo* m_pMyPropSetInfo; + + + // + com::sun::star::uno::Reference< com::sun::star::ucb::XContentIdentifierMapping > + m_xContentIdentifierMapping;// can be used for remote optimized ContentAccess + + //some Properties and helping variables + sal_Int32 m_nRow; + sal_Bool m_bAfterLast; // TRUE, if m_nRow is after final count; can be TRUE without knowing the exact final count + + sal_Int32 m_nLastAppliedPos; + sal_Bool m_bAfterLastApplied; + + sal_Int32 m_nKnownCount; // count we know from the Origin + sal_Bool m_bFinalCount; // TRUE if the Origin has reached final count and we got that count in m_nKnownCount + + sal_Int32 m_nFetchSize; + sal_Int32 m_nFetchDirection; + + sal_Bool m_bLastReadWasFromCache; + sal_Bool m_bLastCachedReadWasNull; + + //cache: + CCRS_Cache m_aCache; + CCRS_Cache m_aCacheContentIdentifierString; + CCRS_Cache m_aCacheContentIdentifier; + CCRS_Cache m_aCacheContent; + + +private: + //----------------------------------------------------------------- + //helping XPropertySet methods. + virtual void SAL_CALL impl_initPropertySetInfo(); + + + //----------------------------------------------------------------- + sal_Bool SAL_CALL + applyPositionToOrigin( sal_Int32 nRow ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + sal_Bool SAL_CALL + applyPositionToOrigin() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + void SAL_CALL + impl_fetchData( sal_Int32 nRow, sal_Int32 nCount + , sal_Int32 nFetchDirection ) + throw( com::sun::star::uno::RuntimeException ); + + sal_Bool SAL_CALL + impl_isKnownValidPosition( sal_Int32 nRow ); + + sal_Bool SAL_CALL + impl_isKnownInvalidPosition( sal_Int32 nRow ); + + void SAL_CALL + impl_changeRowCount( sal_Int32 nOld, sal_Int32 nNew ); + + void SAL_CALL + impl_changeIsRowCountFinal( sal_Bool bOld, sal_Bool bNew ); + +public: + CachedContentResultSet( com::sun::star::uno::Reference< + com::sun::star::sdbc::XResultSet > xOrigin, + com::sun::star::uno::Reference< + com::sun::star::ucb::XContentIdentifierMapping > + xContentIdentifierMapping ); + + virtual ~CachedContentResultSet(); + + //----------------------------------------------------------------- + // XInterface inherited + //----------------------------------------------------------------- + XINTERFACE_DECL() + //----------------------------------------------------------------- + // XTypeProvider + //----------------------------------------------------------------- + XTYPEPROVIDER_DECL() + //----------------------------------------------------------------- + // XServiceInfo + //----------------------------------------------------------------- + XSERVICEINFO_NOFACTORY_DECL() + + //----------------------------------------------------------------- + // XPropertySet inherited + //----------------------------------------------------------------- + + virtual void SAL_CALL + setPropertyValue( const rtl::OUString& aPropertyName, + const com::sun::star::uno::Any& aValue ) + throw( com::sun::star::beans::UnknownPropertyException, + com::sun::star::beans::PropertyVetoException, + com::sun::star::lang::IllegalArgumentException, + com::sun::star::lang::WrappedTargetException, + com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::uno::Any SAL_CALL + getPropertyValue( const rtl::OUString& PropertyName ) + throw( com::sun::star::beans::UnknownPropertyException, + com::sun::star::lang::WrappedTargetException, + com::sun::star::uno::RuntimeException ); + + //----------------------------------------------------------------- + // own inherited + //----------------------------------------------------------------- + virtual void SAL_CALL + impl_disposing( const com::sun::star::lang::EventObject& Source ) + throw( com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL + impl_propertyChange( const com::sun::star::beans::PropertyChangeEvent& evt ) + throw( com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL + impl_vetoableChange( const com::sun::star::beans::PropertyChangeEvent& aEvent ) + throw( com::sun::star::beans::PropertyVetoException, + com::sun::star::uno::RuntimeException ); + + //----------------------------------------------------------------- + // XContentAccess inherited + //----------------------------------------------------------------- + virtual rtl::OUString SAL_CALL + queryContentIdentfierString() + throw( com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::uno::Reference< + com::sun::star::ucb::XContentIdentifier > SAL_CALL + queryContentIdentifier() + throw( com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::uno::Reference< + com::sun::star::ucb::XContent > SAL_CALL + queryContent() + throw( com::sun::star::uno::RuntimeException ); + + //----------------------------------------------------------------- + // XResultSet inherited + //----------------------------------------------------------------- + virtual sal_Bool SAL_CALL + next() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL + isBeforeFirst() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL + isAfterLast() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL + isFirst() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL + isLast() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual void SAL_CALL + beforeFirst() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual void SAL_CALL + afterLast() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL + first() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL + last() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual sal_Int32 SAL_CALL + getRow() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL + absolute( sal_Int32 row ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL + relative( sal_Int32 rows ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL + previous() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual void SAL_CALL + refreshRow() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL + rowUpdated() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL + rowInserted() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL + rowDeleted() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual com::sun::star::uno::Reference< + com::sun::star::uno::XInterface > SAL_CALL + getStatement() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + //----------------------------------------------------------------- + // XRow inherited + //----------------------------------------------------------------- + virtual sal_Bool SAL_CALL + wasNull() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual rtl::OUString SAL_CALL + getString( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual sal_Bool SAL_CALL + getBoolean( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual sal_Int8 SAL_CALL + getByte( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual sal_Int16 SAL_CALL + getShort( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual sal_Int32 SAL_CALL + getInt( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual sal_Int64 SAL_CALL + getLong( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual float SAL_CALL + getFloat( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual double SAL_CALL + getDouble( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL + getBytes( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::util::Date SAL_CALL + getDate( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::util::Time SAL_CALL + getTime( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::util::DateTime SAL_CALL + getTimestamp( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::uno::Reference< + com::sun::star::io::XInputStream > SAL_CALL + getBinaryStream( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::uno::Reference< + com::sun::star::io::XInputStream > SAL_CALL + getCharacterStream( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::uno::Any SAL_CALL + getObject( sal_Int32 columnIndex, + const com::sun::star::uno::Reference< + com::sun::star::container::XNameAccess >& typeMap ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::uno::Reference< + com::sun::star::sdbc::XRef > SAL_CALL + getRef( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::uno::Reference< + com::sun::star::sdbc::XBlob > SAL_CALL + getBlob( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::uno::Reference< + com::sun::star::sdbc::XClob > SAL_CALL + getClob( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::uno::Reference< + com::sun::star::sdbc::XArray > SAL_CALL + getArray( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); +}; + +//========================================================================= + +class CachedContentResultSetFactory + : public cppu::OWeakObject + , public com::sun::star::lang::XTypeProvider + , public com::sun::star::lang::XServiceInfo + , public com::sun::star::ucb::XCachedContentResultSetFactory +{ +protected: + com::sun::star::uno::Reference< + com::sun::star::lang::XMultiServiceFactory > m_xSMgr; + +public: + + CachedContentResultSetFactory( + const com::sun::star::uno::Reference< + com::sun::star::lang::XMultiServiceFactory > & rSMgr); + + virtual ~CachedContentResultSetFactory(); + + //----------------------------------------------------------------- + // XInterface + XINTERFACE_DECL() + + //----------------------------------------------------------------- + // XTypeProvider + XTYPEPROVIDER_DECL() + + //----------------------------------------------------------------- + // XServiceInfo + XSERVICEINFO_DECL() + + //----------------------------------------------------------------- + // XCachedContentResultSetFactory + + virtual com::sun::star::uno::Reference< + com::sun::star::sdbc::XResultSet > SAL_CALL + createCachedContentResultSet( + const com::sun::star::uno::Reference< + com::sun::star::sdbc::XResultSet > & xSource, + const com::sun::star::uno::Reference< + com::sun::star::ucb::XContentIdentifierMapping > & xMapping ) + throw( com::sun::star::uno::RuntimeException ); +}; + +#endif + diff --git a/ucb/source/cacher/cachedcontentresultsetstub.cxx b/ucb/source/cacher/cachedcontentresultsetstub.cxx new file mode 100644 index 000000000000..5d20d2bce5ae --- /dev/null +++ b/ucb/source/cacher/cachedcontentresultsetstub.cxx @@ -0,0 +1,450 @@ +/************************************************************************* + * + * $RCSfile: cachedcontentresultsetstub.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:52:35 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include <cachedcontentresultsetstub.hxx> + +#ifndef _COM_SUN_STAR_UCB_FETCHERROR_HPP_ +#include <com/sun/star/ucb/FetchError.hpp> +#endif + +#ifndef _TOOLS_DEBUG_HXX +#include <tools/debug.hxx> +#endif + +using namespace com::sun::star::beans; +using namespace com::sun::star::lang; +using namespace com::sun::star::sdbc; +using namespace com::sun::star::ucb; +using namespace com::sun::star::uno; +using namespace com::sun::star::util; +using namespace cppu; +using namespace rtl; + +CachedContentResultSetStub::CachedContentResultSetStub( Reference< XResultSet > xOrigin ) + : ContentResultSetWrapper( xOrigin ) + , m_nColumnCount( 0 ) + , m_bColumnCountCached( sal_False ) +{ + impl_init(); +} + +CachedContentResultSetStub::~CachedContentResultSetStub() +{ + impl_deinit(); +} + +//-------------------------------------------------------------------------- +// XInterface methods. +//-------------------------------------------------------------------------- +XINTERFACE_COMMON_IMPL( CachedContentResultSetStub ) + +Any SAL_CALL CachedContentResultSetStub + ::queryInterface( const Type& rType ) + throw ( RuntimeException ) +{ + //list all interfaces inclusive baseclasses of interfaces + + Any aRet = ContentResultSetWrapper::queryInterface( rType ); + if( aRet.hasValue() ) + return aRet; + + aRet = cppu::queryInterface( rType + , static_cast< XTypeProvider* >( this ) + , static_cast< XServiceInfo* >( this ) + , static_cast< XFetchProvider* >( this ) + , static_cast< XFetchProviderForContentAccess* >( this ) + ); + + return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ); +} + +//-------------------------------------------------------------------------- +// XTypeProvider methods. +//-------------------------------------------------------------------------- + +XTYPEPROVIDER_COMMON_IMPL( CachedContentResultSetStub ) +//list all interfaces exclusive baseclasses +Sequence< Type > SAL_CALL CachedContentResultSetStub + ::getTypes() + throw( RuntimeException ) +{ + static Sequence< Type >* pTypes = NULL; + if( !pTypes ) + { + osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() ); + if( !pTypes ) + { + pTypes->realloc( 13 ); + (*pTypes)[0] = CPPU_TYPE_REF( XTypeProvider ); + (*pTypes)[1] = CPPU_TYPE_REF( XServiceInfo ); + (*pTypes)[2] = CPPU_TYPE_REF( XComponent ); + (*pTypes)[3] = CPPU_TYPE_REF( XCloseable ); + (*pTypes)[4] = CPPU_TYPE_REF( XResultSetMetaDataSupplier ); + (*pTypes)[5] = CPPU_TYPE_REF( XPropertySet ); + (*pTypes)[6] = CPPU_TYPE_REF( XPropertyChangeListener ); + (*pTypes)[7] = CPPU_TYPE_REF( XVetoableChangeListener ); + (*pTypes)[8] = CPPU_TYPE_REF( XResultSet ); + (*pTypes)[9] = CPPU_TYPE_REF( XContentAccess ); + (*pTypes)[10] = CPPU_TYPE_REF( XRow ); + (*pTypes)[11] = CPPU_TYPE_REF( XFetchProvider ); + (*pTypes)[12] = CPPU_TYPE_REF( XFetchProviderForContentAccess ); + } + } + return *pTypes; +} + +//-------------------------------------------------------------------------- +// XServiceInfo methods. +//-------------------------------------------------------------------------- + +XSERVICEINFO_NOFACTORY_IMPL_1( CachedContentResultSetStub, + OUString::createFromAscii( "CachedContentResultSetStub" ), + OUString::createFromAscii( CACHED_CRS_STUB_SERVICE_NAME ) ); + +//----------------------------------------------------------------- +// XFetchProvider methods. +//----------------------------------------------------------------- + +#define FETCH_XXX( impl_loadRow, loadInterface ) \ +impl_EnsureNotDisposed(); \ +if( !m_xResultSetOrigin.is() ) \ +{ \ + DBG_ERROR( "broadcaster was disposed already" ); \ + throw RuntimeException(); \ +} \ +FetchResult aRet; \ +aRet.StartIndex = nRowStartPosition; \ +aRet.Orientation = bDirection; \ +aRet.FetchError = FetchError::SUCCESS; /*ENDOFDATA, EXCEPTION*/ \ +sal_Int32 nOldOriginal_Pos = m_xResultSetOrigin->getRow(); \ +if( impl_isForwardOnly() ) \ +{ \ + if( nOldOriginal_Pos != nRowStartPosition ) \ + { \ + /*@todo*/ \ + aRet.FetchError = FetchError::EXCEPTION; \ + return aRet; \ + } \ + if( nRowCount != 1 ) \ + aRet.FetchError = FetchError::EXCEPTION; \ + \ + aRet.Rows.realloc( 1 ); \ + \ + try \ + { \ + impl_loadRow( aRet.Rows[0], loadInterface ); \ + } \ + catch( SQLException& ) \ + { \ + aRet.Rows.realloc( 0 ); \ + aRet.FetchError = FetchError::EXCEPTION; \ + return aRet; \ + } \ + return aRet; \ +} \ +aRet.Rows.realloc( nRowCount ); \ +sal_Bool bOldOriginal_AfterLast = sal_False; \ +if( !nOldOriginal_Pos ) \ + bOldOriginal_AfterLast = m_xResultSetOrigin->isAfterLast(); \ +sal_Int32 nN = 1; \ +sal_Bool bValidNewPos = sal_False; \ +try \ +{ \ + try \ + { \ + /*if( nOldOriginal_Pos != nRowStartPosition )*/ \ + bValidNewPos = m_xResultSetOrigin->absolute( nRowStartPosition ); \ + } \ + catch( SQLException& ) \ + { \ + aRet.Rows.realloc( 0 ); \ + aRet.FetchError = FetchError::EXCEPTION; \ + return aRet; \ + } \ + if( !bValidNewPos ) \ + { \ + aRet.Rows.realloc( 0 ); \ + aRet.FetchError = FetchError::EXCEPTION; \ + \ + /*restore old position*/ \ + if( nOldOriginal_Pos ) \ + m_xResultSetOrigin->absolute( nOldOriginal_Pos ); \ + else if( bOldOriginal_AfterLast ) \ + m_xResultSetOrigin->afterLast(); \ + else \ + m_xResultSetOrigin->beforeFirst(); \ + \ + return aRet; \ + } \ + for( ; nN <= nRowCount; ) \ + { \ + impl_loadRow( aRet.Rows[nN-1], loadInterface ); \ + nN++; \ + if( nN <= nRowCount ) \ + { \ + if( bDirection ) \ + { \ + if( !m_xResultSetOrigin->next() ) \ + { \ + aRet.Rows.realloc( nN-1 ); \ + aRet.FetchError = FetchError::ENDOFDATA; \ + break; \ + } \ + } \ + else \ + { \ + if( !m_xResultSetOrigin->previous() ) \ + { \ + aRet.Rows.realloc( nN-1 ); \ + aRet.FetchError = FetchError::ENDOFDATA; \ + break; \ + } \ + } \ + } \ + } \ +} \ +catch( SQLException& ) \ +{ \ + aRet.Rows.realloc( nN-1 ); \ + aRet.FetchError = FetchError::EXCEPTION; \ +} \ +/*restore old position*/ \ +if( nOldOriginal_Pos ) \ + m_xResultSetOrigin->absolute( nOldOriginal_Pos ); \ +else if( bOldOriginal_AfterLast ) \ + m_xResultSetOrigin->afterLast(); \ +else \ + m_xResultSetOrigin->beforeFirst(); \ +return aRet; + +FetchResult SAL_CALL CachedContentResultSetStub + ::fetch( sal_Int32 nRowStartPosition + , sal_Int32 nRowCount, sal_Bool bDirection ) + throw( RuntimeException ) +{ + FETCH_XXX( impl_getCurrentRowContent, m_xRowOrigin ); +} + +sal_Int32 SAL_CALL CachedContentResultSetStub + ::impl_getColumnCount() +{ + sal_Int32 nCount; + sal_Bool bCached; + { + vos::OGuard aGuard( m_aMutex ); + nCount = m_nColumnCount; + bCached = m_bColumnCountCached; + } + if( !bCached ) + { + try + { + Reference< XResultSetMetaData > xMetaData = getMetaData(); + if( xMetaData.is() ) + nCount = xMetaData->getColumnCount(); + } + catch( SQLException& ) + { + DBG_ERROR( "couldn't determine the column count" ); + nCount = 0; + } + } + vos::OGuard aGuard( m_aMutex ); + m_nColumnCount = nCount; + m_bColumnCountCached = sal_True; + return m_nColumnCount; +} + +void SAL_CALL CachedContentResultSetStub + ::impl_getCurrentRowContent( Any& rRowContent + , Reference< XRow > xRow ) + throw ( SQLException, RuntimeException ) +{ + sal_Int32 nCount = impl_getColumnCount(); + + Sequence< Any > aContent( nCount ); + for( sal_Int32 nN = 1; nN <= nCount; nN++ ) + { + aContent[nN-1] = xRow->getObject( nN, NULL ); + } + + rRowContent <<= aContent; +} + +//----------------------------------------------------------------- +// XFetchProviderForContentAccess methods. +//----------------------------------------------------------------- + +void SAL_CALL CachedContentResultSetStub + ::impl_getCurrentContentIdentifierString( Any& rAny + , Reference< XContentAccess > xContentAccess ) + throw ( RuntimeException ) +{ + rAny <<= xContentAccess->queryContentIdentfierString(); +} + +void SAL_CALL CachedContentResultSetStub + ::impl_getCurrentContentIdentifier( Any& rAny + , Reference< XContentAccess > xContentAccess ) + throw ( RuntimeException ) +{ + rAny <<= xContentAccess->queryContentIdentifier(); +} + +void SAL_CALL CachedContentResultSetStub + ::impl_getCurrentContent( Any& rAny + , Reference< XContentAccess > xContentAccess ) + throw ( RuntimeException ) +{ + rAny <<= xContentAccess->queryContent(); +} + +//virtual +FetchResult SAL_CALL CachedContentResultSetStub + ::fetchContentIdentifierStrings( sal_Int32 nRowStartPosition + , sal_Int32 nRowCount, sal_Bool bDirection ) + throw( com::sun::star::uno::RuntimeException ) +{ + FETCH_XXX( impl_getCurrentContentIdentifierString, m_xContentAccessOrigin ); +} + +//virtual +FetchResult SAL_CALL CachedContentResultSetStub + ::fetchContentIdentifiers( sal_Int32 nRowStartPosition + , sal_Int32 nRowCount, sal_Bool bDirection ) + throw( com::sun::star::uno::RuntimeException ) +{ + FETCH_XXX( impl_getCurrentContentIdentifier, m_xContentAccessOrigin ); +} + +//virtual +FetchResult SAL_CALL CachedContentResultSetStub + ::fetchContents( sal_Int32 nRowStartPosition + , sal_Int32 nRowCount, sal_Bool bDirection ) + throw( com::sun::star::uno::RuntimeException ) +{ + FETCH_XXX( impl_getCurrentContent, m_xContentAccessOrigin ); +} + +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- +// class CachedContentResultSetStubFactory +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- + +CachedContentResultSetStubFactory::CachedContentResultSetStubFactory( + const Reference< XMultiServiceFactory > & rSMgr ) +{ + m_xSMgr = rSMgr; +} + +CachedContentResultSetStubFactory::~CachedContentResultSetStubFactory() +{ +} + +//-------------------------------------------------------------------------- +// CachedContentResultSetStubFactory XInterface methods. +//-------------------------------------------------------------------------- + +XINTERFACE_IMPL_3( CachedContentResultSetStubFactory, + XTypeProvider, + XServiceInfo, + XCachedContentResultSetStubFactory ); + +//-------------------------------------------------------------------------- +// CachedContentResultSetStubFactory XTypeProvider methods. +//-------------------------------------------------------------------------- + +XTYPEPROVIDER_IMPL_3( CachedContentResultSetStubFactory, + XTypeProvider, + XServiceInfo, + XCachedContentResultSetStubFactory ); + +//-------------------------------------------------------------------------- +// CachedContentResultSetStubFactory XServiceInfo methods. +//-------------------------------------------------------------------------- + +XSERVICEINFO_IMPL_1( CachedContentResultSetStubFactory, + OUString::createFromAscii( "CachedContentResultSetStubFactory" ), + OUString::createFromAscii( CACHED_CRS_STUB_FACTORY_NAME ) ); + +//-------------------------------------------------------------------------- +// Service factory implementation. +//-------------------------------------------------------------------------- + +ONE_INSTANCE_SERVICE_FACTORY_IMPL( CachedContentResultSetStubFactory ); + +//-------------------------------------------------------------------------- +// CachedContentResultSetStubFactory XCachedContentResultSetStubFactory methods. +//-------------------------------------------------------------------------- + + //virtual +Reference< XResultSet > SAL_CALL CachedContentResultSetStubFactory + ::createCachedContentResultSetStub( + const Reference< XResultSet > & xSource ) + throw( RuntimeException ) +{ + Reference< XResultSet > xRet; + xRet = new CachedContentResultSetStub( xSource ); + return xRet; +} + + diff --git a/ucb/source/cacher/cachedcontentresultsetstub.hxx b/ucb/source/cacher/cachedcontentresultsetstub.hxx new file mode 100644 index 000000000000..550d78b19dd7 --- /dev/null +++ b/ucb/source/cacher/cachedcontentresultsetstub.hxx @@ -0,0 +1,229 @@ +/************************************************************************* + * + * $RCSfile: cachedcontentresultsetstub.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:52:35 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CACHED_CONTENT_RESULTSET_STUB_HXX +#define _CACHED_CONTENT_RESULTSET_STUB_HXX + +#ifndef _CONTENT_RESULTSET_WRAPPER_HXX +#include <contentresultsetwrapper.hxx> +#endif + +#ifndef _COM_SUN_STAR_LANG_XTYPEPROVIDER_HPP_ +#include <com/sun/star/lang/XTypeProvider.hpp> +#endif + +#ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_ +#include <com/sun/star/lang/XServiceInfo.hpp> +#endif + +#ifndef _COM_SUN_STAR_UCB_XFETCHPROVIDER_HPP_ +#include <com/sun/star/ucb/XFetchProvider.hpp> +#endif + +#ifndef _COM_SUN_STAR_UCB_XFETCHPROVIDERFORCONTENTACCESS_HPP_ +#include <com/sun/star/ucb/XFetchProviderForContentAccess.hpp> +#endif + +#ifndef _COM_SUN_STAR_UCB_XCACHEDCONTENTRESULTSETSTUBFACTORY_HPP_ +#include <com/sun/star/ucb/XCachedContentResultSetStubFactory.hpp> +#endif + +#define CACHED_CRS_STUB_SERVICE_NAME "com.sun.star.ucb.CachedContentResultSetStub" +#define CACHED_CRS_STUB_FACTORY_NAME "com.sun.star.ucb.CachedContentResultSetStubFactory" + +//========================================================================= + +class CachedContentResultSetStub + : public ContentResultSetWrapper + , public com::sun::star::lang::XTypeProvider + , public com::sun::star::lang::XServiceInfo + , public com::sun::star::ucb::XFetchProvider + , public com::sun::star::ucb::XFetchProviderForContentAccess +{ +private: + sal_Int32 m_nColumnCount; + sal_Int32 m_bColumnCountCached; + + void SAL_CALL + impl_getCurrentRowContent( + com::sun::star::uno::Any& rRowContent, + com::sun::star::uno::Reference< + com::sun::star::sdbc::XRow > xRow ) + throw ( com::sun::star::sdbc::SQLException + , com::sun::star::uno::RuntimeException ); + + sal_Int32 SAL_CALL + impl_getColumnCount(); + + void SAL_CALL + impl_getCurrentContentIdentifierString( + com::sun::star::uno::Any& rAny + , com::sun::star::uno::Reference< + com::sun::star::ucb::XContentAccess > xContentAccess ) + throw ( com::sun::star::uno::RuntimeException ); + + void SAL_CALL + impl_getCurrentContentIdentifier( + com::sun::star::uno::Any& rAny + , com::sun::star::uno::Reference< + com::sun::star::ucb::XContentAccess > xContentAccess ) + throw ( com::sun::star::uno::RuntimeException ); + + void SAL_CALL + impl_getCurrentContent( + com::sun::star::uno::Any& rAny + , com::sun::star::uno::Reference< + com::sun::star::ucb::XContentAccess > xContentAccess ) + throw ( com::sun::star::uno::RuntimeException ); + +public: + CachedContentResultSetStub( com::sun::star::uno::Reference< + com::sun::star::sdbc::XResultSet > xOrigin ); + + virtual ~CachedContentResultSetStub(); + + + //----------------------------------------------------------------- + // XInterface inherited + //----------------------------------------------------------------- + XINTERFACE_DECL() + //----------------------------------------------------------------- + // XTypeProvider + //----------------------------------------------------------------- + XTYPEPROVIDER_DECL() + //----------------------------------------------------------------- + // XServiceInfo + //----------------------------------------------------------------- + XSERVICEINFO_NOFACTORY_DECL() + + //----------------------------------------------------------------- + // XFetchProvider + //----------------------------------------------------------------- + + virtual com::sun::star::ucb::FetchResult SAL_CALL + fetch( sal_Int32 nRowStartPosition + , sal_Int32 nRowCount, sal_Bool bDirection ) + throw( com::sun::star::uno::RuntimeException ); + + //----------------------------------------------------------------- + // XFetchProviderForContentAccess + //----------------------------------------------------------------- + virtual com::sun::star::ucb::FetchResult SAL_CALL + fetchContentIdentifierStrings( sal_Int32 nRowStartPosition + , sal_Int32 nRowCount, sal_Bool bDirection ) + throw( com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::ucb::FetchResult SAL_CALL + fetchContentIdentifiers( sal_Int32 nRowStartPosition + , sal_Int32 nRowCount, sal_Bool bDirection ) + throw( com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::ucb::FetchResult SAL_CALL + fetchContents( sal_Int32 nRowStartPosition + , sal_Int32 nRowCount, sal_Bool bDirection ) + throw( com::sun::star::uno::RuntimeException ); +}; + +//========================================================================= + +class CachedContentResultSetStubFactory + : public cppu::OWeakObject + , public com::sun::star::lang::XTypeProvider + , public com::sun::star::lang::XServiceInfo + , public com::sun::star::ucb::XCachedContentResultSetStubFactory +{ +protected: + com::sun::star::uno::Reference< + com::sun::star::lang::XMultiServiceFactory > m_xSMgr; + +public: + + CachedContentResultSetStubFactory( + const com::sun::star::uno::Reference< + com::sun::star::lang::XMultiServiceFactory > & rSMgr); + + virtual ~CachedContentResultSetStubFactory(); + + //----------------------------------------------------------------- + // XInterface + XINTERFACE_DECL() + + //----------------------------------------------------------------- + // XTypeProvider + XTYPEPROVIDER_DECL() + + //----------------------------------------------------------------- + // XServiceInfo + XSERVICEINFO_DECL() + + //----------------------------------------------------------------- + // XCachedContentResultSetStubFactory + + virtual com::sun::star::uno::Reference< + com::sun::star::sdbc::XResultSet > SAL_CALL + createCachedContentResultSetStub( + const com::sun::star::uno::Reference< + com::sun::star::sdbc::XResultSet > & xSource ) + throw( com::sun::star::uno::RuntimeException ); +}; + +#endif + diff --git a/ucb/source/cacher/cacheddynamicresultset.cxx b/ucb/source/cacher/cacheddynamicresultset.cxx new file mode 100644 index 000000000000..e27a1e2d7bbc --- /dev/null +++ b/ucb/source/cacher/cacheddynamicresultset.cxx @@ -0,0 +1,242 @@ +/************************************************************************* + * + * $RCSfile: cacheddynamicresultset.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:52:35 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include <cacheddynamicresultset.hxx> + +#ifndef _COM_SUN_STAR_SDBC_XRESULTSET_HPP_ +#include <com/sun/star/sdbc/XResultSet.hpp> +#endif + +#ifndef _CACHED_CONTENT_RESULTSET_HXX +#include <cachedcontentresultset.hxx> +#endif + +#ifndef _TOOLS_DEBUG_HXX +#include <tools/debug.hxx> +#endif + +using namespace com::sun::star::lang; +using namespace com::sun::star::sdbc; +using namespace com::sun::star::ucb; +using namespace com::sun::star::uno; +using namespace rtl; + +CachedDynamicResultSet::CachedDynamicResultSet( + Reference< XDynamicResultSet > xOrigin + , const Reference< XContentIdentifierMapping > & xContentMapping + , const Reference< XMultiServiceFactory > & xSMgr ) + : DynamicResultSetWrapper( xOrigin, xSMgr ) + , m_xContentIdentifierMapping( xContentMapping ) +{ + impl_init(); +} + +CachedDynamicResultSet::~CachedDynamicResultSet() +{ + impl_deinit(); +} + +//virtual +void SAL_CALL CachedDynamicResultSet + ::impl_InitResultSetOne( const Reference< XResultSet >& xResultSet ) +{ + DynamicResultSetWrapper::impl_InitResultSetOne( xResultSet ); + DBG_ASSERT( m_xSourceResultOne.is(), "need source resultset" ) + + Reference< XResultSet > xCache( + new CachedContentResultSet( m_xSourceResultOne, m_xContentIdentifierMapping ) ); + + vos::OGuard aGuard( m_aMutex ); + m_xMyResultOne = xCache; +} + +//virtual +void SAL_CALL CachedDynamicResultSet + ::impl_InitResultSetTwo( const Reference< XResultSet >& xResultSet ) +{ + DynamicResultSetWrapper::impl_InitResultSetTwo( xResultSet ); + DBG_ASSERT( m_xSourceResultTwo.is(), "need source resultset" ) + + Reference< XResultSet > xCache( + new CachedContentResultSet( m_xSourceResultTwo, m_xContentIdentifierMapping ) ); + + vos::OGuard aGuard( m_aMutex ); + m_xMyResultTwo = xCache; +} + +//-------------------------------------------------------------------------- +// XInterface methods. +//-------------------------------------------------------------------------- +XINTERFACE_COMMON_IMPL( CachedDynamicResultSet ) + +Any SAL_CALL CachedDynamicResultSet + ::queryInterface( const Type& rType ) + throw ( RuntimeException ) +{ + //list all interfaces inclusive baseclasses of interfaces + + Any aRet = DynamicResultSetWrapper::queryInterface( rType ); + if( aRet.hasValue() ) + return aRet; + + aRet = cppu::queryInterface( rType, + static_cast< XTypeProvider* >( this ) + , static_cast< XServiceInfo* >( this ) + ); + return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ); +} + +//-------------------------------------------------------------------------- +// XTypeProvider methods. +//-------------------------------------------------------------------------- +//list all interfaces exclusive baseclasses +XTYPEPROVIDER_IMPL_4( CachedDynamicResultSet + , XTypeProvider + , XServiceInfo + , XDynamicResultSet + , XSourceInitialization + ); + +//-------------------------------------------------------------------------- +// XServiceInfo methods. +//-------------------------------------------------------------------------- + +XSERVICEINFO_NOFACTORY_IMPL_1( CachedDynamicResultSet, + OUString::createFromAscii( "CachedDynamicResultSet" ), + OUString::createFromAscii( CACHED_DRS_SERVICE_NAME ) ); + +//-------------------------------------------------------------------------- +// own methds. ( inherited ) +//-------------------------------------------------------------------------- +//virtual +void SAL_CALL CachedDynamicResultSet + ::impl_disposing( const EventObject& Source ) + throw( RuntimeException ) +{ + DynamicResultSetWrapper::impl_disposing( Source ); + m_xContentIdentifierMapping.clear(); +} + +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- +// class CachedDynamicResultSetFactory +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- + +CachedDynamicResultSetFactory::CachedDynamicResultSetFactory( + const Reference< XMultiServiceFactory > & rSMgr ) +{ + m_xSMgr = rSMgr; +} + +CachedDynamicResultSetFactory::~CachedDynamicResultSetFactory() +{ +} + +//-------------------------------------------------------------------------- +// CachedDynamicResultSetFactory XInterface methods. +//-------------------------------------------------------------------------- + +XINTERFACE_IMPL_3( CachedDynamicResultSetFactory, + XTypeProvider, + XServiceInfo, + XCachedDynamicResultSetFactory ); + +//-------------------------------------------------------------------------- +// CachedDynamicResultSetFactory XTypeProvider methods. +//-------------------------------------------------------------------------- + +XTYPEPROVIDER_IMPL_3( CachedDynamicResultSetFactory, + XTypeProvider, + XServiceInfo, + XCachedDynamicResultSetFactory ); + +//-------------------------------------------------------------------------- +// CachedDynamicResultSetFactory XServiceInfo methods. +//-------------------------------------------------------------------------- + +XSERVICEINFO_IMPL_1( CachedDynamicResultSetFactory, + OUString::createFromAscii( "CachedDynamicResultSetFactory" ), + OUString::createFromAscii( CACHED_DRS_FACTORY_NAME ) ); + +//-------------------------------------------------------------------------- +// Service factory implementation. +//-------------------------------------------------------------------------- + +ONE_INSTANCE_SERVICE_FACTORY_IMPL( CachedDynamicResultSetFactory ); + +//-------------------------------------------------------------------------- +// CachedDynamicResultSetFactory XCachedDynamicResultSetFactory methods. +//-------------------------------------------------------------------------- + +//virtual +Reference< XDynamicResultSet > SAL_CALL CachedDynamicResultSetFactory + ::createCachedDynamicResultSet( + const Reference< XDynamicResultSet > & SourceStub + , const Reference< XContentIdentifierMapping > & ContentIdentifierMapping ) + throw( RuntimeException ) +{ + Reference< XDynamicResultSet > xRet; + xRet = new CachedDynamicResultSet( SourceStub, ContentIdentifierMapping, m_xSMgr ); + return xRet; +} + + diff --git a/ucb/source/cacher/cacheddynamicresultset.hxx b/ucb/source/cacher/cacheddynamicresultset.hxx new file mode 100644 index 000000000000..af58c47b761d --- /dev/null +++ b/ucb/source/cacher/cacheddynamicresultset.hxx @@ -0,0 +1,179 @@ +/************************************************************************* + * + * $RCSfile: cacheddynamicresultset.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:52:35 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CACHED_DYNAMIC_RESULTSET_HXX +#define _CACHED_DYNAMIC_RESULTSET_HXX + +#ifndef _DYNAMIC_RESULTSET_WRAPPER_HXX +#include <dynamicresultsetwrapper.hxx> +#endif + +#ifndef _COM_SUN_STAR_UCB_XCONTENTIDENTIFIERMAPPING_HPP_ +#include <com/sun/star/ucb/XContentIdentifierMapping.hpp> +#endif + +#ifndef _COM_SUN_STAR_UCB_XCACHEDDYNAMICRESULTSETFACTORY_HPP_ +#include <com/sun/star/ucb/XCachedDynamicResultSetFactory.hpp> +#endif + +#define CACHED_DRS_SERVICE_NAME "com.sun.star.ucb.CachedDynamicResultSet" +#define CACHED_DRS_FACTORY_NAME "com.sun.star.ucb.CachedDynamicResultSetFactory" + +//========================================================================= + +class CachedDynamicResultSet + : public DynamicResultSetWrapper + , public com::sun::star::lang::XTypeProvider + , public com::sun::star::lang::XServiceInfo +{ + com::sun::star::uno::Reference< com::sun::star::ucb::XContentIdentifierMapping > + m_xContentIdentifierMapping; + +protected: + virtual void SAL_CALL + impl_InitResultSetOne( const com::sun::star::uno::Reference< + com::sun::star::sdbc::XResultSet >& xResultSet ); + virtual void SAL_CALL + impl_InitResultSetTwo( const com::sun::star::uno::Reference< + com::sun::star::sdbc::XResultSet >& xResultSet ); + +public: + CachedDynamicResultSet( com::sun::star::uno::Reference< + com::sun::star::ucb::XDynamicResultSet > xOrigin + , const com::sun::star::uno::Reference< + com::sun::star::ucb::XContentIdentifierMapping > & xContentMapping + , const com::sun::star::uno::Reference< + com::sun::star::lang::XMultiServiceFactory > & xSMgr ); + + virtual ~CachedDynamicResultSet(); + + + //----------------------------------------------------------------- + // XInterface inherited + //----------------------------------------------------------------- + XINTERFACE_DECL() + //----------------------------------------------------------------- + // XTypeProvider + //----------------------------------------------------------------- + XTYPEPROVIDER_DECL() + //----------------------------------------------------------------- + // XServiceInfo + //----------------------------------------------------------------- + XSERVICEINFO_NOFACTORY_DECL() + + //----------------------------------------------------------------- + // own methods ( inherited ) + //----------------------------------------------------------------- + virtual void SAL_CALL + impl_disposing( const com::sun::star::lang::EventObject& Source ) + throw( com::sun::star::uno::RuntimeException ); +}; + +//========================================================================= + +class CachedDynamicResultSetFactory + : public cppu::OWeakObject + , public com::sun::star::lang::XTypeProvider + , public com::sun::star::lang::XServiceInfo + , public com::sun::star::ucb::XCachedDynamicResultSetFactory +{ +protected: + com::sun::star::uno::Reference< + com::sun::star::lang::XMultiServiceFactory > m_xSMgr; + +public: + + CachedDynamicResultSetFactory( + const com::sun::star::uno::Reference< + com::sun::star::lang::XMultiServiceFactory > & rSMgr); + + virtual ~CachedDynamicResultSetFactory(); + + //----------------------------------------------------------------- + // XInterface + XINTERFACE_DECL() + + //----------------------------------------------------------------- + // XTypeProvider + XTYPEPROVIDER_DECL() + + //----------------------------------------------------------------- + // XServiceInfo + XSERVICEINFO_DECL() + + //----------------------------------------------------------------- + // XCachedDynamicResultSetFactory + + virtual com::sun::star::uno::Reference< + com::sun::star::ucb::XDynamicResultSet > SAL_CALL + createCachedDynamicResultSet( + const com::sun::star::uno::Reference< + com::sun::star::ucb::XDynamicResultSet > & + SourceStub + , const com::sun::star::uno::Reference< + com::sun::star::ucb::XContentIdentifierMapping > & + ContentIdentifierMapping + ) + throw( com::sun::star::uno::RuntimeException ); +}; + +#endif + diff --git a/ucb/source/cacher/cacheddynamicresultsetstub.cxx b/ucb/source/cacher/cacheddynamicresultsetstub.cxx new file mode 100644 index 000000000000..8cfc093976df --- /dev/null +++ b/ucb/source/cacher/cacheddynamicresultsetstub.cxx @@ -0,0 +1,278 @@ +/************************************************************************* + * + * $RCSfile: cacheddynamicresultsetstub.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:52:35 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include <cacheddynamicresultsetstub.hxx> + +#ifndef _COM_SUN_STAR_SDBC_XRESULTSET_HPP_ +#include <com/sun/star/sdbc/XResultSet.hpp> +#endif + +#ifndef _CACHED_CONTENT_RESULTSET_STUB_HXX +#include <cachedcontentresultsetstub.hxx> +#endif + +#ifndef _COM_SUN_STAR_UCB_CONTENTRESULTSETCAPABILITY_HPP_ +#include <com/sun/star/ucb/ContentResultSetCapability.hpp> +#endif + +#ifndef _COM_SUN_STAR_UCB_XSORTEDDYNAMICRESULTSETFACTORY_HPP_ +#include <com/sun/star/ucb/XSortedDynamicResultSetFactory.hpp> +#endif + +#ifndef _TOOLS_DEBUG_HXX +#include <tools/debug.hxx> +#endif + +using namespace com::sun::star::lang; +using namespace com::sun::star::sdbc; +using namespace com::sun::star::ucb; +using namespace com::sun::star::uno; +using namespace rtl; + +CachedDynamicResultSetStub::CachedDynamicResultSetStub( + Reference< XDynamicResultSet > xOrigin + , const Reference< XMultiServiceFactory > & xSMgr ) + : DynamicResultSetWrapper( xOrigin, xSMgr ) +{ + DBG_ASSERT( m_xSMgr.is(), "need Multiservicefactory to create stub" ); + impl_init(); +} + +CachedDynamicResultSetStub::~CachedDynamicResultSetStub() +{ + impl_deinit(); +} + +//virtual +void SAL_CALL CachedDynamicResultSetStub + ::impl_InitResultSetOne( const Reference< XResultSet >& xResultSet ) +{ + DynamicResultSetWrapper::impl_InitResultSetOne( xResultSet ); + DBG_ASSERT( m_xSourceResultOne.is(), "need source resultset" ) + + Reference< XResultSet > xStub( + new CachedContentResultSetStub( m_xSourceResultOne ) ); + + vos::OGuard aGuard( m_aMutex ); + m_xMyResultOne = xStub; +} + +//virtual +void SAL_CALL CachedDynamicResultSetStub + ::impl_InitResultSetTwo( const Reference< XResultSet >& xResultSet ) +{ + DynamicResultSetWrapper::impl_InitResultSetTwo( xResultSet ); + DBG_ASSERT( m_xSourceResultTwo.is(), "need source resultset" ) + + Reference< XResultSet > xStub( + new CachedContentResultSetStub( m_xSourceResultTwo ) ); + + vos::OGuard aGuard( m_aMutex ); + m_xMyResultTwo = xStub; +} + +//-------------------------------------------------------------------------- +// XInterface methods. +//-------------------------------------------------------------------------- +XINTERFACE_COMMON_IMPL( CachedDynamicResultSetStub ) + +Any SAL_CALL CachedDynamicResultSetStub + ::queryInterface( const Type& rType ) + throw ( RuntimeException ) +{ + //list all interfaces inclusive baseclasses of interfaces + + Any aRet = DynamicResultSetWrapper::queryInterface( rType ); + if( aRet.hasValue() ) + return aRet; + + aRet = cppu::queryInterface( rType, + static_cast< XTypeProvider* >( this ) + , static_cast< XServiceInfo* >( this ) + ); + return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ); +} + +//-------------------------------------------------------------------------- +// XTypeProvider methods. +//-------------------------------------------------------------------------- +//list all interfaces exclusive baseclasses +XTYPEPROVIDER_IMPL_5( CachedDynamicResultSetStub + , XTypeProvider + , XServiceInfo + , XDynamicResultSet + , XDynamicResultSetListener + , XSourceInitialization + ); + +//-------------------------------------------------------------------------- +// XServiceInfo methods. +//-------------------------------------------------------------------------- + +XSERVICEINFO_NOFACTORY_IMPL_1( CachedDynamicResultSetStub, + OUString::createFromAscii( "CachedDynamicResultSetStub" ), + OUString::createFromAscii( CACHED_DRS_STUB_SERVICE_NAME ) ); + +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- +// class CachedDynamicResultSetStubFactory +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- + +CachedDynamicResultSetStubFactory::CachedDynamicResultSetStubFactory( + const Reference< XMultiServiceFactory > & rSMgr ) +{ + m_xSMgr = rSMgr; +} + +CachedDynamicResultSetStubFactory::~CachedDynamicResultSetStubFactory() +{ +} + +//-------------------------------------------------------------------------- +// CachedDynamicResultSetStubFactory XInterface methods. +//-------------------------------------------------------------------------- + +XINTERFACE_IMPL_3( CachedDynamicResultSetStubFactory, + XTypeProvider, + XServiceInfo, + XCachedDynamicResultSetStubFactory ); + +//-------------------------------------------------------------------------- +// CachedDynamicResultSetStubFactory XTypeProvider methods. +//-------------------------------------------------------------------------- + +XTYPEPROVIDER_IMPL_3( CachedDynamicResultSetStubFactory, + XTypeProvider, + XServiceInfo, + XCachedDynamicResultSetStubFactory ); + +//-------------------------------------------------------------------------- +// CachedDynamicResultSetStubFactory XServiceInfo methods. +//-------------------------------------------------------------------------- + +XSERVICEINFO_IMPL_1( CachedDynamicResultSetStubFactory, + OUString::createFromAscii( "CachedDynamicResultSetStubFactory" ), + OUString::createFromAscii( CACHED_DRS_STUB_FACTORY_NAME ) ); + +//-------------------------------------------------------------------------- +// Service factory implementation. +//-------------------------------------------------------------------------- + +ONE_INSTANCE_SERVICE_FACTORY_IMPL( CachedDynamicResultSetStubFactory ); + +//-------------------------------------------------------------------------- +// CachedDynamicResultSetStubFactory XCachedDynamicResultSetStubFactory methods. +//-------------------------------------------------------------------------- + +//virtual +Reference< XDynamicResultSet > SAL_CALL CachedDynamicResultSetStubFactory + ::createCachedDynamicResultSetStub( + const Reference< XDynamicResultSet > & Source ) + throw( RuntimeException ) +{ + Reference< XDynamicResultSet > xRet; + xRet = new CachedDynamicResultSetStub( Source, m_xSMgr ); + return xRet; +} + +//virtual +void SAL_CALL CachedDynamicResultSetStubFactory + ::connectToCache( + const Reference< XDynamicResultSet > & Source + , const Reference< XDynamicResultSet > & TargetCache + , const Sequence< NumberedSortingInfo > & SortingInfo + , const Reference< XAnyCompareFactory > & CompareFactory + ) + throw ( ListenerAlreadySetException + , AlreadyInitializedException + , RuntimeException ) +{ + DBG_ASSERT( Source.is(), "a Source is needed" ); + DBG_ASSERT( TargetCache.is(), "a TargetCache is needed" ); + + Reference< XDynamicResultSet > xSource( Source ); + if( SortingInfo.getLength() && + !( xSource->getCapabilities() & ContentResultSetCapability::SORTED ) + ) + { + Reference< XSortedDynamicResultSetFactory > xSortFactory( + m_xSMgr->createInstance( OUString::createFromAscii( + "com.sun.star.ucb.SortedDynamicResultSetFactory" ) ), UNO_QUERY ); + if( xSortFactory.is() ) + { + Reference< XDynamicResultSet > xSorted( + xSortFactory->createSortedDynamicResultSet( + Source, SortingInfo, CompareFactory ) ); + if( xSorted.is() ) + xSource = xSorted; + } + } + + Reference< XDynamicResultSet > xStub( + new CachedDynamicResultSetStub( xSource, m_xSMgr ) ); + + Reference< XSourceInitialization > xTarget( TargetCache, UNO_QUERY ); + DBG_ASSERT( xTarget.is(), "Target must have interface XSourceInitialization" ); + + xTarget->setSource( xStub ); +} + diff --git a/ucb/source/cacher/cacheddynamicresultsetstub.hxx b/ucb/source/cacher/cacheddynamicresultsetstub.hxx new file mode 100644 index 000000000000..c6f19883600d --- /dev/null +++ b/ucb/source/cacher/cacheddynamicresultsetstub.hxx @@ -0,0 +1,175 @@ +/************************************************************************* + * + * $RCSfile: cacheddynamicresultsetstub.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:52:35 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CACHED_DYNAMIC_RESULTSET_STUB_HXX +#define _CACHED_DYNAMIC_RESULTSET_STUB_HXX + +#ifndef _DYNAMIC_RESULTSET_WRAPPER_HXX +#include <dynamicresultsetwrapper.hxx> +#endif + +#ifndef _COM_SUN_STAR_UCB_XCACHEDDYNAMICRESULTSETSTUBFACTORY_HPP_ +#include <com/sun/star/ucb/XCachedDynamicResultSetStubFactory.hpp> +#endif + +#define CACHED_DRS_STUB_SERVICE_NAME "com.sun.star.ucb.CachedDynamicResultSetStub" +#define CACHED_DRS_STUB_FACTORY_NAME "com.sun.star.ucb.CachedDynamicResultSetStubFactory" + +//========================================================================= + +class CachedDynamicResultSetStub + : public DynamicResultSetWrapper + , public com::sun::star::lang::XTypeProvider + , public com::sun::star::lang::XServiceInfo +{ +protected: + virtual void SAL_CALL + impl_InitResultSetOne( const com::sun::star::uno::Reference< + com::sun::star::sdbc::XResultSet >& xResultSet ); + virtual void SAL_CALL + impl_InitResultSetTwo( const com::sun::star::uno::Reference< + com::sun::star::sdbc::XResultSet >& xResultSet ); + +public: + CachedDynamicResultSetStub( com::sun::star::uno::Reference< + com::sun::star::ucb::XDynamicResultSet > xOrigin + , const com::sun::star::uno::Reference< + com::sun::star::lang::XMultiServiceFactory > & xSMgr ); + + virtual ~CachedDynamicResultSetStub(); + + + //----------------------------------------------------------------- + // XInterface inherited + //----------------------------------------------------------------- + XINTERFACE_DECL() + //----------------------------------------------------------------- + // XTypeProvider + //----------------------------------------------------------------- + XTYPEPROVIDER_DECL() + //----------------------------------------------------------------- + // XServiceInfo + //----------------------------------------------------------------- + XSERVICEINFO_NOFACTORY_DECL() +}; + +//========================================================================= + +class CachedDynamicResultSetStubFactory + : public cppu::OWeakObject + , public com::sun::star::lang::XTypeProvider + , public com::sun::star::lang::XServiceInfo + , public com::sun::star::ucb::XCachedDynamicResultSetStubFactory +{ +protected: + com::sun::star::uno::Reference< + com::sun::star::lang::XMultiServiceFactory > m_xSMgr; + +public: + + CachedDynamicResultSetStubFactory( + const com::sun::star::uno::Reference< + com::sun::star::lang::XMultiServiceFactory > & rSMgr); + + virtual ~CachedDynamicResultSetStubFactory(); + + //----------------------------------------------------------------- + // XInterface + XINTERFACE_DECL() + + //----------------------------------------------------------------- + // XTypeProvider + XTYPEPROVIDER_DECL() + + //----------------------------------------------------------------- + // XServiceInfo + XSERVICEINFO_DECL() + + //----------------------------------------------------------------- + // XCachedDynamicResultSetStubFactory + + virtual com::sun::star::uno::Reference< + com::sun::star::ucb::XDynamicResultSet > SAL_CALL + createCachedDynamicResultSetStub( + const com::sun::star::uno::Reference< + com::sun::star::ucb::XDynamicResultSet > & Source ) + throw( com::sun::star::uno::RuntimeException ); + + + virtual void SAL_CALL connectToCache( + const com::sun::star::uno::Reference< + com::sun::star::ucb::XDynamicResultSet > & Source + , const com::sun::star::uno::Reference< + com::sun::star::ucb::XDynamicResultSet > & TargetCache + , const com::sun::star::uno::Sequence< + com::sun::star::ucb::NumberedSortingInfo > & SortingInfo + , const com::sun::star::uno::Reference< + com::sun::star::ucb::XAnyCompareFactory > & CompareFactory + ) + throw ( + com::sun::star::ucb::ListenerAlreadySetException + , com::sun::star::ucb::AlreadyInitializedException + , com::sun::star::uno::RuntimeException + ); +}; + +#endif + diff --git a/ucb/source/cacher/cacheserv.cxx b/ucb/source/cacher/cacheserv.cxx new file mode 100644 index 000000000000..0f0574b76937 --- /dev/null +++ b/ucb/source/cacher/cacheserv.cxx @@ -0,0 +1,235 @@ +/************************************************************************* + * + * $RCSfile: cacheserv.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:52:35 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XSINGLESERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XSingleServiceFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_REGISTRY_XREGISTRYKEY_HPP_ +#include <com/sun/star/registry/XRegistryKey.hpp> +#endif + +#ifndef _CACHED_CONTENT_RESULTSET_HXX +#include <cachedcontentresultset.hxx> +#endif +#ifndef _CACHED_CONTENT_RESULTSET_STUB_HXX +#include <cachedcontentresultsetstub.hxx> +#endif +#ifndef _CACHED_DYNAMIC_RESULTSET_HXX +#include <cacheddynamicresultset.hxx> +#endif +#ifndef _CACHED_DYNAMIC_RESULTSET_STUB_HXX +#include <cacheddynamicresultsetstub.hxx> +#endif + +using namespace rtl; +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::registry; + +//========================================================================= +static sal_Bool writeInfo( void * pRegistryKey, + const OUString & rImplementationName, + Sequence< OUString > const & rServiceNames ) +{ + OUString aKeyName( OUString::createFromAscii( "/" ) ); + aKeyName += rImplementationName; + aKeyName += OUString::createFromAscii( "/UNO/SERVICES" ); + + Reference< XRegistryKey > xKey; + try + { + xKey = static_cast< XRegistryKey * >( + pRegistryKey )->createKey( aKeyName ); + } + catch ( InvalidRegistryException const & ) + { + } + + if ( !xKey.is() ) + return sal_False; + + sal_Bool bSuccess = sal_True; + + for ( sal_Int32 n = 0; n < rServiceNames.getLength(); ++n ) + { + try + { + xKey->createKey( rServiceNames[ n ] ); + } + catch ( InvalidRegistryException const & ) + { + bSuccess = sal_False; + break; + } + } + return bSuccess; +} + +//========================================================================= +extern "C" void SAL_CALL component_getImplementationEnvironment( + const sal_Char ** ppEnvTypeName, uno_Environment ** ppEnv ) +{ + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; +} + +//========================================================================= +extern "C" sal_Bool SAL_CALL component_writeInfo( + void * pServiceManager, void * pRegistryKey ) +{ + return pRegistryKey && + + ////////////////////////////////////////////////////////////////////// + // CachedContentResultSetFactory. + ////////////////////////////////////////////////////////////////////// + + writeInfo( pRegistryKey, + CachedContentResultSetFactory::getImplementationName_Static(), + CachedContentResultSetFactory::getSupportedServiceNames_Static() ) && + + ////////////////////////////////////////////////////////////////////// + // CachedContentResultSetStubFactory. + ////////////////////////////////////////////////////////////////////// + + writeInfo( pRegistryKey, + CachedContentResultSetStubFactory::getImplementationName_Static(), + CachedContentResultSetStubFactory::getSupportedServiceNames_Static() ) && + + ////////////////////////////////////////////////////////////////////// + // CachedDynamicResultSetFactory. + ////////////////////////////////////////////////////////////////////// + + writeInfo( pRegistryKey, + CachedDynamicResultSetFactory::getImplementationName_Static(), + CachedDynamicResultSetFactory::getSupportedServiceNames_Static() ) && + + ////////////////////////////////////////////////////////////////////// + // CachedDynamicResultSetStubFactory. + ////////////////////////////////////////////////////////////////////// + + writeInfo( pRegistryKey, + CachedDynamicResultSetStubFactory::getImplementationName_Static(), + CachedDynamicResultSetStubFactory::getSupportedServiceNames_Static() ); +} + +//========================================================================= +extern "C" void * SAL_CALL component_getFactory( + const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey ) +{ + void * pRet = 0; + + Reference< XMultiServiceFactory > xSMgr( + reinterpret_cast< XMultiServiceFactory * >( pServiceManager ) ); + Reference< XSingleServiceFactory > xFactory; + + ////////////////////////////////////////////////////////////////////// + // CachedContentResultSetFactory. + ////////////////////////////////////////////////////////////////////// + + if ( CachedContentResultSetFactory::getImplementationName_Static(). + compareToAscii( pImplName ) == 0 ) + { + xFactory = CachedContentResultSetFactory::createServiceFactory( xSMgr ); + } + + ////////////////////////////////////////////////////////////////////// + // CachedContentResultSetStubFactory. + ////////////////////////////////////////////////////////////////////// + + else if ( CachedContentResultSetStubFactory::getImplementationName_Static(). + compareToAscii( pImplName ) == 0 ) + { + xFactory = CachedContentResultSetStubFactory::createServiceFactory( xSMgr ); + } + + ////////////////////////////////////////////////////////////////////// + // CachedDynamicResultSetFactory. + ////////////////////////////////////////////////////////////////////// + + else if ( CachedDynamicResultSetFactory::getImplementationName_Static(). + compareToAscii( pImplName ) == 0 ) + { + xFactory = CachedDynamicResultSetFactory::createServiceFactory( xSMgr ); + } + + ////////////////////////////////////////////////////////////////////// + // CachedDynamicResultSetStubFactory. + ////////////////////////////////////////////////////////////////////// + + else if ( CachedDynamicResultSetStubFactory::getImplementationName_Static(). + compareToAscii( pImplName ) == 0 ) + { + xFactory = CachedDynamicResultSetStubFactory::createServiceFactory( xSMgr ); + } + + ////////////////////////////////////////////////////////////////////// + + if ( xFactory.is() ) + { + xFactory->acquire(); + pRet = xFactory.get(); + } + + return pRet; +} + diff --git a/ucb/source/cacher/contentresultsetwrapper.cxx b/ucb/source/cacher/contentresultsetwrapper.cxx new file mode 100644 index 000000000000..8af9075790dd --- /dev/null +++ b/ucb/source/cacher/contentresultsetwrapper.cxx @@ -0,0 +1,1472 @@ +/************************************************************************* + * + * $RCSfile: contentresultsetwrapper.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:52:35 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include <contentresultsetwrapper.hxx> + +#ifndef _COM_SUN_STAR_SDBC_FETCHDIRECTION_HPP_ +#include <com/sun/star/sdbc/FetchDirection.hpp> +#endif + +#ifndef _COM_SUN_STAR_UCB_FETCHERROR_HPP_ +#include <com/sun/star/ucb/FetchError.hpp> +#endif + +#ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HPP_ +#include <com/sun/star/beans/PropertyAttribute.hpp> +#endif + +#ifndef _COM_SUN_STAR_SDBC_RESULTSETTYPE_HPP_ +#include <com/sun/star/sdbc/ResultSetType.hpp> +#endif + +#ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_ +#include <com/sun/star/lang/DisposedException.hpp> +#endif + +#ifndef _RTL_USTRING_HXX_ +#include <rtl/ustring.hxx> +#endif + +#ifndef _TOOLS_DEBUG_HXX +#include <tools/debug.hxx> +#endif + +using namespace com::sun::star::beans; +using namespace com::sun::star::lang; +using namespace com::sun::star::sdbc; +using namespace com::sun::star::ucb; +using namespace com::sun::star::uno; +using namespace com::sun::star::util; +using namespace cppu; +using namespace rtl; + +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- +// class ContentResultSetWrapper +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- + +ContentResultSetWrapper::ContentResultSetWrapper( + Reference< XResultSet > xOrigin ) + : m_xResultSetOrigin( xOrigin ) + , m_xRowOrigin( NULL ) + , m_xContentAccessOrigin( NULL ) + , m_xPropertySetOrigin( NULL ) + , m_xPropertySetInfo( NULL ) + , m_xMetaDataFromOrigin( NULL ) + + , m_pDisposeEventListeners( NULL ) + , m_pPropertyChangeListeners( NULL ) + , m_pVetoableChangeListeners( NULL ) + + , m_bDisposed( sal_False ) + , m_bInDispose( sal_False ) + + , m_nForwardOnly( 2 ) +{ + m_pMyListenerImpl = new ContentResultSetWrapperListener( this ); + m_xMyListenerImpl = Reference< XPropertyChangeListener >( m_pMyListenerImpl ); + + DBG_ASSERT( m_xResultSetOrigin.is(), "XResultSet is required" ); + + m_xRowOrigin = Reference< XRow >( m_xResultSetOrigin, UNO_QUERY ); + DBG_ASSERT( m_xRowOrigin.is(), "interface XRow is required" ); + + m_xContentAccessOrigin = Reference< XContentAccess >( m_xResultSetOrigin, UNO_QUERY ); + DBG_ASSERT( m_xContentAccessOrigin.is(), "interface XContentAccess is required" ); + + m_xPropertySetOrigin = Reference< XPropertySet >( m_xResultSetOrigin, UNO_QUERY ); + DBG_ASSERT( m_xPropertySetOrigin.is(), "interface XPropertySet is required" ); + + //call impl_init() at the end of constructor of derived class +}; + +void SAL_CALL ContentResultSetWrapper::impl_init() +{ + //call this at the end of constructor of derived class + // + + //listen to disposing from Origin: + Reference< XComponent > xComponentOrigin( m_xResultSetOrigin, UNO_QUERY ); + DBG_ASSERT( xComponentOrigin.is(), "interface XComponent is required" ); + xComponentOrigin->addEventListener( static_cast< XPropertyChangeListener * >( m_pMyListenerImpl ) ); +} + +ContentResultSetWrapper::~ContentResultSetWrapper() +{ + //call impl_deinit() at start of destructor of derived class + + delete m_pDisposeEventListeners; + delete m_pPropertyChangeListeners; + delete m_pVetoableChangeListeners; +}; + +void SAL_CALL ContentResultSetWrapper::impl_deinit() +{ + //call this at start of destructor of derived class + // + m_pMyListenerImpl->impl_OwnerDies(); +} + +//virtual +void SAL_CALL ContentResultSetWrapper + ::impl_initPropertySetInfo() +{ + { + vos::OGuard aGuard( m_aMutex ); + if( m_xPropertySetInfo.is() ) + return; + + if( !m_xPropertySetOrigin.is() ) + return; + } + + Reference< XPropertySetInfo > xOrig = + m_xPropertySetOrigin->getPropertySetInfo(); + + { + vos::OGuard aGuard( m_aMutex ); + m_xPropertySetInfo = xOrig; + } +} + +void SAL_CALL ContentResultSetWrapper +::impl_EnsureNotDisposed() + throw( DisposedException, RuntimeException ) +{ + vos::OGuard aGuard( m_aMutex ); + if( m_bDisposed ) + throw DisposedException(); +} + +ContentResultSetWrapper::PropertyChangeListenerContainer_Impl* SAL_CALL + ContentResultSetWrapper + ::impl_getPropertyChangeListenerContainer() +{ + vos::OGuard aGuard( m_aMutex ); + if ( !m_pPropertyChangeListeners ) + m_pPropertyChangeListeners = + new PropertyChangeListenerContainer_Impl( m_aContainerMutex ); + return m_pPropertyChangeListeners; +} + +ContentResultSetWrapper::PropertyChangeListenerContainer_Impl* SAL_CALL + ContentResultSetWrapper + ::impl_getVetoableChangeListenerContainer() +{ + vos::OGuard aGuard( m_aMutex ); + if ( !m_pVetoableChangeListeners ) + m_pVetoableChangeListeners = + new PropertyChangeListenerContainer_Impl( m_aContainerMutex ); + return m_pVetoableChangeListeners; +} + +void SAL_CALL ContentResultSetWrapper + ::impl_notifyPropertyChangeListeners( + const PropertyChangeEvent& rEvt ) +{ + { + vos::OGuard aGuard( m_aMutex ); + if( !m_pPropertyChangeListeners ) + return; + } + + // Notify listeners interested especially in the changed property. + OInterfaceContainerHelper* pContainer = + m_pPropertyChangeListeners->getContainer( rEvt.PropertyName ); + if( pContainer ) + { + OInterfaceIteratorHelper aIter( *pContainer ); + while( aIter.hasMoreElements() ) + { + Reference< XPropertyChangeListener > xListener( + aIter.next(), UNO_QUERY ); + if( xListener.is() ) + xListener->propertyChange( rEvt ); + } + } + + // Notify listeners interested in all properties. + pContainer = m_pPropertyChangeListeners->getContainer( OUString() ); + if( pContainer ) + { + OInterfaceIteratorHelper aIter( *pContainer ); + while( aIter.hasMoreElements() ) + { + Reference< XPropertyChangeListener > xListener( + aIter.next(), UNO_QUERY ); + if( xListener.is() ) + xListener->propertyChange( rEvt ); + } + } +} + +void SAL_CALL ContentResultSetWrapper + ::impl_notifyVetoableChangeListeners( const PropertyChangeEvent& rEvt ) + throw( PropertyVetoException, + RuntimeException ) +{ + { + vos::OGuard aGuard( m_aMutex ); + if( !m_pVetoableChangeListeners ) + return; + } + + // Notify listeners interested especially in the changed property. + OInterfaceContainerHelper* pContainer = + m_pVetoableChangeListeners->getContainer( rEvt.PropertyName ); + if( pContainer ) + { + OInterfaceIteratorHelper aIter( *pContainer ); + while( aIter.hasMoreElements() ) + { + Reference< XVetoableChangeListener > xListener( + aIter.next(), UNO_QUERY ); + if( xListener.is() ) + xListener->vetoableChange( rEvt ); + } + } + + // Notify listeners interested in all properties. + pContainer = m_pVetoableChangeListeners->getContainer( OUString() ); + if( pContainer ) + { + OInterfaceIteratorHelper aIter( *pContainer ); + while( aIter.hasMoreElements() ) + { + Reference< XVetoableChangeListener > xListener( + aIter.next(), UNO_QUERY ); + if( xListener.is() ) + xListener->vetoableChange( rEvt ); + } + } +} + +sal_Bool SAL_CALL ContentResultSetWrapper + ::impl_isForwardOnly() +{ + //m_nForwardOnly == 2 -> don't know + //m_nForwardOnly == 1 -> YES + //m_nForwardOnly == 0 -> NO + + //@todo replace this with lines in comment + vos::OGuard aGuard( m_aMutex ); + m_nForwardOnly = 0; + return m_nForwardOnly; + + + /* + ReacquireableGuard aGuard( m_aMutex ); + if( m_nForwardOnly == 2 ) + { + aGuard.clear(); + if( !getPropertySetInfo().is() ) + { + aGuard.reacquire(); + m_nForwardOnly = 0; + return m_nForwardOnly; + } + aGuard.reacquire(); + + rtl::OUString aName = OUString::createFromAscii( "ResultSetType" ); + //find out, if we are ForwardOnly and cache the value: + + if( !m_xPropertySetOrigin.is() ) + { + DBG_ERROR( "broadcaster was disposed already" ); + m_nForwardOnly = 0; + return m_nForwardOnly; + } + + aGuard.clear(); + Any aAny = m_xPropertySetOrigin->getPropertyValue( aName ); + + aGuard.reacquire(); + long nResultSetType; + if( ( aAny >>= nResultSetType ) && + ( nResultSetType == ResultSetType::FORWARD_ONLY ) ) + m_nForwardOnly = 1; + else + m_nForwardOnly = 0; + } + return m_nForwardOnly; + */ +} + +//-------------------------------------------------------------------------- +// XInterface methods. +//-------------------------------------------------------------------------- +//list all interfaces inclusive baseclasses of interfaces +QUERYINTERFACE_IMPL_START( ContentResultSetWrapper ) + + SAL_STATIC_CAST( XComponent*, this ), + SAL_STATIC_CAST( XCloseable*, this ), + SAL_STATIC_CAST( XResultSetMetaDataSupplier*, this ), + SAL_STATIC_CAST( XPropertySet*, this ), + + SAL_STATIC_CAST( XContentAccess*, this ), + SAL_STATIC_CAST( XResultSet*, this ), + SAL_STATIC_CAST( XRow*, this ) + +QUERYINTERFACE_IMPL_END + +//-------------------------------------------------------------------------- +// XComponent methods. +//-------------------------------------------------------------------------- +// virtual +void SAL_CALL ContentResultSetWrapper + ::dispose() throw( RuntimeException ) +{ + impl_EnsureNotDisposed(); + + ReacquireableGuard aGuard( m_aMutex ); + if( m_bInDispose || m_bDisposed ) + return; + m_bInDispose = sal_True; + + if( m_xPropertySetOrigin.is() ) + { + aGuard.clear(); + try + { + m_xPropertySetOrigin->removePropertyChangeListener( + OUString(), static_cast< XPropertyChangeListener * >( m_pMyListenerImpl ) ); + } + catch( Exception& ) + { + DBG_ERROR( "could not remove PropertyChangeListener" ); + } + try + { + m_xPropertySetOrigin->removeVetoableChangeListener( + OUString(), static_cast< XVetoableChangeListener * >( m_pMyListenerImpl ) ); + } + catch( Exception& ) + { + DBG_ERROR( "could not remove VetoableChangeListener" ); + } + + Reference< XComponent > xComponentOrigin( m_xResultSetOrigin, UNO_QUERY ); + DBG_ASSERT( xComponentOrigin.is(), "interface XComponent is required" ); + xComponentOrigin->removeEventListener( static_cast< XPropertyChangeListener * >( m_pMyListenerImpl ) ); + } + + aGuard.reacquire(); + if( m_pDisposeEventListeners && m_pDisposeEventListeners->getLength() ) + { + EventObject aEvt; + aEvt.Source = static_cast< XComponent * >( this ); + + aGuard.clear(); + m_pDisposeEventListeners->disposeAndClear( aEvt ); + } + + aGuard.reacquire(); + if( m_pPropertyChangeListeners ) + { + EventObject aEvt; + aEvt.Source = static_cast< XPropertySet * >( this ); + + aGuard.clear(); + m_pPropertyChangeListeners->disposeAndClear( aEvt ); + } + + aGuard.reacquire(); + if( m_pVetoableChangeListeners ) + { + EventObject aEvt; + aEvt.Source = static_cast< XPropertySet * >( this ); + + aGuard.clear(); + m_pVetoableChangeListeners->disposeAndClear( aEvt ); + } + + aGuard.reacquire(); + m_bDisposed = sal_True; + m_bInDispose = sal_False; +} + +//-------------------------------------------------------------------------- +// virtual +void SAL_CALL ContentResultSetWrapper + ::addEventListener( const Reference< XEventListener >& Listener ) + throw( RuntimeException ) +{ + impl_EnsureNotDisposed(); + vos::OGuard aGuard( m_aMutex ); + + if ( !m_pDisposeEventListeners ) + m_pDisposeEventListeners = + new OInterfaceContainerHelper( m_aContainerMutex ); + + m_pDisposeEventListeners->addInterface( Listener ); +} + +//-------------------------------------------------------------------------- +// virtual +void SAL_CALL ContentResultSetWrapper + ::removeEventListener( const Reference< XEventListener >& Listener ) + throw( RuntimeException ) +{ + impl_EnsureNotDisposed(); + vos::OGuard aGuard( m_aMutex ); + + if ( m_pDisposeEventListeners ) + m_pDisposeEventListeners->removeInterface( Listener ); +} + +//-------------------------------------------------------------------------- +//XCloseable methods. +//-------------------------------------------------------------------------- +//virtual +void SAL_CALL ContentResultSetWrapper + ::close() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + dispose(); +} + +//-------------------------------------------------------------------------- +//XResultSetMetaDataSupplier methods. +//-------------------------------------------------------------------------- +//virtual +Reference< XResultSetMetaData > SAL_CALL ContentResultSetWrapper + ::getMetaData() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + ReacquireableGuard aGuard( m_aMutex ); + if( !m_xMetaDataFromOrigin.is() && m_xResultSetOrigin.is() ) + { + Reference< XResultSetMetaDataSupplier > xMetaDataSupplier + = Reference< XResultSetMetaDataSupplier >( + m_xResultSetOrigin, UNO_QUERY ); + + if( xMetaDataSupplier.is() ) + { + aGuard.clear(); + + Reference< XResultSetMetaData > xMetaData + = xMetaDataSupplier->getMetaData(); + + aGuard.reacquire(); + m_xMetaDataFromOrigin = xMetaData; + } + } + return m_xMetaDataFromOrigin; +} + + +//-------------------------------------------------------------------------- +// XPropertySet methods. +//-------------------------------------------------------------------------- +// virtual +Reference< XPropertySetInfo > SAL_CALL ContentResultSetWrapper + ::getPropertySetInfo() throw( RuntimeException ) +{ + impl_EnsureNotDisposed(); + { + vos::OGuard aGuard( m_aMutex ); + if( m_xPropertySetInfo.is() ) + return m_xPropertySetInfo; + } + impl_initPropertySetInfo(); + return m_xPropertySetInfo; +} +//-------------------------------------------------------------------------- +// virtual +void SAL_CALL ContentResultSetWrapper + ::setPropertyValue( const OUString& rPropertyName, const Any& rValue ) + throw( UnknownPropertyException, + PropertyVetoException, + IllegalArgumentException, + WrappedTargetException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( !m_xPropertySetOrigin.is() ) + { + DBG_ERROR( "broadcaster was disposed already" ); + throw UnknownPropertyException(); + } + m_xPropertySetOrigin->setPropertyValue( rPropertyName, rValue ); +} + +//-------------------------------------------------------------------------- +// virtual +Any SAL_CALL ContentResultSetWrapper + ::getPropertyValue( const OUString& rPropertyName ) + throw( UnknownPropertyException, + WrappedTargetException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( !m_xPropertySetOrigin.is() ) + { + DBG_ERROR( "broadcaster was disposed already" ); + throw UnknownPropertyException(); + } + return m_xPropertySetOrigin->getPropertyValue( rPropertyName ); +} + +//-------------------------------------------------------------------------- +// virtual +void SAL_CALL ContentResultSetWrapper + ::addPropertyChangeListener( + const OUString& aPropertyName, + const Reference< XPropertyChangeListener >& xListener ) + throw( UnknownPropertyException, + WrappedTargetException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( !getPropertySetInfo().is() ) + { + DBG_ERROR( "broadcaster was disposed already" ); + throw UnknownPropertyException(); + } + + if( aPropertyName.getLength() ) + { + m_xPropertySetInfo->getPropertyByName( aPropertyName ); + //throws UnknownPropertyException, if so + } + + impl_getPropertyChangeListenerContainer(); + BOOL bNeedRegister = !m_pPropertyChangeListeners-> + getContainedTypes().getLength(); + m_pPropertyChangeListeners->addInterface( aPropertyName, xListener ); + if( bNeedRegister ) + { + { + vos::OGuard aGuard( m_aMutex ); + if( !m_xPropertySetOrigin.is() ) + { + DBG_ERROR( "broadcaster was disposed already" ); + return; + } + } + try + { + m_xPropertySetOrigin->addPropertyChangeListener( + OUString(), static_cast< XPropertyChangeListener * >( m_pMyListenerImpl ) ); + } + catch( Exception& rEx ) + { + m_pPropertyChangeListeners->removeInterface( aPropertyName, xListener ); + throw rEx; + } + } +} + +//-------------------------------------------------------------------------- +// virtual +void SAL_CALL ContentResultSetWrapper + ::addVetoableChangeListener( + const OUString& rPropertyName, + const Reference< XVetoableChangeListener >& xListener ) + throw( UnknownPropertyException, + WrappedTargetException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( !getPropertySetInfo().is() ) + { + DBG_ERROR( "broadcaster was disposed already" ); + throw UnknownPropertyException(); + } + if( rPropertyName.getLength() ) + { + m_xPropertySetInfo->getPropertyByName( rPropertyName ); + //throws UnknownPropertyException, if so + } + + impl_getVetoableChangeListenerContainer(); + BOOL bNeedRegister = !m_pVetoableChangeListeners-> + getContainedTypes().getLength(); + m_pVetoableChangeListeners->addInterface( rPropertyName, xListener ); + if( bNeedRegister ) + { + { + vos::OGuard aGuard( m_aMutex ); + if( !m_xPropertySetOrigin.is() ) + { + DBG_ERROR( "broadcaster was disposed already" ); + return; + } + } + try + { + m_xPropertySetOrigin->addVetoableChangeListener( + OUString(), static_cast< XVetoableChangeListener * >( m_pMyListenerImpl ) ); + } + catch( Exception& rEx ) + { + m_pVetoableChangeListeners->removeInterface( rPropertyName, xListener ); + throw rEx; + } + } +} + +//-------------------------------------------------------------------------- +// virtual +void SAL_CALL ContentResultSetWrapper + ::removePropertyChangeListener( + const OUString& rPropertyName, + const Reference< XPropertyChangeListener >& xListener ) + throw( UnknownPropertyException, + WrappedTargetException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + { + //noop, if no listener registered + vos::OGuard aGuard( m_aMutex ); + if( !m_pPropertyChangeListeners ) + return; + } + OInterfaceContainerHelper* pContainer = + m_pPropertyChangeListeners->getContainer( rPropertyName ); + + if( !pContainer ) + { + if( rPropertyName.getLength() ) + { + if( !getPropertySetInfo().is() ) + throw UnknownPropertyException(); + + m_xPropertySetInfo->getPropertyByName( rPropertyName ); + //throws UnknownPropertyException, if so + } + return; //the listener was not registered + } + + m_pPropertyChangeListeners->removeInterface( rPropertyName, xListener ); + + if( !m_pPropertyChangeListeners->getContainedTypes().getLength() ) + { + { + vos::OGuard aGuard( m_aMutex ); + if( !m_xPropertySetOrigin.is() ) + { + DBG_ERROR( "broadcaster was disposed already" ); + return; + } + } + try + { + m_xPropertySetOrigin->removePropertyChangeListener( + OUString(), static_cast< XPropertyChangeListener * >( m_pMyListenerImpl ) ); + } + catch( Exception& ) + { + DBG_ERROR( "could not remove PropertyChangeListener" ); + } + } +} + +//-------------------------------------------------------------------------- +// virtual +void SAL_CALL ContentResultSetWrapper + ::removeVetoableChangeListener( + const OUString& rPropertyName, + const Reference< XVetoableChangeListener >& xListener ) + throw( UnknownPropertyException, + WrappedTargetException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + { + //noop, if no listener registered + vos::OGuard aGuard( m_aMutex ); + if( !m_pVetoableChangeListeners ) + return; + } + OInterfaceContainerHelper* pContainer = + m_pVetoableChangeListeners->getContainer( rPropertyName ); + + if( !pContainer ) + { + if( rPropertyName.getLength() ) + { + if( !getPropertySetInfo().is() ) + throw UnknownPropertyException(); + + m_xPropertySetInfo->getPropertyByName( rPropertyName ); + //throws UnknownPropertyException, if so + } + return; //the listener was not registered + } + + m_pVetoableChangeListeners->removeInterface( rPropertyName, xListener ); + + if( !m_pVetoableChangeListeners->getContainedTypes().getLength() ) + { + { + vos::OGuard aGuard( m_aMutex ); + if( !m_xPropertySetOrigin.is() ) + { + DBG_ERROR( "broadcaster was disposed already" ); + return; + } + } + try + { + m_xPropertySetOrigin->removeVetoableChangeListener( + OUString(), static_cast< XVetoableChangeListener * >( m_pMyListenerImpl ) ); + } + catch( Exception& ) + { + DBG_ERROR( "could not remove VetoableChangeListener" ); + } + } +} + +//-------------------------------------------------------------------------- +// own methods. +//-------------------------------------------------------------------------- + +//virtual +void SAL_CALL ContentResultSetWrapper + ::impl_disposing( const EventObject& rEventObject ) + throw( RuntimeException ) +{ + impl_EnsureNotDisposed(); + + vos::OGuard aGuard( m_aMutex ); + + if( !m_xResultSetOrigin.is() ) + return; + + //release all references to the broadcaster: + m_xResultSetOrigin.clear(); + m_xRowOrigin.clear(); + m_xContentAccessOrigin.clear(); + m_xPropertySetOrigin.clear(); + m_xMetaDataFromOrigin.clear(); + m_xPropertySetInfo.clear(); +} + +//virtual +void SAL_CALL ContentResultSetWrapper + ::impl_propertyChange( const PropertyChangeEvent& rEvt ) + throw( RuntimeException ) +{ + impl_EnsureNotDisposed(); + + PropertyChangeEvent aEvt( rEvt ); + aEvt.Source = static_cast< XPropertySet * >( this ); + aEvt.Further = FALSE; + impl_notifyPropertyChangeListeners( aEvt ); +} + +//virtual +void SAL_CALL ContentResultSetWrapper + ::impl_vetoableChange( const PropertyChangeEvent& rEvt ) + throw( PropertyVetoException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + PropertyChangeEvent aEvt( rEvt ); + aEvt.Source = static_cast< XPropertySet * >( this ); + aEvt.Further = FALSE; + + impl_notifyVetoableChangeListeners( aEvt ); +} + +//-------------------------------------------------------------------------- +// XContentAccess methods. ( -- position dependent ) +//-------------------------------------------------------------------------- + +// virtual +OUString SAL_CALL ContentResultSetWrapper + ::queryContentIdentfierString() + throw( RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( !m_xContentAccessOrigin.is() ) + { + DBG_ERROR( "broadcaster was disposed already" ); + throw RuntimeException(); + } + return m_xContentAccessOrigin->queryContentIdentfierString(); +} + +//-------------------------------------------------------------------------- +// virtual +Reference< XContentIdentifier > SAL_CALL ContentResultSetWrapper + ::queryContentIdentifier() + throw( RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( !m_xContentAccessOrigin.is() ) + { + DBG_ERROR( "broadcaster was disposed already" ); + throw RuntimeException(); + } + return m_xContentAccessOrigin->queryContentIdentifier(); +} + +//-------------------------------------------------------------------------- +// virtual +Reference< XContent > SAL_CALL ContentResultSetWrapper + ::queryContent() + throw( RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( !m_xContentAccessOrigin.is() ) + { + DBG_ERROR( "broadcaster was disposed already" ); + throw RuntimeException(); + } + return m_xContentAccessOrigin->queryContent(); +} + +//----------------------------------------------------------------- +// XResultSet methods. +//----------------------------------------------------------------- +//virtual + +sal_Bool SAL_CALL ContentResultSetWrapper + ::next() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( !m_xResultSetOrigin.is() ) + { + DBG_ERROR( "broadcaster was disposed already" ); + throw RuntimeException(); + } + return m_xResultSetOrigin->next(); +} + +//virtual +sal_Bool SAL_CALL ContentResultSetWrapper + ::previous() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( !m_xResultSetOrigin.is() ) + { + DBG_ERROR( "broadcaster was disposed already" ); + throw RuntimeException(); + } + return m_xResultSetOrigin->previous(); +} + +//virtual +sal_Bool SAL_CALL ContentResultSetWrapper + ::absolute( sal_Int32 row ) + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( !m_xResultSetOrigin.is() ) + { + DBG_ERROR( "broadcaster was disposed already" ); + throw RuntimeException(); + } + return m_xResultSetOrigin->absolute( row ); +} + +//virtual +sal_Bool SAL_CALL ContentResultSetWrapper + ::relative( sal_Int32 rows ) + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( !m_xResultSetOrigin.is() ) + { + DBG_ERROR( "broadcaster was disposed already" ); + throw RuntimeException(); + } + return m_xResultSetOrigin->relative( rows ); +} + + +//virtual +sal_Bool SAL_CALL ContentResultSetWrapper + ::first() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( !m_xResultSetOrigin.is() ) + { + DBG_ERROR( "broadcaster was disposed already" ); + throw RuntimeException(); + } + return m_xResultSetOrigin->first(); +} + +//virtual +sal_Bool SAL_CALL ContentResultSetWrapper + ::last() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( !m_xResultSetOrigin.is() ) + { + DBG_ERROR( "broadcaster was disposed already" ); + throw RuntimeException(); + } + return m_xResultSetOrigin->last(); +} + +//virtual +void SAL_CALL ContentResultSetWrapper + ::beforeFirst() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( !m_xResultSetOrigin.is() ) + { + DBG_ERROR( "broadcaster was disposed already" ); + throw RuntimeException(); + } + m_xResultSetOrigin->beforeFirst(); +} + +//virtual +void SAL_CALL ContentResultSetWrapper + ::afterLast() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( !m_xResultSetOrigin.is() ) + { + DBG_ERROR( "broadcaster was disposed already" ); + throw RuntimeException(); + } + m_xResultSetOrigin->afterLast(); +} + +//virtual +sal_Bool SAL_CALL ContentResultSetWrapper + ::isAfterLast() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( !m_xResultSetOrigin.is() ) + { + DBG_ERROR( "broadcaster was disposed already" ); + throw RuntimeException(); + } + return m_xResultSetOrigin->isAfterLast(); +} + +//virtual +sal_Bool SAL_CALL ContentResultSetWrapper + ::isBeforeFirst() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( !m_xResultSetOrigin.is() ) + { + DBG_ERROR( "broadcaster was disposed already" ); + throw RuntimeException(); + } + return m_xResultSetOrigin->isBeforeFirst(); +} + +//virtual +sal_Bool SAL_CALL ContentResultSetWrapper + ::isFirst() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( !m_xResultSetOrigin.is() ) + { + DBG_ERROR( "broadcaster was disposed already" ); + throw RuntimeException(); + } + return m_xResultSetOrigin->isFirst(); +} + +//virtual +sal_Bool SAL_CALL ContentResultSetWrapper + ::isLast() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( !m_xResultSetOrigin.is() ) + { + DBG_ERROR( "broadcaster was disposed already" ); + throw RuntimeException(); + } + return m_xResultSetOrigin->isLast(); +} + + +//virtual +sal_Int32 SAL_CALL ContentResultSetWrapper + ::getRow() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( !m_xResultSetOrigin.is() ) + { + DBG_ERROR( "broadcaster was disposed already" ); + throw RuntimeException(); + } + return m_xResultSetOrigin->getRow(); +} + +//virtual +void SAL_CALL ContentResultSetWrapper + ::refreshRow() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( !m_xResultSetOrigin.is() ) + { + DBG_ERROR( "broadcaster was disposed already" ); + throw RuntimeException(); + } + m_xResultSetOrigin->refreshRow(); +} + +//virtual +sal_Bool SAL_CALL ContentResultSetWrapper + ::rowUpdated() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( !m_xResultSetOrigin.is() ) + { + DBG_ERROR( "broadcaster was disposed already" ); + throw RuntimeException(); + } + return m_xResultSetOrigin->rowUpdated(); +} +//virtual +sal_Bool SAL_CALL ContentResultSetWrapper + ::rowInserted() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( !m_xResultSetOrigin.is() ) + { + DBG_ERROR( "broadcaster was disposed already" ); + throw RuntimeException(); + } + return m_xResultSetOrigin->rowInserted(); +} + +//virtual +sal_Bool SAL_CALL ContentResultSetWrapper + ::rowDeleted() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( !m_xResultSetOrigin.is() ) + { + DBG_ERROR( "broadcaster was disposed already" ); + throw RuntimeException(); + } + return m_xResultSetOrigin->rowDeleted(); +} + +//virtual +Reference< XInterface > SAL_CALL ContentResultSetWrapper + ::getStatement() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + //@todo ?return anything + return Reference< XInterface >(); +} + +//----------------------------------------------------------------- +// XRow methods. +//----------------------------------------------------------------- + +#define XROW_GETXXX( getXXX ) \ +impl_EnsureNotDisposed(); \ +if( !m_xRowOrigin.is() ) \ +{ \ + DBG_ERROR( "broadcaster was disposed already" );\ + throw RuntimeException(); \ +} \ +return m_xRowOrigin->getXXX( columnIndex ); + +//virtual +sal_Bool SAL_CALL ContentResultSetWrapper + ::wasNull() + throw( SQLException, + RuntimeException ) +{ + impl_EnsureNotDisposed(); + if( !m_xRowOrigin.is() ) + { + DBG_ERROR( "broadcaster was disposed already" ); + throw RuntimeException(); + } + return m_xRowOrigin->wasNull(); +} + +//virtual +rtl::OUString SAL_CALL ContentResultSetWrapper + ::getString( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getString ); +} + +//virtual +sal_Bool SAL_CALL ContentResultSetWrapper + ::getBoolean( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getBoolean ); +} + +//virtual +sal_Int8 SAL_CALL ContentResultSetWrapper + ::getByte( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getByte ); +} + +//virtual +sal_Int16 SAL_CALL ContentResultSetWrapper + ::getShort( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getShort ); +} + +//virtual +sal_Int32 SAL_CALL ContentResultSetWrapper + ::getInt( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getInt ); +} + +//virtual +sal_Int64 SAL_CALL ContentResultSetWrapper + ::getLong( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getLong ); +} + +//virtual +float SAL_CALL ContentResultSetWrapper + ::getFloat( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getFloat ); +} + +//virtual +double SAL_CALL ContentResultSetWrapper + ::getDouble( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getDouble ); +} + +//virtual +Sequence< sal_Int8 > SAL_CALL ContentResultSetWrapper + ::getBytes( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getBytes ); +} + +//virtual +Date SAL_CALL ContentResultSetWrapper + ::getDate( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getDate ); +} + +//virtual +Time SAL_CALL ContentResultSetWrapper + ::getTime( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getTime ); +} + +//virtual +DateTime SAL_CALL ContentResultSetWrapper + ::getTimestamp( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getTimestamp ); +} + +//virtual +Reference< com::sun::star::io::XInputStream > + SAL_CALL ContentResultSetWrapper + ::getBinaryStream( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getBinaryStream ); +} + +//virtual +Reference< com::sun::star::io::XInputStream > + SAL_CALL ContentResultSetWrapper + ::getCharacterStream( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getCharacterStream ); +} + +//virtual +Any SAL_CALL ContentResultSetWrapper + ::getObject( sal_Int32 columnIndex, + const Reference< + com::sun::star::container::XNameAccess >& typeMap ) + throw( SQLException, + RuntimeException ) +{ + //if you change this macro please pay attention to + //define XROW_GETXXX, where this is similar implemented + + impl_EnsureNotDisposed(); + if( !m_xRowOrigin.is() ) + { + DBG_ERROR( "broadcaster was disposed already" ); + throw RuntimeException(); + } + return m_xRowOrigin->getObject( columnIndex, typeMap ); +} + +//virtual +Reference< XRef > SAL_CALL ContentResultSetWrapper + ::getRef( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getRef ); +} + +//virtual +Reference< XBlob > SAL_CALL ContentResultSetWrapper + ::getBlob( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getBlob ); +} + +//virtual +Reference< XClob > SAL_CALL ContentResultSetWrapper + ::getClob( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getClob ); +} + +//virtual +Reference< XArray > SAL_CALL ContentResultSetWrapper + ::getArray( sal_Int32 columnIndex ) + throw( SQLException, + RuntimeException ) +{ + XROW_GETXXX( getArray ); +} + +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- +// class ContentResultSetWrapperListener +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- + +ContentResultSetWrapperListener::ContentResultSetWrapperListener( + ContentResultSetWrapper* pOwner ) + : m_pOwner( pOwner ) +{ +} + +ContentResultSetWrapperListener::~ContentResultSetWrapperListener() +{ +} + +//-------------------------------------------------------------------------- +// XInterface methods. +//-------------------------------------------------------------------------- +//list all interfaces inclusive baseclasses of interfaces +XINTERFACE_COMMON_IMPL( ContentResultSetWrapperListener ) +QUERYINTERFACE_IMPL_START( ContentResultSetWrapperListener ) + + static_cast< XEventListener * >( + static_cast< XPropertyChangeListener * >(this)) + , SAL_STATIC_CAST( XPropertyChangeListener*, this ) + , SAL_STATIC_CAST( XVetoableChangeListener*, this ) + +QUERYINTERFACE_IMPL_END + + +//-------------------------------------------------------------------------- +//XEventListener methods. +//-------------------------------------------------------------------------- + +//virtual +void SAL_CALL ContentResultSetWrapperListener + ::disposing( const EventObject& rEventObject ) + throw( RuntimeException ) +{ + if( m_pOwner ) + m_pOwner->impl_disposing( rEventObject ); +} + +//-------------------------------------------------------------------------- +//XPropertyChangeListener methods. +//-------------------------------------------------------------------------- + +//virtual +void SAL_CALL ContentResultSetWrapperListener + ::propertyChange( const PropertyChangeEvent& rEvt ) + throw( RuntimeException ) +{ + if( m_pOwner ) + m_pOwner->impl_propertyChange( rEvt ); +} + +//-------------------------------------------------------------------------- +//XVetoableChangeListener methods. +//-------------------------------------------------------------------------- +//virtual +void SAL_CALL ContentResultSetWrapperListener + ::vetoableChange( const PropertyChangeEvent& rEvt ) + throw( PropertyVetoException, + RuntimeException ) +{ + if( m_pOwner ) + m_pOwner->impl_vetoableChange( rEvt ); +} + +void SAL_CALL ContentResultSetWrapperListener + ::impl_OwnerDies() +{ + m_pOwner = NULL; +} + diff --git a/ucb/source/cacher/contentresultsetwrapper.hxx b/ucb/source/cacher/contentresultsetwrapper.hxx new file mode 100644 index 000000000000..bd56f14b4d34 --- /dev/null +++ b/ucb/source/cacher/contentresultsetwrapper.hxx @@ -0,0 +1,649 @@ +/************************************************************************* + * + * $RCSfile: contentresultsetwrapper.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:52:35 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _CONTENT_RESULTSET_WRAPPER_HXX +#define _CONTENT_RESULTSET_WRAPPER_HXX + +#ifndef _RTL_USTRING_HXX_ +#include <rtl/ustring.hxx> +#endif + +#ifndef _UCBHELPER_MACROS_HXX +#include <ucbhelper/macros.hxx> +#endif + +#ifndef _VOS_MUTEX_HXX_ +#include <vos/mutex.hxx> +#endif + +#ifndef _CPPUHELPER_WEAK_HXX_ +#include <cppuhelper/weak.hxx> +#endif + +#ifndef _COM_SUN_STAR_LANG_XCOMPONENT_HPP_ +#include <com/sun/star/lang/XComponent.hpp> +#endif + +#ifndef _COM_SUN_STAR_SDBC_XCLOSEABLE_HPP_ +#include <com/sun/star/sdbc/XCloseable.hpp> +#endif + +#ifndef _COM_SUN_STAR_SDBC_XRESULTSETMETADATASUPPLIER_HPP_ +#include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp> +#endif + +#ifndef _COM_SUN_STAR_SDBC_XRESULTSET_HPP_ +#include <com/sun/star/sdbc/XResultSet.hpp> +#endif + +#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_ +#include <com/sun/star/sdbc/XRow.hpp> +#endif + +#ifndef _COM_SUN_STAR_UCB_XCONTENTACCESS_HPP_ +#include <com/sun/star/ucb/XContentAccess.hpp> +#endif + +#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_ +#include <com/sun/star/beans/XPropertySet.hpp> +#endif + +#ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_ +#include <com/sun/star/lang/DisposedException.hpp> +#endif + +#ifndef _CPPUHELPER_INTERFACECONTAINER_HXX_ +#include <cppuhelper/interfacecontainer.hxx> +#endif + +//========================================================================= + +class ContentResultSetWrapperListener; +class ContentResultSetWrapper + : public cppu::OWeakObject + , public com::sun::star::lang::XComponent + , public com::sun::star::sdbc::XCloseable + , public com::sun::star::sdbc::XResultSetMetaDataSupplier + , public com::sun::star::beans::XPropertySet + , public com::sun::star::ucb::XContentAccess + , public com::sun::star::sdbc::XResultSet + , public com::sun::star::sdbc::XRow +{ +protected: + + //-------------------------------------------------------------------------- + //class PropertyChangeListenerContainer_Impl. + + struct equalStr_Impl + { + bool operator()( const rtl::OUString& s1, const rtl::OUString& s2 ) const + { + return !!( s1 == s2 ); + } + }; + + struct hashStr_Impl + { + size_t operator()( const rtl::OUString& rName ) const + { + return rName.hashCode(); + } + }; + + typedef cppu::OMultiTypeInterfaceContainerHelperVar + < rtl::OUString , hashStr_Impl , equalStr_Impl > + PropertyChangeListenerContainer_Impl; + //-------------------------------------------------------------------------- + // class ReacquireableGuard + + class ReacquireableGuard + { + protected: + vos::OMutex* pT; + public: + + ReacquireableGuard(vos::OMutex * pT) : pT(pT) + { + pT->acquire(); + } + + ReacquireableGuard(vos::OMutex& t) : pT(&t) + { + pT->acquire(); + } + + /** Releases mutex. */ + ~ReacquireableGuard() + { + if (pT) + pT->release(); + } + + /** Releases mutex. */ + void clear() + { + if(pT) + { + pT->release(); + pT = NULL; + } + } + + /** Reacquire mutex. */ + void reacquire() + { + if(pT) + { + pT->acquire(); + } + } + }; + + //----------------------------------------------------------------- + //members + + //my Mutex + vos::OMutex m_aMutex; + + //different Interfaces from Origin: + com::sun::star::uno::Reference< com::sun::star::sdbc::XResultSet > + m_xResultSetOrigin; + com::sun::star::uno::Reference< com::sun::star::sdbc::XRow > + m_xRowOrigin; //XRow-interface from m_xOrigin + com::sun::star::uno::Reference< com::sun::star::ucb::XContentAccess > + m_xContentAccessOrigin; //XContentAccess-interface from m_xOrigin + com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > + m_xPropertySetOrigin; //XPropertySet-interface from m_xOrigin + + com::sun::star::uno::Reference< com::sun::star::beans::XPropertySetInfo > + m_xPropertySetInfo; + + sal_Int32 m_nForwardOnly; + +private: + com::sun::star::uno::Reference< com::sun::star::beans::XPropertyChangeListener > + m_xMyListenerImpl; + ContentResultSetWrapperListener* + m_pMyListenerImpl; + + com::sun::star::uno::Reference< com::sun::star::sdbc::XResultSetMetaData > + m_xMetaDataFromOrigin; //XResultSetMetaData from m_xOrigin + + //management of listeners + sal_Bool m_bDisposed; ///Dispose call ready. + sal_Bool m_bInDispose;///In dispose call + osl::Mutex m_aContainerMutex; + cppu::OInterfaceContainerHelper* + m_pDisposeEventListeners; + PropertyChangeListenerContainer_Impl* + m_pPropertyChangeListeners; + PropertyChangeListenerContainer_Impl* + m_pVetoableChangeListeners; + + //----------------------------------------------------------------- + //methods: +private: + PropertyChangeListenerContainer_Impl* SAL_CALL + impl_getPropertyChangeListenerContainer(); + + PropertyChangeListenerContainer_Impl* SAL_CALL + impl_getVetoableChangeListenerContainer(); + +protected: + //----------------------------------------------------------------- + + ContentResultSetWrapper( com::sun::star::uno::Reference< + com::sun::star::sdbc::XResultSet > xOrigin ); + + virtual ~ContentResultSetWrapper(); + + void SAL_CALL impl_init(); + void SAL_CALL impl_deinit(); + + //-- + + virtual void SAL_CALL impl_initPropertySetInfo(); //helping XPropertySet + + void SAL_CALL + impl_EnsureNotDisposed() + throw( com::sun::star::lang::DisposedException, + com::sun::star::uno::RuntimeException ); + + void SAL_CALL + impl_notifyPropertyChangeListeners( + const com::sun::star::beans::PropertyChangeEvent& rEvt ); + + void SAL_CALL + impl_notifyVetoableChangeListeners( + const com::sun::star::beans::PropertyChangeEvent& rEvt ) + throw( com::sun::star::beans::PropertyVetoException, + com::sun::star::uno::RuntimeException ); + + sal_Bool SAL_CALL impl_isForwardOnly(); + +public: + + //----------------------------------------------------------------- + // XInterface + //----------------------------------------------------------------- + virtual com::sun::star::uno::Any SAL_CALL + queryInterface( const com::sun::star::uno::Type & rType ) + throw( com::sun::star::uno::RuntimeException ); + + //----------------------------------------------------------------- + // XComponent + //----------------------------------------------------------------- + virtual void SAL_CALL + dispose() throw( com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL + addEventListener( const com::sun::star::uno::Reference< + com::sun::star::lang::XEventListener >& Listener ) + throw( com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL + removeEventListener( const com::sun::star::uno::Reference< + com::sun::star::lang::XEventListener >& Listener ) + throw( com::sun::star::uno::RuntimeException ); + + //----------------------------------------------------------------- + //XCloseable + //----------------------------------------------------------------- + virtual void SAL_CALL + close() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + //----------------------------------------------------------------- + //XResultSetMetaDataSupplier + //----------------------------------------------------------------- + virtual com::sun::star::uno::Reference< + com::sun::star::sdbc::XResultSetMetaData > SAL_CALL + getMetaData() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + //----------------------------------------------------------------- + // XPropertySet + //----------------------------------------------------------------- + virtual com::sun::star::uno::Reference< + com::sun::star::beans::XPropertySetInfo > SAL_CALL + getPropertySetInfo() + throw( com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL + setPropertyValue( const rtl::OUString& aPropertyName, + const com::sun::star::uno::Any& aValue ) + throw( com::sun::star::beans::UnknownPropertyException, + com::sun::star::beans::PropertyVetoException, + com::sun::star::lang::IllegalArgumentException, + com::sun::star::lang::WrappedTargetException, + com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::uno::Any SAL_CALL + getPropertyValue( const rtl::OUString& PropertyName ) + throw( com::sun::star::beans::UnknownPropertyException, + com::sun::star::lang::WrappedTargetException, + com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL + addPropertyChangeListener( const rtl::OUString& aPropertyName, + const com::sun::star::uno::Reference< + com::sun::star::beans::XPropertyChangeListener >& xListener ) + throw( com::sun::star::beans::UnknownPropertyException, + com::sun::star::lang::WrappedTargetException, + com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL + removePropertyChangeListener( const rtl::OUString& aPropertyName, + const com::sun::star::uno::Reference< + com::sun::star::beans::XPropertyChangeListener >& aListener ) + throw( com::sun::star::beans::UnknownPropertyException, + com::sun::star::lang::WrappedTargetException, + com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL + addVetoableChangeListener( const rtl::OUString& PropertyName, + const com::sun::star::uno::Reference< + com::sun::star::beans::XVetoableChangeListener >& aListener ) + throw( com::sun::star::beans::UnknownPropertyException, + com::sun::star::lang::WrappedTargetException, + com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL + removeVetoableChangeListener( const rtl::OUString& PropertyName, + const com::sun::star::uno::Reference< + com::sun::star::beans::XVetoableChangeListener >& aListener ) + throw( com::sun::star::beans::UnknownPropertyException, + com::sun::star::lang::WrappedTargetException, + com::sun::star::uno::RuntimeException ); + + //----------------------------------------------------------------- + // own methods + //----------------------------------------------------------------- + virtual void SAL_CALL + impl_disposing( const com::sun::star::lang::EventObject& Source ) + throw( com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL + impl_propertyChange( const com::sun::star::beans::PropertyChangeEvent& evt ) + throw( com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL + impl_vetoableChange( const com::sun::star::beans::PropertyChangeEvent& aEvent ) + throw( com::sun::star::beans::PropertyVetoException, + com::sun::star::uno::RuntimeException ); + + //----------------------------------------------------------------- + // XContentAccess + //----------------------------------------------------------------- + virtual rtl::OUString SAL_CALL + queryContentIdentfierString() + throw( com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::uno::Reference< + com::sun::star::ucb::XContentIdentifier > SAL_CALL + queryContentIdentifier() + throw( com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::uno::Reference< + com::sun::star::ucb::XContent > SAL_CALL + queryContent() + throw( com::sun::star::uno::RuntimeException ); + + //----------------------------------------------------------------- + // XResultSet + //----------------------------------------------------------------- + virtual sal_Bool SAL_CALL + next() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL + isBeforeFirst() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL + isAfterLast() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL + isFirst() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL + isLast() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual void SAL_CALL + beforeFirst() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual void SAL_CALL + afterLast() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL + first() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL + last() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual sal_Int32 SAL_CALL + getRow() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL + absolute( sal_Int32 row ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL + relative( sal_Int32 rows ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL + previous() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual void SAL_CALL + refreshRow() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL + rowUpdated() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL + rowInserted() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL + rowDeleted() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + virtual com::sun::star::uno::Reference< + com::sun::star::uno::XInterface > SAL_CALL + getStatement() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + //----------------------------------------------------------------- + // XRow + //----------------------------------------------------------------- + virtual sal_Bool SAL_CALL + wasNull() + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual rtl::OUString SAL_CALL + getString( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual sal_Bool SAL_CALL + getBoolean( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual sal_Int8 SAL_CALL + getByte( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual sal_Int16 SAL_CALL + getShort( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual sal_Int32 SAL_CALL + getInt( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual sal_Int64 SAL_CALL + getLong( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual float SAL_CALL + getFloat( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual double SAL_CALL + getDouble( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL + getBytes( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::util::Date SAL_CALL + getDate( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::util::Time SAL_CALL + getTime( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::util::DateTime SAL_CALL + getTimestamp( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::uno::Reference< + com::sun::star::io::XInputStream > SAL_CALL + getBinaryStream( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::uno::Reference< + com::sun::star::io::XInputStream > SAL_CALL + getCharacterStream( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::uno::Any SAL_CALL + getObject( sal_Int32 columnIndex, + const com::sun::star::uno::Reference< + com::sun::star::container::XNameAccess >& typeMap ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::uno::Reference< + com::sun::star::sdbc::XRef > SAL_CALL + getRef( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::uno::Reference< + com::sun::star::sdbc::XBlob > SAL_CALL + getBlob( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::uno::Reference< + com::sun::star::sdbc::XClob > SAL_CALL + getClob( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::uno::Reference< + com::sun::star::sdbc::XArray > SAL_CALL + getArray( sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); +}; + +//========================================================================= + +class ContentResultSetWrapperListener + : public cppu::OWeakObject + , public com::sun::star::beans::XPropertyChangeListener + , public com::sun::star::beans::XVetoableChangeListener +{ +protected: + ContentResultSetWrapper* m_pOwner; + +public: + ContentResultSetWrapperListener( ContentResultSetWrapper* pOwner ); + + virtual ~ContentResultSetWrapperListener(); + + //----------------------------------------------------------------- + // XInterface + //----------------------------------------------------------------- + XINTERFACE_DECL() + + //----------------------------------------------------------------- + //XEventListener + //----------------------------------------------------------------- + virtual void SAL_CALL + disposing( const com::sun::star::lang::EventObject& Source ) + throw( com::sun::star::uno::RuntimeException ); + + //----------------------------------------------------------------- + //XPropertyChangeListener + //----------------------------------------------------------------- + virtual void SAL_CALL + propertyChange( const com::sun::star::beans::PropertyChangeEvent& evt ) + throw( com::sun::star::uno::RuntimeException ); + + //----------------------------------------------------------------- + //XVetoableChangeListener + //----------------------------------------------------------------- + virtual void SAL_CALL + vetoableChange( const com::sun::star::beans::PropertyChangeEvent& aEvent ) + throw( com::sun::star::beans::PropertyVetoException, + com::sun::star::uno::RuntimeException ); + + //----------------------------------------------------------------- + // own methods: + void SAL_CALL impl_OwnerDies(); +}; + +#endif + diff --git a/ucb/source/cacher/dynamicresultsetwrapper.cxx b/ucb/source/cacher/dynamicresultsetwrapper.cxx new file mode 100644 index 000000000000..8ace53a28d7b --- /dev/null +++ b/ucb/source/cacher/dynamicresultsetwrapper.cxx @@ -0,0 +1,566 @@ +/************************************************************************* + * + * $RCSfile: dynamicresultsetwrapper.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:52:35 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include <dynamicresultsetwrapper.hxx> + +#ifndef _UCBHELPER_MACROS_HXX +#include <ucbhelper/macros.hxx> +#endif + +#ifndef _RTL_USTRING_HXX_ +#include <rtl/ustring.hxx> +#endif + +#ifndef _TOOLS_DEBUG_HXX +#include <tools/debug.hxx> +#endif + +#ifndef _COM_SUN_STAR_UCB_LISTACTIONTYPE_HPP_ +#include <com/sun/star/ucb/ListActionType.hpp> +#endif + +#ifndef _COM_SUN_STAR_UCB_WELCOMEDYNAMICRESULTSETSTRUCT_HPP_ +#include <com/sun/star/ucb/WelcomeDynamicResultSetStruct.hpp> +#endif + +#ifndef _COM_SUN_STAR_UCB_XCACHEDDYNAMICRESULTSETSTUBFACTORY_HPP_ +#include <com/sun/star/ucb/XCachedDynamicResultSetStubFactory.hpp> +#endif + +using namespace com::sun::star::lang; +using namespace com::sun::star::sdbc; +using namespace com::sun::star::ucb; +using namespace com::sun::star::uno; +using namespace cppu; +using namespace rtl; + +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- +// class DynamicResultSetWrapper +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- + +DynamicResultSetWrapper::DynamicResultSetWrapper( + Reference< XDynamicResultSet > xOrigin + , const Reference< XMultiServiceFactory > & xSMgr ) + + : m_xSMgr( xSMgr ) + , m_xSource( xOrigin ) + , m_xSourceResultOne( NULL ) + , m_xSourceResultTwo( NULL ) + // , m_xSourceResultCurrent( NULL ) + // , m_bUseOne( NULL ) + , m_xMyResultOne( NULL ) + , m_xMyResultTwo( NULL ) + , m_xListener( NULL ) + , m_pDisposeEventListeners( NULL ) + , m_bDisposed( sal_False ) + , m_bInDispose( sal_False ) + , m_bStatic( sal_False ) + , m_bGotWelcome( sal_False ) +{ + m_pMyListenerImpl = new DynamicResultSetWrapperListener( this ); + m_xMyListenerImpl = Reference< XDynamicResultSetListener >( m_pMyListenerImpl ); + //call impl_init() at the end of constructor of derived class +}; + +void SAL_CALL DynamicResultSetWrapper::impl_init() +{ + //call this at the end of constructor of derived class + // + + Reference< XDynamicResultSet > xSource = NULL; + { + vos::OGuard aGuard( m_aMutex ); + xSource = m_xSource; + m_xSource = NULL; + } + if( xSource.is() ) + setSource( xSource ); +} + +DynamicResultSetWrapper::~DynamicResultSetWrapper() +{ + //call impl_deinit() at start of destructor of derived class + + delete m_pDisposeEventListeners; +}; + +void SAL_CALL DynamicResultSetWrapper::impl_deinit() +{ + //call this at start of destructor of derived class + // + m_pMyListenerImpl->impl_OwnerDies(); +} + +void SAL_CALL DynamicResultSetWrapper +::impl_EnsureNotDisposed() + throw( DisposedException, RuntimeException ) +{ + vos::OGuard aGuard( m_aMutex ); + if( m_bDisposed ) + throw DisposedException(); +} + +//virtual +void SAL_CALL DynamicResultSetWrapper +::impl_InitResultSetOne( const Reference< XResultSet >& xResultSet ) +{ + vos::OGuard aGuard( m_aMutex ); + DBG_ASSERT( !m_xSourceResultOne.is(), "Source ResultSet One is set already" ); + m_xSourceResultOne = xResultSet; + m_xMyResultOne = xResultSet; +} + +//virtual +void SAL_CALL DynamicResultSetWrapper +::impl_InitResultSetTwo( const Reference< XResultSet >& xResultSet ) +{ + vos::OGuard aGuard( m_aMutex ); + DBG_ASSERT( !m_xSourceResultTwo.is(), "Source ResultSet Two is set already" ); + m_xSourceResultTwo = xResultSet; + m_xMyResultTwo = xResultSet; +} + +//-------------------------------------------------------------------------- +// XInterface methods. +//-------------------------------------------------------------------------- +//list all interfaces inclusive baseclasses of interfaces +QUERYINTERFACE_IMPL_START( DynamicResultSetWrapper ) + SAL_STATIC_CAST( XComponent*, this ) //base of XDynamicResultSet + , SAL_STATIC_CAST( XDynamicResultSet*, this ) + , SAL_STATIC_CAST( XSourceInitialization*, this ) +QUERYINTERFACE_IMPL_END + +//-------------------------------------------------------------------------- +// XComponent methods. +//-------------------------------------------------------------------------- +// virtual +void SAL_CALL DynamicResultSetWrapper + ::dispose() throw( RuntimeException ) +{ + impl_EnsureNotDisposed(); + + Reference< XComponent > xSourceComponent; + { + vos::OClearableGuard aGuard( m_aMutex ); + if( m_bInDispose || m_bDisposed ) + return; + m_bInDispose = sal_True; + + xSourceComponent = Reference< XComponent >(m_xSource, UNO_QUERY); + + if( m_pDisposeEventListeners && m_pDisposeEventListeners->getLength() ) + { + EventObject aEvt; + aEvt.Source = static_cast< XComponent * >( this ); + + aGuard.clear(); + m_pDisposeEventListeners->disposeAndClear( aEvt ); + } + } + + /* //@todo ?? ( only if java collection needs to long ) + if( xSourceComponent.is() ) + xSourceComponent->dispose(); + */ + + vos::OGuard aGuard( m_aMutex ); + m_bDisposed = sal_True; + m_bInDispose = sal_False; +} + +//-------------------------------------------------------------------------- +// virtual +void SAL_CALL DynamicResultSetWrapper + ::addEventListener( const Reference< XEventListener >& Listener ) + throw( RuntimeException ) +{ + impl_EnsureNotDisposed(); + vos::OGuard aGuard( m_aMutex ); + + if ( !m_pDisposeEventListeners ) + m_pDisposeEventListeners = + new OInterfaceContainerHelper( m_aContainerMutex ); + + m_pDisposeEventListeners->addInterface( Listener ); +} + +//-------------------------------------------------------------------------- +// virtual +void SAL_CALL DynamicResultSetWrapper + ::removeEventListener( const Reference< XEventListener >& Listener ) + throw( RuntimeException ) +{ + impl_EnsureNotDisposed(); + vos::OGuard aGuard( m_aMutex ); + + if ( m_pDisposeEventListeners ) + m_pDisposeEventListeners->removeInterface( Listener ); +} + +//-------------------------------------------------------------------------- +// own methods +//-------------------------------------------------------------------------- + +//virtual +void SAL_CALL DynamicResultSetWrapper + ::impl_disposing( const EventObject& rEventObject ) + throw( RuntimeException ) +{ + impl_EnsureNotDisposed(); + + vos::OGuard aGuard( m_aMutex ); + + if( !m_xSource.is() ) + return; + + //release all references to the broadcaster: + m_xSource.clear(); + m_xSourceResultOne.clear();//?? or only when not static?? + m_xSourceResultTwo.clear();//?? + //@todo m_xMyResultOne.clear(); ??? + //@todo m_xMyResultTwo.clear(); ??? +} + +//virtual +void SAL_CALL DynamicResultSetWrapper + ::impl_notify( const ListEvent& Changes ) + throw( RuntimeException ) +{ + impl_EnsureNotDisposed(); + //@todo + /* + <p>The Listener is allowed to blockade this call, until he really want to go + to the new version. The only situation, where the listener has to return the + update call at once is, while he disposes his broadcaster or while he is + removing himsef as listener (otherwise you deadlock)!!! + */ + // handle the actions in the list + + ListEvent aNewEvent; + aNewEvent.Source = static_cast< XDynamicResultSet * >( this ); + aNewEvent.Changes = Changes.Changes; + + { + vos::OGuard aGuard( m_aMutex ); + for( long i=0; !m_bGotWelcome && i<Changes.Changes.getLength(); i++ ) + { + ListAction& rAction = aNewEvent.Changes[i]; + switch( rAction.ListActionType ) + { + case ListActionType::WELCOME: + { + WelcomeDynamicResultSetStruct aWelcome; + if( rAction.ActionInfo >>= aWelcome ) + { + impl_InitResultSetOne( aWelcome.Old ); + impl_InitResultSetTwo( aWelcome.New ); + m_bGotWelcome = TRUE; + + aWelcome.Old = m_xMyResultOne; + aWelcome.New = m_xMyResultTwo; + + rAction.ActionInfo <<= aWelcome; + } + else + { + DBG_ERROR( "ListActionType was WELCOME but ActionInfo didn't contain a WelcomeDynamicResultSetStruct" ); + //throw RuntimeException(); + } + break; + } + } + } + DBG_ASSERT( m_bGotWelcome, "first notification was without WELCOME" ); + } + + if( !m_xListener.is() ) + m_aListenerSet.wait(); + m_xListener->notify( aNewEvent ); + + /* + m_bUseOne = !m_bUseOne; + if( m_bUseOne ) + m_xSourceResultCurrent = m_xSourceResultOne; + else + m_xSourceResultCurrent = m_xSourceResultTwo; + */ +} + +//-------------------------------------------------------------------------- +// XSourceInitialization +//-------------------------------------------------------------------------- +//virtual +void SAL_CALL DynamicResultSetWrapper + ::setSource( const Reference< XInterface > & Source ) + throw( AlreadyInitializedException, RuntimeException ) +{ + impl_EnsureNotDisposed(); + { + vos::OGuard aGuard( m_aMutex ); + if( m_xSource.is() ) + { + throw AlreadyInitializedException(); + } + } + + Reference< XDynamicResultSet > xSourceDynamic( Source, UNO_QUERY ); + DBG_ASSERT( xSourceDynamic.is(), + "the given source is not of required type XDynamicResultSet" ); + + Reference< XDynamicResultSetListener > xListener = NULL; + Reference< XDynamicResultSetListener > xMyListenerImpl = NULL; + + BOOL bStatic = FALSE; + { + vos::OGuard aGuard( m_aMutex ); + m_xSource = xSourceDynamic; + xListener = m_xListener; + bStatic = m_bStatic; + xMyListenerImpl = m_xMyListenerImpl; + } + if( xListener.is() ) + xSourceDynamic->setListener( m_xMyListenerImpl ); + else if( bStatic ) + { + Reference< XComponent > xSourceComponent( Source, UNO_QUERY ); + xSourceComponent->addEventListener( Reference< XEventListener > ::query( xMyListenerImpl ) ); + } + m_aSourceSet.set(); +} + +//-------------------------------------------------------------------------- +// XDynamicResultSet +//-------------------------------------------------------------------------- +//virtual +Reference< XResultSet > SAL_CALL DynamicResultSetWrapper + ::getStaticResultSet() + throw( ListenerAlreadySetException, RuntimeException ) +{ + impl_EnsureNotDisposed(); + + Reference< XDynamicResultSet > xSource = NULL; + Reference< XEventListener > xMyListenerImpl = NULL; + { + vos::OGuard aGuard( m_aMutex ); + if( m_xListener.is() ) + throw ListenerAlreadySetException(); + + xSource = m_xSource; + m_bStatic = sal_True; + xMyListenerImpl = Reference< XEventListener > ::query( m_xMyListenerImpl ); + } + + if( xSource.is() ) + { + Reference< XComponent > xSourceComponent( xSource, UNO_QUERY ); + xSourceComponent->addEventListener( xMyListenerImpl ); + } + if( !xSource.is() ) + m_aSourceSet.wait(); + + + Reference< XResultSet > xResultSet = xSource->getStaticResultSet(); + impl_InitResultSetOne( xResultSet ); + return m_xMyResultOne; +} + +//virtual +void SAL_CALL DynamicResultSetWrapper + ::setListener( const Reference< + XDynamicResultSetListener > & Listener ) + throw( ListenerAlreadySetException, RuntimeException ) +{ + impl_EnsureNotDisposed(); + + Reference< XDynamicResultSet > xSource = NULL; + Reference< XDynamicResultSetListener > xMyListenerImpl = NULL; + { + vos::OGuard aGuard( m_aMutex ); + if( m_xListener.is() ) + throw ListenerAlreadySetException(); + if( m_bStatic ) + throw ListenerAlreadySetException(); + + m_xListener = Listener; + addEventListener( Reference< XEventListener >::query( Listener ) ); + + xSource = m_xSource; + xMyListenerImpl = m_xMyListenerImpl; + } + if ( xSource.is() ) + xSource->setListener( xMyListenerImpl ); + + m_aListenerSet.set(); +} + +//virtual +void SAL_CALL DynamicResultSetWrapper + ::connectToCache( const Reference< XDynamicResultSet > & xCache ) + throw( ListenerAlreadySetException, AlreadyInitializedException, ServiceNotFoundException, RuntimeException ) +{ + impl_EnsureNotDisposed(); + + if( m_xListener.is() ) + throw ListenerAlreadySetException(); + if( m_bStatic ) + throw ListenerAlreadySetException(); + + Reference< XSourceInitialization > xTarget( xCache, UNO_QUERY ); + DBG_ASSERT( xTarget.is(), "The given Target dosn't have the required interface 'XSourceInitialization'" ); + if( xTarget.is() && m_xSMgr.is() ) + { + //@todo m_aSourceSet.wait();? + Reference< XCachedDynamicResultSetStubFactory > xStubFactory( + m_xSMgr->createInstance( OUString::createFromAscii( + "com.sun.star.ucb.CachedDynamicResultSetStubFactory" ) ), UNO_QUERY ); + if( xStubFactory.is() ) + { + xStubFactory->connectToCache( + this, xCache, Sequence< NumberedSortingInfo > (), NULL ); + return; + } + } + DBG_ERROR( "could not connect to cache" ); + throw ServiceNotFoundException(); +} + +//virtual +sal_Int16 SAL_CALL DynamicResultSetWrapper + ::getCapabilities() + throw( RuntimeException ) +{ + impl_EnsureNotDisposed(); + + m_aSourceSet.wait(); + Reference< XDynamicResultSet > xSource = NULL; + { + vos::OGuard aGuard( m_aMutex ); + xSource = m_xSource; + } + return xSource->getCapabilities(); +} + +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- +// class DynamicResultSetWrapperListener +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- + +DynamicResultSetWrapperListener::DynamicResultSetWrapperListener( + DynamicResultSetWrapper* pOwner ) + : m_pOwner( pOwner ) +{ + +} + +DynamicResultSetWrapperListener::~DynamicResultSetWrapperListener() +{ + +} + +//-------------------------------------------------------------------------- +// XInterface methods. +//-------------------------------------------------------------------------- +//list all interfaces inclusive baseclasses of interfaces +XINTERFACE_IMPL_2( DynamicResultSetWrapperListener + , XDynamicResultSetListener + , XEventListener //base of XDynamicResultSetListener + ); + +//-------------------------------------------------------------------------- +// XDynamicResultSetListener methods: +//-------------------------------------------------------------------------- +//virtual +void SAL_CALL DynamicResultSetWrapperListener + ::disposing( const EventObject& rEventObject ) + throw( RuntimeException ) +{ + vos::OGuard aGuard( m_aMutex ); + + if( m_pOwner ) + m_pOwner->impl_disposing( rEventObject ); +} + +//virtual +void SAL_CALL DynamicResultSetWrapperListener + ::notify( const ListEvent& Changes ) + throw( RuntimeException ) +{ + vos::OGuard aGuard( m_aMutex ); + + if( m_pOwner ) + m_pOwner->impl_notify( Changes ); +} + +//-------------------------------------------------------------------------- +// own methods: +//-------------------------------------------------------------------------- + +void SAL_CALL DynamicResultSetWrapperListener + ::impl_OwnerDies() +{ + vos::OGuard aGuard( m_aMutex ); + + m_pOwner = NULL; +} + diff --git a/ucb/source/cacher/dynamicresultsetwrapper.hxx b/ucb/source/cacher/dynamicresultsetwrapper.hxx new file mode 100644 index 000000000000..58c9b4d09c96 --- /dev/null +++ b/ucb/source/cacher/dynamicresultsetwrapper.hxx @@ -0,0 +1,295 @@ +/************************************************************************* + * + * $RCSfile: dynamicresultsetwrapper.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:52:35 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _DYNAMIC_RESULTSET_WRAPPER_HXX +#define _DYNAMIC_RESULTSET_WRAPPER_HXX + +#ifndef _VOS_MUTEX_HXX_ +#include <vos/mutex.hxx> +#endif + +#ifndef _VOS_CONDITN_HXX_ +#include <vos/conditn.hxx> +#endif + +#ifndef _UCBHELPER_MACROS_HXX +#include <ucbhelper/macros.hxx> +#endif + +#ifndef _CPPUHELPER_WEAK_HXX_ +#include <cppuhelper/weak.hxx> +#endif + +#ifndef _COM_SUN_STAR_LANG_XTYPEPROVIDER_HPP_ +#include <com/sun/star/lang/XTypeProvider.hpp> +#endif + +#ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_ +#include <com/sun/star/lang/XServiceInfo.hpp> +#endif + +#ifndef _CPPUHELPER_INTERFACECONTAINER_HXX_ +#include <cppuhelper/interfacecontainer.hxx> +#endif + +#ifndef _COM_SUN_STAR_UCB_XDYNAMICRESULTSET_HPP_ +#include <com/sun/star/ucb/XDynamicResultSet.hpp> +#endif + +#ifndef _COM_SUN_STAR_UCB_XSOURCEINITIALIZATION_HPP_ +#include <com/sun/star/ucb/XSourceInitialization.hpp> +#endif + +#ifndef __com_sun_star_lang_DisposedException_idl__ +#include <com/sun/star/lang/DisposedException.hpp> +#endif + +#ifndef _COM_SUN_STAR_UCB_XDYNAMICRESULTSETLISTENER_HPP_ +#include <com/sun/star/ucb/XDynamicResultSetListener.hpp> +#endif + +#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#endif + +//#define CACHED_CRS_STUB_SERVICE_NAME "com.sun.star.ucb.CachedContentResultSetStub" +//#define CACHED_CRS_STUB_FACTORY_NAME "com.sun.star.ucb.CachedContentResultSetStubFactory" + +//========================================================================= + +class DynamicResultSetWrapperListener; +class DynamicResultSetWrapper + : public cppu::OWeakObject + , public com::sun::star::ucb::XDynamicResultSet + , public com::sun::star::ucb::XSourceInitialization +{ +private: + //management of listeners + sal_Bool m_bDisposed; ///Dispose call ready. + sal_Bool m_bInDispose;///In dispose call + osl::Mutex m_aContainerMutex; + cppu::OInterfaceContainerHelper* + m_pDisposeEventListeners; +protected: + com::sun::star::uno::Reference< com::sun::star::ucb::XDynamicResultSetListener > + m_xMyListenerImpl; + DynamicResultSetWrapperListener* + m_pMyListenerImpl; + + com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > + m_xSMgr; + + vos::OMutex m_aMutex; + sal_Bool m_bStatic; + sal_Bool m_bGotWelcome; + + //different Interfaces from Origin: + com::sun::star::uno::Reference< com::sun::star::ucb::XDynamicResultSet > + m_xSource; + com::sun::star::uno::Reference< com::sun::star::sdbc::XResultSet > + m_xSourceResultOne; + com::sun::star::uno::Reference< com::sun::star::sdbc::XResultSet > + m_xSourceResultTwo; + //com::sun::star::uno::Reference< com::sun::star::sdbc::XResultSet > + // m_xSourceResultCurrent; + //sal_Bool m_bUseOne; + // + com::sun::star::uno::Reference< com::sun::star::sdbc::XResultSet > + m_xMyResultOne; + com::sun::star::uno::Reference< com::sun::star::sdbc::XResultSet > + m_xMyResultTwo; + // + com::sun::star::uno::Reference< com::sun::star::ucb::XDynamicResultSetListener > + m_xListener; + + vos::OCondition m_aSourceSet; + vos::OCondition m_aListenerSet; + +protected: + void SAL_CALL impl_init(); + void SAL_CALL impl_deinit(); + void SAL_CALL + impl_EnsureNotDisposed() + throw( com::sun::star::lang::DisposedException, + com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL + impl_InitResultSetOne( const com::sun::star::uno::Reference< + com::sun::star::sdbc::XResultSet >& xResultSet ); + virtual void SAL_CALL + impl_InitResultSetTwo( const com::sun::star::uno::Reference< + com::sun::star::sdbc::XResultSet >& xResultSet ); + +public: + + DynamicResultSetWrapper( + com::sun::star::uno::Reference< + com::sun::star::ucb::XDynamicResultSet > xOrigin + , const com::sun::star::uno::Reference< + com::sun::star::lang::XMultiServiceFactory > & xSMgr ); + + virtual ~DynamicResultSetWrapper(); + + //----------------------------------------------------------------- + // XInterface + virtual com::sun::star::uno::Any SAL_CALL + queryInterface( const com::sun::star::uno::Type & rType ) + throw( com::sun::star::uno::RuntimeException ); + + //----------------------------------------------------------------- + // XDynamicResultSet + virtual com::sun::star::uno::Reference< com::sun::star::sdbc::XResultSet > SAL_CALL + getStaticResultSet() + throw( com::sun::star::ucb::ListenerAlreadySetException + , com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL + setListener( const com::sun::star::uno::Reference< + com::sun::star::ucb::XDynamicResultSetListener > & Listener ) + throw( com::sun::star::ucb::ListenerAlreadySetException + , com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL + connectToCache( const com::sun::star::uno::Reference< + com::sun::star::ucb::XDynamicResultSet > & xCache ) + throw( com::sun::star::ucb::ListenerAlreadySetException + , com::sun::star::ucb::AlreadyInitializedException + , com::sun::star::ucb::ServiceNotFoundException + , com::sun::star::uno::RuntimeException ); + + virtual sal_Int16 SAL_CALL + getCapabilities() throw( com::sun::star::uno::RuntimeException ); + + //----------------------------------------------------------------- + // XComponent ( base of XDynamicResultSet ) + virtual void SAL_CALL + dispose() throw( com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL + addEventListener( const com::sun::star::uno::Reference< + com::sun::star::lang::XEventListener >& Listener ) + throw( com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL + removeEventListener( const com::sun::star::uno::Reference< + com::sun::star::lang::XEventListener >& Listener ) + throw( com::sun::star::uno::RuntimeException ); + + //----------------------------------------------------------------- + // XSourceInitialization + + virtual void SAL_CALL + setSource( const com::sun::star::uno::Reference< + com::sun::star::uno::XInterface > & Source ) + throw( com::sun::star::ucb::AlreadyInitializedException + , com::sun::star::uno::RuntimeException ); + + //----------------------------------------------------------------- + // own methods: + virtual void SAL_CALL + impl_disposing( const com::sun::star::lang::EventObject& Source ) + throw( com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL + impl_notify( const ::com::sun::star::ucb::ListEvent& Changes ) + throw( com::sun::star::uno::RuntimeException ); +}; + +//========================================================================= + +class DynamicResultSetWrapperListener + : public cppu::OWeakObject + , public com::sun::star::ucb::XDynamicResultSetListener +{ +protected: + DynamicResultSetWrapper* m_pOwner; + ::vos::OMutex m_aMutex; + +public: + DynamicResultSetWrapperListener( DynamicResultSetWrapper* pOwner ); + + virtual ~DynamicResultSetWrapperListener(); + + //----------------------------------------------------------------- + // XInterface + //----------------------------------------------------------------- + XINTERFACE_DECL() + + //----------------------------------------------------------------- + // XEventListener ( base of XDynamicResultSetListener ) + //----------------------------------------------------------------- + virtual void SAL_CALL + disposing( const com::sun::star::lang::EventObject& Source ) + throw( com::sun::star::uno::RuntimeException ); + //----------------------------------------------------------------- + // XDynamicResultSetListener + virtual void SAL_CALL + notify( const ::com::sun::star::ucb::ListEvent& Changes ) + throw( com::sun::star::uno::RuntimeException ); + + //----------------------------------------------------------------- + // own methods: + void SAL_CALL impl_OwnerDies(); +}; + + +#endif + diff --git a/ucb/source/cacher/makefile.mk b/ucb/source/cacher/makefile.mk new file mode 100644 index 000000000000..c031d2195d35 --- /dev/null +++ b/ucb/source/cacher/makefile.mk @@ -0,0 +1,131 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1 $ +# +# last change: $Author: kso $ $Date: 2000-10-16 14:52:35 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (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.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=..$/.. +PRJNAME=ucb +TARGET=cached +ENABLE_EXCEPTIONS=TRUE +NO_BSYMBOLIC=TRUE + +# Version +UCB_MAJOR=1 + +.INCLUDE: svpre.mk +.INCLUDE: settings.mk +.INCLUDE: sv.mk + +#INCPRE+=$(PRJ)$/source$/inc + +SLOFILES=\ + $(SLO)$/contentresultsetwrapper.obj \ + $(SLO)$/cachedcontentresultsetstub.obj \ + $(SLO)$/cachedcontentresultset.obj \ + $(SLO)$/dynamicresultsetwrapper.obj \ + $(SLO)$/cacheddynamicresultsetstub.obj \ + $(SLO)$/cacheddynamicresultset.obj \ + $(SLO)$/cacheserv.obj + +# NETBSD: somewhere we have to instantiate the static data members. +# NETBSD-1.2.1 doesn't know about weak symbols so the default mechanism for GCC won't work. +# SCO and MACOSX: the linker does know about weak symbols, but we can't ignore multiple defined symbols +.IF "$(OS)"=="NETBSD" || "$(OS)"=="SCO" || "$(OS)$(COM)"=="OS2GCC" || "$(OS)"=="MACOSX" +SLOFILES+=$(SLO)$/staticmbcacher.obj +.ENDIF + +LIB1TARGET=$(SLB)$/_$(TARGET).lib +LIB1OBJFILES=$(SLOFILES) + +SHL1TARGET=$(TARGET)$(UCB_MAJOR) +SHL1DEF=$(MISC)$/$(SHL1TARGET).def +SHL1STDLIBS=\ + $(CPPUHELPERLIB) \ + $(CPPULIB) \ + $(SALLIB) \ + $(TOOLSLIB) \ + $(VOSLIB) + +SHL1LIBS=$(LIB1TARGET) +SHL1IMPLIB=i$(TARGET) + +DEF1DEPN=$(MISC)$/$(SHL1TARGET).flt +DEF1NAME=$(SHL1TARGET) +DEF1EXPORT1 =component_getImplementationEnvironment +DEF1EXPORT2 =component_writeInfo +DEF1EXPORT3 =component_getFactory +DEF1DES=Cached Dynamic Resultset + +.INCLUDE: target.mk + +$(MISC)$/$(SHL1TARGET).flt: + @echo ------------------------------ + @echo Making: $@ +# @echo Type >> $@ + @echo cpp >> $@ + @echo m_ >> $@ + @echo rtl >> $@ + @echo vos >> $@ + @echo component_getImplementationEnvironment >> $@ + @echo component_writeInfo >> $@ + @echo component_getFactory >> $@ +.IF "$(COM)"=="MSC" + @echo ??_ >> $@ +.ENDIF # COM MSC diff --git a/ucb/source/core/identify.cxx b/ucb/source/core/identify.cxx new file mode 100644 index 000000000000..a93bb478df7e --- /dev/null +++ b/ucb/source/core/identify.cxx @@ -0,0 +1,149 @@ +/************************************************************************* + * + * $RCSfile: identify.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:52:48 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +/************************************************************************** + TODO + ************************************************************************** + + *************************************************************************/ + +#pragma hdrstop + +#include "identify.hxx" + +using namespace rtl; +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::ucb; + +//========================================================================= +// +// ContentIdentifier Implementation. +// +//========================================================================= + +ContentIdentifier::ContentIdentifier( + const Reference< XMultiServiceFactory >& rxSMgr, + const OUString& ContentId ) +: m_xSMgr( rxSMgr ), + m_aContentId( ContentId ) +{ +} + +//========================================================================= +// virtual +ContentIdentifier::~ContentIdentifier() +{ +} + +//========================================================================= +// +// XInterface methods. +// +//========================================================================= + +XINTERFACE_IMPL_2( ContentIdentifier, + XTypeProvider, + XContentIdentifier ); + +//========================================================================= +// +// XTypeProvider methods. +// +//========================================================================= + +XTYPEPROVIDER_IMPL_2( ContentIdentifier, + XTypeProvider, + XContentIdentifier ); + +//========================================================================= +// +// XContentIdentifier methods. +// +//========================================================================= + +// virtual +OUString SAL_CALL ContentIdentifier::getContentIdentifier() + throw( RuntimeException ) +{ + return m_aContentId; +} + +//========================================================================= +// virtual +OUString SAL_CALL ContentIdentifier::getContentProviderScheme() + throw( RuntimeException ) +{ + if ( !m_aProviderScheme.getLength() && m_aContentId.getLength() ) + { + // The content provider scheme is the part before the first ':' + // within the content id. + sal_Int32 nPos = m_aContentId.indexOf( ':', 0 ); + if ( nPos != -1 ) + { + OUString aScheme( m_aContentId.copy( 0, nPos ) ); + m_aProviderScheme = aScheme.toLowerCase(); + } + } + + return m_aProviderScheme; +} + diff --git a/ucb/source/core/identify.hxx b/ucb/source/core/identify.hxx new file mode 100644 index 000000000000..bf8f5530a817 --- /dev/null +++ b/ucb/source/core/identify.hxx @@ -0,0 +1,116 @@ +/************************************************************************* + * + * $RCSfile: identify.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:52:48 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _IDENTIFY_HXX +#define _IDENTIFY_HXX + +#ifndef _COM_SUN_STAR_UCB_XCONTENTIDENTIFIER_HPP_ +#include <com/sun/star/ucb/XContentIdentifier.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XTYPEPROVIDER_HPP_ +#include <com/sun/star/lang/XTypeProvider.hpp> +#endif + +#ifndef _RTL_USTRBUF_HXX_ +#include <rtl/ustrbuf.hxx> +#endif +#ifndef _CPPUHELPER_WEAK_HXX_ +#include <cppuhelper/weak.hxx> +#endif + +#ifndef _UCBHELPER_MACROS_HXX +#include <ucbhelper/macros.hxx> +#endif + +//========================================================================= + +class ContentIdentifier : + public cppu::OWeakObject, + public com::sun::star::lang::XTypeProvider, + public com::sun::star::ucb::XContentIdentifier +{ +public: + ContentIdentifier( const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& rxSMgr, + const rtl::OUString& ContentId ); + virtual ~ContentIdentifier(); + + // XInterface + XINTERFACE_DECL() + + // XTypeProvider + XTYPEPROVIDER_DECL() + + // XContentIdentifier + virtual rtl::OUString SAL_CALL getContentIdentifier() + throw( com::sun::star::uno::RuntimeException ); + virtual rtl::OUString SAL_CALL getContentProviderScheme() + throw( com::sun::star::uno::RuntimeException ); + +private: + com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > m_xSMgr; + rtl::OUString m_aContentId; + rtl::OUString m_aProviderScheme; +}; + +#endif /* !_IDENTIFY_HXX */ diff --git a/ucb/source/core/makefile.mk b/ucb/source/core/makefile.mk new file mode 100644 index 000000000000..9d58bb35ae51 --- /dev/null +++ b/ucb/source/core/makefile.mk @@ -0,0 +1,132 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1 $ +# +# last change: $Author: kso $ $Date: 2000-10-16 14:52:48 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (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.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=..$/.. +PRJNAME=ucb +TARGET=ucb +ENABLE_EXCEPTIONS=TRUE +NO_BSYMBOLIC=TRUE + +# Version +UCB_MAJOR=1 + +.INCLUDE: svpre.mk +.INCLUDE: settings.mk +.INCLUDE: sv.mk + +SLOFILES=\ + $(SLO)$/flatany.obj \ + $(SLO)$/identify.obj \ + $(SLO)$/ucb.obj \ + $(SLO)$/ucbcfg.obj \ + $(SLO)$/ucbdistributor.obj \ + $(SLO)$/ucbserv.obj \ + $(SLO)$/ucbstore.obj \ + $(SLO)$/ucbprops.obj \ + $(SLO)$/provprox.obj + +# NETBSD: somewhere we have to instantiate the static data members. +# NETBSD-1.2.1 doesn't know about weak symbols so the default mechanism for GCC won't work. +# SCO and MACOSX: the linker does know about weak symbols, but we can't ignore multiple defined symbols +.IF "$(OS)"=="NETBSD" || "$(OS)"=="SCO" || "$(OS)$(COM)"=="OS2GCC" || "$(OS)"=="MACOSX" +SLOFILES+=$(SLO)$/staticmbucbcore.obj +.ENDIF + +LIB1TARGET=$(SLB)$/_$(TARGET).lib +LIB1OBJFILES=$(SLOFILES) + +SHL1TARGET=$(TARGET)$(UCB_MAJOR) +SHL1DEF=$(MISC)$/$(SHL1TARGET).def +SHL1STDLIBS=\ + $(CPPUHELPERLIB) \ + $(CPPULIB) \ + $(SALLIB) \ + $(STORELIB) \ + $(UCBHELPERLIB) +SHL1LIBS=\ + $(LIB1TARGET) \ + $(SLB)$/regexp.lib +SHL1IMPLIB=i$(TARGET) + +DEF1DEPN=$(MISC)$/$(SHL1TARGET).flt +DEF1NAME=$(SHL1TARGET) +DEF1EXPORT1 =component_getImplementationEnvironment +DEF1EXPORT2 =component_writeInfo +DEF1EXPORT3 =component_getFactory +DEF1DES=Universal Content Broker + +.INCLUDE: target.mk + +$(MISC)$/$(SHL1TARGET).flt: + @echo ------------------------------ + @echo Making: $@ +# @echo Type >> $@ + @echo cpp >> $@ + @echo m_ >> $@ + @echo rtl >> $@ + @echo vos >> $@ + @echo component_getImplementationEnvironment >> $@ + @echo component_writeInfo >> $@ + @echo component_getFactory >> $@ +.IF "$(COM)"=="MSC" + @echo ??_ >> $@ +.ENDIF # COM MSC diff --git a/ucb/source/core/providermap.hxx b/ucb/source/core/providermap.hxx new file mode 100644 index 000000000000..160e22c6a01e --- /dev/null +++ b/ucb/source/core/providermap.hxx @@ -0,0 +1,117 @@ +/************************************************************************* + * + * $RCSfile: providermap.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:52:48 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _UCB_PROVIDERMAP_HXX_ +#define _UCB_PROVIDERMAP_HXX_ + +#include <list> + +#ifndef _COM_SUN_STAR_UNO_REFERENCE_H_ +#include <com/sun/star/uno/Reference.h> +#endif + +#ifndef _UCB_REGEXPMAP_HXX_ +#include <regexpmap.hxx> +#endif + +namespace com { namespace sun { namespace star { namespace ucb { + class XContentProvider; +} } } } + +//============================================================================ +class ProviderListEntry_Impl +{ + com::sun::star::uno::Reference< + com::sun::star::ucb::XContentProvider > m_xProvider; + mutable com::sun::star::uno::Reference< + com::sun::star::ucb::XContentProvider > m_xResolvedProvider; + +private: + com::sun::star::uno::Reference< + com::sun::star::ucb::XContentProvider > resolveProvider() const; + +public: + ProviderListEntry_Impl( + const com::sun::star::uno::Reference< + com::sun::star::ucb::XContentProvider >& xProvider ) + : m_xProvider( xProvider ) {} + + com::sun::star::uno::Reference< + com::sun::star::ucb::XContentProvider > getProvider() const + { return m_xProvider; } + inline com::sun::star::uno::Reference< + com::sun::star::ucb::XContentProvider > getResolvedProvider() const; +}; + +inline com::sun::star::uno::Reference< com::sun::star::ucb::XContentProvider > +ProviderListEntry_Impl::getResolvedProvider() const +{ + return m_xResolvedProvider.is() ? m_xResolvedProvider : resolveProvider(); +} + +//============================================================================ +typedef std::list< ProviderListEntry_Impl > ProviderList_Impl; + +//============================================================================ +typedef ucb::RegexpMap< ProviderList_Impl > ProviderMap_Impl; + +#endif // _UCB_PROVIDERMAP_HXX_ + diff --git a/ucb/source/core/provprox.cxx b/ucb/source/core/provprox.cxx new file mode 100644 index 000000000000..c5cc3c0612d7 --- /dev/null +++ b/ucb/source/core/provprox.cxx @@ -0,0 +1,409 @@ +/************************************************************************* + * + * $RCSfile: provprox.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:52:48 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _OSL_DIAGNOSE_H_ +#include <osl/diagnose.h> +#endif +#ifndef _PROVPROX_HXX +#include "provprox.hxx" +#endif + +using namespace rtl; +using namespace com::sun::star::lang; +using namespace com::sun::star::ucb; +using namespace com::sun::star::uno; + +//========================================================================= +//========================================================================= +// +// UcbContentProviderProxyFactory Implementation. +// +//========================================================================= +//========================================================================= + +UcbContentProviderProxyFactory::UcbContentProviderProxyFactory( + const Reference< XMultiServiceFactory >& rxSMgr ) +: m_xSMgr( rxSMgr ) +{ +} + +//========================================================================= +// virtual +UcbContentProviderProxyFactory::~UcbContentProviderProxyFactory() +{ +} + +//========================================================================= +// +// XInterface methods. +// +//========================================================================= + +XINTERFACE_IMPL_3( UcbContentProviderProxyFactory, + XTypeProvider, + XServiceInfo, + XContentProviderFactory ); + +//========================================================================= +// +// XTypeProvider methods. +// +//========================================================================= + +XTYPEPROVIDER_IMPL_3( UcbContentProviderProxyFactory, + XTypeProvider, + XServiceInfo, + XContentProviderFactory ); + +//========================================================================= +// +// XServiceInfo methods. +// +//========================================================================= + +XSERVICEINFO_IMPL_1( UcbContentProviderProxyFactory, + OUString::createFromAscii( + "UcbContentProviderProxyFactory" ), + OUString::createFromAscii( + PROVIDER_FACTORY_SERVICE_NAME ) ); + +//========================================================================= +// +// Service factory implementation. +// +//========================================================================= + +ONE_INSTANCE_SERVICE_FACTORY_IMPL( UcbContentProviderProxyFactory ); + +//========================================================================= +// +// XContentProviderFactory methods. +// +//========================================================================= + +// virtual +Reference< XContentProvider > SAL_CALL +UcbContentProviderProxyFactory::createContentProvider( + const OUString& Service ) + throw( RuntimeException ) +{ + return Reference< XContentProvider >( + new UcbContentProviderProxy( m_xSMgr, Service ) ); +} + +//========================================================================= +//========================================================================= +// +// UcbContentProviderProxy Implementation. +// +//========================================================================= +//========================================================================= + +UcbContentProviderProxy::UcbContentProviderProxy( + const Reference< XMultiServiceFactory >& rxSMgr, + const OUString& Service ) +: m_aService( Service ), + m_bReplace( sal_False ), + m_bRegister( sal_False ), + m_xSMgr( rxSMgr ) +{ +} + +//========================================================================= +// virtual +UcbContentProviderProxy::~UcbContentProviderProxy() +{ +} + +//========================================================================= +// +// XInterface methods. +// +//========================================================================= + +XINTERFACE_COMMON_IMPL( UcbContentProviderProxy ); + +//============================================================================ +// virtual +Any SAL_CALL +UcbContentProviderProxy::queryInterface( const Type & rType ) + throw ( RuntimeException ) +{ + Any aRet = cppu::queryInterface( rType, + static_cast< XTypeProvider * >( this ), + static_cast< XServiceInfo * >( this ), + static_cast< XContentProvider * >( this ), + static_cast< XParameterizedContentProvider * >( this ), + static_cast< XContentProviderSupplier * >( this ) ); + + if ( !aRet.hasValue() ) + aRet = OWeakObject::queryInterface( rType ); + + if ( !aRet.hasValue() ) + { + // Get original provider an forward the call... + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + Reference< XContentProvider > xProvider = getContentProvider(); + if ( xProvider.is() ) + aRet = xProvider->queryInterface( rType ); + } + + return aRet; +} + +//========================================================================= +// +// XTypeProvider methods. +// +//========================================================================= + +XTYPEPROVIDER_IMPL_5( UcbContentProviderProxy, + XTypeProvider, + XServiceInfo, + XContentProvider, + XParameterizedContentProvider, + XContentProviderSupplier ); + +//========================================================================= +// +// XServiceInfo methods. +// +//========================================================================= + +XSERVICEINFO_NOFACTORY_IMPL_1( UcbContentProviderProxy, + OUString::createFromAscii( + "UcbContentProviderProxy" ), + OUString::createFromAscii( + PROVIDER_PROXY_SERVICE_NAME ) ); + +//========================================================================= +// +// XContentProvider methods. +// +//========================================================================= + +// virtual +Reference< XContent > SAL_CALL UcbContentProviderProxy::queryContent( + const Reference< XContentIdentifier >& Identifier ) + throw( IllegalIdentifierException, + RuntimeException ) +{ + // Get original provider an forward the call... + + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + + Reference< XContentProvider > xProvider = getContentProvider(); + if ( xProvider.is() ) + return xProvider->queryContent( Identifier ); + + return Reference< XContent >(); +} + +//========================================================================= +// virtual +sal_Int32 SAL_CALL UcbContentProviderProxy::compareContentIds( + const Reference< XContentIdentifier >& Id1, + const Reference< XContentIdentifier >& Id2 ) + throw( RuntimeException ) +{ + // Get original provider an forward the call... + + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + Reference< XContentProvider > xProvider = getContentProvider(); + if ( xProvider.is() ) + return xProvider->compareContentIds( Id1, Id2 ); + + OSL_ENSURE( sal_False, + "UcbContentProviderProxy::compareContentIds - No provider!" ); + + // @@@ What else? + return 0; +} + +//========================================================================= +// +// XParameterizedContentProvider methods. +// +//========================================================================= + +// virtual +Reference< XContentProvider > SAL_CALL +UcbContentProviderProxy::registerInstance( const OUString& Template, + const OUString& Arguments, + sal_Bool ReplaceExisting ) + throw( IllegalArgumentException, + RuntimeException ) +{ + // Just remember that this method was called ( and the params ). + + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + + if ( !m_bRegister ) + { +// m_xTargetProvider = 0; + m_aTemplate = Template; + m_aArguments = Arguments; + m_bReplace = ReplaceExisting; + + m_bRegister = sal_True; + } + return this; +} + +//========================================================================= +// virtual +Reference< XContentProvider > SAL_CALL +UcbContentProviderProxy::deregisterInstance( const OUString& Template, + const OUString& Arguments ) + throw( IllegalArgumentException, + RuntimeException ) +{ + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + + // registerInstance called at proxy and at original? + if ( m_bRegister && m_xTargetProvider.is() ) + { + m_bRegister = sal_False; + m_xTargetProvider = 0; + + Reference< XParameterizedContentProvider > + xParamProvider( m_xProvider, UNO_QUERY ); + if ( xParamProvider.is() ) + { + try + { + return xParamProvider->deregisterInstance( Template, + Arguments ); + } + catch ( IllegalIdentifierException const & ) + { + OSL_ENSURE( sal_False, + "UcbContentProviderProxy::deregisterInstance - " + "Caught IllegalIdentifierException!" ); + } + } + } + + return this; +} + +//========================================================================= +// +// XContentProviderSupplier methods. +// +//========================================================================= + +// virtual +Reference< XContentProvider > SAL_CALL +UcbContentProviderProxy::getContentProvider() + throw( RuntimeException ) +{ + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + if ( !m_xProvider.is() ) + { + try + { + m_xProvider + = Reference< XContentProvider >( + m_xSMgr->createInstance( m_aService ), UNO_QUERY ); + } + catch ( RuntimeException const & ) + { + throw; + } + catch ( Exception const & ) + { + } + + // registerInstance called at proxy, but not yet at original? + if ( m_xProvider.is() && m_bRegister ) + { + Reference< XParameterizedContentProvider > + xParamProvider( m_xProvider, UNO_QUERY ); + if ( xParamProvider.is() ) + { + try + { + m_xTargetProvider + = xParamProvider->registerInstance( m_aTemplate, + m_aArguments, + m_bReplace ); + } + catch ( IllegalIdentifierException const & ) + { + OSL_ENSURE( sal_False, + "UcbContentProviderProxy::getContentProvider - " + "Caught IllegalIdentifierException!" ); + } + + OSL_ENSURE( m_xTargetProvider.is(), + "UcbContentProviderProxy::getContentProvider - " + "No provider!" ); + } + } + if ( !m_xTargetProvider.is() ) + m_xTargetProvider = m_xProvider; + } + + OSL_ENSURE( m_xProvider.is(), + "UcbContentProviderProxy::getContentProvider - No provider!" ); + return m_xTargetProvider; +} diff --git a/ucb/source/core/provprox.hxx b/ucb/source/core/provprox.hxx new file mode 100644 index 000000000000..34a42a25650a --- /dev/null +++ b/ucb/source/core/provprox.hxx @@ -0,0 +1,221 @@ +/************************************************************************* + * + * $RCSfile: provprox.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:52:48 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _PROVPROX_HXX +#define _PROVPROX_HXX + +#ifndef _OSL_MUTEX_HXX_ +#include <osl/mutex.hxx> +#endif + +#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XTYPEPROVIDER_HPP_ +#include <com/sun/star/lang/XTypeProvider.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_ +#include <com/sun/star/lang/XServiceInfo.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCONTENTPROVIDERFACTORY_HPP_ +#include <com/sun/star/ucb/XContentProviderFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCONTENTPROVIDER_HPP_ +#include <com/sun/star/ucb/XContentProvider.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XPARAMETERIZEDCONTENTPROVIDER_HPP_ +#include <com/sun/star/ucb/XParameterizedContentProvider.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCONTENTPROVIDERSUPPLIER_HPP_ +#include <com/sun/star/ucb/XContentProviderSupplier.hpp> +#endif +#ifndef _CPPUHELPER_WEAK_HXX_ +#include <cppuhelper/weak.hxx> +#endif +#ifndef _UCBHELPER_MACROS_HXX +#include <ucbhelper/macros.hxx> +#endif + +//========================================================================= + +#define PROVIDER_FACTORY_SERVICE_NAME \ + "com.sun.star.ucb.ContentProviderProxyFactory" +#define PROVIDER_PROXY_SERVICE_NAME \ + "com.sun.star.ucb.ContentProviderProxy" + +//============================================================================ +// +// class UcbContentProviderProxyFactory. +// +//============================================================================ + +class UcbContentProviderProxyFactory : + public cppu::OWeakObject, + public com::sun::star::lang::XTypeProvider, + public com::sun::star::lang::XServiceInfo, + public com::sun::star::ucb::XContentProviderFactory +{ + com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > + m_xSMgr; + +public: + UcbContentProviderProxyFactory( + const com::sun::star::uno::Reference< + com::sun::star::lang::XMultiServiceFactory >& rxSMgr ); + virtual ~UcbContentProviderProxyFactory(); + + // XInterface + XINTERFACE_DECL() + + // XTypeProvider + XTYPEPROVIDER_DECL() + + // XServiceInfo + XSERVICEINFO_DECL() + + // XContentProviderFactory + virtual ::com::sun::star::uno::Reference< + ::com::sun::star::ucb::XContentProvider > SAL_CALL + createContentProvider( const ::rtl::OUString& Service ) + throw( ::com::sun::star::uno::RuntimeException ); +}; + +//============================================================================ +// +// class UcbContentProviderProxy. +// +//============================================================================ + +class UcbContentProviderProxy : + public cppu::OWeakObject, + public com::sun::star::lang::XTypeProvider, + public com::sun::star::lang::XServiceInfo, + public com::sun::star::ucb::XContentProviderSupplier, + public com::sun::star::ucb::XContentProvider, + public com::sun::star::ucb::XParameterizedContentProvider +{ + ::osl::Mutex m_aMutex; + ::rtl::OUString m_aService; + ::rtl::OUString m_aTemplate; + ::rtl::OUString m_aArguments; + sal_Bool m_bReplace; + sal_Bool m_bRegister; + + com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > + m_xSMgr; + com::sun::star::uno::Reference< com::sun::star::ucb::XContentProvider > + m_xProvider; + com::sun::star::uno::Reference< com::sun::star::ucb::XContentProvider > + m_xTargetProvider; + +public: + UcbContentProviderProxy( + const com::sun::star::uno::Reference< + com::sun::star::lang::XMultiServiceFactory >& rxSMgr, + const ::rtl::OUString& Service ); + virtual ~UcbContentProviderProxy(); + + // XInterface + XINTERFACE_DECL() + + // XTypeProvider + XTYPEPROVIDER_DECL() + + // XServiceInfo + XSERVICEINFO_NOFACTORY_DECL() + + // XContentProviderSupplier + virtual ::com::sun::star::uno::Reference< + ::com::sun::star::ucb::XContentProvider > SAL_CALL + getContentProvider() + throw( ::com::sun::star::uno::RuntimeException ); + + // XContentProvider + virtual ::com::sun::star::uno::Reference< + ::com::sun::star::ucb::XContent > SAL_CALL + queryContent( const ::com::sun::star::uno::Reference< + ::com::sun::star::ucb::XContentIdentifier >& Identifier ) + throw( ::com::sun::star::ucb::IllegalIdentifierException, + ::com::sun::star::uno::RuntimeException ); + virtual sal_Int32 SAL_CALL + compareContentIds( const ::com::sun::star::uno::Reference< + ::com::sun::star::ucb::XContentIdentifier >& Id1, + const ::com::sun::star::uno::Reference< + ::com::sun::star::ucb::XContentIdentifier >& Id2 ) + throw( ::com::sun::star::uno::RuntimeException ); + + // XParameterizedContentProvider + virtual ::com::sun::star::uno::Reference< + ::com::sun::star::ucb::XContentProvider > SAL_CALL + registerInstance( const ::rtl::OUString& Template, + const ::rtl::OUString& Arguments, + sal_Bool ReplaceExisting ) + throw( ::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::uno::RuntimeException ); + virtual ::com::sun::star::uno::Reference< + ::com::sun::star::ucb::XContentProvider > SAL_CALL + deregisterInstance( const ::rtl::OUString& Template, + const ::rtl::OUString& Arguments ) + throw( ::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::uno::RuntimeException ); +}; + +#endif /* !_PROVPROX_HXX */ diff --git a/ucb/source/core/ucb.cxx b/ucb/source/core/ucb.cxx new file mode 100644 index 000000000000..d7182400452d --- /dev/null +++ b/ucb/source/core/ucb.cxx @@ -0,0 +1,631 @@ +/************************************************************************* + * + * $RCSfile: ucb.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:52:48 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +/************************************************************************** + TODO + ************************************************************************** + + *************************************************************************/ + +#ifndef __HASH_SET__ +#include <stl/hash_set> +#endif +#ifndef _CPPUHELPER_INTERFACECONTAINER_HXX_ +#include <cppuhelper/interfacecontainer.hxx> +#endif +#ifndef _VOS_MUTEX_HXX_ +#include <vos/mutex.hxx> +#endif +#ifndef _COM_SUN_STAR_LANG_ILLEGALARGUMENTEXCEPTION_HPP_ +#include <com/sun/star/lang/IllegalArgumentException.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCONTENTPROVIDER_HPP_ +#include <com/sun/star/ucb/XContentProvider.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCONTENTPROVIDERSUPPLIER_HPP_ +#include <com/sun/star/ucb/XContentProviderSupplier.hpp> +#endif +#ifndef _UCBHELPER_CONFIGUREUCB_HXX_ +#include <ucbhelper/configureucb.hxx> +#endif + +#ifndef _IDENTIFY_HXX +#include "identify.hxx" +#endif + +#include "ucb.hxx" + +// Definitions for ProviderMap_Impl (Solaris wouldn't find explicit template +// instantiations for these in another compilation unit...): +#ifndef _UCB_REGEXPMAP_TPT_ +#include <regexpmap.tpt> +#endif + +using namespace rtl; +using namespace cppu; +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::ucb; + +//========================================================================= +// +// ContentInfoMap_Impl. +// +//========================================================================= + +struct equalStr_Impl +{ + bool operator()( const ContentInfo& i1, const ContentInfo& i2 ) const + { + return !!( i1.Type == i2.Type ); + } +}; + +struct hashStr_Impl +{ + size_t operator()( const ContentInfo& i ) const + { + return i.Type.hashCode(); + } +}; + +//========================================================================= +typedef std::hash_set +< + ContentInfo, + hashStr_Impl, + equalStr_Impl +> +ContentInfoMap_Impl; + +//========================================================================= +// +// UniversalContentBroker Implementation. +// +//========================================================================= + +UniversalContentBroker::UniversalContentBroker( + const Reference< com::sun::star::lang::XMultiServiceFactory >& rXSMgr ) +: m_xSMgr( rXSMgr ), + m_pDisposeEventListeners( NULL ), + m_nInitCount( 0 ) //@@@ see initialize() method +{ +} + +//========================================================================= +// virtual +UniversalContentBroker::~UniversalContentBroker() +{ + delete m_pDisposeEventListeners; +} + +//========================================================================= +// +// XInterface methods. +// +//========================================================================= + +XINTERFACE_IMPL_8( UniversalContentBroker, + XTypeProvider, + XComponent, + XServiceInfo, + XInitialization, + XContentProviderManager, + XContentProvider, + XContentIdentifierFactory, + XContentCreator ); + +//========================================================================= +// +// XTypeProvider methods. +// +//========================================================================= + +XTYPEPROVIDER_IMPL_8( UniversalContentBroker, + XTypeProvider, + XComponent, + XServiceInfo, + XInitialization, + XContentProviderManager, + XContentProvider, + XContentIdentifierFactory, + XContentCreator ); + +//========================================================================= +// +// XComponent methods. +// +//========================================================================= + +// virtual +void SAL_CALL UniversalContentBroker::dispose() + throw( com::sun::star::uno::RuntimeException ) +{ + if ( m_pDisposeEventListeners && m_pDisposeEventListeners->getLength() ) + { + EventObject aEvt; + aEvt.Source = SAL_STATIC_CAST( XComponent*, this ); + m_pDisposeEventListeners->disposeAndClear( aEvt ); + } +} + +//========================================================================= +// virtual +void SAL_CALL UniversalContentBroker::addEventListener( + const Reference< XEventListener >& Listener ) + throw( com::sun::star::uno::RuntimeException ) +{ + if ( !m_pDisposeEventListeners ) + m_pDisposeEventListeners = new OInterfaceContainerHelper( m_aMutex ); + + m_pDisposeEventListeners->addInterface( Listener ); +} + +//========================================================================= +// virtual +void SAL_CALL UniversalContentBroker::removeEventListener( + const Reference< XEventListener >& Listener ) + throw( com::sun::star::uno::RuntimeException ) +{ + if ( m_pDisposeEventListeners ) + m_pDisposeEventListeners->removeInterface( Listener ); + + // Note: Don't want to delete empty container here -> performance. +} + +//========================================================================= +// +// XServiceInfo methods. +// +//========================================================================= + +XSERVICEINFO_IMPL_1( UniversalContentBroker, + OUString::createFromAscii( "UniversalContentBroker" ), + OUString::createFromAscii( UCB_SERVICE_NAME ) ); + +//========================================================================= +// +// Service factory implementation. +// +//========================================================================= + +ONE_INSTANCE_SERVICE_FACTORY_IMPL( UniversalContentBroker ); + +//========================================================================= +// +// XInitialization methods. +// +//========================================================================= + +// virtual +void SAL_CALL UniversalContentBroker::initialize( + const com::sun::star::uno::Sequence< Any >& aArguments ) + throw( com::sun::star::uno::Exception, + com::sun::star::uno::RuntimeException ) +{ + // If exactly one boolean argument of value 'true' is supplied, the UCB is + // configured: + sal_Bool bConfigure; + if (aArguments.getLength() == 1 + && (aArguments[0] >>= bConfigure) + && bConfigure) + { + //@@@ At the moment, there's a problem when one (non-one-instance) + // factory 'wraps' another (one-instance) factory, causing this method + // to be called several times: + oslInterlockedCount nCount + = osl_incrementInterlockedCount(&m_nInitCount); + if (nCount == 1) + ucb::configureUcb(this, + m_xSMgr, + OUString::createFromAscii( + UCBHELPER_CONFIGURATION_KEY_STANDARD)); + else + osl_decrementInterlockedCount(&m_nInitCount); + // make the possibility of overflow less likely... + } +} + +//========================================================================= +// +// XContentProviderManager methods. +// +//========================================================================= + +// virtual +Reference< XContentProvider > SAL_CALL +UniversalContentBroker::registerContentProvider( + const Reference< XContentProvider >& Provider, + const OUString& Scheme, + sal_Bool ReplaceExisting ) + throw( DuplicateProviderException, com::sun::star::uno::RuntimeException ) +{ + osl::MutexGuard aGuard(m_aMutex); + + ProviderMap_Impl::iterator aIt; + try + { + aIt = m_aProviders.find(Scheme); + } + catch (IllegalArgumentException const &) + { + return 0; //@@@ + } + + Reference< XContentProvider > xPrevious; + if (aIt == m_aProviders.end()) + { + ProviderList_Impl aList; + aList.push_front(Provider); + try + { + m_aProviders.add(Scheme, aList, false); + } + catch (IllegalArgumentException const &) + { + return 0; //@@@ + } + } + else + { + if (!ReplaceExisting) + throw DuplicateProviderException(); + + ProviderList_Impl & rList = aIt->getValue(); + xPrevious = rList.front().getProvider(); + rList.push_front(Provider); + } + + return xPrevious; +} + +//========================================================================= +// virtual +void SAL_CALL UniversalContentBroker::deregisterContentProvider( + const Reference< XContentProvider >& Provider, + const OUString& Scheme ) + throw( com::sun::star::uno::RuntimeException ) +{ + osl::MutexGuard aGuard(m_aMutex); + + ProviderMap_Impl::iterator aMapIt; + try + { + aMapIt = m_aProviders.find(Scheme); + } + catch (IllegalArgumentException const &) {} + + if (aMapIt != m_aProviders.end()) + { + ProviderList_Impl & rList = aMapIt->getValue(); + + ProviderList_Impl::iterator aListEnd(rList.end()); + for (ProviderList_Impl::iterator aListIt(rList.begin()); + aListIt != aListEnd; ++aListIt) + { + if ((*aListIt).getProvider() == Provider) + { + rList.erase(aListIt); + break; + } + } + + if (rList.empty()) + m_aProviders.erase(aMapIt); + } +} + +//========================================================================= +// virtual +com::sun::star::uno::Sequence< ContentProviderInfo > SAL_CALL + UniversalContentBroker::queryContentProviders() + throw( com::sun::star::uno::RuntimeException ) +{ + // Return a list with information about active(!) content providers. + + osl::MutexGuard aGuard(m_aMutex); + + com::sun::star::uno::Sequence< ContentProviderInfo > aSeq( + m_aProviders.size() ); + ContentProviderInfo* pInfo = aSeq.getArray(); + + ProviderMap_Impl::const_iterator end = m_aProviders.end(); + for (ProviderMap_Impl::const_iterator it(m_aProviders.begin()); it != end; + ++it) + { + // Note: Active provider is always the first list element. + pInfo->ContentProvider = it->getValue().front().getProvider(); + pInfo->Scheme = it->getRegexp(); + ++pInfo; + } + + return aSeq; +} + +//========================================================================= +// virtual +Reference< XContentProvider > SAL_CALL + UniversalContentBroker::queryContentProvider( const OUString& Scheme ) + throw( com::sun::star::uno::RuntimeException ) +{ + return queryContentProvider( Scheme, sal_False ); +} + +//========================================================================= +// +// XContentProvider methods. +// +//========================================================================= + +// virtual +Reference< XContent > SAL_CALL UniversalContentBroker::queryContent( + const Reference< XContentIdentifier >& Identifier ) + throw( IllegalIdentifierException, com::sun::star::uno::RuntimeException ) +{ + ////////////////////////////////////////////////////////////////////// + // Let the content provider for the scheme given with the content + // identifier create the XContent instance. + ////////////////////////////////////////////////////////////////////// + + if ( !Identifier.is() ) + return Reference< XContent >(); + + Reference< XContentProvider > xProv = + queryContentProvider( Identifier->getContentIdentifier(), sal_True ); + if ( xProv.is() ) + return xProv->queryContent( Identifier ); + + return Reference< XContent >(); +} + +//========================================================================= +// virtual +sal_Int32 SAL_CALL UniversalContentBroker::compareContentIds( + const Reference< XContentIdentifier >& Id1, + const Reference< XContentIdentifier >& Id2 ) + throw( com::sun::star::uno::RuntimeException ) +{ + OUString aURI1( Id1->getContentIdentifier() ); + OUString aURI2( Id2->getContentIdentifier() ); + + Reference< XContentProvider > xProv1 + = queryContentProvider( aURI1, sal_True ); + Reference< XContentProvider > xProv2 + = queryContentProvider( aURI2, sal_True ); + + // When both identifiers belong to the same provider, let that provider + // compare them; otherwise, simply compare the URI strings (which must + // be different): + if ( xProv1.is() && ( xProv1 == xProv2 ) ) + return xProv1->compareContentIds( Id1, Id2 ); + else + return aURI1.compareTo( aURI2 ); +} + +//========================================================================= +// +// XContentIdentifierFactory methods. +// +//========================================================================= + +// virtual +Reference< XContentIdentifier > SAL_CALL + UniversalContentBroker::createContentIdentifier( + const OUString& ContentId ) + throw( com::sun::star::uno::RuntimeException ) +{ + ////////////////////////////////////////////////////////////////////// + // Let the content provider for the scheme given with content + // identifier create the XContentIdentifier instance, if he supports + // the XContentIdentifierFactory interface. Otherwise create standard + // implementation object for XContentIdentifier. + ////////////////////////////////////////////////////////////////////// + + Reference< XContentIdentifier > xIdentifier; + + Reference< XContentProvider > xProv + = queryContentProvider( ContentId, sal_True ); + if ( xProv.is() ) + { + Reference< XContentIdentifierFactory > xFac( xProv, UNO_QUERY ); + if ( xFac.is() ) + xIdentifier = xFac->createContentIdentifier( ContentId ); + } + + if ( !xIdentifier.is() ) + xIdentifier = new ContentIdentifier( m_xSMgr, ContentId ); + + return xIdentifier; +} + +//========================================================================= +// +// XContentCreator methods. +// +//========================================================================= + +// virtual +com::sun::star::uno::Sequence< ContentInfo > SAL_CALL + UniversalContentBroker::queryCreatableContentsInfo() + throw( com::sun::star::uno::RuntimeException ) +{ + ////////////////////////////////////////////////////////////////////// + // Iterate over providers, query info there and merge results. + ////////////////////////////////////////////////////////////////////// + + ContentInfoMap_Impl aInfoMap; + + osl::MutexGuard aGuard(m_aMutex); + + ProviderMap_Impl::const_iterator end = m_aProviders.end(); + for (ProviderMap_Impl::const_iterator it(m_aProviders.begin()); + it != end; ++it) + { + Reference< XContentCreator > + xCreator( it->getValue().front().getResolvedProvider(), UNO_QUERY ); + if ( xCreator.is() ) + { + com::sun::star::uno::Sequence< ContentInfo > aInfo = + xCreator->queryCreatableContentsInfo(); + sal_uInt32 nCount = aInfo.getLength(); + for ( sal_uInt32 n = 0; n < nCount; ++ n ) + { + const ContentInfo& rInfo = aInfo[ n ]; + + // Avoid duplicates. + if ( aInfoMap.find( rInfo ) == aInfoMap.end() ) + aInfoMap.insert( rInfo ); + } + } + } + + // Put collected info into sequence. + + sal_uInt32 nCount = aInfoMap.size(); + com::sun::star::uno::Sequence< ContentInfo > aSeq( nCount ); + ContentInfo* pInfo = aSeq.getArray(); + + ContentInfoMap_Impl::const_iterator iter = aInfoMap.begin(); + for ( sal_uInt32 n = 0; n < nCount; n++, iter++ ) + pInfo[ n ] = (*iter); + + return aSeq; +} + +//========================================================================= +// virtual +Reference< XContent > SAL_CALL + UniversalContentBroker::createNewContent( const ContentInfo& Info ) + throw( com::sun::star::uno::RuntimeException ) +{ + ////////////////////////////////////////////////////////////////////// + // Find the matching content creator and delegate call. + ////////////////////////////////////////////////////////////////////// + + osl::MutexGuard aGuard(m_aMutex); + + ProviderMap_Impl::const_iterator end = m_aProviders.end(); + for (ProviderMap_Impl::const_iterator it(m_aProviders.begin()); it != end; + ++it) + { + // Note: Active provider is always the first list element. + Reference< XContentCreator > + xCreator( it->getValue().front().getResolvedProvider(), UNO_QUERY ); + if ( xCreator.is() ) + { + com::sun::star::uno::Sequence< ContentInfo > aInfo = + xCreator->queryCreatableContentsInfo(); + sal_uInt32 nCount = aInfo.getLength(); + for ( sal_uInt32 n = 0; n < nCount; ++ n ) + { + // Compare content types. + if ( aInfo[ n ].Type == Info.Type ) + { + // Found! + return xCreator->createNewContent( Info ); + } + } + } + } + + // No matching creator found. + return Reference< XContent >(); +} + +//========================================================================= +// +// Non-interface methods +// +//========================================================================= + +Reference< XContentProvider > UniversalContentBroker::queryContentProvider( + const OUString& Scheme, sal_Bool bResolved ) +{ + osl::MutexGuard aGuard( m_aMutex ); + + ProviderList_Impl const * pList = m_aProviders.map( Scheme ); + return pList ? bResolved ? pList->front().getResolvedProvider() + : pList->front().getProvider() + : Reference< XContentProvider >(); +} + +//========================================================================= +// +// ProviderListEntry_Impl implementation. +// +//========================================================================= + +Reference< XContentProvider > ProviderListEntry_Impl::resolveProvider() const +{ + if ( !m_xResolvedProvider.is() ) + { + Reference< XContentProviderSupplier > xSupplier( + m_xProvider, UNO_QUERY ); + if ( xSupplier.is() ) + m_xResolvedProvider = xSupplier->getContentProvider(); + + if ( !m_xResolvedProvider.is() ) + m_xResolvedProvider = m_xProvider; + } + + return m_xResolvedProvider; +} + diff --git a/ucb/source/core/ucb.hxx b/ucb/source/core/ucb.hxx new file mode 100644 index 000000000000..1a9a4ab74af2 --- /dev/null +++ b/ucb/source/core/ucb.hxx @@ -0,0 +1,198 @@ +/************************************************************************* + * + * $RCSfile: ucb.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:52:48 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _UCB_HXX +#define _UCB_HXX + +#ifndef _COM_SUN_STAR_UCB_XCONTENTPROVIDER_HPP_ +#include <com/sun/star/ucb/XContentProvider.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCONTENTIDENTIFIERFACTORY_HPP_ +#include <com/sun/star/ucb/XContentIdentifierFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCONTENTCREATOR_HPP_ +#include <com/sun/star/ucb/XContentCreator.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCONTENTPROVIDERMANAGER_HPP_ +#include <com/sun/star/ucb/XContentProviderManager.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_ +#include <com/sun/star/lang/XServiceInfo.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XCOMPONENT_HPP_ +#include <com/sun/star/lang/XComponent.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XINITIALIZATION_HPP_ +#include <com/sun/star/lang/XInitialization.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XTYPEPROVIDER_HPP_ +#include <com/sun/star/lang/XTypeProvider.hpp> +#endif + +#ifndef _RTL_USTRBUF_HXX_ +#include <rtl/ustrbuf.hxx> +#endif +#ifndef _CPPUHELPER_WEAK_HXX_ +#include <cppuhelper/weak.hxx> +#endif +#ifndef _OSL_MUTEX_HXX_ +#include <osl/mutex.hxx> +#endif + +#ifndef _OSL_INTERLOCK_H_ //@@@ see initialize() method +#include <osl/interlck.h> +#endif + +#ifndef _UCBHELPER_MACROS_HXX +#include <ucbhelper/macros.hxx> +#endif + +#ifndef _UCB_PROVIDERMAP_HXX_ +#include "providermap.hxx" +#endif + +//========================================================================= + +#define UCB_SERVICE_NAME "com.sun.star.ucb.UniversalContentBroker" + +//========================================================================= + +namespace cppu { class OInterfaceContainerHelper; } + +class UniversalContentBroker : + public cppu::OWeakObject, + public com::sun::star::lang::XTypeProvider, + public com::sun::star::lang::XComponent, + public com::sun::star::lang::XServiceInfo, + public com::sun::star::lang::XInitialization, + public com::sun::star::ucb::XContentProviderManager, + public com::sun::star::ucb::XContentProvider, + public com::sun::star::ucb::XContentIdentifierFactory, + public com::sun::star::ucb::XContentCreator +{ +public: + UniversalContentBroker( const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& rXSMgr ); + virtual ~UniversalContentBroker(); + + // XInterface + XINTERFACE_DECL() + + // XTypeProvider + XTYPEPROVIDER_DECL() + + // XServiceInfo + XSERVICEINFO_DECL() + + // XComponent + virtual void SAL_CALL dispose() + throw( com::sun::star::uno::RuntimeException ); + virtual void SAL_CALL addEventListener( const com::sun::star::uno::Reference< com::sun::star::lang::XEventListener >& Listener ) + throw( com::sun::star::uno::RuntimeException ); + virtual void SAL_CALL removeEventListener( const com::sun::star::uno::Reference< com::sun::star::lang::XEventListener >& Listener ) + throw( com::sun::star::uno::RuntimeException ); + + // XInitialization + virtual void SAL_CALL initialize( const com::sun::star::uno::Sequence< com::sun::star::uno::Any >& aArguments ) + throw( com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException ); + + // XContentProviderManager + virtual com::sun::star::uno::Reference< com::sun::star::ucb::XContentProvider > SAL_CALL registerContentProvider( const com::sun::star::uno::Reference< com::sun::star::ucb::XContentProvider >& Provider, const rtl::OUString& Scheme, sal_Bool ReplaceExisting ) + throw( com::sun::star::ucb::DuplicateProviderException, com::sun::star::uno::RuntimeException ); + virtual void SAL_CALL deregisterContentProvider( const com::sun::star::uno::Reference< com::sun::star::ucb::XContentProvider >& Provider, const rtl::OUString& Scheme ) + throw( com::sun::star::uno::RuntimeException ); + virtual com::sun::star::uno::Sequence< com::sun::star::ucb::ContentProviderInfo > SAL_CALL queryContentProviders() + throw( com::sun::star::uno::RuntimeException ); + virtual com::sun::star::uno::Reference< com::sun::star::ucb::XContentProvider > SAL_CALL queryContentProvider( const rtl::OUString& Scheme ) + throw( com::sun::star::uno::RuntimeException ); + + // XContentProvider + virtual com::sun::star::uno::Reference< com::sun::star::ucb::XContent > SAL_CALL queryContent( const com::sun::star::uno::Reference< com::sun::star::ucb::XContentIdentifier >& Identifier ) + throw( com::sun::star::ucb::IllegalIdentifierException, com::sun::star::uno::RuntimeException ); + virtual sal_Int32 SAL_CALL compareContentIds( const com::sun::star::uno::Reference< com::sun::star::ucb::XContentIdentifier >& Id1, const com::sun::star::uno::Reference< com::sun::star::ucb::XContentIdentifier >& Id2 ) + throw( com::sun::star::uno::RuntimeException ); + + // XContentIdentifierFactory + virtual com::sun::star::uno::Reference< com::sun::star::ucb::XContentIdentifier > SAL_CALL createContentIdentifier( const rtl::OUString& ContentId ) + throw( com::sun::star::uno::RuntimeException ); + + // XContentCreator + virtual com::sun::star::uno::Sequence< com::sun::star::ucb::ContentInfo > SAL_CALL + queryCreatableContentsInfo() + throw( com::sun::star::uno::RuntimeException ); + virtual com::sun::star::uno::Reference< com::sun::star::ucb::XContent > SAL_CALL + createNewContent( const com::sun::star::ucb::ContentInfo& Info ) + throw( com::sun::star::uno::RuntimeException ); + +private: + com::sun::star::uno::Reference< com::sun::star::ucb::XContentProvider > + queryContentProvider( const rtl::OUString& Scheme, sal_Bool bResolved ); + + com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > m_xSMgr; + ProviderMap_Impl m_aProviders; + osl::Mutex m_aMutex; + cppu::OInterfaceContainerHelper* m_pDisposeEventListeners; + oslInterlockedCount m_nInitCount; //@@@ see initialize() method +}; + +#endif /* !_UCB_HXX */ diff --git a/ucb/source/core/ucbprops.cxx b/ucb/source/core/ucbprops.cxx new file mode 100644 index 000000000000..6e3da90a9ff9 --- /dev/null +++ b/ucb/source/core/ucbprops.cxx @@ -0,0 +1,539 @@ +/************************************************************************* + * + * $RCSfile: ucbprops.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:52:48 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _OSL_DIAGNOSE_H_ +#include <osl/diagnose.h> +#endif + +#ifndef _COM_SUN_STAR_UNO_TYPE_HXX_ +#include <com/sun/star/uno/Type.hxx> +#endif +#ifndef _COM_SUN_STAR_UNO_SEQUENCE_HXX_ +#include <com/sun/star/uno/Sequence.hxx> +#endif +#ifndef _COM_SUN_STAR_UNO_REFERENCE_HXX_ +#include <com/sun/star/uno/Reference.hxx> +#endif +#ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HPP_ +#include <com/sun/star/beans/PropertyAttribute.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_CROSSREFERENCE_HPP_ +#include <com/sun/star/ucb/CrossReference.hpp> +#endif +#ifndef _COM_SUN_STAR_UTIL_DATETIME_HPP_ +#include <com/sun/star/util/DateTime.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_DOCUMENTHEADERFIELD_HPP_ +#include <com/sun/star/ucb/DocumentHeaderField.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_RECIPIENTINFO_HPP_ +#include <com/sun/star/ucb/RecipientInfo.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_RULESET_HPP_ +#include <com/sun/star/ucb/RuleSet.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_SENDINFO_HPP_ +#include <com/sun/star/ucb/SendInfo.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_SENDMEDIATYPES_HPP_ +#include <com/sun/star/ucb/SendMediaTypes.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XDATACONTAINER_HPP_ +#include <com/sun/star/ucb/XDataContainer.hpp> +#endif + +#ifndef _UCBPROPS_HXX +#include "ucbprops.hxx" +#endif + +using namespace rtl; +using namespace com::sun::star::beans; +using namespace com::sun::star::lang; +using namespace com::sun::star::ucb; +using namespace com::sun::star::uno; +using namespace com::sun::star::util; + +//========================================================================= +// +// struct PropertyTableEntry +// +//========================================================================= + +struct PropertyTableEntry +{ + const char* pName; + sal_Int32 nHandle; + sal_Int16 nAttributes; + const com::sun::star::uno::Type& (*pGetCppuType)(); +}; + +////////////////////////////////////////////////////////////////////////// +// +// CPPU type access functions. +// +////////////////////////////////////////////////////////////////////////// + +static const com::sun::star::uno::Type& OUString_getCppuType() +{ + return getCppuType( static_cast< const rtl::OUString * >( 0 ) ); +} + +static const com::sun::star::uno::Type& sal_uInt16_getCppuType() +{ + // ! uInt -> Int, because of Java !!! + return getCppuType( static_cast< const sal_Int16 * >( 0 ) ); +} + +static const com::sun::star::uno::Type& sal_uInt32_getCppuType() +{ + // ! uInt -> Int, because of Java !!! + return getCppuType( static_cast< const sal_Int32 * >( 0 ) ); +} + +static const com::sun::star::uno::Type& sal_uInt64_getCppuType() +{ + // ! uInt -> Int, because of Java !!! + return getCppuType( static_cast< const sal_Int64 * >( 0 ) ); +} + +static const com::sun::star::uno::Type& enum_getCppuType() +{ + // ! enum -> Int, because of Java !!! + return getCppuType( static_cast< const sal_Int16 * >( 0 ) ); +} + +static const com::sun::star::uno::Type& sal_Bool_getCppuType() +{ + return getCppuBooleanType(); +} + +static const com::sun::star::uno::Type& byte_getCppuType() +{ + return getCppuType( static_cast< const sal_Int8 * >( 0 ) ); +} + +static const com::sun::star::uno::Type& Sequence_CrossReference_getCppuType() +{ + return getCppuType( + static_cast< com::sun::star::uno::Sequence< + com::sun::star::ucb::CrossReference > * >( 0 ) ); +} + +static const com::sun::star::uno::Type& DateTime_getCppuType() +{ + return getCppuType( + static_cast< com::sun::star::util::DateTime * >( 0 ) ); +} + +static const com::sun::star::uno::Type& Sequence_byte_getCppuType() +{ + return getCppuType( + static_cast< com::sun::star::uno::Sequence< sal_Int8 > * >( 0 ) ); +} + +static const com::sun::star::uno::Type& Sequence_DocumentHeaderField_getCppuType() +{ + return getCppuType( + static_cast< com::sun::star::uno::Sequence< + com::sun::star::ucb::DocumentHeaderField > * >( 0 ) ); +} + +static const com::sun::star::uno::Type& XDataContainer_getCppuType() +{ + return getCppuType( + static_cast< com::sun::star::uno::Reference< + com::sun::star::ucb::XDataContainer > * >( 0 ) ); +} + +static const com::sun::star::uno::Type& Sequence_RecipientInfo_getCppuType() +{ + return getCppuType( + static_cast< com::sun::star::uno::Sequence< + com::sun::star::ucb::RecipientInfo > * >( 0 ) ); +} + +static const com::sun::star::uno::Type& RuleSet_getCppuType() +{ + return getCppuType( + static_cast< com::sun::star::ucb::RuleSet * >( 0 ) ); +} + +static const com::sun::star::uno::Type& Sequence_SendInfo_getCppuType() +{ + return getCppuType( + static_cast< com::sun::star::uno::Sequence< + com::sun::star::ucb::SendInfo > * >( 0 ) ); +} + +static const com::sun::star::uno::Type& Sequence_SendMediaTypes_getCppuType() +{ + return getCppuType( + static_cast< com::sun::star::uno::Sequence< + com::sun::star::ucb::SendMediaTypes > * >( 0 ) ); +} + +////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// A table with all well-known UCB properties. +////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +#define ATTR_DEFAULT ( PropertyAttribute::BOUND | PropertyAttribute::MAYBEVOID | PropertyAttribute::MAYBEDEFAULT ) + +static PropertyTableEntry __aPropertyTable[] = +{ + { "Account", -1 /* WID_ACCOUNT */, ATTR_DEFAULT, &OUString_getCppuType }, + { "AutoUpdateInterval", -1 /* WID_AUTOUPDATE_INTERVAL */, ATTR_DEFAULT, &sal_uInt32_getCppuType }, + { "ConfirmEmpty", -1 /* WID_TRASHCAN_FLAG_CONFIRMEMPTY */, + ATTR_DEFAULT, &sal_Bool_getCppuType }, + { "ConnectionLimit", -1 /* WID_HTTP_CONNECTION_LIMIT */, ATTR_DEFAULT, &byte_getCppuType }, + { "ConnectionMode", -1 /* WID_CONNECTION_MODE */, ATTR_DEFAULT, &enum_getCppuType }, + { "ContentCountLimit", -1 /* WID_SHOW_MSGS_TIMELIMIT */, ATTR_DEFAULT, &sal_uInt16_getCppuType }, + { "ContentType", -1 /* WID_CONTENT_TYPE */, ATTR_DEFAULT, &OUString_getCppuType }, + { "Cookie", -1 /* WID_HTTP_COOKIE */, ATTR_DEFAULT, &OUString_getCppuType }, + { "CrossReferences", -1 /* WID_NEWS_XREFLIST */, ATTR_DEFAULT, &Sequence_CrossReference_getCppuType }, + { "DateCreated", -1 /* WID_DATE_CREATED */, ATTR_DEFAULT, &DateTime_getCppuType }, + { "DateModified", -1 /* WID_DATE_MODIFIED */, ATTR_DEFAULT, &DateTime_getCppuType }, + { "DeleteOnServer", -1 /* WID_DELETE_ON_SERVER */, ATTR_DEFAULT, &sal_Bool_getCppuType }, + { "DocumentBody", -1 /* WID_DOCUMENT_BODY */, ATTR_DEFAULT, &Sequence_byte_getCppuType }, + { "DocumentCount", -1 /* WID_TOTALCONTENTCOUNT */, ATTR_DEFAULT | PropertyAttribute::READONLY, + &sal_uInt32_getCppuType }, + { "DocumentCountMarked", + -1 /* WID_MARKED_DOCUMENT_COUNT */, ATTR_DEFAULT | PropertyAttribute::READONLY, + &sal_uInt32_getCppuType }, + { "DocumentHeader", -1 /* WID_DOCUMENT_HEADER */, ATTR_DEFAULT, &Sequence_DocumentHeaderField_getCppuType }, + { "DocumentStoreMode", -1 /* WID_MESSAGE_STOREMODE */, ATTR_DEFAULT, &enum_getCppuType }, + { "DocumentViewMode", -1 /* WID_MESSAGEVIEW_MODE */, ATTR_DEFAULT, &enum_getCppuType }, + { "FTPAccount", -1 /* WID_FTP_ACCOUNT */, ATTR_DEFAULT, &OUString_getCppuType }, + { "Flags", -1 /* WID_FSYS_FLAGS */, ATTR_DEFAULT, &sal_uInt32_getCppuType }, + { "FolderCount", -1 /* WID_FOLDER_COUNT */, ATTR_DEFAULT | PropertyAttribute::READONLY, + &sal_uInt32_getCppuType }, + { "FolderViewMode", -1 /* WID_FOLDERVIEW_MODE */, ATTR_DEFAULT, &enum_getCppuType }, + { "FreeSpace", -1 /* WID_FSYS_DISKSPACE_LEFT */, ATTR_DEFAULT | PropertyAttribute::READONLY, + &sal_uInt64_getCppuType }, + { "HasDocuments", -1 /* WID_FLAG_HAS_MESSAGES */, ATTR_DEFAULT | PropertyAttribute::READONLY, + &sal_Bool_getCppuType }, + { "HasFolders", -1 /* WID_FLAG_HAS_FOLDER */, ATTR_DEFAULT | PropertyAttribute::READONLY, + &sal_Bool_getCppuType }, + { "IsAutoDelete", -1 /* WID_TRASHCAN_FLAG_AUTODELETE */, + ATTR_DEFAULT, &sal_Bool_getCppuType }, + { "IsAutoUpdate", -1 /* WID_UPDATE_ENABLED */, ATTR_DEFAULT, &sal_Bool_getCppuType }, + { "IsDocument", -1 /* WID_FLAG_IS_MESSAGE */, ATTR_DEFAULT | PropertyAttribute::READONLY, + &sal_Bool_getCppuType }, + { "IsFolder", -1 /* WID_FLAG_IS_FOLDER */, ATTR_DEFAULT | PropertyAttribute::READONLY, + &sal_Bool_getCppuType }, + { "IsKeepExpired", -1 /* WID_HTTP_KEEP_EXPIRED */, ATTR_DEFAULT, &sal_Bool_getCppuType }, + { "IsLimitedContentCount", + -1 /* WID_SHOW_MSGS_HAS_TIMELIMIT */, + ATTR_DEFAULT, &sal_Bool_getCppuType }, + { "IsMarked", -1 /* WID_IS_MARKED */, ATTR_DEFAULT, &sal_Bool_getCppuType }, + { "IsRead", -1 /* WID_IS_READ */, ATTR_DEFAULT, &sal_Bool_getCppuType }, + { "IsReadOnly", -1 /* WID_FLAG_READONLY */, ATTR_DEFAULT, &sal_Bool_getCppuType }, + { "IsSubscribed", -1 /* WID_FLAG_SUBSCRIBED */, ATTR_DEFAULT, &sal_Bool_getCppuType }, +// { "IsThreaded", -1 /* WID_THREADED */, ATTR_DEFAULT, &sal_Bool_getCppuType }, + { "IsTimeLimitedStore", -1 /* WID_STORE_MSGS_HAS_TIMELIMIT */, + ATTR_DEFAULT, &sal_Bool_getCppuType }, + { "Keywords", -1 /* WID_KEYWORDS */, ATTR_DEFAULT, &OUString_getCppuType }, + { "LocalBase", -1 /* WID_LOCALBASE */, ATTR_DEFAULT, &OUString_getCppuType }, + { "MessageBCC", -1 /* WID_BCC */, ATTR_DEFAULT, &OUString_getCppuType }, + { "MessageBody", -1 /* WID_MESSAGEBODY */, ATTR_DEFAULT, &XDataContainer_getCppuType }, + { "MessageCC", -1 /* WID_CC */, ATTR_DEFAULT, &OUString_getCppuType }, + { "MessageFrom", -1 /* WID_FROM */, ATTR_DEFAULT, &OUString_getCppuType }, + { "MessageId", -1 /* WID_MESSAGE_ID */, ATTR_DEFAULT, &OUString_getCppuType }, + { "MessageInReplyTo", -1 /* WID_IN_REPLY_TO */, ATTR_DEFAULT, &OUString_getCppuType }, + { "MessageReplyTo", -1 /* WID_REPLY_TO */, ATTR_DEFAULT, &OUString_getCppuType }, + { "MessageTo", -1 /* WID_TO */, ATTR_DEFAULT, &OUString_getCppuType }, + { "NewsGroups", -1 /* WID_NEWSGROUPS */, ATTR_DEFAULT, &OUString_getCppuType }, + { "NoCacheList", -1 /* WID_HTTP_NOCACHE_LIST */, ATTR_DEFAULT, &OUString_getCppuType }, + { "Origin", -1 /* WID_TRASH_ORIGIN */, ATTR_DEFAULT | PropertyAttribute::READONLY, + &OUString_getCppuType }, + { "OutgoingMessageRecipients", + -1 /* WID_RECIPIENTLIST */, ATTR_DEFAULT, &Sequence_RecipientInfo_getCppuType }, + { "OutgoingMessageState", + -1 /* WID_OUTMSGINTERNALSTATE */, ATTR_DEFAULT | PropertyAttribute::READONLY, + &enum_getCppuType }, + { "OutgoingMessageViewMode", + -1 /* WID_SENTMESSAGEVIEW_MODE */, + ATTR_DEFAULT, &enum_getCppuType }, +// { "OwnURL", -1 /* WID_OWN_URL */, ATTR_DEFAULT, &OUString_getCppuType }, + { "Password", -1 /* WID_PASSWORD */, ATTR_DEFAULT, &OUString_getCppuType }, +// { "PresentationURL", -1 /* WID_REAL_URL */, ATTR_DEFAULT | PropertyAttribute::READONLY, +// &OUString_getCppuType }, + { "Priority", -1 /* WID_PRIORITY */, ATTR_DEFAULT, &enum_getCppuType }, + { "References", -1 /* WID_REFERENCES */, ATTR_DEFAULT, &OUString_getCppuType }, + { "Referer", -1 /* WID_HTTP_REFERER */, ATTR_DEFAULT, &OUString_getCppuType }, + { "Rules", -1 /* WID_RULES */, ATTR_DEFAULT, &RuleSet_getCppuType }, + { "SearchCriteria", -1 /* WID_SEARCH_CRITERIA */, ATTR_DEFAULT, &RuleSet_getCppuType }, + { "SearchIndirections", -1 /* WID_SEARCH_INDIRECTIONS */, ATTR_DEFAULT, &sal_Bool_getCppuType }, + { "SearchLocations", -1 /* WID_SEARCH_LOCATIONS */, ATTR_DEFAULT, &OUString_getCppuType }, + { "SearchRecursive", -1 /* WID_SEARCH_RECURSIVE */, ATTR_DEFAULT, &sal_Bool_getCppuType }, + { "SeenCount", -1 /* WID_SEENCONTENTCOUNT */, ATTR_DEFAULT | PropertyAttribute::READONLY, + &sal_uInt32_getCppuType }, + { "SendCopyTarget", -1 /* WID_SEND_COPY_TARGET */, ATTR_DEFAULT, &Sequence_SendInfo_getCppuType }, + { "SendFormats", -1 /* WID_SEND_FORMATS */, ATTR_DEFAULT, &Sequence_SendMediaTypes_getCppuType }, + { "SendFroms", -1 /* WID_SEND_FROM_DEFAULT */, ATTR_DEFAULT, &Sequence_SendInfo_getCppuType }, + { "SendPasswords", -1 /* WID_SEND_PASSWORD */, ATTR_DEFAULT, &Sequence_SendInfo_getCppuType }, + { "SendProtocolPrivate",-1 /* WID_SEND_PRIVATE_PROT_ID */, ATTR_DEFAULT, &sal_uInt16_getCppuType }, + { "SendProtocolPublic", -1 /* WID_SEND_PUBLIC_PROT_ID */, ATTR_DEFAULT, &sal_uInt16_getCppuType }, + { "SendReplyTos", -1 /* WID_SEND_REPLY_TO_DEFAULT */, ATTR_DEFAULT, &Sequence_SendInfo_getCppuType }, + { "SendServerNames", -1 /* WID_SEND_SERVERNAME */, ATTR_DEFAULT, &Sequence_SendInfo_getCppuType }, + { "SendUserNames", -1 /* WID_SEND_USERNAME */, ATTR_DEFAULT, &Sequence_SendInfo_getCppuType }, + { "SendVIMPostOfficePath", + -1 /* WID_SEND_VIM_POPATH */, ATTR_DEFAULT, &OUString_getCppuType }, + { "ServerBase", -1 /* WID_SERVERBASE */, ATTR_DEFAULT, &OUString_getCppuType }, + { "ServerName", -1 /* WID_SERVERNAME */, ATTR_DEFAULT, &OUString_getCppuType }, + { "ServerPort", -1 /* WID_SERVERPORT */, ATTR_DEFAULT, &sal_uInt16_getCppuType }, + { "Size", -1 /* WID_DOCUMENT_SIZE */, ATTR_DEFAULT | PropertyAttribute::READONLY, + &sal_uInt64_getCppuType }, + { "SizeLimit", -1 /* WID_SIZE_LIMIT */, ATTR_DEFAULT, &sal_uInt64_getCppuType }, + { "SubscribedCount", -1 /* WID_SUBSCRNEWSGROUPCOUNT */, ATTR_DEFAULT | PropertyAttribute::READONLY, + &sal_uInt32_getCppuType }, + { "SynchronizePolicy", -1 /* WID_WHO_IS_MASTER */, ATTR_DEFAULT, &enum_getCppuType }, + { "TargetFrames", -1 /* WID_TARGET_FRAMES */, ATTR_DEFAULT, &OUString_getCppuType }, + { "TargetURL", -1 /* WID_TARGET_URL */, ATTR_DEFAULT, &OUString_getCppuType }, +// { "ThreadingInfo", -1 /* WID_THREADING */, ATTR_DEFAULT, &Sequence_ThreadingInfo_getCppuType }, + { "TimeLimitStore", -1 /* WID_STORE_MSGS_TIMELIMIT */, ATTR_DEFAULT, &sal_uInt16_getCppuType }, + { "Title", -1 /* WID_TITLE */, ATTR_DEFAULT, &OUString_getCppuType }, + { "UpdateOnOpen", -1 /* WID_FLAG_UPDATE_ON_OPEN */, ATTR_DEFAULT, &sal_Bool_getCppuType }, + { "UseOutBoxPrivateProtocolSettings", + -1 /* WID_SEND_PRIVATE_OUTBOXPROPS */, + ATTR_DEFAULT, &sal_Bool_getCppuType }, + { "UseOutBoxPublicProtocolSettings", + -1 /* WID_SEND_PUBLIC_OUTBOXPROPS */, + ATTR_DEFAULT, &sal_Bool_getCppuType }, + { "UserName", -1 /* WID_USERNAME */, ATTR_DEFAULT, &OUString_getCppuType }, + { "UserSortCriterium", -1 /* WID_USER_SORT_CRITERIUM */, ATTR_DEFAULT, &OUString_getCppuType }, + { "VIMPostOfficePath", -1 /* WID_VIM_POPATH */, ATTR_DEFAULT, &OUString_getCppuType }, + { "VerificationMode", -1 /* WID_HTTP_VERIFY_MODE */, ATTR_DEFAULT, &enum_getCppuType }, + + ////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // EOT. + ////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + { 0, 0, 0, 0 } +}; + +//========================================================================= +//========================================================================= +// +// UcbPropertiesManager Implementation. +// +//========================================================================= +//========================================================================= + +UcbPropertiesManager::UcbPropertiesManager( + const Reference< XMultiServiceFactory >& rxSMgr ) +: /*m_xSMgr( rxSMgr ),*/ + m_pProps( 0 ) +{ +} + +//========================================================================= +// virtual +UcbPropertiesManager::~UcbPropertiesManager() +{ + delete m_pProps; +} + +//========================================================================= +// +// XInterface methods. +// +//========================================================================= + +XINTERFACE_IMPL_3( UcbPropertiesManager, + XTypeProvider, + XServiceInfo, + XPropertySetInfo ); + +//========================================================================= +// +// XTypeProvider methods. +// +//========================================================================= + +XTYPEPROVIDER_IMPL_3( UcbPropertiesManager, + XTypeProvider, + XServiceInfo, + XPropertySetInfo ); + +//========================================================================= +// +// XServiceInfo methods. +// +//========================================================================= + +XSERVICEINFO_IMPL_1( UcbPropertiesManager, + OUString::createFromAscii( "UcbPropertiesManager" ), + OUString::createFromAscii( + PROPERTIES_MANAGER_SERVICE_NAME ) ); + +//========================================================================= +// +// Service factory implementation. +// +//========================================================================= + +ONE_INSTANCE_SERVICE_FACTORY_IMPL( UcbPropertiesManager ); + +//========================================================================= +// +// XPropertySetInfo methods. +// +//========================================================================= + +// virtual +Sequence< Property > SAL_CALL UcbPropertiesManager::getProperties() + throw( RuntimeException ) +{ + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + + if ( !m_pProps ) + { + m_pProps = new Sequence< Property >( 128 ); + Property* pProps = m_pProps->getArray(); + sal_Int32 nPos = 0; + sal_Int32 nSize = m_pProps->getLength(); + + ////////////////////////////////////////////////////////////////// + // Get info for well-known properties. + ////////////////////////////////////////////////////////////////// + + const PropertyTableEntry* pCurr = &__aPropertyTable[ 0 ]; + while ( pCurr->pName ) + { + if ( nSize <= nPos ) + { + OSL_ENSURE( sal_False, + "UcbPropertiesManager::getProperties - " + "Initial size of property sequence too small!" ); + + m_pProps->realloc( 128 ); + nSize += 128; + } + + Property& rProp = pProps[ nPos ]; + + rProp.Name = OUString::createFromAscii( pCurr->pName ); + rProp.Handle = pCurr->nHandle; + rProp.Type = pCurr->pGetCppuType(); + rProp.Attributes = pCurr->nAttributes; + + nPos++; + pCurr++; + } + + if ( nPos > 0 ) + { + m_pProps->realloc( nPos ); + nSize = m_pProps->getLength(); + } + } + return *m_pProps; +} + +//========================================================================= +// virtual +Property SAL_CALL UcbPropertiesManager::getPropertyByName( const OUString& aName ) + throw( UnknownPropertyException, RuntimeException ) +{ + Property aProp; + if ( queryProperty( aName, aProp ) ) + return aProp; + + throw UnknownPropertyException(); +} + +//========================================================================= +// virtual +sal_Bool SAL_CALL UcbPropertiesManager::hasPropertyByName( const OUString& Name ) + throw( RuntimeException ) +{ + Property aProp; + return queryProperty( Name, aProp ); +} + +//========================================================================= +// +// Non-Interface methods. +// +//========================================================================= + +sal_Bool UcbPropertiesManager::queryProperty( + const OUString& rName, Property& rProp ) +{ + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + + getProperties(); + + const Property* pProps = m_pProps->getConstArray(); + sal_Int32 nCount = m_pProps->getLength(); + for ( sal_Int32 n = 0; n < nCount; ++n ) + { + const Property& rCurrProp = pProps[ n ]; + if ( rCurrProp.Name == rName ) + { + rProp = rCurrProp; + return sal_True; + } + } + + return sal_False; +} + diff --git a/ucb/source/core/ucbprops.hxx b/ucb/source/core/ucbprops.hxx new file mode 100644 index 000000000000..66f501603f38 --- /dev/null +++ b/ucb/source/core/ucbprops.hxx @@ -0,0 +1,143 @@ +/************************************************************************* + * + * $RCSfile: ucbprops.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:52:48 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _UCBPROPS_HXX +#define _UCBPROPS_HXX + +#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XTYPEPROVIDER_HPP_ +#include <com/sun/star/lang/XTypeProvider.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_ +#include <com/sun/star/lang/XServiceInfo.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSETINFO_HPP_ +#include <com/sun/star/beans/XPropertySetInfo.hpp> +#endif +#ifndef _CPPUHELPER_WEAK_HXX_ +#include <cppuhelper/weak.hxx> +#endif +#ifndef _OSL_MUTEX_HXX_ +#include <osl/mutex.hxx> +#endif +#ifndef _UCBHELPER_MACROS_HXX +#include <ucbhelper/macros.hxx> +#endif + +//========================================================================= + +#define PROPERTIES_MANAGER_SERVICE_NAME "com.sun.star.ucb.PropertiesManager" + +//============================================================================ +// +// class UcbPropertiesManager. +// +//============================================================================ + +class UcbPropertiesManager : + public cppu::OWeakObject, + public com::sun::star::lang::XTypeProvider, + public com::sun::star::lang::XServiceInfo, + public com::sun::star::beans::XPropertySetInfo +{ +// com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > +// m_xSMgr; + com::sun::star::uno::Sequence< com::sun::star::beans::Property >* + m_pProps; + osl::Mutex m_aMutex; + +private: + sal_Bool queryProperty( const rtl::OUString& rName, + com::sun::star::beans::Property& rProp ); + +public: + UcbPropertiesManager( const com::sun::star::uno::Reference< + com::sun::star::lang::XMultiServiceFactory >& + rxSMgr ); + virtual ~UcbPropertiesManager(); + + // XInterface + XINTERFACE_DECL() + + // XTypeProvider + XTYPEPROVIDER_DECL() + + // XServiceInfo + XSERVICEINFO_DECL() + + // XPropertySetInfo + virtual com::sun::star::uno::Sequence< + com::sun::star::beans::Property > SAL_CALL + getProperties() + throw( com::sun::star::uno::RuntimeException ); + virtual com::sun::star::beans::Property SAL_CALL + getPropertyByName( const rtl::OUString& aName ) + throw( com::sun::star::beans::UnknownPropertyException, + com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL + hasPropertyByName( const rtl::OUString& Name ) + throw( com::sun::star::uno::RuntimeException ); +}; + +#endif /* !_UCBPROPS_HXX */ + diff --git a/ucb/source/core/ucbserv.cxx b/ucb/source/core/ucbserv.cxx new file mode 100644 index 000000000000..af6e33786a8d --- /dev/null +++ b/ucb/source/core/ucbserv.cxx @@ -0,0 +1,279 @@ +/************************************************************************* + * + * $RCSfile: ucbserv.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:52:48 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XSINGLESERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XSingleServiceFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_REGISTRY_XREGISTRYKEY_HPP_ +#include <com/sun/star/registry/XRegistryKey.hpp> +#endif + +#ifndef _UCB_HXX +#include "ucb.hxx" +#endif +#ifndef _UCBCFG_HXX +#include "ucbcfg.hxx" +#endif +#ifndef _UCBSTORE_HXX +#include "ucbstore.hxx" +#endif +#ifndef _UCBPROPS_HXX +#include "ucbprops.hxx" +#endif +#ifndef _PROVPROX_HXX +#include "provprox.hxx" +#endif +#ifndef _UCB_UCBDISTRIBUTOR_HXX_ +#include "ucbdistributor.hxx" +#endif + +using namespace rtl; +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::registry; + +//========================================================================= +static sal_Bool writeInfo( void * pRegistryKey, + const OUString & rImplementationName, + Sequence< OUString > const & rServiceNames ) +{ + OUString aKeyName( OUString::createFromAscii( "/" ) ); + aKeyName += rImplementationName; + aKeyName += OUString::createFromAscii( "/UNO/SERVICES" ); + + Reference< XRegistryKey > xKey; + try + { + xKey = static_cast< XRegistryKey * >( + pRegistryKey )->createKey( aKeyName ); + } + catch ( InvalidRegistryException const & ) + { + } + + if ( !xKey.is() ) + return sal_False; + + sal_Bool bSuccess = sal_True; + + for ( sal_Int32 n = 0; n < rServiceNames.getLength(); ++n ) + { + try + { + xKey->createKey( rServiceNames[ n ] ); + } + catch ( InvalidRegistryException const & ) + { + bSuccess = sal_False; + break; + } + } + return bSuccess; +} + +//========================================================================= +extern "C" void SAL_CALL component_getImplementationEnvironment( + const sal_Char ** ppEnvTypeName, uno_Environment ** ppEnv ) +{ + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; +} + +//========================================================================= +extern "C" sal_Bool SAL_CALL component_writeInfo( + void * pServiceManager, void * pRegistryKey ) +{ + return pRegistryKey && + + ////////////////////////////////////////////////////////////////////// + // Universal Content Broker. + ////////////////////////////////////////////////////////////////////// + + writeInfo( pRegistryKey, + UniversalContentBroker::getImplementationName_Static(), + UniversalContentBroker::getSupportedServiceNames_Static() ) && + + ////////////////////////////////////////////////////////////////////// + // UCB Configuration. + ////////////////////////////////////////////////////////////////////// + + writeInfo( pRegistryKey, + UcbConfigurationManager::getImplementationName_Static(), + UcbConfigurationManager::getSupportedServiceNames_Static() ) && + + ////////////////////////////////////////////////////////////////////// + // UCB Store. + ////////////////////////////////////////////////////////////////////// + + writeInfo( pRegistryKey, + UcbStore::getImplementationName_Static(), + UcbStore::getSupportedServiceNames_Static() ) && + + ////////////////////////////////////////////////////////////////////// + // UCB PropertiesManager. + ////////////////////////////////////////////////////////////////////// + + writeInfo( pRegistryKey, + UcbPropertiesManager::getImplementationName_Static(), + UcbPropertiesManager::getSupportedServiceNames_Static() ) && + + ////////////////////////////////////////////////////////////////////// + // UCP Proxy Factory. + ////////////////////////////////////////////////////////////////////// + + writeInfo( pRegistryKey, + UcbContentProviderProxyFactory::getImplementationName_Static(), + UcbContentProviderProxyFactory::getSupportedServiceNames_Static() ) && + + ////////////////////////////////////////////////////////////////////// + // UCB Distributor. + ////////////////////////////////////////////////////////////////////// + + writeInfo( pRegistryKey, + chaos_ucb::UcbDistributor::getImplementationName_Static(), + chaos_ucb::UcbDistributor::getSupportedServiceNames_Static() ); +} + +//========================================================================= +extern "C" void * SAL_CALL component_getFactory( + const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey ) +{ + void * pRet = 0; + + Reference< XMultiServiceFactory > xSMgr( + reinterpret_cast< XMultiServiceFactory * >( pServiceManager ) ); + Reference< XSingleServiceFactory > xFactory; + + ////////////////////////////////////////////////////////////////////// + // Universal Content Broker. + ////////////////////////////////////////////////////////////////////// + + if ( UniversalContentBroker::getImplementationName_Static(). + compareToAscii( pImplName ) == 0 ) + { + xFactory = UniversalContentBroker::createServiceFactory( xSMgr ); + } + + ////////////////////////////////////////////////////////////////////// + // UCB Configuration. + ////////////////////////////////////////////////////////////////////// + + else if ( UcbConfigurationManager::getImplementationName_Static(). + compareToAscii( pImplName ) == 0 ) + { + xFactory = UcbConfigurationManager::createServiceFactory( xSMgr ); + } + + ////////////////////////////////////////////////////////////////////// + // UCB Store. + ////////////////////////////////////////////////////////////////////// + + else if ( UcbStore::getImplementationName_Static(). + compareToAscii( pImplName ) == 0 ) + { + xFactory = UcbStore::createServiceFactory( xSMgr ); + } + + ////////////////////////////////////////////////////////////////////// + // UCB PropertiesManager. + ////////////////////////////////////////////////////////////////////// + + else if ( UcbPropertiesManager::getImplementationName_Static(). + compareToAscii( pImplName ) == 0 ) + { + xFactory = UcbPropertiesManager::createServiceFactory( xSMgr ); + } + + ////////////////////////////////////////////////////////////////////// + // UCP Proxy Factory. + ////////////////////////////////////////////////////////////////////// + + else if ( UcbContentProviderProxyFactory::getImplementationName_Static(). + compareToAscii( pImplName ) == 0 ) + { + xFactory + = UcbContentProviderProxyFactory::createServiceFactory( xSMgr ); + } + + ////////////////////////////////////////////////////////////////////// + // UCB Distributor. + ////////////////////////////////////////////////////////////////////// + + else if ( chaos_ucb::UcbDistributor::getImplementationName_Static(). + compareToAscii( pImplName ) == 0 ) + { + xFactory + = chaos_ucb::UcbDistributor::createServiceFactory( xSMgr ); + } + + ////////////////////////////////////////////////////////////////////// + + if ( xFactory.is() ) + { + xFactory->acquire(); + pRet = xFactory.get(); + } + + return pRet; +} + diff --git a/ucb/source/core/ucbstore.cxx b/ucb/source/core/ucbstore.cxx new file mode 100644 index 000000000000..573e3c639447 --- /dev/null +++ b/ucb/source/core/ucbstore.cxx @@ -0,0 +1,2346 @@ +/************************************************************************* + * + * $RCSfile: ucbstore.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:52:48 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +/************************************************************************** + TODO + ************************************************************************** + + UcbStore + + - Vergleiche der URL's case-insensitive -> UNIX ? + + PropertySetRegistry + + *************************************************************************/ + +#ifndef _RTL_CHAR_H_ +#include <rtl/char.h> +#endif +#ifndef _RTL_ALLOC_H_ +#include <rtl/alloc.h> +#endif +#ifndef _RTL_MEMORY_H_ +#include <rtl/memory.h> +#endif +#ifndef _RTL_USTRING_HXX_ +#include <rtl/ustring.hxx> +#endif +#ifndef __LIST__ +#include <stl/list> +#endif +#ifndef __HASH_MAP__ +#include <stl/hash_map> +#endif +#ifndef __VECTOR__ +#include <stl/vector> +#endif +#ifndef _OSL_FILE_HXX_ +#include <osl/file.hxx> +#endif +#ifndef _VOS_MACROS_HXX_ +#include <vos/macros.hxx> +#endif +#ifndef _VOS_DIAGNOSE_HXX_ +#include <vos/diagnose.hxx> +#endif +#ifndef _VOS_MUTEX_HXX_ +#include <vos/mutex.hxx> +#endif +#ifndef _CPPUHELPER_INTERFACECONTAINER_HXX_ +#include <cppuhelper/interfacecontainer.hxx> +#endif +#ifndef _STORE_STORE_HXX_ +#include <store/store.hxx> +#endif +#ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HPP_ +#include <com/sun/star/beans/PropertyAttribute.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_PROPERTYSETINFOCHANGE_HPP_ +#include <com/sun/star/beans/PropertySetInfoChange.hpp> +#endif + +#include "ucbstore.hxx" + +#ifndef _FLATANY_HXX +#include "flatany.hxx" +#endif +#if 0 +#ifndef _CNTPPSET_HXX +#include "cntppset.hxx" +#endif +#endif + +using namespace com::sun::star::beans; +using namespace com::sun::star::container; +using namespace com::sun::star::lang; +using namespace com::sun::star::ucb; +using namespace com::sun::star::uno; +using namespace cppu; +using namespace rtl; + +//========================================================================= +// +// stl hash map support. +// +//========================================================================= + +struct equalStringIgnoreCase_Impl +{ + bool operator ()( const OUString& rKey1, const OUString& rKey2 ) const + { + return !!( rKey1.equalsIgnoreCase( rKey2 ) ); + } +}; + +struct hashStringIgnoreCase_Impl +{ + size_t operator()( const OUString& rKey ) const + { + const sal_Unicode* p = rKey.getStr(); + sal_uInt32 h = 0; + for ( ; *p; ++p ) + h = 5 * h + rtl_char_toLowerCase( *p ); + + return h; + } +}; + +struct equalString_Impl +{ + bool operator()( const OUString& s1, const OUString& s2 ) const + { + return !!( s1 == s2 ); + } +}; + +struct hashString_Impl +{ + size_t operator()( const OUString & rName ) const + { + return rName.hashCode(); + } +}; + +//========================================================================= + +#define PROPERTYSET_STREAM_PREFIX "propset." +#define PROPERTYSET_STREAM_MAGIC 19690713 +#define PROPERTYSET_STREAM_VERSION 1 + +struct PropertySetStreamHeader_Impl +{ + sal_uInt32 m_nMagic; + sal_uInt32 m_nVersion; + sal_uInt32 m_nDataLen; // size of data, without header + sal_uInt32 m_nCount; // number of elements + + PropertySetStreamHeader_Impl() + : m_nMagic( 0 ), m_nVersion( 0 ), m_nDataLen( 0 ), m_nCount( 0 ) {} + + PropertySetStreamHeader_Impl( + sal_uInt32 M, sal_uInt32 V, sal_uInt32 D, sal_uInt32 C ) + : m_nMagic( M ), m_nVersion( V ), m_nDataLen( D ), m_nCount( C ) {} +}; + +#define PROPERTYSET_STREAM_HEADER_SIZE sizeof( PropertySetStreamHeader_Impl ) +#define PROPERTYSET_STREAM_ALIGNMENT 4 /* Bytes */ + +//========================================================================= +// +// class PropertySetStreamBuffer_Impl +// +//========================================================================= + +#define ALIGN_POS( a ) \ + (( a*( PROPERTYSET_STREAM_ALIGNMENT-1))%PROPERTYSET_STREAM_ALIGNMENT) + +class PropertySetStreamBuffer_Impl +{ + sal_uInt32 m_nSize; + sal_uInt32 m_nGrow; + sal_uInt8* m_pBuffer; + sal_uInt8* m_pPos; + +private: + void ensureCapacity( sal_uInt8 nBytesNeeded ); + +public: + PropertySetStreamBuffer_Impl( sal_uInt32 nInitSize, + sal_uInt32 nGrowSize = 4096 ); + ~PropertySetStreamBuffer_Impl(); + + operator sal_uInt8* () const { return m_pBuffer; } + + sal_uInt32 getDataLength() const { return ( m_pPos - m_pBuffer ); } + + sal_Bool readString( OUString& rValue ); + sal_Bool readInt32 ( sal_Int32& rValue ); + sal_Bool readAny ( Any& rValue ); + + sal_Bool writeString( const OUString& rValue ); + sal_Bool writeInt32 ( sal_Int32 nValue ); + sal_Bool writeAny ( const Any& rValue ); +}; + +//========================================================================= +// +// RegistryMap_Impl. +// +//========================================================================= + +typedef std::hash_map +< + OUString, + PropertySetRegistry*, + hashStringIgnoreCase_Impl, + equalStringIgnoreCase_Impl +> +RegistryMap_Impl; + +//========================================================================= +// +// PropertySetMap_Impl. +// +//========================================================================= + +typedef std::hash_map +< + OUString, + PersistentPropertySet*, + hashString_Impl, + equalString_Impl +> +PropertySetMap_Impl; + +//========================================================================= +// +// class PropertySetInfo_Impl +// +//========================================================================= + +class PropertySetInfo_Impl : + public OWeakObject, public XTypeProvider, public XPropertySetInfo +{ + Reference< XMultiServiceFactory > m_xSMgr; + Sequence< Property >* m_pProps; + PersistentPropertySet* m_pOwner; + +private: + sal_Bool queryProperty( const OUString& aName, Property& rProp ); + +public: + PropertySetInfo_Impl( const Reference< XMultiServiceFactory >& rxSMgr, + PersistentPropertySet* pOwner ); + virtual ~PropertySetInfo_Impl(); + + // XInterface + XINTERFACE_DECL() + + // XTypeProvider + XTYPEPROVIDER_DECL() + + // XPropertySetInfo + virtual Sequence< Property > SAL_CALL getProperties() + throw( RuntimeException ); + virtual Property SAL_CALL getPropertyByName( const OUString& aName ) + throw( UnknownPropertyException, RuntimeException ); + virtual sal_Bool SAL_CALL hasPropertyByName( const OUString& Name ) + throw( RuntimeException ); + + // Non-interface methods. + void reset() { delete m_pProps; m_pProps = 0; } +}; + +//========================================================================= +// +// UcbStore_Impl. +// +//========================================================================= + +struct UcbStore_Impl +{ + RegistryMap_Impl m_aRegistries; + osl::Mutex m_aMutex; +}; + +//========================================================================= +//========================================================================= +//========================================================================= +// +// UcbStore Implementation. +// +//========================================================================= +//========================================================================= +//========================================================================= + +UcbStore::UcbStore( const Reference< XMultiServiceFactory >& rXSMgr ) +: m_xSMgr( rXSMgr ), + m_pImpl( new UcbStore_Impl() ) +{ +} + +//========================================================================= +// virtual +UcbStore::~UcbStore() +{ + delete m_pImpl; +} + +//========================================================================= +// +// XInterface methods. +// +//========================================================================= + +XINTERFACE_IMPL_3( UcbStore, + XTypeProvider, + XServiceInfo, + XPropertySetRegistryFactory ); + +//========================================================================= +// +// XTypeProvider methods. +// +//========================================================================= + +XTYPEPROVIDER_IMPL_3( UcbStore, + XTypeProvider, + XServiceInfo, + XPropertySetRegistryFactory ); + +//========================================================================= +// +// XServiceInfo methods. +// +//========================================================================= + +XSERVICEINFO_IMPL_1( UcbStore, + OUString::createFromAscii( "UcbStore" ), + OUString::createFromAscii( STORE_SERVICE_NAME ) ); + +//========================================================================= +// +// Service factory implementation. +// +//========================================================================= + +ONE_INSTANCE_SERVICE_FACTORY_IMPL( UcbStore ); + +//========================================================================= +// +// XPropertySetRegistryFactory methods. +// +//========================================================================= + +// virtual +Reference< XPropertySetRegistry > SAL_CALL +UcbStore::createPropertySetRegistry( const OUString& URL ) + throw( RuntimeException ) +{ + if ( URL.getLength() ) + { + osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + + RegistryMap_Impl& rRegs = m_pImpl->m_aRegistries; + + RegistryMap_Impl::const_iterator it = rRegs.find( URL ); + if ( it != rRegs.end() ) + { + // Already instanciated. + return Reference< XPropertySetRegistry >( (*it).second ); + } + else + { + // Create new and remember, if valid. + PropertySetRegistry* pNew = + PropertySetRegistry::create( m_xSMgr, *this, URL ); + if ( pNew ) + { + rRegs[ URL ] = pNew; + return Reference< XPropertySetRegistry >( pNew ); + } + } + } + + return Reference< XPropertySetRegistry >(); +} + +//========================================================================= +// +// New methods. +// +//========================================================================= + +void UcbStore::removeRegistry( const OUString& URL ) +{ + if ( URL.getLength() ) + { + osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + + RegistryMap_Impl& rRegs = m_pImpl->m_aRegistries; + + RegistryMap_Impl::iterator it = rRegs.find( URL ); + if ( it != rRegs.end() ) + { + // Found. + rRegs.erase( it ); + } + } +} + +//========================================================================= +// +// PropertySetRegistry_Impl. +// +//========================================================================= + +struct PropertySetRegistry_Impl +{ + UcbStore* m_pCreator; + OUString m_aURL; + store::OStoreFile m_aStoreFile; + PropertySetMap_Impl m_aPropSets; + osl::Mutex m_aMutex; + + PropertySetRegistry_Impl( UcbStore& rCreator, + const OUString& rURL, + const store::OStoreFile& rStoreFile ) + : m_pCreator( &rCreator ), m_aURL( rURL ), m_aStoreFile( rStoreFile ) + { + m_pCreator->acquire(); + } + + ~PropertySetRegistry_Impl() + { + m_pCreator->removeRegistry( m_aURL ); + m_pCreator->release(); + } +}; + +//========================================================================= +//========================================================================= +//========================================================================= +// +// PropertySetRegistry Implementation. +// +//========================================================================= +//========================================================================= +//========================================================================= + +PropertySetRegistry::PropertySetRegistry( + const Reference< XMultiServiceFactory >& rXSMgr, + UcbStore& rCreator, + const OUString& rURL, + const store::OStoreFile& rStoreFile ) +: m_xSMgr( rXSMgr ), + m_pImpl( new PropertySetRegistry_Impl( rCreator, rURL, rStoreFile ) ) +{ +} + +//========================================================================= +// virtual +PropertySetRegistry::~PropertySetRegistry() +{ + delete m_pImpl; +} + +//========================================================================= +// +// XInterface methods. +// +//========================================================================= + +XINTERFACE_IMPL_5( PropertySetRegistry, + XTypeProvider, + XServiceInfo, + XPropertySetRegistry, + XElementAccess, /* base of XNameAccess */ + XNameAccess ); + +//========================================================================= +// +// XTypeProvider methods. +// +//========================================================================= + +XTYPEPROVIDER_IMPL_4( PropertySetRegistry, + XTypeProvider, + XServiceInfo, + XPropertySetRegistry, + XNameAccess ); + +//========================================================================= +// +// XServiceInfo methods. +// +//========================================================================= + +XSERVICEINFO_NOFACTORY_IMPL_1( PropertySetRegistry, + OUString::createFromAscii( + "PropertySetRegistry" ), + OUString::createFromAscii( + PROPSET_REG_SERVICE_NAME ) ); + +//========================================================================= +// +// XPropertySetRegistry methods. +// +//========================================================================= + +// virtual +Reference< XPersistentPropertySet > SAL_CALL +PropertySetRegistry::openPropertySet( const OUString& key, sal_Bool create ) + throw( RuntimeException ) +{ + if ( key.getLength() ) + { + osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + + PropertySetMap_Impl& rSets = m_pImpl->m_aPropSets; + + PropertySetMap_Impl::const_iterator it = rSets.find( key ); + if ( it != rSets.end() ) + { + // Already instanciated. + return Reference< XPersistentPropertySet >( (*it).second ); + } + else + { + // Create new and remember, if valid. + PersistentPropertySet* pNew = + PersistentPropertySet::create( m_xSMgr, *this, key, create ); + if ( pNew ) + return Reference< XPersistentPropertySet >( pNew ); + } + } + + return Reference< XPersistentPropertySet >(); +} + +//========================================================================= +// virtual +void SAL_CALL PropertySetRegistry::removePropertySet( const OUString& key ) + throw( RuntimeException ) +{ + OUString aKey( OUString::createFromAscii( PROPERTYSET_STREAM_PREFIX ) ); + aKey += key; + + storeError nError = m_pImpl->m_aStoreFile.remove( + OUString::createFromAscii( "/" ), aKey ); + + VOS_ENSURE( ( nError == store_E_None ) || ( nError == store_E_NotExists ), + "PropertySetRegistry::removePropertySet - error" ); +} + +//========================================================================= +// +// XElementAccess methods. +// +//========================================================================= + +// virtual +com::sun::star::uno::Type SAL_CALL PropertySetRegistry::getElementType() + throw( RuntimeException ) +{ + return getCppuType( ( Reference< XPersistentPropertySet >* ) 0 ); +} + +//========================================================================= +// virtual +sal_Bool SAL_CALL PropertySetRegistry::hasElements() + throw( RuntimeException ) +{ + Sequence< OUString > aSeq( getElementNames() ); + return ( aSeq.getLength() > 0 ); +} + +//========================================================================= +// +// XNameAccess methods. +// +//========================================================================= + +// virtual +Any SAL_CALL PropertySetRegistry::getByName( const OUString& aName ) + throw( NoSuchElementException, WrappedTargetException, RuntimeException ) +{ + Reference< XPersistentPropertySet > xSet( + PersistentPropertySet::create( m_xSMgr, *this, aName, sal_False ) ); + if ( xSet.is() ) + return Any( &xSet, getCppuType( &xSet ) ); + else + throw NoSuchElementException(); + + return Any(); +} + +//========================================================================= +// virtual +Sequence< OUString > SAL_CALL PropertySetRegistry::getElementNames() + throw( RuntimeException ) +{ + osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + + store::OStoreDirectory aDir; + storeError nError = aDir.create( + m_pImpl->m_aStoreFile, OUString(), OUString(), store_AccessReadOnly ); + + if ( nError == store_E_None ) + { + ///////////////////////////////////////////////////////////// + // Collect names. + ///////////////////////////////////////////////////////////// + + std::list< OUString > aElements; + + store::OStoreDirectory::iterator iter; + OUString aKeyName; + const OUString aPrefix( OUString::createFromAscii( + PROPERTYSET_STREAM_PREFIX ) ); + sal_Int32 nPrefixLen = aPrefix.getLength(); + + nError = aDir.first( iter ); + + while ( nError == store_E_None ) + { + aKeyName = OUString( iter.m_pszName ); + + if ( aKeyName.compareTo( aPrefix, nPrefixLen ) == 0 ) + aElements.push_back( + aKeyName.copy( nPrefixLen, + aKeyName.getLength() - nPrefixLen ) ); + + nError = aDir.next( iter ); + } + + ///////////////////////////////////////////////////////////// + // Fill sequence. + ///////////////////////////////////////////////////////////// + + sal_uInt32 nCount = aElements.size(); + if ( nCount ) + { + Sequence< OUString > aSeq( nCount ); + OUString* pNames = aSeq.getArray(); + sal_uInt32 nArrPos = 0; + + std::list < OUString >::const_iterator it = aElements.begin(); + std::list < OUString >::const_iterator end = aElements.end(); + + while ( it != end ) + { + pNames[ nArrPos ] = (*it); + it++; + nArrPos++; + } + + aDir.close(); + return aSeq; + } + } + + aDir.close(); + return Sequence< OUString >( 0 ); +} + +//========================================================================= +// virtual +sal_Bool SAL_CALL PropertySetRegistry::hasByName( const OUString& aName ) + throw( RuntimeException ) +{ + Reference< XPersistentPropertySet > xSet( + PersistentPropertySet::create( m_xSMgr, *this, aName, sal_False ) ); + if ( xSet.is() ) + return sal_True; + + return sal_False; +} + +//========================================================================= +// +// Non-interface methods +// +//========================================================================= + +// static +PropertySetRegistry* PropertySetRegistry::create( + const Reference< XMultiServiceFactory >& rXSMgr, + UcbStore& rCreator, + const OUString& rURL ) +{ + if ( !rURL.getLength() ) + return NULL; + + // Convert URL to system dependent file path. + OUString aUNCPath; + osl::FileBase::RC + eErr = osl::FileBase::getNormalizedPathFromFileURL( rURL, aUNCPath ); + if ( eErr != osl::FileBase::E_None ) + return NULL; + + OUString aPath; + eErr = osl::FileBase::getSystemPathFromNormalizedPath( aUNCPath, aPath ); + if ( eErr != osl::FileBase::E_None ) + return NULL; + + // Try to open/create storage file. + store::OStoreFile aStoreFile; + storeError nError = aStoreFile.create( aPath, store_AccessReadCreate ); + if ( nError != store_E_None ) + return NULL; + + // Root directory must be created explicitely! + store::OStoreDirectory aRootDir; + nError = aRootDir.create( + aStoreFile, OUString(), OUString(), store_AccessReadCreate ); + + return new PropertySetRegistry( rXSMgr, rCreator, rURL, aStoreFile ); +} + +//========================================================================= +osl::Mutex& PropertySetRegistry::getRegistryMutex() const +{ + return m_pImpl->m_aMutex; +} + +//========================================================================= +store::OStoreFile& PropertySetRegistry::getStoreFile() const +{ + return m_pImpl->m_aStoreFile; +} + +//========================================================================= +const OUString& PropertySetRegistry::getURL() const +{ + return m_pImpl->m_aURL; +} + +//========================================================================= +void PropertySetRegistry::add( PersistentPropertySet* pSet ) +{ + OUString key( pSet->getKey() ); + + if ( key.getLength() ) + { + osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + + PropertySetMap_Impl& rSets = m_pImpl->m_aPropSets; + + PropertySetMap_Impl::const_iterator it = rSets.find( key ); + rSets[ key ] = pSet; + } +} + +//========================================================================= +void PropertySetRegistry::remove( PersistentPropertySet* pSet ) +{ + OUString key( pSet->getKey() ); + + if ( key.getLength() ) + { + osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + + PropertySetMap_Impl& rSets = m_pImpl->m_aPropSets; + + PropertySetMap_Impl::iterator it = rSets.find( key ); + if ( it != rSets.end() ) + { + // Found. + rSets.erase( it ); + } + } +} + +//========================================================================= +void PropertySetRegistry::renamePropertySet( const OUString& rOldKey, + const OUString& rNewKey ) +{ + OUString aOldKey( OUString::createFromAscii( PROPERTYSET_STREAM_PREFIX ) ); + OUString aNewKey( aOldKey ); + aOldKey += rOldKey; + aNewKey += rNewKey; + + storeError nError = m_pImpl->m_aStoreFile.rename( + OUString::createFromAscii( "/" ), aOldKey, + OUString::createFromAscii( "/" ), aNewKey ); + + VOS_ENSURE( ( nError == store_E_None ) || ( nError == store_E_NotExists ), + "PropertySetRegistry::renamePropertySet - error" ); +} + +//========================================================================= +// +// PropertyListeners_Impl. +// +//========================================================================= + +typedef OMultiTypeInterfaceContainerHelperVar +< + OUString, + hashString_Impl, + equalString_Impl +> PropertyListeners_Impl; + +//========================================================================= +// +// PropertyInfoList. +// +//========================================================================= + +struct PropertyInfo : public com::sun::star::beans::PropertyValue +{ + sal_Int32 Attributes; + + PropertyInfo() + : Attributes( 0 ) {} + + PropertyInfo( const rtl::OUString& Name, + sal_Int32 Handle, + const ::com::sun::star::uno::Any& Value, + const ::com::sun::star::beans::PropertyState& State, + sal_Int32 Attributes ) + : PropertyValue( Name, Handle, Value, State ), Attributes( Attributes ) {} +}; + +//========================================================================= +// +// PropertyInfoList_Impl. +// +//========================================================================= + +typedef std::vector< PropertyInfo > PropertyInfos_Impl; + +class PropertyInfoList_Impl : public PropertyInfos_Impl {}; + +//========================================================================= +// +// PersistentPropertySet_Impl. +// +//========================================================================= + +struct PersistentPropertySet_Impl +{ + PropertySetRegistry* m_pCreator; + PropertyInfoList_Impl* m_pValues; + PropertySetInfo_Impl* m_pInfo; + OUString m_aKey; + osl::Mutex m_aMutex; + store::OStoreStream m_aStream; + OInterfaceContainerHelper* m_pDisposeEventListeners; + OInterfaceContainerHelper* m_pPropSetChangeListeners; + PropertyListeners_Impl* m_pPropertyChangeListeners; + + PersistentPropertySet_Impl( PropertySetRegistry& rCreator, + const OUString& rKey, + const store::OStoreStream& rStream, + PropertyInfoList_Impl* pValues ) + : m_pCreator( &rCreator ), m_pValues( pValues ), + m_pInfo( NULL ), m_aKey( rKey ), m_aStream( rStream ), + m_pDisposeEventListeners( NULL ), m_pPropSetChangeListeners( NULL ), + m_pPropertyChangeListeners( NULL ) + { + m_pCreator->acquire(); + } + + ~PersistentPropertySet_Impl() + { + m_pCreator->release(); + + if ( m_pInfo ) + m_pInfo->release(); + + delete m_pValues; + delete m_pDisposeEventListeners; + delete m_pPropSetChangeListeners; + delete m_pPropertyChangeListeners; + } +}; + +//========================================================================= +//========================================================================= +//========================================================================= +// +// PersistentPropertySet Implementation. +// +//========================================================================= +//========================================================================= +//========================================================================= + +PersistentPropertySet::PersistentPropertySet( + const Reference< XMultiServiceFactory >& rXSMgr, + PropertySetRegistry& rCreator, + const OUString& rKey, + const store::OStoreStream& rStream ) +: m_xSMgr( rXSMgr ), + m_pImpl( new PersistentPropertySet_Impl( rCreator, rKey, rStream, NULL ) ) +{ + // register at creator. + rCreator.add( this ); +} + +//========================================================================= +PersistentPropertySet::PersistentPropertySet( + const Reference< XMultiServiceFactory >& rXSMgr, + PropertySetRegistry& rCreator, + const OUString& rKey, + const store::OStoreStream& rStream, + const PropertyInfoList_Impl& rValues ) +: m_xSMgr( rXSMgr ), + m_pImpl( new PersistentPropertySet_Impl( + rCreator, + rKey, + rStream, + new PropertyInfoList_Impl( rValues ) ) ) +{ + // Store properties. + store(); + + // register at creator. + rCreator.add( this ); +} + +//========================================================================= +// virtual +PersistentPropertySet::~PersistentPropertySet() +{ + // deregister at creator. + m_pImpl->m_pCreator->remove( this ); + + delete m_pImpl; +} + +//========================================================================= +// +// XInterface methods. +// +//========================================================================= + +XINTERFACE_IMPL_9( PersistentPropertySet, + XTypeProvider, + XServiceInfo, + XComponent, + XPropertySet, /* base of XPersistentPropertySet */ + XNamed, + XPersistentPropertySet, + XPropertyContainer, + XPropertySetInfoChangeNotifier, + XPropertyAccess ); + +//========================================================================= +// +// XTypeProvider methods. +// +//========================================================================= + +XTYPEPROVIDER_IMPL_8( PersistentPropertySet, + XTypeProvider, + XServiceInfo, + XComponent, + XPersistentPropertySet, + XNamed, + XPropertyContainer, + XPropertySetInfoChangeNotifier, + XPropertyAccess ); + +//========================================================================= +// +// XServiceInfo methods. +// +//========================================================================= + +XSERVICEINFO_NOFACTORY_IMPL_1( PersistentPropertySet, + OUString::createFromAscii( + "PersistentPropertySet" ), + OUString::createFromAscii( + PERS_PROPSET_SERVICE_NAME ) ); + +//========================================================================= +// +// XComponent methods. +// +//========================================================================= + +// virtual +void SAL_CALL PersistentPropertySet::dispose() + throw( RuntimeException ) +{ + if ( m_pImpl->m_pDisposeEventListeners && + m_pImpl->m_pDisposeEventListeners->getLength() ) + { + EventObject aEvt; + aEvt.Source = static_cast< XComponent * >( this ); + m_pImpl->m_pDisposeEventListeners->disposeAndClear( aEvt ); + } + + if ( m_pImpl->m_pPropSetChangeListeners && + m_pImpl->m_pPropSetChangeListeners->getLength() ) + { + EventObject aEvt; + aEvt.Source = static_cast< XPropertySetInfoChangeNotifier * >( this ); + m_pImpl->m_pPropSetChangeListeners->disposeAndClear( aEvt ); + } + + if ( m_pImpl->m_pPropertyChangeListeners ) + { + EventObject aEvt; + aEvt.Source = static_cast< XPropertySet * >( this ); + m_pImpl->m_pPropertyChangeListeners->disposeAndClear( aEvt ); + } +} + +//========================================================================= +// virtual +void SAL_CALL PersistentPropertySet::addEventListener( + const Reference< XEventListener >& Listener ) + throw( RuntimeException ) +{ + if ( !m_pImpl->m_pDisposeEventListeners ) + m_pImpl->m_pDisposeEventListeners = + new OInterfaceContainerHelper( m_pImpl->m_aMutex ); + + m_pImpl->m_pDisposeEventListeners->addInterface( Listener ); +} + +//========================================================================= +// virtual +void SAL_CALL PersistentPropertySet::removeEventListener( + const Reference< XEventListener >& Listener ) + throw( RuntimeException ) +{ + if ( m_pImpl->m_pDisposeEventListeners ) + m_pImpl->m_pDisposeEventListeners->removeInterface( Listener ); + + // Note: Don't want to delete empty container here -> performance. +} + +//========================================================================= +// +// XPropertySet methods. +// +//========================================================================= + +// virtual +Reference< XPropertySetInfo > SAL_CALL + PersistentPropertySet::getPropertySetInfo() + throw( RuntimeException ) +{ + osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + + PropertySetInfo_Impl*& rpInfo = m_pImpl->m_pInfo; + if ( !rpInfo ) + { + rpInfo = new PropertySetInfo_Impl( m_xSMgr, this ); + rpInfo->acquire(); + } + return Reference< XPropertySetInfo >( rpInfo ); +} + +//========================================================================= +// virtual +void SAL_CALL PersistentPropertySet::setPropertyValue( + const OUString& aPropertyName, const Any& aValue ) + throw( UnknownPropertyException, + PropertyVetoException, + IllegalArgumentException, + WrappedTargetException, + RuntimeException ) +{ + if ( !aPropertyName.getLength() ) + throw UnknownPropertyException(); + + m_pImpl->m_aMutex.acquire(); + + load(); + + PropertyInfoList_Impl& rSeq = *m_pImpl->m_pValues; + sal_uInt32 nCount = rSeq.size(); + + if ( nCount ) + { + for ( sal_uInt32 n = 0; n < nCount; ++n ) + { + PropertyInfo& rValue = rSeq[ n ]; + + if ( rValue.Name == aPropertyName ) + { + // Check type. + if ( rValue.Value.getValueType() != aValue.getValueType() ) + { + m_pImpl->m_aMutex.release(); + throw IllegalArgumentException(); + } + + // Success. + + rValue.Value = aValue; + rValue.State = PropertyState_DIRECT_VALUE; + + PropertyChangeEvent aEvt; + if ( m_pImpl->m_pPropertyChangeListeners ) + { + aEvt.Source = (OWeakObject*)this; + aEvt.PropertyName = rValue.Name; + aEvt.PropertyHandle = rValue.Handle; + aEvt.Further = sal_False; + aEvt.OldValue = rValue.Value; + aEvt.NewValue = aValue; + } + + // Callback follows! + m_pImpl->m_aMutex.release(); + + if ( m_pImpl->m_pPropertyChangeListeners ) + notifyPropertyChangeEvent( aEvt ); + + store(); + return; + } + } + } + + m_pImpl->m_aMutex.release(); + throw UnknownPropertyException(); +} + +//========================================================================= +// virtual +Any SAL_CALL PersistentPropertySet::getPropertyValue( + const OUString& PropertyName ) + throw( UnknownPropertyException, + WrappedTargetException, + RuntimeException ) +{ + if ( !PropertyName.getLength() ) + throw UnknownPropertyException(); + + osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + + load(); + + const PropertyInfoList_Impl& rSeq = *m_pImpl->m_pValues; + sal_uInt32 nCount = rSeq.size(); + + if ( nCount ) + { + for ( sal_uInt32 n = 0; n < nCount; ++n ) + { + const PropertyInfo& rValue = rSeq[ n ]; + + if ( rValue.Name == PropertyName ) + { + // Found. + return rValue.Value; + } + } + } + + throw UnknownPropertyException(); + + // Make MSC4 happy ;-) + return Any(); +} + +//========================================================================= +// virtual +void SAL_CALL PersistentPropertySet::addPropertyChangeListener( + const OUString& aPropertyName, + const Reference< XPropertyChangeListener >& xListener ) + throw( UnknownPropertyException, + WrappedTargetException, + RuntimeException ) +{ +// load(); + + if ( !m_pImpl->m_pPropertyChangeListeners ) + m_pImpl->m_pPropertyChangeListeners = + new PropertyListeners_Impl( m_pImpl->m_aMutex ); + + m_pImpl->m_pPropertyChangeListeners->addInterface( + aPropertyName, xListener ); +} + +//========================================================================= +// virtual +void SAL_CALL PersistentPropertySet::removePropertyChangeListener( + const OUString& aPropertyName, + const Reference< XPropertyChangeListener >& aListener ) + throw( UnknownPropertyException, + WrappedTargetException, + RuntimeException ) +{ +// load(); + + if ( m_pImpl->m_pPropertyChangeListeners ) + m_pImpl->m_pPropertyChangeListeners->removeInterface( + aPropertyName, aListener ); + + // Note: Don't want to delete empty container here -> performance. +} + +//========================================================================= +// virtual +void SAL_CALL PersistentPropertySet::addVetoableChangeListener( + const OUString& PropertyName, + const Reference< XVetoableChangeListener >& aListener ) + throw( UnknownPropertyException, + WrappedTargetException, + RuntimeException ) +{ +// load(); +// VOS_ENSURE( sal_False, +// "PersistentPropertySet::addVetoableChangeListener - N.Y.I." ); +} + +//========================================================================= +// virtual +void SAL_CALL PersistentPropertySet::removeVetoableChangeListener( + const OUString& PropertyName, + const Reference< XVetoableChangeListener >& aListener ) + throw( UnknownPropertyException, + WrappedTargetException, + RuntimeException ) +{ +// load(); +// VOS_ENSURE( sal_False, +// "PersistentPropertySet::removeVetoableChangeListener - N.Y.I." ); +} + +//========================================================================= +// +// XPersistentPropertySet methods. +// +//========================================================================= + +// virtual +Reference< XPropertySetRegistry > SAL_CALL PersistentPropertySet::getRegistry() + throw( RuntimeException ) +{ + return Reference< XPropertySetRegistry >( m_pImpl->m_pCreator ); +} + +//========================================================================= +// virtual +OUString SAL_CALL PersistentPropertySet::getKey() + throw( RuntimeException ) +{ + return m_pImpl->m_aKey; +} + +//========================================================================= +// +// XNamed methods. +// +//========================================================================= + +// virtual +rtl::OUString SAL_CALL PersistentPropertySet::getName() + throw( RuntimeException ) +{ + // same as getKey() + return m_pImpl->m_aKey; +} + +//========================================================================= +// virtual +void SAL_CALL PersistentPropertySet::setName( const OUString& aName ) + throw( RuntimeException ) +{ + if ( aName != m_pImpl->m_aKey ) + m_pImpl->m_pCreator->renamePropertySet( m_pImpl->m_aKey, aName ); +} + +//========================================================================= +// +// XPropertyContainer methods. +// +//========================================================================= + +// virtual +void SAL_CALL PersistentPropertySet::addProperty( + const OUString& Name, sal_Int16 Attributes, const Any& DefaultValue ) + throw( PropertyExistException, + IllegalTypeException, + IllegalArgumentException, + RuntimeException ) +{ + if ( !Name.getLength() ) + throw IllegalArgumentException(); + + // Check type class ( Not all types can be written to storage ) + TypeClass eTypeClass = DefaultValue.getValueTypeClass(); + if ( eTypeClass == TypeClass_INTERFACE ) + throw IllegalTypeException(); + + osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + + load(); + + PropertyInfoList_Impl& rSeq = *m_pImpl->m_pValues; + sal_uInt32 nCount = rSeq.size(); + + if ( nCount ) + { + for ( sal_uInt32 n = 0; n < nCount; ++n ) + { + PropertyInfo& rValue = rSeq[ n ]; + + if ( rValue.Name == Name ) + { + // Already in set. + throw PropertyExistException(); + } + } + } + + // Property is always removeable. + Attributes |= PropertyAttribute::REMOVEABLE; + + // Add property. + rSeq.push_back( PropertyInfo( Name, + -1, + DefaultValue, + PropertyState_DEFAULT_VALUE, + Attributes ) ); + store(); + + // Property set info is invalid. + if ( m_pImpl->m_pInfo ) + m_pImpl->m_pInfo->reset(); + + // Notify propertyset info change listeners. + if ( m_pImpl->m_pPropSetChangeListeners && + m_pImpl->m_pPropSetChangeListeners->getLength() ) + { + PropertySetInfoChangeEvent evt( + static_cast< OWeakObject * >( this ), + Name, + -1, + PropertySetInfoChange::PROPERTY_INSERTED ); + notifyPropertySetInfoChange( evt ); + } +} + +//========================================================================= +// virtual +void SAL_CALL PersistentPropertySet::removeProperty( const OUString& Name ) + throw( UnknownPropertyException, + NotRemoveableException, + RuntimeException ) +{ + osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + + load(); + + PropertyInfoList_Impl& rSeq = *m_pImpl->m_pValues; + sal_uInt32 nCount = rSeq.size(); + + if ( !nCount ) + throw UnknownPropertyException(); + + sal_Bool bFound = sal_False; + + for ( sal_uInt32 n = 0; n < nCount; ++n ) + { + PropertyInfo& rValue = rSeq[ n ]; + + if ( rValue.Name == Name ) + { + // Found. + + PropertyInfo aValue( rValue ); + + if ( !( rValue.Attributes & PropertyAttribute::REMOVEABLE ) ) + { + // Not removeable! + throw NotRemoveableException(); + } + + // Remove property from sequence. + + sal_uInt32 nNewCount = nCount - 1; + + if ( n == nNewCount ) + { + // Remove last element. + rSeq.pop_back(); + } + else + { + PropertyInfoList_Impl* pNew = new PropertyInfoList_Impl; + PropertyInfoList_Impl& rNew = *pNew; + + for ( sal_uInt32 k = 0, l = 0; k < nNewCount; ++k, ++l ) + { + if ( k == n ) + l++; + + rNew.push_back( rSeq[ l ] ); + } + + delete m_pImpl->m_pValues; + m_pImpl->m_pValues = pNew; + } + + store(); + + // Property set info is invalid. + if ( m_pImpl->m_pInfo ) + m_pImpl->m_pInfo->reset(); + + // Notify propertyset info change listeners. + if ( m_pImpl->m_pPropSetChangeListeners && + m_pImpl->m_pPropSetChangeListeners->getLength() ) + { + PropertySetInfoChangeEvent evt( + static_cast< OWeakObject * >( this ), + aValue.Name, + aValue.Handle, + PropertySetInfoChange::PROPERTY_REMOVED ); + notifyPropertySetInfoChange( evt ); + } + + return; + } + } + + throw UnknownPropertyException(); +} + +//========================================================================= +// +// XPropertySetInfoChangeNotifier methods. +// +//========================================================================= + +// virtual +void SAL_CALL PersistentPropertySet::addPropertySetInfoChangeListener( + const Reference< XPropertySetInfoChangeListener >& Listener ) + throw( RuntimeException ) +{ + if ( !m_pImpl->m_pPropSetChangeListeners ) + m_pImpl->m_pPropSetChangeListeners = + new OInterfaceContainerHelper( m_pImpl->m_aMutex ); + + m_pImpl->m_pPropSetChangeListeners->addInterface( Listener ); +} + +//========================================================================= +// virtual +void SAL_CALL PersistentPropertySet::removePropertySetInfoChangeListener( + const Reference< XPropertySetInfoChangeListener >& Listener ) + throw( RuntimeException ) +{ + if ( m_pImpl->m_pPropSetChangeListeners ) + m_pImpl->m_pPropSetChangeListeners->removeInterface( Listener ); +} + +//========================================================================= +// +// XPropertyAccess methods. +// +//========================================================================= + +// virtual +Sequence< PropertyValue > SAL_CALL PersistentPropertySet::getPropertyValues() + throw( RuntimeException ) +{ + const PropertyInfoList_Impl aInfo( getProperties() ); + sal_uInt32 nCount = aInfo.size(); + Sequence< PropertyValue > aValues( nCount ); + + PropertyValue* pValues = aValues.getArray(); + + for ( sal_uInt32 n = 0; n < nCount; ++n ) + pValues[ n ] = aInfo[ n ]; + + return aValues; +} + +//========================================================================= +// virtual +void SAL_CALL PersistentPropertySet::setPropertyValues( + const Sequence< PropertyValue >& aProps ) + throw( UnknownPropertyException, + PropertyVetoException, + IllegalArgumentException, + WrappedTargetException, + RuntimeException ) +{ + // Note: Unknown properties are ignored - UnknownPropertyExecption's + // will not be thrown! The specification of this method is buggy + // in my opinion. Refer to definition of XMultiProertySet, where + // exceptions are specified well. + + m_pImpl->m_aMutex.acquire(); + + load(); + + PropertyInfoList_Impl& rSeq = *m_pImpl->m_pValues; + sal_uInt32 nCount = rSeq.size(); + + if ( nCount ) + { + const PropertyValue* pNewValues = aProps.getConstArray(); + sal_uInt32 nNewCount = aProps.getLength(); + + typedef std::list< PropertyChangeEvent > Events; + Events aEvents; + + // Iterate over new property value sequence. + for ( sal_uInt32 n = 0; n < nNewCount; ++n ) + { + const PropertyValue& rNewValue = pNewValues[ n ]; + const OUString& rName = rNewValue.Name; + +#ifdef _DEBUG + sal_Bool bFound = sal_False; +#endif + // Iterate over property value sequence. + for ( sal_uInt32 k = 0; k < nCount; ++k ) + { + PropertyInfo& rValue = rSeq[ k ]; + if ( rValue.Name == rName ) + { + // type check ? + + VOS_ENSURE( rNewValue.State == PropertyState_DIRECT_VALUE, + "PersistentPropertySet::setPropertyValues - " + "Wrong property state!" ); + +#ifdef _DEBUG + bFound = sal_True; +#endif + + if ( m_pImpl->m_pPropertyChangeListeners ) + { + PropertyChangeEvent aEvt; + aEvt.Source = (OWeakObject*)this; + aEvt.PropertyName = rNewValue.Name; + aEvt.PropertyHandle = rNewValue.Handle; + aEvt.Further = sal_False; + aEvt.OldValue = rValue.Value; + aEvt.NewValue = rNewValue.Value; + + aEvents.push_back( aEvt ); + } + + rValue.Name = rNewValue.Name; + rValue.Handle = rNewValue.Handle; + rValue.Value = rNewValue.Value; + rValue.State = PropertyState_DIRECT_VALUE; +// rValue.Attributes = <unchanged> + + // Process next property to set. + break; + } + } + + VOS_ENSURE( bFound, + "PersistentPropertySet::setPropertyValues - " + "Unknown property!" ); + } + + // Callback follows! + m_pImpl->m_aMutex.release(); + + if ( m_pImpl->m_pPropertyChangeListeners ) + { + // Notify property changes. + Events::const_iterator it = aEvents.begin(); + Events::const_iterator end = aEvents.end(); + + while ( it != end ) + { + notifyPropertyChangeEvent( (*it) ); + it++; + } + } + + store(); + return; + } + + m_pImpl->m_aMutex.release(); + + VOS_ENSURE( sal_False, + "PersistentPropertySet::setPropertyValues - Nothing set!" ); +} + +//========================================================================= +// +// Non-interface methods +// +//========================================================================= + +// static +PersistentPropertySet* PersistentPropertySet::create( + const Reference< XMultiServiceFactory >& rXSMgr, + PropertySetRegistry& rCreator, + const OUString& rKey, + sal_Bool bCreate ) +{ + if ( !rKey.getLength() ) + return NULL; + + osl::Guard< osl::Mutex > aGuard( rCreator.getRegistryMutex() ); + + storeAccessMode eMode = + bCreate ? store_AccessReadCreate : store_AccessReadWrite; + + store::OStoreFile& rStore = rCreator.getStoreFile(); + OUString aStreamName( OUString::createFromAscii( + PROPERTYSET_STREAM_PREFIX ) ); + aStreamName += rKey; + + store::OStoreStream aStream; + storeError nError = aStream.create( rStore, + OUString::createFromAscii( "/" ), + aStreamName, + eMode ); + + VOS_ENSURE( ( nError == store_E_None ) + || ( ( nError == store_E_NotExists ) + && ( eMode == store_AccessReadWrite ) ), + "PersistentPropertySet::create - Error!" ); + +#if 0 + + sal_Bool bLookForCHAOSViewProps = sal_False; + + const OUString& rURL = rCreator.getURL(); + if ( rURL.getLength() > 3 ) + { + // Note: All View Storages ever written by CHAOS have the + // filename extension 'scc'. + + const OUString aExtension( rURL.copy( rURL.getLength() - 4 ) ); + if ( aExtension.equalsIgnoreCase( + OUString::createFromAscii( ".scc" ) ) ) + { + if ( ( nError == store_E_NotExists ) && + ( eMode == store_AccessReadWrite ) ) + { + // Stream does not exist. But look for CHAOS view props. + bLookForCHAOSViewProps = sal_True; + } + else if ( ( nError == store_E_None ) && + ( eMode == store_AccessReadCreate ) ) + { + sal_uInt32 nSize = 0; + aStream.getSize( nSize ); + if ( nSize == 0 ) + { + // Stream was just created. Look for CHAOS view props. + bLookForCHAOSViewProps = sal_True; + } + } + } + } + + if ( bLookForCHAOSViewProps ) + { + ////////////////////////////////////////////////////////////// + // Compatibility: + // Convert View-Properties from CHAOS-View-Storages. + ////////////////////////////////////////////////////////////// + + PropertyInfoList_Impl aSeq( + CntPersistentPropertySet::query( rURL, rKey ) ); + + if ( nError == store_E_NotExists ) + nError = aStream.create( rStore, + OUString::createFromAscii( "/" ), + aStreamName, + store_AccessReadCreate ); + + if ( nError == store_E_None ) + { + // Note: Pass the sequence to propset, even if it is empty! + return new PersistentPropertySet( rXSMgr, + rCreator, + rKey, + aStream, + aSeq ); + } + } +#endif + + if ( nError == store_E_None ) + return new PersistentPropertySet( rXSMgr, + rCreator, + rKey, + aStream ); + return NULL; +} + +//========================================================================= +const PropertyInfoList_Impl& PersistentPropertySet::getProperties() +{ + osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + + load(); + return *m_pImpl->m_pValues; +} + +//========================================================================= +sal_Bool PersistentPropertySet::load() +{ + osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + + if ( m_pImpl->m_pValues ) + return sal_True; + + osl::Guard< osl::Mutex > aRegistryGuard( + m_pImpl->m_pCreator->getRegistryMutex() ); + + ////////////////////////////////////////////////////////////////////// + // Read header. + ////////////////////////////////////////////////////////////////////// + + PropertySetStreamHeader_Impl aHeader; + + sal_uInt32 nBytesRead = 0; + storeError nError = m_pImpl->m_aStream.readAt( + 0, + &aHeader, + PROPERTYSET_STREAM_HEADER_SIZE, + nBytesRead ); + + if ( ( nError == store_E_None ) && ( nBytesRead == 0 ) ) + { + // Not exists. + m_pImpl->m_pValues = new PropertyInfoList_Impl; + return sal_True; + } + + if ( ( nError == store_E_None ) && + ( nBytesRead == PROPERTYSET_STREAM_HEADER_SIZE ) ) + { + ////////////////////////////////////////////////////////////////// + // Check header. + ////////////////////////////////////////////////////////////////// + + if ( ( aHeader.m_nMagic == PROPERTYSET_STREAM_MAGIC ) && + ( aHeader.m_nVersion == PROPERTYSET_STREAM_VERSION ) ) + { + if ( !aHeader.m_nDataLen ) + { + // Empty. + m_pImpl->m_pValues = new PropertyInfoList_Impl; + return sal_True; + } + + ////////////////////////////////////////////////////////////// + // Read data. + ////////////////////////////////////////////////////////////// + + PropertySetStreamBuffer_Impl aBuffer( aHeader.m_nDataLen ); + + nBytesRead = 0; + nError = m_pImpl->m_aStream.readAt( + PROPERTYSET_STREAM_HEADER_SIZE, + static_cast< sal_uInt8 * >( aBuffer ), + aHeader.m_nDataLen, + nBytesRead ); + + if ( ( nError == store_E_None ) && + ( nBytesRead == aHeader.m_nDataLen ) ) + { + sal_Bool bSuccess = sal_True; + + PropertyInfoList_Impl* pSeq = new PropertyInfoList_Impl; + + for ( sal_uInt32 n = 0; n < aHeader.m_nCount; ++n ) + { + ////////////////////////////////////////////////////// + // Read element. + ////////////////////////////////////////////////////// + + ////////////////////////////////////////////////////// + // data format: + // + // sal_uInt32 nNameLen; + // sal_uInt8* Name; + // ----> OUString PropertyValue.Name + // sal_Int32 Handle; + // ----> sal_Int32 PropertyValue.Handle + // sal_Int32 Attributes; + // ----> sal_Int16 PropertyValue.Attributes + // sal_Int32 State; + // ----> PropertyState PropertyValue.State + // sal_uInt32 nValueLen; + // sal_uInt8* Value; + // ----> Any PropertyValue.Value + ////////////////////////////////////////////////////// + + PropertyInfo aValue; + + bSuccess = aBuffer.readString( aValue.Name ); + if ( !bSuccess ) + break; + + bSuccess = aBuffer.readInt32( aValue.Handle ); + if ( !bSuccess ) + break; + + sal_Int32 nAttributes; + bSuccess = aBuffer.readInt32( nAttributes ); + if ( !bSuccess ) + break; + + aValue.Attributes = nAttributes; // sal_Int16 ! + + sal_Int32 nState; + bSuccess = aBuffer.readInt32( nState ); + if ( !bSuccess ) + break; + + // enum ! + aValue.State = static_cast< PropertyState >( nState ); + + bSuccess = aBuffer.readAny( aValue.Value ); + if ( !bSuccess ) + break; + + pSeq->push_back( aValue ); + } + + if ( bSuccess ) + { + // Success! + m_pImpl->m_pValues = pSeq; + return sal_True; + } + else + delete pSeq; + } + } + } + + VOS_ENSURE( sal_False, "PersistentPropertySet::load - error!" ); + m_pImpl->m_pValues = new PropertyInfoList_Impl; + return sal_False; +} + +//========================================================================= +sal_Bool PersistentPropertySet::store() +{ + osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + + load(); + + osl::Guard< osl::Mutex > aRegistryGuard( + m_pImpl->m_pCreator->getRegistryMutex() ); + + sal_Bool bSuccess = sal_True; + + ////////////////////////////////////////////////////////////////////// + // Create and fill buffer. + ////////////////////////////////////////////////////////////////////// + + const PropertyInfoList_Impl& rSeq = *m_pImpl->m_pValues; + sal_uInt32 nElements = rSeq.size(); + + PropertySetStreamBuffer_Impl aBuffer( 65535 /* Bytes - initial size */ ); + + for ( sal_uInt32 n = 0; n < nElements; ++n ) + { + const PropertyInfo& rValue = rSeq[ n ]; + + ////////////////////////////////////////////////////////////////// + // Put element into buffer. + ////////////////////////////////////////////////////////////////// + // data format: refer to PersistentPropertySet::load(). + ////////////////////////////////////////////////////////////////// + + bSuccess = aBuffer.writeString( rValue.Name ); + if ( !bSuccess ) + break; + + bSuccess = aBuffer.writeInt32( rValue.Handle ); + if ( !bSuccess ) + break; + + bSuccess = aBuffer.writeInt32( rValue.Attributes ); + if ( !bSuccess ) + break; + + bSuccess = aBuffer.writeInt32( rValue.State ); + if ( !bSuccess ) + break; + + bSuccess = aBuffer.writeAny( rValue.Value ); + if ( !bSuccess ) + break; + } + + if ( bSuccess ) + { + sal_uInt32 nDataBytes = aBuffer.getDataLength(); + + ////////////////////////////////////////////////////////////////// + // Write header. + ////////////////////////////////////////////////////////////////// + + PropertySetStreamHeader_Impl aHeader( PROPERTYSET_STREAM_MAGIC, + PROPERTYSET_STREAM_VERSION, + nDataBytes, + nElements ); + sal_uInt32 nBytesWritten; + storeError nError = m_pImpl->m_aStream.writeAt( + 0, + &aHeader, + PROPERTYSET_STREAM_HEADER_SIZE, + nBytesWritten ); + + if ( ( nError == store_E_None ) && + ( nBytesWritten == PROPERTYSET_STREAM_HEADER_SIZE ) ) + { + if ( !nDataBytes ) + { + // Empty. + return sal_True; + } + + ////////////////////////////////////////////////////////////// + // Write data. + ////////////////////////////////////////////////////////////// + + nError = m_pImpl->m_aStream.writeAt( + PROPERTYSET_STREAM_HEADER_SIZE, + static_cast< sal_uInt8 * >( aBuffer ), + nDataBytes, + nBytesWritten ); + + if ( ( nError == store_E_None ) && ( nBytesWritten == nDataBytes ) ) + return sal_True; + } + } + + VOS_ENSURE( sal_False, "PersistentPropertySet::store - error!" ); + return sal_False; +} + +//========================================================================= +void PersistentPropertySet::notifyPropertyChangeEvent( + const PropertyChangeEvent& rEvent ) const +{ + // Get "normal" listeners for the property. + OInterfaceContainerHelper* pContainer = + m_pImpl->m_pPropertyChangeListeners->getContainer( + rEvent.PropertyName ); + if ( pContainer && pContainer->getLength() ) + { + OInterfaceIteratorHelper aIter( *pContainer ); + while ( aIter.hasMoreElements() ) + { + // Propagate event. + Reference< XPropertyChangeListener > xListener( + aIter.next(), UNO_QUERY ); + if ( xListener.is() ) + xListener->propertyChange( rEvent ); + } + } + + // Get "normal" listeners for all properties. + OInterfaceContainerHelper* pNoNameContainer = + m_pImpl->m_pPropertyChangeListeners->getContainer( OUString() ); + if ( pNoNameContainer && pNoNameContainer->getLength() ) + { + OInterfaceIteratorHelper aIter( *pNoNameContainer ); + while ( aIter.hasMoreElements() ) + { + // Propagate event. + Reference< XPropertyChangeListener > xListener( + aIter.next(), UNO_QUERY ); + if ( xListener.is() ) + xListener->propertyChange( rEvent ); + } + } +} + +//========================================================================= +void PersistentPropertySet::notifyPropertySetInfoChange( + const PropertySetInfoChangeEvent& evt ) const +{ + if ( !m_pImpl->m_pPropSetChangeListeners ) + return; + + // Notify event listeners. + OInterfaceIteratorHelper aIter( *( m_pImpl->m_pPropSetChangeListeners ) ); + while ( aIter.hasMoreElements() ) + { + // Propagate event. + Reference< XPropertySetInfoChangeListener > + xListener( aIter.next(), UNO_QUERY ); + if ( xListener.is() ) + xListener->propertySetInfoChange( evt ); + } +} + +//========================================================================= +//========================================================================= +// +// PropertySetStreamBuffer_Impl Implementation. +// +//========================================================================= +//========================================================================= + +PropertySetStreamBuffer_Impl::PropertySetStreamBuffer_Impl( + sal_uInt32 nInitSize, sal_uInt32 nGrowSize ) +: m_nSize( nInitSize ), + m_nGrow( nGrowSize ) +{ + m_pBuffer = static_cast< sal_uInt8 * >( rtl_allocateMemory( m_nSize ) ); + m_pPos = m_pBuffer; +} + +//========================================================================= +PropertySetStreamBuffer_Impl::~PropertySetStreamBuffer_Impl() +{ + rtl_freeMemory( m_pBuffer ); +} + +//========================================================================= +sal_Bool PropertySetStreamBuffer_Impl::readString( OUString& rValue ) +{ + // Read sal_Int32 -> data length. + sal_Int32 nLen = 0; + readInt32( nLen ); + + // Read data bytes -> UTF8 encoded string as byte array. + ensureCapacity( nLen ); + rValue = OUString( reinterpret_cast< const sal_Char * >( m_pPos ), + nLen, + RTL_TEXTENCODING_UTF8 ); + m_pPos += nLen; + + // Align buffer position. + sal_uInt32 nAlignment = ALIGN_POS( nLen ); + ensureCapacity( nAlignment ); + m_pPos += nAlignment; + + return sal_True; +} + +//========================================================================= +sal_Bool PropertySetStreamBuffer_Impl::readInt32( sal_Int32& rValue ) +{ + // Read sal_Int32. + ensureCapacity( sizeof( sal_Int32 ) ); + rtl_copyMemory( &rValue, m_pPos, sizeof( sal_Int32 ) ); + m_pPos += sizeof( sal_Int32 ); + +#ifdef OSL_BIGENDIAN + rValue = VOS_SWAPDWORD( rValue ); +#endif + + return sal_True; +} + +//========================================================================= +sal_Bool PropertySetStreamBuffer_Impl::readAny( Any& rValue ) +{ + // Read sal_Int32 -> data length. + sal_Int32 nLen = 0; + readInt32( nLen ); + + if ( nLen ) + { + // Read data bytes -> Any as byte array. + ensureCapacity( nLen ); + + Sequence< sal_Int8 > aSeq( nLen ); + sal_Int8* pData = aSeq.getArray(); + for ( sal_uInt32 n = 0; n < nLen; ++n ) + { + pData[ n ] = *m_pPos; + m_pPos++; + } + + // Create Any from byte array. + rValue = anyDeserialize( aSeq ); + + // Align buffer position. + sal_uInt32 nAlignment = ALIGN_POS( nLen ); + ensureCapacity( nAlignment ); + m_pPos += nAlignment; + } + + return sal_True; +} + +//========================================================================= +sal_Bool PropertySetStreamBuffer_Impl::writeString( const OUString& rValue ) +{ + const OString aValue( + rValue.getStr(), rValue.getLength(), RTL_TEXTENCODING_UTF8 ); + sal_uInt32 nLen = aValue.getLength(); + + // Write sal_uInt32 -> data length. + writeInt32( nLen ); + + // Write data bytes -> UTF8 encoded string as byte array. + ensureCapacity( nLen ); + rtl_copyMemory( m_pPos, aValue.getStr(), nLen ); + m_pPos += aValue.getLength(); + + // Align buffer position. + sal_uInt32 nAlignment = ALIGN_POS( nLen ); + ensureCapacity( nAlignment ); + m_pPos += nAlignment; + + return sal_True; +} + +//========================================================================= +sal_Bool PropertySetStreamBuffer_Impl::writeInt32( sal_Int32 nValue ) +{ + // Write sal_Int32. + +#ifdef OSL_BIGENDIAN + nValue = VOS_SWAPDWORD( nValue ); +#endif + + ensureCapacity( sizeof( sal_Int32 ) ); + rtl_copyMemory( m_pPos, &nValue, sizeof( sal_Int32 ) ); + m_pPos += sizeof( sal_Int32 ); + + return sal_True; +} + +//========================================================================= +sal_Bool PropertySetStreamBuffer_Impl::writeAny( const Any& rValue ) +{ + // Convert Any to byte sequence. + Sequence< sal_Int8 > aSeq( anySerialize( rValue ) ); + + sal_uInt32 nLen = aSeq.getLength(); + + // Write sal_uInt32 -> data length. + writeInt32( nLen ); + + if ( nLen ) + { + // Write data -> Any as byte array. + ensureCapacity( nLen ); + + const sal_Int8* pData = aSeq.getConstArray(); + for ( sal_uInt32 n = 0; n < nLen; ++n ) + { + *m_pPos = pData[ n ]; + m_pPos++; + } + + // Align buffer position. + sal_uInt32 nAlignment = ALIGN_POS( nLen ); + ensureCapacity( nAlignment ); + m_pPos += nAlignment; + } + + return sal_True; +} + +//========================================================================= +void PropertySetStreamBuffer_Impl::ensureCapacity( sal_uInt8 nBytesNeeded ) +{ + if ( ( m_pPos + nBytesNeeded ) > ( m_pBuffer + m_nSize ) ) + { + sal_uInt32 nPosDelta = m_pPos - m_pBuffer; + + m_pBuffer = static_cast< sal_uInt8 * >( + rtl_reallocateMemory( m_pBuffer, + m_nSize + m_nGrow ) ); + m_pPos = m_pBuffer + nPosDelta; + m_nSize += m_nGrow; + } +} + +//========================================================================= +//========================================================================= +// +// PropertySetInfo_Impl Implementation. +// +//========================================================================= +//========================================================================= + +PropertySetInfo_Impl::PropertySetInfo_Impl( + const Reference< XMultiServiceFactory >& rxSMgr, + PersistentPropertySet* pOwner ) +: m_xSMgr( rxSMgr ), + m_pProps( NULL ), + m_pOwner( pOwner ) +{ +} + +//========================================================================= +// virtual +PropertySetInfo_Impl::~PropertySetInfo_Impl() +{ + delete m_pProps; + + // !!! Do not delete m_pOwner !!! +} + +//========================================================================= +// +// XInterface methods. +// +//========================================================================= + +XINTERFACE_IMPL_2( PropertySetInfo_Impl, + XTypeProvider, + XPropertySetInfo ); + +//========================================================================= +// +// XTypeProvider methods. +// +//========================================================================= + +XTYPEPROVIDER_IMPL_2( PropertySetInfo_Impl, + XTypeProvider, + XPropertySetInfo ); + +//========================================================================= +// +// XPropertySetInfo methods. +// +//========================================================================= + +// virtual +Sequence< Property > SAL_CALL PropertySetInfo_Impl::getProperties() + throw( RuntimeException ) +{ + if ( !m_pProps ) + { + const PropertyInfoList_Impl& rSeq = m_pOwner->getProperties(); + sal_uInt32 nCount = rSeq.size(); + + Sequence< Property >* pPropSeq = new Sequence< Property >( nCount ); + + if ( nCount ) + { + Property* pProps = pPropSeq->getArray(); + for ( sal_uInt32 n = 0; n < nCount; ++n ) + { + const PropertyInfo& rValue = rSeq[ n ]; + Property& rProp = pProps[ n ]; + + rProp.Name = rValue.Name; + rProp.Handle = rValue.Handle; + rProp.Type = rValue.Value.getValueType(); + rProp.Attributes = rValue.Attributes; + } + } + + m_pProps = pPropSeq; + } + + return *m_pProps; +} + +//========================================================================= +// virtual +Property SAL_CALL PropertySetInfo_Impl::getPropertyByName( + const OUString& aName ) + throw( UnknownPropertyException, RuntimeException ) +{ + Property aProp; + if ( queryProperty( aName, aProp ) ) + return aProp; + + throw UnknownPropertyException(); +} + +//========================================================================= +// virtual +sal_Bool SAL_CALL PropertySetInfo_Impl::hasPropertyByName( + const OUString& Name ) + throw( RuntimeException ) +{ + Property aProp; + return queryProperty( Name, aProp ); +} + +//========================================================================= +sal_Bool PropertySetInfo_Impl::queryProperty( + const OUString& aName, Property& rProp ) +{ + const PropertyInfoList_Impl& rSeq = m_pOwner->getProperties(); + sal_uInt32 nCount = rSeq.size(); + for ( sal_uInt32 n = 0; n < nCount; ++n ) + { + const PropertyInfo& rValue = rSeq[ n ]; + if ( rValue.Name == aName ) + { + rProp.Name = rValue.Name; + rProp.Handle = rValue.Handle; + rProp.Type = rValue.Value.getValueType(); + rProp.Attributes = rValue.Attributes; + + return sal_True; + } + } + + return sal_False; +} + diff --git a/ucb/source/core/ucbstore.hxx b/ucb/source/core/ucbstore.hxx new file mode 100644 index 000000000000..5cf29a2583bd --- /dev/null +++ b/ucb/source/core/ucbstore.hxx @@ -0,0 +1,427 @@ +/************************************************************************* + * + * $RCSfile: ucbstore.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:52:48 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _UCBSTORE_HXX +#define _UCBSTORE_HXX + +#ifndef _COM_SUN_STAR_LANG_XTYPEPROVIDER_HPP_ +#include <com/sun/star/lang/XTypeProvider.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_ +#include <com/sun/star/lang/XServiceInfo.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_CONTAINER_XNAMED_HPP_ +#include <com/sun/star/container/XNamed.hpp> +#endif +#ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_ +#include <com/sun/star/container/XNameAccess.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XPROPERTYSETREGISTRYFACTORY_HPP_ +#include <com/sun/star/ucb/XPropertySetRegistryFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XPROPERTYSETREGISTRY_HPP_ +#include <com/sun/star/ucb/XPropertySetRegistry.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XPERSISTENTPROPERTYSET_HPP_ +#include <com/sun/star/ucb/XPersistentPropertySet.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_XPROPERTYCONTAINER_HPP_ +#include <com/sun/star/beans/XPropertyContainer.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSETINFOCHANGENOTIFIER_HPP_ +#include <com/sun/star/beans/XPropertySetInfoChangeNotifier.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_XPROPERTYACCESS_HPP_ +#include <com/sun/star/beans/XPropertyAccess.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XCOMPONENT_HPP_ +#include <com/sun/star/lang/XComponent.hpp> +#endif + +#ifndef _CPPUHELPER_WEAK_HXX_ +#include <cppuhelper/weak.hxx> +#endif + +#ifndef _UCBHELPER_MACROS_HXX +#include <ucbhelper/macros.hxx> +#endif + +namespace store +{ + class OStoreFile; + class OStoreStream; +} + +//========================================================================= + +#define STORE_SERVICE_NAME "com.sun.star.ucb.Store" +#define PROPSET_REG_SERVICE_NAME "com.sun.star.ucb.PropertySetRegistry" +#define PERS_PROPSET_SERVICE_NAME "com.sun.star.ucb.PersistentPropertySet" + +//========================================================================= + +struct UcbStore_Impl; + +class UcbStore : + public cppu::OWeakObject, + public com::sun::star::lang::XTypeProvider, + public com::sun::star::lang::XServiceInfo, + public com::sun::star::ucb::XPropertySetRegistryFactory +{ + com::sun::star::uno::Reference< + com::sun::star::lang::XMultiServiceFactory > m_xSMgr; + UcbStore_Impl* m_pImpl; + +public: + UcbStore( + const com::sun::star::uno::Reference< + com::sun::star::lang::XMultiServiceFactory >& rXSMgr ); + virtual ~UcbStore(); + + // XInterface + XINTERFACE_DECL() + + // XTypeProvider + XTYPEPROVIDER_DECL() + + // XServiceInfo + XSERVICEINFO_DECL() + + // XPropertySetRegistryFactory + virtual com::sun::star::uno::Reference< + com::sun::star::ucb::XPropertySetRegistry > SAL_CALL + createPropertySetRegistry( const rtl::OUString& URL ) + throw( com::sun::star::uno::RuntimeException ); + + // New + void removeRegistry( const rtl::OUString& URL ); +}; + +//========================================================================= + +struct PropertySetRegistry_Impl; + +class PropertySetRegistry : + public cppu::OWeakObject, + public com::sun::star::lang::XTypeProvider, + public com::sun::star::lang::XServiceInfo, + public com::sun::star::ucb::XPropertySetRegistry, + public com::sun::star::container::XNameAccess +{ + friend class PersistentPropertySet; + + com::sun::star::uno::Reference< + com::sun::star::lang::XMultiServiceFactory > m_xSMgr; + PropertySetRegistry_Impl* m_pImpl; + +private: + void add ( PersistentPropertySet* pSet ); + void remove( PersistentPropertySet* pSet ); + + void renamePropertySet( const rtl::OUString& rOldKey, + const rtl::OUString& rNewKey ); +protected: + PropertySetRegistry( + const com::sun::star::uno::Reference< + com::sun::star::lang::XMultiServiceFactory >& rXSMgr, + UcbStore& rCreator, + const rtl::OUString& rURL, + const store::OStoreFile& rStoreFile ); + +public: + virtual ~PropertySetRegistry(); + + // XInterface + XINTERFACE_DECL() + + // XTypeProvider + XTYPEPROVIDER_DECL() + + // XServiceInfo + XSERVICEINFO_NOFACTORY_DECL() + + // XPropertySetRegistry + virtual com::sun::star::uno::Reference< + com::sun::star::ucb::XPersistentPropertySet > SAL_CALL + openPropertySet( const rtl::OUString& key, sal_Bool create ) + throw( com::sun::star::uno::RuntimeException ); + virtual void SAL_CALL + removePropertySet( const rtl::OUString& key ) + throw( com::sun::star::uno::RuntimeException ); + + // XElementAccess ( XNameAccess is derived from it ) + virtual com::sun::star::uno::Type SAL_CALL + getElementType() + throw( com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL + hasElements() + throw( com::sun::star::uno::RuntimeException ); + + // XNameAccess + virtual com::sun::star::uno::Any SAL_CALL + getByName( const rtl::OUString& aName ) + throw( com::sun::star::container::NoSuchElementException, + com::sun::star::lang::WrappedTargetException, + com::sun::star::uno::RuntimeException ); + virtual com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL + getElementNames() + throw( com::sun::star::uno::RuntimeException ); + virtual sal_Bool SAL_CALL + hasByName( const rtl::OUString& aName ) + throw( com::sun::star::uno::RuntimeException ); + + // Non-interface methods + static PropertySetRegistry* create( + const com::sun::star::uno::Reference< + com::sun::star::lang::XMultiServiceFactory >& rXSMgr, + UcbStore& rCreator, + const rtl::OUString& rURL ); + osl::Mutex& getRegistryMutex() const; + store::OStoreFile& getStoreFile() const; + const rtl::OUString& getURL() const; +}; + +//========================================================================= + +struct PersistentPropertySet_Impl; +class PropertyInfoList_Impl; + +class PersistentPropertySet : + public cppu::OWeakObject, + public com::sun::star::lang::XTypeProvider, + public com::sun::star::lang::XServiceInfo, + public com::sun::star::lang::XComponent, + public com::sun::star::ucb::XPersistentPropertySet, + public com::sun::star::container::XNamed, + public com::sun::star::beans::XPropertyContainer, + public com::sun::star::beans::XPropertySetInfoChangeNotifier, + public com::sun::star::beans::XPropertyAccess +{ + com::sun::star::uno::Reference< + com::sun::star::lang::XMultiServiceFactory > m_xSMgr; + PersistentPropertySet_Impl* m_pImpl; + +private: + sal_Bool load(); + sal_Bool store(); + + void notifyPropertyChangeEvent( + const com::sun::star::beans::PropertyChangeEvent& rEvent ) const; + void notifyPropertySetInfoChange( + const com::sun::star::beans::PropertySetInfoChangeEvent& evt ) const; + +protected: + PersistentPropertySet( + const com::sun::star::uno::Reference< + com::sun::star::lang::XMultiServiceFactory >& rXSMgr, + PropertySetRegistry& rCreator, + const rtl::OUString& rKey, + const store::OStoreStream& rStream ); + PersistentPropertySet( + const com::sun::star::uno::Reference< + com::sun::star::lang::XMultiServiceFactory >& rXSMgr, + PropertySetRegistry& rCreator, + const rtl::OUString& rKey, + const store::OStoreStream& rStream, + const PropertyInfoList_Impl& rValues ); + +public: + virtual ~PersistentPropertySet(); + + // XInterface + XINTERFACE_DECL() + + // XTypeProvider + XTYPEPROVIDER_DECL() + + // XServiceInfo + XSERVICEINFO_NOFACTORY_DECL() + + // XComponent + virtual void SAL_CALL + dispose() + throw( com::sun::star::uno::RuntimeException ); + virtual void SAL_CALL + addEventListener( const com::sun::star::uno::Reference< + com::sun::star::lang::XEventListener >& Listener ) + throw( com::sun::star::uno::RuntimeException ); + virtual void SAL_CALL + removeEventListener( const com::sun::star::uno::Reference< + com::sun::star::lang::XEventListener >& Listener ) + throw( com::sun::star::uno::RuntimeException ); + + // XPropertySet + virtual com::sun::star::uno::Reference< + com::sun::star::beans::XPropertySetInfo > SAL_CALL + getPropertySetInfo() + throw( com::sun::star::uno::RuntimeException ); + virtual void SAL_CALL + setPropertyValue( const rtl::OUString& aPropertyName, + const com::sun::star::uno::Any& aValue ) + throw( com::sun::star::beans::UnknownPropertyException, + com::sun::star::beans::PropertyVetoException, + com::sun::star::lang::IllegalArgumentException, + com::sun::star::lang::WrappedTargetException, + com::sun::star::uno::RuntimeException ); + virtual com::sun::star::uno::Any SAL_CALL + getPropertyValue( const rtl::OUString& PropertyName ) + throw( com::sun::star::beans::UnknownPropertyException, + com::sun::star::lang::WrappedTargetException, + com::sun::star::uno::RuntimeException ); + virtual void SAL_CALL + addPropertyChangeListener( const rtl::OUString& aPropertyName, + const com::sun::star::uno::Reference< + com::sun::star::beans::XPropertyChangeListener >& xListener ) + throw( com::sun::star::beans::UnknownPropertyException, + com::sun::star::lang::WrappedTargetException, + com::sun::star::uno::RuntimeException ); + virtual void SAL_CALL + removePropertyChangeListener( const rtl::OUString& aPropertyName, + const com::sun::star::uno::Reference< + com::sun::star::beans::XPropertyChangeListener >& aListener ) + throw( com::sun::star::beans::UnknownPropertyException, + com::sun::star::lang::WrappedTargetException, + com::sun::star::uno::RuntimeException ); + virtual void SAL_CALL + addVetoableChangeListener( const rtl::OUString& PropertyName, + const com::sun::star::uno::Reference< + com::sun::star::beans::XVetoableChangeListener >& aListener ) + throw( com::sun::star::beans::UnknownPropertyException, + com::sun::star::lang::WrappedTargetException, + com::sun::star::uno::RuntimeException ); + virtual void SAL_CALL + removeVetoableChangeListener( const rtl::OUString& PropertyName, + const com::sun::star::uno::Reference< + com::sun::star::beans::XVetoableChangeListener >& aListener ) + throw( com::sun::star::beans::UnknownPropertyException, + com::sun::star::lang::WrappedTargetException, + com::sun::star::uno::RuntimeException ); + + // XPersistentPropertySet + virtual com::sun::star::uno::Reference< + com::sun::star::ucb::XPropertySetRegistry > SAL_CALL + getRegistry() + throw( com::sun::star::uno::RuntimeException ); + virtual rtl::OUString SAL_CALL + getKey() + throw( com::sun::star::uno::RuntimeException ); + + // XNamed + virtual rtl::OUString SAL_CALL + getName() + throw( ::com::sun::star::uno::RuntimeException ); + virtual void SAL_CALL + setName( const ::rtl::OUString& aName ) + throw( ::com::sun::star::uno::RuntimeException ); + + // XPropertyContainer + virtual void SAL_CALL + addProperty( const rtl::OUString& Name, + sal_Int16 Attributes, + const com::sun::star::uno::Any& DefaultValue ) + throw( com::sun::star::beans::PropertyExistException, + com::sun::star::beans::IllegalTypeException, + com::sun::star::lang::IllegalArgumentException, + com::sun::star::uno::RuntimeException ); + virtual void SAL_CALL + removeProperty( const rtl::OUString& Name ) + throw( com::sun::star::beans::UnknownPropertyException, + com::sun::star::beans::NotRemoveableException, + com::sun::star::uno::RuntimeException ); + + // XPropertySetInfoChangeNotifier + virtual void SAL_CALL + addPropertySetInfoChangeListener( const com::sun::star::uno::Reference< + com::sun::star::beans::XPropertySetInfoChangeListener >& Listener ) + throw( com::sun::star::uno::RuntimeException ); + virtual void SAL_CALL + removePropertySetInfoChangeListener( const com::sun::star::uno::Reference< + com::sun::star::beans::XPropertySetInfoChangeListener >& Listener ) + throw( com::sun::star::uno::RuntimeException ); + + // XPropertyAccess + virtual com::sun::star::uno::Sequence< + com::sun::star::beans::PropertyValue > SAL_CALL + getPropertyValues() + throw( com::sun::star::uno::RuntimeException ); + virtual void SAL_CALL + setPropertyValues( const com::sun::star::uno::Sequence< + com::sun::star::beans::PropertyValue >& aProps ) + throw( com::sun::star::beans::UnknownPropertyException, + com::sun::star::beans::PropertyVetoException, + com::sun::star::lang::IllegalArgumentException, + com::sun::star::lang::WrappedTargetException, + com::sun::star::uno::RuntimeException ); + + // Non-interface methods + static PersistentPropertySet* create( + const com::sun::star::uno::Reference< + com::sun::star::lang::XMultiServiceFactory >& rXSMgr, + PropertySetRegistry& rCreator, + const rtl::OUString& rKey, + sal_Bool bCreate ); + const PropertyInfoList_Impl& getProperties(); +}; + +#endif /* !_UCBSTORE_HXX */ diff --git a/ucb/source/inc/regexp.hxx b/ucb/source/inc/regexp.hxx new file mode 100644 index 000000000000..6b1b049bccd5 --- /dev/null +++ b/ucb/source/inc/regexp.hxx @@ -0,0 +1,123 @@ +/************************************************************************* + * + * $RCSfile: regexp.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:53:07 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _UCB_REGEXP_HXX_ +#define _UCB_REGEXP_HXX_ + +#ifndef _RTL_USTRING_HXX_ +#include <rtl/ustring.hxx> +#endif +#ifndef _VOS_DIAGNOSE_H_ +#include <vos/diagnose.hxx> +#endif + +//============================================================================ +namespace ucb { + +class Regexp +{ +public: + enum Kind + { + KIND_PREFIX, + KIND_AUTHORITY, + KIND_DOMAIN + }; + + inline bool operator ==(Regexp const & rOther) const; + + inline bool isDefault() const + { return m_eKind == KIND_PREFIX && m_aPrefix.getLength() == 0; } + + inline Kind getKind() const { return m_eKind; } + + bool matches(rtl::OUString const & rString, rtl::OUString * pTranslation, + bool * pTranslated) const; + + rtl::OUString getRegexp(bool bReverse) const; + + static Regexp parse(rtl::OUString const & rRegexp); + +private: + Kind m_eKind; + rtl::OUString m_aPrefix; + rtl::OUString m_aInfix; + rtl::OUString m_aReversePrefix; + bool m_bEmptyDomain; + bool m_bTranslation; + + inline Regexp(Kind eTheKind, rtl::OUString const & rThePrefix, + bool bTheEmptyDomain, rtl::OUString const & rTheInfix, + bool bTheTranslation, + rtl::OUString const & rTheReversePrefix); +}; + +inline bool Regexp::operator ==(Regexp const & rOther) const +{ + return m_eKind == rOther.m_eKind + && m_aPrefix == rOther.m_aPrefix + && m_aInfix == rOther.m_aInfix; +} + +} + +#endif // _UCPRMT_RMTREGX_HXX_ + diff --git a/ucb/source/inc/regexpmap.hxx b/ucb/source/inc/regexpmap.hxx new file mode 100644 index 000000000000..e9af736f33de --- /dev/null +++ b/ucb/source/inc/regexpmap.hxx @@ -0,0 +1,226 @@ +/************************************************************************* + * + * $RCSfile: regexpmap.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:53:07 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _UCB_REGEXPMAP_HXX_ +#define _UCB_REGEXPMAP_HXX_ + +#ifndef _RTL_OUSTRING_HXX_ +#include <rtl/ustring.hxx> +#endif +#ifndef _SAL_TYPES_H_ +#include <sal/types.h> +#endif + +namespace ucb { + +template< typename Val > class RegexpMap; +template< typename Val > class RegexpMapIter; + +//============================================================================ +template< typename Val > +class RegexpMapEntry +{ +public: + inline RegexpMapEntry(rtl::OUString const & rTheRegexp, + Val * pTheValue): + m_aRegexp(rTheRegexp), m_pValue(pTheValue) {} + + rtl::OUString getRegexp() const { return m_aRegexp; } + + Val const & getValue() const { return *m_pValue; } + + Val & getValue() { return *m_pValue; } + +private: + rtl::OUString m_aRegexp; + Val * m_pValue; +}; + +//============================================================================ +template< typename Val > class RegexpMapIterImpl; + // MSC doesn't like this to be a private RegexpMapConstIter member + // class... + +template< typename Val > +class RegexpMapConstIter +{ + friend RegexpMap< Val >; // to access m_pImpl, ctor + friend RegexpMapIter< Val >; // to access m_pImpl, ctor + +public: + RegexpMapConstIter(); + + RegexpMapConstIter(RegexpMapConstIter const & rOther); + + ~RegexpMapConstIter(); + + RegexpMapConstIter & operator =(RegexpMapConstIter const & rOther); + + RegexpMapConstIter & operator ++(); + + RegexpMapConstIter operator ++(int); + + RegexpMapEntry< Val > const & operator *() const; + + RegexpMapEntry< Val > const * operator ->() const; + + bool equals(RegexpMapConstIter const & rOther) const; + // for free operator ==(), operator !=() + +private: + RegexpMapIterImpl< Val > * m_pImpl; + + RegexpMapConstIter(RegexpMapIterImpl< Val > * pTheImpl); +}; + +//============================================================================ +template< typename Val > +class RegexpMapIter: public RegexpMapConstIter< Val > +{ + friend RegexpMap< Val >; // to access ctor + +public: + RegexpMapIter() {} + + RegexpMapIter & operator ++(); + + RegexpMapIter operator ++(int); + + RegexpMapEntry< Val > & operator *(); + + RegexpMapEntry< Val > const & operator *() const; + + RegexpMapEntry< Val > * operator ->(); + + RegexpMapEntry< Val > const * operator ->() const; + +private: + RegexpMapIter(RegexpMapIterImpl< Val > * pTheImpl); +}; + +//============================================================================ +template< typename Val > struct RegexpMapImpl; + // MSC doesn't like this to be a RegexpMap member class... + +template< typename Val > +class RegexpMap +{ +public: + typedef sal_uInt32 size_type; + typedef RegexpMapIter< Val > iterator; + typedef RegexpMapConstIter< Val > const_iterator; + + RegexpMap(); + + RegexpMap(RegexpMap const & rOther); + + ~RegexpMap(); + + RegexpMap & operator =(RegexpMap const & rOther); + + bool add(rtl::OUString const & rKey, Val const & rValue, bool bOverwrite, + rtl::OUString * pReverse = 0); + // throws com::sun::star::lang::IllegalArgumentException + + iterator find(rtl::OUString const & rKey, rtl::OUString * pReverse = 0); + // throws com::sun::star::lang::IllegalArgumentException + + void erase(iterator const & rPos); + + iterator begin(); + + const_iterator begin() const; + + iterator end(); + + const_iterator end() const; + + bool empty() const; + + size_type size() const; + + Val const * map(rtl::OUString const & rString, + rtl::OUString * pTranslation = 0, bool * pTranslated = 0) + const; + +private: + RegexpMapImpl< Val > * m_pImpl; +}; + +} + +//============================================================================ +template< typename Val > +inline bool operator ==(ucb::RegexpMapConstIter< Val > const & rIter1, + ucb::RegexpMapConstIter< Val > const & rIter2) +{ + return rIter1.equals(rIter2); +} + +template< typename Val > +inline bool operator !=(ucb::RegexpMapConstIter< Val > const & rIter1, + ucb::RegexpMapConstIter< Val > const & rIter2) +{ + return !rIter1.equals(rIter2); +} + +#endif // _UCB_REGEXPMAP_HXX_ + diff --git a/ucb/source/inc/regexpmap.tpt b/ucb/source/inc/regexpmap.tpt new file mode 100644 index 000000000000..1b7b1564e284 --- /dev/null +++ b/ucb/source/inc/regexpmap.tpt @@ -0,0 +1,597 @@ +/************************************************************************* + * + * $RCSfile: regexpmap.tpt,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:53:07 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _UCB_REGEXPMAP_TPT_ +#define _UCB_REGEXPMAP_TPT_ + +#ifndef _UCB_REGEXPMAP_HXX_ +#include <regexpmap.hxx> +#endif + +#include <list> + +#ifndef _RTL_USTRING_HXX_ +#include <rtl/ustring.hxx> +#endif + +#ifndef _UCB_REGEXP_HXX_ +#include "regexp.hxx" +#endif + +namespace unnamed_ucb_regexpmap {} using namespace unnamed_ucb_regexpmap; + // unnamed namespaces don't work well yet... + +using namespace ucb; + +//============================================================================ +namespace unnamed_ucb_regexpmap { + +template< typename Val > +struct Entry +{ + Regexp m_aRegexp; + Val m_aValue; + + inline Entry(Regexp const & rTheRegexp, Val const & rTheValue): + m_aRegexp(rTheRegexp), m_aValue(rTheValue) {} +}; + +//============================================================================ +template< typename Val > class List: public std::list< Entry< Val > > {}; + +} + +//============================================================================ +// +// RegexpMapIterImpl +// +//============================================================================ + +namespace ucb { + +template< typename Val > +class RegexpMapIterImpl +{ +public: + typedef RegexpMapImpl< Val > MapImpl; + typedef List< Val >::iterator ListIterator; + // Solaris needs these for the ctor... + + inline RegexpMapIterImpl(); + + inline RegexpMapIterImpl(MapImpl * pTheMap, int nTheList, + ListIterator aTheIndex); + + RegexpMapIterImpl(RegexpMapImpl< Val > * pTheMap, bool bBegin); + + bool operator ==(RegexpMapIterImpl const & rOther) const; + + RegexpMapImpl< Val > const * getMap() const { return m_pMap; } + + int getList() const { return m_nList; } + + List< Val >::iterator const & getIndex() const { return m_aIndex; } + + void next(); + + RegexpMapEntry< Val > & get(); + +private: + mutable RegexpMapEntry< Val > m_aEntry; + List< Val >::iterator m_aIndex; + RegexpMapImpl< Val > * m_pMap; + int m_nList; + mutable bool m_bEntrySet; + + void setEntry() const; +}; + +} + +template< typename Val > +inline RegexpMapIterImpl< Val >::RegexpMapIterImpl(): + m_aEntry(rtl::OUString(), 0), + m_pMap(0), + m_nList(-1), + m_bEntrySet(false) +{} + +template< typename Val > +inline RegexpMapIterImpl< Val >::RegexpMapIterImpl(MapImpl * pTheMap, + int nTheList, + ListIterator aTheIndex): + m_aEntry(rtl::OUString(), 0), + m_aIndex(aTheIndex), + m_pMap(pTheMap), + m_nList(nTheList), + m_bEntrySet(false) +{} + +//============================================================================ +template< typename Val > +void RegexpMapIterImpl< Val >::setEntry() const +{ + if (!m_bEntrySet) + { + Entry< Val > const & rTheEntry + = m_nList == -1 ? *m_pMap->m_pDefault : *m_aIndex; + m_aEntry + = RegexpMapEntry< Val >(rTheEntry.m_aRegexp.getRegexp(false), + const_cast< Val * >(&rTheEntry.m_aValue)); + m_bEntrySet = true; + } +} + +//============================================================================ +template< typename Val > +RegexpMapIterImpl< Val >::RegexpMapIterImpl(RegexpMapImpl< Val > * pTheMap, + bool bBegin): + m_aEntry(rtl::OUString(), 0), + m_pMap(pTheMap), + m_bEntrySet(false) +{ + if (bBegin) + { + m_nList = -1; + m_aIndex = List< Val >::iterator(); + if (!m_pMap->m_pDefault) + next(); + } + else + { + m_nList = Regexp::KIND_DOMAIN; + m_aIndex = m_pMap->m_aList[Regexp::KIND_DOMAIN].end(); + } +} + +//============================================================================ +template< typename Val > +bool RegexpMapIterImpl< Val >::operator ==(RegexpMapIterImpl const & rOther) + const +{ + return m_pMap == rOther.m_pMap + && m_nList == rOther.m_nList + && m_aIndex == rOther.m_aIndex; +} + +//============================================================================ +template< typename Val > +void RegexpMapIterImpl< Val >::next() +{ + switch (m_nList) + { + case Regexp::KIND_DOMAIN: + if (m_aIndex == m_pMap->m_aList[m_nList].end()) + return; + default: + ++m_aIndex; + if (m_nList == Regexp::KIND_DOMAIN + || m_aIndex != m_pMap->m_aList[m_nList].end()) + break; + case -1: + do + { + ++m_nList; + m_aIndex = m_pMap->m_aList[m_nList].begin(); + } + while (m_nList < Regexp::KIND_DOMAIN + && m_aIndex == m_pMap->m_aList[m_nList].end()); + break; + } + m_bEntrySet = false; +} + +//============================================================================ +template< typename Val > +RegexpMapEntry< Val > & RegexpMapIterImpl< Val >::get() +{ + setEntry(); + return m_aEntry; +} + +//============================================================================ +// +// RegexpMapConstIter +// +//============================================================================ + +template< typename Val > +RegexpMapConstIter< Val >::RegexpMapConstIter(RegexpMapIterImpl< Val > * + pTheImpl): + m_pImpl(pTheImpl) +{} + +//============================================================================ +template< typename Val > +RegexpMapConstIter< Val >::RegexpMapConstIter(): + m_pImpl(new RegexpMapIterImpl< Val >) +{} + +//============================================================================ +template< typename Val > +RegexpMapConstIter< Val >::RegexpMapConstIter(RegexpMapConstIter const & + rOther): + m_pImpl(new RegexpMapIterImpl< Val >(*rOther.m_pImpl)) +{} + +//============================================================================ +template< typename Val > +RegexpMapConstIter< Val >::~RegexpMapConstIter() +{ + delete m_pImpl; +} + +//============================================================================ +template< typename Val > +RegexpMapConstIter< Val > & +RegexpMapConstIter< Val >::operator =(RegexpMapConstIter const & rOther) +{ + *m_pImpl = *rOther.m_pImpl; + return *this; +} + +//============================================================================ +template< typename Val > +RegexpMapConstIter< Val > & RegexpMapConstIter< Val >::operator ++() +{ + m_pImpl->next(); + return *this; +} + +//============================================================================ +template< typename Val > +RegexpMapConstIter< Val > RegexpMapConstIter< Val >::operator ++(int) +{ + RegexpMapConstIter aTemp(*this); + m_pImpl->next(); + return aTemp; +} + +//============================================================================ +template< typename Val > +RegexpMapEntry< Val > const & RegexpMapConstIter< Val >::operator *() const +{ + return m_pImpl->get(); +} + +//============================================================================ +template< typename Val > +RegexpMapEntry< Val > const * RegexpMapConstIter< Val >::operator ->() const +{ + return &m_pImpl->get(); +} + +//============================================================================ +template< typename Val > +bool RegexpMapConstIter< Val >::equals(RegexpMapConstIter const & rOther) + const +{ + return *m_pImpl == *rOther.m_pImpl; +} + +//============================================================================ +// +// RegexpMapIter +// +//============================================================================ + +template< typename Val > +RegexpMapIter< Val >::RegexpMapIter(RegexpMapIterImpl< Val > * pTheImpl): + RegexpMapConstIter< Val >(pTheImpl) +{} + +//============================================================================ +template< typename Val > +RegexpMapIter< Val > & RegexpMapIter< Val >::operator ++() +{ + m_pImpl->next(); + return *this; +} + +//============================================================================ +template< typename Val > +RegexpMapIter< Val > RegexpMapIter< Val >::operator ++(int) +{ + RegexpMapIter aTemp(*this); + m_pImpl->next(); + return aTemp; +} + +//============================================================================ +template< typename Val > +RegexpMapEntry< Val > & RegexpMapIter< Val >::operator *() +{ + return m_pImpl->get(); +} + +//============================================================================ +template< typename Val > +RegexpMapEntry< Val > const & RegexpMapIter< Val >::operator *() const +{ + return m_pImpl->get(); +} + +//============================================================================ +template< typename Val > +RegexpMapEntry< Val > * RegexpMapIter< Val >::operator ->() +{ + return &m_pImpl->get(); +} + +//============================================================================ +template< typename Val > +RegexpMapEntry< Val > const * RegexpMapIter< Val >::operator ->() const +{ + return &m_pImpl->get(); +} + +//============================================================================ +// +// RegexpMap +// +//============================================================================ + +namespace ucb { + +template< typename Val > +struct RegexpMapImpl +{ + List< Val > m_aList[Regexp::KIND_DOMAIN + 1]; + Entry< Val > * m_pDefault; + + RegexpMapImpl(): m_pDefault(0) {} + + ~RegexpMapImpl() { delete m_pDefault; } +}; + +} + +//============================================================================ +template< typename Val > +RegexpMap< Val >::RegexpMap(): + m_pImpl(new RegexpMapImpl< Val >) +{} + +//============================================================================ +template< typename Val > +RegexpMap< Val >::RegexpMap(RegexpMap const & rOther): + m_pImpl(new RegexpMapImpl< Val >(*rOther.m_pImpl)) +{} + +//============================================================================ +template< typename Val > +RegexpMap< Val >::~RegexpMap() +{ + delete m_pImpl; +} + +//============================================================================ +template< typename Val > +RegexpMap< Val > & RegexpMap< Val >::operator =(RegexpMap const & rOther) +{ + *m_pImpl = *rOther.m_pImpl; + return *this; +} + +//============================================================================ +template< typename Val > +bool RegexpMap< Val >::add(rtl::OUString const & rKey, Val const & rValue, + bool bOverwrite, rtl::OUString * pReverse) +{ + Regexp aRegexp(Regexp::parse(rKey)); + + if (aRegexp.isDefault()) + { + if (m_pImpl->m_pDefault) + { + if (!bOverwrite) + return false; + delete m_pImpl->m_pDefault; + } + m_pImpl->m_pDefault = new Entry< Val >(aRegexp, rValue); + } + else + { + List< Val > & rTheList = m_pImpl->m_aList[aRegexp.getKind()]; + + List< Val >::iterator aEnd(rTheList.end()); + for (List< Val >::iterator aIt(rTheList.begin()); aIt != aEnd; ++aIt) + if (aIt->m_aRegexp == aRegexp) + if (bOverwrite) + { + rTheList.erase(aIt); + break; + } + else + return false; + + rTheList.push_back(Entry< Val >(aRegexp, rValue)); + } + + if (pReverse) + *pReverse = aRegexp.getRegexp(true); + + return true; +} + +//============================================================================ +template< typename Val > +RegexpMap< Val >::iterator RegexpMap< Val >::find(rtl::OUString const & rKey, + rtl::OUString * pReverse) +{ + Regexp aRegexp(Regexp::parse(rKey)); + + if (pReverse) + *pReverse = aRegexp.getRegexp(true); + + if (aRegexp.isDefault()) + { + if (m_pImpl->m_pDefault) + return RegexpMapIter< Val >(new RegexpMapIterImpl< Val >(m_pImpl, + true)); + } + else + { + List< Val > & rTheList = m_pImpl->m_aList[aRegexp.getKind()]; + + List< Val > ::iterator aEnd(rTheList.end()); + for (List< Val >::iterator aIt(rTheList.begin()); aIt != aEnd; ++aIt) + if (aIt->m_aRegexp == aRegexp) + return RegexpMapIter< Val >(new RegexpMapIterImpl< Val >( + m_pImpl, + aRegexp.getKind(), aIt)); + } + + return RegexpMapIter< Val >(new RegexpMapIterImpl< Val >(m_pImpl, false)); +} + +//============================================================================ +template< typename Val > +void RegexpMap< Val >::erase(iterator const & rPos) +{ + if (rPos.m_pImpl->getMap() == m_pImpl) + if (rPos.m_pImpl->getList() == -1) + { + if (m_pImpl->m_pDefault) + { + delete m_pImpl->m_pDefault; + m_pImpl->m_pDefault = 0; + } + } + else + m_pImpl->m_aList[rPos.m_pImpl->getList()]. + erase(rPos.m_pImpl->getIndex()); +} + +//============================================================================ +template< typename Val > +RegexpMap< Val >::iterator RegexpMap< Val >::begin() +{ + return RegexpMapIter< Val >(new RegexpMapIterImpl< Val >(m_pImpl, true)); +} + +//============================================================================ +template< typename Val > +RegexpMap< Val >::const_iterator RegexpMap< Val >::begin() const +{ + return RegexpMapConstIter< Val >(new RegexpMapIterImpl< Val >(m_pImpl, + true)); +} + +//============================================================================ +template< typename Val > +RegexpMap< Val >::iterator RegexpMap< Val >::end() +{ + return RegexpMapIter< Val >(new RegexpMapIterImpl< Val >(m_pImpl, false)); +} + +//============================================================================ +template< typename Val > +RegexpMap< Val >::const_iterator RegexpMap< Val >::end() const +{ + return RegexpMapConstIter< Val >(new RegexpMapIterImpl< Val >(m_pImpl, + false)); +} + +//============================================================================ +template< typename Val > +bool RegexpMap< Val >::empty() const +{ + return !m_pImpl->m_pDefault + && m_pImpl->m_aList[Regexp::KIND_PREFIX].empty() + && m_pImpl->m_aList[Regexp::KIND_AUTHORITY].empty() + && m_pImpl->m_aList[Regexp::KIND_DOMAIN].empty(); +} + +//============================================================================ +template< typename Val > +RegexpMap< Val >::size_type RegexpMap< Val >::size() const +{ + return (m_pImpl->m_pDefault ? 1 : 0) + + m_pImpl->m_aList[Regexp::KIND_PREFIX].size() + + m_pImpl->m_aList[Regexp::KIND_AUTHORITY].size() + + m_pImpl->m_aList[Regexp::KIND_DOMAIN].size(); +} + +//============================================================================ +template< typename Val > +Val const * RegexpMap< Val >::map(rtl::OUString const & rString, + rtl::OUString * pTranslation, + bool * pTranslated) const +{ + for (int n = Regexp::KIND_DOMAIN; n >= Regexp::KIND_PREFIX; --n) + { + List< Val > const & rTheList = m_pImpl->m_aList[n]; + + List< Val >::const_iterator aEnd(rTheList.end()); + for (List< Val >::const_iterator aIt(rTheList.begin()); aIt != aEnd; + ++aIt) + if (aIt->m_aRegexp.matches(rString, pTranslation, pTranslated)) + return &aIt->m_aValue; + } + if (m_pImpl->m_pDefault + && m_pImpl->m_pDefault->m_aRegexp.matches(rString, pTranslation, + pTranslated)) + return &m_pImpl->m_pDefault->m_aValue; + return 0; +} + +#endif // _UCB_REGEXPMAP_TPT_ diff --git a/ucb/source/regexp/makefile.mk b/ucb/source/regexp/makefile.mk new file mode 100644 index 000000000000..b74cf33750cf --- /dev/null +++ b/ucb/source/regexp/makefile.mk @@ -0,0 +1,76 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1 $ +# +# last change: $Author: kso $ $Date: 2000-10-16 14:53:21 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (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.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=..$/.. +PRJNAME=ucb +TARGET=regexp +AUTOSEG=true +ENABLE_EXCEPTIONS=true + +.INCLUDE : svpre.mk +.INCLUDE : settings.mk +.INCLUDE : sv.mk + +SLOFILES=\ + $(SLO)$/regexp.obj + +.INCLUDE : target.mk diff --git a/ucb/source/regexp/regexp.cxx b/ucb/source/regexp/regexp.cxx new file mode 100644 index 000000000000..1164182f0a9b --- /dev/null +++ b/ucb/source/regexp/regexp.cxx @@ -0,0 +1,509 @@ +/************************************************************************* + * + * $RCSfile: regexp.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:53:21 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _UCB_REGEXP_HXX_ +#include <regexp.hxx> +#endif + +#include <cstddef> + +#ifndef _COM_SUN_STAR_LANG_ILLEGALARGUMENTEXCEPTION_HPP_ +#include <com/sun/star/lang/IllegalArgumentException.hpp> +#endif +#ifndef _RTL_USTRBUF_HXX_ +#include <rtl/ustrbuf.hxx> +#endif +#ifndef _RTL_USTRING_HXX_ +#include <rtl/ustring.hxx> +#endif +#ifndef _VOS_DIAGNOSE_H_ +#include <vos/diagnose.hxx> +#endif + +namespace unnamed_ucb_regexp {} using namespace unnamed_ucb_regexp; + // unnamed namespaces don't work well yet... + +using namespace com::sun::star; +using namespace ucb; + +//============================================================================ +// +// Regexp +// +//============================================================================ + +inline Regexp::Regexp(Kind eTheKind, rtl::OUString const & rThePrefix, + bool bTheEmptyDomain, rtl::OUString const & rTheInfix, + bool bTheTranslation, + rtl::OUString const & rTheReversePrefix): + m_eKind(eTheKind), + m_aPrefix(rThePrefix), + m_aInfix(rTheInfix), + m_aReversePrefix(rTheReversePrefix), + m_bEmptyDomain(bTheEmptyDomain), + m_bTranslation(bTheTranslation) +{ + VOS_ASSERT(m_eKind == KIND_DOMAIN + || !m_bEmptyDomain && m_aInfix.getLength() == 0); + VOS_ASSERT(m_bTranslation || m_aReversePrefix.getLength() == 0); +} + +//============================================================================ +namespace unnamed_ucb_regexp { + +bool matchStringIgnoreCase(sal_Unicode const ** pBegin, + sal_Unicode const * pEnd, + rtl::OUString const & rString) +{ + sal_Unicode const * p = *pBegin; + + sal_Unicode const * q = rString.getStr(); + sal_Unicode const * qEnd = q + rString.getLength(); + + if (pEnd - p < qEnd - q) + return false; + + while (q != qEnd) + { + sal_Unicode c1 = *p++; + sal_Unicode c2 = *q++; + if (c1 >= 'a' && c1 <= 'z') + c1 -= 'a' - 'A'; + if (c2 >= 'a' && c2 <= 'z') + c2 -= 'a' - 'A'; + if (c1 != c2) + return false; + } + + *pBegin = p; + return true; +} + +} + +bool Regexp::matches(rtl::OUString const & rString, + rtl::OUString * pTranslation, bool * pTranslated) const +{ + sal_Unicode const * pBegin = rString.getStr(); + sal_Unicode const * pEnd = pBegin + rString.getLength(); + + bool bMatches = false; + + sal_Unicode const * p = pBegin; + if (matchStringIgnoreCase(&p, pEnd, m_aPrefix)) + { + sal_Unicode const * pBlock1Begin = p; + sal_Unicode const * pBlock1End = pEnd; + + sal_Unicode const * pBlock2Begin = 0; + sal_Unicode const * pBlock2End = 0; + + switch (m_eKind) + { + case KIND_PREFIX: + bMatches = true; + break; + + case KIND_AUTHORITY: + bMatches = p == pEnd || *p == '/' || *p == '?' || *p == '#'; + break; + + case KIND_DOMAIN: + if (!m_bEmptyDomain) + { + if (p == pEnd || *p == '/' || *p == '?' || *p == '#') + break; + ++p; + } + for (;;) + { + sal_Unicode const * q = p; + if (matchStringIgnoreCase(&q, pEnd, m_aInfix) + && (q == pEnd || *q == '/' || *q == '?' || *q == '#')) + { + bMatches = true; + pBlock1End = p; + pBlock2Begin = q; + pBlock2End = pEnd; + break; + } + + if (p == pEnd) + break; + + sal_Unicode c = *p++; + if (c == '/' || c == '?' || c == '#') + break; + } + break; + } + + if (bMatches) + if (m_bTranslation) + { + if (pTranslation) + { + rtl::OUStringBuffer aBuffer(m_aReversePrefix); + aBuffer.append(pBlock1Begin, pBlock1End - pBlock1Begin); + aBuffer.append(m_aInfix); + aBuffer.append(pBlock2Begin, pBlock2End - pBlock2Begin); + *pTranslation = aBuffer.makeStringAndClear(); + } + if (pTranslated) + *pTranslated = true; + } + else + { + if (pTranslation) + *pTranslation = rString; + if (pTranslated) + *pTranslated = false; + } + } + + return bMatches; +} + +//============================================================================ +namespace unnamed_ucb_regexp { + +inline bool isAlpha(sal_Unicode c) +{ + return c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z'; +} + +inline bool isDigit(sal_Unicode c) +{ + return c >= '0' && c <= '9'; +} + +bool isScheme(rtl::OUString const & rString) +{ + // Return true if rString matches <scheme> from RFC 2396: + sal_Unicode const * p = rString.getStr(); + sal_Unicode const * pEnd = p + rString.getLength(); + if (p != pEnd && isAlpha(*p)) + for (++p;;) + { + if (p == pEnd) + return true; + sal_Unicode c = *p++; + if (!(isAlpha(c) || isDigit(c) + || c == '+' || c == '-' || c == '.')) + break; + } + return false; +} + +void appendStringLiteral(rtl::OUStringBuffer * pBuffer, + rtl::OUString const & rString) +{ + VOS_ASSERT(pBuffer); + + pBuffer->append(sal_Unicode('"')); + sal_Unicode const * p = rString.getStr(); + sal_Unicode const * pEnd = p + rString.getLength(); + while (p != pEnd) + { + sal_Unicode c = *p++; + if (c == '"' || c == '\\') + pBuffer->append(sal_Unicode('\\')); + pBuffer->append(c); + } + pBuffer->append(sal_Unicode('"')); +} + +} + +rtl::OUString Regexp::getRegexp(bool bReverse) const +{ + if (m_bTranslation) + { + rtl::OUStringBuffer aBuffer; + if (bReverse) + { + if (m_aReversePrefix.getLength() != 0) + appendStringLiteral(&aBuffer, m_aReversePrefix); + } + else + { + if (m_aPrefix.getLength() != 0) + appendStringLiteral(&aBuffer, m_aPrefix); + } + switch (m_eKind) + { + case KIND_PREFIX: + aBuffer.appendAscii(RTL_CONSTASCII_STRINGPARAM("(.*)")); + break; + + case KIND_AUTHORITY: + aBuffer. + appendAscii(RTL_CONSTASCII_STRINGPARAM("(([/?#].*)?)")); + break; + + case KIND_DOMAIN: + aBuffer.appendAscii(RTL_CONSTASCII_STRINGPARAM("([^/?#]")); + aBuffer.append(sal_Unicode(m_bEmptyDomain ? '*' : '+')); + if (m_aInfix.getLength() != 0) + appendStringLiteral(&aBuffer, m_aInfix); + aBuffer. + appendAscii(RTL_CONSTASCII_STRINGPARAM("([/?#].*)?)")); + break; + } + aBuffer.appendAscii(RTL_CONSTASCII_STRINGPARAM("->")); + if (bReverse) + { + if (m_aPrefix.getLength() != 0) + appendStringLiteral(&aBuffer, m_aPrefix); + } + else + { + if (m_aReversePrefix.getLength() != 0) + appendStringLiteral(&aBuffer, m_aReversePrefix); + } + aBuffer.appendAscii(RTL_CONSTASCII_STRINGPARAM("\\1")); + return aBuffer.makeStringAndClear(); + } + else if (m_eKind == KIND_PREFIX && isScheme(m_aPrefix)) + return m_aPrefix; + else + { + rtl::OUStringBuffer aBuffer; + if (m_aPrefix.getLength() != 0) + appendStringLiteral(&aBuffer, m_aPrefix); + switch (m_eKind) + { + case KIND_PREFIX: + aBuffer.appendAscii(RTL_CONSTASCII_STRINGPARAM(".*")); + break; + + case KIND_AUTHORITY: + aBuffer.appendAscii(RTL_CONSTASCII_STRINGPARAM("([/?#].*)?")); + break; + + case KIND_DOMAIN: + aBuffer.appendAscii(RTL_CONSTASCII_STRINGPARAM("[^/?#]")); + aBuffer.append(sal_Unicode(m_bEmptyDomain ? '*' : '+')); + if (m_aInfix.getLength() != 0) + appendStringLiteral(&aBuffer, m_aInfix); + aBuffer.appendAscii(RTL_CONSTASCII_STRINGPARAM("([/?#].*)?")); + break; + } + return aBuffer.makeStringAndClear(); + } +} + +//============================================================================ +namespace unnamed_ucb_regexp { + +bool matchString(sal_Unicode const ** pBegin, sal_Unicode const * pEnd, + sal_Char const * pString, size_t nStringLength) +{ + sal_Unicode const * p = *pBegin; + + sal_uChar const * q = reinterpret_cast< sal_uChar const * >(pString); + sal_uChar const * qEnd = q + nStringLength; + + if (pEnd - p < qEnd - q) + return false; + + while (q != qEnd) + { + sal_Unicode c1 = *p++; + sal_Unicode c2 = *q++; + if (c1 != c2) + return false; + } + + *pBegin = p; + return true; +} + +bool scanStringLiteral(sal_Unicode const ** pBegin, sal_Unicode const * pEnd, + rtl::OUString * pString) +{ + sal_Unicode const * p = *pBegin; + + if (p == pEnd || *p++ != '"') + return false; + + rtl::OUStringBuffer aBuffer; + for (;;) + { + if (p == pEnd) + return false; + sal_Unicode c = *p++; + if (c == '"') + break; + if (c == '\\') + { + if (p == pEnd) + return false; + c = *p++; + if (c != '"' && c != '\\') + return false; + } + aBuffer.append(c); + } + + *pBegin = p; + *pString = aBuffer.makeStringAndClear(); + return true; +} + +} + +Regexp Regexp::parse(rtl::OUString const & rRegexp) +{ + // Detect an input of '<scheme>' as an abbreviation of '"<scheme>".*' + // where <scheme> is as defined in RFC 2396: + if (isScheme(rRegexp)) + return Regexp(Regexp::KIND_PREFIX, rRegexp, false, rtl::OUString(), + false, rtl::OUString()); + + sal_Unicode const * p = rRegexp.getStr(); + sal_Unicode const * pEnd = p + rRegexp.getLength(); + + rtl::OUString aPrefix; + scanStringLiteral(&p, pEnd, &aPrefix); + + if (p == pEnd) + throw lang::IllegalArgumentException(); + + if (matchString(&p, pEnd, RTL_CONSTASCII_STRINGPARAM(".*"))) + { + if (p != pEnd) + throw lang::IllegalArgumentException(); + + return Regexp(Regexp::KIND_PREFIX, aPrefix, false, rtl::OUString(), + false, rtl::OUString()); + } + else if (matchString(&p, pEnd, RTL_CONSTASCII_STRINGPARAM("(.*)->"))) + { + rtl::OUString aReversePrefix; + scanStringLiteral(&p, pEnd, &aReversePrefix); + + if (!matchString(&p, pEnd, RTL_CONSTASCII_STRINGPARAM("\\1")) + || p != pEnd) + throw lang::IllegalArgumentException(); + + return Regexp(Regexp::KIND_PREFIX, aPrefix, false, rtl::OUString(), + true, aReversePrefix); + } + else if (matchString(&p, pEnd, RTL_CONSTASCII_STRINGPARAM("([/?#].*)?"))) + { + if (p != pEnd) + throw lang::IllegalArgumentException(); + + return Regexp(Regexp::KIND_AUTHORITY, aPrefix, false, rtl::OUString(), + false, rtl::OUString()); + } + else if (matchString(&p, pEnd, + RTL_CONSTASCII_STRINGPARAM("(([/?#].*)?)->"))) + { + rtl::OUString aReversePrefix; + if (!(scanStringLiteral(&p, pEnd, &aReversePrefix) + && matchString(&p, pEnd, RTL_CONSTASCII_STRINGPARAM("\\1")) + && p == pEnd)) + throw lang::IllegalArgumentException(); + + return Regexp(Regexp::KIND_AUTHORITY, aPrefix, false, rtl::OUString(), + true, aReversePrefix); + } + else + { + bool bOpen = false; + if (p != pEnd && *p == '(') + { + ++p; + bOpen = true; + } + + if (!matchString(&p, pEnd, RTL_CONSTASCII_STRINGPARAM("[^/?#]"))) + throw lang::IllegalArgumentException(); + + if (p == pEnd || *p != '*' && *p != '+') + throw lang::IllegalArgumentException(); + bool bEmptyDomain = *p++ == '*'; + + rtl::OUString aInfix; + scanStringLiteral(&p, pEnd, &aInfix); + + if (!matchString(&p, pEnd, RTL_CONSTASCII_STRINGPARAM("([/?#].*)?"))) + throw lang::IllegalArgumentException(); + + rtl::OUString aReversePrefix; + if (bOpen + && !(matchString(&p, pEnd, RTL_CONSTASCII_STRINGPARAM(")->")) + && scanStringLiteral(&p, pEnd, &aReversePrefix) + && matchString(&p, pEnd, RTL_CONSTASCII_STRINGPARAM("\\1")))) + throw lang::IllegalArgumentException(); + + if (p != pEnd) + throw lang::IllegalArgumentException(); + + return Regexp(Regexp::KIND_DOMAIN, aPrefix, bEmptyDomain, aInfix, + bOpen, aReversePrefix); + } + + throw lang::IllegalArgumentException(); +} + diff --git a/ucb/source/sorter/makefile.mk b/ucb/source/sorter/makefile.mk new file mode 100644 index 000000000000..93601205bb8f --- /dev/null +++ b/ucb/source/sorter/makefile.mk @@ -0,0 +1,135 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1 $ +# +# last change: $Author: kso $ $Date: 2000-10-16 14:53:23 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (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.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=..$/.. +PRJNAME=ucb +TARGET=srtrs +ENABLE_EXCEPTIONS=TRUE +NO_BSYMBOLIC=TRUE + +# Version +UCB_MAJOR=1 + +.INCLUDE: svpre.mk +.INCLUDE: settings.mk +.INCLUDE: sv.mk + +#INCPRE+=$(PRJ)$/source$/inc + +SLOFILES=\ + $(SLO)$/sortdynres.obj \ + $(SLO)$/sortresult.obj \ + $(SLO)$/sortmain.obj + +# NETBSD: somewhere we have to instantiate the static data members. +# NETBSD-1.2.1 doesn't know about weak symbols so the default mechanism for GCC won't work. +# SCO and MACOSX: the linker does know about weak symbols, but we can't ignore multiple defined symbols +.IF "$(OS)"=="NETBSD" || "$(OS)"=="SCO" || "$(OS)$(COM)"=="OS2GCC" || "$(OS)"=="MACOSX" +SLOFILES+=$(SLO)$/staticmbsorter.obj +.ENDIF + +LIB1TARGET=$(SLB)$/_$(TARGET).lib +LIB1OBJFILES=$(SLOFILES) + +SHL1TARGET=$(TARGET)$(UCB_MAJOR) +SHL1DEF=$(MISC)$/$(SHL1TARGET).def +SHL1STDLIBS=\ + $(CPPUHELPERLIB) \ + $(CPPULIB) \ + $(SALLIB) \ + $(TOOLSLIB) \ + $(VOSLIB) + +#SHL1STDLIBS=\ +# $(CPPUHELPERLIB) \ +# $(CPPULIB) \ +# $(SALLIB) \ +# $(STORELIB) + + + +SHL1LIBS=$(LIB1TARGET) +SHL1IMPLIB=i$(TARGET) + +DEF1DEPN=$(MISC)$/$(SHL1TARGET).flt +DEF1NAME=$(SHL1TARGET) +DEF1EXPORT1 =component_getImplementationEnvironment +DEF1EXPORT2 =component_writeInfo +DEF1EXPORT3 =component_getFactory +DEF1DES=UCB : Sorted Dynamic ResultSet + +.INCLUDE: target.mk + +$(MISC)$/$(SHL1TARGET).flt: + @echo ------------------------------ + @echo Making: $@ +# @echo Type >> $@ + @echo cpp >> $@ + @echo m_ >> $@ + @echo rtl >> $@ + @echo vos >> $@ + @echo component_getImplementationEnvironment >> $@ + @echo component_writeInfo >> $@ + @echo component_getFactory >> $@ +.IF "$(COM)"=="MSC" + @echo ??_ >> $@ +.ENDIF # COM MSC diff --git a/ucb/source/sorter/sortdynres.cxx b/ucb/source/sorter/sortdynres.cxx new file mode 100644 index 000000000000..2a34473294a8 --- /dev/null +++ b/ucb/source/sorter/sortdynres.cxx @@ -0,0 +1,665 @@ +/************************************************************************* + * + * $RCSfile: sortdynres.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:53:23 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include <sortdynres.hxx> + +#ifndef _CPPUHELPER_INTERFACECONTAINER_HXX_ +#include <cppuhelper/interfacecontainer.hxx> +#endif + +#ifndef _COM_SUN_STAR_UCB_CONTENTRESULTSETCAPABILITY_HPP_ +#include <com/sun/star/ucb/ContentResultSetCapability.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_LISTACTIONTYPE_HPP_ +#include <com/sun/star/ucb/ListActionType.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_WELCOMEDYNAMICRESULTSETSTRUCT_HPP_ +#include <com/sun/star/ucb/WelcomeDynamicResultSetStruct.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCACHEDDYNAMICRESULTSETSTUBFACTORY_HPP_ +#include <com/sun/star/ucb/XCachedDynamicResultSetStubFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XSOURCEINITIALIZATION_HPP_ +#include <com/sun/star/ucb/XSourceInitialization.hpp> +#endif + +//----------------------------------------------------------------------------- +using namespace com::sun::star::beans; +using namespace com::sun::star::lang; +using namespace com::sun::star::sdbc; +using namespace com::sun::star::ucb; +using namespace com::sun::star::uno; +using namespace cppu; +using namespace rtl; + +//========================================================================= + +// The mutex to synchronize access to containers. +static osl::Mutex& getContainerMutex() +{ + static osl::Mutex* pMutex = NULL; + if( !pMutex ) + { + osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() ); + if( !pMutex ) + { + static osl::Mutex aMutex; + pMutex = &aMutex; + } + } + + return *pMutex; +} + +//========================================================================= +// +// SortedDynamicResultSet +// +//========================================================================= + +SortedDynamicResultSet::SortedDynamicResultSet( + const Reference < XDynamicResultSet > &xOriginal, + const Sequence < NumberedSortingInfo > &aOptions, + const Reference < XAnyCompareFactory > &xCompFac, + const Reference < XMultiServiceFactory > &xSMgr ) +{ + mpDisposeEventListeners = NULL; + mpOwnListener = new SortedDynamicResultSetListener( this ); + + mxOwnListener = Reference< XDynamicResultSetListener >( mpOwnListener ); + + mxOriginal = xOriginal; + maOptions = aOptions; + mxCompFac = xCompFac; + mxSMgr = xSMgr; + + mpOne = NULL; + mpTwo = NULL; + + mbGotWelcome = FALSE; + mbUseOne = TRUE; + mbStatic = FALSE; +} + +//-------------------------------------------------------------------------- +SortedDynamicResultSet::~SortedDynamicResultSet() +{ + mpOwnListener->impl_OwnerDies(); + mxOwnListener.clear(); + + delete mpDisposeEventListeners; + + mxOne.clear(); + mxTwo.clear(); + mxOriginal.clear(); + + mpOne = NULL; + mpTwo = NULL; +} + +//-------------------------------------------------------------------------- +// XInterface methods. +//-------------------------------------------------------------------------- + +XINTERFACE_IMPL_4( SortedDynamicResultSet, + XTypeProvider, + XServiceInfo, + XComponent, /* base class of XDynamicResultSet */ + XDynamicResultSet ); + +//-------------------------------------------------------------------------- +// XTypeProvider methods. +//-------------------------------------------------------------------------- + +XTYPEPROVIDER_IMPL_3( SortedDynamicResultSet, + XTypeProvider, + XServiceInfo, + XDynamicResultSet ); + +//-------------------------------------------------------------------------- +// XServiceInfo methods. +//-------------------------------------------------------------------------- + +XSERVICEINFO_NOFACTORY_IMPL_1( SortedDynamicResultSet, + OUString::createFromAscii( "SortedDynamicResultSet" ), + OUString::createFromAscii( DYNAMIC_RESULTSET_SERVICE_NAME ) ); + + +//-------------------------------------------------------------------------- +// XComponent methods. +//-------------------------------------------------------------------------- +void SAL_CALL SortedDynamicResultSet::dispose() + throw( RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + + if ( mpDisposeEventListeners && mpDisposeEventListeners->getLength() ) + { + EventObject aEvt; + aEvt.Source = static_cast< XComponent * >( this ); + mpDisposeEventListeners->disposeAndClear( aEvt ); + } + + mxOne.clear(); + mxTwo.clear(); + mxOriginal.clear(); + + mpOne = NULL; + mpTwo = NULL; + mbUseOne = TRUE; +} + +//-------------------------------------------------------------------------- +void SAL_CALL SortedDynamicResultSet::addEventListener( + const Reference< XEventListener >& Listener ) + throw( RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + + if ( !mpDisposeEventListeners ) + mpDisposeEventListeners = + new OInterfaceContainerHelper( getContainerMutex() ); + + mpDisposeEventListeners->addInterface( Listener ); +} + +//-------------------------------------------------------------------------- +void SAL_CALL SortedDynamicResultSet::removeEventListener( + const Reference< XEventListener >& Listener ) + throw( RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + + if ( mpDisposeEventListeners ) + mpDisposeEventListeners->removeInterface( Listener ); +} + +//-------------------------------------------------------------------------- +// XDynamicResultSet methods. +// ------------------------------------------------------------------------------ +Reference< XResultSet > SAL_CALL +SortedDynamicResultSet::getStaticResultSet() + throw( ListenerAlreadySetException, RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + + if ( mxListener.is() ) + throw ListenerAlreadySetException(); + + mbStatic = TRUE; + + if ( mxOriginal.is() ) + { + mpOne = new SortedResultSet( mxOriginal->getStaticResultSet() ); + mxOne = mpOne; + mpOne->Initialize( maOptions, mxCompFac ); + } + + return mxOne; +} + +// ------------------------------------------------------------------------------ +void SAL_CALL +SortedDynamicResultSet::setListener( const Reference< XDynamicResultSetListener >& Listener ) + throw( ListenerAlreadySetException, RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + + if ( mxListener.is() ) + throw ListenerAlreadySetException(); + + addEventListener( Reference< XEventListener >::query( Listener ) ); + + mxListener = Listener; + + if ( mxOriginal.is() ) + mxOriginal->setListener( mxOwnListener ); +} + +// ------------------------------------------------------------------------------ +void SAL_CALL +SortedDynamicResultSet::connectToCache( + const Reference< XDynamicResultSet > & xCache ) + throw( ListenerAlreadySetException, + AlreadyInitializedException, + ServiceNotFoundException, + RuntimeException ) +{ + if( mxListener.is() ) + throw ListenerAlreadySetException(); + + if( mbStatic ) + throw ListenerAlreadySetException(); + + Reference< XSourceInitialization > xTarget( xCache, UNO_QUERY ); + if( xTarget.is() && mxSMgr.is() ) + { + Reference< XCachedDynamicResultSetStubFactory > xStubFactory( + mxSMgr->createInstance( OUString::createFromAscii( + "com.sun.star.ucb.CachedDynamicResultSetStubFactory" ) ), UNO_QUERY ); + if( xStubFactory.is() ) + { + xStubFactory->connectToCache( + this, xCache, Sequence< NumberedSortingInfo > (), NULL ); + return; + } + } + throw ServiceNotFoundException(); +} + +// ------------------------------------------------------------------------------ +sal_Int16 SAL_CALL +SortedDynamicResultSet::getCapabilities() + throw( RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + + sal_Int16 nCaps = 0; + + if ( mxOriginal.is() ) + nCaps = mxOriginal->getCapabilities(); + + nCaps |= ContentResultSetCapability::SORTED; + + return nCaps; +} + +//-------------------------------------------------------------------------- +// XDynamicResultSetListener methods. +// ------------------------------------------------------------------------------ + +/** In the first notify-call the listener gets the two + <type>XResultSet</type>s and has to hold them. The <type>XResultSet</type>s + are implementations of the service <type>ContentResultSet</type>. + + <p>The notified new <type>XResultSet</type> will stay valid after returning + notification. The old one will become invalid after returning notification. + + <p>While in notify-call the listener is allowed to read old and new version, + except in the first call, where only the new Resultset is valid. + + <p>The Listener is allowed to blockade this call, until he really want to go + to the new version. The only situation, where the listener has to return the + update call at once is, while he disposes his broadcaster or while he is + removing himsef as listener (otherwise you deadlock)!!! +*/ +void SAL_CALL +SortedDynamicResultSet::impl_notify( const ListEvent& Changes ) + throw( RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + + BOOL bHasNew = FALSE; + BOOL bHasModified = FALSE; + + SortedResultSet *pCurSet = NULL; + + // mxNew und mxOld vertauschen und anschliessend die Tabellen von Old + // nach New kopieren + if ( mbGotWelcome ) + { + if ( mbUseOne ) + { + mbUseOne = FALSE; + mpTwo->CopyData( mpOne ); + pCurSet = mpTwo; + } + else + { + mbUseOne = TRUE; + mpOne->CopyData( mpTwo ); + pCurSet = mpOne; + } + } + + long nOldCount = pCurSet->GetCount(); + Any aRet = pCurSet->getPropertyValue( OUString::createFromAscii( "IsRowCountFinal" ) ); + BOOL bWasFinal; + + aRet >>= bWasFinal; + + // handle the actions in the list + for ( long i=0; i<Changes.Changes.getLength(); i++ ) + { + const ListAction aAction = Changes.Changes[i]; + switch ( aAction.ListActionType ) + { + case ListActionType::WELCOME: + { + WelcomeDynamicResultSetStruct aWelcome; + if ( aAction.ActionInfo >>= aWelcome ) + { + mpTwo = new SortedResultSet( aWelcome.Old ); + mxTwo = mpTwo; + mpOne = new SortedResultSet( aWelcome.New ); + mxOne = mpOne; + mpOne->Initialize( maOptions, mxCompFac ); + mbGotWelcome = TRUE; + mbUseOne = TRUE; + pCurSet = mpOne; + + aWelcome.Old = mxTwo; + aWelcome.New = mxOne; + + ListAction *pWelcomeAction = new ListAction; + pWelcomeAction->ActionInfo <<= aWelcome; + pWelcomeAction->Position = 0; + pWelcomeAction->Count = 0; + pWelcomeAction->ListActionType = ListActionType::WELCOME; + + maActions.Insert( pWelcomeAction ); + } + else + { + // throw RuntimeException(); + } + break; + } + case ListActionType::INSERTED: + { + pCurSet->InsertNew( aAction.Position, aAction.Count ); + bHasNew = TRUE; + break; + } + case ListActionType::REMOVED: + { + pCurSet->Remove( aAction.Position, + aAction.Count, + &maActions ); + break; + } + case ListActionType::MOVED: + { + long nOffset; + if ( aAction.ActionInfo >>= nOffset ) + { + pCurSet->Move( aAction.Position, + aAction.Count, + nOffset ); + } + break; + } + case ListActionType::PROPERTIES_CHANGED: + { + pCurSet->SetChanged( aAction.Position, aAction.Count ); + bHasModified = TRUE; + break; + } + default: break; + } + } + + if ( bHasModified ) + pCurSet->ResortModified( &maActions ); + + if ( bHasNew ) + pCurSet->ResortNew( &maActions ); + + // send the new actions with a notify to the listeners + SendNotify(); + + // check for propertyChangeEvents + pCurSet->CheckProperties( nOldCount, bWasFinal ); +} + +//----------------------------------------------------------------- +// XEventListener +//----------------------------------------------------------------- +void SAL_CALL +SortedDynamicResultSet::impl_disposing( const EventObject& Source ) + throw( RuntimeException ) +{ + mxListener.clear(); + mxOriginal.clear(); +} + +// ------------------------------------------------------------------------------ +// private methods +// ------------------------------------------------------------------------------ +void SortedDynamicResultSet::SendNotify() +{ + long nCount = maActions.Count(); + + if ( nCount && mxListener.is() ) + { + Sequence< ListAction > aActionList( maActions.Count() ); + ListAction *pActionList = aActionList.getArray(); + + for ( long i=0; i<nCount; i++ ) + { + pActionList[ i ] = *(maActions.GetAction( i )); + } + + ListEvent aNewEvent; + aNewEvent.Changes = aActionList; + + mxListener->notify( aNewEvent ); + } + + // clean up + maActions.Clear(); +} + +//========================================================================= +// +// SortedDynamicResultSetFactory +// +//========================================================================= +SortedDynamicResultSetFactory::SortedDynamicResultSetFactory( + const Reference< XMultiServiceFactory > & rSMgr ) +{ + mxSMgr = rSMgr; +} + +//-------------------------------------------------------------------------- +SortedDynamicResultSetFactory::~SortedDynamicResultSetFactory() +{ +} + +//-------------------------------------------------------------------------- +// XInterface methods. +//-------------------------------------------------------------------------- + +XINTERFACE_IMPL_3( SortedDynamicResultSetFactory, + XTypeProvider, + XServiceInfo, + XSortedDynamicResultSetFactory ); + +//-------------------------------------------------------------------------- +// XTypeProvider methods. +//-------------------------------------------------------------------------- + +XTYPEPROVIDER_IMPL_3( SortedDynamicResultSetFactory, + XTypeProvider, + XServiceInfo, + XSortedDynamicResultSetFactory ); + +//-------------------------------------------------------------------------- +// XServiceInfo methods. +//-------------------------------------------------------------------------- + +XSERVICEINFO_IMPL_1( SortedDynamicResultSetFactory, + OUString::createFromAscii( "SortedDynamicResultSetFactory" ), + OUString::createFromAscii( DYNAMIC_RESULTSET_FACTORY_NAME ) ); + + +//-------------------------------------------------------------------------- +// Service factory implementation. +//-------------------------------------------------------------------------- + +ONE_INSTANCE_SERVICE_FACTORY_IMPL( SortedDynamicResultSetFactory ); + +//-------------------------------------------------------------------------- +// SortedDynamicResultSetFactory methods. +//-------------------------------------------------------------------------- +Reference< XDynamicResultSet > SAL_CALL +SortedDynamicResultSetFactory::createSortedDynamicResultSet( + const Reference< XDynamicResultSet > & Source, + const Sequence< NumberedSortingInfo > & Info, + const Reference< XAnyCompareFactory > & CompareFactory ) + throw( RuntimeException ) +{ + Reference< XDynamicResultSet > xRet; + xRet = new SortedDynamicResultSet( Source, Info, CompareFactory, mxSMgr ); + return xRet; +} + +//========================================================================= +// +// EventList +// +//========================================================================= + +EventList::EventList() +{} + +//-------------------------------------------------------------------------- +EventList::~EventList() +{ + Clear(); +} + +//-------------------------------------------------------------------------- +void EventList::Clear() +{ + ListAction *pData = (ListAction*) List::First(); + + while ( pData ) + { + delete pData; + pData = (ListAction*) List::Next(); + } + + List::Clear(); +} + +//-------------------------------------------------------------------------- +void EventList::AddEvent( long nType, long nPos, long nCount ) +{ + ListAction *pAction = new ListAction; + pAction->Position = nPos; + pAction->Count = nCount; + pAction->ListActionType = nType; + + Insert( pAction ); +} + +//================================================================= +// +// SortedDynamicResultSetListener +// +//================================================================= + +SortedDynamicResultSetListener::SortedDynamicResultSetListener( + SortedDynamicResultSet *mOwner ) +{ + mpOwner = mOwner; +} + +//----------------------------------------------------------------- +SortedDynamicResultSetListener::~SortedDynamicResultSetListener() +{ +} + +//----------------------------------------------------------------- +// XInterface methods. +//----------------------------------------------------------------- + +XINTERFACE_IMPL_2( SortedDynamicResultSetListener, + XEventListener, /* base class of XDynamicResultSetListener */ + XDynamicResultSetListener ); + +//----------------------------------------------------------------- +// XEventListener ( base of XDynamicResultSetListener ) +//----------------------------------------------------------------- +void SAL_CALL +SortedDynamicResultSetListener::disposing( const EventObject& Source ) + throw( RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + + if ( mpOwner ) + mpOwner->impl_disposing( Source ); +} + +//----------------------------------------------------------------- +// XDynamicResultSetListener +//----------------------------------------------------------------- +void SAL_CALL +SortedDynamicResultSetListener::notify( const ListEvent& Changes ) + throw( RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + + if ( mpOwner ) + mpOwner->impl_notify( Changes ); +} + +//----------------------------------------------------------------- +// own methods: +//----------------------------------------------------------------- +void SAL_CALL +SortedDynamicResultSetListener::impl_OwnerDies() +{ + vos::OGuard aGuard( maMutex ); + mpOwner = NULL; +} + diff --git a/ucb/source/sorter/sortdynres.hxx b/ucb/source/sorter/sortdynres.hxx new file mode 100644 index 000000000000..abdb85fc5003 --- /dev/null +++ b/ucb/source/sorter/sortdynres.hxx @@ -0,0 +1,325 @@ +/************************************************************************* + * + * $RCSfile: sortdynres.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:53:23 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _SORTDYNRES_HXX +#define _SORTDYNRES_HXX + +#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XTYPEPROVIDER_HPP_ +#include <com/sun/star/lang/XTypeProvider.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_ +#include <com/sun/star/lang/XServiceInfo.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XCOMPONENT_HPP_ +#include <com/sun/star/lang/XComponent.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_NUMBEREDSORTINGINFO_HPP_ +#include <com/sun/star/ucb/NumberedSortingInfo.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XRESULTSET_HPP_ +#include <com/sun/star/sdbc/XResultSet.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XDYNAMICRESULTSET_HPP_ +#include <com/sun/star/ucb/XDynamicResultSet.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XDYNAMICRESULTSETLISTENER_HPP_ +#include <com/sun/star/ucb/XDynamicResultSetListener.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_LISTENERALREADYSETEXCEPTION_HPP_ +#include <com/sun/star/ucb/ListenerAlreadySetException.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XSORTEDDYNAMICRESULTSETFACTORY_HPP_ +#include <com/sun/star/ucb/XSortedDynamicResultSetFactory.hpp> +#endif + +#ifndef _CPPUHELPER_WEAK_HXX_ +#include <cppuhelper/weak.hxx> +#endif + +#ifndef _VOS_MUTEX_HXX_ +#include <vos/mutex.hxx> +#endif + +#include <tools/list.hxx> + +#ifndef _UCBHELPER_MACROS_HXX +#include <ucbhelper/macros.hxx> +#endif + +#ifndef _SORTRESULT_HXX +#include "sortresult.hxx" +#endif + +namespace cppu { + class OInterfaceContainerHelper; +} + +//----------------------------------------------------------------------------- + +#define NUMBERED_SORTINGINFO com::sun::star::ucb::NumberedSortingInfo +#define RUNTIMEEXCEPTION com::sun::star::uno::RuntimeException +#define REFERENCE com::sun::star::uno::Reference +#define SEQUENCE com::sun::star::uno::Sequence +#define EVENTOBJECT com::sun::star::lang::EventObject +#define XEVENTLISTENER com::sun::star::lang::XEventListener +#define XMULTISERVICEFACTORY com::sun::star::lang::XMultiServiceFactory +#define XRESULTSET com::sun::star::sdbc::XResultSet +#define SQLEXCEPTION com::sun::star::sdbc::SQLException +#define XANYCOMPAREFACTORY com::sun::star::ucb::XAnyCompareFactory +#define XDYNAMICRESULTSET com::sun::star::ucb::XDynamicResultSet +#define XDYNAMICRESULTSETLISTENER com::sun::star::ucb::XDynamicResultSetListener +#define LISTENERALREADYSETEXCEPTION com::sun::star::ucb::ListenerAlreadySetException + +#define DYNAMIC_RESULTSET_SERVICE_NAME "com.sun.star.ucb.SortedDynamicResultSet" +#define DYNAMIC_RESULTSET_FACTORY_NAME "com.sun.star.ucb.SortedDynamicResultSetFactory" + +//----------------------------------------------------------------------------- +class SortedDynamicResultSetListener; + +class SortedDynamicResultSet: + public cppu::OWeakObject, + public com::sun::star::lang::XTypeProvider, + public com::sun::star::lang::XServiceInfo, + public com::sun::star::ucb::XDynamicResultSet +{ + cppu::OInterfaceContainerHelper *mpDisposeEventListeners; + + REFERENCE < XDYNAMICRESULTSETLISTENER > mxListener; + REFERENCE < XDYNAMICRESULTSETLISTENER > mxOwnListener; + + REFERENCE < XRESULTSET > mxOne; + REFERENCE < XRESULTSET > mxTwo; + REFERENCE < XDYNAMICRESULTSET > mxOriginal; + SEQUENCE < NUMBERED_SORTINGINFO > maOptions; + REFERENCE < XANYCOMPAREFACTORY > mxCompFac; + REFERENCE < XMULTISERVICEFACTORY > mxSMgr; + + SortedResultSet* mpOne; + SortedResultSet* mpTwo; + SortedDynamicResultSetListener* mpOwnListener; + + EventList maActions; + ::vos::OMutex maMutex; + BOOL mbGotWelcome :1; + BOOL mbUseOne :1; + BOOL mbStatic :1; + +private: + + void SendNotify(); + +public: + SortedDynamicResultSet( const REFERENCE < XDYNAMICRESULTSET > &xOriginal, + const SEQUENCE < NUMBERED_SORTINGINFO > &aOptions, + const REFERENCE < XANYCOMPAREFACTORY > &xCompFac, + const REFERENCE < XMULTISERVICEFACTORY > &xSMgr ); + + ~SortedDynamicResultSet(); + + //----------------------------------------------------------------- + // XInterface + //----------------------------------------------------------------- + XINTERFACE_DECL() + + //----------------------------------------------------------------- + // XTypeProvider + //----------------------------------------------------------------- + XTYPEPROVIDER_DECL() + + //----------------------------------------------------------------- + // XServiceInfo + //----------------------------------------------------------------- + XSERVICEINFO_NOFACTORY_DECL() + + //----------------------------------------------------------------- + // XComponent + //----------------------------------------------------------------- + virtual void SAL_CALL + dispose() throw( RUNTIME_EXCEPTION ); + + virtual void SAL_CALL + addEventListener( const REFERENCE< XEVENTLISTENER >& Listener ) + throw( RUNTIME_EXCEPTION ); + + virtual void SAL_CALL + removeEventListener( const REFERENCE< XEVENTLISTENER >& Listener ) + throw( RUNTIME_EXCEPTION ); + + //----------------------------------------------------------------- + // XDynamicResultSet + //----------------------------------------------------------------- + virtual REFERENCE< XRESULTSET > SAL_CALL + getStaticResultSet( ) + throw( LISTENERALREADYSETEXCEPTION, RUNTIMEEXCEPTION ); + + virtual void SAL_CALL + setListener( const REFERENCE< XDYNAMICRESULTSETLISTENER >& Listener ) + throw( LISTENERALREADYSETEXCEPTION, RUNTIMEEXCEPTION ); + + virtual void SAL_CALL + connectToCache( const REFERENCE< XDYNAMICRESULTSET > & xCache ) + throw( LISTENERALREADYSETEXCEPTION, + com::sun::star::ucb::AlreadyInitializedException, + com::sun::star::ucb::ServiceNotFoundException, + RUNTIMEEXCEPTION ); + + virtual sal_Int16 SAL_CALL + getCapabilities() + throw( RUNTIMEEXCEPTION ); + + //----------------------------------------------------------------- + // own methods: + //----------------------------------------------------------------- + virtual void SAL_CALL + impl_disposing( const EVENTOBJECT& Source ) + throw( RUNTIMEEXCEPTION ); + + virtual void SAL_CALL + impl_notify( const ::com::sun::star::ucb::ListEvent& Changes ) + throw( RUNTIMEEXCEPTION ); +}; + +//----------------------------------------------------------------------------- + +class SortedDynamicResultSetListener: + public cppu::OWeakObject, + public com::sun::star::ucb::XDynamicResultSetListener +{ + SortedDynamicResultSet *mpOwner; + ::vos::OMutex maMutex; + +public: + SortedDynamicResultSetListener( SortedDynamicResultSet *mOwner ); + ~SortedDynamicResultSetListener(); + + //----------------------------------------------------------------- + // XInterface + //----------------------------------------------------------------- + XINTERFACE_DECL() + + //----------------------------------------------------------------- + // XEventListener ( base of XDynamicResultSetListener ) + //----------------------------------------------------------------- + virtual void SAL_CALL + disposing( const EVENTOBJECT& Source ) + throw( RUNTIMEEXCEPTION ); + + //----------------------------------------------------------------- + // XDynamicResultSetListener + //----------------------------------------------------------------- + virtual void SAL_CALL + notify( const ::com::sun::star::ucb::ListEvent& Changes ) + throw( RUNTIMEEXCEPTION ); + + //----------------------------------------------------------------- + // own methods: + //----------------------------------------------------------------- + void SAL_CALL impl_OwnerDies(); +}; + +//----------------------------------------------------------------------------- + +class SortedDynamicResultSetFactory: + public cppu::OWeakObject, + public com::sun::star::lang::XTypeProvider, + public com::sun::star::lang::XServiceInfo, + public com::sun::star::ucb::XSortedDynamicResultSetFactory +{ + + REFERENCE< XMULTISERVICEFACTORY > mxSMgr; + +public: + + SortedDynamicResultSetFactory( + const REFERENCE< XMULTISERVICEFACTORY > & rSMgr); + + ~SortedDynamicResultSetFactory(); + + //----------------------------------------------------------------- + // XInterface + //----------------------------------------------------------------- + XINTERFACE_DECL() + + //----------------------------------------------------------------- + // XTypeProvider + //----------------------------------------------------------------- + XTYPEPROVIDER_DECL() + + //----------------------------------------------------------------- + // XServiceInfo + //----------------------------------------------------------------- + XSERVICEINFO_DECL() + + //----------------------------------------------------------------- + // XSortedDynamicResultSetFactory + + virtual REFERENCE< XDYNAMICRESULTSET > SAL_CALL + createSortedDynamicResultSet( + const REFERENCE< XDYNAMICRESULTSET > & Source, + const SEQUENCE< NUMBERED_SORTINGINFO > & Info, + const REFERENCE< XANYCOMPAREFACTORY > & CompareFactory ) + throw( RUNTIMEEXCEPTION ); +}; + +#endif diff --git a/ucb/source/sorter/sortmain.cxx b/ucb/source/sorter/sortmain.cxx new file mode 100644 index 000000000000..1165ccbf8dc3 --- /dev/null +++ b/ucb/source/sorter/sortmain.cxx @@ -0,0 +1,172 @@ +/************************************************************************* + * + * $RCSfile: sortmain.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:53:23 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _SORTDYNRES_HXX +#include <sortdynres.hxx> +#endif + +#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XSINGLESERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XSingleServiceFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_REGISTRY_XREGISTRYKEY_HPP_ +#include <com/sun/star/registry/XRegistryKey.hpp> +#endif + +using namespace rtl; +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::registry; + +//========================================================================= +static sal_Bool writeInfo( void * pRegistryKey, + const OUString & rImplementationName, + Sequence< OUString > const & rServiceNames ) +{ + OUString aKeyName( OUString::createFromAscii( "/" ) ); + aKeyName += rImplementationName; + aKeyName += OUString::createFromAscii( "/UNO/SERVICES" ); + + Reference< XRegistryKey > xKey; + try + { + xKey = static_cast< XRegistryKey * >( + pRegistryKey )->createKey( aKeyName ); + } + catch ( InvalidRegistryException const & ) + { + } + + if ( !xKey.is() ) + return sal_False; + + sal_Bool bSuccess = sal_True; + + for ( sal_Int32 n = 0; n < rServiceNames.getLength(); ++n ) + { + try + { + xKey->createKey( rServiceNames[ n ] ); + } + catch ( InvalidRegistryException const & ) + { + bSuccess = sal_False; + break; + } + } + return bSuccess; +} + +//========================================================================= +extern "C" void SAL_CALL component_getImplementationEnvironment( + const sal_Char ** ppEnvTypeName, uno_Environment ** ppEnv ) +{ + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; +} + +//========================================================================= +extern "C" sal_Bool SAL_CALL component_writeInfo( + void * pServiceManager, void * pRegistryKey ) +{ + return pRegistryKey && + + ////////////////////////////////////////////////////////////////////// + // SortedDynamicResultSetFactory. + ////////////////////////////////////////////////////////////////////// + + writeInfo( pRegistryKey, + SortedDynamicResultSetFactory::getImplementationName_Static(), + SortedDynamicResultSetFactory::getSupportedServiceNames_Static() ); +} + +//========================================================================= +extern "C" void * SAL_CALL component_getFactory( + const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey ) +{ + void * pRet = 0; + + Reference< XMultiServiceFactory > xSMgr( + reinterpret_cast< XMultiServiceFactory * >( pServiceManager ) ); + Reference< XSingleServiceFactory > xFactory; + + ////////////////////////////////////////////////////////////////////// + // SortedDynamicResultSetFactory. + ////////////////////////////////////////////////////////////////////// + + if ( SortedDynamicResultSetFactory::getImplementationName_Static(). + compareToAscii( pImplName ) == 0 ) + { + xFactory = SortedDynamicResultSetFactory::createServiceFactory( xSMgr ); + } + + ////////////////////////////////////////////////////////////////////// + + if ( xFactory.is() ) + { + xFactory->acquire(); + pRet = xFactory.get(); + } + + return pRet; +} + diff --git a/ucb/source/sorter/sortresult.cxx b/ucb/source/sorter/sortresult.cxx new file mode 100644 index 000000000000..c65fea5e59ee --- /dev/null +++ b/ucb/source/sorter/sortresult.cxx @@ -0,0 +1,2027 @@ +/************************************************************************* + * + * $RCSfile: sortresult.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:53:23 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include <sortresult.hxx> + +#ifndef _CPPUHELPER_INTERFACECONTAINER_HXX_ +#include <cppuhelper/interfacecontainer.hxx> +#endif +#ifndef _COM_SUN_STAR_SDBC_DATATYPE_HPP_ +#include <com/sun/star/sdbc/DataType.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XRESULTSETMETADATA_HPP_ +#include <com/sun/star/sdbc/XResultSetMetaData.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XRESULTSETMETADATASUPPLIER_HPP_ +#include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_LISTACTIONTYPE_HPP_ +#include <com/sun/star/ucb/ListActionType.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XANYCOMPARE_HPP_ +#include <com/sun/star/ucb/XAnyCompare.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XANYCOMPAREFACTORY_HPP_ +#include <com/sun/star/ucb/XAnyCompareFactory.hpp> +#endif + +#include <tools/debug.hxx> + +#ifndef _STRING_HXX +#include <tools/string.hxx> +#endif + +//----------------------------------------------------------------------------- +using namespace com::sun::star::beans; +using namespace com::sun::star::container; +using namespace com::sun::star::io; +using namespace com::sun::star::lang; +using namespace com::sun::star::sdbc; +using namespace com::sun::star::ucb; +using namespace com::sun::star::uno; +using namespace com::sun::star::util; +using namespace cppu; +using namespace rtl; + +//========================================================================= + +// The mutex to synchronize access to containers. +static osl::Mutex& getContainerMutex() +{ + static osl::Mutex* pMutex = NULL; + if( !pMutex ) + { + osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() ); + if( !pMutex ) + { + static osl::Mutex aMutex; + pMutex = &aMutex; + } + } + + return *pMutex; +} + +//========================================================================== + +struct SortInfo +{ + BOOL mbUseOwnCompare; + BOOL mbAscending; + BOOL mbCaseSensitive; + sal_Int32 mnColumn; + sal_Int32 mnType; + SortInfo* mpNext; + Reference < XAnyCompare > mxCompareFunction; +}; + +//----------------------------------------------------------------------------- + +struct SortListData +{ + sal_Bool mbModified; + long mnCurPos; + long mnOldPos; + + SortListData( long nPos, sal_Bool bModified = sal_False ); +}; + +//============================================================================ +// +// class SRSPropertySetInfo. +// +//============================================================================ + +class SRSPropertySetInfo : + public OWeakObject, + public XTypeProvider, + public XPropertySetInfo +{ + Property maProps[2]; + +private: + +public: + SRSPropertySetInfo(); + virtual ~SRSPropertySetInfo(); + + // XInterface + XINTERFACE_DECL() + + // XTypeProvider + XTYPEPROVIDER_DECL() + + // XPropertySetInfo + virtual Sequence< Property > SAL_CALL getProperties() + throw( RuntimeException ); + virtual Property SAL_CALL getPropertyByName( const OUString& aName ) + throw( UnknownPropertyException, RuntimeException ); + virtual sal_Bool SAL_CALL hasPropertyByName( const OUString& Name ) + throw( RuntimeException ); +}; + +//========================================================================= +// +// PropertyChangeListenerContainer_Impl. +// +//========================================================================= + +struct equalStr_Impl +{ + bool operator()( const OUString& s1, const OUString& s2 ) const + { + return !!( s1 == s2 ); + } +}; + +struct hashStr_Impl +{ + size_t operator()( const OUString& rName ) const + { + return rName.hashCode(); + } +}; + +typedef OMultiTypeInterfaceContainerHelperVar +< + OUString, + hashStr_Impl, + equalStr_Impl +> PropertyChangeListenerContainer_Impl; + +//========================================================================= +// +// class PropertyChangeListeners_Impl +// +//========================================================================= + +class PropertyChangeListeners_Impl : public PropertyChangeListenerContainer_Impl +{ +public: + PropertyChangeListeners_Impl() + : PropertyChangeListenerContainer_Impl( getContainerMutex() ) {} +}; + +//========================================================================== +SortedResultSet::SortedResultSet( Reference< XResultSet > aResult ) +{ + mpDisposeEventListeners = NULL; + mpPropChangeListeners = NULL; + mpVetoChangeListeners = NULL; + mpPropSetInfo = NULL; + + mxOriginal = aResult; + mpSortInfo = NULL; + mnLastSort = 0; + mnCurEntry = 0; + mnCount = 0; + mbIsCopy = FALSE; +} + +//-------------------------------------------------------------------------- +SortedResultSet::~SortedResultSet() +{ + mxOriginal.clear(); + mxOther.clear(); + + if ( !mbIsCopy ) + { + SortInfo *pInfo = mpSortInfo; + while ( pInfo ) + { + mpSortInfo = pInfo->mpNext; + delete pInfo; + pInfo = mpSortInfo; + } + } + + mpSortInfo = NULL; + + if ( mpPropSetInfo ) + mpPropSetInfo->release(); + + delete mpPropChangeListeners; + delete mpVetoChangeListeners; +} + +//-------------------------------------------------------------------------- +// XInterface methods. +//-------------------------------------------------------------------------- + +XINTERFACE_IMPL_9( SortedResultSet, + XTypeProvider, + XServiceInfo, + XComponent, + XContentAccess, + XResultSet, + XRow, + XCloseable, + XResultSetMetaDataSupplier, + XPropertySet ); + +//-------------------------------------------------------------------------- +// XTypeProvider methods. +//-------------------------------------------------------------------------- + +XTYPEPROVIDER_IMPL_9( SortedResultSet, + XTypeProvider, + XServiceInfo, + XComponent, + XContentAccess, + XResultSet, + XRow, + XCloseable, + XResultSetMetaDataSupplier, + XPropertySet ); + +//-------------------------------------------------------------------------- +// XServiceInfo methods. +//-------------------------------------------------------------------------- + +XSERVICEINFO_NOFACTORY_IMPL_1( SortedResultSet, + OUString::createFromAscii( "SortedResultSet" ), + OUString::createFromAscii( RESULTSET_SERVICE_NAME ) ); + +//-------------------------------------------------------------------------- +// XComponent methods. +//-------------------------------------------------------------------------- +void SAL_CALL SortedResultSet::dispose() + throw( RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + + if ( mpDisposeEventListeners && mpDisposeEventListeners->getLength() ) + { + EventObject aEvt; + aEvt.Source = static_cast< XComponent * >( this ); + mpDisposeEventListeners->disposeAndClear( aEvt ); + } + + if ( mpPropChangeListeners ) + { + EventObject aEvt; + aEvt.Source = static_cast< XPropertySet * >( this ); + mpPropChangeListeners->disposeAndClear( aEvt ); + } + + if ( mpVetoChangeListeners ) + { + EventObject aEvt; + aEvt.Source = static_cast< XPropertySet * >( this ); + mpVetoChangeListeners->disposeAndClear( aEvt ); + } + + mxOriginal.clear(); + mxOther.clear(); +} + +//-------------------------------------------------------------------------- +void SAL_CALL SortedResultSet::addEventListener( + const Reference< XEventListener >& Listener ) + throw( RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + + if ( !mpDisposeEventListeners ) + mpDisposeEventListeners = + new OInterfaceContainerHelper( getContainerMutex() ); + + mpDisposeEventListeners->addInterface( Listener ); +} + +//-------------------------------------------------------------------------- +void SAL_CALL SortedResultSet::removeEventListener( + const Reference< XEventListener >& Listener ) + throw( RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + + if ( mpDisposeEventListeners ) + mpDisposeEventListeners->removeInterface( Listener ); +} + +//-------------------------------------------------------------------------- +// XContentAccess methods. +//-------------------------------------------------------------------------- + +OUString SAL_CALL +SortedResultSet::queryContentIdentfierString() + throw( RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + return Reference< XContentAccess >::query(mxOriginal)->queryContentIdentfierString(); +} + +//-------------------------------------------------------------------------- +Reference< XContentIdentifier > SAL_CALL +SortedResultSet::queryContentIdentifier() + throw( RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + return Reference< XContentAccess >::query(mxOriginal)->queryContentIdentifier(); +} + +//-------------------------------------------------------------------------- +Reference< XContent > SAL_CALL +SortedResultSet::queryContent() + throw( RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + return Reference< XContentAccess >::query(mxOriginal)->queryContent(); +} + + +//-------------------------------------------------------------------------- +// XResultSet methods. +//-------------------------------------------------------------------------- +sal_Bool SAL_CALL SortedResultSet::next() + throw ( SQLException, RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + + mnCurEntry++; + + if ( mnCurEntry > 0 ) + { + if ( mnCurEntry <= mnCount ) + { + sal_Int32 nIndex = maS2O[ mnCurEntry ]; + return mxOriginal->absolute( nIndex ); + } + else + { + mnCurEntry = mnCount + 1; + } + } + return FALSE; +} + +//------------------------------------------------------------------------- +sal_Bool SAL_CALL SortedResultSet::isBeforeFirst() + throw ( SQLException, RuntimeException ) +{ + if ( mnCurEntry ) + return sal_False; + else + return sal_True; +} + +//------------------------------------------------------------------------- +sal_Bool SAL_CALL SortedResultSet::isAfterLast() + throw ( SQLException, RuntimeException ) +{ + if ( mnCurEntry > mnCount ) + return sal_True; + else + return sal_False; +} + +//------------------------------------------------------------------------- +sal_Bool SAL_CALL SortedResultSet::isFirst() + throw ( SQLException, RuntimeException ) +{ + if ( mnCurEntry == 1 ) + return sal_True; + else + return sal_False; +} + +//------------------------------------------------------------------------- +sal_Bool SAL_CALL SortedResultSet::isLast() + throw ( SQLException, RuntimeException ) +{ + if ( mnCurEntry == mnCount ) + return sal_True; + else + return sal_False; +} + +//------------------------------------------------------------------------- +void SAL_CALL SortedResultSet::beforeFirst() + throw ( SQLException, RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + mnCurEntry = 0; + mxOriginal->beforeFirst(); +} + +//------------------------------------------------------------------------- +void SAL_CALL SortedResultSet::afterLast() + throw ( SQLException, RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + mnCurEntry = mnCount+1; + mxOriginal->afterLast(); +} + +//------------------------------------------------------------------------- +sal_Bool SAL_CALL SortedResultSet::first() + throw ( SQLException, RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + + if ( mnCount ) + { + mnCurEntry = 1; + sal_Int32 nIndex = maS2O[ mnCurEntry ]; + return mxOriginal->absolute( nIndex ); + } + else + { + mnCurEntry = 0; + return sal_False; + } +} + +//------------------------------------------------------------------------- +sal_Bool SAL_CALL SortedResultSet::last() + throw ( SQLException, RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + + if ( mnCount ) + { + mnCurEntry = mnCount; + sal_Int32 nIndex = maS2O[ mnCurEntry ]; + return mxOriginal->absolute( nIndex ); + } + else + { + mnCurEntry = 0; + return sal_False; + } +} + +//------------------------------------------------------------------------- +sal_Int32 SAL_CALL SortedResultSet::getRow() + throw ( SQLException, RuntimeException ) +{ + return mnCurEntry; +} + +//------------------------------------------------------------------------- +/** + moves the cursor to the given row number in the result set. + <p>If the row number is positive, the cursor moves to the given row + number with respect to the beginning of the result set. The first + row is row 1, the second is row 2, and so on. + <p>If the given row number is negative, the cursor moves to an + absolute row position with respect to the end of the result set. + For example, calling <code>moveToPosition(-1)</code> positions the + cursor on the last row, <code>moveToPosition(-2)</code> indicates the + next-to-last row, and so on. + <p>An attempt to position the cursor beyond the first/last row in the + result set leaves the cursor before/after the first/last row, + respectively. + <p>Note: Calling <code>moveToPosition(1)</code> is the same + as calling <code>moveToFirst()</code>. Calling + <code>moveToPosition(-1)</code> is the same as calling + <code>moveToLast()</code>. + @param row + is the number of rows to move. Could be negative. + @returns + <TRUE/> if the cursor is on a row; <FALSE/> otherwise + @throws SQLException + if a database access error occurs or if row is 0, or the result set + type is FORWARD_ONLY. + */ +sal_Bool SAL_CALL SortedResultSet::absolute( sal_Int32 row ) + throw ( SQLException, RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + + sal_Int32 nIndex; + + if ( row > 0 ) + { + if ( row <= mnCount ) + { + mnCurEntry = row; + nIndex = maS2O[ mnCurEntry ]; + return mxOriginal->absolute( nIndex ); + } + else + { + mnCurEntry = mnCount + 1; + return sal_False; + } + } + else if ( row == 0 ) + { + throw SQLException(); + } + else + { + if ( mnCount + row + 1 > 0 ) + { + mnCurEntry = mnCount + row + 1; + nIndex = maS2O[ mnCurEntry ]; + return mxOriginal->absolute( nIndex ); + } + else + { + mnCurEntry = 0; + return sal_False; + } + } +} + +//------------------------------------------------------------------------- +/** + moves the cursor a relative number of rows, either positive or negative. + <p> + Attempting to move beyond the first/last row in the result set positions + the cursor before/after the first/last row. Calling + <code>moveRelative(0)</code> is valid, but does not change the cursor + position. + <p>Note: Calling <code>moveRelative(1)</code> is different from calling + <code>moveNext()</code> because is makes sense to call + <code>moveNext()</code> when there is no current row, for example, + when the cursor is positioned before the first row or after the last + row of the result set. + @param rows + is the number of rows to move. Could be negative. + @returns + <TRUE/> if the cursor is on a valid row; <FALSE/> if it is off + the result set. + @throws SQLException + if a database access error occurs or if there is no + current row, or the result set type is FORWARD_ONLY. + */ +sal_Bool SAL_CALL SortedResultSet::relative( sal_Int32 rows ) + throw ( SQLException, RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + + if ( ( mnCurEntry <= 0 ) || ( mnCurEntry > mnCount ) ) + { + throw SQLException(); + } + + if ( rows == 0 ) + return sal_True; + + sal_Int32 nTmp = mnCurEntry + rows; + + if ( nTmp <= 0 ) + { + mnCurEntry = 0; + return sal_False; + } + else if ( nTmp > mnCount ) + { + mnCurEntry = mnCount + 1; + return sal_False; + } + else + { + mnCurEntry = nTmp; + nTmp = maS2O[ mnCurEntry ]; + return mxOriginal->absolute( nTmp ); + } +} + +//------------------------------------------------------------------------- +/** + moves the cursor to the previous row in the result set. + <p>Note: <code>previous()</code> is not the same as + <code>relative(-1)</code> because it makes sense to call + <code>previous()</code> when there is no current row. + @returns <TRUE/> if the cursor is on a valid row; <FALSE/> if it is off + the result set. + @throws SQLException + if a database access error occurs or the result set type + is FORWARD_ONLY. + */ +sal_Bool SAL_CALL SortedResultSet::previous() + throw ( SQLException, RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + + mnCurEntry -= 1; + + if ( mnCurEntry > 0 ) + { + if ( mnCurEntry <= mnCount ) + { + sal_Int32 nIndex = maS2O[ mnCurEntry ]; + return mxOriginal->absolute( nIndex ); + } + } + else + mnCurEntry = 0; + + return sal_False; +} + +//------------------------------------------------------------------------- +void SAL_CALL SortedResultSet::refreshRow() + throw ( SQLException, RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + + if ( ( mnCurEntry <= 0 ) || ( mnCurEntry > mnCount ) ) + { + throw SQLException(); + } + + mxOriginal->refreshRow(); +} + +//------------------------------------------------------------------------- +sal_Bool SAL_CALL SortedResultSet::rowUpdated() + throw ( SQLException, RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + + if ( ( mnCurEntry <= 0 ) || ( mnCurEntry > mnCount ) ) + { + throw SQLException(); + } + + return mxOriginal->rowUpdated(); +} + +//------------------------------------------------------------------------- +sal_Bool SAL_CALL SortedResultSet::rowInserted() + throw ( SQLException, RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + + if ( ( mnCurEntry <= 0 ) || ( mnCurEntry > mnCount ) ) + { + throw SQLException(); + } + + return mxOriginal->rowInserted(); +} + +//------------------------------------------------------------------------- +sal_Bool SAL_CALL SortedResultSet::rowDeleted() + throw ( SQLException, RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + + if ( ( mnCurEntry <= 0 ) || ( mnCurEntry > mnCount ) ) + { + throw SQLException(); + } + + return mxOriginal->rowDeleted(); +} + +//------------------------------------------------------------------------- +Reference< XInterface > SAL_CALL SortedResultSet::getStatement() + throw ( SQLException, RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + + if ( ( mnCurEntry <= 0 ) || ( mnCurEntry > mnCount ) ) + { + throw SQLException(); + } + + return mxOriginal->getStatement(); +} + +//-------------------------------------------------------------------------- +// XRow methods. +//-------------------------------------------------------------------------- + +sal_Bool SAL_CALL SortedResultSet::wasNull() + throw( SQLException, RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + return Reference< XRow >::query(mxOriginal)->wasNull(); +} + +//------------------------------------------------------------------------- +OUString SAL_CALL SortedResultSet::getString( sal_Int32 columnIndex ) + throw( SQLException, RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + return Reference< XRow >::query(mxOriginal)->getString( columnIndex ); +} + +//------------------------------------------------------------------------- +sal_Bool SAL_CALL SortedResultSet::getBoolean( sal_Int32 columnIndex ) + throw( SQLException, RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + return Reference< XRow >::query(mxOriginal)->getBoolean( columnIndex ); +} + +//------------------------------------------------------------------------- +sal_Int8 SAL_CALL SortedResultSet::getByte( sal_Int32 columnIndex ) + throw( SQLException, RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + return Reference< XRow >::query(mxOriginal)->getByte( columnIndex ); +} + +//------------------------------------------------------------------------- +sal_Int16 SAL_CALL SortedResultSet::getShort( sal_Int32 columnIndex ) + throw( SQLException, RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + return Reference< XRow >::query(mxOriginal)->getShort( columnIndex ); +} + +//------------------------------------------------------------------------- +sal_Int32 SAL_CALL SortedResultSet::getInt( sal_Int32 columnIndex ) + throw( SQLException, RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + return Reference< XRow >::query(mxOriginal)->getInt( columnIndex ); +} +//------------------------------------------------------------------------- +sal_Int64 SAL_CALL SortedResultSet::getLong( sal_Int32 columnIndex ) + throw( SQLException, RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + return Reference< XRow >::query(mxOriginal)->getLong( columnIndex ); +} + +//------------------------------------------------------------------------- +float SAL_CALL SortedResultSet::getFloat( sal_Int32 columnIndex ) + throw( SQLException, RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + return Reference< XRow >::query(mxOriginal)->getFloat( columnIndex ); +} + +//------------------------------------------------------------------------- +double SAL_CALL SortedResultSet::getDouble( sal_Int32 columnIndex ) + throw( SQLException, RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + return Reference< XRow >::query(mxOriginal)->getDouble( columnIndex ); +} + +//------------------------------------------------------------------------- +Sequence< sal_Int8 > SAL_CALL SortedResultSet::getBytes( sal_Int32 columnIndex ) + throw( SQLException, RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + return Reference< XRow >::query(mxOriginal)->getBytes( columnIndex ); +} + +//------------------------------------------------------------------------- +Date SAL_CALL SortedResultSet::getDate( sal_Int32 columnIndex ) + throw( SQLException, RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + return Reference< XRow >::query(mxOriginal)->getDate( columnIndex ); +} + +//------------------------------------------------------------------------- +Time SAL_CALL SortedResultSet::getTime( sal_Int32 columnIndex ) + throw( SQLException, RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + return Reference< XRow >::query(mxOriginal)->getTime( columnIndex ); +} + +//------------------------------------------------------------------------- +DateTime SAL_CALL SortedResultSet::getTimestamp( sal_Int32 columnIndex ) + throw( SQLException, RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + return Reference< XRow >::query(mxOriginal)->getTimestamp( columnIndex ); +} + +//------------------------------------------------------------------------- +Reference< XInputStream > SAL_CALL +SortedResultSet::getBinaryStream( sal_Int32 columnIndex ) + throw( SQLException, RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + return Reference< XRow >::query(mxOriginal)->getBinaryStream( columnIndex ); +} + +//------------------------------------------------------------------------- +Reference< XInputStream > SAL_CALL +SortedResultSet::getCharacterStream( sal_Int32 columnIndex ) + throw( SQLException, RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + return Reference< XRow >::query(mxOriginal)->getCharacterStream( columnIndex ); +} + +//------------------------------------------------------------------------- +Any SAL_CALL SortedResultSet::getObject( sal_Int32 columnIndex, + const Reference< XNameAccess >& typeMap ) + throw( SQLException, RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + return Reference< XRow >::query(mxOriginal)->getObject( columnIndex, + typeMap); +} + +//------------------------------------------------------------------------- +Reference< XRef > SAL_CALL SortedResultSet::getRef( sal_Int32 columnIndex ) + throw( SQLException, RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + return Reference< XRow >::query(mxOriginal)->getRef( columnIndex ); +} + +//------------------------------------------------------------------------- +Reference< XBlob > SAL_CALL SortedResultSet::getBlob( sal_Int32 columnIndex ) + throw( SQLException, RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + return Reference< XRow >::query(mxOriginal)->getBlob( columnIndex ); +} + +//------------------------------------------------------------------------- +Reference< XClob > SAL_CALL SortedResultSet::getClob( sal_Int32 columnIndex ) + throw( SQLException, RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + return Reference< XRow >::query(mxOriginal)->getClob( columnIndex ); +} + +//------------------------------------------------------------------------- +Reference< XArray > SAL_CALL SortedResultSet::getArray( sal_Int32 columnIndex ) + throw( SQLException, RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + return Reference< XRow >::query(mxOriginal)->getArray( columnIndex ); +} + + +//-------------------------------------------------------------------------- +// XCloseable methods. +//-------------------------------------------------------------------------- + +void SAL_CALL SortedResultSet::close() + throw( SQLException, RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + Reference< XCloseable >::query(mxOriginal)->close(); +} + +//-------------------------------------------------------------------------- +// XResultSetMetaDataSupplier methods. +//-------------------------------------------------------------------------- + +Reference< XResultSetMetaData > SAL_CALL SortedResultSet::getMetaData() + throw( SQLException, RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + return Reference< XResultSetMetaDataSupplier >::query(mxOriginal)->getMetaData(); +} + + +//-------------------------------------------------------------------------- +// XPropertySet methods. +//-------------------------------------------------------------------------- + +Reference< XPropertySetInfo > SAL_CALL +SortedResultSet::getPropertySetInfo() throw( RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + + if ( !mpPropSetInfo ) + { + mpPropSetInfo = new SRSPropertySetInfo(); + mpPropSetInfo->acquire(); + } + + return Reference< XPropertySetInfo >( mpPropSetInfo ); +} + +//-------------------------------------------------------------------------- +void SAL_CALL SortedResultSet::setPropertyValue( + const OUString& PropertyName, + const Any& Value ) + throw( UnknownPropertyException, + PropertyVetoException, + IllegalArgumentException, + WrappedTargetException, + RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + + if ( ( PropertyName.compareToAscii( "RowCount" ) == COMPARE_EQUAL ) || + ( PropertyName.compareToAscii( "IsRowCountFinal" ) == COMPARE_EQUAL ) ) + throw IllegalArgumentException(); + else + throw UnknownPropertyException(); +} + +//-------------------------------------------------------------------------- +Any SAL_CALL SortedResultSet::getPropertyValue( const OUString& PropertyName ) + throw( UnknownPropertyException, + WrappedTargetException, + RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + + Any aRet; + + if ( PropertyName.compareToAscii( "RowCount" ) == COMPARE_EQUAL ) + { + aRet <<= maS2O.Count(); + } + else if ( PropertyName.compareToAscii( "IsRowCountFinal" ) == COMPARE_EQUAL ) + { + sal_Int32 nOrgCount; + sal_Bool bOrgFinal; + Any aOrgRet; + + aRet <<= (sal_Bool) FALSE; + + aOrgRet = Reference< XPropertySet >::query(mxOriginal)-> + getPropertyValue( PropertyName ); + aOrgRet >>= bOrgFinal; + + if ( bOrgFinal ) + { + aOrgRet = Reference< XPropertySet >::query(mxOriginal)-> + getPropertyValue( OUString::createFromAscii( "RowCount" ) ); + aOrgRet >>= nOrgCount; + if ( nOrgCount == maS2O.Count() ) + aRet <<= (sal_Bool) TRUE; + } + } + else + throw UnknownPropertyException(); + + return aRet; +} + +//-------------------------------------------------------------------------- +void SAL_CALL SortedResultSet::addPropertyChangeListener( + const OUString& PropertyName, + const Reference< XPropertyChangeListener >& Listener ) + throw( UnknownPropertyException, + WrappedTargetException, + RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + + if ( !mpPropChangeListeners ) + mpPropChangeListeners = + new PropertyChangeListeners_Impl(); + + mpPropChangeListeners->addInterface( PropertyName, Listener ); +} + +//-------------------------------------------------------------------------- +void SAL_CALL SortedResultSet::removePropertyChangeListener( + const OUString& PropertyName, + const Reference< XPropertyChangeListener >& Listener ) + throw( UnknownPropertyException, + WrappedTargetException, + RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + + if ( mpPropChangeListeners ) + mpPropChangeListeners->removeInterface( PropertyName, Listener ); +} + +//-------------------------------------------------------------------------- +void SAL_CALL SortedResultSet::addVetoableChangeListener( + const OUString& PropertyName, + const Reference< XVetoableChangeListener >& Listener ) + throw( UnknownPropertyException, + WrappedTargetException, + RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + + if ( !mpVetoChangeListeners ) + mpVetoChangeListeners = + new PropertyChangeListeners_Impl(); + + mpVetoChangeListeners->addInterface( PropertyName, Listener ); +} + +//-------------------------------------------------------------------------- +void SAL_CALL SortedResultSet::removeVetoableChangeListener( + const OUString& PropertyName, + const Reference< XVetoableChangeListener >& Listener ) + throw( UnknownPropertyException, + WrappedTargetException, + RuntimeException ) +{ + vos::OGuard aGuard( maMutex ); + + if ( mpVetoChangeListeners ) + mpVetoChangeListeners->removeInterface( PropertyName, Listener ); +} + +//-------------------------------------------------------------------------- +// private methods +//-------------------------------------------------------------------------- +long SortedResultSet::CompareImpl( Reference < XResultSet > xResultOne, + Reference < XResultSet > xResultTwo, + long nIndexOne, long nIndexTwo, + SortInfo* pSortInfo ) + +{ + Reference < XRow > xRowOne = Reference< XRow >::query( xResultOne ); + Reference < XRow > xRowTwo = Reference< XRow >::query( xResultTwo ); + + long nCompare = 0; + long nColumn = pSortInfo->mnColumn; + + switch ( pSortInfo->mnType ) + { + case DataType::BIT : + case DataType::TINYINT : + case DataType::SMALLINT : + case DataType::INTEGER : + { + sal_Int32 aOne, aTwo; + + if ( xResultOne->absolute( nIndexOne ) ) + aOne = xRowOne->getInt( nColumn ); + if ( xResultTwo->absolute( nIndexTwo ) ) + aTwo = xRowTwo->getInt( nColumn ); + + if ( aOne < aTwo ) + nCompare = -1; + else if ( aOne == aTwo ) + nCompare = 0; + else + nCompare = 1; + + break; + } + case DataType::BIGINT : + { + sal_Int64 aOne, aTwo; + + if ( xResultOne->absolute( nIndexOne ) ) + aOne = xRowOne->getLong( nColumn ); + if ( xResultTwo->absolute( nIndexTwo ) ) + aTwo = xRowTwo->getLong( nColumn ); + + if ( aOne < aTwo ) + nCompare = -1; + else if ( aOne == aTwo ) + nCompare = 0; + else + nCompare = 1; + + break; + } + case DataType::CHAR : + case DataType::VARCHAR : + case DataType::LONGVARCHAR : + { + OUString aOne, aTwo; + + if ( xResultOne->absolute( nIndexOne ) ) + aOne = xRowOne->getString( nColumn ); + if ( xResultTwo->absolute( nIndexTwo ) ) + aTwo = xRowTwo->getString( nColumn ); + + if ( ! pSortInfo->mbCaseSensitive ) + { + aOne = aOne.toLowerCase(); + aTwo = aTwo.toLowerCase(); + } + + nCompare = aOne.compareTo( aTwo ); + break; + } + case DataType::DATE : + { + Date aOne, aTwo; + sal_Int32 nTmp; + + if ( xResultOne->absolute( nIndexOne ) ) + aOne = xRowOne->getDate( nColumn ); + if ( xResultTwo->absolute( nIndexTwo ) ) + aTwo = xRowTwo->getDate( nColumn ); + + nTmp = (sal_Int32) aTwo.Year - (sal_Int32) aOne.Year; + if ( !nTmp ) { + nTmp = (sal_Int32) aTwo.Month - (sal_Int32) aOne.Month; + if ( !nTmp ) + nTmp = (sal_Int32) aTwo.Day - (sal_Int32) aOne.Day; + } + + if ( nTmp < 0 ) + nCompare = -1; + else if ( nTmp == 0 ) + nCompare = 0; + else + nCompare = 1; + + break; + } + case DataType::TIME : + { + Time aOne, aTwo; + sal_Int32 nTmp; + + if ( xResultOne->absolute( nIndexOne ) ) + aOne = xRowOne->getTime( nColumn ); + if ( xResultTwo->absolute( nIndexTwo ) ) + aTwo = xRowTwo->getTime( nColumn ); + + nTmp = (sal_Int32) aTwo.Hours - (sal_Int32) aOne.Hours; + if ( !nTmp ) { + nTmp = (sal_Int32) aTwo.Minutes - (sal_Int32) aOne.Minutes; + if ( !nTmp ) { + nTmp = (sal_Int32) aTwo.Seconds - (sal_Int32) aOne.Seconds; + if ( !nTmp ) + nTmp = (sal_Int32) aTwo.HundredthSeconds + - (sal_Int32) aOne.HundredthSeconds; + }} + + if ( nTmp < 0 ) + nCompare = -1; + else if ( nTmp == 0 ) + nCompare = 0; + else + nCompare = 1; + + break; + } + case DataType::TIMESTAMP : + { + DateTime aOne, aTwo; + sal_Int32 nTmp; + + if ( xResultOne->absolute( nIndexOne ) ) + aOne = xRowOne->getTimestamp( nColumn ); + if ( xResultTwo->absolute( nIndexTwo ) ) + aTwo = xRowTwo->getTimestamp( nColumn ); + + nTmp = (sal_Int32) aTwo.Year - (sal_Int32) aOne.Year; + if ( !nTmp ) { + nTmp = (sal_Int32) aTwo.Month - (sal_Int32) aOne.Month; + if ( !nTmp ) { + nTmp = (sal_Int32) aTwo.Day - (sal_Int32) aOne.Day; + if ( !nTmp ) { + nTmp = (sal_Int32) aTwo.Hours - (sal_Int32) aOne.Hours; + if ( !nTmp ) { + nTmp = (sal_Int32) aTwo.Minutes - (sal_Int32) aOne.Minutes; + if ( !nTmp ) { + nTmp = (sal_Int32) aTwo.Seconds - (sal_Int32) aOne.Seconds; + if ( !nTmp ) + nTmp = (sal_Int32) aTwo.HundredthSeconds + - (sal_Int32) aOne.HundredthSeconds; + }}}}} + + if ( nTmp < 0 ) + nCompare = -1; + else if ( nTmp == 0 ) + nCompare = 0; + else + nCompare = 1; + + break; + } + case DataType::REAL : + { + float aOne, aTwo; + + if ( xResultOne->absolute( nIndexOne ) ) + aOne = xRowOne->getFloat( nColumn ); + if ( xResultTwo->absolute( nIndexTwo ) ) + aTwo = xRowTwo->getFloat( nColumn ); + + if ( aOne < aTwo ) + nCompare = -1; + else if ( aOne == aTwo ) + nCompare = 0; + else + nCompare = 1; + + break; + } + case DataType::FLOAT : + case DataType::DOUBLE : + { + double aOne, aTwo; + + if ( xResultOne->absolute( nIndexOne ) ) + aOne = xRowOne->getDouble( nColumn ); + if ( xResultTwo->absolute( nIndexTwo ) ) + aTwo = xRowTwo->getDouble( nColumn ); + + if ( aOne < aTwo ) + nCompare = -1; + else if ( aOne == aTwo ) + nCompare = 0; + else + nCompare = 1; + + break; + } + default: + { + DBG_ERRORFILE( "DataType not supported for compare!" ); + } + } + + return nCompare; +} + +//-------------------------------------------------------------------------- +long SortedResultSet::CompareImpl( Reference < XResultSet > xResultOne, + Reference < XResultSet > xResultTwo, + long nIndexOne, long nIndexTwo ) +{ + long nCompare = 0; + SortInfo* pInfo = mpSortInfo; + + while ( !nCompare && pInfo ) + { + if ( pInfo->mbUseOwnCompare ) + { + nCompare = CompareImpl( xResultOne, xResultTwo, + nIndexOne, nIndexTwo, pInfo ); + } + else + { + Any aOne, aTwo; + + Reference < XRow > xRowOne = + Reference< XRow >::query( xResultOne ); + Reference < XRow > xRowTwo = + Reference< XRow >::query( xResultTwo ); + + if ( xResultOne->absolute( nIndexOne ) ) + aOne = xRowOne->getObject( pInfo->mnColumn, NULL ); + if ( xResultTwo->absolute( nIndexTwo ) ) + aTwo = xRowTwo->getObject( pInfo->mnColumn, NULL ); + + nCompare = pInfo->mxCompareFunction->compare( aOne, aTwo ); + } + + if ( ! pInfo->mbAscending ) + nCompare = - nCompare; + + pInfo = pInfo->mpNext; + } + + return nCompare; +} + +//-------------------------------------------------------------------------- +long SortedResultSet::Compare( SortListData *pOne, + SortListData *pTwo ) +{ + long nIndexOne; + long nIndexTwo; + + Reference < XResultSet > xResultOne; + Reference < XResultSet > xResultTwo; + + if ( pOne->mbModified ) + { + xResultOne = mxOther; + nIndexOne = pOne->mnOldPos; + } + else + { + xResultOne = mxOriginal; + nIndexOne = pOne->mnCurPos; + } + + if ( pTwo->mbModified ) + { + xResultTwo = mxOther; + nIndexTwo = pTwo->mnOldPos; + } + else + { + xResultTwo = mxOriginal; + nIndexTwo = pTwo->mnCurPos; + } + + long nCompare; + nCompare = CompareImpl( xResultOne, xResultTwo, + nIndexOne, nIndexTwo ); + return nCompare; +} + +//-------------------------------------------------------------------------- +long SortedResultSet::FindPos( SortListData *pEntry, + long _nStart, long _nEnd ) +{ + if ( _nStart > _nEnd ) + return _nStart + 1; + + long nStart = _nStart; + long nEnd = _nEnd; + long nMid, nCompare; + + SortListData *pMid; + + while ( nStart <= nEnd ) + { + nMid = ( nEnd - nStart ) / 2 + nStart; + pMid = maS2O.GetData( nMid ); + nCompare = Compare( pEntry, pMid ); + + if ( !nCompare ) + nCompare = ((long) pEntry ) - ( (long) pMid ); + + if ( nCompare < 0 ) // pEntry < pMid + nEnd = nMid - 1; + else + nStart = nMid + 1; + } + + if ( nCompare < 0 ) // pEntry < pMid + return nMid; + else + return nMid+1; +} + +//-------------------------------------------------------------------------- +void SortedResultSet::PropertyChanged( const PropertyChangeEvent& rEvt ) +{ + vos::OGuard aGuard( maMutex ); + + if ( !mpPropChangeListeners ) + return; + + // Notify listeners interested especially in the changed property. + OInterfaceContainerHelper* pPropsContainer = + mpPropChangeListeners->getContainer( rEvt.PropertyName ); + if ( pPropsContainer ) + { + OInterfaceIteratorHelper aIter( *pPropsContainer ); + while ( aIter.hasMoreElements() ) + { + Reference< XPropertyChangeListener > xListener( + aIter.next(), UNO_QUERY ); + if ( xListener.is() ) + xListener->propertyChange( rEvt ); + } + } + + // Notify listeners interested in all properties. + pPropsContainer = mpPropChangeListeners->getContainer( OUString() ); + if ( pPropsContainer ) + { + OInterfaceIteratorHelper aIter( *pPropsContainer ); + while ( aIter.hasMoreElements() ) + { + Reference< XPropertyChangeListener > xListener( + aIter.next(), UNO_QUERY ); + if ( xListener.is() ) + xListener->propertyChange( rEvt ); + } + } +} + +//------------------------------------------------------------------------- + +//-------------------------------------------------------------------------- +// public methods +//-------------------------------------------------------------------------- + +void SortedResultSet::CopyData( SortedResultSet *pSource ) +{ + const SortedEntryList *pSrcS2O = pSource->GetS2OList(); + const List *pSrcO2S = pSource->GetO2SList(); + + long i, nCount; + + maS2O.Clear(); + maO2S.Clear(); + maModList.Clear(); + + maS2O.Insert( NULL, 0 ); + maO2S.Insert( 0, (ULONG) 0 ); // value, pos + + nCount = pSrcS2O->Count(); + + for ( i=1; i<nCount; i++ ) + { + maS2O.Insert( new SortListData( (*pSrcS2O)[ i ] ), i ); + maO2S.Insert( pSrcO2S->GetObject( i ), (ULONG) i ); + } + + mnLastSort = maS2O.Count(); + mxOther = pSource->GetResultSet(); + + if ( !mpSortInfo ) + { + mpSortInfo = pSource->GetSortInfo(); + mbIsCopy = TRUE; + } +} + +//-------------------------------------------------------------------------- +void SortedResultSet::Initialize( + const Sequence < NumberedSortingInfo > &xSortInfo, + const Reference< XAnyCompareFactory > &xCompFactory ) +{ + BuildSortInfo( mxOriginal, xSortInfo, xCompFactory ); + // Insert dummy at pos 0 + SortListData *pData = new SortListData( 0 ); + maS2O.Insert( pData, 0 ); + + long nIndex = 1; + + // now fetch all the elements from the original result set, + // get there new position in the sorted result set and insert + // an entry in the sorted to original mapping list + while ( mxOriginal->absolute( nIndex ) ) + { + pData = new SortListData( nIndex ); + long nPos = FindPos( pData, 1, nIndex-1 ); + + maS2O.Insert( pData, nPos ); + + nIndex++; + } + + // when we have fetched all the elements, we can create the + // original to sorted mapping list from the s2o list + maO2S.Clear(); + maO2S.Insert( NULL, (ULONG) 0 ); + + // insert some dummy entries first and replace then + // the entries with the right ones + long i; + + for ( i=1; i<maS2O.Count(); i++ ) + maO2S.Insert( (void*) 0, (ULONG) i ); // Insert( data, pos ) + for ( i=1; i<maS2O.Count(); i++ ) + maO2S.Replace( (void*) i, (ULONG) maS2O[ i ] ); // Insert( data, pos ) + + mnCount = maS2O.Count() - 1; +} + +//-------------------------------------------------------------------------- +void SortedResultSet::CheckProperties( long nOldCount, BOOL bWasFinal ) +{ + vos::OGuard aGuard( maMutex ); + + if ( !mpPropChangeListeners ) + return; + + // check for propertyChangeEvents + if ( nOldCount != GetCount() ) + { + BOOL bIsFinal; + PropertyChangeEvent aEvt; + + aEvt.PropertyName = OUString::createFromAscii( "RowCount" ); + aEvt.Further = FALSE; + aEvt.PropertyHandle = -1; + aEvt.OldValue <<= nOldCount; + aEvt.NewValue <<= GetCount(); + + PropertyChanged( aEvt ); + + OUString aName = OUString::createFromAscii( "IsRowCountFinal" ); + Any aRet = getPropertyValue( aName ); + aRet >>= bIsFinal; + if ( bIsFinal != bWasFinal ) + { + aEvt.PropertyName = aName; + aEvt.Further = FALSE; + aEvt.PropertyHandle = -1; + aEvt.OldValue <<= (sal_Bool) bWasFinal; + aEvt.NewValue <<= (sal_Bool) bIsFinal; + PropertyChanged( aEvt ); + } + } +} + +//------------------------------------------------------------------------- +void SortedResultSet::InsertNew( long nPos, long nCount ) +{ + // in der maS2O Liste alle Eintrge, die >= nPos sind, um nCount + // erhhen + SortListData *pData; + long i, nEnd; + + nEnd = maS2O.Count(); + for ( i=1; i<=nEnd; i++ ) + { + pData = maS2O.GetData( i ); + if ( pData->mnCurPos >= nPos ) + { + pData->mnCurPos += nCount; + } + } + + // und die neuen eintrge hinten an die maS2O Liste anhngen bzw + // an der Position nPos in der maO2S Liste einfgen + for ( i=0; i<nCount; i++ ) + { + nEnd += 1; + pData = new SortListData( nEnd ); + + maS2O.Insert( pData, nEnd ); // Insert( Wert, Position ) + maO2S.Insert( (void*)nEnd, (ULONG)(nPos+i) ); // Insert( Wert, Position ) + } + + mnCount += nCount; +} + +//------------------------------------------------------------------------- +void SortedResultSet::Remove( long nPos, long nCount, EventList *pEvents ) +{ + long i, j, nOldLastSort; + // correct mnLastSort first + nOldLastSort = mnLastSort; + if ( nPos <= mnLastSort ) + { + if ( nPos + nCount - 1 <= mnLastSort ) + mnLastSort -= nCount; + else + mnLastSort = nPos - 1; + } + + // remove the entries from the lists and correct the positions + // in the original2sorted list + for ( i=0; i<nCount; i++ ) + { + long nSortPos = (long) maO2S.GetObject( nPos ); + maO2S.Remove( (ULONG) nPos ); + + for ( j=1; j<=maO2S.Count(); j++ ) + { + long nVal = (long) maO2S.GetObject( (ULONG) j ); + if ( nVal > nSortPos ) + { + --nVal; + maO2S.Replace( (void*) nVal, j ); + } + } + + SortListData *pData = maS2O.Remove( nSortPos ); + if ( pData->mbModified ) + maModList.Remove( (void*) pData ); + delete pData; + + // generate remove Event, but not for new entries + if ( nSortPos <= nOldLastSort ) + pEvents->AddEvent( ListActionType::REMOVED, nSortPos, 1 ); + } + + // correct the positions in the sorted list + for ( i=1; i<= maS2O.Count(); i++ ) + { + SortListData *pData = maS2O.GetData( i ); + if ( pData->mnCurPos > nPos ) + pData->mnCurPos -= nCount; + } + + mnCount -= nCount; +} + +//------------------------------------------------------------------------- +void SortedResultSet::Move( long nPos, long nCount, long nOffset ) +{ + if ( !nOffset ) + return; + + long i, nSortPos, nTo; + SortListData *pData; + + for ( i=0; i<nCount; i++ ) + { + nSortPos = (long) maO2S.GetObject( nPos+i ); + pData = maS2O.GetData( nSortPos ); + pData->mnCurPos += nOffset; + } + + if ( nOffset < 0 ) + { + for ( i=nPos+nOffset; i<nPos; i++ ) + { + nSortPos = (long) maO2S.GetObject( i ); + pData = maS2O.GetData( nSortPos ); + pData->mnCurPos += nCount; + } + } + else + { + long nStart = nPos + nCount; + long nEnd = nStart + nOffset; + for ( i=nStart; i<nEnd; i++ ) + { + nSortPos = (long) maO2S.GetObject( i ); + pData = maS2O.GetData( nSortPos ); + pData->mnCurPos -= nCount; + } + } + + // remember the to be moved entries + long *pTmpArr = new long[ nCount ]; + for ( i=0; i<nCount; i++ ) + pTmpArr[i] = (long)maO2S.GetObject( (ULONG)( nPos+i ) ); + + // now move the entries, which are in the way + if ( nOffset < 0 ) + { + // be carefully here, because nOffset is negative here, so an + // addition is a subtraction + long nFrom = nPos - 1; + nTo = nPos + nCount - 1; + + // same for i here + for ( i=0; i>nOffset; i-- ) + { + long nVal = (long) maO2S.GetObject( (ULONG)( nFrom+i ) ); + maO2S.Replace( (void*) nVal, (ULONG)( nTo+i ) ); + } + + } + else + { + long nStart = nPos + nCount; + for ( i=0; i<nOffset; i++ ) + { + long nVal = (long) maO2S.GetObject( (ULONG)( nStart+i ) ); + maO2S.Replace( (void*) nVal, (ULONG)( nPos+i ) ); + } + } + + // finally put the remembered entries at there new location + nTo = nPos + nOffset; + for ( i=0; i<nCount; i++ ); + { + maO2S.Replace( (void*)pTmpArr[ i ], (ULONG)( nTo+i ) ); + } +} + +//-------------------------------------------------------------------------- +void SortedResultSet::BuildSortInfo( + Reference< XResultSet > aResult, + const Sequence < NumberedSortingInfo > &xSortInfo, + const Reference< XAnyCompareFactory > &xCompFactory ) +{ + Reference < XResultSetMetaDataSupplier > xMeta ( aResult, UNO_QUERY ); + + if ( ! xMeta.is() ) + { + DBG_ERRORFILE( "No MetaData, No Sorting!" ); + return; + } + + Reference < XResultSetMetaData > xData = xMeta->getMetaData(); + const NumberedSortingInfo *pSortInfo = xSortInfo.getConstArray(); + + sal_Int32 nColumn; + OUString aPropName; + SortInfo *pInfo; + + for ( long i=xSortInfo.getLength(); i > 0; ) + { + --i; + nColumn = pSortInfo[ i ].ColumnIndex; + aPropName = xData->getColumnName( nColumn ); + pInfo = new SortInfo; + + if ( xCompFactory.is() ) + pInfo->mxCompareFunction = xCompFactory->createAnyCompareByName( + aPropName ); + + if ( pInfo->mxCompareFunction.is() ) + { + pInfo->mbUseOwnCompare = FALSE; + pInfo->mnType = 0; + } + else + { + pInfo->mbUseOwnCompare = TRUE; + pInfo->mnType = xData->getColumnType( nColumn ); + } + + pInfo->mnColumn = nColumn; + pInfo->mbAscending = pSortInfo[ i ].Ascending; + pInfo->mbCaseSensitive = xData->isCaseSensitive( nColumn ); + pInfo->mpNext = mpSortInfo; + mpSortInfo = pInfo; + } +} + +//------------------------------------------------------------------------- +void SortedResultSet::SetChanged( long nPos, long nCount ) +{ + for ( long i=0; i<nCount; i++ ) + { + long nSortPos = (long) maO2S.GetObject( nPos ); + if ( nSortPos < mnLastSort ) + { + SortListData *pData = maS2O.GetData( nSortPos ); + if ( ! pData->mbModified ) + { + pData->mbModified = TRUE; + maModList.Insert( pData, LIST_APPEND ); + } + } + nPos += 1; + } +} + +//------------------------------------------------------------------------- +void SortedResultSet::ResortModified( EventList* pList ) +{ + ULONG i, j; + long nCompare, nCurPos, nNewPos; + long nStart, nEnd, nOffset, nVal; + SortListData *pData; + ListAction *pAction; + + for ( i=0; i<maModList.Count(); i++ ) + { + pData = (SortListData*) maModList.GetObject( i ); + nCompare = CompareImpl( mxOther, mxOriginal, + pData->mnOldPos, pData->mnCurPos ); + pData->mbModified = FALSE; + if ( nCompare != 0 ) + { + nCurPos = (long) maO2S.GetObject( (ULONG) pData->mnCurPos ); + if ( nCompare < 0 ) + { + nNewPos = FindPos( pData, 1, nCurPos-1 ); + nStart = nNewPos; + nEnd = nCurPos; + nOffset = 1; + } + else + { + nNewPos = FindPos( pData, nCurPos+1, mnLastSort ); + nStart = nCurPos; + nEnd = mnLastSort; + nOffset = -1; + } + + if ( nNewPos != nCurPos ) + { + // correct the lists! + maS2O.Remove( (ULONG) nCurPos ); + maS2O.Insert( pData, nNewPos ); + for ( j=1; j<maO2S.Count(); j++ ) + { + nVal = (long) maO2S.GetObject( (ULONG)( j ) ); + if ( ( nStart <= nVal ) && ( nVal <= nEnd ) ) + { + nVal += nOffset; + maO2S.Replace( (void*) (nVal), (ULONG)( j ) ); + } + } + + maO2S.Replace( (void*) nNewPos, (ULONG) pData->mnCurPos ); + + pAction = new ListAction; + pAction->Position = nCurPos; + pAction->Count = 1; + pAction->ListActionType = ListActionType::MOVED; + pAction->ActionInfo <<= nNewPos-nCurPos; + pList->Insert( pAction ); + } + pList->AddEvent( ListActionType::PROPERTIES_CHANGED, + nNewPos, 1 ); + } + } + maModList.Clear(); +} + +//------------------------------------------------------------------------- +void SortedResultSet::ResortNew( EventList* pList ) +{ + long i, j, nNewPos, nVal; + SortListData *pData; + + for ( i = mnLastSort; i<maS2O.Count(); i++ ) + { + pData = (SortListData*) maModList.GetObject( i ); + nNewPos = FindPos( pData, 1, mnLastSort ); + if ( nNewPos != i ) + { + maS2O.Remove( (ULONG) i ); + maS2O.Insert( pData, nNewPos ); + // maO2S liste korigieren + for ( j=1; j<maO2S.Count(); j++ ) + { + nVal = (long) maO2S.GetObject( (ULONG)( j ) ); + if ( nVal >= nNewPos ) + maO2S.Replace( (void*) (nVal+1), (ULONG)( j ) ); + } + maO2S.Replace( (void*) nNewPos, (ULONG) pData->mnCurPos ); + } + mnLastSort++; + pList->AddEvent( ListActionType::INSERTED, nNewPos, 1 ); + } +} + +//------------------------------------------------------------------------- +// +// SortListData +// +//------------------------------------------------------------------------- +SortListData::SortListData( long nPos, BOOL bModified ) +{ + mbModified = bModified; + mnCurPos = nPos; + mnOldPos = nPos; +}; + + +//========================================================================= +SortedEntryList::SortedEntryList() + : List( 64, 128 ) +{} + +//------------------------------------------------------------------------- +SortedEntryList::~SortedEntryList() +{ + Clear(); +} + +//------------------------------------------------------------------------- +void SortedEntryList::Clear() +{ + SortListData *pData = (SortListData*) List::First(); + + while ( pData ) + { + delete pData; + pData = (SortListData*) List::Next(); + } + + List::Clear(); +} + +//------------------------------------------------------------------------- +void SortedEntryList::Insert( SortListData *pEntry, long nPos ) +{ + List::Insert( pEntry, (ULONG) nPos ); +} + +//------------------------------------------------------------------------- +SortListData* SortedEntryList::Remove( long nPos ) +{ + SortListData *pData = (SortListData*) List::Remove( nPos ); + return pData; +} + +//------------------------------------------------------------------------- +SortListData* SortedEntryList::GetData( long nPos ) +{ + SortListData *pData = (SortListData*) List::GetObject( nPos ); + return pData; +} + +//------------------------------------------------------------------------- +long SortedEntryList::operator [] ( long nPos ) const +{ + SortListData *pData = (SortListData*) List::GetObject( nPos ); + if ( pData ) + if ( ! pData->mbModified ) + return pData->mnCurPos; + else + { + DBG_ERRORFILE( "SortedEntryList: Can't get value for modified entry!"); + return 0; + } + else + { + DBG_ERRORFILE( "SortedEntryList: invalid pos!"); + return 0; + } +} + +//------------------------------------------------------------------------- +// +// class SRSPropertySetInfo. +// +//------------------------------------------------------------------------- + +SRSPropertySetInfo::SRSPropertySetInfo() +{ + maProps[0].Name = OUString::createFromAscii( "RowCount" ); + maProps[0].Handle = -1; + maProps[0].Type = ::getCppuType( (const OUString*) NULL ); + maProps[0].Attributes = -1; + + maProps[1].Name = OUString::createFromAscii( "IsRowCountFinal" ); + maProps[1].Handle = -1; + maProps[1].Type = ::getBooleanCppuType(); + maProps[1].Attributes = -1; +} + +//------------------------------------------------------------------------- +SRSPropertySetInfo::~SRSPropertySetInfo() +{} + +//------------------------------------------------------------------------- +// XInterface methods. +//------------------------------------------------------------------------- + +XINTERFACE_IMPL_2( SRSPropertySetInfo, + XTypeProvider, + XPropertySetInfo ); + +//------------------------------------------------------------------------- +// XTypeProvider methods. +//------------------------------------------------------------------------- + +XTYPEPROVIDER_IMPL_2( SRSPropertySetInfo, + XTypeProvider, + XPropertySetInfo ); + +//------------------------------------------------------------------------- +// XPropertySetInfo methods. +//------------------------------------------------------------------------- +Sequence< Property > SAL_CALL +SRSPropertySetInfo::getProperties() throw( RuntimeException ) +{ + return Sequence < Property > ( maProps, 2 ); +} + +//------------------------------------------------------------------------- +Property SAL_CALL +SRSPropertySetInfo::getPropertyByName( const OUString& Name ) + throw( UnknownPropertyException, RuntimeException ) +{ + if ( Name.compareToAscii( "RowCount" ) == COMPARE_EQUAL ) + return maProps[0]; + else if ( Name.compareToAscii( "IsRowCountFinal" ) == COMPARE_EQUAL ) + return maProps[1]; + else + throw UnknownPropertyException(); +} + +//------------------------------------------------------------------------- +sal_Bool SAL_CALL +SRSPropertySetInfo::hasPropertyByName( const OUString& Name ) + throw( RuntimeException ) +{ + if ( Name.compareToAscii( "RowCount" ) == COMPARE_EQUAL ) + return TRUE; + else if ( Name.compareToAscii( "IsRowCountFinal" ) == COMPARE_EQUAL ) + return TRUE; + else + return FALSE; +} + diff --git a/ucb/source/sorter/sortresult.hxx b/ucb/source/sorter/sortresult.hxx new file mode 100644 index 000000000000..353aa8c9ce58 --- /dev/null +++ b/ucb/source/sorter/sortresult.hxx @@ -0,0 +1,497 @@ +/************************************************************************* + * + * $RCSfile: sortresult.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:53:23 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _SORTRESULT_HXX +#define _SORTRESULT_HXX + +#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_ +#include <com/sun/star/beans/XPropertySet.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XTYPEPROVIDER_HPP_ +#include <com/sun/star/lang/XTypeProvider.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_ +#include <com/sun/star/lang/XServiceInfo.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XCOMPONENT_HPP_ +#include <com/sun/star/lang/XComponent.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XCLOSEABLE_HPP_ +#include <com/sun/star/sdbc/XCloseable.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XRESULTSET_HPP_ +#include <com/sun/star/sdbc/XResultSet.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XRESULTSETMETADATA_HPP_ +#include <com/sun/star/sdbc/XResultSetMetaData.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XRESULTSETMETADATASUPPLIER_HPP_ +#include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_ +#include <com/sun/star/sdbc/XRow.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCONTENTACCESS_HPP_ +#include <com/sun/star/ucb/XContentAccess.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_NUMBEREDSORTINGINFO_HPP_ +#include <com/sun/star/ucb/NumberedSortingInfo.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XANYCOMPAREFACTORY_HPP_ +#include <com/sun/star/ucb/XAnyCompareFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_LISTACTION_HPP_ +#include <com/sun/star/ucb/ListAction.hpp> +#endif + +#ifndef _CPPUHELPER_WEAK_HXX_ +#include <cppuhelper/weak.hxx> +#endif + +#ifndef _VOS_MUTEX_HXX_ +#include <vos/mutex.hxx> +#endif + + +#include <tools/list.hxx> + +#ifndef _UCBHELPER_MACROS_HXX +#include <ucbhelper/macros.hxx> +#endif + +namespace cppu { + class OInterfaceContainerHelper; +} + +//----------------------------------------------------------------------------- +struct SortInfo; +struct SortListData; +class SRSPropertySetInfo; +class PropertyChangeListeners_Impl; + +//----------------------------------------------------------------------------- +class SortedEntryList : protected List +{ +public: + SortedEntryList(); + ~SortedEntryList(); + + List::Count; + + void Clear(); + void Insert( SortListData *pEntry, long nPos ); + SortListData* Remove( long nPos ); + SortListData* GetData( long nPos ); + + long operator [] ( long nPos ) const; +}; + + +//----------------------------------------------------------------------------- +#define LISTACTION com::sun::star::ucb::ListAction + +class EventList : protected List +{ +public: + EventList(); + ~EventList(); + + List::Count; + + void AddEvent( long nType, long nPos, long nCount ); + void Insert( LISTACTION *pAction ) { List::Insert( pAction, LIST_APPEND ); } + void Clear(); + LISTACTION* GetAction( long nIndex ) { return (LISTACTION*) GetObject( nIndex ); } +}; + +//----------------------------------------------------------------------------- + +#define PROPERTYCHANGEEVENT com::sun::star::beans::PropertyChangeEvent +#define RUNTIME_EXCEPTION com::sun::star::uno::RuntimeException +#define REFERENCE com::sun::star::uno::Reference +#define SEQUENCE com::sun::star::uno::Sequence +#define XEVENTLISTENER com::sun::star::lang::XEventListener +#define XRESULTSET com::sun::star::sdbc::XResultSet +#define SQLEXCEPTION com::sun::star::sdbc::SQLException +#define XRESULTSETMETADATA com::sun::star::sdbc::XResultSetMetaData +#define NUMBERED_SORTINGINFO com::sun::star::ucb::NumberedSortingInfo +#define XANYCOMPAREFACTORY com::sun::star::ucb::XAnyCompareFactory + +#define RESULTSET_SERVICE_NAME "com.sun.star.ucb.SortedResultSet" + +//----------------------------------------------------------------------------- + +class SortedResultSet: + public cppu::OWeakObject, + public com::sun::star::lang::XTypeProvider, + public com::sun::star::lang::XServiceInfo, + public com::sun::star::lang::XComponent, + public com::sun::star::ucb::XContentAccess, + public XRESULTSET, + public com::sun::star::sdbc::XRow, + public com::sun::star::sdbc::XCloseable, + public com::sun::star::sdbc::XResultSetMetaDataSupplier, + public com::sun::star::beans::XPropertySet +{ + cppu::OInterfaceContainerHelper *mpDisposeEventListeners; + PropertyChangeListeners_Impl *mpPropChangeListeners; + PropertyChangeListeners_Impl *mpVetoChangeListeners; + + REFERENCE < XRESULTSET > mxOriginal; + REFERENCE < XRESULTSET > mxOther; + + SRSPropertySetInfo* mpPropSetInfo; + SortInfo* mpSortInfo; + ::vos::OMutex maMutex; + SortedEntryList maS2O; // maps the sorted entries to the original ones + List maO2S; // maps the original Entries to the sorted ones + List maModList; // keeps track of modified entries + long mnLastSort; // index of the last sorted entry; + long mnCurEntry; // index of the current entry + long mnCount; // total count of the elements + BOOL mbIsCopy; + + +private: + + long FindPos( SortListData *pEntry, long nStart, long nEnd ); + long Compare( SortListData *pOne, + SortListData *pTwo ); + void BuildSortInfo( REFERENCE< XRESULTSET > aResult, + const SEQUENCE < NUMBERED_SORTINGINFO > &xSortInfo, + const REFERENCE< XANYCOMPAREFACTORY > &xCompFac ); + long CompareImpl( REFERENCE < XRESULTSET > xResultOne, + REFERENCE < XRESULTSET > xResultTwo, + long nIndexOne, long nIndexTwo, + SortInfo* pSortInfo ); + long CompareImpl( REFERENCE < XRESULTSET > xResultOne, + REFERENCE < XRESULTSET > xResultTwo, + long nIndexOne, long nIndexTwo ); + void PropertyChanged( const PROPERTYCHANGEEVENT& rEvt ); + +public: + SortedResultSet( REFERENCE< XRESULTSET > aResult ); + ~SortedResultSet(); + + const SortedEntryList* GetS2OList() const { return &maS2O; } + const List* GetO2SList() const { return &maO2S; } + REFERENCE < XRESULTSET > GetResultSet() const { return mxOriginal; } + SortInfo* GetSortInfo() const { return mpSortInfo; } + long GetCount() const { return mnCount; } + + void CopyData( SortedResultSet* pSource ); + void Initialize( const SEQUENCE < NUMBERED_SORTINGINFO > &xSortInfo, + const REFERENCE< XANYCOMPAREFACTORY > &xCompFac ); + void CheckProperties( long nOldCount, BOOL bWasFinal ); + + void InsertNew( long nPos, long nCount ); + void SetChanged( long nPos, long nCount ); + void Remove( long nPos, long nCount, EventList *pList ); + void Move( long nPos, long nCount, long nOffset ); + + void ResortModified( EventList* pList ); + void ResortNew( EventList* pList ); + + // XInterface + XINTERFACE_DECL() + + // XTypeProvider + XTYPEPROVIDER_DECL() + + // XServiceInfo + XSERVICEINFO_NOFACTORY_DECL() + + // XComponent + virtual void SAL_CALL + dispose() throw( RUNTIME_EXCEPTION ); + + virtual void SAL_CALL + addEventListener( const REFERENCE< XEVENTLISTENER >& Listener ) + throw( RUNTIME_EXCEPTION ); + + virtual void SAL_CALL + removeEventListener( const REFERENCE< XEVENTLISTENER >& Listener ) + throw( RUNTIME_EXCEPTION ); + + // XContentAccess + virtual rtl::OUString SAL_CALL + queryContentIdentfierString() + throw( RUNTIME_EXCEPTION ); + virtual REFERENCE< + com::sun::star::ucb::XContentIdentifier > SAL_CALL + queryContentIdentifier() + throw( RUNTIME_EXCEPTION ); + virtual REFERENCE< + com::sun::star::ucb::XContent > SAL_CALL + queryContent() + throw( RUNTIME_EXCEPTION ); + + // XResultSet + virtual sal_Bool SAL_CALL + next() + throw( SQLEXCEPTION, RUNTIME_EXCEPTION ); + virtual sal_Bool SAL_CALL + isBeforeFirst() + throw( SQLEXCEPTION, RUNTIME_EXCEPTION ); + virtual sal_Bool SAL_CALL + isAfterLast() + throw( SQLEXCEPTION, RUNTIME_EXCEPTION ); + virtual sal_Bool SAL_CALL + isFirst() + throw( SQLEXCEPTION, RUNTIME_EXCEPTION ); + virtual sal_Bool SAL_CALL + isLast() + throw( SQLEXCEPTION, RUNTIME_EXCEPTION ); + virtual void SAL_CALL + beforeFirst() + throw( SQLEXCEPTION, RUNTIME_EXCEPTION ); + virtual void SAL_CALL + afterLast() + throw( SQLEXCEPTION, RUNTIME_EXCEPTION ); + virtual sal_Bool SAL_CALL + first() + throw( SQLEXCEPTION, RUNTIME_EXCEPTION ); + virtual sal_Bool SAL_CALL + last() + throw( SQLEXCEPTION, RUNTIME_EXCEPTION ); + virtual sal_Int32 SAL_CALL + getRow() + throw( SQLEXCEPTION, RUNTIME_EXCEPTION ); + virtual sal_Bool SAL_CALL + absolute( sal_Int32 row ) + throw( SQLEXCEPTION, RUNTIME_EXCEPTION ); + virtual sal_Bool SAL_CALL + relative( sal_Int32 rows ) + throw( SQLEXCEPTION, RUNTIME_EXCEPTION ); + virtual sal_Bool SAL_CALL + previous() + throw( SQLEXCEPTION, RUNTIME_EXCEPTION ); + virtual void SAL_CALL + refreshRow() + throw( SQLEXCEPTION, RUNTIME_EXCEPTION ); + virtual sal_Bool SAL_CALL + rowUpdated() + throw( SQLEXCEPTION, RUNTIME_EXCEPTION ); + virtual sal_Bool SAL_CALL + rowInserted() + throw( SQLEXCEPTION, RUNTIME_EXCEPTION ); + virtual sal_Bool SAL_CALL + rowDeleted() + throw( SQLEXCEPTION, RUNTIME_EXCEPTION ); + virtual REFERENCE< + com::sun::star::uno::XInterface > SAL_CALL + getStatement() + throw( SQLEXCEPTION, RUNTIME_EXCEPTION ); + + // XRow + virtual sal_Bool SAL_CALL + wasNull() throw( SQLEXCEPTION, RUNTIME_EXCEPTION ); + + virtual rtl::OUString SAL_CALL + getString( sal_Int32 columnIndex ) + throw( SQLEXCEPTION, RUNTIME_EXCEPTION ); + + virtual sal_Bool SAL_CALL + getBoolean( sal_Int32 columnIndex ) + throw( SQLEXCEPTION, RUNTIME_EXCEPTION ); + + virtual sal_Int8 SAL_CALL + getByte( sal_Int32 columnIndex ) + throw( SQLEXCEPTION, RUNTIME_EXCEPTION ); + + virtual sal_Int16 SAL_CALL + getShort( sal_Int32 columnIndex ) + throw( SQLEXCEPTION, RUNTIME_EXCEPTION ); + + virtual sal_Int32 SAL_CALL + getInt( sal_Int32 columnIndex ) + throw( SQLEXCEPTION, RUNTIME_EXCEPTION ); + + virtual sal_Int64 SAL_CALL + getLong( sal_Int32 columnIndex ) + throw( SQLEXCEPTION, RUNTIME_EXCEPTION ); + + virtual float SAL_CALL + getFloat( sal_Int32 columnIndex ) + throw( SQLEXCEPTION, RUNTIME_EXCEPTION ); + + virtual double SAL_CALL + getDouble( sal_Int32 columnIndex ) + throw( SQLEXCEPTION, RUNTIME_EXCEPTION ); + + virtual com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL + getBytes( sal_Int32 columnIndex ) + throw( SQLEXCEPTION, RUNTIME_EXCEPTION ); + + virtual com::sun::star::util::Date SAL_CALL + getDate( sal_Int32 columnIndex ) + throw( SQLEXCEPTION, RUNTIME_EXCEPTION ); + + virtual com::sun::star::util::Time SAL_CALL + getTime( sal_Int32 columnIndex ) + throw( SQLEXCEPTION, RUNTIME_EXCEPTION ); + + virtual com::sun::star::util::DateTime SAL_CALL + getTimestamp( sal_Int32 columnIndex ) + throw( SQLEXCEPTION, RUNTIME_EXCEPTION ); + + virtual REFERENCE< + com::sun::star::io::XInputStream > SAL_CALL + getBinaryStream( sal_Int32 columnIndex ) + throw( SQLEXCEPTION, RUNTIME_EXCEPTION ); + + virtual REFERENCE< + com::sun::star::io::XInputStream > SAL_CALL + getCharacterStream( sal_Int32 columnIndex ) + throw( SQLEXCEPTION, RUNTIME_EXCEPTION ); + + virtual com::sun::star::uno::Any SAL_CALL + getObject( sal_Int32 columnIndex, + const REFERENCE< + com::sun::star::container::XNameAccess >& typeMap ) + throw( SQLEXCEPTION, RUNTIME_EXCEPTION ); + virtual REFERENCE< + com::sun::star::sdbc::XRef > SAL_CALL + getRef( sal_Int32 columnIndex ) + throw( SQLEXCEPTION, RUNTIME_EXCEPTION ); + virtual REFERENCE< + com::sun::star::sdbc::XBlob > SAL_CALL + getBlob( sal_Int32 columnIndex ) + throw( SQLEXCEPTION, RUNTIME_EXCEPTION ); + virtual REFERENCE< + com::sun::star::sdbc::XClob > SAL_CALL + getClob( sal_Int32 columnIndex ) + throw( SQLEXCEPTION, RUNTIME_EXCEPTION ); + virtual REFERENCE< + com::sun::star::sdbc::XArray > SAL_CALL + getArray( sal_Int32 columnIndex ) + throw( SQLEXCEPTION, RUNTIME_EXCEPTION ); + + // XCloseable + virtual void SAL_CALL + close() + throw( SQLEXCEPTION, RUNTIME_EXCEPTION ); + + // XResultSetMetaDataSupplier + virtual REFERENCE< XRESULTSETMETADATA > SAL_CALL + getMetaData() + throw( SQLEXCEPTION, RUNTIME_EXCEPTION ); + + + // XPropertySet + virtual REFERENCE< + com::sun::star::beans::XPropertySetInfo > SAL_CALL + getPropertySetInfo() + throw( RUNTIME_EXCEPTION ); + + virtual void SAL_CALL + setPropertyValue( const rtl::OUString& PropertyName, + const com::sun::star::uno::Any& Value ) + throw( com::sun::star::beans::UnknownPropertyException, + com::sun::star::beans::PropertyVetoException, + com::sun::star::lang::IllegalArgumentException, + com::sun::star::lang::WrappedTargetException, + RUNTIME_EXCEPTION ); + + virtual com::sun::star::uno::Any SAL_CALL + getPropertyValue( const rtl::OUString& PropertyName ) + throw( com::sun::star::beans::UnknownPropertyException, + com::sun::star::lang::WrappedTargetException, + RUNTIME_EXCEPTION ); + + virtual void SAL_CALL + addPropertyChangeListener( const rtl::OUString& PropertyName, + const REFERENCE< + com::sun::star::beans::XPropertyChangeListener >& Listener ) + throw( com::sun::star::beans::UnknownPropertyException, + com::sun::star::lang::WrappedTargetException, + RUNTIME_EXCEPTION ); + + virtual void SAL_CALL + removePropertyChangeListener( const rtl::OUString& PropertyName, + const REFERENCE< + com::sun::star::beans::XPropertyChangeListener >& Listener ) + throw( com::sun::star::beans::UnknownPropertyException, + com::sun::star::lang::WrappedTargetException, + RUNTIME_EXCEPTION ); + + virtual void SAL_CALL + addVetoableChangeListener( const rtl::OUString& PropertyName, + const REFERENCE< + com::sun::star::beans::XVetoableChangeListener >& Listener ) + throw( com::sun::star::beans::UnknownPropertyException, + com::sun::star::lang::WrappedTargetException, + RUNTIME_EXCEPTION ); + + virtual void SAL_CALL + removeVetoableChangeListener( const rtl::OUString& PropertyName, + const REFERENCE< + com::sun::star::beans::XVetoableChangeListener >& aListener ) + throw( com::sun::star::beans::UnknownPropertyException, + com::sun::star::lang::WrappedTargetException, + RUNTIME_EXCEPTION ); +}; + +#endif + diff --git a/ucb/source/ucp/file/bc.cxx b/ucb/source/ucp/file/bc.cxx new file mode 100644 index 000000000000..f84732d91f97 --- /dev/null +++ b/ucb/source/ucp/file/bc.cxx @@ -0,0 +1,1286 @@ +/************************************************************************* + * + * $RCSfile: bc.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:53:36 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _OSL_FILE_HXX_ +#include <osl/file.hxx> +#endif +#ifndef _VOS_DIAGNOSE_HXX_ +#include <vos/diagnose.hxx> +#endif +#ifndef _COM_SUN_STAR_UCB_OPENMODE_HPP_ +#include <com/sun/star/ucb/OpenMode.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBBUTE_HPP_ +#include <com/sun/star/beans/PropertyAttribute.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XPROGRESSHANDLER_HPP_ +#include <com/sun/star/ucb/XProgressHandler.hpp> +#endif +#ifndef _COM_SUN_STAR_TASK_XINTERACTIONHANDLER_HPP_ +#include <com/sun/star/task/XInteractionHandler.hpp> +#endif +#ifndef _COM_SUN_STAR_IO_XACTIVEDATASTREAMER_HPP_ +#include <com/sun/star/io/XActiveDataStreamer.hpp> +#endif +#ifndef _COM_SUN_STAR_IO_XOUTPUTSTREAM_HPP_ +#include <com/sun/star/io/XOutputStream.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_NUMBEREDSORTINGINFO_HPP_ +#include <com/sun/star/ucb/NumberedSortingInfo.hpp> +#endif +#ifndef _COM_SUN_STAR_IO_XACTIVEDATASINK_HPP_ +#include <com/sun/star/io/XActiveDataSink.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_PROPERTYCHANGEEVENT_HPP_ +#include <com/sun/star/beans/PropertyChangeEvent.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_PROPERTYSETINFOCHANGE_HPP_ +#include <com/sun/star/beans/PropertySetInfoChange.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_CONTENTACTION_HPP_ +#include <com/sun/star/ucb/ContentAction.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_NAMECLASH_HPP_ +#include <com/sun/star/ucb/NameClash.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_CONTENTINFOATTRIBUTE_HPP_ +#include <com/sun/star/ucb/ContentInfoAttribute.hpp> +#endif + +#ifndef _FILGLOB_HXX_ +#include "filglob.hxx" +#endif +#ifndef _FILID_HXX_ +#include "filid.hxx" +#endif +#ifndef _FILROW_HXX_ +#include "filrow.hxx" +#endif +#ifndef _BC_HXX_ +#include "bc.hxx" +#endif +#ifndef _PROV_HXX_ +#include "prov.hxx" +#endif + +using namespace fileaccess; +using namespace com::sun::star; +using namespace com::sun::star::ucb; + +// PropertyListeners + + +typedef cppu::OMultiTypeInterfaceContainerHelperVar< rtl::OUString,hashOUString,equalOUString > +PropertyListeners_impl; + +class fileaccess::PropertyListeners + : public PropertyListeners_impl +{ +public: + PropertyListeners( ::osl::Mutex& aMutex ) + : PropertyListeners_impl( aMutex ) + { + } +}; + + +/****************************************************************************************/ +/* */ +/* BaseContent */ +/* */ +/****************************************************************************************/ + +//////////////////////////////////////////////////////////////////////////////// +// Private Constructor for just inserted Contents + +BaseContent::BaseContent( shell* pMyShell, + const rtl::OUString& parentName, + sal_Bool bFolder ) + : m_pMyShell( pMyShell ), + m_xContentIdentifier( 0 ), + m_pDisposeEventListeners( 0 ), + m_pContentEventListeners( 0 ), + m_pPropertySetInfoChangeListeners( 0 ), + m_pPropertyListener( 0 ), + m_aUncPath( parentName ), + m_nState( JustInserted ), + m_bFolder( bFolder ) +{ + m_pMyShell->m_pProvider->acquire(); + // No registering, since we have no name +} + + +//////////////////////////////////////////////////////////////////////////////// +// Constructor for full featured Contents + +BaseContent::BaseContent( shell* pMyShell, + const uno::Reference< XContentIdentifier >& xContentIdentifier, + const rtl::OUString& aUncPath ) + : m_pMyShell( pMyShell ), + m_xContentIdentifier( xContentIdentifier ), + m_pDisposeEventListeners( 0 ), + m_pContentEventListeners( 0 ), + m_pPropertySetInfoChangeListeners( 0 ), + m_pPropertyListener( 0 ), + m_aUncPath( aUncPath ), + m_nState( FullFeatured ), + m_bFolder( false ) +{ + m_pMyShell->m_pProvider->acquire(); + m_pMyShell->registerNotifier( m_aUncPath,this ); + m_pMyShell->InsertDefaultProperties( m_aUncPath ); +} + + +BaseContent::~BaseContent( ) +{ + if( ( m_nState & FullFeatured ) || ( m_nState & Deleted ) ) + { + m_pMyShell->deregisterNotifier( m_aUncPath,this ); + } + m_pMyShell->m_pProvider->release(); + + if( m_pDisposeEventListeners ) + delete m_pDisposeEventListeners; + if( m_pContentEventListeners ) + delete m_pContentEventListeners; + if( m_pPropertyListener ) + delete m_pPropertyListener; + if( m_pPropertySetInfoChangeListeners ) + delete m_pPropertySetInfoChangeListeners; +} + + +////////////////////////////////////////////////////////////////////////// +// XInterface +////////////////////////////////////////////////////////////////////////// + +void SAL_CALL +BaseContent::acquire( void ) + throw( uno::RuntimeException ) +{ + OWeakObject::acquire(); +} + + +void SAL_CALL +BaseContent::release( void ) + throw( uno::RuntimeException ) +{ + OWeakObject::release(); +} + + +uno::Any SAL_CALL +BaseContent::queryInterface( const uno::Type& rType ) + throw( uno::RuntimeException ) +{ + uno::Any aRet = cppu::queryInterface( rType, + SAL_STATIC_CAST( lang::XComponent*, this ), + SAL_STATIC_CAST( XCommandProcessor*, this ), + SAL_STATIC_CAST( container::XChild*, this ), + SAL_STATIC_CAST( beans::XPropertiesChangeNotifier*, this ), + SAL_STATIC_CAST( beans::XPropertyContainer*, this ), + SAL_STATIC_CAST( XContentCreator*,this ), + SAL_STATIC_CAST( beans::XPropertySetInfoChangeNotifier*, this ), + SAL_STATIC_CAST( XContent*,this) ); + return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ); +} + + + + +////////////////////////////////////////////////////////////////////////////////////////// +// XComponent +//////////////////////////////////////////////////////////////////////////////////////// + +void SAL_CALL +BaseContent::addEventListener( const uno::Reference< lang::XEventListener >& Listener ) + throw( uno::RuntimeException ) +{ + vos::OGuard aGuard( m_aMutex ); + + if ( ! m_pDisposeEventListeners ) + m_pDisposeEventListeners = + new cppu::OInterfaceContainerHelper( m_aEventListenerMutex ); + + m_pDisposeEventListeners->addInterface( Listener ); +} + + +void SAL_CALL +BaseContent::removeEventListener( const uno::Reference< lang::XEventListener >& Listener ) + throw( uno::RuntimeException ) +{ + vos::OGuard aGuard( m_aMutex ); + + if ( m_pDisposeEventListeners ) + m_pDisposeEventListeners->removeInterface( Listener ); +} + + +void SAL_CALL +BaseContent::dispose() + throw( uno::RuntimeException ) +{ + vos::OGuard aGuard( m_aMutex ); + lang::EventObject aEvt; + aEvt.Source = static_cast< XContent* >( this ); + + if ( m_pDisposeEventListeners && m_pDisposeEventListeners->getLength() ) + m_pDisposeEventListeners->disposeAndClear( aEvt ); + + if ( m_pContentEventListeners && m_pContentEventListeners->getLength() ) + m_pContentEventListeners->disposeAndClear( aEvt ); + + if( m_pPropertyListener ) + m_pPropertyListener->disposeAndClear( aEvt ); + + if( m_pPropertySetInfoChangeListeners ) + m_pPropertySetInfoChangeListeners->disposeAndClear( aEvt ); + +} + + +////////////////////////////////////////////////////////////////////////////////////////// +// XCommandProcessor +////////////////////////////////////////////////////////////////////////////////////////// + +sal_Int32 SAL_CALL +BaseContent::createCommandIdentifier( void ) + throw( uno::RuntimeException ) +{ + return m_pMyShell->getCommandId(); +} + + +void SAL_CALL +BaseContent::abort( sal_Int32 CommandId ) + throw( uno::RuntimeException ) +{ + m_pMyShell->abort( CommandId ); +} + + +uno::Any SAL_CALL +BaseContent::execute( const Command& aCommand, + sal_Int32 CommandId, + const uno::Reference< XCommandEnvironment >& Environment ) + throw( uno::Exception, + CommandAbortedException, + uno::RuntimeException ) +{ + if( CommandId ) + { + uno::Reference< task::XInteractionHandler > xIH( 0 ); + uno::Reference< ucb::XProgressHandler > xPH( 0 ); + + if( Environment.is() ) + { + xIH = Environment->getInteractionHandler(); + xPH = Environment->getProgressHandler(); + } + m_pMyShell->startTask( CommandId, + xIH, + xPH ); + } + + uno::Any aAny; + sal_Bool success = true; // Hope the best + + try + { + if( ! aCommand.Name.compareToAscii( "getPropertySetInfo" ) ) + { + aAny <<= getPropertySetInfo( CommandId ); + } + else if( ! aCommand.Name.compareToAscii( "getCommandInfo" ) ) + { + aAny <<= getCommandInfo( CommandId ); + } + else if( ! aCommand.Name.compareToAscii( "setPropertyValues" ) ) + { + uno::Sequence< beans::PropertyValue > sPropertyValues; + + if( ! ( aCommand.Argument >>= sPropertyValues ) ) + throw CommandAbortedException(); + + setPropertyValues( CommandId,sPropertyValues ); + aAny <<= getCppuVoidType(); + } + else if( ! aCommand.Name.compareToAscii( "getPropertyValues" ) ) + { + uno::Sequence< beans::Property > ListOfRequestedProperties; + + if( ! ( aCommand.Argument >>= ListOfRequestedProperties ) ) + throw CommandAbortedException(); + + aAny <<= getPropertyValues( CommandId, + ListOfRequestedProperties ); + } + else if( ! aCommand.Name.compareToAscii( "open" ) ) + { + OpenCommandArgument2 aOpenArgument; + OpenCommandArgument aFalseCommandArgument; + if( ! ( aCommand.Argument >>= aOpenArgument ) ) + { + if( ! ( aCommand.Argument >>= aFalseCommandArgument ) ) + throw CommandAbortedException(); + + aOpenArgument.Mode = aFalseCommandArgument.Mode; + aOpenArgument.Priority = aFalseCommandArgument.Priority; + aOpenArgument.Sink = aFalseCommandArgument.Sink; + aOpenArgument.Properties = aFalseCommandArgument.Properties; + aOpenArgument.SortingInfo = uno::Sequence< NumberedSortingInfo >( 0 ); + } + + uno::Reference< XDynamicResultSet > result = open( CommandId,aOpenArgument ); + if( result.is() ) + { + aAny <<= result; + } + else + { + aAny <<= getCppuVoidType(); + } + } + else if( ! aCommand.Name.compareToAscii( "delete" ) ) + { + sal_Bool aDeleteArgument; + if( ! ( aCommand.Argument >>= aDeleteArgument ) ) + throw CommandAbortedException(); + deleteContent( CommandId, + aDeleteArgument ); + aAny <<= getCppuVoidType(); + } + else if( ! aCommand.Name.compareToAscii( "transfer" ) ) + { + TransferInfo aTransferInfo; + if( ! ( aCommand.Argument >>= aTransferInfo ) ) + throw CommandAbortedException(); + transfer( CommandId, + aTransferInfo ); + aAny <<= getCppuVoidType(); + } + else if( ! aCommand.Name.compareToAscii( "insert" ) ) + { + InsertCommandArgument aInsertArgument; + if( ! ( aCommand.Argument >>= aInsertArgument ) ) + throw CommandAbortedException(); + + insert( CommandId,aInsertArgument ); + aAny <<= getCppuVoidType(); + } + else if( ! aCommand.Name.compareToAscii( "update" ) ) + { + aAny <<= getCppuVoidType(); + } + else + { + success = false; + } + + if( CommandId ) + m_pMyShell->endTask( CommandId ); + + if( ! success ) + throw CommandAbortedException(); + + return aAny; + } + catch( ... ) + { + if( CommandId ) + m_pMyShell->endTask( CommandId ); + throw; + } +} + + + + + +void SAL_CALL +BaseContent::addPropertiesChangeListener( + const uno::Sequence< rtl::OUString >& PropertyNames, + const uno::Reference< beans::XPropertiesChangeListener >& Listener ) + throw( uno::RuntimeException ) +{ + if( ! Listener.is() ) + return; + + vos::OGuard aGuard( m_aMutex ); + + if( ! m_pPropertyListener ) + m_pPropertyListener = new PropertyListeners( m_aEventListenerMutex ); + + + if( PropertyNames.getLength() == 0 ) + m_pPropertyListener->addInterface( rtl::OUString(),Listener ); + else + { + uno::Reference< beans::XPropertySetInfo > xProp = m_pMyShell->info_p( -1,m_aUncPath ); + for( sal_Int32 i = 0; i < PropertyNames.getLength(); ++i ) + if( xProp->hasPropertyByName( PropertyNames[i] ) ) + m_pPropertyListener->addInterface( PropertyNames[i],Listener ); + } +} + + +void SAL_CALL +BaseContent::removePropertiesChangeListener( const uno::Sequence< rtl::OUString >& PropertyNames, + const uno::Reference< beans::XPropertiesChangeListener >& Listener ) + throw( com::sun::star::uno::RuntimeException ) +{ + if( ! Listener.is() || ! m_pPropertyListener ) + return; + + vos::OGuard aGuard( m_aMutex ); + + for( sal_Int32 i = 0; i < PropertyNames.getLength(); ++i ) + m_pPropertyListener->removeInterface( PropertyNames[i],Listener ); + + m_pPropertyListener->removeInterface( rtl::OUString(), Listener ); +} + + +///////////////////////////////////////////////////////////////////////////////////////// +// XContent +///////////////////////////////////////////////////////////////////////////////////////// + +uno::Reference< ucb::XContentIdentifier > SAL_CALL +BaseContent::getIdentifier() + throw( uno::RuntimeException ) +{ + return m_xContentIdentifier; +} + + +rtl::OUString SAL_CALL +BaseContent::getContentType() + throw( uno::RuntimeException ) +{ + if( !( m_nState & Deleted ) ) + { + if( m_nState & JustInserted ) + { + if ( m_bFolder ) + return m_pMyShell->FolderContentType; + else + return m_pMyShell->FileContentType; + } + else + { + try + { + // Who am I ? + uno::Sequence< beans::Property > seq(1); + seq[0] = beans::Property( rtl::OUString::createFromAscii("IsDocument"), + -1, + getCppuType( static_cast< sal_Bool* >(0) ), + 0 ); + uno::Reference< sdbc::XRow > xRow = getPropertyValues( -1,seq ); + sal_Bool IsDocument = xRow->getBoolean( 1 ); + + if ( !xRow->wasNull() ) + { + if ( IsDocument ) + return m_pMyShell->FileContentType; + else + return m_pMyShell->FolderContentType; + } + else + { + VOS_ENSURE( false, + "BaseContent::getContentType - Property value was null!" ); + } + } + catch ( sdbc::SQLException const & ) + { + VOS_ENSURE( false, + "BaseContent::getContentType - Caught SQLException!" ); + } + } + } + + return rtl::OUString(); +} + + + +void SAL_CALL +BaseContent::addContentEventListener( + const uno::Reference< XContentEventListener >& Listener ) + throw( uno::RuntimeException ) +{ + vos::OGuard aGuard( m_aMutex ); + + if ( ! m_pContentEventListeners ) + m_pContentEventListeners = + new cppu::OInterfaceContainerHelper( m_aEventListenerMutex ); + + + m_pContentEventListeners->addInterface( Listener ); +} + + +void SAL_CALL +BaseContent::removeContentEventListener( + const uno::Reference< XContentEventListener >& Listener ) + throw( uno::RuntimeException ) +{ + vos::OGuard aGuard( m_aMutex ); + + if ( m_pContentEventListeners ) + m_pContentEventListeners->removeInterface( Listener ); +} + + + +//////////////////////////////////////////////////////////////////////////////// +// XPropertyContainer +//////////////////////////////////////////////////////////////////////////////// + + +void SAL_CALL +BaseContent::addProperty( + const rtl::OUString& Name, + sal_Int16 Attributes, + const uno::Any& DefaultValue ) + throw( beans::PropertyExistException, + beans::IllegalTypeException, + lang::IllegalArgumentException, + uno::RuntimeException) +{ + if( ( m_nState & JustInserted ) || ( m_nState & Deleted ) || Name == rtl::OUString() ) + { + throw lang::IllegalArgumentException(); + } + + m_pMyShell->associate( m_aUncPath,Name,DefaultValue,Attributes ); +} + + +void SAL_CALL +BaseContent::removeProperty( + const rtl::OUString& Name ) + throw( beans::UnknownPropertyException, + beans::NotRemoveableException, + uno::RuntimeException) +{ + + if( m_nState & Deleted ) + throw beans::UnknownPropertyException(); + + m_pMyShell->deassociate( m_aUncPath, Name ); +} + +//////////////////////////////////////////////////////////////////////////////// +// XContentCreator +//////////////////////////////////////////////////////////////////////////////// + +uno::Sequence< ContentInfo > SAL_CALL +BaseContent::queryCreatableContentsInfo( + void ) + throw( uno::RuntimeException ) +{ + uno::Sequence< ContentInfo > seq(2); + + // file + seq[0].Type = m_pMyShell->FileContentType; + seq[0].Attributes = ContentInfoAttribute::INSERT_WITH_INPUTSTREAM; + + uno::Sequence< beans::Property > props( 1 ); + props[0] = beans::Property( + rtl::OUString::createFromAscii( "Title" ), + -1, + getCppuType( static_cast< rtl::OUString* >( 0 ) ), + beans::PropertyAttribute::MAYBEVOID + | beans::PropertyAttribute::BOUND ); + seq[0].Properties = props; + + // folder + seq[1].Type = m_pMyShell->FolderContentType; + seq[1].Attributes = 0; + seq[1].Properties = props; + return seq; +} + + +uno::Reference< XContent > SAL_CALL +BaseContent::createNewContent( + const ContentInfo& Info ) + throw( uno::RuntimeException ) +{ + // Check type. + if ( !Info.Type.getLength() ) + return uno::Reference< XContent >(); + + sal_Bool bFolder + = ( Info.Type.compareTo( m_pMyShell->FolderContentType ) == 0 ); + if ( !bFolder ) + { + if ( Info.Type.compareTo( m_pMyShell->FileContentType ) != 0 ) + { + // Neither folder nor file to create! + return uno::Reference< XContent >(); + } + } + + // Who am I ? + sal_Bool IsDocument = false; + + try + { + uno::Sequence< beans::Property > seq(1); + seq[0] = beans::Property( rtl::OUString::createFromAscii("IsDocument"), + -1, + getCppuType( static_cast< sal_Bool* >(0) ), + 0 ); + uno::Reference< sdbc::XRow > xRow = getPropertyValues( -1,seq ); + IsDocument = xRow->getBoolean( 1 ); + + if ( xRow->wasNull() ) + { + VOS_ENSURE( false, + "BaseContent::createNewContent - Property value was null!" ); + return uno::Reference< XContent >(); + } + } + catch ( sdbc::SQLException const & ) + { + VOS_ENSURE( false, + "BaseContent::createNewContent - Caught SQLException!" ); + return uno::Reference< XContent >(); + } + + rtl::OUString dstUncPath; + + if( IsDocument ) + { + // KSO: Why is a document a XContentCreator? This is quite unusual. + dstUncPath = m_pMyShell->getParentName( m_aUncPath ); + } + else + dstUncPath = m_aUncPath; + + BaseContent* p = new BaseContent( m_pMyShell, dstUncPath, bFolder ); + return uno::Reference< XContent >( p ); +} + + +//////////////////////////////////////////////////////////////////////////////// +// XPropertySetInfoChangeNotifier +//////////////////////////////////////////////////////////////////////////////// + + +void SAL_CALL +BaseContent::addPropertySetInfoChangeListener( + const uno::Reference< beans::XPropertySetInfoChangeListener >& Listener ) + throw( uno::RuntimeException ) +{ + vos::OGuard aGuard( m_aMutex ); + if( ! m_pPropertySetInfoChangeListeners ) + m_pPropertySetInfoChangeListeners = new cppu::OInterfaceContainerHelper( m_aEventListenerMutex ); + + m_pPropertySetInfoChangeListeners->addInterface( Listener ); +} + + +void SAL_CALL +BaseContent::removePropertySetInfoChangeListener( + const uno::Reference< beans::XPropertySetInfoChangeListener >& Listener ) + throw( uno::RuntimeException ) +{ + vos::OGuard aGuard( m_aMutex ); + + if( m_pPropertySetInfoChangeListeners ) + m_pPropertySetInfoChangeListeners->removeInterface( Listener ); +} + + +//////////////////////////////////////////////////////////////////////////////// +// XChild +//////////////////////////////////////////////////////////////////////////////// + +uno::Reference< uno::XInterface > SAL_CALL +BaseContent::getParent( + void ) + throw( uno::RuntimeException ) +{ + rtl::OUString ParentUnq = m_pMyShell->getParentName( m_aUncPath ); + rtl::OUString ParentUrl; + + + sal_Bool err = m_pMyShell->getUrlFromUnq( ParentUnq, ParentUrl ); + if( err ) + return uno::Reference< uno::XInterface >( 0 ); + + FileContentIdentifier* p = new FileContentIdentifier( m_pMyShell,ParentUnq ); + uno::Reference< XContentIdentifier > Identifier( p ); + + try + { + uno::Reference< XContent > content = m_pMyShell->m_pProvider->queryContent( Identifier ); + return content; + } + catch( IllegalIdentifierException ) + { + return uno::Reference< uno::XInterface >(); + } +} + + +void SAL_CALL +BaseContent::setParent( + const uno::Reference< uno::XInterface >& Parent ) + throw( lang::NoSupportException, + uno::RuntimeException) +{ + throw lang::NoSupportException(); +} + + +////////////////////////////////////////////////////////////////////////////////////////// +// Private Methods +////////////////////////////////////////////////////////////////////////////////////////// + + +uno::Reference< XCommandInfo > SAL_CALL +BaseContent::getCommandInfo( + sal_Int32 nMyCommandIdentifier ) + throw( uno::RuntimeException ) +{ + if( m_nState & Deleted ) + return uno::Reference< XCommandInfo >(); + + return m_pMyShell->info_c( nMyCommandIdentifier,m_aUncPath ); +} + + +uno::Reference< beans::XPropertySetInfo > SAL_CALL +BaseContent::getPropertySetInfo( + sal_Int32 nMyCommandIdentifier ) + throw( uno::RuntimeException ) +{ + if( m_nState & Deleted ) + return uno::Reference< beans::XPropertySetInfo >(); + + return m_pMyShell->info_p( nMyCommandIdentifier,m_aUncPath ); +} + + + + +uno::Reference< sdbc::XRow > SAL_CALL +BaseContent::getPropertyValues( + sal_Int32 nMyCommandIdentifier, + const uno::Sequence< beans::Property >& PropertySet ) + throw( uno::RuntimeException ) +{ + sal_Int32 nProps = PropertySet.getLength(); + if ( !nProps ) + return uno::Reference< sdbc::XRow >(); + + if( m_nState & Deleted ) + { + uno::Sequence< uno::Any > aValues( nProps ); + return uno::Reference< sdbc::XRow >( new XRow_impl( m_pMyShell, aValues ) ); + } + + if( m_nState & JustInserted ) + { + uno::Sequence< uno::Any > aValues( nProps ); + uno::Any* pValues = aValues.getArray(); + + const beans::Property* pProps = PropertySet.getConstArray(); + + for ( sal_Int32 n = 0; n < nProps; ++n ) + { + const beans::Property& rProp = pProps[ n ]; + uno::Any& rValue = pValues[ n ]; + + if ( rProp.Name.compareToAscii( "ContentType" ) == 0 ) + { + rValue <<= m_bFolder ? m_pMyShell->FolderContentType + : m_pMyShell->FileContentType; + } + else if ( rProp.Name.compareToAscii( "IsFolder" ) == 0 ) + { + rValue <<= m_bFolder; + } + else if ( rProp.Name.compareToAscii( "IsDocument" ) == 0 ) + { + rValue <<= sal_Bool( !m_bFolder ); + } +// else +// rValue = uno::Any(); + } + + return uno::Reference< sdbc::XRow >( + new XRow_impl( m_pMyShell, aValues ) ); + } + + return m_pMyShell->getv( nMyCommandIdentifier, + m_aUncPath, + PropertySet ); +} + + +void SAL_CALL +BaseContent::setPropertyValues( + sal_Int32 nMyCommandIdentifier, + const uno::Sequence< beans::PropertyValue >& Values ) + throw( uno::RuntimeException ) +{ + if( m_nState & Deleted ) + { + return; + } + + rtl::OUString Title = rtl::OUString::createFromAscii( "Title" ); + sal_Unicode slash = '/'; + + + // Special handling for files which have to be inserted + if( m_nState & JustInserted ) + { + for( sal_Int32 i = 0; i < Values.getLength(); ++i ) + { + + if( Values[i].Name == Title && ! ( m_nState & NameForInsertionSet ) ) + { + rtl::OUString NewTitle; + if( Values[i].Value >>= NewTitle ) + { + if( m_aUncPath.lastIndexOf( sal_Unicode('/') ) != m_aUncPath.getLength() - 1 ) + m_aUncPath += rtl::OUString::createFromAscii("/"); + + m_aUncPath += NewTitle; + m_nState |= NameForInsertionSet; + } + } + } + } + else + { + m_pMyShell->setv( nMyCommandIdentifier, // Does not handle Title + m_aUncPath, + Values ); + + + + // Special handling Title: Setting Title is equivalent to a renaming of the underlying file + for( sal_Int32 i = 0; i < Values.getLength(); ++i ) + { + if( Values[i].Name == Title ) + { + rtl::OUString NewTitle; + if( Values[i].Value >>= NewTitle ) + { + rtl::OUString aDstName = m_pMyShell->getParentName( m_aUncPath ); + if( aDstName.lastIndexOf( sal_Unicode('/') ) != aDstName.getLength() - 1 ) + aDstName += rtl::OUString::createFromAscii("/"); + + aDstName += NewTitle; + + m_pMyShell->move( nMyCommandIdentifier, // move notifies the childs also ; + m_aUncPath, + aDstName, + NameClash::KEEP ); + } + // NameChanges come back trough a ContentEvent + // + break; + } + } + } +} + + + +uno::Reference< XDynamicResultSet > SAL_CALL +BaseContent::open( + sal_Int32 nMyCommandIdentifier, + const OpenCommandArgument2& aCommandArgument ) + throw( CommandAbortedException ) +{ + if( ( m_nState & Deleted ) || ( m_nState & JustInserted ) ) + return uno::Reference< XDynamicResultSet >(); + + + uno::Reference< io::XOutputStream > outputStream( aCommandArgument.Sink,uno::UNO_QUERY ); + if( outputStream.is() ) + { + m_pMyShell->page( nMyCommandIdentifier, + m_aUncPath, + outputStream ); + } + + uno::Reference< io::XActiveDataSink > activeDataSink( aCommandArgument.Sink,uno::UNO_QUERY ); + if( activeDataSink.is() ) + { + activeDataSink->setInputStream( m_pMyShell->open( nMyCommandIdentifier, + m_aUncPath ) ); + } + + + uno::Reference< io::XActiveDataStreamer > activeDataStreamer( aCommandArgument.Sink,uno::UNO_QUERY ); + if( activeDataStreamer.is() ) + { + activeDataStreamer->setStream( m_pMyShell->open_rw( nMyCommandIdentifier, + m_aUncPath ) ); + } + + return m_pMyShell->ls( nMyCommandIdentifier, + m_aUncPath, + aCommandArgument.Mode, + aCommandArgument.Properties, + aCommandArgument.SortingInfo ); +} + + +void SAL_CALL +BaseContent::deleteContent( sal_Int32 nMyCommandIdentifier, + sal_Bool bDeleteArgument ) +{ + if( m_nState & Deleted ) + return; + m_pMyShell->remove( nMyCommandIdentifier, + m_aUncPath ); + + vos::OGuard aGuard( m_aMutex ); + m_nState |= Deleted; +} + + + +void SAL_CALL +BaseContent::transfer( sal_Int32 nMyCommandIdentifier, + const TransferInfo& aTransferInfo ) + throw( CommandAbortedException ) +{ + + if( m_nState & Deleted ) + return; + + // No write access to route + if( m_pMyShell->m_bFaked && m_aUncPath.compareToAscii( "//./" ) == 0 ) + throw CommandAbortedException(); + + sal_Unicode slash = '/'; + rtl::OUString srcUnc; + sal_Bool err = m_pMyShell->getUnqFromUrl( aTransferInfo.SourceURL,srcUnc ); + if( err ) + throw CommandAbortedException(); + + rtl::OUString srcUncPath; + sal_Bool mounted = m_pMyShell->checkMountPoint( srcUnc,srcUncPath ); + + if( ! mounted ) + throw CommandAbortedException(); + + rtl::OUString NewTitle; + if( aTransferInfo.NewTitle.getLength() ) + NewTitle = aTransferInfo.NewTitle; + else + { + sal_Int32 lastSlash = srcUncPath.lastIndexOf( slash ); + NewTitle = srcUncPath.copy( lastSlash+1 ); + } + + + // Who am I ? + uno::Sequence< beans::Property > seq(1); + seq[0] = beans::Property( rtl::OUString::createFromAscii("IsDocument"), + -1, + getCppuType( static_cast< sal_Bool* >(0) ), + 0 ); + uno::Reference< sdbc::XRow > xRow = getPropertyValues( nMyCommandIdentifier,seq ); + sal_Bool IsDocument = xRow->getBoolean( 1 ); + if( xRow->wasNull() ) + throw CommandAbortedException(); + + + rtl::OUString dstUncPath; + + if( IsDocument ) { + sal_Int32 lastSlash = m_aUncPath.lastIndexOf( slash ); + dstUncPath = m_aUncPath.copy(0,lastSlash ); + } + else + dstUncPath = m_aUncPath; + + dstUncPath += ( rtl::OUString::createFromAscii( "/" ) + NewTitle ); + + sal_Int32 NameClash = aTransferInfo.NameClash; + + if( aTransferInfo.MoveData ) + m_pMyShell->move( nMyCommandIdentifier,srcUncPath,dstUncPath,NameClash ); + else + m_pMyShell->copy( nMyCommandIdentifier,srcUncPath,dstUncPath,NameClash ); +} + + +void SAL_CALL +BaseContent::write( sal_Int32 nMyCommandIdentifier, + sal_Bool OverWrite, + const uno::Reference< io::XInputStream >& aInputStream ) + throw( CommandAbortedException ) +{ + sal_Bool err = ! m_pMyShell->write( nMyCommandIdentifier, + m_aUncPath, + OverWrite, + aInputStream ); + if( err ) + throw CommandAbortedException() ; +} + + + + +void SAL_CALL BaseContent::insert( sal_Int32 nMyCommandIdentifier, + const InsertCommandArgument& aInsertArgument ) + throw( CommandAbortedException ) +{ + if( m_nState & FullFeatured ) + { + write( nMyCommandIdentifier, + aInsertArgument.ReplaceExisting, + aInsertArgument.Data ); + return; + } + + if( ! ( m_nState & JustInserted ) ) + return; + + // Inserts the content, which has the flag m_bIsFresh + + sal_Bool success = ( m_nState & NameForInsertionSet ); + if( success ) + { + // Who am I ? + sal_Bool bDocument = false; + + try + { + uno::Sequence< beans::Property > seq(1); + seq[0] = beans::Property( rtl::OUString::createFromAscii("IsDocument"), + -1, + getCppuType( static_cast< sal_Bool* >(0) ), + 0 ); + uno::Reference< sdbc::XRow > xRow = getPropertyValues( -1,seq ); + bDocument = xRow->getBoolean( 1 ); + + success = !xRow->wasNull(); + + VOS_ENSURE( success, + "BaseContent::insert - Property value was null!" ); + } + catch ( sdbc::SQLException const & ) + { + VOS_ENSURE( false, + "BaseContent::insert - Caught SQLException!" ); + success = false; + } + + if ( success ) + { + if( bDocument ) + { + success = m_pMyShell->mkfil( nMyCommandIdentifier, + m_aUncPath, + aInsertArgument.ReplaceExisting, + aInsertArgument.Data ); + } + else + { + success = m_pMyShell->mkdir( nMyCommandIdentifier, + m_aUncPath ); + } + } + } + + if( ! success ) + { + throw CommandAbortedException(); + } + + FileContentIdentifier* p = new FileContentIdentifier( m_pMyShell,m_aUncPath ); + m_xContentIdentifier = uno::Reference< XContentIdentifier >( p ); + + m_pMyShell->registerNotifier( m_aUncPath,this ); + m_pMyShell->InsertDefaultProperties( m_aUncPath ); + + vos::OGuard aGuard( m_aMutex ); + m_nState = FullFeatured; +} + + + +ContentEventNotifier* +BaseContent::cDEL( void ) +{ + vos::OGuard aGuard( m_aMutex ); + + m_nState |= Deleted; + + ContentEventNotifier* p; + if( m_pContentEventListeners ) + p = new ContentEventNotifier( m_pMyShell, + this, + m_xContentIdentifier, + m_pContentEventListeners->getElements() ); + else + p = 0; + + return p; +} + + +ContentEventNotifier* +BaseContent::cEXC( const rtl::OUString aNewName ) +{ + vos::OGuard aGuard( m_aMutex ); + + uno::Reference< XContentIdentifier > xOldRef = m_xContentIdentifier; + m_aUncPath = aNewName; + FileContentIdentifier* pp = new FileContentIdentifier( m_pMyShell,aNewName ); + m_xContentIdentifier = uno::Reference< XContentIdentifier >( pp ); + + ContentEventNotifier* p = 0; + if( m_pContentEventListeners ) + p = new ContentEventNotifier( m_pMyShell, + this, + m_xContentIdentifier, + xOldRef, + m_pContentEventListeners->getElements() ); + + return p; +} + + +ContentEventNotifier* +BaseContent::cCEL( void ) +{ + vos::OGuard aGuard( m_aMutex ); + ContentEventNotifier* p = 0; + if( m_pContentEventListeners ) + p = new ContentEventNotifier( m_pMyShell, + this, + m_xContentIdentifier, + m_pContentEventListeners->getElements() ); + + return p; +} + +PropertySetInfoChangeNotifier* +BaseContent::cPSL( void ) +{ + vos::OGuard aGuard( m_aMutex ); + PropertySetInfoChangeNotifier* p = 0; + if( m_pPropertySetInfoChangeListeners ) + p = new PropertySetInfoChangeNotifier( m_pMyShell, + this, + m_xContentIdentifier, + m_pPropertySetInfoChangeListeners->getElements() ); + + return p; +} + + + +PropertyChangeNotifier* +BaseContent::cPCL( void ) +{ + vos::OGuard aGuard( m_aMutex ); + + uno::Sequence< rtl::OUString > seqNames; + + if( m_pPropertyListener ) + seqNames = m_pPropertyListener->getContainedTypes(); + + PropertyChangeNotifier* p = 0; + + sal_Int32 length = seqNames.getLength(); + + if( length ) + { + ListenerMap* listener = new ListenerMap(); + for( sal_Int32 i = 0; i < length; ++i ) + { + (*listener)[seqNames[i]] = m_pPropertyListener->getContainer( seqNames[i] )->getElements(); + } + + p = new PropertyChangeNotifier( m_pMyShell, + this, + m_xContentIdentifier, + listener ); + } + + return p; +} + + +rtl::OUString BaseContent::getKey( void ) +{ + return m_aUncPath; +} diff --git a/ucb/source/ucp/file/bc.hxx b/ucb/source/ucp/file/bc.hxx new file mode 100644 index 000000000000..4f616bbb7613 --- /dev/null +++ b/ucb/source/ucp/file/bc.hxx @@ -0,0 +1,414 @@ +/************************************************************************* + * + * $RCSfile: bc.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:53:36 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _BC_HXX_ +#define _BC_HXX_ + +#ifndef _VOS_MUTEX_HXX_ +#include <vos/mutex.hxx> +#endif +#ifndef _RTL_USTRING_ +#include <rtl/ustring> +#endif +#ifndef _CPPUHELPER_WEAK_HXX_ +#include <cppuhelper/weak.hxx> +#endif +#ifndef _CPPUHELPER_INTERFACECONTAINER_H_ +#include <cppuhelper/interfacecontainer.h> +#endif +#ifndef _COM_SUN_STAR_UNO_XINTERFACE_HPP_ +#include <com/sun/star/uno/XInterface.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XCOMPONENT_HPP_ +#include <com/sun/star/lang/XComponent.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCOMMANDPROCESSOR_HPP_ +#include <com/sun/star/ucb/XCommandProcessor.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_XPROPERTIESCHANGENOTIFIER_HPP_ +#include <com/sun/star/beans/XPropertiesChangeNotifier.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCONTENT_HPP_ +#include <com/sun/star/ucb/XContent.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCONTENTPROVIDER_HPP_ +#include <com/sun/star/ucb/XContentProvider.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XRESULTSET_HPP_ +#include <com/sun/star/ucb/XDynamicResultSet.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_ +#include <com/sun/star/sdbc/XRow.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_PROPERTYCHANGEEVENT_HPP_ +#include <com/sun/star/beans/PropertyChangeEvent.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_PROPERTY_HPP_ +#include <com/sun/star/beans/Property.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_ +#include <com/sun/star/beans/PropertyValue.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCOMMANDINFO_HPP_ +#include <com/sun/star/ucb/XCommandInfo.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_INSERTCOMMANDARGUMENT_HPP_ +#include <com/sun/star/ucb/InsertCommandArgument.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSETINFO_HPP_ +#include <com/sun/star/beans/XPropertySetInfo.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_XPROPERTYCONTAINER_HPP_ +#include <com/sun/star/beans/XPropertyContainer.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSETINFOCHANGENOTIFIER_HPP_ +#include <com/sun/star/beans/XPropertySetInfoChangeNotifier.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSETINFOCHANGELISTENER_HPP_ +#include <com/sun/star/beans/XPropertySetInfoChangeListener.hpp> +#endif +#ifndef _COM_SUN_STAR_CONTAINER_XCHILD_HPP_ +#include <com/sun/star/container/XChild.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCONTENTCREATOR_HPP_ +#include <com/sun/star/ucb/XContentCreator.hpp> +#endif +#ifndef _COM_SUN_STAR_IO_XINPUTSTREAM_HPP_ +#include <com/sun/star/io/XInputStream.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_OPENCOMMANDARGUMENT2_HPP_ +#include <com/sun/star/ucb/OpenCommandArgument2.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_SHELL_HXX_ +#include "shell.hxx" +#endif + + +namespace fileaccess { + + class PropertyListeners; + class shell; + class FileProvider; + + class BaseContent: + public cppu::OWeakObject, + public com::sun::star::lang::XComponent, + public com::sun::star::ucb::XCommandProcessor, + public com::sun::star::beans::XPropertiesChangeNotifier, + public com::sun::star::beans::XPropertyContainer, + public com::sun::star::beans::XPropertySetInfoChangeNotifier, + public com::sun::star::ucb::XContentCreator, + public com::sun::star::container::XChild, + public com::sun::star::ucb::XContent, + public fileaccess::Notifier // implementation class + { + private: + + // A special creator for inserted contents; Creates an ugly object + BaseContent( shell* pMyShell, + const rtl::OUString& parentName, + sal_Bool bFolder ); + + public: + BaseContent( + shell* pMyShell, + const com::sun::star::uno::Reference< com::sun::star::ucb::XContentIdentifier >& xContentIdentifier, + const rtl::OUString& aUnqPath ); + + virtual ~BaseContent(); + + // XInterface + virtual com::sun::star::uno::Any SAL_CALL + queryInterface( + const com::sun::star::uno::Type& aType ) + throw( com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL + acquire( + void ) + throw( com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL + release( + void ) + throw( com::sun::star::uno::RuntimeException); + + + // XComponent + virtual void SAL_CALL + dispose( + void ) + throw( com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL + addEventListener( + const com::sun::star::uno::Reference< com::sun::star::lang::XEventListener >& xListener ) + throw( com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL + removeEventListener( const com::sun::star::uno::Reference< com::sun::star::lang::XEventListener >& aListener ) + throw( com::sun::star::uno::RuntimeException ); + + + // XCommandProcessor + virtual sal_Int32 SAL_CALL + createCommandIdentifier( + void ) + throw( com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::uno::Any SAL_CALL + execute( + const com::sun::star::ucb::Command& aCommand, + sal_Int32 CommandId, + const com::sun::star::uno::Reference< com::sun::star::ucb::XCommandEnvironment >& Environment ) + throw( com::sun::star::uno::Exception, + com::sun::star::ucb::CommandAbortedException, + com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL + abort( + sal_Int32 CommandId ) + throw( com::sun::star::uno::RuntimeException ); + + + // XContent + virtual com::sun::star::uno::Reference< com::sun::star::ucb::XContentIdentifier > SAL_CALL + getIdentifier( + void ) + throw( com::sun::star::uno::RuntimeException ); + + virtual rtl::OUString SAL_CALL + getContentType( + void ) + throw( com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL + addContentEventListener( + const com::sun::star::uno::Reference< com::sun::star::ucb::XContentEventListener >& Listener ) + throw( com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL + removeContentEventListener( + const com::sun::star::uno::Reference< com::sun::star::ucb::XContentEventListener >& Listener ) + throw( com::sun::star::uno::RuntimeException ); + + // XPropertiesChangeNotifier + + virtual void SAL_CALL + addPropertiesChangeListener( + const com::sun::star::uno::Sequence< rtl::OUString >& PropertyNames, + const com::sun::star::uno::Reference< + com::sun::star::beans::XPropertiesChangeListener >& Listener ) + throw( com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL + removePropertiesChangeListener( const com::sun::star::uno::Sequence< rtl::OUString >& PropertyNames, + const com::sun::star::uno::Reference< + com::sun::star::beans::XPropertiesChangeListener >& Listener ) + throw( com::sun::star::uno::RuntimeException ); + + // XPropertyContainer + + virtual void SAL_CALL + addProperty( + const rtl::OUString& Name, + sal_Int16 Attributes, + const com::sun::star::uno::Any& DefaultValue ) + throw( com::sun::star::beans::PropertyExistException, + com::sun::star::beans::IllegalTypeException, + com::sun::star::lang::IllegalArgumentException, + com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL + removeProperty( + const rtl::OUString& Name ) + throw( com::sun::star::beans::UnknownPropertyException, + com::sun::star::beans::NotRemoveableException, + com::sun::star::uno::RuntimeException ); + + // XPropertySetInfoChangeNotifier + + virtual void SAL_CALL + addPropertySetInfoChangeListener( + const com::sun::star::uno::Reference< + com::sun::star::beans::XPropertySetInfoChangeListener >& Listener ) + throw( com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL + removePropertySetInfoChangeListener( + const com::sun::star::uno::Reference< + com::sun::star::beans::XPropertySetInfoChangeListener >& Listener ) + throw( com::sun::star::uno::RuntimeException ); + + + // XContentCreator + + virtual com::sun::star::uno::Sequence< com::sun::star::ucb::ContentInfo > SAL_CALL + queryCreatableContentsInfo( + void ) + throw( com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::uno::Reference< com::sun::star::ucb::XContent > SAL_CALL + createNewContent( + const com::sun::star::ucb::ContentInfo& Info ) + throw( com::sun::star::uno::RuntimeException ); + + + // XChild + virtual com::sun::star::uno::Reference< com::sun::star::uno::XInterface > SAL_CALL + getParent( + void ) throw( com::sun::star::uno::RuntimeException ); + + // Not supported + virtual void SAL_CALL + setParent( const com::sun::star::uno::Reference< com::sun::star::uno::XInterface >& Parent ) + throw( com::sun::star::lang::NoSupportException, + com::sun::star::uno::RuntimeException); + + + // Notifier + + ContentEventNotifier* cDEL( void ); + ContentEventNotifier* cEXC( const rtl::OUString aNewName ); + ContentEventNotifier* cCEL( void ); + PropertySetInfoChangeNotifier* cPSL( void ); + PropertyChangeNotifier* cPCL( void ); + rtl::OUString getKey( void ); + + private: + // Data members + shell* m_pMyShell; + com::sun::star::uno::Reference< com::sun::star::ucb::XContentIdentifier > m_xContentIdentifier; + rtl::OUString m_aUncPath; + + enum state { NameForInsertionSet = 1, + JustInserted = 2, + Deleted = 4, + FullFeatured = 8, + Connected = 16 }; + sal_Bool m_bFolder; + sal_uInt16 m_nState; + + vos::OMutex m_aMutex; + + osl::Mutex m_aEventListenerMutex; + cppu::OInterfaceContainerHelper* m_pDisposeEventListeners; + cppu::OInterfaceContainerHelper* m_pContentEventListeners; + cppu::OInterfaceContainerHelper* m_pPropertySetInfoChangeListeners; + PropertyListeners* m_pPropertyListener; + + + // Private Methods + com::sun::star::uno::Reference< com::sun::star::ucb::XCommandInfo > SAL_CALL + getCommandInfo( + sal_Int32 nMyCommandIdentifier ) + throw( com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::uno::Reference< com::sun::star::beans::XPropertySetInfo > SAL_CALL + getPropertySetInfo( + sal_Int32 nMyCommandIdentifier ) + throw( com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::uno::Reference< com::sun::star::sdbc::XRow > SAL_CALL + getPropertyValues( + sal_Int32 nMyCommandIdentifier, + const com::sun::star::uno::Sequence< com::sun::star::beans::Property >& PropertySet ) + throw( com::sun::star::uno::RuntimeException ); + + void SAL_CALL + setPropertyValues( + sal_Int32 nMyCommandIdentifier, + const com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >& Values ) + throw( com::sun::star::uno::RuntimeException ); + + com::sun::star::uno::Reference< com::sun::star::ucb::XDynamicResultSet > SAL_CALL + open( + sal_Int32 nMyCommandIdentifier, + const com::sun::star::ucb::OpenCommandArgument2& aCommandArgument ) + throw( com::sun::star::ucb::CommandAbortedException ); + + void SAL_CALL + deleteContent( sal_Int32 nMyCommandIdentifier, + sal_Bool bDeleteArgument ); + + void SAL_CALL + transfer( sal_Int32 nMyCommandIdentifier, + const com::sun::star::ucb::TransferInfo& aTransferInfo ) + throw( com::sun::star::ucb::CommandAbortedException ); + + void SAL_CALL + insert( sal_Int32 nMyCommandIdentifier, + const com::sun::star::ucb::InsertCommandArgument& aInsertArgument ) + throw( com::sun::star::ucb::CommandAbortedException ); + + void SAL_CALL + write( sal_Int32 nMyCommandIdentifier, + sal_Bool OverWrite, + const com::sun::star::uno::Reference< com::sun::star::io::XInputStream >& aInputStream ) + throw( com::sun::star::ucb::CommandAbortedException ); + + friend class ContentEventNotifier; + }; + +} // end namespace fileaccess + +#endif + diff --git a/ucb/source/ucp/file/filglob.hxx b/ucb/source/ucp/file/filglob.hxx new file mode 100644 index 000000000000..a86327cf4809 --- /dev/null +++ b/ucb/source/ucp/file/filglob.hxx @@ -0,0 +1,92 @@ +/************************************************************************* + * + * $RCSfile: filglob.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:53:36 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _FILGLOB_HXX_ +#define _FILGLOB_HXX_ + +#ifndef _RTL_USTRING_ +#include <rtl/ustring> +#endif + + +namespace fileaccess { + + + struct equalOUString + { + bool operator()( const rtl::OUString& rKey1, const rtl::OUString& rKey2 ) const + { + return !!( rKey1 == rKey2 ); + } + }; + + + struct hashOUString + { + size_t operator()( const rtl::OUString& rName ) const + { + return rName.hashCode(); + } + }; + +} + + +#endif diff --git a/ucb/source/ucp/file/filid.cxx b/ucb/source/ucp/file/filid.cxx new file mode 100644 index 000000000000..ff5e46a15470 --- /dev/null +++ b/ucb/source/ucp/file/filid.cxx @@ -0,0 +1,192 @@ +/************************************************************************* + * + * $RCSfile: filid.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:53:36 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _FILID_HXX_ +#include "filid.hxx" +#endif +#ifndef _SHELL_HXX_ +#include "shell.hxx" +#endif + +using namespace fileaccess; +using namespace com::sun::star; +using namespace com::sun::star::ucb; + + +FileContentIdentifier::FileContentIdentifier( + shell* pMyShell, + const rtl::OUString& aUnqPath, + sal_Bool IsNormalized ) + : m_pMyShell( pMyShell ), + m_bNormalized( IsNormalized ) +{ + rtl::OUString aRedirectedPath; + + if( IsNormalized ) + { + m_pMyShell->uncheckMountPoint( aUnqPath,aRedirectedPath ); + if( aRedirectedPath == rtl::OUString() && m_pMyShell->m_vecMountPoint.size() ) + { + aRedirectedPath = rtl::OUString::createFromAscii( "//./" ); + } + m_pMyShell->getUrlFromUnq( aRedirectedPath,m_aContentId ); + m_aNormalizedId = aUnqPath; + } + else + { + m_pMyShell->getUnqFromUrl( aUnqPath,m_aNormalizedId ); + m_pMyShell->checkMountPoint( m_aNormalizedId,aRedirectedPath ); + + m_aNormalizedId = aRedirectedPath; + m_aContentId = aUnqPath; + } + m_pMyShell->getScheme( m_aProviderScheme ); +} + +FileContentIdentifier::~FileContentIdentifier() +{ +} + + +void SAL_CALL +FileContentIdentifier::acquire( + void ) + throw( uno::RuntimeException ) +{ + OWeakObject::acquire(); +} + + +void SAL_CALL +FileContentIdentifier::release( + void ) + throw( uno::RuntimeException ) +{ + OWeakObject::release(); +} + + +uno::Any SAL_CALL +FileContentIdentifier::queryInterface( + const uno::Type& rType ) + throw( uno::RuntimeException ) +{ + uno::Any aRet = cppu::queryInterface( rType, + SAL_STATIC_CAST( lang::XTypeProvider*, this), + SAL_STATIC_CAST( XContentIdentifier*, this) ); + return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ); +} + + +uno::Sequence< sal_Int8 > SAL_CALL +FileContentIdentifier::getImplementationId() + throw( uno::RuntimeException ) +{ + static cppu::OImplementationId* pId = NULL; + if ( !pId ) + { + osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() ); + if ( !pId ) + { + static cppu::OImplementationId id( sal_False ); + pId = &id; + } + } + return (*pId).getImplementationId(); +} + + +uno::Sequence< uno::Type > SAL_CALL +FileContentIdentifier::getTypes( + void ) + throw( uno::RuntimeException ) +{ + static cppu::OTypeCollection* pCollection = NULL; + if ( !pCollection ) { + osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() ); + if ( !pCollection ) + { + static cppu::OTypeCollection collection( + getCppuType( static_cast< uno::Reference< lang::XTypeProvider >* >( 0 ) ), + getCppuType( static_cast< uno::Reference< XContentIdentifier >* >( 0 ) ) ); + pCollection = &collection; + } + } + return (*pCollection).getTypes(); +} + + +rtl::OUString +SAL_CALL +FileContentIdentifier::getContentIdentifier( + void ) + throw( uno::RuntimeException ) +{ + return m_aContentId; +} + + +rtl::OUString SAL_CALL +FileContentIdentifier::getContentProviderScheme( + void ) + throw( uno::RuntimeException ) +{ + return m_aProviderScheme; +} diff --git a/ucb/source/ucp/file/filid.hxx b/ucb/source/ucp/file/filid.hxx new file mode 100644 index 000000000000..ae472bd9a244 --- /dev/null +++ b/ucb/source/ucp/file/filid.hxx @@ -0,0 +1,144 @@ +/************************************************************************* + * + * $RCSfile: filid.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:53:36 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _FILID_HXX_ +#define _FILID_HXX_ + +#ifndef _RTL_USTRING_ +#include <rtl/ustring> +#endif +#ifndef _CPPUHELPER_WEAK_HXX_ +#include <cppuhelper/weak.hxx> +#endif +#ifndef _COM_SUN_STAR_LANG_XTYPEPROVIDER_HPP_ +#include <com/sun/star/lang/XTypeProvider.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCONTENTIDENTIFIER_HPP_ +#include <com/sun/star/ucb/XContentIdentifier.hpp> +#endif + +namespace fileaccess { + + class shell; + + class FileContentIdentifier : + public cppu::OWeakObject, + public com::sun::star::lang::XTypeProvider, + public com::sun::star::ucb::XContentIdentifier + { + + // This implementation has to be reworked + public: + FileContentIdentifier( shell* pMyShell, + const rtl::OUString& aUnqPath, + sal_Bool IsNormalized = true ); + + virtual ~FileContentIdentifier(); + + // XInterface + virtual com::sun::star::uno::Any SAL_CALL + queryInterface( + const com::sun::star::uno::Type& aType ) + throw( com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL + acquire( + void ) + throw( com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL + release( + void ) + throw( com::sun::star::uno::RuntimeException ); + + // XTypeProvider + virtual com::sun::star::uno::Sequence< com::sun::star::uno::Type > SAL_CALL + getTypes( + void ) + throw( com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL + getImplementationId( + void ) + throw( com::sun::star::uno::RuntimeException ); + + // XContentIdentifier + virtual rtl::OUString SAL_CALL + getContentIdentifier( + void ) + throw( com::sun::star::uno::RuntimeException ); + + virtual rtl::OUString SAL_CALL + getContentProviderScheme( + void ) + throw( com::sun::star::uno::RuntimeException ); + + private: + shell* m_pMyShell; + rtl::OUString m_aContentId; // The URL string + rtl::OUString m_aNormalizedId; // The somehow normalized string + rtl::OUString m_aProviderScheme; + sal_Bool m_bNormalized; + }; + +} // end namespace fileaccess + + +#endif diff --git a/ucb/source/ucp/file/filinl.hxx b/ucb/source/ucp/file/filinl.hxx new file mode 100644 index 000000000000..13d43575001e --- /dev/null +++ b/ucb/source/ucp/file/filinl.hxx @@ -0,0 +1,115 @@ +/************************************************************************* + * + * $RCSfile: filinl.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:53:36 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _FILINL_HXX_ +#define _FILINL_HXX_ + +inline const sal_Bool& SAL_CALL shell::MyProperty::IsNative() const +{ + return isNative; +} +inline const rtl::OUString& SAL_CALL shell::MyProperty::getPropertyName() const +{ + return PropertyName; +} +inline const sal_Int32& SAL_CALL shell::MyProperty::getHandle() const +{ + return Handle; +} +inline const com::sun::star::uno::Type& SAL_CALL shell::MyProperty::getType() const +{ + return Typ; +} + +inline const com::sun::star::uno::Any& SAL_CALL shell::MyProperty::getValue() const +{ + return Value; +} +inline const com::sun::star::beans::PropertyState& SAL_CALL shell::MyProperty::getState() const +{ + return State; +} +inline const sal_Int16& SAL_CALL shell::MyProperty::getAttributes() const +{ + return Attributes; +} +inline void SAL_CALL shell::MyProperty::setHandle( const sal_Int32& __Handle ) const +{ + (( MyProperty* )this )->Handle = __Handle; +} +inline void SAL_CALL shell::MyProperty::setType( const com::sun::star::uno::Type& __Typ ) const +{ + (( MyProperty* )this )->Typ = __Typ; +} +inline void SAL_CALL shell::MyProperty::setValue( const com::sun::star::uno::Any& __Value ) const +{ + (( MyProperty* )this )->Value = __Value; +} +inline void SAL_CALL shell::MyProperty::setState( const com::sun::star::beans::PropertyState& __State ) const +{ + (( MyProperty* )this )->State = __State; +} +inline void SAL_CALL shell::MyProperty::setAttributes( const sal_Int16& __Attributes ) const +{ + (( MyProperty* )this )->Attributes = __Attributes; +} + + +#endif diff --git a/ucb/source/ucp/file/filnot.cxx b/ucb/source/ucp/file/filnot.cxx new file mode 100644 index 000000000000..15a12072da43 --- /dev/null +++ b/ucb/source/ucp/file/filnot.cxx @@ -0,0 +1,324 @@ +/************************************************************************* + * + * $RCSfile: filnot.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:53:36 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _COM_SUN_STAR_UCB_XCONTENT_HPP_ +#include <com/sun/star/ucb/XContent.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_CONTENTACTION_HPP_ +#include <com/sun/star/ucb/ContentAction.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_PROPERTYSETINFOCHANGE_HPP_ +#include <com/sun/star/beans/PropertySetInfoChange.hpp> +#endif +#ifndef _FILNOT_HXX_ +#include "filnot.hxx" +#endif +#ifndef _FILID_HXX_ +#include "filid.hxx" +#endif +#ifndef _BC_HXX_ +#include "bc.hxx" +#endif +#ifndef _PROV_HXX_ +#include "prov.hxx" +#endif + + + +using namespace fileaccess; +using namespace com::sun::star; +using namespace com::sun::star::ucb; + + +ContentEventNotifier::ContentEventNotifier( shell* pMyShell, + BaseContent* pCreatorContent, + const uno::Reference< XContentIdentifier >& xCreatorId, + const uno::Sequence< uno::Reference< uno::XInterface > >& sListeners ) + : m_pMyShell( pMyShell ), + m_pCreatorContent( pCreatorContent ), + m_xCreatorId( xCreatorId ), + m_sListeners( sListeners ) +{ +} + + +ContentEventNotifier::ContentEventNotifier( shell* pMyShell, + BaseContent* pCreatorContent, + const uno::Reference< XContentIdentifier >& xCreatorId, + const uno::Reference< XContentIdentifier >& xOldId, + const uno::Sequence< uno::Reference< uno::XInterface > >& sListeners ) + : m_pMyShell( pMyShell ), + m_pCreatorContent( pCreatorContent ), + m_xCreatorId( xCreatorId ), + m_xOldId( xOldId ), + m_sListeners( sListeners ) +{ +} + + + +void ContentEventNotifier::notifyChildInserted( const rtl::OUString& aChildName ) +{ + uno::Reference< uno::XInterface > shooter( static_cast< XContent* >( m_pCreatorContent ),uno::UNO_QUERY ); + + FileContentIdentifier* p = new FileContentIdentifier( m_pMyShell,aChildName ); + uno::Reference< XContentIdentifier > xChildId( p ); + + uno::Reference< XContent > xChildContent = m_pMyShell->m_pProvider->queryContent( xChildId ); + + ContentEvent aEvt( shooter, + ContentAction::INSERTED, + xChildContent, + m_xCreatorId ); + + for( sal_Int32 i = 0; i < m_sListeners.getLength(); ++i ) + { + uno::Reference< XContentEventListener > ref( m_sListeners[i],uno::UNO_QUERY ); + if( ref.is() ) + ref->contentEvent( aEvt ); + } +} + +void ContentEventNotifier::notifyDeleted( void ) +{ + uno::Reference< uno::XInterface > shooter( static_cast< XContent* >( m_pCreatorContent ),uno::UNO_QUERY ); + uno::Reference< XContent > xDeletedContent( static_cast< XContent* >( m_pCreatorContent ),uno::UNO_QUERY ); + + ContentEvent aEvt( shooter, + ContentAction::DELETED, + xDeletedContent, + m_xCreatorId ); + + + for( sal_Int32 i = 0; i < m_sListeners.getLength(); ++i ) + { + uno::Reference< XContentEventListener > ref( m_sListeners[i],uno::UNO_QUERY ); + if( ref.is() ) + ref->contentEvent( aEvt ); + } +} + + + +void ContentEventNotifier::notifyRemoved( const rtl::OUString& aChildName ) +{ + uno::Reference< uno::XInterface > shooter( static_cast< XContent* >( m_pCreatorContent ),uno::UNO_QUERY ); + + FileContentIdentifier* p = new FileContentIdentifier( m_pMyShell,aChildName ); + uno::Reference< XContentIdentifier > xChildId( p ); + + BaseContent* pp = new BaseContent( m_pMyShell,xChildId,aChildName ); + { + vos::OGuard aGuard( pp->m_aMutex ); + pp->m_nState |= BaseContent::Deleted; + } + + uno::Reference< XContent > xDeletedContent( pp ); + + + ContentEvent aEvt( shooter, + ContentAction::REMOVED, + xDeletedContent, + m_xCreatorId ); + + for( sal_Int32 i = 0; i < m_sListeners.getLength(); ++i ) + { + uno::Reference< XContentEventListener > ref( m_sListeners[i],uno::UNO_QUERY ); + if( ref.is() ) + ref->contentEvent( aEvt ); + } +} + +void ContentEventNotifier::notifyExchanged() +{ + uno::Reference< uno::XInterface > shooter( static_cast< XContent* >( m_pCreatorContent ),uno::UNO_QUERY ); + + ContentEvent aEvt( shooter, + ContentAction::EXCHANGED, + m_pCreatorContent, + m_xOldId ); + + for( sal_Int32 i = 0; i < m_sListeners.getLength(); ++i ) + { + uno::Reference< XContentEventListener > ref( m_sListeners[i],uno::UNO_QUERY ); + if( ref.is() ) + ref->contentEvent( aEvt ); + } +} + +/*********************************************************************************/ +/* */ +/* PropertySetInfoChangeNotifier */ +/* */ +/*********************************************************************************/ + + +PropertySetInfoChangeNotifier::PropertySetInfoChangeNotifier( + shell* pMyShell, + BaseContent* pCreatorContent, + const uno::Reference< XContentIdentifier >& xCreatorId, + const uno::Sequence< uno::Reference< uno::XInterface > >& sListeners ) + : m_pMyShell( pMyShell ), + m_pCreatorContent( pCreatorContent ), + m_xCreatorId( xCreatorId ), + m_sListeners( sListeners ) +{ + +} + + +void SAL_CALL +PropertySetInfoChangeNotifier::notifyPropertyAdded( const rtl::OUString & aPropertyName ) +{ + uno::Reference< uno::XInterface > shooter( static_cast< XContent* >( m_pCreatorContent ),uno::UNO_QUERY ); + beans::PropertySetInfoChangeEvent aEvt( shooter, + aPropertyName, + -1, + beans::PropertySetInfoChange::PROPERTY_INSERTED ); + + for( sal_Int32 i = 0; i < m_sListeners.getLength(); ++i ) + { + uno::Reference< beans::XPropertySetInfoChangeListener > ref( m_sListeners[i],uno::UNO_QUERY ); + if( ref.is() ) + ref->propertySetInfoChange( aEvt ); + } +} + + +void SAL_CALL +PropertySetInfoChangeNotifier::notifyPropertyRemoved( const rtl::OUString & aPropertyName ) +{ + uno::Reference< uno::XInterface > shooter( static_cast< XContent* >( m_pCreatorContent ),uno::UNO_QUERY ); + beans::PropertySetInfoChangeEvent aEvt( shooter, + aPropertyName, + -1, + beans::PropertySetInfoChange::PROPERTY_REMOVED ); + + for( sal_Int32 i = 0; i < m_sListeners.getLength(); ++i ) + { + uno::Reference< beans::XPropertySetInfoChangeListener > ref( m_sListeners[i],uno::UNO_QUERY ); + if( ref.is() ) + ref->propertySetInfoChange( aEvt ); + } +} + + +/*********************************************************************************/ +/* */ +/* PropertySetInfoChangeNotifier */ +/* */ +/*********************************************************************************/ + + +PropertyChangeNotifier::PropertyChangeNotifier( + shell* pMyShell, + BaseContent* pCreatorContent, + const com::sun::star::uno::Reference< com::sun::star::ucb::XContentIdentifier >& xCreatorId, + ListenerMap* pListeners ) + : m_pMyShell( pMyShell ), + m_pCreatorContent( pCreatorContent ), + m_xCreatorId( xCreatorId ), + m_pListeners( pListeners ) +{ +} + + +PropertyChangeNotifier::~PropertyChangeNotifier() +{ + delete m_pListeners; +} + + +void PropertyChangeNotifier::notifyPropertyChanged( + uno::Sequence< beans::PropertyChangeEvent > Changes ) +{ + sal_Int32 j; + + for( j = 0; j < Changes.getLength(); ++j ) + Changes[j].Source = static_cast< XContent *>( m_pCreatorContent ); + + // notify listeners for all Events + + uno::Sequence< uno::Reference< uno::XInterface > > seqList = (*m_pListeners)[ rtl::OUString() ]; + for( j = 0; j < seqList.getLength(); ++j ) + { + uno::Reference< beans::XPropertiesChangeListener > aListener( seqList[j],uno::UNO_QUERY ); + if( aListener.is() ) + { + aListener->propertiesChange( Changes ); + } + } + + uno::Sequence< beans::PropertyChangeEvent > seq(1); + for( j = 0; j < Changes.getLength(); ++j ) + { + seq[0] = Changes[j]; + seqList = (*m_pListeners)[ seq[0].PropertyName ]; + + for( sal_Int32 i = 0; i < seqList.getLength(); ++i ) + { + uno::Reference< beans::XPropertiesChangeListener > aListener( seqList[j],uno::UNO_QUERY ); + if( aListener.is() ) + { + aListener->propertiesChange( seq ); + } + } + } +} diff --git a/ucb/source/ucp/file/filnot.hxx b/ucb/source/ucp/file/filnot.hxx new file mode 100644 index 000000000000..67936b47d0d9 --- /dev/null +++ b/ucb/source/ucp/file/filnot.hxx @@ -0,0 +1,183 @@ +/************************************************************************* + * + * $RCSfile: filnot.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:53:36 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _FILNOT_HXX_ +#define _FILNOT_HXX_ + +#ifndef __SGI_STL_HASH_MAP +#include <stl/hash_map> +#endif +#ifndef _COM_SUN_STAR_UNO_SEQUENCE_HXX_ +#include <com/sun/star/uno/Sequence.hxx> +#endif +#ifndef _COM_SUN_STAR_UNO_XINTERFACE_HPP_ +#include <com/sun/star/uno/XInterface.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_PROPERTYCHANGEEVENT_HPP_ +#include <com/sun/star/beans/PropertyChangeEvent.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCONTENTIDENTIFIER_HPP_ +#include <com/sun/star/ucb/XContentIdentifier.hpp> +#endif +#ifndef _FILGLOB_HXX_ +#include "filglob.hxx" +#endif + + +namespace fileaccess { + + class shell; + class BaseContent; + + class ContentEventNotifier + { + private: + shell* m_pMyShell; + BaseContent* m_pCreatorContent; + com::sun::star::uno::Reference< com::sun::star::ucb::XContentIdentifier > m_xCreatorId; + com::sun::star::uno::Reference< com::sun::star::ucb::XContentIdentifier > m_xOldId; + com::sun::star::uno::Sequence< com::sun::star::uno::Reference< com::sun::star::uno::XInterface > > m_sListeners; + public: + + ContentEventNotifier( + shell* pMyShell, + BaseContent* pCreatorContent, + const com::sun::star::uno::Reference< com::sun::star::ucb::XContentIdentifier >& xCreatorId, + const com::sun::star::uno::Sequence< + com::sun::star::uno::Reference< com::sun::star::uno::XInterface > >& sListeners ); + + ContentEventNotifier( + shell* pMyShell, + BaseContent* pCreatorContent, + const com::sun::star::uno::Reference< com::sun::star::ucb::XContentIdentifier >& xCreatorId, + const com::sun::star::uno::Reference< com::sun::star::ucb::XContentIdentifier >& xOldId, + const com::sun::star::uno::Sequence< + com::sun::star::uno::Reference< com::sun::star::uno::XInterface > >& sListeners ); + + void notifyChildInserted( const rtl::OUString& aChildName ); + void notifyDeleted( void ); + void notifyRemoved( const rtl::OUString& aChildName ); + void notifyExchanged( ); + }; + + + class PropertySetInfoChangeNotifier + { + private: + shell* m_pMyShell; + BaseContent* m_pCreatorContent; + com::sun::star::uno::Reference< com::sun::star::ucb::XContentIdentifier > m_xCreatorId; + com::sun::star::uno::Sequence< com::sun::star::uno::Reference< com::sun::star::uno::XInterface > > m_sListeners; + public: + PropertySetInfoChangeNotifier( + shell* pMyShell, + BaseContent* pCreatorContent, + const com::sun::star::uno::Reference< com::sun::star::ucb::XContentIdentifier >& xCreatorId, + const com::sun::star::uno::Sequence< + com::sun::star::uno::Reference< com::sun::star::uno::XInterface > >& sListeners ); + + void SAL_CALL notifyPropertyAdded( const rtl::OUString & aPropertyName ); + void SAL_CALL notifyPropertyRemoved( const rtl::OUString & aPropertyName ); + }; + + + typedef std::hash_map< rtl::OUString, + com::sun::star::uno::Sequence< com::sun::star::uno::Reference< com::sun::star::uno::XInterface > >, + hashOUString, + equalOUString > ListenerMap; + + class PropertyChangeNotifier + { + private: + shell* m_pMyShell; + BaseContent* m_pCreatorContent; + com::sun::star::uno::Reference< com::sun::star::ucb::XContentIdentifier > m_xCreatorId; + ListenerMap* m_pListeners; + public: + PropertyChangeNotifier( + shell* pMyShell, + BaseContent* pCreatorContent, + const com::sun::star::uno::Reference< com::sun::star::ucb::XContentIdentifier >& xCreatorId, + ListenerMap* pListeners ); + + ~PropertyChangeNotifier(); + + void notifyPropertyChanged( + com::sun::star::uno::Sequence< com::sun::star::beans::PropertyChangeEvent > seqChanged ); + }; + + + class Notifier + { + public: + // Side effect of this function is the change of the name + virtual ContentEventNotifier* cEXC( const rtl::OUString aNewName ) = 0; + // Side effect is the change of the state of the object to "deleted". + virtual ContentEventNotifier* cDEL( void ) = 0; + virtual ContentEventNotifier* cCEL( void ) = 0; + virtual PropertySetInfoChangeNotifier* cPSL( void ) = 0; + virtual PropertyChangeNotifier* cPCL( void ) = 0; + virtual rtl::OUString getKey( void ) = 0; + }; + + +} // end namespace fileaccess + +#endif diff --git a/ucb/source/ucp/file/filprp.cxx b/ucb/source/ucp/file/filprp.cxx new file mode 100644 index 000000000000..9fa3c1ec5a5d --- /dev/null +++ b/ucb/source/ucp/file/filprp.cxx @@ -0,0 +1,179 @@ +/************************************************************************* + * + * $RCSfile: filprp.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:53:36 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _SHELL_HXX_ +#include "shell.hxx" +#endif +#ifndef _PROV_HXX_ +#include "prov.hxx" +#endif +#ifndef _FILPRP_HXX_ +#include "filprp.hxx" +#endif + +using namespace fileaccess; +using namespace com::sun::star; +using namespace com::sun::star::ucb; + + +#ifndef _FILINL_HXX_ +#include "filinl.hxx" +#endif + + +XPropertySetInfo_impl::XPropertySetInfo_impl( shell* pMyShell,const rtl::OUString& aUnqPath ) + : m_pMyShell( pMyShell ), + m_xProvider( pMyShell->m_pProvider ), + m_count( 0 ), + m_seq( 0 ) +{ + shell::ContentMap::iterator it = m_pMyShell->m_aContent.find( aUnqPath ); + + shell::PropertySet& properties = *(it->second.properties); + shell::PropertySet::iterator it1 = properties.begin(); + + m_seq.realloc( properties.size() ); + + while( it1 != properties.end() ) + { + m_seq[ m_count++ ] = beans::Property( it1->getPropertyName(), + it1->getHandle(), + it1->getType(), + it1->getAttributes() ); + ++it1; + } +} + + +XPropertySetInfo_impl::XPropertySetInfo_impl( shell* pMyShell,const uno::Sequence< beans::Property >& seq ) + : m_pMyShell( pMyShell ), + m_count( seq.getLength() ), + m_seq( seq ) +{ +} + + +XPropertySetInfo_impl::~XPropertySetInfo_impl() +{ + m_pMyShell->m_pProvider->release(); +} + + +void SAL_CALL +XPropertySetInfo_impl::acquire( + void ) + throw( uno::RuntimeException ) +{ + OWeakObject::acquire(); +} + + +void SAL_CALL +XPropertySetInfo_impl::release( + void ) + throw( uno::RuntimeException ) +{ + OWeakObject::release(); +} + + +uno::Any SAL_CALL +XPropertySetInfo_impl::queryInterface( + const uno::Type& rType ) + throw( uno::RuntimeException ) +{ + uno::Any aRet = cppu::queryInterface( rType, + SAL_STATIC_CAST( beans::XPropertySetInfo*,this) ); + return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ); +} + + +beans::Property SAL_CALL +XPropertySetInfo_impl::getPropertyByName( + const rtl::OUString& aName ) + throw( beans::UnknownPropertyException, + uno::RuntimeException) +{ + for( sal_Int32 i = 0; i < m_seq.getLength(); ++i ) + if( m_seq[i].Name == aName ) return m_seq[i]; + + throw beans::UnknownPropertyException(); +} + + + +uno::Sequence< beans::Property > SAL_CALL +XPropertySetInfo_impl::getProperties( + void ) + throw( uno::RuntimeException ) +{ + return m_seq; +} + + +sal_Bool SAL_CALL +XPropertySetInfo_impl::hasPropertyByName( + const rtl::OUString& aName ) + throw( uno::RuntimeException ) +{ + for( sal_Int32 i = 0; i < m_seq.getLength(); ++i ) + if( m_seq[i].Name == aName ) return true; + return false; +} diff --git a/ucb/source/ucp/file/filprp.hxx b/ucb/source/ucp/file/filprp.hxx new file mode 100644 index 000000000000..b9e94c3fb47b --- /dev/null +++ b/ucb/source/ucp/file/filprp.hxx @@ -0,0 +1,131 @@ +/************************************************************************* + * + * $RCSfile: filprp.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:53:36 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _FILPRP_HXX_ +#define _FILPRP_HXX_ + + +#ifndef _CPPUHELPER_WEAK_HXX_ +#include <cppuhelper/weak.hxx> +#endif +#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSETINFO_HPP_ +#include <com/sun/star/beans/XPropertySetInfo.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCONTENTPROVIDER_HPP_ +#include <com/sun/star/ucb/XContentProvider.hpp> +#endif + + +namespace fileaccess { + + class shell; + + class XPropertySetInfo_impl + : public cppu::OWeakObject, + public com::sun::star::beans::XPropertySetInfo + { + public: + XPropertySetInfo_impl( shell* pMyShell,const rtl::OUString& aUnqPath ); + XPropertySetInfo_impl( shell* pMyShell,const com::sun::star::uno::Sequence< com::sun::star::beans::Property >& seq ); + + virtual ~XPropertySetInfo_impl(); + + // XInterface + virtual com::sun::star::uno::Any SAL_CALL + queryInterface( + const com::sun::star::uno::Type& aType ) + throw( com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL + acquire( + void ) + throw( com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL + release( + void ) + throw( com::sun::star::uno::RuntimeException ); + + + virtual com::sun::star::uno::Sequence< com::sun::star::beans::Property > SAL_CALL + getProperties( + void ) + throw( com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::beans::Property SAL_CALL + getPropertyByName( + const rtl::OUString& aName ) + throw( com::sun::star::beans::UnknownPropertyException, + com::sun::star::uno::RuntimeException); + + virtual sal_Bool SAL_CALL + hasPropertyByName( const rtl::OUString& Name ) + throw( com::sun::star::uno::RuntimeException ); + + private: + shell* m_pMyShell; + com::sun::star::uno::Reference< com::sun::star::ucb::XContentProvider > m_xProvider; + sal_Int32 m_count; + com::sun::star::uno::Sequence< com::sun::star::beans::Property > m_seq; + }; +} + +#endif + diff --git a/ucb/source/ucp/file/filrow.cxx b/ucb/source/ucp/file/filrow.cxx new file mode 100644 index 000000000000..e73745729d2c --- /dev/null +++ b/ucb/source/ucp/file/filrow.cxx @@ -0,0 +1,453 @@ +/************************************************************************* + * + * $RCSfile: filrow.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:53:36 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _FILROW_HXX_ +#include "filrow.hxx" +#endif +#ifndef _SHELL_HXX_ +#include "shell.hxx" +#endif +#ifndef _PROV_HXX_ +#include "prov.hxx" +#endif + +using namespace fileaccess; +using namespace com::sun::star; +//using namespace com::sun::star::ucb; + + +// Funktion for TypeConverting + + +template< class _type_ > +sal_Bool convert( shell* pShell, + uno::Reference< script::XTypeConverter >& xConverter, + uno::Any& rValue, + _type_& aReturn ) +{ + sal_Bool no_success = ! ( rValue >>= aReturn ); + + if ( no_success ) + { + if( ! xConverter.is() ) + { + xConverter = uno::Reference< script::XTypeConverter >( + pShell->m_xMultiServiceFactory->createInstance( + rtl::OUString::createFromAscii( "com.sun.star.script.Converter" ) ),uno::UNO_QUERY ); + +/* DBG_ASSERT( m_xTypeConverter.is(), + "PropertyValueSet::getTypeConverter() - " + "Service 'com.sun.star.script.Converter' n/a!" );*/ + } + try + { + uno::Any aConvertedValue + = xConverter->convertTo( rValue,getCppuType( static_cast< const _type_* >(0) ) ); + no_success = ! ( aConvertedValue >>= aReturn ); + } + catch ( lang::IllegalArgumentException ) + { + no_success = sal_True; + } + catch ( script::CannotConvertException ) + { + no_success = sal_True; + } + } + return no_success; +} + + +XRow_impl::XRow_impl( shell* pMyShell,const uno::Sequence< uno::Any >& seq ) + : m_aValueMap( seq ), + m_pMyShell( pMyShell ), + m_xProvider( pMyShell->m_pProvider ), + m_xTypeConverter( 0 ) +{ +} + +XRow_impl::~XRow_impl() +{ +} + + +void SAL_CALL +XRow_impl::acquire( + void ) + throw( uno::RuntimeException ) +{ + OWeakObject::acquire(); +} + +void SAL_CALL +XRow_impl::release( + void ) + throw( uno::RuntimeException ) +{ + OWeakObject::release(); +} + + +uno::Any SAL_CALL +XRow_impl::queryInterface( + const uno::Type& rType ) + throw( uno::RuntimeException ) +{ + uno::Any aRet = cppu::queryInterface( rType, + SAL_STATIC_CAST( sdbc::XRow*,this) ); + return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ); +} + + + +sal_Bool SAL_CALL +XRow_impl::wasNull( + void ) + throw( sdbc::SQLException, + uno::RuntimeException) +{ + return m_nWasNull; +} + + +rtl::OUString SAL_CALL +XRow_impl::getString( + sal_Int32 columnIndex ) + throw( sdbc::SQLException, + uno::RuntimeException) +{ + if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() ) + throw sdbc::SQLException(); + rtl::OUString Value; + vos::OGuard aGuard( m_aMutex ); + m_nWasNull = ::convert<rtl::OUString>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value ); + return Value; +} + +sal_Bool SAL_CALL +XRow_impl::getBoolean( + sal_Int32 columnIndex ) + throw( sdbc::SQLException, + uno::RuntimeException) +{ + if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() ) + throw sdbc::SQLException(); + sal_Bool Value( false ); + vos::OGuard aGuard( m_aMutex ); + m_nWasNull = ::convert<sal_Bool>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value ); + return Value; +} + + +sal_Int8 SAL_CALL +XRow_impl::getByte( + sal_Int32 columnIndex ) + throw( sdbc::SQLException, + uno::RuntimeException) +{ + if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() ) + throw sdbc::SQLException(); + sal_Int8 Value( 0 ); + vos::OGuard aGuard( m_aMutex ); + m_nWasNull = ::convert<sal_Int8>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value ); + return Value; +} + +sal_Int16 SAL_CALL +XRow_impl::getShort( + sal_Int32 columnIndex ) + throw( sdbc::SQLException, + uno::RuntimeException) +{ + if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() ) + throw sdbc::SQLException(); + sal_Int16 Value( 0 ); + vos::OGuard aGuard( m_aMutex ); + m_nWasNull = ::convert<sal_Int16>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value ); + return Value; +} + + +sal_Int32 SAL_CALL +XRow_impl::getInt( + sal_Int32 columnIndex ) + throw( sdbc::SQLException, + uno::RuntimeException) +{ + if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() ) + throw sdbc::SQLException(); + sal_Int32 Value( 0 ); + vos::OGuard aGuard( m_aMutex ); + m_nWasNull = ::convert<sal_Int32>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value ); + return Value; +} + +sal_Int64 SAL_CALL +XRow_impl::getLong( + sal_Int32 columnIndex ) + throw( sdbc::SQLException, + uno::RuntimeException) +{ + if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() ) + throw sdbc::SQLException(); + sal_Int64 Value( 0 ); + vos::OGuard aGuard( m_aMutex ); + m_nWasNull = ::convert<sal_Int64>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value ); + return Value; +} + +float SAL_CALL +XRow_impl::getFloat( + sal_Int32 columnIndex ) + throw( sdbc::SQLException, + uno::RuntimeException) +{ + if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() ) + throw sdbc::SQLException(); + float Value( 0 ); + vos::OGuard aGuard( m_aMutex ); + m_nWasNull = ::convert<float>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value ); + return Value; +} + +double SAL_CALL +XRow_impl::getDouble( + sal_Int32 columnIndex ) + throw( sdbc::SQLException, + uno::RuntimeException) +{ + if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() ) + throw sdbc::SQLException(); + double Value( 0 ); + vos::OGuard aGuard( m_aMutex ); + m_nWasNull = ::convert<double>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value ); + return Value; +} + +uno::Sequence< sal_Int8 > SAL_CALL +XRow_impl::getBytes( + sal_Int32 columnIndex ) + throw( sdbc::SQLException, + uno::RuntimeException) +{ + if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() ) + throw sdbc::SQLException(); + uno::Sequence< sal_Int8 > Value(0); + vos::OGuard aGuard( m_aMutex ); + m_nWasNull = ::convert<uno::Sequence< sal_Int8 > >( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value ); + return Value; +} + +util::Date SAL_CALL +XRow_impl::getDate( + sal_Int32 columnIndex ) + throw( sdbc::SQLException, + uno::RuntimeException) +{ + if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() ) + throw sdbc::SQLException(); + util::Date Value; + vos::OGuard aGuard( m_aMutex ); + m_nWasNull = ::convert<util::Date>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value ); + return Value; +} + +util::Time SAL_CALL +XRow_impl::getTime( + sal_Int32 columnIndex ) + throw( sdbc::SQLException, + uno::RuntimeException) +{ + if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() ) + throw sdbc::SQLException(); + util::Time Value; + vos::OGuard aGuard( m_aMutex ); + m_nWasNull = ::convert<util::Time>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value ); + return Value; +} + +util::DateTime SAL_CALL +XRow_impl::getTimestamp( + sal_Int32 columnIndex ) + throw( sdbc::SQLException, + uno::RuntimeException) +{ + if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() ) + throw sdbc::SQLException(); + util::DateTime Value; + vos::OGuard aGuard( m_aMutex ); + m_nWasNull = ::convert<util::DateTime>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value ); + return Value; +} + + +uno::Reference< io::XInputStream > SAL_CALL +XRow_impl::getBinaryStream( + sal_Int32 columnIndex ) + throw( sdbc::SQLException, + uno::RuntimeException) +{ + if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() ) + throw sdbc::SQLException(); + uno::Reference< io::XInputStream > Value; + vos::OGuard aGuard( m_aMutex ); + m_nWasNull = ::convert<uno::Reference< io::XInputStream > >( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value ); + return Value; +} + + +uno::Reference< io::XInputStream > SAL_CALL +XRow_impl::getCharacterStream( + sal_Int32 columnIndex ) + throw( sdbc::SQLException, + uno::RuntimeException) +{ + if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() ) + throw sdbc::SQLException(); + uno::Reference< io::XInputStream > Value; + vos::OGuard aGuard( m_aMutex ); + m_nWasNull = ::convert< uno::Reference< io::XInputStream> >( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value ); + return Value; +} + + +uno::Any SAL_CALL +XRow_impl::getObject( + sal_Int32 columnIndex, + const uno::Reference< container::XNameAccess >& typeMap ) + throw( sdbc::SQLException, + uno::RuntimeException) +{ + if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() ) + throw sdbc::SQLException(); + uno::Any Value; + vos::OGuard aGuard( m_aMutex ); + m_nWasNull = ::convert<uno::Any>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value ); + return Value; +} + +uno::Reference< sdbc::XRef > SAL_CALL +XRow_impl::getRef( + sal_Int32 columnIndex ) + throw( sdbc::SQLException, + uno::RuntimeException) +{ + if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() ) + throw sdbc::SQLException(); + uno::Reference< sdbc::XRef > Value; + vos::OGuard aGuard( m_aMutex ); + m_nWasNull = ::convert<uno::Reference< sdbc::XRef> >( m_pMyShell, + m_xTypeConverter, + m_aValueMap[ --columnIndex ], + Value ); + return Value; +} + +uno::Reference< sdbc::XBlob > SAL_CALL +XRow_impl::getBlob( + sal_Int32 columnIndex ) + throw( sdbc::SQLException, + uno::RuntimeException) +{ + if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() ) + throw sdbc::SQLException(); + uno::Reference< sdbc::XBlob > Value; + vos::OGuard aGuard( m_aMutex ); + m_nWasNull = ::convert<uno::Reference< sdbc::XBlob> >( m_pMyShell, + m_xTypeConverter, + m_aValueMap[ --columnIndex ], + Value ); + return Value; +} + +uno::Reference< sdbc::XClob > SAL_CALL +XRow_impl::getClob( + sal_Int32 columnIndex ) + throw( sdbc::SQLException, + uno::RuntimeException) +{ + if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() ) + throw sdbc::SQLException(); + uno::Reference< sdbc::XClob > Value; + vos::OGuard aGuard( m_aMutex ); + m_nWasNull = ::convert<uno::Reference< sdbc::XClob> >( m_pMyShell, + m_xTypeConverter, + m_aValueMap[ --columnIndex ], + Value ); + return Value; +} + + +uno::Reference< sdbc::XArray > SAL_CALL +XRow_impl::getArray( + sal_Int32 columnIndex ) + throw( sdbc::SQLException, + uno::RuntimeException) +{ + if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() ) + throw sdbc::SQLException(); + uno::Reference< sdbc::XArray > Value; + vos::OGuard aGuard( m_aMutex ); + m_nWasNull = ::convert<uno::Reference< sdbc::XArray> >( m_pMyShell, + m_xTypeConverter, + m_aValueMap[ --columnIndex ], + Value ); + return Value; +} diff --git a/ucb/source/ucp/file/filrow.hxx b/ucb/source/ucp/file/filrow.hxx new file mode 100644 index 000000000000..ba8ec70fb460 --- /dev/null +++ b/ucb/source/ucp/file/filrow.hxx @@ -0,0 +1,239 @@ +/************************************************************************* + * + * $RCSfile: filrow.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:53:36 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _FILROW_HXX_ +#define _FILROW_HXX_ +#endif + +#ifndef _VOS_MUTEX_HXX_ +#include <vos/mutex.hxx> +#endif +#ifndef _CPPUHELPER_WEAK_HXX_ +#include <cppuhelper/weak.hxx> +#endif +#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_ +#include <com/sun/star/sdbc/XRow.hpp> +#endif +#ifndef _COM_SUN_STAR_SCRIPT_XTYPECONVERTER_HPP_ +#include <com/sun/star/script/XTypeConverter.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCONTENTPROVIDER_HPP_ +#include <com/sun/star/ucb/XContentProvider.hpp> +#endif + +namespace fileaccess { + + class shell; + + class XRow_impl: + public cppu::OWeakObject, + public com::sun::star::sdbc::XRow + { + public: + XRow_impl( shell* pShell,const com::sun::star::uno::Sequence< com::sun::star::uno::Any >& __m_aValueMap ); + ~XRow_impl(); + + virtual com::sun::star::uno::Any SAL_CALL + queryInterface( + const com::sun::star::uno::Type& aType ) + throw( com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL + acquire( + void ) + throw( com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL + release( + void ) + throw( com::sun::star::uno::RuntimeException); + + virtual sal_Bool SAL_CALL + wasNull( + void ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual rtl::OUString SAL_CALL + getString( + sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException); + + virtual sal_Bool SAL_CALL + getBoolean( + sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException); + + virtual sal_Int8 SAL_CALL + getByte( + sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException); + + virtual sal_Int16 SAL_CALL + getShort( + sal_Int32 columnIndex ) + throw( + com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual sal_Int32 SAL_CALL + getInt( + sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual sal_Int64 SAL_CALL + getLong( + sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + virtual float SAL_CALL + getFloat( + sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException); + + virtual double SAL_CALL + getDouble( + sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException); + + virtual com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL + getBytes( + sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException); + + virtual com::sun::star::util::Date SAL_CALL + getDate( + sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException); + + virtual com::sun::star::util::Time SAL_CALL + getTime( + sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException); + + virtual com::sun::star::util::DateTime SAL_CALL + getTimestamp( + sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException); + + virtual com::sun::star::uno::Reference< com::sun::star::io::XInputStream > SAL_CALL + getBinaryStream( + sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException); + + virtual com::sun::star::uno::Reference< com::sun::star::io::XInputStream > SAL_CALL + getCharacterStream( + sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException); + + virtual com::sun::star::uno::Any SAL_CALL + getObject( + sal_Int32 columnIndex, + const com::sun::star::uno::Reference< com::sun::star::container::XNameAccess >& typeMap ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException); + + virtual com::sun::star::uno::Reference< com::sun::star::sdbc::XRef > SAL_CALL + getRef( + sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException); + + virtual com::sun::star::uno::Reference< com::sun::star::sdbc::XBlob > SAL_CALL + getBlob( + sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException); + + virtual com::sun::star::uno::Reference< com::sun::star::sdbc::XClob > SAL_CALL + getClob( + sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException); + + virtual com::sun::star::uno::Reference< com::sun::star::sdbc::XArray > SAL_CALL + getArray( + sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException); + + private: + vos::OMutex m_aMutex; + com::sun::star::uno::Sequence< com::sun::star::uno::Any > m_aValueMap; + sal_Bool m_nWasNull; + shell* m_pMyShell; + com::sun::star::uno::Reference< com::sun::star::ucb::XContentProvider > m_xProvider; + com::sun::star::uno::Reference< com::sun::star::script::XTypeConverter > m_xTypeConverter; + }; + +} // end namespace fileaccess diff --git a/ucb/source/ucp/file/filrset.cxx b/ucb/source/ucp/file/filrset.cxx new file mode 100644 index 000000000000..34d1c1b8cbd5 --- /dev/null +++ b/ucb/source/ucp/file/filrset.cxx @@ -0,0 +1,959 @@ +/************************************************************************* + * + * $RCSfile: filrset.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:53:36 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _COM_SUN_STAR_UCB_WELCOMEDYNAMICRESULTSETSTRUCT_HPP_ +#include <com/sun/star/ucb/WelcomeDynamicResultSetStruct.hpp> +#endif +#ifndef _FILID_HXX_ +#include "filid.hxx" +#endif +#ifndef _SHELL_HXX_ +#include "shell.hxx" +#endif +#ifndef _FILPRP_HXX_ +#include "filprp.hxx" +#endif +#ifndef _FILRSET_HXX_ +#include "filrset.hxx" +#endif + +#ifndef _COM_SUN_STAR_UCB_OPENMODE_HPP_ +#include <com/sun/star/ucb/OpenMode.hpp> +#endif +#ifndef _PROV_HXX_ +#include "prov.hxx" +#endif + +#ifndef _COM_SUN_STAR_UNO_REFERENCE_H_ +#include <com/sun/star/uno/Reference.h> +#endif + +#ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBBUTE_HPP_ +#include <com/sun/star/beans/PropertyAttribute.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_LISTACTIONTYPE_HPP_ +#include <com/sun/star/ucb/ListActionType.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XSOURCEINITIALIZATION_HPP_ +#include <com/sun/star/ucb/XSourceInitialization.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCACHEDDYNAMICRESULTSETSTUBFACTORY_HPP_ +#include <com/sun/star/ucb/XCachedDynamicResultSetStubFactory.hpp> +#endif + +#ifndef _UCBHELPER_RESULTSETMETADATA_HXX +#include <ucbhelper/resultsetmetadata.hxx> +#endif + +using namespace fileaccess; +using namespace com::sun::star; +using namespace com::sun::star::ucb; + + +XResultSet_impl::XResultSet_impl( shell* pMyShell, + const rtl::OUString& aUnqPath, + sal_Int32 OpenMode, + const uno::Sequence< beans::Property >& seq, + const uno::Sequence< NumberedSortingInfo >& seqSort ) + : m_pMyShell( pMyShell ), + m_xProvider( pMyShell->m_pProvider ), + m_sProperty( seq ), + m_sSortingInfo( seqSort ), + m_aBaseDirectory( aUnqPath ), + m_aFolder( aUnqPath ), + m_pDisposeEventListeners( 0 ), + m_pRowCountListeners( 0 ), + m_pIsFinalListeners( 0 ), + m_nRow( -1 ), + m_bStatic( false ), + m_bRowCountFinal( false ), + m_nOpenMode( OpenMode ) +{ + m_bFaked = m_pMyShell->m_bFaked && m_aBaseDirectory.compareToAscii( "//./" ) == 0; + if( m_bFaked ) + { + m_nIsOpen = true; + } + else if( m_aFolder.open() != osl::FileBase::E_None ) + { + m_nIsOpen = false; + m_aFolder.close(); + } + else + m_nIsOpen = true; + + m_pMyShell->registerNotifier( m_aBaseDirectory,this ); +} + + +XResultSet_impl::~XResultSet_impl() +{ + m_pMyShell->deregisterNotifier( m_aBaseDirectory,this ); + + if( m_nIsOpen && ! m_bFaked ) + m_aFolder.close(); + + delete m_pDisposeEventListeners; + delete m_pRowCountListeners; + delete m_pIsFinalListeners; +} + + +sal_Bool SAL_CALL XResultSet_impl::CtorSuccess() +{ + return m_nIsOpen; +} + + +void SAL_CALL +XResultSet_impl::acquire( + void ) + throw( uno::RuntimeException ) +{ + OWeakObject::acquire(); +} + + +void SAL_CALL +XResultSet_impl::release( + void ) + throw( uno::RuntimeException ) +{ + OWeakObject::release(); +} + + + +uno::Any SAL_CALL +XResultSet_impl::queryInterface( + const uno::Type& rType ) + throw( uno::RuntimeException ) +{ + uno::Any aRet = cppu::queryInterface( rType, + SAL_STATIC_CAST( lang::XComponent*, this), + SAL_STATIC_CAST( lang::XEventListener*, this), + SAL_STATIC_CAST( sdbc::XRow*, this), + SAL_STATIC_CAST( sdbc::XResultSet*, this), + SAL_STATIC_CAST( sdbc::XCloseable*, this), + SAL_STATIC_CAST( sdbc::XResultSetMetaDataSupplier*, this), + SAL_STATIC_CAST( beans::XPropertySet*, this ), + SAL_STATIC_CAST( XContentAccess*, this), + SAL_STATIC_CAST( XDynamicResultSet*,this) ); + return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ); +} + + +void SAL_CALL +XResultSet_impl::disposing( const lang::EventObject& Source ) + throw( uno::RuntimeException ) +{ + // To do, but what +} + + +void SAL_CALL +XResultSet_impl::addEventListener( + const uno::Reference< lang::XEventListener >& Listener ) + throw( uno::RuntimeException ) +{ + vos::OGuard aGuard( m_aMutex ); + + if ( ! m_pDisposeEventListeners ) + m_pDisposeEventListeners = + new cppu::OInterfaceContainerHelper( m_aEventListenerMutex ); + + m_pDisposeEventListeners->addInterface( Listener ); +} + + +void SAL_CALL +XResultSet_impl::removeEventListener( + const uno::Reference< lang::XEventListener >& Listener ) + throw( uno::RuntimeException ) +{ + vos::OGuard aGuard( m_aMutex ); + + if ( m_pDisposeEventListeners ) + m_pDisposeEventListeners->removeInterface( Listener ); +} + + + +void SAL_CALL +XResultSet_impl::dispose() + throw( uno::RuntimeException ) +{ + vos::OGuard aGuard( m_aMutex ); + + lang::EventObject aEvt; + aEvt.Source = static_cast< lang::XComponent * >( this ); + + if ( m_pDisposeEventListeners && m_pDisposeEventListeners->getLength() ) + { + m_pDisposeEventListeners->disposeAndClear( aEvt ); + } + if( m_pRowCountListeners && m_pRowCountListeners->getLength() ) + { + m_pRowCountListeners->disposeAndClear( aEvt ); + } + if( m_pIsFinalListeners && m_pIsFinalListeners->getLength() ) + { + m_pIsFinalListeners->disposeAndClear( aEvt ); + } +} + + + +void XResultSet_impl::rowCountChanged() +{ + sal_Int32 aOldValue,aNewValue; + uno::Sequence< uno::Reference< uno::XInterface > > seq; + { + vos::OGuard aGuard( m_aMutex ); + if( m_pRowCountListeners ) + seq = m_pRowCountListeners->getElements(); + aNewValue = m_aItems.size(); + aOldValue = aNewValue-1; + } + beans::PropertyChangeEvent aEv; + aEv.PropertyName = rtl::OUString::createFromAscii( "RowCount" ); + aEv.Further = false; + aEv.PropertyHandle = -1; + aEv.OldValue <<= aOldValue; + aEv.NewValue <<= aNewValue; + for( sal_Int32 i = 0; i < seq.getLength(); ++i ) + { + uno::Reference< beans::XPropertyChangeListener > listener( seq[i],uno::UNO_QUERY ); + if( listener.is() ) + listener->propertyChange( aEv ); + } +} + + +void XResultSet_impl::isFinalChanged() +{ + uno::Sequence< uno::Reference< uno::XInterface > > seq; + { + vos::OGuard aGuard( m_aMutex ); + if( m_pIsFinalListeners ) + seq = m_pIsFinalListeners->getElements(); + m_bRowCountFinal = true; + } + beans::PropertyChangeEvent aEv; + aEv.PropertyName = rtl::OUString::createFromAscii( "IsRowCountFinal" ); + aEv.Further = false; + aEv.PropertyHandle = -1; + sal_Bool fval = false; + sal_Bool tval = true; + aEv.OldValue <<= fval; + aEv.NewValue <<= tval; + for( sal_Int32 i = 0; i < seq.getLength(); ++i ) + { + uno::Reference< beans::XPropertyChangeListener > listener( seq[i],uno::UNO_QUERY ); + if( listener.is() ) + listener->propertyChange( aEv ); + } +} + + +sal_Bool SAL_CALL +XResultSet_impl::OneMoreFaked( void ) + throw( sdbc::SQLException, + uno::RuntimeException ) +{ + sal_Int32 k = m_aItems.size(); + if( k < m_pMyShell->m_vecMountPoint.size() && + ( m_nOpenMode == OpenMode::ALL || m_nOpenMode == OpenMode::FOLDERS ) ) + { + sal_Bool IsRegular; + rtl::OUString aUnqPath = m_pMyShell->m_vecMountPoint[k].m_aDirectory; + osl::DirectoryItem aDirItem; + osl::DirectoryItem::get( aUnqPath,aDirItem ); + uno::Reference< sdbc::XRow > aRow = m_pMyShell->getv( -1,this,m_sProperty,aDirItem,aUnqPath,IsRegular ); + vos::OGuard aGuard( m_aMutex ); + m_aItems.push_back( aRow ); + m_aIdents.push_back( uno::Reference< XContentIdentifier >() ); + m_aUnqPath.push_back( aUnqPath ); + rowCountChanged(); + return true; + } + + return false; +} + + +sal_Bool SAL_CALL +XResultSet_impl::OneMore( + void ) + throw( sdbc::SQLException, + uno::RuntimeException ) +{ + if( m_bFaked ) + return OneMoreFaked(); + + osl::DirectoryItem m_aDirIte; + + if( ! m_nIsOpen ) return false; + + osl::FileBase::RC err = m_aFolder.getNextItem( m_aDirIte ); + + if( err == osl::FileBase::E_NOENT || err == osl::FileBase::E_INVAL ) + { + m_aFolder.close(); + isFinalChanged(); + return ( m_nIsOpen = false ); + } + else if( err == osl::FileBase::E_None ) + { + sal_Bool IsRegular; + rtl::OUString aUnqPath; + uno::Reference< sdbc::XRow > aRow = m_pMyShell->getv( -1,this,m_sProperty,m_aDirIte,aUnqPath,IsRegular ); + + if( m_nOpenMode == OpenMode::DOCUMENTS ) + { + if( IsRegular ) + { + vos::OGuard aGuard( m_aMutex ); + m_aItems.push_back( aRow ); + m_aIdents.push_back( uno::Reference< XContentIdentifier >() ); + m_aUnqPath.push_back( aUnqPath ); + rowCountChanged(); + return true; + } + else + { + return OneMore(); + } + } + else if( m_nOpenMode == OpenMode::FOLDERS ) + { + if( ! IsRegular ) + { + vos::OGuard aGuard( m_aMutex ); + m_aItems.push_back( aRow ); + m_aIdents.push_back( uno::Reference< XContentIdentifier >() ); + m_aUnqPath.push_back( aUnqPath ); + rowCountChanged(); + return true; + } + else + { + return OneMore(); + } + } + else + { + vos::OGuard aGuard( m_aMutex ); + m_aItems.push_back( aRow ); + m_aIdents.push_back( uno::Reference< XContentIdentifier >() ); + m_aUnqPath.push_back( aUnqPath ); + rowCountChanged(); + return true; + } + } + else + { + throw sdbc::SQLException(); + return false; + } +} + + +sal_Bool SAL_CALL +XResultSet_impl::next( + void ) + throw( sdbc::SQLException, + uno::RuntimeException ) +{ + sal_Bool test; + if( ++m_nRow < m_aItems.size() ) test = true; + else test = OneMore(); + return test; +} + + +sal_Bool SAL_CALL +XResultSet_impl::isBeforeFirst( + void ) + throw( sdbc::SQLException, + uno::RuntimeException ) +{ + return m_nRow == -1; +} + + +sal_Bool SAL_CALL +XResultSet_impl::isAfterLast( + void ) + throw( sdbc::SQLException, + uno::RuntimeException ) +{ + return m_nRow >= sal_Int32( m_aItems.size() ); // Cannot happen, if m_aFolder.isOpen() +} + + +sal_Bool SAL_CALL +XResultSet_impl::isFirst( + void ) + throw( sdbc::SQLException, + uno::RuntimeException ) +{ + return m_nRow == 0; +} + + +sal_Bool SAL_CALL +XResultSet_impl::isLast( + void ) + throw( sdbc::SQLException, + uno::RuntimeException) +{ + if( m_nRow == m_aItems.size() - 1 ) + return ! OneMore(); + else + return false; +} + + +void SAL_CALL +XResultSet_impl::beforeFirst( + void ) + throw( sdbc::SQLException, + uno::RuntimeException) +{ + m_nRow = -1; +} + + +void SAL_CALL +XResultSet_impl::afterLast( + void ) + throw( sdbc::SQLException, + uno::RuntimeException ) +{ + m_nRow = m_aItems.size(); + while( OneMore() ) + ++m_nRow; +} + + +sal_Bool SAL_CALL +XResultSet_impl::first( + void ) + throw( sdbc::SQLException, + uno::RuntimeException) +{ + m_nRow = -1; + return next(); +} + + +sal_Bool SAL_CALL +XResultSet_impl::last( + void ) + throw( sdbc::SQLException, + uno::RuntimeException ) +{ + m_nRow = m_aItems.size() - 1; + while( OneMore() ) + ++m_nRow; + return true; +} + + +sal_Int32 SAL_CALL +XResultSet_impl::getRow( + void ) + throw( sdbc::SQLException, + uno::RuntimeException) +{ + // Test, whether behind last row + if( -1 == m_nRow || m_nRow >= m_aItems.size() ) + return 0; + else + return m_nRow+1; +} + + +sal_Bool SAL_CALL +XResultSet_impl::absolute( + sal_Int32 row ) + throw( sdbc::SQLException, + uno::RuntimeException) +{ + if( !row ) + throw sdbc::SQLException(); + + if( row >= 0 ) + { + m_nRow = -1; + while( row-- ) next(); + } + else + { + row = - row - 1; + last(); + while( row-- ) --m_nRow; + } + + return 0<= m_nRow && m_nRow < m_aItems.size(); +} + + +sal_Bool SAL_CALL +XResultSet_impl::relative( + sal_Int32 row ) + throw( sdbc::SQLException, + uno::RuntimeException) +{ + if( isAfterLast() || isBeforeFirst() ) + throw sdbc::SQLException(); + if( row > 0 ) + while( row-- ) next(); + else if( row < 0 ) + while( row++ && m_nRow > - 1 ) previous(); + + return 0 <= m_nRow && m_nRow < m_aItems.size(); +} + + + +sal_Bool SAL_CALL +XResultSet_impl::previous( + void ) + throw( sdbc::SQLException, + uno::RuntimeException) +{ + if( m_nRow > m_aItems.size() ) + m_nRow = m_aItems.size(); // Correct Handling of afterLast + if( 0 <= m_nRow ) -- m_nRow; + + return 0 <= m_nRow && m_nRow < m_aItems.size(); +} + + +void SAL_CALL +XResultSet_impl::refreshRow( + void ) + throw( sdbc::SQLException, + uno::RuntimeException) +{ + // get the row from the filesystem + return; +} + + +sal_Bool SAL_CALL +XResultSet_impl::rowUpdated( + void ) + throw( sdbc::SQLException, + uno::RuntimeException ) +{ + return false; +} + +sal_Bool SAL_CALL +XResultSet_impl::rowInserted( + void ) + throw( sdbc::SQLException, + uno::RuntimeException ) +{ + return false; +} + +sal_Bool SAL_CALL +XResultSet_impl::rowDeleted( + void ) + throw( sdbc::SQLException, + uno::RuntimeException ) +{ + return false; +} + + +uno::Reference< uno::XInterface > SAL_CALL +XResultSet_impl::getStatement( + void ) + throw( sdbc::SQLException, + uno::RuntimeException ) +{ + uno::Reference< uno::XInterface > test( 0 ); + return test; +} + + +// XCloseable + +void SAL_CALL +XResultSet_impl::close( + void ) + throw( sdbc::SQLException, + uno::RuntimeException) +{ + if( m_nIsOpen ) + { + if( ! m_bFaked ) + m_aFolder.close(); + + isFinalChanged(); + vos::OGuard aGuard( m_aMutex ); + m_nIsOpen = false; + } +} + + + +rtl::OUString SAL_CALL +XResultSet_impl::queryContentIdentfierString( + void ) + throw( uno::RuntimeException ) +{ + uno::Reference< XContentIdentifier > xContentId = queryContentIdentifier(); + + if( xContentId.is() ) + return xContentId->getContentIdentifier(); + else + return rtl::OUString(); +} + + +uno::Reference< XContentIdentifier > SAL_CALL +XResultSet_impl::queryContentIdentifier( + void ) + throw( uno::RuntimeException ) +{ + if( 0 <= m_nRow && m_nRow < m_aItems.size() ) + { + if( ! m_aIdents[m_nRow].is() ) + { + FileContentIdentifier* p = new FileContentIdentifier( m_pMyShell,m_aUnqPath[ m_nRow ] ); + m_aIdents[m_nRow] = uno::Reference< XContentIdentifier >(p); + } + return m_aIdents[m_nRow]; + } + return uno::Reference< XContentIdentifier >(); +} + + +uno::Reference< XContent > SAL_CALL +XResultSet_impl::queryContent( + void ) + throw( uno::RuntimeException ) +{ + if( 0 <= m_nRow && m_nRow < m_aItems.size() ) + return m_pMyShell->m_pProvider->queryContent( queryContentIdentifier() ); + else + return uno::Reference< XContent >(); +} + + +// XDynamicResultSet + + +// virtual +uno::Reference< sdbc::XResultSet > SAL_CALL +XResultSet_impl::getStaticResultSet() + throw( ListenerAlreadySetException, + uno::RuntimeException ) +{ + vos::OGuard aGuard( m_aMutex ); + + if ( m_xListener.is() ) + throw ListenerAlreadySetException(); + + return uno::Reference< sdbc::XResultSet >( this ); +} + +//========================================================================= +// virtual +void SAL_CALL +XResultSet_impl::setListener( + const uno::Reference< XDynamicResultSetListener >& Listener ) + throw( ListenerAlreadySetException, + uno::RuntimeException ) +{ + vos::OClearableGuard aGuard( m_aMutex ); + + if ( m_xListener.is() ) + throw ListenerAlreadySetException(); + + m_xListener = Listener; + + ////////////////////////////////////////////////////////////////////// + // Create "welcome event" and send it to listener. + ////////////////////////////////////////////////////////////////////// + + // Note: We only have the implementation for a static result set at the + // moment (src590). The dynamic result sets passed to the listener + // are a fake. This implementation will never call "notify" at the + // listener to propagate any changes!!! + + uno::Any aInfo; + aInfo <<= WelcomeDynamicResultSetStruct( this, /* "old" */ + this /* "new" */ ); + + uno::Sequence< ListAction > aActions( 1 ); + aActions.getArray()[ 0 ] = ListAction( 0, // Position; not used + 0, // Count; not used + ListActionType::WELCOME, + aInfo ); + aGuard.clear(); + + Listener->notify( + ListEvent( static_cast< cppu::OWeakObject * >( this ), aActions ) ); +} + +//========================================================================= +// virtual +void SAL_CALL +XResultSet_impl::connectToCache( + const uno::Reference< XDynamicResultSet > & xCache ) + throw( ListenerAlreadySetException, + AlreadyInitializedException, + ServiceNotFoundException, + uno::RuntimeException ) +{ + //@todo check this implementation; get XMultiServiceFactory + uno::Reference< lang::XMultiServiceFactory > mxSMgr = m_pMyShell->m_xMultiServiceFactory; + + if( m_xListener.is() ) + throw ListenerAlreadySetException(); + if( m_bStatic ) + throw ListenerAlreadySetException(); + + uno::Reference< XSourceInitialization > xTarget( xCache, uno::UNO_QUERY ); + if( xTarget.is() && mxSMgr.is() ) + { + uno::Reference< XCachedDynamicResultSetStubFactory > xStubFactory( + mxSMgr->createInstance( rtl::OUString::createFromAscii( + "com.sun.star.ucb.CachedDynamicResultSetStubFactory" ) ), uno::UNO_QUERY ); + if( xStubFactory.is() ) + { + xStubFactory->connectToCache( + this, xCache,m_sSortingInfo, NULL ); + return; + } + } + throw ServiceNotFoundException(); +} + +//========================================================================= +// virtual +sal_Int16 SAL_CALL +XResultSet_impl::getCapabilities() + throw( uno::RuntimeException ) +{ + // Never set ContentResultSetCapability::SORTED + // - Underlying ChaosContent cannot provide sorted data... + return 0; +} + +// XResultSetMetaDataSupplier +uno::Reference< sdbc::XResultSetMetaData > SAL_CALL +XResultSet_impl::getMetaData( + void ) + throw( sdbc::SQLException, + uno::RuntimeException ) +{ + ::ucb::ResultSetMetaData* p = + new ::ucb::ResultSetMetaData( m_pMyShell->m_xMultiServiceFactory, + m_sProperty ); + return uno::Reference< sdbc::XResultSetMetaData >( p ); +} + + + +// XPropertySet +uno::Reference< beans::XPropertySetInfo > SAL_CALL +XResultSet_impl::getPropertySetInfo() + throw( uno::RuntimeException) +{ + + uno::Sequence< beans::Property > seq(2); + seq[0].Name = rtl::OUString::createFromAscii( "RowCount" ); + seq[0].Handle = -1; + seq[0].Type = getCppuType( static_cast< sal_Int32* >(0) ); + seq[0].Attributes = beans::PropertyAttribute::READONLY; + + seq[0].Name = rtl::OUString::createFromAscii( "IsRowCountFinal" ); + seq[0].Handle = -1; + seq[0].Type = getCppuType( static_cast< sal_Bool* >(0) ); + seq[0].Attributes = beans::PropertyAttribute::READONLY; + + XPropertySetInfo_impl* p = new XPropertySetInfo_impl( m_pMyShell, + seq ); + return uno::Reference< beans::XPropertySetInfo > ( p ); +} + + + +void SAL_CALL XResultSet_impl::setPropertyValue( + const rtl::OUString& aPropertyName, const uno::Any& aValue ) + throw( beans::UnknownPropertyException, + beans::PropertyVetoException, + lang::IllegalArgumentException, + lang::WrappedTargetException, + uno::RuntimeException) +{ + if( aPropertyName == rtl::OUString::createFromAscii( "IsRowCountFinal" ) || + aPropertyName == rtl::OUString::createFromAscii( "RowCount" ) ) + return; + throw beans::UnknownPropertyException(); +} + + +uno::Any SAL_CALL XResultSet_impl::getPropertyValue( + const rtl::OUString& PropertyName ) + throw( beans::UnknownPropertyException, + lang::WrappedTargetException, + uno::RuntimeException) +{ + if( PropertyName == rtl::OUString::createFromAscii( "IsRowCountFinal" ) ) + { + uno::Any aAny; + aAny <<= m_bRowCountFinal; + return aAny; + } + else if ( PropertyName == rtl::OUString::createFromAscii( "RowCount" ) ) + { + uno::Any aAny; + sal_Int32 count = m_aItems.size(); + aAny <<= count; + return aAny; + } + else + throw beans::UnknownPropertyException(); +} + + +void SAL_CALL XResultSet_impl::addPropertyChangeListener( + const rtl::OUString& aPropertyName, + const uno::Reference< beans::XPropertyChangeListener >& xListener ) + throw( beans::UnknownPropertyException, + lang::WrappedTargetException, + uno::RuntimeException) +{ + if( aPropertyName == rtl::OUString::createFromAscii( "IsRowCountFinal" ) ) + { + vos::OGuard aGuard( m_aMutex ); + if ( ! m_pIsFinalListeners ) + m_pIsFinalListeners = + new cppu::OInterfaceContainerHelper( m_aEventListenerMutex ); + + m_pIsFinalListeners->addInterface( xListener ); + } + else if ( aPropertyName == rtl::OUString::createFromAscii( "RowCount" ) ) + { + vos::OGuard aGuard( m_aMutex ); + if ( ! m_pRowCountListeners ) + m_pRowCountListeners = + new cppu::OInterfaceContainerHelper( m_aEventListenerMutex ); + m_pRowCountListeners->addInterface( xListener ); + } + else + throw beans::UnknownPropertyException(); +} + + +void SAL_CALL XResultSet_impl::removePropertyChangeListener( + const rtl::OUString& aPropertyName, + const uno::Reference< beans::XPropertyChangeListener >& aListener ) + throw( beans::UnknownPropertyException, + lang::WrappedTargetException, + uno::RuntimeException) +{ + if( aPropertyName == rtl::OUString::createFromAscii( "IsRowCountFinal" ) && + m_pIsFinalListeners ) + { + vos::OGuard aGuard( m_aMutex ); + m_pIsFinalListeners->removeInterface( aListener ); + } + else if ( aPropertyName == rtl::OUString::createFromAscii( "RowCount" ) && + m_pRowCountListeners ) + { + vos::OGuard aGuard( m_aMutex ); + + m_pRowCountListeners->removeInterface( aListener ); + } + else + throw beans::UnknownPropertyException(); +} + +void SAL_CALL XResultSet_impl::addVetoableChangeListener( + const rtl::OUString& PropertyName, + const uno::Reference< beans::XVetoableChangeListener >& aListener ) + throw( beans::UnknownPropertyException, + lang::WrappedTargetException, + uno::RuntimeException) +{ +} + + +void SAL_CALL XResultSet_impl::removeVetoableChangeListener( + const rtl::OUString& PropertyName, + const uno::Reference< beans::XVetoableChangeListener >& aListener ) + throw( beans::UnknownPropertyException, + lang::WrappedTargetException, + uno::RuntimeException) +{ +} + + + diff --git a/ucb/source/ucp/file/filrset.hxx b/ucb/source/ucp/file/filrset.hxx new file mode 100644 index 000000000000..c0314da3ad73 --- /dev/null +++ b/ucb/source/ucp/file/filrset.hxx @@ -0,0 +1,736 @@ +/************************************************************************* + * + * $RCSfile: filrset.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:53:36 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _FILRSET_HXX_ +#define _FILRSET_HXX_ + +#ifndef __SGI_STL_VECTOR +#include <stl/vector> +#endif + +#ifndef _OSL_FILE_HXX_ +#include <osl/file.hxx> +#endif +#ifndef _CPPUHELPER_WEAK_HXX_ +#include <cppuhelper/weak.hxx> +#endif +#ifndef _CPPUHELPER_INTERFACECONTAINER_HXX_ +#include <cppuhelper/interfacecontainer.hxx> +#endif +#ifndef _COM_SUN_STAR_UCB_XCONTENTACCESS_HPP_ +#include <com/sun/star/ucb/XContentAccess.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XCLOSEABLE_HPP_ +#include <com/sun/star/sdbc/XCloseable.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_ +#include <com/sun/star/beans/XPropertySet.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XDYNAMICRESULTSET_HPP__ +#include <com/sun/star/ucb/XDynamicResultSet.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XDYNAMICRESULTSETLISTENER_HPP_ +#include <com/sun/star/ucb/XDynamicResultSetListener.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XRESULTSETMETADATASUPPLIER_HPP_ +#include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_NUMBEREDSORTINGINFO_HPP_ +#include <com/sun/star/ucb/NumberedSortingInfo.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCONTENTPROVIDER_HPP_ +#include <com/sun/star/ucb/XContentProvider.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCONTENTIDENTIFIER_HPP_ +#include <com/sun/star/ucb/XContentIdentifier.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_PROPERTY_HPP_ +#include <com/sun/star/beans/Property.hpp> +#endif + +#ifndef _FILROW_HXX_ +#include "filrow.hxx" +#endif +#ifndef _FILNOT_HXX_ +#include "filnot.hxx" +#endif + + + +namespace fileaccess { + + class Notifier; + + class XResultSet_impl + : public cppu::OWeakObject, + public com::sun::star::lang::XEventListener, + public com::sun::star::sdbc::XRow, + public com::sun::star::sdbc::XResultSet, + public com::sun::star::ucb::XDynamicResultSet, + public com::sun::star::sdbc::XCloseable, + public com::sun::star::sdbc::XResultSetMetaDataSupplier, + public com::sun::star::beans::XPropertySet, + public com::sun::star::ucb::XContentAccess, + public Notifier + { + public: + + XResultSet_impl( shell* pMyShell, + const rtl::OUString& aUnqPath, + sal_Int32 OpenMode, + const com::sun::star::uno::Sequence< com::sun::star::beans::Property >& seq, + const com::sun::star::uno::Sequence< com::sun::star::ucb::NumberedSortingInfo >& seqSort ); + + virtual ~XResultSet_impl(); + + virtual ContentEventNotifier* cDEL( void ) + { + return 0; + } + + virtual ContentEventNotifier* cEXC( const rtl::OUString aNewName ) + { + return 0; + } + + virtual ContentEventNotifier* cCEL( void ) + { + return 0; + } + + virtual PropertySetInfoChangeNotifier* cPSL( void ) + { + return 0; + } + + virtual PropertyChangeNotifier* cPCL( void ) + { + return 0; + } + + virtual rtl::OUString getKey( void ) + { + return m_aBaseDirectory; + } + + sal_Bool SAL_CALL CtorSuccess(); + + // XInterface + virtual com::sun::star::uno::Any SAL_CALL + queryInterface( + const com::sun::star::uno::Type& aType ) + throw( com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL + acquire( + void ) + throw( com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL + release( + void ) + throw( com::sun::star::uno::RuntimeException); + + // XEventListener + virtual void SAL_CALL + disposing( + const com::sun::star::lang::EventObject& Source ) + throw( com::sun::star::uno::RuntimeException ); + + // XComponent + virtual void SAL_CALL + dispose( + void ) + throw( com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL + addEventListener( + const com::sun::star::uno::Reference< com::sun::star::lang::XEventListener >& xListener ) + throw( com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL + removeEventListener( const com::sun::star::uno::Reference< com::sun::star::lang::XEventListener >& aListener ) + throw( com::sun::star::uno::RuntimeException ); + + + // XRow + virtual sal_Bool SAL_CALL + wasNull( + void ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ) + { + if( 0<= m_nRow && m_nRow < m_aItems.size() ) + m_nWasNull = m_aItems[m_nRow]->wasNull(); + else + m_nWasNull = true; + return m_nWasNull; + } + + virtual rtl::OUString SAL_CALL + getString( + sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException) + { + if( 0 <= m_nRow && m_nRow < m_aItems.size() ) + return m_aItems[m_nRow]->getString( columnIndex ); + else + return rtl::OUString(); + } + + virtual sal_Bool SAL_CALL + getBoolean( + sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException) + { + if( 0 <= m_nRow && m_nRow < m_aItems.size() ) + return m_aItems[m_nRow]->getBoolean( columnIndex ); + else + return false; + } + + virtual sal_Int8 SAL_CALL + getByte( + sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException) + { + if( 0 <= m_nRow && m_nRow < m_aItems.size() ) + return m_aItems[m_nRow]->getByte( columnIndex ); + else + return sal_Int8( 0 ); + } + + virtual sal_Int16 SAL_CALL + getShort( + sal_Int32 columnIndex ) + throw( + com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException) + { + if( 0 <= m_nRow && m_nRow < m_aItems.size() ) + return m_aItems[m_nRow]->getShort( columnIndex ); + else + return sal_Int16( 0 ); + } + + virtual sal_Int32 SAL_CALL + getInt( + sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ) + { + if( 0 <= m_nRow && m_nRow < m_aItems.size() ) + return m_aItems[m_nRow]->getInt( columnIndex ); + else + return sal_Int32( 0 ); + } + + virtual sal_Int64 SAL_CALL + getLong( + sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException) + { + if( 0 <= m_nRow && m_nRow < m_aItems.size() ) + return m_aItems[m_nRow]->getLong( columnIndex ); + else + return sal_Int64( 0 ); + } + + virtual float SAL_CALL + getFloat( + sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ) + { + if( 0 <= m_nRow && m_nRow < m_aItems.size() ) + return m_aItems[m_nRow]->getFloat( columnIndex ); + else + return float( 0 ); + } + + virtual double SAL_CALL + getDouble( + sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ) + { + if( 0 <= m_nRow && m_nRow < m_aItems.size() ) + return m_aItems[m_nRow]->getDouble( columnIndex ); + else + return double( 0 ); + } + + virtual com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL + getBytes( + sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ) + { + if( 0 <= m_nRow && m_nRow < m_aItems.size() ) + return m_aItems[m_nRow]->getBytes( columnIndex ); + else + return com::sun::star::uno::Sequence< sal_Int8 >(); + } + + virtual com::sun::star::util::Date SAL_CALL + getDate( + sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException) + { + if( 0 <= m_nRow && m_nRow < m_aItems.size() ) + return m_aItems[m_nRow]->getDate( columnIndex ); + else + return com::sun::star::util::Date(); + } + + virtual com::sun::star::util::Time SAL_CALL + getTime( + sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException) + { + if( 0 <= m_nRow && m_nRow < m_aItems.size() ) + return m_aItems[m_nRow]->getTime( columnIndex ); + else + return com::sun::star::util::Time(); + } + + virtual com::sun::star::util::DateTime SAL_CALL + getTimestamp( + sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException) + { + if( 0 <= m_nRow && m_nRow < m_aItems.size() ) + return m_aItems[m_nRow]->getTimestamp( columnIndex ); + else + return com::sun::star::util::DateTime(); + } + + virtual com::sun::star::uno::Reference< com::sun::star::io::XInputStream > SAL_CALL + getBinaryStream( + sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException) + { + if( 0 <= m_nRow && m_nRow < m_aItems.size() ) + return m_aItems[m_nRow]->getBinaryStream( columnIndex ); + else + return com::sun::star::uno::Reference< com::sun::star::io::XInputStream >(); + } + + virtual com::sun::star::uno::Reference< com::sun::star::io::XInputStream > SAL_CALL + getCharacterStream( + sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException) + { + if( 0 <= m_nRow && m_nRow < m_aItems.size() ) + return m_aItems[m_nRow]->getCharacterStream( columnIndex ); + else + return com::sun::star::uno::Reference< com::sun::star::io::XInputStream >(); + } + + virtual com::sun::star::uno::Any SAL_CALL + getObject( + sal_Int32 columnIndex, + const com::sun::star::uno::Reference< com::sun::star::container::XNameAccess >& typeMap ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException) + { + if( 0 <= m_nRow && m_nRow < m_aItems.size() ) + return m_aItems[m_nRow]->getObject( columnIndex,typeMap ); + else + return com::sun::star::uno::Any(); + } + + virtual com::sun::star::uno::Reference< com::sun::star::sdbc::XRef > SAL_CALL + getRef( + sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException) + { + if( 0 <= m_nRow && m_nRow < m_aItems.size() ) + return m_aItems[m_nRow]->getRef( columnIndex ); + else + return com::sun::star::uno::Reference< com::sun::star::sdbc::XRef >(); + } + + virtual com::sun::star::uno::Reference< com::sun::star::sdbc::XBlob > SAL_CALL + getBlob( + sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException) + { + if( 0 <= m_nRow && m_nRow < m_aItems.size() ) + return m_aItems[m_nRow]->getBlob( columnIndex ); + else + return com::sun::star::uno::Reference< com::sun::star::sdbc::XBlob >(); + } + + virtual com::sun::star::uno::Reference< com::sun::star::sdbc::XClob > SAL_CALL + getClob( + sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException) + { + if( 0 <= m_nRow && m_nRow < m_aItems.size() ) + return m_aItems[m_nRow]->getClob( columnIndex ); + else + return com::sun::star::uno::Reference< com::sun::star::sdbc::XClob >(); + } + + virtual com::sun::star::uno::Reference< com::sun::star::sdbc::XArray > SAL_CALL + getArray( + sal_Int32 columnIndex ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException) + { + if( 0 <= m_nRow && m_nRow < m_aItems.size() ) + return m_aItems[m_nRow]->getArray( columnIndex ); + else + return com::sun::star::uno::Reference< com::sun::star::sdbc::XArray >(); + } + + + // XResultSet + + virtual sal_Bool SAL_CALL + next( + void ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException); + + virtual sal_Bool SAL_CALL + isBeforeFirst( + void ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException); + + virtual sal_Bool SAL_CALL + isAfterLast( + void ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException); + + virtual sal_Bool SAL_CALL + isFirst( + void ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException); + + virtual sal_Bool SAL_CALL + isLast( + void ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL + beforeFirst( + void ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL + afterLast( + void ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException); + + virtual sal_Bool SAL_CALL + first( + void ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException); + + virtual sal_Bool SAL_CALL + last( + void ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException); + + virtual sal_Int32 SAL_CALL + getRow( + void ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException); + + virtual sal_Bool SAL_CALL + absolute( + sal_Int32 row ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException); + + virtual sal_Bool SAL_CALL + relative( + sal_Int32 rows ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException); + + virtual sal_Bool SAL_CALL + previous( + void ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL + refreshRow( + void ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException); + + virtual sal_Bool SAL_CALL + rowUpdated( + void ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException); + + virtual sal_Bool SAL_CALL + rowInserted( + void ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException); + + virtual sal_Bool SAL_CALL + rowDeleted( + void ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException); + + + virtual com::sun::star::uno::Reference< com::sun::star::uno::XInterface > SAL_CALL + getStatement( + void ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException); + + + // XDynamicResultSet + + virtual com::sun::star::uno::Reference< com::sun::star::sdbc::XResultSet > SAL_CALL + getStaticResultSet( + void ) + throw( com::sun::star::ucb::ListenerAlreadySetException, + com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL + setListener( + const com::sun::star::uno::Reference< + com::sun::star::ucb::XDynamicResultSetListener >& Listener ) + throw( com::sun::star::ucb::ListenerAlreadySetException, + com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL + connectToCache( const com::sun::star::uno::Reference< com::sun::star::ucb::XDynamicResultSet > & xCache ) + throw( com::sun::star::ucb::ListenerAlreadySetException, + com::sun::star::ucb::AlreadyInitializedException, + com::sun::star::ucb::ServiceNotFoundException, + com::sun::star::uno::RuntimeException ); + + virtual sal_Int16 SAL_CALL + getCapabilities() + throw( com::sun::star::uno::RuntimeException ); + + + // XCloseable + + virtual void SAL_CALL + close( + void ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException); + + // XContentAccess + + virtual rtl::OUString SAL_CALL + queryContentIdentfierString( + void ) + throw( com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::uno::Reference< com::sun::star::ucb::XContentIdentifier > SAL_CALL + queryContentIdentifier( + void ) + throw( com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::uno::Reference< com::sun::star::ucb::XContent > SAL_CALL + queryContent( + void ) + throw( com::sun::star::uno::RuntimeException ); + + // XResultSetMetaDataSupplier + virtual com::sun::star::uno::Reference< com::sun::star::sdbc::XResultSetMetaData > SAL_CALL + getMetaData( + void ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException); + + + // XPropertySet + virtual com::sun::star::uno::Reference< com::sun::star::beans::XPropertySetInfo > SAL_CALL + getPropertySetInfo() + throw( com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL setPropertyValue( + const rtl::OUString& aPropertyName, + const com::sun::star::uno::Any& aValue ) + throw( com::sun::star::beans::UnknownPropertyException, + com::sun::star::beans::PropertyVetoException, + com::sun::star::lang::IllegalArgumentException, + com::sun::star::lang::WrappedTargetException, + com::sun::star::uno::RuntimeException); + + virtual com::sun::star::uno::Any SAL_CALL + getPropertyValue( + const rtl::OUString& PropertyName ) + throw( com::sun::star::beans::UnknownPropertyException, + com::sun::star::lang::WrappedTargetException, + com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL + addPropertyChangeListener( + const rtl::OUString& aPropertyName, + const com::sun::star::uno::Reference< com::sun::star::beans::XPropertyChangeListener >& xListener ) + throw( com::sun::star::beans::UnknownPropertyException, + com::sun::star::lang::WrappedTargetException, + com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL + removePropertyChangeListener( + const rtl::OUString& aPropertyName, + const com::sun::star::uno::Reference< com::sun::star::beans::XPropertyChangeListener >& aListener ) + throw( com::sun::star::beans::UnknownPropertyException, + com::sun::star::lang::WrappedTargetException, + com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL + addVetoableChangeListener( + const rtl::OUString& PropertyName, + const com::sun::star::uno::Reference< com::sun::star::beans::XVetoableChangeListener >& aListener ) + throw( com::sun::star::beans::UnknownPropertyException, + com::sun::star::lang::WrappedTargetException, + com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL removeVetoableChangeListener( + const rtl::OUString& PropertyName, + const com::sun::star::uno::Reference< com::sun::star::beans::XVetoableChangeListener >& aListener ) + throw( com::sun::star::beans::UnknownPropertyException, + com::sun::star::lang::WrappedTargetException, + com::sun::star::uno::RuntimeException); + + private: + + // Members + // const uno::Reference< lang::XMultiServiceFactory > m_xMSF; + // const uno::Reference< ucb::XContentProvider > m_xProvider; + + shell* m_pMyShell; + com::sun::star::uno::Reference< com::sun::star::ucb::XContentProvider > m_xProvider; + sal_Bool m_nIsOpen; + sal_Int32 m_nRow; + sal_Bool m_nWasNull; + sal_Int32 m_nOpenMode; + sal_Bool m_bRowCountFinal; + + typedef std::vector< com::sun::star::uno::Reference< com::sun::star::ucb::XContentIdentifier > > IdentSet; + typedef std::vector< com::sun::star::uno::Reference< com::sun::star::sdbc::XRow > > ItemSet; + typedef std::vector< rtl::OUString > UnqPathSet; + + IdentSet m_aIdents; + ItemSet m_aItems; + UnqPathSet m_aUnqPath; + const rtl::OUString m_aBaseDirectory; + + osl::Directory m_aFolder; + com::sun::star::uno::Sequence< com::sun::star::beans::Property > m_sProperty; + com::sun::star::uno::Sequence< com::sun::star::ucb::NumberedSortingInfo > m_sSortingInfo; + + vos::OMutex m_aMutex; + osl::Mutex m_aEventListenerMutex; + cppu::OInterfaceContainerHelper* m_pDisposeEventListeners; + + cppu::OInterfaceContainerHelper* m_pRowCountListeners; + cppu::OInterfaceContainerHelper* m_pIsFinalListeners; + + com::sun::star::uno::Reference< com::sun::star::ucb::XDynamicResultSetListener > m_xListener; + sal_Bool m_bStatic, m_bFaked; + + // Methods + sal_Bool SAL_CALL OneMore( void ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + sal_Bool SAL_CALL OneMoreFaked( void ) + throw( com::sun::star::sdbc::SQLException, + com::sun::star::uno::RuntimeException ); + + void rowCountChanged(); + void isFinalChanged(); + }; + + +} // end namespace fileaccess + + +#endif diff --git a/ucb/source/ucp/file/filtask.cxx b/ucb/source/ucp/file/filtask.cxx new file mode 100644 index 000000000000..21e81121a6f9 --- /dev/null +++ b/ucb/source/ucp/file/filtask.cxx @@ -0,0 +1,138 @@ +/************************************************************************* + * + * $RCSfile: filtask.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:53:36 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _FILTASK_HXX_ +#include "filtask.hxx" +#endif + +/*********************************************************************************/ +/* */ +/* TaskHandling */ +/* */ +/*********************************************************************************/ + +using namespace fileaccess; +using namespace com::sun::star; +using namespace com::sun::star::ucb; + + +TaskManager::TaskManager() + : m_nCommandId( 0 ) +{ +} + + + +TaskManager::~TaskManager() +{ +} + + + +void SAL_CALL +TaskManager::startTask( + sal_Int32 CommandId, + const uno::Reference< task::XInteractionHandler >& xIH, + const uno::Reference< XProgressHandler >& xPH ) + throw( CommandAbortedException ) +{ + vos::OGuard aGuard( m_aMutex ); + TaskMap::iterator it = m_aTaskMap.find( CommandId ); + if( it != m_aTaskMap.end() ) + { + throw CommandAbortedException(); + } + m_aTaskMap[ CommandId ] = TaskHandling( xIH,xPH ); +} + + + +void SAL_CALL +TaskManager::endTask( sal_Int32 CommandId ) +{ + vos::OGuard aGuard( m_aMutex ); + TaskMap::iterator it = m_aTaskMap.find( CommandId ); + if( it == m_aTaskMap.end() ) + return; + else + m_aTaskMap.erase( it ); +} + + + +void SAL_CALL +TaskManager::abort( sal_Int32 CommandId ) +{ + vos::OGuard aGuard( m_aMutex ); + TaskMap::iterator it = m_aTaskMap.find( CommandId ); + if( it == m_aTaskMap.end() ) + return; + else + it->second.setAbort(); +} + + + +sal_Int32 SAL_CALL +TaskManager::getCommandId( void ) +{ + vos::OGuard aGuard( m_aMutex ); + return ++m_nCommandId; +} diff --git a/ucb/source/ucp/file/filtask.hxx b/ucb/source/ucp/file/filtask.hxx new file mode 100644 index 000000000000..da4aaee1a6d1 --- /dev/null +++ b/ucb/source/ucp/file/filtask.hxx @@ -0,0 +1,150 @@ +/************************************************************************* + * + * $RCSfile: filtask.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:53:36 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _FILTASK_HXX_ +#define _FILTASK_HXX_ +#endif + +#ifndef __SGI_STL_HASH_MAP +#include <stl/hash_map> +#endif +#ifndef _VOS_MUTEX_HXX_ +#include <vos/mutex.hxx> +#endif +#ifndef _COM_SUN_STAR_UCB_COMMANDABORTEDEXCEPTION_HPP_ +#include <com/sun/star/ucb/CommandAbortedException.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XPROGRESSHANDLER_HPP_ +#include <com/sun/star/ucb/XProgressHandler.hpp> +#endif +#ifndef _COM_SUN_STAR_TASK_XINTERACTIONHANDLER_HPP_ +#include <com/sun/star/task/XInteractionHandler.hpp> +#endif + +namespace fileaccess +{ + class TaskManager + { + protected: + // Typ definitions + struct equal_sal_Int32 + { + bool operator() ( sal_Int32 a, sal_Int32 b ) const + { + return a == b; + } + }; + + + class TaskHandling + { + private: + sal_Bool m_bAbort; + com::sun::star::uno::Reference< com::sun::star::task::XInteractionHandler > m_xInteractionHandler; + com::sun::star::uno::Reference< com::sun::star::ucb::XProgressHandler > m_xProgressHandler; + + public: + TaskHandling() + : m_xInteractionHandler( 0 ), + m_xProgressHandler( 0 ), + m_bAbort( false ) + { + + } + TaskHandling( + const com::sun::star::uno::Reference< com::sun::star::task::XInteractionHandler >& m_xIH, + const com::sun::star::uno::Reference< com::sun::star::ucb::XProgressHandler >& m_xPH ) + : m_xInteractionHandler( m_xIH ), + m_xProgressHandler( m_xPH ), + m_bAbort( false ) + { + } + + void SAL_CALL setAbort() + { + m_bAbort = true; + } + + }; + + typedef std::hash_map< sal_Int32,TaskHandling,std::hash< sal_Int32 >, equal_sal_Int32 > TaskMap; + + private: + vos::OMutex m_aMutex; + sal_Int32 m_nCommandId; + TaskMap m_aTaskMap; + + public: + + TaskManager(); + virtual ~TaskManager(); + + void SAL_CALL startTask( + sal_Int32 CommandId, + const com::sun::star::uno::Reference< com::sun::star::task::XInteractionHandler >& xIH, + const com::sun::star::uno::Reference< com::sun::star::ucb::XProgressHandler >& xPH ) + throw( com::sun::star::ucb::CommandAbortedException ); + + void SAL_CALL endTask( sal_Int32 CommandId ); + sal_Int32 SAL_CALL getCommandId( void ); + void SAL_CALL abort( sal_Int32 CommandId ); + }; + +} // end namespace TaskHandling diff --git a/ucb/source/ucp/file/makefile.mk b/ucb/source/ucp/file/makefile.mk new file mode 100644 index 000000000000..dd7b9428d019 --- /dev/null +++ b/ucb/source/ucp/file/makefile.mk @@ -0,0 +1,130 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1 $ +# +# last change: $Author: kso $ $Date: 2000-10-16 14:53:36 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (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.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=..$/..$/.. +PRJNAME=ucb +TARGET=ucpfile +ENABLE_EXCEPTIONS=TRUE +NO_BSYMBOLIC=TRUE + +# Version +UCPFILE_MAJOR=1 + +.INCLUDE: svpre.mk +.INCLUDE: settings.mk +.INCLUDE: sv.mk + +SLOFILES=\ + $(SLO)$/prov.obj \ + $(SLO)$/bc.obj \ + $(SLO)$/shell.obj \ + $(SLO)$/filtask.obj \ + $(SLO)$/filrow.obj \ + $(SLO)$/filrset.obj \ + $(SLO)$/filid.obj \ + $(SLO)$/filnot.obj \ + $(SLO)$/filprp.obj + +# NETBSD: somewhere we have to instantiate the static data members. +# NETBSD-1.2.1 doesn't know about weak symbols so the default mechanism for GCC won't work. +# SCO and MACOSX: the linker does know about weak symbols, but we can't ignore multiple defined symbols +.IF "$(OS)"=="NETBSD" || "$(OS)"=="SCO" || "$(OS)$(COM)"=="OS2GCC" || "$(OS)"=="MACOSX" +SLOFILES+=$(SLO)$/staticmbfile.obj +.ENDIF + +LIB1TARGET=$(SLB)$/_$(TARGET).lib +LIB1OBJFILES=$(SLOFILES) + +SHL1TARGET=$(TARGET)$(UCPFILE_MAJOR) +SHL1DEF=$(MISC)$/$(SHL1TARGET).def +SHL1LIBS=$(LIB1TARGET) +SHL1IMPLIB=i$(TARGET) +SHL1STDLIBS=\ + $(CPPUHELPERLIB) \ + $(CPPULIB) \ + $(SALLIB) \ + $(VOSLIB) \ + $(UCBHELPERLIB) + +DEF1DEPN=$(MISC)$/$(SHL1TARGET).flt +DEF1NAME=$(SHL1TARGET) +DEF1EXPORT1 =component_getImplementationEnvironment +DEF1EXPORT2 =component_writeInfo +DEF1EXPORT3 =component_getFactory +DEF1DES=UCB : File System Content Provider + +.INCLUDE: target.mk + +$(MISC)$/$(SHL1TARGET).flt: + @echo ------------------------------ + @echo Making: $@ +# @echo Type >> $@ + @echo cpp >> $@ + @echo m_ >> $@ + @echo rtl >> $@ + @echo vos >> $@ + @echo component_getImplementationEnvironment >> $@ + @echo component_writeInfo >> $@ + @echo component_getFactory >> $@ +.IF "$(COM)"=="MSC" + @echo ??_ >> $@ +.ENDIF # COM MSC diff --git a/ucb/source/ucp/file/prov.cxx b/ucb/source/ucp/file/prov.cxx new file mode 100644 index 000000000000..a10fd6e3e688 --- /dev/null +++ b/ucb/source/ucp/file/prov.cxx @@ -0,0 +1,780 @@ +/************************************************************************* + * + * $RCSfile: prov.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:53:36 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _OSL_FILE_HXX_ +#include <osl/file.hxx> +#endif +#ifndef _OSL_SOCKET_H_ +#include <osl/socket.h> +#endif +#ifndef _VOS_DIAGNOSE_HXX_ +#include <vos/diagnose.hxx> +#endif +#ifndef _CPPUHELPER_FACTORY_HXX_ +#include <cppuhelper/factory.hxx> +#endif +#ifndef _COM_SUN_STAR_REGISTRY_XREGISTRYKEY_HPP_ +#include <com/sun/star/registry/XRegistryKey.hpp> +#endif +#ifndef COM_SUN_STAR_CONTAINER_XHIERARCHICALNAMEACCESS_HPP_ +#include <com/sun/star/container/XHierarchicalNameAccess.hpp> +#endif +#ifndef _COM_SUN_STAR_FRAME_XCONFIGMANAGER_HPP_ +#include <com/sun/star/frame/XConfigManager.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBBUTE_HPP_ +#include <com/sun/star/beans/PropertyAttribute.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_FILESYSTEMNOTATION_HPP_ +#include <com/sun/star/ucb/FileSystemNotation.hpp> +#endif +#ifndef _FILID_HXX_ +#include "filid.hxx" +#endif +#ifndef _SHELL_HXX_ +#include "shell.hxx" +#endif +#ifndef _BC_HXX_ +#include "bc.hxx" +#endif +#ifndef _PROV_HXX_ +#include "prov.hxx" +#endif + +using namespace fileaccess; +using namespace com::sun::star; +using namespace com::sun::star::ucb; + +//========================================================================= +static sal_Bool writeInfo( void * pRegistryKey, + const rtl::OUString & rImplementationName, + uno::Sequence< rtl::OUString > const & rServiceNames ) +{ + rtl::OUString aKeyName( rtl::OUString::createFromAscii( "/" ) ); + aKeyName += rImplementationName; + aKeyName += rtl::OUString::createFromAscii( "/UNO/SERVICES" ); + + uno::Reference< registry::XRegistryKey > xKey; + try + { + xKey = static_cast< registry::XRegistryKey * >( + pRegistryKey )->createKey( aKeyName ); + } + catch ( registry::InvalidRegistryException const & ) + { + } + + if ( !xKey.is() ) + return sal_False; + + sal_Bool bSuccess = sal_True; + + for ( sal_Int32 n = 0; n < rServiceNames.getLength(); ++n ) + { + try + { + xKey->createKey( rServiceNames[ n ] ); + } + catch ( registry::InvalidRegistryException const & ) + { + bSuccess = sal_False; + break; + } + } + return bSuccess; +} + +//========================================================================= +extern "C" void SAL_CALL component_getImplementationEnvironment( + const sal_Char ** ppEnvTypeName, uno_Environment ** ppEnv ) +{ + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; +} + +//========================================================================= +extern "C" sal_Bool SAL_CALL component_writeInfo( + void * pServiceManager, void * pRegistryKey ) +{ + return pRegistryKey && + + ////////////////////////////////////////////////////////////////////// + // File Content Provider. + ////////////////////////////////////////////////////////////////////// + + writeInfo( pRegistryKey, + fileaccess::shell::getImplementationName_static(), + fileaccess::shell::getSupportedServiceNames_static() ); +} + +//========================================================================= +extern "C" void * SAL_CALL component_getFactory( + const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey ) +{ + void * pRet = 0; + + uno::Reference< lang::XMultiServiceFactory > xSMgr( + reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ) ); + uno::Reference< lang::XSingleServiceFactory > xFactory; + + ////////////////////////////////////////////////////////////////////// + // File Content Provider. + ////////////////////////////////////////////////////////////////////// + + if ( fileaccess::shell::getImplementationName_static(). + compareToAscii( pImplName ) == 0 ) + { + xFactory = FileProvider::createServiceFactory( xSMgr ); + } + + ////////////////////////////////////////////////////////////////////// + + if ( xFactory.is() ) + { + xFactory->acquire(); + pRet = xFactory.get(); + } + + return pRet; +} + +/****************************************************************************/ +/* */ +/* */ +/* FileProvider */ +/* */ +/* */ +/****************************************************************************/ + + +#ifdef UNX +extern "C" oslFileError osl_getRealPath(rtl_uString* strPath, rtl_uString** strRealPath); +#endif + +FileProvider::FileProvider( const uno::Reference< lang::XMultiServiceFactory >& xMultiServiceFactory ) + : m_xMultiServiceFactory( xMultiServiceFactory ), + m_pMyShell( 0 ) +{ + + if( ! m_pMyShell ) + m_pMyShell = new shell( m_xMultiServiceFactory, this ); + + try + { + rtl::OUString sProviderService = + rtl::OUString::createFromAscii( "com.sun.star.configuration.ConfigurationProvider" ); + + uno::Reference< lang::XMultiServiceFactory > + sProvider( + m_xMultiServiceFactory->createInstance( sProviderService ), + uno::UNO_QUERY ); + + rtl::OUString sReaderService = + rtl::OUString::createFromAscii( "com.sun.star.configuration.ConfigurationAccess" ); + + uno::Sequence< uno::Any > aArguments( 1 ); +#if SUPD > 604 + aArguments[0] <<= + rtl::OUString::createFromAscii( "org.openoffice.Security" ); +#else + aArguments[0] <<= + rtl::OUString::createFromAscii( "com.sun.star.Security" ); +#endif + uno::Reference< container::XHierarchicalNameAccess > xHierAccess( + sProvider->createInstanceWithArguments( sReaderService,aArguments ), + uno::UNO_QUERY ); + + uno::Reference< container::XNameAccess > xSubNode( xHierAccess,uno::UNO_QUERY ); + + rtl::OUString d = rtl::OUString::createFromAscii( "Directory" ); + rtl::OUString a = rtl::OUString::createFromAscii( "AliasName" ); + + rtl::OUString aRootDirectory; + if( xSubNode.is() ) + { + uno::Reference< frame::XConfigManager > xCfgMgr( + m_xMultiServiceFactory->createInstance( + rtl::OUString::createFromAscii( + "com.sun.star.config.SpecialConfigManager" ) ), + uno::UNO_QUERY ); + + uno::Any aAny = xSubNode->getByName( rtl::OUString::createFromAscii("MountPoints" ) ); + uno::Reference< container::XNameAccess > xSubSubNode; + aAny >>= xSubSubNode; + + uno::Sequence< rtl::OUString > seqNames = + xSubSubNode->getElementNames(); + for( sal_Int32 k = 0; k < seqNames.getLength(); ++k ) + { + uno::Any nocheinany = xSubSubNode->getByName( seqNames[k] ); + uno::Reference< container::XNameAccess > xAuaAuaAuaNode; + nocheinany >>= xAuaAuaAuaNode; + + uno::Any vorletztesany = xAuaAuaAuaNode->getByName( d ); + rtl::OUString aDirectory; + vorletztesany >>= aDirectory; + + uno::Any letztesany = xAuaAuaAuaNode->getByName( a ); + rtl::OUString aAliasName; + letztesany >>= aAliasName; + + VOS_ENSURE( xCfgMgr.is(), + "FileProvider::FileProvider - No Config Manager!" ); + + rtl::OUString aUnqDir; + rtl::OUString aUnqAl; + + if ( xCfgMgr.is() ) + { + // Substitute path variables, like "$(user)". + + rtl::OUString aDir + = xCfgMgr->substituteVariables( aDirectory ); + osl::FileBase::getNormalizedPathFromFileURL( aDir, aUnqDir ); + + rtl::OUString aAlias + = xCfgMgr->substituteVariables( aAliasName ); + osl::FileBase::getNormalizedPathFromFileURL( aAlias, aUnqAl ); + } + + if ( !aUnqDir.getLength() ) + m_pMyShell->getUnqFromUrl( aDirectory,aUnqDir ); + + if ( !aUnqAl.getLength() ) + m_pMyShell->getUnqFromUrl( aAliasName,aUnqAl ); + + if ( aUnqDir.getLength() && aUnqAl.getLength() ) + { + m_pMyShell->m_vecMountPoint.push_back( + shell::MountPoint( aUnqAl, aUnqDir ) ); + m_pMyShell->m_bFaked = true; + } + +#ifdef UNX + rtl::OUString aRealUnqDir; + rtl::OUString aRealUnqAlias; + + osl_getRealPath( aUnqDir.pData, &aRealUnqDir.pData ); + osl_getRealPath( aUnqAl.pData, &aRealUnqAlias.pData ); + + if ( !aRealUnqAlias.getLength() ) + aRealUnqAlias = aUnqAl; + + if ( aRealUnqDir.getLength() && aRealUnqAlias.getLength() ) + { + m_pMyShell->m_vecMountPoint.push_back( + shell::MountPoint( aRealUnqAlias, aRealUnqDir ) ); + m_pMyShell->m_bFaked = true; + } +#endif + + } + } + } + catch( ... ) + { + + } +} + +FileProvider::~FileProvider() +{ + if( m_pMyShell ) + delete m_pMyShell; +} + + +////////////////////////////////////////////////////////////////////////// +// XInterface +////////////////////////////////////////////////////////////////////////// + +void SAL_CALL +FileProvider::acquire( + void ) + throw( uno::RuntimeException ) +{ + OWeakObject::acquire(); +} + + +void SAL_CALL +FileProvider::release( + void ) + throw( uno::RuntimeException ) +{ + OWeakObject::release(); +} + + +uno::Any SAL_CALL +FileProvider::queryInterface( + const uno::Type& rType ) + throw( uno::RuntimeException ) +{ + uno::Any aRet = cppu::queryInterface( rType, + SAL_STATIC_CAST( XContentProvider*, this ), + SAL_STATIC_CAST( XContentIdentifierFactory*, this ), + SAL_STATIC_CAST( lang::XServiceInfo*, this ), + SAL_STATIC_CAST( beans::XPropertySet*, this ) ); + return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ); +} + + + +//////////////////////////////////////////////////////////////////////////////// +// XServiceInfo methods. + +rtl::OUString SAL_CALL +FileProvider::getImplementationName() + throw( uno::RuntimeException ) +{ + return fileaccess::shell::getImplementationName_static(); +} + + +sal_Bool SAL_CALL +FileProvider::supportsService( + const rtl::OUString& ServiceName ) + throw( uno::RuntimeException ) +{ + return ServiceName == rtl::OUString::createFromAscii( "com.sun.star.ucb.FileProvider" ); +} + + +uno::Sequence< rtl::OUString > SAL_CALL +FileProvider::getSupportedServiceNames( + void ) + throw( uno::RuntimeException ) +{ + return fileaccess::shell::getSupportedServiceNames_static(); +} + + + +uno::Reference< lang::XSingleServiceFactory > SAL_CALL +FileProvider::createServiceFactory( + const uno::Reference< lang::XMultiServiceFactory >& rxServiceMgr ) +{ + /** + * Create a single service factory.<BR> + * Note: The function pointer ComponentInstantiation points to a function throws Exception. + * + * @param rServiceManager the service manager used by the implementation. + * @param rImplementationName the implementation name. An empty string is possible. + * @param ComponentInstantiation the function pointer to create an object. + * @param rServiceNames the service supported by the implementation. + * @return a factory that support the interfaces XServiceProvider, XServiceInfo + * XSingleServiceFactory and XComponent. + * + * @see createOneInstanceFactory + */ + /* + * Reference< ::com::sun::star::lang::XSingleServiceFactory > createSingleFactory + * ( + * const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rServiceManager, + * const ::rtl::OUString & rImplementationName, + * ComponentInstantiation pCreateFunction, + + * const ::com::sun::star::uno::Sequence< ::rtl::OUString > & rServiceNames + * ); + */ + + return uno::Reference< lang::XSingleServiceFactory > ( cppu::createSingleFactory( + rxServiceMgr, + fileaccess::shell::getImplementationName_static(), + FileProvider::CreateInstance, + fileaccess::shell::getSupportedServiceNames_static() ) ); +} + +#if SUPD > 583 +uno::Reference< uno::XInterface > SAL_CALL +#else +uno::Reference< uno::XInterface > +#endif +FileProvider::CreateInstance( + const uno::Reference< lang::XMultiServiceFactory >& xMultiServiceFactory ) +{ + lang::XServiceInfo* xP = (lang::XServiceInfo*) new FileProvider( xMultiServiceFactory ); + return uno::Reference< uno::XInterface >::query( xP ); +} + + + +//////////////////////////////////////////////////////////////////////////////// +// XContent +//////////////////////////////////////////////////////////////////////////////// + + +uno::Reference< XContent > SAL_CALL +FileProvider::queryContent( + const uno::Reference< XContentIdentifier >& xIdentifier ) + throw( IllegalIdentifierException, + uno::RuntimeException) +{ + + rtl::OUString aUnc; + sal_Bool err = m_pMyShell->getUnqFromUrl( xIdentifier->getContentIdentifier(), + aUnc ); + + if( err ) + throw IllegalIdentifierException(); + + + rtl::OUString aRedirectedPath; + sal_Bool mounted = m_pMyShell->checkMountPoint( aUnc,aRedirectedPath ); + + BaseContent* pBaseContent = 0; + if( mounted ) + pBaseContent = new BaseContent( m_pMyShell,xIdentifier,aRedirectedPath ); + + return uno::Reference< XContent >( pBaseContent ); +} + + + +sal_Int32 SAL_CALL +FileProvider::compareContentIds( + const uno::Reference< XContentIdentifier >& Id1, + const uno::Reference< XContentIdentifier >& Id2 ) + throw( uno::RuntimeException ) +{ + rtl::OUString aUrl1 = Id1->getContentIdentifier(); + rtl::OUString aUrl2 = Id2->getContentIdentifier(); + + return aUrl1.compareTo( aUrl2 ); +} + + + +uno::Reference< XContentIdentifier > SAL_CALL +FileProvider::createContentIdentifier( + const rtl::OUString& ContentId ) + throw( uno::RuntimeException ) +{ + FileContentIdentifier* p = new FileContentIdentifier( m_pMyShell,ContentId,false ); + return uno::Reference< XContentIdentifier >( p ); +} + + + +//XPropertySetInfoImpl + +class XPropertySetInfoImpl2 + : public cppu::OWeakObject, + public beans::XPropertySetInfo +{ +public: + XPropertySetInfoImpl2(); + ~XPropertySetInfoImpl2(); + + // XInterface + virtual uno::Any SAL_CALL + queryInterface( + const uno::Type& aType ) + throw( uno::RuntimeException); + + virtual void SAL_CALL + acquire( + void ) + throw( uno::RuntimeException); + + virtual void SAL_CALL + release( + void ) + throw( uno::RuntimeException ); + + + virtual uno::Sequence< beans::Property > SAL_CALL + getProperties( + void ) + throw( uno::RuntimeException ); + + virtual beans::Property SAL_CALL + getPropertyByName( + const rtl::OUString& aName ) + throw( beans::UnknownPropertyException, + uno::RuntimeException); + + virtual sal_Bool SAL_CALL + hasPropertyByName( const rtl::OUString& Name ) + throw( uno::RuntimeException ); + + +private: + uno::Sequence< beans::Property > m_seq; +}; + + +XPropertySetInfoImpl2::XPropertySetInfoImpl2() + : m_seq( 2 ) +{ + m_seq[0] = beans::Property( rtl::OUString::createFromAscii( "HostName" ), + -1, + getCppuType( static_cast< rtl::OUString* >( 0 ) ), + beans::PropertyAttribute::READONLY ); + + m_seq[1] = beans::Property( rtl::OUString::createFromAscii( "FileSystemNotation" ), + -1, + getCppuType( static_cast< sal_Int32* >( 0 ) ), + beans::PropertyAttribute::READONLY ); +} + + +XPropertySetInfoImpl2::~XPropertySetInfoImpl2() +{ + // nothing +} + + +void SAL_CALL +XPropertySetInfoImpl2::acquire( + void ) + throw( uno::RuntimeException ) +{ + OWeakObject::acquire(); +} + + +void SAL_CALL +XPropertySetInfoImpl2::release( + void ) + throw( uno::RuntimeException ) +{ + OWeakObject::release(); +} + + +uno::Any SAL_CALL +XPropertySetInfoImpl2::queryInterface( + const uno::Type& rType ) + throw( uno::RuntimeException ) +{ + uno::Any aRet = cppu::queryInterface( rType, + SAL_STATIC_CAST( beans::XPropertySetInfo*,this) ); + return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ); +} + + +beans::Property SAL_CALL +XPropertySetInfoImpl2::getPropertyByName( + const rtl::OUString& aName ) + throw( beans::UnknownPropertyException, + uno::RuntimeException) +{ + for( sal_Int32 i = 0; i < m_seq.getLength(); ++i ) + if( m_seq[i].Name == aName ) + return m_seq[i]; + + throw beans::UnknownPropertyException(); +} + + + +uno::Sequence< beans::Property > SAL_CALL +XPropertySetInfoImpl2::getProperties( + void ) + throw( uno::RuntimeException ) +{ + return m_seq; +} + + +sal_Bool SAL_CALL +XPropertySetInfoImpl2::hasPropertyByName( + const rtl::OUString& aName ) + throw( uno::RuntimeException ) +{ + for( sal_Int32 i = 0; i < m_seq.getLength(); ++i ) + if( m_seq[i].Name == aName ) + return true; + return false; +} + + + + + +void SAL_CALL FileProvider::initProperties( void ) +{ + if( ! m_xPropertySetInfo.is() ) + { + osl_getLocalHostname( &m_HostName.pData ); + +#if defined ( UNX ) + m_FileSystemNotation = FileSystemNotation::UNIX_NOTATION; +#elif defined( WNT ) + m_FileSystemNotation = FileSystemNotation::DOS_NOTATION; +#else + m_FileSystemNotation = FileSystemNotation::UNKNOWN_NOTATION; +#endif + + // static const sal_Int32 UNKNOWN_NOTATION = (sal_Int32)0; + // static const sal_Int32 UNIX_NOTATION = (sal_Int32)1; + // static const sal_Int32 DOS_NOTATION = (sal_Int32)2; + // static const sal_Int32 MAC_NOTATION = (sal_Int32)3; + + XPropertySetInfoImpl2* p = new XPropertySetInfoImpl2(); + m_xPropertySetInfo = uno::Reference< beans::XPropertySetInfo >( p ); + } +} + + +// XPropertySet + +uno::Reference< beans::XPropertySetInfo > SAL_CALL +FileProvider::getPropertySetInfo( ) + throw( uno::RuntimeException ) +{ + initProperties(); + return m_xPropertySetInfo; +} + + +void SAL_CALL +FileProvider::setPropertyValue( const rtl::OUString& aPropertyName, + const uno::Any& aValue ) + throw( beans::UnknownPropertyException, + beans::PropertyVetoException, + lang::IllegalArgumentException, + lang::WrappedTargetException, + uno::RuntimeException ) +{ + if( aPropertyName.compareToAscii( "FileSystemNotation" ) == 0 || + aPropertyName.compareToAscii( "HostName" ) == 0 ) + return; + else + throw beans::UnknownPropertyException(); +} + + + +uno::Any SAL_CALL +FileProvider::getPropertyValue( + const rtl::OUString& aPropertyName ) + throw( beans::UnknownPropertyException, + lang::WrappedTargetException, + uno::RuntimeException ) +{ + initProperties(); + if( aPropertyName.compareToAscii( "FileSystemNotation" ) == 0 ) + { + uno::Any aAny; + aAny <<= m_FileSystemNotation; + return aAny; + } + else if( aPropertyName.compareToAscii( "HostName" ) == 0 ) + { + uno::Any aAny; + aAny <<= m_HostName; + return aAny; + } + else + throw beans::UnknownPropertyException(); +} + + +void SAL_CALL +FileProvider::addPropertyChangeListener( + const rtl::OUString& aPropertyName, + const uno::Reference< beans::XPropertyChangeListener >& xListener ) + throw( beans::UnknownPropertyException, + lang::WrappedTargetException, + uno::RuntimeException) +{ + return; +} + + +void SAL_CALL +FileProvider::removePropertyChangeListener( + const rtl::OUString& aPropertyName, + const uno::Reference< beans::XPropertyChangeListener >& aListener ) + throw( beans::UnknownPropertyException, + lang::WrappedTargetException, + uno::RuntimeException ) +{ + return; +} + +void SAL_CALL +FileProvider::addVetoableChangeListener( + const rtl::OUString& PropertyName, + const uno::Reference< beans::XVetoableChangeListener >& aListener ) + throw( beans::UnknownPropertyException, + lang::WrappedTargetException, + uno::RuntimeException ) +{ + return; +} + + +void SAL_CALL +FileProvider::removeVetoableChangeListener( + const rtl::OUString& PropertyName, + const uno::Reference< beans::XVetoableChangeListener >& aListener ) + throw( beans::UnknownPropertyException, + lang::WrappedTargetException, + uno::RuntimeException) +{ + return; +} + + + + diff --git a/ucb/source/ucp/file/prov.hxx b/ucb/source/ucp/file/prov.hxx new file mode 100644 index 000000000000..87b8699669f3 --- /dev/null +++ b/ucb/source/ucp/file/prov.hxx @@ -0,0 +1,254 @@ +/************************************************************************* + * + * $RCSfile: prov.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:53:36 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _PROV_HXX_ +#define _PROV_HXX_ + +#ifndef _CPPUHELPER_WEAK_HXX_ +#include <cppuhelper/weak.hxx> +#endif +#ifndef _VOS_MUTEX_HXX_ +#include <vos/mutex.hxx> +#endif +#ifndef _COM_SUN_STAR_UNO_XINTERFACE_HPP_ +#include <com/sun/star/uno/XInterface.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XSINGLESERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XSingleServiceFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_ +#include <com/sun/star/lang/XServiceInfo.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCONTENTPROVIDER_HPP_ +#include <com/sun/star/ucb/XContentProvider.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCONTENTIDENTIFIERFACTORY_HPP_ +#include <com/sun/star/ucb/XContentIdentifierFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_ +#include <com/sun/star/beans/XPropertySet.hpp> +#endif + +// FileProvider + + + +namespace fileaccess { + + // Forward declaration + + class BaseContent; + class shell; + + class FileProvider: + public cppu::OWeakObject, + public com::sun::star::lang::XServiceInfo, + public com::sun::star::ucb::XContentProvider, + public com::sun::star::ucb::XContentIdentifierFactory, + public com::sun::star::beans::XPropertySet + { + friend class BaseContent; + public: + + FileProvider( const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& xMSF ); + ~FileProvider(); + + // XInterface + virtual com::sun::star::uno::Any SAL_CALL + queryInterface( + const com::sun::star::uno::Type& aType ) + throw( com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL + acquire( + void ) + throw( com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL + release( + void ) + throw( com::sun::star::uno::RuntimeException); + + // XServiceInfo + virtual rtl::OUString SAL_CALL + getImplementationName( + void ) + throw( com::sun::star::uno::RuntimeException ); + + virtual sal_Bool SAL_CALL + supportsService( + const rtl::OUString& ServiceName ) + throw(com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL + getSupportedServiceNames( + void ) + throw( com::sun::star::uno::RuntimeException ); + + + static com::sun::star::uno::Reference< com::sun::star::lang::XSingleServiceFactory > SAL_CALL + createServiceFactory( + const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& rxServiceMgr ); + +#if SUPD > 583 + static com::sun::star::uno::Reference< com::sun::star::uno::XInterface > SAL_CALL + CreateInstance( + const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& xMultiServiceFactory ); +#else + static com::sun::star::uno::Reference< com::sun::star::uno::XInterface > + CreateInstance( + const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& xMultiServiceFactory ); +#endif + // XContentProvider + virtual com::sun::star::uno::Reference< com::sun::star::ucb::XContent > SAL_CALL + queryContent( + const com::sun::star::uno::Reference< com::sun::star::ucb::XContentIdentifier >& Identifier ) + throw( com::sun::star::ucb::IllegalIdentifierException, + com::sun::star::uno::RuntimeException); + + // XContentIdentifierFactory + + virtual com::sun::star::uno::Reference< com::sun::star::ucb::XContentIdentifier > SAL_CALL + createContentIdentifier( + const rtl::OUString& ContentId ) + throw( com::sun::star::uno::RuntimeException ); + + + virtual sal_Int32 SAL_CALL + compareContentIds( + const com::sun::star::uno::Reference< com::sun::star::ucb::XContentIdentifier >& Id1, + const com::sun::star::uno::Reference< com::sun::star::ucb::XContentIdentifier >& Id2 ) + throw( com::sun::star::uno::RuntimeException ); + + // XProperySet + + virtual com::sun::star::uno::Reference< com::sun::star::beans::XPropertySetInfo > SAL_CALL + getPropertySetInfo( ) + throw( com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL + setPropertyValue( + const rtl::OUString& aPropertyName, + const com::sun::star::uno::Any& aValue ) + throw( com::sun::star::beans::UnknownPropertyException, + com::sun::star::beans::PropertyVetoException, + com::sun::star::lang::IllegalArgumentException, + com::sun::star::lang::WrappedTargetException, + com::sun::star::uno::RuntimeException ); + + virtual com::sun::star::uno::Any SAL_CALL + getPropertyValue( + const rtl::OUString& PropertyName ) + throw( com::sun::star::beans::UnknownPropertyException, + com::sun::star::lang::WrappedTargetException, + com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL + addPropertyChangeListener( + const rtl::OUString& aPropertyName, + const com::sun::star::uno::Reference< com::sun::star::beans::XPropertyChangeListener >& xListener ) + throw( com::sun::star::beans::UnknownPropertyException, + com::sun::star::lang::WrappedTargetException, + com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL + removePropertyChangeListener( + const rtl::OUString& aPropertyName, + const com::sun::star::uno::Reference< com::sun::star::beans::XPropertyChangeListener >& aListener ) + throw( com::sun::star::beans::UnknownPropertyException, + com::sun::star::lang::WrappedTargetException, + com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL + addVetoableChangeListener( + const rtl::OUString& PropertyName, + const com::sun::star::uno::Reference< com::sun::star::beans::XVetoableChangeListener >& aListener ) + throw( com::sun::star::beans::UnknownPropertyException, + com::sun::star::lang::WrappedTargetException, + com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL + removeVetoableChangeListener( + const rtl::OUString& PropertyName, + const com::sun::star::uno::Reference< com::sun::star::beans::XVetoableChangeListener >& aListener ) + throw( com::sun::star::beans::UnknownPropertyException, + com::sun::star::lang::WrappedTargetException, + com::sun::star::uno::RuntimeException); + + private: + // Members + com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > m_xMultiServiceFactory; + + void SAL_CALL initProperties( void ); + rtl::OUString m_HostName; + sal_Int32 m_FileSystemNotation; + com::sun::star::uno::Reference< com::sun::star::beans::XPropertySetInfo > m_xPropertySetInfo; + + shell* m_pMyShell; + }; + +} // end namespace fileaccess + +#endif + diff --git a/ucb/source/ucp/file/shell.cxx b/ucb/source/ucp/file/shell.cxx new file mode 100644 index 000000000000..0fd1799ba247 --- /dev/null +++ b/ucb/source/ucp/file/shell.cxx @@ -0,0 +1,3121 @@ +/************************************************************************* + * + * $RCSfile: shell.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:53:36 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _VOS_DIAGNOSE_H_ +#include <vos/diagnose.hxx> +#endif +#ifndef _RTL_USTRBUF_HXX_ +#include <rtl/ustrbuf.hxx> +#endif +#ifndef _OSL_TIME_H_ +#include <osl/time.h> +#endif +#ifndef _OSL_FILE_HXX_ +#include <osl/file.hxx> +#endif +#ifndef _COM_SUN_STAR_UCB_INSERTCOMMANDARGUMENT_HPP_ +#include <com/sun/star/ucb/InsertCommandArgument.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_NAMECLASH_HPP_ +#include <com/sun/star/ucb/NameClash.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCONTENTIDENTIFIER_HPP_ +#include <com/sun/star/ucb/XContentIdentifier.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XCOMPONENT_HPP_ +#include <com/sun/star/lang/XComponent.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCONTENTACCESS_ +#include <com/sun/star/ucb/XContentAccess.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBBUTE_HPP_ +#include <com/sun/star/beans/PropertyAttribute.hpp> +#endif +#ifndef _COM_SUN_STAR_IO_XSEEKABLE_HPP_ +#include <com/sun/star/io/XSeekable.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_OPENCOMMANDARGUMENT_HPP_ +#include <com/sun/star/ucb/OpenCommandArgument.hpp> +#endif +#ifndef _COM_SUN_STAR_REGISTRY_XSIMPLEREGISTRY_HPP_ +#include <com/sun/star/registry/XSimpleRegistry.hpp> +#endif +#ifndef _COM_SUN_STAR_FRAME_XCONFIGMANAGER_HPP_ +#include <com/sun/star/frame/XConfigManager.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XPROPERTYSETREGISTRYFACTORY_HPP_ +#include <com/sun/star/ucb/XPropertySetRegistryFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_TRANSFERINFO_HPP_ +#include <com/sun/star/ucb/TransferInfo.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_PROPERTYCHANGEEVENT_HPP_ +#include <com/sun/star/beans/PropertyChangeEvent.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_XPROPERTIESCHANGELISTENER_HPP_ +#include <com/sun/star/beans/XPropertiesChangeListener.hpp> +#endif + +#ifndef _FILRSET_HXX_ +#include "filrset.hxx" +#endif +#ifndef _FILROW_HXX_ +#include "filrow.hxx" +#endif +#ifndef _FILPRP_HXX_ +#include "filprp.hxx" +#endif +#ifndef _FILID_HXX_ +#include "filid.hxx" +#endif +#ifndef _SHELL_HXX_ +#include "shell.hxx" +#endif +#ifndef _PROV_HXX_ +#include "prov.hxx" +#endif +#ifndef _BC_HXX_ +#include "bc.hxx" +#endif + +using namespace fileaccess; +using namespace com::sun::star; +using namespace com::sun::star::ucb; + + +shell::UnqPathData::UnqPathData() + : properties( 0 ), + notifier( 0 ), + xS( 0 ), + xC( 0 ), + xA( 0 ) +{ + // empty +} + + +shell::UnqPathData::UnqPathData( const UnqPathData& a ) + : properties( a.properties ), + notifier( a.notifier ), + xS( a.xS ), + xC( a.xC ), + xA( a.xA ) +{ +} + + +shell::UnqPathData& shell::UnqPathData::operator=( UnqPathData& a ) +{ + properties = a.properties; + notifier = a.notifier; + xS = a.xS; + xC = a.xC; + xA = a.xA; + a.properties = 0; + a.notifier = 0; + a.xS = 0; + a.xC = 0; + a.xA = 0; + return *this; +} + +shell::UnqPathData::~UnqPathData() +{ + if( properties ) + delete properties; + if( notifier ) + delete notifier; +} + + + +//////////////////////////////////////////////////////////////////////////////////////// + + + + + +shell::MyProperty::MyProperty( const rtl::OUString& __PropertyName ) + : PropertyName( __PropertyName ) +{ + // empty +} + + +shell::MyProperty::MyProperty( const sal_Bool& __isNative, + const rtl::OUString& __PropertyName, + const sal_Int32& __Handle, + const com::sun::star::uno::Type& __Typ, + const com::sun::star::uno::Any& __Value, + const com::sun::star::beans::PropertyState& __State, + const sal_Int16& __Attributes ) + : isNative( __isNative ), + PropertyName( __PropertyName ), + Handle( __Handle ), + Typ( __Typ ), + Value( __Value ), + State( __State ), + Attributes( __Attributes ) +{ + // empty +} + +shell::MyProperty::~MyProperty() +{ + // empty for now +} + + +#ifndef _FILINL_HXX_ +#include "filinl.hxx" +#endif + + +shell::shell( const uno::Reference< lang::XMultiServiceFactory >& xMultiServiceFactory, + FileProvider* pProvider ) + : TaskManager(), + m_xMultiServiceFactory( xMultiServiceFactory ), + m_pProvider( pProvider ), + m_sCommandInfo( 8 ), + m_bFaked( false ), + Title( rtl::OUString::createFromAscii( "Title" ) ), + IsDocument( rtl::OUString::createFromAscii( "IsDocument" ) ), + IsFolder( rtl::OUString::createFromAscii( "IsFolder" ) ), + DateCreated( rtl::OUString::createFromAscii( "DateCreated" ) ), + DateModified( rtl::OUString::createFromAscii( "DateModified" ) ), + Size( rtl::OUString::createFromAscii( "Size" ) ), + FolderCount( rtl::OUString::createFromAscii( "FolderCount" ) ), + DocumentCount( rtl::OUString::createFromAscii( "DocumentCount" ) ), + ContentType( rtl::OUString::createFromAscii( "ContentType" ) ), + IsReadOnly( rtl::OUString::createFromAscii( "IsReadOnly" ) ), + FolderContentType( rtl::OUString::createFromAscii( "application/vnd.sun.staroffice.fsys-folder" ) ), + FileContentType( rtl::OUString::createFromAscii( "application/vnd.sun.staroffice.fsys-file" ) ) +{ + // Title + m_aDefaultProperties.insert( MyProperty( true, + Title, + -1 , + getCppuType( static_cast< rtl::OUString* >( 0 ) ), + uno::Any(), + beans::PropertyState_DEFAULT_VALUE, + beans::PropertyAttribute::MAYBEVOID + | beans::PropertyAttribute::BOUND ) ); + + + // IsFolder + m_aDefaultProperties.insert( MyProperty( true, + IsFolder, + -1 , + getCppuType( static_cast< sal_Bool* >( 0 ) ), + uno::Any(), + beans::PropertyState_DEFAULT_VALUE, + beans::PropertyAttribute::MAYBEVOID + | beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::READONLY ) ); + + + // IsDocument + m_aDefaultProperties.insert( MyProperty( true, + IsDocument, + -1 , + getCppuType( static_cast< sal_Bool* >( 0 ) ), + uno::Any(), + beans::PropertyState_DEFAULT_VALUE, + beans::PropertyAttribute::MAYBEVOID + | beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::READONLY ) ); + + + // ContentType + uno::Any aAny; + aAny <<= rtl::OUString(); + m_aDefaultProperties.insert( MyProperty( false, + ContentType, + -1 , + getCppuType( static_cast< rtl::OUString* >( 0 ) ), + aAny, + beans::PropertyState_DEFAULT_VALUE, + beans::PropertyAttribute::MAYBEVOID + | beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::READONLY ) ); + + + // DateCreated + m_aDefaultProperties.insert( MyProperty( true, + DateCreated, + -1, + getCppuType( static_cast< util::DateTime* >( 0 ) ), + uno::Any(), + beans::PropertyState_DEFAULT_VALUE, + beans::PropertyAttribute::MAYBEVOID + | beans::PropertyAttribute::BOUND ) ); + + + // DateModified + m_aDefaultProperties.insert( MyProperty( true, + DateModified, + -1 , + getCppuType( static_cast< util::DateTime* >( 0 ) ), + uno::Any(), + beans::PropertyState_DEFAULT_VALUE, + beans::PropertyAttribute::MAYBEVOID + | beans::PropertyAttribute::BOUND ) ); + + + // DocumentCount + m_aDefaultProperties.insert( MyProperty( true, + DocumentCount, + -1, + getCppuType( static_cast< sal_Int32* >( 0 ) ), + uno::Any(), + beans::PropertyState_DEFAULT_VALUE, + beans::PropertyAttribute::MAYBEVOID + | beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::READONLY ) ); + + // FolderCount + m_aDefaultProperties.insert( MyProperty( true, + FolderCount, + -1, + getCppuType( static_cast< sal_Int32* >( 0 ) ), + uno::Any(), + beans::PropertyState_DEFAULT_VALUE, + beans::PropertyAttribute::MAYBEVOID + | beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::READONLY ) ); + + // Size + m_aDefaultProperties.insert( MyProperty( true, + Size, + -1, + getCppuType( static_cast< sal_Int64* >( 0 ) ), + uno::Any(), + beans::PropertyState_DEFAULT_VALUE, + beans::PropertyAttribute::MAYBEVOID + | beans::PropertyAttribute::BOUND ) ); + + m_aDefaultProperties.insert( MyProperty( true, + IsReadOnly, + -1 , + getCppuType( static_cast< sal_Bool* >( 0 ) ), + uno::Any(), + beans::PropertyState_DEFAULT_VALUE, + beans::PropertyAttribute::MAYBEVOID + | beans::PropertyAttribute::BOUND ) ); + + + // Commands + m_sCommandInfo[0].Name = rtl::OUString::createFromAscii( "getCommandInfo" ); + m_sCommandInfo[0].Handle = -1; + m_sCommandInfo[0].ArgType = getCppuVoidType(); + + m_sCommandInfo[1].Name = rtl::OUString::createFromAscii( "getPropertySetInfo" ); + m_sCommandInfo[1].Handle = -1; + m_sCommandInfo[1].ArgType = getCppuVoidType(); + + m_sCommandInfo[2].Name = rtl::OUString::createFromAscii( "getPropertyValues" ); + m_sCommandInfo[2].Handle = -1; + m_sCommandInfo[2].ArgType = getCppuType( static_cast< uno::Sequence< beans::Property >* >( 0 ) ); + + m_sCommandInfo[3].Name = rtl::OUString::createFromAscii( "setPropertyValues" ); + m_sCommandInfo[3].Handle = -1; + m_sCommandInfo[3].ArgType = getCppuType( static_cast< uno::Sequence< beans::PropertyValue >* >( 0 ) ); + + m_sCommandInfo[4].Name = rtl::OUString::createFromAscii( "open" ); + m_sCommandInfo[4].Handle = -1; + m_sCommandInfo[4].ArgType = getCppuType( static_cast< OpenCommandArgument* >( 0 ) ); + + m_sCommandInfo[5].Name = rtl::OUString::createFromAscii( "transfer" ); + m_sCommandInfo[5].Handle = -1; + m_sCommandInfo[5].ArgType = getCppuType( static_cast< TransferInfo* >( 0 ) ); + + m_sCommandInfo[6].Name = rtl::OUString::createFromAscii( "delete" ); + m_sCommandInfo[6].Handle = -1; + m_sCommandInfo[6].ArgType = getCppuType( static_cast< sal_Bool* >( 0 ) ); + + m_sCommandInfo[7].Name = rtl::OUString::createFromAscii( "insert" ); + m_sCommandInfo[7].Handle = -1; + m_sCommandInfo[7].ArgType = getCppuType( static_cast< InsertCommandArgument* > ( 0 ) ); + + rtl::OUString Store = rtl::OUString::createFromAscii( "com.sun.star.ucb.Store" ); + uno::Reference< XPropertySetRegistryFactory > xRegFac( m_xMultiServiceFactory->createInstance( Store ), + uno::UNO_QUERY ); + + rtl::OUString Special = rtl::OUString::createFromAscii( "com.sun.star.config.SpecialConfigManager" ); + + uno::Reference< registry::XSimpleRegistry > xCfgReg( m_xMultiServiceFactory->createInstance( Special ), + uno::UNO_QUERY ); + + uno::Reference< frame::XConfigManager > xCfgMgr( xCfgReg,uno::UNO_QUERY ); + + + if ( xRegFac.is() && xCfgReg.is() && xCfgMgr.is() ) + { + rtl::OUString aRegURL; + + try + { + uno::Reference< registry::XRegistryKey > xRegistryKey( xCfgReg->getRootKey() ); + if ( xRegistryKey.is() ) + xRegistryKey = xRegistryKey->openKey( + rtl::OUString::createFromAscii( "Directories/Storage-Dir") ); + + if ( xRegistryKey.is() ) + aRegURL = xRegistryKey->getStringValue(); + } + catch ( registry::InvalidRegistryException& ) + { + } + + aRegURL = xCfgMgr->substituteVariables( aRegURL ); + + if ( aRegURL.getLength() ) + { + rtl::OUString aRegUNC; + osl::FileBase::normalizePath( aRegURL,aRegUNC ); + + rtl::OUString aLastChar( aRegUNC.copy( aRegUNC.getLength() - 1 ) ); + rtl::OUString aTmpOWStr = rtl::OUString::createFromAscii ( "/" ); + if ( aLastChar != aTmpOWStr ) + aRegUNC += aTmpOWStr; + + aRegUNC += rtl::OUString::createFromAscii( "file.rdb" ); + osl::FileBase::getFileURLFromNormalizedPath( aRegUNC,aRegURL ); + // Open/create a registry + m_xFileRegistry = xRegFac->createPropertySetRegistry( aRegURL ); + } + } +} + + +shell::~shell() +{ +} + + +/*********************************************************************************/ +/* */ +/* de/registerNotifier-Implementation */ +/* */ +/*********************************************************************************/ + +void SAL_CALL +shell::registerNotifier( const rtl::OUString& aUnqPath, Notifier* pNotifier ) +{ + vos::OGuard aGuard( m_aMutex ); + + ContentMap::iterator it = + m_aContent.insert( ContentMap::value_type( aUnqPath,UnqPathData() ) ).first; + + if( ! it->second.notifier ) + it->second.notifier = new NotifierList(); + + std::list< Notifier* >& nlist = *( it->second.notifier ); + + std::list<Notifier*>::iterator it1 = nlist.begin(); + while( it1 != nlist.end() ) // Every "Notifier" only once + { + if( *it1 == pNotifier ) return; + ++it1; + } + nlist.push_back( pNotifier ); +} + + + +void SAL_CALL +shell::deregisterNotifier( const rtl::OUString& aUnqPath,Notifier* pNotifier ) +{ + vos::OGuard aGuard( m_aMutex ); + + ContentMap::iterator it = m_aContent.find( aUnqPath ); + if( it == m_aContent.end() ) + return; + + it->second.notifier->remove( pNotifier ); + + if( ! it->second.notifier->size() ) + m_aContent.erase( it ); +} + + +/*********************************************************************************/ +/* */ +/* load-Implementation */ +/* */ +/*********************************************************************************/ + +void SAL_CALL +shell::load( const ContentMap::iterator& it, sal_Bool create ) +{ + if( ! it->second.properties ) + it->second.properties = new PropertySet; + + if( ( ! it->second.xS.is() || + ! it->second.xC.is() || + ! it->second.xA.is() ) + && m_xFileRegistry.is() ) + { + + uno::Reference< ucb::XPersistentPropertySet > xS = m_xFileRegistry->openPropertySet( it->first,create ); + if( xS.is() ) + { + uno::Reference< beans::XPropertyContainer > xC( xS,uno::UNO_QUERY ); + uno::Reference< beans::XPropertyAccess > xA( xS,uno::UNO_QUERY ); + + it->second.xS = xS; + it->second.xC = xC; + it->second.xA = xA; + + // Now put in all values in the storage in the local hash; + + PropertySet& properties = *(it->second.properties); + uno::Sequence< beans::Property > seq = xS->getPropertySetInfo()->getProperties(); + + for( sal_Int32 i = 0; i < seq.getLength(); ++i ) + { + MyProperty readProp( false, + seq[i].Name, + seq[i].Handle, + seq[i].Type, + xS->getPropertyValue( seq[i].Name ), + beans::PropertyState_DIRECT_VALUE, + seq[i].Attributes ); + if( properties.find( readProp ) == properties.end() ) + properties.insert( readProp ); + } + } + else if( create ) + { + // Catastrophic error + } + } +} + + +/*********************************************************************************/ +/* */ +/* de/associate-Implementation */ +/* */ +/*********************************************************************************/ + + +void SAL_CALL +shell::associate( const rtl::OUString& aUnqPath, + const rtl::OUString& PropertyName, + const uno::Any& DefaultValue, + const sal_Int16 Attributes ) + throw( beans::PropertyExistException, + beans::IllegalTypeException, + uno::RuntimeException ) +{ + MyProperty newProperty( false, + PropertyName, + -1, + DefaultValue.getValueType(), + DefaultValue, + beans::PropertyState_DEFAULT_VALUE, + Attributes ); + + shell::PropertySet::iterator it1 = m_aDefaultProperties.find( newProperty ); + if( it1 != m_aDefaultProperties.end() ) + throw beans::PropertyExistException(); + + { + vos::OGuard aGuard( m_aMutex ); + + ContentMap::iterator it = m_aContent.insert( ContentMap::value_type( aUnqPath,UnqPathData() ) ).first; + + // Load the XPersistentPropertySetInfo and create it, if it does not exist + load( it,true ); + + PropertySet& properties = *(it->second.properties); + it1 = properties.find( newProperty ); + if( it1 != properties.end() ) + throw beans::PropertyExistException(); + + // Property does not exist + properties.insert( newProperty ); + it->second.xC->addProperty( PropertyName,Attributes,DefaultValue ); + } + notifyPropertyAdded( getPropertySetListeners( aUnqPath ), PropertyName ); +} + + + + +void SAL_CALL +shell::deassociate( const rtl::OUString& aUnqPath, + const rtl::OUString& PropertyName ) + throw( beans::UnknownPropertyException, + beans::NotRemoveableException, + uno::RuntimeException ) +{ + MyProperty oldProperty( PropertyName ); + + shell::PropertySet::iterator it1 = m_aDefaultProperties.find( oldProperty ); + if( it1 != m_aDefaultProperties.end() ) + throw beans::NotRemoveableException(); + + vos::OGuard aGuard( m_aMutex ); + + ContentMap::iterator it = m_aContent.insert( ContentMap::value_type( aUnqPath,UnqPathData() ) ).first; + + load( it,false ); + + PropertySet& properties = *(it->second.properties); + + it1 = properties.find( oldProperty ); + if( it1 == properties.end() ) + throw beans::UnknownPropertyException(); + + properties.erase( it1 ); + + if( it->second.xC.is() ) + it->second.xC->removeProperty( PropertyName ); + + if( properties.size() == 9 ) + { + MyProperty ContentTProperty( ContentType ); + + if( properties.find( ContentTProperty )->getState() == beans::PropertyState_DEFAULT_VALUE ) + { + it->second.xS = 0; + it->second.xC = 0; + it->second.xA = 0; + m_xFileRegistry->removePropertySet( aUnqPath ); + } + } + notifyPropertyRemoved( getPropertySetListeners( aUnqPath ), PropertyName ); +} + + + + +/*********************************************************************************/ +/* */ +/* page-Implementation */ +/* */ +/*********************************************************************************/ + + +void SAL_CALL shell::page( sal_Int32 CommandId, + const rtl::OUString& aUnqPath, + const uno::Reference< io::XOutputStream >& xOutputStream ) + throw( CommandAbortedException ) +{ + uno::Reference< XContentProvider > xProvider( m_pProvider ); + osl::File aFile( aUnqPath ); + osl::FileBase::RC err = aFile.open( OpenFlag_Read ); + + if( err != osl::FileBase::E_None ) + { + aFile.close(); + return; + } + + const sal_uInt64 bfz = 4*1024; + sal_Int8 BFF[bfz]; + sal_uInt64 nrc; // Retrieved number of Bytes; + sal_Bool no_err; + + do + { + no_err = aFile.read( (void*) BFF,bfz,nrc ) == osl::FileBase::E_None; + if( no_err ) + { + uno::Sequence< sal_Int8 > seq( BFF,nrc ); + xOutputStream->writeBytes( seq ); + } + else + break; + } while( nrc == bfz ); + + aFile.close(); + if( ! no_err ) + { + throw CommandAbortedException(); + } +} + + +/*********************************************************************************/ +/* */ +/* open-Implementation */ +/* */ +/*********************************************************************************/ + + + +class XInputStream_impl + : public cppu::OWeakObject, + public io::XInputStream, + public io::XSeekable +{ +public: + XInputStream_impl( shell* pMyShell,const rtl::OUString& aUncPath ); + virtual ~XInputStream_impl(); + + sal_Bool SAL_CALL CtorSuccess(); + + virtual uno::Any SAL_CALL + queryInterface( + const uno::Type& rType ) + throw( uno::RuntimeException) + { + uno::Any aRet = cppu::queryInterface( rType, + SAL_STATIC_CAST( io::XInputStream*,this ), + SAL_STATIC_CAST( io::XSeekable*,this ) ); + return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ); + } + + virtual void SAL_CALL + acquire( + void ) + throw( uno::RuntimeException) + { + OWeakObject::acquire(); + } + + virtual void SAL_CALL + release( + void ) + throw( uno::RuntimeException ) + { + OWeakObject::release(); + } + + virtual sal_Int32 SAL_CALL + readBytes( + uno::Sequence< sal_Int8 >& aData, + sal_Int32 nBytesToRead ) + throw( io::NotConnectedException, + io::BufferSizeExceededException, + io::IOException, + uno::RuntimeException); + + virtual sal_Int32 SAL_CALL + readSomeBytes( + uno::Sequence< sal_Int8 >& aData, + sal_Int32 nMaxBytesToRead ) + throw( io::NotConnectedException, + io::BufferSizeExceededException, + io::IOException, + uno::RuntimeException); + + virtual void SAL_CALL + skipBytes( + sal_Int32 nBytesToSkip ) + throw( io::NotConnectedException, + io::BufferSizeExceededException, + io::IOException, + uno::RuntimeException ); + + virtual sal_Int32 SAL_CALL + available( + void ) + throw( io::NotConnectedException, + io::IOException, + uno::RuntimeException ); + + virtual void SAL_CALL + closeInput( + void ) + throw( io::NotConnectedException, + io::IOException, + uno::RuntimeException ); + + virtual void SAL_CALL + seek( + sal_Int64 location ) + throw( lang::IllegalArgumentException, + io::IOException, + uno::RuntimeException ); + + virtual sal_Int64 SAL_CALL + getPosition( + void ) + throw( io::IOException, + uno::RuntimeException ); + + virtual sal_Int64 SAL_CALL + getLength( + void ) + throw( io::IOException, + uno::RuntimeException ); + +private: + shell* m_pMyShell; + uno::Reference< XContentProvider > m_xProvider; + sal_Bool m_nIsOpen; + osl::File m_aFile; +}; + + + +uno::Reference< io::XInputStream > SAL_CALL +shell::open( sal_Int32 CommandId, + const rtl::OUString& aUnqPath ) +{ + XInputStream_impl* xInputStream = new XInputStream_impl( this,aUnqPath ); + + if( ! xInputStream->CtorSuccess() ) { + delete xInputStream; + xInputStream = 0; + } + return uno::Reference< io::XInputStream >( xInputStream ); +} + + +XInputStream_impl::XInputStream_impl( shell* pMyShell,const rtl::OUString& aUncPath ) + : m_pMyShell( pMyShell ), + m_aFile( aUncPath ), + m_xProvider( pMyShell->m_pProvider ) +{ + if( m_aFile.open( OpenFlag_Read ) != osl::FileBase::E_None ) + { + m_nIsOpen = false; + m_aFile.close(); + } + else + m_nIsOpen = true; +} + + +XInputStream_impl::~XInputStream_impl() +{ + closeInput(); +} + +sal_Bool SAL_CALL XInputStream_impl::CtorSuccess() +{ + return m_nIsOpen; +}; + + +sal_Int32 SAL_CALL +XInputStream_impl::readBytes( + uno::Sequence< sal_Int8 >& aData, + sal_Int32 nBytesToRead ) + throw( io::NotConnectedException, + io::BufferSizeExceededException, + io::IOException, + uno::RuntimeException) +{ + if( ! m_nIsOpen ) throw io::IOException(); + + sal_Int8 * buffer; + try + { + buffer = new sal_Int8[nBytesToRead]; + } + catch( std::bad_alloc ) + { + if( m_nIsOpen ) m_aFile.close(); + throw io::BufferSizeExceededException(); + } + + sal_uInt64 nrc; + m_aFile.read( (void* )buffer,sal_uInt64(nBytesToRead),nrc ); + + aData = uno::Sequence< sal_Int8 > ( buffer,nrc ); + delete[] buffer; + return ( sal_Int32 ) nrc; +} + +sal_Int32 SAL_CALL +XInputStream_impl::readSomeBytes( + uno::Sequence< sal_Int8 >& aData, + sal_Int32 nMaxBytesToRead ) + throw( io::NotConnectedException, + io::BufferSizeExceededException, + io::IOException, + uno::RuntimeException) +{ + return readBytes( aData,nMaxBytesToRead ); +} + + +void SAL_CALL +XInputStream_impl::skipBytes( + sal_Int32 nBytesToSkip ) + throw( io::NotConnectedException, + io::BufferSizeExceededException, + io::IOException, + uno::RuntimeException) +{ + m_aFile.setPos( osl_Pos_Current, sal_uInt64( nBytesToSkip ) ); +} + + +sal_Int32 SAL_CALL +XInputStream_impl::available( + void ) + throw( io::NotConnectedException, + io::IOException, + uno::RuntimeException) +{ + return 0; +} + + +void SAL_CALL +XInputStream_impl::closeInput( + void ) + throw( io::NotConnectedException, + io::IOException, + uno::RuntimeException ) +{ + if( m_nIsOpen ) + { + osl::FileBase::RC err = m_aFile.close(); + if( err != osl::FileBase::E_None ) + throw io::IOException(); + m_nIsOpen = false; + } +} + + +void SAL_CALL +XInputStream_impl::seek( + sal_Int64 location ) + throw( lang::IllegalArgumentException, + io::IOException, + uno::RuntimeException ) +{ + if( location < 0 ) + throw lang::IllegalArgumentException(); + if( osl::FileBase::E_None != m_aFile.setPos( Pos_Absolut, sal_uInt64( location ) ) ) + throw io::IOException(); +} + + +sal_Int64 SAL_CALL +XInputStream_impl::getPosition( + void ) + throw( io::IOException, + uno::RuntimeException ) +{ + sal_uInt64 uPos; + if( osl::FileBase::E_None != m_aFile.getPos( uPos ) ) + throw io::IOException(); + return sal_Int64( uPos ); +} + +sal_Int64 SAL_CALL +XInputStream_impl::getLength( + void ) + throw( io::IOException, + uno::RuntimeException ) +{ + osl::DirectoryItem aDirectoryItem; + osl::FileBase::RC err = osl::DirectoryItem::get( m_aFile,aDirectoryItem ); + if( err != osl::FileBase::E_None ) + throw io::IOException(); + osl::FileStatus aFileStatus( FileStatusMask_FileSize ); + aDirectoryItem.getFileStatus( aFileStatus ); + if( aFileStatus.isValid( FileStatusMask_FileSize ) ) + return sal_Int64( aFileStatus.getFileSize() ); + else + throw io::IOException(); +} + + +/*********************************************************************************/ +/* */ +/* open for read/write access-Implementation */ +/* */ +/*********************************************************************************/ + + + +class XStream_impl + : public cppu::OWeakObject, + public io::XStream, + public io::XSeekable +{ +public: + XStream_impl( shell* pMyShell,const rtl::OUString& aUncPath ); + virtual ~XStream_impl(); + + sal_Bool SAL_CALL CtorSuccess(); + + virtual uno::Any SAL_CALL + queryInterface( + const uno::Type& rType ) + throw( uno::RuntimeException) + { + uno::Any aRet = cppu::queryInterface( rType, + SAL_STATIC_CAST( io::XStream*,this ), + SAL_STATIC_CAST( io::XSeekable*,this ) ); + return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ); + } + + virtual void SAL_CALL + acquire( + void ) + throw( uno::RuntimeException) + { + OWeakObject::acquire(); + } + + virtual void SAL_CALL + release( + void ) + throw( uno::RuntimeException ) + { + OWeakObject::release(); + } + + virtual sal_Int32 SAL_CALL + readBytes( + uno::Sequence< sal_Int8 >& aData, + sal_Int32 nBytesToRead ) + throw( io::NotConnectedException, + io::BufferSizeExceededException, + io::IOException, + uno::RuntimeException); + + virtual sal_Int32 SAL_CALL + readSomeBytes( + uno::Sequence< sal_Int8 >& aData, + sal_Int32 nMaxBytesToRead ) + throw( io::NotConnectedException, + io::BufferSizeExceededException, + io::IOException, + uno::RuntimeException); + + virtual void SAL_CALL + writeBytes( const uno::Sequence< sal_Int8 >& aData ) + throw( io::NotConnectedException, + io::BufferSizeExceededException, + io::IOException, + uno::RuntimeException); + + virtual void SAL_CALL + skipBytes( + sal_Int32 nBytesToSkip ) + throw( io::NotConnectedException, + io::BufferSizeExceededException, + io::IOException, + uno::RuntimeException ); + + virtual sal_Int32 SAL_CALL + available( + void ) + throw( io::NotConnectedException, + io::IOException, + uno::RuntimeException ); + + virtual void SAL_CALL + flush() + throw( io::NotConnectedException, + io::BufferSizeExceededException, + io::IOException, + uno::RuntimeException); + + virtual void SAL_CALL + closeStream( + void ) + throw( io::NotConnectedException, + io::IOException, + uno::RuntimeException ); + + virtual void SAL_CALL + seek( + sal_Int64 location ) + throw( lang::IllegalArgumentException, + io::IOException, + uno::RuntimeException ); + + virtual sal_Int64 SAL_CALL + getPosition( + void ) + throw( io::IOException, + uno::RuntimeException ); + + virtual sal_Int64 SAL_CALL + getLength( + void ) + throw( io::IOException, + uno::RuntimeException ); + +private: + shell* m_pMyShell; + uno::Reference< XContentProvider > m_xProvider; + sal_Bool m_nIsOpen; + osl::File m_aFile; +}; + + + +uno::Reference< io::XStream > SAL_CALL +shell::open_rw( sal_Int32 CommandId, + const rtl::OUString& aUnqPath ) +{ + XStream_impl* xStream = new XStream_impl( this,aUnqPath ); + + if( ! xStream->CtorSuccess() ) + { + delete xStream; + xStream = 0; + } + return uno::Reference< io::XStream >( xStream ); +} + + + +XStream_impl::XStream_impl( shell* pMyShell,const rtl::OUString& aUncPath ) + : m_pMyShell( pMyShell ), + m_aFile( aUncPath ), + m_xProvider( m_pMyShell->m_pProvider ) +{ + if( m_aFile.open( OpenFlag_Read | OpenFlag_Write ) != osl::FileBase::E_None ) + { + m_nIsOpen = false; + m_aFile.close(); + } + else + m_nIsOpen = true; +} + + +XStream_impl::~XStream_impl() +{ + closeStream(); +} + +sal_Bool SAL_CALL XStream_impl::CtorSuccess() +{ + return m_nIsOpen; +} + + +sal_Int32 SAL_CALL +XStream_impl::readBytes( + uno::Sequence< sal_Int8 >& aData, + sal_Int32 nBytesToRead ) + throw( io::NotConnectedException, + io::BufferSizeExceededException, + io::IOException, + uno::RuntimeException) +{ + if( ! m_nIsOpen ) + throw io::IOException(); + + sal_Int8 * buffer; + try + { + buffer = new sal_Int8[nBytesToRead]; + } + catch( std::bad_alloc ) + { + if( m_nIsOpen ) m_aFile.close(); + throw io::BufferSizeExceededException(); + } + + sal_uInt64 nrc; + m_aFile.read( (void* )buffer,sal_uInt64(nBytesToRead),nrc ); + + aData = uno::Sequence< sal_Int8 > ( buffer,nrc ); + delete[] buffer; + return ( sal_Int32 ) nrc; +} + + +sal_Int32 SAL_CALL +XStream_impl::readSomeBytes( + uno::Sequence< sal_Int8 >& aData, + sal_Int32 nMaxBytesToRead ) + throw( io::NotConnectedException, + io::BufferSizeExceededException, + io::IOException, + uno::RuntimeException) +{ + return readBytes( aData,nMaxBytesToRead ); +} + + +void SAL_CALL +XStream_impl::skipBytes( + sal_Int32 nBytesToSkip ) + throw( io::NotConnectedException, + io::BufferSizeExceededException, + io::IOException, + uno::RuntimeException) +{ + m_aFile.setPos( osl_Pos_Current, sal_uInt64( nBytesToSkip ) ); +} + + +sal_Int32 SAL_CALL +XStream_impl::available( + void ) + throw( io::NotConnectedException, + io::IOException, + uno::RuntimeException) +{ + return 0; +} + + +void SAL_CALL +XStream_impl::writeBytes( const uno::Sequence< sal_Int8 >& aData ) + throw( io::NotConnectedException, + io::BufferSizeExceededException, + io::IOException, + uno::RuntimeException) +{ + sal_Int32 length = aData.getLength(); + sal_uInt64 nWrittenBytes; + if( length ) + { + const sal_Int8* p = aData.getConstArray(); + m_aFile.write( ((void*)(p)), + sal_uInt64( length ), + nWrittenBytes ); + if( nWrittenBytes != length ) + { + // DBG_ASSERT( "Write Operation not successful" ); + } + } +} + + +void SAL_CALL +XStream_impl::closeStream( + void ) + throw( io::NotConnectedException, + io::IOException, + uno::RuntimeException ) +{ + if( m_nIsOpen ) + { + osl::FileBase::RC err = m_aFile.close(); + if( err != osl::FileBase::E_None ) throw io::IOException(); + m_nIsOpen = false; + } +} + + +void SAL_CALL +XStream_impl::seek( + sal_Int64 location ) + throw( lang::IllegalArgumentException, + io::IOException, + uno::RuntimeException ) +{ + if( location < 0 ) + throw lang::IllegalArgumentException(); + if( osl::FileBase::E_None != m_aFile.setPos( Pos_Absolut, sal_uInt64( location ) ) ) + throw io::IOException(); +} + + +sal_Int64 SAL_CALL +XStream_impl::getPosition( + void ) + throw( io::IOException, + uno::RuntimeException ) +{ + sal_uInt64 uPos; + if( osl::FileBase::E_None != m_aFile.getPos( uPos ) ) + throw io::IOException(); + return sal_Int64( uPos ); +} + +sal_Int64 SAL_CALL +XStream_impl::getLength( + void ) + throw( io::IOException, + uno::RuntimeException ) +{ + osl::DirectoryItem aDirectoryItem; + osl::FileBase::RC err = osl::DirectoryItem::get( m_aFile,aDirectoryItem ); + if( err != osl::FileBase::E_None ) + throw io::IOException(); + osl::FileStatus aFileStatus( FileStatusMask_FileSize ); + aDirectoryItem.getFileStatus( aFileStatus ); + if( aFileStatus.isValid( FileStatusMask_FileSize ) ) + return sal_Int64( aFileStatus.getFileSize() ); + else + throw io::IOException(); +} + + +void SAL_CALL +XStream_impl::flush() + throw( io::NotConnectedException, + io::BufferSizeExceededException, + io::IOException, + uno::RuntimeException ) +{ + return; +} + + +/*********************************************************************************/ +/* */ +/* info_c implementation */ +/* */ +/*********************************************************************************/ + + +class fileaccess::XCommandInfo_impl + : public cppu::OWeakObject, + public XCommandInfo +{ +public: + + XCommandInfo_impl( shell* pMyShell, const rtl::OUString& aUnqPath ); + virtual ~XCommandInfo_impl(); + + // XInterface + virtual uno::Any SAL_CALL + queryInterface( + const uno::Type& aType ) + throw( uno::RuntimeException); + + virtual void SAL_CALL + acquire( + void ) + throw( uno::RuntimeException); + + virtual void SAL_CALL + release( + void ) + throw( uno::RuntimeException); + + // XCommandInfo + + virtual uno::Sequence< CommandInfo > SAL_CALL + getCommands( + void ) + throw( uno::RuntimeException); + + virtual CommandInfo SAL_CALL + getCommandInfoByName( + const rtl::OUString& Name ) + throw( UnsupportedCommandException, + uno::RuntimeException); + + virtual CommandInfo SAL_CALL + getCommandInfoByHandle( + sal_Int32 Handle ) + throw( UnsupportedCommandException, + uno::RuntimeException ); + + virtual sal_Bool SAL_CALL + hasCommandByName( + const rtl::OUString& Name ) + throw( uno::RuntimeException ); + + virtual sal_Bool SAL_CALL + hasCommandByHandle( + sal_Int32 Handle ) + throw( uno::RuntimeException ); +private: + + shell* m_pMyShell; + uno::Reference< XContentProvider > m_xProvider; +}; + + +uno::Reference< XCommandInfo > SAL_CALL +shell::info_c( sal_Int32 CommandId, const rtl::OUString& aUnqPath ) +{ + XCommandInfo_impl* p = new XCommandInfo_impl( this,aUnqPath ); + return uno::Reference< XCommandInfo >( p ); +} + + +XCommandInfo_impl::XCommandInfo_impl( shell* pMyShell,const rtl::OUString& aUnqPath ) + : m_pMyShell( pMyShell ), + m_xProvider( pMyShell->m_pProvider ) +{ +} + +XCommandInfo_impl::~XCommandInfo_impl() +{ +} + + + +void SAL_CALL +XCommandInfo_impl::acquire( + void ) + throw( uno::RuntimeException ) +{ + OWeakObject::acquire(); +} + + +void SAL_CALL +XCommandInfo_impl::release( + void ) + throw( uno::RuntimeException ) +{ + OWeakObject::release(); +} + + +uno::Any SAL_CALL +XCommandInfo_impl::queryInterface( + const uno::Type& rType ) + throw( uno::RuntimeException ) +{ + uno::Any aRet = cppu::queryInterface( rType, + SAL_STATIC_CAST( XCommandInfo*,this) ); + return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ); +} + + +uno::Sequence< CommandInfo > SAL_CALL +XCommandInfo_impl::getCommands( + void ) + throw( uno::RuntimeException ) +{ + return m_pMyShell->m_sCommandInfo; +} + + +CommandInfo SAL_CALL +XCommandInfo_impl::getCommandInfoByName( + const rtl::OUString& aName ) + throw( UnsupportedCommandException, + uno::RuntimeException) +{ + for( sal_Int32 i = 0; i < m_pMyShell->m_sCommandInfo.getLength(); i++ ) + if( m_pMyShell->m_sCommandInfo[i].Name == aName ) + return m_pMyShell->m_sCommandInfo[i]; + + throw UnsupportedCommandException(); +} + + +CommandInfo SAL_CALL +XCommandInfo_impl::getCommandInfoByHandle( + sal_Int32 Handle ) + throw( UnsupportedCommandException, + uno::RuntimeException ) +{ + for( sal_Int32 i = 0; i < m_pMyShell->m_sCommandInfo.getLength(); ++i ) + if( m_pMyShell->m_sCommandInfo[i].Handle == Handle ) + return m_pMyShell->m_sCommandInfo[i]; + + throw UnsupportedCommandException(); +} + + +sal_Bool SAL_CALL +XCommandInfo_impl::hasCommandByName( + const rtl::OUString& aName ) + throw( uno::RuntimeException ) +{ + for( sal_Int32 i = 0; i < m_pMyShell->m_sCommandInfo.getLength(); ++i ) + if( m_pMyShell->m_sCommandInfo[i].Name == aName ) + return true; + + return false; +} + + +sal_Bool SAL_CALL +XCommandInfo_impl::hasCommandByHandle( + sal_Int32 Handle ) + throw( uno::RuntimeException ) +{ + for( sal_Int32 i = 0; i < m_pMyShell->m_sCommandInfo.getLength(); ++i ) + if( m_pMyShell->m_sCommandInfo[i].Handle == Handle ) + return true; + + return false; +} + + +/*********************************************************************************/ +/* */ +/* info_p-Implementation */ +/* */ +/*********************************************************************************/ + + + + +uno::Reference< beans::XPropertySetInfo > SAL_CALL +shell::info_p( sal_Int32 CommandId, + const rtl::OUString& aUnqPath ) +{ + vos::OGuard aGuard( m_aMutex ); + XPropertySetInfo_impl* p = new XPropertySetInfo_impl( this,aUnqPath ); + return uno::Reference< beans::XPropertySetInfo >( p ); +} + + + + + + +/*********************************************************************************/ +/* */ +/* setv-Implementation */ +/* */ +/*********************************************************************************/ + +void SAL_CALL +shell::setv( sal_Int32 CommandId, + const rtl::OUString& aUnqPath, + const uno::Sequence< beans::PropertyValue >& values ) +{ + vos::OGuard aGuard( m_aMutex ); + + sal_Int32 propChanged = 0; + uno::Sequence< beans::PropertyChangeEvent > seqChanged( values.getLength() ); + + shell::ContentMap::iterator it = m_aContent.find( aUnqPath ); + PropertySet& properties = *( it->second.properties ); + shell::PropertySet::iterator it1; + uno::Any aAny; + + for( sal_Int32 i = 0; i < values.getLength(); ++i ) + { + MyProperty toset( values[i].Name ); + it1 = properties.find( toset ); + if( it1 == properties.end() ) continue; + + aAny = it1->getValue(); + if( aAny == values[i].Value ) continue; + + seqChanged[ propChanged ].PropertyName = values[i].Name; + seqChanged[ propChanged ].PropertyHandle = -1; + seqChanged[ propChanged ].Further = false; + seqChanged[ propChanged ].OldValue <<= aAny; + seqChanged[ propChanged++ ].NewValue = values[i].Value; + + it1->setValue( values[i].Value ); + + if( ! it1->IsNative() ) + { + // Also put logical properties into storage + if( !it->second.xS.is() ) + load( it,true ); + + // Special logic for ContentType + if( ( values[i].Name == ContentType ) && + it1->getState() == beans::PropertyState_DEFAULT_VALUE ) + { + it1->setState( beans::PropertyState_DIRECT_VALUE ); + it->second.xC->addProperty( values[i].Name, + beans::PropertyAttribute::MAYBEVOID, + values[i].Value ); + } + + it->second.xS->setPropertyValue( values[i].Name,values[i].Value ); + } + else + { + // Setting of physical file properties + } + } + + if( propChanged ) + { + seqChanged.realloc( propChanged ); + notifyPropertyChanges( getPropertyChangeNotifier( aUnqPath ),seqChanged ); + } +} + + +/*********************************************************************************/ +/* */ +/* getv-Implementation */ +/* */ +/*********************************************************************************/ + + + + + + + + +uno::Reference< sdbc::XRow > SAL_CALL +shell::getv( sal_Int32 CommandId, + const rtl::OUString& aUnqPath, + const uno::Sequence< beans::Property >& properties ) +{ + uno::Sequence< uno::Any > seq( properties.getLength() ); + + sal_Int32 n_Mask; + getMaskFromProperties( n_Mask,properties ); + osl::FileStatus aFileStatus( n_Mask ); + + osl::DirectoryItem aDirItem; + osl::DirectoryItem::get( aUnqPath,aDirItem ); + aDirItem.getFileStatus( aFileStatus ); + + { + vos::OGuard aGuard( m_aMutex ); + + shell::ContentMap::iterator it = m_aContent.find( aUnqPath ); + commit( it,aFileStatus ); + + shell::PropertySet::iterator it1; + PropertySet& propset = *(it->second.properties); + + for( sal_Int32 i = 0; i < seq.getLength(); ++i ) + { + MyProperty readProp( properties[i].Name ); + it1 = propset.find( readProp ); + if( it1 == propset.end() ) + seq[i] = uno::Any(); + else + seq[i] = it1->getValue(); + } + } + + XRow_impl* p = new XRow_impl( this,seq ); + return uno::Reference< sdbc::XRow >( p ); +} + + + + +/*********************************************************************************/ +/* */ +/* ls-Implementation */ +/* */ +/*********************************************************************************/ + + + + + + + +uno::Reference< XDynamicResultSet > SAL_CALL +shell::ls( sal_Int32 CommandId, + const rtl::OUString& aUnqPath, + const sal_Int32 OpenMode, + const uno::Sequence< beans::Property >& seq, + const uno::Sequence< NumberedSortingInfo >& seqSort ) +{ + XResultSet_impl* p = new XResultSet_impl( this,aUnqPath,OpenMode,seq,seqSort ); + + if( ! p->CtorSuccess() ) + { + delete p; p = 0; + } + + return uno::Reference< XDynamicResultSet > ( p ); +} + + + + + + + +/********************************************************************************/ +/* */ +/* transfer-commandos */ +/* */ +/********************************************************************************/ + + + +// Returns true if dstUnqPath is a child from srcUnqPath or both are equal +sal_Bool SAL_CALL isChild( const rtl::OUString& srcUnqPath, + const rtl::OUString& dstUnqPath ) +{ + static sal_Unicode slash = '/'; + // Simple lexical comparison + sal_Int32 srcL = srcUnqPath.getLength(); + sal_Int32 dstL = dstUnqPath.getLength(); + + return ( + ( srcUnqPath == dstUnqPath ) + || + ( ( dstL > srcL ) + && + ( srcUnqPath.compareTo( dstUnqPath, srcL ) == 0 ) + && + ( dstUnqPath[ srcL ] == slash ) ) + ); +} + + +// Changes the prefix in name +rtl::OUString SAL_CALL newName( + const rtl::OUString& aNewPrefix, + const rtl::OUString& aOldPrefix, + const rtl::OUString& old_Name ) +{ + sal_Int32 srcL = aOldPrefix.getLength(); + + rtl::OUString new_Name = old_Name.copy( srcL ); + new_Name = ( aNewPrefix + new_Name ); + return new_Name; +} + + +rtl::OUString SAL_CALL getTitle( const rtl::OUString& aPath ) +{ + sal_Unicode slash = '/'; + sal_Int32 lastIndex = aPath.lastIndexOf( slash ); + return aPath.copy( lastIndex + 1 ); +} + + +void SAL_CALL +shell::erasePersistentSet( const rtl::OUString& aUnqPath, + sal_Bool withChilds ) +{ + if( ! m_xFileRegistry.is() ) + { + VOS_ASSERT( m_xFileRegistry.is() ); + } + + uno::Sequence< rtl::OUString > seqNames; + + if( withChilds ) + { + uno::Reference< container::XNameAccess > xName( m_xFileRegistry,uno::UNO_QUERY ); + seqNames = xName->getElementNames(); + } + + sal_Int32 count = withChilds ? seqNames.getLength() : 1; + + rtl::OUString + old_Name = aUnqPath; + + for( sal_Int32 j = 0; j < count; ++j ) + { + if( withChilds && ! ( ::isChild( old_Name,seqNames[j] ) ) ) + continue; + + if( withChilds ) + { + old_Name = seqNames[j]; + } + + { + // Release possible references + vos::OGuard aGuard( m_aMutex ); + ContentMap::iterator it = m_aContent.find( old_Name ); + if( it != m_aContent.end() ) + { + it->second.xS = 0; + it->second.xC = 0; + it->second.xA = 0; + + delete it->second.properties; + it->second.properties = 0; + } + } + + if( m_xFileRegistry.is() ) + m_xFileRegistry->removePropertySet( old_Name ); + } +} + + + +void SAL_CALL +shell::copyPersistentSet( const rtl::OUString& srcUnqPath, + const rtl::OUString& dstUnqPath, + sal_Bool withChilds ) +{ + if( ! m_xFileRegistry.is() ) + { + VOS_ASSERT( m_xFileRegistry.is() ); + } + + uno::Sequence< rtl::OUString > seqNames; + + if( withChilds ) + { + uno::Reference< container::XNameAccess > xName( m_xFileRegistry,uno::UNO_QUERY ); + seqNames = xName->getElementNames(); + } + + sal_Int32 count = withChilds ? seqNames.getLength() : 1; + + rtl::OUString + old_Name = srcUnqPath, + new_Name = dstUnqPath; + + for( sal_Int32 j = 0; j < count; ++j ) + { + if( withChilds && ! ( ::isChild( srcUnqPath,seqNames[j] ) ) ) + continue; + + if( withChilds ) + { + old_Name = seqNames[j]; + new_Name = ::newName( dstUnqPath,srcUnqPath,old_Name ); + } + + uno::Reference< XPersistentPropertySet > x_src; + + if( m_xFileRegistry.is() ) + { + x_src = m_xFileRegistry->openPropertySet( old_Name,false ); + m_xFileRegistry->removePropertySet( new_Name ); + } + + if( x_src.is() ) + { + uno::Sequence< beans::Property > seqProperty = + x_src->getPropertySetInfo()->getProperties(); + + if( seqProperty.getLength() ) + { + uno::Reference< XPersistentPropertySet > + x_dstS = m_xFileRegistry->openPropertySet( new_Name,true ); + uno::Reference< beans::XPropertyContainer > + x_dstC( x_dstS,uno::UNO_QUERY ); + + for( sal_Int32 i = 0; i < seqProperty.getLength(); ++i ) + { + x_dstC->addProperty( seqProperty[i].Name, + seqProperty[i].Attributes, + x_src->getPropertyValue( seqProperty[i].Name ) ); + } + } + } + } // end for( sal_Int... +} + + +// Moves "srcUnqPath" to "dstUnqPath/NewTitle" +void SAL_CALL +shell::move( sal_Int32 CommandId, + const rtl::OUString srcUnqPath, + const rtl::OUString dstUnqPathIn, + const sal_Int32 NameClash ) + throw( CommandAbortedException ) +{ + rtl::OUString dstUnqPath( dstUnqPathIn ); + + // Moving file or folder ? + osl::DirectoryItem aItem; + osl::FileBase::RC err = osl::DirectoryItem::get( srcUnqPath,aItem ); + if( err ) + throw CommandAbortedException(); + osl::FileStatus aStatus( FileStatusMask_Type ); + aItem.getFileStatus( aStatus ); + + sal_Bool isDocument; + if( aStatus.isValid( FileStatusMask_Type ) ) + isDocument = aStatus.getFileType() == osl::FileStatus::Regular; + + err = osl::File::move( srcUnqPath,dstUnqPath ); // Why, the hell, is this not all what has to be done? + + if( err == osl::FileBase::E_EXIST ) + { + switch( NameClash ) + { + case NameClash::KEEP: + return; + break; + case NameClash::OVERWRITE: + { + sal_Int32 IsWhat = isDocument ? -1 : 1; +// don't call shell::remove because that function will send a deleted hint +// for dstUnqPath which isn't right. dstUnqPath will exist again after the +// call to osl::File::move. call osl::File::remove() instead. +// remove( CommandId,dstUnqPath,IsWhat ); + osl::File::remove( dstUnqPath ); + err = osl::File::move( srcUnqPath,dstUnqPath ); + } + break; + case NameClash::RENAME: + { + // "invent" a new valid title. + + sal_Int32 nPos = -1; + sal_Int32 nLastDot = dstUnqPath.lastIndexOf( '.' ); + sal_Int32 nLastSlash = dstUnqPath.lastIndexOf( '/' ); + if ( ( nLastSlash < nLastDot ) // dot is part of last(!) path segment + && ( nLastSlash != ( nLastDot - 1 ) ) ) // file name does not start with a dot + nPos = nLastDot; + else + nPos = dstUnqPath.getLength(); + + sal_Int32 nTry = 0; + rtl::OUString newDstUnqPath; + + do + { + newDstUnqPath = dstUnqPath; + + rtl::OUString aPostFix( rtl::OUString::createFromAscii( "_" ) ); + aPostFix += rtl::OUString::valueOf( ++nTry ); + + newDstUnqPath = newDstUnqPath.replaceAt( nPos, 0, aPostFix ); + + err = osl::File::move( srcUnqPath,newDstUnqPath ); + } + while ( ( err == osl::FileBase::E_EXIST ) && ( nTry < 10000 ) ); + + if ( err ) + { + VOS_ENSURE( sal_False, + "shell::move - Unable to resolve name clash" ); + throw CommandAbortedException(); + } + else + dstUnqPath = newDstUnqPath; + + break; + } + case NameClash::ERROR: + break; + default: + break; + } + } + + if( err ) + throw CommandAbortedException(); + + + copyPersistentSet( srcUnqPath,dstUnqPath, !isDocument ); + + rtl::OUString aDstParent = getParentName( dstUnqPath ); + rtl::OUString aDstTitle = getTitle( dstUnqPath ); + + rtl::OUString aSrcParent = getParentName( srcUnqPath ); + rtl::OUString aSrcTitle = getTitle( srcUnqPath ); + + notifyInsert( getContentEventListeners( aDstParent ),dstUnqPath ); + if( aDstParent != aSrcParent ) + notifyContentRemoved( getContentEventListeners( aSrcParent ),srcUnqPath ); + + notifyContentExchanged( getContentExchangedEventListeners( srcUnqPath,dstUnqPath, !isDocument ) ); + +/* + if( aSrcTitle != aDstTitle ) + { + uno::Sequence< beans::PropertyChangeEvent > seq(1); + seq[0].PropertyName = Title; + seq[0].Further = false; + seq[0].PropertyHandle = -1; + seq[0].OldValue <<= aSrcTitle; + seq[0].NewValue <<= aDstTitle; + notifyPropertyChanges( getPropertyChangeNotifier( dstUnqPath ),seq ); + } +*/ + erasePersistentSet( srcUnqPath, !isDocument ); +} + + +osl::FileBase::RC SAL_CALL +shell::copy_recursive( const rtl::OUString& srcUnqPath, + const rtl::OUString& dstUnqPath, + sal_Int32 TypeToCopy ) +{ + osl::FileBase::RC err; + + if( TypeToCopy == -1 ) // Document + { + err = osl::File::copy( srcUnqPath,dstUnqPath ); + } + else if( TypeToCopy == +1 ) // Folder + { + err = osl::Directory::create( dstUnqPath ); + osl::FileBase::RC next = err; + if( err == osl::FileBase::E_None ) + { + sal_Int32 n_Mask = FileStatusMask_FilePath | FileStatusMask_FileName | FileStatusMask_Type; + + osl::Directory aDir( srcUnqPath ); + aDir.open(); + osl::DirectoryItem aDirItem; + + while( ( next = aDir.getNextItem( aDirItem ) ) == osl::FileBase::E_None ) + { + sal_Bool IsDocument; + osl::FileStatus aFileStatus( n_Mask ); + aDirItem.getFileStatus( aFileStatus ); + if( aFileStatus.isValid( FileStatusMask_Type ) ) + IsDocument = aFileStatus.getFileType() == osl::FileStatus::Regular; + + // Getting the information for the next recursive copy + sal_Int32 newTypeToCopy = IsDocument ? -1 : +1; + + rtl::OUString newSrcUnqPath; + if( aFileStatus.isValid( FileStatusMask_FilePath ) ) + newSrcUnqPath = aFileStatus.getFilePath(); + + rtl::OUString newDstUnqPath = dstUnqPath; + rtl::OUString tit; + if( aFileStatus.isValid( FileStatusMask_FileName ) ) + tit = aFileStatus.getFileName(); + if( newDstUnqPath.lastIndexOf( sal_Unicode('/') ) != newDstUnqPath.getLength()-1 ) + newDstUnqPath += rtl::OUString::createFromAscii( "/" ); + newDstUnqPath += tit; + + copy_recursive( newSrcUnqPath,newDstUnqPath,newTypeToCopy ); + } + + aDir.close(); + if( next != osl::FileBase::E_NOENT ) + err = osl::FileBase::E_INVAL; + } + } + + return err; +} + + +void SAL_CALL +shell::copy( + sal_Int32 CommandId, + const rtl::OUString srcUnqPath, + const rtl::OUString dstUnqPathIn, + sal_Int32 NameClash ) + throw( CommandAbortedException ) +{ + rtl::OUString dstUnqPath( dstUnqPathIn ); + + // Moving file or folder ? + osl::DirectoryItem aItem; + osl::FileBase::RC err = osl::DirectoryItem::get( srcUnqPath,aItem ); + if( err ) + throw CommandAbortedException(); + osl::FileStatus aStatus( FileStatusMask_Type ); + aItem.getFileStatus( aStatus ); + + sal_Bool isDocument; + if( aStatus.isValid( FileStatusMask_Type ) ) + isDocument = aStatus.getFileType() == osl::FileStatus::Regular; + + sal_Int32 IsWhat = isDocument ? -1 : 1; + + err = copy_recursive( srcUnqPath,dstUnqPath,IsWhat ); + + if( err == osl::FileBase::E_EXIST ) + { + switch( NameClash ) + { + case NameClash::KEEP: + return; + break; + case NameClash::OVERWRITE: + { + remove( CommandId,dstUnqPath,IsWhat ); + err = copy_recursive( srcUnqPath,dstUnqPath,IsWhat ); + } + break; + case NameClash::RENAME: + { + // "invent" a new valid title. + + sal_Int32 nPos = -1; + sal_Int32 nLastDot = dstUnqPath.lastIndexOf( '.' ); + sal_Int32 nLastSlash = dstUnqPath.lastIndexOf( '/' ); + if ( ( nLastSlash < nLastDot ) // dot is part of last(!) path segment + && ( nLastSlash != ( nLastDot - 1 ) ) ) // file name does not start with a dot + nPos = nLastDot; + else + nPos = dstUnqPath.getLength(); + + sal_Int32 nTry = 0; + rtl::OUString newDstUnqPath; + + do + { + newDstUnqPath = dstUnqPath; + + rtl::OUString aPostFix( rtl::OUString::createFromAscii( "_" ) ); + aPostFix += rtl::OUString::valueOf( ++nTry ); + + newDstUnqPath = newDstUnqPath.replaceAt( nPos, 0, aPostFix ); + + err = copy_recursive( srcUnqPath, dstUnqPath, IsWhat ); + } + while ( ( err == osl::FileBase::E_EXIST ) && ( nTry < 10000 ) ); + + if ( err ) + { + VOS_ENSURE( sal_False, + "shell::copy - Unable to resolve name clash" ); + throw CommandAbortedException(); + } + else + dstUnqPath = newDstUnqPath; + + break; + } + case NameClash::ERROR: + break; + default: + break; + } + } + + if( err ) + throw CommandAbortedException(); + + copyPersistentSet( srcUnqPath,dstUnqPath, !isDocument ); + notifyInsert( getContentEventListeners( getParentName( dstUnqPath ) ),dstUnqPath ); +} + + +// Recursive deleting + +void SAL_CALL +shell::remove( sal_Int32 CommandId, + const rtl::OUString& aUnqPath, + sal_Int32 IsWhat ) +{ + sal_Int32 nMask = FileStatusMask_Type | FileStatusMask_FilePath; + osl::DirectoryItem aItem; + osl::FileStatus aStatus( nMask ); + + if( IsWhat == 0 ) + { + osl::DirectoryItem::get( aUnqPath, aItem ); + aItem.getFileStatus( aStatus ); + if( aStatus.isValid( nMask ) && + ( aStatus.getFileType() == osl::FileStatus::Regular || + aStatus.getFileType() == osl::FileStatus::Link ) ) + IsWhat = -1; + else if( aStatus.isValid( nMask ) && + ( aStatus.getFileType() == osl::FileStatus::Directory || + aStatus.getFileType() == osl::FileStatus::Volume ) ) + IsWhat = +1; + } + + if( IsWhat == -1 ) + { + osl::File::remove( aUnqPath ); + + notifyContentDeleted( getContentDeletedEventListeners(aUnqPath) ); + erasePersistentSet( aUnqPath ); // Removes from XPersistentPropertySet + } + else if( IsWhat == +1 ) + { + sal_Int32 recurse; + rtl::OUString name; + osl::Directory aFolder( aUnqPath ); + aFolder.open(); + + osl::FileBase::RC rcError = aFolder.getNextItem( aItem ); + while( osl::FileBase::E_None == rcError ) + { + aItem.getFileStatus( aStatus ); + + if( aStatus.isValid( nMask ) && + aStatus.getFileType() == osl::FileStatus::Regular ) + recurse = -1; + else if( aStatus.isValid( nMask ) && + ( aStatus.getFileType() == osl::FileStatus::Directory || + aStatus.getFileType() == osl::FileStatus::Volume ) ) + recurse = +1; + + name = aStatus.getFilePath(); + remove( CommandId, + name, + recurse ); + + rcError = aFolder.getNextItem( aItem ); + } + aFolder.close(); + osl::FileBase::RC err = osl::Directory::remove( aUnqPath ); + if( ! err ) + { + notifyContentDeleted( getContentDeletedEventListeners(aUnqPath) ); + erasePersistentSet( aUnqPath ); + } + } +} + + + + + +sal_Bool SAL_CALL +shell::mkdir( sal_Int32 CommandId, + const rtl::OUString& aUnqPath ) +{ + // Copy the Listener to be ThreadSave + + sal_Bool bSuccess = osl::FileBase::E_None == osl::Directory::create( aUnqPath ); + + if( bSuccess ) + { + rtl::OUString aPrtPath = getParentName( aUnqPath ); + notifyInsert( getContentEventListeners( aPrtPath ),aUnqPath ); + } + + return bSuccess; +} + + + +sal_Bool SAL_CALL +shell::mkfil( sal_Int32 CommandId, + const rtl::OUString& aUnqPath, + sal_Bool Overwrite, + const uno::Reference< io::XInputStream >& aInputStream ) +{ + + // return value unimportant + write( CommandId, + aUnqPath, + Overwrite, + aInputStream ); + + // Always notifications for an insert + // Cannot give an error + + rtl::OUString aPrtPath = getParentName( aUnqPath ); + notifyInsert( getContentEventListeners( aPrtPath ),aUnqPath ); + + return true; +} + + + +sal_Bool SAL_CALL +shell::write( sal_Int32 CommandId, + const rtl::OUString& aUnqPath, + sal_Bool OverWrite, + const uno::Reference< io::XInputStream >& aInputStream ) +{ + + osl::File aFile( aUnqPath ); + + sal_Bool bSuccess; + if( OverWrite ) + { + bSuccess = osl::FileBase::E_None == aFile.open( OpenFlag_Write | OpenFlag_Create ); + if( ! bSuccess ) + bSuccess = osl::FileBase::E_None == aFile.open( OpenFlag_Write ); + } + else + { + bSuccess = osl::FileBase::E_None == aFile.open( OpenFlag_Write ); + if( bSuccess ) + { + aFile.close(); + return true; + } + else + { + bSuccess = osl::FileBase::E_None == aFile.open( OpenFlag_Write | OpenFlag_Create ); + } + } + + if( bSuccess && aInputStream.is() ) + { + sal_uInt64 nTotalNumberOfBytes = 0; + sal_uInt64 nWrittenBytes; + sal_Int32 nReadBytes, nRequestedBytes = 2048; + uno::Sequence< sal_Int8 > seq( nRequestedBytes ); + do + { + nReadBytes = aInputStream->readBytes( seq, + nRequestedBytes ); + if( nReadBytes ) + { + const sal_Int8* p = seq.getConstArray(); + aFile.write( ((void*)(p)), + sal_uInt64( nReadBytes ), + nWrittenBytes ); + nTotalNumberOfBytes += nWrittenBytes; + if( nWrittenBytes != nReadBytes ) + { + // DBG_ASSERT( "Write Operation not successful" ); + } + } + } while( sal_uInt64( nReadBytes ) == nRequestedBytes ); + aFile.setSize( nTotalNumberOfBytes ); + } + +// else +// bSuccess = false; + + + aFile.close(); + + return bSuccess; +} + + + +/*********************************************************************************/ +/* */ +/* InsertDefaultProperties-Implementation */ +/* */ +/*********************************************************************************/ + + +void SAL_CALL shell::InsertDefaultProperties( const rtl::OUString& aUnqPath ) +{ + vos::OGuard aGuard( m_aMutex ); + + ContentMap::iterator it = + m_aContent.insert( ContentMap::value_type( aUnqPath,UnqPathData() ) ).first; + + load( it,false ); + + MyProperty ContentTProperty( ContentType ); + + PropertySet& properties = *(it->second.properties); + sal_Bool ContentNotDefau = properties.find( ContentTProperty ) != properties.end(); + + shell::PropertySet::iterator it1 = m_aDefaultProperties.begin(); + while( it1 != m_aDefaultProperties.end() ) + { + if( ContentNotDefau && it1->getPropertyName() == ContentType ) + { + // No insertion + } + else + properties.insert( *it1 ); + ++it1; + } +} + + +void SAL_CALL +shell::getScheme( rtl::OUString& Scheme ) +{ + Scheme = rtl::OUString::createFromAscii( "file" ); +} + +rtl::OUString SAL_CALL +shell::getImplementationName_static( void ) +{ + return rtl::OUString::createFromAscii( "FileProvider" ); +} + + +uno::Sequence< rtl::OUString > SAL_CALL +shell::getSupportedServiceNames_static( void ) +{ + rtl::OUString Supported = rtl::OUString::createFromAscii( "com.sun.star.ucb.FileContentProvider" ) ; + com::sun::star::uno::Sequence< rtl::OUString > Seq( &Supported,1 ); + return Seq; +} + + +sal_Bool SAL_CALL shell::getUnqFromUrl( const rtl::OUString& Url,rtl::OUString& Unq ) +{ + if( 0 == Url.compareToAscii( "file:///" ) || + 0 == Url.compareToAscii( "file://localhost/" ) || + 0 == Url.compareToAscii( "file://127.0.0.1/" ) ) + { + Unq = rtl::OUString::createFromAscii( "//./" ); + return false; + } + + sal_Bool err = osl::FileBase::E_None != osl::FileBase::getNormalizedPathFromFileURL( Url,Unq ); + + sal_Int32 l = Unq.getLength()-1; + if( ! err && Unq.getStr()[ l ] == '/' && + Unq.indexOf( '/', RTL_CONSTASCII_LENGTH("//") ) < l ) + Unq = Unq.copy(0, Unq.getLength() - 1); + + return err; +} + +sal_Bool SAL_CALL shell::getUrlFromUnq( const rtl::OUString& Unq,rtl::OUString& Url ) +{ + if( Unq.compareToAscii( "//./" ) == 0 ) + { + Url = rtl::OUString::createFromAscii( "file:///" ); + return false; + } + + rtl::OUString aUnq = Unq; + if( aUnq[ aUnq.getLength()-1 ] == sal_Unicode( ':' ) && aUnq.getLength() == 6 ) + { + aUnq += rtl::OUString::createFromAscii( "/" ); + } + sal_Bool err = osl::FileBase::E_None != osl::FileBase::getFileURLFromNormalizedPath( aUnq,Url ); + return err; +} + + + +// Privat methods + + +void SAL_CALL shell::getMaskFromProperties( sal_Int32& n_Mask, const uno::Sequence< beans::Property >& seq ) +{ + n_Mask = FileStatusMask_FilePath; + + rtl::OUString PropertyName; + for( sal_Int32 i = 0; i < seq.getLength(); ++i ) + { + PropertyName = seq[i].Name; + + if( PropertyName == Title ) + n_Mask |= FileStatusMask_FileName; + else if( PropertyName == IsDocument || PropertyName == IsFolder ) + n_Mask |= FileStatusMask_Type; + else if( PropertyName == DateCreated ) + n_Mask |= FileStatusMask_CreationTime; + else if( PropertyName == DateModified ) + n_Mask |= FileStatusMask_ModifyTime; + else if( PropertyName == Size ) + n_Mask |= FileStatusMask_FileSize; + else if( PropertyName == IsReadOnly ) + n_Mask |= FileStatusMask_Attributes; +// else if( PropertyName == FolderCount ) +// ; +// else if( PropertyName == DocumentCount ) +// ; + } +} + + + +void SAL_CALL +shell::commit( const shell::ContentMap::iterator& it, + const osl::FileStatus& aFileStatus ) +{ + uno::Any aAny; + shell::PropertySet::iterator it1; + + if( it->second.properties == 0 ) + { + rtl::OUString aPath = it->first; + InsertDefaultProperties( aPath ); + } + + PropertySet& properties = *( it->second.properties ); + + if( aFileStatus.isValid( FileStatusMask_FileName ) ) + { + aAny <<= aFileStatus.getFileName(); + + if( m_bFaked ) + { + for( sal_Int32 i = 0; i < m_vecMountPoint.size(); ++i ) + if( it->first == m_vecMountPoint[i].m_aDirectory ) + aAny <<= m_vecMountPoint[i].m_aTitle; + } + + it1 = properties.find( MyProperty( Title ) ); + if( it1 != properties.end() ) + { + it1->setValue( aAny ); + } + } + + if( aFileStatus.isValid( FileStatusMask_Type ) ) + { + sal_Bool dummy = + osl::FileStatus::Volume == aFileStatus.getFileType() + || + osl::FileStatus::Directory == aFileStatus.getFileType(); + + aAny <<= dummy; + it1 = properties.find( MyProperty( IsFolder ) ); + if( it1 != properties.end() ) + { + it1->setValue( aAny ); + } + + dummy = osl::FileStatus::Regular == aFileStatus.getFileType(); + aAny <<= dummy; + it1 = properties.find( MyProperty( IsDocument ) ); + if( it1 != properties.end() ) + { + it1->setValue( aAny ); + } + } + + if( m_bFaked && it->first.compareToAscii( "//./" ) == 0 ) + { + sal_Bool dummy = true; + + aAny <<= dummy; + it1 = properties.find( MyProperty( IsFolder ) ); + if( it1 != properties.end() ) + { + it1->setValue( aAny ); + } + + dummy = false; + aAny <<= dummy; + it1 = properties.find( MyProperty( IsDocument ) ); + if( it1 != properties.end() ) + { + it1->setValue( aAny ); + } + } + + if( aFileStatus.isValid( FileStatusMask_FileSize ) ) + { + aAny <<= sal_Int64( aFileStatus.getFileSize() ); + it1 = properties.find( MyProperty( Size ) ); + if( it1 != properties.end() ) + { + it1->setValue( aAny ); + } + } + + if( aFileStatus.isValid( FileStatusMask_Attributes ) ) + { + sal_uInt64 Attr = aFileStatus.getAttributes(); + sal_Bool readonly = ( Attr & Attribute_ReadOnly ) != 0; + aAny <<= readonly; + it1 = properties.find( MyProperty( IsReadOnly ) ); + if( it1 != properties.end() ) + { + it1->setValue( aAny ); + } + } + + if( m_bFaked && it->first.compareToAscii( "//./" ) == 0 ) + { + sal_Bool readonly = true; + aAny <<= readonly; + it1 = properties.find( MyProperty( IsReadOnly ) ); + if( it1 != properties.end() ) + { + it1->setValue( aAny ); + } + } + + if( aFileStatus.isValid( FileStatusMask_ModifyTime ) ) + { + TimeValue temp = aFileStatus.getModifyTime(); + + // Convert system time to local time (for EA) + TimeValue myLocalTime; + osl_getLocalTimeFromSystemTime( &temp, &myLocalTime ); + + oslDateTime myDateTime; + osl_getDateTimeFromTimeValue( &myLocalTime, &myDateTime ); + util::DateTime aDateTime; + + aDateTime.HundredthSeconds = myDateTime.NanoSeconds / 10000000; + aDateTime.Seconds = myDateTime.Seconds; + aDateTime.Minutes = myDateTime.Minutes; + aDateTime.Hours = myDateTime.Hours; + aDateTime.Day = myDateTime.Day; + aDateTime.Month = myDateTime.Month; + aDateTime.Year = myDateTime.Year; + aAny <<= aDateTime; + it1 = properties.find( MyProperty( DateModified ) ); + if( it1 != properties.end() ) + { + it1->setValue( aAny ); + } + } + + if( aFileStatus.isValid( FileStatusMask_CreationTime ) ) + { + TimeValue temp = aFileStatus.getCreationTime(); + + // Convert system time to local time (for EA) + TimeValue myLocalTime; + osl_getLocalTimeFromSystemTime( &temp, &myLocalTime ); + + oslDateTime myDateTime; + osl_getDateTimeFromTimeValue( &myLocalTime,&myDateTime ); + util::DateTime aDateTime; + + aDateTime.HundredthSeconds = myDateTime.NanoSeconds / 10000000; + aDateTime.Seconds = myDateTime.Seconds; + aDateTime.Minutes = myDateTime.Minutes; + aDateTime.Hours = myDateTime.Hours; + aDateTime.Day = myDateTime.Day; + aDateTime.Month = myDateTime.Month; + aDateTime.Year = myDateTime.Year; + aAny <<= aDateTime; + it1 = properties.find( MyProperty( DateCreated ) ); + if( it1 != properties.end() ) + { + it1->setValue( aAny ); + } + } +} + + + + +uno::Reference< sdbc::XRow > SAL_CALL +shell::getv( + sal_Int32 CommandId, + Notifier* pNotifier, + const uno::Sequence< beans::Property >& properties, + osl::DirectoryItem& aDirItem, + rtl::OUString& aUnqPath, + sal_Bool& aIsRegular ) +{ + uno::Sequence< uno::Any > seq( properties.getLength() ); + + sal_Int32 n_Mask; + getMaskFromProperties( n_Mask,properties ); + n_Mask |= FileStatusMask_Type; + + osl::FileStatus aFileStatus( n_Mask ); + aDirItem.getFileStatus( aFileStatus ); + + aUnqPath = aFileStatus.getFilePath(); + aIsRegular = aFileStatus.getFileType() == osl::FileStatus::Regular; + + registerNotifier( aUnqPath,pNotifier ); + InsertDefaultProperties( aUnqPath ); + { + vos::OGuard aGuard( m_aMutex ); + sal_Bool changer = false; + + shell::ContentMap::iterator it = m_aContent.find( aUnqPath ); + commit( it,aFileStatus ); + + shell::PropertySet::iterator it1; + PropertySet& propset = *(it->second.properties); + + for( sal_Int32 i = 0; i < seq.getLength(); ++i ) + { + MyProperty readProp( properties[i].Name ); + it1 = propset.find( readProp ); + if( it1 == propset.end() ) + seq[i] = uno::Any(); + else + seq[i] = it1->getValue(); + } + } + deregisterNotifier( aUnqPath,pNotifier ); + + XRow_impl* p = new XRow_impl( this,seq ); + return uno::Reference< sdbc::XRow >( p ); +} + + + + +rtl::OUString +shell::getParentName( const rtl::OUString& aFileName ) +{ + sal_Int32 lastIndex = aFileName.lastIndexOf( sal_Unicode('/') ); + rtl::OUString aParent = aFileName.copy( 0,lastIndex ); + + if( aParent[ aParent.getLength()-1] == sal_Unicode(':') && aParent.getLength() == 6 ) + aParent += rtl::OUString::createFromAscii( "/" ); + if( 0 == aParent.compareToAscii( "//." ) ) + aParent = rtl::OUString::createFromAscii( "//./" ); + + + return aParent; +} + + + +// EventListener + + +std::list< ContentEventNotifier* >* SAL_CALL +shell::getContentEventListeners( const rtl::OUString& aName ) +{ + std::list< ContentEventNotifier* >* p = new std::list< ContentEventNotifier* >; + std::list< ContentEventNotifier* >& listeners = *p; + { + vos::OGuard aGuard( m_aMutex ); + shell::ContentMap::iterator it = m_aContent.find( aName ); + if( it != m_aContent.end() && it->second.notifier ) + { + std::list<Notifier*>& listOfNotifiers = *( it->second.notifier ); + std::list<Notifier*>::iterator it1 = listOfNotifiers.begin(); + while( it1 != listOfNotifiers.end() ) + { + Notifier* pointer = *it1; + ContentEventNotifier* not = pointer->cCEL(); + if( not ) + listeners.push_back( not ); + ++it1; + } + } + } + return p; +} + + + +std::list< ContentEventNotifier* >* SAL_CALL +shell::getContentDeletedEventListeners( const rtl::OUString& aName ) +{ + std::list< ContentEventNotifier* >* p = new std::list< ContentEventNotifier* >; + std::list< ContentEventNotifier* >& listeners = *p; + { + vos::OGuard aGuard( m_aMutex ); + shell::ContentMap::iterator it = m_aContent.find( aName ); + if( it != m_aContent.end() && it->second.notifier ) + { + std::list<Notifier*>& listOfNotifiers = *( it->second.notifier ); + std::list<Notifier*>::iterator it1 = listOfNotifiers.begin(); + while( it1 != listOfNotifiers.end() ) + { + Notifier* pointer = *it1; + ContentEventNotifier* not = pointer->cDEL(); + if( not ) + listeners.push_back( not ); + ++it1; + } + } + } + return p; +} + + +void SAL_CALL +shell::notifyInsert( std::list< ContentEventNotifier* >* listeners,const rtl::OUString& aChildName ) +{ + std::list< ContentEventNotifier* >::iterator it = listeners->begin(); + while( it != listeners->end() ) + { + (*it)->notifyChildInserted( aChildName ); + delete (*it); + ++it; + } + delete listeners; +} + + +void SAL_CALL +shell::notifyContentDeleted( std::list< ContentEventNotifier* >* listeners ) +{ + std::list< ContentEventNotifier* >::iterator it = listeners->begin(); + while( it != listeners->end() ) + { + (*it)->notifyDeleted(); + delete (*it); + ++it; + } + delete listeners; +} + + +void SAL_CALL +shell::notifyContentRemoved( std::list< ContentEventNotifier* >* listeners, + const rtl::OUString& aChildName ) +{ + std::list< ContentEventNotifier* >::iterator it = listeners->begin(); + while( it != listeners->end() ) + { + (*it)->notifyRemoved( aChildName ); + delete (*it); + ++it; + } + delete listeners; +} + + + + +std::list< PropertySetInfoChangeNotifier* >* SAL_CALL +shell::getPropertySetListeners( const rtl::OUString& aName ) +{ + std::list< PropertySetInfoChangeNotifier* >* p = new std::list< PropertySetInfoChangeNotifier* >; + std::list< PropertySetInfoChangeNotifier* >& listeners = *p; + { + vos::OGuard aGuard( m_aMutex ); + shell::ContentMap::iterator it = m_aContent.find( aName ); + if( it != m_aContent.end() && it->second.notifier ) + { + std::list<Notifier*>& listOfNotifiers = *( it->second.notifier ); + std::list<Notifier*>::iterator it1 = listOfNotifiers.begin(); + while( it1 != listOfNotifiers.end() ) + { + Notifier* pointer = *it1; + PropertySetInfoChangeNotifier* not = pointer->cPSL(); + if( not ) + listeners.push_back( not ); + ++it1; + } + } + } + return p; +} + + +void SAL_CALL +shell::notifyPropertyAdded( std::list< PropertySetInfoChangeNotifier* >* listeners, + const rtl::OUString& aPropertyName ) +{ + std::list< PropertySetInfoChangeNotifier* >::iterator it = listeners->begin(); + while( it != listeners->end() ) + { + (*it)->notifyPropertyAdded( aPropertyName ); + delete (*it); + ++it; + } + delete listeners; +} + + +void SAL_CALL +shell::notifyPropertyRemoved( std::list< PropertySetInfoChangeNotifier* >* listeners, + const rtl::OUString& aPropertyName ) +{ + std::list< PropertySetInfoChangeNotifier* >::iterator it = listeners->begin(); + while( it != listeners->end() ) + { + (*it)->notifyPropertyRemoved( aPropertyName ); + delete (*it); + ++it; + } + delete listeners; +} + + + +std::vector< std::list< ContentEventNotifier* >* >* SAL_CALL +shell::getContentExchangedEventListeners( const rtl::OUString aOldPrefix, + const rtl::OUString aNewPrefix, + sal_Bool withChilds ) +{ + + std::vector< std::list< ContentEventNotifier* >* >* aVectorOnHeap = + new std::vector< std::list< ContentEventNotifier* >* >; + std::vector< std::list< ContentEventNotifier* >* >& aVector = *aVectorOnHeap; + + sal_Int32 count; + rtl::OUString aOldName; + rtl::OUString aNewName; + std::vector< rtl::OUString > oldChildList; + + { + vos::OGuard aGuard( m_aMutex ); + + if( ! withChilds ) + { + aOldName = aOldPrefix; + aNewName = aNewPrefix; + count = 1; + } + else + { + ContentMap::iterator itnames = m_aContent.begin(); + while( itnames != m_aContent.end() ) + { + if( ::isChild( aOldPrefix,itnames->first ) ) + { + oldChildList.push_back( itnames->first ); + } + ++itnames; + } + count = oldChildList.size(); + } + + + for( sal_Int32 j = 0; j < count; ++j ) + { + std::list< ContentEventNotifier* >* p = new std::list< ContentEventNotifier* >; + std::list< ContentEventNotifier* >& listeners = *p; + + if( withChilds ) + { + aOldName = oldChildList[j]; + aNewName = ::newName( aNewPrefix,aOldPrefix,aOldName ); + } + + shell::ContentMap::iterator itold = m_aContent.find( aOldName ); + if( itold != m_aContent.end() ) + { + shell::ContentMap::iterator itnew = m_aContent.insert( + ContentMap::value_type( aNewName,UnqPathData() ) ).first; + + // copy Ownership also + delete itnew->second.properties; + itnew->second.properties = itold->second.properties; + itold->second.properties = 0; + + // copy existing list + std::list< Notifier* >* copyList = itnew->second.notifier; + itnew->second.notifier = itold->second.notifier; + itold->second.notifier = 0; + + m_aContent.erase( itold ); + + if( itnew != m_aContent.end() && itnew->second.notifier ) + { + std::list<Notifier*>& listOfNotifiers = *( itnew->second.notifier ); + std::list<Notifier*>::iterator it1 = listOfNotifiers.begin(); + while( it1 != listOfNotifiers.end() ) + { + Notifier* pointer = *it1; + ContentEventNotifier* not = pointer->cEXC( aNewName ); + if( not ) + listeners.push_back( not ); + ++it1; + } + } + + // Merge with preexisting notifiers + // However, these may be in status BaseContent::Deleted + if( copyList != 0 ) + { + std::list< Notifier* >::iterator copyIt = copyList->begin(); + while( copyIt != copyList->end() ) + { + itnew->second.notifier->push_back( *copyIt ); + ++copyIt; + } + } + delete copyList; + } + aVector.push_back( p ); + } + } + + return aVectorOnHeap; +} + + + +void SAL_CALL +shell::notifyContentExchanged( std::vector< std::list< ContentEventNotifier* >* >* listeners_vec ) +{ + std::list< ContentEventNotifier* >* listeners; + for( sal_Int32 i = 0; i < listeners_vec->size(); ++i ) + { + listeners = (*listeners_vec)[i]; + std::list< ContentEventNotifier* >::iterator it = listeners->begin(); + while( it != listeners->end() ) + { + (*it)->notifyExchanged(); + delete (*it); + ++it; + } + delete listeners; + } + delete listeners_vec; +} + + + +std::list< PropertyChangeNotifier* >* SAL_CALL +shell::getPropertyChangeNotifier( const rtl::OUString& aName ) +{ + std::list< PropertyChangeNotifier* >* p = new std::list< PropertyChangeNotifier* >; + std::list< PropertyChangeNotifier* >& listeners = *p; + { + vos::OGuard aGuard( m_aMutex ); + shell::ContentMap::iterator it = m_aContent.find( aName ); + if( it != m_aContent.end() && it->second.notifier ) + { + std::list<Notifier*>& listOfNotifiers = *( it->second.notifier ); + std::list<Notifier*>::iterator it1 = listOfNotifiers.begin(); + while( it1 != listOfNotifiers.end() ) + { + Notifier* pointer = *it1; + PropertyChangeNotifier* not = pointer->cPCL(); + if( not ) + listeners.push_back( not ); + ++it1; + } + } + } + return p; +} + + +void SAL_CALL shell::notifyPropertyChanges( std::list< PropertyChangeNotifier* >* listeners, + const uno::Sequence< beans::PropertyChangeEvent >& seqChanged ) +{ + std::list< PropertyChangeNotifier* >::iterator it = listeners->begin(); + while( it != listeners->end() ) + { + (*it)->notifyPropertyChanged( seqChanged ); + delete (*it); + ++it; + } + delete listeners; +} + + + +// Return value: not mounted + +#ifdef UNX +extern "C" oslFileError osl_getRealPath(rtl_uString* strPath, rtl_uString** strRealPath); +#endif + +sal_Bool SAL_CALL shell::checkMountPoint( const rtl::OUString& aUnqPath, + rtl::OUString& aRedirectedPath ) +{ + sal_Int32 numMp = m_vecMountPoint.size(); + + if( ! numMp ) + { + // No access restrictions + aRedirectedPath = aUnqPath; + return true; + } + + + if( aUnqPath.compareTo( rtl::OUString::createFromAscii( "//./" ) ) == 0 ) + { + aRedirectedPath = aUnqPath; + return true; + } + +#ifdef UNX + rtl::OUString aRealUnqPath; +#endif + + for( sal_Int32 j = 0; j < numMp; ++j ) + { + rtl::OUString aAlias = m_vecMountPoint[j].m_aMountPoint; + rtl::OUString aDir = m_vecMountPoint[j].m_aDirectory; + sal_Int32 nL = aAlias.getLength(); + if( aUnqPath.compareTo( aAlias,nL ) == 0 ) + { + aRedirectedPath = aDir; + aRedirectedPath += aUnqPath.copy( nL ); + return true; + } +#ifdef UNX + else + { + oslFileError error = osl_File_E_None; + + if ( !aRealUnqPath.pData->length ) + error = osl_getRealPath( aUnqPath.pData, &aRealUnqPath.pData ); + + if ( osl_File_E_None == error && aRealUnqPath.compareTo( aAlias,nL ) == 0 ) + { + aRedirectedPath = aDir; + aRedirectedPath += aUnqPath.copy( nL ); + return true; + } + } +#endif + } + + return false; +} + + + +sal_Bool SAL_CALL shell::uncheckMountPoint( const rtl::OUString& aUnqPath, + rtl::OUString& aRedirectedPath ) +{ + sal_Int32 numMp = m_vecMountPoint.size(); + + if( ! numMp ) + { + // No access restrictions + aRedirectedPath = aUnqPath; + return true; + } + + + if( aUnqPath.compareTo( rtl::OUString::createFromAscii( "//./" ) ) == 0 ) + { + aRedirectedPath = aUnqPath; + return true; + } + +#ifdef UNX + rtl::OUString aRealUnqPath; +#endif + + for( sal_Int32 j = 0; j < numMp; ++j ) + { + sal_Int32 nL = m_vecMountPoint[j].m_aDirectory.getLength(); + if( aUnqPath.compareTo( m_vecMountPoint[j].m_aDirectory,nL ) == 0 ) + { + aRedirectedPath = m_vecMountPoint[j].m_aMountPoint; + aRedirectedPath += aUnqPath.copy( nL ); + return true; + } +#ifdef UNX + else + { + oslFileError error = osl_File_E_None; + + if ( !aRealUnqPath.pData->length ) + error = osl_getRealPath( aUnqPath.pData, &aRealUnqPath.pData ); + + if ( osl_File_E_None == error && aRealUnqPath.compareTo( m_vecMountPoint[j].m_aDirectory,nL ) == 0 ) + { + aRedirectedPath = m_vecMountPoint[j].m_aMountPoint; + aRedirectedPath += aUnqPath.copy( nL ); + return true; + } + } +#endif + } + + return false; +} + + +shell::MountPoint::MountPoint( const rtl::OUString& aMountPoint, + const rtl::OUString& aDirectory ) + : m_aMountPoint( aMountPoint ), + m_aDirectory( aDirectory ) +{ + rtl::OUString Title = aMountPoint; + sal_Int32 lastIndex = Title.lastIndexOf( sal_Unicode( '/' ) ); + m_aTitle = Title.copy( lastIndex + 1 ); +} diff --git a/ucb/source/ucp/file/shell.hxx b/ucb/source/ucp/file/shell.hxx new file mode 100644 index 000000000000..393c2b736704 --- /dev/null +++ b/ucb/source/ucp/file/shell.hxx @@ -0,0 +1,526 @@ +/************************************************************************* + * + * $RCSfile: shell.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:53:36 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + + +#ifndef _SHELL_HXX_ +#define _SHELL_HXX_ + + +#ifndef _CPPUHELPER_WEAK_HXX_ +#include <cppuhelper/weak.hxx> +#endif +#ifndef _CPPUHELPER_INTERFACECONTAINER_HXX_ +#include <cppuhelper/interfacecontainer.hxx> +#endif +#ifndef _CPPUHELPER_TYPEPROVIDER_HXX_ +#include <cppuhelper/typeprovider.hxx> +#endif +#ifndef __SGI_STL_VECTOR +#include <stl/vector> +#endif +#ifndef __SGI_STL_HASH_MAP +#include <stl/hash_map> +#endif +#ifndef __SGI_STL_HASH_SET +#include <stl/hash_set> +#endif +#ifndef _SGI_STL_LIST +#include <stl/list> +#endif +#ifndef _OSL_FILE_HXX_ +#include <osl/file.hxx> +#endif +#ifndef _RTL_USTRING_ +#include <rtl/ustring> +#endif +#ifndef _VOS_MUTEX_HXX_ +#include <vos/mutex.hxx> +#endif +#ifndef _COM_SUN_STAR_UNO_SEQUENCE_HXX_ +#include <com/sun/star/uno/Sequence.hxx> +#endif +#ifndef _COM_SUN_STAR_BEANS_PROPERTYCHANGEEVENT_HPP_ +#include <com/sun/star/beans/PropertyChangeEvent.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCOMMANDINFO_HPP_ +#include <com/sun/star/ucb/XCommandInfo.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_PROPERTY_HPP_ +#include <com/sun/star/beans/Property.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_ +#include <com/sun/star/beans/PropertyValue.hpp> +#endif +#ifndef _COM_SUN_STAR_IO_XSTREAM_HPP_ +#include <com/sun/star/io/XStream.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_XPROPERTYCHANGELISTENER_HPP_ +#include <com/sun/star/beans/XPropertyChangeListener.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCOMMANDPROCESSOR_HPP_ +#include <com/sun/star/ucb/XCommandProcessor.hpp> +#endif +#ifndef _COM_SUN_STAR_IO_XOUTPUTSTREAM_HPP_ +#include <com/sun/star/io/XOutputStream.hpp> +#endif +#ifndef _COM_SUN_STAR_IO_XINPUTSTREAM_HPP_ +#include <com/sun/star/io/XInputStream.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSETINFO_HPP_protected +#include <com/sun/star/beans/XPropertySetInfo.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_XPROPERTIESCHANGENOTIFIER_HPP_ +#include <com/sun/star/beans/XPropertiesChangeNotifier.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_NUMBEREDSORTINGINFO_HPP_ +#include <com/sun/star/ucb/NumberedSortingInfo.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_ +#include <com/sun/star/sdbc/XRow.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCONTENTPROVIDER_HPP_ +#include <com/sun/star/ucb/XContentProvider.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XDYNAMICRESULTSET_HPP__ +#include <com/sun/star/ucb/XDynamicResultSet.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_XPROPERTYCONTAINER_HPP_ +#include <com/sun/star/beans/XPropertyContainer.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_XPROPERTYACCESS_HPP_ +#include <com/sun/star/beans/XPropertyAccess.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XPROPERTYSETREGISTRYFACTORY_HPP_ +#include <com/sun/star/ucb/XPropertySetRegistryFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_TRANSFERINFO_HPP_ +#include <com/sun/star/ucb/TransferInfo.hpp> +#endif +#ifndef _FILTASK_HXX_ +#include "filtask.hxx" +#endif +#ifndef _FILNOT_HXX_ +#include "filnot.hxx" +#endif + +namespace fileaccess { + + class FileProvider; + class XPropertySetInfo_impl; + class XCommandInfo_impl; + class XResultSet_impl; + class BaseContent; + class shell; + + class shell + : public virtual TaskManager + { + friend class XPropertySetInfo_impl; + friend class XResultSet_impl; + friend class XCommandInfo_impl; + public: + // Type definitions + + typedef rtl::OUString UniquePath; + typedef equalOUString eUniquePath; + typedef hashOUString hUniquePath; + + class MyProperty + { + private: + rtl::OUString PropertyName; + sal_Int32 Handle; + sal_Bool isNative; + com::sun::star::uno::Type Typ; // Duplicates information in Value + com::sun::star::uno::Any Value; + com::sun::star::beans::PropertyState State; + sal_Int16 Attributes; + public: + MyProperty(); + MyProperty( const rtl::OUString& __PropertyName ); + MyProperty( const sal_Bool& __isNative, + const rtl::OUString& __PropertyName, + const sal_Int32& __Handle, + const com::sun::star::uno::Type& __Typ, + const com::sun::star::uno::Any& __Value, + const com::sun::star::beans::PropertyState& __State, + const sal_Int16& __Attributes ); + + ~MyProperty(); + inline const sal_Bool& SAL_CALL IsNative() const; + inline const rtl::OUString& SAL_CALL getPropertyName() const; + inline const sal_Int32& SAL_CALL getHandle() const; + inline const com::sun::star::uno::Type& SAL_CALL getType() const; + inline const com::sun::star::uno::Any& SAL_CALL getValue() const; + inline const com::sun::star::beans::PropertyState& SAL_CALL getState() const; + inline const sal_Int16& SAL_CALL getAttributes() const; + + // The set* functions are declared const, because the key of "this" stays intact + inline void SAL_CALL setHandle( const sal_Int32& __Handle ) const; + inline void SAL_CALL setType( const com::sun::star::uno::Type& __Type ) const; + inline void SAL_CALL setValue( const com::sun::star::uno::Any& __Value ) const; + inline void SAL_CALL setState( const com::sun::star::beans::PropertyState& __State ) const; + inline void SAL_CALL setAttributes( const sal_Int16& __Attributes ) const; + }; + + struct eMyProperty + { + bool operator()( const MyProperty& rKey1, const MyProperty& rKey2 ) const + { + return !!( rKey1.getPropertyName() == rKey2.getPropertyName() ); + } + }; + + struct hMyProperty + { + size_t operator()( const MyProperty& rName ) const + { + return rName.getPropertyName().hashCode(); + } + }; + + typedef std::hash_set< MyProperty,hMyProperty,eMyProperty > PropertySet; + typedef std::list< Notifier* > NotifierList; + + + class UnqPathData + { + public: + UnqPathData(); + ~UnqPathData(); + UnqPathData( const UnqPathData& ); + UnqPathData& operator=( UnqPathData& ); + + PropertySet* properties; + NotifierList* notifier; + + // Three views on the PersistentPropertySet + com::sun::star::uno::Reference< com::sun::star::ucb::XPersistentPropertySet > xS; + com::sun::star::uno::Reference< com::sun::star::beans::XPropertyContainer > xC; + com::sun::star::uno::Reference< com::sun::star::beans::XPropertyAccess > xA; + }; + + typedef std::hash_map< UniquePath,UnqPathData,hUniquePath,eUniquePath > ContentMap; + + public: + // MethodenDefinitionen + shell( const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& xMultiServiceFactory, + FileProvider* pProvider ); + + virtual ~shell(); + + void SAL_CALL registerNotifier( const rtl::OUString& aUnqPath,Notifier* pNotifier ); + void SAL_CALL deregisterNotifier( const rtl::OUString& aUnqPath,Notifier* pNotifier ); + + + void SAL_CALL associate( const rtl::OUString& UnqPath, + const rtl::OUString& PropertyName, + const com::sun::star::uno::Any& DefaultValue, + const sal_Int16 Attributes ) + throw( com::sun::star::beans::PropertyExistException, + com::sun::star::beans::IllegalTypeException, + com::sun::star::uno::RuntimeException); + + + void SAL_CALL deassociate( const rtl::OUString& UnqPath, + const rtl::OUString& PropertyName ) + throw( com::sun::star::beans::UnknownPropertyException, + com::sun::star::beans::NotRemoveableException, + com::sun::star::uno::RuntimeException); + + com::sun::star::uno::Reference< com::sun::star::ucb::XDynamicResultSet > SAL_CALL + ls( sal_Int32 CommandId, + const rtl::OUString& aUnqPath, + const sal_Int32 OpenMode, + const com::sun::star::uno::Sequence< com::sun::star::beans::Property >& sProperty, + const com::sun::star::uno::Sequence< com::sun::star::ucb::NumberedSortingInfo > & sSortingInfo ); + + + com::sun::star::uno::Reference< com::sun::star::io::XInputStream > SAL_CALL + open( sal_Int32 CommandId, + const rtl::OUString& aUnqPath ); + + com::sun::star::uno::Reference< com::sun::star::io::XStream > SAL_CALL + open_rw( sal_Int32 CommandId, + const rtl::OUString& aUnqPath ); + + void SAL_CALL page( sal_Int32 CommandId, + const rtl::OUString& aUnqPath, + const com::sun::star::uno::Reference< com::sun::star::io::XOutputStream >& xOutputStream ) + throw( com::sun::star::ucb::CommandAbortedException ); + + // Info for the properties + com::sun::star::uno::Reference< com::sun::star::beans::XPropertySetInfo > SAL_CALL + info_p( sal_Int32 CommandId, + const rtl::OUString& aUnqPath ); + + // Info for commands + com::sun::star::uno::Reference< com::sun::star::ucb::XCommandInfo > SAL_CALL + info_c( sal_Int32 CommandId, + const rtl::OUString& aUnqPath ); + + + // Setting values + void SAL_CALL setv( sal_Int32 CommandId, + const rtl::OUString& aUnqPath, + const com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >& values ); + + // Reading values + com::sun::star::uno::Reference< com::sun::star::sdbc::XRow > SAL_CALL + getv( sal_Int32 CommandId, + const rtl::OUString& aUnqPath, + const com::sun::star::uno::Sequence< com::sun::star::beans::Property >& properties ); + + // + void SAL_CALL + move( sal_Int32 CommandId, + const rtl::OUString srcUnqPath, // Full file(folder)-path + const rtl::OUString dstUnqPath, // Path to the destination-directory + const sal_Int32 NameClash ) + throw( com::sun::star::ucb::CommandAbortedException ); + + void SAL_CALL + copy( sal_Int32 CommandId, // See "move" + const rtl::OUString srcUnqPath, + const rtl::OUString dstUnqPath, + sal_Int32 NameClash ) + throw( com::sun::star::ucb::CommandAbortedException ); + +#define RemoveFolder 1 +#define RemoveFile -1 +#define RemoveUnknown 0 + + void SAL_CALL + remove( sal_Int32 CommandId, + const rtl::OUString& aUnqPath, + sal_Int32 TypeToMove = RemoveUnknown ); + +#undef RemoveUnknown +#undef RemoveFile +#undef RemoveFolder + + + sal_Bool SAL_CALL // Creates new directory + mkdir( sal_Int32 CommandId, // returns success + const rtl::OUString& aDirectoryName ); + + + sal_Bool SAL_CALL // Returns success + mkfil( sal_Int32 CommandId, // Creates new file + const rtl::OUString& aFileName, // returns success + sal_Bool OverWrite, + const com::sun::star::uno::Reference< com::sun::star::io::XInputStream >& aInputStream ); + + sal_Bool SAL_CALL // Returns success + write( sal_Int32 CommandId, + const rtl::OUString& aUnqPath, + sal_Bool OverWrite, + const com::sun::star::uno::Reference< com::sun::star::io::XInputStream >& aInputStream ); + + + void SAL_CALL InsertDefaultProperties( const rtl::OUString& aUnqPath ); + static void SAL_CALL getScheme( rtl::OUString& Scheme ); + sal_Bool SAL_CALL getUnqFromUrl( const rtl::OUString& Url, rtl::OUString& Unq ); + sal_Bool SAL_CALL getUrlFromUnq( const rtl::OUString& Unq, rtl::OUString& Url ); + rtl::OUString SAL_CALL getParentName( const rtl::OUString& aFileName ); + + + + + // Methods for "writeComponentInfo" and "createComponentFactory" + static rtl::OUString SAL_CALL getImplementationName_static( void ); + static com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames_static( void ); + + + FileProvider* m_pProvider; + com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > m_xMultiServiceFactory; + com::sun::star::uno::Reference< com::sun::star::ucb::XPropertySetRegistry > m_xFileRegistry; + private: + // Get EventListeners + std::list< ContentEventNotifier* >* SAL_CALL getContentEventListeners( const rtl::OUString& aName ); + std::list< ContentEventNotifier* >* SAL_CALL getContentDeletedEventListeners( const rtl::OUString& aName ); + std::vector< std::list< ContentEventNotifier* >* >* SAL_CALL getContentExchangedEventListeners( + const rtl::OUString aOldPrefix, + const rtl::OUString aNewPrefix, + sal_Bool withChilds ); + std::list< PropertyChangeNotifier* >* SAL_CALL getPropertyChangeNotifier( const rtl::OUString& aName ); + std::list< PropertySetInfoChangeNotifier* >* SAL_CALL getPropertySetListeners( const rtl::OUString& aName ); + + + // Notifications + void SAL_CALL notifyPropertyChanges( std::list< PropertyChangeNotifier* >* listeners, + const com::sun::star::uno::Sequence< com::sun::star::beans::PropertyChangeEvent >& + seqChanged ); + + void SAL_CALL notifyContentExchanged( std::vector< std::list< ContentEventNotifier* >* >* listeners_vec ); + + void SAL_CALL notifyInsert( std::list< ContentEventNotifier* >* listeners,const rtl::OUString& aChildName ); + + void SAL_CALL notifyContentDeleted( std::list< ContentEventNotifier* >* listeners ); + + void SAL_CALL notifyContentRemoved( std::list< ContentEventNotifier* >* listeners, + const rtl::OUString& aChildName ); + + + + void SAL_CALL notifyPropertyAdded( std::list< PropertySetInfoChangeNotifier* >* listeners, + const rtl::OUString& aPropertyName ); + + void SAL_CALL notifyPropertyRemoved( std::list< PropertySetInfoChangeNotifier* >* listeners, + const rtl::OUString& aPropertyName ); + + // Methods + + void SAL_CALL erasePersistentSet( const rtl::OUString& aUnqPath, + sal_Bool withChilds = false ); + + void SAL_CALL copyPersistentSet( const rtl::OUString& srcUnqPath, + const rtl::OUString& dstUnqPath, + sal_Bool withChilds = false ); + + // Special optimized method for getting the properties of a directoryitem + com::sun::star::uno::Reference< com::sun::star::sdbc::XRow > SAL_CALL + getv( sal_Int32 CommandId, + Notifier* pNotifier, + const com::sun::star::uno::Sequence< com::sun::star::beans::Property >& properties, + osl::DirectoryItem& DirItem, + rtl::OUString& aUnqPath, + sal_Bool& bIsRegular ); + + + void SAL_CALL + getMaskFromProperties( + sal_Int32& n_Mask, + const com::sun::star::uno::Sequence< com::sun::star::beans::Property >& seq ); + + void SAL_CALL + load( const shell::ContentMap::iterator& it, sal_Bool create ); + + void SAL_CALL + commit( + const shell::ContentMap::iterator& it, + const osl::FileStatus& aFileStatus ); + + void SAL_CALL + setFileProperties( const com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >& values, + sal_Int32 numberOfValues ); + + osl::FileBase::RC SAL_CALL copy_recursive( const rtl::OUString& srcUnqPath, + const rtl::OUString& dstUnqPath, + sal_Int32 TypeToCopy ); + + // General + vos::OMutex m_aMutex; + ContentMap m_aContent; + + // Default properties + + const rtl::OUString Title; + const rtl::OUString IsDocument; + const rtl::OUString IsFolder; + const rtl::OUString DateCreated; + const rtl::OUString DateModified; + const rtl::OUString Size; + const rtl::OUString FolderCount; + const rtl::OUString DocumentCount; + const rtl::OUString ContentType; + const rtl::OUString IsReadOnly; + + public: + const rtl::OUString FolderContentType; + const rtl::OUString FileContentType; + + private: + PropertySet m_aDefaultProperties; + + // Commands + com::sun::star::uno::Sequence< com::sun::star::ucb::CommandInfo > m_sCommandInfo; + + public: + + sal_Bool m_bFaked; + + struct MountPoint + { + MountPoint( const rtl::OUString& aMountPoint, + const rtl::OUString& aDirectory ); + + rtl::OUString m_aTitle; + rtl::OUString m_aMountPoint; + rtl::OUString m_aDirectory; + }; + + std::vector< MountPoint > m_vecMountPoint; + + sal_Bool SAL_CALL checkMountPoint( const rtl::OUString& aUnqPath, + rtl::OUString& aRedirectedPath ); + + sal_Bool SAL_CALL uncheckMountPoint( const rtl::OUString& aUnqPath, + rtl::OUString& aRedirectedPath ); + + }; +} // end namespace fileaccess + +#endif + diff --git a/ucb/source/ucp/hierarchy/dynamicresultset.cxx b/ucb/source/ucp/hierarchy/dynamicresultset.cxx new file mode 100644 index 000000000000..1db2506639dd --- /dev/null +++ b/ucb/source/ucp/hierarchy/dynamicresultset.cxx @@ -0,0 +1,129 @@ +/************************************************************************* + * + * $RCSfile: dynamicresultset.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:54:18 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +/************************************************************************** + TODO + ************************************************************************** + + - This implementation is not a dynamic result set!!! It only implements + the necessary interfaces, but never recognizes/notifies changes!!! + + *************************************************************************/ + +#ifndef _HIERARCHYDATASUPPLIER_HXX +#include "hierarchydatasupplier.hxx" +#endif +#ifndef _DYNAMICRESULTSET_HXX +#include "dynamicresultset.hxx" +#endif + +using namespace com::sun::star::lang; +using namespace com::sun::star::ucb; +using namespace com::sun::star::uno; +using namespace hierarchy_ucp; + +//========================================================================= +//========================================================================= +// +// DynamicResultSet Implementation. +// +//========================================================================= +//========================================================================= + +DynamicResultSet::DynamicResultSet( + const Reference< XMultiServiceFactory >& rxSMgr, + const vos::ORef< HierarchyContent >& rxContent, + const OpenCommandArgument2& rCommand ) +: ResultSetImplHelper( rxSMgr, rCommand ), + m_xContent( rxContent ) +{ +} + +//========================================================================= +// +// Non-interface methods. +// +//========================================================================= + +void DynamicResultSet::initStatic() +{ + m_xResultSet1 + = new ::ucb::ResultSet( + m_xSMgr, + m_aCommand.Properties, + new HierarchyResultSetDataSupplier( m_xSMgr, + m_xContent, + m_aCommand.Mode ) ); +} + +//========================================================================= +void DynamicResultSet::initDynamic() +{ + m_xResultSet1 + = new ::ucb::ResultSet( + m_xSMgr, + m_aCommand.Properties, + new HierarchyResultSetDataSupplier( m_xSMgr, + m_xContent, + m_aCommand.Mode ) ); + m_xResultSet2 = m_xResultSet1; +} + diff --git a/ucb/source/ucp/hierarchy/dynamicresultset.hxx b/ucb/source/ucp/hierarchy/dynamicresultset.hxx new file mode 100644 index 000000000000..86d67a1fadff --- /dev/null +++ b/ucb/source/ucp/hierarchy/dynamicresultset.hxx @@ -0,0 +1,96 @@ +/************************************************************************* + * + * $RCSfile: dynamicresultset.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:54:18 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _DYNAMICRESULTSET_HXX +#define _DYNAMICRESULTSET_HXX + +#ifndef _VOS_REF_HXX_ +#include <vos/ref.hxx> +#endif +#ifndef _UCBHELPER_RESULTSETHELPER_HXX +#include <ucbhelper/resultsethelper.hxx> +#endif + +#ifndef _HIERARCHYCONTENT_HXX +#include "hierarchycontent.hxx" +#endif + +namespace hierarchy_ucp { + +class DynamicResultSet : public ::ucb::ResultSetImplHelper +{ + vos::ORef< HierarchyContent > m_xContent; + +private: + virtual void initStatic(); + virtual void initDynamic(); + +public: + DynamicResultSet( + const com::sun::star::uno::Reference< + com::sun::star::lang::XMultiServiceFactory >& rxSMgr, + const vos::ORef< HierarchyContent >& rxContent, + const com::sun::star::ucb::OpenCommandArgument2& rCommand ); +}; + +} + +#endif /* !_DYNAMICRESULTSET_HXX */ diff --git a/ucb/source/ucp/hierarchy/hierarchycontent.cxx b/ucb/source/ucp/hierarchy/hierarchycontent.cxx new file mode 100644 index 000000000000..db48c0e15b96 --- /dev/null +++ b/ucb/source/ucp/hierarchy/hierarchycontent.cxx @@ -0,0 +1,1641 @@ +/************************************************************************* + * + * $RCSfile: hierarchycontent.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:54:18 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +/************************************************************************** + TODO + ************************************************************************** + + - optimize transfer command. "Move" should be implementable much more + efficient! + + ************************************************************************** + + - Root Folder vs. 'normal' Folder + - root doesn't support command 'delete' + - root doesn't support command 'insert' + - root needs not created via XContentCreator - queryContent with root + folder id ( HIERARCHY_ROOT_FOLDER_URL ) always returns a value != 0 + - root has no parent. + + *************************************************************************/ + +#ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HPP_ +#include <com/sun/star/beans/PropertyAttribute.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_XPROPERTYACCESS_HPP_ +#include <com/sun/star/beans/XPropertyAccess.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_ +#include <com/sun/star/sdbc/XRow.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_INSERTCOMMANDARGUMENT_HPP_ +#include <com/sun/star/ucb/InsertCommandArgument.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_OPENCOMMANDARGUMENT2_HPP_ +#include <com/sun/star/ucb/OpenCommandArgument2.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCOMMANDINFO_HPP_ +#include <com/sun/star/ucb/XCommandInfo.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XPERSISTENTPROPERTYSET_HPP_ +#include <com/sun/star/ucb/XPersistentPropertySet.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_NAMECLASH_HPP_ +#include <com/sun/star/ucb/NameClash.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_TRANSFERINFO_HPP_ +#include <com/sun/star/ucb/TransferInfo.hpp> +#endif +#ifndef _VOS_DIAGNOSE_HXX_ +#include <vos/diagnose.hxx> +#endif +#ifndef _UCBHELPER_CONTENTIDENTIFIER_HXX +#include <ucbhelper/contentidentifier.hxx> +#endif +#ifndef _UCBHELPER_PROPERTYVALUESET_HXX +#include <ucbhelper/propertyvalueset.hxx> +#endif + +#ifndef _HIERARCHYCONTENT_HXX +#include "hierarchycontent.hxx" +#endif +#ifndef _HIERARCHYPROVIDER_HXX +#include "hierarchyprovider.hxx" +#endif +#ifndef _DYNAMICRESULTSET_HXX +#include "dynamicresultset.hxx" +#endif + +using namespace com::sun::star::container; +using namespace com::sun::star::beans; +using namespace com::sun::star::lang; +using namespace com::sun::star::sdbc; +using namespace com::sun::star::ucb; +using namespace com::sun::star::uno; +using namespace cppu; +using namespace rtl; + +using namespace hierarchy_ucp; + +//========================================================================= +//========================================================================= +// +// HierarchyContent Implementation. +// +//========================================================================= +//========================================================================= + +// static ( "virtual" ctor ) +HierarchyContent* HierarchyContent::create( + const Reference< XMultiServiceFactory >& rxSMgr, + ::ucb::ContentProviderImplHelper* pProvider, + const Reference< XContentIdentifier >& Identifier ) +{ + // Fail, if content does not exist. + HierarchyContentProperties aProps; + if ( !loadData( rxSMgr, Identifier, aProps ) ) + return 0; + + return new HierarchyContent( rxSMgr, pProvider, Identifier, aProps ); +} + +//========================================================================= +// static ( "virtual" ctor ) +HierarchyContent* HierarchyContent::create( + const Reference< XMultiServiceFactory >& rxSMgr, + ::ucb::ContentProviderImplHelper* pProvider, + const Reference< XContentIdentifier >& Identifier, + const ContentInfo& Info ) +{ + if ( !Info.Type.getLength() ) + return 0; + + if ( ( Info.Type.compareToAscii( HIERARCHY_FOLDER_CONTENT_TYPE ) != 0 ) && + ( Info.Type.compareToAscii( HIERARCHY_LINK_CONTENT_TYPE ) != 0 ) ) + return 0; + +#if 0 + // Fail, if content does exist. + if ( hasData( rxSMgr, Identifier ) ) + return 0; +#endif + + return new HierarchyContent( rxSMgr, pProvider, Identifier, Info ); +} + +//========================================================================= +HierarchyContent::HierarchyContent( + const Reference< XMultiServiceFactory >& rxSMgr, + ::ucb::ContentProviderImplHelper* pProvider, + const Reference< XContentIdentifier >& Identifier, + const HierarchyContentProperties& rProps ) +: ContentImplHelper( rxSMgr, pProvider, Identifier ), + m_aProps( rProps ), + m_eState( PERSISTENT ) +{ + setKind( Identifier ); +} + +//========================================================================= +HierarchyContent::HierarchyContent( + const Reference< XMultiServiceFactory >& rxSMgr, + ::ucb::ContentProviderImplHelper* pProvider, + const Reference< XContentIdentifier >& Identifier, + const ContentInfo& Info ) +: ContentImplHelper( rxSMgr, pProvider, Identifier, sal_False ), + m_eState( TRANSIENT ) +{ + if ( Info.Type.compareToAscii( HIERARCHY_FOLDER_CONTENT_TYPE ) == 0 ) + { + // New folder... + m_aProps.aContentType = Info.Type; +// m_aProps.aTitle = + m_aProps.bIsFolder = sal_True; + m_aProps.bIsDocument = sal_False; + } + else + { + VOS_ENSURE( + Info.Type.compareToAscii( HIERARCHY_LINK_CONTENT_TYPE ) == 0, + "HierarchyContent::HierarchyContent - Wrong content info!" ); + + // New link... + m_aProps.aContentType = Info.Type; +// m_aProps.aTitle = + m_aProps.bIsFolder = sal_False; + m_aProps.bIsDocument = sal_True; + } + + setKind( Identifier ); +} + +//========================================================================= +// virtual +HierarchyContent::~HierarchyContent() +{ +} + +//========================================================================= +// +// XInterface methods. +// +//========================================================================= + +// virtual +void SAL_CALL HierarchyContent::acquire() + throw( RuntimeException ) +{ + ContentImplHelper::acquire(); +} + +//========================================================================= +// virtual +void SAL_CALL HierarchyContent::release() + throw( RuntimeException ) +{ + ContentImplHelper::release(); +} + +//========================================================================= +// virtual +Any SAL_CALL HierarchyContent::queryInterface( const Type & rType ) + throw ( RuntimeException ) +{ + Any aRet; + + if ( isFolder() ) + aRet = cppu::queryInterface( rType, + static_cast< XContentCreator * >( this ) ); + + return aRet.hasValue() ? aRet : ContentImplHelper::queryInterface( rType ); +} + +//========================================================================= +// +// XTypeProvider methods. +// +//========================================================================= + +XTYPEPROVIDER_COMMON_IMPL( HierarchyContent ); + +//========================================================================= +// virtual +Sequence< Type > SAL_CALL HierarchyContent::getTypes() + throw( RuntimeException ) +{ + static OTypeCollection* pCollection = NULL; + + if ( !pCollection ) + { + osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() ); + if ( !pCollection ) + { + if ( isFolder() ) + { + static OTypeCollection aCollection( + CPPU_TYPE_REF( XTypeProvider ), + CPPU_TYPE_REF( XServiceInfo ), + CPPU_TYPE_REF( XComponent ), + CPPU_TYPE_REF( XContent ), + CPPU_TYPE_REF( XCommandProcessor ), + CPPU_TYPE_REF( XPropertiesChangeNotifier ), + CPPU_TYPE_REF( XCommandInfoChangeNotifier ), + CPPU_TYPE_REF( XPropertyContainer ), + CPPU_TYPE_REF( XPropertySetInfoChangeNotifier ), + CPPU_TYPE_REF( XChild ), + CPPU_TYPE_REF( XContentCreator ) ); // !! + pCollection = &aCollection; + } + else + { + static OTypeCollection aCollection( + CPPU_TYPE_REF( XTypeProvider ), + CPPU_TYPE_REF( XServiceInfo ), + CPPU_TYPE_REF( XComponent ), + CPPU_TYPE_REF( XContent ), + CPPU_TYPE_REF( XCommandProcessor ), + CPPU_TYPE_REF( XPropertiesChangeNotifier ), + CPPU_TYPE_REF( XCommandInfoChangeNotifier ), + CPPU_TYPE_REF( XPropertyContainer ), + CPPU_TYPE_REF( XPropertySetInfoChangeNotifier ), + CPPU_TYPE_REF( XChild ) ); + pCollection = &aCollection; + } + } + } + + return (*pCollection).getTypes(); +} + +//========================================================================= +// +// XServiceInfo methods. +// +//========================================================================= + +// virtual +OUString SAL_CALL HierarchyContent::getImplementationName() + throw( RuntimeException ) +{ + return OUString::createFromAscii( "HierarchyContent" ); +} + +//========================================================================= +// virtual +Sequence< OUString > SAL_CALL HierarchyContent::getSupportedServiceNames() + throw( RuntimeException ) +{ + Sequence< OUString > aSNS( 1 ); + + if ( m_eKind == LINK ) + aSNS.getArray()[ 0 ] = OUString::createFromAscii( + HIERARCHY_LINK_CONTENT_SERVICE_NAME ); + else if ( m_eKind == FOLDER ) + aSNS.getArray()[ 0 ] = OUString::createFromAscii( + HIERARCHY_FOLDER_CONTENT_SERVICE_NAME ); + else + aSNS.getArray()[ 0 ] = OUString::createFromAscii( + HIERARCHY_ROOT_FOLDER_CONTENT_SERVICE_NAME ); + + return aSNS; +} + +//========================================================================= +// +// XContent methods. +// +//========================================================================= + +// virtual +OUString SAL_CALL HierarchyContent::getContentType() + throw( RuntimeException ) +{ + return m_aProps.aContentType; +} + +//========================================================================= +// virtual +Reference< XContentIdentifier > SAL_CALL HierarchyContent::getIdentifier() + throw( RuntimeException ) +{ + // Transient? + if ( m_eState == TRANSIENT ) + { + // Transient contents have no identifier. + return Reference< XContentIdentifier >(); + } + + return ContentImplHelper::getIdentifier(); +} + +//========================================================================= +// +// XCommandProcessor methods. +// +//========================================================================= + +// virtual +Any SAL_CALL HierarchyContent::execute( const Command& aCommand, + sal_Int32 CommandId, + const Reference< + XCommandEnvironment >& Environment ) + throw( Exception, CommandAbortedException, RuntimeException ) +{ + Any aRet; + + if ( aCommand.Name.compareToAscii( "getPropertyValues" ) == 0 ) + { + ////////////////////////////////////////////////////////////////// + // getPropertyValues + ////////////////////////////////////////////////////////////////// + + Sequence< Property > Properties; + if ( !( aCommand.Argument >>= Properties ) ) + { + VOS_ENSURE( sal_False, "Wrong argument type!" ); + return Any(); + } + + aRet <<= getPropertyValues( Properties ); + } + else if ( aCommand.Name.compareToAscii( "setPropertyValues" ) == 0 ) + { + ////////////////////////////////////////////////////////////////// + // setPropertyValues + ////////////////////////////////////////////////////////////////// + + Sequence< PropertyValue > aProperties; + if ( !( aCommand.Argument >>= aProperties ) ) + { + VOS_ENSURE( sal_False, "Wrong argument type!" ); + return Any(); + } + + if ( !aProperties.getLength() ) + { + VOS_ENSURE( sal_False, "No properties!" ); + return Any(); + } + + setPropertyValues( aProperties ); + } + else if ( aCommand.Name.compareToAscii( "getPropertySetInfo" ) == 0 ) + { + ////////////////////////////////////////////////////////////////// + // getPropertySetInfo + ////////////////////////////////////////////////////////////////// + + aRet <<= getPropertySetInfo(); + } + else if ( aCommand.Name.compareToAscii( "getCommandInfo" ) == 0 ) + { + ////////////////////////////////////////////////////////////////// + // getCommandInfo + ////////////////////////////////////////////////////////////////// + + aRet <<= getCommandInfo(); + } + else if ( isFolder() && ( aCommand.Name.compareToAscii( "open" ) == 0 ) ) + { + ////////////////////////////////////////////////////////////////// + // open command for a folder content + ////////////////////////////////////////////////////////////////// + + OpenCommandArgument2 aOpenCommand; + if ( aCommand.Argument >>= aOpenCommand ) + { + Reference< XDynamicResultSet > xSet + = new DynamicResultSet( m_xSMgr, this, aOpenCommand ); + aRet <<= xSet; + } + else + { + VOS_ENSURE( sal_False, + "HierarchyContent::execute - invalid parameter!" ); + throw CommandAbortedException(); + } + } + else if ( aCommand.Name.compareToAscii( "insert" ) == 0 ) + { + ////////////////////////////////////////////////////////////////// + // insert + // ( Not available at root folder and at persistent objects ) + ////////////////////////////////////////////////////////////////// + + InsertCommandArgument aArg; + if ( aCommand.Argument >>= aArg ) + { + sal_Int32 nNameClash = aArg.ReplaceExisting + ? NameClash::OVERWRITE + : NameClash::ERROR; + insert( nNameClash ); + } + else + { + VOS_ENSURE( sal_False, + "HierarchyContent::execute - invalid parameter!" ); + throw CommandAbortedException(); + } + } + else if ( aCommand.Name.compareToAscii( "delete" ) == 0 ) + { + ////////////////////////////////////////////////////////////////// + // delete + // ( Not available at root folder and at non-persistent objects ) + ////////////////////////////////////////////////////////////////// + + sal_Bool bDeletePhysical = sal_False; + aCommand.Argument >>= bDeletePhysical; + destroy( bDeletePhysical ); + + // Remove own and all children's persistent data. + removeData(); + + // Remove own and all children's Additional Core Properties. + removeAdditionalPropertySet( sal_True ); + } + else if ( aCommand.Name.compareToAscii( "transfer" ) == 0 ) + { + ////////////////////////////////////////////////////////////////// + // transfer + // ( Not available at link objects ) + ////////////////////////////////////////////////////////////////// + + TransferInfo aInfo; + if ( aCommand.Argument >>= aInfo ) + { + transfer( aInfo ); + } + else + { + VOS_ENSURE( sal_False, + "HierarchyContent::execute - invalid parameter!" ); + throw CommandAbortedException(); + } + } + else + { + ////////////////////////////////////////////////////////////////// + // Unknown command + ////////////////////////////////////////////////////////////////// + + VOS_ENSURE( sal_False, + "HierarchyContent::execute - unknown command!" ); + throw CommandAbortedException(); + } + + return aRet; +} + +//========================================================================= +// virtual +void SAL_CALL HierarchyContent::abort( sal_Int32 CommandId ) + throw( RuntimeException ) +{ + // @@@ Generally, no action takes much time... +} + +//========================================================================= +// +// XContentCreator methods. +// +//========================================================================= + +// virtual +Sequence< ContentInfo > SAL_CALL +HierarchyContent::queryCreatableContentsInfo() + throw( RuntimeException ) +{ + if ( isFolder() ) + { + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + + Sequence< ContentInfo > aSeq( 2 ); + + // Folder. + aSeq.getArray()[ 0 ].Type + = OUString::createFromAscii( HIERARCHY_FOLDER_CONTENT_TYPE ); + aSeq.getArray()[ 0 ].Attributes = 0; + + Sequence< Property > aFolderProps( 1 ); + aFolderProps.getArray()[ 0 ] = Property( + OUString::createFromAscii( "Title" ), + -1, + getCppuType( static_cast< const OUString * >( 0 ) ), + PropertyAttribute::BOUND ); + aSeq.getArray()[ 0 ].Properties = aFolderProps; + + // Link. + aSeq.getArray()[ 1 ].Type + = OUString::createFromAscii( HIERARCHY_LINK_CONTENT_TYPE ); + aSeq.getArray()[ 1 ].Attributes = 0; + + Sequence< Property > aLinkProps( 2 ); + aLinkProps.getArray()[ 0 ] = Property( + OUString::createFromAscii( "Title" ), + -1, + getCppuType( static_cast< const OUString * >( 0 ) ), + PropertyAttribute::BOUND ); + aLinkProps.getArray()[ 1 ] = Property( + OUString::createFromAscii( "TargetURL" ), + -1, + getCppuType( static_cast< const OUString * >( 0 ) ), + PropertyAttribute::BOUND ); + aSeq.getArray()[ 1 ].Properties = aLinkProps; + + return aSeq; + } + else + { + VOS_ENSURE( sal_False, + "queryCreatableContentsInfo called on non-folder object!" ); + + return Sequence< ContentInfo >( 0 ); + } +} + +//========================================================================= +// virtual +Reference< XContent > SAL_CALL HierarchyContent::createNewContent( + const ContentInfo& Info ) + throw( RuntimeException ) +{ + if ( isFolder() ) + { + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + + if ( !Info.Type.getLength() ) + return Reference< XContent >(); + + if ( ( Info.Type.compareToAscii( HIERARCHY_FOLDER_CONTENT_TYPE ) != 0 ) + && + ( Info.Type.compareToAscii( HIERARCHY_LINK_CONTENT_TYPE ) != 0 ) ) + return Reference< XContent >(); + + OUString aURL = m_xIdentifier->getContentIdentifier(); + + VOS_ENSURE( aURL.getLength() > 0, + "HierarchyContent::createNewContent - empty identifier!" ); + + if ( ( aURL.lastIndexOf( '/' ) + 1 ) != aURL.getLength() ) + aURL += OUString::createFromAscii( "/" ); + + if ( Info.Type.compareToAscii( HIERARCHY_FOLDER_CONTENT_TYPE ) == 0 ) + aURL += OUString::createFromAscii( "New_Folder" ); + else + aURL += OUString::createFromAscii( "New_Link" ); + + Reference< XContentIdentifier > xId( + new ::ucb::ContentIdentifier( m_xSMgr, aURL ) ); + + return create( m_xSMgr, m_xProvider.getBodyPtr(), xId, Info ); + } + else + { + VOS_ENSURE( sal_False, + "createNewContent called on non-folder object!" ); + return Reference< XContent >(); + } +} + +//========================================================================= +// virtual +OUString HierarchyContent::getParentURL() +{ + OUString aURL = m_xIdentifier->getContentIdentifier(); + + // Am I the root folder? + if ( m_eKind == ROOT ) + return OUString(); + + sal_Int32 nPos = aURL.lastIndexOf( '/' ); + + if ( nPos == ( aURL.getLength() - 1 ) ) + { + // Trailing slash found. Skip. + nPos = aURL.lastIndexOf( '/', nPos ); + } + + if ( nPos != -1 ) + { + OUString aParentURL = aURL.copy( 0, nPos ); + return aParentURL; + } + + return OUString(); +} + +//========================================================================= +//static +sal_Bool HierarchyContent::hasData( + const Reference< XMultiServiceFactory >& rxSMgr, + const Reference< XContentIdentifier >& Identifier ) +{ + OUString aURL = Identifier->getContentIdentifier(); + +// if ( aURL.compareToAscii( HIERARCHY_ROOT_FOLDER_URL, +// HIERARCHY_ROOT_FOLDER_URL_LENGTH ) != 0 ) +// { +// // Illegal identifier! +// return sal_False; +// } + + // Am I the root folder? + if ( aURL.getLength() == HIERARCHY_ROOT_FOLDER_URL_LENGTH ) + { + // hasData must always return 'true' for root folder + // even if no persistent data exist!!! + return sal_True; + } + + HierarchyEntry aEntry( rxSMgr, aURL ); + HierarchyEntryData aData; + + return aEntry.hasData(); +} + +//========================================================================= +//static +sal_Bool HierarchyContent::loadData( + const Reference< XMultiServiceFactory >& rxSMgr, + const Reference< XContentIdentifier >& Identifier, + HierarchyContentProperties& rProps ) +{ + OUString aURL = Identifier->getContentIdentifier(); + +// if ( aURL.compareToAscii( HIERARCHY_ROOT_FOLDER_URL, +// HIERARCHY_ROOT_FOLDER_URL_LENGTH ) != 0 ) +// { +// // Illegal identifier! +// return sal_False; +// } + + // Am I the root folder? + if ( aURL.getLength() == HIERARCHY_ROOT_FOLDER_URL_LENGTH ) + { + // loadData must always return 'true' for root folder + // even if no persistent data exist!!! --> Fill props!!! + + rProps.aContentType = OUString::createFromAscii( + HIERARCHY_FOLDER_CONTENT_TYPE ); +// rProps.aTitle = OUString(); +// rProps.aTargetURL = OUString(); + rProps.bIsFolder = sal_True; + rProps.bIsDocument = sal_False; + } + else + { + + HierarchyEntry aEntry( rxSMgr, aURL ); + if ( !aEntry.getData( rProps ) ) + return sal_False; + + if ( rProps.aTargetURL.getLength() > 0 ) + { + rProps.aContentType = OUString::createFromAscii( + HIERARCHY_LINK_CONTENT_TYPE ); + rProps.bIsFolder = sal_False; + rProps.bIsDocument = sal_True; + } + else + { + rProps.aContentType = OUString::createFromAscii( + HIERARCHY_FOLDER_CONTENT_TYPE ); + rProps.bIsFolder = sal_True; + rProps.bIsDocument = sal_False; + } + } + return sal_True; +} + +//========================================================================= +sal_Bool HierarchyContent::storeData() +{ + HierarchyEntry aEntry( m_xSMgr, m_xIdentifier->getContentIdentifier() ); + return aEntry.setData( m_aProps, sal_True ); +} + +//========================================================================= +sal_Bool HierarchyContent::renameData( + const Reference< XContentIdentifier >& xOldId, + const Reference< XContentIdentifier >& xNewId ) +{ + HierarchyEntry aEntry( m_xSMgr, xOldId->getContentIdentifier() ); + return aEntry.move( xNewId->getContentIdentifier() ); +} + +//========================================================================= +sal_Bool HierarchyContent::removeData() +{ + HierarchyEntry aEntry( m_xSMgr, m_xIdentifier->getContentIdentifier() ); + return aEntry.remove(); +} + +//========================================================================= +void HierarchyContent::setKind( + const Reference< XContentIdentifier >& Identifier ) +{ + if ( m_aProps.bIsFolder ) + { + // Am I the root folder? + if ( Identifier->getContentIdentifier().compareToAscii( + HIERARCHY_ROOT_FOLDER_URL ) == 0 ) + m_eKind = ROOT; + else + m_eKind = FOLDER; + } + else + m_eKind = LINK; +} + +//========================================================================= +Reference< XContentIdentifier > HierarchyContent::getIdentifierFromTitle() +{ + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + + // Assemble new content identifier... + + OUString aURL( m_xIdentifier->getContentIdentifier() ); + sal_Int32 nPos = aURL.lastIndexOf( '/' ); + + if ( nPos == ( aURL.getLength() - 1 ) ) + { + // Trailing slash found. Skip. + nPos = aURL.lastIndexOf( '/', nPos ); + } + + if ( nPos == -1 ) + { + VOS_ENSURE( sal_False, + "HierarchyContent::getIdentifierFromTitle - Invalid URL!" ); + return Reference< XContentIdentifier >(); + } + + OUString aNewURL = aURL.copy( 0, nPos + 1 ); + aNewURL += HierarchyContentProvider::encodeSegment( m_aProps.aTitle ); + + return Reference< XContentIdentifier >( + new ::ucb::ContentIdentifier( m_xSMgr, aNewURL ) ); +} + +//========================================================================= +void HierarchyContent::queryChildren( HierarchyContentRefList& rChildren ) +{ + if ( ( m_eKind != FOLDER ) && ( m_eKind != ROOT ) ) + return; + + // Obtain a list with a snapshot of all currently instanciated contents + // from provider and extract the contents which are direct children + // of this content. + + ::ucb::ContentRefList aAllContents; + m_xProvider->queryExistingContents( aAllContents ); + + OUString aURL = m_xIdentifier->getContentIdentifier(); + sal_Int32 nPos = aURL.lastIndexOf( '/' ); + + if ( nPos != ( aURL.getLength() - 1 ) ) + { + // No trailing slash found. Append. + aURL += OUString::createFromAscii( "/" ); + } + + sal_Int32 nLen = aURL.getLength(); + + ::ucb::ContentRefList::const_iterator it = aAllContents.begin(); + ::ucb::ContentRefList::const_iterator end = aAllContents.end(); + + while ( it != end ) + { + ::ucb::ContentImplHelperRef xChild = (*it); + OUString aChildURL = xChild->getIdentifier()->getContentIdentifier(); + + // Is aURL a prefix of aChildURL? + if ( ( aChildURL.getLength() > nLen ) && + ( aChildURL.compareTo( aURL, nLen ) == 0 ) ) + { + sal_Int32 nPos = nLen; + nPos = aChildURL.indexOf( '/', nPos ); + + if ( ( nPos == -1 ) || + ( nPos == ( aChildURL.getLength() - 1 ) ) ) + { + // No further slashes/ only a final slash. It's a child! + rChildren.push_back( + HierarchyContentRef( + static_cast< HierarchyContent * >( + xChild.getBodyPtr() ) ) ); + } + } + ++it; + } +} + +//========================================================================= +sal_Bool HierarchyContent::exchangeIdentity( + const Reference< XContentIdentifier >& xNewId ) +{ + if ( !xNewId.is() ) + return sal_False; + + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + + Reference< XContent > xThis = this; + + // Already persistent? + if ( m_eState != PERSISTENT ) + { + VOS_ENSURE( sal_False, + "HierarchyContent::exchangeIdentity - Not persistent!" ); + return sal_False; + } + + // Am I the root folder? + if ( m_eKind == ROOT ) + { + VOS_ENSURE( sal_False, "HierarchyContent::exchangeIdentity - " + "Not supported by root folder!" ); + return sal_False; + } + + // Exchange own identitity. + + // Fail, if a content with given id already exists. + if ( !hasData( xNewId ) ) + { + OUString aOldURL = m_xIdentifier->getContentIdentifier(); + + if ( exchange( xNewId ) ) + { + if ( m_eKind == FOLDER ) + { + // Process instanciated children... + + HierarchyContentRefList aChildren; + queryChildren( aChildren ); + + HierarchyContentRefList::const_iterator it = aChildren.begin(); + HierarchyContentRefList::const_iterator end = aChildren.end(); + + while ( it != end ) + { + HierarchyContentRef xChild = (*it); + + // Create new content identifier for the child... + Reference< XContentIdentifier > xOldChildId + = xChild->getIdentifier(); + OUString aOldChildURL = xOldChildId->getContentIdentifier(); + OUString aNewChildURL + = aOldChildURL.replaceAt( + 0, + aOldURL.getLength(), + xNewId->getContentIdentifier() ); + Reference< XContentIdentifier > xNewChildId + = new ::ucb::ContentIdentifier( m_xSMgr, aNewChildURL ); + + if ( !xChild->exchangeIdentity( xNewChildId ) ) + return sal_False; + + ++it; + } + } + return sal_True; + } + } + + VOS_ENSURE( sal_False, + "HierarchyContent::exchangeIdentity - " + "Panic! Cannot exchange identity!" ); + return sal_False; +} + +//========================================================================= +// static +Reference< XRow > HierarchyContent::getPropertyValues( + const Reference< XMultiServiceFactory >& rSMgr, + const Sequence< Property >& rProperties, + const HierarchyContentProperties& rData, + const vos::ORef< ucb::ContentProviderImplHelper >& rProvider, + const OUString& rContentId ) +{ + // Note: Empty sequence means "get values of all supported properties". + + vos::ORef< ::ucb::PropertyValueSet > xRow + = new ::ucb::PropertyValueSet( rSMgr ); + + sal_Int32 nCount = rProperties.getLength(); + if ( nCount ) + { + Reference< XPropertySet > xAdditionalPropSet; + sal_Bool bTriedToGetAdditonalPropSet = sal_False; + + const Property* pProps = rProperties.getConstArray(); + for ( sal_Int32 n = 0; n < nCount; ++n ) + { + const Property& rProp = pProps[ n ]; + + // Process Core properties. + + if ( rProp.Name.compareToAscii( "ContentType" ) == 0 ) + { + xRow->appendString ( rProp, rData.aContentType ); + } + else if ( rProp.Name.compareToAscii( "Title" ) == 0 ) + { + xRow->appendString ( rProp, rData.aTitle ); + } + else if ( rProp.Name.compareToAscii( "IsDocument" ) == 0 ) + { + xRow->appendBoolean( rProp, rData.bIsDocument ); + } + else if ( rProp.Name.compareToAscii( "IsFolder" ) == 0 ) + { + xRow->appendBoolean( rProp, rData.bIsFolder ); + } + else if ( rProp.Name.compareToAscii( "TargetURL" ) == 0 ) + { + // TargetURL is only supported by links. + + if ( rData.bIsDocument ) + xRow->appendString( rProp, rData.aTargetURL ); + else + xRow->appendVoid( rProp ); + } + + else + { + // Not a Core Property! Maybe it's an Additional Core Property?! + + if ( !bTriedToGetAdditonalPropSet && !xAdditionalPropSet.is() ) + { + xAdditionalPropSet + = Reference< XPropertySet >( + rProvider->getAdditionalPropertySet( rContentId, + sal_False ), + UNO_QUERY ); + bTriedToGetAdditonalPropSet = sal_True; + } + + if ( xAdditionalPropSet.is() ) + { + if ( !xRow->appendPropertySetValue( + xAdditionalPropSet, + rProp ) ) + { + // Append empty entry. + xRow->appendVoid( rProp ); + } + } + else + { + // Append empty entry. + xRow->appendVoid( rProp ); + } + } + } + } + else + { + // Append all Core Properties. + xRow->appendString ( + Property( OUString::createFromAscii( "ContentType" ), + -1, + getCppuType( static_cast< const OUString * >( 0 ) ), + PropertyAttribute::BOUND | PropertyAttribute::READONLY ), + rData.aContentType ); + xRow->appendString ( + Property( OUString::createFromAscii( "Title" ), + -1, + getCppuType( static_cast< const OUString * >( 0 ) ), + PropertyAttribute::BOUND ), + rData.aTitle ); + xRow->appendBoolean( + Property( OUString::createFromAscii( "IsDocument" ), + -1, + getCppuBooleanType(), + PropertyAttribute::BOUND | PropertyAttribute::READONLY ), + rData.bIsDocument ); + xRow->appendBoolean( + Property( OUString::createFromAscii( "IsFolder" ), + -1, + getCppuBooleanType(), + PropertyAttribute::BOUND | PropertyAttribute::READONLY ), + rData.bIsFolder ); + + if ( rData.bIsDocument ) + xRow->appendString( + Property( OUString::createFromAscii( "TargetURL" ), + -1, + getCppuType( static_cast< const OUString * >( 0 ) ), + PropertyAttribute::BOUND ), + rData.aTargetURL ); + + // Append all Additional Core Properties. + + Reference< XPropertySet > xSet( + rProvider->getAdditionalPropertySet( rContentId, sal_False ), + UNO_QUERY ); + xRow->appendPropertySet( xSet ); + } + + return Reference< XRow >( xRow.getBodyPtr() ); +} + +//========================================================================= +Reference< XRow > HierarchyContent::getPropertyValues( + const Sequence< Property >& rProperties ) +{ + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + return getPropertyValues( m_xSMgr, + rProperties, + m_aProps, + m_xProvider, + m_xIdentifier->getContentIdentifier() ); +} + +//========================================================================= +void HierarchyContent::setPropertyValues( + const Sequence< PropertyValue >& rValues ) +{ + osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex ); + + Sequence< PropertyChangeEvent > aChanges( rValues.getLength() ); + sal_Int32 nChanged = 0; + + PropertyChangeEvent aEvent; + aEvent.Source = static_cast< OWeakObject * >( this ); + aEvent.Further = sal_False; +// aEvent.PropertyName = + aEvent.PropertyHandle = -1; +// aEvent.OldValue = +// aEvent.NewValue = + + const PropertyValue* pValues = rValues.getConstArray(); + sal_Int32 nCount = rValues.getLength(); + + Reference< XPersistentPropertySet > xAdditionalPropSet; + sal_Bool bTriedToGetAdditonalPropSet = sal_False; + + sal_Bool bExchange = sal_False; + + for ( sal_Int32 n = 0; n < nCount; ++n ) + { + const PropertyValue& rValue = pValues[ n ]; + + if ( rValue.Name.compareToAscii( "ContentType" ) == 0 ) + { + // Read-only property! + } + else if ( rValue.Name.compareToAscii( "IsDocument" ) == 0 ) + { + // Read-only property! + } + else if ( rValue.Name.compareToAscii( "IsFolder" ) == 0 ) + { + // Read-only property! + } + else if ( rValue.Name.compareToAscii( "Title" ) == 0 ) + { + OUString aNewValue; + if ( rValue.Value >>= aNewValue ) + { + // No empty titles! + if ( aNewValue.getLength() > 0 ) + { + if ( aNewValue != m_aProps.aTitle ) + { + osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex ); + m_aProps.aTitle = aNewValue; + + // modified title -> modified URL -> exchange ! + if ( m_eState == PERSISTENT ) + bExchange = sal_True; + + aGuard.clear(); + + aEvent.PropertyName = rValue.Name; + aEvent.OldValue = makeAny( m_aProps.aTitle ); + aEvent.NewValue = makeAny( aNewValue ); + + aChanges.getArray()[ nChanged ] = aEvent; + nChanged++; + } + } + } + } + else if ( rValue.Name.compareToAscii( "TargetURL" ) == 0 ) + { + // TargetURL is only supported by links. + + if ( m_eKind == LINK ) + { + OUString aNewValue; + if ( rValue.Value >>= aNewValue ) + { + // No empty target URL's! + if ( aNewValue.getLength() > 0 ) + { + if ( aNewValue != m_aProps.aTargetURL ) + { + osl::ClearableGuard< osl::Mutex > aGuard( + m_aMutex ); + m_aProps.aTargetURL = aNewValue; + aGuard.clear(); + + aEvent.PropertyName = rValue.Name; + aEvent.OldValue = makeAny( m_aProps.aTargetURL ); + aEvent.NewValue = makeAny( aNewValue ); + + aChanges.getArray()[ nChanged ] = aEvent; + nChanged++; + } + } + } + } + } + else + { + // Not a Core Property! Maybe it's an Additional Core Property?! + + if ( !bTriedToGetAdditonalPropSet && !xAdditionalPropSet.is() ) + { + xAdditionalPropSet = getAdditionalPropertySet( sal_False ); + bTriedToGetAdditonalPropSet = sal_True; + } + + if ( xAdditionalPropSet.is() ) + { + try + { + Any aOldValue = xAdditionalPropSet->getPropertyValue( + rValue.Name ); + xAdditionalPropSet->setPropertyValue( + rValue.Name, rValue.Value ); + + if ( aOldValue != rValue.Value ) + { + aEvent.PropertyName = rValue.Name; + aEvent.OldValue = aOldValue; + aEvent.NewValue = rValue.Value; + + aChanges.getArray()[ nChanged ] = aEvent; + nChanged++; + } + } + catch ( UnknownPropertyException ) + { + } + catch ( WrappedTargetException ) + { + } + catch ( PropertyVetoException ) + { + } + catch ( IllegalArgumentException ) + { + } + } + } + } + + // @@@ What, if exchange fails??? Rollback of Title prop? Old title is + // contained in aChanges... + if ( bExchange ) + { + Reference< XContentIdentifier > xOldId = m_xIdentifier; + Reference< XContentIdentifier > xNewId = getIdentifierFromTitle(); + + if ( exchangeIdentity( xNewId ) ) + { + // Adapt persistent data. + renameData( xOldId, xNewId ); + + // Adapt Additional Core Properties. + renameAdditionalPropertySet( + xOldId->getContentIdentifier(), + xNewId->getContentIdentifier(), + sal_True ); + } + } + + if ( nChanged > 0 ) + { + // Save changes, if content was already made persistent. + if ( m_eState == PERSISTENT ) + storeData(); + + aGuard.clear(); + aChanges.realloc( nChanged ); + notifyPropertiesChange( aChanges ); + } +} + +//========================================================================= +void HierarchyContent::insert( sal_Int32 nNameClashResolve ) + throw( CommandAbortedException ) +{ + osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex ); + + // Transient? + if ( m_eState != TRANSIENT ) + { + VOS_ENSURE( sal_False, "HierarchyContent::insert - Not transient!" ); + throw CommandAbortedException(); + } + + // Am I the root folder? + if ( m_eKind == ROOT ) + { + VOS_ENSURE( sal_False, "HierarchyContent::insert - " + "Not supported by root folder!" ); + throw CommandAbortedException(); + } + + // Check, if all required properties were set. + if ( m_aProps.aTitle.getLength() == 0 ) + { + VOS_ENSURE( sal_False, "HierarchyContent::insert - No Title!" ); + throw CommandAbortedException(); + } + + // Assemble new content identifier... + + Reference< XContentIdentifier > xId = getIdentifierFromTitle(); + if ( !xId.is() ) + throw CommandAbortedException(); + + if ( hasData( xId ) ) + { + // Handle name clash... + + switch ( nNameClashResolve ) + { + // fail. + case NameClash::ERROR: + throw CommandAbortedException(); + + // replace existing object. + case NameClash::OVERWRITE: + break; + + // "invent" a new valid title. + case NameClash::RENAME: + { + sal_Int32 nTry = 0; + + do + { + OUString aNewId = xId->getContentIdentifier(); + aNewId += OUString::createFromAscii( "_" ); + aNewId += OUString::valueOf( ++nTry ); + xId = new ::ucb::ContentIdentifier( m_xSMgr, aNewId ); + } + while ( hasData( xId ) && ( nTry < 100000 ) ); + + if ( nTry == 100000 ) + { + VOS_ENSURE( sal_False, + "HierarchyContent::insert - " + "Unable to resolve name clash" ); + throw CommandAbortedException(); + } + else + { + m_aProps.aTitle += OUString::createFromAscii( "_" ); + m_aProps.aTitle += OUString::valueOf( nTry ); + } + break; + } + + // keep existing sub-objects, transfer non-clashing sub-objects. + case NameClash::KEEP: + // @@@ + + default: + throw CommandAbortedException(); + } + } + + m_xIdentifier = xId; + + if ( !storeData() ) + throw CommandAbortedException(); + + m_eState = PERSISTENT; + + aGuard.clear(); + inserted(); +} + +//========================================================================= +void HierarchyContent::destroy( sal_Bool bDeletePhysical ) + throw( CommandAbortedException ) +{ + // @@@ take care about bDeletePhysical -> trashcan support + + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + + Reference< XContent > xThis = this; + + // Persistent? + if ( m_eState != PERSISTENT ) + { + VOS_ENSURE( sal_False, "HierarchyContent::destroy - Not persistent!" ); + throw CommandAbortedException(); + } + + // Am I the root folder? + if ( m_eKind == ROOT ) + { + VOS_ENSURE( sal_False, "HierarchyContent::destroy - " + "Not supported by root folder!" ); + throw CommandAbortedException(); + } + + m_eState = DEAD; + deleted(); + + if ( m_eKind == FOLDER ) + { + // Process instanciated children... + + HierarchyContentRefList aChildren; + queryChildren( aChildren ); + + HierarchyContentRefList::const_iterator it = aChildren.begin(); + HierarchyContentRefList::const_iterator end = aChildren.end(); + + while ( it != end ) + { + (*it)->destroy( bDeletePhysical ); + ++it; + } + } +} + +//========================================================================= +void HierarchyContent::transfer( const TransferInfo& rInfo ) + throw( CommandAbortedException ) +{ + osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex ); + + // Persistent? + if ( m_eState != PERSISTENT ) + { + VOS_ENSURE( sal_False, "HierarchyContent::transfer - Not persistent!" ); + throw CommandAbortedException(); + } + + if ( rInfo.SourceURL.getLength() == 0 ) + throw CommandAbortedException(); + + // Is source a hierarchy content? + if ( rInfo.SourceURL.compareToAscii( + HIERARCHY_ROOT_FOLDER_URL, HIERARCHY_ROOT_FOLDER_URL_LENGTH ) != 0 ) + throw CommandAbortedException(); + + // Is source not a parent of me / not me? + OUString aId = m_xIdentifier->getContentIdentifier(); + sal_Int32 nPos = aId.lastIndexOf( '/' ); + if ( nPos != ( aId.getLength() - 1 ) ) + { + // No trailing slash found. Append. + aId += OUString::createFromAscii( "/" ); + } + + if ( rInfo.SourceURL.getLength() <= aId.getLength() ) + { + if ( aId.compareTo( + rInfo.SourceURL, rInfo.SourceURL.getLength() ) == 0 ) + throw CommandAbortedException(); + } + + try + { + ////////////////////////////////////////////////////////////////// + // 0) Obtain content object for source. + ////////////////////////////////////////////////////////////////// + + Reference< XContentIdentifier > xId = + new ::ucb::ContentIdentifier( m_xSMgr, rInfo.SourceURL ); + + // Note: The static cast is okay here, because its sure that + // m_xProvider is always the HierarchyContentProvider. + vos::ORef< HierarchyContent > xSource + = static_cast< HierarchyContent * >( + m_xProvider->queryContent( xId ).get() ); + if ( !xSource.isValid() ) + throw CommandAbortedException(); + + ////////////////////////////////////////////////////////////////// + // 1) Create new child content. + ////////////////////////////////////////////////////////////////// + + OUString aType = xSource->isFolder() + ? OUString::createFromAscii( + HIERARCHY_FOLDER_CONTENT_TYPE ) + : OUString::createFromAscii( + HIERARCHY_LINK_CONTENT_TYPE ); + ContentInfo aInfo; + aInfo.Type = aType; + aInfo.Attributes = 0; + + // Note: The static cast is okay here, because its sure that + // createNewContent always creates a HierarchyContent. + vos::ORef< HierarchyContent > xTarget + = static_cast< HierarchyContent * >( + createNewContent( aInfo ).get() ); + if ( !xTarget.isValid() ) + throw CommandAbortedException(); + + ////////////////////////////////////////////////////////////////// + // 2) Copy data from source content to child content. + ////////////////////////////////////////////////////////////////// + + Sequence< Property > aProps + = xSource->getPropertySetInfo()->getProperties(); + sal_Int32 nCount = aProps.getLength(); + + if ( nCount ) + { + sal_Bool bHadTitle = ( rInfo.NewTitle.getLength() == 0 ); + + // Get all source values. + Reference< XRow > xRow = xSource->getPropertyValues( aProps ); + + Sequence< PropertyValue > aValues( nCount ); + PropertyValue* pValues = aValues.getArray(); + + const Property* pProps = aProps.getConstArray(); + for ( sal_Int32 n = 0; n < nCount; ++n ) + { + const Property& rProp = pProps[ n ]; + PropertyValue& rValue = pValues[ n ]; + + rValue.Name = rProp.Name; + rValue.Handle = rProp.Handle; + + if ( !bHadTitle && rProp.Name.compareToAscii( "Title" ) == 0 ) + { + // Set new title instead of original. + bHadTitle = sal_True; + rValue.Value <<= rInfo.NewTitle; + } + else + rValue.Value + = xRow->getObject( n + 1, Reference< XNameAccess >() ); + + rValue.State = PropertyState_DIRECT_VALUE; + + if ( rProp.Attributes & PropertyAttribute::REMOVABLE ) + { + // Add Additional Core Property. + try + { + xTarget->addProperty( rProp.Name, + rProp.Attributes, + rValue.Value ); + } + catch ( PropertyExistException & ) + { + } + catch ( IllegalTypeException & ) + { + } + catch ( IllegalArgumentException & ) + { + } + } + } + + // Set target values. + xTarget->setPropertyValues( aValues ); + } + + ////////////////////////////////////////////////////////////////// + // 3) Commit (insert) child. + ////////////////////////////////////////////////////////////////// + + xTarget->insert( rInfo.NameClash ); + + ////////////////////////////////////////////////////////////////// + // 4) Transfer (copy) children of source. + ////////////////////////////////////////////////////////////////// + + if ( xSource->isFolder() ) + { + HierarchyEntry aFolder( m_xSMgr, xId->getContentIdentifier() ); + HierarchyEntry::iterator it; + + while ( aFolder.next( it ) ) + { + const HierarchyEntryData& rResult = *it; + + OUString aChildId = xId->getContentIdentifier(); + if ( ( aChildId.lastIndexOf( '/' ) + 1 ) + != aChildId.getLength() ) + aChildId += OUString::createFromAscii( "/" ); + + aChildId += HierarchyContentProvider::encodeSegment( + rResult.aTitle ); + + Reference< XContentIdentifier > xChildId + = new ::ucb::ContentIdentifier( m_xSMgr, aChildId ); + + vos::ORef< HierarchyContent > xChild + = static_cast< HierarchyContent * >( + m_xProvider->queryContent( xChildId ).get() ); + + TransferInfo aInfo; + aInfo.MoveData = sal_False; + aInfo.NewTitle = OUString(); + aInfo.SourceURL = aChildId; + aInfo.NameClash = rInfo.NameClash; + + // Transfer child to target. + xTarget->transfer( aInfo ); + } + } + + ////////////////////////////////////////////////////////////////// + // 5) Destroy source ( when moving only ) . + ////////////////////////////////////////////////////////////////// + + if ( rInfo.MoveData ) + { + xSource->destroy( sal_True ); + + // Remove all persistent data of source and its children. + xSource->removeData(); + + // Remove own and all children's Additional Core Properties. + xSource->removeAdditionalPropertySet( sal_True ); + } + } + catch ( IllegalIdentifierException & ) + { + // queryContent + VOS_ENSURE( sal_False, "HierarchyContent::transfer - " + "Caught IllegalIdentifierException!" ); + throw CommandAbortedException(); + } +} + diff --git a/ucb/source/ucp/hierarchy/hierarchycontent.hxx b/ucb/source/ucp/hierarchy/hierarchycontent.hxx new file mode 100644 index 000000000000..abe02413022e --- /dev/null +++ b/ucb/source/ucp/hierarchy/hierarchycontent.hxx @@ -0,0 +1,299 @@ +/************************************************************************* + * + * $RCSfile: hierarchycontent.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:54:18 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _HIERARCHYCONTENT_HXX +#define _HIERARCHYCONTENT_HXX + +#ifndef __LIST__ +#include <stl/list> +#endif +#ifndef _COM_SUN_STAR_UCB_XCONTENTCREATOR_HPP_ +#include <com/sun/star/ucb/XContentCreator.hpp> +#endif +#ifndef _VOS_REF_HXX_ +#include <vos/ref.hxx> +#endif + +#ifndef _UCBHELPER_CONTENTHELPER_HXX +#include <ucbhelper/contenthelper.hxx> +#endif + +#ifndef _HIERARCHYDATA_HXX +#include "hierarchydata.hxx" +#endif + +namespace com { namespace sun { namespace star { namespace beans { + struct Property; + struct PropertyValue; +} } } } + +namespace com { namespace sun { namespace star { namespace sdbc { + class XRow; +} } } } + +namespace com { namespace sun { namespace star { namespace ucb { + struct TransferInfo; +} } } } + +namespace hierarchy_ucp +{ + +//========================================================================= + +#define HIERARCHY_ROOT_FOLDER_CONTENT_SERVICE_NAME \ + "com.sun.star.ucb.HierarchyRootFolderContent" +#define HIERARCHY_FOLDER_CONTENT_SERVICE_NAME \ + "com.sun.star.ucb.HierarchyFolderContent" +#define HIERARCHY_LINK_CONTENT_SERVICE_NAME \ + "com.sun.star.ucb.HierarchyLinkContent" + +//========================================================================= + +struct HierarchyContentProperties : HierarchyEntryData +{ + ::rtl::OUString aContentType; // ContentType + sal_Bool bIsDocument; // IsDocument + sal_Bool bIsFolder; // IsFolder + + HierarchyContentProperties() + : bIsDocument( sal_False ), bIsFolder( sal_True ) {} +}; + +//========================================================================= + +class HierarchyContent : public ::ucb::ContentImplHelper, + public com::sun::star::ucb::XContentCreator +{ + enum ContentKind { LINK, FOLDER, ROOT }; + enum ContentState { TRANSIENT, // created via CreateNewContent, + // but did not process "insert" yet + PERSISTENT, // processed "insert" + DEAD // processed "delete" + }; + + HierarchyContentProperties m_aProps; + ContentKind m_eKind; + ContentState m_eState; + +private: + HierarchyContent( + const com::sun::star::uno::Reference< + com::sun::star::lang::XMultiServiceFactory >& rxSMgr, + ::ucb::ContentProviderImplHelper* pProvider, + const com::sun::star::uno::Reference< + com::sun::star::ucb::XContentIdentifier >& Identifier, + const HierarchyContentProperties& rProps ); + HierarchyContent( + const com::sun::star::uno::Reference< + com::sun::star::lang::XMultiServiceFactory >& rxSMgr, + ::ucb::ContentProviderImplHelper* pProvider, + const com::sun::star::uno::Reference< + com::sun::star::ucb::XContentIdentifier >& Identifier, + const com::sun::star::ucb::ContentInfo& Info ); + + virtual const ::ucb::PropertyInfoTableEntry& getPropertyInfoTable(); + virtual const ::ucb::CommandInfoTableEntry& getCommandInfoTable(); + virtual ::rtl::OUString getParentURL(); + + static sal_Bool hasData( + const com::sun::star::uno::Reference< + com::sun::star::lang::XMultiServiceFactory >& rxSMgr, + const com::sun::star::uno::Reference< + com::sun::star::ucb::XContentIdentifier >& Identifier ); + sal_Bool hasData( + const com::sun::star::uno::Reference< + com::sun::star::ucb::XContentIdentifier >& Identifier ) + { return hasData( m_xSMgr, Identifier ); } + static sal_Bool loadData( + const com::sun::star::uno::Reference< + com::sun::star::lang::XMultiServiceFactory >& rxSMgr, + const com::sun::star::uno::Reference< + com::sun::star::ucb::XContentIdentifier >& Identifier, + HierarchyContentProperties& rProps ); + sal_Bool storeData(); + sal_Bool renameData( const com::sun::star::uno::Reference< + com::sun::star::ucb::XContentIdentifier >& xOldId, + const com::sun::star::uno::Reference< + com::sun::star::ucb::XContentIdentifier >& xNewId ); + sal_Bool removeData(); + + void setKind( const com::sun::star::uno::Reference< + com::sun::star::ucb::XContentIdentifier >& Identifier ); + + sal_Bool isFolder() const { return ( m_eKind > LINK ); } + + ::com::sun::star::uno::Reference< + ::com::sun::star::ucb::XContentIdentifier > + getIdentifierFromTitle(); + + typedef vos::ORef< HierarchyContent > HierarchyContentRef; + typedef std::list< HierarchyContentRef > HierarchyContentRefList; + void queryChildren( HierarchyContentRefList& rChildren ); + + sal_Bool exchangeIdentity( + const ::com::sun::star::uno::Reference< + ::com::sun::star::ucb::XContentIdentifier >& xNewId ); + + ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow > + getPropertyValues( const ::com::sun::star::uno::Sequence< + ::com::sun::star::beans::Property >& rProperties ); + void setPropertyValues( + const ::com::sun::star::uno::Sequence< + ::com::sun::star::beans::PropertyValue >& rValues ); + + void insert( sal_Int32 nNameClashResolve ) + throw( ::com::sun::star::ucb::CommandAbortedException ); + + void destroy( sal_Bool bDeletePhysical ) + throw( ::com::sun::star::ucb::CommandAbortedException ); + + void HierarchyContent::transfer( + const ::com::sun::star::ucb::TransferInfo& rInfo ) + throw( ::com::sun::star::ucb::CommandAbortedException ); + +public: + // Create existing content. Fail, if not already exists. + static HierarchyContent* create( + const com::sun::star::uno::Reference< + com::sun::star::lang::XMultiServiceFactory >& rxSMgr, + ::ucb::ContentProviderImplHelper* pProvider, + const com::sun::star::uno::Reference< + com::sun::star::ucb::XContentIdentifier >& Identifier ); + + // Create new content. Fail, if already exists. + static HierarchyContent* create( + const com::sun::star::uno::Reference< + com::sun::star::lang::XMultiServiceFactory >& rxSMgr, + ::ucb::ContentProviderImplHelper* pProvider, + const com::sun::star::uno::Reference< + com::sun::star::ucb::XContentIdentifier >& Identifier, + const com::sun::star::ucb::ContentInfo& Info ); + + virtual ~HierarchyContent(); + + // XInterface + XINTERFACE_DECL() + + // XTypeProvider + XTYPEPROVIDER_DECL() + + // XServiceInfo + virtual ::rtl::OUString SAL_CALL + getImplementationName() + throw( ::com::sun::star::uno::RuntimeException ); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL + getSupportedServiceNames() + throw( ::com::sun::star::uno::RuntimeException ); + + // XContent + virtual rtl::OUString SAL_CALL + getContentType() + throw( com::sun::star::uno::RuntimeException ); + virtual com::sun::star::uno::Reference< + com::sun::star::ucb::XContentIdentifier > SAL_CALL + getIdentifier() + throw( com::sun::star::uno::RuntimeException ); + + // XCommandProcessor + virtual com::sun::star::uno::Any SAL_CALL + execute( const com::sun::star::ucb::Command& aCommand, + sal_Int32 CommandId, + const com::sun::star::uno::Reference< + com::sun::star::ucb::XCommandEnvironment >& Environment ) + throw( com::sun::star::uno::Exception, + com::sun::star::ucb::CommandAbortedException, + com::sun::star::uno::RuntimeException ); + virtual void SAL_CALL + abort( sal_Int32 CommandId ) + throw( com::sun::star::uno::RuntimeException ); + + ////////////////////////////////////////////////////////////////////// + // Additional interfaces + ////////////////////////////////////////////////////////////////////// + + // XContentCreator + virtual com::sun::star::uno::Sequence< + com::sun::star::ucb::ContentInfo > SAL_CALL + queryCreatableContentsInfo() + throw( com::sun::star::uno::RuntimeException ); + virtual com::sun::star::uno::Reference< + com::sun::star::ucb::XContent > SAL_CALL + createNewContent( const com::sun::star::ucb::ContentInfo& Info ) + throw( com::sun::star::uno::RuntimeException ); + + ////////////////////////////////////////////////////////////////////// + // Non-interface methods. + ////////////////////////////////////////////////////////////////////// + + static ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow > + getPropertyValues( const ::com::sun::star::uno::Reference< + ::com::sun::star::lang::XMultiServiceFactory >& rSMgr, + const ::com::sun::star::uno::Sequence< + ::com::sun::star::beans::Property >& rProperties, + const HierarchyContentProperties& rData, + const ::vos::ORef< ::ucb::ContentProviderImplHelper >& + rProvider, + const ::rtl::OUString& rContentId ); +}; + +} // namespace hierarchy_ucp + +#endif /* !_HIERARCHYCONTENT_HXX */ diff --git a/ucb/source/ucp/hierarchy/hierarchycontentcaps.cxx b/ucb/source/ucp/hierarchy/hierarchycontentcaps.cxx new file mode 100644 index 000000000000..de58ffe2291a --- /dev/null +++ b/ucb/source/ucp/hierarchy/hierarchycontentcaps.cxx @@ -0,0 +1,509 @@ +/************************************************************************* + * + * $RCSfile: hierarchycontentcaps.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:54:18 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +/************************************************************************** + TODO + ************************************************************************** + + ************************************************************************** + + Props/Commands: + + root folder folder link link + (new) (new) + ---------------------------------------------------------------- + ContentType x x x x x + IsDocument x x x x x + IsFolder x x x x x + Title x x x x x + TargetURL x x + + getCommandInfo x x x x x + getPropertySetInfo x x x x x + getPropertyValues x x x x x + setPropertyValues x x x x x + insert x x + delete x x + open x x + transfer x x + + *************************************************************************/ + +#ifndef _COM_SUN_STAR_BEANS_PROPERTY_HPP_ +#include <com/sun/star/beans/Property.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HPP_ +#include <com/sun/star/beans/PropertyAttribute.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_ +#include <com/sun/star/beans/PropertyValue.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_OPENCOMMANDARGUMENT2_HPP_ +#include <com/sun/star/ucb/OpenCommandArgument2.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_TRANSFERINFO_HPP_ +#include <com/sun/star/ucb/TransferInfo.hpp> +#endif +#ifndef _COM_SUN_STAR_UNO_SEQUENCE_HXX_ +#include <com/sun/star/uno/Sequence.hxx> +#endif + +#ifndef _HIERARCHYCONTENT_HXX +#include "hierarchycontent.hxx" +#endif + +using namespace com::sun::star::beans; +using namespace com::sun::star::uno; +using namespace com::sun::star::ucb; +using namespace hierarchy_ucp; +using namespace rtl; + +//========================================================================= +// +// HierarchyContent implementation. +// +//========================================================================= + +//========================================================================= +// +// IMPORTENT: If any property data ( name / type / ... ) are changed, then +// HierarchyContent::getPropertyValues(...) must be adapted too! +// +//========================================================================= + +// virtual +const ::ucb::PropertyInfoTableEntry& + HierarchyContent::getPropertyInfoTable() +{ + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + + if ( m_eKind == LINK ) + { + //================================================================= + // + // Link: Supported properties + // + //================================================================= + + static ::ucb::PropertyInfoTableEntry aLinkPropertyInfoTable[] = + { + /////////////////////////////////////////////////////////////// + // Required properties + /////////////////////////////////////////////////////////////// + { + "ContentType", + -1, + &getCppuType( static_cast< const OUString * >( 0 ) ), + PropertyAttribute::BOUND | PropertyAttribute::READONLY + }, + { + "IsDocument", + -1, + &getCppuBooleanType(), + PropertyAttribute::BOUND | PropertyAttribute::READONLY + }, + { + "IsFolder", + -1, + &getCppuBooleanType(), + PropertyAttribute::BOUND | PropertyAttribute::READONLY + }, + { + "Title", + -1, + &getCppuType( static_cast< const OUString * >( 0 ) ), + PropertyAttribute::BOUND + }, + /////////////////////////////////////////////////////////////// + // Optional standard properties + /////////////////////////////////////////////////////////////// + { + "TargetURL", + -1, + &getCppuType( static_cast< const OUString * >( 0 ) ), + PropertyAttribute::BOUND + }, + /////////////////////////////////////////////////////////////// + // New properties + /////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////// + // EOT + /////////////////////////////////////////////////////////////// + { + 0, // name + 0, // handle + 0, // type + 0 // attributes + } + }; + return *aLinkPropertyInfoTable; + } + else if ( m_eKind == FOLDER ) + { + //================================================================= + // + // Folder: Supported properties + // + //================================================================= + + static ::ucb::PropertyInfoTableEntry aFolderPropertyInfoTable[] = + { + /////////////////////////////////////////////////////////////// + // Required properties + /////////////////////////////////////////////////////////////// + { + "ContentType", + -1, + &getCppuType( static_cast< const OUString * >( 0 ) ), + PropertyAttribute::BOUND | PropertyAttribute::READONLY + }, + { + "IsDocument", + -1, + &getCppuBooleanType(), + PropertyAttribute::BOUND | PropertyAttribute::READONLY + }, + { + "IsFolder", + -1, + &getCppuBooleanType(), + PropertyAttribute::BOUND | PropertyAttribute::READONLY + }, + { + "Title", + -1, + &getCppuType( static_cast< const OUString * >( 0 ) ), + PropertyAttribute::BOUND + }, + /////////////////////////////////////////////////////////////// + // Optional standard properties + /////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////// + // New properties + /////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////// + // EOT + /////////////////////////////////////////////////////////////// + { + 0, // name + 0, // handle + 0, // type + 0 // attributes + } + }; + return *aFolderPropertyInfoTable; + } + else + { + //================================================================= + // + // Root Folder: Supported properties + // + //================================================================= + + static ::ucb::PropertyInfoTableEntry aRootFolderPropertyInfoTable[] = + { + /////////////////////////////////////////////////////////////// + // Required properties + /////////////////////////////////////////////////////////////// + { + "ContentType", + -1, + &getCppuType( static_cast< const OUString * >( 0 ) ), + PropertyAttribute::BOUND | PropertyAttribute::READONLY + }, + { + "IsDocument", + -1, + &getCppuBooleanType(), + PropertyAttribute::BOUND | PropertyAttribute::READONLY + }, + { + "IsFolder", + -1, + &getCppuBooleanType(), + PropertyAttribute::BOUND | PropertyAttribute::READONLY + }, + { + "Title", + -1, + &getCppuType( static_cast< const OUString * >( 0 ) ), + PropertyAttribute::BOUND | PropertyAttribute::READONLY + }, + /////////////////////////////////////////////////////////////// + // Optional standard properties + /////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////// + // New properties + /////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////// + // EOT + /////////////////////////////////////////////////////////////// + { + 0, // name + 0, // handle + 0, // type + 0 // attributes + } + }; + return *aRootFolderPropertyInfoTable; + } +} + +//========================================================================= +// virtual +const ::ucb::CommandInfoTableEntry& + HierarchyContent::getCommandInfoTable() +{ + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + + if ( m_eKind == LINK ) + { + //================================================================= + // + // Link: Supported commands + // + //================================================================= + + static ::ucb::CommandInfoTableEntry aLinkCommandInfoTable[] = + { + /////////////////////////////////////////////////////////////// + // Required commands + /////////////////////////////////////////////////////////////// + { + "getCommandInfo", + -1, + &getCppuVoidType() + }, + { + "getPropertySetInfo", + -1, + &getCppuVoidType() + }, + { + "getPropertyValues", + -1, + &getCppuType( static_cast< Sequence< Property > * >( 0 ) ) + }, + { + "setPropertyValues", + -1, + &getCppuType( static_cast< Sequence< PropertyValue > * >( 0 ) ) + }, + /////////////////////////////////////////////////////////////// + // Optional standard commands + /////////////////////////////////////////////////////////////// + { + "delete", + -1, + &getCppuBooleanType() + }, + { + "insert", + -1, + &getCppuVoidType() + }, + /////////////////////////////////////////////////////////////// + // New commands + /////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////// + // EOT + /////////////////////////////////////////////////////////////// + { + 0, // name + 0, // handle + 0 // type + } + }; + return *aLinkCommandInfoTable; + } + else if ( m_eKind == FOLDER ) + { + //================================================================= + // + // Folder: Supported commands + // + //================================================================= + + static ::ucb::CommandInfoTableEntry aFolderCommandInfoTable[] = + { + /////////////////////////////////////////////////////////////// + // Required commands + /////////////////////////////////////////////////////////////// + { + "getCommandInfo", + -1, + &getCppuVoidType() + }, + { + "getPropertySetInfo", + -1, + &getCppuVoidType() + }, + { + "getPropertyValues", + -1, + &getCppuType( static_cast< Sequence< Property > * >( 0 ) ) + }, + { + "setPropertyValues", + -1, + &getCppuType( static_cast< Sequence< PropertyValue > * >( 0 ) ) + }, + /////////////////////////////////////////////////////////////// + // Optional standard commands + /////////////////////////////////////////////////////////////// + { + "delete", + -1, + &getCppuBooleanType() + }, + { + "insert", + -1, + &getCppuVoidType() + }, + { + "open", + -1, + &getCppuType( static_cast< OpenCommandArgument2 * >( 0 ) ) + }, + { + "transfer", + -1, + &getCppuType( static_cast< TransferInfo * >( 0 ) ) + }, + /////////////////////////////////////////////////////////////// + // New commands + /////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////// + // EOT + /////////////////////////////////////////////////////////////// + { + 0, // name + 0, // handle + 0 // type + } + }; + return *aFolderCommandInfoTable; + } + else + { + //================================================================= + // + // Root Folder: Supported commands + // + //================================================================= + + static ::ucb::CommandInfoTableEntry aRootFolderCommandInfoTable[] = + { + /////////////////////////////////////////////////////////////// + // Required commands + /////////////////////////////////////////////////////////////// + { + "getCommandInfo", + -1, + &getCppuVoidType() + }, + { + "getPropertySetInfo", + -1, + &getCppuVoidType() + }, + { + "getPropertyValues", + -1, + &getCppuType( static_cast< Sequence< Property > * >( 0 ) ) + }, + { + "setPropertyValues", + -1, + &getCppuType( static_cast< Sequence< PropertyValue > * >( 0 ) ) + }, + /////////////////////////////////////////////////////////////// + // Optional standard commands + /////////////////////////////////////////////////////////////// + { + "open", + -1, + &getCppuType( static_cast< OpenCommandArgument2 * >( 0 ) ) + }, + { + "transfer", + -1, + &getCppuType( static_cast< TransferInfo * >( 0 ) ) + }, + /////////////////////////////////////////////////////////////// + // New commands + /////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////// + // EOT + /////////////////////////////////////////////////////////////// + { + 0, // name + 0, // handle + 0 // type + } + }; + return *aRootFolderCommandInfoTable; + } +} + diff --git a/ucb/source/ucp/hierarchy/hierarchydata.cxx b/ucb/source/ucp/hierarchy/hierarchydata.cxx new file mode 100644 index 000000000000..012efbaf254a --- /dev/null +++ b/ucb/source/ucp/hierarchy/hierarchydata.cxx @@ -0,0 +1,1129 @@ +/************************************************************************* + * + * $RCSfile: hierarchydata.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:54:18 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +/************************************************************************** + TODO + ************************************************************************** + + - HierarchyEntry::move + --> Umstellen auf Benutzung von XNamed ( wenn es von config db api + unterstuetzt wird ). + + *************************************************************************/ + +#ifndef _HIERARCHYDATA_HXX +#include "hierarchydata.hxx" +#endif + +#ifndef __VECTOR__ +#include <stl/vector> +#endif + +#ifndef _COM_SUN_STAR_CONTAINER_XHIERARCHICALNAMEACCESS_HPP_ +#include <com/sun/star/container/XHierarchicalNameAccess.hpp> +#endif +#ifndef _COM_SUN_STAR_CONTAINER_XNAMECONTAINER_HPP_ +#include <com/sun/star/container/XNameContainer.hpp> +#endif +#ifndef _COM_SUN_STAR_CONTAINER_XNAMEREPLACE_HPP_ +#include <com/sun/star/container/XNameReplace.hpp> +#endif +#ifndef _COM_SUN_STAR_UTIL_XCHANGESBATCH_HPP_ +#include <com/sun/star/util/XChangesBatch.hpp> +#endif +#ifndef _COM_SUN_STAR_UTIL_XSTRINGESCAPE_HPP_ +#include <com/sun/star/util/XStringEscape.hpp> +#endif +#ifndef _VOS_DIAGNOSE_HXX_ +#include <vos/diagnose.hxx> +#endif +#ifndef _HIERARCHYPROVIDER_HXX +#include "hierarchyprovider.hxx" +#endif + +using namespace com::sun::star::container; +using namespace com::sun::star::util; +using namespace com::sun::star::lang; +using namespace com::sun::star::uno; +using namespace rtl; +using namespace hierarchy_ucp; + +namespace hierarchy_ucp +{ + +struct HierarchyEntry::iterator_Impl +{ + HierarchyEntryData entry; + Reference< XHierarchicalNameAccess > dir; + Sequence< OUString> names; + sal_Int32 pos; + + iterator_Impl() : pos( -1 /* before first */ ) {}; +}; + +} // hierarchy_ucp + +//========================================================================= +//========================================================================= +// +// HierarchyEntry Implementation. +// +//========================================================================= +//========================================================================= + +#if SUPD>604 + +#define HIERARCHY_ROOT_DB_KEY "/org.openoffice.ucb.Hierarchy/Root" +#define HIERARCHY_ROOT_DB_KEY_LENGTH 34 + +#else + +#define HIERARCHY_ROOT_DB_KEY "/com.sun.star.ucb.Hierarchy/Root" +#define HIERARCHY_ROOT_DB_KEY_LENGTH 32 + +#endif + +//========================================================================= +HierarchyEntry::HierarchyEntry( const Reference< XMultiServiceFactory >& rSMgr, + const OUString& rURL ) +: m_xSMgr( rSMgr ) +{ + // Note: do not init m_aPath init list. createPathFromHierarchyURL + // needs m_xSMgr and m_aMutex. + m_aPath = createPathFromHierarchyURL( rURL ); +} + +//========================================================================= +sal_Bool HierarchyEntry::hasData() +{ + try + { + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + + if ( !m_xConfigProvider.is() ) + m_xConfigProvider = Reference< XMultiServiceFactory >( + m_xSMgr->createInstance( + OUString::createFromAscii( + "com.sun.star.configuration.ConfigurationProvider" ) ), + UNO_QUERY ); + + if ( m_xConfigProvider.is() ) + { + // Create Root object. + + Sequence< Any > aArguments( 1 ); + aArguments[ 0 ] + <<= OUString::createFromAscii( HIERARCHY_ROOT_DB_KEY ); + + Reference< XHierarchicalNameAccess > xRootHierAccess( + m_xConfigProvider->createInstanceWithArguments( + OUString::createFromAscii( + "com.sun.star.configuration.ConfigurationAccess" ), + aArguments ), + UNO_QUERY ); + + VOS_ENSURE( xRootHierAccess.is(), + "HierarchyEntry::hasData - No root!" ); + + if ( xRootHierAccess.is() ) + return xRootHierAccess->hasByHierarchicalName( m_aPath ); + } + } + catch ( RuntimeException& ) + { + throw; + } + catch ( Exception& ) + { + // createInstance, createInstanceWithArguments + + VOS_ENSURE( sal_False, + "HierarchyEntry::hasData - caught Exception!" ); + } + + return sal_False; +} + +//========================================================================= +sal_Bool HierarchyEntry::getData( Any& rTitle, + Any& rTargetURL, + sal_Bool bChildren, + Any& rChildren ) +{ + try + { + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + + if ( !m_xConfigProvider.is() ) + m_xConfigProvider = Reference< XMultiServiceFactory >( + m_xSMgr->createInstance( + OUString::createFromAscii( + "com.sun.star.configuration.ConfigurationProvider" ) ), + UNO_QUERY ); + + if ( m_xConfigProvider.is() ) + { + // Create Root object. + + Sequence< Any > aArguments( 1 ); + aArguments[ 0 ] + <<= OUString::createFromAscii( HIERARCHY_ROOT_DB_KEY ); + + Reference< XHierarchicalNameAccess > xRootHierAccess( + m_xConfigProvider->createInstanceWithArguments( + OUString::createFromAscii( + "com.sun.star.configuration.ConfigurationAccess" ), + aArguments ), + UNO_QUERY ); + + VOS_ENSURE( xRootHierAccess.is(), + "HierarchyEntry::getData - No root!" ); + + if ( xRootHierAccess.is() ) + { + OUString aTitlePath = m_aPath; + OUString aTargetURLPath = m_aPath; + OUString aChildrenPath = m_aPath; + + aTitlePath += OUString::createFromAscii( "/Title" ); + aTargetURLPath += OUString::createFromAscii( "/TargetURL" ); + aChildrenPath += OUString::createFromAscii( "/Children" ); + + // Get Title value. + rTitle + = xRootHierAccess->getByHierarchicalName( aTitlePath ); + + // Get TargetURL value. + rTargetURL + = xRootHierAccess->getByHierarchicalName( aTargetURLPath ); + + // Get Children value. + if ( bChildren ) + rChildren + = xRootHierAccess->getByHierarchicalName( + aChildrenPath ); + return sal_True; + } + } + } + catch ( RuntimeException& ) + { + throw; + } + catch ( NoSuchElementException& ) + { + // getByHierarchicalName + + VOS_ENSURE( sal_False, + "HierarchyEntry::getData - caught NoSuchElementException!" ); + } + catch ( Exception& ) + { + // createInstance, createInstanceWithArguments + + VOS_ENSURE( sal_False, + "HierarchyEntry::getData - caught Exception!" ); + } + return sal_False; +} + +//========================================================================= +sal_Bool HierarchyEntry::getData( HierarchyEntryData& rData ) +{ + Any aTitle; + Any aTargetURL; + if ( getData( aTitle, aTargetURL, sal_False, Any() ) ) + { + if ( ( aTitle >>= rData.aTitle ) + && ( aTargetURL >>= rData.aTargetURL ) ) + return sal_True; + } + return sal_False; +} + +//========================================================================= +sal_Bool HierarchyEntry::setData( const OUString& rOldPath, + const OUString& rPath, + const Any& rTitle, + const Any& rTargetURL, + sal_Bool bCreate, + sal_Bool bFailIfExists, + sal_Bool bChildren, + const Any& rChildren, + const Reference< XChangesBatch >& rxBatch, + const OUString& rBatchPath ) +{ + try + { + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + + if ( !m_xConfigProvider.is() ) + m_xConfigProvider = Reference< XMultiServiceFactory >( + m_xSMgr->createInstance( + OUString::createFromAscii( + "com.sun.star.configuration.ConfigurationProvider" ) ), + UNO_QUERY ); + + if ( m_xConfigProvider.is() ) + { + // Create parent's key. It must exist! + + OUString aParentPath + = OUString::createFromAscii( HIERARCHY_ROOT_DB_KEY ); + OUString aKey = rPath; + sal_Bool bRoot = sal_True; + + sal_Int32 nPos = rPath.lastIndexOf( '/' ); + if ( nPos != -1 ) + { + aKey = rPath.copy( nPos + 1 ); + + // Skip "/Children" segment of the path, too. + nPos = rPath.lastIndexOf( '/', nPos - 1 ); + + VOS_ENSURE( nPos != -1, + "HierarchyEntry::setData - Wrong path!" ); + + aParentPath += OUString::createFromAscii( "/" ); + aParentPath += rPath.copy( 0, nPos ); + bRoot = sal_False; + } + + OUString aBatchPath + = ( rBatchPath.getLength() > 0 ) ? rBatchPath : aParentPath; + + Reference< XChangesBatch > xBatch = rxBatch; + if ( !xBatch.is() ) + { + Sequence< Any > aArguments( 1 ); + aArguments[ 0 ] <<= aParentPath; + + xBatch = Reference< XChangesBatch >( + m_xConfigProvider->createInstanceWithArguments( + OUString::createFromAscii( + "com.sun.star.configuration.ConfigurationUpdateAccess" ), + aArguments ), + UNO_QUERY ); + } + + VOS_ENSURE( xBatch.is(), + "HierarchyEntry::setData - No batch!" ); + + Reference< XNameAccess > xParentNameAccess( xBatch, UNO_QUERY ); + + if ( rxBatch.is() ) + { + Reference< XHierarchicalNameAccess > xTmp( + xParentNameAccess, UNO_QUERY ); + + VOS_ENSURE( xTmp.is(), + "HierarchyEntry::setData - No hier name access!" ); + + if ( xTmp.is() ) + { + OUString aName = rPath.copy( + aBatchPath.getLength() + - HIERARCHY_ROOT_DB_KEY_LENGTH ); + sal_Int32 nPos1 = aName.lastIndexOf( '/' ); + if ( nPos1 != -1 ) + { + // Skip "/Children" segment of the path, too. + nPos1 = aName.lastIndexOf( '/', nPos1 - 1 ); + + VOS_ENSURE( nPos1 != -1, + "HierarchyEntry::setData - Wrong path!" ); + + aName = aName.replaceAt( nPos1, + aName.getLength() - nPos1, + OUString() ); + } + + xTmp->getByHierarchicalName( aName ) >>= xParentNameAccess; + } + } + + VOS_ENSURE( xParentNameAccess.is(), + "HierarchyEntry::setData - No name access!" ); + + if ( xBatch.is() && xParentNameAccess.is() ) + { + // Try to create own key. It must not exist! + + sal_Bool bExists = sal_True; + Any aMyKey; + + try + { + Reference< XNameAccess > xNameAccess; + + if ( bRoot ) + { + xNameAccess = xParentNameAccess; + } + else + { + xParentNameAccess->getByName( + OUString::createFromAscii( "Children" ) ) + >>= xNameAccess; + } + + if ( xNameAccess->hasByName( aKey ) ) + aMyKey = xNameAccess->getByName( aKey ); + else + bExists = sal_False; + } + catch ( NoSuchElementException& ) + { + bExists = sal_False; + } + + Reference< XNameReplace > xNameReplace; + Reference< XNameContainer > xContainer; + + if ( bExists ) + { + if ( bFailIfExists ) + return sal_False; + + // Key exists. Replace values. + + aMyKey >>= xNameReplace; + + VOS_ENSURE( xNameReplace.is(), + "HierarchyEntry::setData - No name replace!" ); + } + else + { + if ( !bCreate ) + return sal_True; + + // Key does not exist. Create / fill / insert it. + + Reference< XSingleServiceFactory > xFac; + + if ( bRoot ) + { + // Special handling for children of root, + // which is not an entry. It's only a set + // of entries. + xFac = Reference< XSingleServiceFactory >( + xParentNameAccess, UNO_QUERY ); + } + else + { + // Append new entry to parents child list, + // which is a set of entries. + xParentNameAccess->getByName( + OUString::createFromAscii( + "Children" ) ) >>= xFac; + } + + VOS_ENSURE( xFac.is(), + "HierarchyEntry::setData - No factory!" ); + + if ( xFac.is() ) + { + xNameReplace = Reference< XNameReplace >( + xFac->createInstance(), UNO_QUERY ); + + VOS_ENSURE( xNameReplace.is(), + "HierarchyEntry::setData - No name replace!" ); + + if ( xNameReplace.is() ) + { + xContainer = Reference< XNameContainer >( + xFac, UNO_QUERY ); + + VOS_ENSURE( xContainer.is(), + "HierarchyEntry::setData - No container!" ); + } + } + } + + if ( xNameReplace.is() ) + { + // Set Title value. + xNameReplace->replaceByName( + OUString::createFromAscii( "Title" ), + rTitle ); + + // Set TargetURL value. + xNameReplace->replaceByName( + OUString::createFromAscii( "TargetURL" ), + rTargetURL ); + + if ( xContainer.is() ) + xContainer->insertByName( + aKey, makeAny( xNameReplace ) ); + + // SEE BELOW! At the moment, each single change must be committed. + + // Commit changes. + xBatch->commitChanges(); + +#if 0 + // Doesn't work. According to FS possibly never will ... + + // Set Children, if given. + if ( bChildren ) + xNameReplace->replaceByName( + OUString::createFromAscii( "Children" ), + rChildren ); +#else + // Copy children manually :-( + + if ( bChildren && ( rOldPath.getLength() > 0 ) ) + { + Reference< XNameAccess > xChildrenNameAccess; + rChildren >>= xChildrenNameAccess; + + if ( xChildrenNameAccess.is() ) + { + Sequence< Any > aArguments( 1 ); + aArguments[ 0 ] + <<= OUString::createFromAscii( + HIERARCHY_ROOT_DB_KEY ); + + Reference< XHierarchicalNameAccess > + xRootHierAccess( + m_xConfigProvider->createInstanceWithArguments( + OUString::createFromAscii( + "com.sun.star.configuration.ConfigurationAccess" ), + aArguments ), + UNO_QUERY ); + + VOS_ENSURE( xRootHierAccess.is(), + "HierarchyEntry::getData - No root!" ); + + if ( xRootHierAccess.is() ) + { + Sequence< OUString >aElems + = xChildrenNameAccess->getElementNames(); + const OUString* pElems = aElems.getConstArray(); + sal_Int32 nCount = aElems.getLength(); + + if ( nCount > 0 ) + { + OUString aTitleKey = + OUString::createFromAscii( + "/Title" ); + OUString aTargetURLKey = + OUString::createFromAscii( + "/TargetURL" ); + OUString aChildrenKey = + OUString::createFromAscii( + "/Children" ); + + OUString aFullChildPath = rPath; + aFullChildPath += aChildrenKey; + aFullChildPath + += OUString::createFromAscii( "/" ); + + OUString aOldFullChildPath = rOldPath; + aOldFullChildPath += aChildrenKey; + aOldFullChildPath + += OUString::createFromAscii( "/" ); + + // Iterate over children. + for ( sal_Int32 n = 0; n < nCount; ++n ) + { + const OUString& rElem = pElems[ n ]; + + // Get data from old child... + + OUString aOldChildPath + = aOldFullChildPath; + aOldChildPath += rElem; + + OUString aTitle = aOldChildPath; + OUString aTargetURL = aOldChildPath; + OUString aChildren = aOldChildPath; + + aTitle += aTitleKey; + aTargetURL += aTargetURLKey; + aChildren += aChildrenKey; + + Any aTitleValue + = xRootHierAccess + ->getByHierarchicalName( + aTitle ); + + Any aTargetURLValue + = xRootHierAccess + ->getByHierarchicalName( + aTargetURL ); + Any aChildrenValue + = xRootHierAccess + ->getByHierarchicalName( + aChildren ); + + OUString aChildPath = aFullChildPath; + aChildPath += rElem; + + aOldChildPath = aOldFullChildPath; + aOldChildPath += rElem; + + // Recurse... + if ( !setData( aOldChildPath, + aChildPath, + aTitleValue, + aTargetURLValue, + sal_True, // create + sal_True, // fail, if exists + sal_True, // copy children + aChildrenValue, + xBatch, // no commit + aBatchPath ) ) + return sal_False; + } + } + } + } + } +#endif + +#if 0 + // Transaction with more then one change do not work at the moment!!! + + if ( !rxBatch.is() ) + { + // Commit changes. + xBatch->commitChanges(); + } +#endif + return sal_True; + } + } + } + } + catch ( RuntimeException& ) + { + throw; + } + catch ( IllegalArgumentException& ) + { + // escapeString, replaceByName, insertByName + + VOS_ENSURE( sal_False, + "HierarchyEntry::setData - caught IllegalArgumentException!" ); + } + catch ( NoSuchElementException& ) + { + // replaceByName, getByName, getByHierarchicalName + + VOS_ENSURE( sal_False, + "HierarchyEntry::setData - caught NoSuchElementException!" ); + } + catch ( ElementExistException& ) + { + // insertByName + + VOS_ENSURE( sal_False, + "HierarchyEntry::setData - caught ElementExistException!" ); + } + catch ( WrappedTargetException& ) + { + // replaceByName, insertByName, getByName, commitChanges + + VOS_ENSURE( sal_False, + "HierarchyEntry::setData - caught WrappedTargetException!" ); + } + catch ( Exception& ) + { + // createInstance, createInstanceWithArguments + + VOS_ENSURE( sal_False, + "HierarchyEntry::setData - caught Exception!" ); + } + + return sal_False; +} + +//========================================================================= +sal_Bool HierarchyEntry::setData( + const HierarchyEntryData& rData, sal_Bool bCreate ) +{ + return setData( OUString(), // no old path + m_aPath, + makeAny( rData.aTitle ), + makeAny( rData.aTargetURL ), + bCreate, + sal_False, // don't fail if exists + sal_False, // no children data given + Any(), + Reference< XChangesBatch >(), // commit data + OUString() ); +} + +//========================================================================= +sal_Bool HierarchyEntry::move( const OUString& rNewURL ) +{ + OUString aNewPath = createPathFromHierarchyURL( rNewURL ); + + if ( aNewPath == m_aPath ) + return sal_True; + + if ( aNewPath.compareTo( m_aPath, aNewPath.lastIndexOf( '/' ) + 1 ) != 0 ) + { + VOS_ENSURE( sal_False, + "HierarchyEntry::move - " + "Only move inside one directory allowed!" ); + return sal_False; + } + + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + +#if 0 + // In the near future... + + - get update access for m_aPath + - update access -> XNamed + - xNamed::setName( newName ) + - updateaccess commit +#else + ////////////////////////////////////////////////////////////////////// + // (1) Get old entry... + ////////////////////////////////////////////////////////////////////// + Any aTitle; + Any aTargetURL; + Any aChildren; + if ( getData( aTitle, aTargetURL, sal_True, aChildren ) ) + { + ////////////////////////////////////////////////////////////////// + // (2) Insert entry at new location. Fail, if another entry with + // same key already exists... + ////////////////////////////////////////////////////////////////// + if ( setData( m_aPath, // old path + aNewPath, // new path + aTitle, + aTargetURL, + sal_True, // create, if not exists + sal_True, // fail, if exists + sal_True, // process aChildren + aChildren, + Reference< XChangesBatch >(), // commit data + OUString() ) ) + { + ////////////////////////////////////////////////////////////// + // (3) Remove old entry. + ////////////////////////////////////////////////////////////// + return remove(); + } + } + + return sal_False; +#endif +} + +//========================================================================= +sal_Bool HierarchyEntry::remove() +{ + try + { + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + + if ( !m_xConfigProvider.is() ) + m_xConfigProvider = Reference< XMultiServiceFactory >( + m_xSMgr->createInstance( + OUString::createFromAscii( + "com.sun.star.configuration.ConfigurationProvider" ) ), + UNO_QUERY ); + + if ( m_xConfigProvider.is() ) + { + // Create parent's key. It must exist! + + OUString aParentPath + = OUString::createFromAscii( HIERARCHY_ROOT_DB_KEY ); + OUString aKey + = m_aPath; + sal_Bool bRoot = sal_True; + + sal_Int32 nPos = m_aPath.lastIndexOf( '/' ); + if ( nPos != -1 ) + { + aKey = m_aPath.copy( nPos + 1 ); + + // Skip "/Children" segment of the path, too. + nPos = m_aPath.lastIndexOf( '/', nPos - 1 ); + + VOS_ENSURE( nPos != -1, + "HierarchyEntry::remove - Wrong path!" ); + + aParentPath += OUString::createFromAscii( "/" ); + aParentPath += m_aPath.copy( 0, nPos ); + bRoot = sal_False; + } + + Sequence< Any > aArguments( 1 ); + aArguments[ 0 ] <<= aParentPath; + + Reference< XChangesBatch > xBatch( + m_xConfigProvider->createInstanceWithArguments( + OUString::createFromAscii( + "com.sun.star.configuration.ConfigurationUpdateAccess" ), + aArguments ), + UNO_QUERY ); + + VOS_ENSURE( xBatch.is(), + "HierarchyEntry::remove - No batch!" ); + + Reference< XNameAccess > xParentNameAccess( xBatch, UNO_QUERY ); + + VOS_ENSURE( xParentNameAccess.is(), + "HierarchyEntry::remove - No name access!" ); + + if ( xBatch.is() && xParentNameAccess.is() ) + { + Reference< XNameContainer > xContainer; + + if ( bRoot ) + { + // Special handling for children of root, + // which is not an entry. It's only a set + // of entries. + xContainer = Reference< XNameContainer >( + xParentNameAccess, UNO_QUERY ); + } + else + { + // Append new entry to parents child list, + // which is a set of entries. + xParentNameAccess->getByName( + OUString::createFromAscii( "Children" ) ) + >>= xContainer; + } + + VOS_ENSURE( xContainer.is(), + "HierarchyEntry::remove - No container!" ); + + if ( xContainer.is() ) + { + xContainer->removeByName( aKey ); + xBatch->commitChanges(); + return sal_True; + } + } + } + } + catch ( RuntimeException& ) + { + throw; + } + catch ( NoSuchElementException& ) + { + // getByName, removeByName + + VOS_ENSURE( sal_False, + "HierarchyEntry::remove - caught NoSuchElementException!" ); + } + catch ( WrappedTargetException& ) + { + // getByName, commitChanges + + VOS_ENSURE( sal_False, + "HierarchyEntry::remove - caught WrappedTargetException!" ); + } + catch ( Exception& ) + { + // createInstance, createInstanceWithArguments + + VOS_ENSURE( sal_False, + "HierarchyEntry::remove - caught Exception!" ); + } + + return sal_False; +} + +//========================================================================= +sal_Bool HierarchyEntry::first( iterator& it ) +{ + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + + if ( it.m_pImpl->pos == -1 ) + { + // Init... + + try + { + if ( !m_xConfigProvider.is() ) + m_xConfigProvider = Reference< XMultiServiceFactory >( + m_xSMgr->createInstance( + OUString::createFromAscii( + "com.sun.star.configuration.ConfigurationProvider" ) ), + UNO_QUERY ); + + if ( m_xConfigProvider.is() ) + { + OUString aPath + = OUString::createFromAscii( HIERARCHY_ROOT_DB_KEY ); + + // No slash in path -> root entry -> special handling needed. + if ( m_aPath.getLength() > 0 ) + { + aPath += OUString::createFromAscii( "/" ); + aPath += m_aPath; + aPath += OUString::createFromAscii( "/Children" ); + } + + Sequence< Any > aArguments( 1 ); + aArguments[ 0 ] <<= aPath; + + Reference< XNameAccess > xNameAccess( + m_xConfigProvider->createInstanceWithArguments( + OUString::createFromAscii( + "com.sun.star.configuration.ConfigurationAccess" ), + aArguments ), + UNO_QUERY ); + + VOS_ENSURE( xNameAccess.is(), + "HierarchyEntry::first - No name access!" ); + + if ( xNameAccess.is() ) + it.m_pImpl->names = xNameAccess->getElementNames(); + + Reference< XHierarchicalNameAccess > xHierNameAccess( + xNameAccess, UNO_QUERY ); + + VOS_ENSURE( xHierNameAccess.is(), + "HierarchyEntry::first - No hier. name access!" ); + + if ( xHierNameAccess.is() ) + it.m_pImpl->dir = xHierNameAccess; + } + } + catch ( RuntimeException& ) + { + throw; + } + catch ( Exception& ) + { + VOS_ENSURE( sal_False, + "HierarchyEntry::first - caught Exception!" ); + } + } + + if ( it.m_pImpl->names.getLength() == 0 ) + return sal_False; + + it.m_pImpl->pos = 0; + return sal_True; +} + +//========================================================================= +sal_Bool HierarchyEntry::next( iterator& it ) +{ + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + + if ( it.m_pImpl->pos == -1 ) + return first( it ); + + ++(it.m_pImpl->pos); + + return ( it.m_pImpl->pos < it.m_pImpl->names.getLength() ); +} + +//========================================================================= +OUString HierarchyEntry::createPathFromHierarchyURL( const OUString& rURL ) +{ + try + { + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + + if ( !m_xConfigProvider.is() ) + m_xConfigProvider = Reference< XMultiServiceFactory >( + m_xSMgr->createInstance( + OUString::createFromAscii( + "com.sun.star.configuration.ConfigurationProvider" ) ), + UNO_QUERY ); + + if ( m_xConfigProvider.is() ) + { + // Create Root object. + + Sequence< Any > aArguments( 1 ); + aArguments[ 0 ] + <<= OUString::createFromAscii( HIERARCHY_ROOT_DB_KEY ); + + m_xEscaper = Reference< XStringEscape >( + m_xConfigProvider->createInstanceWithArguments( + OUString::createFromAscii( + "com.sun.star.configuration.ConfigurationUpdateAccess" ), + aArguments ), + UNO_QUERY ); + } + } + catch ( RuntimeException& ) + { + throw; + } + catch ( Exception& ) + { + // createInstance, createInstanceWithArguments + + VOS_ENSURE( sal_False, + "HierarchyEntry::createPathFromHierarchyURL - " + "caught Exception!" ); + } + + VOS_ENSURE( m_xEscaper.is(), + "HierarchyEntry::createPathFromHierarchyURL - No escaper!" ); + + // Transform path.... + // folder/subfolder/subsubfolder + // --> folder/Children/subfolder/Children/subsubfolder + + // Erase URL scheme and ":/" from rURL to get the path. + OUString aPath = rURL.copy( HIERARCHY_URL_SCHEME_LENGTH + 2 ); + sal_Int32 nLen = aPath.getLength(); + + OUString aNewPath; + if ( nLen ) + { + const OUString aChildren = OUString::createFromAscii( "/Children/" ); + sal_Int32 nStart = 0; + sal_Int32 nEnd = aPath.indexOf( '/' ); + + do + { + if ( nEnd == -1 ) + nEnd = nLen; + + OUString aToken = aPath.copy( nStart, nEnd - nStart ); + + if ( m_xEscaper.is() ) + { + try + { + aToken = m_xEscaper->escapeString( aToken ); + } + catch ( IllegalArgumentException& ) + { + VOS_ENSURE( sal_False, + "HierarchyEntry::createPathFromHierarchyURL - " + "caught IllegalArgumentException!" ); + } + } + + aNewPath += aToken; + + if ( nEnd != nLen ) + { + aNewPath += aChildren; + nStart = nEnd + 1; + nEnd = aPath.indexOf( '/', nStart ); + } + } + while ( nEnd != nLen ); + } + + return aNewPath; +} + +//========================================================================= +//========================================================================= +// +// HierarchyEntry::iterator Implementation. +// +//========================================================================= +//========================================================================= + +HierarchyEntry::iterator::iterator() +{ + m_pImpl = new iterator_Impl; +} + +//========================================================================= +HierarchyEntry::iterator::~iterator() +{ + delete m_pImpl; +} + +//========================================================================= +const HierarchyEntryData& HierarchyEntry::iterator::operator*() const +{ + if ( ( m_pImpl->pos != -1 ) + && ( m_pImpl->dir.is() ) + && ( m_pImpl->pos < m_pImpl->names.getLength() ) ) + { + try + { + OUString aKey = m_pImpl->names.getConstArray()[ m_pImpl->pos ]; + OUString aTitle = aKey; + OUString aTargetURL = aKey; + aTitle += OUString::createFromAscii( "/Title" ); + aTargetURL += OUString::createFromAscii( "/TargetURL" ); + + m_pImpl->dir->getByHierarchicalName( aTitle ) + >>= m_pImpl->entry.aTitle; + m_pImpl->dir->getByHierarchicalName( aTargetURL ) + >>= m_pImpl->entry.aTargetURL; + + } + catch ( NoSuchElementException& ) + { + m_pImpl->entry = HierarchyEntryData(); + } + } + + return m_pImpl->entry; +} + diff --git a/ucb/source/ucp/hierarchy/hierarchydata.hxx b/ucb/source/ucp/hierarchy/hierarchydata.hxx new file mode 100644 index 000000000000..318d8c581271 --- /dev/null +++ b/ucb/source/ucp/hierarchy/hierarchydata.hxx @@ -0,0 +1,165 @@ +/************************************************************************* + * + * $RCSfile: hierarchydata.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:54:18 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _HIERARCHYDATA_HXX +#define _HIERARCHYDATA_HXX + +#ifndef _RTL_USTRING_HXX_ +#include <rtl/ustring.hxx> +#endif +#ifndef _OSL_MUTEX_HXX_ +#include <osl/mutex.hxx> +#endif +#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#endif + +namespace com { namespace sun { namespace star { namespace util { + class XChangesBatch; + class XStringEscape; +} } } } + +namespace hierarchy_ucp +{ + +//========================================================================= + +struct HierarchyEntryData +{ + ::rtl::OUString aTitle; // Title + ::rtl::OUString aTargetURL; // Target URL ( links only ) + + HierarchyEntryData() {} + HierarchyEntryData( const ::rtl::OUString& rTitle, + const ::rtl::OUString& rTargetURL ) + : aTitle( rTitle ), aTargetURL( rTargetURL ) {} +}; + +//========================================================================= + +class HierarchyEntry +{ + ::rtl::OUString m_aPath; + ::osl::Mutex m_aMutex; + ::com::sun::star::uno::Reference< + ::com::sun::star::lang::XMultiServiceFactory > m_xSMgr; + ::com::sun::star::uno::Reference< + ::com::sun::star::lang::XMultiServiceFactory > m_xConfigProvider; + ::com::sun::star::uno::Reference< + ::com::sun::star::util::XStringEscape > m_xEscaper; + +private: + sal_Bool getData( ::com::sun::star::uno::Any& rTitle, + ::com::sun::star::uno::Any& rTargetURL, + sal_Bool bChildren, + ::com::sun::star::uno::Any& rChildren ); + sal_Bool setData( const ::rtl::OUString& rOldPath, + const ::rtl::OUString& rPath, + const ::com::sun::star::uno::Any& rTitle, + const ::com::sun::star::uno::Any& rTargetURL, + sal_Bool bCreate, + sal_Bool bFailIfExists, + sal_Bool bChildren, + const ::com::sun::star::uno::Any& rChildren, + const ::com::sun::star::uno::Reference< + ::com::sun::star::util::XChangesBatch >& rxBatch, + const ::rtl::OUString& rBatchPath ); + ::rtl::OUString createPathFromHierarchyURL( const ::rtl::OUString& rURL ); + +public: + HierarchyEntry( const ::com::sun::star::uno::Reference< + ::com::sun::star::lang::XMultiServiceFactory >& rSMgr, + const ::rtl::OUString& rURL ); + + sal_Bool hasData(); + + sal_Bool getData( HierarchyEntryData& rData ); + + sal_Bool setData( const HierarchyEntryData& rData, sal_Bool bCreate ); + + sal_Bool move( const ::rtl::OUString& rNewURL ); + + sal_Bool remove(); + + // Iteration. + + struct iterator_Impl; + + class iterator + { + friend class HierarchyEntry; + + iterator_Impl* m_pImpl; + + public: + iterator(); + ~iterator(); + + const HierarchyEntryData& operator*() const; + }; + + sal_Bool first( iterator& it ); + sal_Bool next ( iterator& it ); +}; + +} // namespace hierarchy_ucp + +#endif /* !_HIERARCHYDATA_HXX */ diff --git a/ucb/source/ucp/hierarchy/hierarchydatasupplier.cxx b/ucb/source/ucp/hierarchy/hierarchydatasupplier.cxx new file mode 100644 index 000000000000..41cbd8684781 --- /dev/null +++ b/ucb/source/ucp/hierarchy/hierarchydatasupplier.cxx @@ -0,0 +1,490 @@ +/************************************************************************* + * + * $RCSfile: hierarchydatasupplier.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:54:18 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +/************************************************************************** + TODO + ************************************************************************** + + *************************************************************************/ + +#ifndef __VECTOR__ +#include <stl/vector> +#endif +#ifndef _UCBHELPER_CONTENTIDENTIFIER_HXX +#include <ucbhelper/contentidentifier.hxx> +#endif +#ifndef _HIERARCHYDATASUPPLIER_HXX +#include "hierarchydatasupplier.hxx" +#endif +#ifndef _HIERARCHYPROVIDER_HXX +#include "hierarchyprovider.hxx" +#endif +#ifndef _HIERARCHYCONTENT_HXX +#include "hierarchycontent.hxx" +#endif + +using namespace com::sun::star::beans; +using namespace com::sun::star::lang; +using namespace com::sun::star::ucb; +using namespace com::sun::star::uno; +using namespace com::sun::star::sdbc; +using namespace rtl; +using namespace ucb; + +using namespace hierarchy_ucp; + +namespace hierarchy_ucp +{ + +//========================================================================= +// +// struct ResultListEntry. +// +//========================================================================= + +struct ResultListEntry +{ + OUString aId; + Reference< XContentIdentifier > xId; + Reference< XContent > xContent; + Reference< XRow > xRow; + HierarchyEntryData rData; + + ResultListEntry( const HierarchyEntryData& rEntry ) : rData( rEntry ) {} +}; + +//========================================================================= +// +// ResultList. +// +//========================================================================= + +typedef std::vector< ResultListEntry* > ResultList; + +//========================================================================= +// +// struct DataSupplier_Impl. +// +//========================================================================= + +struct DataSupplier_Impl +{ + osl::Mutex m_aMutex; + ResultList m_aResults; + vos::ORef< HierarchyContent > m_xContent; + Reference< XMultiServiceFactory > m_xSMgr; + HierarchyEntry m_aFolder; + HierarchyEntry::iterator m_aIterator; + sal_Int32 m_nOpenMode; + sal_Bool m_bCountFinal; + + DataSupplier_Impl( const Reference< XMultiServiceFactory >& rxSMgr, + const vos::ORef< HierarchyContent >& rContent, + sal_Int32 nOpenMode ) + : m_xContent( rContent ), m_xSMgr( rxSMgr ), + m_aFolder( rxSMgr, rContent->getIdentifier()->getContentIdentifier() ), + m_nOpenMode( nOpenMode ), m_bCountFinal( sal_False ) {} + ~DataSupplier_Impl(); +}; + +//========================================================================= +DataSupplier_Impl::~DataSupplier_Impl() +{ + ResultList::const_iterator it = m_aResults.begin(); + ResultList::const_iterator end = m_aResults.end(); + + while ( it != end ) + { + delete (*it); + it++; + } +} + +} + +//========================================================================= +//========================================================================= +// +// HierarchyResultSetDataSupplier Implementation. +// +//========================================================================= +//========================================================================= + +HierarchyResultSetDataSupplier::HierarchyResultSetDataSupplier( + const Reference< XMultiServiceFactory >& rxSMgr, + const vos::ORef< HierarchyContent >& rContent, + sal_Int32 nOpenMode ) +: m_pImpl( new DataSupplier_Impl( rxSMgr, rContent, nOpenMode ) ) +{ +} + +//========================================================================= +// virtual +HierarchyResultSetDataSupplier::~HierarchyResultSetDataSupplier() +{ + delete m_pImpl; +} + +//========================================================================= +// virtual +OUString HierarchyResultSetDataSupplier::queryContentIdentifierString( + sal_uInt32 nIndex ) +{ + osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + + if ( nIndex < m_pImpl->m_aResults.size() ) + { + OUString aId = m_pImpl->m_aResults[ nIndex ]->aId; + if ( aId.getLength() ) + { + // Already cached. + return aId; + } + } + + if ( getResult( nIndex ) ) + { + OUString aId + = m_pImpl->m_xContent->getIdentifier()->getContentIdentifier(); + + if ( ( aId.lastIndexOf( '/' ) + 1 ) != aId.getLength() ) + aId += OUString::createFromAscii( "/" ); + + aId += HierarchyContentProvider::encodeSegment( + m_pImpl->m_aResults[ nIndex ]->rData.aTitle ); + + m_pImpl->m_aResults[ nIndex ]->aId = aId; + return aId; + } + return OUString(); +} + +//========================================================================= +// virtual +Reference< XContentIdentifier > +HierarchyResultSetDataSupplier::queryContentIdentifier( sal_uInt32 nIndex ) +{ + osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + + if ( nIndex < m_pImpl->m_aResults.size() ) + { + Reference< XContentIdentifier > xId + = m_pImpl->m_aResults[ nIndex ]->xId; + if ( xId.is() ) + { + // Already cached. + return xId; + } + } + + OUString aId = queryContentIdentifierString( nIndex ); + if ( aId.getLength() ) + { + Reference< XContentIdentifier > xId = new ContentIdentifier( aId ); + m_pImpl->m_aResults[ nIndex ]->xId = xId; + return xId; + } + return Reference< XContentIdentifier >(); +} + +//========================================================================= +// virtual +Reference< XContent > HierarchyResultSetDataSupplier::queryContent( + sal_uInt32 nIndex ) +{ + osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + + if ( nIndex < m_pImpl->m_aResults.size() ) + { + Reference< XContent > xContent + = m_pImpl->m_aResults[ nIndex ]->xContent; + if ( xContent.is() ) + { + // Already cached. + return xContent; + } + } + + Reference< XContentIdentifier > xId = queryContentIdentifier( nIndex ); + if ( xId.is() ) + { + try + { + Reference< XContent > xContent + = m_pImpl->m_xContent->getProvider()->queryContent( xId ); + m_pImpl->m_aResults[ nIndex ]->xContent = xContent; + return xContent; + + } + catch ( IllegalIdentifierException& ) + { + } + } + return Reference< XContent >(); +} + +//========================================================================= +// virtual +sal_Bool HierarchyResultSetDataSupplier::getResult( sal_uInt32 nIndex ) +{ + osl::ClearableGuard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + + if ( m_pImpl->m_aResults.size() > nIndex ) + { + // Result already present. + return sal_True; + } + + // Result not (yet) present. + + if ( m_pImpl->m_bCountFinal ) + return sal_False; + + // Try to obtain result... + + sal_uInt32 nOldCount = m_pImpl->m_aResults.size(); + sal_Bool bFound = sal_False; + sal_uInt32 nPos = nOldCount; + + while ( m_pImpl->m_aFolder.next( m_pImpl->m_aIterator ) ) + { + const HierarchyEntryData& rResult = *m_pImpl->m_aIterator; + if ( checkResult( rResult ) ) + { + m_pImpl->m_aResults.push_back( new ResultListEntry( rResult ) ); + + if ( nPos == nIndex ) + { + // Result obtained. + bFound = sal_True; + break; + } + } + nPos++; + } + + if ( !bFound ) + m_pImpl->m_bCountFinal = sal_True; + + vos::ORef< ResultSet > xResultSet = getResultSet(); + if ( xResultSet.isValid() ) + { + // Callbacks follow! + aGuard.clear(); + + if ( nOldCount < m_pImpl->m_aResults.size() ) + xResultSet->rowCountChanged( + nOldCount, m_pImpl->m_aResults.size() ); + + if ( m_pImpl->m_bCountFinal ) + xResultSet->rowCountFinal(); + } + + return bFound; +} + +//========================================================================= +// virtual +sal_uInt32 HierarchyResultSetDataSupplier::totalCount() +{ + osl::ClearableGuard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + + if ( m_pImpl->m_bCountFinal ) + return m_pImpl->m_aResults.size(); + + sal_uInt32 nOldCount = m_pImpl->m_aResults.size(); + + while ( m_pImpl->m_aFolder.next( m_pImpl->m_aIterator ) ) + { + const HierarchyEntryData& rResult = *m_pImpl->m_aIterator; + if ( checkResult( rResult ) ) + m_pImpl->m_aResults.push_back( new ResultListEntry( rResult ) ); + } + + m_pImpl->m_bCountFinal = sal_True; + + vos::ORef< ResultSet > xResultSet = getResultSet(); + if ( xResultSet.isValid() ) + { + // Callbacks follow! + aGuard.clear(); + + if ( nOldCount < m_pImpl->m_aResults.size() ) + xResultSet->rowCountChanged( + nOldCount, m_pImpl->m_aResults.size() ); + + xResultSet->rowCountFinal(); + } + + return m_pImpl->m_aResults.size(); +} + +//========================================================================= +// virtual +sal_uInt32 HierarchyResultSetDataSupplier::currentCount() +{ + return m_pImpl->m_aResults.size(); +} + +//========================================================================= +// virtual +sal_Bool HierarchyResultSetDataSupplier::isCountFinal() +{ + return m_pImpl->m_bCountFinal; +} + +//========================================================================= +// virtual +Reference< XRow > HierarchyResultSetDataSupplier::queryPropertyValues( + sal_uInt32 nIndex ) +{ + osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + + if ( nIndex < m_pImpl->m_aResults.size() ) + { + Reference< XRow > xRow = m_pImpl->m_aResults[ nIndex ]->xRow; + if ( xRow.is() ) + { + // Already cached. + return xRow; + } + } + + if ( getResult( nIndex ) ) + { + HierarchyContentProperties aData; + + aData.aTitle = m_pImpl->m_aResults[ nIndex ]->rData.aTitle; + aData.aTargetURL = m_pImpl->m_aResults[ nIndex ]->rData.aTargetURL; + aData.bIsDocument = ( aData.aTargetURL.getLength() > 0 ); + aData.bIsFolder = !aData.bIsDocument; + aData.aContentType = aData.bIsFolder + ? OUString::createFromAscii( + HIERARCHY_FOLDER_CONTENT_TYPE ) + : OUString::createFromAscii( + HIERARCHY_LINK_CONTENT_TYPE ); + + Reference< XRow > xRow = HierarchyContent::getPropertyValues( + m_pImpl->m_xSMgr, + getResultSet()->getProperties(), + aData, + m_pImpl->m_xContent->getProvider(), + queryContentIdentifierString( nIndex ) ); + m_pImpl->m_aResults[ nIndex ]->xRow = xRow; + return xRow; + } + + return Reference< XRow >(); +} + +//========================================================================= +// virtual +void HierarchyResultSetDataSupplier::releasePropertyValues( sal_uInt32 nIndex ) +{ + osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + + if ( nIndex < m_pImpl->m_aResults.size() ) + m_pImpl->m_aResults[ nIndex ]->xRow = Reference< XRow >(); +} + +//========================================================================= +// virtual +void HierarchyResultSetDataSupplier::close() +{ +} + +//========================================================================= +// virtual +void HierarchyResultSetDataSupplier::validate() + throw( ResultSetException ) +{ +} + +//========================================================================= +sal_Bool HierarchyResultSetDataSupplier::checkResult( + const HierarchyEntryData& rResult ) +{ + switch ( m_pImpl->m_nOpenMode ) + { + case OpenMode::FOLDERS: + if ( rResult.aTargetURL.getLength() > 0 ) + { + // Entry is a link. + return sal_False; + } + break; + + case OpenMode::DOCUMENTS: + if ( rResult.aTargetURL.getLength() == 0 ) + { + // Entry is a folder. + return sal_False; + } + break; + + case OpenMode::ALL: + default: + break; + } + + return sal_True; +} + diff --git a/ucb/source/ucp/hierarchy/hierarchydatasupplier.hxx b/ucb/source/ucp/hierarchy/hierarchydatasupplier.hxx new file mode 100644 index 000000000000..eede0425865c --- /dev/null +++ b/ucb/source/ucp/hierarchy/hierarchydatasupplier.hxx @@ -0,0 +1,119 @@ +/************************************************************************* + * + * $RCSfile: hierarchydatasupplier.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:54:18 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _HIERARCHYDATASUPPLIER_HXX +#define _HIERARCHYDATASUPPLIER_HXX + +#ifndef _COM_SUN_STAR_UCB_OPENMODE_HPP_ +#include <com/sun/star/ucb/OpenMode.hpp> +#endif + +#ifndef _UCBHELPER_RESULTSET_HXX +#include <ucbhelper/resultset.hxx> +#endif + +namespace hierarchy_ucp { + +struct HierarchyEntryData; +struct DataSupplier_Impl; +class HierarchyContent; + +class HierarchyResultSetDataSupplier : public ucb::ResultSetDataSupplier +{ + DataSupplier_Impl* m_pImpl; + +private: + sal_Bool checkResult( const HierarchyEntryData& rResult ); + +public: + HierarchyResultSetDataSupplier( + const com::sun::star::uno::Reference< + com::sun::star::lang::XMultiServiceFactory >& rxSMgr, + const vos::ORef< HierarchyContent >& rContent, + sal_Int32 nOpenMode = com::sun::star::ucb::OpenMode::ALL ); + virtual ~HierarchyResultSetDataSupplier(); + + virtual rtl::OUString queryContentIdentifierString( sal_uInt32 nIndex ); + virtual com::sun::star::uno::Reference< + com::sun::star::ucb::XContentIdentifier > + queryContentIdentifier( sal_uInt32 nIndex ); + virtual com::sun::star::uno::Reference< com::sun::star::ucb::XContent > + queryContent( sal_uInt32 nIndex ); + + virtual sal_Bool getResult( sal_uInt32 nIndex ); + + virtual sal_uInt32 totalCount(); + virtual sal_uInt32 currentCount(); + virtual sal_Bool isCountFinal(); + + virtual com::sun::star::uno::Reference< com::sun::star::sdbc::XRow > + queryPropertyValues( sal_uInt32 nIndex ); + virtual void releasePropertyValues( sal_uInt32 nIndex ); + + virtual void close(); + + virtual void validate() + throw( com::sun::star::ucb::ResultSetException ); +}; + +} // namespace hierarchy_ucp + +#endif /* !_HIERARCHYDATASUPPLIER_HXX */ diff --git a/ucb/source/ucp/hierarchy/hierarchyprovider.cxx b/ucb/source/ucp/hierarchy/hierarchyprovider.cxx new file mode 100644 index 000000000000..24f222a0cf31 --- /dev/null +++ b/ucb/source/ucp/hierarchy/hierarchyprovider.cxx @@ -0,0 +1,196 @@ +/************************************************************************* + * + * $RCSfile: hierarchyprovider.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:54:18 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +/************************************************************************** + TODO + ************************************************************************** + + *************************************************************************/ + +#ifndef _VOS_DIAGNOSE_HXX_ +#include <vos/diagnose.hxx> +#endif +#ifndef _UCBHELPER_CONTENTIDENTIFIER_HXX +#include <ucbhelper/contentidentifier.hxx> +#endif + +#ifndef _HIERARCHYPROVIDER_HXX +#include "hierarchyprovider.hxx" +#endif +#ifndef _HIERARCHYCONTENT_HXX +#include "hierarchycontent.hxx" +#endif + +using namespace com::sun::star::lang; +using namespace com::sun::star::ucb; +using namespace com::sun::star::uno; +using namespace rtl; + +using namespace hierarchy_ucp; + +//========================================================================= +//========================================================================= +// +// HierarchyContentProvider Implementation. +// +//========================================================================= +//========================================================================= + +HierarchyContentProvider::HierarchyContentProvider( + const Reference< XMultiServiceFactory >& rXSMgr ) +: ::ucb::ContentProviderImplHelper( rXSMgr ) +{ +} + +//========================================================================= +// virtual +HierarchyContentProvider::~HierarchyContentProvider() +{ +} + +//========================================================================= +// +// XInterface methods. +// +//========================================================================= + +XINTERFACE_IMPL_3( HierarchyContentProvider, + XTypeProvider, + XServiceInfo, + XContentProvider ); + +//========================================================================= +// +// XTypeProvider methods. +// +//========================================================================= + +XTYPEPROVIDER_IMPL_3( HierarchyContentProvider, + XTypeProvider, + XServiceInfo, + XContentProvider ); + +//========================================================================= +// +// XServiceInfo methods. +// +//========================================================================= + +XSERVICEINFO_IMPL_1( HierarchyContentProvider, + OUString::createFromAscii( + "HierarchyContentProvider" ), + OUString::createFromAscii( + HIERARCHY_CONTENT_PROVIDER_SERVICE_NAME ) ); + +//========================================================================= +// +// Service factory implementation. +// +//========================================================================= + +ONE_INSTANCE_SERVICE_FACTORY_IMPL( HierarchyContentProvider ); + +//========================================================================= +// +// XContentProvider methods. +// +//========================================================================= + +// virtual +Reference< XContent > SAL_CALL HierarchyContentProvider::queryContent( + const Reference< XContentIdentifier >& Identifier ) + throw( IllegalIdentifierException, RuntimeException ) +{ + vos::OGuard aGuard( m_aMutex ); + + // Check URL scheme... + + OUString aScheme( OUString::createFromAscii( HIERARCHY_URL_SCHEME ) ); + if ( !Identifier->getContentProviderScheme().equalsIgnoreCase( aScheme ) ) + throw IllegalIdentifierException(); + + // Check URL. Must be at least the URL of the Root Folder. + OUString aId = Identifier->getContentIdentifier(); + if ( aId.compareToAscii( HIERARCHY_ROOT_FOLDER_URL, + HIERARCHY_ROOT_FOLDER_URL_LENGTH ) != 0 ) + throw IllegalIdentifierException(); + + // Encode URL and create new Id. This may "correct" user-typed-in URL's. + Reference< XContentIdentifier > xCanonicId = + new ::ucb::ContentIdentifier( m_xSMgr, encodeURL( aId ) ); + + // Check, if a content with given id already exists... + Reference< XContent > xContent + = queryExistingContent( xCanonicId ).getBodyPtr(); + if ( xContent.is() ) + return xContent; + + // Create a new content. Note that the content will insert itself + // into m_pContents by calling addContent(...) from it's ctor. + + xContent = HierarchyContent::create( m_xSMgr, this, xCanonicId ); + + if ( xContent.is() && !xContent->getIdentifier().is() ) + throw IllegalIdentifierException(); + + return xContent; +} + diff --git a/ucb/source/ucp/hierarchy/hierarchyprovider.hxx b/ucb/source/ucp/hierarchy/hierarchyprovider.hxx new file mode 100644 index 000000000000..4d5f4042d53e --- /dev/null +++ b/ucb/source/ucp/hierarchy/hierarchyprovider.hxx @@ -0,0 +1,125 @@ +/************************************************************************* + * + * $RCSfile: hierarchyprovider.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:54:18 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _HIERARCHYPROVIDER_HXX +#define _HIERARCHYPROVIDER_HXX + +#ifndef _UCBHELPER_PROVIDERHELPER_HXX +#include <ucbhelper/providerhelper.hxx> +#endif + +namespace hierarchy_ucp { + +//========================================================================= + +#define HIERARCHY_CONTENT_PROVIDER_SERVICE_NAME \ + "com.sun.star.ucb.HierarchyContentProvider" +#define HIERARCHY_CONTENT_PROVIDER_SERVICE_NAME_LENGTH 41 + +#define HIERARCHY_URL_SCHEME \ + "vnd.sun.star.hier" +#define HIERARCHY_URL_SCHEME_LENGTH 17 + +#define HIERARCHY_FOLDER_CONTENT_TYPE \ + "application/" HIERARCHY_URL_SCHEME "-folder" +#define HIERARCHY_LINK_CONTENT_TYPE \ + "application/" HIERARCHY_URL_SCHEME "-link" + +#define HIERARCHY_ROOT_FOLDER_URL \ + HIERARCHY_URL_SCHEME ":/" +#define HIERARCHY_ROOT_FOLDER_URL_LENGTH ( HIERARCHY_URL_SCHEME_LENGTH + 2 ) + +//========================================================================= + +class HierarchyContentProvider : public ::ucb::ContentProviderImplHelper +{ +public: + HierarchyContentProvider( + const com::sun::star::uno::Reference< + com::sun::star::lang::XMultiServiceFactory >& rXSMgr ); + virtual ~HierarchyContentProvider(); + + // XInterface + XINTERFACE_DECL() + + // XTypeProvider + XTYPEPROVIDER_DECL() + + // XServiceInfo + XSERVICEINFO_DECL() + + // XContentProvider + virtual com::sun::star::uno::Reference< + com::sun::star::ucb::XContent > SAL_CALL + queryContent( const com::sun::star::uno::Reference< + com::sun::star::ucb::XContentIdentifier >& Identifier ) + throw( com::sun::star::ucb::IllegalIdentifierException, + com::sun::star::uno::RuntimeException ); + + // Non-Interface methods + static rtl::OUString encodeURL( const rtl::OUString& rURL ); + static rtl::OUString encodeSegment( const rtl::OUString& rSegment ); + static rtl::OUString decodeSegment( const rtl::OUString& rSegment ); +}; + +} // namespace hierarchy_ucp + +#endif /* !_HIERARCHYPROVIDER_HXX */ diff --git a/ucb/source/ucp/hierarchy/hierarchyservices.cxx b/ucb/source/ucp/hierarchy/hierarchyservices.cxx new file mode 100644 index 000000000000..7a5ada177810 --- /dev/null +++ b/ucb/source/ucp/hierarchy/hierarchyservices.cxx @@ -0,0 +1,173 @@ +/************************************************************************* + * + * $RCSfile: hierarchyservices.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:54:18 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XSINGLESERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XSingleServiceFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_REGISTRY_XREGISTRYKEY_HPP_ +#include <com/sun/star/registry/XRegistryKey.hpp> +#endif + +#ifndef _HIERARCHYPROVIDER_HXX +#include "hierarchyprovider.hxx" +#endif + +using namespace rtl; +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::registry; +using namespace hierarchy_ucp; + +//========================================================================= +static sal_Bool writeInfo( void * pRegistryKey, + const OUString & rImplementationName, + Sequence< OUString > const & rServiceNames ) +{ + OUString aKeyName( OUString::createFromAscii( "/" ) ); + aKeyName += rImplementationName; + aKeyName += OUString::createFromAscii( "/UNO/SERVICES" ); + + Reference< XRegistryKey > xKey; + try + { + xKey = static_cast< XRegistryKey * >( + pRegistryKey )->createKey( aKeyName ); + } + catch ( InvalidRegistryException const & ) + { + } + + if ( !xKey.is() ) + return sal_False; + + sal_Bool bSuccess = sal_True; + + for ( sal_Int32 n = 0; n < rServiceNames.getLength(); ++n ) + { + try + { + xKey->createKey( rServiceNames[ n ] ); + } + catch ( InvalidRegistryException const & ) + { + bSuccess = sal_False; + break; + } + } + return bSuccess; +} + +//========================================================================= +extern "C" void SAL_CALL component_getImplementationEnvironment( + const sal_Char ** ppEnvTypeName, uno_Environment ** ppEnv ) +{ + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; +} + +//========================================================================= +extern "C" sal_Bool SAL_CALL component_writeInfo( + void * pServiceManager, void * pRegistryKey ) +{ + return pRegistryKey && + + ////////////////////////////////////////////////////////////////////// + // Hierarchy Content Provider. + ////////////////////////////////////////////////////////////////////// + + writeInfo( pRegistryKey, + HierarchyContentProvider::getImplementationName_Static(), + HierarchyContentProvider::getSupportedServiceNames_Static() ); +} + +//========================================================================= +extern "C" void * SAL_CALL component_getFactory( + const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey ) +{ + void * pRet = 0; + + Reference< XMultiServiceFactory > xSMgr( + reinterpret_cast< XMultiServiceFactory * >( pServiceManager ) ); + Reference< XSingleServiceFactory > xFactory; + + ////////////////////////////////////////////////////////////////////// + // Hierarchy Content Provider. + ////////////////////////////////////////////////////////////////////// + + if ( HierarchyContentProvider::getImplementationName_Static(). + compareToAscii( pImplName ) == 0 ) + { + xFactory = HierarchyContentProvider::createServiceFactory( xSMgr ); + } + + ////////////////////////////////////////////////////////////////////// + + if ( xFactory.is() ) + { + xFactory->acquire(); + pRet = xFactory.get(); + } + + return pRet; +} + diff --git a/ucb/source/ucp/hierarchy/makefile.mk b/ucb/source/ucp/hierarchy/makefile.mk new file mode 100644 index 000000000000..c68f9b17e104 --- /dev/null +++ b/ucb/source/ucp/hierarchy/makefile.mk @@ -0,0 +1,126 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1 $ +# +# last change: $Author: kso $ $Date: 2000-10-16 14:54:18 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (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.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=..$/..$/.. +PRJNAME=ucb +TARGET=ucphier +ENABLE_EXCEPTIONS=TRUE +USE_DEFFILE=TRUE +NO_BSYMBOLIC=TRUE + +# Version +UCPHIER_MAJOR=1 + +# --- Settings --------------------------------------------------------- + +.INCLUDE: svpre.mk +.INCLUDE: settings.mk +.INCLUDE: sv.mk + +# --- General ----------------------------------------------------- + +SLOFILES=\ + $(SLO)$/hierarchyservices.obj \ + $(SLO)$/hierarchydata.obj \ + $(SLO)$/hierarchyprovider.obj \ + $(SLO)$/hierarchycontent.obj \ + $(SLO)$/hierarchycontentcaps.obj \ + $(SLO)$/hierarchydatasupplier.obj \ + $(SLO)$/hierarchyurlcode.obj \ + $(SLO)$/dynamicresultset.obj + +# NETBSD: somewhere we have to instantiate the static data members. +# NETBSD-1.2.1 doesn't know about weak symbols so the default mechanism for GCC won't work. +# SCO and MACOSX: the linker does know about weak symbols, but we can't ignore multiple defined symbols +.IF "$(OS)"=="NETBSD" || "$(OS)"=="SCO" || "$(OS)$(COM)"=="OS2GCC" || "$(OS)"=="MACOSX" +SLOFILES+=$(SLO)$/staticmbhierarchy.obj +.ENDIF + +LIB1TARGET=$(SLB)$/_$(TARGET).lib +LIB1OBJFILES=$(SLOFILES) + +# --- Shared-Library --------------------------------------------------- + +SHL1TARGET=$(TARGET)$(UCPHIER_MAJOR) +SHL1IMPLIB=i$(TARGET) +SHL1VERSIONMAP= $(TARGET).map + +SHL1STDLIBS=\ + $(CPPUHELPERLIB) \ + $(CPPULIB) \ + $(SALLIB) \ + $(VOSLIB) \ + $(UCBHELPERLIB) + +SHL1DEF=$(MISC)$/$(SHL1TARGET).def +SHL1LIBS=$(LIB1TARGET) + +# --- Def-File --------------------------------------------------------- + +DEF1NAME=$(SHL1TARGET) +DEF1EXPORTFILE= $(TARGET).dxp +DEF1DES=UCB Hierarchy Content Provider + +# --- Targets ---------------------------------------------------------- + +.INCLUDE: target.mk + diff --git a/ucb/source/ucp/hierarchy/ucphier.map b/ucb/source/ucp/hierarchy/ucphier.map new file mode 100644 index 000000000000..319e7b11a9a7 --- /dev/null +++ b/ucb/source/ucp/hierarchy/ucphier.map @@ -0,0 +1,8 @@ +HIER_1_0 { + global: + component_getImplementationEnvironment; + component_writeInfo; + component_getFactory; + local: + *; +}; diff --git a/ucb/source/ucp/webdav/DAVAuthListener.hxx b/ucb/source/ucp/webdav/DAVAuthListener.hxx new file mode 100644 index 000000000000..8f453bb68f53 --- /dev/null +++ b/ucb/source/ucp/webdav/DAVAuthListener.hxx @@ -0,0 +1,95 @@ +/************************************************************************* + * + * $RCSfile: DAVAuthListener.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:55:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _DAVAUTHLISTENER_HXX_ +#define _DAVAUTHLISTENER_HXX_ + +#ifndef _RTL_USTRBUF_HXX_ +#include <rtl/ustrbuf.hxx> +#endif +#ifndef _RTL_USTRING_HXX_ +#include <rtl/ustring.hxx> +#endif + +#ifndef _COM_SUN_STAR_UCB_XREFERENCE_HPP_ +#include <com/sun/star/uno/XReference.hpp> +#endif + +#ifndef _COM_SUN_STAR_UCB_XCOMMANDENVIRONMENT_HPP_ +#include <com/sun/star/ucb/XCommandEnvironment.hpp> +#endif + +namespace webdav_ucp +{ + +class DAVAuthListener +{ + public: + virtual int authenticate(const ::rtl::OUString & inRealm, + const ::rtl::OUString & inHostName, + ::rtl::OUStringBuffer & inUserName, + ::rtl::OUStringBuffer & inPassWord, + const com::sun::star::uno::Reference< + com::sun::star::ucb::XCommandEnvironment >& inEnv) + = 0; +}; + +}; // namespace webdav_ucp +#endif // _DAVAUTHLISTENER_HXX_ diff --git a/ucb/source/ucp/webdav/DAVException.hxx b/ucb/source/ucp/webdav/DAVException.hxx new file mode 100644 index 000000000000..18d5efc6157c --- /dev/null +++ b/ucb/source/ucp/webdav/DAVException.hxx @@ -0,0 +1,88 @@ +/************************************************************************* + * + * $RCSfile: DAVException.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:55:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _DAVEXCEPTION_HXX_ +#define _DAVEXCEPTION_HXX_ + +namespace webdav_ucp +{ + +class DAVException +{ + public: + enum ExceptionCode { DAV_HTTP_LOOKUP = 0, + DAV_HTTP_ERROR, + DAV_SESSION_CREATE, + DAV_REQUEST_CREATE, + DAV_INVALID_ARG, + DAV_FILE_OPEN, + DAV_FILE_WRITE, + DAV_UNKNOWN }; + + ExceptionCode mExceptionCode; + + public: + DAVException( ExceptionCode inExceptionCode ) : + mExceptionCode( inExceptionCode ) {}; + ~DAVException( ) {}; +}; + +}; // namespace webdav_ucp +#endif // _DAVEXCEPTION_HXX_ diff --git a/ucb/source/ucp/webdav/DAVProperties.cxx b/ucb/source/ucp/webdav/DAVProperties.cxx new file mode 100644 index 000000000000..724d082c63dc --- /dev/null +++ b/ucb/source/ucp/webdav/DAVProperties.cxx @@ -0,0 +1,86 @@ +/************************************************************************* + * + * $RCSfile: DAVProperties.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:55:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#include "DAVProperties.hxx" + +using namespace webdav_ucp; + +const ::rtl::OUString DAVProperties::CREATIONDATE = + ::rtl::OUString::createFromAscii( "creationdate" ); +const ::rtl::OUString DAVProperties::DISPLAYNAME = + ::rtl::OUString::createFromAscii( "displayname" ); +const ::rtl::OUString DAVProperties::GETCONTENTLANGUAGE = + ::rtl::OUString::createFromAscii( "getcontentlanguage" ); +const ::rtl::OUString DAVProperties::GETCONTENTLENGTH = + ::rtl::OUString::createFromAscii( "getcontentlength" ); +const ::rtl::OUString DAVProperties::GETCONTENTTYPE = + ::rtl::OUString::createFromAscii( "getcontenttype" ); +const ::rtl::OUString DAVProperties::GETETAG = + ::rtl::OUString::createFromAscii( "getetag" ); +const ::rtl::OUString DAVProperties::GETLASTMODIFIED = + ::rtl::OUString::createFromAscii( "getlastmodified" ); +const ::rtl::OUString DAVProperties::LOCKDISCOVERY = + ::rtl::OUString::createFromAscii( "lockdiscovery" ); +const ::rtl::OUString DAVProperties::RESOURCETYPE = + ::rtl::OUString::createFromAscii( "resourcetype" ); +const ::rtl::OUString DAVProperties::SOURCE = + ::rtl::OUString::createFromAscii( "source" ); +const ::rtl::OUString DAVProperties::SUPPORTEDLOCK = + ::rtl::OUString::createFromAscii( "supportedlock" ); diff --git a/ucb/source/ucp/webdav/DAVProperties.hxx b/ucb/source/ucp/webdav/DAVProperties.hxx new file mode 100644 index 000000000000..da8211abed74 --- /dev/null +++ b/ucb/source/ucp/webdav/DAVProperties.hxx @@ -0,0 +1,86 @@ +/************************************************************************* + * + * $RCSfile: DAVProperties.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:55:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _DAVPROPERTIES_HXX_ +#define _DAVPROPERTIES_HXX_ + +#include <rtl/ustring.hxx> + +namespace webdav_ucp +{ + +class DAVProperties +{ + public: + static const ::rtl::OUString CREATIONDATE; + static const ::rtl::OUString DISPLAYNAME; + static const ::rtl::OUString GETCONTENTLANGUAGE; + static const ::rtl::OUString GETCONTENTLENGTH; + static const ::rtl::OUString GETCONTENTTYPE; + static const ::rtl::OUString GETETAG; + static const ::rtl::OUString GETLASTMODIFIED; + static const ::rtl::OUString LOCKDISCOVERY; + static const ::rtl::OUString RESOURCETYPE; + static const ::rtl::OUString SOURCE; + static const ::rtl::OUString SUPPORTEDLOCK; +}; + +}; // namespace webdav_ucp +#endif // _DAVPROPERTIES_HXX_ diff --git a/ucb/source/ucp/webdav/DAVResource.hxx b/ucb/source/ucp/webdav/DAVResource.hxx new file mode 100644 index 000000000000..0e3b3784fcbc --- /dev/null +++ b/ucb/source/ucp/webdav/DAVResource.hxx @@ -0,0 +1,89 @@ +/************************************************************************* + * + * $RCSfile: DAVResource.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:55:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _DAVRESOURCE_HXX_ +#define _DAVRESOURCE_HXX_ + +#include <stl/vector> +#include <rtl/ustring.hxx> +#include <com/sun/star/beans/PropertyValue.hpp> + +namespace webdav_ucp +{ + +class DAVResource +{ + private: + bool canDelete; + + public: + ::rtl::OUString uri; + std::vector < com::sun::star::beans::PropertyValue* > properties; + + public: + DAVResource(const DAVResource & inDAVResource); + DAVResource(const ::rtl::OUString & inUri, bool incanDelete = true ); + + void deletePropertyValues( void ); + void operator=( const DAVResource & inDAVResource ); +}; + +}; // namespace webdav_ucp +#endif // _DAVRESOURCE_HXX_ diff --git a/ucb/source/ucp/webdav/DAVSession.hxx b/ucb/source/ucp/webdav/DAVSession.hxx new file mode 100644 index 000000000000..bad4e3971d38 --- /dev/null +++ b/ucb/source/ucp/webdav/DAVSession.hxx @@ -0,0 +1,151 @@ +/************************************************************************* + * + * $RCSfile: DAVSession.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:55:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _DAVSESSION_HXX_ +#define _DAVSESSION_HXX_ + +#include "DAVAuthListener.hxx" +#include "DAVException.hxx" +#include "DAVProperties.hxx" +#include "DAVResource.hxx" +#include "DAVSessionFactory.hxx" +#include "DAVTypes.hxx" +#include <rtl/ustring.hxx> +#include <cppuhelper/weak.hxx> +#include <com/sun/star/uno/XReference.hpp> +#include <com/sun/star/io/XInputStream.hpp> +#include <com/sun/star/io/XOutputStream.hpp> +#include <com/sun/star/ucb/XCommandEnvironment.hpp> + +namespace webdav_ucp +{ + +class DAVSession : public ::cppu::OWeakObject +{ +public: + virtual sal_Bool CanUse( const ::rtl::OUString & inUri ) = 0; + + // Authentication methods + // + virtual void setServerAuthListener(DAVAuthListener * inDAVAuthListener) = 0; + virtual void setProxyAuthListener(DAVAuthListener * inDAVAuthListener ) = 0; + + + // DAV methods + // + + virtual void PROPFIND( const ::rtl::OUString & inUri, + const Depth inDepth, + const std::vector< ::rtl::OUString > & inPropertyNames, + std::vector< DAVResource > & inResources, + const com::sun::star::uno::Reference< + com::sun::star::ucb::XCommandEnvironment >& inEnv ) = 0; + + virtual com::sun::star::uno::Reference< com::sun::star::io::XInputStream > + GET( const ::rtl::OUString & inUri, + const com::sun::star::uno::Reference< + com::sun::star::ucb::XCommandEnvironment >& inEnv ) = 0; + + virtual void GET( const ::rtl::OUString & inUri, + com::sun::star::uno::Reference< com::sun::star::io::XOutputStream >& o, + const com::sun::star::uno::Reference< + com::sun::star::ucb::XCommandEnvironment >& inEnv ) = 0; + + virtual void PUT( const ::rtl::OUString & inUri, + com::sun::star::uno::Reference< com::sun::star::io::XInputStream >& s, + const com::sun::star::uno::Reference< + com::sun::star::ucb::XCommandEnvironment >& inEnv ) = 0; + + virtual void MKCOL( const ::rtl::OUString & inUri, + const com::sun::star::uno::Reference< + com::sun::star::ucb::XCommandEnvironment >& inEnv ) = 0; + + virtual void COPY( const ::rtl::OUString & inSource, + const ::rtl::OUString & inDestination, + const com::sun::star::uno::Reference< + com::sun::star::ucb::XCommandEnvironment >& inEnv, + sal_Bool inOverwrite = false ) = 0; + + virtual void MOVE( const ::rtl::OUString & inSource, + const ::rtl::OUString & inDestination, + const com::sun::star::uno::Reference< + com::sun::star::ucb::XCommandEnvironment >& inEnv, + sal_Bool inOverwrite = false ) = 0; + + virtual void DESTROY( const ::rtl::OUString & inUri, + const com::sun::star::uno::Reference< + com::sun::star::ucb::XCommandEnvironment >& inEnv ) = 0; + + // Note: Uncomment the following if locking support is required + /* + virtual void LOCK ( const Lock & inLock, + const com::sun::star::uno::Reference< + com::sun::star::ucb::XCommandEnvironment >& inEnv ) = 0; + + virtual void UNLOCK ( const Lock & inLock, + const com::sun::star::uno::Reference< + com::sun::star::ucb::XCommandEnvironment >& inEnv) = 0; + */ +}; + +}; // namespace webdav_ucp + +#endif // _DAVSESSION_HXX_ + diff --git a/ucb/source/ucp/webdav/DAVSessionFactory.cxx b/ucb/source/ucp/webdav/DAVSessionFactory.cxx new file mode 100644 index 000000000000..5753c4dfd407 --- /dev/null +++ b/ucb/source/ucp/webdav/DAVSessionFactory.cxx @@ -0,0 +1,113 @@ +/************************************************************************* + * + * $RCSfile: DAVSessionFactory.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:55:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#include "DAVSessionFactory.hxx" +#include "NeonSession.hxx" + +using namespace std; +using namespace rtl; +using namespace vos; +using namespace webdav_ucp; + +std::vector< DAVSession * > DAVSessionFactory::sActiveSessions; + +ORef< DAVSession > DAVSessionFactory::createDAVSession( const OUString & inUri ) +{ + DAVSession * theSession = GetExistingSession( inUri ); + if ( theSession == NULL ) + { + theSession = new NeonSession( inUri ); + sActiveSessions.push_back( theSession ); + } + + return theSession; +} + +void DAVSessionFactory::ReleaseDAVSession( DAVSession * inSession ) +{ + std::vector< DAVSession * >::iterator theIterator = + sActiveSessions.begin(); + while ( theIterator != sActiveSessions.end() ) + { + if ( *theIterator == inSession ) + { + sActiveSessions.erase( theIterator ); + break; + } + ++theIterator; + } +} + +DAVSession * DAVSessionFactory::GetExistingSession( const OUString & inUri ) +{ + DAVSession * theSession = NULL; + std::vector< DAVSession * >::iterator theIterator = + sActiveSessions.begin(); + while ( theIterator != sActiveSessions.end() ) + { + if ( (*theIterator)->CanUse( inUri ) ) + { + theSession = *theIterator; + break; + } + ++theIterator; + } + return theSession; +} diff --git a/ucb/source/ucp/webdav/DAVSessionFactory.hxx b/ucb/source/ucp/webdav/DAVSessionFactory.hxx new file mode 100644 index 000000000000..5162114773ae --- /dev/null +++ b/ucb/source/ucp/webdav/DAVSessionFactory.hxx @@ -0,0 +1,89 @@ +/************************************************************************* + * + * $RCSfile: DAVSessionFactory.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:55:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _DAVSESSIONFACTORY_HXX_ +#define _DAVSESSIONFACTORY_HXX_ + +#include <stl/vector> +#include <rtl/ustring.hxx> +#include <vos/ref.hxx> + +namespace webdav_ucp +{ + + +class DAVSession; +class DAVSessionFactory +{ + private: + static std::vector< DAVSession * > sActiveSessions; + + public: + static ::vos::ORef< DAVSession > createDAVSession( + const ::rtl::OUString & inUri ); + + static void ReleaseDAVSession( DAVSession * inSession ); + + private: + static DAVSession * GetExistingSession( const ::rtl::OUString & inUri ); +}; + +}; // namespace webdav_ucp +#endif // _DAVSESSIONFACTORY_HXX_ diff --git a/ucb/source/ucp/webdav/DAVTypes.hxx b/ucb/source/ucp/webdav/DAVTypes.hxx new file mode 100644 index 000000000000..93c10b880a65 --- /dev/null +++ b/ucb/source/ucp/webdav/DAVTypes.hxx @@ -0,0 +1,96 @@ +/************************************************************************* + * + * $RCSfile: DAVTypes.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:55:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _DAVTYPES_HXX_ +#define _DAVTYPES_HXX_ + +#include <rtl/ustring.hxx> +#include <com/sun/star/uno/Sequence.hxx> + + +namespace webdav_ucp +{ + +enum Depth { ZERO = 0, ONE = 1, INFINITY = -1 }; + +// Note: Uncomment the following if locking support is required +/* +enum LockScope { EXCLUSIVE = 0, SHARED }; + +enum LockType { WRITE = 0 }; + +struct LockEntry +{ + LockScope scope; + LockType type; +}; + +struct Lock : public LockEntry +{ + rtl::OUString uri; + Depth depth; + rtl::OUString owner; + long timeout; + com::sun::star::uno::Sequence< rtl::OUString > locktoken; +}; +*/ + +}; // namespace webdav_ucp +#endif // _DAVTYPES_HXX_ diff --git a/ucb/source/ucp/webdav/DateTimeHelper.cxx b/ucb/source/ucp/webdav/DateTimeHelper.cxx new file mode 100644 index 000000000000..99c29001f959 --- /dev/null +++ b/ucb/source/ucp/webdav/DateTimeHelper.cxx @@ -0,0 +1,207 @@ +/************************************************************************* + * + * $RCSfile: DateTimeHelper.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:55:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#include <stdio.h> + +#ifndef _COM_SUN_STAR_UTIL_DATETIME_HPP_ +#include <com/sun/star/util/DateTime.hpp> +#endif + +#include "DateTimeHelper.hxx" + +using namespace com::sun::star::util; +using namespace rtl; + +using namespace webdav_ucp; + +bool DateTimeHelper::ISO8601_To_DateTime (const OUString& s, + DateTime& dateTime) +{ + const char* _s = OUStringToOString (s, RTL_TEXTENCODING_ASCII_US).getStr (); + + sal_Int32 year; + sal_Int32 month; + sal_Int32 day; + sal_Int32 hours; + sal_Int32 minutes; + sal_Int32 seconds; + + sal_Int32 i = sscanf (_s, "%4d-%2d-%2dT%2d:%2d:%2d", + &year, &month, &day, + &hours, &minutes, &seconds); + if (i != 6) + return false; + + dateTime.Year = year; + dateTime.Month = month; + dateTime.Day = day; + dateTime.Hours = hours; + dateTime.Minutes = minutes; + dateTime.Seconds = seconds; + + return true; +} + +sal_Int32 DateTimeHelper::convertMonthToInt (const OUString& day) +{ + if (day.compareToAscii ("Jan") == 0) + return 1; + else if (day.compareToAscii ("Feb") == 0) + return 2; + else if (day.compareToAscii ("Mar") == 0) + return 3; + else if (day.compareToAscii ("Apr") == 0) + return 4; + else if (day.compareToAscii ("May") == 0) + return 5; + else if (day.compareToAscii ("Jun") == 0) + return 6; + else if (day.compareToAscii ("Jul") == 0) + return 7; + else if (day.compareToAscii ("Aug") == 0) + return 8; + else if (day.compareToAscii ("Sep") == 0) + return 9; + else if (day.compareToAscii ("Oct") == 0) + return 10; + else if (day.compareToAscii ("Nov") == 0) + return 11; + else if (day.compareToAscii ("Dec") == 0) + return 12; + else + return 0; +} + +bool DateTimeHelper::RFC2068_To_DateTime (const OUString& s, + DateTime& dateTime) +{ + sal_Int32 year; + sal_Int32 month; + sal_Int32 day; + sal_Int32 hours; + sal_Int32 minutes; + sal_Int32 seconds; + sal_Char string_month[3 + 1]; + + sal_Int32 found = s.indexOf (','); + if (found != -1) + { + OUString _s = s.copy (found); + const sal_Char* __s = + OUStringToOString (_s, RTL_TEXTENCODING_ASCII_US).getStr (); + + // RFC 1123 + found = sscanf (__s, ", %2d %3s %4d %2d:%2d:%2d GMT", + &day, string_month, &year, + &hours, &minutes, &seconds); + if (found != 6) + { + // RFC 1036 + found = sscanf (__s, ", %2d-%3s-%2d %2d:%2d:%2d GMT", + &day, &string_month, &year, + &hours, &minutes, &seconds); + } + found = (found == 6) ? 1 : 0; + } + else + { + char string_day[3 + 1]; + + const sal_Char* _s = + OUStringToOString (s, RTL_TEXTENCODING_ASCII_US).getStr (); + + // ANSI C's asctime () format + found = sscanf (_s, "%3s %3s %d %2d:%2d:%2d %4d", + string_day, string_month, + &day, + &hours, &minutes, &seconds, + &year); + found = (found == 7) ? 1 : 0; + } + + if (found) + { + month = DateTimeHelper::convertMonthToInt (OUString::createFromAscii (string_month)); + if (month) + { + dateTime.Year = year; + dateTime.Month = month; + dateTime.Day = day; + dateTime.Hours = hours; + dateTime.Minutes = minutes; + dateTime.Seconds = seconds; + } + else + found = 0; + } + + return (found) ? true : false; +} + +bool DateTimeHelper::convert (const OUString& s, DateTime& dateTime) +{ + if (ISO8601_To_DateTime (s, dateTime)) + return true; + else if (RFC2068_To_DateTime (s, dateTime)) + return true; + else + return false; +} + diff --git a/ucb/source/ucp/webdav/DateTimeHelper.hxx b/ucb/source/ucp/webdav/DateTimeHelper.hxx new file mode 100644 index 000000000000..19d0064eaa26 --- /dev/null +++ b/ucb/source/ucp/webdav/DateTimeHelper.hxx @@ -0,0 +1,87 @@ +/************************************************************************* + * + * $RCSfile: DateTimeHelper.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:55:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _WEBDAV_DATETIME_HELPER_HXX +#define _WEBDAV_DATETIME_HELPER_HXX + +namespace webdav_ucp +{ + +class DateTimeHelper +{ +private: + static sal_Int32 convertMonthToInt (const ::rtl::OUString& ); + + static bool ISO8601_To_DateTime (const ::rtl::OUString&, + ::com::sun::star::util::DateTime& ); + + static bool RFC2068_To_DateTime (const ::rtl::OUString&, + ::com::sun::star::util::DateTime& ); + +public: + static bool convert (const ::rtl::OUString&, + ::com::sun::star::util::DateTime& ); +}; + +}; // namespace webdav_ucp + +#endif + diff --git a/ucb/source/ucp/webdav/NeonInputStream.cxx b/ucb/source/ucp/webdav/NeonInputStream.cxx new file mode 100644 index 000000000000..d0d9b67476fb --- /dev/null +++ b/ucb/source/ucp/webdav/NeonInputStream.cxx @@ -0,0 +1,181 @@ +/************************************************************************* + * + * $RCSfile: NeonInputStream.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:55:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#include "NeonInputStream.hxx" + +using namespace cppu; +using namespace rtl; +using namespace com::sun::star::io; +using namespace com::sun::star::uno; +using namespace webdav_ucp; + + +// ------------------------------------------------------------------- +// Constructor +// ------------------------------------------------------------------- +NeonInputStream::NeonInputStream( void ) +{ + mLen = 0; + mPos = 0; +} + +// ------------------------------------------------------------------- +// Destructor +// ------------------------------------------------------------------- +NeonInputStream::~NeonInputStream( void ) +{ +} + +// ------------------------------------------------------------------- +// AddToStream +// Allows the caller to add some data to the "end" of the stream +// ------------------------------------------------------------------- +void NeonInputStream::AddToStream( const char * inBuf, sal_Int32 inLen ) +{ + mInputBuffer += OStringToOUString( OString( inBuf, inLen ), + RTL_TEXTENCODING_UTF8 ); + mLen += inLen; +} + +// ------------------------------------------------------------------- +// queryInterface +// ------------------------------------------------------------------- +Any NeonInputStream::queryInterface( const Type &type ) + throw( RuntimeException ) +{ + Any aRet = ::cppu::queryInterface( type, + SAL_STATIC_CAST( XInputStream*, this ) ); + return (aRet.hasValue() ? aRet : OWeakObject::queryInterface( type )); +} + +// ------------------------------------------------------------------- +// readBytes +// "Reads" the specified number of bytes from the stream and stores +// them in the provided Sequence +// ------------------------------------------------------------------- +sal_Int32 SAL_CALL NeonInputStream::readBytes( + ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) + throw( ::com::sun::star::io::NotConnectedException, + ::com::sun::star::io::BufferSizeExceededException, + ::com::sun::star::io::IOException, + ::com::sun::star::uno::RuntimeException ) +{ + // Work out how much we're actually going to write + sal_Int32 theBytes2Read = nBytesToRead; + sal_Int32 theBytesLeft = mLen - mPos; + if ( theBytes2Read > theBytesLeft ) + theBytes2Read = theBytesLeft; + + // Verify the provided buffer is large enough + sal_Int8 * theBuffer = aData.getArray(); + sal_Int32 theBufferSize = aData.getLength(); + if ( theBytes2Read > theBufferSize ) + throw ::com::sun::star::io::BufferSizeExceededException() ; + + // Write the data + for ( sal_Int32 theIndex = 0; theIndex < theBytes2Read; theIndex ++ ) + theBuffer[ theIndex ] = sal_Int8 ( mInputBuffer[ mPos + theIndex ] ); + + // Update our stream position for next time + mPos += theBytes2Read; + + return theBytes2Read; +} + +// ------------------------------------------------------------------- +// readSomeBytes +// ------------------------------------------------------------------- +sal_Int32 SAL_CALL NeonInputStream::readSomeBytes( + ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) + throw( ::com::sun::star::io::NotConnectedException, + ::com::sun::star::io::BufferSizeExceededException, + ::com::sun::star::io::IOException, + ::com::sun::star::uno::RuntimeException ) +{ + // Warning: What should this be doing ? + return readBytes( aData, nMaxBytesToRead ); +} + +// ------------------------------------------------------------------- +// skipBytes +// Moves the current stream position forward +// ------------------------------------------------------------------- +void SAL_CALL NeonInputStream::skipBytes( sal_Int32 nBytesToSkip ) + throw( ::com::sun::star::io::NotConnectedException, + ::com::sun::star::io::BufferSizeExceededException, + ::com::sun::star::io::IOException, + ::com::sun::star::uno::RuntimeException ) +{ + mPos += nBytesToSkip; + if ( mPos >= mLen ) + mPos = mLen; +} + +// ------------------------------------------------------------------- +// available +// Returns the number of unread bytes currently remaining on the stream +// ------------------------------------------------------------------- +sal_Int32 SAL_CALL NeonInputStream::available( ) + throw( ::com::sun::star::io::NotConnectedException, + ::com::sun::star::io::BufferSizeExceededException, + ::com::sun::star::uno::RuntimeException ) +{ + return mLen - mPos; +} diff --git a/ucb/source/ucp/webdav/NeonInputStream.hxx b/ucb/source/ucp/webdav/NeonInputStream.hxx new file mode 100644 index 000000000000..0235dcffc582 --- /dev/null +++ b/ucb/source/ucp/webdav/NeonInputStream.hxx @@ -0,0 +1,143 @@ +/************************************************************************* + * + * $RCSfile: NeonInputStream.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:55:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _NEONINPUTSTREAM_HXX_ +#define _NEONINPUTSTREAM_HXX_ + +#include <cppuhelper/weak.hxx> +#include <sal/types.h> +#include <rtl/ustring.hxx> +#include <com/sun/star/io/XInputStream.hpp> + + +namespace webdav_ucp +{ + +// ------------------------------------------------------------------- +// NeonInputStream +// A simple XInputStream implementation provided specifically for use +// by the DAVSession::GET method. +// ------------------------------------------------------------------- +class NeonInputStream : public ::com::sun::star::io::XInputStream, + public ::cppu::OWeakObject +{ + private: + ::rtl::OUString mInputBuffer; + sal_Int32 mLen; + sal_Int32 mPos; + + public: + NeonInputStream( void ); + virtual ~NeonInputStream(); + + // Add some data to the end of the stream + void AddToStream( const char * inBuf, sal_Int32 inLen ); + + // XInterface + virtual com::sun::star::uno::Any SAL_CALL queryInterface( + const ::com::sun::star::uno::Type & type ) + throw( ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL acquire( void ) + throw ( ::com::sun::star::uno::RuntimeException ) + { OWeakObject::acquire(); } + + virtual void SAL_CALL release( void ) + throw( ::com::sun::star::uno::RuntimeException ) + { OWeakObject::release(); } + + + // XInputStream + virtual sal_Int32 SAL_CALL readBytes( + ::com::sun::star::uno::Sequence< sal_Int8 > & aData, + sal_Int32 nBytesToRead ) + throw( ::com::sun::star::io::NotConnectedException, + ::com::sun::star::io::BufferSizeExceededException, + ::com::sun::star::io::IOException, + ::com::sun::star::uno::RuntimeException ); + + virtual sal_Int32 SAL_CALL readSomeBytes( + ::com::sun::star::uno::Sequence< sal_Int8 > & aData, + sal_Int32 nMaxBytesToRead ) + throw( ::com::sun::star::io::NotConnectedException, + ::com::sun::star::io::BufferSizeExceededException, + ::com::sun::star::io::IOException, + ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL skipBytes( sal_Int32 nBytesToSkip ) + throw( ::com::sun::star::io::NotConnectedException, + ::com::sun::star::io::BufferSizeExceededException, + ::com::sun::star::io::IOException, + ::com::sun::star::uno::RuntimeException ); + + virtual sal_Int32 SAL_CALL available( void ) + throw( ::com::sun::star::io::NotConnectedException, + ::com::sun::star::io::BufferSizeExceededException, + ::com::sun::star::uno::RuntimeException ); + + virtual void SAL_CALL closeInput( void ) + throw( ::com::sun::star::io::NotConnectedException, + ::com::sun::star::io::IOException, + ::com::sun::star::uno::RuntimeException ) + {}; +}; + +}; // namespace webdav_ucp +#endif // _NEONINPUTSTREAM_HXX_ diff --git a/ucb/source/ucp/webdav/NeonPropFindRequest.cxx b/ucb/source/ucp/webdav/NeonPropFindRequest.cxx new file mode 100644 index 000000000000..249de6adfd92 --- /dev/null +++ b/ucb/source/ucp/webdav/NeonPropFindRequest.cxx @@ -0,0 +1,270 @@ +/************************************************************************* + * + * $RCSfile: NeonPropFindRequest.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:55:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#include "NeonPropFindRequest.hxx" +#include "DAVException.hxx" + +#define ELM_creationdate (1000) +#define ELM_displayname (1001) +#define ELM_getcontentlanguage (1002) +#define ELM_getcontentlength (1003) +#define ELM_getcontenttype (1004) +#define ELM_getetag (1005) +#define ELM_getlastmodified (1006) +#define ELM_lockdiscovery (1007) +#define ELM_resourcetype (1008) +#define ELM_source (1009) +#define ELM_supportedlock (1010) +#define ELM_collection (1011) + +#define GetPropName( s ) OUStringToOString( s, RTL_TEXTENCODING_DONTKNOW ) + +using namespace rtl; +using namespace com::sun::star::beans; +using namespace std; +using namespace webdav_ucp; + + + +const NeonPropFindXmlElem NeonPropFindRequest::sXmlElems[] = +{ + { "DAV:", "creationdate", + ELM_creationdate, HIP_XML_CDATA }, + { "DAV:", "displayname", + ELM_displayname, HIP_XML_CDATA }, + { "DAV:", "getcontentlanguage", + ELM_getcontentlanguage, HIP_XML_CDATA }, + { "DAV:", "getcontentlength", + ELM_getcontentlength, HIP_XML_CDATA }, + { "DAV:", "getcontenttype", + ELM_getcontenttype, HIP_XML_CDATA }, + { "DAV:", "getetag", + ELM_getetag, HIP_XML_CDATA }, + { "DAV:", "getlastmodified", + ELM_getlastmodified, HIP_XML_CDATA }, + { "DAV:", "lockdiscovery", + ELM_lockdiscovery, HIP_XML_CDATA }, + { "DAV:", "resourcetype", + ELM_resourcetype, 0 }, + { "DAV:", "source", + ELM_source, HIP_XML_CDATA }, + { "DAV:", "supportedlock", + ELM_supportedlock, HIP_XML_CDATA }, + { "DAV:", "collection", + ELM_collection, 0 }, + { NULL } +}; + +// ------------------------------------------------------------------- +// Constructor +// ------------------------------------------------------------------- +NeonPropFindRequest::NeonPropFindRequest( HttpSession * inSession, + const char * inPath, + const Depth inDepth, + const vector<OUString> inPropNames, + vector< DAVResource > & ioResources) +{ + // Create a propfind handler + if ( ( mPropFindHandler = dav_propfind_create( inSession, + inPath, + inDepth ) ) == NULL ) + throw DAVException( DAVException::DAV_REQUEST_CREATE ); + + // Setup the Begin and End resource handlers + dav_propfind_set_resource_handlers( mPropFindHandler, + StartResource, + EndResource ); + + // Setup the CheckContext and End element handlers + hip_xml_add_handler( dav_propfind_get_parser( mPropFindHandler ), + sXmlElems, + CheckContext, + NULL, + EndElement, + mPropFindHandler ); + + // Generate the list of properties we're looking for + int thePropCount = inPropNames.size(); + int theRetVal; + if ( thePropCount > 0 ) + { + NeonPropName * thePropNames = new NeonPropName[ thePropCount + 1 ]; + for ( int theIndex = 0; theIndex < thePropCount; theIndex ++ ) + { + thePropNames[ theIndex ].nspace = "DAV:"; + // Warning: Why am I doing a strdup here? + thePropNames[ theIndex ].name = + strdup( GetPropName( inPropNames[ theIndex ] ) ); + } + thePropNames[ theIndex ].nspace = NULL; + thePropNames[ theIndex ].name = NULL; + + // Send the request + theRetVal = dav_propfind_named( mPropFindHandler, + thePropNames, + &ioResources ); + + for ( theIndex = 0; theIndex < thePropCount; theIndex ++ ) + free( (void *)thePropNames[ theIndex ].name ); + delete thePropNames; + } + else + throw DAVException( DAVException::DAV_INVALID_ARG ); + + if ( theRetVal != HTTP_OK ) + throw DAVException( DAVException::DAV_HTTP_ERROR ); +} + +// ------------------------------------------------------------------- +// Destructor +// ------------------------------------------------------------------- +NeonPropFindRequest::~NeonPropFindRequest( ) +{ +} + +// ------------------------------------------------------------------- +// StartResource +// Marks the start of a resource in the server response. +// Adds a DAVResource to the vector supplied at instantiation. +// ------------------------------------------------------------------- +void * NeonPropFindRequest::StartResource( void * inUserData, + const char * inHref ) +{ + DAVResource * theResource = new DAVResource( + OStringToOUString( inHref, RTL_TEXTENCODING_UTF8 ), + false ); + //theResource->uri = OStringToOUString( inHref, RTL_TEXTENCODING_UTF8 ); + vector< DAVResource > * theResources = (vector< DAVResource > * )inUserData; + theResources->push_back( *theResource ); + return theResources; +} + +// ------------------------------------------------------------------- +// EndResource +// Warning: Do we need this? +// ------------------------------------------------------------------- +void NeonPropFindRequest::EndResource( void * inUserData, + void * inResource, + const char * inStatusLine, + const HttpStatus * inHttpStatus, + const char * inDescription ) +{ +} + + +// ------------------------------------------------------------------- +// EndElement +// Marks the end of the current XML element in the server response +// Creates and adds a new PropertyValue to the DAVResource created in +// StartResource. +// ------------------------------------------------------------------- +int NeonPropFindRequest::EndElement( void * inUserData, + const NeonPropFindXmlElem * inXmlElem, + const char * inCdata ) +{ + if ( inXmlElem->id != ELM_resourcetype ) + { + // Create & set the PropertyValue + PropertyValue *thePropertyValue = new PropertyValue; + // Warning: What should Handle be? + thePropertyValue->Handle = 0; + thePropertyValue->State = PropertyState_DIRECT_VALUE; + + if ( inXmlElem->id == ELM_collection ) + { + thePropertyValue->Name = OStringToOUString( "resourcetype", + RTL_TEXTENCODING_UTF8 ); + thePropertyValue->Value <<= OStringToOUString( "collection", + RTL_TEXTENCODING_UTF8 ); + } + else + { + thePropertyValue->Name = OStringToOUString( inXmlElem->name, + RTL_TEXTENCODING_UTF8 ); + thePropertyValue->Value <<= OStringToOUString( inCdata, + RTL_TEXTENCODING_UTF8 ); + } + + + // Get hold of the current DAVResource ( as created in StartResource ) + vector< DAVResource > * theResources = + (vector< DAVResource > * )dav_propfind_get_current_resource( + ( NeonPropFindHandler *)inUserData ); + + // Add the newly created PropertyValue + vector< DAVResource >::iterator theIterator = theResources->end(); + theIterator--; + theIterator->properties.push_back( thePropertyValue ); + } + + return 0; +} + +// ------------------------------------------------------------------- +// CheckContext +// Verify that the current child element is valid given the current +// parent element +// ------------------------------------------------------------------- +int NeonPropFindRequest::CheckContext( NeonPropFindXmlId inChild, + NeonPropFindXmlId inParent ) +{ + //Warning: This should be filled in + return 0; +} diff --git a/ucb/source/ucp/webdav/NeonPropFindRequest.hxx b/ucb/source/ucp/webdav/NeonPropFindRequest.hxx new file mode 100644 index 000000000000..f588c0e52a20 --- /dev/null +++ b/ucb/source/ucp/webdav/NeonPropFindRequest.hxx @@ -0,0 +1,106 @@ +/************************************************************************* + * + * $RCSfile: NeonPropFindRequest.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:55:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _NEONPROPFINDREQUEST_HXX_ +#define _NEONPROPFINDREQUEST_HXX_ + +#include "NeonTypes.hxx" +#include "DAVTypes.hxx" +#include "DAVResource.hxx" +#include <rtl/ustring.hxx> +#include <stl/vector> + +namespace webdav_ucp +{ + +class NeonPropFindRequest +{ + private: + NeonPropFindHandler * mPropFindHandler; + static const NeonPropFindXmlElem sXmlElems[]; + + public: + NeonPropFindRequest( HttpSession * inSession, + const char * inPath, + const Depth inDepth, + const std::vector< ::rtl::OUString > inPropNames, + std::vector< DAVResource > & ioResources ); + + ~NeonPropFindRequest( ); + + private: + static void * StartResource( void * inUserData, const char * inHref ); + static void EndResource( void * inUserData, + void * inResource, + const char * inStatusLine, + const HttpStatus * inHttpStatus, + const char * inDescription ); + + static int EndElement( void * inUserData, + const NeonPropFindXmlElem * inXmlElem, + const char * inCdata ); + + static int CheckContext( NeonPropFindXmlId inChild, + NeonPropFindXmlId inParent ); + +}; + +}; // namespace webdav_ucp +#endif // _NEONPROPFINDREQUEST_HXX_ diff --git a/ucb/source/ucp/webdav/NeonSession.cxx b/ucb/source/ucp/webdav/NeonSession.cxx new file mode 100644 index 000000000000..6912c10e2af2 --- /dev/null +++ b/ucb/source/ucp/webdav/NeonSession.cxx @@ -0,0 +1,543 @@ +/************************************************************************* + * + * $RCSfile: NeonSession.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:55:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#include "NeonSession.hxx" +#include "NeonInputStream.hxx" +#include "NeonPropFindRequest.hxx" +#include "NeonPUTFile.hxx" +#include "NeonUri.hxx" +#include <dav_basic.h> +#include <http_basic.h> + +using namespace rtl; +using namespace com::sun::star::uno; +using namespace com::sun::star::io; +using namespace com::sun::star::ucb; +using namespace webdav_ucp; + +sal_Bool NeonSession::sSockInited = sal_False; + +// ------------------------------------------------------------------- +// Constructor +// ------------------------------------------------------------------- +NeonSession::NeonSession( const OUString & inUri ) +{ + Init(); + NeonUri theUri( inUri ); + + mHostName = *new OString( OUStringToOString( theUri.GetHost(), + RTL_TEXTENCODING_UTF8 ) ); + mPort = theUri.GetPort(); + + + mHttpSession = CreateSession( mHostName, + theUri.GetPort() ); + if ( mHttpSession == NULL ) + throw DAVException( DAVException::DAV_SESSION_CREATE ); + + // Note: Uncomment the following if locking support is required + /* + mNeonLockSession = dav_lock_register( mHttpSession ); + + if ( mNeonLockSession == NULL ) + throw DAVException( DAVException::DAV_SESSION_CREATE ); + */ +} + +// ------------------------------------------------------------------- +// Destructor +// ------------------------------------------------------------------- +NeonSession::~NeonSession( ) +{ + DAVSessionFactory::ReleaseDAVSession( this ); + + if ( mHttpSession != NULL ) + { + http_session_destroy( mHttpSession ); + mHttpSession = NULL; + // Note: Uncomment the following if locking support is required + /* + if ( mNeonLockSession != NULL ) + { + dav_lock_unregister( mNeonLockSession ); + mNeonLockSession = NULL; + } + */ + } +} + +sal_Bool NeonSession::CanUse( const OUString & inUri ) +{ + sal_Bool IsConnected = sal_False; + NeonUri theUri( inUri ); + if ( theUri.GetPort() == mPort && + OUStringToOString( theUri.GetHost(), RTL_TEXTENCODING_UTF8 ) == + mHostName ) + IsConnected = sal_True; + return IsConnected; +} + +void NeonSession::setServerAuthListener(DAVAuthListener * inDAVAuthListener) +{ + if ( inDAVAuthListener != NULL ) + { + mListener = inDAVAuthListener; + http_set_server_auth( mHttpSession, NeonAuth, this ); + } +} + +void NeonSession::setProxyAuthListener(DAVAuthListener * inDAVAuthListener) +{ + // Note: Content is currently not using proxy auth +} +// ------------------------------------------------------------------- +// PROPFIND +// ------------------------------------------------------------------- +void NeonSession::PROPFIND( const OUString & inUri, + const Depth inDepth, + const std::vector< OUString > & inPropNames, + std::vector< DAVResource > & ioResources, + const com::sun::star::uno::Reference< + com::sun::star::ucb::XCommandEnvironment >& inEnv ) + throw ( DAVException ) +{ + osl::Guard< osl::Mutex > theGuard( mMutex ); + + mEnv = inEnv; + + NeonUri theUri( inUri ); + NeonPropFindRequest theRequest( mHttpSession, + OUStringToOString( theUri.GetPath(), + RTL_TEXTENCODING_UTF8 ), + inDepth, + inPropNames, + ioResources ); +} + +// ------------------------------------------------------------------- +// GET +// ------------------------------------------------------------------- +Reference< XInputStream > NeonSession::GET( const OUString & inUri, + const com::sun::star::uno::Reference< + com::sun::star::ucb::XCommandEnvironment >& inEnv ) + throw ( DAVException ) +{ + osl::Guard< osl::Mutex > theGuard( mMutex ); + + mEnv = inEnv; + + NeonUri theUri( inUri ); + NeonInputStream * theInputStream = new NeonInputStream; + int theRetVal = http_read_file( mHttpSession, + OUStringToOString( theUri.GetPath(), + RTL_TEXTENCODING_UTF8 ), + GETReader, + theInputStream ); + + if ( theRetVal != HTTP_OK ) + throw DAVException( DAVException::DAV_HTTP_ERROR ); + + return theInputStream; +} + +// ------------------------------------------------------------------- +// GET +// ------------------------------------------------------------------- +void NeonSession::GET( const OUString & inUri, + Reference< XOutputStream > & ioOutputStream, + const com::sun::star::uno::Reference< + com::sun::star::ucb::XCommandEnvironment >& inEnv ) + throw ( DAVException ) +{ + osl::Guard< osl::Mutex > theGuard( mMutex ); + + mEnv = inEnv; + + NeonUri theUri( inUri ); + int theRetVal = http_read_file( mHttpSession, + OUStringToOString( theUri.GetPath(), + RTL_TEXTENCODING_UTF8 ), + GETWriter, + &ioOutputStream ); + + if ( theRetVal != HTTP_OK ) + throw DAVException( DAVException::DAV_HTTP_ERROR ); +} + +// ------------------------------------------------------------------- +// PUT +// ------------------------------------------------------------------- +void NeonSession::PUT( const OUString & inUri, + Reference< XInputStream > & inInputStream, + const com::sun::star::uno::Reference< + com::sun::star::ucb::XCommandEnvironment >& inEnv ) + throw ( DAVException ) +{ + osl::Guard< osl::Mutex > theGuard( mMutex ); + + mEnv = inEnv; + + NeonUri theUri( inUri ); + NeonPUTFile thePUTFile( inInputStream ); + int theRetVal = http_put( mHttpSession, + OUStringToOString( theUri.GetPath(), + RTL_TEXTENCODING_UTF8 ), + thePUTFile.GetFILE() ); + thePUTFile.Remove(); + + if ( theRetVal != HTTP_OK ) + throw DAVException( DAVException::DAV_HTTP_ERROR ); +} + +// ------------------------------------------------------------------- +// MKCOL +// ------------------------------------------------------------------- +void NeonSession::MKCOL( const OUString & inUri, + const com::sun::star::uno::Reference< + com::sun::star::ucb::XCommandEnvironment >& inEnv ) + throw ( DAVException ) +{ + osl::Guard< osl::Mutex > theGuard( mMutex ); + + mEnv = inEnv; + + NeonUri theUri( inUri ); + int theRetVal = dav_mkcol( mHttpSession, + OUStringToOString( theUri.GetPath(), + RTL_TEXTENCODING_UTF8 ) ); + + if ( theRetVal != HTTP_OK ) + throw DAVException( DAVException::DAV_HTTP_ERROR ); +} + +// ------------------------------------------------------------------- +// COPY +// ------------------------------------------------------------------- +void NeonSession::COPY( const OUString & inSource, + const OUString & inDestination, + const com::sun::star::uno::Reference< + com::sun::star::ucb::XCommandEnvironment >& inEnv, + sal_Bool inOverWrite ) + throw ( DAVException ) +{ + osl::Guard< osl::Mutex > theGuard( mMutex ); + + mEnv = inEnv; + + NeonUri theSourceUri( inSource ); + NeonUri theDestinationUri( inDestination ); + + int theRetVal = dav_copy( mHttpSession, + inOverWrite ? 1 : 0, + OUStringToOString( theSourceUri.GetPath(), + RTL_TEXTENCODING_UTF8 ), + OUStringToOString( theDestinationUri.GetPath(), + RTL_TEXTENCODING_UTF8 ) ); + + + if ( theRetVal != HTTP_OK ) + throw DAVException( DAVException::DAV_HTTP_ERROR ); +} + +// ------------------------------------------------------------------- +// MOVE +// ------------------------------------------------------------------- +void NeonSession::MOVE( const OUString & inSource, + const OUString & inDestination, + const com::sun::star::uno::Reference< + com::sun::star::ucb::XCommandEnvironment >& inEnv, + sal_Bool inOverWrite ) + throw ( DAVException ) +{ + osl::Guard< osl::Mutex > theGuard( mMutex ); + + mEnv = inEnv; + + NeonUri theSourceUri( inSource ); + NeonUri theDestinationUri( inDestination ); + int theRetVal = dav_move( mHttpSession, + inOverWrite ? 1 : 0, + OUStringToOString( theSourceUri.GetPath(), + RTL_TEXTENCODING_UTF8 ), + OUStringToOString( theDestinationUri.GetPath(), + RTL_TEXTENCODING_UTF8 ) ); + + if ( theRetVal != HTTP_OK ) + throw DAVException( DAVException::DAV_HTTP_ERROR ); +} + + +// ------------------------------------------------------------------- +// DESTROY +// ------------------------------------------------------------------- +void NeonSession::DESTROY( const OUString & inUri, + const com::sun::star::uno::Reference< + com::sun::star::ucb::XCommandEnvironment >& inEnv ) + throw ( DAVException ) +{ + osl::Guard< osl::Mutex > theGuard( mMutex ); + + mEnv = inEnv; + + NeonUri theUri( inUri ); + int theRetVal = dav_delete( mHttpSession, + OUStringToOString( theUri.GetPath(), + RTL_TEXTENCODING_UTF8 ) ); + + if ( theRetVal != HTTP_OK ) + throw DAVException( DAVException::DAV_HTTP_ERROR ); +} + +// ------------------------------------------------------------------- +// LOCK +// ------------------------------------------------------------------- +// Note: Uncomment the following if locking support is required +/* +void NeonSession::LOCK( const Lock & inLock, + const com::sun::star::uno::Reference< + com::sun::star::ucb::XCommandEnvironment >& inEnv ) + throw ( DAVException ) +{ + mEnv = inEnv; + + Lockit( inLock, true ); +} +*/ + +// ------------------------------------------------------------------- +// UNLOCK +// ------------------------------------------------------------------- +// Note: Uncomment the following if locking support is required +/* +void NeonSession::UNLOCK( const Lock & inLock, + const com::sun::star::uno::Reference< + com::sun::star::ucb::XCommandEnvironment >& inEnv ) + throw ( DAVException ) +{ + Lockit( inLock, false ); +} +*/ + +// ------------------------------------------------------------------- +// Init +// Initialises "Neon sockets" +// ------------------------------------------------------------------- +void NeonSession::Init( void ) +{ + if ( sSockInited == sal_False ) + { + if ( sock_init() != 0 ) + throw DAVException( DAVException::DAV_SESSION_CREATE ); + sSockInited = sal_True; + } +} + +// ------------------------------------------------------------------- +// CreateSession +// Creates a new neon session. +// ------------------------------------------------------------------- +HttpSession * NeonSession::CreateSession( const char * inHost, + int inPort ) +{ + if ( inHost == NULL || inPort <= 0 ) + throw DAVException( DAVException::DAV_INVALID_ARG ); + + HttpSession * theHttpSession; + if ( ( theHttpSession = http_session_create() ) == NULL ) + throw DAVException( DAVException::DAV_SESSION_CREATE ); + + if ( http_session_server( theHttpSession, inHost, inPort ) != HTTP_OK ) + { + http_session_destroy( theHttpSession ); + throw DAVException( DAVException::DAV_HTTP_LOOKUP ); + } + + return theHttpSession; +} + +// ------------------------------------------------------------------- +// GETReader +// A simple Neon http_block_reader for use with a http GET method +// in conjunction with an XInputStream +// ------------------------------------------------------------------- +void NeonSession::GETReader( void * inUserData, + const char * inBuf, + size_t inLen ) +{ + NeonInputStream * theInputStream = ( NeonInputStream *) inUserData; + theInputStream->AddToStream( inBuf, inLen ); +} + +// ------------------------------------------------------------------- +// GETWriter +// A simple Neon http_block_reader for use with a http GET method +// in conjunction with an XOutputStream +// ------------------------------------------------------------------- +void NeonSession::GETWriter( void * inUserData, + const char * inBuf, + size_t inLen ) +{ + Reference< XOutputStream > * theOutputStreamPtr = + ( Reference< XOutputStream > *) inUserData; + Reference< XOutputStream > theOutputStream = *theOutputStreamPtr; + + const Sequence< sal_Int8 > theSequence( ( sal_Int8 *) inBuf, inLen ); + theOutputStream->writeBytes( theSequence ); +} + +// Note: Uncomment the following if locking support is required +/* +void NeonSession::Lockit( const Lock & inLock, bool inLockit ) +{ + osl::Guard< osl::Mutex > theGuard( mMutex ); + + // Create the neon lock + NeonLock * theLock = new NeonLock; + int theRetVal; + + // Set the lock uri + NeonUri theUri( inLock.uri ); + theLock->uri = const_cast< char * > + ( OUStringToOString( theUri.GetPath(), RTL_TEXTENCODING_UTF8 ).getStr() ); + + if ( inLockit ) + { + // Set the lock depth + switch( inLock.depth ) + { + case ZERO: + case INFINITY: + theLock->depth = int ( inLock.depth ); + break; + default: + throw DAVException( DAVException::DAV_INVALID_ARG ); + break; + } + + // Set the lock scope + switch ( inLock.scope ) + { + case EXCLUSIVE: + theLock->scope = dav_lockscope_exclusive; + break; + case SHARED: + theLock->scope = dav_lockscope_shared; + break; + default: + throw DAVException( DAVException::DAV_INVALID_ARG ); + break; + } + + // Set the lock owner + const char * theOwner = + OUStringToOString( inLock.owner, RTL_TEXTENCODING_UTF8 ); + theLock->owner = const_cast< char * > ( theOwner ); + + // Set the lock timeout + // Note: Neon ignores the timeout + //theLock->timeout = inLock.timeout; + + theRetVal = dav_lock( mHttpSession, theLock ); + } + else + { + + // Set the lock token + OUString theToken = inLock.locktoken.getConstArray()[ 0 ]; + theLock->token = const_cast< char * > + ( OUStringToOString( theToken, RTL_TEXTENCODING_UTF8 ).getStr() ); + + theRetVal = dav_unlock( mHttpSession, theLock ); + } + + if ( theRetVal != HTTP_OK ) + throw DAVException( DAVException::DAV_HTTP_ERROR ); +} +*/ + +int NeonSession::NeonAuth( void * inUserData, + const char * inRealm, + const char * inHostName, + char ** inUserName, + char ** inPassWord ) +{ + NeonSession * theSession = ( NeonSession * )inUserData; + OUStringBuffer theUserNameBuffer; + OUStringBuffer thePassWordBuffer; + + int theRetVal = theSession->mListener->authenticate( + OUString::createFromAscii( inRealm ), + OUString::createFromAscii( inHostName ), + theUserNameBuffer, + thePassWordBuffer, + theSession->mEnv ); + + OUString theUserName = theUserNameBuffer.makeStringAndClear(); + OString *theStr = new OString( OUStringToOString( theUserName, + RTL_TEXTENCODING_UTF8 ) ); + inUserName[0] = const_cast< char *> ( theStr->getStr() ); + + OUString thePassWord = thePassWordBuffer.makeStringAndClear(); + theStr = new OString( OUStringToOString( thePassWord, + RTL_TEXTENCODING_UTF8 ) ); + inPassWord[0] = const_cast< char *> ( theStr->getStr() ); + + return theRetVal; +} diff --git a/ucb/source/ucp/webdav/NeonSession.hxx b/ucb/source/ucp/webdav/NeonSession.hxx new file mode 100644 index 000000000000..72e2c6b6fcb4 --- /dev/null +++ b/ucb/source/ucp/webdav/NeonSession.hxx @@ -0,0 +1,202 @@ +/************************************************************************* + * + * $RCSfile: NeonSession.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:55:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _NEONSESSION_HXX_ +#define _NEONSESSION_HXX_ + +#include "DAVSession.hxx" +#include "NeonTypes.hxx" +#include <osl/mutex.hxx> +#include <stl/vector> + +namespace webdav_ucp +{ + +// ------------------------------------------------------------------- +// NeonSession +// A DAVSession implementation using the neon/expat library +// ------------------------------------------------------------------- +class NeonSession : public DAVSession +{ + private: + osl::Mutex mMutex; + HttpSession * mHttpSession; + rtl::OString mHostName; + sal_Int32 mPort; + + // Authentication stuff + DAVAuthListener *mListener; + com::sun::star::uno::Reference< + com::sun::star::ucb::XCommandEnvironment > mEnv; + + + // Note: Uncomment the following if locking support is required + // NeonLockSession * mNeonLockSession; + + static sal_Bool sSockInited; + + public: + NeonSession( const rtl::OUString & inUri ); + virtual ~NeonSession( ); + + + // DAVSession methods + virtual sal_Bool CanUse( const ::rtl::OUString & inUri ); + + virtual void setServerAuthListener(DAVAuthListener * inDAVAuthListener); + virtual void setProxyAuthListener(DAVAuthListener * inDAVAuthListener); + + virtual void PROPFIND( const ::rtl::OUString & inUri, + const Depth inDepth, + const std::vector< ::rtl::OUString >& inPropNames, + std::vector< DAVResource > & ioResources, + const com::sun::star::uno::Reference< + com::sun::star::ucb::XCommandEnvironment >& inEnv ) + throw( DAVException ); + + virtual com::sun::star::uno::Reference< com::sun::star::io::XInputStream > + GET( const ::rtl::OUString & inUri, + const com::sun::star::uno::Reference< + com::sun::star::ucb::XCommandEnvironment >& inEnv ) + throw( DAVException ); + + virtual void GET( const ::rtl::OUString & inUri, + com::sun::star::uno::Reference< + com::sun::star::io::XOutputStream > & ioOutputStream, + const com::sun::star::uno::Reference< + com::sun::star::ucb::XCommandEnvironment >& inEnv ) + throw( DAVException ); + + + virtual void PUT( const ::rtl::OUString & inUri, + com::sun::star::uno::Reference< + com::sun::star::io::XInputStream > & inInputStream, + const com::sun::star::uno::Reference< + com::sun::star::ucb::XCommandEnvironment >& inEnv ) + throw( DAVException ); + + virtual void MKCOL( const ::rtl::OUString & inUri, + const com::sun::star::uno::Reference< + com::sun::star::ucb::XCommandEnvironment >& inEnv ) + throw( DAVException ); + + virtual void COPY( const ::rtl::OUString & inSource, + const ::rtl::OUString & inDestination, + const com::sun::star::uno::Reference< + com::sun::star::ucb::XCommandEnvironment >& inEnv, + sal_Bool inOverWrite ) + throw( DAVException ); + + virtual void MOVE( const ::rtl::OUString & inSource, + const ::rtl::OUString & inDestination, + const com::sun::star::uno::Reference< + com::sun::star::ucb::XCommandEnvironment >& inEnv, + sal_Bool inOverWrite ) + throw( DAVException ); + + virtual void DESTROY( const ::rtl::OUString & inUri, + const com::sun::star::uno::Reference< + com::sun::star::ucb::XCommandEnvironment >& inEnv ) + throw( DAVException ); + + // Note: Uncomment the following if locking support is required + /* + virtual void LOCK (const Lock & inLock, + const com::sun::star::uno::Reference< + com::sun::star::ucb::XCommandEnvironment >& inEnv ) + throw ( DAVException ); + + virtual void UNLOCK (const Lock & inLock, + const com::sun::star::uno::Reference< + com::sun::star::ucb::XCommandEnvironment >& inEnv ) + throw ( DAVException ); + */ + + private: + // Initialise "Neon sockets" + void Init( void ); + + // Create a Neon session for server at supplied host & port + HttpSession * CreateSession( const char * inHostName, int inPort ); + + // A simple Neon http_block_reader for use with a http GET method + // in conjunction with an XInputStream + static void GETReader( void * inUserData, + const char * inBuf, + size_t inLen ); + + // A simple Neon http_block_reader for use with a http GET method + // in conjunction with an XOutputStream + static void GETWriter( void * inUserData, + const char * inBuf, + size_t inLen ); + + // Note: Uncomment the following if locking support is required + // void Lockit( const Lock & inLock, bool inLockit ); + + static int NeonAuth( void * inUserData, + const char * inRealm, + const char * inHostName, + char ** inUserName, + char ** inPassWord ); +}; + +}; // namespace_ucp +#endif // _NEONSESSION_HXX_ diff --git a/ucb/source/ucp/webdav/NeonTypes.hxx b/ucb/source/ucp/webdav/NeonTypes.hxx new file mode 100644 index 000000000000..7cc3615cdfa4 --- /dev/null +++ b/ucb/source/ucp/webdav/NeonTypes.hxx @@ -0,0 +1,90 @@ +/************************************************************************* + * + * $RCSfile: NeonTypes.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:55:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _NEONTYPES_HXX_ +#define _NEONTYPES_HXX_ + +#if STLPORT_VERSION < 321 +#include <tools/presys.h> +#include <vector.h> +#include <tools/postsys.h> +#else +#include <vector> +#endif // STLPORT_VERSION < 321 + +#ifdef _USE_NO_NAMERSPACES_ +#define std +#endif + +#include <http_request.h> +#include <dav_props.h> +#include <uri.h> + +typedef http_session HttpSession; +typedef http_req HttpRequest; +typedef http_status HttpStatus; + +typedef dav_propfind_handler NeonPropFindHandler; +typedef dav_propname NeonPropName; +typedef struct hip_xml_elm NeonPropFindXmlElem; +typedef hip_xml_elmid NeonPropFindXmlId; + +// Note: Uncomment the following if locking support is required +#endif _NEONTYPES_HXX_ diff --git a/ucb/source/ucp/webdav/NeonUri.cxx b/ucb/source/ucp/webdav/NeonUri.cxx new file mode 100644 index 000000000000..c7a8ce593726 --- /dev/null +++ b/ucb/source/ucp/webdav/NeonUri.cxx @@ -0,0 +1,141 @@ +/************************************************************************* + * + * $RCSfile: NeonUri.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:55:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include "NeonUri.hxx" +#include "DAVException.hxx" + +using namespace rtl; +using namespace webdav_ucp; + + +uri NeonUri::sUriDefaults = { "http", NULL, DEFAULT_HTTP_PORT, NULL }; + +// ------------------------------------------------------------------- +// Constructor +// ------------------------------------------------------------------- +NeonUri::NeonUri( const OUString & inUri ) +{ + if ( inUri.getLength() <= 0 ) + throw DAVException( DAVException::DAV_INVALID_ARG ); + + OString theInputUri ( + inUri.getStr(), inUri.getLength(), RTL_TEXTENCODING_UTF8); + + uri theUri; + if ( uri_parse( theInputUri.getStr(), &theUri, &sUriDefaults ) != 0 ) + { + uri_free( &theUri ); + throw DAVException( DAVException::DAV_INVALID_ARG ); + } + + mScheme = OStringToOUString( theUri.scheme, RTL_TEXTENCODING_UTF8 ); + mHostName = OStringToOUString( theUri.host, RTL_TEXTENCODING_UTF8 ); + mPort = theUri.port; + mPath = OStringToOUString( theUri.path, RTL_TEXTENCODING_UTF8 ); + + calculateURI (); +} + +// ------------------------------------------------------------------- +// Destructor +// ------------------------------------------------------------------- +NeonUri::~NeonUri( ) +{ +} + +void NeonUri::calculateURI () +{ + mURI = mScheme; + mURI += OUString::createFromAscii ("://"); + mURI += mHostName; + mURI += OUString::createFromAscii (":"); + mURI += OUString::valueOf (mPort); + mURI += mPath; +} + +::rtl::OUString NeonUri::GetPathBaseName () const +{ + sal_Int32 nPos = mPath.lastIndexOf ('/'); + if (nPos == mPath.getLength () - 1) + { + // Trailing slash found. Skip. + nPos = mPath.lastIndexOf ('/', nPos); + } + if (nPos != -1) + return mPath.copy (nPos + 1, mPath.getLength () - nPos - 1); + else + return OUString::createFromAscii ("/"); +} + +::rtl::OUString NeonUri::GetPathDirName () const +{ + sal_Int32 nPos = mPath.lastIndexOf ('/'); + if (nPos == mPath.getLength () - 1) + { + // Trailing slash found. Skip. + nPos = mPath.lastIndexOf ('/', nPos); + } + if (nPos != -1) + return mPath.copy (0, nPos + 1); + else + return OUString::createFromAscii ("/"); +} + diff --git a/ucb/source/ucp/webdav/NeonUri.hxx b/ucb/source/ucp/webdav/NeonUri.hxx new file mode 100644 index 000000000000..8a8dc6f47851 --- /dev/null +++ b/ucb/source/ucp/webdav/NeonUri.hxx @@ -0,0 +1,117 @@ +/************************************************************************* + * + * $RCSfile: NeonUri.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:55:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#ifndef _NEONURI_HXX_ +#define _NEONURI_HXX_ + +#include <uri.h> +#include <rtl/ustring.hxx> + +namespace webdav_ucp +{ + +#define DEFAULT_HTTP_PORT 80 + +// ------------------------------------------------------------------- +// NeonUri +// A URI implementation for use with the neon/expat library +// ------------------------------------------------------------------- +class NeonUri +{ + private: + ::rtl::OUString mURI; + ::rtl::OUString mScheme; + ::rtl::OUString mHostName; + sal_Int32 mPort; + ::rtl::OUString mPath; + static uri sUriDefaults; + + void calculateURI (); + + public: + NeonUri( const ::rtl::OUString & inUri ); + ~NeonUri( ); + + const ::rtl::OUString & GetHostName( void ) const + { return mHostName; }; + const ::rtl::OUString & GetURI( void ) const + { return mURI; }; + const ::rtl::OUString & GetScheme( void ) const + { return mScheme; }; + const ::rtl::OUString & GetHost( void ) const + { return mHostName; }; + sal_Int32 GetPort( void ) const + { return mPort; }; + const ::rtl::OUString & GetPath( void ) const + { return mPath; }; + + ::rtl::OUString GetPathBaseName ( void ) const; + ::rtl::OUString GetPathDirName ( void ) const; + + + void SetScheme (const ::rtl::OUString& scheme) + { mScheme = scheme; calculateURI (); }; + + void AppendPath (const ::rtl::OUString& path) + { mPath += path; calculateURI (); }; +}; + +}; // namespace webdav_ucp +#endif // _NEONURI_HXX_ diff --git a/ucb/source/ucp/webdav/exports.map b/ucb/source/ucp/webdav/exports.map new file mode 100644 index 000000000000..73671aa97840 --- /dev/null +++ b/ucb/source/ucp/webdav/exports.map @@ -0,0 +1,8 @@ +DAV_1_0 { + global: + component_getImplementationEnvironment; + component_writeInfo; + component_getFactory; + local: + *; +}; diff --git a/ucb/source/ucp/webdav/makefile.mk b/ucb/source/ucp/webdav/makefile.mk new file mode 100644 index 000000000000..9b1289d714de --- /dev/null +++ b/ucb/source/ucp/webdav/makefile.mk @@ -0,0 +1,169 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1 $ +# +# last change: $Author: kso $ $Date: 2000-10-16 14:55:20 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (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.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* + +# UCP Version - Increase, if UCP libraray becomes incompatible. +UCP_VERSION=1 + +# Name for the UCP. Will become part of the library name (See below). +UCP_NAME=dav + +# Relative path to project root. +PRJ = ..$/..$/.. + +# Project Name. +PRJNAME=ucb + +TARGET=ucp$(UCP_NAME) + +ENABLE_EXCEPTIONS=TRUE +USE_DEFFILE=TRUE +NO_BSYMBOLIC=TRUE + +# --- Settings --------------------------------------------------------- + +.INCLUDE: svpre.mk +.INCLUDE: settings.mk +.INCLUDE: sv.mk + +NEONINCDIR=external$/neon +CFLAGS+= -I$(SOLARINCDIR)$/$(NEONINCDIR) + +# --- General ----------------------------------------------------- + +# @@@ Add own files here. +SLOFILES=\ + $(SLO)$/webdavservices.obj \ + $(SLO)$/webdavprovider.obj \ + $(SLO)$/webdavcontent.obj \ + $(SLO)$/webdavcontentcaps.obj \ + $(SLO)$/webdavresultset.obj \ + $(SLO)$/webdavdatasupplier.obj \ + $(SLO)$/DAVProperties.obj \ + $(SLO)$/DAVResource.obj \ + $(SLO)$/DAVSessionFactory.obj \ + $(SLO)$/NeonUri.obj \ + $(SLO)$/NeonInputStream.obj \ + $(SLO)$/NeonPropFindRequest.obj \ + $(SLO)$/NeonPUTFile.obj \ + $(SLO)$/NeonSession.obj \ + $(SLO)$/authinteraction.obj \ + $(SLO)$/DateTimeHelper.obj + +# NETBSD: somewhere we have to instantiate the static data members. +# NETBSD-1.2.1 doesn't know about weak symbols so the default mechanism for GCC won't work. +# SCO and MACOSX: the linker does know about weak symbols, but we can't ignore multiple defined symbols +.IF "$(OS)"=="NETBSD" || "$(OS)"=="SCO" || "$(OS)$(COM)"=="OS2GCC" || "$(OS)"=="MACOSX" +SLOFILES+=$(SLO)$/staticmbwebdav.obj +.ENDIF + +LIB1TARGET=$(SLB)$/_$(TARGET).lib +LIB1OBJFILES=$(SLOFILES) + +# --- Shared-Library --------------------------------------------------- + +SHL1TARGET=$(TARGET)$(UCP_VERSION) +SHL1IMPLIB=i$(TARGET) +SHL1VERSIONMAP=exports.map + +# @@@ Add additional libs here. + +# EXPATASCII3RDLIB is first available in src599c... + +.IF "$(EXPATASCII3RDLIB)" == "" + +.IF "$(GUI)" == "UNX" +EXPATASCII3RDLIB=-lascii_expat_xmlparse -lexpat_xmltok +.ENDIF # unx + +.IF "$(GUI)" == "WNT" +EXPATASCII3RDLIB=ascii_expat_xmlparse.lib expat_xmltok.lib +.ENDIF # wnt + +.ENDIF # EXPATASCII3RDLIB + +SHL1STDLIBS=\ + $(CPPUHELPERLIB) \ + $(CPPULIB) \ + $(SALLIB) \ + $(VOSLIB) \ + $(UCBHELPERLIB) \ + $(NEON3RDLIB) \ + $(EXPATASCII3RDLIB) + +.IF "$(GUI)"=="WNT" +SHL1STDLIBS+= wsock32.lib +.ENDIF + +SHL1DEF=$(MISC)$/$(SHL1TARGET).def +SHL1LIBS=$(LIB1TARGET) + +# --- Def-File --------------------------------------------------------- + +DEF1NAME=$(SHL1TARGET) +DEF1EXPORTFILE=exports.dxp + +DEF1DES=UCB WebDAV Content Provider + +# --- Targets ---------------------------------------------------------- + +.INCLUDE: target.mk + diff --git a/ucb/source/ucp/webdav/webdavcontent.cxx b/ucb/source/ucp/webdav/webdavcontent.cxx new file mode 100644 index 000000000000..1a8a6bef9759 --- /dev/null +++ b/ucb/source/ucp/webdav/webdavcontent.cxx @@ -0,0 +1,1574 @@ +/************************************************************************* + * + * $RCSfile: webdavcontent.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:55:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +/************************************************************************** + TODO + ************************************************************************** + + *************************************************************************/ + + + +#ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HPP_ +#include <com/sun/star/beans/PropertyAttribute.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_XPROPERTYACCESS_HPP_ +#include <com/sun/star/beans/XPropertyAccess.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_ +#include <com/sun/star/sdbc/XRow.hpp> +#endif +#ifndef _COM_SUN_STAR_UTIL_DATETIME_HPP_ +#include <com/sun/star/util/DateTime.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_CONTENTINFOATTRIBUTE_HPP_ +#include <com/sun/star/ucb/ContentInfoAttribute.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_OPENCOMMANDARGUMENT2_HPP_ +#include <com/sun/star/ucb/OpenCommandArgument2.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_INSERTCOMMANDARGUMENT_HPP_ +#include <com/sun/star/ucb/InsertCommandArgument.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_TRANSFERINFO_HPP_ +#include <com/sun/star/ucb/TransferInfo.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_NAMECLASH_HPP_ +#include <com/sun/star/ucb/NameClash.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCOMMANDINFO_HPP_ +#include <com/sun/star/ucb/XCommandInfo.hpp> +#endif +#ifndef _COM_SUN_STAR_IO_XOUTPUTSTREAM_HPP_ +#include <com/sun/star/io/XOutputStream.hpp> +#endif +#ifndef _COM_SUN_STAR_IO_XACTIVEDATASINK_HPP_ +#include <com/sun/star/io/XActiveDataSink.hpp> +#endif + +#ifndef _COM_SUN_STAR_UCB_XPERSISTENTPROPERTYSET_HPP_ +#include <com/sun/star/ucb/XPersistentPropertySet.hpp> +#endif +#ifndef _VOS_DIAGNOSE_HXX_ +#include <vos/diagnose.hxx> +#endif +#ifndef _UCBHELPER_CONTENTIDENTIFIER_HXX +#include <ucbhelper/contentidentifier.hxx> +#endif +#ifndef _UCBHELPER_PROPERTYVALUESET_HXX +#include <ucbhelper/propertyvalueset.hxx> +#endif + +#ifndef _WEBDAV_UCP_CONTENT_HXX +#include "webdavcontent.hxx" +#endif +#ifndef _WEBDAV_UCP_PROVIDER_HXX +#include "webdavprovider.hxx" +#endif +#ifndef _WEBDAV_UCP_RESULTSET_HXX +#include "webdavresultset.hxx" +#endif + +#ifndef _WEBDAV_SESSION_HXX +#include "DAVSession.hxx" +#endif + +#ifndef _WEBDAV_UCP_AUTHINTERACTION_HXX +#include "authinteraction.hxx" +#endif + +#include "DateTimeHelper.hxx" + +#include "NeonUri.hxx" + +using namespace com::sun::star::container; +using namespace com::sun::star::beans; +using namespace com::sun::star::util; +using namespace com::sun::star::lang; +using namespace com::sun::star::sdbc; +using namespace com::sun::star::ucb; +using namespace com::sun::star::uno; +using namespace com::sun::star::io; +using namespace cppu; +using namespace rtl; + +using namespace webdav_ucp; + +class AuthListener : public DAVAuthListener +{ + virtual int authenticate(const ::rtl::OUString & inRealm, + const ::rtl::OUString & inHostName, + ::rtl::OUStringBuffer & inUserName, + ::rtl::OUStringBuffer & inPassWord, + const com::sun::star::uno::Reference< + com::sun::star::ucb::XCommandEnvironment >& Environment) + { + if ( Environment.is() ) { + Reference< com::sun::star::task::XInteractionHandler > xIH + = Environment->getInteractionHandler(); + if ( xIH.is() ) { + xIH->handle(new InteractionRequest_Impl(inHostName,inRealm,inUserName,inPassWord)); + } + } + return 0; + } +} webdavAuthListener; + + +void ContentProperties::setValues(DAVResource& resource) +{ + + // title + OUString aURL = resource.uri; + sal_Int32 nPos = aURL.lastIndexOf( '/' ); + sal_Int32 nEnd = aURL.getLength(); + + if ( nPos == ( aURL.getLength() - 1 ) ) { + // Trailing slash found. Skip. + nPos = aURL.lastIndexOf( '/', nPos ); + nEnd--; + } + if ( nPos != -1 ) { + aTitle = aURL.copy( nPos+1, nEnd-nPos-1 ); + } + + // other required properties (default values) + getcontenttype = OUString::createFromAscii( WEBDAV_CONTENT_TYPE ); + bIsDocument = sal_True; + bIsFolder = sal_False; + + std::vector< com::sun::star::beans::PropertyValue* >::iterator it; + for ( it=resource.properties.begin(); it!=resource.properties.end(); ++it) { + if ( (*it) == 0 ) { + continue; + } + + if ( (*it)->Name.equals(DAVProperties::CREATIONDATE) ) { + (*it)->Value >>= creationdate; + + // Map the DAV:creationdate to UCP:DateCreated + // + DateTimeHelper::convert (creationdate, dateCreated); + } + else if ( (*it)->Name.equals(DAVProperties::DISPLAYNAME) ) { + (*it)->Value >>= displayname; + } + else if ( (*it)->Name.equals(DAVProperties::GETCONTENTLANGUAGE) ) { + (*it)->Value >>= getcontentlanguage; + } + else if ( (*it)->Name.equals(DAVProperties::GETCONTENTLENGTH) ) { + (*it)->Value >>= getcontentlength; + + // Map the DAV:getcontentlength to UCP:Size + // + size = getcontentlength.toInt64 (); + } + else if ( (*it)->Name.equals(DAVProperties::GETCONTENTTYPE) ) { + (*it)->Value >>= getcontenttype; + } + else if ( (*it)->Name.equals(DAVProperties::GETETAG) ) { + (*it)->Value >>= getetag; + } + else if ( (*it)->Name.equals(DAVProperties::GETLASTMODIFIED) ) { + (*it)->Value >>= getlastmodified; + + // Map the DAV:getlastmodified to UCP:DateModified + // + DateTimeHelper::convert (getlastmodified, dateModified); + } + else if ( (*it)->Name.equals(DAVProperties::LOCKDISCOVERY) ) { + (*it)->Value >>= lockdiscovery; + } + else if ( (*it)->Name.equals(DAVProperties::RESOURCETYPE) ) { + (*it)->Value >>= resourcetype; + if (resourcetype.getLength()>0) { + bIsDocument = sal_False; + bIsFolder = sal_True; + } + } + else if ( (*it)->Name.equals(DAVProperties::SOURCE) ) { + (*it)->Value >>= source; + } + else if ( (*it)->Name.equals(DAVProperties::SUPPORTEDLOCK) ) { + (*it)->Value >>= supportedlock; + } + } +} + + +//========================================================================= +//========================================================================= +// +// Content Implementation. +// +//========================================================================= +//========================================================================= + + +//========================================================================= +// ctr for content on an existing webdav resource +Content::Content( const Reference< XMultiServiceFactory >& rxSMgr, + ::ucb::ContentProviderImplHelper* pProvider, + const Reference< XContentIdentifier >& Identifier ) + throw ( ContentCreationException ) + : ContentImplHelper( rxSMgr, pProvider, Identifier ) +{ + _transient = sal_False; + _upToDate = sal_False; + initpath(); + + try { + // set the webdav session + _pWebdavSession = DAVSessionFactory::createDAVSession(m_xIdentifier->getContentIdentifier()); + _pWebdavSession->setServerAuthListener(&webdavAuthListener); + } + catch (DAVException e) { + VOS_ENSURE( sal_False, "createDAVSession : DAVException" ); + throw ContentCreationException(); + } + + if ( ! update( Reference< XCommandEnvironment >() ) ) { + // may have failed because of authentification + // throw CommandAbortedException(); + } + +} + + +//========================================================================= +// ctr for content on an non-existing webdav resource +Content::Content( const Reference< XMultiServiceFactory >& rxSMgr, + ::ucb::ContentProviderImplHelper* pProvider, + const Reference< XContentIdentifier >& Identifier, + ::vos::ORef< DAVSession > pSession, + sal_Bool isCollection) + throw ( ContentCreationException ) + : ContentImplHelper( rxSMgr, pProvider, Identifier, sal_False ) +{ + _transient = sal_True; + _upToDate = sal_False; + _pWebdavSession = pSession; + + initpath(); + + // this is not an existing Content, let's set some props anyway ... + + if (isCollection) { + m_aProps.bIsDocument = sal_False; + m_aProps.bIsFolder = sal_True; + } + else { + m_aProps.bIsDocument = sal_True; + m_aProps.bIsFolder = sal_False; + } + +} + +//========================================================================= +// init dav server and path +void Content::initpath() + throw ( ContentCreationException ) +{ + OUString aURL = m_xIdentifier->getContentIdentifier(); + + // webdavscheme://user@host:port/path + sal_Int32 indexOfSecondSlash = aURL.indexOf('/',WEBDAV_URL_SCHEME_LENGTH+2); + sal_Int32 indexOfThirdSlash = aURL.indexOf('/',indexOfSecondSlash+1); + if (indexOfThirdSlash==-1) { + VOS_ENSURE( sal_False, "No third '/' in URL " ); + throw ContentCreationException(); + } + + _path = aURL.copy(indexOfThirdSlash); + +} + +//========================================================================= +// init dav server and path +sal_Bool Content::update(const Reference< XCommandEnvironment >& Environment) +{ + std::vector< DAVResource > resources; + try { + // properties initialization + std::vector< OUString > propertyNames; + propertyNames.push_back(DAVProperties::CREATIONDATE); + propertyNames.push_back(DAVProperties::DISPLAYNAME); + propertyNames.push_back(DAVProperties::GETCONTENTLANGUAGE); + propertyNames.push_back(DAVProperties::GETCONTENTLENGTH); + propertyNames.push_back(DAVProperties::GETCONTENTTYPE); + propertyNames.push_back(DAVProperties::GETETAG); + propertyNames.push_back(DAVProperties::GETLASTMODIFIED); + propertyNames.push_back(DAVProperties::LOCKDISCOVERY); + propertyNames.push_back(DAVProperties::RESOURCETYPE); + propertyNames.push_back(DAVProperties::SOURCE); + // propertyNames.push_back(DAVProperties::SUPPORTEDLOCK); + + _pWebdavSession->PROPFIND (_path,ZERO,propertyNames,resources, Environment); + } + catch (DAVException e) { + VOS_ENSURE( sal_False, "PROPFIND : DAVException" ); + return sal_False; + } + + if (resources.size()!=1) { + return sal_False; + } + + m_aProps.setValues(resources[0]); + _upToDate = sal_True; + return sal_True; +} + +//========================================================================= +// virtual +Content::~Content() +{ +} + +//========================================================================= +// +// XInterface methods. +// +//========================================================================= + +// virtual +void SAL_CALL Content::acquire() + throw( RuntimeException ) +{ + ContentImplHelper::acquire(); +} + +//========================================================================= +// virtual +void SAL_CALL Content::release() + throw( RuntimeException ) +{ + ContentImplHelper::release(); +} + +//========================================================================= +// virtual +Any SAL_CALL Content::queryInterface( const Type & rType ) + throw ( RuntimeException ) +{ + Any aRet; + + if ( isFolder() ) + aRet = cppu::queryInterface( rType, + static_cast< XContentCreator * >( this ) ); + + return aRet.hasValue() ? aRet : ContentImplHelper::queryInterface( rType ); +} + + +//========================================================================= +// +// XTypeProvider methods. +// +//========================================================================= + +XTYPEPROVIDER_COMMON_IMPL( Content ); + +//========================================================================= +// virtual +Sequence< Type > SAL_CALL Content::getTypes() + throw( RuntimeException ) +{ + static OTypeCollection* pCollection = NULL; + + if ( !pCollection ) + { + osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() ); + if ( !pCollection ) + { + if ( isFolder() ) + { + static OTypeCollection aCollection( + CPPU_TYPE_REF( XTypeProvider ), + CPPU_TYPE_REF( XServiceInfo ), + CPPU_TYPE_REF( XComponent ), + CPPU_TYPE_REF( XContent ), + CPPU_TYPE_REF( XCommandProcessor ), + CPPU_TYPE_REF( XPropertiesChangeNotifier ), + CPPU_TYPE_REF( XCommandInfoChangeNotifier ), + CPPU_TYPE_REF( XPropertyContainer ), + CPPU_TYPE_REF( XPropertySetInfoChangeNotifier ), + CPPU_TYPE_REF( XChild ), + CPPU_TYPE_REF( XContentCreator ) ); // !! + pCollection = &aCollection; + } + else + { + static OTypeCollection aCollection( + CPPU_TYPE_REF( XTypeProvider ), + CPPU_TYPE_REF( XServiceInfo ), + CPPU_TYPE_REF( XComponent ), + CPPU_TYPE_REF( XContent ), + CPPU_TYPE_REF( XCommandProcessor ), + CPPU_TYPE_REF( XPropertiesChangeNotifier ), + CPPU_TYPE_REF( XCommandInfoChangeNotifier ), + CPPU_TYPE_REF( XPropertyContainer ), + CPPU_TYPE_REF( XPropertySetInfoChangeNotifier ), + CPPU_TYPE_REF( XChild ) ); + pCollection = &aCollection; + } + } + } + + return (*pCollection).getTypes(); +} + +//========================================================================= +// +// XServiceInfo methods. +// +//========================================================================= + +// virtual +OUString SAL_CALL Content::getImplementationName() + throw( RuntimeException ) +{ + return OUString::createFromAscii( "WebDAV_ucp_Content" ); +} + +//========================================================================= +// virtual +Sequence< OUString > SAL_CALL Content::getSupportedServiceNames() + throw( RuntimeException ) +{ + Sequence< OUString > aSNS( 1 ); + aSNS.getArray()[ 0 ] + = OUString::createFromAscii( WEBDAV_CONTENT_SERVICE_NAME ); + return aSNS; +} + +//========================================================================= +// +// XContent methods. +// +//========================================================================= + +// virtual +OUString SAL_CALL Content::getContentType() + throw( RuntimeException ) +{ + return m_aProps.getcontenttype; +} + +//========================================================================= +// +// XCommandProcessor methods. +// +//========================================================================= + +// virtual +Any SAL_CALL Content::execute( const Command& aCommand, + sal_Int32 CommandId, + const Reference< + XCommandEnvironment >& Environment ) + throw( Exception, CommandAbortedException, RuntimeException ) +{ + Any aRet; + + if ( !_transient && !_upToDate ) { + // initialisation for content created by the provider + if ( ! update(Environment) ) { + throw CommandAbortedException(); + } + } + + // fprintf (stderr, "\nCOMMAND : "); + // fprintf (stderr, OUStringToOString( aCommand.Name, RTL_TEXTENCODING_ASCII_US ) ); + // fprintf (stderr, "\n"); + + if ( aCommand.Name.compareToAscii( "getPropertyValues" ) == 0 ) + { + ////////////////////////////////////////////////////////////////// + // getPropertyValues + ////////////////////////////////////////////////////////////////// + + Sequence< Property > Properties; + if ( !( aCommand.Argument >>= Properties ) ) + { + VOS_ENSURE( sal_False, "Wrong argument type!" ); + return Any(); + } + + aRet <<= getPropertyValues( Properties ); + } + else if ( aCommand.Name.compareToAscii( "setPropertyValues" ) == 0 ) + { + ////////////////////////////////////////////////////////////////// + // setPropertyValues + ////////////////////////////////////////////////////////////////// + + Sequence< PropertyValue > aProperties; + if ( !( aCommand.Argument >>= aProperties ) ) + { + VOS_ENSURE( sal_False, "Wrong argument type!" ); + return Any(); + } + + if ( !aProperties.getLength() ) + { + VOS_ENSURE( sal_False, "No properties!" ); + return Any(); + } + + setPropertyValues( aProperties ); + } + else if ( aCommand.Name.compareToAscii( "getPropertySetInfo" ) == 0 ) + { + ////////////////////////////////////////////////////////////////// + // getPropertySetInfo + ////////////////////////////////////////////////////////////////// + + // Note: Implemented by base class. + aRet <<= getPropertySetInfo(); + } + else if ( aCommand.Name.compareToAscii( "getCommandInfo" ) == 0 ) + { + ////////////////////////////////////////////////////////////////// + // getCommandInfo + ////////////////////////////////////////////////////////////////// + + // Note: Implemented by base class. + aRet <<= getCommandInfo(); + } + else if ( aCommand.Name.compareToAscii( "open" ) == 0 ) + { + ////////////////////////////////////////////////////////////////// + // open command + ////////////////////////////////////////////////////////////////// + + OpenCommandArgument2 aOpenCommand; + if ( aCommand.Argument >>= aOpenCommand ) + { + if (isFolder()) { + std::vector< DAVResource >* pResources = new std::vector< DAVResource >; + getChildrenResources(*pResources, Environment); + Reference< XDynamicResultSet > xSet + = new DynamicResultSet( m_xSMgr, this, aOpenCommand, pResources ); + aRet <<= xSet; + } + else { + OUString aURL = m_xIdentifier->getContentIdentifier(); + Reference< XOutputStream > xOut + = Reference< XOutputStream >(aOpenCommand.Sink, UNO_QUERY ); + if (xOut.is()) + { + // PUSH: write data + try { + _pWebdavSession->GET(_path, xOut, Environment); + } catch (DAVException e) { + VOS_ENSURE( sal_False, "GET : DAVException" ); + throw CommandAbortedException(); + } + } + else + { Reference< XActiveDataSink > xDataSink + = Reference< XActiveDataSink >(aOpenCommand.Sink, UNO_QUERY ); + if (xDataSink.is()) + { + // PULL: wait for client read + try { + Reference< XInputStream > xIn =_pWebdavSession->GET(_path, Environment); + xDataSink->setInputStream(xIn); + } catch (DAVException e) { + VOS_ENSURE( sal_False, "GET : DAVException" ); + throw CommandAbortedException(); + } + } + else + { + VOS_ENSURE( sal_False, + "Content::execute - invalid parameter!" ); + throw CommandAbortedException(); + } + } + } + } + else + { + VOS_ENSURE( sal_False, + "Content::execute - invalid parameter!" ); + throw CommandAbortedException(); + } + } + else if ( aCommand.Name.compareToAscii( "insert" ) == 0 ) + { + ////////////////////////////////////////////////////////////////// + // insert + ////////////////////////////////////////////////////////////////// + + InsertCommandArgument arg; + aCommand.Argument >>= arg; + insert(arg.Data,arg.ReplaceExisting, Environment); + } + else if ( + ( aCommand.Name.compareToAscii( "delete" ) == 0 ) + || ( aCommand.Name.compareToAscii( "DELETE" ) == 0 ) + ) + { + ////////////////////////////////////////////////////////////////// + // delete + ////////////////////////////////////////////////////////////////// + + sal_Bool bDeletePhysical = sal_False; + aCommand.Argument >>= bDeletePhysical; + +// KSO: Ignore parameter and destroy the content, if you don't support +// putting objects into trashcan. ( Since we do not have a trash can +// service yet (src603), you actually have no other coice. ) +// if (bDeletePhysical){ + try { + _pWebdavSession->DESTROY (_path, Environment); + } catch (DAVException e) { + VOS_ENSURE( sal_False, "DELETE : DAVException" ); + throw CommandAbortedException(); + } +// } + destroy( bDeletePhysical ); + } + /* + else if (aCommand.Name.compareToAscii( "transfer" ) == 0) + { + // This command transfers (copies/moves) an object from one location + // to another. It must be executed at the folder content representing + // the destination of the transfer operation. + + // This is opposite of the WebDAV COPY/MOVE methods + // They operate on the source not the target + // + // COPY /container/index.html HTTP/1.1 + // Host: www.foo.bar + // Desitnation: http://www.foo.bar/othercontainer + // Depth: Infinity + // + // @@@@ Does the TransferInfo::SourceURL have + // the same scheme as this content + // + // @@@@ Does the TransferInfo::SourceURL have + // the same host + // + // If the latter is true we can use the same + // DAV session. If not we either have to create + // a temporary new DAV session for the host source + // in question or obtain content for the source + // + + // DELETE, COPY and MOVE are not atomic operations, + // unless the 'overwrite' option is set to false. + // Thus a WebDAV server will return a multi-status + // for the method in question saying what resource + // failed to be deleted, copied or moved. + // It is assumed that the operation is completely + // successful since the DAVSession interface does + // not yet return multi-status responses to these + // commands + // + + if (!isFolder()) + { + throw CommandAbortedException(); + } + + TransferInfo transferArgs; + aCommand.Argument >>= transferArgs; + + if (transferArgs.NameClash == NameClash::KEEP | + transferArgs.NameClash == NameClash::RENAME ) + { + throw CommandAbortedException(); + + // @@@ RENAME and KEEP are not directly implemented + // by WebDAV methods + } + + // @@@ This implementation of 'transfer' only works + // if the source and target are the same scheme + // and the same host + // + // In addition just like 'delete' it assumes that + // if the DAV method succeeded then all resources + // were deleted, which is not the case with a + // multi-status response + // + // Overwrite is always set to false regardless of + // NameClass value + + + try + { + NeonUri sourceURI (transferArgs.SourceURL); + NeonUri targetURI (m_xIdentifier->getContentIdentifier()); + + // Check for same scheme + // + if (sourceURI.GetScheme ().getLength () && + sourceURI.GetScheme () != targetURI.GetScheme () != 0) + { + throw CommandAbortedException(); + } + // Check for same host + // + if (sourceURI.GetHost ().getLength () && + sourceURI.GetHost () != targetURI.GetHost ()) + { + throw CommandAbortedException(); + } + + if (!transferArgs.NewTitle.getLength ()) + { + transferArgs.NewTitle = sourceURI.GetPathBaseName (); + } + + if (transferArgs.NewTitle.compareToAscii ("/") == 0) + { + throw CommandAbortedException(); + } + + targetURI.SetScheme (OUString::createFromAscii ("http")); + targetURI.AppendPath (transferArgs.NewTitle); + + if (transferArgs.MoveData == true) + { + _pWebdavSession->MOVE (sourceURI.GetPath (), targetURI.GetURI (), Environment); + // @@@ Should check for resources that could not be moved + // (due to source access or target overwrite) and send + // this information through the interaction handler. + + // @@@ Existing content should be checked to see if it needs + // to be deleted at the source + + // @@@ Existing content should be checked to see if it has + // been overwritten at the target + + // @@@ Delete source content + } + else + { + _pWebdavSession->COPY (sourceURI.GetPath (), targetURI.GetURI (), Environment); + // @@@ Should check for resources that could not be copied + // (due to source access or target overwrite) and send + // this information through the interaction handler + + // @@@ Existing content should be checked to see if it has + // been overwritten at the target + } + } + catch (DAVException& e) + { + throw CommandAbortedException(); + } + } + */ + /* + else if ( aCommand.Name.compareToAscii( "COPY" ) == 0 ) + { + ////////////////////////////////////////////////////////////////// + // COPY + ////////////////////////////////////////////////////////////////// + + OUString destination; + aCommand.Argument >>= destination; + try { + _pWebdavSession->COPY (_path, destination, Environment); + } catch (DAVException e) { + VOS_ENSURE( sal_False, "COPY : DAVException" ); + throw CommandAbortedException(); + } + // synchronize destination ? + } + else if ( aCommand.Name.compareToAscii( "MOVE" ) == 0 ) + { + ////////////////////////////////////////////////////////////////// + // MOVE + ////////////////////////////////////////////////////////////////// + + OUString destination; + aCommand.Argument >>= destination; + try { + _pWebdavSession->MOVE (_path, destination, Environment); + } catch (DAVException e) { + VOS_ENSURE( sal_False, "MOVE : DAVException" ); + throw CommandAbortedException(); + } + // synchronize destination ? + } + */ + else + { + ////////////////////////////////////////////////////////////////// + // Unknown command + ////////////////////////////////////////////////////////////////// + + VOS_ENSURE( sal_False, + "Content::execute - unknown command!" ); + throw CommandAbortedException(); + } + + return aRet; +} + +//========================================================================= +// virtual +void SAL_CALL Content::abort( sal_Int32 CommandId ) + throw( RuntimeException ) +{ + // @@@ Implement logic to abort running commands, if this makes + // sense for your content. +} + + +//========================================================================= +// +// XContentCreator methods. +// +//========================================================================= + +// virtual +Sequence< ContentInfo > SAL_CALL +Content::queryCreatableContentsInfo() + throw( RuntimeException ) +{ + if ( isFolder() ) + { + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + + Sequence< ContentInfo > aSeq( 2 ); + + // document. + aSeq.getArray()[ 0 ].Type + = OUString::createFromAscii( WEBDAV_CONTENT_TYPE ); + aSeq.getArray()[ 0 ].Attributes + = ContentInfoAttribute::INSERT_WITH_INPUTSTREAM; + + Sequence< Property > aDocProps( 1 ); + aDocProps.getArray()[ 0 ] = Property( + OUString::createFromAscii( "Title" ), + -1, + getCppuType( static_cast< rtl::OUString* >( 0 ) ), + PropertyAttribute::MAYBEVOID + | PropertyAttribute::BOUND ); + aSeq.getArray()[ 0 ].Properties = aDocProps; + + // folder. + aSeq.getArray()[ 1 ].Type + = OUString::createFromAscii( WEBDAV_COLLECTION_TYPE ); + aSeq.getArray()[ 1 ].Attributes = 0; + + Sequence< Property > aFolderProps( 1 ); + aFolderProps.getArray()[ 0 ] = Property( + OUString::createFromAscii( "Title" ), + -1, + getCppuType( static_cast< rtl::OUString* >( 0 ) ), + PropertyAttribute::MAYBEVOID + | PropertyAttribute::BOUND ); + aSeq.getArray()[ 1 ].Properties = aFolderProps; + return aSeq; + } + else + { + VOS_ENSURE( sal_False, + "queryCreatableContentsInfo called on non-folder object!" ); + + return Sequence< ContentInfo >( 0 ); + } +} + +//========================================================================= +// virtual +Reference< XContent > SAL_CALL Content::createNewContent( const ContentInfo& Info ) + throw( RuntimeException ) +{ + if ( isFolder() ) + { + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + + if ( !Info.Type.getLength() ) + return Reference< XContent >(); + + if ( ( Info.Type.compareToAscii( WEBDAV_COLLECTION_TYPE ) != 0 ) + && + ( Info.Type.compareToAscii( WEBDAV_CONTENT_TYPE ) != 0 ) ) + return Reference< XContent >(); + + + OUString aURL = m_xIdentifier->getContentIdentifier(); + + VOS_ENSURE( aURL.getLength() > 0, + "WebdavContent::createNewContent - empty identifier!" ); + + if ( ( aURL.lastIndexOf( '/' ) + 1 ) != aURL.getLength() ) + aURL += OUString::createFromAscii( "/" ); + + sal_Bool isCollection; + if ( Info.Type.compareToAscii( WEBDAV_COLLECTION_TYPE ) == 0 ) { + aURL += OUString::createFromAscii( "New_Collection" ); + isCollection = sal_True; + } + else { + aURL += OUString::createFromAscii( "New_Content" ); + isCollection = sal_False; + } + +// fprintf ( stderr, "new Content URL : " ); +// fprintf ( stderr, OUStringToOString( aURL, RTL_TEXTENCODING_ASCII_US ) ); +// fprintf ( stderr, "\n" ); + Reference< XContentIdentifier > xId( new ::ucb::ContentIdentifier( m_xSMgr, aURL ) ); + + // create the local content + try { + return new ::webdav_ucp::Content( m_xSMgr, + m_xProvider.getBodyPtr(), + xId, + _pWebdavSession, + isCollection); + } + catch (ContentCreationException e ) { + return Reference< XContent >(); + } + } + else + { + VOS_ENSURE( sal_False, "createNewContent called on non-folder object!" ); + return Reference< XContent >(); + } +} + +//========================================================================= +// virtual +OUString Content::getParentURL() +{ + OUString aURL = m_xIdentifier->getContentIdentifier(); + + sal_Int32 nPos = aURL.lastIndexOf( '/' ); + + if ( nPos == ( aURL.getLength() - 1 ) ) + { + // Trailing slash found. Skip. + nPos = aURL.lastIndexOf( '/', nPos ); + } + + if ( nPos != -1 ) + { + OUString aParentURL = aURL.copy( 0, nPos+1 ); + return aParentURL; + } + + return OUString(); +} + + +//========================================================================= +// +// Non-interface methods. +// +//========================================================================= + + + +//========================================================================= +// static +Reference< XRow > Content::getPropertyValues( + const Reference< XMultiServiceFactory >& rSMgr, + const Sequence< Property >& rProperties, + const ContentProperties& rData, + const vos::ORef< ucb::ContentProviderImplHelper >& rProvider, + const OUString& rContentId ) +{ + // Note: Empty sequence means "get values of all supported properties". + + vos::ORef< ::ucb::PropertyValueSet > xRow + = new ::ucb::PropertyValueSet( rSMgr ); + + sal_Int32 nCount = rProperties.getLength(); + if ( nCount ) + { + Reference< XPropertySet > xAdditionalPropSet; + sal_Bool bTriedToGetAdditonalPropSet = sal_False; + + const Property* pProps = rProperties.getConstArray(); + for ( sal_Int32 n = 0; n < nCount; ++n ) + { + const Property& rProp = pProps[ n ]; + + // Process Core properties. + + if ( rProp.Name.compareToAscii( "ContentType" ) == 0 ) { + xRow->appendString( rProp, rData.getcontenttype ); + } + else if ( rProp.Name.compareToAscii( "Title" ) == 0 ) + { + xRow->appendString ( rProp, rData.aTitle ); + } + else if ( rProp.Name.compareToAscii( "IsDocument" ) == 0 ) + { + xRow->appendBoolean( rProp, rData.bIsDocument ); + } + else if ( rProp.Name.compareToAscii( "IsFolder" ) == 0 ) + { + xRow->appendBoolean( rProp, rData.bIsFolder ); + } + else if ( rProp.Name.compareToAscii( "Size" ) == 0 ) + { + xRow->appendLong( rProp, rData.size ); + } + else if ( rProp.Name.compareToAscii( "DateCreated" ) == 0 ) + { + xRow->appendTimestamp( rProp, rData.dateCreated ); + } + else if ( rProp.Name.compareToAscii( "DateModified" ) == 0 ) + { + xRow->appendTimestamp( rProp, rData.dateModified ); + } + else if ( rProp.Name.equals(DAVProperties::CREATIONDATE) ) { + xRow->appendString( rProp, rData.creationdate ); + } + else if ( rProp.Name.equals(DAVProperties::DISPLAYNAME) ) { + xRow->appendString( rProp, rData.displayname ); + } + else if ( rProp.Name.equals(DAVProperties::GETCONTENTLANGUAGE) ) { + xRow->appendString( rProp, rData.getcontentlanguage ); + } + else if ( rProp.Name.equals(DAVProperties::GETCONTENTLENGTH) ) { + xRow->appendString( rProp, rData.getcontentlength ); + } + else if ( rProp.Name.equals(DAVProperties::GETCONTENTTYPE) ) { + xRow->appendString( rProp, rData.getcontenttype ); + } + else if ( rProp.Name.equals(DAVProperties::GETETAG) ) { + xRow->appendString( rProp, rData.getetag ); + } + else if ( rProp.Name.equals(DAVProperties::GETLASTMODIFIED) ) { + xRow->appendString( rProp, rData.getlastmodified ); + } + else if ( rProp.Name.equals(DAVProperties::LOCKDISCOVERY) ) { + xRow->appendString( rProp, rData.lockdiscovery ); + } + else if ( rProp.Name.equals(DAVProperties::RESOURCETYPE) ) { + xRow->appendString( rProp, rData.resourcetype ); + } + else if ( rProp.Name.equals(DAVProperties::SOURCE) ) { + xRow->appendString( rProp, rData.source ); + } + else if ( rProp.Name.equals(DAVProperties::SUPPORTEDLOCK) ) { + xRow->appendString( rProp, rData.supportedlock ); + } + else + { + // @@@ Note: If your data source supports adding/removing + // properties, you should implement the interface + // XPropertyContainer by yourself and supply your own + // logic here. The base class uses the service + // "com.sun.star.ucb.Store" to maintain Additional Core + // properties. But using server functionality is preferred! + + // Not a Core Property! Maybe it's an Additional Core Property?! + + if ( !bTriedToGetAdditonalPropSet && !xAdditionalPropSet.is() ) + { + xAdditionalPropSet + = Reference< XPropertySet >( + rProvider->getAdditionalPropertySet( rContentId, + sal_False ), + UNO_QUERY ); + bTriedToGetAdditonalPropSet = sal_True; + } + + if ( xAdditionalPropSet.is() ) + { + if ( !xRow->appendPropertySetValue( + xAdditionalPropSet, + rProp ) ) + { + // Append empty entry. + xRow->appendVoid( rProp ); + } + } + else + { + // Append empty entry. + xRow->appendVoid( rProp ); + } + } + } + } + else + { + // Append all Core Properties. + xRow->appendString ( + Property( OUString::createFromAscii( "ContentType" ), + -1, + getCppuType( static_cast< const OUString * >( 0 ) ), + PropertyAttribute::BOUND | PropertyAttribute::READONLY ), + rData.getcontenttype ); + xRow->appendString ( + Property( OUString::createFromAscii( "Title" ), + -1, + getCppuType( static_cast< const OUString * >( 0 ) ), + PropertyAttribute::BOUND ), + rData.aTitle ); + xRow->appendBoolean( + Property( OUString::createFromAscii( "IsDocument" ), + -1, + getCppuBooleanType(), + PropertyAttribute::BOUND | PropertyAttribute::READONLY ), + rData.bIsDocument ); + xRow->appendBoolean( + Property( OUString::createFromAscii( "IsFolder" ), + -1, + getCppuBooleanType(), + PropertyAttribute::BOUND | PropertyAttribute::READONLY ), + rData.bIsFolder ); + xRow->appendLong( + Property( OUString::createFromAscii( "Size" ), + -1, + getCppuType( static_cast< const sal_Int64 * >( 0 ) ), + PropertyAttribute::BOUND | PropertyAttribute::READONLY ), + rData.size ); + xRow->appendTimestamp( + Property( OUString::createFromAscii( "DateCreated" ), + -1, + getCppuType( static_cast< const DateTime * >( 0 ) ), + PropertyAttribute::BOUND | PropertyAttribute::READONLY ), + rData.dateCreated ); + xRow->appendTimestamp( + Property( OUString::createFromAscii( "DateModified" ), + -1, + getCppuType( static_cast< const DateTime * >( 0 ) ), + PropertyAttribute::BOUND | PropertyAttribute::READONLY ), + rData.dateModified ); + xRow->appendString ( + Property( DAVProperties::CREATIONDATE , + -1, + getCppuType( static_cast< const OUString * >( 0 ) ), + PropertyAttribute::BOUND ), + rData.creationdate ); + xRow->appendString ( + Property( DAVProperties::DISPLAYNAME , + -1, + getCppuType( static_cast< const OUString * >( 0 ) ), + PropertyAttribute::BOUND ), + rData.displayname ); + xRow->appendString ( + Property( DAVProperties::GETCONTENTLANGUAGE , + -1, + getCppuType( static_cast< const OUString * >( 0 ) ), + PropertyAttribute::BOUND ), + rData.getcontentlanguage ); + xRow->appendString ( + Property( DAVProperties::GETCONTENTLENGTH , + -1, + getCppuType( static_cast< const OUString * >( 0 ) ), + PropertyAttribute::BOUND ), + rData.getcontentlength ); + xRow->appendString ( + Property( DAVProperties::GETCONTENTTYPE , + -1, + getCppuType( static_cast< const OUString * >( 0 ) ), + PropertyAttribute::BOUND ), + rData.getcontenttype ); + xRow->appendString ( + Property( DAVProperties::GETETAG , + -1, + getCppuType( static_cast< const OUString * >( 0 ) ), + PropertyAttribute::BOUND ), + rData.getetag ); + xRow->appendString ( + Property( DAVProperties::GETLASTMODIFIED , + -1, + getCppuType( static_cast< const OUString * >( 0 ) ), + PropertyAttribute::BOUND ), + rData.getlastmodified ); + xRow->appendString ( + Property( DAVProperties::LOCKDISCOVERY , + -1, + getCppuType( static_cast< const OUString * >( 0 ) ), + PropertyAttribute::BOUND ), + rData.lockdiscovery ); + xRow->appendString ( + Property( DAVProperties::RESOURCETYPE , + -1, + getCppuType( static_cast< const OUString * >( 0 ) ), + PropertyAttribute::BOUND ), + rData.resourcetype ); + xRow->appendString ( + Property( DAVProperties::SOURCE , + -1, + getCppuType( static_cast< const OUString * >( 0 ) ), + PropertyAttribute::BOUND ), + rData.source ); + xRow->appendString ( + Property( DAVProperties::SUPPORTEDLOCK , + -1, + getCppuType( static_cast< const OUString * >( 0 ) ), + PropertyAttribute::BOUND ), + rData.supportedlock ); + + + + + // @@@ Append other properties supported directly. + + // @@@ Note: If your data source supports adding/removing + // properties, you should implement the interface + // XPropertyContainer by yourself and supply your own + // logic here. The base class uses the service + // "com.sun.star.ucb.Store" to maintain Additional Core + // properties. But using server functionality is preferred! + + // Append all Additional Core Properties. + + Reference< XPropertySet > xSet( + rProvider->getAdditionalPropertySet( rContentId, sal_False ), + UNO_QUERY ); + xRow->appendPropertySet( xSet ); + } + + return Reference< XRow >( xRow.getBodyPtr() ); +} + +//========================================================================= +Reference< XRow > Content::getPropertyValues( const Sequence< Property >& rProperties ) +{ + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + return getPropertyValues( m_xSMgr, + rProperties, + m_aProps, + m_xProvider, + m_xIdentifier->getContentIdentifier() ); +} + +//========================================================================= +void Content::setPropertyValues( const Sequence< PropertyValue >& rValues ) +{ + osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex ); + + Sequence< PropertyChangeEvent > aChanges( rValues.getLength() ); + sal_Int32 nChanged = 0; + + PropertyChangeEvent aEvent; + aEvent.Source = static_cast< OWeakObject * >( this ); + aEvent.Further = sal_False; + // aEvent.PropertyName = + aEvent.PropertyHandle = -1; + // aEvent.OldValue = + // aEvent.NewValue = + + const PropertyValue* pValues = rValues.getConstArray(); + sal_Int32 nCount = rValues.getLength(); + + Reference< XPersistentPropertySet > xAdditionalPropSet; + sal_Bool bTriedToGetAdditonalPropSet = sal_False; + + for ( sal_Int32 n = 0; n < nCount; ++n ) + { + const PropertyValue& rValue = pValues[ n ]; + + if ( rValue.Name.compareToAscii( "ContentType" ) == 0 ) + { + // Read-only property! + } + else if ( rValue.Name.compareToAscii( "IsDocument" ) == 0 ) + { + // Read-only property! + } + else if ( rValue.Name.compareToAscii( "IsFolder" ) == 0 ) + { + // Read-only property! + } + else if ( rValue.Name.compareToAscii( "Title" ) == 0 ) + { + //only allowed if the state is TRANSIENT (after a createNewContent and before a insert + if (_transient) { + OUString aNewValue; + if ( rValue.Value >>= aNewValue ) + { + if ( aNewValue != m_aProps.aTitle ) + { + osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex ); + m_aProps.aTitle = aNewValue; + + aGuard.clear(); + + aEvent.PropertyName = rValue.Name; + aEvent.OldValue = makeAny( m_aProps.aTitle ); + aEvent.NewValue = makeAny( aNewValue ); + + aChanges.getArray()[ nChanged ] = aEvent; + nChanged++; + } + } + } + } + } + + if ( nChanged > 0 ) + { + // @@@ Save changes. + //@@@ storeData(); + + aGuard.clear(); + aChanges.realloc( nChanged ); + notifyPropertiesChange( aChanges ); + } +} + + +//========================================================================= +void Content::queryChildren(ContentRefList& rChildren ) +{ + // Obtain a list with a snapshot of all currently instanciated contents + // from provider and extract the contents which are direct children + // of this content. + + ::ucb::ContentRefList aAllContents; + m_xProvider->queryExistingContents( aAllContents ); + + OUString aURL = m_xIdentifier->getContentIdentifier(); + sal_Int32 nPos = aURL.lastIndexOf( '/' ); + + if ( nPos != ( aURL.getLength() - 1 ) ) + { + // No trailing slash found. Append. + aURL += OUString::createFromAscii( "/" ); + } + + sal_Int32 nLen = aURL.getLength(); + + ::ucb::ContentRefList::const_iterator it = aAllContents.begin(); + ::ucb::ContentRefList::const_iterator end = aAllContents.end(); + + while ( it != end ) + { + ::ucb::ContentImplHelperRef xChild = (*it); + OUString aChildURL = xChild->getIdentifier()->getContentIdentifier(); + + // Is aURL a prefix of aChildURL? + if ( ( aChildURL.getLength() > nLen ) && + ( aChildURL.compareTo( aURL, nLen ) == 0 ) ) + { + sal_Int32 nPos = nLen; + nPos = aChildURL.indexOf( '/', nPos ); + + if ( ( nPos == -1 ) || + ( nPos == ( aChildURL.getLength() - 1 ) ) ) + { + // No further slashes / only a final slash. It's a child! + rChildren.push_back( + ::webdav_ucp::Content::ContentRef( + static_cast< ::webdav_ucp::Content * >( + xChild.getBodyPtr() ) ) ); + } + } + ++it; + } +} + +//========================================================================= +void Content::insert(Reference<XInputStream> xInputStream, + sal_Bool bReplaceExisting, + const Reference< XCommandEnvironment >& Environment) + throw( CommandAbortedException ) +{ + osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex ); + + // Check, if all required properties were set. + // aTitle + // IsFolder + + if ( m_aProps.aTitle.getLength() == 0 ) + { + VOS_ENSURE( sal_False, "Content::insert - property value missing!" ); + throw CommandAbortedException(); + } + + // Assemble new content identifier... + + // change the URL from scheme://xxx/xxx/new_content to scheme://xxx/xxx/<m_aProps.aTitle> + + //OUString currentURL = m_xIdentifier->getContentIdentifier(); + OUString aURL = getParentURL(); + aURL += m_aProps.aTitle; +// fprintf ( stderr, "() " ); +// fprintf ( stderr, OUStringToOString( aURL, RTL_TEXTENCODING_ASCII_US ) ); +// fprintf ( stderr, "\n" ); + + // webdavscheme://user@host:port/path + sal_Int32 indexOfSecondSlash = aURL.indexOf('/',WEBDAV_URL_SCHEME_LENGTH+2); + sal_Int32 indexOfThirdSlash = aURL.indexOf('/',indexOfSecondSlash+1); + if (indexOfThirdSlash==-1) { + VOS_ENSURE( sal_False, "No third '/' in URL " ); + throw CommandAbortedException(); + } + if ( isFolder() ) + { + sal_Int32 nPos = aURL.lastIndexOf( '/' ); + if ( nPos != ( aURL.getLength() - 1 ) ) + { + // No trailing slash found. Append. + aURL += OUString::createFromAscii( "/" ); + } + } + + _path = aURL.copy(indexOfThirdSlash); + + Reference< XContentIdentifier > xId( new ::ucb::ContentIdentifier( m_xSMgr, aURL ) ); + if ( !xId.is() ) { + VOS_ENSURE( sal_False, "Cannot create ContentIdentifier" ); + throw CommandAbortedException(); + } + + m_xIdentifier = xId; + + try { + + if ( isFolder() ) + { + _pWebdavSession->MKCOL(_path, Environment); + } + else + { + _pWebdavSession->PUT(_path, xInputStream, Environment); + } + + } catch (DAVException e) { + if ( isFolder() ) + VOS_ENSURE( sal_False, "MKCOL : DAVException\n" ); + else + VOS_ENSURE( sal_False, "PUT : DAVException\n" ); + throw CommandAbortedException(); + } + if ( ! update(Environment) ) { + throw CommandAbortedException(); + } + + aGuard.clear(); + inserted(); + _transient = sal_False; +} + +//========================================================================= +void Content::destroy( sal_Bool bDeletePhysical ) + throw( CommandAbortedException ) +{ + // @@@ take care about bDeletePhysical -> trashcan support + OUString aURL = m_xIdentifier->getContentIdentifier(); + +// fprintf(stderr, " destroy : "); +// fprintf ( stderr, OUStringToOString( aURL, RTL_TEXTENCODING_ASCII_US ) ); +// fprintf(stderr, " \n"); + Reference< XContent > xThis = this; + + deleted(); + + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + + // Process instanciated children... + +// fprintf(stderr, " destroy 2\n"); + ::webdav_ucp::Content::ContentRefList aChildren; + queryChildren( aChildren ); + + ContentRefList::const_iterator it = aChildren.begin(); + ContentRefList::const_iterator end = aChildren.end(); + +// fprintf(stderr, " destroy children\n"); + while ( it != end ) + { + (*it)->destroy( bDeletePhysical ); + ++it; + } +} + +void Content::getChildrenResources(std::vector< DAVResource >& resources, + const Reference< XCommandEnvironment >& Environment ) +{ + // propfind depth 1, build ContentProperty for each children + + // @@@ limit it to the resultset properties + std::vector< OUString > propertyNames; + propertyNames.push_back(DAVProperties::CREATIONDATE); + propertyNames.push_back(DAVProperties::DISPLAYNAME); + propertyNames.push_back(DAVProperties::GETCONTENTLANGUAGE); + propertyNames.push_back(DAVProperties::GETCONTENTLENGTH); + propertyNames.push_back(DAVProperties::GETCONTENTTYPE); + propertyNames.push_back(DAVProperties::GETETAG); + propertyNames.push_back(DAVProperties::GETLASTMODIFIED); + propertyNames.push_back(DAVProperties::LOCKDISCOVERY); + propertyNames.push_back(DAVProperties::RESOURCETYPE); + propertyNames.push_back(DAVProperties::SOURCE); +// propertyNames.push_back(DAVProperties::SUPPORTEDLOCK); + + + OUString aURL = m_xIdentifier->getContentIdentifier(); + + try { + _pWebdavSession->PROPFIND (_path, ONE, propertyNames, resources, Environment); + } + catch (DAVException e){ + VOS_ENSURE( sal_False, "PROPFIND : DAVException" ); + throw CommandAbortedException(); + } +} + diff --git a/ucb/source/ucp/webdav/webdavcontent.hxx b/ucb/source/ucp/webdav/webdavcontent.hxx new file mode 100644 index 000000000000..9548e708ac36 --- /dev/null +++ b/ucb/source/ucp/webdav/webdavcontent.hxx @@ -0,0 +1,292 @@ +/************************************************************************* + * + * $RCSfile: webdavcontent.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:55:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _WEBDAV_UCP_CONTENT_HXX +#define _WEBDAV_UCP_CONTENT_HXX + +#ifndef _NEONTYPES_HXX_ +#include "NeonTypes.hxx" +#endif +#ifndef _DAVSESSION_HXX_ +#include "DAVSession.hxx" +#endif + +#ifndef __VECTOR__ +#include <stl/vector> +#endif +#ifndef __LIST__ +#include <stl/list> +#endif +#ifndef _VOS_REF_HXX_ +#include <vos/ref.hxx> +#endif + +#ifndef _COM_SUN_STAR_UCB_XCONTENTCREATOR_HPP_ +#include <com/sun/star/ucb/XContentCreator.hpp> +#endif +#ifndef _COM_SUN_STAR_IO_XINPUTSTREAM_HPP_ +#include <com/sun/star/io/XInputStream.hpp> +#endif +#ifndef _COM_SUN_STAR_UTIL_DATETIME_HPP_ +#include <com/sun/star/util/DateTime.hpp> +#endif + +#ifndef _UCBHELPER_CONTENTHELPER_HXX +#include <ucbhelper/contenthelper.hxx> +#endif + +namespace com { namespace sun { namespace star { namespace beans { + struct Property; + struct PropertyValue; +} } } } + +namespace com { namespace sun { namespace star { namespace sdbc { + class XRow; +} } } } + +namespace webdav_ucp +{ + +//========================================================================= + +// UNO service name for the content. +#define WEBDAV_CONTENT_SERVICE_NAME "com.sun.star.ucb.WebDAVContent" + +//========================================================================= + +class DAVResource; +class ContentCreationException : public ::com::sun::star::uno::Exception +{}; + +struct ContentProperties +{ + ::rtl::OUString aTitle; // Title + ::rtl::OUString getcontenttype; // ContentType + sal_Bool bIsDocument; // IsDocument + sal_Bool bIsFolder; // IsFolder + sal_Int64 size; // Size + ::com::sun::star::util::DateTime dateCreated; // DateCreated + ::com::sun::star::util::DateTime dateModified; // DateModified + + ::rtl::OUString creationdate; + ::rtl::OUString displayname; + ::rtl::OUString getcontentlanguage; + ::rtl::OUString getcontentlength; + ::rtl::OUString getetag; + ::rtl::OUString getlastmodified; + //@@@ ::com::sun::star::uno::Sequence<::com::sun::star::dav::lock> lockdiscovery; + ::rtl::OUString lockdiscovery; + ::rtl::OUString resourcetype; + //@@@ ::com::sun::star::uno::Any source; + ::rtl::OUString source; + //@@@ ::com::sun::star::uno::Sequence<::com::sun::star::dav::lock> supportedlock; + ::rtl::OUString supportedlock; + + ContentProperties() + : bIsDocument( sal_False ), bIsFolder( sal_True ) {} + + void setValues(DAVResource& res); +}; + +//========================================================================= + +class Content : public ::ucb::ContentImplHelper, + public com::sun::star::ucb::XContentCreator +{ + ContentProperties m_aProps; + ::vos::ORef< DAVSession > _pWebdavSession; + ::rtl::OUString _path; + sal_Bool _transient; + sal_Bool _upToDate; + +private: + + sal_Bool update(const ::com::sun::star::uno::Reference< + com::sun::star::ucb::XCommandEnvironment >& Environment); + void initpath() + throw ( ContentCreationException ); + + + virtual const ::ucb::PropertyInfoTableEntry& getPropertyInfoTable(); + virtual const ::ucb::CommandInfoTableEntry& getCommandInfoTable(); + virtual ::rtl::OUString getParentURL(); + + sal_Bool isFolder() const { return ( m_aProps.bIsFolder ); } + void setFolder() { + m_aProps.bIsFolder = sal_True; + m_aProps.bIsDocument = sal_True; + } + + ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow > + getPropertyValues( const ::com::sun::star::uno::Sequence< + ::com::sun::star::beans::Property >& rProperties ); + void setPropertyValues( + const ::com::sun::star::uno::Sequence< + ::com::sun::star::beans::PropertyValue >& rValues); + + typedef vos::ORef< Content > ContentRef; + typedef std::list< ContentRef > ContentRefList; + void queryChildren( ContentRefList& rChildren); + + + // Command "insert" + void insert(com::sun::star::uno::Reference<com::sun::star::io::XInputStream> xInputStream, + sal_Bool bReplaceExisting, + const com::sun::star::uno::Reference< + com::sun::star::ucb::XCommandEnvironment >& Environment ) + throw( ::com::sun::star::ucb::CommandAbortedException ); + + // Command "delete" + void destroy( sal_Bool bDeletePhysical ) + throw( ::com::sun::star::ucb::CommandAbortedException ); + +public: + Content( const ::com::sun::star::uno::Reference< + ::com::sun::star::lang::XMultiServiceFactory >& rxSMgr, + ::ucb::ContentProviderImplHelper* pProvider, + const ::com::sun::star::uno::Reference< + ::com::sun::star::ucb::XContentIdentifier >& Identifier ) + throw ( ContentCreationException ); + Content( const ::com::sun::star::uno::Reference< + ::com::sun::star::lang::XMultiServiceFactory >& rxSMgr, + ::ucb::ContentProviderImplHelper* pProvider, + const ::com::sun::star::uno::Reference< + ::com::sun::star::ucb::XContentIdentifier >& Identifier, + ::vos::ORef< DAVSession> pSession, + sal_Bool isCollection) + throw ( ContentCreationException ); + virtual ~Content(); + + // XInterface + XINTERFACE_DECL() + + // XTypeProvider + XTYPEPROVIDER_DECL() + + // XServiceInfo + virtual ::rtl::OUString SAL_CALL + getImplementationName() + throw( ::com::sun::star::uno::RuntimeException ); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL + getSupportedServiceNames() + throw( ::com::sun::star::uno::RuntimeException ); + + // XContent + virtual rtl::OUString SAL_CALL + getContentType() + throw( com::sun::star::uno::RuntimeException ); + + // XCommandProcessor + virtual com::sun::star::uno::Any SAL_CALL + execute( const com::sun::star::ucb::Command& aCommand, + sal_Int32 CommandId, + const com::sun::star::uno::Reference< + com::sun::star::ucb::XCommandEnvironment >& Environment ) + throw( com::sun::star::uno::Exception, + com::sun::star::ucb::CommandAbortedException, + com::sun::star::uno::RuntimeException ); + virtual void SAL_CALL + abort( sal_Int32 CommandId ) + throw( com::sun::star::uno::RuntimeException ); + + ////////////////////////////////////////////////////////////////////// + // Additional interfaces + ////////////////////////////////////////////////////////////////////// + + // Add additional interfaces ( like com::sun:.star::ucb::XContentCreator ). + // XContentCreator + virtual com::sun::star::uno::Sequence< + com::sun::star::ucb::ContentInfo > SAL_CALL + queryCreatableContentsInfo() + throw( com::sun::star::uno::RuntimeException ); + virtual com::sun::star::uno::Reference< + com::sun::star::ucb::XContent > SAL_CALL + createNewContent( const com::sun::star::ucb::ContentInfo& Info ) + throw( com::sun::star::uno::RuntimeException ); + + +////////////////////////////////////////////////////////////////////// +// Non-interface methods. +////////////////////////////////////////////////////////////////////// + ::vos::ORef< DAVSession > getSession() { + return _pWebdavSession; + } + +// Called from resultset data supplier. +static ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow > +getPropertyValues( const ::com::sun::star::uno::Reference< + ::com::sun::star::lang::XMultiServiceFactory >& rSMgr, + const ::com::sun::star::uno::Sequence< + ::com::sun::star::beans::Property >& rProperties, + const ContentProperties& rData, + const ::vos::ORef< ::ucb::ContentProviderImplHelper >& + rProvider, + const ::rtl::OUString& rContentId ); + + void getChildrenResources(std::vector< DAVResource >& resources, + const com::sun::star::uno::Reference< + com::sun::star::ucb::XCommandEnvironment >& Environment ); + +}; + +}; + +#endif diff --git a/ucb/source/ucp/webdav/webdavcontentcaps.cxx b/ucb/source/ucp/webdav/webdavcontentcaps.cxx new file mode 100644 index 000000000000..c0a6a3226711 --- /dev/null +++ b/ucb/source/ucp/webdav/webdavcontentcaps.cxx @@ -0,0 +1,373 @@ +/************************************************************************* + * + * $RCSfile: webdavcontentcaps.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:55:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +/************************************************************************** + TODO + ************************************************************************** + + *************************************************************************/ + +#ifndef _COM_SUN_STAR_BEANS_PROPERTY_HPP_ +#include <com/sun/star/beans/Property.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HPP_ +#include <com/sun/star/beans/PropertyAttribute.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_ +#include <com/sun/star/beans/PropertyValue.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_OPENCOMMANDARGUMENT2_HPP_ +#include <com/sun/star/ucb/OpenCommandArgument2.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_INSERTCOMMANDARGUMENT_HPP_ +#include <com/sun/star/ucb/InsertCommandArgument.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_TRANSFERINFO_HPP_ +#include <com/sun/star/ucb/TransferInfo.hpp> +#endif +#ifndef _COM_SUN_STAR_UNO_SEQUENCE_HXX_ +#include <com/sun/star/uno/Sequence.hxx> +#endif + +#ifndef _COM_SUN_STAR_UTIL_DATETIME_HXX_ +#include <com/sun/star/util/DateTime.hpp> +#endif + +#include <com/sun/star/io/XInputStream.hpp> +#include <com/sun/star/io/XOutputStream.hpp> + +#ifndef _WEBDAV_UCP_CONTENT_HXX +#include "webdavcontent.hxx" +#endif + +#ifndef _WEBDAV_SESSION_HXX +#include "DAVSession.hxx" +#endif + +using namespace com::sun::star::util; +using namespace com::sun::star::beans; +using namespace com::sun::star::uno; +using namespace com::sun::star::ucb; +using namespace rtl; + +using namespace webdav_ucp; + +//========================================================================= +// +// Content implementation. +// +//========================================================================= + +//========================================================================= +// +// IMPORTENT: If any property data ( name / type / ... ) are changed, then +// Content::getPropertyValues(...) must be adapted too! +// +//========================================================================= + +// virtual +const ::ucb::PropertyInfoTableEntry +& Content::getPropertyInfoTable() +{ + // @@@ Add additional properties... + + // @@@ Note: If your data source supports adding/removing properties, + // you should implement the interface XPropertyContainer + // by yourself and supply your own logic here. The base class + // uses the service "com.sun.star.ucb.Store" to maintain + // Additional Core properties. But using server functionality + // is preferred! In fact you should return a table conatining + // even that dynamicly added properties. + + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + + //================================================================= + // + // Supported properties + // + //================================================================= + + static ::ucb::PropertyInfoTableEntry aPropertyInfoTable[] = + { + /////////////////////////////////////////////////////////////// + // Required properties + /////////////////////////////////////////////////////////////// + { + "ContentType", + -1, + &getCppuType( static_cast< const OUString * >( 0 ) ), + PropertyAttribute::BOUND | PropertyAttribute::READONLY + }, + { + "IsDocument", + -1, + &getCppuBooleanType(), + PropertyAttribute::BOUND | PropertyAttribute::READONLY + }, + { + "IsFolder", + -1, + &getCppuBooleanType(), + PropertyAttribute::BOUND | PropertyAttribute::READONLY + }, + { + "Title", + -1, + &getCppuType( static_cast< const OUString * >( 0 ) ), + PropertyAttribute::BOUND | PropertyAttribute::READONLY + }, + { + "Size", + -1, + &getCppuType( static_cast< const sal_Int64 * >( 0 ) ), + PropertyAttribute::BOUND | PropertyAttribute::READONLY + }, + { + "DateCreated", + -1, + &getCppuType( static_cast< const DateTime * >( 0 ) ), + PropertyAttribute::BOUND | PropertyAttribute::READONLY + }, + { + "DateModified", + -1, + &getCppuType( static_cast< const DateTime * >( 0 ) ), + PropertyAttribute::BOUND | PropertyAttribute::READONLY + }, + { + *new OString(OUStringToOString(DAVProperties::CREATIONDATE,RTL_TEXTENCODING_ASCII_US)), + -1, + &getCppuType( static_cast< const OUString * >( 0 ) ), + PropertyAttribute::BOUND | PropertyAttribute::READONLY + }, + { + *new OString(OUStringToOString(DAVProperties::DISPLAYNAME,RTL_TEXTENCODING_ASCII_US)), + -1, + &getCppuType( static_cast< const OUString * >( 0 ) ), + PropertyAttribute::BOUND | PropertyAttribute::READONLY + }, + { + *new OString(OUStringToOString(DAVProperties::GETCONTENTLANGUAGE,RTL_TEXTENCODING_ASCII_US)), + -1, + &getCppuType( static_cast< const OUString * >( 0 ) ), + PropertyAttribute::BOUND | PropertyAttribute::READONLY + }, + { + *new OString(OUStringToOString(DAVProperties::GETCONTENTLENGTH,RTL_TEXTENCODING_ASCII_US)), + -1, + &getCppuType( static_cast< const OUString * >( 0 ) ), + PropertyAttribute::BOUND | PropertyAttribute::READONLY + }, + { + *new OString(OUStringToOString(DAVProperties::GETCONTENTTYPE,RTL_TEXTENCODING_ASCII_US)), + -1, + &getCppuType( static_cast< const OUString * >( 0 ) ), + PropertyAttribute::BOUND | PropertyAttribute::READONLY + }, + { + *new OString(OUStringToOString(DAVProperties::GETETAG,RTL_TEXTENCODING_ASCII_US)), + -1, + &getCppuType( static_cast< const OUString * >( 0 ) ), + PropertyAttribute::BOUND | PropertyAttribute::READONLY + }, + { + *new OString(OUStringToOString(DAVProperties::GETLASTMODIFIED,RTL_TEXTENCODING_ASCII_US)), + -1, + &getCppuType( static_cast< const OUString * >( 0 ) ), + PropertyAttribute::BOUND | PropertyAttribute::READONLY + }, + { + *new OString(OUStringToOString(DAVProperties::LOCKDISCOVERY,RTL_TEXTENCODING_ASCII_US)), + -1, + &getCppuType( static_cast< const OUString * >( 0 ) ), + PropertyAttribute::BOUND | PropertyAttribute::READONLY + }, + { + *new OString(OUStringToOString(DAVProperties::RESOURCETYPE,RTL_TEXTENCODING_ASCII_US)), + -1, + &getCppuType( static_cast< const OUString * >( 0 ) ), + PropertyAttribute::BOUND | PropertyAttribute::READONLY + }, + { + *new OString(OUStringToOString(DAVProperties::SOURCE,RTL_TEXTENCODING_ASCII_US)), + -1, + &getCppuType( static_cast< const OUString * >( 0 ) ), + PropertyAttribute::BOUND | PropertyAttribute::READONLY + }, + { + *new OString(OUStringToOString(DAVProperties::SUPPORTEDLOCK,RTL_TEXTENCODING_ASCII_US)), + -1, + &getCppuType( static_cast< const OUString * >( 0 ) ), + PropertyAttribute::BOUND | PropertyAttribute::READONLY + }, + + + /////////////////////////////////////////////////////////////// + // Optional standard properties + /////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////// + // New properties + /////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////// + // EOT + /////////////////////////////////////////////////////////////// + { + 0, // name + 0, // handle + 0, // type + 0 // attributes + } + }; + return *aPropertyInfoTable; +} + +//========================================================================= +// virtual +const ::ucb::CommandInfoTableEntry& Content::getCommandInfoTable() +{ + // @@@ Add additional commands... + + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + + //================================================================= + // + // Supported commands + // + //================================================================= + + static ::ucb::CommandInfoTableEntry aCommandInfoTable[] = + { + /////////////////////////////////////////////////////////////// + // Required commands + /////////////////////////////////////////////////////////////// + { + "getCommandInfo", + -1, + &getCppuVoidType() + }, + { + "getPropertySetInfo", + -1, + &getCppuVoidType() + }, + { + "getPropertyValues", + -1, + &getCppuType( static_cast< Sequence< Property > * >( 0 ) ) + }, + { + "setPropertyValues", + -1, + &getCppuType( static_cast< Sequence< PropertyValue > * >( 0 ) ) + }, + /////////////////////////////////////////////////////////////// + // Optional standard commands + /////////////////////////////////////////////////////////////// + { + "delete", + -1, + &getCppuBooleanType() + }, + { + "insert", + -1, + &getCppuType( static_cast< InsertCommandArgument * >( 0 ) ) + }, + { + "open", + -1, + &getCppuType( static_cast< OpenCommandArgument2 * >( 0 ) ) + }, + /* + { + "transfer", + -1, + &getCppuType( static_cast< TransferInfo * >( 0 ) ) + }, + */ + /* + { + "COPY", + -1, + &getCppuType( static_cast< const OUString * >( 0 ) ), + }, + { + "MOVE", + -1, + &getCppuType( static_cast< const OUString * >( 0 ) ), + }, + */ + /////////////////////////////////////////////////////////////// + // New commands + /////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////// + // EOT + /////////////////////////////////////////////////////////////// + { + 0, // name + 0, // handle + 0 // type + } + }; + + return *aCommandInfoTable; +} + diff --git a/ucb/source/ucp/webdav/webdavdatasupplier.cxx b/ucb/source/ucp/webdav/webdavdatasupplier.cxx new file mode 100644 index 000000000000..b453ae9534a1 --- /dev/null +++ b/ucb/source/ucp/webdav/webdavdatasupplier.cxx @@ -0,0 +1,426 @@ +/************************************************************************* + * + * $RCSfile: webdavdatasupplier.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:55:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +/************************************************************************** + TODO + ************************************************************************** + + *************************************************************************/ + +#ifndef _COM_SUN_STAR_UCB_OPENMODE_HPP_ +#include <com/sun/star/ucb/OpenMode.hpp> +#endif + +#ifndef _UCBHELPER_CONTENTIDENTIFIER_HXX +#include <ucbhelper/contentidentifier.hxx> +#endif +#ifndef _UCBHELPER_PROVIDERHELPER_HXX +#include <ucbhelper/providerhelper.hxx> +#endif + +#ifndef _WEBDAV_UCP_DATASUPPLIER_HXX +#include "webdavdatasupplier.hxx" +#endif +#ifndef _WEBDAV_UCP_CONTENT_HXX +#include "webdavcontent.hxx" +#endif + +#ifndef _WEBDAV_SESSION_HXX +#include "DAVSession.hxx" +#endif + +using namespace com::sun::star::beans; +using namespace com::sun::star::lang; +using namespace com::sun::star::ucb; +using namespace com::sun::star::uno; +using namespace com::sun::star::sdbc; +using namespace rtl; +using namespace ucb; + +using namespace webdav_ucp; + +namespace webdav_ucp +{ + +//========================================================================= +// +// struct ResultListEntry. +// +//========================================================================= + +struct ResultListEntry +{ + OUString aId; + Reference< XContentIdentifier > xId; + Reference< XContent > xContent; + Reference< XRow > xRow; + const ContentProperties* pData; + + ResultListEntry( const ContentProperties* pEntry ) : pData( pEntry ) {}; + ~ResultListEntry() {delete pData;} +}; + +//========================================================================= +// +// ResultList. +// +//========================================================================= + +typedef std::vector< ResultListEntry* > ResultList; + +//========================================================================= +// +// struct DataSupplier_Impl. +// +//========================================================================= + +struct DataSupplier_Impl +{ + osl::Mutex m_aMutex; + ResultList m_aResults; + vos::ORef< Content > m_xContent; + Reference< XMultiServiceFactory > m_xSMgr; + sal_Bool m_bCountFinal; + + DataSupplier_Impl( const Reference< XMultiServiceFactory >& rxSMgr, + const vos::ORef< Content >& rContent ) + : m_xContent( rContent ), m_xSMgr( rxSMgr ), + m_bCountFinal( sal_False ) {} + ~DataSupplier_Impl(); +}; + +//========================================================================= +DataSupplier_Impl::~DataSupplier_Impl() +{ + ResultList::const_iterator it = m_aResults.begin(); + ResultList::const_iterator end = m_aResults.end(); + + while ( it != end ) + { + delete (*it); + it++; + } +} + +} + +//========================================================================= +//========================================================================= +// +// DataSupplier Implementation. +// +//========================================================================= +//========================================================================= + +DataSupplier::DataSupplier( const Reference< XMultiServiceFactory >& rxSMgr, + const vos::ORef< Content >& rContent, + sal_Int32 nOpenMode, + std::vector< DAVResource >& resources) +: m_pImpl( new DataSupplier_Impl( rxSMgr, rContent ) ) +{ + for (sal_Int32 i=0; i<resources.size()-1; i++) + { + ContentProperties* pContentProperty = new ContentProperties; + pContentProperty->setValues(resources[i]); + + // Check resource against open mode. + sal_Bool bMatchesOpenMode = sal_True; + + switch ( nOpenMode ) + { + case OpenMode::FOLDERS: + if ( !pContentProperty->bIsFolder ) + { + // Entry is a document. + bMatchesOpenMode = sal_False; + } + break; + + case OpenMode::DOCUMENTS: + if ( !pContentProperty->bIsDocument ) + { + // Entry is a folder. + bMatchesOpenMode = sal_False; + } + break; + + case OpenMode::ALL: + default: + break; + } + + if ( bMatchesOpenMode ) + m_pImpl->m_aResults.push_back(new ResultListEntry( pContentProperty ) ); + } + + + m_pImpl->m_bCountFinal = sal_True; + vos::ORef< ResultSet > xResultSet = getResultSet(); + if ( xResultSet.isValid() ) + { + xResultSet->rowCountFinal(); + } +} + +//========================================================================= +// virtual +DataSupplier::~DataSupplier() +{ + delete m_pImpl; +} + +//========================================================================= +// virtual +OUString DataSupplier::queryContentIdentifierString( sal_uInt32 nIndex ) +{ + osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + + if ( nIndex < m_pImpl->m_aResults.size() ) + { + OUString aId = m_pImpl->m_aResults[ nIndex ]->aId; + if ( aId.getLength() ) + { + // Already cached. + return aId; + } + } + + if ( getResult( nIndex ) ) + { + OUString aId + = m_pImpl->m_xContent->getIdentifier()->getContentIdentifier(); + + const ContentProperties& props = *(m_pImpl->m_aResults[ nIndex ]->pData); + +// fprintf(stderr,OUStringToOString( props.aTitle, RTL_TEXTENCODING_ASCII_US )); +// fprintf(stderr, "\n"); + +// fprintf(stderr,OUStringToOString(aId, RTL_TEXTENCODING_ASCII_US )); +// fprintf(stderr, "\n"); + +// fprintf(stderr, "size : %d\n", m_pImpl->m_aResults.size()); + + if ( ( aId.lastIndexOf( '/' ) + 1 ) != aId.getLength() ) + aId += OUString::createFromAscii( "/" ); + + aId += props.aTitle; + + m_pImpl->m_aResults[ nIndex ]->aId = aId; + return aId; + } + return OUString(); +} + +//========================================================================= +// virtual +Reference< XContentIdentifier > DataSupplier::queryContentIdentifier( sal_uInt32 nIndex ) +{ + osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + + if ( nIndex < m_pImpl->m_aResults.size() ) + { + Reference< XContentIdentifier > xId + = m_pImpl->m_aResults[ nIndex ]->xId; + if ( xId.is() ) + { + // Already cached. + return xId; + } + } + + OUString aId = queryContentIdentifierString( nIndex ); + if ( aId.getLength() ) + { + Reference< XContentIdentifier > xId = new ContentIdentifier( aId ); + m_pImpl->m_aResults[ nIndex ]->xId = xId; + return xId; + } + return Reference< XContentIdentifier >(); +} + +//========================================================================= +// virtual +Reference< XContent > DataSupplier::queryContent( sal_uInt32 nIndex ) +{ + osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + + if ( nIndex < m_pImpl->m_aResults.size() ) + { + Reference< XContent > xContent = m_pImpl->m_aResults[ nIndex ]->xContent; + if ( xContent.is() ) + { + // Already cached. + return xContent; + } + } + + Reference< XContentIdentifier > xId = queryContentIdentifier( nIndex ); + if ( xId.is() ) + { + try + { + Reference< XContent > xContent + = m_pImpl->m_xContent->getProvider()->queryContent( xId ); + m_pImpl->m_aResults[ nIndex ]->xContent = xContent; + return xContent; + + } + catch ( IllegalIdentifierException& ) + { + } + } + return Reference< XContent >(); +} + +//========================================================================= +// virtual +sal_Bool DataSupplier::getResult( sal_uInt32 nIndex ) +{ + osl::ClearableGuard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + + if ( m_pImpl->m_aResults.size() > nIndex ) + { + // Result already present. + return sal_True; + } + + // Result not (yet) present. + + if ( m_pImpl->m_bCountFinal ) + return sal_False; + +} + +//========================================================================= +// virtual +sal_uInt32 DataSupplier::totalCount() +{ + return m_pImpl->m_aResults.size(); +} + +//========================================================================= +// virtual +sal_uInt32 DataSupplier::currentCount() +{ + return m_pImpl->m_aResults.size(); +} + +//========================================================================= +// virtual +sal_Bool DataSupplier::isCountFinal() +{ + return m_pImpl->m_bCountFinal; +} + +//========================================================================= +// virtual +Reference< XRow > DataSupplier::queryPropertyValues( sal_uInt32 nIndex ) +{ + osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + + if ( nIndex < m_pImpl->m_aResults.size() ) + { + Reference< XRow > xRow = m_pImpl->m_aResults[ nIndex ]->xRow; + if ( xRow.is() ) + { + // Already cached. + return xRow; + } + } + + if ( getResult( nIndex ) ) + { + Reference< XRow > xRow = Content::getPropertyValues( + m_pImpl->m_xSMgr, + getResultSet()->getProperties(), + *(m_pImpl->m_aResults[ nIndex ]->pData), + m_pImpl->m_xContent->getProvider(), + queryContentIdentifierString( nIndex ) ); + m_pImpl->m_aResults[ nIndex ]->xRow = xRow; + return xRow; + } + + return Reference< XRow >(); +} + +//========================================================================= +// virtual +void DataSupplier::releasePropertyValues( sal_uInt32 nIndex ) +{ + osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + + if ( nIndex < m_pImpl->m_aResults.size() ) + m_pImpl->m_aResults[ nIndex ]->xRow = Reference< XRow >(); +} + +//========================================================================= +// virtual +void DataSupplier::close() +{ +} + +//========================================================================= +// virtual +void DataSupplier::validate() + throw( ResultSetException ) +{ +} + diff --git a/ucb/source/ucp/webdav/webdavdatasupplier.hxx b/ucb/source/ucp/webdav/webdavdatasupplier.hxx new file mode 100644 index 000000000000..e2ed5349fe1e --- /dev/null +++ b/ucb/source/ucp/webdav/webdavdatasupplier.hxx @@ -0,0 +1,115 @@ +/************************************************************************* + * + * $RCSfile: webdavdatasupplier.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:55:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _WEBDAV_UCP_DATASUPPLIER_HXX +#define _WEBDAV_UCP_DATASUPPLIER_HXX + +#ifndef _UCBHELPER_RESULTSET_HXX +#include <ucbhelper/resultset.hxx> +#endif +#ifndef __VECTOR__ +#include <stl/vector> +#endif +namespace webdav_ucp { + +struct DataSupplier_Impl; +class Content; +class DAVResource; + +class DataSupplier : public ucb::ResultSetDataSupplier +{ + DataSupplier_Impl* m_pImpl; + +public: + DataSupplier( const com::sun::star::uno::Reference< + com::sun::star::lang::XMultiServiceFactory >& rxSMgr, + const vos::ORef< Content >& rContent, + sal_Int32 nOpenMode, + std::vector< DAVResource >& resources); + + virtual ~DataSupplier(); + + virtual rtl::OUString queryContentIdentifierString( sal_uInt32 nIndex ); + virtual com::sun::star::uno::Reference< + com::sun::star::ucb::XContentIdentifier > + queryContentIdentifier( sal_uInt32 nIndex ); + virtual com::sun::star::uno::Reference< com::sun::star::ucb::XContent > + queryContent( sal_uInt32 nIndex ); + + virtual sal_Bool getResult( sal_uInt32 nIndex ); + + virtual sal_uInt32 totalCount(); + virtual sal_uInt32 currentCount(); + virtual sal_Bool isCountFinal(); + + virtual com::sun::star::uno::Reference< com::sun::star::sdbc::XRow > + queryPropertyValues( sal_uInt32 nIndex ); + virtual void releasePropertyValues( sal_uInt32 nIndex ); + + virtual void close(); + + virtual void validate() + throw( com::sun::star::ucb::ResultSetException ); +}; + +} + +#endif diff --git a/ucb/source/ucp/webdav/webdavprovider.cxx b/ucb/source/ucp/webdav/webdavprovider.cxx new file mode 100644 index 000000000000..aa3b9ff454e5 --- /dev/null +++ b/ucb/source/ucp/webdav/webdavprovider.cxx @@ -0,0 +1,216 @@ +/************************************************************************* + * + * $RCSfile: webdavprovider.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:55:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +/************************************************************************** + TODO + ************************************************************************** + + *************************************************************************/ + +#ifndef _VOS_DIAGNOSE_HXX_ +#include <vos/diagnose.hxx> +#endif +#ifndef _UCBHELPER_CONTENTIDENTIFIER_HXX +#include <ucbhelper/contentidentifier.hxx> +#endif + +#ifndef _WEBDAV_UCP_PROVIDER_HXX +#include "webdavprovider.hxx" +#endif +#ifndef _WEBDAV_UCP_CONTENT_HXX +#include "webdavcontent.hxx" +#endif + +using namespace com::sun::star::lang; +using namespace com::sun::star::ucb; +using namespace com::sun::star::uno; +using namespace rtl; + +using namespace webdav_ucp; + +//========================================================================= +//========================================================================= +// +// ContentProvider Implementation. +// +//========================================================================= +//========================================================================= + +ContentProvider::ContentProvider( + const Reference< XMultiServiceFactory >& rSMgr ) +: ::ucb::ContentProviderImplHelper( rSMgr ) +{ +} + +//========================================================================= +// virtual +ContentProvider::~ContentProvider() +{ +} + +//========================================================================= +// +// XInterface methods. +// +//========================================================================= + +// @@@ Add own interfaces. +XINTERFACE_IMPL_3( ContentProvider, + XTypeProvider, + XServiceInfo, + XContentProvider ); + +//========================================================================= +// +// XTypeProvider methods. +// +//========================================================================= + +// @@@ Add own interfaces. +XTYPEPROVIDER_IMPL_3( ContentProvider, + XTypeProvider, + XServiceInfo, + XContentProvider ); + +//========================================================================= +// +// XServiceInfo methods. +// +//========================================================================= + +XSERVICEINFO_IMPL_1( ContentProvider, + OUString::createFromAscii( + "webdav_ucp_ContentProvider" ), + OUString::createFromAscii( + WEBDAV_CONTENT_PROVIDER_SERVICE_NAME ) ); + +//========================================================================= +// +// Service factory implementation. +// +//========================================================================= + +ONE_INSTANCE_SERVICE_FACTORY_IMPL( ContentProvider ); + +//========================================================================= +// +// XContentProvider methods. +// +//========================================================================= + +// virtual +Reference< XContent > SAL_CALL ContentProvider::queryContent( + const Reference< XContentIdentifier >& Identifier ) + throw( IllegalIdentifierException, RuntimeException ) +{ + vos::OGuard aGuard( m_aMutex ); + + + + // Check URL scheme... + + OUString aScheme( OUString::createFromAscii( WEBDAV_URL_SCHEME ) ); + if ( !Identifier->getContentProviderScheme().equalsIgnoreCase( aScheme ) ) + throw IllegalIdentifierException(); + + // @@@ Further id checks may go here... +#if 0 + if ( id-check-failes ) + throw IllegalIdentifierException(); +#endif + + // @@@ Id normalization may go here... +#if 0 + // Normalize URL and create new Id. + OUString aCanonicURL = xxxxx( Identifier->getContentIdentifier() ); + Reference< XContentIdentifier > xCanonicId = + new ::ucb::ContentIdentifier( m_xSMgr, aCanonicURL ); +#else + Reference< XContentIdentifier > xCanonicId = Identifier; +#endif + + + // Check, if a content with given id already exists... + Reference< XContent > xContent + = queryExistingContent( xCanonicId ).getBodyPtr(); + if ( xContent.is() ) + return xContent; + + // @@@ Decision, which content implementation to instanciate may be + // made here ( in case you have different content classes ). + + // Create a new content. Note that the content will insert itself + // into providers content list by calling addContent(...) from it's ctor. + +// fprintf ( stderr, OUStringToOString( Identifier->getContentIdentifier(), RTL_TEXTENCODING_ASCII_US ) ); + try { + xContent = new ::webdav_ucp::Content( m_xSMgr, this, xCanonicId ); + } + catch (ContentCreationException e) { + throw IllegalIdentifierException(); + } + + if ( !xContent->getIdentifier().is() ) + throw IllegalIdentifierException(); + + return xContent; +} + diff --git a/ucb/source/ucp/webdav/webdavprovider.hxx b/ucb/source/ucp/webdav/webdavprovider.hxx new file mode 100644 index 000000000000..dddf99c474ed --- /dev/null +++ b/ucb/source/ucp/webdav/webdavprovider.hxx @@ -0,0 +1,128 @@ +/************************************************************************* + * + * $RCSfile: webdavprovider.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:55:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _WEBDAV_UCP_PROVIDER_HXX +#define _WEBDAV_UCP_PROVIDER_HXX + +#ifndef _UCBHELPER_PROVIDERHELPER_HXX +#include <ucbhelper/providerhelper.hxx> +#endif + +namespace webdav_ucp { + +//========================================================================= + +// UNO service name for the provider. This name will be used by the UCB to +// create instances of the provider. +#define WEBDAV_CONTENT_PROVIDER_SERVICE_NAME \ + "com.sun.star.ucb.WebDAVContentProvider" +#define WEBDAV_CONTENT_PROVIDER_SERVICE_NAME_LENGTH 38 + +// @@@ URL scheme. This is the scheme the provider will be able to create +// contents for. The UCB will select the provider ( i.e. in order to create +// contents ) according to this scheme. +#define WEBDAV_URL_SCHEME \ + "vnd.sun.star.webdav" +#define WEBDAV_URL_SCHEME_LENGTH 19 + +// @@@ UCB Content Type(s). +#define WEBDAV_CONTENT_TYPE \ + "application/" WEBDAV_URL_SCHEME "-content" +#define WEBDAV_COLLECTION_TYPE \ + "application/" WEBDAV_URL_SCHEME "-collection" +//========================================================================= + +class ContentProvider : public ::ucb::ContentProviderImplHelper +{ +public: + ContentProvider( const ::com::sun::star::uno::Reference< + ::com::sun::star::lang::XMultiServiceFactory >& rSMgr ); + virtual ~ContentProvider(); + + // XInterface + XINTERFACE_DECL() + + // XTypeProvider + XTYPEPROVIDER_DECL() + + // XServiceInfo + XSERVICEINFO_DECL() + + // XContentProvider + virtual ::com::sun::star::uno::Reference< + ::com::sun::star::ucb::XContent > SAL_CALL + queryContent( const ::com::sun::star::uno::Reference< + ::com::sun::star::ucb::XContentIdentifier >& Identifier ) + throw( ::com::sun::star::ucb::IllegalIdentifierException, + ::com::sun::star::uno::RuntimeException ); + + ////////////////////////////////////////////////////////////////////// + // Additional interfaces + ////////////////////////////////////////////////////////////////////// + + ////////////////////////////////////////////////////////////////////// + // Non-interface methods. + ////////////////////////////////////////////////////////////////////// +}; + +} + +#endif diff --git a/ucb/source/ucp/webdav/webdavresultset.cxx b/ucb/source/ucp/webdav/webdavresultset.cxx new file mode 100644 index 000000000000..684bf2da0c3f --- /dev/null +++ b/ucb/source/ucp/webdav/webdavresultset.cxx @@ -0,0 +1,130 @@ +/************************************************************************* + * + * $RCSfile: webdavresultset.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:55:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +/************************************************************************** + TODO + ************************************************************************** + + - This implementation is not a dynamic result set!!! It only implements + the necessary interfaces, but never recognizes/notifies changes!!! + + *************************************************************************/ + +#ifndef _WEBDAV_UCP_RESULTSET_HXX +#include "webdavresultset.hxx" +#endif +#ifndef _WEBDAV_SESSION_HXX +#include "DAVSession.hxx" +#endif +using namespace com::sun::star::lang; +using namespace com::sun::star::ucb; +using namespace com::sun::star::uno; + +using namespace webdav_ucp; + +//========================================================================= +//========================================================================= +// +// DynamicResultSet Implementation. +// +//========================================================================= +//========================================================================= + +DynamicResultSet::DynamicResultSet( const Reference< XMultiServiceFactory >& rxSMgr, + const vos::ORef< Content >& rxContent, + const OpenCommandArgument2& rCommand, + std::vector< DAVResource >* pResources ) +: ResultSetImplHelper( rxSMgr, rCommand ), + m_xContent( rxContent ), + m_pResources( pResources ) +{ +} + +DynamicResultSet::~DynamicResultSet() +{ + delete m_pResources; +} +//========================================================================= +// +// Non-interface methods. +// +//========================================================================= + +void DynamicResultSet::initStatic() +{ + m_xResultSet1 + = new ::ucb::ResultSet( m_xSMgr, + m_aCommand.Properties, + new DataSupplier( + m_xSMgr, m_xContent, m_aCommand.Mode, *m_pResources) ); +} + +//========================================================================= +void DynamicResultSet::initDynamic() +{ + m_xResultSet1 + = new ::ucb::ResultSet( m_xSMgr, + m_aCommand.Properties, + new DataSupplier( + m_xSMgr, m_xContent, m_aCommand.Mode, *m_pResources) ); + m_xResultSet2 = m_xResultSet1; +} + diff --git a/ucb/source/ucp/webdav/webdavresultset.hxx b/ucb/source/ucp/webdav/webdavresultset.hxx new file mode 100644 index 000000000000..7f1fa28f9937 --- /dev/null +++ b/ucb/source/ucp/webdav/webdavresultset.hxx @@ -0,0 +1,102 @@ +/************************************************************************* + * + * $RCSfile: webdavresultset.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:55:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _WEBDAV_UCP_RESULTSET_HXX +#define _WEBDAV_UCP_RESULTSET_HXX + +#ifndef _UCBHELPER_RESULTSETHELPER_HXX +#include <ucbhelper/resultsethelper.hxx> +#endif +#ifndef _VOS_REF_HXX_ +#include <vos/ref.hxx> +#endif + +#ifndef _WEBDAV_UCP_CONTENT_HXX +#include "webdavcontent.hxx" +#endif +#ifndef _WEBDAV_UCP_DATASUPPLIER_HXX +#include "webdavdatasupplier.hxx" +#endif + +namespace webdav_ucp { + +class DynamicResultSet : public ::ucb::ResultSetImplHelper +{ + vos::ORef< Content > m_xContent; + std::vector< DAVResource >* m_pResources; + +private: + virtual void initStatic(); + virtual void initDynamic(); + +public: + DynamicResultSet( const com::sun::star::uno::Reference< + com::sun::star::lang::XMultiServiceFactory >& rxSMgr, + const vos::ORef< Content >& rxContent, + const com::sun::star::ucb::OpenCommandArgument2& rCommand, + std::vector< DAVResource >* pResources ); + + ~DynamicResultSet(); +}; + +} + +#endif diff --git a/ucb/source/ucp/webdav/webdavservices.cxx b/ucb/source/ucp/webdav/webdavservices.cxx new file mode 100644 index 000000000000..7237bc1a9347 --- /dev/null +++ b/ucb/source/ucp/webdav/webdavservices.cxx @@ -0,0 +1,173 @@ +/************************************************************************* + * + * $RCSfile: webdavservices.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:55:20 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XSINGLESERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XSingleServiceFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_REGISTRY_XREGISTRYKEY_HPP_ +#include <com/sun/star/registry/XRegistryKey.hpp> +#endif + +#ifndef _WEBDAV_UCP_PROVIDER_HXX +#include "webdavprovider.hxx" +#endif + +using namespace rtl; +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::registry; + +//========================================================================= +static sal_Bool writeInfo( void * pRegistryKey, + const OUString & rImplementationName, + Sequence< OUString > const & rServiceNames ) +{ + OUString aKeyName( OUString::createFromAscii( "/" ) ); + aKeyName += rImplementationName; + aKeyName += OUString::createFromAscii( "/UNO/SERVICES" ); + + Reference< XRegistryKey > xKey; + try + { + xKey = static_cast< XRegistryKey * >( + pRegistryKey )->createKey( aKeyName ); + } + catch ( InvalidRegistryException const & ) + { + } + + if ( !xKey.is() ) + return sal_False; + + sal_Bool bSuccess = sal_True; + + for ( sal_Int32 n = 0; n < rServiceNames.getLength(); ++n ) + { + try + { + xKey->createKey( rServiceNames[ n ] ); + } + catch ( InvalidRegistryException const & ) + { + bSuccess = sal_False; + break; + } + } + return bSuccess; +} + +//========================================================================= +extern "C" void SAL_CALL component_getImplementationEnvironment( + const sal_Char ** ppEnvTypeName, uno_Environment ** ppEnv ) +{ + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; +} + +//========================================================================= +extern "C" sal_Bool SAL_CALL component_writeInfo( + void * pServiceManager, void * pRegistryKey ) +{ + return pRegistryKey && + + ////////////////////////////////////////////////////////////////////// + // WebDAV Content Provider. + ////////////////////////////////////////////////////////////////////// + + writeInfo( pRegistryKey, + ::webdav_ucp::ContentProvider::getImplementationName_Static(), + ::webdav_ucp::ContentProvider::getSupportedServiceNames_Static() ); +} + +//========================================================================= +extern "C" void * SAL_CALL component_getFactory( + const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey ) +{ + void * pRet = 0; + + Reference< XMultiServiceFactory > xSMgr( + reinterpret_cast< XMultiServiceFactory * >( pServiceManager ) ); + Reference< XSingleServiceFactory > xFactory; + + ////////////////////////////////////////////////////////////////////// + // WebDAV Content Provider. + ////////////////////////////////////////////////////////////////////// + + if ( ::webdav_ucp::ContentProvider::getImplementationName_Static(). + compareToAscii( pImplName ) == 0 ) + { + xFactory = ::webdav_ucp::ContentProvider::createServiceFactory( xSMgr ); + } + + ////////////////////////////////////////////////////////////////////// + + if ( xFactory.is() ) + { + xFactory->acquire(); + pRet = xFactory.get(); + } + + return pRet; +} + + diff --git a/ucb/workben/ucb/makefile.mk b/ucb/workben/ucb/makefile.mk new file mode 100644 index 000000000000..29db22cf2dc2 --- /dev/null +++ b/ucb/workben/ucb/makefile.mk @@ -0,0 +1,125 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1 $ +# +# last change: $Author: kso $ $Date: 2000-10-16 14:56:13 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (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.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=..$/.. + +PRJNAME=ucb +TARGET=ucbdemo +LIBTARGET=NO + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings --- + +.INCLUDE : svpre.mk +.INCLUDE : settings.mk +.INCLUDE : sv.mk + +# --- Files --- + +.IF "$(depend)" != "" + +OBJFILES=\ + $(OBJ)$/srcharg.obj \ + $(OBJ)$/ucbdemo.obj + +.ENDIF # depend + +#SRSFILES= $(SRS)$/ucbdemo.srs + +# +# UCBDEMO +# +APP1TARGET= ucbdemo +APP1OBJS=\ + $(OBJ)$/srcharg.obj \ + $(OBJ)$/ucbdemo.obj +#APP1RES= $(RES)$/ucbdemo.res + +.IF "$(COMPHELPERLIB)"=="" + +.IF "$(GUI)" == "UNX" +COMPHELPERLIB=-licomphelp2 +.ENDIF # unx + +.IF "$(GUI)"=="WNT" +COMPHELPERLIB=icomphelp2.lib +.ENDIF # wnt + +.ENDIF + +APP1STDLIBS=\ + $(SALLIB) \ + $(VOSLIB) \ + $(CPPULIB) \ + $(CPPUHELPERLIB) \ + $(COMPHELPERLIB) \ + $(TOOLSLIB) \ + $(SVTOOLLIB) \ + $(SVLIB) + +APP1DEF= $(MISC)\$(APP1TARGET).def + +# --- Targets --- + +.INCLUDE : target.mk + diff --git a/ucb/workben/ucb/srcharg.cxx b/ucb/workben/ucb/srcharg.cxx new file mode 100644 index 000000000000..30d35da8d491 --- /dev/null +++ b/ucb/workben/ucb/srcharg.cxx @@ -0,0 +1,537 @@ +/************************************************************************* + * + * $RCSfile: srcharg.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:56:13 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include <limits> + +#ifndef _COM_SUN_STAR_UCB_RULEOPERATOR_HPP_ +#include <com/sun/star/ucb/RuleOperator.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_SEARCHINFO_HPP_ +#include <com/sun/star/ucb/SearchInfo.hpp> +#endif +#ifndef _COM_SUN_STAR_UTIL_DATE_HPP_ +#include <com/sun/star/util/Date.hpp> +#endif +#ifndef _DATE_HXX +#include <tools/date.hxx> +#endif +#ifndef TOOLS_INETMIME_HXX +#include <tools/inetmime.hxx> +#endif +#ifndef _STRING_HXX +#include <tools/string.hxx> +#endif + +#ifndef CHAOS_UCBDEMO_SRCHARG_HXX +#include <srcharg.hxx> +#endif + +#undef max // declared as a macro in <tools/solar.h>... +#undef min // declared as a macro in <tools/solar.h>... + +namespace unnamed_chaos_ucbdemo_srcharg {} +using namespace unnamed_chaos_ucbdemo_srcharg; + // unnamed namespaces don't work well yet... + +using namespace com::sun::star; + +//============================================================================ +// +// skipWhiteSpace +// +//============================================================================ + +namespace unnamed_chaos_ucbdemo_srcharg { + +void skipWhiteSpace(sal_Unicode const *& rBegin, sal_Unicode const * pEnd) +{ + while (rBegin != pEnd + && (*rBegin == '\n' || *rBegin == '\t' || *rBegin == ' ')) + ++rBegin; +} + +//============================================================================ +// +// scanAtom +// +//============================================================================ + +String scanAtom(sal_Unicode const *& rBegin, sal_Unicode const * pEnd) +{ + sal_Unicode const * pTheBegin = rBegin; + while (rBegin != pEnd && INetMIME::isAlpha(*rBegin)) + ++rBegin; + return String(pTheBegin, rBegin - pTheBegin); +} + +//============================================================================ +// +// scanProperty +// +//============================================================================ + +String scanProperty(sal_Unicode const *& rBegin, sal_Unicode const * pEnd) +{ + sal_Unicode const * pTheBegin = rBegin; + while (rBegin != pEnd + && !(*rBegin == '\n' || *rBegin == '\t' || *rBegin == ' ')) + ++rBegin; + return String(pTheBegin, rBegin - pTheBegin); +} + +//============================================================================ +// +// scanOperator +// +//============================================================================ + +String scanOperator(sal_Unicode const *& rBegin, sal_Unicode const * pEnd) +{ + sal_Unicode const * pTheBegin = rBegin; + while (rBegin != pEnd + && (INetMIME::isAlpha(*rBegin) || *rBegin == '!' + || *rBegin >= '<' && *rBegin <= '>')) + ++rBegin; + return String(pTheBegin, rBegin - pTheBegin); +} + +} + +//============================================================================ +// +// parseSearchArgument +// +//============================================================================ + +bool parseSearchArgument(String const & rInput, ucb::SearchInfo & rInfo) +{ + /* Format of rInput: + + argument = *option [criterium *("OR" criterium)] + + option = ("--RECURSE" "=" ("NONE" / "ONE" / "DEEP")) + / (("--BASE" / "--FOLDERVIEW" / "--DOCVIEW" + / "--INDIRECT") + "=" bool) + + criterium = "EMPTY" / (term *("AND" term)) + + term = text-term / date-term / numeric-term / bool-term + + text-term = property ("CONT" / "!CONT" / ">=" / "<=" / "==" / "!=") + string *("-C" / "-R") + + date-term = property + (((">=" / "<=" / "==" / "!=") date) + / (("OLDER" / "YOUNGER") number)) + + numeric-term = property (">=" / "<=" / "==" / "!=") number + + bool-term = property ("TRUE" / "FALSE") + + property = 1*VCHAR + + string = DQUOTE + *(<any Unicode code point except DQUOTE or "\"> + / ("\" %x75 4HEXDIG) ; \uHHHH + / ("\" (DQUOTE / "\"))) + DQUOTE + + date = 1*2DIGIT "/" 1*2DIGIT "/" 4DIGIT ; mm/dd/yyyy + + number = ["+" / "-"] 1*DIGIT + */ + + sal_Unicode const * p = rInput.GetBuffer(); + sal_Unicode const * pEnd = p + rInput.Len(); + + // Parse options: + rInfo.Recursion = ucb::SearchRecursion_ONE_LEVEL; + rInfo.IncludeBase = true; + rInfo.RespectFolderViewRestrictions = true; + rInfo.RespectDocViewRestrictions = false; + rInfo.FollowIndirections = false; + enum OptionID { OPT_RECURSE, OPT_BASE, OPT_FOLDERVIEW, OPT_DOCVIEW, + OPT_INDIRECT, OPT_Count }; + struct OptionInfo + { + bool m_bSpecified; + sal_Bool * m_pValue; + }; + OptionInfo aOptions[OPT_Count]; + aOptions[OPT_RECURSE].m_bSpecified = false; + aOptions[OPT_RECURSE].m_pValue = 0; + aOptions[OPT_BASE].m_bSpecified = false; + aOptions[OPT_BASE].m_pValue = &rInfo.IncludeBase; + aOptions[OPT_FOLDERVIEW].m_bSpecified = false; + aOptions[OPT_FOLDERVIEW].m_pValue + = &rInfo.RespectFolderViewRestrictions; + aOptions[OPT_DOCVIEW].m_bSpecified = false; + aOptions[OPT_DOCVIEW].m_pValue = &rInfo.RespectDocViewRestrictions; + aOptions[OPT_INDIRECT].m_bSpecified = false; + aOptions[OPT_INDIRECT].m_pValue = &rInfo.FollowIndirections; + while (p != pEnd) + { + sal_Unicode const * q = p; + + skipWhiteSpace(q, pEnd); + if (pEnd - q < 2 || *q++ != '-' || *q++ != '-') + break; + String aOption(scanAtom(q, pEnd)); + OptionID eID; + if (aOption.EqualsIgnoreCaseAscii("recurse")) + eID = OPT_RECURSE; + else if (aOption.EqualsIgnoreCaseAscii("base")) + eID = OPT_BASE; + else if (aOption.EqualsIgnoreCaseAscii("folderview")) + eID = OPT_FOLDERVIEW; + else if (aOption.EqualsIgnoreCaseAscii("docview")) + eID = OPT_DOCVIEW; + else if (aOption.EqualsIgnoreCaseAscii("indirect")) + eID = OPT_INDIRECT; + else + break; + + if (aOptions[eID].m_bSpecified) + break; + aOptions[eID].m_bSpecified = true; + + skipWhiteSpace(q, pEnd); + if (q == pEnd || *q++ != '=') + break; + + skipWhiteSpace(q, pEnd); + String aValue(scanAtom(q, pEnd)); + if (eID == OPT_RECURSE) + { + if (aValue.EqualsIgnoreCaseAscii("none")) + rInfo.Recursion = ucb::SearchRecursion_NONE; + else if (aValue.EqualsIgnoreCaseAscii("one")) + rInfo.Recursion = ucb::SearchRecursion_ONE_LEVEL; + else if (aValue.EqualsIgnoreCaseAscii("deep")) + rInfo.Recursion = ucb::SearchRecursion_DEEP; + else + break; + } + else if (aValue.EqualsIgnoreCaseAscii("true")) + *aOptions[eID].m_pValue = true; + else if (aValue.EqualsIgnoreCaseAscii("false")) + *aOptions[eID].m_pValue = false; + else + break; + + p = q; + } + + // Parse criteria: + ucb::SearchCriterium aCriterium; + for (;;) + { + sal_Unicode const * q = p; + + // Parse either property name or "empty": + skipWhiteSpace(q, pEnd); + String aProperty(scanProperty(q, pEnd)); + sal_Unicode const * pPropertyEnd = q; + + // Parse operator: + skipWhiteSpace(q, pEnd); + String aOperator(scanOperator(q, pEnd)); + struct Operator + { + sal_Char const * m_pName; + sal_Int16 m_nText; + sal_Int16 m_nDate; + sal_Int16 m_nNumeric; + sal_Int16 m_nBool; + }; + static Operator const aOperators[] + = { { "cont", ucb::RuleOperator::CONTAINS, 0, 0, 0 }, + { "!cont", ucb::RuleOperator::CONTAINSNOT, 0, 0, 0 }, + { ">=", ucb::RuleOperator::GREATEREQUAL, + ucb::RuleOperator::GREATEREQUAL, + ucb::RuleOperator::GREATEREQUAL, 0 }, + { "<=", ucb::RuleOperator::LESSEQUAL, + ucb::RuleOperator::LESSEQUAL, ucb::RuleOperator::LESSEQUAL, + 0 }, + { "==", ucb::RuleOperator::EQUAL, ucb::RuleOperator::EQUAL, + ucb::RuleOperator::EQUAL, 0 }, + { "!=", ucb::RuleOperator::NOTEQUAL, + ucb::RuleOperator::NOTEQUAL, ucb::RuleOperator::NOTEQUAL, + 0 }, + { "true", 0, 0, 0, ucb::RuleOperator::VALUE_TRUE }, + { "false", 0, 0, 0, ucb::RuleOperator::VALUE_FALSE } }; + int const nOperatorCount = sizeof aOperators / sizeof (Operator); + Operator const * pTheOperator = 0; + for (int i = 0; i < nOperatorCount; ++i) + if (aOperator.EqualsIgnoreCaseAscii(aOperators[i].m_pName)) + { + pTheOperator = aOperators + i; + break; + } + bool bTerm = pTheOperator != 0; + + sal_Int16 nOperatorID; + uno::Any aTheOperand; + bool bCaseSensitive = false; + bool bRegularExpression = false; + if (bTerm) + { + skipWhiteSpace(q, pEnd); + bool bHasOperand = false; + + // Parse string operand: + if (!bHasOperand && pTheOperator->m_nText) + { + if (q != pEnd && *q == '"') + { + String aString; + for (sal_Unicode const * r = q + 1;;) + { + if (r == pEnd) + break; + sal_Unicode c = *r++; + if (c == '"') + { + bHasOperand = true; + aTheOperand <<= rtl::OUString(aString); + nOperatorID = pTheOperator->m_nText; + q = r; + break; + } + if (c == '\\') + { + if (r == pEnd) + break; + c = *r++; + if (c == 'u') + { + if (pEnd - r < 4) + break; + c = 0; + bool bBad = false; + for (int i = 0; i < 4; ++i) + { + int nWeight + = INetMIME::getHexWeight(*r++); + if (nWeight < 0) + { + bBad = false; + break; + } + c = sal_Unicode(c << 4 | nWeight); + } + if (bBad) + break; + } + else if (c != '"' && c != '\\') + break; + } + aString += c; + } + } + + // Parse "-C" and "-R": + if (bHasOperand) + for (;;) + { + skipWhiteSpace(q, pEnd); + if (pEnd - q >= 2 && q[0] == '-' + && (q[1] == 'C' || q[1] == 'c') + && !bCaseSensitive) + { + bCaseSensitive = true; + q += 2; + } + else if (pEnd - q >= 2 && q[0] == '-' + && (q[1] == 'R' || q[1] == 'r') + && !bRegularExpression) + { + bRegularExpression = true; + q += 2; + } + else + break; + } + } + + // Parse date operand: + if (!bHasOperand && pTheOperator->m_nDate != 0) + { + sal_Unicode const * r = q; + bool bOK = true; + USHORT nMonth = 0; + if (bOK && r != pEnd && INetMIME::isDigit(*r)) + nMonth = INetMIME::getWeight(*r++); + else + bOK = false; + if (bOK && r != pEnd && INetMIME::isDigit(*r)) + nMonth = 10 * nMonth + INetMIME::getWeight(*r++); + if (!(bOK && r != pEnd && *r++ == '/')) + bOK = false; + USHORT nDay = 0; + if (bOK && r != pEnd && INetMIME::isDigit(*r)) + nDay = INetMIME::getWeight(*r++); + else + bOK = false; + if (bOK && r != pEnd && INetMIME::isDigit(*r)) + nDay = 10 * nDay + INetMIME::getWeight(*r++); + if (!(bOK && r != pEnd && *r++ == '/')) + bOK = false; + USHORT nYear = 0; + for (int i = 0; bOK && i < 4; ++i) + if (r != pEnd && INetMIME::isDigit(*r)) + nYear = 10 * nYear + INetMIME::getWeight(*r++); + else + bOK = false; + if (bOK && Date(nDay, nMonth, nYear).IsValid()) + { + bHasOperand = true; + aTheOperand <<= util::Date(nDay, nMonth, nYear); + nOperatorID = pTheOperator->m_nDate; + q = r; + } + } + + // Parse number operand: + if (!bHasOperand && pTheOperator->m_nNumeric != 0) + { + sal_Unicode const * r = q; + bool bNegative = false; + if (*r == '+') + ++r; + else if (*r == '-') + { + bNegative = true; + ++r; + } + sal_uInt64 nNumber = 0; + bool bDigits = false; + while (r != pEnd && INetMIME::isDigit(*r)) + { + nNumber = 10 * nNumber + INetMIME::getWeight(*r++); + if (nNumber > std::numeric_limits< sal_Int32 >::max()) + { + bDigits = false; + break; + } + } + if (bDigits) + { + bHasOperand = true; + aTheOperand + <<= sal_Int32(bNegative ? -sal_Int32(nNumber) : + sal_Int32(nNumber)); + nOperatorID = pTheOperator->m_nNumeric; + q = r; + } + } + + // Bool operator has no operand: + if (!bHasOperand && pTheOperator->m_nBool != 0) + { + bHasOperand = true; + nOperatorID = pTheOperator->m_nBool; + } + + bTerm = bHasOperand; + } + + bool bEmpty = false; + if (bTerm) + { + aCriterium.Terms.realloc(aCriterium.Terms.getLength() + 1); + aCriterium.Terms[aCriterium.Terms.getLength() - 1] + = ucb::RuleTerm(aProperty, aTheOperand, nOperatorID, + bCaseSensitive, bRegularExpression); + } + else if (aCriterium.Terms.getLength() == 0 + && aProperty.EqualsIgnoreCaseAscii("empty")) + { + bEmpty = true; + q = pPropertyEnd; + } + + if (!(bTerm || bEmpty)) + break; + + p = q; + skipWhiteSpace(p, pEnd); + + q = p; + String aConnection(scanAtom(q, pEnd)); + if (p == pEnd || aConnection.EqualsIgnoreCaseAscii("or")) + { + rInfo.Criteria.realloc(rInfo.Criteria.getLength() + 1); + rInfo.Criteria[rInfo.Criteria.getLength() - 1] = aCriterium; + aCriterium = ucb::SearchCriterium(); + p = q; + } + else if (bTerm && aConnection.EqualsIgnoreCaseAscii("and")) + p = q; + else + break; + } + + skipWhiteSpace(p, pEnd); + return p == pEnd; +} + diff --git a/ucb/workben/ucb/srcharg.hxx b/ucb/workben/ucb/srcharg.hxx new file mode 100644 index 000000000000..31c7bc3b9b03 --- /dev/null +++ b/ucb/workben/ucb/srcharg.hxx @@ -0,0 +1,75 @@ +/************************************************************************* + * + * $RCSfile: srcharg.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:56:13 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef CHAOS_UCBDEMO_SRCHARG_HXX +#define CHAOS_UCBDEMO_SRCHARG_HXX + +class String; +namespace com { namespace sun { namespace star { namespace ucb { + struct SearchInfo; +} } } } + +//============================================================================ +bool parseSearchArgument(String const & rInput, + com::sun::star::ucb::SearchInfo & rInfo); + +#endif // CHAOS_UCBDEMO_SRCHARG_HXX + diff --git a/ucb/workben/ucb/ucbdemo.cxx b/ucb/workben/ucb/ucbdemo.cxx new file mode 100644 index 000000000000..d565f5cb4619 --- /dev/null +++ b/ucb/workben/ucb/ucbdemo.cxx @@ -0,0 +1,3086 @@ +/************************************************************************* + * + * $RCSfile: ucbdemo.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: kso $ $Date: 2000-10-16 14:56:13 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (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.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include <stack> + +#ifndef _VOS_DYNLOAD_HXX_ +#include <vos/dynload.hxx> +#endif +#ifndef _VOS_MUTEX_HXX_ +#include <vos/mutex.hxx> +#endif +#ifndef _VOS_PROFILE_HXX_ +#include <vos/profile.hxx> +#endif +#ifndef _VOS_PROCESS_HXX_ +#include <vos/process.hxx> +#endif +#ifndef _CPPUHELPER_SERVICEFACTORY_HXX_ +#include <cppuhelper/servicefactory.hxx> +#endif +#ifndef _COMPHELPER_PROCESSFACTORY_HXX_ +#include <comphelper/processfactory.hxx> +#endif +#ifndef _COM_SUN_STAR_UCB_CONTENTACTION_HPP_ +#include <com/sun/star/ucb/ContentAction.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_OPENCOMMANDARGUMENT2_HPP_ +#include <com/sun/star/ucb/OpenCommandArgument2.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_CONTENTRESULTSETCAPABILITY_HPP_ +#include <com/sun/star/ucb/ContentResultSetCapability.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_SEARCHCOMMANDARGUMENT_HPP_ +#include <com/sun/star/ucb/SearchCommandArgument.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_NAMECLASH_HPP_ +#include <com/sun/star/ucb/NameClash.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_TRANSFERINFO_HPP_ +#include <com/sun/star/ucb/TransferInfo.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCONTENTPROVIDER_HPP_ +#include <com/sun/star/ucb/XContentProvider.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCONTENTIDENTIFIERFACTORY_HPP_ +#include <com/sun/star/ucb/XContentIdentifierFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_COMMANDINFO_HPP_ +#include <com/sun/star/ucb/CommandInfo.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCONTENTPROVIDERCONFIGURATIONMANAGER_HPP_ +#include <com/sun/star/ucb/XContentProviderConfigurationManager.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCONTENTPROVIDERMANAGER_HPP_ +#include <com/sun/star/ucb/XContentProviderManager.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_PROPERTY_HPP_ +#include <com/sun/star/beans/Property.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XCOMPONENT_HPP_ +#include <com/sun/star/lang/XComponent.hpp> +#endif +#if 0 +#ifndef _COM_SUN_STAR_REGISTRY_XIMPLEMENTATIONREGISTRATION_HPP_ +#include <com/sun/star/registry/XImplementationRegistration.hpp> +#endif +#endif +#ifndef _COM_SUN_STAR_REGISTRY_XSIMPLEREGISTRY_HPP_ +#include <com/sun/star/registry/XSimpleRegistry.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_CHAOSPROGRESSSTART_HPP_ +#include <com/sun/star/ucb/CHAOSProgressStart.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_OPENMODE_HPP_ +#include <com/sun/star/ucb/OpenMode.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_NUMBEREDSORTINGINFO_HPP_ +#include <com/sun/star/ucb/NumberedSortingInfo.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_RESULTSETEXCEPTION_HPP_ +#include <com/sun/star/ucb/ResultSetException.hpp> +#endif +#ifndef _COM_SUN_STAR_IO_XOUTPUTSTREAM_HPP_ +#include <com/sun/star/io/XOutputStream.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XPROPERTYSETREGISTRYFACTORY_HPP_ +#include <com/sun/star/ucb/XPropertySetRegistryFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_XPROPERTYCONTAINER_HPP_ +#include <com/sun/star/beans/XPropertyContainer.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XPROGRESSHANDLER_HPP_ +#include <com/sun/star/ucb/XProgressHandler.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCOMMANDENVIRONMENT_HPP_ +#include <com/sun/star/ucb/XCommandEnvironment.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_XPROPERTIESCHANGELISTENER_HPP_ +#include <com/sun/star/beans/XPropertiesChangeListener.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_XPROPERTIESCHANGENOTIFIER_HPP_ +#include <com/sun/star/beans/XPropertiesChangeNotifier.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCOMMANDPROCESSOR_HPP_ +#include <com/sun/star/ucb/XCommandProcessor.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XDYNAMICRESULTSET_HPP_ +#include <com/sun/star/ucb/XDynamicResultSet.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_ +#include <com/sun/star/sdbc/XRow.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCONTENTACCESS_HPP_ +#include <com/sun/star/ucb/XContentAccess.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCOMMANDINFO_HPP_ +#include <com/sun/star/ucb/XCommandInfo.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_ +#include <com/sun/star/beans/PropertyValue.hpp> +#endif +#ifndef _COM_SUN_STAR_BRIDGE_XUNOURLRESOLVER_HPP_ +#include <com/sun/star/bridge/XUnoUrlResolver.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XSORTEDDYNAMICRESULTSETFACTORY_HPP_ +#include <com/sun/star/ucb/XSortedDynamicResultSetFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XPARAMETERIZEDCONTENTPROVIDER_HPP_ +#include <com/sun/star/ucb/XParameterizedContentProvider.hpp> +#endif + +#if 0 /*SB*/ +#ifndef _COM_SUN_STAR_UCB_XREMOTECONTENTPROVIDERACCEPTOR_HPP_ +#include <com/sun/star/ucb/XRemoteContentProviderAcceptor.hpp> +#endif +#endif /*SB*/ + +#ifndef _CPPUHELPER_WEAK_HXX_ +#include <cppuhelper/weak.hxx> +#endif + +#ifndef _TOOLS_DEBUG_HXX +#include <tools/debug.hxx> +#endif + +#ifndef _SV_WRKWIN_HXX //autogen +#include <vcl/wrkwin.hxx> +#endif +#ifndef _SV_TOOLBOX_HXX //autogen +#include <vcl/toolbox.hxx> +#endif +#ifndef _SV_EDIT_HXX //autogen +#include <vcl/edit.hxx> +#endif +#ifndef _SV_LSTBOX_HXX +#include <vcl/lstbox.hxx> +#endif +#ifndef _SV_SVAPP_HXX //autogen +#include <vcl/svapp.hxx> +#endif +#ifndef _SV_HELP_HXX //autogen +#include <vcl/help.hxx> +#endif + +#ifndef CHAOS_UCBDEMO_SRCHARG_HXX +#include <srcharg.hxx> +#endif + +#ifndef _MAX_PATH +#include <limits.h> +#define _MAX_PATH PATH_MAX +#endif + +using namespace vos; +using namespace rtl; +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::beans; +using namespace com::sun::star::registry; +using namespace com::sun::star::ucb; +using namespace com::sun::star::task; +using namespace com::sun::star::io; +using namespace com::sun::star::sdbc; +using namespace com::sun::star::container; +using namespace com::sun::star::bridge; +using namespace com::sun::star::connection; + +/*======================================================================== + * + * MyOutWindow. + * + *======================================================================*/ + +#define MYOUTWINDOW_MAXLINES 4096 + +class MyOutWindow : public ListBox +{ +public: + MyOutWindow( Window *pParent, WinBits nWinStyle ) + : ListBox ( pParent, nWinStyle | WB_AUTOHSCROLL ) {} + ~MyOutWindow() {} + + void Append( const String &rLine ); +}; + +//------------------------------------------------------------------------- +void MyOutWindow::Append( const String &rLine ) +{ + String aLine( rLine ); + + xub_StrLen nPos = aLine.Search( '\n' ); + while ( nPos != STRING_NOTFOUND ) + { + if ( GetEntryCount() >= MYOUTWINDOW_MAXLINES ) + RemoveEntry( 0 ); + + InsertEntry( aLine.Copy( 0, nPos ) ); + + aLine.Erase( 0, nPos + 1 ); + nPos = aLine.Search( '\n' ); + } + + if ( GetEntryCount() >= MYOUTWINDOW_MAXLINES ) + RemoveEntry( 0 ); + + InsertEntry( aLine ); + + SetTopEntry( MYOUTWINDOW_MAXLINES - 1 ); +} + +/*======================================================================== + * + * MessagePrinter. + * + *=======================================================================*/ + +class MessagePrinter +{ +protected: + MyOutWindow* m_pOutEdit; + +public: + MessagePrinter( MyOutWindow* pOutEdit = NULL ) + : m_pOutEdit( pOutEdit ) {} + void setOutEdit( MyOutWindow* pOutEdit ) + { m_pOutEdit = pOutEdit; } + void print( const sal_Char* pText ); + void print( const UniString& rText ); +}; + +//------------------------------------------------------------------------- +void MessagePrinter::print( const sal_Char* pText ) +{ + print( UniString::CreateFromAscii( pText ) ); +} + +//------------------------------------------------------------------------- +void MessagePrinter::print( const UniString& rText ) +{ + vos::OGuard aGuard( Application::GetSolarMutex() ); + + if ( m_pOutEdit ) + { + m_pOutEdit->Append( rText ); + m_pOutEdit->Update(); + } +} + +//============================================================================ +// +// TestOutputStream +// +//============================================================================ + +class TestOutputStream: + public cppu::OWeakObject, + public XOutputStream +{ + OUString m_sStart; + bool m_bMore; + +public: + TestOutputStream(): m_bMore(false) {} + + virtual com::sun::star::uno::Any SAL_CALL queryInterface( + const com::sun::star::uno::Type & rType) + throw(RuntimeException); + virtual void SAL_CALL acquire() throw (RuntimeException) + { OWeakObject::acquire(); } + + virtual void SAL_CALL release() throw (RuntimeException) + { OWeakObject::release(); } + + virtual void SAL_CALL writeBytes(const Sequence< sal_Int8 > & rData) + throw(RuntimeException); + + virtual void SAL_CALL flush() throw() {} + + virtual void SAL_CALL closeOutput() throw() {}; + + OUString getStart() const; +}; + +//============================================================================ +// virtual +Any SAL_CALL +TestOutputStream::queryInterface(const com::sun::star::uno::Type & rType) + throw(RuntimeException) +{ + Any aRet = cppu::queryInterface(rType, + static_cast< XOutputStream * >(this)); + return aRet.hasValue() ? aRet : OWeakObject::queryInterface(rType); +} + +//============================================================================ +// virtual +void SAL_CALL TestOutputStream::writeBytes(const Sequence< sal_Int8 > & rData) + throw(RuntimeException) +{ + sal_Int32 nLen = rData.getLength(); + if (m_sStart.getLength() + nLen > 500) + { + nLen = 500 - m_sStart.getLength(); + m_bMore = true; + } + m_sStart + += OUString(reinterpret_cast< const sal_Char * >(rData. + getConstArray()), + nLen, RTL_TEXTENCODING_ISO_8859_1); +} + +//============================================================================ +OUString TestOutputStream::getStart() const +{ + OUString sResult = m_sStart; + if (m_bMore) + sResult += OUString::createFromAscii("..."); + return sResult; +} + +/*======================================================================== + * + * ProgressHandler. + * + *=======================================================================*/ + +class ProgressHandler: + public cppu::OWeakObject, + public XProgressHandler +{ + MessagePrinter & m_rPrinter; + + OUString toString(const Any & rStatus); + +public: + ProgressHandler(MessagePrinter & rThePrinter): m_rPrinter(rThePrinter) {} + + virtual com::sun::star::uno::Any SAL_CALL queryInterface( + const com::sun::star::uno::Type & rType) + throw(RuntimeException); + + virtual void SAL_CALL acquire() throw (RuntimeException) + { OWeakObject::acquire(); } + + virtual void SAL_CALL release() throw (RuntimeException) + { OWeakObject::release(); } + + virtual void SAL_CALL push(const Any & rStatus) throw (RuntimeException); + + virtual void SAL_CALL update(const Any & rStatus) + throw (RuntimeException); + + virtual void SAL_CALL pop() throw (RuntimeException); +}; + +OUString ProgressHandler::toString(const Any & rStatus) +{ + CHAOSProgressStart aStart; + if (rStatus >>= aStart) + { + OUString sResult; + if (aStart.Text.getLength() > 0) + { + sResult = aStart.Text; + sResult += OUString::createFromAscii(" "); + } + sResult += OUString::createFromAscii("["); + sResult += OUString::valueOf(aStart.Minimum); + sResult += OUString::createFromAscii(".."); + sResult += OUString::valueOf(aStart.Maximum); + sResult += OUString::createFromAscii("]"); + return sResult; + } + + OUString sText; + if (rStatus >>= sText) + return sText; + + sal_Int32 nValue; + if (rStatus >>= nValue) + { + OUString sResult = OUString::createFromAscii(".."); + sResult += OUString::valueOf(nValue); + sResult += OUString::createFromAscii(".."); + return OUString(sResult); + } + + return OUString::createFromAscii("(Unknown object)"); +} + +//============================================================================ +// virtual +Any SAL_CALL +ProgressHandler::queryInterface( const com::sun::star::uno::Type & rType ) + throw(RuntimeException) +{ + Any aRet = cppu::queryInterface( + rType, + static_cast< XProgressHandler* >(this)); + return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ); +} + +//============================================================================ +// virtual +void SAL_CALL ProgressHandler::push(const Any & rStatus) + throw (RuntimeException) +{ + OUString sMessage = OUString::createFromAscii("Status push: "); + sMessage += toString(rStatus); + m_rPrinter.print(sMessage); +} + +//============================================================================ +// virtual +void SAL_CALL ProgressHandler::update(const Any & rStatus) + throw (RuntimeException) +{ + OUString sMessage = OUString::createFromAscii("Status update: "); + sMessage += toString(rStatus); + m_rPrinter.print(sMessage); +} + +//============================================================================ +// virtual +void SAL_CALL ProgressHandler::pop() throw (RuntimeException) +{ + m_rPrinter.print("Status pop"); +} + +/*======================================================================== + * + * Ucb. + * + *=======================================================================*/ + +#define UCB_MODULE_NAME "ucb1" + +class Ucb : public MessagePrinter +{ +public: + enum Remote { REMOTE_NO, REMOTE_UCB, REMOTE_UCP }; + +private: + Reference< XMultiServiceFactory > m_xFac; + Reference< XContentProviderManager > m_xProvMgr; + Reference< XContentProvider > m_xProv; + Reference< XContentIdentifierFactory > m_xIdFac; + Remote m_eRemote; + sal_Bool m_bInited : 1; + + static OUString getUnoURL(); + +public: + Ucb( Reference< XMultiServiceFactory >& rxFactory, Remote eRemote ); + ~Ucb(); + + sal_Bool init(); + + Reference< XMultiServiceFactory > getServiceFactory() const + { return m_xFac; } + + XContentIdentifierFactory* getContentIdentifierFactory(); + XContentProvider* getContentProvider(); + + static sal_Bool install ( Reference< XMultiServiceFactory >& rxFactory, + sal_Bool bRemoteUCB ); + static sal_Bool uninstall( Reference< XMultiServiceFactory >& rxFactory ); + + static OUString m_aProtocol; +}; + +// static +OUString Ucb::m_aProtocol; + +//------------------------------------------------------------------------- +// static +OUString Ucb::getUnoURL() +{ + OUString aUnoURL(OUString::createFromAscii( + "uno:socket,host=localhost,port=8121;")); + if (m_aProtocol.getLength() == 0) + aUnoURL += OUString::createFromAscii("urp"); + else + aUnoURL += m_aProtocol; + aUnoURL += OUString::createFromAscii(";UCB.Factory"); + return aUnoURL; +} + +//------------------------------------------------------------------------- +Ucb::Ucb( Reference< XMultiServiceFactory >& rxFactory, Remote eRemote ) +: m_xFac( rxFactory ), + m_bInited( sal_False ), + m_eRemote( eRemote ) +{ +} + +//------------------------------------------------------------------------- +Ucb::~Ucb() +{ +} + +//------------------------------------------------------------------------- +sal_Bool Ucb::init() +{ + if ( m_bInited ) + return sal_True; + + switch ( m_eRemote ) + { + case REMOTE_NO: + // Create auto configured UCB: + if ( m_xFac.is() ) + { + Sequence< Any > aArgs(1); + aArgs[0] <<= sal_True; + m_xProvMgr = Reference< XContentProviderManager >( + m_xFac->createInstanceWithArguments( + OUString::createFromAscii( + "com.sun.star.ucb.UniversalContentBroker" ), + aArgs ), + UNO_QUERY ); + } + break; + + case REMOTE_UCB: + { + if (!m_xFac.is()) + { + print("No XMultiServiceFactory"); + return false; + } + + Reference< XUnoUrlResolver > xResolver; + try + { + xResolver + = Reference< XUnoUrlResolver >( + m_xFac-> + createInstance( + OUString::createFromAscii( + "com.sun.star.bridge.UnoUrlResolver")), + UNO_QUERY); + } + catch (RuntimeException const &) { throw; } + catch (Exception const &) {} + if (!xResolver.is()) + { + print("Bad com.sun.star.bridge.UnoUrlResolver"); + return false; + } + + Reference< XMultiServiceFactory > xRemoteFactory; + try + { + xRemoteFactory + = Reference< XMultiServiceFactory >(xResolver-> + resolve( + getUnoURL()), + UNO_QUERY); + } + catch (NoConnectException const &) {} + catch (ConnectionSetupException const &) {} + catch (IllegalArgumentException const &) {} + if (!xRemoteFactory.is()) + { + print("Can't connect to remote UCB"); + return false; + } + + try + { + xRemoteFactory + = Reference< XMultiServiceFactory >( + xRemoteFactory-> + createInstance( + OUString::createFromAscii( + "com.sun.star.lang.ServiceManager")), + UNO_QUERY); + } + catch (RuntimeException const &) { throw; } + catch (Exception const &) {} + if (!xRemoteFactory.is()) + { + print("Bad remote com.sun.star.lang.ServiceManager"); + return false; + } + + try + { + //@@@ The remote broker service should be created using + // createInstanceWithArguments(), specifing whether and how + // the broker should be configured. Not supplying these + // arguments implies that the remote broker service must + // already be instantiated and configured when this call is + // made: + m_xProvMgr + = Reference< XContentProviderManager >( + xRemoteFactory-> + createInstance( + OUString::createFromAscii( + "com.sun.star.ucb." + "UniversalContentBroker")), + UNO_QUERY); + } + catch (RuntimeException const &) { throw; } + catch (Exception const &) {} + if (!m_xProvMgr.is()) + { + print("Bad remote com.sun.star.ucb.UniversalContentBroker"); + return false; + } + break; + } + + case REMOTE_UCP: + { + // Create unconfigured UCB: + Sequence< Any > aArgs(1); + aArgs[0] <<= sal_False; + if ( m_xFac.is() ) + m_xProvMgr = Reference< XContentProviderManager >( + m_xFac->createInstanceWithArguments( + OUString::createFromAscii( + "com.sun.star.ucb.UniversalContentBroker" ), + aArgs ), + UNO_QUERY ); + + if ( m_xProvMgr.is() ) + { + Reference< XContentProvider > xProvider; + try + { + xProvider + = Reference< XContentProvider >( + m_xFac-> + createInstance( + OUString::createFromAscii( + "com.sun.star.ucb." + "RemoteAccessContentProvider")), + UNO_QUERY); + } + catch (RuntimeException const &) { throw; } + catch (Exception const &) {} + + OUString aTemplate(OUString::createFromAscii(".*")); + + Reference< XParameterizedContentProvider > + xParameterized(xProvider, UNO_QUERY); + if (xParameterized.is()) + { + Reference< XContentProvider > xInstance; + try + { + xInstance + = xParameterized->registerInstance(aTemplate, + getUnoURL(), + true); + //@@@ if this call replaces an old instance, the + // commit-or-rollback code below will not work + } + catch (IllegalArgumentException const &) {} + + if (xInstance.is()) + xProvider = xInstance; + } + + if (xProvider.is()) + try + { + m_xProvMgr->registerContentProvider(xProvider, + aTemplate, + true); + } + catch (DuplicateProviderException const &) + { + if (xParameterized.is()) + try + { + xParameterized-> + deregisterInstance(aTemplate, + getUnoURL()); + } + catch (IllegalArgumentException const &) {} + } + catch (...) + { + if (xParameterized.is()) + try + { + xParameterized-> + deregisterInstance(aTemplate, + getUnoURL()); + } + catch (IllegalArgumentException const &) {} + throw; + } + } + break; + } + } + + m_bInited = m_xProvMgr.is(); + if (m_bInited) + { + print( "Registered schemes:" ); + Sequence< ContentProviderInfo > aInfo = + m_xProvMgr->queryContentProviders(); + const ContentProviderInfo* pInfo = aInfo.getConstArray(); + sal_uInt32 nCount = aInfo.getLength(); + for ( sal_uInt32 m = 0; m < nCount; ++m ) + { + UniString aText( UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( " " ) ) ); + aText += UniString( pInfo[ m ].Scheme ); + print( aText ); + } + } + else + print( "Error creating UCB service! Did you run 'ucbdemo -i'?" ); + return m_bInited; +} + +//------------------------------------------------------------------------- +XContentIdentifierFactory* Ucb::getContentIdentifierFactory() +{ + if ( !m_xIdFac.is() ) + { + if ( init() ) + m_xIdFac = + Reference< XContentIdentifierFactory >( m_xProvMgr, UNO_QUERY ); + } + + return m_xIdFac.get(); +} + +//------------------------------------------------------------------------- +XContentProvider* Ucb::getContentProvider() +{ + if ( !m_xProv.is() ) + { + if ( init() ) + m_xProv = Reference< XContentProvider >( m_xProvMgr, UNO_QUERY ); + } + + return m_xProv.get(); +} + +//------------------------------------------------------------------------- +// static +sal_Bool Ucb::install( Reference< XMultiServiceFactory >& rxFactory, + sal_Bool bRemoteUCB ) +{ + if ( !rxFactory.is() ) + return sal_False; + +#if 0 + Reference< XInterface > xIfc( + rxFactory->createInstance ( + OUString::createFromAscii( + "com.sun.star.registry.ImplementationRegistration" ) ) ); + + if ( !xIfc.is() ) + return sal_False; + + Reference< XImplementationRegistration > xReg( xIfc, UNO_QUERY ); + if ( !xReg.is() ) + return sal_False; + + OUString aLibName; + vos::ORealDynamicLoader::computeLibraryName( + OUString::createFromAscii( UCB_MODULE_NAME ), aLibName ); + try + { + xReg->registerImplementation( + OUString::createFromAscii( + "com.sun.star.loader.SharedLibrary" ), + aLibName, + Reference< XSimpleRegistry >() ); + } + catch ( CannotRegisterImplementationException& ) + { + DBG_ERROR( "registerImplementation failed!" ); + return sal_False; + } +#else + Reference< XInterface > +#endif + + ////////////////////////////////////////////////////////////////////// + // Store CHAOS content provider service information in registry... + ////////////////////////////////////////////////////////////////////// + + xIfc = rxFactory->createInstance( + OUString::createFromAscii( "com.sun.star.ucb.Configuration" ) ); + + Reference< XContentProviderConfigurationManager > + xManager( xIfc, UNO_QUERY ); + if ( !xManager.is() ) + { + DBG_ERROR( "Error creating service 'com.sun.star.ucb.Configuration'!" ); + return sal_False; + } + + static sal_Char const * const aKeys[] + = { "ContentProviderServices", "LocalContentProviderServices", 0 }; + for (sal_Char const * const * p = aKeys; *p; ++p) + { + Reference< XContentProviderConfiguration > + xConfig(xManager->queryContentProviderConfiguration( + OUString::createFromAscii(*p))); + if (xConfig.is()) + if (bRemoteUCB && p == aKeys) + { +#if 1 + xConfig->addContentProviderService( + OUString::createFromAscii( ".*" ), + OUString::createFromAscii( + "com.sun.star.ucb.RemoteAccessContentProvider" ), + getUnoURL(), + sal_False ); +#else + xConfig->addContentProviderService( + OUString::createFromAscii( ".*" ), + OUString::createFromAscii( + "com.sun.star.ucb.RemoteAccessContentProvider" ), + OUString::createFromAscii( + "uno:socket,host=munch,port=8121;urp;UCB.Factory" ), + sal_False ); + xConfig->addContentProviderService( + OUString::createFromAscii( + "\"file://munch\"(([/?#].*)?)->\"file://\"\\1" ), + OUString::createFromAscii( + "com.sun.star.ucb.RemoteAccessContentProvider" ), + OUString::createFromAscii( + "uno:socket,host=munch,port=8121;urp;UCB.Factory" ), + sal_False ); +// xConfig->addContentProviderService( +// OUString::createFromAscii( +// "\"file://\"[^/?#]+([/?#].*)?" ), +// OUString::createFromAscii( +// "com.sun.star.ucb.RemoteAccessContentProvider" ), +// OUString::createFromAscii( +// "uno:socket,host=munch,port=8121;urp;UCB.Factory" ), +// sal_False ); + xConfig->addContentProviderService( + OUString::createFromAscii( "file" ), + OUString::createFromAscii( + "com.sun.star.ucb.FileContentProvider" ), + OUString(), + sal_False ); +#endif + } + else + { + ////////////////////////////////////////////////////////////// + // com.sun.star.ucb.HierarchyContentProvider + ////////////////////////////////////////////////////////////// + + xConfig->addContentProviderService( + OUString::createFromAscii( "vnd.sun.star.hier" ), + OUString::createFromAscii( + "com.sun.star.ucb.HierarchyContentProvider" ), + OUString(), + sal_False ); + + ////////////////////////////////////////////////////////////// + // com.sun.star.ucb.RemoteAccessContentProvider + ////////////////////////////////////////////////////////////// + + if (p == aKeys) + xConfig->addContentProviderService( + OUString::createFromAscii( "vnd.sun.star.ucb" ), + OUString::createFromAscii( + "com.sun.star.ucb.RemoteAccessContentProvider" ), + OUString(), + sal_False ); + + ////////////////////////////////////////////////////////////// + // com.sun.star.ucb.FileContentProvider + ////////////////////////////////////////////////////////////// + + xConfig->addContentProviderService( + OUString::createFromAscii( "file" ), + OUString::createFromAscii( + "com.sun.star.ucb.FileContentProvider" ), + OUString(), + sal_False ); + + ////////////////////////////////////////////////////////////// + // com.sun.star.ucb.ChaosContentProvider + ////////////////////////////////////////////////////////////// + + static const OUString aProvider( + OUString::createFromAscii( + "com.sun.star.ucb.ChaosContentProvider" ) ); + + // Note: These are the registrations necessary to get working + // all(!) services provided by CHAOS. + + // Official schemes. + + xConfig->addContentProviderService( + OUString::createFromAscii( "ftp" ), + aProvider, + OUString(), + sal_False ); + xConfig->addContentProviderService( + OUString::createFromAscii( "http" ), + aProvider, + OUString(), + sal_False ); + xConfig->addContentProviderService( + OUString::createFromAscii( "imap" ), + aProvider, + OUString(), + sal_False ); + xConfig->addContentProviderService( + OUString::createFromAscii( "news" ), + aProvider, + OUString(), + sal_False ); + xConfig->addContentProviderService( + OUString::createFromAscii( "vnd.sun.staroffice.out" ), + aProvider, + OUString(), + sal_False ); + xConfig->addContentProviderService( + OUString::createFromAscii( "vnd.sun.staroffice.pop3" ), + aProvider, + OUString(), + sal_False ); + xConfig->addContentProviderService( + OUString::createFromAscii( "vnd.sun.staroffice.searchfolder" ), + aProvider, + OUString(), + sal_False ); + xConfig->addContentProviderService( + OUString::createFromAscii( "vnd.sun.staroffice.trashcan" ), + aProvider, + OUString(), + sal_False ); + xConfig->addContentProviderService( + OUString::createFromAscii( "vnd.sun.staroffice.vim" ), + aProvider, + OUString(), + sal_False ); + + // Additional internal schemes. + xConfig->addContentProviderService( + OUString::createFromAscii( "out" ), + aProvider, + OUString(), + sal_False ); + xConfig->addContentProviderService( + OUString::createFromAscii( "pop3" ), + aProvider, + OUString(), + sal_False ); + xConfig->addContentProviderService( + OUString::createFromAscii( "private" ), + aProvider, + OUString(), + sal_False ); + xConfig->addContentProviderService( + OUString::createFromAscii( "vim" ), + aProvider, + OUString(), + sal_False ); + } + } + + return sal_True; +} + +//------------------------------------------------------------------------- +// static +sal_Bool Ucb::uninstall( Reference< XMultiServiceFactory >& rxFactory ) +{ +#if 0 + if ( !rxFactory.is() ) + return sal_False; + + Reference< XInterface > xIfc( + rxFactory->createInstance ( + OUString::createFromAscii( + "com.sun.star.registry.ImplementationRegistration" ) ) ); + + if ( !xIfc.is() ) + return sal_False; + + Reference< XImplementationRegistration > xReg( xIfc, UNO_QUERY ); + if ( !xReg.is() ) + return sal_False; + + OUString aLibName; + vos::ORealDynamicLoader::computeLibraryName( + OUString::createFromAscii( UCB_MODULE_NAME ), aLibName ); + + sal_Bool bRet = sal_True; + + try + { + bRet = xReg->revokeImplementation( + aLibName, Reference< XSimpleRegistry >() ); + } + catch ( ... ) + { + return sal_False; + } + + return bRet; +#else + if ( rxFactory.is() ) + { + Reference< XPropertySet > xSet( rxFactory, UNO_QUERY ); + if ( xSet.is() ) + { + Any aValue; + + try + { + aValue = xSet->getPropertyValue( + OUString::createFromAscii( "Registry" ) ); + } + catch ( UnknownPropertyException& ) {} + catch ( WrappedTargetException& ) {} + + Reference< XSimpleRegistry > xReg( + *(Reference< XInterface >*)aValue.getValue(), UNO_QUERY ); + + if ( xReg.is() ) + try + { + Reference< XRegistryKey > xRootKey( xReg->getRootKey() ); + if ( xRootKey.is() ) + { + Reference< XRegistryKey > xImplKey( + xRootKey->createKey( + OUString::createFromAscii( + "/IMPLEMENTATIONS/UcbConfiguration" ) ) ); + if ( xImplKey.is() ) + { + sal_Bool bSuccess = sal_True; + try + { + xImplKey-> + deleteKey( + OUString::createFromAscii( + "ContentProviderServices" ) ); + } + catch ( InvalidRegistryException& ) + { + bSuccess = sal_False; + } + try + { + xImplKey-> + deleteKey( + OUString::createFromAscii( + "LocalContentProviderServices" ) ); + } + catch ( InvalidRegistryException& ) + { + bSuccess = sal_False; + } + return bSuccess; + } + } + } + catch( InvalidRegistryException& ) {} + catch( InvalidValueException& ) {} + } + } + + return sal_False; +#endif +} + +/*======================================================================== + * + * UcbTaskEnvironment. + * + *=======================================================================*/ + +class UcbTaskEnvironment : public cppu::OWeakObject, + public XCommandEnvironment +{ + Reference< XInteractionHandler > m_xInteractionHandler; + Reference< XProgressHandler > m_xProgressHandler; + +public: + UcbTaskEnvironment( const Reference< XInteractionHandler>& + rxInteractionHandler, + const Reference< XProgressHandler>& + rxProgressHandler ); + virtual ~UcbTaskEnvironment(); + + // Interface implementations... + + // XInterface + + virtual com::sun::star::uno::Any SAL_CALL queryInterface( + const com::sun::star::uno::Type & rType ) + throw( RuntimeException ); + virtual void SAL_CALL acquire() + throw( RuntimeException ); + virtual void SAL_CALL release() + throw( RuntimeException ); + + // XCommandEnvironemnt + + virtual Reference<XInteractionHandler> SAL_CALL getInteractionHandler() + throw (RuntimeException) + { return m_xInteractionHandler; } + + virtual Reference<XProgressHandler> SAL_CALL getProgressHandler() + throw (RuntimeException) + { return m_xProgressHandler; } + + // !!! Das Interface ist noch nicht vollstaendig !!! + // -- application settings -> client language, etc. + // -- ??? +}; + +//------------------------------------------------------------------------- +UcbTaskEnvironment::UcbTaskEnvironment( + const Reference< XInteractionHandler >& + rxInteractionHandler, + const Reference< XProgressHandler >& + rxProgressHandler ) +: m_xInteractionHandler( rxInteractionHandler ), + m_xProgressHandler( rxProgressHandler ) +{ +} + +//------------------------------------------------------------------------- +// virtual +UcbTaskEnvironment::~UcbTaskEnvironment() +{ +} + +//---------------------------------------------------------------------------- +// +// XInterface methods +// +//---------------------------------------------------------------------------- + +// virtual +Any SAL_CALL +UcbTaskEnvironment::queryInterface( const com::sun::star::uno::Type & rType ) + throw( RuntimeException ) +{ + Any aRet = cppu::queryInterface( + rType, + static_cast< XCommandEnvironment* >( this ) ); + return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ); +} + +//---------------------------------------------------------------------------- +// virtual +void SAL_CALL UcbTaskEnvironment::acquire() + throw( RuntimeException ) +{ + OWeakObject::acquire(); +} + +//---------------------------------------------------------------------------- +// virtual +void SAL_CALL UcbTaskEnvironment::release() + throw( RuntimeException ) +{ + OWeakObject::release(); +} + +/*======================================================================== + * + * UcbContent. + * + *=======================================================================*/ + +class UcbContent : public MessagePrinter, + public cppu::OWeakObject, + public XContentEventListener, + public XPropertiesChangeListener +{ + Ucb& m_rUCB; + Reference< XContent > m_xContent; + sal_Int32 m_aCommandId; + + struct OpenStackEntry + { + Reference< XContentIdentifier > m_xIdentifier; + Reference< XContent > m_xContent; + sal_uInt32 m_nLevel; + bool m_bUseIdentifier; + + OpenStackEntry(Reference< XContentIdentifier > const & rTheIdentifier, + sal_uInt32 nTheLevel): + m_xIdentifier(rTheIdentifier), m_nLevel(nTheLevel), + m_bUseIdentifier(true) {} + + OpenStackEntry(Reference< XContent > const & rTheContent, + sal_uInt32 nTheLevel): + m_xContent(rTheContent), m_nLevel(nTheLevel), + m_bUseIdentifier(false) {} + }; + typedef std::stack< OpenStackEntry > OpenStack; + +private: + UcbContent( Ucb& rUCB, Reference< XContent >& rxContent, MyOutWindow* pOutEdit ); + +protected: + virtual ~UcbContent(); + +public: + static UcbContent* create( + Ucb& rUCB, const UniString& rURL, MyOutWindow* pOutEdit ); + void dispose(); + + const UniString getURL() const; + const UniString getType() const; + + Sequence< CommandInfo > getCommands(); + Sequence< Property > getProperties(); + + Any executeCommand ( const OUString& rName, const Any& rArgument, + bool bPrint = true ); + Any getPropertyValue( const OUString& rName ); + void setPropertyValue( const OUString& rName, const Any& rValue ); + void addProperty ( const OUString& rName, const Any& rValue ); + void removeProperty ( const OUString& rName ); + + OUString getStringPropertyValue( const OUString& rName ); + void setStringPropertyValue( const OUString& rName, const OUString& rValue ); + void addStringProperty( const OUString& rName, const OUString& rValue ); + void open( const OUString & rName, const UniString& rInput, + bool bPrint, bool bTiming, bool bSort, + OpenStack * pStack = 0, sal_uInt32 nLevel = 0, + sal_Int32 nFetchSize = 0 ); + void openAll( Ucb& rUCB, bool bPrint, bool bTiming, bool bSort, + sal_Int32 nFetchSize ); + void transfer( const OUString& rSourceURL, sal_Bool bMove ); + void destroy(); + + // XInterface + virtual com::sun::star::uno::Any SAL_CALL + queryInterface( const com::sun::star::uno::Type & rType ) + throw( RuntimeException ); + virtual void SAL_CALL + acquire() + throw( RuntimeException ); + virtual void SAL_CALL + release() + throw( RuntimeException ); + + // XEventListener + // ( base interface of XContentEventListener, XPropertiesChangeListener ) + virtual void SAL_CALL + disposing( const EventObject& Source ) + throw( RuntimeException ); + + // XContentEventListener + virtual void SAL_CALL + contentEvent( const ContentEvent& evt ) + throw( RuntimeException ); + + // XPropertiesChangeListener + virtual void SAL_CALL + propertiesChange( const Sequence< PropertyChangeEvent >& evt ) + throw( RuntimeException ); +}; + +//------------------------------------------------------------------------- +UcbContent::UcbContent( Ucb& rUCB, Reference< XContent >& rxContent, MyOutWindow* pOutEdit) +: MessagePrinter( pOutEdit ), + m_rUCB( rUCB ), + m_xContent( rxContent ), + m_aCommandId( 0 ) +{ + Reference< XCommandProcessor > xProc( rxContent, UNO_QUERY ); + if ( xProc.is() ) + { + // Generally, one command identifier per thread is enough. It + // can be used for all commands executed by the processor which + // created this id. + m_aCommandId = xProc->createCommandIdentifier(); + } +} + +//---------------------------------------------------------------------------- +// virtual +UcbContent::~UcbContent() +{ +} + +//------------------------------------------------------------------------- +// static +UcbContent* UcbContent::create( + Ucb& rUCB, const UniString& rURL, MyOutWindow* pOutEdit ) +{ + if ( !rURL.Len() ) + return NULL; + + ////////////////////////////////////////////////////////////////////// + // Get XContentIdentifier interface from UCB and let it create an + // identifer for the given URL. + ////////////////////////////////////////////////////////////////////// + + Reference< XContentIdentifierFactory > xIdFac = + rUCB.getContentIdentifierFactory(); + if ( !xIdFac.is() ) + return NULL; + + Reference< XContentIdentifier > xId = + xIdFac->createContentIdentifier( rURL ); + if ( !xId.is() ) + return NULL; + + ////////////////////////////////////////////////////////////////////// + // Get XContentProvider interface from UCB and let it create a + // content for the given identifier. + ////////////////////////////////////////////////////////////////////// + + Reference< XContentProvider > xProv = rUCB.getContentProvider(); + if ( !xProv.is() ) + return NULL; + + Reference< XContent > xContent; + try + { + xContent = xProv->queryContent( xId ); + } + catch (IllegalIdentifierException const &) {} + if ( !xContent.is() ) + return NULL; + + UcbContent* pNew = new UcbContent( rUCB, xContent, pOutEdit ); + pNew->acquire(); + + // Register listener(s). + xContent->addContentEventListener( pNew ); + + Reference< XPropertiesChangeNotifier > xNotifier( xContent, UNO_QUERY ); + if ( xNotifier.is() ) + { + // Empty sequence -> interested in any property changes. + xNotifier->addPropertiesChangeListener( Sequence< OUString >(), pNew ); + } + + return pNew; +} + +//------------------------------------------------------------------------- +const UniString UcbContent::getURL() const +{ + Reference< XContentIdentifier > xId( m_xContent->getIdentifier() ); + if ( xId.is() ) + return UniString( xId->getContentIdentifier() ); + + return UniString(); +} + +//------------------------------------------------------------------------- +const UniString UcbContent::getType() const +{ + const UniString aType( m_xContent->getContentType() ); + return aType; +} + +//------------------------------------------------------------------------- +void UcbContent::dispose() +{ + Reference< XComponent > xComponent( m_xContent, UNO_QUERY ); + if ( xComponent.is() ) + xComponent->dispose(); +} + +//---------------------------------------------------------------------------- +Any UcbContent::executeCommand( const OUString& rName, + const Any& rArgument, + bool bPrint ) +{ + Reference< XCommandProcessor > xProc( m_xContent, UNO_QUERY ); + if ( xProc.is() ) + { + Command aCommand; + aCommand.Name = rName; + aCommand.Handle = -1; /* unknown */ + aCommand.Argument = rArgument; + + Reference< XInteractionHandler > xInteractionHandler; + if (m_rUCB.getServiceFactory().is()) + xInteractionHandler + = Reference< XInteractionHandler >( + m_rUCB.getServiceFactory()-> + createInstance( + OUString::createFromAscii( + "com.sun.star.uui.InteractionHandler")), + UNO_QUERY); + Reference< XProgressHandler > + xProgressHandler(new ProgressHandler(m_rUCB)); + Reference< XCommandEnvironment > xEnv( + new UcbTaskEnvironment( xInteractionHandler, + xProgressHandler ) ); + + if ( bPrint ) + { + UniString aText( UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( + "Executing command: " ) ) ); + aText += UniString( rName ); + print( aText ); + } + + // Execute command + Any aResult; + bool bException = false; + bool bAborted = false; + try + { + aResult = xProc->execute( aCommand, m_aCommandId, xEnv ); + } + catch ( CommandAbortedException ) + { + bAborted = true; + } + catch ( Exception ) + { + bException = true; + } + + if ( bPrint ) + { + if ( bException ) + print( "execute(...) threw an exception!" ); + + if ( bAborted ) + print( "execute(...) aborted!" ); + + if ( !bException && !bAborted ) + print( "execute() finished." ); + } + + return aResult; + } + + print( "executeCommand failed!" ); + return Any(); +} + +//---------------------------------------------------------------------------- +void UcbContent::open( const OUString & rName, const UniString& rInput, + bool bPrint, bool bTiming, bool bSort, + OpenStack * pStack, sal_uInt32 nLevel, + sal_Int32 nFetchSize ) +{ + Any aArg; + + bool bDoSort = false; + + OpenCommandArgument2 aOpenArg; + if (rName.compareToAscii("search") == 0) + { + SearchCommandArgument aArgument; + if (!parseSearchArgument(rInput, aArgument.Info)) + { + print("Can't parse search argument"); + return; + } + aArgument.Properties.realloc(5); + aArgument.Properties[0].Name = OUString::createFromAscii("Title"); + aArgument.Properties[0].Handle = -1; + aArgument.Properties[1].Name + = OUString::createFromAscii("DateCreated"); + aArgument.Properties[1].Handle = -1; + aArgument.Properties[2].Name = OUString::createFromAscii("Size"); + aArgument.Properties[2].Handle = -1; + aArgument.Properties[3].Name = OUString::createFromAscii("IsFolder"); + aArgument.Properties[3].Handle = -1; + aArgument.Properties[4].Name + = OUString::createFromAscii("IsDocument"); + aArgument.Properties[4].Handle = -1; + aArg <<= aArgument; + } + else + { + aOpenArg.Mode = OpenMode::ALL; + aOpenArg.Priority = 32768; +// if ( bFolder ) + { + // Property values which shall be in the result set... + Sequence< Property > aProps( 5 ); + Property* pProps = aProps.getArray(); + pProps[ 0 ].Name = OUString::createFromAscii( "Title" ); + pProps[ 0 ].Handle = -1; // Important! +/**/ pProps[ 0 ].Type = getCppuType(static_cast< rtl::OUString * >(0)); + // HACK for sorting... + pProps[ 1 ].Name = OUString::createFromAscii( "DateCreated" ); + pProps[ 1 ].Handle = -1; // Important! + pProps[ 2 ].Name = OUString::createFromAscii( "Size" ); + pProps[ 2 ].Handle = -1; // Important! + pProps[ 3 ].Name = OUString::createFromAscii( "IsFolder" ); + pProps[ 3 ].Handle = -1; // Important! +/**/ pProps[ 3 ].Type = getCppuType(static_cast< sal_Bool * >(0)); + // HACK for sorting... + pProps[ 4 ].Name = OUString::createFromAscii( "IsDocument" ); + pProps[ 4 ].Handle = -1; // Important! + aOpenArg.Properties = aProps; + + bDoSort = bSort; + if (bDoSort) + { + // Sort criteria... Note that column numbering starts with 1! + aOpenArg.SortingInfo.realloc(2); + // primary sort criterium: column 4 --> IsFolder + aOpenArg.SortingInfo[ 0 ].ColumnIndex = 4; + aOpenArg.SortingInfo[ 0 ].Ascending = sal_False; + // secondary sort criterium: column 1 --> Title + aOpenArg.SortingInfo[ 1 ].ColumnIndex = 1; + aOpenArg.SortingInfo[ 1 ].Ascending = sal_True; + } + } +// else + aOpenArg.Sink + = static_cast< cppu::OWeakObject * >(new TestOutputStream); + aArg <<= aOpenArg; + } + +// putenv("PROT_REMOTE_ACTIVATE=1"); // to log remote uno traffic + + ULONG nTime; + if ( bTiming ) + nTime = Time::GetSystemTicks(); + + Any aResult = executeCommand( rName, aArg, bPrint ); + + Reference< XDynamicResultSet > xDynamicResultSet; + if ( ( aResult >>= xDynamicResultSet ) && xDynamicResultSet.is() ) + { + if (bDoSort) + { + sal_Int16 nCaps = xDynamicResultSet->getCapabilities(); + if (!(nCaps & ContentResultSetCapability::SORTED)) + { + if (bPrint) + print("Result set rows are not sorted" + "---using sorting cursor"); + + Reference< XSortedDynamicResultSetFactory > xSortedFactory; + if (m_rUCB.getServiceFactory().is()) + xSortedFactory + = Reference< XSortedDynamicResultSetFactory >( + m_rUCB. + getServiceFactory()-> + createInstance( + OUString::createFromAscii( + "com.sun.star.ucb.SortedDynamic" + "ResultSetFactory")), + UNO_QUERY); + Reference< XDynamicResultSet > xSorted; + if (xSortedFactory.is()) + xSorted + = xSortedFactory-> + createSortedDynamicResultSet(xDynamicResultSet, + aOpenArg. + SortingInfo, + 0); + if (xSorted.is()) + xDynamicResultSet = xSorted; + else + print("Sorting cursor not available!"); + } + } + + Reference< XResultSet > xResultSet( + xDynamicResultSet->getStaticResultSet() ); + if ( xResultSet.is() ) + { + if ( bPrint ) + { + print( "Folder object opened - iterating:" ); + print( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( + "Content-ID : ContentType : Title : Size : IsFolder " + ": IsDocument\n" + "-------------------------------------------------" ) ) ); + } + + if (nFetchSize > 0) + { + bool bSet = false; + Reference< XPropertySet > xProperties(xResultSet, UNO_QUERY); + if (xProperties.is()) + try + { + xProperties-> + setPropertyValue(OUString::createFromAscii( + "FetchSize"), + makeAny(nFetchSize)); + bSet = true; + } + catch (UnknownPropertyException const &) {} + catch (PropertyVetoException const &) {} + catch (IllegalArgumentException const &) {} + catch (WrappedTargetException const &) {} + if (!bSet) + print("Fetch size not set!"); + } + + try + { + ULONG n = 0; + Reference< XContentAccess > xContentAccess( + xResultSet, UNO_QUERY ); + Reference< XRow > xRow( xResultSet, UNO_QUERY ); + + while ( xResultSet->next() ) + { + UniString aText; + + if ( bPrint ) + { + OUString aId( xContentAccess-> + queryContentIdentfierString() ); + aText += UniString::CreateFromInt32( ++n ); + aText.AppendAscii( RTL_CONSTASCII_STRINGPARAM( + ") " ) ); + aText += UniString( aId ); + aText.AppendAscii( RTL_CONSTASCII_STRINGPARAM( + " : " ) ); + } + + // Title: + UniString aTitle( xRow->getString( 1 ) ); + if ( bPrint ) + { + if ( aTitle.Len() == 0 && xRow->wasNull() ) + aText.AppendAscii( RTL_CONSTASCII_STRINGPARAM( + "<null>" ) ); + else + aText += aTitle; + aText.AppendAscii( RTL_CONSTASCII_STRINGPARAM( + " : " ) ); + } + + // Size: + sal_Int32 nSize = xRow->getInt( 3 ); + if ( bPrint ) + { + if ( nSize == 0 && xRow->wasNull() ) + aText.AppendAscii( RTL_CONSTASCII_STRINGPARAM( + "<null>" ) ); + else + aText += UniString::CreateFromInt32( nSize ); + aText.AppendAscii( RTL_CONSTASCII_STRINGPARAM( + " : " ) ); + } + + // IsFolder: + sal_Bool bFolder = xRow->getBoolean( 4 ); + if ( bPrint ) + { + if ( !bFolder && xRow->wasNull() ) + aText.AppendAscii( RTL_CONSTASCII_STRINGPARAM( + "<null>" ) ); + else + aText + += bFolder ? + UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( + "true" ) ) : + UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( + "false" ) ); + aText.AppendAscii( RTL_CONSTASCII_STRINGPARAM( + " : " ) ); + } + + // IsDocument: + sal_Bool bDocument = xRow->getBoolean( 5 ); + if ( bPrint ) + { + if ( !bFolder && xRow->wasNull() ) + aText.AppendAscii( RTL_CONSTASCII_STRINGPARAM( + "<null>" ) ); + else + aText + += bDocument ? + UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( + "true" ) ) : + UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( + "false" ) ); // IsDocument + } + + if ( bPrint ) + print( aText ); + + if ( pStack && bFolder ) + pStack->push( OpenStackEntry( +#if 1 + xContentAccess-> + queryContentIdentifier(), +#else + xContentAccess->queryContent(), +#endif + nLevel + 1 ) ); + } + } + catch ( ResultSetException ) + { + print( "ResultSetException caught!" ); + } + + if ( bPrint ) + print( "Iteration done." ); + } + } +Reference< XComponent > xComponent(xDynamicResultSet, UNO_QUERY); +if (xComponent.is()) + xComponent->dispose(); + +// putenv("PROT_REMOTE_ACTIVATE="); // to log remote uno traffic + + if ( bTiming ) + { + nTime = Time::GetSystemTicks() - nTime; + UniString + aText( UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( "Operation took " ) ) ); + aText += UniString::CreateFromInt64( nTime ); + aText.AppendAscii( RTL_CONSTASCII_STRINGPARAM( " ms." ) ); + print( aText ); + } +} + +//---------------------------------------------------------------------------- +void UcbContent::openAll( Ucb& rUCB, bool bPrint, bool bTiming, bool bSort, + sal_Int32 nFetchSize ) +{ + ULONG nTime; + if ( bTiming ) + nTime = Time::GetSystemTicks(); + + OpenStack aStack; + aStack.push( OpenStackEntry( m_xContent, 0 ) ); + + while ( !aStack.empty() ) + { + OpenStackEntry aEntry( aStack.top() ); + aStack.pop(); + + if ( bPrint ) + { + UniString aText; + for ( sal_uInt32 i = aEntry.m_nLevel; i != 0; --i ) + aText += '='; + aText.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "LEVEL " ) ); + aText += UniString::CreateFromInt64( aEntry.m_nLevel ); + + Reference< XContentIdentifier > xID; + if ( aEntry.m_bUseIdentifier ) + xID = aEntry.m_xIdentifier; + else if ( aEntry.m_xContent.is() ) + xID = aEntry.m_xContent->getIdentifier(); + if ( xID.is() ) + { + aText.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": " ) ); + aText += UniString( xID->getContentIdentifier() ); + } + + print( aText ); + } + + Reference< XContent > xSavedContent( m_xContent ); + if ( aEntry.m_bUseIdentifier ) + { + Reference< XContentProvider > xProv = rUCB.getContentProvider(); + if ( !xProv.is() ) + { + print( "No content provider" ); + return; + } + + Reference< XContent > xChild; + try + { + xChild = xProv->queryContent( aEntry.m_xIdentifier ); + } + catch (IllegalIdentifierException const &) {} + if ( !xChild.is() ) + { + print( "No content" ); + return; + } + + m_xContent = xChild; + } + else + m_xContent = aEntry.m_xContent; + try + { + open( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( + "open" ) ), + UniString(), bPrint, false, bSort, &aStack, + aEntry.m_nLevel, nFetchSize ); + } + catch ( ... ) + { + m_xContent = xSavedContent; + throw; + } + m_xContent = xSavedContent; + } + + if ( bTiming ) + { + nTime = Time::GetSystemTicks() - nTime; + UniString + aText( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( + "Operation took " ) ) ); + aText += UniString::CreateFromInt64( nTime ); + aText.AppendAscii( RTL_CONSTASCII_STRINGPARAM( " ms." ) ); + print( aText ); + } +} + +//---------------------------------------------------------------------------- +void UcbContent::transfer( const OUString& rSourceURL, sal_Bool bMove ) +{ +/* + TransferInfo: + + sal_Bool MoveData; + ::rtl::OUString SourceURL; + ::rtl::OUString NewTitle; + sal_Int32 NameClash; +*/ + + if ( bMove ) + print( "Moving content..." ); + else + print( "Copying content..." ); + + Any aArg; + aArg <<= TransferInfo( bMove, rSourceURL, OUString(), NameClash::ERROR ); + executeCommand( OUString::createFromAscii( "transfer" ), aArg ); +} + +//---------------------------------------------------------------------------- +void UcbContent::destroy() +{ + print( "Deleting content..." ); + + Any aArg; + aArg <<= sal_Bool( sal_True ); // delete physically, not only to trash. + executeCommand( OUString::createFromAscii( "delete" ), aArg ); +} + +//------------------------------------------------------------------------- +Sequence< CommandInfo > UcbContent::getCommands() +{ + Any aResult = executeCommand( + OUString::createFromAscii( "getCommandInfo" ), Any() ); + + Reference< XCommandInfo > xInfo; + if ( aResult >>= xInfo ) + { + Sequence< CommandInfo > aCommands( xInfo->getCommands() ); + const CommandInfo* pCommands = aCommands.getConstArray(); + + String aText( UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( "Commands:\n" ) ) ); + sal_uInt32 nCount = aCommands.getLength(); + for ( sal_uInt32 n = 0; n < nCount; ++n ) + { + aText.AppendAscii( RTL_CONSTASCII_STRINGPARAM( " " ) ); + aText += String( pCommands[ n ].Name ); + aText += '\n'; + } + print( aText ); + + return aCommands; + } + + print( "getCommands failed!" ); + return Sequence< CommandInfo >(); +} + +//------------------------------------------------------------------------- +Sequence< Property > UcbContent::getProperties() +{ + Any aResult = executeCommand( + OUString::createFromAscii( "getPropertySetInfo" ), Any() ); + + Reference< XPropertySetInfo > xInfo; + if ( aResult >>= xInfo ) + { + Sequence< Property > aProps( xInfo->getProperties() ); + const Property* pProps = aProps.getConstArray(); + + String aText( UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( "Properties:\n" ) ) ); + sal_uInt32 nCount = aProps.getLength(); + for ( sal_uInt32 n = 0; n < nCount; ++n ) + { + aText.AppendAscii( RTL_CONSTASCII_STRINGPARAM( " " ) ); + aText += UniString( pProps[ n ].Name ); + aText += '\n'; + } + print( aText ); + + return aProps; + } + + print( "getProperties failed!" ); + return Sequence< Property >(); +} + +//---------------------------------------------------------------------------- +Any UcbContent::getPropertyValue( const OUString& rName ) +{ + Sequence< Property > aProps( 1 ); + Property& rProp = aProps.getArray()[ 0 ]; + + rProp.Name = rName; + rProp.Handle = -1; /* unknown */ +// rProp.Type = ; +// rProp.Attributes = ; + + Any aArg; + aArg <<= aProps; + + Any aResult = executeCommand( + OUString::createFromAscii( "getPropertyValues" ), aArg ); + + Reference< XRow > xValues; + if ( aResult >>= xValues ) + return xValues->getObject( 1, Reference< XNameAccess>() ); + + print( "getPropertyValue failed!" ); + return Any(); +} + +//---------------------------------------------------------------------------- +OUString UcbContent::getStringPropertyValue( const OUString& rName ) +{ + Any aAny = getPropertyValue( rName ); + if ( aAny.getValueType() == getCppuType( (const ::rtl::OUString *)NULL ) ) + { + const OUString aValue( + *SAL_STATIC_CAST( const OUString*, aAny.getValue() ) ); + + UniString aText( rName ); + aText.AppendAscii( RTL_CONSTASCII_STRINGPARAM( " value: '" ) ); + aText += UniString( aValue ); + aText.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "'" ) ); + print( aText ); + + return aValue; + } + + print( "getStringPropertyValue failed!" ); + return OUString(); +} + +//---------------------------------------------------------------------------- +void UcbContent::setPropertyValue( const OUString& rName, const Any& rValue ) +{ + Sequence< PropertyValue > aProps( 1 ); + PropertyValue& rProp = aProps.getArray()[ 0 ]; + + rProp.Name = rName; + rProp.Handle = -1; /* unknown */ + rProp.Value = rValue; +// rProp.State = ; + + Any aArg; + aArg <<= aProps; + + executeCommand( OUString::createFromAscii( "setPropertyValues" ), aArg ); +} + +//---------------------------------------------------------------------------- +void UcbContent::setStringPropertyValue( const OUString& rName, + const OUString& rValue ) +{ + Any aAny; + aAny.setValue( &rValue, getCppuType( (const OUString *)NULL ) ); + setPropertyValue( rName, aAny ); + + const OUString aValue( + *SAL_STATIC_CAST( const OUString*, aAny.getValue() ) ); + + UniString aText( rName ); + aText.AppendAscii( RTL_CONSTASCII_STRINGPARAM( " value set to: '" ) ); + aText += UniString( aValue ); + aText.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "'" ) ); + print( aText ); +} + +//---------------------------------------------------------------------------- +void UcbContent::addProperty( const OUString& rName, const Any& rValue ) +{ + Reference< XPropertyContainer > xContainer( m_xContent, UNO_QUERY ); + if ( xContainer.is() ) + { + UniString aText( UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( + "Adding property: " ) ) ); + aText += UniString( rName ); + print( aText ); + + try + { + xContainer->addProperty( rName, 0, rValue ); + } + catch ( PropertyExistException& ) + { + print( "Adding property failed. Already exists!" ); + return; + } + catch ( IllegalTypeException& ) + { + print( "Adding property failed. Illegal Type!" ); + return; + } + catch ( IllegalArgumentException& ) + { + print( "Adding property failed. Illegal Argument!" ); + return; + } + + print( "Adding property succeeded." ); + return; + } + + print( "Adding property failed. No XPropertyContainer!" ); +} + +//---------------------------------------------------------------------------- +void UcbContent::addStringProperty( + const OUString& rName, const OUString& rValue ) +{ + Any aValue; + aValue <<= rValue; + addProperty( rName, aValue ); +} + +//---------------------------------------------------------------------------- +void UcbContent::removeProperty( const OUString& rName ) +{ + Reference< XPropertyContainer > xContainer( m_xContent, UNO_QUERY ); + if ( xContainer.is() ) + { + UniString aText( UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( + "Removing property: " ) ) ); + aText += UniString( rName ); + print( aText ); + + try + { + xContainer->removeProperty( rName ); + } + catch ( UnknownPropertyException& ) + { + print( "Adding property failed. Unknown!" ); + return; + } + + print( "Removing property succeeded." ); + return; + } + + print( "Removing property failed. No XPropertyContainer!" ); +} + +//---------------------------------------------------------------------------- +// +// XInterface methods +// +//---------------------------------------------------------------------------- + +// virtual +Any SAL_CALL +UcbContent::queryInterface( const com::sun::star::uno::Type & rType ) + throw(RuntimeException) +{ + Any aRet = cppu::queryInterface( + rType, + static_cast< XEventListener* >( + static_cast< XContentEventListener* >( this ) ), + static_cast< XContentEventListener* >( this ), + static_cast< XPropertiesChangeListener* >( this ) ); + return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ); +} + +//---------------------------------------------------------------------------- +// virtual +void SAL_CALL UcbContent::acquire() + throw( RuntimeException ) +{ + OWeakObject::acquire(); +} + +//---------------------------------------------------------------------------- +// virtual +void SAL_CALL UcbContent::release() + throw( RuntimeException ) +{ + OWeakObject::release(); +} + +//---------------------------------------------------------------------------- +// +// XEventListener methods. +// +//---------------------------------------------------------------------------- + +// virtual +void SAL_CALL UcbContent::disposing( const EventObject& Source ) + throw( RuntimeException ) +{ + print ( "Content: disposing..." ); +} + +//---------------------------------------------------------------------------- +// +// XContentEventListener methods, +// +//---------------------------------------------------------------------------- + +// virtual +void SAL_CALL UcbContent::contentEvent( const ContentEvent& evt ) + throw( RuntimeException ) +{ + switch ( evt.Action ) + { + case ContentAction::INSERTED: + { + UniString aText( UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( + "contentEvent: INSERTED: " ) ) ); + if ( evt.Content.is() ) + { + Reference< XContentIdentifier > xId( + evt.Content->getIdentifier() ); + aText += UniString( xId->getContentIdentifier() ); + aText.AppendAscii( RTL_CONSTASCII_STRINGPARAM( " - " ) ); + aText += UniString( evt.Content->getContentType() ); + } + + print( aText ); + break; + } + case ContentAction::REMOVED: + print( "contentEvent: REMOVED" ); + break; + + case ContentAction::DELETED: + print( "contentEvent: DELETED" ); + break; + + case ContentAction::EXCHANGED: + print( "contentEvent: EXCHANGED" ); + break; + + case ContentAction::SEARCH_MATCHED: + { + String aMatch(RTL_CONSTASCII_USTRINGPARAM( + "contentEvent: SEARCH MATCHED ")); + if (evt.Id.is()) + { + aMatch += String(evt.Id->getContentIdentifier()); + if (evt.Content.is()) + { + aMatch.AppendAscii(RTL_CONSTASCII_STRINGPARAM(" - ")); + aMatch += String(evt.Content->getContentType()); + } + } + else + aMatch.AppendAscii(RTL_CONSTASCII_STRINGPARAM("<no id>")); + print(aMatch); + break; + } + + default: + print( "contentEvent..." ); + break; + } +} + +//---------------------------------------------------------------------------- +// +// XPropertiesChangeListener methods. +// +//---------------------------------------------------------------------------- + +// virtual +void SAL_CALL UcbContent::propertiesChange( + const Sequence< PropertyChangeEvent >& evt ) + throw( RuntimeException ) +{ + print( "propertiesChange..." ); + + sal_uInt32 nCount = evt.getLength(); + if ( nCount ) + { + const PropertyChangeEvent* pEvents = evt.getConstArray(); + for ( sal_uInt32 n = 0; n < nCount; ++n ) + { + UniString aText( UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( " " ) ) ); + aText += UniString( pEvents[ n ].PropertyName ); + print( aText ); + } + } +} + +/*======================================================================== + * + * MyWin. + * + *=======================================================================*/ + +#define MYWIN_ITEMID_CLEAR 1 +#define MYWIN_ITEMID_CREATE 2 +#define MYWIN_ITEMID_RELEASE 3 +#define MYWIN_ITEMID_COMMANDS 4 +#define MYWIN_ITEMID_PROPS 5 +#define MYWIN_ITEMID_ADD_PROP 6 +#define MYWIN_ITEMID_REMOVE_PROP 7 +#define MYWIN_ITEMID_GET_PROP 8 +#define MYWIN_ITEMID_SET_PROP 9 +#define MYWIN_ITEMID_OPEN 10 +#define MYWIN_ITEMID_OPEN_ALL 11 +#define MYWIN_ITEMID_UPDATE 12 +#define MYWIN_ITEMID_SYNCHRONIZE 13 +#define MYWIN_ITEMID_COPY 14 +#define MYWIN_ITEMID_MOVE 15 +#define MYWIN_ITEMID_DELETE 16 +#define MYWIN_ITEMID_SEARCH 17 +#define MYWIN_ITEMID_TIMING 18 +#define MYWIN_ITEMID_SORT 19 +#define MYWIN_ITEMID_FETCHSIZE 20 + +//------------------------------------------------------------------------- +class MyWin : public WorkWindow +{ +private: + ToolBox* m_pTool; + Edit* m_pCmdEdit; + MyOutWindow* m_pOutEdit; + + Ucb m_aUCB; + UcbContent* m_pContent; + + sal_Int32 m_nFetchSize; + bool m_bTiming; + bool m_bSort; + +#if 0 /*SB*/ + Reference< XContentProviderManager > m_xRemoteUCB; + Reference< XRemoteContentProviderAcceptor > m_xAcceptor; +#endif /*SB*/ + +public: + MyWin( Window *pParent, WinBits nWinStyle, + Reference< XMultiServiceFactory >& rxFactory, + Ucb::Remote eRemote ); + virtual ~MyWin(); + + void Resize( void ); + DECL_LINK ( ToolBarHandler, ToolBox* ); + + void print( const UniString& rText ); + void print( const sal_Char* pText ); +}; + +//------------------------------------------------------------------------- +MyWin::MyWin( Window *pParent, WinBits nWinStyle, + Reference< XMultiServiceFactory >& rxFactory, + Ucb::Remote eRemote ) +: WorkWindow( pParent, nWinStyle ), + m_pTool( NULL ), + m_pOutEdit( NULL ), + m_aUCB( rxFactory, eRemote ), + m_pContent( NULL ), + m_nFetchSize( 0 ), + m_bTiming( false ), + m_bSort( false ) +{ + // ToolBox. + m_pTool = new ToolBox( this, WB_SVLOOK | WB_BORDER | WB_SCROLL ); + + m_pTool->InsertItem ( MYWIN_ITEMID_CLEAR, + UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( + "Clear" ) ) ); + m_pTool->SetHelpText( MYWIN_ITEMID_CLEAR, + UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( + "Clear the Output Window" ) ) ); + m_pTool->InsertSeparator(); + m_pTool->InsertItem ( MYWIN_ITEMID_CREATE, + UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( + "Create" ) ) ); + m_pTool->SetHelpText( MYWIN_ITEMID_CREATE, + UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( + "Create a content" ) ) ); + m_pTool->InsertItem ( MYWIN_ITEMID_RELEASE, + UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( + "Release" ) ) ); + m_pTool->SetHelpText( MYWIN_ITEMID_RELEASE, + UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( + "Release current content" ) ) ); + m_pTool->InsertSeparator(); + m_pTool->InsertItem ( MYWIN_ITEMID_COMMANDS, + UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( + "Commands" ) ) ); + m_pTool->SetHelpText( MYWIN_ITEMID_COMMANDS, + UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( + "Get Commands supported by the content" ) ) ); + m_pTool->InsertItem ( MYWIN_ITEMID_PROPS, + UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( + "Properties" ) ) ); + m_pTool->SetHelpText( MYWIN_ITEMID_PROPS, + UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( + "Get Properties supported by the content" ) ) ); + m_pTool->InsertSeparator(); + m_pTool->InsertItem ( MYWIN_ITEMID_ADD_PROP, + UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( + "addProperty" ) ) ); + m_pTool->SetHelpText( MYWIN_ITEMID_ADD_PROP, + UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( + "Add a new string(!) property to the content. " + "Type the property name in the entry field and " + "push this button. The default value for the " + "property will be set to the string 'DefaultValue'" ) ) ); + m_pTool->InsertItem ( MYWIN_ITEMID_REMOVE_PROP, + UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( + "removeProperty" ) ) ); + m_pTool->SetHelpText( MYWIN_ITEMID_REMOVE_PROP, + UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( + "Removes a property from the content. " + "Type the property name in the entry field and " + "push this button." ) ) ); + m_pTool->InsertItem ( MYWIN_ITEMID_GET_PROP, + UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( + "getPropertyValue" ) ) ); + m_pTool->SetHelpText( MYWIN_ITEMID_GET_PROP, + UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( + "Get a string(!) property value from the content. " + "Type the property name in the entry field and " + "push this button to obtain the value" ) ) ); + m_pTool->InsertItem ( MYWIN_ITEMID_SET_PROP, + UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( + "setPropertyValue" ) ) ); + m_pTool->SetHelpText( MYWIN_ITEMID_SET_PROP, + UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( + "Set a string(!) property value of the content." + "Type the property name in the entry field and " + "push this button to set the value to the string " + "'NewValue'" ) ) ); + m_pTool->InsertSeparator(); + m_pTool->InsertItem ( MYWIN_ITEMID_OPEN, + UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( + "Open" ) ) ); + m_pTool->SetHelpText( MYWIN_ITEMID_OPEN, + UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( + "Open the content" ) ) ); + m_pTool->InsertItem ( MYWIN_ITEMID_OPEN_ALL, + UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( + "Open All" ) ) ); + m_pTool->SetHelpText( MYWIN_ITEMID_OPEN_ALL, + UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( + "Open the content and all of its" + " children" ) ) ); + m_pTool->InsertItem ( MYWIN_ITEMID_UPDATE, + UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( + "Update" ) ) ); + m_pTool->SetHelpText( MYWIN_ITEMID_UPDATE, + UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( + "Update the content" ) ) ); + m_pTool->InsertItem ( MYWIN_ITEMID_SYNCHRONIZE, + UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( + "Synchronize" ) ) ); + m_pTool->SetHelpText( MYWIN_ITEMID_SYNCHRONIZE, + UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( + "Synchronize the content" ) ) ); + m_pTool->InsertItem ( MYWIN_ITEMID_SEARCH, + UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( + "Search" ) ) ); + m_pTool->SetHelpText( MYWIN_ITEMID_SEARCH, + UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( + "Search the content" ) ) ); + + m_pTool->InsertSeparator(); + m_pTool->InsertItem ( MYWIN_ITEMID_COPY, + UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( + "Copy" ) ) ); + m_pTool->SetHelpText( MYWIN_ITEMID_COPY, + UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( + "Copy a content. Type the URL of the source " + "content into the entry field." ) ) ); + m_pTool->InsertItem ( MYWIN_ITEMID_MOVE, + UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( + "Move" ) ) ); + m_pTool->SetHelpText( MYWIN_ITEMID_MOVE, + UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( + "Move a content. Type the URL of the source " + "content into the entry field." ) ) ); + m_pTool->InsertItem ( MYWIN_ITEMID_DELETE, + UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( + "Delete" ) ) ); + m_pTool->SetHelpText( MYWIN_ITEMID_DELETE, + UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( + "Delete the content." ) ) ); + + m_pTool->InsertSeparator(); + m_pTool->InsertItem ( MYWIN_ITEMID_TIMING, + UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( + "Timing" ) ), + TIB_CHECKABLE | TIB_AUTOCHECK ); + m_pTool->SetHelpText( MYWIN_ITEMID_TIMING, + UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( + "Display execution times instead of" + " output" ) ) ); + m_pTool->InsertItem ( MYWIN_ITEMID_SORT, + UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( + "Sort" ) ), + TIB_CHECKABLE | TIB_AUTOCHECK ); + m_pTool->SetHelpText( MYWIN_ITEMID_SORT, + UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( + "Sort result sets" ) ) ); + m_pTool->InsertItem ( MYWIN_ITEMID_FETCHSIZE, + UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( + "Fetch Size" ) ) ); + m_pTool->SetHelpText( MYWIN_ITEMID_FETCHSIZE, + UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( + "Set cached cursor fetch size to positive value" ) ) ); + + m_pTool->SetSelectHdl( LINK( this, MyWin, ToolBarHandler ) ); + m_pTool->Show(); + + // Edit. + m_pCmdEdit = new Edit( this ); + m_pCmdEdit->SetReadOnly( FALSE ); + m_pCmdEdit->SetText( UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM("file:///c|/" ) ) ); + m_pCmdEdit->Show(); + + // MyOutWindow. + m_pOutEdit = new MyOutWindow( this, WB_HSCROLL | WB_VSCROLL | WB_BORDER ); + m_pOutEdit->SetReadOnly( TRUE ); + m_pOutEdit->Show(); + + m_aUCB.setOutEdit( m_pOutEdit ); + +#if 0 /*SB*/ + Sequence< Any > aArgs(1); + aArgs[0] <<= sal_True; + m_xRemoteUCB + = Reference< XContentProviderManager >( + rxFactory-> + createInstanceWithArguments( + OUString::createFromAscii( + "com.sun.star.ucb.UniversalContentBroker"), + aArgs), + UNO_QUERY); + m_xAcceptor + = Reference< XRemoteContentProviderAcceptor >( + rxFactory-> + createInstance( + OUString::createFromAscii( + "com.sun.star.ucb.RemoteContentProviderAcceptor")), + UNO_QUERY); + m_xAcceptor->addRemoteContentProvider(OUString::createFromAscii("myself"), + rxFactory, + Sequence< OUString >()); +#endif /*SB*/ +} + +//------------------------------------------------------------------------- +// virtual +MyWin::~MyWin() +{ +#if 0 /*SB*/ + m_xAcceptor-> + removeRemoteContentProvider(OUString::createFromAscii("myself")); + m_xAcceptor = 0; + m_xRemoteUCB = 0; +#endif /*SB*/ + + if ( m_pContent ) + { + m_pContent->dispose(); + m_pContent->release(); + } + + delete m_pTool; + delete m_pCmdEdit; + delete m_pOutEdit; +} + +//------------------------------------------------------------------------- +void MyWin::Resize() +{ + Size aWinSize = GetOutputSizePixel(); + int nWinW = aWinSize.Width(); + int nWinH = aWinSize.Height(); + int nBoxH = m_pTool->CalcWindowSizePixel().Height(); + + m_pTool->SetPosSizePixel ( + Point( 0, 0 ), Size ( nWinW, nBoxH ) ); + m_pCmdEdit->SetPosSizePixel( + Point( 0, nBoxH ), Size( nWinW, nBoxH ) ); + m_pOutEdit->SetPosSizePixel( + Point( 0, nBoxH + nBoxH ), Size ( nWinW, nWinH - ( nBoxH + nBoxH ) ) ); +} + +//------------------------------------------------------------------------- +void MyWin::print( const sal_Char* pText ) +{ + print( UniString::CreateFromAscii( pText ) ); +} + +//------------------------------------------------------------------------- +void MyWin::print( const UniString& rText ) +{ + vos::OGuard aGuard( Application::GetSolarMutex() ); + + if ( m_pOutEdit ) + { + m_pOutEdit->Append( rText ); + m_pOutEdit->Update(); + } +} + +//------------------------------------------------------------------------- +IMPL_LINK( MyWin, ToolBarHandler, ToolBox*, pToolBox ) +{ + USHORT nItemId = pToolBox->GetCurItemId(); + UniString aCmdLine = m_pCmdEdit->GetText(); + + ULONG n = Application::ReleaseSolarMutex(); + + switch( nItemId ) + { + case MYWIN_ITEMID_CLEAR: + { + vos::OGuard aGuard( Application::GetSolarMutex() ); + + m_pOutEdit->Clear(); + m_pOutEdit->Show(); + break; + } + + case MYWIN_ITEMID_CREATE: + if ( m_pContent ) + { + UniString aText( UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( + "Content released: " ) ) ); + aText += m_pContent->getURL(); + + m_pContent->dispose(); + m_pContent->release(); + m_pContent = NULL; + + print( aText ); + } + + m_pContent = UcbContent::create( m_aUCB, aCmdLine, m_pOutEdit ); + if ( m_pContent ) + { + String aText( UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( + "Created content: " ) ) ); + aText += String( m_pContent->getURL() ); + aText.AppendAscii( RTL_CONSTASCII_STRINGPARAM( " - " ) ); + aText += String( m_pContent->getType() ); + print( aText ); + } + else + { + String aText( UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( + "Creation failed for content: " ) ) ); + aText += String( aCmdLine ); + print( aText ); + } + break; + + case MYWIN_ITEMID_RELEASE: + if ( m_pContent ) + { + UniString aText( UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( + "Content released: " ) ) ); + aText += m_pContent->getURL(); + + m_pContent->dispose(); + m_pContent->release(); + m_pContent = NULL; + + print( aText ); + } + else + print( "No content!" ); + + break; + + case MYWIN_ITEMID_COMMANDS: + if ( m_pContent ) + m_pContent->getCommands(); + else + print( "No content!" ); + + break; + + case MYWIN_ITEMID_PROPS: + if ( m_pContent ) + m_pContent->getProperties(); + else + print( "No content!" ); + + break; + + case MYWIN_ITEMID_ADD_PROP: + if ( m_pContent ) + m_pContent->addStringProperty( + aCmdLine, + OUString::createFromAscii( "DefaultValue" ) ); + else + print( "No content!" ); + + break; + + case MYWIN_ITEMID_REMOVE_PROP: + if ( m_pContent ) + m_pContent->removeProperty( aCmdLine ); + else + print( "No content!" ); + + break; + + case MYWIN_ITEMID_GET_PROP: + if ( m_pContent ) + m_pContent->getStringPropertyValue( aCmdLine ); + else + print( "No content!" ); + + break; + + case MYWIN_ITEMID_SET_PROP: + if ( m_pContent ) + m_pContent->setStringPropertyValue( + aCmdLine, + OUString::createFromAscii( "NewValue" ) ); + else + print( "No content!" ); + + break; + + case MYWIN_ITEMID_OPEN: + if ( m_pContent ) + m_pContent->open(OUString::createFromAscii("open"), + aCmdLine, !m_bTiming, m_bTiming, m_bSort, 0, + 0, m_nFetchSize); + else + print( "No content!" ); + + break; + + case MYWIN_ITEMID_OPEN_ALL: + if ( m_pContent ) + m_pContent->openAll(m_aUCB, !m_bTiming, m_bTiming, m_bSort, + m_nFetchSize); + else + print( "No content!" ); + + break; + + case MYWIN_ITEMID_UPDATE: + if ( m_pContent ) + m_pContent->open(OUString::createFromAscii("update"), + aCmdLine, !m_bTiming, m_bTiming, m_bSort, 0, + 0, m_nFetchSize); + else + print( "No content!" ); + + break; + + case MYWIN_ITEMID_SYNCHRONIZE: + if ( m_pContent ) + m_pContent->open(OUString::createFromAscii("synchronize"), + aCmdLine, !m_bTiming, m_bTiming, m_bSort, 0, + 0, m_nFetchSize); + else + print( "No content!" ); + + break; + + case MYWIN_ITEMID_SEARCH: + if ( m_pContent ) + m_pContent->open(OUString::createFromAscii("search"), + aCmdLine, !m_bTiming, m_bTiming, m_bSort, 0, + 0, m_nFetchSize); + else + print( "No content!" ); + + break; + + case MYWIN_ITEMID_COPY: + if ( m_pContent ) + m_pContent->transfer( aCmdLine, sal_False ); + else + print( "No content!" ); + + break; + + case MYWIN_ITEMID_MOVE: + if ( m_pContent ) + m_pContent->transfer( aCmdLine, sal_True ); + else + print( "No content!" ); + + break; + + case MYWIN_ITEMID_DELETE: + if ( m_pContent ) + m_pContent->destroy(); + else + print( "No content!" ); + + break; + + case MYWIN_ITEMID_TIMING: + m_bTiming = m_pTool->IsItemChecked(MYWIN_ITEMID_TIMING) != false; + break; + + case MYWIN_ITEMID_SORT: + m_bSort = m_pTool->IsItemChecked(MYWIN_ITEMID_SORT) != false; + break; + + case MYWIN_ITEMID_FETCHSIZE: + { + m_nFetchSize = aCmdLine.ToInt32(); + String aText; + if (m_nFetchSize > 0) + { + aText.AssignAscii("Fetch size set to "); + aText += String::CreateFromInt32(m_nFetchSize); + } + else + aText.AssignAscii("Fetch size reset to default"); + print(aText); + break; + } + + default: // Ignored. + break; + } + + Application::AcquireSolarMutex( n ); + return 0; +} + +/*======================================================================== + * + * MyApp. + * + *=======================================================================*/ +class MyApp : public Application +{ +public: + virtual void Main(); +}; + +MyApp aMyApp; + +//------------------------------------------------------------------------- +// virtual +void MyApp::Main() +{ + ////////////////////////////////////////////////////////////////////// + // Read command line params. + ////////////////////////////////////////////////////////////////////// + + sal_Bool bApplicatRdb = sal_False; + sal_Bool bInstall = sal_False; + sal_Bool bInstallRemote = sal_False; + sal_Bool bUninstall = sal_False; + Ucb::Remote eRemote = Ucb::REMOTE_NO; + + USHORT nParams = Application::GetCommandLineParamCount(); + for ( USHORT n = 0; n < nParams; ++n ) + { + XubString aParam( Application::GetCommandLineParam( n ) ); + if ( aParam.EqualsIgnoreCaseAscii( "-a" ) || + aParam.EqualsIgnoreCaseAscii( "/a" ) ) + { + bApplicatRdb = sal_True; + } + else if ( aParam.EqualsIgnoreCaseAscii( "-i" ) || + aParam.EqualsIgnoreCaseAscii( "/i" ) ) + { + bInstall = sal_True; + } + else if ( aParam.Len() >= 3 + && (aParam.GetChar(0) == '-' || aParam.GetChar(0) == '/') + && (aParam.GetChar(1) == 'i' || aParam.GetChar(1) == 'I') + && (aParam.GetChar(2) == 'r' || aParam.GetChar(2) == 'R') ) + { + bInstall = sal_True; + bInstallRemote = sal_True; + Ucb::m_aProtocol = aParam.Copy(3); + } + else if ( aParam.EqualsIgnoreCaseAscii( "-u" ) || + aParam.EqualsIgnoreCaseAscii( "/u" ) ) + { + bUninstall = sal_True; + } + else if ( aParam.Len() >= 2 + && (aParam.GetChar(0) == '-' || aParam.GetChar(0) == '/') + && (aParam.GetChar(1) == 'r' || aParam.GetChar(1) == 'R') ) + { + ////////////////////////////////////////////////////////// + // Remote UCB/UCP + ////////////////////////////////////////////////////////// + + eRemote = aParam.GetChar(1) == 'r' ? Ucb::REMOTE_UCB : + Ucb::REMOTE_UCP; + Ucb::m_aProtocol = aParam.Copy(2); + } + } + + ////////////////////////////////////////////////////////////////////// + // Initialize local Service Manager and basic services. + ////////////////////////////////////////////////////////////////////// + + OStartupInfo aInfo; + OUString aExeName; + if ( aInfo.getExecutableFile( aExeName ) != OStartupInfo::E_None ) + { + DBG_ERROR( "Error getting Executable file name!" ); + return; + } + + OUString aReadOnlyRegFile; + OUString aWritableRegFile; + aReadOnlyRegFile = aExeName.copy( 0, aExeName.lastIndexOf( '/' ) + 1 ); + aWritableRegFile + = aReadOnlyRegFile; + aReadOnlyRegFile += OUString::createFromAscii( "applicat.rdb" ); + aWritableRegFile += OUString::createFromAscii( "ucbdemo.rdb" ); + + if ( bApplicatRdb ) + { + aWritableRegFile = aReadOnlyRegFile; + aReadOnlyRegFile = OUString(); + } + + Reference< XMultiServiceFactory > xFac; + try + { + xFac = cppu::createRegistryServiceFactory( + aWritableRegFile, aReadOnlyRegFile ); + } + catch ( com::sun::star::uno::Exception ) + { + DBG_ERROR( "Error creating RegistryServiceFactory!" ); + return; + } + + comphelper::setProcessServiceFactory( xFac ); + + ////////////////////////////////////////////////////////////////////// + // Process command line params. + ////////////////////////////////////////////////////////////////////// + + Reference< XComponent > xComponent( xFac, UNO_QUERY ); + + if ( bUninstall ) + { + ////////////////////////////////////////////////////////// + // Remove registry entries. + ////////////////////////////////////////////////////////// + Ucb::uninstall( xFac ); + } + + if ( bInstall ) + { + ////////////////////////////////////////////////////////// + // Write UCB service info into registry and store CHAOS + // content provider service information in registry... + ////////////////////////////////////////////////////////// + Ucb::install( xFac, bInstallRemote ); + } + + ////////////////////////////////////////////////////////////////////// + // Create Application Window... + ////////////////////////////////////////////////////////////////////// + + Help::EnableBalloonHelp(); + + MyWin *pMyWin = new MyWin( NULL, WB_APP | WB_STDWORK, xFac, + eRemote ); + + String aTitle( UniString::CreateFromAscii( + RTL_CONSTASCII_STRINGPARAM( + "UCB Demo/Test Application ( " ) ) ); + switch ( eRemote ) + { + case Ucb::REMOTE_NO: + aTitle.AppendAscii( + RTL_CONSTASCII_STRINGPARAM( "Local UCB Client )" ) ); + break; + + case Ucb::REMOTE_UCB: + aTitle.AppendAscii( + RTL_CONSTASCII_STRINGPARAM( "Remote UCB Client )" ) ); + break; + + case Ucb::REMOTE_UCP: + aTitle.AppendAscii( + RTL_CONSTASCII_STRINGPARAM( "Remote UCP Client )" ) ); + break; + } + + pMyWin->SetText( aTitle ); + + if ( bUninstall ) + pMyWin->print( + "UCB services and configuration removed from registry." ); + + if ( bInstall ) + pMyWin->print( + "UCB services and configuration written to registry." ); + + pMyWin->Show(); + + ////////////////////////////////////////////////////////////////////// + // Go... + ////////////////////////////////////////////////////////////////////// + + EnterMultiThread( TRUE ); + Execute(); + EnterMultiThread( FALSE ); + + ////////////////////////////////////////////////////////////////////// + // Destroy Application Window... + ////////////////////////////////////////////////////////////////////// + + delete pMyWin; + + ////////////////////////////////////////////////////////////////////// + // Cleanup. + ////////////////////////////////////////////////////////////////////// + + // Dispose local service manager. + if ( xComponent.is() ) + xComponent->dispose(); +} + |