From 8b8926aeba974cf07fdbaf121a11ef8a2c3c23e0 Mon Sep 17 00:00:00 2001 From: Andreas Bille Date: Wed, 16 May 2001 06:36:23 +0000 Subject: Initial revison the C++ help provider --- xmlhelp/source/cxxhelp/provider/content.cxx | 408 ++++++++++++++ xmlhelp/source/cxxhelp/provider/contentcaps.cxx | 250 +++++++++ xmlhelp/source/cxxhelp/provider/databases.cxx | 572 ++++++++++++++++++++ xmlhelp/source/cxxhelp/provider/makefile.mk | 138 +++++ xmlhelp/source/cxxhelp/provider/provider.cxx | 199 +++++++ xmlhelp/source/cxxhelp/provider/resultset.cxx | 130 +++++ xmlhelp/source/cxxhelp/provider/resultsetbase.cxx | 630 ++++++++++++++++++++++ xmlhelp/source/cxxhelp/provider/services.cxx | 174 ++++++ xmlhelp/source/cxxhelp/provider/urlparameter.cxx | 461 ++++++++++++++++ 9 files changed, 2962 insertions(+) create mode 100644 xmlhelp/source/cxxhelp/provider/content.cxx create mode 100644 xmlhelp/source/cxxhelp/provider/contentcaps.cxx create mode 100644 xmlhelp/source/cxxhelp/provider/databases.cxx create mode 100644 xmlhelp/source/cxxhelp/provider/makefile.mk create mode 100644 xmlhelp/source/cxxhelp/provider/provider.cxx create mode 100644 xmlhelp/source/cxxhelp/provider/resultset.cxx create mode 100644 xmlhelp/source/cxxhelp/provider/resultsetbase.cxx create mode 100644 xmlhelp/source/cxxhelp/provider/services.cxx create mode 100644 xmlhelp/source/cxxhelp/provider/urlparameter.cxx (limited to 'xmlhelp') diff --git a/xmlhelp/source/cxxhelp/provider/content.cxx b/xmlhelp/source/cxxhelp/provider/content.cxx new file mode 100644 index 000000000000..3dfc3bf6ce00 --- /dev/null +++ b/xmlhelp/source/cxxhelp/provider/content.cxx @@ -0,0 +1,408 @@ +/************************************************************************* + * + * $RCSfile: content.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: abi $ $Date: 2001-05-16 07:36: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): _______________________________________ + * + * + ************************************************************************/ + +/************************************************************************** + TODO + ************************************************************************** + + *************************************************************************/ + +#ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HPP_ +#include +#endif +#ifndef _COM_SUN_STAR_BEANS_XPROPERTYACCESS_HPP_ +#include +#endif +#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_ +#include +#endif +#ifndef _COM_SUN_STAR_UCB_OPENCOMMANDARGUMENT2_HPP_ +#include +#endif +#ifndef _COM_SUN_STAR_UCB_OPENMODE_HPP_ +#include +#endif +#ifndef _COM_SUN_STAR_UCB_XCOMMANDINFO_HPP_ +#include +#endif +#ifndef _COM_SUN_STAR_UCB_XPERSISTENTPROPERTYSET_HPP_ +#include +#endif +#ifndef _VOS_DIAGNOSE_HXX_ +#include +#endif +#ifndef _UCBHELPER_CONTENTIDENTIFIER_HXX +#include +#endif +#ifndef _UCBHELPER_PROPERTYVALUESET_HXX +#include +#endif + +#ifndef _CONTENT_HXX +#include +#endif +#ifndef _PROVIDER_HXX +#include +#endif +#ifndef _RESULTSET_HXX +#include +#endif +#ifndef _DATABASES_HXX_ +#include +#endif +#ifndef _RESULTSETFACTORY_HXX +#include +#endif +#ifndef _RESULTSETBASE_HXX +#include +#endif +#ifndef _RESULTSETFORROOT_HXX +#include +#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 chelp; + +//========================================================================= +//========================================================================= +// +// Content Implementation. +// +//========================================================================= +//========================================================================= + +Content::Content( const Reference< XMultiServiceFactory >& rxSMgr, + ::ucb::ContentProviderImplHelper* pProvider, + const Reference< XContentIdentifier >& Identifier ) + : ContentImplHelper( rxSMgr, pProvider, Identifier ), + m_aURLParameter( Identifier->getContentIdentifier() ) +{ + // m_aProps.aTitle = + // m_aprops.aContentType = + // m_aProps.bIsDocument = + // m_aProps.bIsFolder = +} + +//========================================================================= +// 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; + 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 ) + { + 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( "CHelpContent" ); +} + +//========================================================================= +// virtual +Sequence< OUString > SAL_CALL Content::getSupportedServiceNames() + throw( RuntimeException ) +{ + Sequence< OUString > aSNS( 1 ); + aSNS.getArray()[ 0 ] + = OUString::createFromAscii( MYUCP_CONTENT_SERVICE_NAME ); + return aSNS; +} + +//========================================================================= +// +// XContent methods. +// +//========================================================================= + +// virtual +OUString SAL_CALL Content::getContentType() + throw( RuntimeException ) +{ + return OUString::createFromAscii( MYUCP_CONTENT_TYPE ); +} + +//========================================================================= +// +// XCommandProcessor methods. +// +//========================================================================= + +//virtual +void SAL_CALL Content::abort( sal_Int32 CommandId ) + throw( RuntimeException ) +{ +} + + + +class ResultSetForRootFactory + : public ResultSetFactory +{ +private: + + Reference< XMultiServiceFactory > m_xSMgr; + Reference< XContentProvider > m_xProvider; + sal_Int32 m_nOpenMode; + Sequence< Property > m_seq; + Sequence< NumberedSortingInfo > m_seqSort; + URLParameter m_aURLParameter; + + +public: + + ResultSetForRootFactory( const Reference< XMultiServiceFactory >& xSMgr, + const Reference< XContentProvider >& xProvider, + sal_Int32 nOpenMode, + const Sequence< Property >& seq, + const Sequence< NumberedSortingInfo >& seqSort, + URLParameter aURLParameter ) + : m_xSMgr( xSMgr ), + m_xProvider( xProvider ), + m_nOpenMode( nOpenMode ), + m_seq( seq ), + m_seqSort( seqSort ), + m_aURLParameter( aURLParameter ) + { + } + + ResultSetBase* createResultSet() + { + return new ResultSetForRoot( m_xSMgr, + m_xProvider, + m_nOpenMode, + m_seq, + m_seqSort, + m_aURLParameter ); + } +}; + + + +// virtual +Any SAL_CALL Content::execute( const Command& aCommand, + sal_Int32 CommandId, + const Reference< + XCommandEnvironment >& Environment ) + throw( Exception, CommandAbortedException, RuntimeException ) +{ + Any aRet; + + if ( aCommand.Name.compareToAscii( "getPropertyValues" ) == 0 ) + { + Sequence< Property > Properties; + if ( !( aCommand.Argument >>= Properties ) ) + { + VOS_ENSURE( sal_False, "Wrong argument type!" ); + return aRet; + } + + aRet <<= getPropertyValues( Properties ); + } + else if ( aCommand.Name.compareToAscii( "setPropertyValues" ) == 0 ) + { + // No properties can be set + } + else if ( aCommand.Name.compareToAscii( "getPropertySetInfo" ) == 0 ) + { + // Note: Implemented by base class. + aRet <<= getPropertySetInfo( Environment ); + } + else if ( aCommand.Name.compareToAscii( "getCommandInfo" ) == 0 ) + { + // Note: Implemented by base class. + aRet <<= getCommandInfo( Environment ); + } + else if ( aCommand.Name.compareToAscii( "open" ) == 0 ) + { + OpenCommandArgument2 aOpenCommand; + if ( !( aCommand.Argument >>= aOpenCommand ) ) + { + VOS_ENSURE( sal_False, + "Content::execute - invalid parameter!" ); + throw CommandAbortedException(); + } + + if( m_aURLParameter.isRoot() ) + { + Reference< XDynamicResultSet > xSet + = new DynamicResultSet( m_xSMgr, + this, + aOpenCommand, + Environment, + new ResultSetForRootFactory( m_xSMgr, + m_xProvider.getBodyPtr(), + aOpenCommand.Mode, + aOpenCommand.Properties, + aOpenCommand.SortingInfo, + m_aURLParameter ) ); + aRet <<= xSet; + } + + if( m_aURLParameter.isQuery() ) + { + + } + } + else + { + ////////////////////////////////////////////////////////////////// + // Unsupported command + ////////////////////////////////////////////////////////////////// + + VOS_ENSURE( sal_False, "Content::execute - unsupported command!" ); + throw CommandAbortedException(); + } + + return aRet; +} + + + + +//========================================================================= +Reference< XRow > Content::getPropertyValues( + const Sequence< Property >& rProperties ) +{ + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + return Reference< XRow >(0); +} diff --git a/xmlhelp/source/cxxhelp/provider/contentcaps.cxx b/xmlhelp/source/cxxhelp/provider/contentcaps.cxx new file mode 100644 index 000000000000..9d2a6cc50cb6 --- /dev/null +++ b/xmlhelp/source/cxxhelp/provider/contentcaps.cxx @@ -0,0 +1,250 @@ +/************************************************************************* + * + * $RCSfile: contentcaps.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: abi $ $Date: 2001-05-16 07:36: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): _______________________________________ + * + * + ************************************************************************/ + +/************************************************************************** + TODO + ************************************************************************** + + *************************************************************************/ + +#ifndef _COM_SUN_STAR_BEANS_PROPERTY_HPP_ +#include +#endif +#ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HPP_ +#include +#endif +#ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_ +#include +#endif +#ifndef _COM_SUN_STAR_UCB_COMMANDINFO_HPP_ +#include +#endif +/* +#ifndef _COM_SUN_STAR_UCB_INSERTCOMMANDARGUMENT_HPP_ +#include +#endif +#ifndef _COM_SUN_STAR_UCB_OPENCOMMANDARGUMENT2_HPP_ +#include +#endif +*/ +#ifndef _COM_SUN_STAR_UNO_SEQUENCE_HXX_ +#include +#endif + +// @@@ Adjust multi-include-protection-ifdef and header file name. +#ifndef _MYUCP_CONTENT_HXX +#include +#endif + +using namespace com::sun::star::beans; +using namespace com::sun::star::uno; +using namespace com::sun::star::ucb; +using namespace rtl; + +// @@@ Adjust namespace name. +using namespace chelp; + +//========================================================================= +// +// Content implementation. +// +//========================================================================= + +//========================================================================= +// +// IMPORTENT: If any property data ( name / type / ... ) are changed, then +// Content::getPropertyValues(...) must be adapted too! +// +//========================================================================= + +// virtual +Sequence< Property > Content::getProperties( + const Reference< XCommandEnvironment > & xEnv ) +{ + // @@@ 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 + // + //================================================================= + + #define PROPERTY_COUNT 4 + + static Property aPropertyInfoTable[] = + { + /////////////////////////////////////////////////////////////// + // Required properties + /////////////////////////////////////////////////////////////// + Property( + OUString( RTL_CONSTASCII_USTRINGPARAM( "ContentType" ) ), + -1, + getCppuType( static_cast< const OUString * >( 0 ) ), + PropertyAttribute::BOUND | PropertyAttribute::READONLY + ), + Property( + OUString( RTL_CONSTASCII_USTRINGPARAM( "IsDocument" ) ), + -1, + getCppuBooleanType(), + PropertyAttribute::BOUND | PropertyAttribute::READONLY + ), + Property( + OUString( RTL_CONSTASCII_USTRINGPARAM( "IsFolder" ) ), + -1, + getCppuBooleanType(), + PropertyAttribute::BOUND | PropertyAttribute::READONLY + ), + Property( + OUString( RTL_CONSTASCII_USTRINGPARAM( "Title" ) ), + -1, + getCppuType( static_cast< const OUString * >( 0 ) ), + PropertyAttribute::BOUND + ) + /////////////////////////////////////////////////////////////// + // Optional standard properties + /////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////// + // New properties + /////////////////////////////////////////////////////////////// + }; + return Sequence< Property >( aPropertyInfoTable, PROPERTY_COUNT ); +} + +//========================================================================= +// virtual +Sequence< CommandInfo > Content::getCommands( + const Reference< XCommandEnvironment > & xEnv ) +{ + // @@@ Add additional commands... + +// osl::Guard< osl::Mutex > aGuard( m_aMutex ); + + //================================================================= + // + // Supported commands + // + //================================================================= + + #define COMMAND_COUNT 4 + + static CommandInfo aCommandInfoTable[] = + { + /////////////////////////////////////////////////////////////// + // Required commands + /////////////////////////////////////////////////////////////// + CommandInfo( + OUString( RTL_CONSTASCII_USTRINGPARAM( "getCommandInfo" ) ), + -1, + getCppuVoidType() + ), + CommandInfo( + OUString( RTL_CONSTASCII_USTRINGPARAM( "getPropertySetInfo" ) ), + -1, + getCppuVoidType() + ), + CommandInfo( + OUString( RTL_CONSTASCII_USTRINGPARAM( "getPropertyValues" ) ), + -1, + getCppuType( static_cast< Sequence< Property > * >( 0 ) ) + ), + CommandInfo( + OUString( RTL_CONSTASCII_USTRINGPARAM( "setPropertyValues" ) ), + -1, + getCppuType( static_cast< Sequence< PropertyValue > * >( 0 ) ) + ) + /////////////////////////////////////////////////////////////// + // Optional standard commands + /////////////////////////////////////////////////////////////// +/* + CommandInfo( + OUString( RTL_CONSTASCII_USTRINGPARAM( "delete" ) ), + -1, + getCppuBooleanType() + ), + CommandInfo( + OUString( RTL_CONSTASCII_USTRINGPARAM( "insert" ) ), + -1, + getCppuType( static_cast< InsertCommandArgument * >( 0 ) ) + ), + CommandInfo( + OUString( RTL_CONSTASCII_USTRINGPARAM( "open" ) ), + -1, + getCppuType( static_cast< OpenCommandArgument2 * >( 0 ) ) + ) +*/ + /////////////////////////////////////////////////////////////// + // New commands + /////////////////////////////////////////////////////////////// + }; + + return Sequence< CommandInfo >( aCommandInfoTable, COMMAND_COUNT ); +} + diff --git a/xmlhelp/source/cxxhelp/provider/databases.cxx b/xmlhelp/source/cxxhelp/provider/databases.cxx new file mode 100644 index 000000000000..18a455adaac6 --- /dev/null +++ b/xmlhelp/source/cxxhelp/provider/databases.cxx @@ -0,0 +1,572 @@ +#ifndef _DATABASES_HXX_ +#include +#endif +#ifndef _OSL_FILE_HXX_ +#include +#endif + + +using namespace chelp; + + +// The same for the jar files +// private static final Hashtable _jarHash = new Hashtable(); + + +// public static final Hashtable _modInfo = new Hashtable(); + + +osl::Mutex Databases::m_aMutex; +rtl::OUString Databases::m_aInstallDirectory; // Installation directory +Databases::DatabasesTable Databases::m_aDatabases; // Language and module dependent databases +Databases::LangSetTable Databases::m_aLangSet; // Mapping to of lang-country to lang +Databases::ModInfoTable Databases::m_aModInfo; // Module information + + +void Databases::setInstallPath( const rtl::OUString& aInstallDirectory ) +{ + osl::MutexGuard aGuard( m_aMutex ); + m_aInstallDirectory = aInstallDirectory; +} + + +rtl::OUString Databases::getInstallPath() +{ + osl::MutexGuard aGuard( m_aMutex ); + + return rtl::OUString::createFromAscii( "//./e:/src630c/help/" ); + + + // return m_aInstallDirectory; +} + + +rtl::OUString Databases::getURLMode() +{ + return rtl::OUString::createFromAscii( "with-jars" ); + // return rtl::OUString::createFromAscii( "with-files" ); +} + + +std::vector< rtl::OUString > Databases::getModuleList( const rtl::OUString& Language ) +{ + rtl::OUString fileName,dirName = getInstallPath() + lang( Language ); + osl::Directory dirFile( dirName ); + + osl::DirectoryItem aDirItem; + osl::FileStatus aStatus( FileStatusMask_FileName ); + + std::vector< rtl::OUString > ret; + sal_Int32 idx; + + if( osl::FileBase::E_None != dirFile.open() ) + return ret; + + while( dirFile.getNextItem( aDirItem ) == osl::FileBase::E_None && + aDirItem.getFileStatus( aStatus ) == osl::FileBase::E_None ) + { + if( ! aStatus.isValid( FileStatusMask_FileName ) ) + continue; + + fileName = aStatus.getFileName(); + + // Check, whether fileName is of the form *.db with the exception of picture.db + idx = fileName.lastIndexOf( sal_Unicode( '.' ) ); + + if( idx == -1 ) + continue; + + const sal_Unicode* str = fileName.getStr(); + + if( fileName.getLength() == idx + 3 && + ( str[idx + 1] == 'd' || str[idx + 1] == 'D' ) && + ( str[idx + 2] == 'b' || str[idx + 2] == 'B' ) && + ( fileName = fileName.copy(0,idx).toLowerCase() ).compareToAscii( "picture" ) != 0 ) + ret.push_back( fileName ); + } + + return ret; +} + + + +StaticModuleInformation* Databases::getStaticInformationForModule( const rtl::OUString& Module, + const rtl::OUString& Language ) +{ + osl::MutexGuard aGuard( m_aMutex ); + + rtl::OUString key = lang(Language) + rtl::OUString::createFromAscii( "/" ) + Module; + + ModInfoTable::iterator it = + m_aModInfo.insert( ModInfoTable::value_type( key,0 ) ).first; + + if( ! it->second ) + { + osl::File cfgFile( getInstallPath() + + key + + rtl::OUString::createFromAscii( ".cfg" ) ); + + if( osl::FileBase::E_None != cfgFile.open( OpenFlag_Read ) ) + return 0; + + sal_uInt32 pos = 0; + sal_uInt64 nRead; + sal_Char buffer[2048]; + sal_Unicode lineBuffer[1028]; + rtl::OUString fileContent; + + while( osl::FileBase::E_None == cfgFile.read( &buffer,2048,nRead ) && nRead ) + fileContent += rtl::OUString( buffer,sal_Int32( nRead ),RTL_TEXTENCODING_UTF8 ); + + cfgFile.close(); + + const sal_Unicode* str = fileContent.getStr(); + rtl::OUString current,lang,program,startid,title,heading,fulltext; + + for( sal_Int32 i = 0;i < fileContent.getLength();i++ ) + { + sal_Unicode ch = str[ i ]; + if( ch == sal_Unicode( '\n' ) || ch == sal_Unicode( '\r' ) ) + { + if( pos ) + { + current = rtl::OUString( lineBuffer,pos ); + + if( current.compareToAscii( "Title",5 ) == 0 ) + { + title = current.copy( current.indexOf(sal_Unicode( '=' ) ) + 1 ); + } + else if( current.compareToAscii( "Start",5 ) == 0 ) + { + startid = current.copy( current.indexOf('=') + 1 ); + } + else if( current.compareToAscii( "Language",8 ) == 0 ) + { + lang = current.copy( current.indexOf('=') + 1 ); + } + else if( current.compareToAscii( "Program",7 ) == 0 ) + { + program = current.copy( current.indexOf('=') + 1 ); + } + else if( current.compareToAscii( "Heading",7 ) == 0 ) + { + heading = current.copy( current.indexOf('=') + 1 ); + } + else if( current.compareToAscii( "FullText",8 ) == 0 ) + { + fulltext = current.copy( current.indexOf('=') + 1 ); + } + } + pos = 0; + } + else + lineBuffer[ pos++ ] = ch; + } + it->second = new StaticModuleInformation( title,startid,program,heading,fulltext ); + } + + return it->second; +} + + + +rtl::OUString Databases::lang( const rtl::OUString& Language ) +{ + osl::MutexGuard aGuard( m_aMutex ); + + rtl::OUString ret; + LangSetTable::iterator it = m_aLangSet.find( Language ); + + if( it == m_aLangSet.end() ) + { + sal_Int32 idx; + if( ( idx = Language.indexOf( '-' ) ) != -1 || + ( idx = Language.indexOf( '_' ) ) != -1 ) + ret = Language.copy( 0,idx ); + else + ret = Language; + + osl::DirectoryItem aDirItem; + if( osl::FileBase::E_None == osl::DirectoryItem::get( getInstallPath() + ret,aDirItem ) ) + m_aLangSet[ Language ] = ret; + } + else + ret = it->second; + + return ret; +} + + + + + + + + + + + + + + +// public static synchronized Db getDatabaseForLanguage( String Database,String Language ) +// { +// if( Database == null || Language == null ) +// return null; +// String key = lang(Language) + File.separator + Database; // For example de/swriter +// Db table = ( Db ) _dbHash.get( key ); +// if( table == null ) +// { +// try +// { +// table = new Db( null,0 ); + +// String tablePath = _installDirectory + key + ".db"; +// table.open( tablePath,null,Db.DB_BTREE,Db.DB_RDONLY,0644 ); +// _dbHash.put( key,table ); +// } +// catch( DbException e ) +// { +// System.err.println( "Unsupported language in helpsystem: " + Language ); +// System.err.println( "module: " + Database ); +// System.err.println( e.getMessage() ); +// } +// catch( FileNotFoundException e ) +// { +// System.err.println( "Unsupported language in helpsystem: " + Language ); +// System.err.println( "module: " + Database ); +// System.err.println( e.getMessage() ); +// } +// } + +// return table; +// } + + +// static Hashtable _helptextHash = new Hashtable(); + + +// public static synchronized Db getHelptextDbForLanguage( String Database,String Language ) +// { +// String key = lang( Language ) + File.separator + Database; // For example de/swriter +// Db table = ( Db ) _helptextHash.get( key ); +// if( table == null ) +// { +// try +// { +// table = new Db( null,0 ); + +// String tablePath = _installDirectory + key + ".ht"; +// table.open( tablePath,null,Db.DB_BTREE,Db.DB_RDONLY,0644 ); +// _dbHash.put( key,table ); +// } +// catch( DbException e ) +// { +// System.err.println( "Unsupported language in helpsystem: " + Language ); +// System.err.println( "module: " + Database ); +// System.err.println( e.getMessage() ); +// } +// catch( FileNotFoundException e ) +// { +// System.err.println( "Unsupported language in helpsystem: " + Language ); +// System.err.println( "module: " + Database ); +// System.err.println( e.getMessage() ); +// } +// } + +// return table; +// } + + + +// public static synchronized JarFile getJarFileForLanguage( String Database,String Language ) +// { +// if( Language == null || Database == null ) +// return null; + +// String key = lang(Language) + File.separator + Database; +// JarFile jarFile = ( JarFile ) _jarHash.get( key ); +// if( jarFile == null ) +// { +// try +// { +// File file = new File( _installDirectory + key ); +// if( file.exists() ) +// { +// jarFile = new JarFile( file ); +// _jarHash.put( key,jarFile ); +// } +// else +// throw new java.io.IOException(); +// } +// catch( IOException e ) +// { +// System.err.println( "Jarfile not found: " + Database + " " + Language ); +// } +// } + +// return jarFile; +// } + + +// public static InputStream getCssSheet() +// { +// try +// { +// return new FileInputStream( _installDirectory + "custom.css" ); +// } +// catch( FileNotFoundException e ) +// { +// return null; +// } +// } + + +// public static InputStream errorFile( String Language ) +// { +// try +// { +// return new FileInputStream( _installDirectory + lang(Language) + File.separator + "err.html" ); +// } +// catch( IOException e ) +// { +// String errorFile = +// " "+ +// " The requested document does not exist in the database !! "+ +// " "; + +// return new ByteArrayInputStream( errorFile.getBytes() ); +// } +// } + + + +// public static InputStream popupDocument( HelpURLParameter xPar ) +// { +// // String popupFile = +// // " "+ +// // " " + +// // " " + +// // 1 " "; + +// String popupFile = +// " "+ +// " "+ +// " "+ +// " "+ +// " "+ +// " "+ +// " "+ +// " "; + +// System.out.println( popupFile ); + +// return new ByteArrayInputStream( popupFile.getBytes() ); +// } + + +// private static final Hashtable _keyword = new Hashtable(); + + +// public static final class KeywordInfo +// { +// int pos = 0; +// String[] listKey = new String[100]; +// String[][] listId; +// String[][] listAnchor; +// String[][] listTitle; + +// public String [] getKeywordList() +// { +// return listKey; +// } + +// public String[][] getIdList() +// { +// return listId; +// } + + +// public String[][] getAnchorList() +// { +// return listAnchor; +// } + +// public String[][] getTitleList() +// { +// return listTitle; +// } + +// private void realloc( int length ) +// { +// String[] buff = listKey; +// listKey = new String[ length ]; +// int count = ( listKey.length > buff.length ) ? buff.length : listKey.length; +// for( int i = 0; i < count; ++i ) +// listKey[i] = buff[i]; +// buff = null; +// } + + +// public String[] getTitleForIndex( int i ) +// { +// return listTitle[i]; +// } + + +// void insert( String id ) +// { +// if( pos == listKey.length ) +// realloc( pos + 100 ); +// listKey[ pos++ ] = id; +// } + + +// public String[] insertId( int index,String ids ) +// { +// int pos = 0; +// String[] test = new String[10]; +// while( ids != null && ids.length() != 0 ) +// { +// int idx = ids.indexOf( ';' ); +// if( pos == test.length ) +// { +// String[] buff = test; +// test = new String[ pos+10 ]; +// for( int i = 0; i < buff.length; ++i ) +// test[i] = buff[i]; +// buff = null; +// } + +// test[pos++] = ids.substring(0,idx); +// ids = ids.substring( 1+idx ); +// } + +// String[] buff = test; +// test = new String[ pos ]; +// for( int i = 0; i < pos; ++i ) +// test[i] = buff[i]; + +// listId[index] = test; +// listAnchor[index] = new String[test.length]; + +// for( int k = 0; k < listId[index].length; ++k ) +// { +// if( listId[index][k] == null ) +// { +// listId[index][k] = ""; +// listAnchor[index][k] = ""; +// } +// else +// { +// int idx = listId[index][k].indexOf('#'); +// if( idx != -1 ) +// { +// listAnchor[index][k] = listId[index][k].substring(1+idx).trim(); +// listId[index][k] = listId[index][k].substring(0,idx).trim(); +// } +// else +// listAnchor[index][k] = ""; +// } +// } + +// listTitle[index] = new String[test.length]; +// return test; +// } + + + +// public void sort() +// { +// realloc( pos ); +// Arrays.sort( listKey ); +// listId = new String[ listKey.length ][]; +// listAnchor = new String[ listKey.length ][]; +// listTitle = new String[ listKey.length ][]; +// } +// } + + +// public static synchronized KeywordInfo getKeyword( String Database, String Language ) +// { +// String keyStr = lang(Language) + File.separator + Database; +// KeywordInfo info = ( KeywordInfo ) _keyword.get( keyStr ); + +// if( info == null ) +// { +// try +// { +// HashMap internalHash = new HashMap(); +// String fileName = HelpDatabases.getInstallDirectory() + keyStr + ".key"; +// Db table = new Db( null,0 ); +// System.err.println( fileName ); +// table.open( fileName,null,Db.DB_BTREE,Db.DB_RDONLY,0644 ); +// Dbc cursor = table.cursor( null,0 ); +// StringDbt key = new StringDbt(); +// StringDbt data = new StringDbt(); + +// boolean first = true; +// key.set_flags( Db.DB_DBT_MALLOC ); // Initially the cursor must allocate the necessary memory +// data.set_flags( Db.DB_DBT_MALLOC ); +// info = new KeywordInfo(); + +// String keyStri; + +// while( Db.DB_NOTFOUND != cursor.get( key,data,Db.DB_NEXT ) ) +// { +// keyStri = key.getString(); +// info.insert( keyStri ); +// internalHash.put( keyStri,data.getString() ); +// if( first ) +// { +// key.set_flags( Db.DB_DBT_REALLOC ); +// data.set_flags( Db.DB_DBT_REALLOC ); +// first = false; +// } +// } + +// info.sort(); +// cursor.close(); +// table.close( 0 ); + +// String[] keywords = info.getKeywordList(); +// Db table2 = getDatabaseForLanguage( Database,Language ); +// for( int i = 0; i < keywords.length; ++i ) +// { +// String[] id = info.insertId( i,((String)internalHash.get( keywords[i])) ); +// String[] title = info.getTitleForIndex( i ); + +// for( int j = 0; j < id.length; ++j ) +// { +// StringDbt key1 = new StringDbt(); +// key1.setString( id[j] ); +// StringDbt data1 = new StringDbt(); +// try +// { +// table2.get( null,key1,data1,0 ); +// title[j] = data1.getTitle(); +// } +// catch( Exception e ) +// { +// e.printStackTrace(); +// title[j] = ""; +// } +// } +// } + +// _keyword.put( keyStr,info ); +// } +// catch( Exception e ) +// { +// e.printStackTrace(); +// System.err.println( "any other exception in getKeyword: " + e.getMessage() ); +// } +// } + +// return info; +// } + +// } // end class HelpDatabases + + +// } diff --git a/xmlhelp/source/cxxhelp/provider/makefile.mk b/xmlhelp/source/cxxhelp/provider/makefile.mk new file mode 100644 index 000000000000..036763216d92 --- /dev/null +++ b/xmlhelp/source/cxxhelp/provider/makefile.mk @@ -0,0 +1,138 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1 $ +# +# last change: $Author: abi $ $Date: 2001-05-16 07:36: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): _______________________________________ +# +# +# +#************************************************************************* + +# @@@ UCP Version - Increase, if your UCP libraray becomes incompatible. +UCP_VERSION=1 + +# @@@ Name for your UCP. Will become part of the library name (See below). +UCP_NAME=chelp + +# @@@ Relative path to project root. +PRJ=..$/..$/.. + +# @@@ Name of the project your UCP code recides it. +PRJNAME=xmlhelp + +TARGET=ucp$(UCP_NAME) + +ENABLE_EXCEPTIONS=TRUE +USE_DEFFILE=TRUE +NO_BSYMBOLIC=TRUE + +# --- Settings --------------------------------------------------------- + +.INCLUDE: settings.mk + +.IF "$(GUI)"=="WNT" +CFLAGS+=/GR +.ENDIF + +# --- General ----------------------------------------------------- + +# @@@ Adjust template file names. Add own files here. +SLOFILES=\ + $(SLO)$/services.obj \ + $(SLO)$/provider.obj \ + $(SLO)$/content.obj \ + $(SLO)$/resultset.obj \ + $(SLO)$/resultsetbase.obj \ + $(SLO)$/contentcaps.obj \ + $(SLO)$/urlparameter.obj \ + $(SLO)$/databases.obj + +# You need these only if you implement a folder content, +# which supports the command "open" returning a result set. +# $(SLO)$/myucp_resultset.obj +# $(SLO)$/myucp_datasupplier.obj + +LIB1TARGET=$(SLB)$/_$(TARGET).lib +LIB1OBJFILES=$(SLOFILES) + +# --- Shared-Library --------------------------------------------------- + +SHL1TARGET=$(TARGET)$(UCP_VERSION) +SHL1IMPLIB=i$(TARGET) +SHL1VERSIONMAP=exports.map + +# @@@ Add additional libs here. +SHL1STDLIBS=\ + $(CPPUHELPERLIB) \ + $(CPPULIB) \ + $(SALLIB) \ + $(VOSLIB) \ + $(UCBHELPERLIB) + +SHL1DEF=$(MISC)$/$(SHL1TARGET).def +SHL1LIBS=$(LIB1TARGET) + +# --- Def-File --------------------------------------------------------- + +DEF1NAME=$(SHL1TARGET) +DEF1EXPORTFILE=exports.dxp + +# @@@ A description string for you UCP. +DEF1DES=UCB Help Content Provider + +# --- Targets ---------------------------------------------------------- + +.INCLUDE: target.mk + diff --git a/xmlhelp/source/cxxhelp/provider/provider.cxx b/xmlhelp/source/cxxhelp/provider/provider.cxx new file mode 100644 index 000000000000..8e7504ae1b5a --- /dev/null +++ b/xmlhelp/source/cxxhelp/provider/provider.cxx @@ -0,0 +1,199 @@ +/************************************************************************* + * + * $RCSfile: provider.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: abi $ $Date: 2001-05-16 07:36: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): _______________________________________ + * + * + ************************************************************************/ + +/************************************************************************** + TODO + ************************************************************************** + + *************************************************************************/ + +#ifndef _VOS_DIAGNOSE_HXX_ +#include +#endif +#ifndef _UCBHELPER_CONTENTIDENTIFIER_HXX +#include +#endif + +#ifndef _PROVIDER_HXX +#include +#endif +#ifndef _CONTENT_HXX +#include +#endif + +using namespace com::sun::star::lang; +using namespace com::sun::star::ucb; +using namespace com::sun::star::uno; +using namespace rtl; + +using namespace chelp; + +//========================================================================= +//========================================================================= +// +// ContentProvider Implementation. +// +//========================================================================= +//========================================================================= + +ContentProvider::ContentProvider( const Reference< XMultiServiceFactory >& rSMgr ) + : ::ucb::ContentProviderImplHelper( rSMgr ), + isInitialized( false ), + m_aScheme( OUString::createFromAscii( MYUCP_URL_SCHEME ) ) +{ +} + +//========================================================================= +// virtual +ContentProvider::~ContentProvider() +{ +} + +//========================================================================= +// +// XInterface methods. +// +//========================================================================= + +XINTERFACE_IMPL_3( ContentProvider, + XTypeProvider, + XServiceInfo, + XContentProvider ); + +//========================================================================= +// +// XTypeProvider methods. +// +//========================================================================= + +XTYPEPROVIDER_IMPL_3( ContentProvider, + XTypeProvider, + XServiceInfo, + XContentProvider ); + +//========================================================================= +// +// XServiceInfo methods. +// +//========================================================================= + +XSERVICEINFO_IMPL_1( ContentProvider, + OUString::createFromAscii( + "CHelpContentProvider" ), + OUString::createFromAscii( + MYUCP_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 >& xCanonicId ) + throw( IllegalIdentifierException, RuntimeException ) +{ + if ( ! xCanonicId->getContentProviderScheme().equalsIgnoreCase( m_aScheme ) ) + { // Wrong URL-scheme + throw IllegalIdentifierException(); + } + + if( ! isInitialized ) + init(); + + // Check, if a content with given id already exists... + Reference< XContent > xContent + = queryExistingContent( xCanonicId ).getBodyPtr(); + if ( xContent.is() ) + return xContent; + + xContent = new Content( m_xSMgr,this,xCanonicId ); + + // Further checks + + if ( !xContent->getIdentifier().is() ) + throw IllegalIdentifierException(); + + return xContent; +} + + + +void ContentProvider::init() +{ + //t + // Get installation path, for example + + isInitialized = true; +} + + + + + diff --git a/xmlhelp/source/cxxhelp/provider/resultset.cxx b/xmlhelp/source/cxxhelp/provider/resultset.cxx new file mode 100644 index 000000000000..30b00eabdbcb --- /dev/null +++ b/xmlhelp/source/cxxhelp/provider/resultset.cxx @@ -0,0 +1,130 @@ +/************************************************************************* + * + * $RCSfile: resultset.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: abi $ $Date: 2001-05-16 07:36: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 _COM_SUN_STAR_SDBC_XRESULTSET_HPP_ +#include +#endif +#ifndef _DATASUPPLIER_HXX +#include +#endif +#ifndef _RESULTSET_HXX +#include +#endif +#ifndef _RESULTSETFACTORY_HXX +#include +#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 chelp; + +//========================================================================= +//========================================================================= +// +// DynamicResultSet Implementation. +// +//========================================================================= +//========================================================================= + +DynamicResultSet::DynamicResultSet( + const Reference< XMultiServiceFactory >& rxSMgr, + const vos::ORef< Content >& rxContent, + const OpenCommandArgument2& rCommand, + const Reference< XCommandEnvironment >& rxEnv, + ResultSetFactory* pFactory ) + : ResultSetImplHelper( rxSMgr, rCommand ), + m_xContent( rxContent ), + m_xEnv( rxEnv ), + m_pFactory( pFactory ) +{ +} + +DynamicResultSet::~DynamicResultSet() +{ + delete m_pFactory; +} + +//========================================================================= +// +// Non-interface methods. +// +//========================================================================= + +void DynamicResultSet::initStatic() +{ + m_xResultSet1 = Reference< XResultSet >( m_pFactory->createResultSet() ); +} + +//========================================================================= +void DynamicResultSet::initDynamic() +{ + m_xResultSet1 = Reference< XResultSet >( m_pFactory->createResultSet() ); + + m_xResultSet2 = m_xResultSet1; +} + + + + diff --git a/xmlhelp/source/cxxhelp/provider/resultsetbase.cxx b/xmlhelp/source/cxxhelp/provider/resultsetbase.cxx new file mode 100644 index 000000000000..e1310674ec30 --- /dev/null +++ b/xmlhelp/source/cxxhelp/provider/resultsetbase.cxx @@ -0,0 +1,630 @@ +/************************************************************************* + * + * $RCSfile: resultsetbase.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: abi $ $Date: 2001-05-16 07:36: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 _UCBHELPER_CONTENTIDENTIFIER_HXX +#include +#endif +#ifndef _COM_SUN_STAR_UCB_OPENMODE_HPP_ +#include +#endif +#ifndef _COM_SUN_STAR_UNO_REFERENCE_H_ +#include +#endif +#ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBBUTE_HPP_ +#include +#endif +#ifndef _COM_SUN_STAR_UCB_LISTACTIONTYPE_HPP_ +#include +#endif +#ifndef _COM_SUN_STAR_UCB_XSOURCEINITIALIZATION_HPP_ +#include +#endif +#ifndef _UCBHELPER_RESULTSETMETADATA_HXX +#include +#endif +#ifndef _RESULTSETBASE_HXX +#include +#endif + +using namespace chelp; +using namespace com::sun::star; +using namespace com::sun::star::ucb; + + +ResultSetBase::ResultSetBase( const uno::Reference< lang::XMultiServiceFactory >& xMSF, + const uno::Reference< XContentProvider >& xProvider, + sal_Int32 nOpenMode, + const uno::Sequence< beans::Property >& seq, + const uno::Sequence< NumberedSortingInfo >& seqSort ) + : m_xMSF( xMSF ), + m_xProvider( xProvider ), + m_nRow( -1 ), + m_nWasNull( true ), + m_nOpenMode( nOpenMode ), + m_bRowCountFinal( true ), + m_sProperty( seq ), + m_sSortingInfo( seqSort ), + m_pDisposeEventListeners( 0 ), + m_pRowCountListeners( 0 ), + m_pIsFinalListeners( 0 ) +{ +} + +ResultSetBase::~ResultSetBase() +{ + delete m_pIsFinalListeners; + delete m_pRowCountListeners; + delete m_pDisposeEventListeners; +} + + +// XInterface + +void SAL_CALL +ResultSetBase::acquire( + void ) + throw( uno::RuntimeException ) +{ + OWeakObject::acquire(); +} + + +void SAL_CALL +ResultSetBase::release( + void ) + throw( uno::RuntimeException ) +{ + OWeakObject::release(); +} + + + +uno::Any SAL_CALL +ResultSetBase::queryInterface( + const uno::Type& rType ) + throw( uno::RuntimeException ) +{ + uno::Any aRet = cppu::queryInterface( rType, + SAL_STATIC_CAST( lang::XComponent*, this), + SAL_STATIC_CAST( sdbc::XRow*, this), + SAL_STATIC_CAST( sdbc::XResultSet*, this), + SAL_STATIC_CAST( sdbc::XResultSetMetaDataSupplier*, this), + SAL_STATIC_CAST( beans::XPropertySet*, this ), + SAL_STATIC_CAST( XContentAccess*, this) ); + return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ); +} + + + +// XComponent + + +void SAL_CALL +ResultSetBase::addEventListener( + const uno::Reference< lang::XEventListener >& Listener ) + throw( uno::RuntimeException ) +{ + osl::MutexGuard aGuard( m_aMutex ); + + if ( ! m_pDisposeEventListeners ) + m_pDisposeEventListeners = + new cppu::OInterfaceContainerHelper( m_aMutex ); + + m_pDisposeEventListeners->addInterface( Listener ); +} + + +void SAL_CALL +ResultSetBase::removeEventListener( + const uno::Reference< lang::XEventListener >& Listener ) + throw( uno::RuntimeException ) +{ + osl::MutexGuard aGuard( m_aMutex ); + + if ( m_pDisposeEventListeners ) + m_pDisposeEventListeners->removeInterface( Listener ); +} + + + +void SAL_CALL +ResultSetBase::dispose() + throw( uno::RuntimeException ) +{ + osl::MutexGuard 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 ); + } +} + + + +// XResultSet + +sal_Bool SAL_CALL +ResultSetBase::next( + void ) + throw( sdbc::SQLException, + uno::RuntimeException ) +{ + sal_Bool test; + if( ++m_nRow < m_aItems.size() ) + test = true; + else + test = false; + return test; +} + + +sal_Bool SAL_CALL +ResultSetBase::isBeforeFirst( + void ) + throw( sdbc::SQLException, + uno::RuntimeException ) +{ + return m_nRow == -1; +} + + +sal_Bool SAL_CALL +ResultSetBase::isAfterLast( + void ) + throw( sdbc::SQLException, + uno::RuntimeException ) +{ + return m_nRow >= m_aItems.size(); // Cannot happen, if m_aFolder.isOpen() +} + + +sal_Bool SAL_CALL +ResultSetBase::isFirst( + void ) + throw( sdbc::SQLException, + uno::RuntimeException ) +{ + return m_nRow == 0; +} + + +sal_Bool SAL_CALL +ResultSetBase::isLast( + void ) + throw( sdbc::SQLException, + uno::RuntimeException) +{ + if( m_nRow == m_aItems.size() - 1 ) + return true; + else + return false; +} + + +void SAL_CALL +ResultSetBase::beforeFirst( + void ) + throw( sdbc::SQLException, + uno::RuntimeException) +{ + m_nRow = -1; +} + + +void SAL_CALL +ResultSetBase::afterLast( + void ) + throw( sdbc::SQLException, + uno::RuntimeException ) +{ + m_nRow = m_aItems.size(); +} + + +sal_Bool SAL_CALL +ResultSetBase::first( + void ) + throw( sdbc::SQLException, + uno::RuntimeException) +{ + m_nRow = -1; + return next(); +} + + +sal_Bool SAL_CALL +ResultSetBase::last( + void ) + throw( sdbc::SQLException, + uno::RuntimeException ) +{ + m_nRow = m_aItems.size() - 1; + return true; +} + + +sal_Int32 SAL_CALL +ResultSetBase::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 ResultSetBase::absolute( sal_Int32 row ) + throw( sdbc::SQLException, uno::RuntimeException) +{ + if( row >= 0 ) + m_nRow = row - 1; + else + { + last(); + m_nRow += ( row + 1 ); + if( m_nRow < -1 ) + m_nRow = -1; + } + + return 0<= m_nRow && m_nRow < m_aItems.size(); +} + + + + +sal_Bool SAL_CALL +ResultSetBase::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 +ResultSetBase::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 +ResultSetBase::refreshRow( + void ) + throw( sdbc::SQLException, + uno::RuntimeException) +{ +} + + +sal_Bool SAL_CALL +ResultSetBase::rowUpdated( + void ) + throw( sdbc::SQLException, + uno::RuntimeException ) +{ + return false; +} + +sal_Bool SAL_CALL +ResultSetBase::rowInserted( + void ) + throw( sdbc::SQLException, + uno::RuntimeException ) +{ + return false; +} + +sal_Bool SAL_CALL +ResultSetBase::rowDeleted( + void ) + throw( sdbc::SQLException, + uno::RuntimeException ) +{ + return false; +} + + +uno::Reference< uno::XInterface > SAL_CALL +ResultSetBase::getStatement( + void ) + throw( sdbc::SQLException, + uno::RuntimeException ) +{ + uno::Reference< uno::XInterface > test( 0 ); + return test; +} + + +// XCloseable + +void SAL_CALL +ResultSetBase::close( + void ) + throw( sdbc::SQLException, + uno::RuntimeException) +{ +} + + +rtl::OUString SAL_CALL +ResultSetBase::queryContentIdentifierString( + void ) + throw( uno::RuntimeException ) +{ + return getDocumentURL(); +} + + +uno::Reference< XContentIdentifier > SAL_CALL +ResultSetBase::queryContentIdentifier( + void ) + throw( uno::RuntimeException ) +{ + if( 0 <= m_nRow && m_nRow < m_aItems.size() ) + { + rtl::OUString url = getDocumentURL(); + if( ! m_aIdents[m_nRow].is() && url.getLength() ) + m_aIdents[m_nRow] = uno::Reference< XContentIdentifier >( new ::ucb::ContentIdentifier( m_xMSF,url ) ); + return m_aIdents[m_nRow]; + } + + return uno::Reference< XContentIdentifier >(); +} + + +uno::Reference< XContent > SAL_CALL +ResultSetBase::queryContent( + void ) + throw( uno::RuntimeException ) +{ + if( 0 <= m_nRow && m_nRow < m_aItems.size() ) + return m_xProvider->queryContent( queryContentIdentifier() ); + else + return uno::Reference< XContent >(); +} + + + +// XPropertySet +uno::Reference< beans::XPropertySetInfo > SAL_CALL +ResultSetBase::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; + +// XPropertySetInfoImpl* p = new XPropertySetInfoImpl( m_pMyShell, +// seq ); + return uno::Reference< beans::XPropertySetInfo > ( 0 ); +} + + + +void SAL_CALL ResultSetBase::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 ResultSetBase::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 ResultSetBase::addPropertyChangeListener( + const rtl::OUString& aPropertyName, + const uno::Reference< beans::XPropertyChangeListener >& xListener ) + throw( beans::UnknownPropertyException, + lang::WrappedTargetException, + uno::RuntimeException) +{ + if( aPropertyName == rtl::OUString::createFromAscii( "IsRowCountFinal" ) ) + { + osl::MutexGuard aGuard( m_aMutex ); + if ( ! m_pIsFinalListeners ) + m_pIsFinalListeners = + new cppu::OInterfaceContainerHelper( m_aMutex ); + + m_pIsFinalListeners->addInterface( xListener ); + } + else if ( aPropertyName == rtl::OUString::createFromAscii( "RowCount" ) ) + { + osl::MutexGuard aGuard( m_aMutex ); + if ( ! m_pRowCountListeners ) + m_pRowCountListeners = + new cppu::OInterfaceContainerHelper( m_aMutex ); + m_pRowCountListeners->addInterface( xListener ); + } + else + throw beans::UnknownPropertyException(); +} + + +void SAL_CALL ResultSetBase::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 ) + { + osl::MutexGuard aGuard( m_aMutex ); + m_pIsFinalListeners->removeInterface( aListener ); + } + else if ( aPropertyName == rtl::OUString::createFromAscii( "RowCount" ) && + m_pRowCountListeners ) + { + osl::MutexGuard aGuard( m_aMutex ); + m_pRowCountListeners->removeInterface( aListener ); + } + else + throw beans::UnknownPropertyException(); +} + + +void SAL_CALL ResultSetBase::addVetoableChangeListener( + const rtl::OUString& PropertyName, + const uno::Reference< beans::XVetoableChangeListener >& aListener ) + throw( beans::UnknownPropertyException, + lang::WrappedTargetException, + uno::RuntimeException) +{ +} + + +void SAL_CALL ResultSetBase::removeVetoableChangeListener( + const rtl::OUString& PropertyName, + const uno::Reference< beans::XVetoableChangeListener >& aListener ) + throw( beans::UnknownPropertyException, + lang::WrappedTargetException, + uno::RuntimeException) +{ +} + + + +// XResultSetMetaDataSupplier +uno::Reference< sdbc::XResultSetMetaData > SAL_CALL +ResultSetBase::getMetaData( + void ) + throw( sdbc::SQLException, + uno::RuntimeException ) +{ + ::ucb::ResultSetMetaData* p = + new ::ucb::ResultSetMetaData( + m_xMSF, m_sProperty ); + return uno::Reference< sdbc::XResultSetMetaData >( p ); +} diff --git a/xmlhelp/source/cxxhelp/provider/services.cxx b/xmlhelp/source/cxxhelp/provider/services.cxx new file mode 100644 index 000000000000..9f3b3639bdfd --- /dev/null +++ b/xmlhelp/source/cxxhelp/provider/services.cxx @@ -0,0 +1,174 @@ +/************************************************************************* + * + * $RCSfile: services.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: abi $ $Date: 2001-05-16 07:36: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 _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_ +#include +#endif +#ifndef _COM_SUN_STAR_LANG_XSINGLESERVICEFACTORY_HPP_ +#include +#endif +#ifndef _COM_SUN_STAR_REGISTRY_XREGISTRYKEY_HPP_ +#include +#endif + +#ifndef _PROVIDER_HXX +#include +#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 && + + ////////////////////////////////////////////////////////////////////// + // Write info into registry. + ////////////////////////////////////////////////////////////////////// + + // @@@ Adjust namespace names. + writeInfo( pRegistryKey, + ::chelp::ContentProvider::getImplementationName_Static(), + ::chelp::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; + + ////////////////////////////////////////////////////////////////////// + // Create factory, if implementation name matches. + ////////////////////////////////////////////////////////////////////// + + // @@@ Adjust namespace names. + if ( ::chelp::ContentProvider::getImplementationName_Static(). + compareToAscii( pImplName ) == 0 ) + { + xFactory = ::chelp::ContentProvider::createServiceFactory( xSMgr ); + } + + ////////////////////////////////////////////////////////////////////// + + if ( xFactory.is() ) + { + xFactory->acquire(); + pRet = xFactory.get(); + } + + return pRet; +} + diff --git a/xmlhelp/source/cxxhelp/provider/urlparameter.cxx b/xmlhelp/source/cxxhelp/provider/urlparameter.cxx new file mode 100644 index 000000000000..72b0c94824b8 --- /dev/null +++ b/xmlhelp/source/cxxhelp/provider/urlparameter.cxx @@ -0,0 +1,461 @@ +#ifndef _DB_CXX_H_ +#include +#endif +#ifndef _URLPARAMETER_HXX_ +#include +#endif +#ifndef _DATABASES_HXX_ +#include +#endif + + +namespace chelp { + + inline bool ascii_isDigit( sal_Unicode ch ) + { + return ((ch >= 0x0030) && (ch <= 0x0039)); + } + + inline bool ascii_isLetter( sal_Unicode ch ) + { + return (( (ch >= 0x0041) && (ch <= 0x005A)) || ((ch >= + 0x0061) && (ch <= 0x007A))); + } + + inline bool isLetterOrDigit( sal_Unicode ch ) + { + return ascii_isLetter( ch ) || ascii_isDigit( ch ); + } + +} + +using namespace chelp; + + +URLParameter::URLParameter( const rtl::OUString& aURL ) throw( com::sun::star::ucb::IllegalIdentifierException ) + : m_aURL( aURL ) +{ + init( false ); + parse(); +} + + +URLParameter::URLParameter( const rtl::OUString& aURL, + const rtl::OUString& aDefaultLanguage ) throw( com::sun::star::ucb::IllegalIdentifierException ) + : m_aURL( aURL ), + m_aDefaultLanguage( aDefaultLanguage ) +{ + init( true ); + parse(); +} + + +rtl::OUString URLParameter::get_id() +{ + if( m_aId.compareToAscii("start") == 0 ) + { // module is set + StaticModuleInformation* inf = + Databases::getStaticInformationForModule( get_module(), + get_language() ); + if( inf ) + m_aId = inf->get_id(); + + m_bStart = true; + } + + return m_aId; +} + +rtl::OUString URLParameter::get_tag() +{ + if( isFile() ) + return get_the_tag(); + else + return m_aTag; +} + + +rtl::OUString URLParameter::get_title() +{ + if( isFile() ) + return get_the_title(); + else if( m_aModule.compareToAscii("") != 0 ) + { + StaticModuleInformation* inf = + Databases::getStaticInformationForModule( get_module(), + get_language() ); + if( inf ) + m_aTitle = inf->get_title(); + } + else // This must be the root + m_aTitle = rtl::OUString::createFromAscii("root"); + + return m_aTitle; +} + + +rtl::OUString URLParameter::get_language() +{ + if( m_aLanguage.getLength() == 0 ) + m_aLanguage = m_aDefaultLanguage; + + return m_aLanguage; +} + + +rtl::OUString URLParameter::get_program() +{ + if( m_aProgram.compareToAscii( "" ) != 0 ) + { + StaticModuleInformation* inf = + Databases::getStaticInformationForModule( get_module(), + get_language() ); + if( inf ) + m_aProgram = inf->get_program(); + } + return m_aProgram; +} + + +// public InputStream getInputFromJarFile() +// { +// try +// { +// JarFile jarFile = Databases.getJarFileForLanguage( get_jar(),get_language() ); // For module and language +// String path = get_path(); +// int idx; +// if( ( idx = path.indexOf( '#' ) ) != -1 ) +// path = path.substring(0,idx); + +// JarEntry jarEntry = jarFile.getJarEntry( path ); +// if( jarEntry != null ) +// return jarFile.getInputStream( jarEntry ); +// else +// { +// // System.out.println( "File not found in jar: " + get_jar() + " " + path ); +// return Databases.errorFile( get_language() ); +// } +// } +// catch( Exception e ) +// { +// return Databases.errorFile( get_language() ); +// } +// } + + + + +// public InputStream getInputFromDisk() +// { +// try +// { +// String fileName = Databases.getInstallDirectory() +// + Databases.lang(get_language()) +// + File.separator +// + get_path(); + +// int idx; +// if( ( idx = fileName.indexOf( '#' ) ) != -1 ) +// fileName = fileName.substring(0,idx); + +// File aFile = new File( fileName ); +// if( aFile.exists() ) +// { +// return new FileInputStream( aFile ); +// } +// else +// { +// System.out.println( "File not found from disk: " + get_path() ); +// return Databases.errorFile( get_language() ); +// } +// } +// catch( Exception e ) +// { +// return Databases.errorFile( get_language() ); +// } +// } + + +// public byte[] getByteArrayText() +// { +// try +// { +// Db db = Databases.getHelptextDbForLanguage( get_module(),get_language() ); + +// StringDbt key = new StringDbt( _id ); +// StringDbt data = new StringDbt(); + +// int err = db.get(null,key,data,0); +// if( data != null ) +// try +// { +// return data.getString().getBytes( "UTF8" ); +// } +// catch( UnsupportedEncodingException e ) +// { +// return data.getString().getBytes(); +// } +// else +// return new byte[0]; +// } +// catch( DbException err ) +// { +// System.out.println( "No database for language: HelpURLParameter._readBerkeley" ); +// return new byte[0]; +// } +// } + + +void URLParameter::init( bool bDefaultLanguageIsInitialized ) +{ + m_bBerkeleyRead = false; + m_bStart = false; + +// m_aTag = rtl::OUString::createFromAscii( "" ); +// m_aId = rtl::OUString::createFromAscii( "" ); +// m_aPath = rtl::OUString::createFromAscii( "" ); +// m_aModule = rtl::OUString::createFromAscii( "" ); +// m_aTitle = rtl::OUString::createFromAscii( "" ); +// m_aJar = rtl::OUString::createFromAscii( "" ); +// m_aEid = rtl::OUString::createFromAscii( "" ); +// m_aLanguage = rtl::OUString::createFromAscii( "" ); + +// if( ! bDefaultLanguageIsInitialized ) +// m_aDefaultLanguage = rtl::OUString::createFromAscii( "" ); + +// m_aPrefix = rtl::OUString::createFromAscii( "" ); +// m_aDevice = rtl::OUString::createFromAscii( "" ); +// m_aProgram = rtl::OUString::createFromAscii( "" ); +// m_aSystem = rtl::OUString::createFromAscii( "" ); +// m_aActive = rtl::OUString::createFromAscii( "" ); + +// m_aQuery = rtl::OUString::createFromAscii( "" ); +// m_aScope = rtl::OUString::createFromAscii( "" ); + m_nHitCount = 100; // The default maximum hitcount +} + + +rtl::OUString URLParameter::get_the_tag() +{ + if( ! m_bBerkeleyRead ) + readBerkeley(); + + m_bBerkeleyRead = true; + + return m_aTag; +} + + + +rtl::OUString URLParameter::get_the_path() +{ + if( ! m_bBerkeleyRead ) + readBerkeley(); + m_bBerkeleyRead = true; + + return m_aPath; +} + + + +rtl::OUString URLParameter::get_the_title() +{ + if( ! m_bBerkeleyRead ) + readBerkeley(); + m_bBerkeleyRead = true; + + return m_aTitle; +} + + +rtl::OUString URLParameter::get_the_jar() +{ + if( ! m_bBerkeleyRead ) + readBerkeley(); + m_bBerkeleyRead = true; + + return m_aJar; +} + + +void URLParameter::readBerkeley() +{ +// if( get_id().compareToAscii("") != 0 ) +// { +// try +// { +// Db* db = Databases::getDatabaseForLanguage( get_module(), +// get_language() ); + +// StringDbt key = new StringDbt( m_aId ); +// StringDbt data = new StringDbt(); + +// int err = db.get(null,key,data,0); +// if( data != null ) +// { +// m_aTitle = data.getTitle(); +// m_aPath = data.getFile(); +// m_aJar = data.getDatabase(); +// m_aTag = data.getHash(); +// } + +// } +// catch( const DbException& err ) +// { +// printf( "URLParameter::readBerkeley() -> DbException" ); +// } +// } +} + + +void URLParameter::parse() throw( com::sun::star::ucb::IllegalIdentifierException ) +{ + m_aExpr = m_aURL; + + sal_Int32 lstIdx = m_aExpr.lastIndexOf( sal_Unicode( '#' ) ); + if( lstIdx != -1 ) + m_aExpr = m_aExpr.copy( 0,lstIdx ); + + if( ! scheme() || ! name( module() ) || ! query() ) + throw com::sun::star::ucb::IllegalIdentifierException(); +} + + + +bool URLParameter::scheme() +{ +#define PREFIX_LENGTH 20 + if( m_aExpr.compareToAscii( "vnd.sun.star.help://",PREFIX_LENGTH ) == 0 ) + { + m_aExpr = m_aExpr.copy( PREFIX_LENGTH ); +#undef PREFIX_LENGTH + return true; + } +#define PREFIX_LENGTH 19 + else if( m_aExpr.compareToAscii( "vnd.sun.star.help:/",PREFIX_LENGTH ) == 0 ) + { + m_aExpr = m_aExpr.copy( PREFIX_LENGTH ); +#undef PREFIX_LENGTH + return true; + } +#define PREFIX_LENGTH 18 + else if( m_aExpr.compareToAscii( "vnd.sun.star.help:",PREFIX_LENGTH ) == 0 ) + { + m_aExpr = m_aExpr.copy( PREFIX_LENGTH ); +#undef PREFIX_LENGTH + return true; + } + else + return false; +} + + + +bool URLParameter::module() +{ + sal_Int32 idx = 0,length = m_aExpr.getLength(); + + while( idx < length && isLetterOrDigit( (m_aExpr.getStr())[idx] ) ) + ++idx; + + if( idx != 0 ) + { + m_aModule = m_aExpr.copy( 0,idx ); + m_aExpr = m_aExpr.copy( idx ); + return true; + } + else + return false; +} + + + +bool URLParameter::name( bool modulePresent ) +{ + // if modulepresent, a name may be present, but must not + + sal_Int32 length = m_aExpr.getLength(); + + + if( length != 0 && (m_aExpr.getStr())[0] == sal_Unicode( '/' ) ) + { + sal_Int32 idx = 1; + while( idx < length && isLetterOrDigit( (m_aExpr.getStr())[idx] ) ) + ++idx; + + if( idx != 1 && ! modulePresent ) + return false; + else + { + m_aId = m_aExpr.copy( 1,idx ); + m_aExpr = m_aExpr.copy( idx ); + } + } + + return true; +} + + +bool URLParameter::query() +{ + rtl::OUString query; + + if( ! m_aExpr.getLength() ) + return true; + else if( (m_aExpr.getStr())[0] == sal_Unicode( '?' ) ) + query = m_aExpr.copy( 1 ).trim(); + else + return false; + + + bool ret = true; + sal_Int32 delimIdx,equalIdx; + rtl::OUString parameter,value; + + while( query.getLength() != 0 ) + { + delimIdx = query.indexOf( sal_Unicode( '&' ) ); + equalIdx = query.indexOf( sal_Unicode( '=' ) ); + parameter = query.copy( 0,equalIdx ).trim(); + if( delimIdx == -1 ) + { + value = query.copy( equalIdx + 1 ).trim(); + query = rtl::OUString(); + } + else + { + value = query.copy( equalIdx+1,delimIdx - equalIdx - 1 ).trim(); + query = query.copy( delimIdx+1 ).trim(); + } + + if( parameter.compareToAscii( "Language" ) == 0 ) + m_aLanguage = value; + else if( parameter.compareToAscii( "Device" ) == 0 ) + m_aDevice = value; + else if( parameter.compareToAscii( "Program" ) == 0 ) + m_aProgram = value; + else if( parameter.compareToAscii( "Eid" ) == 0 ) + m_aEid = value; + else if( parameter.compareToAscii( "Query" ) == 0 ) + { + if( ! m_aQuery.getLength() ) + m_aQuery = value; + else + m_aQuery += ( rtl::OUString::createFromAscii( " " ) + value ); + } + else if( parameter.compareToAscii( "Scope" ) == 0 ) + m_aScope = value; + else if( parameter.compareToAscii( "System" ) == 0 ) + m_aSystem = value; + else if( parameter.compareToAscii( "HelpPrefix" ) == 0 ) + m_aPrefix = value; + else if( parameter.compareToAscii( "HitCount" ) == 0 ) + m_nHitCount = value.toInt32(); + else if( parameter.compareToAscii( "Active" ) == 0 ) + m_aActive = value; + else + ret = false; + } + + return ret; +} -- cgit