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 #include <rtl/ustrbuf.hxx>
25 #include <resourcemodel/LoggedResources.hxx>
26 #include <resourcemodel/QNameToString.hxx>
27 
28 namespace writerfilter
29 {
30 
31 // class: LoggedResourcesHelper
32 
LoggedResourcesHelper(TagLogger::Pointer_t pLogger,const string & sPrefix)33 LoggedResourcesHelper::LoggedResourcesHelper(TagLogger::Pointer_t pLogger, const string & sPrefix)
34 : mpLogger(pLogger), msPrefix(sPrefix)
35 {
36 }
37 
~LoggedResourcesHelper()38 LoggedResourcesHelper::~LoggedResourcesHelper()
39 {
40 }
41 
startElement(const string & sElement)42 void LoggedResourcesHelper::startElement(const string & sElement)
43 {
44     mpLogger->startElement(msPrefix + "." + sElement);
45 }
46 
endElement(const string & sElement)47 void LoggedResourcesHelper::endElement(const string & sElement)
48 {
49     mpLogger->endElement(msPrefix + "." + sElement);
50 }
51 
chars(const::rtl::OUString & rChars)52 void LoggedResourcesHelper::chars(const ::rtl::OUString & rChars)
53 {
54     mpLogger->chars(rChars);
55 }
56 
chars(const string & rChars)57 void LoggedResourcesHelper::chars(const string & rChars)
58 {
59     mpLogger->chars(rChars);
60 }
61 
attribute(const string & rName,const string & rValue)62 void LoggedResourcesHelper::attribute(const string & rName, const string & rValue)
63 {
64     mpLogger->attribute(rName, rValue);
65 }
66 
attribute(const string & rName,sal_uInt32 nValue)67 void LoggedResourcesHelper::attribute(const string & rName, sal_uInt32 nValue)
68 {
69     mpLogger->attribute(rName, nValue);
70 }
71 
setPrefix(const string & rPrefix)72 void LoggedResourcesHelper::setPrefix(const string & rPrefix)
73 {
74     msPrefix = rPrefix;
75 }
76 
77 // class: LoggedStream
78 
LoggedStream(TagLogger::Pointer_t pLogger,const string & sPrefix)79 LoggedStream::LoggedStream(TagLogger::Pointer_t pLogger, const string & sPrefix)
80 : mHelper(pLogger, sPrefix)
81 {
82 }
83 
~LoggedStream()84 LoggedStream::~LoggedStream()
85 {
86 }
87 
startSectionGroup()88 void LoggedStream::startSectionGroup()
89 {
90 #ifdef DEBUG_LOGGING
91     mHelper.startElement("section");
92 #endif
93 
94     lcl_startSectionGroup();
95 }
96 
endSectionGroup()97 void LoggedStream::endSectionGroup()
98 {
99     lcl_endSectionGroup();
100 
101 #ifdef DEBUG_LOGGING
102     mHelper.endElement("section");
103 #endif
104 }
105 
startParagraphGroup()106 void LoggedStream::startParagraphGroup()
107 {
108 #ifdef DEBUG_LOGGING
109     mHelper.startElement("paragraph");
110 #endif
111 
112     lcl_startParagraphGroup();
113 }
114 
endParagraphGroup()115 void LoggedStream::endParagraphGroup()
116 {
117     lcl_endParagraphGroup();
118 
119 #ifdef DEBUG_LOGGING
120     mHelper.endElement("paragraph");
121 #endif
122 }
123 
124 
startCharacterGroup()125 void LoggedStream::startCharacterGroup()
126 {
127 #ifdef DEBUG_LOGGING
128     mHelper.startElement("charactergroup");
129 #endif
130 
131     lcl_startCharacterGroup();
132 }
133 
endCharacterGroup()134 void LoggedStream::endCharacterGroup()
135 {
136     lcl_endCharacterGroup();
137 
138 #ifdef DEBUG_LOGGING
139     mHelper.endElement("charactergroup");
140 #endif
141 }
142 
startShape(::com::sun::star::uno::Reference<::com::sun::star::drawing::XShape> xShape)143 void LoggedStream::startShape( ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > xShape )
144 {
145 #ifdef DEBUG_LOGGING
146     mHelper.startElement("shape");
147 #endif
148 
149     lcl_startShape(xShape);
150 }
151 
endShape()152 void LoggedStream::endShape()
153 {
154     lcl_endShape();
155 
156 #ifdef DEBUG_LOGGING
157     mHelper.endElement("shape");
158 #endif
159 }
160 
text(const sal_uInt8 * data,size_t len)161 void LoggedStream::text(const sal_uInt8 * data, size_t len)
162 {
163 #ifdef DEBUG_LOGGING
164     mHelper.startElement("text");
165 
166     ::rtl::OUString sText( (const sal_Char*) data, len, RTL_TEXTENCODING_MS_1252 );
167 
168     mHelper.startElement("data");
169     mHelper.chars(sText);
170     mHelper.endElement("data");
171 #endif
172 
173     lcl_text(data, len);
174 
175 #ifdef DEBUG_LOGGING
176     mHelper.endElement("text");
177 #endif
178 }
179 
utext(const sal_uInt8 * data,size_t len)180 void LoggedStream::utext(const sal_uInt8 * data, size_t len)
181 {
182 #ifdef DEBUG_LOGGING
183     mHelper.startElement("utext");
184     mHelper.startElement("data");
185 
186     ::rtl::OUString sText;
187     ::rtl::OUStringBuffer aBuffer = ::rtl::OUStringBuffer(len);
188     aBuffer.append( (const sal_Unicode *) data, len);
189     sText = aBuffer.makeStringAndClear();
190 
191     mHelper.chars(sText);
192 
193     mHelper.endElement("data");
194 #endif
195 
196     lcl_utext(data, len);
197 
198 #ifdef DEBUG_LOGGING
199     mHelper.endElement("utext");
200 #endif
201 }
202 
props(writerfilter::Reference<Properties>::Pointer_t ref)203 void LoggedStream::props(writerfilter::Reference<Properties>::Pointer_t ref)
204 {
205 #ifdef DEBUG_LOGGING
206     mHelper.startElement("props");
207 #endif
208 
209     lcl_props(ref);
210 
211 #ifdef DEBUG_LOGGING
212     mHelper.endElement("props");
213 #endif
214 }
215 
table(Id name,writerfilter::Reference<Table>::Pointer_t ref)216 void LoggedStream::table(Id name, writerfilter::Reference<Table>::Pointer_t ref)
217 {
218 #ifdef DEBUG_LOGGING
219     mHelper.startElement("table");
220     mHelper.attribute("name", (*QNameToString::Instance())(name));
221 #endif
222 
223     lcl_table(name, ref);
224 
225 #ifdef DEBUG_LOGGING
226     mHelper.endElement("table");
227 #endif
228 }
229 
substream(Id name,writerfilter::Reference<Stream>::Pointer_t ref)230 void LoggedStream::substream(Id name, writerfilter::Reference<Stream>::Pointer_t ref)
231 {
232 #ifdef DEBUG_LOGGING
233     mHelper.startElement("substream");
234     mHelper.attribute("name", (*QNameToString::Instance())(name));
235 #endif
236 
237     lcl_substream(name, ref);
238 
239 #ifdef DEBUG_LOGGING
240     mHelper.endElement("substream");
241 #endif
242 }
243 
info(const string & _info)244 void LoggedStream::info(const string & _info)
245 {
246 #ifdef DEBUG_LOGGING
247     mHelper.startElement("info");
248     mHelper.attribute("text", _info);
249 #endif
250 
251     lcl_info(_info);
252 
253 #ifdef DEBUG_LOGGING
254     mHelper.endElement("info");
255 #endif
256 }
257 
258 // class LoggedProperties
LoggedProperties(TagLogger::Pointer_t pLogger,const string & sPrefix)259 LoggedProperties::LoggedProperties(TagLogger::Pointer_t pLogger, const string & sPrefix)
260 : mHelper(pLogger, sPrefix)
261 {
262 }
263 
~LoggedProperties()264 LoggedProperties::~LoggedProperties()
265 {
266 }
267 
attribute(Id name,Value & val)268 void LoggedProperties::attribute(Id name, Value & val)
269 {
270 #ifdef DEBUG_LOGGING
271     mHelper.startElement("attribute");
272     mHelper.attribute("name", (*QNameToString::Instance())(name));
273     mHelper.attribute("value", val.toString());
274     mHelper.endElement("attribute");
275 #endif
276 
277     lcl_attribute(name, val);
278 }
279 
sprm(Sprm & _sprm)280 void LoggedProperties::sprm(Sprm & _sprm)
281 {
282 #ifdef DEBUG_LOGGING
283     mHelper.startElement("sprm");
284     mHelper.attribute("name", (*QNameToString::Instance())(_sprm.getId()));
285     mHelper.chars(sprm.toString());
286 #endif
287 
288     lcl_sprm(_sprm);
289 
290 #ifdef DEBUG_LOGGING
291     mHelper.endElement("sprm");
292 #endif
293 }
294 
LoggedTable(TagLogger::Pointer_t pLogger,const string & sPrefix)295 LoggedTable::LoggedTable(TagLogger::Pointer_t pLogger, const string & sPrefix)
296 : mHelper(pLogger, sPrefix)
297 {
298 }
299 
~LoggedTable()300 LoggedTable::~LoggedTable()
301 {
302 }
303 
entry(int pos,writerfilter::Reference<Properties>::Pointer_t ref)304 void LoggedTable::entry(int pos, writerfilter::Reference<Properties>::Pointer_t ref)
305 {
306 #ifdef DEBUG_LOGGING
307     mHelper.startElement("entry");
308     mHelper.attribute("pos", pos);
309 #endif
310 
311     lcl_entry(pos, ref);
312 
313 #ifdef DEBUG_LOGGING
314     mHelper.endElement("entry");
315 #endif
316 }
317 
318 }
319