Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "WW8ResourceModelImpl.hxx"
21 : #include <doctok/resources.hxx>
22 : #include "WW8OutputWithDepth.hxx"
23 : #include <resourcemodel/TableManager.hxx>
24 : #include <rtl/string.hxx>
25 : #include <resourcemodel/QNameToString.hxx>
26 :
27 : namespace writerfilter {
28 :
29 : namespace doctok
30 : {
31 : using namespace ::std;
32 :
33 :
34 : // ------- WW8TableDataHandler ---------
35 :
36 : typedef WW8PropertySet::Pointer_t TablePropsPointer_t;
37 :
38 : class WW8TableDataHandler : public TableDataHandler<string,
39 : TablePropsPointer_t>
40 : {
41 : public:
42 0 : virtual ~WW8TableDataHandler() {}
43 :
44 : typedef boost::shared_ptr<WW8TableDataHandler> Pointer_t;
45 : virtual void startTable(unsigned int nRows, unsigned int nDepth,
46 : TablePropsPointer_t pProps);
47 : virtual void endTable(unsigned int nestedTableLevel);
48 : virtual void startRow(unsigned int nCols,
49 : TablePropsPointer_t pProps);
50 : virtual void endRow();
51 : virtual void startCell(const string & start, TablePropsPointer_t pProps);
52 : virtual void endCell(const string & end);
53 : };
54 :
55 0 : void WW8TableDataHandler::startTable(unsigned int nRows, unsigned int nDepth,
56 : TablePropsPointer_t /*pProps*/)
57 : {
58 : char sBuffer[256];
59 :
60 0 : string tmpStr = "<tabledata.table rows=\"";
61 0 : snprintf(sBuffer, sizeof(sBuffer), "%d", nRows);
62 0 : tmpStr += sBuffer;
63 0 : tmpStr += "\" depth=\"";
64 0 : snprintf(sBuffer, sizeof(sBuffer), "%d", nDepth);
65 0 : tmpStr += sBuffer;
66 0 : tmpStr += "\">";
67 :
68 0 : output.addItem(tmpStr);
69 0 : }
70 :
71 0 : void WW8TableDataHandler::endTable(unsigned int /*nestedTableLevel*/)
72 : {
73 0 : output.addItem("</tabledata.table>");
74 0 : }
75 :
76 0 : void WW8TableDataHandler::startRow
77 : (unsigned int nCols, TablePropsPointer_t /*pProps*/)
78 : {
79 : char sBuffer[256];
80 :
81 0 : snprintf(sBuffer, sizeof(sBuffer), "%d", nCols);
82 0 : string tmpStr = "<tabledata.row cells=\"";
83 0 : tmpStr += sBuffer;
84 0 : tmpStr += "\">";
85 0 : output.addItem(tmpStr);
86 0 : }
87 :
88 0 : void WW8TableDataHandler::endRow()
89 : {
90 0 : output.addItem("</tabledata.row>");
91 0 : }
92 :
93 0 : void WW8TableDataHandler::startCell(const string & start,
94 : TablePropsPointer_t /*pProps*/)
95 : {
96 0 : output.addItem("<tabledata.cell>");
97 0 : output.addItem(start);
98 0 : output.addItem(", ");
99 0 : }
100 :
101 0 : void WW8TableDataHandler::endCell(const string & end)
102 : {
103 0 : output.addItem(end);
104 0 : output.addItem("</tabledata.cell>");
105 0 : }
106 :
107 : //-------- WW8TableReference -----------------------------------
108 :
109 0 : void WW8TableReference::resolve(Table & /*rHandler*/)
110 : {
111 0 : output.addItem("<table/>");
112 0 : }
113 :
114 0 : string WW8TableReference::getType() const
115 : {
116 0 : return "WW8TableReference";
117 : }
118 :
119 0 : void WW8PropertiesReference::resolve(Properties & rHandler)
120 : {
121 0 : if (mpPropSet != NULL)
122 : {
123 0 : if (mpPropSet->isPap())
124 : {
125 0 : WW8IntValue aValue(mpPropSet->get_istd());
126 :
127 0 : rHandler.attribute(NS_rtf::LN_ISTD, aValue);
128 : }
129 :
130 0 : WW8PropertySetIterator::Pointer_t pIt = mpPropSet->begin();
131 0 : WW8PropertySetIterator::Pointer_t pItEnd = mpPropSet->end();
132 :
133 : try
134 : {
135 0 : while (! pIt->equal(*pItEnd))
136 : {
137 0 : WW8Sprm aSprm(pIt->get());
138 0 : rHandler.sprm(aSprm);
139 :
140 0 : ++(*pIt);
141 0 : }
142 : }
143 0 : catch (ExceptionOutOfBounds)
144 : {
145 0 : }
146 : }
147 0 : }
148 :
149 0 : string WW8PropertiesReference::getType() const
150 : {
151 0 : return "WW8PropertiesReference";
152 : }
153 :
154 0 : WW8BinaryObjReference::WW8BinaryObjReference
155 : (WW8StructBase * pParent, sal_uInt32 nOffset, sal_uInt32 nCount)
156 0 : : WW8StructBase(pParent, nOffset, nCount)
157 : {
158 0 : }
159 :
160 0 : WW8BinaryObjReference::WW8BinaryObjReference
161 : (WW8StructBase * pParent)
162 0 : : WW8StructBase(pParent, 0x0, pParent->getCount())
163 : {
164 0 : }
165 :
166 : writerfilter::Reference<BinaryObj>::Pointer_t
167 0 : WW8BinaryObjReference::getBinary()
168 : {
169 : return writerfilter::Reference<BinaryObj>::Pointer_t
170 0 : (new WW8BinaryObjReference(*this));
171 : }
172 :
173 0 : void WW8BinaryObjReference::resolve(BinaryObj & rHandler)
174 : {
175 : writerfilter::Reference<Properties>::Pointer_t pRef =
176 0 : writerfilter::Reference<Properties>::Pointer_t();
177 :
178 0 : if (getCount() > 0)
179 0 : rHandler.data(get(0), getCount(), pRef);
180 0 : }
181 :
182 0 : string WW8BinaryObjReference::getType() const
183 : {
184 0 : return "WW8BinaryObjReference";
185 : }
186 :
187 0 : sal_uInt32 WW8Sprm::getId() const
188 : {
189 0 : sal_uInt32 nResult = 0;
190 :
191 0 : if (mpProperty.get() != NULL)
192 0 : nResult = mpProperty->getId();
193 0 : else if (mpBinary.get() != NULL)
194 0 : nResult = NS_rtf::LN_blob;
195 :
196 0 : return nResult;
197 : }
198 :
199 0 : string WW8Sprm::toString() const
200 : {
201 0 : string sResult = "";
202 :
203 0 : if (mpProperty.get() != NULL)
204 0 : sResult = mpProperty->toString();
205 :
206 0 : return sResult;
207 : }
208 :
209 0 : Value::Pointer_t WW8Sprm::getValue()
210 : {
211 0 : Value::Pointer_t pResult;
212 :
213 0 : if (mpProperty.get() != NULL)
214 0 : pResult = Value::Pointer_t(createValue(mpProperty->getParam()));
215 :
216 0 : return pResult;
217 : }
218 :
219 0 : writerfilter::Reference<BinaryObj>::Pointer_t WW8Sprm::getBinary()
220 : {
221 0 : writerfilter::Reference<BinaryObj>::Pointer_t pResult;
222 :
223 0 : if (mpBinary.get() != NULL)
224 : pResult = writerfilter::Reference<BinaryObj>::Pointer_t
225 0 : (mpBinary->clone());
226 0 : else if (mpProperty.get() != NULL)
227 : pResult = createSprmBinary
228 0 : (dynamic_cast<WW8PropertyImpl &>(*(mpProperty.get())));
229 :
230 0 : return pResult;
231 : }
232 :
233 0 : writerfilter::Reference<Stream>::Pointer_t WW8Sprm::getStream()
234 : {
235 0 : return writerfilter::Reference<Stream>::Pointer_t();
236 : }
237 :
238 0 : writerfilter::Reference<Properties>::Pointer_t WW8Sprm::getProps()
239 : {
240 0 : writerfilter::Reference<Properties>::Pointer_t pResult;
241 :
242 0 : if (mpProperty.get() != NULL)
243 : {
244 : pResult = createSprmProps
245 0 : (dynamic_cast<WW8PropertyImpl &>(*(mpProperty.get())));
246 : }
247 :
248 0 : return pResult;
249 : }
250 :
251 0 : Sprm::Kind WW8Sprm::getKind()
252 : {
253 0 : return SprmKind(getId());
254 : }
255 :
256 0 : string WW8Sprm::getName() const
257 : {
258 0 : return (*SprmIdToString::Instance())(getId());
259 : }
260 :
261 0 : int WW8Value::getInt() const
262 : {
263 0 : return 0;
264 : }
265 :
266 0 : uno::Any WW8Value::getAny() const
267 : {
268 0 : return uno::Any();
269 : }
270 :
271 0 : OUString WW8Value::getString() const
272 : {
273 0 : return OUString();
274 : }
275 :
276 0 : string WW8Value::toString() const
277 : {
278 0 : return string();
279 : }
280 :
281 0 : writerfilter::Reference<Properties>::Pointer_t WW8Value::getProperties()
282 : {
283 0 : return writerfilter::Reference<Properties>::Pointer_t();
284 : }
285 :
286 0 : writerfilter::Reference<Stream>::Pointer_t WW8Value::getStream()
287 : {
288 0 : return writerfilter::Reference<Stream>::Pointer_t();
289 : }
290 :
291 0 : writerfilter::Reference<BinaryObj>::Pointer_t WW8Value::getBinary()
292 : {
293 0 : return writerfilter::Reference<BinaryObj>::Pointer_t();
294 : }
295 :
296 0 : int WW8IntValue::getInt() const
297 : {
298 0 : return mValue;
299 : }
300 :
301 0 : OUString WW8IntValue::getString() const
302 : {
303 0 : return OUString::valueOf(static_cast<sal_Int32>(mValue));
304 : }
305 :
306 0 : uno::Any WW8IntValue::getAny() const
307 : {
308 0 : uno::Any aResult;
309 :
310 0 : aResult <<= static_cast<sal_uInt32>(mValue);
311 :
312 0 : return aResult;
313 : }
314 :
315 0 : string WW8IntValue::toString() const
316 : {
317 : char sBuffer[255];
318 :
319 0 : snprintf(sBuffer, sizeof(sBuffer), "%x", mValue);
320 :
321 0 : return string(sBuffer);
322 : }
323 :
324 0 : WW8Value::Pointer_t createValue(int value)
325 : {
326 0 : return WW8Value::Pointer_t(new WW8IntValue(value));
327 : }
328 :
329 : SAL_WNODEPRECATED_DECLARATIONS_PUSH
330 0 : WW8Value::Pointer_t createValue(WW8Value::Pointer_t value)
331 : {
332 0 : return value;
333 : }
334 : SAL_WNODEPRECATED_DECLARATIONS_POP
335 :
336 0 : int WW8StringValue::getInt() const
337 : {
338 0 : return 0;
339 : }
340 :
341 0 : OUString WW8StringValue::getString() const
342 : {
343 0 : return mString;
344 : }
345 :
346 0 : uno::Any WW8StringValue::getAny() const
347 : {
348 0 : uno::Any aResult;
349 :
350 0 : aResult <<= mString;
351 :
352 0 : return aResult;
353 : }
354 :
355 0 : string WW8StringValue::toString() const
356 : {
357 0 : string result;
358 :
359 0 : sal_uInt32 nCount = mString.getLength();
360 0 : for (sal_uInt32 n = 0; n < nCount; ++n)
361 : {
362 0 : if (mString[n] <= 0xff && isprint(mString[n]))
363 : {
364 0 : sal_Unicode nC = mString[n];
365 :
366 0 : if (nC < 256)
367 0 : result += sal::static_int_cast<char>(nC);
368 : else
369 0 : result += ".";
370 : }
371 : else
372 : {
373 : char sBuffer[64];
374 :
375 0 : snprintf(sBuffer, sizeof(sBuffer), "\\u%04x", mString[n]);
376 0 : result += sBuffer;
377 : }
378 : }
379 :
380 0 : return result;
381 : }
382 :
383 0 : WW8Value::Pointer_t createValue(const OUString & rStr)
384 : {
385 0 : return WW8Value::Pointer_t(new WW8StringValue(rStr));
386 : }
387 :
388 : writerfilter::Reference<Properties>::Pointer_t
389 0 : WW8PropertiesValue::getProperties()
390 : {
391 0 : return mRef;
392 : }
393 :
394 0 : string WW8PropertiesValue::toString() const
395 : {
396 0 : return "properties";
397 : }
398 :
399 0 : writerfilter::Reference<Stream>::Pointer_t WW8StreamValue::getStream()
400 : {
401 0 : return mRef;
402 : }
403 :
404 0 : string WW8StreamValue::toString() const
405 : {
406 0 : return "stream";
407 : }
408 :
409 0 : writerfilter::Reference<BinaryObj>::Pointer_t WW8BinaryObjValue::getBinary()
410 : {
411 0 : return mRef;
412 : }
413 :
414 0 : string WW8BinaryObjValue::toString() const
415 : {
416 0 : return "binaryObj";
417 : }
418 :
419 0 : WW8Value::Pointer_t createValue
420 : (writerfilter::Reference<Properties>::Pointer_t rRef)
421 : {
422 0 : return WW8Value::Pointer_t(new WW8PropertiesValue(rRef));
423 : }
424 :
425 0 : WW8Value::Pointer_t createValue(writerfilter::Reference<Stream>::Pointer_t rRef)
426 : {
427 0 : return WW8Value::Pointer_t(new WW8StreamValue(rRef));
428 : }
429 :
430 0 : WW8Value::Pointer_t createValue
431 : (writerfilter::Reference<BinaryObj>::Pointer_t rRef)
432 : {
433 0 : return WW8Value::Pointer_t(new WW8BinaryObjValue(rRef));
434 : }
435 :
436 :
437 : }
438 :
439 15 : }
440 :
441 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|