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 : : #ifndef LOGHANDLER_HXX
30 : : #define LOGHANDLER_HXX
31 : :
32 : : #include <com/sun/star/logging/XLogFormatter.hpp>
33 : : #include <com/sun/star/uno/XComponentContext.hpp>
34 : : #include <com/sun/star/logging/LogRecord.hpp>
35 : :
36 : : #include <comphelper/namedvaluecollection.hxx>
37 : : #include <cppuhelper/interfacecontainer.hxx>
38 : : #include <rtl/string.hxx>
39 : :
40 : : //........................................................................
41 : : namespace logging
42 : : {
43 : : //........................................................................
44 : :
45 : : //====================================================================
46 : : //=
47 : : //====================================================================
48 : 0 : class LogHandlerHelper
49 : : {
50 : : private:
51 : : // <attributes>
52 : : rtl_TextEncoding m_eEncoding;
53 : : sal_Int32 m_nLevel;
54 : : ::com::sun::star::uno::Reference< ::com::sun::star::logging::XLogFormatter >
55 : : m_xFormatter;
56 : : // <//attributes>
57 : :
58 : : ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >
59 : : m_xContext;
60 : : ::osl::Mutex& m_rMutex;
61 : : ::cppu::OBroadcastHelper& m_rBHelper;
62 : : bool m_bInitialized;
63 : :
64 : : public:
65 : : LogHandlerHelper(
66 : : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext,
67 : : ::osl::Mutex& _rMutex,
68 : : ::cppu::OBroadcastHelper& _rBHelper
69 : : );
70 : :
71 : : public:
72 : 27 : bool getIsInitialized() const { return m_bInitialized; }
73 : 9 : void setIsInitialized() { m_bInitialized = true; }
74 : :
75 : : bool getEncoding( ::rtl::OUString& _out_rEncoding ) const;
76 : : bool setEncoding( const ::rtl::OUString& _rEncoding );
77 : :
78 : : inline rtl_TextEncoding
79 : 0 : getTextEncoding() const { return m_eEncoding; }
80 : :
81 : : inline ::com::sun::star::uno::Reference< ::com::sun::star::logging::XLogFormatter >
82 : 18 : getFormatter() const { return m_xFormatter; }
83 : : inline void
84 : 18 : setFormatter( const ::com::sun::star::uno::Reference< ::com::sun::star::logging::XLogFormatter >& _rxFormatter )
85 : : {
86 : 18 : m_xFormatter = _rxFormatter;
87 : 18 : }
88 : :
89 : : inline sal_Int32
90 : 0 : getLevel() const { return m_nLevel; }
91 : : inline void
92 : 9 : setLevel( const sal_Int32 _nLevel )
93 : : {
94 : 9 : m_nLevel = _nLevel;
95 : 9 : }
96 : :
97 : : /** prepares implementation of an public accessible method of a log handler
98 : :
99 : : <code>enterMethod</code> does the following things:
100 : : <ul><li>It acquires the mutex given in the constructor.</li>
101 : : <li>It checks whether the component is already initialized, and throws an exception if not os.</li>
102 : : <li>It checks whether the component is already disposed, and throws an exception if not os.</li>
103 : : <li>It creates a default formatter (PlainTextFormatter), if no formatter exists at this time.</li>
104 : : </ul>
105 : : */
106 : : void enterMethod();
107 : :
108 : : /** formats a record for publishing it
109 : :
110 : : The method first checks whether the records log level is greater or equal our own
111 : : log level. If not, <FALSE/> is returned.
112 : :
113 : : Second, our formatter is used to create a unicode string from the log record. If an error occurs
114 : : during this, e.g. if the formatter is <NULL/> or throws an exception during formatting,
115 : : <FALSE/> is returned.
116 : :
117 : : Finally, the unicode string is encoded into a byte string, using our encoding setting. Then,
118 : : <TRUE/> is returned.
119 : : */
120 : : bool formatForPublishing( const ::com::sun::star::logging::LogRecord& _rRecord, ::rtl::OString& _out_rEntry ) const;
121 : :
122 : : /** retrieves our formatter's heading, encoded with our encoding
123 : :
124 : : @return <TRUE/> in case of success, <FALSE/> if any error occurred
125 : : */
126 : : bool getEncodedHead( ::rtl::OString& _out_rHead ) const;
127 : :
128 : : /** retrieves our formatter's tail, encoded with our encoding
129 : :
130 : : @return <TRUE/> in case of success, <FALSE/> if any error occurred
131 : : */
132 : : bool getEncodedTail( ::rtl::OString& _out_rTail ) const;
133 : :
134 : : /** initializes the instance from a collection of named settings
135 : :
136 : : The recognized named settings are <code>Encoding</code>, <code>Formatter</code>, and <code>Level</code>,
137 : : which initialize the respective attributes.
138 : :
139 : : Settings which are recognized are remove from the given collection. This allows
140 : : the caller to determine whether or not the collection contained any unsupported
141 : : items, and react appropriately.
142 : :
143 : : @throws IllegalArgumentException
144 : : if one of the values in the collection is of wrong type.
145 : : */
146 : : void initFromSettings( const ::comphelper::NamedValueCollection& _rSettings );
147 : : };
148 : :
149 : : //........................................................................
150 : : } // namespace logging
151 : : //........................................................................
152 : :
153 : : #endif // LOGHANDLER_HXX
154 : :
155 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|