From 425b7f5c0f1d0bc580bbc955c6934611e0db7c20 Mon Sep 17 00:00:00 2001 From: Andreas Bille Date: Wed, 11 Jul 2001 14:35:25 +0000 Subject: [PATCH] Begining xml-parsing --- xmlhelp/source/treeview/makefile.mk | 5 +- xmlhelp/source/treeview/tvfactory.cxx | 2 +- xmlhelp/source/treeview/tvread.cxx | 320 +++++++++++++++++++++----- xmlhelp/source/treeview/tvread.hxx | 63 ++++- 4 files changed, 320 insertions(+), 70 deletions(-) diff --git a/xmlhelp/source/treeview/makefile.mk b/xmlhelp/source/treeview/makefile.mk index a1350e1f0f50..6f99bd640f22 100644 --- a/xmlhelp/source/treeview/makefile.mk +++ b/xmlhelp/source/treeview/makefile.mk @@ -2,9 +2,9 @@ # # $RCSfile: makefile.mk,v $ # -# $Revision: 1.1 $ +# $Revision: 1.2 $ # -# last change: $Author: abi $ $Date: 2001-07-10 18:56:35 $ +# last change: $Author: abi $ $Date: 2001-07-11 15:35:25 $ # # The Contents of this file are made available subject to the terms of # either of the following licenses @@ -85,6 +85,7 @@ SHL1IMPLIB=i$(TARGET) SHL1STDLIBS=\ $(CPPUHELPERLIB) \ $(CPPULIB) \ + $(EXPATASCII3RDLIB) \ $(SALLIB) \ $(VOSLIB) \ $(UCBHELPERLIB) diff --git a/xmlhelp/source/treeview/tvfactory.cxx b/xmlhelp/source/treeview/tvfactory.cxx index 03da1731e2d3..cc31594fca55 100644 --- a/xmlhelp/source/treeview/tvfactory.cxx +++ b/xmlhelp/source/treeview/tvfactory.cxx @@ -141,7 +141,7 @@ TVFactory::createInstanceWithArguments( { if( ! m_xHDS.is() ) { - cppu::OWeakObject* p = new TVRead( m_xMSF,Arguments ); + cppu::OWeakObject* p = new TVChildTarget( m_xMSF,Arguments ); m_xHDS = Reference< XInterface >( p ); } diff --git a/xmlhelp/source/treeview/tvread.cxx b/xmlhelp/source/treeview/tvread.cxx index ad96d80ffed8..e1711ec34bd3 100644 --- a/xmlhelp/source/treeview/tvread.cxx +++ b/xmlhelp/source/treeview/tvread.cxx @@ -1,6 +1,14 @@ +#include #ifndef _TREEVIEW_TVREAD_HXX_ #include "tvread.hxx" #endif +#ifndef XmlParse_INCLUDED +#include +#endif +#ifndef _OSL_FILE_HXX_ +#include +#endif + using namespace treeview; using namespace com::sun::star; @@ -10,24 +18,17 @@ using namespace com::sun::star::util; using namespace com::sun::star::container; -TVRead::TVRead( const Reference< XMultiServiceFactory >& xMSF ) - : m_xMSF( xMSF ), - Title( rtl::OUString::createFromAscii( "startpage" ) ), - TargetURL( rtl::OUString::createFromAscii( "vnd.sun.star.help://swriter/start?Language=de&System=WIN" ) ), - Children( 0 ) -{ -} - TVRead::TVRead( const Reference< XMultiServiceFactory >& xMSF, - const Sequence< Any >& aSeq ) + const rtl::OUString& aTitle, + const rtl::OUString& aTargetURL, + const rtl::Reference< TVChildTarget > aChildren ) : m_xMSF( xMSF ), - Title( rtl::OUString::createFromAscii( "root" ) ), - TargetURL(), - Children( 1 ) + Title( aTitle ), + TargetURL( aTargetURL ), + Children( aChildren ) { - Children[0] = new TVRead( xMSF ); } @@ -97,26 +98,26 @@ Any SAL_CALL TVRead::getByName( const rtl::OUString& aName ) throw( NoSuchElementException, WrappedTargetException, - RuntimeException) + RuntimeException ) { + bool found( true ); Any aAny; if( aName.compareToAscii( "Title" ) == 0 ) aAny <<= Title; else if( aName.compareToAscii( "TargetURL" ) == 0 ) aAny <<= TargetURL; - else + else if( aName.compareToAscii( "Children" ) == 0 ) { - for( unsigned int i = 0; i < Children.size(); ++i ) - if( Children[i]->Title == aName ) - { - cppu::OWeakObject* p = Children[i].get(); - aAny <<= Reference< XInterface >( p ); - return aAny; - } - throw NoSuchElementException(); + cppu::OWeakObject* p = Children.get(); + aAny <<= Reference< XInterface >( p ); } + else + found = false; - return aAny; + if( found ) + return aAny; + + throw NoSuchElementException(); } @@ -126,9 +127,11 @@ Sequence< rtl::OUString > SAL_CALL TVRead::getElementNames( ) throw( RuntimeException ) { - Sequence< rtl::OUString > seq( Children.size() ); - for( unsigned int i = 0; i < Children.size(); ++i ) - seq[i] = Children[i]->Title; + Sequence< rtl::OUString > seq( 3 ); + + seq[0] = rtl::OUString::createFromAscii( "Title" ); + seq[1] = rtl::OUString::createFromAscii( "TargetURL" ); + seq[2] = rtl::OUString::createFromAscii( "Children" ); return seq; } @@ -140,12 +143,9 @@ TVRead::hasByName( const rtl::OUString& aName ) throw( RuntimeException ) { if( aName.compareToAscii( "Title" ) == 0 || - aName.compareToAscii( "TargetURL" ) == 0 ) + aName.compareToAscii( "TargetURL" ) == 0 || + aName.compareToAscii( "Children" ) == 0 ) return true; - else - for( unsigned int i = 0; i < Children.size(); ++i ) - if( aName == Children[i]->Title ) - return true; return false; } @@ -160,50 +160,248 @@ TVRead::getByHierarchicalName( const rtl::OUString& aName ) { sal_Int32 idx; rtl::OUString name( aName ); - if( ( idx = name.indexOf( sal_Unicode( '/' ) ) ) != -1 ) - { - rtl::OUString childName = name.copy( 0,idx ); - TVRead* p = 0; - for( unsigned int i = 0; i < Children.size(); ++i ) - if( Children[i]->Title == childName ) - { - p = Children[i].get(); - break; - } - if( p ) - return p->getByHierarchicalName( name.copy( 1 + idx ) ); - else - throw NoSuchElementException(); - } + if( ( idx = name.indexOf( sal_Unicode( '/' ) ) ) != -1 && + name.copy( 0,idx ).compareToAscii( "Children" ) == 0 ) + return Children->getByHierarchicalName( name.copy( 1 + idx ) ); - return getByName( aName ); + return getByName( name ); } + sal_Bool SAL_CALL TVRead::hasByHierarchicalName( const rtl::OUString& aName ) throw( RuntimeException ) { sal_Int32 idx; rtl::OUString name( aName ); + + if( ( idx = name.indexOf( sal_Unicode( '/' ) ) ) != -1 && + name.copy( 0,idx ).compareToAscii( "Children" ) == 0 ) + return Children->hasByHierarchicalName( name.copy( 1 + idx ) ); + + return hasByName( name ); +} + + + +/**************************************************************************/ +/* */ +/* TVChildTarget */ +/* */ +/**************************************************************************/ + + +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 ) + { + + } + else if( strcmp( name,"help_section" ) == 0 ) + { + + } + else if( strcmp( name,"node" ) == 0 ) + { + + } + else if( strcmp( name,"topic" ) == 0 ) + { + + } +} + + +void end_handler(void *userData, + const XML_Char *name ) +{ + // TVDom *tvDom = static_cast< TVDom* >( userData ); +} + + +void data_handler( void *userData, + const XML_Char *s, + int len) +{ + // TVDom *tvDom = static_cast< TVDom* >( userData ); +} + + +void cdatastart_handler( void *userData ) +{ + // TVDom *tvDom = static_cast< TVDom* >( userData ); +} + + +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 ) +{ + Elements[0] = + new TVRead( + xMSF, + rtl::OUString::createFromAscii( "content1" ), + rtl::OUString::createFromAscii( "vnd.sun.star.help://swriter/start?Language=de&System=WIN" ) ); + + Elements[1] = + new TVRead( + xMSF, + rtl::OUString::createFromAscii( "content2" ), + rtl::OUString::createFromAscii( "vnd.sun.star.help://swriter/des?Language=de&System=WIN" ) ); + + + osl::File aFile( rtl::OUString::createFromAscii( + "file:///e:/src637a3_49/help/de/treeview.xml" ) ); + + sal_uInt64 ret,len = 7258; + char* s = new char[ int(len) ]; + int isFinal = true; + + XML_Parser parser = XML_ParserCreate( 0 ); + + aFile.open( OpenFlag_Read ); + aFile.read( s,len,ret ); + + + XML_SetElementHandler( parser, + start_handler, + end_handler ); + + XML_SetCharacterDataHandler( parser, + data_handler); + + + XML_SetCdataSectionHandler( parser, + cdatastart_handler, + cdataend_handler ); + + TVDom* tvDom = new TVDom(); + XML_SetUserData( parser,tvDom ); + + + int parsed = XML_Parse( parser,s,int( len ),isFinal ); + + delete tvDom; + aFile.close(); + delete[] s; + XML_ParserFree( parser ); +} + + +TVChildTarget::~TVChildTarget() +{ +} + + + +Any SAL_CALL +TVChildTarget::getByName( const rtl::OUString& aName ) + throw( NoSuchElementException, + WrappedTargetException, + RuntimeException ) +{ + sal_Int32 idx = aName.toInt32() - 1; + if( idx < 0 || Elements.size() <= sal_uInt32( idx ) ) + throw NoSuchElementException(); + + Any aAny; + cppu::OWeakObject* p = Elements[idx].get(); + aAny <<= Reference< XInterface >( p ); + return aAny; +} + + + + +Sequence< rtl::OUString > SAL_CALL +TVChildTarget::getElementNames( ) + throw( RuntimeException ) +{ + Sequence< rtl::OUString > seq( Elements.size() ); + for( unsigned i = 0; i < Elements.size(); ++i ) + seq[i] = rtl::OUString::valueOf( sal_Int32( 1+i ) ); + + return seq; +} + + + +sal_Bool SAL_CALL +TVChildTarget::hasByName( const rtl::OUString& aName ) + throw( RuntimeException ) +{ + sal_Int32 idx = aName.toInt32() - 1; + if( idx < 0 || Elements.size() <= sal_uInt32( idx ) ) + return false; + + return true; +} + + + +// XHierarchicalNameAccess + +Any SAL_CALL +TVChildTarget::getByHierarchicalName( const rtl::OUString& aName ) + throw( NoSuchElementException, + RuntimeException ) +{ + sal_Int32 idx; + rtl::OUString name( aName ); + + if( ( idx = name.indexOf( sal_Unicode( '/' ) ) ) != -1 ) + { + sal_Int32 pref = name.copy( 0,idx ).toInt32() - 1; + + if( pref < 0 || Elements.size() <= sal_uInt32( pref ) ) + throw NoSuchElementException(); + + return Elements[pref]->getByHierarchicalName( name.copy( 1 + idx ) ); + } + else + return getByName( name ); +} + + + +sal_Bool SAL_CALL +TVChildTarget::hasByHierarchicalName( const rtl::OUString& aName ) + throw( RuntimeException ) +{ + sal_Int32 idx; + rtl::OUString name( aName ); + if( ( idx = name.indexOf( sal_Unicode( '/' ) ) ) != -1 ) { - rtl::OUString childName = name.copy( 0,idx ); - TVRead* p = 0; - for( unsigned int i = 0; i < Children.size(); ++i ) - if( Children[i]->Title == childName ) - { - p = Children[i].get(); - break; - } + sal_Int32 pref = name.copy( 0,idx ).toInt32() - 1; - if( p ) - return p->hasByHierarchicalName( name.copy( 1 + idx ) ); - else + if( pref < 0 || Elements.size() <= sal_uInt32( pref ) ) return false; - } - return hasByName( aName ); + return Elements[pref]->hasByHierarchicalName( name.copy( 1 + idx ) ); + } + else + return hasByName( name ); } diff --git a/xmlhelp/source/treeview/tvread.hxx b/xmlhelp/source/treeview/tvread.hxx index d514dd34ff40..f3b6e31b5925 100644 --- a/xmlhelp/source/treeview/tvread.hxx +++ b/xmlhelp/source/treeview/tvread.hxx @@ -42,6 +42,10 @@ namespace treeview { + + class TVChildTarget; + + class TVRead : public cppu::OWeakObject, public com::sun::star::lang::XTypeProvider, @@ -50,12 +54,14 @@ namespace treeview { public com::sun::star::util::XChangesNotifier, public com::sun::star::lang::XComponent { + friend class TVChildTarget; + public: - TVRead( const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& xMSF ); - TVRead( const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& xMSF, - const com::sun::star::uno::Sequence< com::sun::star::uno::Any >& aSeq ); + const rtl::OUString& aTitle, + const rtl::OUString& aTargetURL, + const rtl::Reference< TVChildTarget > aTargetRef = rtl::Reference< TVChildTarget >(0) ); ~TVRead(); @@ -169,12 +175,57 @@ namespace treeview { private: - rtl::OUString Title; - rtl::OUString TargetURL; - std::vector< rtl::Reference< TVRead > > Children; + rtl::OUString Title; + rtl::OUString TargetURL; + rtl::Reference< TVChildTarget > Children; + com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > m_xMSF; }; + + + class TVChildTarget + : public TVRead + { + 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(); + + virtual com::sun::star::uno::Any SAL_CALL + getByName( const rtl::OUString& aName ) + throw( com::sun::star::container::NoSuchElementException, + com::sun::star::lang::WrappedTargetException, + com::sun::star::uno::RuntimeException); + + virtual com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL + getElementNames( ) + throw( com::sun::star::uno::RuntimeException ); + + virtual sal_Bool SAL_CALL + hasByName( const rtl::OUString& aName ) + throw( com::sun::star::uno::RuntimeException ); + + + + // XHierarchicalNameAccess + + virtual com::sun::star::uno::Any SAL_CALL + getByHierarchicalName( const rtl::OUString& aName ) + throw( com::sun::star::container::NoSuchElementException, + com::sun::star::uno::RuntimeException ); + + virtual sal_Bool SAL_CALL + hasByHierarchicalName( const rtl::OUString& aName ) + throw( com::sun::star::uno::RuntimeException ); + + + private: + std::vector< rtl::Reference< TVRead > > Elements; + }; + }