xref: /AOO41X/main/xmlhelp/source/cxxhelp/provider/urlparameter.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_xmlhelp.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #define WORKAROUND_98119
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #ifdef WORKAROUND_98119
34*cdf0e10cSrcweir #include "bufferedinputstream.hxx"
35*cdf0e10cSrcweir #endif
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir #include <string.h>
38*cdf0e10cSrcweir #ifndef _VOS_DIAGNOSE_HXX_
39*cdf0e10cSrcweir #include <vos/diagnose.hxx>
40*cdf0e10cSrcweir #endif
41*cdf0e10cSrcweir #include <osl/thread.h>
42*cdf0e10cSrcweir #include <rtl/memory.h>
43*cdf0e10cSrcweir #include <osl/file.hxx>
44*cdf0e10cSrcweir #include <cppuhelper/weak.hxx>
45*cdf0e10cSrcweir #include <cppuhelper/queryinterface.hxx>
46*cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
47*cdf0e10cSrcweir #include <rtl/uri.hxx>
48*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
49*cdf0e10cSrcweir #include <libxslt/xslt.h>
50*cdf0e10cSrcweir #include <libxslt/transform.h>
51*cdf0e10cSrcweir #include <libxslt/xsltutils.h>
52*cdf0e10cSrcweir #include "db.hxx"
53*cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataSink.hpp>
54*cdf0e10cSrcweir #include <com/sun/star/io/XInputStream.hpp>
55*cdf0e10cSrcweir #include <com/sun/star/io/XSeekable.hpp>
56*cdf0e10cSrcweir #include <com/sun/star/ucb/OpenCommandArgument2.hpp>
57*cdf0e10cSrcweir #include <com/sun/star/ucb/OpenMode.hpp>
58*cdf0e10cSrcweir #include <com/sun/star/ucb/XCommandProcessor.hpp>
59*cdf0e10cSrcweir #include <com/sun/star/ucb/XCommandEnvironment.hpp>
60*cdf0e10cSrcweir #include <com/sun/star/ucb/XContentIdentifier.hpp>
61*cdf0e10cSrcweir #include <com/sun/star/ucb/XContentProvider.hpp>
62*cdf0e10cSrcweir #include <com/sun/star/ucb/XContentIdentifierFactory.hpp>
63*cdf0e10cSrcweir #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
64*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir #include "urlparameter.hxx"
67*cdf0e10cSrcweir #include "databases.hxx"
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir namespace chelp {
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir 	inline bool ascii_isDigit( sal_Unicode ch )
72*cdf0e10cSrcweir 	{
73*cdf0e10cSrcweir 		return ((ch >= 0x0030) && (ch <= 0x0039));
74*cdf0e10cSrcweir 	}
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir 	inline bool ascii_isLetter( sal_Unicode ch )
77*cdf0e10cSrcweir 	{
78*cdf0e10cSrcweir 		return ( ( (ch >= 0x0041) && (ch <= 0x005A) ) ||
79*cdf0e10cSrcweir 				 ( (ch >= 0x0061) && (ch <= 0x007A) ) );
80*cdf0e10cSrcweir 	}
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir 	inline bool isLetterOrDigit( sal_Unicode ch )
83*cdf0e10cSrcweir 	{
84*cdf0e10cSrcweir 		return ascii_isLetter( ch ) || ascii_isDigit( ch );
85*cdf0e10cSrcweir 	}
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir }
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir using namespace cppu;
90*cdf0e10cSrcweir using namespace com::sun::star::io;
91*cdf0e10cSrcweir using namespace com::sun::star::uno;
92*cdf0e10cSrcweir using namespace com::sun::star::lang;
93*cdf0e10cSrcweir using namespace com::sun::star::ucb;
94*cdf0e10cSrcweir using namespace com::sun::star::beans;
95*cdf0e10cSrcweir using namespace com::sun::star::container;
96*cdf0e10cSrcweir using namespace berkeleydbproxy;
97*cdf0e10cSrcweir using namespace chelp;
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir URLParameter::URLParameter( const rtl::OUString& aURL,
101*cdf0e10cSrcweir 							Databases* pDatabases )
102*cdf0e10cSrcweir 	throw( com::sun::star::ucb::IllegalIdentifierException )
103*cdf0e10cSrcweir 	: m_pDatabases( pDatabases ),
104*cdf0e10cSrcweir       m_aURL( aURL )
105*cdf0e10cSrcweir {
106*cdf0e10cSrcweir 	init( false );
107*cdf0e10cSrcweir 	parse();
108*cdf0e10cSrcweir }
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir bool URLParameter::isErrorDocument()
112*cdf0e10cSrcweir {
113*cdf0e10cSrcweir 	bool bErrorDoc = false;
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir 	if( isFile() )
116*cdf0e10cSrcweir 	{
117*cdf0e10cSrcweir 		Reference< XHierarchicalNameAccess > xNA =
118*cdf0e10cSrcweir 			m_pDatabases->findJarFileForPath( get_jar(), get_language(), get_path() );
119*cdf0e10cSrcweir 		bErrorDoc = !xNA.is();
120*cdf0e10cSrcweir 	}
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir 	return bErrorDoc;
123*cdf0e10cSrcweir }
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir rtl::OString URLParameter::getByName( const char* par )
127*cdf0e10cSrcweir {
128*cdf0e10cSrcweir 	rtl::OUString val;
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir 	if( strcmp( par,"Program" ) == 0 )
131*cdf0e10cSrcweir 		val = get_program();
132*cdf0e10cSrcweir 	else if( strcmp( par,"Database" ) == 0 )
133*cdf0e10cSrcweir 		val = get_module();
134*cdf0e10cSrcweir 	else if( strcmp( par,"DatabasePar" ) == 0 )
135*cdf0e10cSrcweir 		val = get_dbpar();
136*cdf0e10cSrcweir 	else if( strcmp( par,"Id" ) == 0 )
137*cdf0e10cSrcweir 		val = get_id();
138*cdf0e10cSrcweir 	else if( strcmp( par,"Path" ) == 0 )
139*cdf0e10cSrcweir 		val = get_path();
140*cdf0e10cSrcweir 	else if( strcmp( par,"Language" ) == 0 )
141*cdf0e10cSrcweir 		val = get_language();
142*cdf0e10cSrcweir 	else if( strcmp( par,"System" ) == 0 )
143*cdf0e10cSrcweir 		val = get_system();
144*cdf0e10cSrcweir 	else if( strcmp( par,"HelpPrefix" ) == 0 )
145*cdf0e10cSrcweir 		val = get_prefix();
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir 	return rtl::OString( val.getStr(),val.getLength(),RTL_TEXTENCODING_UTF8 );
148*cdf0e10cSrcweir }
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir rtl::OUString URLParameter::get_id()
152*cdf0e10cSrcweir {
153*cdf0e10cSrcweir 	if( m_aId.compareToAscii("start") == 0 )
154*cdf0e10cSrcweir 	{   // module is set
155*cdf0e10cSrcweir 		StaticModuleInformation* inf =
156*cdf0e10cSrcweir 			m_pDatabases->getStaticInformationForModule( get_module(),
157*cdf0e10cSrcweir 														 get_language() );
158*cdf0e10cSrcweir 		if( inf )
159*cdf0e10cSrcweir 			m_aId = inf->get_id();
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir 		m_bStart = true;
162*cdf0e10cSrcweir 	}
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir 	return m_aId;
165*cdf0e10cSrcweir }
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir rtl::OUString URLParameter::get_tag()
168*cdf0e10cSrcweir {
169*cdf0e10cSrcweir 	if( isFile() )
170*cdf0e10cSrcweir 		return get_the_tag();
171*cdf0e10cSrcweir 	else
172*cdf0e10cSrcweir 		return m_aTag;
173*cdf0e10cSrcweir }
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir rtl::OUString URLParameter::get_title()
177*cdf0e10cSrcweir {
178*cdf0e10cSrcweir 	if( isFile() )
179*cdf0e10cSrcweir 		return get_the_title();
180*cdf0e10cSrcweir 	else if( m_aModule.compareToAscii("") != 0 )
181*cdf0e10cSrcweir 	{
182*cdf0e10cSrcweir 		StaticModuleInformation* inf =
183*cdf0e10cSrcweir 			m_pDatabases->getStaticInformationForModule( get_module(),
184*cdf0e10cSrcweir 														 get_language() );
185*cdf0e10cSrcweir 		if( inf )
186*cdf0e10cSrcweir 			m_aTitle = inf->get_title();
187*cdf0e10cSrcweir 	}
188*cdf0e10cSrcweir 	else   // This must be the root
189*cdf0e10cSrcweir 		m_aTitle = rtl::OUString::createFromAscii("root");
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir 	return m_aTitle;
192*cdf0e10cSrcweir }
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir rtl::OUString URLParameter::get_language()
196*cdf0e10cSrcweir {
197*cdf0e10cSrcweir 	if( m_aLanguage.getLength() == 0 )
198*cdf0e10cSrcweir 		return m_aDefaultLanguage;
199*cdf0e10cSrcweir 
200*cdf0e10cSrcweir 	return m_aLanguage;
201*cdf0e10cSrcweir }
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir rtl::OUString URLParameter::get_program()
205*cdf0e10cSrcweir {
206*cdf0e10cSrcweir 	if( ! m_aProgram.getLength() )
207*cdf0e10cSrcweir 	{
208*cdf0e10cSrcweir 		StaticModuleInformation* inf =
209*cdf0e10cSrcweir 			m_pDatabases->getStaticInformationForModule( get_module(),
210*cdf0e10cSrcweir 														 get_language() );
211*cdf0e10cSrcweir 		if( inf )
212*cdf0e10cSrcweir 			m_aProgram = inf->get_program();
213*cdf0e10cSrcweir 	}
214*cdf0e10cSrcweir 	return m_aProgram;
215*cdf0e10cSrcweir }
216*cdf0e10cSrcweir 
217*cdf0e10cSrcweir 
218*cdf0e10cSrcweir void URLParameter::init( bool bDefaultLanguageIsInitialized )
219*cdf0e10cSrcweir {
220*cdf0e10cSrcweir 	(void)bDefaultLanguageIsInitialized;
221*cdf0e10cSrcweir 
222*cdf0e10cSrcweir 	m_bBerkeleyRead = false;
223*cdf0e10cSrcweir 	m_bStart = false;
224*cdf0e10cSrcweir     m_bUseDB = true;
225*cdf0e10cSrcweir 	m_nHitCount = 100;                // The default maximum hitcount
226*cdf0e10cSrcweir }
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir rtl::OUString URLParameter::get_the_tag()
230*cdf0e10cSrcweir {
231*cdf0e10cSrcweir     if(m_bUseDB) {
232*cdf0e10cSrcweir         if( ! m_bBerkeleyRead )
233*cdf0e10cSrcweir             readBerkeley();
234*cdf0e10cSrcweir 
235*cdf0e10cSrcweir         m_bBerkeleyRead = true;
236*cdf0e10cSrcweir 
237*cdf0e10cSrcweir         return m_aTag;
238*cdf0e10cSrcweir     }
239*cdf0e10cSrcweir     else
240*cdf0e10cSrcweir         return rtl::OUString();
241*cdf0e10cSrcweir }
242*cdf0e10cSrcweir 
243*cdf0e10cSrcweir 
244*cdf0e10cSrcweir 
245*cdf0e10cSrcweir rtl::OUString URLParameter::get_the_path()
246*cdf0e10cSrcweir {
247*cdf0e10cSrcweir     if(m_bUseDB) {
248*cdf0e10cSrcweir         if( ! m_bBerkeleyRead )
249*cdf0e10cSrcweir             readBerkeley();
250*cdf0e10cSrcweir         m_bBerkeleyRead = true;
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir         return m_aPath;
253*cdf0e10cSrcweir     }
254*cdf0e10cSrcweir     else
255*cdf0e10cSrcweir         return get_id();
256*cdf0e10cSrcweir }
257*cdf0e10cSrcweir 
258*cdf0e10cSrcweir 
259*cdf0e10cSrcweir 
260*cdf0e10cSrcweir rtl::OUString URLParameter::get_the_title()
261*cdf0e10cSrcweir {
262*cdf0e10cSrcweir     if(m_bUseDB) {
263*cdf0e10cSrcweir         if( ! m_bBerkeleyRead )
264*cdf0e10cSrcweir             readBerkeley();
265*cdf0e10cSrcweir         m_bBerkeleyRead = true;
266*cdf0e10cSrcweir 
267*cdf0e10cSrcweir         return m_aTitle;
268*cdf0e10cSrcweir     }
269*cdf0e10cSrcweir     else
270*cdf0e10cSrcweir         return rtl::OUString();
271*cdf0e10cSrcweir }
272*cdf0e10cSrcweir 
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir rtl::OUString URLParameter::get_the_jar()
275*cdf0e10cSrcweir {
276*cdf0e10cSrcweir     if(m_bUseDB) {
277*cdf0e10cSrcweir         if( ! m_bBerkeleyRead )
278*cdf0e10cSrcweir             readBerkeley();
279*cdf0e10cSrcweir         m_bBerkeleyRead = true;
280*cdf0e10cSrcweir 
281*cdf0e10cSrcweir         return m_aJar;
282*cdf0e10cSrcweir     }
283*cdf0e10cSrcweir     else
284*cdf0e10cSrcweir         return get_module() + rtl::OUString::createFromAscii(".jar");
285*cdf0e10cSrcweir }
286*cdf0e10cSrcweir 
287*cdf0e10cSrcweir 
288*cdf0e10cSrcweir 
289*cdf0e10cSrcweir 
290*cdf0e10cSrcweir void URLParameter::readBerkeley()
291*cdf0e10cSrcweir {
292*cdf0e10cSrcweir 	static rtl::OUString aQuestionMark( rtl::OUString::createFromAscii( "?" ) );
293*cdf0e10cSrcweir 
294*cdf0e10cSrcweir 	if( get_id().compareToAscii("") == 0 )
295*cdf0e10cSrcweir 		return;
296*cdf0e10cSrcweir 
297*cdf0e10cSrcweir 	rtl::OUString aModule = get_module();
298*cdf0e10cSrcweir 	rtl::OUString aLanguage = get_language();
299*cdf0e10cSrcweir 
300*cdf0e10cSrcweir 	DataBaseIterator aDbIt( *m_pDatabases, aModule, aLanguage, false );
301*cdf0e10cSrcweir 	bool bSuccess = false;
302*cdf0e10cSrcweir 
303*cdf0e10cSrcweir 	int nSize = 0;
304*cdf0e10cSrcweir 	const sal_Char* pData = NULL;
305*cdf0e10cSrcweir 
306*cdf0e10cSrcweir 	Dbt data;
307*cdf0e10cSrcweir 	DBData aDBData;
308*cdf0e10cSrcweir 	rtl::OUString aExtensionPath;
309*cdf0e10cSrcweir     rtl::OUString aExtensionRegistryPath;
310*cdf0e10cSrcweir 	while( true )
311*cdf0e10cSrcweir 	{
312*cdf0e10cSrcweir 		Db* db = aDbIt.nextDb( &aExtensionPath, &aExtensionRegistryPath );
313*cdf0e10cSrcweir 		if( !db )
314*cdf0e10cSrcweir 			break;
315*cdf0e10cSrcweir 
316*cdf0e10cSrcweir 		rtl::OString keyStr( m_aId.getStr(),m_aId.getLength(),RTL_TEXTENCODING_UTF8 );
317*cdf0e10cSrcweir 
318*cdf0e10cSrcweir 		DBHelp* pDBHelp = db->getDBHelp();
319*cdf0e10cSrcweir 		if( pDBHelp != NULL )
320*cdf0e10cSrcweir 		{
321*cdf0e10cSrcweir 			bSuccess = pDBHelp->getValueForKey( keyStr, aDBData );
322*cdf0e10cSrcweir 			if( bSuccess )
323*cdf0e10cSrcweir 			{
324*cdf0e10cSrcweir 				nSize = aDBData.getSize();
325*cdf0e10cSrcweir 				pData = aDBData.getData();
326*cdf0e10cSrcweir 				break;
327*cdf0e10cSrcweir 			}
328*cdf0e10cSrcweir 		}
329*cdf0e10cSrcweir 		else
330*cdf0e10cSrcweir 		{
331*cdf0e10cSrcweir 			Dbt key( static_cast< void* >( const_cast< sal_Char* >( keyStr.getStr() ) ),
332*cdf0e10cSrcweir 					 keyStr.getLength() );
333*cdf0e10cSrcweir 			int err = db->get( 0,&key,&data,0 );
334*cdf0e10cSrcweir 			if( err == 0 )
335*cdf0e10cSrcweir 			{
336*cdf0e10cSrcweir 				bSuccess = true;
337*cdf0e10cSrcweir 				nSize = data.get_size();
338*cdf0e10cSrcweir 				pData = static_cast<sal_Char*>( data.get_data() );
339*cdf0e10cSrcweir 				break;
340*cdf0e10cSrcweir 			}
341*cdf0e10cSrcweir 		}
342*cdf0e10cSrcweir 	}
343*cdf0e10cSrcweir 
344*cdf0e10cSrcweir 	if( bSuccess )
345*cdf0e10cSrcweir 	{
346*cdf0e10cSrcweir 		DbtToStringConverter converter( pData, nSize );
347*cdf0e10cSrcweir 		m_aTitle = converter.getTitle();
348*cdf0e10cSrcweir 		m_pDatabases->replaceName( m_aTitle );
349*cdf0e10cSrcweir 		m_aPath  = converter.getFile();
350*cdf0e10cSrcweir 		m_aJar   = converter.getDatabase();
351*cdf0e10cSrcweir 		if( aExtensionPath.getLength() > 0 )
352*cdf0e10cSrcweir 		{
353*cdf0e10cSrcweir 			rtl::OUStringBuffer aExtendedJarStrBuf;
354*cdf0e10cSrcweir 			aExtendedJarStrBuf.append( aQuestionMark );
355*cdf0e10cSrcweir 			aExtendedJarStrBuf.append( aExtensionPath );
356*cdf0e10cSrcweir 			aExtendedJarStrBuf.append( aQuestionMark );
357*cdf0e10cSrcweir 			aExtendedJarStrBuf.append( m_aJar );
358*cdf0e10cSrcweir 			m_aJar = aExtendedJarStrBuf.makeStringAndClear();
359*cdf0e10cSrcweir             m_aExtensionRegistryPath = aExtensionRegistryPath;
360*cdf0e10cSrcweir 		}
361*cdf0e10cSrcweir 		m_aTag   = converter.getHash();
362*cdf0e10cSrcweir 	}
363*cdf0e10cSrcweir }
364*cdf0e10cSrcweir 
365*cdf0e10cSrcweir 
366*cdf0e10cSrcweir 
367*cdf0e10cSrcweir // Class encapsulating the transformation of the XInputStream to XHTML
368*cdf0e10cSrcweir 
369*cdf0e10cSrcweir 
370*cdf0e10cSrcweir class InputStreamTransformer
371*cdf0e10cSrcweir 	: public OWeakObject,
372*cdf0e10cSrcweir 	  public XInputStream,
373*cdf0e10cSrcweir 	  public XSeekable
374*cdf0e10cSrcweir {
375*cdf0e10cSrcweir public:
376*cdf0e10cSrcweir 
377*cdf0e10cSrcweir 	InputStreamTransformer( URLParameter* urlParam,
378*cdf0e10cSrcweir 							Databases*    pDatatabases,
379*cdf0e10cSrcweir 							bool isRoot = false );
380*cdf0e10cSrcweir 
381*cdf0e10cSrcweir 	~InputStreamTransformer();
382*cdf0e10cSrcweir 
383*cdf0e10cSrcweir 	virtual Any SAL_CALL queryInterface( const Type& rType ) throw( RuntimeException );
384*cdf0e10cSrcweir 	virtual void SAL_CALL acquire( void ) throw();
385*cdf0e10cSrcweir 	virtual void SAL_CALL release( void ) throw();
386*cdf0e10cSrcweir 
387*cdf0e10cSrcweir 	virtual sal_Int32 SAL_CALL readBytes( Sequence< sal_Int8 >& aData,sal_Int32 nBytesToRead )
388*cdf0e10cSrcweir 		throw( NotConnectedException,
389*cdf0e10cSrcweir 			   BufferSizeExceededException,
390*cdf0e10cSrcweir 			   IOException,
391*cdf0e10cSrcweir 			   RuntimeException);
392*cdf0e10cSrcweir 
393*cdf0e10cSrcweir 	virtual sal_Int32 SAL_CALL readSomeBytes( Sequence< sal_Int8 >& aData,sal_Int32 nMaxBytesToRead )
394*cdf0e10cSrcweir 		throw( NotConnectedException,
395*cdf0e10cSrcweir 			   BufferSizeExceededException,
396*cdf0e10cSrcweir 			   IOException,
397*cdf0e10cSrcweir 			   RuntimeException);
398*cdf0e10cSrcweir 
399*cdf0e10cSrcweir 	virtual void SAL_CALL skipBytes( sal_Int32 nBytesToSkip ) throw( NotConnectedException,
400*cdf0e10cSrcweir 																	 BufferSizeExceededException,
401*cdf0e10cSrcweir 																	 IOException,
402*cdf0e10cSrcweir 																	 RuntimeException );
403*cdf0e10cSrcweir 
404*cdf0e10cSrcweir 	virtual sal_Int32 SAL_CALL available( void ) throw( NotConnectedException,
405*cdf0e10cSrcweir 														IOException,
406*cdf0e10cSrcweir 														RuntimeException );
407*cdf0e10cSrcweir 
408*cdf0e10cSrcweir 	virtual void SAL_CALL closeInput( void ) throw( NotConnectedException,
409*cdf0e10cSrcweir 													IOException,
410*cdf0e10cSrcweir 													RuntimeException );
411*cdf0e10cSrcweir 
412*cdf0e10cSrcweir 	virtual void SAL_CALL seek( sal_Int64 location ) throw( IllegalArgumentException,
413*cdf0e10cSrcweir 															IOException,
414*cdf0e10cSrcweir 															RuntimeException );
415*cdf0e10cSrcweir 
416*cdf0e10cSrcweir 	virtual sal_Int64 SAL_CALL getPosition( void ) throw( IOException,RuntimeException );
417*cdf0e10cSrcweir 
418*cdf0e10cSrcweir 	virtual sal_Int64 SAL_CALL getLength( void ) throw( IOException,RuntimeException );
419*cdf0e10cSrcweir 
420*cdf0e10cSrcweir 	void addToBuffer( const char* buffer,int len );
421*cdf0e10cSrcweir 
422*cdf0e10cSrcweir 	sal_Int8* getData() const { return (sal_Int8*) buffer; }
423*cdf0e10cSrcweir 
424*cdf0e10cSrcweir     sal_Int32 getLen() const { return sal_Int32( len ); }
425*cdf0e10cSrcweir 
426*cdf0e10cSrcweir private:
427*cdf0e10cSrcweir 
428*cdf0e10cSrcweir 	osl::Mutex m_aMutex;
429*cdf0e10cSrcweir 
430*cdf0e10cSrcweir 	int len,pos;
431*cdf0e10cSrcweir 	char *buffer;
432*cdf0e10cSrcweir };
433*cdf0e10cSrcweir 
434*cdf0e10cSrcweir 
435*cdf0e10cSrcweir 
436*cdf0e10cSrcweir void URLParameter::open( const Reference< XMultiServiceFactory >& rxSMgr,
437*cdf0e10cSrcweir 						 const Command& aCommand,
438*cdf0e10cSrcweir 						 sal_Int32 CommandId,
439*cdf0e10cSrcweir 						 const Reference< XCommandEnvironment >& Environment,
440*cdf0e10cSrcweir 						 const Reference< XOutputStream >& xDataSink )
441*cdf0e10cSrcweir {
442*cdf0e10cSrcweir 	(void)rxSMgr;
443*cdf0e10cSrcweir 	(void)aCommand;
444*cdf0e10cSrcweir 	(void)CommandId;
445*cdf0e10cSrcweir 	(void)Environment;
446*cdf0e10cSrcweir 
447*cdf0e10cSrcweir     if( ! xDataSink.is() )
448*cdf0e10cSrcweir         return;
449*cdf0e10cSrcweir 
450*cdf0e10cSrcweir 	if( isPicture() )
451*cdf0e10cSrcweir 	{
452*cdf0e10cSrcweir 		Reference< XInputStream > xStream;
453*cdf0e10cSrcweir 		Reference< XHierarchicalNameAccess > xNA =
454*cdf0e10cSrcweir 			m_pDatabases->jarFile( rtl::OUString::createFromAscii( "picture.jar" ),
455*cdf0e10cSrcweir 								   get_language() );
456*cdf0e10cSrcweir 
457*cdf0e10cSrcweir 		rtl::OUString path = get_path();
458*cdf0e10cSrcweir 		if( xNA.is() )
459*cdf0e10cSrcweir 		{
460*cdf0e10cSrcweir 			try
461*cdf0e10cSrcweir 			{
462*cdf0e10cSrcweir 				Any aEntry = xNA->getByHierarchicalName( path );
463*cdf0e10cSrcweir 				Reference< XActiveDataSink > xSink;
464*cdf0e10cSrcweir 				if( ( aEntry >>= xSink ) && xSink.is() )
465*cdf0e10cSrcweir 					xStream = xSink->getInputStream();
466*cdf0e10cSrcweir 			}
467*cdf0e10cSrcweir 			catch ( NoSuchElementException & )
468*cdf0e10cSrcweir 			{
469*cdf0e10cSrcweir 			}
470*cdf0e10cSrcweir 		}
471*cdf0e10cSrcweir         if( xStream.is() )
472*cdf0e10cSrcweir         {
473*cdf0e10cSrcweir             sal_Int32 ret;
474*cdf0e10cSrcweir             Sequence< sal_Int8 > aSeq( 4096 );
475*cdf0e10cSrcweir             while( true )
476*cdf0e10cSrcweir             {
477*cdf0e10cSrcweir                 try
478*cdf0e10cSrcweir                 {
479*cdf0e10cSrcweir                     ret = xStream->readBytes( aSeq,4096 );
480*cdf0e10cSrcweir                     xDataSink->writeBytes( aSeq );
481*cdf0e10cSrcweir                     if( ret < 4096 )
482*cdf0e10cSrcweir                         break;
483*cdf0e10cSrcweir                 }
484*cdf0e10cSrcweir                 catch( const Exception& )
485*cdf0e10cSrcweir                 {
486*cdf0e10cSrcweir                     break;
487*cdf0e10cSrcweir                 }
488*cdf0e10cSrcweir             }
489*cdf0e10cSrcweir         }
490*cdf0e10cSrcweir 	}
491*cdf0e10cSrcweir 	else
492*cdf0e10cSrcweir     {
493*cdf0e10cSrcweir 		// a standard document or else an active help text, plug in the new input stream
494*cdf0e10cSrcweir 		InputStreamTransformer* p = new InputStreamTransformer( this,m_pDatabases,isRoot() );
495*cdf0e10cSrcweir         try
496*cdf0e10cSrcweir         {
497*cdf0e10cSrcweir             xDataSink->writeBytes( Sequence< sal_Int8 >( p->getData(),p->getLen() ) );
498*cdf0e10cSrcweir         }
499*cdf0e10cSrcweir         catch( const Exception& )
500*cdf0e10cSrcweir         {
501*cdf0e10cSrcweir         }
502*cdf0e10cSrcweir         delete p;
503*cdf0e10cSrcweir     }
504*cdf0e10cSrcweir     xDataSink->closeOutput();
505*cdf0e10cSrcweir }
506*cdf0e10cSrcweir 
507*cdf0e10cSrcweir 
508*cdf0e10cSrcweir 
509*cdf0e10cSrcweir void URLParameter::open( const Reference< XMultiServiceFactory >& rxSMgr,
510*cdf0e10cSrcweir 						 const Command& aCommand,
511*cdf0e10cSrcweir 						 sal_Int32 CommandId,
512*cdf0e10cSrcweir 						 const Reference< XCommandEnvironment >& Environment,
513*cdf0e10cSrcweir 						 const Reference< XActiveDataSink >& xDataSink )
514*cdf0e10cSrcweir {
515*cdf0e10cSrcweir 	(void)rxSMgr;
516*cdf0e10cSrcweir 	(void)aCommand;
517*cdf0e10cSrcweir 	(void)CommandId;
518*cdf0e10cSrcweir 	(void)Environment;
519*cdf0e10cSrcweir 
520*cdf0e10cSrcweir 	if( isPicture() )
521*cdf0e10cSrcweir 	{
522*cdf0e10cSrcweir 		Reference< XInputStream > xStream;
523*cdf0e10cSrcweir 		Reference< XHierarchicalNameAccess > xNA =
524*cdf0e10cSrcweir 			m_pDatabases->jarFile( rtl::OUString::createFromAscii( "picture.jar" ),
525*cdf0e10cSrcweir 								   get_language() );
526*cdf0e10cSrcweir 
527*cdf0e10cSrcweir 		rtl::OUString path = get_path();
528*cdf0e10cSrcweir 		if( xNA.is() )
529*cdf0e10cSrcweir 		{
530*cdf0e10cSrcweir 			try
531*cdf0e10cSrcweir 			{
532*cdf0e10cSrcweir 				Any aEntry = xNA->getByHierarchicalName( path );
533*cdf0e10cSrcweir 				Reference< XActiveDataSink > xSink;
534*cdf0e10cSrcweir 				if( ( aEntry >>= xSink ) && xSink.is() )
535*cdf0e10cSrcweir 					xStream = xSink->getInputStream();
536*cdf0e10cSrcweir 			}
537*cdf0e10cSrcweir 			catch ( NoSuchElementException & )
538*cdf0e10cSrcweir 			{
539*cdf0e10cSrcweir 			}
540*cdf0e10cSrcweir 		}
541*cdf0e10cSrcweir #ifdef WORKAROUND_98119
542*cdf0e10cSrcweir 		xDataSink->setInputStream( turnToSeekable(xStream) );
543*cdf0e10cSrcweir #else
544*cdf0e10cSrcweir 		xDataSink->setInputStream( xStream );
545*cdf0e10cSrcweir #endif
546*cdf0e10cSrcweir 	}
547*cdf0e10cSrcweir 	else
548*cdf0e10cSrcweir 		// a standard document or else an active help text, plug in the new input stream
549*cdf0e10cSrcweir 		xDataSink->setInputStream( new InputStreamTransformer( this,m_pDatabases,isRoot() ) );
550*cdf0e10cSrcweir }
551*cdf0e10cSrcweir 
552*cdf0e10cSrcweir 
553*cdf0e10cSrcweir // #include <stdio.h>
554*cdf0e10cSrcweir 
555*cdf0e10cSrcweir void URLParameter::parse() throw( com::sun::star::ucb::IllegalIdentifierException )
556*cdf0e10cSrcweir {
557*cdf0e10cSrcweir     // fprintf(stdout,"url send to xmlhelp: %s\n",(rtl::OUStringToOString(m_aURL,RTL_TEXTENCODING_UTF8).getStr()));
558*cdf0e10cSrcweir 	m_aExpr = m_aURL;
559*cdf0e10cSrcweir 
560*cdf0e10cSrcweir 	sal_Int32 lstIdx = m_aExpr.lastIndexOf( sal_Unicode( '#' ) );
561*cdf0e10cSrcweir 	if( lstIdx != -1 )
562*cdf0e10cSrcweir 		m_aExpr = m_aExpr.copy( 0,lstIdx );
563*cdf0e10cSrcweir 
564*cdf0e10cSrcweir 	if( ! scheme() ||
565*cdf0e10cSrcweir         ! name( module() ) ||
566*cdf0e10cSrcweir         ! query() ||
567*cdf0e10cSrcweir         ! m_aLanguage.getLength() ||
568*cdf0e10cSrcweir         ! m_aSystem.getLength() )
569*cdf0e10cSrcweir 		throw com::sun::star::ucb::IllegalIdentifierException();
570*cdf0e10cSrcweir }
571*cdf0e10cSrcweir 
572*cdf0e10cSrcweir 
573*cdf0e10cSrcweir bool URLParameter::scheme()
574*cdf0e10cSrcweir {
575*cdf0e10cSrcweir 	// Correct extension help links as sometimes the
576*cdf0e10cSrcweir 	// module is missing resulting in a misformed URL
577*cdf0e10cSrcweir 	if( m_aExpr.compareToAscii( "vnd.sun.star.help:///", 21 ) == 0 )
578*cdf0e10cSrcweir 	{
579*cdf0e10cSrcweir 		sal_Int32 nLen = m_aExpr.getLength();
580*cdf0e10cSrcweir 		rtl::OUString aLastStr = m_aExpr.copy( nLen - 6 );
581*cdf0e10cSrcweir 		if( aLastStr.compareToAscii( "DbPAR=" ) == 0 )
582*cdf0e10cSrcweir 		{
583*cdf0e10cSrcweir 			rtl::OUString aNewExpr = m_aExpr.copy( 0, 20 );
584*cdf0e10cSrcweir 			rtl::OUString aSharedStr = rtl::OUString::createFromAscii( "shared" );
585*cdf0e10cSrcweir 			aNewExpr += aSharedStr;
586*cdf0e10cSrcweir 			aNewExpr += m_aExpr.copy( 20 );
587*cdf0e10cSrcweir 			aNewExpr += aSharedStr;
588*cdf0e10cSrcweir 			m_aExpr = aNewExpr;
589*cdf0e10cSrcweir 		}
590*cdf0e10cSrcweir 	}
591*cdf0e10cSrcweir 
592*cdf0e10cSrcweir 	for( sal_Int32 nPrefixLen = 20 ; nPrefixLen >= 18 ; --nPrefixLen )
593*cdf0e10cSrcweir 	{
594*cdf0e10cSrcweir 		if( m_aExpr.compareToAscii( "vnd.sun.star.help://", nPrefixLen ) == 0 )
595*cdf0e10cSrcweir 		{
596*cdf0e10cSrcweir 			m_aExpr = m_aExpr.copy( nPrefixLen );
597*cdf0e10cSrcweir 			return true;
598*cdf0e10cSrcweir 		}
599*cdf0e10cSrcweir 	}
600*cdf0e10cSrcweir 	return false;
601*cdf0e10cSrcweir }
602*cdf0e10cSrcweir 
603*cdf0e10cSrcweir 
604*cdf0e10cSrcweir bool URLParameter::module()
605*cdf0e10cSrcweir {
606*cdf0e10cSrcweir 	sal_Int32 idx = 0,length = m_aExpr.getLength();
607*cdf0e10cSrcweir 
608*cdf0e10cSrcweir 	while( idx < length && isLetterOrDigit( (m_aExpr.getStr())[idx] ) )
609*cdf0e10cSrcweir 		++idx;
610*cdf0e10cSrcweir 
611*cdf0e10cSrcweir 	if( idx != 0 )
612*cdf0e10cSrcweir 	{
613*cdf0e10cSrcweir 		m_aModule = m_aExpr.copy( 0,idx );
614*cdf0e10cSrcweir 		m_aExpr = m_aExpr.copy( idx );
615*cdf0e10cSrcweir 		return true;
616*cdf0e10cSrcweir 	}
617*cdf0e10cSrcweir 	else
618*cdf0e10cSrcweir 		return false;
619*cdf0e10cSrcweir }
620*cdf0e10cSrcweir 
621*cdf0e10cSrcweir 
622*cdf0e10cSrcweir 
623*cdf0e10cSrcweir bool URLParameter::name( bool modulePresent )
624*cdf0e10cSrcweir {
625*cdf0e10cSrcweir 	// if modulepresent, a name may be present, but must not
626*cdf0e10cSrcweir 
627*cdf0e10cSrcweir 	sal_Int32 length = m_aExpr.getLength();
628*cdf0e10cSrcweir 
629*cdf0e10cSrcweir 	if( length != 0 && (m_aExpr.getStr())[0] == sal_Unicode( '/' ) )
630*cdf0e10cSrcweir 	{
631*cdf0e10cSrcweir 		sal_Int32 idx = 1;
632*cdf0e10cSrcweir 		while( idx < length && (m_aExpr.getStr())[idx] != '?' )
633*cdf0e10cSrcweir //                ( isLetterOrDigit( (m_aExpr.getStr())[idx] )
634*cdf0e10cSrcweir //                  || (m_aExpr.getStr())[idx] == '/'
635*cdf0e10cSrcweir //                  || (m_aExpr.getStr())[idx] == '.' ))
636*cdf0e10cSrcweir 			++idx;
637*cdf0e10cSrcweir 
638*cdf0e10cSrcweir 		if( idx != 1 && ! modulePresent )
639*cdf0e10cSrcweir 			return false;
640*cdf0e10cSrcweir 		else
641*cdf0e10cSrcweir 		{
642*cdf0e10cSrcweir 			m_aId = m_aExpr.copy( 1,idx-1 );
643*cdf0e10cSrcweir 			m_aExpr = m_aExpr.copy( idx );
644*cdf0e10cSrcweir 		}
645*cdf0e10cSrcweir 	}
646*cdf0e10cSrcweir 
647*cdf0e10cSrcweir //    fprintf(stdout,"id %s\n",(rtl::OUStringToOString(m_aId,RTL_TEXTENCODING_UTF8).getStr()));
648*cdf0e10cSrcweir 	return true;
649*cdf0e10cSrcweir }
650*cdf0e10cSrcweir 
651*cdf0e10cSrcweir 
652*cdf0e10cSrcweir bool URLParameter::query()
653*cdf0e10cSrcweir {
654*cdf0e10cSrcweir 	rtl::OUString query_;
655*cdf0e10cSrcweir 
656*cdf0e10cSrcweir 	if( ! m_aExpr.getLength() )
657*cdf0e10cSrcweir 		return true;
658*cdf0e10cSrcweir 	else if( (m_aExpr.getStr())[0] == sal_Unicode( '?' ) )
659*cdf0e10cSrcweir 		query_ = m_aExpr.copy( 1 ).trim();
660*cdf0e10cSrcweir 	else
661*cdf0e10cSrcweir 		return false;
662*cdf0e10cSrcweir 
663*cdf0e10cSrcweir 
664*cdf0e10cSrcweir 	bool ret = true;
665*cdf0e10cSrcweir 	sal_Int32 delimIdx,equalIdx;
666*cdf0e10cSrcweir 	rtl::OUString parameter,value;
667*cdf0e10cSrcweir 
668*cdf0e10cSrcweir 	while( query_.getLength() != 0 )
669*cdf0e10cSrcweir 	{
670*cdf0e10cSrcweir 		delimIdx = query_.indexOf( sal_Unicode( '&' ) );
671*cdf0e10cSrcweir 		equalIdx = query_.indexOf( sal_Unicode( '=' ) );
672*cdf0e10cSrcweir 		parameter = query_.copy( 0,equalIdx ).trim();
673*cdf0e10cSrcweir 		if( delimIdx == -1 )
674*cdf0e10cSrcweir 		{
675*cdf0e10cSrcweir 			value = query_.copy( equalIdx + 1 ).trim();
676*cdf0e10cSrcweir 			query_ = rtl::OUString();
677*cdf0e10cSrcweir 		}
678*cdf0e10cSrcweir 		else
679*cdf0e10cSrcweir 		{
680*cdf0e10cSrcweir 			value = query_.copy( equalIdx+1,delimIdx - equalIdx - 1 ).trim();
681*cdf0e10cSrcweir 			query_ = query_.copy( delimIdx+1 ).trim();
682*cdf0e10cSrcweir 		}
683*cdf0e10cSrcweir 
684*cdf0e10cSrcweir 		if( parameter.compareToAscii( "Language" ) == 0 )
685*cdf0e10cSrcweir 			m_aLanguage = value;
686*cdf0e10cSrcweir 		else if( parameter.compareToAscii( "Device" ) == 0 )
687*cdf0e10cSrcweir 			m_aDevice = value;
688*cdf0e10cSrcweir 		else if( parameter.compareToAscii( "Program" ) == 0 )
689*cdf0e10cSrcweir 			m_aProgram = value;
690*cdf0e10cSrcweir 		else if( parameter.compareToAscii( "Eid" ) == 0 )
691*cdf0e10cSrcweir 			m_aEid = value;
692*cdf0e10cSrcweir 		else if( parameter.compareToAscii( "UseDB" ) == 0 )
693*cdf0e10cSrcweir             m_bUseDB = ! ( value.compareToAscii("no") == 0 );
694*cdf0e10cSrcweir         else if( parameter.compareToAscii( "DbPAR" ) == 0 )
695*cdf0e10cSrcweir             m_aDbPar = value;
696*cdf0e10cSrcweir 		else if( parameter.compareToAscii( "Query" ) == 0 )
697*cdf0e10cSrcweir 		{
698*cdf0e10cSrcweir 			if( ! m_aQuery.getLength() )
699*cdf0e10cSrcweir 				m_aQuery = value;
700*cdf0e10cSrcweir 			else
701*cdf0e10cSrcweir 				m_aQuery += ( rtl::OUString::createFromAscii( " " ) + value );
702*cdf0e10cSrcweir 		}
703*cdf0e10cSrcweir 		else if( parameter.compareToAscii( "Scope" ) == 0 )
704*cdf0e10cSrcweir 			m_aScope = value;
705*cdf0e10cSrcweir 		else if( parameter.compareToAscii( "System" ) == 0 )
706*cdf0e10cSrcweir 			m_aSystem = value;
707*cdf0e10cSrcweir 		else if( parameter.compareToAscii( "HelpPrefix" ) == 0 )
708*cdf0e10cSrcweir 			m_aPrefix = rtl::Uri::decode(
709*cdf0e10cSrcweir                 value,
710*cdf0e10cSrcweir                 rtl_UriDecodeWithCharset,
711*cdf0e10cSrcweir                 RTL_TEXTENCODING_UTF8 );
712*cdf0e10cSrcweir 		else if( parameter.compareToAscii( "HitCount" ) == 0 )
713*cdf0e10cSrcweir 			m_nHitCount = value.toInt32();
714*cdf0e10cSrcweir 		else if( parameter.compareToAscii( "Active" ) == 0 )
715*cdf0e10cSrcweir 			m_aActive = value;
716*cdf0e10cSrcweir 		else
717*cdf0e10cSrcweir 			ret = false;
718*cdf0e10cSrcweir 	}
719*cdf0e10cSrcweir 
720*cdf0e10cSrcweir 	return ret;
721*cdf0e10cSrcweir }
722*cdf0e10cSrcweir 
723*cdf0e10cSrcweir struct UserData {
724*cdf0e10cSrcweir 
725*cdf0e10cSrcweir 	UserData( InputStreamTransformer* pTransformer,
726*cdf0e10cSrcweir 			  URLParameter*           pInitial,
727*cdf0e10cSrcweir 			  Databases*              pDatabases )
728*cdf0e10cSrcweir 		: m_pTransformer( pTransformer ),
729*cdf0e10cSrcweir           m_pDatabases( pDatabases ),
730*cdf0e10cSrcweir 		  m_pInitial( pInitial )
731*cdf0e10cSrcweir 	{
732*cdf0e10cSrcweir 	}
733*cdf0e10cSrcweir 
734*cdf0e10cSrcweir 	InputStreamTransformer*             m_pTransformer;
735*cdf0e10cSrcweir 	Databases*                          m_pDatabases;
736*cdf0e10cSrcweir 	URLParameter*                       m_pInitial;
737*cdf0e10cSrcweir };
738*cdf0e10cSrcweir 
739*cdf0e10cSrcweir UserData *ugblData = 0;
740*cdf0e10cSrcweir 
741*cdf0e10cSrcweir extern "C" {
742*cdf0e10cSrcweir 
743*cdf0e10cSrcweir static int
744*cdf0e10cSrcweir fileMatch(const char * URI) {
745*cdf0e10cSrcweir 	if ((URI != NULL) && !strncmp(URI, "file:/", 6))
746*cdf0e10cSrcweir         return 1;
747*cdf0e10cSrcweir     return 0;
748*cdf0e10cSrcweir }
749*cdf0e10cSrcweir 
750*cdf0e10cSrcweir static int
751*cdf0e10cSrcweir zipMatch(const char * URI) {
752*cdf0e10cSrcweir 	if ((URI != NULL) && !strncmp(URI, "vnd.sun.star.zip:/", 18))
753*cdf0e10cSrcweir         return 1;
754*cdf0e10cSrcweir     return 0;
755*cdf0e10cSrcweir }
756*cdf0e10cSrcweir 
757*cdf0e10cSrcweir static int
758*cdf0e10cSrcweir helpMatch(const char * URI) {
759*cdf0e10cSrcweir 	if ((URI != NULL) && !strncmp(URI, "vnd.sun.star.help:/", 19))
760*cdf0e10cSrcweir         return 1;
761*cdf0e10cSrcweir     return 0;
762*cdf0e10cSrcweir }
763*cdf0e10cSrcweir 
764*cdf0e10cSrcweir static void *
765*cdf0e10cSrcweir fileOpen(const char *URI) {
766*cdf0e10cSrcweir 	osl::File *pRet = new osl::File(rtl::OUString(URI, strlen(URI), RTL_TEXTENCODING_UTF8));
767*cdf0e10cSrcweir 	pRet->open(OpenFlag_Read);
768*cdf0e10cSrcweir 	return pRet;
769*cdf0e10cSrcweir }
770*cdf0e10cSrcweir 
771*cdf0e10cSrcweir static void *
772*cdf0e10cSrcweir zipOpen(const char * /*URI*/) {
773*cdf0e10cSrcweir 	rtl::OUString language,jar,path;
774*cdf0e10cSrcweir 
775*cdf0e10cSrcweir 	if( ugblData->m_pInitial->get_eid().getLength() )
776*cdf0e10cSrcweir 		return (void*)(new Reference< XHierarchicalNameAccess >);
777*cdf0e10cSrcweir 	else
778*cdf0e10cSrcweir 	{
779*cdf0e10cSrcweir 		jar = ugblData->m_pInitial->get_jar();
780*cdf0e10cSrcweir 		language = ugblData->m_pInitial->get_language();
781*cdf0e10cSrcweir 		path = ugblData->m_pInitial->get_path();
782*cdf0e10cSrcweir 	}
783*cdf0e10cSrcweir 
784*cdf0e10cSrcweir 	Reference< XHierarchicalNameAccess > xNA =
785*cdf0e10cSrcweir 		ugblData->m_pDatabases->findJarFileForPath( jar, language, path );
786*cdf0e10cSrcweir 
787*cdf0e10cSrcweir     Reference< XInputStream > xInputStream;
788*cdf0e10cSrcweir 
789*cdf0e10cSrcweir 	if( xNA.is() )
790*cdf0e10cSrcweir 	{
791*cdf0e10cSrcweir 		try
792*cdf0e10cSrcweir 		{
793*cdf0e10cSrcweir 			Any aEntry = xNA->getByHierarchicalName( path );
794*cdf0e10cSrcweir 			Reference< XActiveDataSink > xSink;
795*cdf0e10cSrcweir 			if( ( aEntry >>= xSink ) && xSink.is() )
796*cdf0e10cSrcweir 				xInputStream = xSink->getInputStream();
797*cdf0e10cSrcweir 		}
798*cdf0e10cSrcweir 		catch ( NoSuchElementException & )
799*cdf0e10cSrcweir 		{
800*cdf0e10cSrcweir 		}
801*cdf0e10cSrcweir 	}
802*cdf0e10cSrcweir 
803*cdf0e10cSrcweir 	if( xInputStream.is() )
804*cdf0e10cSrcweir 	{
805*cdf0e10cSrcweir 		return new Reference<XInputStream>(xInputStream);
806*cdf0e10cSrcweir 	}
807*cdf0e10cSrcweir 	return 0;
808*cdf0e10cSrcweir }
809*cdf0e10cSrcweir 
810*cdf0e10cSrcweir static void *
811*cdf0e10cSrcweir helpOpen(const char * URI) {
812*cdf0e10cSrcweir 	rtl::OUString language,jar,path;
813*cdf0e10cSrcweir 
814*cdf0e10cSrcweir 	URLParameter urlpar( rtl::OUString::createFromAscii( URI ),
815*cdf0e10cSrcweir 						 ugblData->m_pDatabases );
816*cdf0e10cSrcweir 
817*cdf0e10cSrcweir 	jar = urlpar.get_jar();
818*cdf0e10cSrcweir 	language = urlpar.get_language();
819*cdf0e10cSrcweir 	path = urlpar.get_path();
820*cdf0e10cSrcweir 
821*cdf0e10cSrcweir 	Reference< XHierarchicalNameAccess > xNA =
822*cdf0e10cSrcweir 		ugblData->m_pDatabases->findJarFileForPath( jar, language, path );
823*cdf0e10cSrcweir 
824*cdf0e10cSrcweir     Reference< XInputStream > xInputStream;
825*cdf0e10cSrcweir 
826*cdf0e10cSrcweir 	if( xNA.is() )
827*cdf0e10cSrcweir 	{
828*cdf0e10cSrcweir 		try
829*cdf0e10cSrcweir 		{
830*cdf0e10cSrcweir 			Any aEntry = xNA->getByHierarchicalName( path );
831*cdf0e10cSrcweir 			Reference< XActiveDataSink > xSink;
832*cdf0e10cSrcweir 			if( ( aEntry >>= xSink ) && xSink.is() )
833*cdf0e10cSrcweir 				xInputStream = xSink->getInputStream();
834*cdf0e10cSrcweir 		}
835*cdf0e10cSrcweir 		catch ( NoSuchElementException & )
836*cdf0e10cSrcweir 		{
837*cdf0e10cSrcweir 		}
838*cdf0e10cSrcweir 	}
839*cdf0e10cSrcweir 
840*cdf0e10cSrcweir 	if( xInputStream.is() )
841*cdf0e10cSrcweir 		return new Reference<XInputStream>(xInputStream);
842*cdf0e10cSrcweir 	return 0;
843*cdf0e10cSrcweir }
844*cdf0e10cSrcweir 
845*cdf0e10cSrcweir static int
846*cdf0e10cSrcweir helpRead(void * context, char * buffer, int len) {
847*cdf0e10cSrcweir 	Reference< XInputStream > *pRef = (Reference< XInputStream >*)context;
848*cdf0e10cSrcweir 
849*cdf0e10cSrcweir 	Sequence< sal_Int8 > aSeq;
850*cdf0e10cSrcweir 	len = (*pRef)->readBytes( aSeq,len);
851*cdf0e10cSrcweir 	memcpy(buffer, aSeq.getConstArray(), len);
852*cdf0e10cSrcweir 
853*cdf0e10cSrcweir 	return len;
854*cdf0e10cSrcweir }
855*cdf0e10cSrcweir 
856*cdf0e10cSrcweir static int
857*cdf0e10cSrcweir zipRead(void * context, char * buffer, int len) {
858*cdf0e10cSrcweir 	if( ugblData->m_pInitial->get_eid().getLength() )
859*cdf0e10cSrcweir 	{
860*cdf0e10cSrcweir 		ugblData->m_pDatabases->popupDocument( ugblData->m_pInitial,&buffer,&len);
861*cdf0e10cSrcweir 		return len;
862*cdf0e10cSrcweir 	}
863*cdf0e10cSrcweir 	else
864*cdf0e10cSrcweir 		return helpRead(context, buffer, len);
865*cdf0e10cSrcweir }
866*cdf0e10cSrcweir 
867*cdf0e10cSrcweir static int
868*cdf0e10cSrcweir fileRead(void * context, char * buffer, int len) {
869*cdf0e10cSrcweir 	int nRead = 0;
870*cdf0e10cSrcweir 	osl::File *pFile = (osl::File*)context;
871*cdf0e10cSrcweir 	if (pFile)
872*cdf0e10cSrcweir 	{
873*cdf0e10cSrcweir 		sal_uInt64 uRead = 0;
874*cdf0e10cSrcweir 		if (osl::FileBase::E_None == pFile->read(buffer, len, uRead))
875*cdf0e10cSrcweir 			nRead = static_cast<int>(uRead);
876*cdf0e10cSrcweir 	}
877*cdf0e10cSrcweir 	return nRead;
878*cdf0e10cSrcweir }
879*cdf0e10cSrcweir 
880*cdf0e10cSrcweir static int
881*cdf0e10cSrcweir uriClose(void * context) {
882*cdf0e10cSrcweir 	Reference< XInputStream > *pRef = (Reference< XInputStream >*)context;
883*cdf0e10cSrcweir 	delete pRef;
884*cdf0e10cSrcweir     return 0;
885*cdf0e10cSrcweir }
886*cdf0e10cSrcweir 
887*cdf0e10cSrcweir static int
888*cdf0e10cSrcweir fileClose(void * context) {
889*cdf0e10cSrcweir 	osl::File *pFile = (osl::File*)context;
890*cdf0e10cSrcweir 	if (pFile)
891*cdf0e10cSrcweir 	{
892*cdf0e10cSrcweir 		pFile->close();
893*cdf0e10cSrcweir 		delete pFile;
894*cdf0e10cSrcweir 	}
895*cdf0e10cSrcweir 	return 0;
896*cdf0e10cSrcweir }
897*cdf0e10cSrcweir 
898*cdf0e10cSrcweir } // extern "C"
899*cdf0e10cSrcweir 
900*cdf0e10cSrcweir /*
901*cdf0e10cSrcweir // For debugging only
902*cdf0e10cSrcweir extern "C" void StructuredXMLErrorFunction(void *userData, xmlErrorPtr error)
903*cdf0e10cSrcweir {
904*cdf0e10cSrcweir 	(void)userData;
905*cdf0e10cSrcweir 	(void)error;
906*cdf0e10cSrcweir 
907*cdf0e10cSrcweir 	// Reset error handler
908*cdf0e10cSrcweir 	xmlSetStructuredErrorFunc( NULL, NULL );
909*cdf0e10cSrcweir }
910*cdf0e10cSrcweir */
911*cdf0e10cSrcweir 
912*cdf0e10cSrcweir InputStreamTransformer::InputStreamTransformer( URLParameter* urlParam,
913*cdf0e10cSrcweir 												Databases*    pDatabases,
914*cdf0e10cSrcweir 												bool isRoot )
915*cdf0e10cSrcweir 	: len( 0 ),
916*cdf0e10cSrcweir 	  pos( 0 ),
917*cdf0e10cSrcweir 	  buffer( new char[1] ) // Initializing with one element to avoid gcc compiler warning
918*cdf0e10cSrcweir {
919*cdf0e10cSrcweir 	if( isRoot )
920*cdf0e10cSrcweir 	{
921*cdf0e10cSrcweir 		delete[] buffer;
922*cdf0e10cSrcweir 		pDatabases->cascadingStylesheet( urlParam->get_language(),
923*cdf0e10cSrcweir 										 &buffer,
924*cdf0e10cSrcweir 										 &len );
925*cdf0e10cSrcweir 	}
926*cdf0e10cSrcweir 	else if( urlParam->isActive() )
927*cdf0e10cSrcweir 	{
928*cdf0e10cSrcweir 		delete[] buffer;
929*cdf0e10cSrcweir 		pDatabases->setActiveText( urlParam->get_module(),
930*cdf0e10cSrcweir 								   urlParam->get_language(),
931*cdf0e10cSrcweir 								   urlParam->get_id(),
932*cdf0e10cSrcweir 								   &buffer,
933*cdf0e10cSrcweir 								   &len );
934*cdf0e10cSrcweir 	}
935*cdf0e10cSrcweir 	else
936*cdf0e10cSrcweir 	{
937*cdf0e10cSrcweir 		UserData userData( this,urlParam,pDatabases );
938*cdf0e10cSrcweir 
939*cdf0e10cSrcweir 		// Uses the implementation detail, that rtl::OString::getStr returns a zero terminated character-array
940*cdf0e10cSrcweir 
941*cdf0e10cSrcweir 		const char* parameter[47];
942*cdf0e10cSrcweir 		rtl::OString parString[46];
943*cdf0e10cSrcweir 		int last = 0;
944*cdf0e10cSrcweir 
945*cdf0e10cSrcweir 		parString[last++] = "Program";
946*cdf0e10cSrcweir 		rtl::OString aPureProgramm( urlParam->getByName( "Program" ) );
947*cdf0e10cSrcweir 		parString[last++] = rtl::OString('\'') + aPureProgramm + rtl::OString('\'');
948*cdf0e10cSrcweir 		parString[last++] = "Database";
949*cdf0e10cSrcweir 		parString[last++] = rtl::OString('\'') + urlParam->getByName( "DatabasePar" ) + rtl::OString('\'');
950*cdf0e10cSrcweir 		parString[last++] = "Id";
951*cdf0e10cSrcweir 		parString[last++] = rtl::OString('\'') + urlParam->getByName( "Id" ) + rtl::OString('\'');
952*cdf0e10cSrcweir 		parString[last++] = "Path";
953*cdf0e10cSrcweir 		rtl::OString aPath( urlParam->getByName( "Path" ) );
954*cdf0e10cSrcweir 		parString[last++] = rtl::OString('\'') + aPath + rtl::OString('\'');
955*cdf0e10cSrcweir 
956*cdf0e10cSrcweir 		rtl::OString aPureLanguage = urlParam->getByName( "Language" );
957*cdf0e10cSrcweir 		parString[last++] = "Language";
958*cdf0e10cSrcweir 		parString[last++] = rtl::OString('\'') + aPureLanguage + rtl::OString('\'');
959*cdf0e10cSrcweir 		parString[last++] = "System";
960*cdf0e10cSrcweir 		parString[last++] = rtl::OString('\'') + urlParam->getByName( "System" ) + rtl::OString('\'');
961*cdf0e10cSrcweir 		parString[last++] = "productname";
962*cdf0e10cSrcweir 		parString[last++] = rtl::OString('\'') + rtl::OString(
963*cdf0e10cSrcweir             pDatabases->getProductName().getStr(),
964*cdf0e10cSrcweir             pDatabases->getProductName().getLength(),
965*cdf0e10cSrcweir             RTL_TEXTENCODING_UTF8 ) + rtl::OString('\'');
966*cdf0e10cSrcweir 		parString[last++] = "productversion";
967*cdf0e10cSrcweir 		parString[last++] = rtl::OString('\'') +
968*cdf0e10cSrcweir             rtl::OString(  pDatabases->getProductVersion().getStr(),
969*cdf0e10cSrcweir                           pDatabases->getProductVersion().getLength(),
970*cdf0e10cSrcweir                           RTL_TEXTENCODING_UTF8 ) + rtl::OString('\'');
971*cdf0e10cSrcweir 
972*cdf0e10cSrcweir         parString[last++] = "imgrepos";
973*cdf0e10cSrcweir         parString[last++] = rtl::OString('\'') + pDatabases->getImagesZipFileURL() + rtl::OString('\'');
974*cdf0e10cSrcweir         parString[last++] = "hp";
975*cdf0e10cSrcweir         parString[last++] = rtl::OString('\'') + urlParam->getByName( "HelpPrefix" ) + rtl::OString('\'');
976*cdf0e10cSrcweir 
977*cdf0e10cSrcweir         if( parString[last-1].getLength() )
978*cdf0e10cSrcweir         {
979*cdf0e10cSrcweir             parString[last++] = "sm";
980*cdf0e10cSrcweir             parString[last++] = "'vnd.sun.star.help%3A%2F%2F'";
981*cdf0e10cSrcweir             parString[last++] = "qm";
982*cdf0e10cSrcweir             parString[last++] = "'%3F'";
983*cdf0e10cSrcweir             parString[last++] = "es";
984*cdf0e10cSrcweir             parString[last++] = "'%3D'";
985*cdf0e10cSrcweir             parString[last++] = "am";
986*cdf0e10cSrcweir             parString[last++] = "'%26'";
987*cdf0e10cSrcweir             parString[last++] = "cl";
988*cdf0e10cSrcweir             parString[last++] = "'%3A'";
989*cdf0e10cSrcweir             parString[last++] = "sl";
990*cdf0e10cSrcweir             parString[last++] = "'%2F'";
991*cdf0e10cSrcweir             parString[last++] = "hm";
992*cdf0e10cSrcweir             parString[last++] = "'%23'";
993*cdf0e10cSrcweir             parString[last++] = "cs";
994*cdf0e10cSrcweir             parString[last++] = "'css'";
995*cdf0e10cSrcweir 
996*cdf0e10cSrcweir             parString[last++] = "vendorname";
997*cdf0e10cSrcweir             parString[last++] = rtl::OString("''");
998*cdf0e10cSrcweir             parString[last++] = "vendorversion";
999*cdf0e10cSrcweir             parString[last++] = rtl::OString("''");
1000*cdf0e10cSrcweir             parString[last++] = "vendorshort";
1001*cdf0e10cSrcweir             parString[last++] = rtl::OString("''");
1002*cdf0e10cSrcweir         }
1003*cdf0e10cSrcweir 
1004*cdf0e10cSrcweir 		// Do we need to add extension path?
1005*cdf0e10cSrcweir 		::rtl::OUString aExtensionPath;
1006*cdf0e10cSrcweir 		rtl::OUString aJar = urlParam->get_jar();
1007*cdf0e10cSrcweir 
1008*cdf0e10cSrcweir 		bool bAddExtensionPath = false;
1009*cdf0e10cSrcweir         rtl::OUString aExtensionRegistryPath;
1010*cdf0e10cSrcweir         sal_Int32 nQuestionMark1 = aJar.indexOf( sal_Unicode('?') );
1011*cdf0e10cSrcweir         sal_Int32 nQuestionMark2 = aJar.lastIndexOf( sal_Unicode('?') );
1012*cdf0e10cSrcweir 		if( nQuestionMark1 != -1 && nQuestionMark2 != -1 && nQuestionMark1 != nQuestionMark2 )
1013*cdf0e10cSrcweir 		{
1014*cdf0e10cSrcweir 			aExtensionPath = aJar.copy( nQuestionMark1 + 1, nQuestionMark2 - nQuestionMark1 - 1 );
1015*cdf0e10cSrcweir             aExtensionRegistryPath = urlParam->get_ExtensionRegistryPath();
1016*cdf0e10cSrcweir 			bAddExtensionPath = true;
1017*cdf0e10cSrcweir 		}
1018*cdf0e10cSrcweir 		else
1019*cdf0e10cSrcweir 		{
1020*cdf0e10cSrcweir 			// Path not yet specified, search directly
1021*cdf0e10cSrcweir 			Reference< XHierarchicalNameAccess > xNA = pDatabases->findJarFileForPath
1022*cdf0e10cSrcweir 				( aJar, urlParam->get_language(), urlParam->get_path(), &aExtensionPath, &aExtensionRegistryPath );
1023*cdf0e10cSrcweir 			if( xNA.is() && aExtensionPath.getLength() )
1024*cdf0e10cSrcweir 				bAddExtensionPath = true;
1025*cdf0e10cSrcweir 		}
1026*cdf0e10cSrcweir 
1027*cdf0e10cSrcweir 		if( bAddExtensionPath )
1028*cdf0e10cSrcweir 		{
1029*cdf0e10cSrcweir 			Reference< XMultiServiceFactory > xFactory = comphelper::getProcessServiceFactory();
1030*cdf0e10cSrcweir 			Reference< XPropertySet > xProps( xFactory, UNO_QUERY );
1031*cdf0e10cSrcweir 			OSL_ASSERT( xProps.is() );
1032*cdf0e10cSrcweir 			Reference< XComponentContext > xContext;
1033*cdf0e10cSrcweir 			if (xProps.is())
1034*cdf0e10cSrcweir 			{
1035*cdf0e10cSrcweir 				xProps->getPropertyValue(
1036*cdf0e10cSrcweir 					::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("DefaultContext") ) ) >>= xContext;
1037*cdf0e10cSrcweir 			}
1038*cdf0e10cSrcweir 			if( !xContext.is() )
1039*cdf0e10cSrcweir 			{
1040*cdf0e10cSrcweir 				throw RuntimeException(
1041*cdf0e10cSrcweir 					::rtl::OUString::createFromAscii( "InputStreamTransformer::InputStreamTransformer(), no XComponentContext" ),
1042*cdf0e10cSrcweir 					Reference< XInterface >() );
1043*cdf0e10cSrcweir 			}
1044*cdf0e10cSrcweir 
1045*cdf0e10cSrcweir 			rtl::OUString aOUExpandedExtensionPath = Databases::expandURL( aExtensionRegistryPath, xContext );
1046*cdf0e10cSrcweir 			rtl::OString aExpandedExtensionPath = rtl::OUStringToOString( aOUExpandedExtensionPath, osl_getThreadTextEncoding() );
1047*cdf0e10cSrcweir 
1048*cdf0e10cSrcweir 			parString[last++] = "ExtensionPath";
1049*cdf0e10cSrcweir 			parString[last++] = rtl::OString('\'') + aExpandedExtensionPath + rtl::OString('\'');
1050*cdf0e10cSrcweir 
1051*cdf0e10cSrcweir 			// ExtensionId
1052*cdf0e10cSrcweir 			rtl::OString aPureExtensionId;
1053*cdf0e10cSrcweir 			sal_Int32 iSlash = aPath.indexOf( '/' );
1054*cdf0e10cSrcweir 			if( iSlash != -1 )
1055*cdf0e10cSrcweir 				aPureExtensionId = aPath.copy( 0, iSlash );
1056*cdf0e10cSrcweir 
1057*cdf0e10cSrcweir 			parString[last++] = "ExtensionId";
1058*cdf0e10cSrcweir 			parString[last++] = rtl::OString('\'') + aPureExtensionId + rtl::OString('\'');
1059*cdf0e10cSrcweir 		}
1060*cdf0e10cSrcweir 
1061*cdf0e10cSrcweir 		for( int i = 0; i < last; ++i )
1062*cdf0e10cSrcweir 			parameter[i] = parString[i].getStr();
1063*cdf0e10cSrcweir 		parameter[last] = 0;
1064*cdf0e10cSrcweir 
1065*cdf0e10cSrcweir 		rtl::OUString xslURL = pDatabases->getInstallPathAsURL();
1066*cdf0e10cSrcweir 
1067*cdf0e10cSrcweir 		rtl::OString xslURLascii(
1068*cdf0e10cSrcweir 			xslURL.getStr(),
1069*cdf0e10cSrcweir 			xslURL.getLength(),
1070*cdf0e10cSrcweir 			RTL_TEXTENCODING_UTF8);
1071*cdf0e10cSrcweir 		xslURLascii += "main_transform.xsl";
1072*cdf0e10cSrcweir 
1073*cdf0e10cSrcweir         ugblData = &userData;
1074*cdf0e10cSrcweir 
1075*cdf0e10cSrcweir         xmlInitParser();
1076*cdf0e10cSrcweir         xmlRegisterInputCallbacks(zipMatch, zipOpen, zipRead, uriClose);
1077*cdf0e10cSrcweir         xmlRegisterInputCallbacks(helpMatch, helpOpen, helpRead, uriClose);
1078*cdf0e10cSrcweir 		xmlRegisterInputCallbacks(fileMatch, fileOpen, fileRead, fileClose);
1079*cdf0e10cSrcweir 		//xmlSetStructuredErrorFunc( NULL, (xmlStructuredErrorFunc)StructuredXMLErrorFunction );
1080*cdf0e10cSrcweir 
1081*cdf0e10cSrcweir         xsltStylesheetPtr cur =
1082*cdf0e10cSrcweir             xsltParseStylesheetFile((const xmlChar *)xslURLascii.getStr());
1083*cdf0e10cSrcweir 
1084*cdf0e10cSrcweir         xmlDocPtr doc = xmlParseFile("vnd.sun.star.zip:/");
1085*cdf0e10cSrcweir 
1086*cdf0e10cSrcweir         xmlDocPtr res = xsltApplyStylesheet(cur, doc, parameter);
1087*cdf0e10cSrcweir         if (res)
1088*cdf0e10cSrcweir 		{
1089*cdf0e10cSrcweir 			xmlChar *doc_txt_ptr=0;
1090*cdf0e10cSrcweir 			int doc_txt_len;
1091*cdf0e10cSrcweir 			xsltSaveResultToString(&doc_txt_ptr, &doc_txt_len, res, cur);
1092*cdf0e10cSrcweir 			addToBuffer((const char*)doc_txt_ptr, doc_txt_len);
1093*cdf0e10cSrcweir 			xmlFree(doc_txt_ptr);
1094*cdf0e10cSrcweir         }
1095*cdf0e10cSrcweir         xmlPopInputCallbacks();	//filePatch
1096*cdf0e10cSrcweir         xmlPopInputCallbacks();	//helpPatch
1097*cdf0e10cSrcweir         xmlPopInputCallbacks();	//zipMatch
1098*cdf0e10cSrcweir         xmlFreeDoc(res);
1099*cdf0e10cSrcweir         xmlFreeDoc(doc);
1100*cdf0e10cSrcweir         xsltFreeStylesheet(cur);
1101*cdf0e10cSrcweir 	}
1102*cdf0e10cSrcweir }
1103*cdf0e10cSrcweir 
1104*cdf0e10cSrcweir 
1105*cdf0e10cSrcweir InputStreamTransformer::~InputStreamTransformer()
1106*cdf0e10cSrcweir {
1107*cdf0e10cSrcweir 	delete[] buffer;
1108*cdf0e10cSrcweir }
1109*cdf0e10cSrcweir 
1110*cdf0e10cSrcweir 
1111*cdf0e10cSrcweir Any SAL_CALL InputStreamTransformer::queryInterface( const Type& rType ) throw( RuntimeException )
1112*cdf0e10cSrcweir {
1113*cdf0e10cSrcweir 	Any aRet = ::cppu::queryInterface( rType,
1114*cdf0e10cSrcweir 									   SAL_STATIC_CAST( XInputStream*,this ),
1115*cdf0e10cSrcweir 									   SAL_STATIC_CAST( XSeekable*,this ) );
1116*cdf0e10cSrcweir 
1117*cdf0e10cSrcweir 	return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
1118*cdf0e10cSrcweir }
1119*cdf0e10cSrcweir 
1120*cdf0e10cSrcweir 
1121*cdf0e10cSrcweir 
1122*cdf0e10cSrcweir void SAL_CALL InputStreamTransformer::acquire( void ) throw()
1123*cdf0e10cSrcweir {
1124*cdf0e10cSrcweir 	OWeakObject::acquire();
1125*cdf0e10cSrcweir }
1126*cdf0e10cSrcweir 
1127*cdf0e10cSrcweir 
1128*cdf0e10cSrcweir 
1129*cdf0e10cSrcweir void SAL_CALL InputStreamTransformer::release( void ) throw()
1130*cdf0e10cSrcweir {
1131*cdf0e10cSrcweir 	OWeakObject::release();
1132*cdf0e10cSrcweir }
1133*cdf0e10cSrcweir 
1134*cdf0e10cSrcweir 
1135*cdf0e10cSrcweir 
1136*cdf0e10cSrcweir sal_Int32 SAL_CALL InputStreamTransformer::readBytes( Sequence< sal_Int8 >& aData,sal_Int32 nBytesToRead )
1137*cdf0e10cSrcweir 	throw( NotConnectedException,
1138*cdf0e10cSrcweir 		   BufferSizeExceededException,
1139*cdf0e10cSrcweir 		   IOException,
1140*cdf0e10cSrcweir 		   RuntimeException)
1141*cdf0e10cSrcweir {
1142*cdf0e10cSrcweir 	osl::MutexGuard aGuard( m_aMutex );
1143*cdf0e10cSrcweir 
1144*cdf0e10cSrcweir 	int curr,available_ = len-pos;
1145*cdf0e10cSrcweir 	if( nBytesToRead <= available_ )
1146*cdf0e10cSrcweir 		curr = nBytesToRead;
1147*cdf0e10cSrcweir 	else
1148*cdf0e10cSrcweir 		curr = available_;
1149*cdf0e10cSrcweir 
1150*cdf0e10cSrcweir 	if( 0 <= curr && aData.getLength() < curr )
1151*cdf0e10cSrcweir 		aData.realloc( curr );
1152*cdf0e10cSrcweir 
1153*cdf0e10cSrcweir 	for( int k = 0; k < curr; ++k )
1154*cdf0e10cSrcweir 		aData[k] = buffer[pos++];
1155*cdf0e10cSrcweir 
1156*cdf0e10cSrcweir 	return curr > 0 ? curr : 0;
1157*cdf0e10cSrcweir }
1158*cdf0e10cSrcweir 
1159*cdf0e10cSrcweir 
1160*cdf0e10cSrcweir sal_Int32 SAL_CALL InputStreamTransformer::readSomeBytes( Sequence< sal_Int8 >& aData,sal_Int32 nMaxBytesToRead )
1161*cdf0e10cSrcweir 	throw( NotConnectedException,
1162*cdf0e10cSrcweir 		   BufferSizeExceededException,
1163*cdf0e10cSrcweir 		   IOException,
1164*cdf0e10cSrcweir 		   RuntimeException)
1165*cdf0e10cSrcweir {
1166*cdf0e10cSrcweir 	return readBytes( aData,nMaxBytesToRead );
1167*cdf0e10cSrcweir }
1168*cdf0e10cSrcweir 
1169*cdf0e10cSrcweir 
1170*cdf0e10cSrcweir 
1171*cdf0e10cSrcweir void SAL_CALL InputStreamTransformer::skipBytes( sal_Int32 nBytesToSkip ) throw( NotConnectedException,
1172*cdf0e10cSrcweir 																				 BufferSizeExceededException,
1173*cdf0e10cSrcweir 																				 IOException,
1174*cdf0e10cSrcweir 																				 RuntimeException )
1175*cdf0e10cSrcweir {
1176*cdf0e10cSrcweir 	osl::MutexGuard aGuard( m_aMutex );
1177*cdf0e10cSrcweir 	while( nBytesToSkip-- ) ++pos;
1178*cdf0e10cSrcweir }
1179*cdf0e10cSrcweir 
1180*cdf0e10cSrcweir 
1181*cdf0e10cSrcweir 
1182*cdf0e10cSrcweir sal_Int32 SAL_CALL InputStreamTransformer::available( void ) throw( NotConnectedException,
1183*cdf0e10cSrcweir 																	IOException,
1184*cdf0e10cSrcweir 																	RuntimeException )
1185*cdf0e10cSrcweir {
1186*cdf0e10cSrcweir 	osl::MutexGuard aGuard( m_aMutex );
1187*cdf0e10cSrcweir 	return len-pos > 0 ? len - pos : 0 ;
1188*cdf0e10cSrcweir }
1189*cdf0e10cSrcweir 
1190*cdf0e10cSrcweir 
1191*cdf0e10cSrcweir 
1192*cdf0e10cSrcweir void SAL_CALL InputStreamTransformer::closeInput( void ) throw( NotConnectedException,
1193*cdf0e10cSrcweir 																IOException,
1194*cdf0e10cSrcweir 																RuntimeException )
1195*cdf0e10cSrcweir {
1196*cdf0e10cSrcweir }
1197*cdf0e10cSrcweir 
1198*cdf0e10cSrcweir 
1199*cdf0e10cSrcweir 
1200*cdf0e10cSrcweir void SAL_CALL InputStreamTransformer::seek( sal_Int64 location ) throw( IllegalArgumentException,
1201*cdf0e10cSrcweir 																		IOException,
1202*cdf0e10cSrcweir 																		RuntimeException )
1203*cdf0e10cSrcweir {
1204*cdf0e10cSrcweir 	osl::MutexGuard aGuard( m_aMutex );
1205*cdf0e10cSrcweir 	if( location < 0 )
1206*cdf0e10cSrcweir 		throw IllegalArgumentException();
1207*cdf0e10cSrcweir 	else
1208*cdf0e10cSrcweir 		pos = sal::static_int_cast<sal_Int32>( location );
1209*cdf0e10cSrcweir 
1210*cdf0e10cSrcweir 	if( pos > len )
1211*cdf0e10cSrcweir 		pos = len;
1212*cdf0e10cSrcweir }
1213*cdf0e10cSrcweir 
1214*cdf0e10cSrcweir 
1215*cdf0e10cSrcweir 
1216*cdf0e10cSrcweir sal_Int64 SAL_CALL InputStreamTransformer::getPosition( void ) throw( IOException,
1217*cdf0e10cSrcweir 																	  RuntimeException )
1218*cdf0e10cSrcweir {
1219*cdf0e10cSrcweir 	osl::MutexGuard aGuard( m_aMutex );
1220*cdf0e10cSrcweir 	return sal_Int64( pos );
1221*cdf0e10cSrcweir }
1222*cdf0e10cSrcweir 
1223*cdf0e10cSrcweir 
1224*cdf0e10cSrcweir 
1225*cdf0e10cSrcweir sal_Int64 SAL_CALL InputStreamTransformer::getLength( void ) throw( IOException,RuntimeException )
1226*cdf0e10cSrcweir {
1227*cdf0e10cSrcweir 	osl::MutexGuard aGuard( m_aMutex );
1228*cdf0e10cSrcweir 
1229*cdf0e10cSrcweir 	return len;
1230*cdf0e10cSrcweir }
1231*cdf0e10cSrcweir 
1232*cdf0e10cSrcweir 
1233*cdf0e10cSrcweir void InputStreamTransformer::addToBuffer( const char* buffer_,int len_ )
1234*cdf0e10cSrcweir {
1235*cdf0e10cSrcweir 	osl::MutexGuard aGuard( m_aMutex );
1236*cdf0e10cSrcweir 
1237*cdf0e10cSrcweir 	char* tmp = buffer;
1238*cdf0e10cSrcweir 	buffer = new char[ len+len_ ];
1239*cdf0e10cSrcweir 	rtl_copyMemory( (void*)(buffer),(void*)(tmp),sal_uInt32( len ) );
1240*cdf0e10cSrcweir 	rtl_copyMemory( (void*)(buffer+len),(void*)(buffer_),sal_uInt32( len_ ) );
1241*cdf0e10cSrcweir 	delete[] tmp;
1242*cdf0e10cSrcweir 	len += len_;
1243*cdf0e10cSrcweir }
1244