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