1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XSLTFilter.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_filter.hxx"
36 #include <cppuhelper/factory.hxx>
37 #include <cppuhelper/servicefactory.hxx>
38 #include <cppuhelper/implbase1.hxx>
39 #include <cppuhelper/implbase2.hxx>
40 #include <cppuhelper/implbase3.hxx>
41 #include <cppuhelper/implbase4.hxx>
42 #include <cppuhelper/implbase.hxx>
45 #include <osl/conditn.h>
46 #include <tools/urlobj.hxx>
47 #include <osl/module.h>
48 #include <osl/file.hxx>
49 #include <osl/process.h>
51 #include <com/sun/star/lang/XComponent.hpp>
53 #include <com/sun/star/uno/Any.hxx>
54 #include <com/sun/star/uno/Type.hxx>
56 #include <com/sun/star/beans/PropertyValue.hpp>
58 #include <com/sun/star/xml/sax/XParser.hpp>
59 #include <com/sun/star/xml/sax/InputSource.hpp>
60 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
61 #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
62 #include <com/sun/star/xml/sax/SAXException.hpp>
63 #include <com/sun/star/xml/XImportFilter.hpp>
64 #include <com/sun/star/xml/XExportFilter.hpp>
65 #include <com/sun/star/beans/XPropertySet.hpp>
66 #include <com/sun/star/util/XMacroExpander.hpp>
68 #include <com/sun/star/io/XInputStream.hpp>
69 #include <com/sun/star/io/XOutputStream.hpp>
70 #include <com/sun/star/io/XActiveDataSource.hpp>
71 #include <com/sun/star/io/XActiveDataSink.hpp>
72 #include <com/sun/star/io/XActiveDataControl.hpp>
73 #include <com/sun/star/io/XStreamListener.hpp>
74 #include <com/sun/star/uno/Any.hxx>
75 #include <com/sun/star/lang/EventObject.hpp>
76 #include <com/sun/star/util/XStringSubstitution.hpp>
77 #include <com/sun/star/beans/NamedValue.hpp>
79 #include <xmloff/attrlist.hxx>
82 using namespace ::rtl
;
83 using namespace ::cppu
;
84 using namespace ::osl
;
85 using namespace ::com::sun::star::beans
;
86 using namespace ::com::sun::star::io
;
87 using namespace ::com::sun::star::uno
;
88 using namespace ::com::sun::star::lang
;
89 using namespace ::com::sun::star::registry
;
90 using namespace ::com::sun::star::xml
;
91 using namespace ::com::sun::star::xml::sax
;
92 using namespace ::com::sun::star::util
;
97 class FLABridge
: public WeakImplHelper1
< XDocumentHandler
>
100 const Reference
<XDocumentHandler
>& m_rDocumentHandler
;
101 const sal_Unicode
*eval(const sal_Unicode
*expr
, sal_Int32 exprLen
);
106 FLABridge(const Reference
<XDocumentHandler
>& m_rDocumentHandler
);
109 virtual void SAL_CALL
startDocument()
110 throw (SAXException
,RuntimeException
);
111 virtual void SAL_CALL
endDocument()
112 throw (SAXException
, RuntimeException
);
113 virtual void SAL_CALL
startElement(const OUString
& str
, const Reference
<XAttributeList
>& attriblist
)
114 throw (SAXException
,RuntimeException
);
115 virtual void SAL_CALL
endElement(const OUString
& str
)
116 throw (SAXException
, RuntimeException
);
117 virtual void SAL_CALL
characters(const OUString
& str
)
118 throw (SAXException
, RuntimeException
);
119 virtual void SAL_CALL
ignorableWhitespace(const OUString
& str
)
120 throw (SAXException
, RuntimeException
);
121 virtual void SAL_CALL
processingInstruction(const OUString
& str
, const OUString
& str2
)
122 throw (com::sun::star::xml::sax::SAXException
,RuntimeException
);
123 virtual void SAL_CALL
setDocumentLocator(const Reference
<XLocator
>& doclocator
)
124 throw (SAXException
,RuntimeException
);
128 FLABridge::FLABridge(const Reference
<XDocumentHandler
>& _rDocumentHandler
) : m_rDocumentHandler(_rDocumentHandler
), active(false)
132 void FLABridge::startDocument() throw (SAXException
,RuntimeException
){
133 OSL_ASSERT(m_rDocumentHandler
.is());
134 m_rDocumentHandler
->startDocument();
137 void FLABridge::endDocument() throw (SAXException
,RuntimeException
){
138 OSL_ASSERT(m_rDocumentHandler
.is());
139 m_rDocumentHandler
->endDocument();
144 void FLABridge::startElement(const OUString
& str
, const Reference
<XAttributeList
>& attriblist
)
145 throw (SAXException
, RuntimeException
)
147 OSL_ASSERT(m_rDocumentHandler
.is());
150 // SvXMLAttributeList* _attriblist=SvXMLAttributeList::getImplementation(attriblist);
151 const int len
=attriblist
->getLength();
152 SvXMLAttributeList
*_newattriblist
= new SvXMLAttributeList();
153 for(int i
=0;i
<len
;i
++)
155 const OUString
& name
=attriblist
->getNameByIndex( sal::static_int_cast
<sal_Int16
>( i
) );
157 static const OUString
_value_(".value", 6, RTL_TEXTENCODING_ASCII_US
);
158 if ((pos
=name
.lastIndexOf(L
'.'))!=-1 && name
.match(_value_
, pos
))
160 const OUString
newName(name
, pos
);
161 const OUString
& value
=attriblist
->getValueByIndex( sal::static_int_cast
<sal_Int16
>( i
) );
162 const OUString
newValue(ev
.eval(value
.getStr(), value
.getLength()));
163 if (newValue
.getLength()>0)
165 _newattriblist
->AddAttribute(newName
, newValue
);
170 _newattriblist
->AddAttribute(name
, attriblist
->getValueByIndex( sal::static_int_cast
<sal_Int16
>( i
)));
173 const Reference
<XAttributeList
> newattriblist(_newattriblist
);
174 m_rDocumentHandler
->startElement(str
, newattriblist
);
178 if (str
.compareToAscii("fla:fla.activate")==0)
182 m_rDocumentHandler
->startElement(str
, attriblist
);
186 void FLABridge::endElement(const OUString
& str
)
187 throw (SAXException
, RuntimeException
)
189 OSL_ASSERT(m_rDocumentHandler
.is());
190 m_rDocumentHandler
->endElement(str
);
193 void FLABridge::characters(const OUString
& str
)
194 throw (SAXException
, RuntimeException
)
196 OSL_ASSERT(m_rDocumentHandler
.is());
197 m_rDocumentHandler
->characters(str
);
200 void FLABridge::ignorableWhitespace(const OUString
& str
)
201 throw (SAXException
, RuntimeException
)
203 OSL_ASSERT(m_rDocumentHandler
.is());
204 m_rDocumentHandler
->ignorableWhitespace(str
);
207 void FLABridge::processingInstruction(const OUString
& str
, const OUString
& str2
)
208 throw (SAXException
, RuntimeException
)
210 OSL_ASSERT(m_rDocumentHandler
.is());
211 m_rDocumentHandler
->processingInstruction(str
, str2
);
214 void FLABridge::setDocumentLocator(const Reference
<XLocator
>& doclocator
)
215 throw (SAXException
, RuntimeException
)
217 OSL_ASSERT(m_rDocumentHandler
.is());
218 m_rDocumentHandler
->setDocumentLocator(doclocator
);
223 class XSLTFilter
: public WeakImplHelper4
< XImportFilter
, XExportFilter
, XDocumentHandler
, XStreamListener
>
226 // the UNO ServiceFactory
227 Reference
< XMultiServiceFactory
> m_rServiceFactory
;
229 // DocumentHandler interface of the css::xml::sax::Writer service
230 Reference
< XExtendedDocumentHandler
> m_rDocumentHandler
;
231 Reference
< XOutputStream
> m_rOutputStream
;
233 // controls pretty-printing
234 sal_Bool m_bPrettyPrint
;
236 Reference
< XActiveDataControl
> m_tcontrol
;
237 oslCondition m_cTransformed
;
238 sal_Bool m_bTerminated
;
241 OUString m_aExportBaseUrl
;
242 OUString m_aOldBaseUrl
;
244 OUString
rel2abs(const OUString
&);
245 OUString
expandUrl(const OUString
&);
250 XSLTFilter( const Reference
< XMultiServiceFactory
> &r
);
253 virtual void SAL_CALL
error(const Any
& a
) throw (RuntimeException
);
254 virtual void SAL_CALL
closed() throw (RuntimeException
);
255 virtual void SAL_CALL
terminated() throw (RuntimeException
);
256 virtual void SAL_CALL
started() throw (RuntimeException
);
257 virtual void SAL_CALL
disposing(const EventObject
& e
) throw (RuntimeException
);
261 virtual sal_Bool SAL_CALL
importer(
262 const Sequence
<PropertyValue
>& aSourceData
,
263 const Reference
<XDocumentHandler
>& xHandler
,
264 const Sequence
<OUString
>& msUserData
)
265 throw(RuntimeException
);
268 virtual sal_Bool SAL_CALL
exporter(
269 const Sequence
<PropertyValue
>& aSourceData
,
270 const Sequence
<OUString
>& msUserData
)
271 throw(RuntimeException
);
274 virtual void SAL_CALL
startDocument()
275 throw (SAXException
,RuntimeException
);
276 virtual void SAL_CALL
endDocument()
277 throw (SAXException
, RuntimeException
);
278 virtual void SAL_CALL
startElement(const OUString
& str
, const Reference
<XAttributeList
>& attriblist
)
279 throw (SAXException
,RuntimeException
);
280 virtual void SAL_CALL
endElement(const OUString
& str
)
281 throw (SAXException
, RuntimeException
);
282 virtual void SAL_CALL
characters(const OUString
& str
)
283 throw (SAXException
, RuntimeException
);
284 virtual void SAL_CALL
ignorableWhitespace(const OUString
& str
)
285 throw (SAXException
, RuntimeException
);
286 virtual void SAL_CALL
processingInstruction(const OUString
& str
, const OUString
& str2
)
287 throw (com::sun::star::xml::sax::SAXException
,RuntimeException
);
288 virtual void SAL_CALL
setDocumentLocator(const Reference
<XLocator
>& doclocator
)
289 throw (SAXException
,RuntimeException
);
292 XSLTFilter::XSLTFilter( const Reference
< XMultiServiceFactory
> &r
)
293 : m_rServiceFactory(r
)
294 , m_bPrettyPrint(sal_True
)
295 , m_bTerminated(sal_False
)
296 , m_bError(sal_False
)
298 m_cTransformed
= osl_createCondition();
301 void XSLTFilter::disposing(const EventObject
& ) throw (RuntimeException
)
305 ::rtl::OUString
XSLTFilter::expandUrl( const ::rtl::OUString
& sUrl
)
307 ::rtl::OUString sExpandedUrl
;
310 Reference
< XComponentContext
> xContext
;
311 Reference
< XPropertySet
> xProps( m_rServiceFactory
, UNO_QUERY_THROW
);
312 xContext
.set( xProps
->getPropertyValue( ::rtl::OUString::createFromAscii( "DefaultContext" ) ), UNO_QUERY_THROW
);
313 Reference
< XMacroExpander
> xMacroExpander( xContext
->getValueByName( ::rtl::OUString::createFromAscii( "/singletons/com.sun.star.util.theMacroExpander" ) ), UNO_QUERY_THROW
);
314 sExpandedUrl
= xMacroExpander
->expandMacros(sUrl
);
315 sal_Int32 nPos
= sExpandedUrl
.indexOf(::rtl::OUString::createFromAscii("vnd.sun.star.expand:"));
317 sExpandedUrl
= sExpandedUrl
.copy(nPos
+20);
319 catch (Exception
&) {}
323 void XSLTFilter::started() throw (RuntimeException
)
325 osl_resetCondition(m_cTransformed
);
327 void XSLTFilter::error(const Any
& a
) throw (RuntimeException
)
332 OString
aMessage("XSLTFilter::error was called: ");
333 aMessage
+= OUStringToOString(e
.Message
, RTL_TEXTENCODING_ASCII_US
);
334 OSL_ENSURE(sal_False
, aMessage
);
337 osl_setCondition(m_cTransformed
);
339 void XSLTFilter::closed() throw (RuntimeException
)
341 osl_setCondition(m_cTransformed
);
343 void XSLTFilter::terminated() throw (RuntimeException
)
345 m_bTerminated
= sal_True
;
346 osl_setCondition(m_cTransformed
);
349 OUString
XSLTFilter::rel2abs(const OUString
& s
)
352 Reference
< XStringSubstitution
> subs(m_rServiceFactory
->createInstance(
353 OUString::createFromAscii("com.sun.star.util.PathSubstitution")), UNO_QUERY
);
354 OUString aWorkingDir
= subs
->getSubstituteVariableValue(OUString::createFromAscii("$(progurl)"));
355 INetURLObject
aObj( aWorkingDir
);
356 aObj
.setFinalSlash();
358 INetURLObject aURL
= aObj
.smartRel2Abs(
359 s
, bWasAbsolute
, false, INetURLObject::WAS_ENCODED
, RTL_TEXTENCODING_UTF8
, true );
360 return aURL
.GetMainURL(INetURLObject::NO_DECODE
);
365 sal_Bool
XSLTFilter::importer(
366 const Sequence
<PropertyValue
>& aSourceData
,
367 const Reference
<XDocumentHandler
>& xHandler
,
368 const Sequence
<OUString
>& msUserData
)
369 throw (RuntimeException
)
371 if ( msUserData
.getLength() < 5 )
374 OUString udImport
= msUserData
[2];
375 OUString udStyleSheet
= rel2abs(msUserData
[4]);
377 // get information from media descriptor
378 // the imput stream that represents the imported file
379 // is most important here since we need to supply it to
380 // the sax parser that drives the supplied document handler
381 sal_Int32 nLength
= aSourceData
.getLength();
382 OUString aName
, aFileName
, aURL
;
383 Reference
< XInputStream
> xInputStream
;
384 for ( sal_Int32 i
= 0 ; i
< nLength
; i
++)
386 aName
= aSourceData
[i
].Name
;
387 if (aName
.equalsAscii("InputStream"))
388 aSourceData
[i
].Value
>>= xInputStream
;
389 else if ( aName
.equalsAscii("FileName"))
390 aSourceData
[i
].Value
>>= aFileName
;
391 else if ( aName
.equalsAscii("URL"))
392 aSourceData
[i
].Value
>>= aURL
;
394 OSL_ASSERT(xInputStream
.is());
395 if (!xInputStream
.is()) return sal_False
;
397 // create SAX parser that will read the document file
398 // and provide events to xHandler passed to this call
399 Reference
< XParser
> xSaxParser( m_rServiceFactory
->createInstance(
400 OUString::createFromAscii("com.sun.star.xml.sax.Parser")), UNO_QUERY
);
401 OSL_ASSERT(xSaxParser
.is());
402 if(!xSaxParser
.is())return sal_False
;
404 // create transformer
405 Sequence
< Any
> args(3);
408 nv
.Name
= OUString::createFromAscii("StylesheetURL");
409 nv
.Value
<<= expandUrl(udStyleSheet
); args
[0] <<= nv
;
410 nv
.Name
= OUString::createFromAscii("SourceURL");
411 nv
.Value
<<= aURL
; args
[1] <<= nv
;
412 nv
.Name
= OUString::createFromAscii("SourceBaseURL");
413 nv
.Value
<<= OUString(INetURLObject(aURL
).getBase());
416 m_tcontrol
= Reference
< XActiveDataControl
>(m_rServiceFactory
->createInstanceWithArguments(
417 OUString::createFromAscii("com.sun.star.comp.JAXTHelper"), args
), UNO_QUERY
);
419 OSL_ASSERT(xHandler
.is());
420 OSL_ASSERT(xInputStream
.is());
421 OSL_ASSERT(m_tcontrol
.is());
422 if (xHandler
.is() && xInputStream
.is() && m_tcontrol
.is())
426 // we want to be notfied when the processing is done...
427 m_tcontrol
->addListener(Reference
< XStreamListener
>(this));
429 // connect input to transformer
430 Reference
< XActiveDataSink
> tsink(m_tcontrol
, UNO_QUERY
);
431 tsink
->setInputStream(xInputStream
);
434 Reference
< XOutputStream
> pipeout(m_rServiceFactory
->createInstance(
435 OUString::createFromAscii("com.sun.star.io.Pipe")), UNO_QUERY
);
436 Reference
< XInputStream
> pipein(pipeout
, UNO_QUERY
);
438 //connect transformer to pipe
439 Reference
< XActiveDataSource
> tsource(m_tcontrol
, UNO_QUERY
);
440 tsource
->setOutputStream(pipeout
);
442 // connect pipe to sax parser
444 aInput
.sSystemId
= aURL
;
445 aInput
.sPublicId
= aURL
;
446 aInput
.aInputStream
= pipein
;
449 xSaxParser
->setDocumentHandler(new FLABridge(xHandler
));
453 // osl_waitCondition(m_cTransformed, 0);
454 if (!m_bError
&& !m_bTerminated
)
456 // parse the transformed XML buffered in the pipe
457 xSaxParser
->parseStream(aInput
);
458 osl_waitCondition(m_cTransformed
, 0);
464 #if OSL_DEBUG_LEVEL > 0
465 catch( Exception
& exc
)
470 // something went wrong
471 OSL_ENSURE(0, OUStringToOString(exc
.Message
, RTL_TEXTENCODING_ASCII_US
).getStr());
480 sal_Bool
XSLTFilter::exporter(
481 const Sequence
<PropertyValue
>& aSourceData
,
482 const Sequence
<OUString
>& msUserData
)
483 throw (RuntimeException
)
485 if ( msUserData
.getLength() < 6 )
488 // get interesting values from user data
489 OUString udImport
= msUserData
[2];
490 OUString udStyleSheet
= rel2abs(msUserData
[5]);
493 // we are especialy interested in the output stream
494 // since that is where our xml-writer will push the data
495 // from it's data-source interface
496 OUString aName
, sURL
;
497 sal_Bool bIndent
= sal_False
;
498 OUString aDoctypePublic
;
499 OUString aDoctypeSystem
;
500 // Reference<XOutputStream> rOutputStream;
501 sal_Int32 nLength
= aSourceData
.getLength();
502 for ( sal_Int32 i
= 0 ; i
< nLength
; i
++)
504 aName
= aSourceData
[i
].Name
;
505 if ( aName
.equalsAscii("Indent"))
506 aSourceData
[i
].Value
>>= bIndent
;
507 if ( aName
.equalsAscii("DocType_Public"))
508 aSourceData
[i
].Value
>>= aDoctypePublic
;
509 if ( aName
.equalsAscii("DocType_System"))
510 aSourceData
[i
].Value
>>= aDoctypeSystem
;
511 if ( aName
.equalsAscii("OutputStream"))
512 aSourceData
[i
].Value
>>= m_rOutputStream
;
513 else if ( aName
.equalsAscii("URL" ))
514 aSourceData
[i
].Value
>>= sURL
;
517 if (!m_rDocumentHandler
.is()) {
518 // get the document writer
519 m_rDocumentHandler
= Reference
<XExtendedDocumentHandler
>(
520 m_rServiceFactory
->createInstance(
521 OUString::createFromAscii("com.sun.star.xml.sax.Writer")),
525 // create transformer
526 Sequence
< Any
> args(4);
528 nv
.Name
= OUString::createFromAscii("StylesheetURL");
529 nv
.Value
<<= expandUrl(udStyleSheet
); args
[0] <<= nv
;
530 nv
.Name
= OUString::createFromAscii("TargetURL");
531 nv
.Value
<<= sURL
; args
[1] <<= nv
;
532 nv
.Name
= OUString::createFromAscii("DoctypeSystem");
533 nv
.Value
<<= aDoctypeSystem
; args
[2] <<= nv
;
534 nv
.Name
= OUString::createFromAscii("DoctypePublic");
535 nv
.Value
<<= aDoctypePublic
; args
[3] <<= nv
;
536 nv
.Name
= OUString::createFromAscii("TargetBaseURL");
537 INetURLObject
ineturl(sURL
);
538 ineturl
.removeSegment();
539 m_aExportBaseUrl
= ineturl
.GetMainURL(INetURLObject::NO_DECODE
);
540 nv
.Value
<<= m_aExportBaseUrl
;
543 m_tcontrol
= Reference
< XActiveDataControl
>(m_rServiceFactory
->createInstanceWithArguments(
544 OUString::createFromAscii("com.sun.star.comp.JAXTHelper"), args
), UNO_QUERY
);
546 OSL_ASSERT(m_rDocumentHandler
.is());
547 OSL_ASSERT(m_rOutputStream
.is());
548 OSL_ASSERT(m_tcontrol
.is());
549 if (m_tcontrol
.is() && m_rOutputStream
.is() && m_rDocumentHandler
.is())
551 // we want to be notfied when the processing is done...
552 m_tcontrol
->addListener(Reference
< XStreamListener
>(this));
555 Reference
< XOutputStream
> pipeout(m_rServiceFactory
->createInstance(
556 OUString::createFromAscii("com.sun.star.io.Pipe")), UNO_QUERY
);
557 Reference
< XInputStream
> pipein(pipeout
, UNO_QUERY
);
559 // connect sax writer to pipe
560 Reference
< XActiveDataSource
> xmlsource(m_rDocumentHandler
, UNO_QUERY
);
561 xmlsource
->setOutputStream(pipeout
);
563 // connect pipe to transformer
564 Reference
< XActiveDataSink
> tsink(m_tcontrol
, UNO_QUERY
);
565 tsink
->setInputStream(pipein
);
567 // connect transformer to output
568 Reference
< XActiveDataSource
> tsource(m_tcontrol
, UNO_QUERY
);
569 tsource
->setOutputStream(m_rOutputStream
);
571 // we will start receiving events after returning 'true'.
572 // we will start the transformation as soon as we receive the startDocument
582 // for the DocumentHandler implementation, we just proxy the the
583 // events to the XML writer that we created upon the output stream
584 // that was provided by the XMLFilterAdapter
585 void XSLTFilter::startDocument() throw (SAXException
,RuntimeException
){
586 OSL_ASSERT(m_rDocumentHandler
.is());
587 m_rDocumentHandler
->startDocument();
591 void XSLTFilter::endDocument() throw (SAXException
, RuntimeException
){
592 OSL_ASSERT(m_rDocumentHandler
.is());
593 m_rDocumentHandler
->endDocument();
594 // wait for the transformer to finish
595 osl_waitCondition(m_cTransformed
, 0);
596 if (!m_bError
&& !m_bTerminated
)
600 throw RuntimeException();
605 void XSLTFilter::startElement(const OUString
& str
, const Reference
<XAttributeList
>& attriblist
)
606 throw (SAXException
, RuntimeException
)
608 OSL_ASSERT(m_rDocumentHandler
.is());
609 // SvXMLAttributeList* _attriblist=SvXMLAttributeList::getImplementation(attriblist);
610 m_rDocumentHandler
->startElement(str
, attriblist
);
613 void XSLTFilter::endElement(const OUString
& str
)
614 throw (SAXException
, RuntimeException
)
616 OSL_ASSERT(m_rDocumentHandler
.is());
617 m_rDocumentHandler
->endElement(str
);
620 void XSLTFilter::characters(const OUString
& str
)
621 throw (SAXException
, RuntimeException
)
623 OSL_ASSERT(m_rDocumentHandler
.is());
624 m_rDocumentHandler
->characters(str
);
627 void XSLTFilter::ignorableWhitespace(const OUString
& str
)
628 throw (SAXException
, RuntimeException
)
630 OSL_ASSERT(m_rDocumentHandler
.is());
631 if (!m_bPrettyPrint
) return;
632 m_rDocumentHandler
->ignorableWhitespace(str
);
635 void XSLTFilter::processingInstruction(const OUString
& str
, const OUString
& str2
)
636 throw (SAXException
, RuntimeException
)
638 OSL_ASSERT(m_rDocumentHandler
.is());
639 m_rDocumentHandler
->processingInstruction(str
, str2
);
642 void XSLTFilter::setDocumentLocator(const Reference
<XLocator
>& doclocator
)
643 throw (SAXException
, RuntimeException
)
645 OSL_ASSERT(m_rDocumentHandler
.is());
646 m_rDocumentHandler
->setDocumentLocator(doclocator
);
649 // --------------------------------------
650 // Component management
651 // --------------------------------------
652 #define SERVICE_NAME "com.sun.star.documentconversion.XSLTFilter"
653 #define IMPLEMENTATION_NAME "com.sun.star.comp.documentconversion.XSLTFilter"
655 static Reference
< XInterface
> SAL_CALL
CreateInstance( const Reference
< XMultiServiceFactory
> &r
)
657 return Reference
< XInterface
>(( OWeakObject
*)new XSLTFilter(r
));
660 static Sequence
< OUString
> getSupportedServiceNames()
662 static Sequence
< OUString
> *pNames
= 0;
665 MutexGuard
guard( Mutex::getGlobalMutex() );
668 static Sequence
< OUString
> seqNames(1);
669 seqNames
.getArray()[0] = OUString::createFromAscii(SERVICE_NAME
);
678 using namespace XSLT
;
682 void SAL_CALL
component_getImplementationEnvironment(
683 const sal_Char
** ppEnvTypeName
, uno_Environment
** /* ppEnv */ )
685 *ppEnvTypeName
= CPPU_CURRENT_LANGUAGE_BINDING_NAME
;
688 sal_Bool SAL_CALL
component_writeInfo(void * /* pServiceManager */, void * pRegistryKey
)
694 Reference
< XRegistryKey
> xNewKey(
695 reinterpret_cast< XRegistryKey
* >( pRegistryKey
)->createKey(
696 OUString::createFromAscii( "/" IMPLEMENTATION_NAME
"/UNO/SERVICES" ) ) );
698 const Sequence
< OUString
> & rSNL
= getSupportedServiceNames();
699 const OUString
* pArray
= rSNL
.getConstArray();
700 for ( sal_Int32 nPos
= rSNL
.getLength(); nPos
--; )
701 xNewKey
->createKey( pArray
[nPos
] );
705 catch (InvalidRegistryException
&)
707 OSL_ENSURE( sal_False
, "### InvalidRegistryException!" );
713 void * SAL_CALL
component_getFactory(
714 const sal_Char
* pImplName
, void * pServiceManager
, void * /* pRegistryKey */ )
718 if (pServiceManager
&& rtl_str_compare( pImplName
, IMPLEMENTATION_NAME
) == 0)
720 Reference
< XSingleServiceFactory
> xFactory( createSingleFactory(
721 reinterpret_cast< XMultiServiceFactory
* >( pServiceManager
),
722 OUString::createFromAscii( pImplName
),
723 CreateInstance
, getSupportedServiceNames() ) );
728 pRet
= xFactory
.get();