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