1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "bufferedinputstream.hxx"
24 #include <osl/diagnose.hxx>
25 #include <osl/thread.h>
26 #include <osl/file.hxx>
27 #include <cppuhelper/weak.hxx>
28 #include <cppuhelper/queryinterface.hxx>
29 #include <comphelper/processfactory.hxx>
30 #include <rtl/uri.hxx>
31 #include <rtl/ustrbuf.hxx>
32 #include <libxslt/xslt.h>
33 #include <libxslt/transform.h>
34 #include <libxslt/xsltutils.h>
36 #include <com/sun/star/io/XActiveDataSink.hpp>
37 #include <com/sun/star/io/XInputStream.hpp>
38 #include <com/sun/star/io/XSeekable.hpp>
39 #include <com/sun/star/ucb/OpenCommandArgument2.hpp>
40 #include <com/sun/star/ucb/OpenMode.hpp>
41 #include <com/sun/star/ucb/XCommandProcessor.hpp>
42 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
43 #include <com/sun/star/ucb/XContentIdentifier.hpp>
44 #include <com/sun/star/ucb/XContentProvider.hpp>
45 #include <com/sun/star/ucb/XContentIdentifierFactory.hpp>
46 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
48 #include "urlparameter.hxx"
49 #include "databases.hxx"
53 inline bool ascii_isDigit( sal_Unicode ch
)
55 return ((ch
>= 0x0030) && (ch
<= 0x0039));
58 inline bool ascii_isLetter( sal_Unicode ch
)
60 return ( ( (ch
>= 0x0041) && (ch
<= 0x005A) ) ||
61 ( (ch
>= 0x0061) && (ch
<= 0x007A) ) );
64 inline bool isLetterOrDigit( sal_Unicode ch
)
66 return ascii_isLetter( ch
) || ascii_isDigit( ch
);
72 using namespace com::sun::star::io
;
73 using namespace com::sun::star::uno
;
74 using namespace com::sun::star::lang
;
75 using namespace com::sun::star::ucb
;
76 using namespace com::sun::star::beans
;
77 using namespace com::sun::star::container
;
78 using namespace chelp
;
81 URLParameter::URLParameter( const OUString
& aURL
,
82 Databases
* pDatabases
)
83 throw( com::sun::star::ucb::IllegalIdentifierException
)
84 : m_pDatabases( pDatabases
),
92 bool URLParameter::isErrorDocument()
94 bool bErrorDoc
= false;
98 Reference
< XHierarchicalNameAccess
> xNA
=
99 m_pDatabases
->findJarFileForPath( get_jar(), get_language(), get_path() );
100 bErrorDoc
= !xNA
.is();
107 OString
URLParameter::getByName( const char* par
)
111 if( strcmp( par
,"Program" ) == 0 )
113 else if( strcmp( par
,"Database" ) == 0 )
115 else if( strcmp( par
,"DatabasePar" ) == 0 )
117 else if( strcmp( par
,"Id" ) == 0 )
119 else if( strcmp( par
,"Path" ) == 0 )
121 else if( strcmp( par
,"Language" ) == 0 )
122 val
= get_language();
123 else if( strcmp( par
,"System" ) == 0 )
125 else if( strcmp( par
,"HelpPrefix" ) == 0 )
128 return OString( val
.getStr(),val
.getLength(),RTL_TEXTENCODING_UTF8
);
132 OUString
URLParameter::get_id()
134 if( m_aId
== "start" )
136 StaticModuleInformation
* inf
=
137 m_pDatabases
->getStaticInformationForModule( get_module(),
140 m_aId
= inf
->get_id();
148 OUString
URLParameter::get_tag()
151 return get_the_tag();
157 OUString
URLParameter::get_title()
160 return get_the_title();
161 else if( !m_aModule
.isEmpty() )
163 StaticModuleInformation
* inf
=
164 m_pDatabases
->getStaticInformationForModule( get_module(),
167 m_aTitle
= inf
->get_title();
169 else // This must be the root
176 OUString
URLParameter::get_language()
178 if( m_aLanguage
.isEmpty() )
179 return m_aDefaultLanguage
;
185 OUString
URLParameter::get_program()
187 if( m_aProgram
.isEmpty() )
189 StaticModuleInformation
* inf
=
190 m_pDatabases
->getStaticInformationForModule( get_module(),
193 m_aProgram
= inf
->get_program();
199 void URLParameter::init( bool bDefaultLanguageIsInitialized
)
201 (void)bDefaultLanguageIsInitialized
;
203 m_bHelpDataFileRead
= false;
206 m_nHitCount
= 100; // The default maximum hitcount
210 OUString
URLParameter::get_the_tag()
213 if( ! m_bHelpDataFileRead
)
216 m_bHelpDataFileRead
= true;
226 OUString
URLParameter::get_the_path()
229 if( ! m_bHelpDataFileRead
)
231 m_bHelpDataFileRead
= true;
241 OUString
URLParameter::get_the_title()
244 if( ! m_bHelpDataFileRead
)
246 m_bHelpDataFileRead
= true;
255 OUString
URLParameter::get_the_jar()
258 if( ! m_bHelpDataFileRead
)
260 m_bHelpDataFileRead
= true;
265 return get_module() + ".jar";
269 void URLParameter::readHelpDataFile()
271 if( get_id().isEmpty() )
274 OUString aModule
= get_module();
275 OUString aLanguage
= get_language();
277 DataBaseIterator
aDbIt( *m_pDatabases
, aModule
, aLanguage
, false );
278 bool bSuccess
= false;
280 const sal_Char
* pData
= NULL
;
282 helpdatafileproxy::HDFData aHDFData
;
283 OUString aExtensionPath
;
284 OUString aExtensionRegistryPath
;
287 helpdatafileproxy::Hdf
* pHdf
= aDbIt
.nextHdf( &aExtensionPath
, &aExtensionRegistryPath
);
291 OString
keyStr( m_aId
.getStr(),m_aId
.getLength(),RTL_TEXTENCODING_UTF8
);
292 bSuccess
= pHdf
->getValueForKey( keyStr
, aHDFData
);
295 pData
= aHDFData
.getData();
302 DbtToStringConverter
converter( pData
);
303 m_aTitle
= converter
.getTitle();
304 m_pDatabases
->replaceName( m_aTitle
);
305 m_aPath
= converter
.getFile();
306 m_aJar
= converter
.getDatabase();
307 if( !aExtensionPath
.isEmpty() )
309 m_aJar
= "?" + aExtensionPath
+ "?" + m_aJar
;
310 m_aExtensionRegistryPath
= aExtensionRegistryPath
;
312 m_aTag
= converter
.getHash();
318 // Class encapsulating the transformation of the XInputStream to XHTML
321 class InputStreamTransformer
322 : public OWeakObject
,
328 InputStreamTransformer( URLParameter
* urlParam
,
329 Databases
* pDatatabases
,
330 bool isRoot
= false );
332 virtual ~InputStreamTransformer();
334 virtual Any SAL_CALL
queryInterface( const Type
& rType
) throw( RuntimeException
, std::exception
) SAL_OVERRIDE
;
335 virtual void SAL_CALL
acquire() throw() SAL_OVERRIDE
;
336 virtual void SAL_CALL
release() throw() SAL_OVERRIDE
;
338 virtual sal_Int32 SAL_CALL
readBytes( Sequence
< sal_Int8
>& aData
,sal_Int32 nBytesToRead
)
339 throw( NotConnectedException
,
340 BufferSizeExceededException
,
342 RuntimeException
, std::exception
) SAL_OVERRIDE
;
344 virtual sal_Int32 SAL_CALL
readSomeBytes( Sequence
< sal_Int8
>& aData
,sal_Int32 nMaxBytesToRead
)
345 throw( NotConnectedException
,
346 BufferSizeExceededException
,
348 RuntimeException
, std::exception
) SAL_OVERRIDE
;
350 virtual void SAL_CALL
skipBytes( sal_Int32 nBytesToSkip
) throw( NotConnectedException
,
351 BufferSizeExceededException
,
353 RuntimeException
, std::exception
) SAL_OVERRIDE
;
355 virtual sal_Int32 SAL_CALL
available() throw( NotConnectedException
,
357 RuntimeException
, std::exception
) SAL_OVERRIDE
;
359 virtual void SAL_CALL
closeInput() throw( NotConnectedException
,
361 RuntimeException
, std::exception
) SAL_OVERRIDE
;
363 virtual void SAL_CALL
seek( sal_Int64 location
) throw( IllegalArgumentException
,
365 RuntimeException
, std::exception
) SAL_OVERRIDE
;
367 virtual sal_Int64 SAL_CALL
getPosition() throw( IOException
,RuntimeException
, std::exception
) SAL_OVERRIDE
;
369 virtual sal_Int64 SAL_CALL
getLength() throw( IOException
,RuntimeException
, std::exception
) SAL_OVERRIDE
;
371 void addToBuffer( const char* buffer
,int len
);
373 sal_Int8
const * getData() const { return reinterpret_cast<sal_Int8
const *>(buffer
); }
375 sal_Int32
getLen() const { return sal_Int32( len
); }
387 void URLParameter::open( const Command
& aCommand
,
389 const Reference
< XCommandEnvironment
>& Environment
,
390 const Reference
< XOutputStream
>& xDataSink
)
396 if( ! xDataSink
.is() )
401 Reference
< XInputStream
> xStream
;
402 Reference
< XHierarchicalNameAccess
> xNA
=
403 m_pDatabases
->jarFile( OUString( "picture.jar" ),
406 OUString path
= get_path();
411 Any aEntry
= xNA
->getByHierarchicalName( path
);
412 Reference
< XActiveDataSink
> xSink
;
413 if( ( aEntry
>>= xSink
) && xSink
.is() )
414 xStream
= xSink
->getInputStream();
416 catch ( NoSuchElementException
& )
423 Sequence
< sal_Int8
> aSeq( 4096 );
428 ret
= xStream
->readBytes( aSeq
,4096 );
429 xDataSink
->writeBytes( aSeq
);
433 catch( const Exception
& )
442 // a standard document or else an active help text, plug in the new input stream
443 InputStreamTransformer
* p
= new InputStreamTransformer( this,m_pDatabases
,isRoot() );
446 xDataSink
->writeBytes( Sequence
< sal_Int8
>( p
->getData(),p
->getLen() ) );
448 catch( const Exception
& )
453 xDataSink
->closeOutput();
458 void URLParameter::open( const Command
& aCommand
,
460 const Reference
< XCommandEnvironment
>& Environment
,
461 const Reference
< XActiveDataSink
>& xDataSink
)
469 Reference
< XInputStream
> xStream
;
470 Reference
< XHierarchicalNameAccess
> xNA
=
471 m_pDatabases
->jarFile( OUString( "picture.jar" ),
474 OUString path
= get_path();
479 Any aEntry
= xNA
->getByHierarchicalName( path
);
480 Reference
< XActiveDataSink
> xSink
;
481 if( ( aEntry
>>= xSink
) && xSink
.is() )
482 xStream
= xSink
->getInputStream();
484 catch ( NoSuchElementException
& )
488 xDataSink
->setInputStream( turnToSeekable(xStream
) );
491 // a standard document or else an active help text, plug in the new input stream
492 xDataSink
->setInputStream( new InputStreamTransformer( this,m_pDatabases
,isRoot() ) );
496 void URLParameter::parse() throw( com::sun::star::ucb::IllegalIdentifierException
)
500 sal_Int32 lstIdx
= m_aExpr
.lastIndexOf( '#' );
502 m_aExpr
= m_aExpr
.copy( 0,lstIdx
);
505 ! name( module() ) ||
507 m_aLanguage
.isEmpty() ||
508 m_aSystem
.isEmpty() )
509 throw com::sun::star::ucb::IllegalIdentifierException();
513 bool URLParameter::scheme()
515 // Correct extension help links as sometimes the
516 // module is missing resulting in a malformed URL
517 if( m_aExpr
.startsWith("vnd.sun.star.help:///") )
519 sal_Int32 nLen
= m_aExpr
.getLength();
521 m_aExpr
.copy(sal::static_int_cast
<sal_uInt32
>(nLen
) - 6);
522 if( aLastStr
== "DbPAR=" )
524 OUString aNewExpr
= m_aExpr
.copy( 0, 20 );
525 OUString
aSharedStr("shared");
526 aNewExpr
+= aSharedStr
;
527 aNewExpr
+= m_aExpr
.copy( 20 );
528 aNewExpr
+= aSharedStr
;
533 for( sal_Int32 nPrefixLen
= 20 ; nPrefixLen
>= 18 ; --nPrefixLen
)
535 if( m_aExpr
.matchAsciiL( "vnd.sun.star.help://", nPrefixLen
) )
537 m_aExpr
= m_aExpr
.copy( nPrefixLen
);
545 bool URLParameter::module()
547 sal_Int32 idx
= 0,length
= m_aExpr
.getLength();
549 while( idx
< length
&& isLetterOrDigit( (m_aExpr
.getStr())[idx
] ) )
554 m_aModule
= m_aExpr
.copy( 0,idx
);
555 m_aExpr
= m_aExpr
.copy( idx
);
564 bool URLParameter::name( bool modulePresent
)
566 // if modulepresent, a name may be present, but must not
568 sal_Int32 length
= m_aExpr
.getLength();
570 if( length
!= 0 && (m_aExpr
.getStr())[0] == '/' )
573 while( idx
< length
&& (m_aExpr
.getStr())[idx
] != '?' )
576 if( idx
!= 1 && ! modulePresent
)
580 m_aId
= m_aExpr
.copy( 1,idx
-1 );
581 m_aExpr
= m_aExpr
.copy( idx
);
589 bool URLParameter::query()
593 if( m_aExpr
.isEmpty() )
595 else if( (m_aExpr
.getStr())[0] == '?' )
596 query_
= m_aExpr
.copy( 1 ).trim();
602 sal_Int32 delimIdx
,equalIdx
;
603 OUString parameter
,value
;
605 while( !query_
.isEmpty() )
607 delimIdx
= query_
.indexOf( '&' );
608 equalIdx
= query_
.indexOf( '=' );
609 parameter
= query_
.copy( 0,equalIdx
).trim();
612 value
= query_
.copy( equalIdx
+ 1 ).trim();
617 value
= query_
.copy( equalIdx
+1,delimIdx
- equalIdx
- 1 ).trim();
618 query_
= query_
.copy( delimIdx
+1 ).trim();
621 if( parameter
== "Language" )
623 else if( parameter
== "Device" )
625 else if( parameter
== "Program" )
627 else if( parameter
== "Eid" )
629 else if( parameter
== "UseDB" )
630 m_bUseDB
= value
!= "no";
631 else if( parameter
== "DbPAR" )
633 else if( parameter
== "Query" )
635 if( m_aQuery
.isEmpty() )
638 m_aQuery
+= " " + value
;
640 else if( parameter
== "Scope" )
642 else if( parameter
== "System" )
644 else if( parameter
== "HelpPrefix" )
645 m_aPrefix
= rtl::Uri::decode(
647 rtl_UriDecodeWithCharset
,
648 RTL_TEXTENCODING_UTF8
);
649 else if( parameter
== "HitCount" )
650 m_nHitCount
= value
.toInt32();
651 else if( parameter
== "Active" )
653 else if( parameter
== "Version" )
654 ; // ignored (but accepted) in the build-in help, useful only for the online help
664 UserData( InputStreamTransformer
* pTransformer
,
665 URLParameter
* pInitial
,
666 Databases
* pDatabases
)
667 : m_pTransformer( pTransformer
),
668 m_pDatabases( pDatabases
),
669 m_pInitial( pInitial
)
673 InputStreamTransformer
* m_pTransformer
;
674 Databases
* m_pDatabases
;
675 URLParameter
* m_pInitial
;
678 UserData
*ugblData
= 0;
683 fileMatch(const char * URI
) {
684 if ((URI
!= NULL
) && !strncmp(URI
, "file:/", 6))
690 zipMatch(const char * URI
) {
691 if ((URI
!= NULL
) && !strncmp(URI
, "vnd.sun.star.zip:/", 18))
697 helpMatch(const char * URI
) {
698 if ((URI
!= NULL
) && !strncmp(URI
, "vnd.sun.star.help:/", 19))
704 fileOpen(const char *URI
) {
705 osl::File
*pRet
= new osl::File(OUString(URI
, strlen(URI
), RTL_TEXTENCODING_UTF8
));
706 pRet
->open(osl_File_OpenFlag_Read
);
711 zipOpen(SAL_UNUSED_PARAMETER
const char *) {
712 OUString language
,jar
,path
;
714 if( !ugblData
->m_pInitial
->get_eid().isEmpty() )
715 return (void*)(new Reference
< XHierarchicalNameAccess
>);
718 jar
= ugblData
->m_pInitial
->get_jar();
719 language
= ugblData
->m_pInitial
->get_language();
720 path
= ugblData
->m_pInitial
->get_path();
723 Reference
< XHierarchicalNameAccess
> xNA
=
724 ugblData
->m_pDatabases
->findJarFileForPath( jar
, language
, path
);
726 Reference
< XInputStream
> xInputStream
;
732 Any aEntry
= xNA
->getByHierarchicalName( path
);
733 Reference
< XActiveDataSink
> xSink
;
734 if( ( aEntry
>>= xSink
) && xSink
.is() )
735 xInputStream
= xSink
->getInputStream();
737 catch ( NoSuchElementException
& )
742 if( xInputStream
.is() )
744 return new Reference
<XInputStream
>(xInputStream
);
750 helpOpen(const char * URI
) {
751 OUString language
,jar
,path
;
753 URLParameter
urlpar( OUString::createFromAscii( URI
),
754 ugblData
->m_pDatabases
);
756 jar
= urlpar
.get_jar();
757 language
= urlpar
.get_language();
758 path
= urlpar
.get_path();
760 Reference
< XHierarchicalNameAccess
> xNA
=
761 ugblData
->m_pDatabases
->findJarFileForPath( jar
, language
, path
);
763 Reference
< XInputStream
> xInputStream
;
769 Any aEntry
= xNA
->getByHierarchicalName( path
);
770 Reference
< XActiveDataSink
> xSink
;
771 if( ( aEntry
>>= xSink
) && xSink
.is() )
772 xInputStream
= xSink
->getInputStream();
774 catch ( NoSuchElementException
& )
779 if( xInputStream
.is() )
780 return new Reference
<XInputStream
>(xInputStream
);
785 helpRead(void * context
, char * buffer
, int len
) {
786 Reference
< XInputStream
> *pRef
= static_cast<Reference
< XInputStream
>*>(context
);
788 Sequence
< sal_Int8
> aSeq
;
789 len
= (*pRef
)->readBytes( aSeq
,len
);
790 memcpy(buffer
, aSeq
.getConstArray(), len
);
796 zipRead(void * context
, char * buffer
, int len
) {
797 return helpRead(context
, buffer
, len
);
801 fileRead(void * context
, char * buffer
, int len
) {
803 osl::File
*pFile
= static_cast<osl::File
*>(context
);
806 sal_uInt64 uRead
= 0;
807 if (osl::FileBase::E_None
== pFile
->read(buffer
, len
, uRead
))
808 nRead
= static_cast<int>(uRead
);
814 uriClose(void * context
) {
815 Reference
< XInputStream
> *pRef
= static_cast<Reference
< XInputStream
>*>(context
);
821 fileClose(void * context
) {
822 osl::File
*pFile
= static_cast<osl::File
*>(context
);
833 InputStreamTransformer::InputStreamTransformer( URLParameter
* urlParam
,
834 Databases
* pDatabases
,
838 buffer( new char[1] ) // Initializing with one element to avoid gcc compiler warning
843 pDatabases
->cascadingStylesheet( urlParam
->get_language(),
847 else if( urlParam
->isActive() )
850 pDatabases
->setActiveText( urlParam
->get_module(),
851 urlParam
->get_language(),
858 UserData
userData( this,urlParam
,pDatabases
);
860 // Uses the implementation detail, that OString::getStr returns a zero terminated character-array
862 const char* parameter
[47];
863 OString parString
[46];
866 parString
[last
++] = "Program";
867 OString
aPureProgramm( urlParam
->getByName( "Program" ) );
868 parString
[last
++] = OString('\'') + aPureProgramm
+ OString('\'');
869 parString
[last
++] = "Database";
870 parString
[last
++] = OString('\'') + urlParam
->getByName( "DatabasePar" ) + OString('\'');
871 parString
[last
++] = "Id";
872 parString
[last
++] = OString('\'') + urlParam
->getByName( "Id" ) + OString('\'');
873 parString
[last
++] = "Path";
874 OString
aPath( urlParam
->getByName( "Path" ) );
875 parString
[last
++] = OString('\'') + aPath
+ OString('\'');
877 OString aPureLanguage
= urlParam
->getByName( "Language" );
878 parString
[last
++] = "Language";
879 parString
[last
++] = OString('\'') + aPureLanguage
+ OString('\'');
880 parString
[last
++] = "System";
881 parString
[last
++] = OString('\'') + urlParam
->getByName( "System" ) + OString('\'');
882 parString
[last
++] = "productname";
883 parString
[last
++] = OString('\'') + OString(
884 pDatabases
->getProductName().getStr(),
885 pDatabases
->getProductName().getLength(),
886 RTL_TEXTENCODING_UTF8
) + OString('\'');
887 parString
[last
++] = "productversion";
888 parString
[last
++] = OString('\'') +
889 OString( pDatabases
->getProductVersion().getStr(),
890 pDatabases
->getProductVersion().getLength(),
891 RTL_TEXTENCODING_UTF8
) + OString('\'');
893 parString
[last
++] = "imgtheme";
894 parString
[last
++] = OString('\'') + pDatabases
->getImageTheme() + OString('\'');
895 parString
[last
++] = "hp";
896 parString
[last
++] = OString('\'') + urlParam
->getByName( "HelpPrefix" ) + OString('\'');
898 if( !parString
[last
-1].isEmpty() )
900 parString
[last
++] = "sm";
901 parString
[last
++] = "'vnd.sun.star.help%3A%2F%2F'";
902 parString
[last
++] = "qm";
903 parString
[last
++] = "'%3F'";
904 parString
[last
++] = "es";
905 parString
[last
++] = "'%3D'";
906 parString
[last
++] = "am";
907 parString
[last
++] = "'%26'";
908 parString
[last
++] = "cl";
909 parString
[last
++] = "'%3A'";
910 parString
[last
++] = "sl";
911 parString
[last
++] = "'%2F'";
912 parString
[last
++] = "hm";
913 parString
[last
++] = "'%23'";
914 parString
[last
++] = "cs";
915 parString
[last
++] = "'css'";
917 parString
[last
++] = "vendorname";
918 parString
[last
++] = OString("''");
919 parString
[last
++] = "vendorversion";
920 parString
[last
++] = OString("''");
921 parString
[last
++] = "vendorshort";
922 parString
[last
++] = OString("''");
925 // Do we need to add extension path?
926 OUString aExtensionPath
;
927 OUString aJar
= urlParam
->get_jar();
929 bool bAddExtensionPath
= false;
930 OUString aExtensionRegistryPath
;
931 sal_Int32 nQuestionMark1
= aJar
.indexOf( '?' );
932 sal_Int32 nQuestionMark2
= aJar
.lastIndexOf( '?' );
933 if( nQuestionMark1
!= -1 && nQuestionMark2
!= -1 && nQuestionMark1
!= nQuestionMark2
)
935 aExtensionPath
= aJar
.copy( nQuestionMark1
+ 1, nQuestionMark2
- nQuestionMark1
- 1 );
936 aExtensionRegistryPath
= urlParam
->get_ExtensionRegistryPath();
937 bAddExtensionPath
= true;
941 // Path not yet specified, search directly
942 Reference
< XHierarchicalNameAccess
> xNA
= pDatabases
->findJarFileForPath
943 ( aJar
, urlParam
->get_language(), urlParam
->get_path(), &aExtensionPath
, &aExtensionRegistryPath
);
944 if( xNA
.is() && !aExtensionPath
.isEmpty() )
945 bAddExtensionPath
= true;
948 if( bAddExtensionPath
)
950 Reference
< XComponentContext
> xContext(
951 comphelper::getProcessComponentContext() );
953 OUString aOUExpandedExtensionPath
= Databases::expandURL( aExtensionRegistryPath
, xContext
);
954 OString aExpandedExtensionPath
= OUStringToOString( aOUExpandedExtensionPath
, osl_getThreadTextEncoding() );
956 parString
[last
++] = "ExtensionPath";
957 parString
[last
++] = OString('\'') + aExpandedExtensionPath
+ OString('\'');
960 OString aPureExtensionId
;
961 sal_Int32 iSlash
= aPath
.indexOf( '/' );
963 aPureExtensionId
= aPath
.copy( 0, iSlash
);
965 parString
[last
++] = "ExtensionId";
966 parString
[last
++] = OString('\'') + aPureExtensionId
+ OString('\'');
969 for( int i
= 0; i
< last
; ++i
)
970 parameter
[i
] = parString
[i
].getStr();
973 OUString xslURL
= pDatabases
->getInstallPathAsURL();
978 RTL_TEXTENCODING_UTF8
);
979 xslURLascii
+= "main_transform.xsl";
981 ugblData
= &userData
;
984 xmlRegisterInputCallbacks(zipMatch
, zipOpen
, zipRead
, uriClose
);
985 xmlRegisterInputCallbacks(helpMatch
, helpOpen
, helpRead
, uriClose
);
986 xmlRegisterInputCallbacks(fileMatch
, fileOpen
, fileRead
, fileClose
);
988 xsltStylesheetPtr cur
=
989 xsltParseStylesheetFile(reinterpret_cast<const xmlChar
*>(xslURLascii
.getStr()));
991 xmlDocPtr doc
= xmlParseFile("vnd.sun.star.zip:/");
993 xmlDocPtr res
= xsltApplyStylesheet(cur
, doc
, parameter
);
996 xmlChar
*doc_txt_ptr
=0;
998 xsltSaveResultToString(&doc_txt_ptr
, &doc_txt_len
, res
, cur
);
999 addToBuffer(reinterpret_cast<char*>(doc_txt_ptr
), doc_txt_len
);
1000 xmlFree(doc_txt_ptr
);
1002 xmlPopInputCallbacks(); //filePatch
1003 xmlPopInputCallbacks(); //helpPatch
1004 xmlPopInputCallbacks(); //zipMatch
1007 xsltFreeStylesheet(cur
);
1012 InputStreamTransformer::~InputStreamTransformer()
1018 Any SAL_CALL
InputStreamTransformer::queryInterface( const Type
& rType
) throw( RuntimeException
, std::exception
)
1020 Any aRet
= ::cppu::queryInterface( rType
,
1021 (static_cast< XInputStream
* >(this)),
1022 (static_cast< XSeekable
* >(this)) );
1024 return aRet
.hasValue() ? aRet
: OWeakObject::queryInterface( rType
);
1029 void SAL_CALL
InputStreamTransformer::acquire() throw()
1031 OWeakObject::acquire();
1036 void SAL_CALL
InputStreamTransformer::release() throw()
1038 OWeakObject::release();
1043 sal_Int32 SAL_CALL
InputStreamTransformer::readBytes( Sequence
< sal_Int8
>& aData
,sal_Int32 nBytesToRead
)
1044 throw( NotConnectedException
,
1045 BufferSizeExceededException
,
1047 RuntimeException
, std::exception
)
1049 osl::MutexGuard
aGuard( m_aMutex
);
1051 int curr
,available_
= len
-pos
;
1052 if( nBytesToRead
<= available_
)
1053 curr
= nBytesToRead
;
1057 if( 0 <= curr
&& aData
.getLength() < curr
)
1058 aData
.realloc( curr
);
1060 for( int k
= 0; k
< curr
; ++k
)
1061 aData
[k
] = buffer
[pos
++];
1063 return curr
> 0 ? curr
: 0;
1067 sal_Int32 SAL_CALL
InputStreamTransformer::readSomeBytes( Sequence
< sal_Int8
>& aData
,sal_Int32 nMaxBytesToRead
)
1068 throw( NotConnectedException
,
1069 BufferSizeExceededException
,
1071 RuntimeException
, std::exception
)
1073 return readBytes( aData
,nMaxBytesToRead
);
1078 void SAL_CALL
InputStreamTransformer::skipBytes( sal_Int32 nBytesToSkip
) throw( NotConnectedException
,
1079 BufferSizeExceededException
,
1081 RuntimeException
, std::exception
)
1083 osl::MutexGuard
aGuard( m_aMutex
);
1084 while( nBytesToSkip
-- ) ++pos
;
1089 sal_Int32 SAL_CALL
InputStreamTransformer::available() throw( NotConnectedException
,
1091 RuntimeException
, std::exception
)
1093 osl::MutexGuard
aGuard( m_aMutex
);
1094 return len
-pos
> 0 ? len
- pos
: 0 ;
1099 void SAL_CALL
InputStreamTransformer::closeInput() throw( NotConnectedException
,
1101 RuntimeException
, std::exception
)
1107 void SAL_CALL
InputStreamTransformer::seek( sal_Int64 location
) throw( IllegalArgumentException
,
1109 RuntimeException
, std::exception
)
1111 osl::MutexGuard
aGuard( m_aMutex
);
1113 throw IllegalArgumentException();
1115 pos
= sal::static_int_cast
<sal_Int32
>( location
);
1123 sal_Int64 SAL_CALL
InputStreamTransformer::getPosition() throw( IOException
,
1124 RuntimeException
, std::exception
)
1126 osl::MutexGuard
aGuard( m_aMutex
);
1127 return sal_Int64( pos
);
1132 sal_Int64 SAL_CALL
InputStreamTransformer::getLength() throw( IOException
,RuntimeException
, std::exception
)
1134 osl::MutexGuard
aGuard( m_aMutex
);
1140 void InputStreamTransformer::addToBuffer( const char* buffer_
,int len_
)
1142 osl::MutexGuard
aGuard( m_aMutex
);
1145 buffer
= new char[ len
+len_
];
1146 memcpy( (void*)(buffer
),(void*)(tmp
),sal_uInt32( len
) );
1147 memcpy( (void*)(buffer
+len
),(void*)(buffer_
),sal_uInt32( len_
) );
1152 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */