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: filtertracer.hxx,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 #ifndef _FILTERTRACER_HXX
32 #define _FILTERTRACER_HXX
34 #include <rtl/ustring.hxx>
35 #include <tools/debug.hxx>
36 #include <tools/stream.hxx>
37 #include <tools/string.hxx>
38 #include <tools/urlobj.hxx>
39 #include <tools/stack.hxx>
41 #include <com/sun/star/uno/Reference.h>
42 #include <com/sun/star/uno/RuntimeException.hpp>
43 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
44 #include <com/sun/star/lang/XComponent.hpp>
45 #include <com/sun/star/registry/XRegistryKey.hpp>
46 #include <com/sun/star/lang/XComponent.hpp>
47 #include <cppuhelper/implbase1.hxx>
48 #include <cppuhelper/implbase4.hxx>
49 #include <com/sun/star/beans/PropertyValue.hpp>
50 #include <com/sun/star/lang/XInitialization.hpp>
51 #include <com/sun/star/lang/XServiceInfo.hpp>
52 #include <com/sun/star/util/logging/XLogger.hpp>
53 #include <com/sun/star/util/logging/LogLevel.hpp>
54 #include <com/sun/star/io/XOutputStream.hpp>
55 #include <com/sun/star/util/XTextSearch.hpp>
56 #include <com/sun/star/util/SearchResult.hpp>
57 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
59 // -----------------------------------------------------------------------------
61 #define NMSP_IO com::sun::star::io
62 #define NMSP_UNO com::sun::star::uno
63 #define NMSP_BEANS com::sun::star::beans
64 #define NMSP_LANG com::sun::star::lang
65 #define NMSP_UTIL com::sun::star::util
66 #define NMSP_SAX com::sun::star::xml::sax
67 #define NMSP_LOGGING NMSP_UTIL::logging
70 #define REF( _def_Obj ) NMSP_UNO::Reference< _def_Obj >
71 #define SEQ( _def_Obj ) NMSP_UNO::Sequence< _def_Obj >
72 #define B2UCONST( _def_pChar ) (rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(_def_pChar )))
79 /** Some options of the FilterTracer can be initialized
80 via XInitialization interface.
82 Therefore the first sequence of PropertyValues that
83 is given in the argument list is used.
85 Following Properties are supported:
87 OutputStream com.sun.star.io.XOutputStream Defines the output stream. Optional it is possible to provide
88 the URL property, then the corresponding output stream will
89 be generated automatically.
91 URL string Defines the URL, which is used to create an output stream.
92 This property is used only, if there is no valid
93 OutputStream property available.
95 DocumentHandler com.sun.star.xml.sax.XDocumentHandler The output can also be written to a DocumentHandler,
96 then the "characters" method of the handler is used.
98 LogLevel long Defines the LogLevel for the FilterTracer.
99 Using logp with a LogLevel that is higher as the LogLevel
100 for the FilterTracer component will generate no output.
101 LogLevel constants are defined in sun::star::util::logging::LogLevel
102 The default LogLevel com::sun::star::logging::LogLevel::ALL
104 ClassFilter string This property defines a filter for the SourceClass string of logp.
105 The ClassFilter string can be separated into multiple tokens using
106 a semicolon. If one of the ClassFilter token is part of the
107 SourceClass string of the logp method then there will be no output.
109 MethodFilter string This property defines a filter for the SourceMethod string of logp.
110 The MethodFilter string can be separated into multiple tokens using
111 a semicolon. If one of the MethodFilter token is part of the
112 SourceMethod string of the logp method then there will be no output.
114 MessageFilter string This property defines a filter for the Message string of logp.
115 The MessageFilter string can be separated into multiple tokens using
116 a semicolon. If one of the MessageFilter token is part of the
117 Message string of the logp method then there will be no output.
121 class FilterTracer
: public cppu::WeakImplHelper4
123 NMSP_LOGGING::XLogger
,
124 NMSP_LANG::XInitialization
,
125 NMSP_LANG::XServiceInfo
,
126 NMSP_UTIL::XTextSearch
129 REF( NMSP_LANG::XMultiServiceFactory
) xFact
;
132 sal_Int32 mnLogLevel
;
133 rtl::OUString msClassFilter
;
134 rtl::OUString msMethodFilter
;
135 rtl::OUString msMessageFilter
;
138 REF( NMSP_IO::XOutputStream
) mxOutputStream
;
139 REF( NMSP_SAX::XDocumentHandler
) mxDocumentHandler
;
141 REF( NMSP_UTIL::XTextSearch
) mxTextSearch
;
142 NMSP_UTIL::SearchOptions maSearchOptions
;
144 sal_Bool
ImplFilter( const rtl::OUString
& rFilter
, const rtl::OUString
& rString
);
147 FilterTracer( const REF( NMSP_LANG::XMultiServiceFactory
)& rxMgr
);
148 virtual ~FilterTracer();
151 virtual void SAL_CALL
acquire() throw();
152 virtual void SAL_CALL
release() throw();
155 virtual void SAL_CALL
initialize( const SEQ( NMSP_UNO::Any
)& aArguments
)
156 throw ( NMSP_UNO::Exception
, NMSP_UNO::RuntimeException
);
159 virtual rtl::OUString SAL_CALL
getImplementationName()
160 throw ( NMSP_UNO::RuntimeException
);
161 virtual sal_Bool SAL_CALL
supportsService( const rtl::OUString
& rServiceName
)
162 throw ( NMSP_UNO::RuntimeException
);
163 virtual SEQ( rtl::OUString
) SAL_CALL
getSupportedServiceNames()
164 throw ( NMSP_UNO::RuntimeException
);
167 virtual REF( NMSP_LOGGING::XLogger
) SAL_CALL
getLogger( const rtl::OUString
& rName
) throw (::com::sun::star::uno::RuntimeException
);
168 virtual sal_Int32 SAL_CALL
getLevel() throw (::com::sun::star::uno::RuntimeException
);
169 virtual rtl::OUString SAL_CALL
getName() throw (::com::sun::star::uno::RuntimeException
);
170 virtual sal_Bool SAL_CALL
isLoggable( sal_Int32 nLevel
) throw (::com::sun::star::uno::RuntimeException
);
171 virtual void SAL_CALL
logp( sal_Int32 nLevel
, const rtl::OUString
& rSourceClass
,
172 const rtl::OUString
& rSourceMethod
, const rtl::OUString
& rMessage
) throw (::com::sun::star::uno::RuntimeException
);
175 virtual void SAL_CALL
setOptions( const NMSP_UTIL::SearchOptions
& ) throw (::com::sun::star::uno::RuntimeException
);
176 virtual NMSP_UTIL::SearchResult SAL_CALL
searchForward( const rtl::OUString
& rSearchStr
,
177 sal_Int32 nStartPos
, sal_Int32 nEndPos
) throw (::com::sun::star::uno::RuntimeException
);
178 virtual NMSP_UTIL::SearchResult SAL_CALL
searchBackward( const rtl::OUString
& rSearchStr
,
179 sal_Int32 nStartPos
, sal_Int32 nEndPos
) throw (::com::sun::star::uno::RuntimeException
);
182 rtl::OUString
FilterTracer_getImplementationName()
183 throw ( NMSP_UNO::RuntimeException
);
184 sal_Bool SAL_CALL
FilterTracer_supportsService( const rtl::OUString
& rServiceName
)
185 throw( NMSP_UNO::RuntimeException
);
186 SEQ( rtl::OUString
) SAL_CALL
FilterTracer_getSupportedServiceNames()
187 throw( NMSP_UNO::RuntimeException
);