merge the formfield patch from ooo-build
[ooovba.git] / filter / source / filtertracer / filtertracer.cxx
blobbbf9e1e1ef71e178f2c3fcfc0e9c2addcca477cc
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: filtertracer.cxx,v $
10 * $Revision: 1.7 $
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"
33 #include "filtertracer.hxx"
34 #include <uno/mapping.hxx>
35 #include <unotools/streamwrap.hxx>
36 #include <unotools/ucbstreamhelper.hxx>
37 // ----------------
38 // - FILTERTRACER -
39 // ----------------
41 rtl::OUString FilterTracer_getImplementationName()
42 throw( NMSP_UNO::RuntimeException )
44 return B2UCONST( "com.sun.star.util.FilterTracer" );
46 sal_Bool SAL_CALL FilterTracer_supportsService( const rtl::OUString& ServiceName )
47 throw( NMSP_UNO::RuntimeException )
49 return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.util.logging.Logger" ) );
51 SEQ( rtl::OUString ) SAL_CALL FilterTracer_getSupportedServiceNames()
52 throw( NMSP_UNO::RuntimeException )
54 SEQ( rtl::OUString ) aRet(1);
55 rtl::OUString* pArray = aRet.getArray();
56 pArray[0] = B2UCONST( "com.sun.star.util.logging.Logger" );
57 return aRet;
60 // -----------------------------------------------------------------------------
62 FilterTracer::FilterTracer( const REF( NMSP_LANG::XMultiServiceFactory )& rxMgr ) :
63 xFact ( rxMgr ),
64 mpStream ( NULL ),
65 mnLogLevel ( NMSP_LOGGING::LogLevel::ALL )
67 REF( NMSP_UNO::XInterface ) xObj( rxMgr->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.util.TextSearch" ) ) );
68 mxTextSearch = REF( NMSP_UTIL::XTextSearch )( xObj, ::com::sun::star::uno::UNO_QUERY );
70 FilterTracer::~FilterTracer()
72 if ( mpStream )
74 mxOutputStream = NULL;
75 delete mpStream;
79 // -----------------------------------------------------------------------------
81 // XInterface
82 void SAL_CALL FilterTracer::acquire() throw()
84 OWeakObject::acquire();
86 void SAL_CALL FilterTracer::release() throw()
88 OWeakObject::release();
91 // -----------------------------------------------------------------------------
93 // checks if the tokens of rFilter can be found in rString
94 sal_Bool FilterTracer::ImplFilter( const rtl::OUString& rFilter, const rtl::OUString& rString )
96 sal_Bool bFilter = sal_False;
97 if ( mxTextSearch.is() )
99 maSearchOptions.searchString = rFilter;
100 mxTextSearch->setOptions( maSearchOptions );
101 NMSP_UTIL::SearchResult aSearchResult = mxTextSearch->searchForward( rString, 0, rString.getLength() );
102 bFilter = aSearchResult.subRegExpressions != 0;
104 return bFilter;
107 // -----------------------------------------------------------------------------
109 // XInitialization
110 void SAL_CALL FilterTracer::initialize( const SEQ( NMSP_UNO::Any )& aArguments )
111 throw ( NMSP_UNO::Exception, NMSP_UNO::RuntimeException )
113 sal_Int32 i;
114 SEQ( NMSP_BEANS::PropertyValue ) aParameter;
115 for ( i = 0; i < aArguments.getLength(); i++ )
117 if ( aArguments[ i ] >>= aParameter )
118 break;
120 for ( i = 0; i < aParameter.getLength(); i++ )
122 const NMSP_BEANS::PropertyValue& rProp = aParameter[ i ];
123 if ( rProp.Name.equalsAscii( "LogLevel" ) )
124 rProp.Value >>= mnLogLevel;
125 else if ( rProp.Name.equalsAscii( "ClassFilter" ) )
126 rProp.Value >>= msClassFilter;
127 else if ( rProp.Name.equalsAscii( "MethodFilter" ) )
128 rProp.Value >>= msMethodFilter;
129 else if ( rProp.Name.equalsAscii( "MessageFilter" ) )
130 rProp.Value >>= msMessageFilter;
131 else if ( rProp.Name.equalsAscii( "OutputStream" ) )
132 rProp.Value >>= mxOutputStream;
133 else if ( rProp.Name.equalsAscii( "URL" ) )
134 rProp.Value >>= msURL;
135 else if ( rProp.Name.equalsAscii( "DocumentHandler" ) )
136 rProp.Value >>= mxDocumentHandler;
139 // check if we have to create the XOutputStream
140 if ( !mxOutputStream.is() && msURL.getLength() )
142 mpStream = ::utl::UcbStreamHelper::CreateStream( msURL, STREAM_WRITE | STREAM_TRUNC | STREAM_SHARE_DENYNONE );
143 if ( mpStream )
145 ::utl::OOutputStreamWrapper* pHelper = new ::utl::OOutputStreamWrapper( *mpStream );
146 mxOutputStream = pHelper;
151 // -----------------------------------------------------------------------------
153 // XServiceInfo
154 rtl::OUString SAL_CALL FilterTracer::getImplementationName()
155 throw( NMSP_UNO::RuntimeException )
157 return FilterTracer_getImplementationName();
159 sal_Bool SAL_CALL FilterTracer::supportsService( const rtl::OUString& rServiceName )
160 throw( NMSP_UNO::RuntimeException )
162 return FilterTracer_supportsService( rServiceName );
164 SEQ( rtl::OUString ) SAL_CALL FilterTracer::getSupportedServiceNames()
165 throw ( NMSP_UNO::RuntimeException )
167 return FilterTracer_getSupportedServiceNames();
170 // -----------------------------------------------------------------------------
172 // XLogger
173 REF( NMSP_LOGGING::XLogger ) SAL_CALL FilterTracer::getLogger( const rtl::OUString& /* rName */ )
174 throw (::com::sun::star::uno::RuntimeException)
176 REF( NMSP_LOGGING::XLogger ) xLog( this );
177 return xLog;
179 sal_Int32 SAL_CALL FilterTracer::getLevel() throw (::com::sun::star::uno::RuntimeException)
181 return mnLogLevel;
183 rtl::OUString SAL_CALL FilterTracer::getName() throw (::com::sun::star::uno::RuntimeException)
185 rtl::OUString aName;
186 return aName;
188 sal_Bool SAL_CALL FilterTracer::isLoggable( sal_Int32 nLevel )
189 throw (::com::sun::star::uno::RuntimeException)
191 return mnLogLevel <= nLevel;
193 void SAL_CALL FilterTracer::logp( sal_Int32 /* nLevel */, const rtl::OUString& rSourceClass,
194 const rtl::OUString& rSourceMethod, const rtl::OUString& rMessage )
195 throw (::com::sun::star::uno::RuntimeException)
197 if ( mxOutputStream.is() || mxDocumentHandler.is() )
199 if ( ! ( ImplFilter( msClassFilter, rSourceClass ) || ImplFilter( msMethodFilter, rSourceMethod )
200 || ImplFilter( msMessageFilter, rMessage ) ) )
202 rtl::OString sClass( rtl::OUStringToOString( rSourceClass, RTL_TEXTENCODING_UTF8 ) );
203 rtl::OString sMethod( rtl::OUStringToOString( rSourceMethod, RTL_TEXTENCODING_UTF8 ) );
204 rtl::OString sMessage( rtl::OUStringToOString( rMessage, RTL_TEXTENCODING_UTF8 ) );
207 SEQ( sal_Int8 ) aData( sClass.getLength() + sMethod.getLength() + sMessage.getLength() );
208 sal_Int8* pPtr = aData.getArray();
209 memcpy( pPtr, sClass.getStr(), sClass.getLength() );
210 pPtr += sClass.getLength();
211 memcpy( pPtr, sMethod.getStr(), sMethod.getLength() );
212 pPtr += sMethod.getLength();
213 memcpy( pPtr, sMessage.getStr(), sMessage.getLength() );
214 pPtr += sMessage.getLength();
215 if ( mxOutputStream.is() )
216 mxOutputStream->writeBytes( aData );
217 if ( mxDocumentHandler.is() )
218 mxDocumentHandler->characters( ::rtl::OUString( (sal_Char*)aData.getArray(), aData.getLength(), RTL_TEXTENCODING_UTF8 ) );
220 catch ( ... )
228 // -----------------------------------------------------------------------------
230 // XTextSearch
231 void SAL_CALL FilterTracer::setOptions( const NMSP_UTIL::SearchOptions& rSearchOptions )
232 throw (::com::sun::star::uno::RuntimeException)
234 maSearchOptions = rSearchOptions;
237 // -----------------------------------------------------------------------------
239 NMSP_UTIL::SearchResult SAL_CALL FilterTracer::searchForward( const rtl::OUString& rSearchStr,
240 sal_Int32 nStartPos, sal_Int32 nEndPos ) throw (::com::sun::star::uno::RuntimeException)
242 NMSP_UTIL::SearchResult nSearchResult;
243 if ( mxTextSearch.is() )
244 mxTextSearch->searchForward( rSearchStr, nStartPos, nEndPos );
245 return nSearchResult;
248 // -----------------------------------------------------------------------------
250 NMSP_UTIL::SearchResult SAL_CALL FilterTracer::searchBackward( const rtl::OUString& rSearchStr,
251 sal_Int32 nStartPos, sal_Int32 nEndPos ) throw (::com::sun::star::uno::RuntimeException)
253 NMSP_UTIL::SearchResult nSearchResult;
254 if ( mxTextSearch.is() )
255 mxTextSearch->searchBackward( rSearchStr, nStartPos, nEndPos );
256 return nSearchResult;