1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _FILTERTRACER_HXX
25 #define _FILTERTRACER_HXX
26 
27 #include <rtl/ustring.hxx>
28 #include <tools/debug.hxx>
29 #include <tools/stream.hxx>
30 #include <tools/string.hxx>
31 #include <tools/urlobj.hxx>
32 #include <tools/stack.hxx>
33 
34 #include <com/sun/star/uno/Reference.h>
35 #include <com/sun/star/uno/RuntimeException.hpp>
36 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
37 #include <com/sun/star/lang/XComponent.hpp>
38 #include <com/sun/star/registry/XRegistryKey.hpp>
39 #include <com/sun/star/lang/XComponent.hpp>
40 #include <cppuhelper/implbase1.hxx>
41 #include <cppuhelper/implbase4.hxx>
42 #include <com/sun/star/beans/PropertyValue.hpp>
43 #include <com/sun/star/lang/XInitialization.hpp>
44 #include <com/sun/star/lang/XServiceInfo.hpp>
45 #include <com/sun/star/util/logging/XLogger.hpp>
46 #include <com/sun/star/util/logging/LogLevel.hpp>
47 #include <com/sun/star/io/XOutputStream.hpp>
48 #include <com/sun/star/util/XTextSearch.hpp>
49 #include <com/sun/star/util/SearchResult.hpp>
50 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
51 
52 // -----------------------------------------------------------------------------
53 
54 #define NMSP_IO			com::sun::star::io
55 #define NMSP_UNO		com::sun::star::uno
56 #define NMSP_BEANS      com::sun::star::beans
57 #define NMSP_LANG		com::sun::star::lang
58 #define NMSP_UTIL		com::sun::star::util
59 #define NMSP_SAX		com::sun::star::xml::sax
60 #define NMSP_LOGGING	NMSP_UTIL::logging
61 
62 
63 #define REF( _def_Obj )         NMSP_UNO::Reference< _def_Obj >
64 #define SEQ( _def_Obj )         NMSP_UNO::Sequence< _def_Obj >
65 #define B2UCONST( _def_pChar )  (rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(_def_pChar )))
66 
67 // ----------------
68 // - FILTERTRACER -
69 // ----------------
70 //
71 
72 /** Some options of the FilterTracer can be initialized
73     via XInitialization interface.
74 
75 	Therefore the first sequence of	PropertyValues that
76 	is given in the argument list is used.
77 
78 	Following Properties are supported:
79 
80 	OutputStream	com.sun.star.io.XOutputStream	Defines the output stream. Optional it is possible to provide
81 													the URL property, then the corresponding output stream will
82 													be generated automatically.
83 
84 	URL				string							Defines the URL, which is used to create an output stream.
85 													This property is used only, if there is no valid
86 													OutputStream property available.
87 
88 	DocumentHandler	com.sun.star.xml.sax.XDocumentHandler	The output can also be written to a DocumentHandler,
89 															then the "characters" method of the handler is used.
90 
91     LogLevel		long							Defines the LogLevel for the FilterTracer.
92 													Using logp with a LogLevel that is higher as the LogLevel
93 													for	the FilterTracer component will generate no output.
94 													LogLevel constants are defined in sun::star::util::logging::LogLevel
95 													The default LogLevel com::sun::star::logging::LogLevel::ALL
96 
97 	ClassFilter		string							This property defines a filter for the SourceClass string of logp.
98 													The ClassFilter string can be separated into multiple tokens using
99 													a semicolon. If one of the ClassFilter token is part of the
100 													SourceClass string of the logp method then there will be no output.
101 
102 	MethodFilter	string							This property defines a filter for the SourceMethod string of logp.
103 													The MethodFilter string can be separated into multiple tokens using
104 													a semicolon. If one of the MethodFilter token is part of the
105 													SourceMethod string of the logp method then there will be no output.
106 
107 	MessageFilter	string							This property defines a filter for the Message string of logp.
108 													The MessageFilter string can be separated into multiple tokens using
109 													a semicolon. If one of the MessageFilter token is part of the
110 													Message string of the logp method then there will be no output.
111 
112 */
113 
114 class FilterTracer : public cppu::WeakImplHelper4
115 <
116 	NMSP_LOGGING::XLogger,
117 	NMSP_LANG::XInitialization,
118 	NMSP_LANG::XServiceInfo,
119 	NMSP_UTIL::XTextSearch
120 >
121 {
122 	REF( NMSP_LANG::XMultiServiceFactory )	xFact;
123 	SvStream*		mpStream;
124 
125 	sal_Int32		mnLogLevel;
126 	rtl::OUString	msClassFilter;
127 	rtl::OUString	msMethodFilter;
128 	rtl::OUString	msMessageFilter;
129 	rtl::OUString	msURL;
130 
131 	REF( NMSP_IO::XOutputStream )		mxOutputStream;
132 	REF( NMSP_SAX::XDocumentHandler)	mxDocumentHandler;
133 
134 	REF( NMSP_UTIL::XTextSearch )		mxTextSearch;
135 	NMSP_UTIL::SearchOptions			maSearchOptions;
136 
137 	sal_Bool				ImplFilter( const rtl::OUString& rFilter, const rtl::OUString& rString );
138 
139 public:
140 							FilterTracer( const REF( NMSP_LANG::XMultiServiceFactory )& rxMgr );
141 	virtual 				~FilterTracer();
142 
143 	// XInterface
144     virtual void SAL_CALL	acquire() throw();
145     virtual void SAL_CALL	release() throw();
146 
147 	// XInitialization
148     virtual void SAL_CALL initialize( const SEQ( NMSP_UNO::Any )& aArguments )
149 		throw ( NMSP_UNO::Exception, NMSP_UNO::RuntimeException );
150 
151 	// XServiceInfo
152     virtual rtl::OUString SAL_CALL getImplementationName()
153 		throw ( NMSP_UNO::RuntimeException );
154     virtual sal_Bool SAL_CALL supportsService( const rtl::OUString& rServiceName )
155 		throw ( NMSP_UNO::RuntimeException );
156     virtual SEQ( rtl::OUString ) SAL_CALL getSupportedServiceNames()
157 		throw ( NMSP_UNO::RuntimeException );
158 
159 	// XLogger
160     virtual REF( NMSP_LOGGING::XLogger ) SAL_CALL getLogger( const rtl::OUString& rName ) throw (::com::sun::star::uno::RuntimeException);
161     virtual sal_Int32 SAL_CALL getLevel() throw (::com::sun::star::uno::RuntimeException);
162 	virtual rtl::OUString SAL_CALL getName() throw (::com::sun::star::uno::RuntimeException);
163 	virtual sal_Bool SAL_CALL isLoggable( sal_Int32 nLevel ) throw (::com::sun::star::uno::RuntimeException);
164 	virtual void SAL_CALL logp( sal_Int32 nLevel, const rtl::OUString& rSourceClass,
165 					const rtl::OUString& rSourceMethod, const rtl::OUString& rMessage ) throw (::com::sun::star::uno::RuntimeException);
166 
167 	// XTextSearch
168 	virtual void SAL_CALL setOptions( const NMSP_UTIL::SearchOptions& ) throw (::com::sun::star::uno::RuntimeException);
169 	virtual NMSP_UTIL::SearchResult SAL_CALL searchForward( const rtl::OUString& rSearchStr,
170 		sal_Int32 nStartPos, sal_Int32 nEndPos ) throw (::com::sun::star::uno::RuntimeException);
171 	virtual NMSP_UTIL::SearchResult SAL_CALL searchBackward( const rtl::OUString& rSearchStr,
172 		sal_Int32 nStartPos, sal_Int32 nEndPos ) throw (::com::sun::star::uno::RuntimeException);
173 };
174 
175 rtl::OUString FilterTracer_getImplementationName()
176 	throw ( NMSP_UNO::RuntimeException );
177 sal_Bool SAL_CALL FilterTracer_supportsService( const rtl::OUString& rServiceName )
178 	throw( NMSP_UNO::RuntimeException );
179 SEQ( rtl::OUString ) SAL_CALL FilterTracer_getSupportedServiceNames()
180 	throw( NMSP_UNO::RuntimeException );
181 
182 #endif
183