diff options
author | Andreas Bille <abi@openoffice.org> | 2001-07-12 12:32:24 +0000 |
---|---|---|
committer | Andreas Bille <abi@openoffice.org> | 2001-07-12 12:32:24 +0000 |
commit | d508d9e32d28380484ffd2f6acbc04c098a27194 (patch) | |
tree | 133e32d8c95bcc5446a64e827e02a186454de6de /xmlhelp | |
parent | 408abfcc27a2459ef8f803bdf18fa90319bf4722 (diff) |
Complete
Diffstat (limited to 'xmlhelp')
-rw-r--r-- | xmlhelp/source/treeview/tvfactory.cxx | 35 | ||||
-rw-r--r-- | xmlhelp/source/treeview/tvread.cxx | 483 | ||||
-rw-r--r-- | xmlhelp/source/treeview/tvread.hxx | 28 |
3 files changed, 475 insertions, 71 deletions
diff --git a/xmlhelp/source/treeview/tvfactory.cxx b/xmlhelp/source/treeview/tvfactory.cxx index cc31594fca55..b1aa326c724a 100644 --- a/xmlhelp/source/treeview/tvfactory.cxx +++ b/xmlhelp/source/treeview/tvfactory.cxx @@ -1,6 +1,9 @@ #ifndef _COM_SUN_STAR_LANG_XSINGLESERVICEFACTORY_HPP_ #include <com/sun/star/lang/XSingleServiceFactory.hpp> #endif +#ifndef _COM_SUN_STAR_CONTAINER_XHIERARCHICALNAMEACCESS_HPP_ +#include <com/sun/star/container/XHierarchicalNameAccess.hpp> +#endif #ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_ #include <com/sun/star/beans/PropertyValue.hpp> #endif @@ -17,6 +20,7 @@ using namespace com::sun::star; using namespace com::sun::star::uno; using namespace com::sun::star::lang; using namespace com::sun::star::beans; +using namespace com::sun::star::container; @@ -141,11 +145,38 @@ TVFactory::createInstanceWithArguments( { if( ! m_xHDS.is() ) { - cppu::OWeakObject* p = new TVChildTarget( m_xMSF,Arguments ); + cppu::OWeakObject* p = new TVChildTarget( m_xMSF ); m_xHDS = Reference< XInterface >( p ); } - return m_xHDS; + Reference< XInterface > ret = m_xHDS; + + rtl::OUString hierview; + for( int i = 0; i < Arguments.getLength(); ++i ) + { + PropertyValue pV; + if( ! ( Arguments[i] >>= pV ) ) + continue; + + if( pV.Name.compareToAscii( "nodepath" ) ) + continue; + + if( ! ( pV.Value >>= hierview ) ) + continue; + + break; + } + + if( hierview.getLength() ) + { + Reference< XHierarchicalNameAccess > xhieraccess( m_xHDS,UNO_QUERY ); + Any aAny = xhieraccess->getByHierarchicalName( hierview ); + Reference< XInterface > xInterface; + aAny >>= xInterface; + return xInterface; + } + else + return m_xHDS; } diff --git a/xmlhelp/source/treeview/tvread.cxx b/xmlhelp/source/treeview/tvread.cxx index e1711ec34bd3..738baa7602c4 100644 --- a/xmlhelp/source/treeview/tvread.cxx +++ b/xmlhelp/source/treeview/tvread.cxx @@ -1,4 +1,7 @@ #include <string.h> +#ifndef _VOS_DIAGNOSE_HXX_ +#include <vos/diagnose.hxx> +#endif #ifndef _TREEVIEW_TVREAD_HXX_ #include "tvread.hxx" #endif @@ -8,27 +11,164 @@ #ifndef _OSL_FILE_HXX_ #include <osl/file.hxx> #endif +#ifndef _COM_SUN_STAR_FRAME_XCONFIGMANAGER_HPP_ +#include <com/sun/star/frame/XConfigManager.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_ +#include <com/sun/star/beans/PropertyValue.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_PROPERTYSTATE_HPP_ +#include <com/sun/star/beans/PropertyState.hpp> +#endif + +namespace treeview { + + + class TVDom + { + friend class TVChildTarget; + friend class TVRead; + + public: + + TVDom( TVDom* arent = 0 ) + : parent( arent ), + childs( 0 ) + { + } + + ~TVDom() + { + for( unsigned i = 0; i < childs.size(); ++i ) + delete childs[i]; + } + + + TVDom* newChild() + { + childs.push_back( new TVDom( this ) ); + return childs.back(); + } + + + TVDom* getParent() const + { + return parent; + } + + enum Kind { + tree_view, + tree_node, + tree_leaf, + other + }; + + bool isLeaf() const { return kind == TVDom::tree_leaf; } + void setKind( Kind ind ) { kind = ind; } + Kind getKind( ) const { return kind; } + + + void setApplication( const char* appl ) + { + application = rtl::OUString( (sal_Char*)(appl), + strlen( appl ), + RTL_TEXTENCODING_UTF8 ); + } + + void setTitle( const char* itle ) + { + title = rtl::OUString( (sal_Char*)(itle), + strlen( itle ), + RTL_TEXTENCODING_UTF8 ); + } + + void setTitle( const XML_Char* itle,int len ) + { + title = rtl::OUString( (sal_Char*)(itle), + len, + RTL_TEXTENCODING_UTF8 ); + } + + void setId( const char* d ) + { + id = rtl::OUString( (sal_Char*)(d), + strlen( d ), + RTL_TEXTENCODING_UTF8 ); + } + + void setAnchor( const char* nchor ) + { + anchor = rtl::OUString( (sal_Char*)(nchor), + strlen( nchor ), + RTL_TEXTENCODING_UTF8 ); + } + + rtl::OUString getTargetURL() + { + if( ! targetURL.getLength() ) + { + const TVDom* p = this; + while( ! p->application.getLength() ) + p = p->parent; + + targetURL = ( rtl::OUString::createFromAscii( "vnd.sun.star.help://" ) + + p->application + + rtl::OUString::createFromAscii( "/" ) + + id ); + } + + return targetURL; + } + + private: + + Kind kind; + rtl::OUString application; + rtl::OUString title; + rtl::OUString id; + rtl::OUString anchor; + rtl::OUString targetURL; + + TVDom *parent; + std::vector< TVDom* > childs; + }; + +} + using namespace treeview; using namespace com::sun::star; using namespace com::sun::star::uno; +using namespace com::sun::star::beans; using namespace com::sun::star::lang; using namespace com::sun::star::util; +using namespace com::sun::star::frame; using namespace com::sun::star::container; +TVRead::TVRead() +{ +} + + -TVRead::TVRead( const Reference< XMultiServiceFactory >& xMSF, - const rtl::OUString& aTitle, - const rtl::OUString& aTargetURL, - const rtl::Reference< TVChildTarget > aChildren ) - : m_xMSF( xMSF ), - Title( aTitle ), - TargetURL( aTargetURL ), - Children( aChildren ) +TVRead::TVRead( const ConfigData& configData,TVDom* tvDom ) { + if( ! tvDom ) + return; + + Title = tvDom->title; + if( tvDom->isLeaf() ) + { + TargetURL = ( tvDom->getTargetURL() + configData.appendix ); + if( tvDom->anchor.getLength() ) + TargetURL += ( rtl::OUString::createFromAscii( "#" ) + + tvDom->anchor ); + } + else + Children = new TVChildTarget( configData,tvDom ); } @@ -194,34 +334,45 @@ TVRead::hasByHierarchicalName( const rtl::OUString& aName ) /**************************************************************************/ -class TVDom -{ -public: - -private: -}; void start_handler(void *userData, const XML_Char *name, const XML_Char **atts) { - TVDom *tvDom = static_cast< TVDom* >( userData ); - if( strcmp( name,"tree_view" ) == 0 ) - { + TVDom::Kind kind; - } - else if( strcmp( name,"help_section" ) == 0 ) - { + if( strcmp( name,"help_section" ) == 0 || + strcmp( name,"node" ) == 0 ) + kind = TVDom::tree_node; + else if( strcmp( name,"topic" ) == 0 ) + kind = TVDom::tree_leaf; + else + return; - } - else if( strcmp( name,"node" ) == 0 ) - { + TVDom **tvDom = static_cast< TVDom** >( userData ); + TVDom *p; + p = *tvDom; - } - else if( strcmp( name,"topic" ) == 0 ) +// if( kind == TVDom::tree_node ) { + *tvDom = p->newChild(); + p = *tvDom; + } + p->setKind( kind ); + while( *atts ) + { + if( strcmp( *atts,"application" ) == 0 ) + p->setApplication( *(atts+1) ); + else if( strcmp( *atts,"title" ) == 0 ) + p->setTitle( *(atts+1) ); + else if( strcmp( *atts,"id" ) == 0 ) + p->setId( *(atts+1) ); + else if( strcmp( *atts,"anchor" ) == 0 ) + p->setAnchor( *(atts+1) ); + + atts+=2; } } @@ -229,7 +380,10 @@ void start_handler(void *userData, void end_handler(void *userData, const XML_Char *name ) { - // TVDom *tvDom = static_cast< TVDom* >( userData ); + TVDom **tvDom = static_cast< TVDom** >( userData ); + +// if( (*tvDom)->getKind() == TVDom::tree_node ) + *tvDom = (*tvDom)->getParent(); } @@ -237,45 +391,46 @@ void data_handler( void *userData, const XML_Char *s, int len) { - // TVDom *tvDom = static_cast< TVDom* >( userData ); + TVDom **tvDom = static_cast< TVDom** >( userData ); + if( (*tvDom)->isLeaf() ) + (*tvDom)->setTitle( s,len ); } -void cdatastart_handler( void *userData ) + +TVChildTarget::TVChildTarget( const ConfigData& configData,TVDom* tvDom ) { - // TVDom *tvDom = static_cast< TVDom* >( userData ); + Elements.resize( tvDom->childs.size() ); + for( unsigned i = 0; i < Elements.size(); ++i ) + Elements[i] = new TVRead( configData,tvDom->childs[i] ); } -void cdataend_handler( void *userData ) -{ - // TVDom *tvDom = static_cast< TVDom* >( userData ); -} -TVChildTarget::TVChildTarget( const Reference< XMultiServiceFactory >& xMSF, - const Sequence< Any >& aSeq ) - : TVRead( xMSF,rtl::OUString(),rtl::OUString() ), - Elements( 2 ) +TVChildTarget::TVChildTarget( const Reference< XMultiServiceFactory >& xMSF ) { - Elements[0] = - new TVRead( - xMSF, - rtl::OUString::createFromAscii( "content1" ), - rtl::OUString::createFromAscii( "vnd.sun.star.help://swriter/start?Language=de&System=WIN" ) ); + ConfigData configData = init( xMSF ); - Elements[1] = - new TVRead( - xMSF, - rtl::OUString::createFromAscii( "content2" ), - rtl::OUString::createFromAscii( "vnd.sun.star.help://swriter/des?Language=de&System=WIN" ) ); + if( ! configData.fileurl.getLength() || + ! configData.locale.getLength() || + ! configData.system.getLength() || + ! configData.filelen ) + return; + osl::File aFile( + configData.fileurl ); - osl::File aFile( rtl::OUString::createFromAscii( - "file:///e:/src637a3_49/help/de/treeview.xml" ) ); + configData.appendix = + rtl::OUString::createFromAscii( "?Language=" ) + + configData.locale + + rtl::OUString::createFromAscii( "&System=" ) + + configData.system; + + sal_uInt64 ret,len = configData.filelen; + if( ! len ) return; - sal_uInt64 ret,len = 7258; char* s = new char[ int(len) ]; int isFinal = true; @@ -283,7 +438,7 @@ TVChildTarget::TVChildTarget( const Reference< XMultiServiceFactory >& xMSF, aFile.open( OpenFlag_Read ); aFile.read( s,len,ret ); - + aFile.close(); XML_SetElementHandler( parser, start_handler, @@ -293,20 +448,20 @@ TVChildTarget::TVChildTarget( const Reference< XMultiServiceFactory >& xMSF, data_handler); - XML_SetCdataSectionHandler( parser, - cdatastart_handler, - cdataend_handler ); - - TVDom* tvDom = new TVDom(); - XML_SetUserData( parser,tvDom ); - + TVDom tvDom; + TVDom* pTVDom = &tvDom; + XML_SetUserData( parser,&pTVDom ); int parsed = XML_Parse( parser,s,int( len ),isFinal ); - delete tvDom; - aFile.close(); delete[] s; XML_ParserFree( parser ); + + // now TVDom holds the relevant information + + Elements.resize( tvDom.childs.size() ); + for( unsigned i = 0; i < Elements.size(); ++i ) + Elements[i] = new TVRead( configData,tvDom.childs[i] ); } @@ -405,3 +560,211 @@ TVChildTarget::hasByHierarchicalName( const rtl::OUString& aName ) else return hasByName( name ); } + + + + + + +ConfigData TVChildTarget::init( const Reference< XMultiServiceFactory >& xSMgr ) +{ + ConfigData configData; + + rtl::OUString sProviderService = + rtl::OUString::createFromAscii( "com.sun.star.configuration.ConfigurationProvider" ); + + Any aAny; + aAny <<= rtl::OUString::createFromAscii( "local" ); + PropertyValue aProp( rtl::OUString::createFromAscii( "servertype" ), + -1, + aAny, + PropertyState_DIRECT_VALUE ); + + Sequence< Any > seq(1); + seq[0] <<= aProp; + + Reference< XMultiServiceFactory > sProvider; + try + { + sProvider = + Reference< XMultiServiceFactory >( + xSMgr->createInstanceWithArguments( sProviderService,seq ), + UNO_QUERY ); + } + catch( const com::sun::star::uno::Exception& ) + { + VOS_ENSHURE( sProvider.is()," cant instantiate the multiservicefactory " ); + } + + + if( ! sProvider.is() ) + return configData; + + rtl::OUString sReaderService = + rtl::OUString::createFromAscii( "com.sun.star.configuration.ConfigurationAccess" ); + + seq[0] <<= rtl::OUString::createFromAscii( "org.openoffice.Office.Common" ); + + + Reference< XHierarchicalNameAccess > xHierAccess; + try + { + xHierAccess = + Reference< XHierarchicalNameAccess > + ( sProvider->createInstanceWithArguments( sReaderService,seq ), + UNO_QUERY ); + } + catch( const com::sun::star::uno::Exception& ) + { + VOS_ENSHURE( xHierAccess.is()," cant instantiate the reader service " ); + } + + if( ! xHierAccess.is() ) + return configData; + + try + { + aAny = + xHierAccess->getByHierarchicalName( rtl::OUString::createFromAscii("Path/Current/Help") ); + } + catch( const com::sun::star::container::NoSuchElementException& ) + { + VOS_ENSHURE( false," path to help files could not be determined " ); + return configData; + } + + + rtl::OUString instPath; + bool err = ! ( aAny >>= instPath ); + + if( err ) + { + VOS_ENSHURE( false," path to help files could not be determined " ); + return configData; + } + + Reference< XConfigManager > xCfgMgr; + try + { + xCfgMgr = + Reference< XConfigManager >( + xSMgr->createInstance( rtl::OUString::createFromAscii( "com.sun.star.config.SpecialConfigManager" ) ), + UNO_QUERY ); + } + catch( const com::sun::star::uno::Exception& ) + { + VOS_ENSHURE( xCfgMgr.is()," cant instantiate the special config manager " ); + } + + + if( ! xCfgMgr.is() ) + return configData; + + instPath = xCfgMgr->substituteVariables( instPath ); + + rtl::OUString url; + osl::FileBase::RC errFile = osl::FileBase::getFileURLFromSystemPath( instPath,url ); + if( errFile != osl::FileBase::E_None ) + return configData; + + + Any aAny1; + try + { + aAny1 = + xHierAccess->getByHierarchicalName( rtl::OUString::createFromAscii("Help/System") ); + } + catch( const com::sun::star::container::NoSuchElementException& ) + { + VOS_ENSHURE( false," " ); + return configData; + } + + + rtl::OUString system; + err = ! ( aAny1 >>= system ); + + if( err ) + { + VOS_ENSHURE( false," path to help files could not be determined " ); + return configData; + } + + + // Reading Locale + + seq[0] <<= rtl::OUString::createFromAscii( "org.openoffice.UserProfile" ); + + try + { + xHierAccess = + Reference< XHierarchicalNameAccess > + ( sProvider->createInstanceWithArguments( sReaderService,seq ), + UNO_QUERY ); + } + catch( const com::sun::star::uno::Exception& ) + { + VOS_ENSHURE( xHierAccess.is()," cant instantiate the reader service " ); + } + + if( ! xHierAccess.is() ) + return configData; + + Any aAny2; + try + { + aAny2 = + xHierAccess->getByHierarchicalName( rtl::OUString::createFromAscii("International/Locale") ); + } + catch( const com::sun::star::container::NoSuchElementException& ) + { + VOS_ENSHURE( false," path to help files could not be determined " ); + return configData; + } + + rtl::OUString locale; + err = ! ( aAny2 >>= locale ); + + if( err ) + { + VOS_ENSHURE( false," "); + return configData; + } + + + // Determine fileurl from url and locale + + if( url.lastIndexOf( sal_Unicode( '/' ) ) != url.getLength() - 1 ) + url += rtl::OUString::createFromAscii( "/" ); + + rtl::OUString ret; + + sal_Int32 idx; + osl::DirectoryItem aDirItem; + + if( osl::FileBase::E_None == osl::DirectoryItem::get( url + locale,aDirItem ) ) + ret = locale; + else if( ( ( idx = locale.indexOf( '-' ) ) != -1 || + ( idx = locale.indexOf( '_' ) ) != -1 ) && + osl::FileBase::E_None == osl::DirectoryItem::get( url + locale.copy( 0,idx ), + aDirItem ) ) + ret = locale.copy( 0,idx ); + + url = url + ret + rtl::OUString::createFromAscii( "/treeview.xml" ); + + // Determine the filelen + sal_uInt64 filelen = 0; + + osl::FileStatus aStatus( FileStatusMask_FileSize ); + if( osl::FileBase::E_None == osl::DirectoryItem::get( url,aDirItem ) && + osl::FileBase::E_None == aDirItem.getFileStatus( aStatus ) && + aStatus.isValid( FileStatusMask_FileSize ) ) + filelen = aStatus.getFileSize(); + + + configData.fileurl = url; + configData.system = system; + configData.locale = locale; + configData.filelen = filelen; + return configData; +} diff --git a/xmlhelp/source/treeview/tvread.hxx b/xmlhelp/source/treeview/tvread.hxx index f3b6e31b5925..1a397aa032ad 100644 --- a/xmlhelp/source/treeview/tvread.hxx +++ b/xmlhelp/source/treeview/tvread.hxx @@ -43,6 +43,15 @@ namespace treeview { + struct ConfigData + { + sal_uInt64 filelen; + rtl::OUString fileurl,locale,system; + rtl::OUString appendix; + }; + + + class TVDom; class TVChildTarget; @@ -58,10 +67,9 @@ namespace treeview { public: - TVRead( const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& xMSF, - const rtl::OUString& aTitle, - const rtl::OUString& aTargetURL, - const rtl::Reference< TVChildTarget > aTargetRef = rtl::Reference< TVChildTarget >(0) ); + TVRead(); + + TVRead( const ConfigData& configData,TVDom* tvDom = 0 ); ~TVRead(); @@ -178,8 +186,6 @@ namespace treeview { rtl::OUString Title; rtl::OUString TargetURL; rtl::Reference< TVChildTarget > Children; - - com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > m_xMSF; }; @@ -189,12 +195,13 @@ namespace treeview { { public: - TVChildTarget( const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& xMSF, - const com::sun::star::uno::Sequence< com::sun::star::uno::Any >& aSeq ); + TVChildTarget( const ConfigData& configData,TVDom* tvDom ); + + TVChildTarget( const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& xMSF ); ~TVChildTarget(); - virtual com::sun::star::uno::Any SAL_CALL + virtual com::sun::star::uno::Any SAL_CALL getByName( const rtl::OUString& aName ) throw( com::sun::star::container::NoSuchElementException, com::sun::star::lang::WrappedTargetException, @@ -224,6 +231,9 @@ namespace treeview { private: std::vector< rtl::Reference< TVRead > > Elements; + + ConfigData + init( const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& xMSF ); }; } |