diff options
author | Andreas Bille <abi@openoffice.org> | 2001-06-13 09:12:40 +0000 |
---|---|---|
committer | Andreas Bille <abi@openoffice.org> | 2001-06-13 09:12:40 +0000 |
commit | e4fd76b99f7c0563768a26684f63f6d29d063920 (patch) | |
tree | 5b41f7a8a7f106d22ae04a0530b077cb014e7eaf /xmlhelp | |
parent | 6a11c04366d6cd809dad783d652db97934ba3712 (diff) |
#87493#
custom css buffered. optimization
Diffstat (limited to 'xmlhelp')
-rw-r--r-- | xmlhelp/source/cxxhelp/provider/databases.cxx | 91 | ||||
-rw-r--r-- | xmlhelp/source/cxxhelp/provider/urlparameter.cxx | 101 |
2 files changed, 120 insertions, 72 deletions
diff --git a/xmlhelp/source/cxxhelp/provider/databases.cxx b/xmlhelp/source/cxxhelp/provider/databases.cxx index bcc143c4d005..c2ae09a6efbf 100644 --- a/xmlhelp/source/cxxhelp/provider/databases.cxx +++ b/xmlhelp/source/cxxhelp/provider/databases.cxx @@ -2,9 +2,9 @@ * * $RCSfile: databases.cxx,v $ * - * $Revision: 1.8 $ + * $Revision: 1.9 $ * - * last change: $Author: abi $ $Date: 2001-06-13 09:10:13 $ + * last change: $Author: abi $ $Date: 2001-06-13 10:12:40 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -81,29 +81,15 @@ using namespace com::sun::star::uno; using namespace com::sun::star::io; using namespace com::sun::star::container; -// 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 -// rtl::OUString Databases::m_aInstallDirectoryAsSystemPath; // Installation directory -// rtl::OUString Databases::m_aInstallDirectoryAsURL; // 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 -// Databases::KeywordInfoTable Databases::m_aKeywordInfo; -// Databases::JarFileTable Databases::m_aJarFileTable; // open jar files Databases::Databases( const rtl::OUString& instPath, com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > xSMgr ) : m_xSMgr( xSMgr ), m_nErrorDocLength( 0 ), - m_pErrorDoc( 0 ) + m_pErrorDoc( 0 ), + m_nCustomCSSDocLength( 0 ), + m_pCustomCSSDoc( 0 ) { setInstallPath( instPath ); } @@ -111,6 +97,10 @@ Databases::Databases( const rtl::OUString& instPath, Databases::~Databases() { + // release stylesheet + + delete[] m_pCustomCSSDoc; + // release errorDocument delete[] m_pErrorDoc; @@ -642,15 +632,12 @@ void Databases::errorDocument( const rtl::OUString& Language, char** buffer, int* byteCount ) { - m_nErrorDocLength; - if( ! m_pErrorDoc ) { rtl::OUString fileURL = getInstallPathAsURL() + lang( Language ) - + rtl::OUString::createFromAscii( "/" ) - + rtl::OUString::createFromAscii( "err.html" ); + + rtl::OUString::createFromAscii( "/err.html" ); osl::DirectoryItem aDirItem; osl::File aFile( fileURL ); @@ -685,6 +672,64 @@ void Databases::errorDocument( const rtl::OUString& Language, +void Databases::cascadingStylesheet( const rtl::OUString& Language, + char** buffer, + int* byteCount ) +{ + if( ! m_pCustomCSSDoc ) + { + int retry = 2; + bool error = true; + rtl::OUString fileURL; + + while( error && retry ) + { + if( retry == 2 ) + fileURL = + getInstallPathAsURL() + + lang( Language ) + + rtl::OUString::createFromAscii( "/custom.css" ); + else if( retry == 1 ) + fileURL = + getInstallPathAsURL() + + rtl::OUString::createFromAscii( "custom.css" ); + + osl::DirectoryItem aDirItem; + osl::File aFile( fileURL ); + osl::FileStatus aStatus( FileStatusMask_FileSize ); + + if( osl::FileBase::E_None == osl::DirectoryItem::get( fileURL,aDirItem ) && + osl::FileBase::E_None == aFile.open( OpenFlag_Read ) && + osl::FileBase::E_None == aDirItem.getFileStatus( aStatus ) ) + { + m_nCustomCSSDocLength = int( aStatus.getFileSize() ); + m_pCustomCSSDoc = new char[ 1 + m_nCustomCSSDocLength ]; + m_pCustomCSSDoc[ m_nCustomCSSDocLength ] = 0; + sal_uInt64 a = m_nCustomCSSDocLength,b = m_nCustomCSSDocLength; + aFile.read( m_pCustomCSSDoc,a,b ); + aFile.close(); + error = false; + } + + --retry; + } + + if( error ) + { + m_nCustomCSSDocLength = 0; + m_pCustomCSSDoc = new char[ 0 ]; + } + } + + *byteCount = m_nCustomCSSDocLength; + *buffer = new char[ 1 + *byteCount ]; + (*buffer)[*byteCount] = 0; + rtl_copyMemory( *buffer,m_pCustomCSSDoc,m_nCustomCSSDocLength ); + +} + + + void Databases::setActiveText( const rtl::OUString& Module, const rtl::OUString& Language, const rtl::OUString& Id, diff --git a/xmlhelp/source/cxxhelp/provider/urlparameter.cxx b/xmlhelp/source/cxxhelp/provider/urlparameter.cxx index 102c8cbaaed2..34a830c64473 100644 --- a/xmlhelp/source/cxxhelp/provider/urlparameter.cxx +++ b/xmlhelp/source/cxxhelp/provider/urlparameter.cxx @@ -2,9 +2,9 @@ * * $RCSfile: urlparameter.cxx,v $ * - * $Revision: 1.13 $ + * $Revision: 1.14 $ * - * last change: $Author: abi $ $Date: 2001-06-13 09:10:13 $ + * last change: $Author: abi $ $Date: 2001-06-13 10:12:40 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -357,7 +357,8 @@ class InputStreamTransformer public: InputStreamTransformer( URLParameter* urlParam, - Databases* pDatatabases ); + Databases* pDatatabases, + bool isRoot = false ); ~InputStreamTransformer(); @@ -419,59 +420,32 @@ void URLParameter::open( const Reference< XMultiServiceFactory >& rxSMgr, const Reference< XCommandEnvironment >& Environment, const Reference< XActiveDataSink >& xDataSink ) { - bool IsRoot; - - if( ( IsRoot = isRoot() ) || isPicture() ) + if( isPicture() ) { - rtl::OUString url; + Reference< XInputStream > xStream; + Reference< XHierarchicalNameAccess > xNA = + m_pDatabases->jarFile( rtl::OUString::createFromAscii( "picture.jar" ), + get_language() ); - if( IsRoot ) + rtl::OUString path = get_path(); + if( xNA.is() ) { - // error handling is missing - // better not to open the file every time it is requested - - url = - m_pDatabases->getInstallPathAsURL() + - rtl::OUString::createFromAscii( "custom.css" ); - - rtl::OUString service = rtl::OUString::createFromAscii( "com.sun.star.ucb.UniversalContentBroker" ); - Reference< XContentProvider > provider( rxSMgr->createInstance( service ),UNO_QUERY ); - Reference< XContentIdentifierFactory > factory( provider,UNO_QUERY ); - Reference< XContentIdentifier > xIdentifier = factory->createContentIdentifier( url ); - Reference< XContent > xContent = provider->queryContent( xIdentifier ); - Reference< XCommandProcessor > processor( xContent,UNO_QUERY ); - - processor->execute( aCommand, - CommandId, - Environment ); - } - else - { // a picture - Reference< XInputStream > xStream; - Reference< XHierarchicalNameAccess > xNA = - m_pDatabases->jarFile( rtl::OUString::createFromAscii( "picture.jar" ), - get_language() ); - - rtl::OUString path = get_path(); - if( xNA.is() ) + try + { + Any aEntry = xNA->getByHierarchicalName( path ); + Reference< XActiveDataSink > xSink; + if( ( aEntry >>= xSink ) && xSink.is() ) + xStream = xSink->getInputStream(); + } + catch ( NoSuchElementException & ) { - try - { - Any aEntry = xNA->getByHierarchicalName( path ); - Reference< XActiveDataSink > xSink; - if( ( aEntry >>= xSink ) && xSink.is() ) - xStream = xSink->getInputStream(); - } - catch ( NoSuchElementException & ) - { - } } - xDataSink->setInputStream( xStream ); } + xDataSink->setInputStream( xStream ); } else // a standard document or else an active help text, plug in the new input stream - xDataSink->setInputStream( new InputStreamTransformer( this,m_pDatabases ) ); + xDataSink->setInputStream( new InputStreamTransformer( this,m_pDatabases,isRoot() ) ); } @@ -682,12 +656,20 @@ struct UserData { InputStreamTransformer::InputStreamTransformer( URLParameter* urlParam, - Databases* pDatabases ) + Databases* pDatabases, + bool isRoot ) : len( 0 ), pos( 0 ), buffer( new char[0] ) { - if( urlParam->isActive() ) + if( isRoot ) + { + delete[] buffer; + pDatabases->cascadingStylesheet( urlParam->get_language(), + &buffer, + &len ); + } + else if( urlParam->isActive() ) { delete[] buffer; pDatabases->setActiveText( urlParam->get_module(), @@ -1099,3 +1081,24 @@ int schemehandlerclose( void *userData, // Reference< XInputStream > m_xInputStream; // }; + + + + + // error handling is missing + // better not to open the file every time it is requested + +// url = +// m_pDatabases->getInstallPathAsURL() + +// rtl::OUString::createFromAscii( "custom.css" ); + +// rtl::OUString service = rtl::OUString::createFromAscii( "com.sun.star.ucb.UniversalContentBroker" ); +// Reference< XContentProvider > provider( rxSMgr->createInstance( service ),UNO_QUERY ); +// Reference< XContentIdentifierFactory > factory( provider,UNO_QUERY ); +// Reference< XContentIdentifier > xIdentifier = factory->createContentIdentifier( url ); +// Reference< XContent > xContent = provider->queryContent( xIdentifier ); +// Reference< XCommandProcessor > processor( xContent,UNO_QUERY ); + +// processor->execute( aCommand, +// CommandId, +// Environment ); |