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